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

Parse for await (async of ...) #13244

Merged
merged 7 commits into from May 1, 2021

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented May 1, 2021

Q                       A
Fixed Issues? Fixes #13235
Patch: Bug Fix? Yes
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes? No
License MIT

This allows the parser to correctly parse for await (async of []); by implementing the suggestion given by @JLHwung in #13235 (comment).

When the expression parser sees async of, it will peek ahead for a = character before it commits to parsing an async arrow function.

On its own this would also cause for (async of []); to parse, which is forbidden, so we also add explicit code to the for parser to detect and reject for-of statements that begin with async of.

@babel-bot
Copy link
Collaborator

babel-bot commented May 1, 2021

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 1, 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 cc7e470:

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

@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label May 1, 2021
@Zalathar
Copy link
Contributor Author

Zalathar commented May 1, 2021

Is there any particular place I should be putting these parser tests? I wasn't sure if I should put them in es2015/for-of/.

@JLHwung
Copy link
Contributor

JLHwung commented May 1, 2021

@Zalathar The for(async of tests can be placed in es2021, resulted from a need-Consensus PR: tc39/ecma262#2256

The for await(async of tests can be placed in es2018/async-generators. The syntax hasn't changed since then.

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

Awesome!

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Thanks!

@nicolo-ribaudo nicolo-ribaudo changed the title Parse for await (async of by adding lookahead to unary async arrow parsing Parse for await (async of ...) May 1, 2021
@nicolo-ribaudo nicolo-ribaudo merged commit fa01fbe into babel:main May 1, 2021
@Zalathar Zalathar deleted the async-arrow-lookahead branch May 1, 2021 16:11
@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 Aug 1, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 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: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Parser can't parse "for await (async of []);"
4 participants