-
Notifications
You must be signed in to change notification settings - Fork 656
π Confusing error for await-expression inside non-async context #2479
Comments
Hi @Boshen , could you please be more specific about what would you expect from our parser? Even though our parser shows two errors, the first one seems to be cover the illegal use of |
I'm expecting a single error, and any mention of The two error messages are understandable from the spec perspective, but from user perspective it's rather confusing. Also, the formatter breaks it into two statements just because we forgot to write |
Thank you! That makes sense now. This should be an easy fix, I think: https://github.com/rome/tools/blob/main/crates/rome_js_parser/src/syntax/expr.rs#L1377-L1380 |
I think the root cause of the issue is that await expression parsing is completely disabled in non-async context (here https://github.com/rome/tools/blob/main/crates/rome_js_parser/src/syntax/expr.rs#L1730) so |
Fixed in #3573 |
What happened?
In non-async context (Module),
await expression shows
which is super confusing, and the formatter will break it into two lines.
Expected result
acorn:
Cannot use keyword 'await' outside an async function
babel:
Unexpected reserved word 'await'.
swc:
await isn't allowed in non-async function
typescript:
'await' expressions are only allowed within async functions and at the top levels of modules.
Playground
https://play.rome.tools/?lineWidth=80&indentStyle=tab"eStyle=double&indentWidth=2&typescript=false&jsx=false&sourceType=module#ZgB1AG4AYwB0AGkAbwBuACAAZgBvAG8AKAApACAAewAKACAAIABhAHcAYQBpAHQAIABiAGEAcgA7AAoAfQA=
Code of Conduct
The text was updated successfully, but these errors were encountered: