[Bug]: Parser can't parse "for await (async of []);" #13235
Labels
i: bug
outdated
A closed issue/PR that is archived due to age. Recommended to make a new issue
pkg: parser
馃捇
How are you using Babel?
Programmatic API (
babel.transform
,babel.parse
)Input code
Babel REPL
Configuration file name
No response
Configuration
Current and expected behavior
Expected:
for await
statement with the identifierasync
as its left-hand-side.Actual:
Environment
Possible solution
After
for await (
not followed byvar
/let
/const
, the ECMAScript grammar requires a LeftHandExpression followed byof
.Babel instead parses an arbitrary expression, and then checks that the expression can be converted to a left-hand-side. This mostly works, except that when the next two tokens are
async of
the expression parser sees them as the start of an async arrow function with parameterof
(which is not a LeftHandExpression).The solution I currently have in mind is to explicitly look ahead for
async of
after thefor await (
, and parse the left-hand-side as an identifier instead of an expression. That will fix this edge-case, and the existing approach of parsing an expression should remain viable in all other cases for now.Additional context
#13208
prettier/prettier#10781 (review)
The text was updated successfully, but these errors were encountered: