Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow
#a in #b in c
and similar expressions (#13727)
* Disallow `#a in #b in c` and similar expressions * Update packages/babel-parser/src/parser/expression.js Co-authored-by: Hu谩ng J霉nli脿ng <jlhwung@gmail.com> * Add test for `await #x in` * Flow * Update flow allowlist * Flow Co-authored-by: Hu谩ng J霉nli脿ng <jlhwung@gmail.com>
- Loading branch information
1 parent
5a361fe
commit 44388e6
Showing
11 changed files
with
505 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...abel-parser/test/fixtures/es2022/class-private-methods/asi-failure-generator/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Unexpected token (3:9)" | ||
"throws": "Unexpected token (3:6)" | ||
} |
7 changes: 7 additions & 0 deletions
7
...el-parser/test/fixtures/experimental/private-in/invalid-private-followed-by-in-1/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Foo { | ||
#a; | ||
#b; | ||
method() { | ||
#a in #b in c | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
...parser/test/fixtures/experimental/private-in/invalid-private-followed-by-in-1/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":60,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: Private names are only allowed in property accesses (`obj.#b`) or in `in` expressions (`#b in obj`). (5:10)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":60,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":60,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":10,"end":60,"loc":{"start":{"line":1,"column":10},"end":{"line":7,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassPrivateProperty", | ||
"start":14,"end":17,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":5}}, | ||
"static": false, | ||
"key": { | ||
"type": "PrivateName", | ||
"start":14,"end":16,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":4}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":15,"end":16,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":4},"identifierName":"a"}, | ||
"name": "a" | ||
} | ||
}, | ||
"value": null | ||
}, | ||
{ | ||
"type": "ClassPrivateProperty", | ||
"start":20,"end":23,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":5}}, | ||
"static": false, | ||
"key": { | ||
"type": "PrivateName", | ||
"start":20,"end":22,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":4}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":21,"end":22,"loc":{"start":{"line":3,"column":3},"end":{"line":3,"column":4},"identifierName":"b"}, | ||
"name": "b" | ||
} | ||
}, | ||
"value": null | ||
}, | ||
{ | ||
"type": "ClassMethod", | ||
"start":26,"end":58,"loc":{"start":{"line":4,"column":2},"end":{"line":6,"column":3}}, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":26,"end":32,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":8},"identifierName":"method"}, | ||
"name": "method" | ||
}, | ||
"computed": false, | ||
"kind": "method", | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":35,"end":58,"loc":{"start":{"line":4,"column":11},"end":{"line":6,"column":3}}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":41,"end":54,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":17}}, | ||
"expression": { | ||
"type": "BinaryExpression", | ||
"start":41,"end":54,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":17}}, | ||
"left": { | ||
"type": "BinaryExpression", | ||
"start":41,"end":49,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":12}}, | ||
"left": { | ||
"type": "PrivateName", | ||
"start":41,"end":43,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":6}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":42,"end":43,"loc":{"start":{"line":5,"column":5},"end":{"line":5,"column":6},"identifierName":"a"}, | ||
"name": "a" | ||
} | ||
}, | ||
"operator": "in", | ||
"right": { | ||
"type": "PrivateName", | ||
"start":47,"end":49,"loc":{"start":{"line":5,"column":10},"end":{"line":5,"column":12}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":48,"end":49,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":12},"identifierName":"b"}, | ||
"name": "b" | ||
} | ||
} | ||
}, | ||
"operator": "in", | ||
"right": { | ||
"type": "Identifier", | ||
"start":53,"end":54,"loc":{"start":{"line":5,"column":16},"end":{"line":5,"column":17},"identifierName":"c"}, | ||
"name": "c" | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...el-parser/test/fixtures/experimental/private-in/invalid-private-followed-by-in-2/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Foo { | ||
#a; | ||
method() { | ||
1 + #a in b | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
...parser/test/fixtures/experimental/private-in/invalid-private-followed-by-in-2/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":52,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: Private names are only allowed in property accesses (`obj.#a`) or in `in` expressions (`#a in obj`). (4:8)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":52,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":52,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":10,"end":52,"loc":{"start":{"line":1,"column":10},"end":{"line":6,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassPrivateProperty", | ||
"start":14,"end":17,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":5}}, | ||
"static": false, | ||
"key": { | ||
"type": "PrivateName", | ||
"start":14,"end":16,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":4}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":15,"end":16,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":4},"identifierName":"a"}, | ||
"name": "a" | ||
} | ||
}, | ||
"value": null | ||
}, | ||
{ | ||
"type": "ClassMethod", | ||
"start":20,"end":50,"loc":{"start":{"line":3,"column":2},"end":{"line":5,"column":3}}, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":20,"end":26,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":8},"identifierName":"method"}, | ||
"name": "method" | ||
}, | ||
"computed": false, | ||
"kind": "method", | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":29,"end":50,"loc":{"start":{"line":3,"column":11},"end":{"line":5,"column":3}}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":35,"end":46,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":15}}, | ||
"expression": { | ||
"type": "BinaryExpression", | ||
"start":35,"end":46,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":15}}, | ||
"left": { | ||
"type": "BinaryExpression", | ||
"start":35,"end":41,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":10}}, | ||
"left": { | ||
"type": "NumericLiteral", | ||
"start":35,"end":36,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":5}}, | ||
"extra": { | ||
"rawValue": 1, | ||
"raw": "1" | ||
}, | ||
"value": 1 | ||
}, | ||
"operator": "+", | ||
"right": { | ||
"type": "PrivateName", | ||
"start":39,"end":41,"loc":{"start":{"line":4,"column":8},"end":{"line":4,"column":10}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":40,"end":41,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":10},"identifierName":"a"}, | ||
"name": "a" | ||
} | ||
} | ||
}, | ||
"operator": "in", | ||
"right": { | ||
"type": "Identifier", | ||
"start":45,"end":46,"loc":{"start":{"line":4,"column":14},"end":{"line":4,"column":15},"identifierName":"b"}, | ||
"name": "b" | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...el-parser/test/fixtures/experimental/private-in/invalid-private-followed-by-in-3/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Foo { | ||
#a; | ||
|
||
method() { | ||
for (var x = #a in y); | ||
} | ||
} |
Oops, something went wrong.