Treat for loop body as part of loop scope (#9586)
This commit is contained in:
parent
e6c1065d19
commit
d0e196d210
@ -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);
|
||||
|
||||
3
packages/babel-parser/test/fixtures/core/scope/for-let/input.js
vendored
Normal file
3
packages/babel-parser/test/fixtures/core/scope/for-let/input.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
for (let i = 0;;) {
|
||||
let i;
|
||||
}
|
||||
191
packages/babel-parser/test/fixtures/core/scope/for-let/output.json
vendored
Normal file
191
packages/babel-parser/test/fixtures/core/scope/for-let/output.json
vendored
Normal file
@ -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": []
|
||||
}
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/core/scope/for-var/input.js
vendored
Normal file
3
packages/babel-parser/test/fixtures/core/scope/for-var/input.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
for (let i = 0;;) {
|
||||
var i;
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/core/scope/for-var/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/core/scope/for-var/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Identifier 'i' has already been declared (2:8)"
|
||||
}
|
||||
@ -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)
|
||||
language/statements/for-of/head-var-no-expr.js(strict mode)
|
||||
Loading…
x
Reference in New Issue
Block a user