From 2655e84f0d7e367e4aff6cfd7503eb4e60826fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Wed, 21 Mar 2018 20:28:40 +0000 Subject: [PATCH] implement AST_Yield spidermonkey AST --- lib/mozilla-ast.js | 1 + lib/parse.js | 5 ++++- test/input/spidermonkey/input.js | 7 +++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js index ec8bc87d..275047b1 100644 --- a/lib/mozilla-ast.js +++ b/lib/mozilla-ast.js @@ -464,6 +464,7 @@ map("ForInStatement", AST_ForIn, "left>init, right>object, body>body"); map("ForOfStatement", AST_ForOf, "left>init, right>object, body>body"); map("AwaitExpression", AST_Await, "argument>expression"); + map("YieldExpression", AST_Yield, "argument>expression, delegate=is_star"); map("DebuggerStatement", AST_Debugger); map("VariableDeclarator", AST_VarDef, "id>name, init>value"); map("CatchClause", AST_Catch, "param>argname, body%body"); diff --git a/lib/parse.js b/lib/parse.js index 78640dc5..313d890f 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1726,6 +1726,7 @@ function parse($TEXT, options) { croak("Unexpected yield expression outside generator function", S.prev.line, S.prev.col, S.prev.pos); } + var start = S.token; var star = false; var has_expression = true; @@ -1749,8 +1750,10 @@ function parse($TEXT, options) { } return new AST_Yield({ + start : start, is_star : star, - expression : has_expression ? expression() : null + expression : has_expression ? expression() : null, + end : prev() }); } diff --git a/test/input/spidermonkey/input.js b/test/input/spidermonkey/input.js index 033bbfa4..7cdc7c19 100644 --- a/test/input/spidermonkey/input.js +++ b/test/input/spidermonkey/input.js @@ -17,10 +17,13 @@ export {A1, B1} from "a.js"; export {C}; (a, [b], {c:foo = 3}, ...d) => null; -() => {} +() => {}; async function f() { } -function*gen() { } +function*gen() { + yield 1; + yield* 2; +} class Class extends Object { constructor(...args) {