Skip to content

Commit

Permalink
fix: allow await within SCOPE_FUNCTION under static block
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Apr 1, 2021
1 parent ddca830 commit ce0c08f
Show file tree
Hide file tree
Showing 13 changed files with 790 additions and 487 deletions.
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/expression.js
Expand Up @@ -2350,7 +2350,7 @@ export default class ExpressionParser extends LValParser {
if (this.prodParam.hasAwait) {
this.raise(startLoc, Errors.AwaitBindingIdentifier);
return;
} else if (this.scope.inStaticBlock && !this.scope.inNonArrowFunction) {
} else if (this.scope.inStaticBlock && !this.scope.inFunction) {
this.raise(startLoc, Errors.AwaitBindingIdentifierInStaticBlock);
return;
} else {
Expand Down
@@ -0,0 +1,9 @@
var C;

C = class { static { () => await } };

C = class { static { (await) => {} } };

C = class { static { (x = await) => {} } };

C = class { static { ({ [await]: x }) => {} } };
@@ -0,0 +1,279 @@
{
"type": "File",
"start":0,"end":181,"loc":{"start":{"line":1,"column":0},"end":{"line":9,"column":48}},
"errors": [
"SyntaxError: Can not use 'await' as identifier inside a static block (5:22)",
"SyntaxError: Can not use 'await' as identifier inside a static block (7:26)",
"SyntaxError: Can not use 'await' as identifier inside a static block (9:25)"
],
"program": {
"type": "Program",
"start":0,"end":181,"loc":{"start":{"line":1,"column":0},"end":{"line":9,"column":48}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}},
"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":8,"end":45,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":37}},
"expression": {
"type": "AssignmentExpression",
"start":8,"end":44,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":36}},
"operator": "=",
"left": {
"type": "Identifier",
"start":8,"end":9,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":1},"identifierName":"C"},
"name": "C"
},
"right": {
"type": "ClassExpression",
"start":12,"end":44,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":36}},
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start":18,"end":44,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":36}},
"body": [
{
"type": "StaticBlock",
"start":20,"end":42,"loc":{"start":{"line":3,"column":12},"end":{"line":3,"column":34}},
"body": [
{
"type": "ExpressionStatement",
"start":29,"end":40,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":32}},
"expression": {
"type": "ArrowFunctionExpression",
"start":29,"end":40,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":32}},
"id": null,
"generator": false,
"async": false,
"params": [],
"body": {
"type": "Identifier",
"start":35,"end":40,"loc":{"start":{"line":3,"column":27},"end":{"line":3,"column":32},"identifierName":"await"},
"name": "await"
}
}
}
]
}
]
}
}
}
},
{
"type": "ExpressionStatement",
"start":47,"end":86,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":39}},
"expression": {
"type": "AssignmentExpression",
"start":47,"end":85,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":38}},
"operator": "=",
"left": {
"type": "Identifier",
"start":47,"end":48,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":1},"identifierName":"C"},
"name": "C"
},
"right": {
"type": "ClassExpression",
"start":51,"end":85,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":38}},
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start":57,"end":85,"loc":{"start":{"line":5,"column":10},"end":{"line":5,"column":38}},
"body": [
{
"type": "StaticBlock",
"start":59,"end":83,"loc":{"start":{"line":5,"column":12},"end":{"line":5,"column":36}},
"body": [
{
"type": "ExpressionStatement",
"start":68,"end":81,"loc":{"start":{"line":5,"column":21},"end":{"line":5,"column":34}},
"expression": {
"type": "ArrowFunctionExpression",
"start":68,"end":81,"loc":{"start":{"line":5,"column":21},"end":{"line":5,"column":34}},
"id": null,
"generator": false,
"async": false,
"params": [
{
"type": "Identifier",
"start":69,"end":74,"loc":{"start":{"line":5,"column":22},"end":{"line":5,"column":27},"identifierName":"await"},
"name": "await"
}
],
"body": {
"type": "BlockStatement",
"start":79,"end":81,"loc":{"start":{"line":5,"column":32},"end":{"line":5,"column":34}},
"body": [],
"directives": []
}
}
}
]
}
]
}
}
}
},
{
"type": "ExpressionStatement",
"start":88,"end":131,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":43}},
"expression": {
"type": "AssignmentExpression",
"start":88,"end":130,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":42}},
"operator": "=",
"left": {
"type": "Identifier",
"start":88,"end":89,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":1},"identifierName":"C"},
"name": "C"
},
"right": {
"type": "ClassExpression",
"start":92,"end":130,"loc":{"start":{"line":7,"column":4},"end":{"line":7,"column":42}},
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start":98,"end":130,"loc":{"start":{"line":7,"column":10},"end":{"line":7,"column":42}},
"body": [
{
"type": "StaticBlock",
"start":100,"end":128,"loc":{"start":{"line":7,"column":12},"end":{"line":7,"column":40}},
"body": [
{
"type": "ExpressionStatement",
"start":109,"end":126,"loc":{"start":{"line":7,"column":21},"end":{"line":7,"column":38}},
"expression": {
"type": "ArrowFunctionExpression",
"start":109,"end":126,"loc":{"start":{"line":7,"column":21},"end":{"line":7,"column":38}},
"id": null,
"generator": false,
"async": false,
"params": [
{
"type": "AssignmentPattern",
"start":110,"end":119,"loc":{"start":{"line":7,"column":22},"end":{"line":7,"column":31}},
"left": {
"type": "Identifier",
"start":110,"end":111,"loc":{"start":{"line":7,"column":22},"end":{"line":7,"column":23},"identifierName":"x"},
"name": "x"
},
"right": {
"type": "Identifier",
"start":114,"end":119,"loc":{"start":{"line":7,"column":26},"end":{"line":7,"column":31},"identifierName":"await"},
"name": "await"
}
}
],
"body": {
"type": "BlockStatement",
"start":124,"end":126,"loc":{"start":{"line":7,"column":36},"end":{"line":7,"column":38}},
"body": [],
"directives": []
}
}
}
]
}
]
}
}
}
},
{
"type": "ExpressionStatement",
"start":133,"end":181,"loc":{"start":{"line":9,"column":0},"end":{"line":9,"column":48}},
"expression": {
"type": "AssignmentExpression",
"start":133,"end":180,"loc":{"start":{"line":9,"column":0},"end":{"line":9,"column":47}},
"operator": "=",
"left": {
"type": "Identifier",
"start":133,"end":134,"loc":{"start":{"line":9,"column":0},"end":{"line":9,"column":1},"identifierName":"C"},
"name": "C"
},
"right": {
"type": "ClassExpression",
"start":137,"end":180,"loc":{"start":{"line":9,"column":4},"end":{"line":9,"column":47}},
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start":143,"end":180,"loc":{"start":{"line":9,"column":10},"end":{"line":9,"column":47}},
"body": [
{
"type": "StaticBlock",
"start":145,"end":178,"loc":{"start":{"line":9,"column":12},"end":{"line":9,"column":45}},
"body": [
{
"type": "ExpressionStatement",
"start":154,"end":176,"loc":{"start":{"line":9,"column":21},"end":{"line":9,"column":43}},
"expression": {
"type": "ArrowFunctionExpression",
"start":154,"end":176,"loc":{"start":{"line":9,"column":21},"end":{"line":9,"column":43}},
"id": null,
"generator": false,
"async": false,
"params": [
{
"type": "ObjectPattern",
"start":155,"end":169,"loc":{"start":{"line":9,"column":22},"end":{"line":9,"column":36}},
"properties": [
{
"type": "ObjectProperty",
"start":157,"end":167,"loc":{"start":{"line":9,"column":24},"end":{"line":9,"column":34}},
"method": false,
"computed": true,
"key": {
"type": "Identifier",
"start":158,"end":163,"loc":{"start":{"line":9,"column":25},"end":{"line":9,"column":30},"identifierName":"await"},
"name": "await"
},
"shorthand": false,
"value": {
"type": "Identifier",
"start":166,"end":167,"loc":{"start":{"line":9,"column":33},"end":{"line":9,"column":34},"identifierName":"x"},
"name": "x"
}
}
]
}
],
"body": {
"type": "BlockStatement",
"start":174,"end":176,"loc":{"start":{"line":9,"column":41},"end":{"line":9,"column":43}},
"body": [],
"directives": []
}
}
}
]
}
]
}
}
}
}
],
"directives": []
}
}
@@ -0,0 +1,7 @@
var C;

C = class { static { async (await) => {} } };

C = class { static { async (x = await) => {} } };

C = class { static { async ({ [await]: x }) => {} } };

0 comments on commit ce0c08f

Please sign in to comment.