Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Raise recoverable error for await expressions in sync functions (#12520)
- Loading branch information
1 parent
d98418e
commit 8fcba6e
Showing
24 changed files
with
726 additions
and
59 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: 0 additions & 3 deletions
3
packages/babel-parser/test/fixtures/es2017/async-functions/9/options.json
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
packages/babel-parser/test/fixtures/es2017/async-functions/9/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,54 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}}, | ||
"errors": [ | ||
"SyntaxError: 'await' is only allowed within async functions (1:24)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "FunctionDeclaration", | ||
"start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12},"identifierName":"foo"}, | ||
"name": "foo" | ||
}, | ||
"generator": false, | ||
"async": false, | ||
"params": [ | ||
{ | ||
"type": "Identifier", | ||
"start":13,"end":20,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":20},"identifierName":"promise"}, | ||
"name": "promise" | ||
} | ||
], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":22,"end":40,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":40}}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":24,"end":38,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":38}}, | ||
"expression": { | ||
"type": "AwaitExpression", | ||
"start":24,"end":37,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":37}}, | ||
"argument": { | ||
"type": "Identifier", | ||
"start":30,"end":37,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":37},"identifierName":"promise"}, | ||
"name": "promise" | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
4 changes: 0 additions & 4 deletions
4
...rser/test/fixtures/es2017/async-functions/allow-await-outside-function-throw/options.json
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
...arser/test/fixtures/es2017/async-functions/allow-await-outside-function-throw/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,52 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"errors": [ | ||
"SyntaxError: 'await' is only allowed within async functions (2:9)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "FunctionDeclaration", | ||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10},"identifierName":"a"}, | ||
"name": "a" | ||
}, | ||
"generator": false, | ||
"async": false, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":13,"end":33,"loc":{"start":{"line":1,"column":13},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ReturnStatement", | ||
"start":17,"end":31,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":16}}, | ||
"argument": { | ||
"type": "AwaitExpression", | ||
"start":24,"end":31,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":16}}, | ||
"argument": { | ||
"type": "NumericLiteral", | ||
"start":30,"end":31,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":16}}, | ||
"extra": { | ||
"rawValue": 1, | ||
"raw": "1" | ||
}, | ||
"value": 1 | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...est/fixtures/es2017/async-functions/await-identifier-with-line-break-in-function/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,4 @@ | ||
function foo() { | ||
await | ||
foo; | ||
} |
50 changes: 50 additions & 0 deletions
50
.../fixtures/es2017/async-functions/await-identifier-with-line-break-in-function/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,50 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "FunctionDeclaration", | ||
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12},"identifierName":"foo"}, | ||
"name": "foo" | ||
}, | ||
"generator": false, | ||
"async": false, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":15,"end":33,"loc":{"start":{"line":1,"column":15},"end":{"line":4,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":19,"end":24,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":7}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":19,"end":24,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":7},"identifierName":"await"}, | ||
"name": "await" | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":27,"end":31,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":6}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":27,"end":30,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":5},"identifierName":"foo"}, | ||
"name": "foo" | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
...est/fixtures/es2017/async-functions/await-inside-arrow-expression-disallowed/options.json
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
...test/fixtures/es2017/async-functions/await-inside-arrow-expression-disallowed/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,48 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}}, | ||
"errors": [ | ||
"SyntaxError: 'await' is only allowed within async functions (1:8)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}}, | ||
"expression": { | ||
"type": "ArrowFunctionExpression", | ||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}}, | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":6,"end":17,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":17}}, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":8,"end":15,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":15}}, | ||
"expression": { | ||
"type": "AwaitExpression", | ||
"start":8,"end":15,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":15}}, | ||
"argument": { | ||
"type": "Identifier", | ||
"start":14,"end":15,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":15},"identifierName":"x"}, | ||
"name": "x" | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
...tures/es2017/async-functions/await-inside-parameters-of-async-arrow-function/options.json
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.