Fix output for "use asm" code from SpiderMonkey AST
authorMihai Bazon <mihai.bazon@gmail.com>
Thu, 12 Nov 2015 10:18:25 +0000 (12:18 +0200)
committerMihai Bazon <mihai.bazon@gmail.com>
Thu, 12 Nov 2015 10:18:25 +0000 (12:18 +0200)
(will only work properly if the SM tree contains "raw" properties for
Literal number nodes)

lib/ast.js
lib/mozilla-ast.js
lib/output.js
lib/parse.js

index f5225d7..0ac14dc 100644 (file)
@@ -85,7 +85,7 @@ function DEFNODE(type, props, methods, base) {
     return ctor;
 };
 
-var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos nlb comments_before file literal", {
+var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos nlb comments_before file raw", {
 }, null);
 
 var AST_Node = DEFNODE("Node", "start end", {
index 2bb469f..c1b2b68 100644 (file)
                 prefix: true,
                 argument: {
                     type: "Literal",
-                    value: -value
+                    value: -value,
+                    raw: M.start.raw
                 }
             };
         }
         return {
             type: "Literal",
-            value: value
+            value: value,
+            raw: M.start.raw
         };
     });
 
 
     /* -----[ tools ]----- */
 
+    function raw_token(moznode) {
+        if (moznode.type == "Literal") {
+            return moznode.raw != null ? moznode.raw : moznode.value + "";
+        }
+    }
+
     function my_start_token(moznode) {
         var loc = moznode.loc, start = loc && loc.start;
         var range = moznode.range;
             pos     : range ? range[0] : moznode.start,
             endline : start && start.line,
             endcol  : start && start.column,
-            endpos  : range ? range[0] : moznode.start
+            endpos  : range ? range[0] : moznode.start,
+            raw     : raw_token(moznode),
         });
     };
 
             pos     : range ? range[1] : moznode.end,
             endline : end && end.line,
             endcol  : end && end.column,
-            endpos  : range ? range[1] : moznode.end
+            endpos  : range ? range[1] : moznode.end,
+            raw     : raw_token(moznode),
         });
     };
 
index 9dadf0e..f10c918 100644 (file)
@@ -1178,8 +1178,8 @@ function OutputStream(options) {
         output.print_string(self.getValue(), self.quote);
     });
     DEFPRINT(AST_Number, function(self, output){
-        if (use_asm) {
-            output.print(self.start.literal);
+        if (use_asm && self.start.raw != null) {
+            output.print(self.start.raw);
         } else {
             output.print(make_num(self.getValue()));
         }
index 901d10a..de27d98 100644 (file)
@@ -286,7 +286,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
             file    : filename
         };
         if (/^(?:num|string|regexp)$/i.test(type)) {
-            ret.literal = $TEXT.substring(ret.pos, ret.endpos);
+            ret.raw = $TEXT.substring(ret.pos, ret.endpos);
         }
         if (!is_comment) {
             ret.comments_before = S.comments_before;