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

Allow await when it is not in AsyncArrowHead #11148

Conversation

arku
Copy link
Contributor

@arku arku commented Feb 16, 2020

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

This PR fixes the parser error thrown for the input (await) => {}. I tried to fix the other cases mentioned in the issue description and after struggling with delaying the await position check in case of async call expressions, I reached out to @JLHwung for help. He added that the delay check is indeed difficult and it is best to refactor the await position tracking with a scope based recording mechanism that is non-trivial.

@arku arku force-pushed the fix/async-identifiers-outside-async-functions branch from eda041d to 19aa381 Compare February 17, 2020 01:56
@nicolo-ribaudo nicolo-ribaudo added pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Feb 17, 2020
@arku arku force-pushed the fix/async-identifiers-outside-async-functions branch from 19aa381 to 99c07ae Compare March 10, 2020 03:46
@arku arku marked this pull request as ready for review March 10, 2020 03:46
@@ -59,6 +59,7 @@ export default class State {
// Flags to track
inParameters: boolean = false;
maybeInArrowParameters: boolean = false;
maybeInAsyncArrowHead: boolean = false;
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear to me what the difference between these two flags should be. Isn't the arrow head its parameters?

Copy link
Contributor

Choose a reason for hiding this comment

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

The maybeInAsyncArrowHead lives across function declarations.

async (foo = function (await) {}) => {}

When parsing await, maybeInAsyncArrowHead is true but maybeInArrowParameters is false.

Copy link
Member

Choose a reason for hiding this comment

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

We should add a comment in the code explaining it 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolo-ribaudo Done. Let me know if we can make it better.

@arku arku force-pushed the fix/async-identifiers-outside-async-functions branch 2 times, most recently from 0964918 to bc35c6a Compare March 11, 2020 17:28
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.

The CI failures don't seem to be related to this PR.

Comment on lines 564 to 566
if (state.maybeAsyncArrow) {
this.state.maybeInAsyncArrowHead = state.maybeAsyncArrow;
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: inside the if state.maybeAsyncArrow is always true.

Suggested change
if (state.maybeAsyncArrow) {
this.state.maybeInAsyncArrowHead = state.maybeAsyncArrow;
}
if (state.maybeAsyncArrow) this.state.maybeInAsyncArrowHead = true;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolo-ribaudo Ah, yeah. Just updated the PR.

@arku arku force-pushed the fix/async-identifiers-outside-async-functions branch from bc35c6a to 2d07de2 Compare March 15, 2020 22:48
@arku arku force-pushed the fix/async-identifiers-outside-async-functions branch from 2d07de2 to cc7cc42 Compare March 15, 2020 22:50
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!

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.

Await parsing is tricky. We should definitely revisit it later. @arku Thanks!

@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 Jun 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 2020
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.

await should be allowed when it is not in AsyncArrowHead
3 participants