Skip to content
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

Implement async-do-expressions transform #13117

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Apr 7, 2021

Q                       A
Fixed Issues? Implement Async Do Expressions transform
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

The transform is derived from

export function replaceExpressionWithStatements(

with changes listed below:

  • No toSequenceExpression call, an async arrow closure is always created
  • No support of completion records in loop. The do expression proposal has forbidden such productions: https://tc39.es/proposal-do-expressions/#sec-EndsInIterationOrBareIfOrDeclaration We should address that in @babel/parser.
  • No generator support: The proposal forbids yield within the async do block
  • Compiles to (async) arrow function

I avoided extending NodePath#replaceExpressionWithStatements because of the differences mentioned above and the hazard of breaking other plugins.

Additional Context
When working on this PR, I realize that

this.traverse(hoistVariablesVisitor);
is a no-op because the traverse stops at the function closure wrapping the do block, which means Babel does not hoist variable declarations defined in do block. I will fix that in another PR (#13122).

/cc @bakkot

@JLHwung JLHwung added PR: New Feature 🚀 A type of pull request used for our changelog categories Spec: Async do expressions labels Apr 7, 2021
@JLHwung JLHwung force-pushed the proposal-async-do-expressions branch from a916a70 to b1319f1 Compare April 7, 2021 17:53
@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 7, 2021

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 e03a570:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@babel-bot
Copy link
Collaborator

babel-bot commented Apr 7, 2021

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/45101/

@JLHwung JLHwung mentioned this pull request Apr 7, 2021
2 tasks
@JLHwung JLHwung force-pushed the proposal-async-do-expressions branch from ceee6d0 to e03a570 Compare April 7, 2021 18:49
Copy link
Member

@hzoo hzoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glad implementation seems pretty straightforward! I guess we aren't linking to the proposal repo other than on website?

@nicolo-ribaudo
Copy link
Member

Merging to feat-7.14.0/async-do-expressions.

@JLHwung Could you open a website PR adding a page for this plugin?

@nicolo-ribaudo nicolo-ribaudo merged commit 9c923a8 into babel:feat-7.14.0/async-do-expressions Apr 12, 2021
@nicolo-ribaudo nicolo-ribaudo deleted the proposal-async-do-expressions branch April 12, 2021 14:00
nicolo-ribaudo pushed a commit that referenced this pull request Apr 12, 2021
Co-authored-by: Brian Ng <bng412@gmail.com>
nicolo-ribaudo pushed a commit that referenced this pull request Apr 20, 2021
Co-authored-by: Brian Ng <bng412@gmail.com>
nicolo-ribaudo pushed a commit that referenced this pull request Apr 28, 2021
Co-authored-by: Brian Ng <bng412@gmail.com>
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 13, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: New Feature 🚀 A type of pull request used for our changelog categories Spec: Async do expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants