From 5cb280f986bdbb56f09adc89bc59422880d79352 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Wed, 27 Feb 2019 15:53:28 -0800 Subject: [PATCH] Fix scope check for 2nd+ lexical bindings (#9600) --- packages/babel-parser/src/util/scope.js | 3 +-- .../core/scope/dupl-bind-2nd-lvl-lex-nested/input.js | 5 +++++ .../core/scope/dupl-bind-2nd-lvl-lex-nested/options.json | 3 +++ .../test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/input.js | 3 +++ .../fixtures/core/scope/dupl-bind-2nd-lvl-lex/options.json | 3 +++ .../core/scope/dupl-bind-2nd-lvl-var-nested/input.js | 5 +++++ .../core/scope/dupl-bind-2nd-lvl-var-nested/options.json | 3 +++ .../test/fixtures/core/scope/dupl-bind-2nd-lvl-var/input.js | 3 +++ .../fixtures/core/scope/dupl-bind-2nd-lvl-var/options.json | 3 +++ 9 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex-nested/input.js create mode 100644 packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex-nested/options.json create mode 100644 packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/input.js create mode 100644 packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/options.json create mode 100644 packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var-nested/input.js create mode 100644 packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var-nested/options.json create mode 100644 packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var/input.js create mode 100644 packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var/options.json diff --git a/packages/babel-parser/src/util/scope.js b/packages/babel-parser/src/util/scope.js index 8d9e08b1a8..a9cf9d89ed 100644 --- a/packages/babel-parser/src/util/scope.js +++ b/packages/babel-parser/src/util/scope.js @@ -117,8 +117,7 @@ export default class ScopeHandler { const scope = this.scopeStack[i]; if ( (scope.lexical.indexOf(name) > -1 && - !(scope.flags & SCOPE_SIMPLE_CATCH) && - scope.lexical[0] === name) || + !(scope.flags & SCOPE_SIMPLE_CATCH && scope.lexical[0] === name)) || (!this.treatFunctionsAsVarInScope(scope) && scope.functions.indexOf(name) > -1) ) { diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex-nested/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex-nested/input.js new file mode 100644 index 0000000000..9c289f87c3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex-nested/input.js @@ -0,0 +1,5 @@ +{ + let bar; + var foo = 1; + let foo = 1; +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex-nested/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex-nested/options.json new file mode 100644 index 0000000000..b09098cda9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex-nested/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (4:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/input.js new file mode 100644 index 0000000000..512f688865 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/input.js @@ -0,0 +1,3 @@ +let bar; +var foo = 1; +let foo = 1; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/options.json new file mode 100644 index 0000000000..37dd7bff72 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-lex/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (3:4)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var-nested/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var-nested/input.js new file mode 100644 index 0000000000..59ae63e301 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var-nested/input.js @@ -0,0 +1,5 @@ +{ + let bar; + let foo = 1; + var foo = 1; +} diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var-nested/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var-nested/options.json new file mode 100644 index 0000000000..b09098cda9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var-nested/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (4:6)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var/input.js b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var/input.js new file mode 100644 index 0000000000..aebd03c057 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var/input.js @@ -0,0 +1,3 @@ +let bar; +let foo = 1; +var foo = 1; diff --git a/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var/options.json b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var/options.json new file mode 100644 index 0000000000..37dd7bff72 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/dupl-bind-2nd-lvl-var/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'foo' has already been declared (3:4)" +} \ No newline at end of file