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
Better error output for await in non-async functions #2387
Comments
+1. Too frequent issues about this case. |
@zloirock Do you have references? I can't recall any. There are a bunch of places where we could output more useful error messages for certain scenarios (but makes it much more confusing in others) but there's nothing misleading about this being an unexpected token. |
@sebmck I remember 5-10 in different chat rooms, will find in the tracker. |
+1 ran into this myself, it's pretty easy to figure out once you're accustomed to working with async/await, but it can be a pain when you're starting out |
Unexpected token implies to me that it's a missing/incorrect symbol, or a
keyword somewhere random. In other words, a syntax error.
But this isn't a syntax error. It's a semantic error. It's only unexpected
because the function isn't in async mode. Apart from the absence of the
async specifier, it's a totally valid token.
If the parser thinks async functions and regular functions are completely
different things, fine (although I don't see why this would be the case),
but I seriously doubt the programmer does. An async function is a
particular type of function, but it's still a function.
|
@SystemParadox: You could make that argument for many other syntax errors, e.g. I do agree though that more detailed error messages are useful. |
This sounds like a job for a linting tool. I don't know that it belongs in Babel itself though. |
Moved to babel/babylon#113 |
Throws:
This is a bit misleading. Can we change this to say something like "await can only be used in async functions"?
Thanks.
The text was updated successfully, but these errors were encountered: