Fix top-level await parsing (#38483) #38517
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The previous implementation wasn't able to handle case like
await (async () => {})
outside of "async" functions.One problem is that the syntax can be exactly the same for two usecases:
Use case 1
An await expression on the self-calling async function
Use case 2
A call to the function returned by a call to the "await" user defined function with the
async () => {}
argument.We have no way to know which case we want to handle. This pull request handles Use case 2 first. If there is some identifier named "await" defined, we make this statement a function call, otherwise, we make it an await expression.
I can update this PR if someone has a better idea to handle this ambiguous case.
Fixes #38483