diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index 5e77de8ba3..0f55802ea0 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -901,7 +901,6 @@ export default class StatementParser extends ExpressionParser { node.update = this.match(tt.parenR) ? null : this.parseExpression(); this.expect(tt.parenR); - this.scope.exit(); node.body = // For the smartPipelines plugin: Disable topic references from outer // contexts within the loop body. They are permitted in test expressions, @@ -911,6 +910,7 @@ export default class StatementParser extends ExpressionParser { this.parseStatement("for"), ); + this.scope.exit(); this.state.labels.pop(); return this.finishNode(node, "ForStatement"); @@ -937,7 +937,6 @@ export default class StatementParser extends ExpressionParser { node.right = this.parseExpression(); this.expect(tt.parenR); - this.scope.exit(); node.body = // For the smartPipelines plugin: // Disable topic references from outer contexts within the loop body. @@ -947,6 +946,7 @@ export default class StatementParser extends ExpressionParser { this.parseStatement("for"), ); + this.scope.exit(); this.state.labels.pop(); return this.finishNode(node, type); diff --git a/packages/babel-parser/test/fixtures/core/scope/for-let/input.js b/packages/babel-parser/test/fixtures/core/scope/for-let/input.js new file mode 100644 index 0000000000..a169b40380 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/for-let/input.js @@ -0,0 +1,3 @@ +for (let i = 0;;) { + let i; +} diff --git a/packages/babel-parser/test/fixtures/core/scope/for-let/output.json b/packages/babel-parser/test/fixtures/core/scope/for-let/output.json new file mode 100644 index 0000000000..8af98b16aa --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/for-let/output.json @@ -0,0 +1,191 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ForStatement", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "init": { + "type": "VariableDeclaration", + "start": 5, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 9, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "i" + }, + "name": "i" + }, + "init": { + "type": "NumericLiteral", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ], + "kind": "let" + }, + "test": null, + "update": null, + "body": { + "type": "BlockStatement", + "start": 18, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "id": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "i" + }, + "name": "i" + }, + "init": null + } + ], + "kind": "let" + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/scope/for-var/input.js b/packages/babel-parser/test/fixtures/core/scope/for-var/input.js new file mode 100644 index 0000000000..400b636e5c --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/for-var/input.js @@ -0,0 +1,3 @@ +for (let i = 0;;) { + var i; +} diff --git a/packages/babel-parser/test/fixtures/core/scope/for-var/options.json b/packages/babel-parser/test/fixtures/core/scope/for-var/options.json new file mode 100644 index 0000000000..10e45adf45 --- /dev/null +++ b/packages/babel-parser/test/fixtures/core/scope/for-var/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Identifier 'i' has already been declared (2:8)" +} \ No newline at end of file diff --git a/scripts/tests/test262/test262_whitelist.txt b/scripts/tests/test262/test262_whitelist.txt index 716f19338c..0c385c9bc7 100644 --- a/scripts/tests/test262/test262_whitelist.txt +++ b/scripts/tests/test262/test262_whitelist.txt @@ -1,3 +1,4 @@ + annexB/language/statements/for-in/bare-initializer.js(default) annexB/language/statements/for-in/bare-initializer.js(strict mode) built-ins/RegExp/property-escapes/binary-property-with-value-ASCII_-_F-negated.js(default) @@ -719,23 +720,13 @@ language/statements/for-in/dstr/array-rest-before-elision.js(default) language/statements/for-in/dstr/array-rest-before-elision.js(strict mode) language/statements/for-in/dstr/array-rest-elision-invalid.js(default) language/statements/for-in/dstr/array-rest-elision-invalid.js(strict mode) -language/statements/for-in/head-const-bound-names-in-stmt.js(default) -language/statements/for-in/head-const-bound-names-in-stmt.js(strict mode) -language/statements/for-in/head-let-bound-names-in-stmt.js(default) -language/statements/for-in/head-let-bound-names-in-stmt.js(strict mode) language/statements/for-of/dstr/array-rest-before-elision.js(default) language/statements/for-of/dstr/array-rest-before-elision.js(strict mode) language/statements/for-of/dstr/array-rest-elision-invalid.js(default) language/statements/for-of/dstr/array-rest-elision-invalid.js(strict mode) -language/statements/for-of/head-const-bound-names-in-stmt.js(default) -language/statements/for-of/head-const-bound-names-in-stmt.js(strict mode) language/statements/for-of/head-decl-no-expr.js(default) language/statements/for-of/head-decl-no-expr.js(strict mode) language/statements/for-of/head-expr-no-expr.js(default) language/statements/for-of/head-expr-no-expr.js(strict mode) -language/statements/for-of/head-let-bound-names-in-stmt.js(default) -language/statements/for-of/head-let-bound-names-in-stmt.js(strict mode) language/statements/for-of/head-var-no-expr.js(default) -language/statements/for-of/head-var-no-expr.js(strict mode) -language/statements/for/head-let-bound-names-in-stmt.js(default) -language/statements/for/head-let-bound-names-in-stmt.js(strict mode) \ No newline at end of file +language/statements/for-of/head-var-no-expr.js(strict mode) \ No newline at end of file