Visitar URL original
Parse `for await (async of ...)` by Zalathar · Pull Request #13244 · babel/babel · GitHub
Skip to content

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

Merged
nicolo-ribaudo merged 7 commits into
babel:mainfrom
Zalathar:async-arrow-lookahead
May 1, 2021
Merged

nicolo-ribaudo merged 7 commits into
babel:mainfrom
Zalathar:async-arrow-lookahead

Conversation

@Zalathar

@Zalathar Zalathar commented May 1, 2021 •

Copy link
Copy Markdown
Contributor
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

babel-bot commented May 1, 2021 •

Copy link
Copy Markdown
Collaborator

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

@codesandbox-ci

codesandbox-ci Bot commented May 1, 2021 •

Copy link
Copy Markdown

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

Comment thread packages/babel-parser/src/parser/statement.js Outdated
@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label May 1, 2021
@Zalathar

Zalathar commented May 1, 2021

Copy link
Copy Markdown
Contributor Author

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/.

@Zalathar
Zalathar force-pushed the async-arrow-lookahead branch from 2479882 to 3890721 Compare May 1, 2021 14:45
@JLHwung

JLHwung commented May 1, 2021

Copy link
Copy Markdown
Contributor

@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.

@JLHwung JLHwung left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome!

@Zalathar
Zalathar force-pushed the async-arrow-lookahead branch from 3890721 to cc7e470 Compare May 1, 2021 14:58

@nicolo-ribaudo nicolo-ribaudo left a comment

Copy link
Copy Markdown
Member

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