Parse async do expressions#13043
Parse async do expressions#13043JLHwung merged 13 commits intobabel:feat-7.14.0/async-do-expressionsfrom
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 652f932:
|
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/45060/ |
19284d2 to
9bddd9e
Compare
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
Can you add a test for a statement starting with async do? They are different from sync do expressions because async ones don't have the do-while ambiguity.
And also one with a line break between async and do in a statement position.
| const { node } = path; | ||
| if (node.async) { | ||
| // Async do expressions are not yet supported | ||
| return; |
There was a problem hiding this comment.
Nit: path.buildCodeFrameError?
There was a problem hiding this comment.
I lean to skip these paths otherwise if we support them in proposal-async-do-expressions, the error here will impose a restriction that proposal-async-do-expressions must run before proposal-do-expressions.
We have similar approach on skipping for await of in for-of transform:
babel/packages/babel-plugin-transform-for-of/src/index.js
Lines 58 to 60 in 16d8300
| ) { | ||
| throw new Error( | ||
| "'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.", | ||
| ); |
There was a problem hiding this comment.
If we add .missingPlugin = ["doExpressions"] to the error (similarly to what expectPlugin does), @babel/core will suggest adding plugin-proposal-do-expressions to the config.
71918f6 to
dd438d0
Compare
| @@ -0,0 +1,3 @@ | |||
| /* leading comments | |||
| */(async do | |||
| {1;}) + 0; No newline at end of file | |||
There was a problem hiding this comment.
I don't think we will need parentheses here.
63bac69 to
5aab1a9
Compare
5aab1a9 to
652f932
Compare
|
Merged to |
* parse async do expressions * add test cases * update test fixtures * chore: add syntax-async-do-expressions * generater support * fix: do not transform async do expressions * chore: add asyncDoExpressions to missing plugin helpers * update ast types * add more test cases * throw when asyncDoExpressions is enabled but not doExpressions * avoid add parentheses for async do expressions * address review comments * chore: update parser typings
* parse async do expressions * add test cases * update test fixtures * chore: add syntax-async-do-expressions * generater support * fix: do not transform async do expressions * chore: add asyncDoExpressions to missing plugin helpers * update ast types * add more test cases * throw when asyncDoExpressions is enabled but not doExpressions * avoid add parentheses for async do expressions * address review comments * chore: update parser typings
* parse async do expressions * add test cases * update test fixtures * chore: add syntax-async-do-expressions * generater support * fix: do not transform async do expressions * chore: add asyncDoExpressions to missing plugin helpers * update ast types * add more test cases * throw when asyncDoExpressions is enabled but not doExpressions * avoid add parentheses for async do expressions * address review comments * chore: update parser typings
The AST design follows ESTree async do expressions experimental proposal.
For parsing, a new parser plugin
asyncDoExpressionsis introduced. Since the ECMA proposal is built off on Do Expressions, parsing an async do expressions(async do {})requires both parser plugindoExpressionsandasyncDoExpressions.We also skip async do expressions on
proposal-do-expressionssince it is not supported yet. The transform support will be landed in later PRs.