Skip to content

Commit

Permalink
Fix scope check for 2nd+ lexical bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGu authored and marijnh committed Feb 5, 2019
1 parent 600e770 commit c4fdd0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion acorn/src/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pp.declareName = function(name, bindingType, pos) {
} else {
for (let i = this.scopeStack.length - 1; i >= 0; --i) {
const scope = this.scopeStack[i]
if (scope.lexical.indexOf(name) > -1 && !(scope.flags & SCOPE_SIMPLE_CATCH) && scope.lexical[0] === name ||
if (scope.lexical.indexOf(name) > -1 && !((scope.flags & SCOPE_SIMPLE_CATCH) && scope.lexical[0] === name) ||
!this.treatFunctionsAsVarInScope(scope) && scope.functions.indexOf(name) > -1) {
redeclared = true
break
Expand Down
8 changes: 8 additions & 0 deletions test/tests-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -16226,8 +16226,16 @@ testFail("var foo = 1; let foo = 1;", "Identifier 'foo' has already been declare

testFail("{ var foo = 1; let foo = 1; }", "Identifier 'foo' has already been declared (1:19)", {ecmaVersion: 6})

testFail("let bar; var foo = 1; let foo = 1;", "Identifier 'foo' has already been declared (1:26)", {ecmaVersion: 6})

testFail("{ let bar; var foo = 1; let foo = 1; }", "Identifier 'foo' has already been declared (1:28)", {ecmaVersion: 6})

testFail("let foo = 1; var foo = 1;", "Identifier 'foo' has already been declared (1:17)", {ecmaVersion: 6})

testFail("let bar; let foo = 1; var foo = 1;", "Identifier 'foo' has already been declared (1:26)", {ecmaVersion: 6})

testFail("{ let bar; let foo = 1; var foo = 1; }", "Identifier 'foo' has already been declared (1:28)", {ecmaVersion: 6})

testFail("let foo = 1; let foo = 1;", "Identifier 'foo' has already been declared (1:17)", {ecmaVersion: 6})

testFail("var foo = 1; const foo = 1;", "Identifier 'foo' has already been declared (1:19)", {ecmaVersion: 6})
Expand Down

0 comments on commit c4fdd0f

Please sign in to comment.