New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse async do expressions #13043
Parse async do expressions #13043
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: path.buildCodeFrameError
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
if (isAwait) { | |
return; | |
} |
) { | ||
throw new Error( | ||
"'asyncDoExpressions' requires 'doExpressions', please add 'doExpressions' to parser plugins.", | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
asyncDoExpressions
is introduced. Since the ECMA proposal is built off on Do Expressions, parsing an async do expressions(async do {})
requires both parser plugindoExpressions
andasyncDoExpressions
.We also skip async do expressions on
proposal-do-expressions
since it is not supported yet. The transform support will be landed in later PRs.