Skip to content

Commit

Permalink
Correctly disallow var declarations with init in for-of loops
Browse files Browse the repository at this point in the history
  • Loading branch information
danez authored and marijnh committed Mar 26, 2019
1 parent b406e91 commit 07c7202
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions acorn/src/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ pp.parseForIn = function(node, init) {
init.type === "VariableDeclaration" &&
init.declarations[0].init != null &&
(
!isForIn ||
this.options.ecmaVersion < 8 ||
this.strict ||
init.kind !== "var" ||
Expand Down
1 change: 1 addition & 0 deletions test/tests-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -13121,6 +13121,7 @@ testFail("for (const x = 42 in list) process(x);", "for-in loop variable declara
testFail("for (let x = 42 of list) process(x);", "for-of loop variable declaration may not have an initializer (1:5)", {ecmaVersion: 6});
testFail("for (const x = 42 of list) process(x);", "for-of loop variable declaration may not have an initializer (1:5)", {ecmaVersion: 6});
testFail("for (var x = 42 of list) process(x);", "for-of loop variable declaration may not have an initializer (1:5)", {ecmaVersion: 6});
testFail("for (var x = 42 of list) process(x);", "for-of loop variable declaration may not have an initializer (1:5)", {ecmaVersion: 8});
testFail("for (var {x} = 42 of list) process(x);", "for-of loop variable declaration may not have an initializer (1:5)", {ecmaVersion: 6});
testFail("for (var [x] = 42 of list) process(x);", "for-of loop variable declaration may not have an initializer (1:5)", {ecmaVersion: 6});
testFail("var x; for (x = 42 of list) process(x);", "Invalid left-hand side in for-loop (1:12)", {ecmaVersion: 6});
Expand Down

0 comments on commit 07c7202

Please sign in to comment.