Simplify & fix rest argument validity checks.
This commit is contained in:
parent
cdd444eff1
commit
5d96bbd781
23
acorn.js
23
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:
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user