Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix await binding error within static block (#13088)
* fix: allow await within SCOPE_FUNCTION under static block * perf: scan scopeStack for once * add new test case * chore: update allowlist
- Loading branch information
Showing
15 changed files
with
1,091 additions
and
400 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
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
3 changes: 3 additions & 0 deletions
3
...rimental/class-static-block/await-binding-in-arrow-function-in-static-block copy/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,3 @@ | ||
var C; | ||
// await in body is allowed | ||
C = class { static { () => await } }; |
100 changes: 100 additions & 0 deletions
100
...ental/class-static-block/await-binding-in-arrow-function-in-static-block copy/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,100 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":72,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":37}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":72,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":37}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "VariableDeclaration", | ||
"start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}}, | ||
"trailingComments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " await in body is allowed", | ||
"start":7,"end":34,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":27}} | ||
} | ||
], | ||
"declarations": [ | ||
{ | ||
"type": "VariableDeclarator", | ||
"start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"C"}, | ||
"name": "C" | ||
}, | ||
"init": null | ||
} | ||
], | ||
"kind": "var" | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":35,"end":72,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":37}}, | ||
"leadingComments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " await in body is allowed", | ||
"start":7,"end":34,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":27}} | ||
} | ||
], | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":35,"end":71,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":36}}, | ||
"operator": "=", | ||
"left": { | ||
"type": "Identifier", | ||
"start":35,"end":36,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":1},"identifierName":"C"}, | ||
"name": "C" | ||
}, | ||
"right": { | ||
"type": "ClassExpression", | ||
"start":39,"end":71,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":36}}, | ||
"id": null, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":45,"end":71,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":36}}, | ||
"body": [ | ||
{ | ||
"type": "StaticBlock", | ||
"start":47,"end":69,"loc":{"start":{"line":3,"column":12},"end":{"line":3,"column":34}}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":56,"end":67,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":32}}, | ||
"expression": { | ||
"type": "ArrowFunctionExpression", | ||
"start":56,"end":67,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":32}}, | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [], | ||
"body": { | ||
"type": "Identifier", | ||
"start":62,"end":67,"loc":{"start":{"line":3,"column":27},"end":{"line":3,"column":32},"identifierName":"await"}, | ||
"name": "await" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
}, | ||
"comments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " await in body is allowed", | ||
"start":7,"end":34,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":27}} | ||
} | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
...imental/class-static-block/await-binding-in-async-arrow-function-in-static-block/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 @@ | ||
var C; | ||
// await is not allowed in async arrow | ||
C = class { static { async (await) => {} } }; | ||
|
||
C = class { static { async (x = await) => {} } }; | ||
|
||
C = class { static { async ({ [await]: x }) => {} } }; |
251 changes: 251 additions & 0 deletions
251
...ntal/class-static-block/await-binding-in-async-arrow-function-in-static-block/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,251 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":198,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":54}}, | ||
"errors": [ | ||
"SyntaxError: Can not use 'await' as identifier inside a static block. (3:28)", | ||
"SyntaxError: Can not use 'await' as identifier inside a static block. (5:32)", | ||
"SyntaxError: Can not use 'await' as identifier inside a static block. (7:31)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":198,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":54}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "VariableDeclaration", | ||
"start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}}, | ||
"trailingComments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " await is not allowed in async arrow", | ||
"start":7,"end":45,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":38}} | ||
} | ||
], | ||
"declarations": [ | ||
{ | ||
"type": "VariableDeclarator", | ||
"start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"C"}, | ||
"name": "C" | ||
}, | ||
"init": null | ||
} | ||
], | ||
"kind": "var" | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":46,"end":91,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":45}}, | ||
"leadingComments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " await is not allowed in async arrow", | ||
"start":7,"end":45,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":38}} | ||
} | ||
], | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":46,"end":90,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":44}}, | ||
"operator": "=", | ||
"left": { | ||
"type": "Identifier", | ||
"start":46,"end":47,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":1},"identifierName":"C"}, | ||
"name": "C" | ||
}, | ||
"right": { | ||
"type": "ClassExpression", | ||
"start":50,"end":90,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":44}}, | ||
"id": null, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":56,"end":90,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":44}}, | ||
"body": [ | ||
{ | ||
"type": "StaticBlock", | ||
"start":58,"end":88,"loc":{"start":{"line":3,"column":12},"end":{"line":3,"column":42}}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":67,"end":86,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":40}}, | ||
"expression": { | ||
"type": "ArrowFunctionExpression", | ||
"start":67,"end":86,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":40}}, | ||
"id": null, | ||
"generator": false, | ||
"async": true, | ||
"params": [ | ||
{ | ||
"type": "Identifier", | ||
"start":74,"end":79,"loc":{"start":{"line":3,"column":28},"end":{"line":3,"column":33},"identifierName":"await"}, | ||
"name": "await" | ||
} | ||
], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":84,"end":86,"loc":{"start":{"line":3,"column":38},"end":{"line":3,"column":40}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":93,"end":142,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":49}}, | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":93,"end":141,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":48}}, | ||
"operator": "=", | ||
"left": { | ||
"type": "Identifier", | ||
"start":93,"end":94,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":1},"identifierName":"C"}, | ||
"name": "C" | ||
}, | ||
"right": { | ||
"type": "ClassExpression", | ||
"start":97,"end":141,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":48}}, | ||
"id": null, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":103,"end":141,"loc":{"start":{"line":5,"column":10},"end":{"line":5,"column":48}}, | ||
"body": [ | ||
{ | ||
"type": "StaticBlock", | ||
"start":105,"end":139,"loc":{"start":{"line":5,"column":12},"end":{"line":5,"column":46}}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":114,"end":137,"loc":{"start":{"line":5,"column":21},"end":{"line":5,"column":44}}, | ||
"expression": { | ||
"type": "ArrowFunctionExpression", | ||
"start":114,"end":137,"loc":{"start":{"line":5,"column":21},"end":{"line":5,"column":44}}, | ||
"id": null, | ||
"generator": false, | ||
"async": true, | ||
"params": [ | ||
{ | ||
"type": "AssignmentPattern", | ||
"start":121,"end":130,"loc":{"start":{"line":5,"column":28},"end":{"line":5,"column":37}}, | ||
"left": { | ||
"type": "Identifier", | ||
"start":121,"end":122,"loc":{"start":{"line":5,"column":28},"end":{"line":5,"column":29},"identifierName":"x"}, | ||
"name": "x" | ||
}, | ||
"right": { | ||
"type": "Identifier", | ||
"start":125,"end":130,"loc":{"start":{"line":5,"column":32},"end":{"line":5,"column":37},"identifierName":"await"}, | ||
"name": "await" | ||
} | ||
} | ||
], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":135,"end":137,"loc":{"start":{"line":5,"column":42},"end":{"line":5,"column":44}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":144,"end":198,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":54}}, | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":144,"end":197,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":53}}, | ||
"operator": "=", | ||
"left": { | ||
"type": "Identifier", | ||
"start":144,"end":145,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":1},"identifierName":"C"}, | ||
"name": "C" | ||
}, | ||
"right": { | ||
"type": "ClassExpression", | ||
"start":148,"end":197,"loc":{"start":{"line":7,"column":4},"end":{"line":7,"column":53}}, | ||
"id": null, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":154,"end":197,"loc":{"start":{"line":7,"column":10},"end":{"line":7,"column":53}}, | ||
"body": [ | ||
{ | ||
"type": "StaticBlock", | ||
"start":156,"end":195,"loc":{"start":{"line":7,"column":12},"end":{"line":7,"column":51}}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":165,"end":193,"loc":{"start":{"line":7,"column":21},"end":{"line":7,"column":49}}, | ||
"expression": { | ||
"type": "ArrowFunctionExpression", | ||
"start":165,"end":193,"loc":{"start":{"line":7,"column":21},"end":{"line":7,"column":49}}, | ||
"id": null, | ||
"generator": false, | ||
"async": true, | ||
"params": [ | ||
{ | ||
"type": "ObjectPattern", | ||
"start":172,"end":186,"loc":{"start":{"line":7,"column":28},"end":{"line":7,"column":42}}, | ||
"properties": [ | ||
{ | ||
"type": "ObjectProperty", | ||
"start":174,"end":184,"loc":{"start":{"line":7,"column":30},"end":{"line":7,"column":40}}, | ||
"method": false, | ||
"computed": true, | ||
"key": { | ||
"type": "Identifier", | ||
"start":175,"end":180,"loc":{"start":{"line":7,"column":31},"end":{"line":7,"column":36},"identifierName":"await"}, | ||
"name": "await" | ||
}, | ||
"shorthand": false, | ||
"value": { | ||
"type": "Identifier", | ||
"start":183,"end":184,"loc":{"start":{"line":7,"column":39},"end":{"line":7,"column":40},"identifierName":"x"}, | ||
"name": "x" | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":191,"end":193,"loc":{"start":{"line":7,"column":47},"end":{"line":7,"column":49}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
}, | ||
"comments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " await is not allowed in async arrow", | ||
"start":7,"end":45,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":38}} | ||
} | ||
] | ||
} |
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
Oops, something went wrong.