diff options
Diffstat (limited to 'lib/parse.js')
-rw-r--r-- | lib/parse.js | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/parse.js b/lib/parse.js index d5098ff5..c8f63d80 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1039,6 +1039,7 @@ function parse($TEXT, options) { } function for_() { + var await = is("name", "await") && next(); expect("("); var init = null; if (!is("punc", ";")) { @@ -1049,16 +1050,26 @@ function parse($TEXT, options) { : is("keyword", "var") ? (next(), var_(true)) : expression(true); - if (is("operator", "in")) { + var ctor; + if (await) { + expect_token("name", "of"); + ctor = AST_ForAwaitOf; + } else if (is("operator", "in")) { + next(); + ctor = AST_ForIn; + } else if (is("name", "of")) { + next(); + ctor = AST_ForOf; + } + if (ctor) { if (init instanceof AST_Definitions) { if (init.definitions.length > 1) { - token_error(init.start, "Only one variable declaration allowed in for..in loop"); + token_error(init.start, "Only one variable declaration allowed in for..in/of loop"); } } else if (!(is_assignable(init) || (init = to_destructured(init)) instanceof AST_Destructured)) { - token_error(init.start, "Invalid left-hand side in for..in loop"); + token_error(init.start, "Invalid left-hand side in for..in/of loop"); } - next(); - return for_in(init); + return for_enum(ctor, init); } } return regular_for(init); @@ -1078,10 +1089,10 @@ function parse($TEXT, options) { }); } - function for_in(init) { + function for_enum(ctor, init) { var obj = expression(); expect(")"); - return new AST_ForIn({ + return new ctor({ init : init, object : obj, body : in_loop(statement) @@ -1523,7 +1534,7 @@ function parse($TEXT, options) { func.end = prev(); return subscripts(func, allow_calls); } - if (is("name")) { + if (is("name") && is_token(peek(), "punc", "=>")) { start = S.token; sym = _make_symbol(AST_SymbolRef, start); next(); |