diff --git a/acorn.js b/acorn.js index 91284e04ac..847a6ba67c 100644 --- a/acorn.js +++ b/acorn.js @@ -315,7 +315,7 @@ function initParserState() { lastStart = lastEnd = tokPos; if (options.locations) lastEndLoc = curPosition(); - inFunction = inGenerator = strict = false; + inFunction = inGenerator = false; labels = []; skipSpace(); readToken(); @@ -616,6 +616,7 @@ tokType = _eof; tokContext = [b_stat]; tokExprAllowed = true; + strict = false; if (tokPos === 0 && options.allowHashBang && input.slice(0, 2) === '#!') { skipLineComment(2); } @@ -1523,8 +1524,10 @@ break; case "SpreadElement": last.type = "RestElement"; - toAssignable(last.argument); - checkSpreadAssign(last.argument); + var arg = last.argument; + toAssignable(arg); + if (arg.type !== "Identifier" && arg.type !== "ArrayPattern") + unexpected(arg.start); break; default: toAssignable(last); @@ -1545,8 +1548,7 @@ function parseRest() { var node = startNode(); next(); - node.argument = parseAssignableAtom(); - checkSpreadAssign(node.argument); + node.argument = tokType === _name || tokType === _bracketL ? parseAssignableAtom() : unexpected(); return finishNode(node, "RestElement"); } @@ -1598,13 +1600,6 @@ return finishNode(node, "AssignmentPattern"); } - // Checks if node can be assignable spread argument. - - function checkSpreadAssign(node) { - if (node.type !== "Identifier" && node.type !== "ArrayPattern") - unexpected(node.start); - } - // Verify that argument names are not repeated, and it does not // try to bind the words `eval` or `arguments`. @@ -1691,7 +1686,11 @@ break; case "AssignmentPattern": + checkLVal(expr.left); + break; + case "RestElement": + checkLVal(expr.argument); break; default: diff --git a/acorn_loose.js b/acorn_loose.js index 297589a498..ab0c6ea709 100644 --- a/acorn_loose.js +++ b/acorn_loose.js @@ -325,9 +325,6 @@ } function parseStatement() { - if (token.type === tt.slash || token.type === tt.assign && token.value === "/=") - next(true); - var starttype = token.type, node = startNode(); switch (starttype) { diff --git a/test/tests-harmony.js b/test/tests-harmony.js index 641f18657f..596e5f7ab0 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -15013,3 +15013,6 @@ testFail("if (1) let x = 10;", "Unexpected token (1:7)", {ecmaVersion: 6}); testFail("for (;;) const x = 10;", "Unexpected token (1:9)", {ecmaVersion: 6}); testFail("while (1) function foo(){}", "Unexpected token (1:10)", {ecmaVersion: 6}); testFail("if (1) ; else class Cls {}", "Unexpected token (1:14)", {ecmaVersion: 6}); + +testFail("'use strict'; [...eval] = arr", "Assigning to eval in strict mode (1:18)", {ecmaVersion: 6}); +testFail("'use strict'; ({eval = defValue} = obj)", "Assigning to eval in strict mode (1:16)", {ecmaVersion: 6});