From 05ba26c7c8b96bddeb7b97ef42b5c03283b8e72e Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Sat, 2 Aug 2014 13:18:27 +0300 Subject: [PATCH] Small fixes for AST conversion. --- lib/mozilla-ast.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js index d1577308..0d2259de 100644 --- a/lib/mozilla-ast.js +++ b/lib/mozilla-ast.js @@ -282,7 +282,7 @@ 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) }; }); @@ -335,9 +335,21 @@ }); 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 }; }); @@ -422,8 +434,8 @@ 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 + ")")( -- 2.34.1