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

Correct handling of newline after async with paren-less arrow func #8830

Merged
merged 1 commit into from
Oct 9, 2018

Conversation

Retsam
Copy link
Contributor

@Retsam Retsam commented Oct 8, 2018

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

Assuming the issue reported in #8795 is correct (I haven't read the spec, but the described behavior seems to match other parsers such as flow or typescript), then

async
x => x

should parse as two expression statements, not a single arrow function like it currently does.

…unction

If async is followed by a newline, then a paren-less arrow function should be parsed as two expressions
@babel-bot
Copy link
Collaborator

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

1 similar comment
@babel-bot
Copy link
Collaborator

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

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.

async
(x) => {}

Already works?

@existentialism existentialism added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser labels Oct 9, 2018
@Retsam
Copy link
Contributor Author

Retsam commented Oct 9, 2018

async
(x) => x

is a parse error, which seems consistent how other parsers treat it. (e.g. acorn) I'm not good enough at reading the spec to say if that's the correct behavior.

@nicolo-ribaudo
Copy link
Member

I think that it should be allowed (they are two expression statements), but you can test it in the console of a modern browser.

@Retsam
Copy link
Contributor Author

Retsam commented Oct 9, 2018

Yeah, the version with parens is a syntax error in Firefox, Chrome, and Safari. (And the paren-less version is not)

@nicolo-ribaudo
Copy link
Member

Oh ok 👍

@nicolo-ribaudo nicolo-ribaudo merged commit d2c75c2 into babel:master Oct 9, 2018
@pvdz
Copy link

pvdz commented Oct 11, 2018

Yeah the spec is a little difficult to read. Basically you're supposed to parse async( as a regular call first, in which case the newline between async and ( is fine. Then if you find an arrow, you're supposed to apply the cover grammar, which disallows the newline. If the cover grammar can't be applied the parser must consider it a syntax error.

For the paren-less case there is no cover grammar to apply as there is no ambiguity. If there's a newline there's an ASI and if there's no newline then async foo can only lead to an arrow (well, or a crash :) )

Thanks for fixing :)

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 4, 2019
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 pkg: parser 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.

Parser: async paren-less arrow with newline should throw
5 participants