diff options
Diffstat (limited to 'lib/mozilla-ast.js')
-rw-r--r-- | lib/mozilla-ast.js | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js index 09c5b105..028441b7 100644 --- a/lib/mozilla-ast.js +++ b/lib/mozilla-ast.js @@ -220,7 +220,7 @@ start: my_start_token(M), end: my_end_token(M), key: key, - value: from_moz(M[M.shorthand ? "key" : "value"]), + value: from_moz(M.value), }; if (M.kind == "init") return new (M.method ? AST_ObjectMethod : AST_ObjectKeyVal)(args); args.value = new AST_Accessor(args.value); @@ -395,6 +395,20 @@ path: M.source.value, }); }, + ImportExpression: function(M) { + var start = my_start_token(M); + var arg = from_moz(M.source); + return new AST_Call({ + start: start, + end: my_end_token(M), + expression: new AST_SymbolRef({ + start: start, + end: arg.start, + name: "import", + }), + args: [ arg ], + }); + }, VariableDeclaration: function(M) { return new ({ const: AST_Const, @@ -462,7 +476,7 @@ } while (p.type == "ArrayPattern" || p.type == "AssignmentPattern" && p.left === FROM_MOZ_STACK[level + 1] || p.type == "ObjectPattern" - || p.type == "Property" && p[p.shorthand ? "key" : "value"] === FROM_MOZ_STACK[level + 1] + || p.type == "Property" && p.value === FROM_MOZ_STACK[level + 1] || p.type == "VariableDeclarator" && p.id === FROM_MOZ_STACK[level + 1]); var ctor = AST_SymbolRef; switch (p.type) { @@ -731,18 +745,9 @@ }); def_to_moz(AST_ExportDefault, function To_Moz_ExportDefaultDeclaration(M) { - var decl = to_moz(M.body); - switch (decl.type) { - case "ClassExpression": - decl.type = "ClassDeclaration"; - break; - case "FunctionExpression": - decl.type = "FunctionDeclaration"; - break; - } return { type: "ExportDefaultDeclaration", - declaration: decl, + declaration: to_moz(M.body), }; }); @@ -1158,11 +1163,15 @@ var FROM_MOZ_STACK = null; - function from_moz(node) { - FROM_MOZ_STACK.push(node); - var ret = node != null ? MOZ_TO_ME[node.type](node) : null; + function from_moz(moz) { + FROM_MOZ_STACK.push(moz); + var node = null; + if (moz) { + if (!HOP(MOZ_TO_ME, moz.type)) throw new Error("Unsupported type: " + moz.type); + node = MOZ_TO_ME[moz.type](moz); + } FROM_MOZ_STACK.pop(); - return ret; + return node; } AST_Node.from_mozilla_ast = function(node) { |