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

This comment has been minimized.

Copy link
Collaborator

babel-bot commented Oct 8, 2018

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

1 similar comment
@babel-bot

This comment has been minimized.

Copy link
Collaborator

babel-bot commented Oct 8, 2018

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

Copy link
Member

nicolo-ribaudo left a comment

async
(x) => {}

Already works?

@Retsam

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

nicolo-ribaudo commented Oct 9, 2018

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

nicolo-ribaudo commented Oct 9, 2018

Oh ok 👍

@nicolo-ribaudo nicolo-ribaudo merged commit d2c75c2 into babel:master Oct 9, 2018
4 checks passed
4 checks passed
babel/repl REPL preview is available
Details
ci/circleci Your tests passed on CircleCI!
Details
codecov/project 80.58% (target 80%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@pvdz

This comment has been minimized.

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 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.
Projects
None yet
5 participants
You can’t perform that action at this time.