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
Confusing error when using await in non-async function #9799
Comments
This comment might help with improving this: #9084 (comment) |
All parsers throw similar errors
I think there is nothing we can do, unless parsers improve it. |
Specifically Babel can throw "'await' is only allowed within async functions", but it somehow trickily depends on its configuration. |
You are right require('@babel/parser').parse('function foo () {await bar();}', {sourceType: 'module'})
Uncaught [SyntaxError: 'await' is only allowed within async functions (1:17)
] {
loc: Position { line: 1, column: 17 },
pos: 17
} |
require('@babel/parser').parse('function foo () {await bar();}', {sourceType: 'module', errorRecovery: true})
Uncaught [SyntaxError: Unexpected token, expected ";" (1:23)
] {
loc: Position { line: 1, column: 23 },
pos: 23
} |
Filed an issue on babel babel/babel#12436 |
Fixed by #10345 |
Prettier 2.2.1
Playground link
Input:
Output:
Expected behavior:
Honestly, this error message makes no sense.
Perhaps a more relevant message would be:
The text was updated successfully, but these errors were encountered: