diff src/jscomp.sml @ 943:e2194a6793ae

Fix JavaScript char literals; don't generate demo links to nonexistent files
author Adam Chlipala <adamc@hcoop.net>
date Tue, 15 Sep 2009 13:07:57 -0400
parents 36f787c02287
children 5be3d19b59f3
line wrap: on
line diff
--- a/src/jscomp.sml	Tue Sep 15 12:41:54 2009 -0400
+++ b/src/jscomp.sml	Tue Sep 15 13:07:57 2009 -0400
@@ -537,34 +537,34 @@
                         val strcat = strcat loc
 
                         fun jsPrim p =
-                            case p of
-                                Prim.String s =>
-                                str ("\""
-                                     ^ String.translate (fn #"'" =>
-                                                            if mode = Attribute then
-                                                                "\\047"
-                                                            else
-                                                                "'"
-                                                          | #"\"" => "\\\""
-                                                          | #"<" =>
-                                                            (*if mode = Script then
-                                                                "<"
-                                                            else*)
-                                                                "\\074"
-                                                          | #"\\" => "\\\\"
-                                                          | #"\n" => "\\n"
-                                                          | #"\r" => "\\r"
-                                                          | #"\t" => "\\t"
-                                                          | ch =>
-                                                            if Char.isPrint ch then
-                                                                String.str ch
-                                                            else
-                                                                "\\" ^ padWith (#"0",
-                                                                                Int.fmt StringCvt.OCT (ord ch),
-                                                                                3)) s
-                                     ^ "\"")
-                              | Prim.Char ch => str ("'" ^ String.str ch ^ "'")
-                              | _ => str (Prim.toString p)
+                            let
+                                fun jsChar ch =
+                                    case ch of
+                                        #"'" =>
+                                        if mode = Attribute then
+                                            "\\047"
+                                        else
+                                            "'"
+                                      | #"\"" => "\\\""
+                                      | #"<" => "\\074"
+                                      | #"\\" => "\\\\"
+                                      | #"\n" => "\\n"
+                                      | #"\r" => "\\r"
+                                      | #"\t" => "\\t"
+                                      | ch =>
+                                        if Char.isPrint ch then
+                                            String.str ch
+                                        else
+                                            "\\" ^ padWith (#"0",
+                                                            Int.fmt StringCvt.OCT (ord ch),
+                                                            3)
+                            in
+                                case p of
+                                    Prim.String s =>
+                                    str ("\"" ^ String.translate jsChar s ^ "\"")
+                                  | Prim.Char ch => str ("'" ^ jsChar ch ^ "'")
+                                  | _ => str (Prim.toString p)
+                            end
 
                         fun jsPat depth inner (p, _) succ fail =
                             case p of