[Pkg-javascript-commits] [node-acorn-jsx] 424/484: Simplify & fix rest argument validity checks.
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:21:05 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-acorn-jsx.
commit 5d96bbd781538b14d61bb1259a446317520fc0ba
Author: Ingvar Stepanyan <me at rreverser.com>
Date: Sat Jan 24 13:38:14 2015 +0200
Simplify & fix rest argument validity checks.
---
acorn.js | 23 +++++++++++------------
acorn_loose.js | 3 ---
test/tests-harmony.js | 3 +++
3 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/acorn.js b/acorn.js
index 91284e0..847a6ba 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 297589a..ab0c6ea 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 641f186..596e5f7 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});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git
More information about the Pkg-javascript-commits
mailing list