Small fixes for AST conversion.
authorIngvar Stepanyan <me@rreverser.com>
Sat, 2 Aug 2014 10:18:27 +0000 (13:18 +0300)
committerIngvar Stepanyan <me@rreverser.com>
Sat, 2 Aug 2014 10:18:27 +0000 (13:18 +0300)
lib/mozilla-ast.js

index d157730..0d2259d 100644 (file)
             type: M.operator == "++" || M.operator == "--" ? "UpdateExpression" : "UnaryExpression",
             operator: M.operator,
             prefix: M instanceof AST_UnaryPrefix,
-            argument: to_moz(M.argument)
+            argument: to_moz(M.expression)
         };
     });
 
     });
 
     def_to_moz(AST_Constant, function To_Moz_Literal(M) {
+        var value = M.value;
+        if (typeof value === 'number' && (value < 0 || (value === 0 && 1 / value < 0))) {
+            return {
+                type: "UnaryExpression",
+                operator: "-",
+                prefix: true,
+                argument: {
+                    type: "Literal",
+                    value: -value
+                }
+            };
+        }
         return {
             type: "Literal",
-            value: M.value
+            value: value
         };
     });
 
         moz_to_me += "\n})\n}";
         me_to_moz += "\n}\n}";
 
-        moz_to_me = parse(moz_to_me).print_to_string({ beautify: true });
-        me_to_moz = parse(me_to_moz).print_to_string({ beautify: true });
+        //moz_to_me = parse(moz_to_me).print_to_string({ beautify: true });
+        //me_to_moz = parse(me_to_moz).print_to_string({ beautify: true });
         //console.log(moz_to_me);
 
         moz_to_me = new Function("my_start_token", "my_end_token", "from_moz", "return(" + moz_to_me + ")")(