Skip to content
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

Closed
SystemParadox opened this issue Sep 16, 2015 · 9 comments
Closed

Better error output for await in non-async functions #2387

SystemParadox opened this issue Sep 16, 2015 · 9 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@SystemParadox
Copy link

function test() {
    await foo();
}

Throws:

Unexpected token(2:8)

This is a bit misleading. Can we change this to say something like "await can only be used in async functions"?

Thanks.

@zloirock
Copy link
Member

+1. Too frequent issues about this case.

@sebmck
Copy link
Contributor

sebmck commented Sep 16, 2015

@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.

@zloirock
Copy link
Member

@sebmck I remember 5-10 in different chat rooms, will find in the tracker.

@zloirock
Copy link
Member

In this repo found only #2180 and #1902, looks like most in chats / another repos.

@JohnyDays
Copy link

+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

@SystemParadox
Copy link
Author

SystemParadox commented Sep 16, 2015 via email

@fkling
Copy link
Contributor

fkling commented Sep 16, 2015

@SystemParadox: You could make that argument for many other syntax errors, e.g. function(){}. Function declarations need names so this is a syntax error. Even though they create the same kind of object at runtime, the syntax of function declarations and function expressions are different. Similarly the syntax of an async function is different from a "normal" function. If you don't follow the syntax, it's a syntax error.

I do agree though that more detailed error messages are useful.

@jamiebuilds
Copy link
Contributor

This sounds like a job for a linting tool. I don't know that it belongs in Babel itself though.

@danez
Copy link
Member

danez commented Sep 8, 2016

Moved to babel/babylon#113

@danez danez closed this as completed Sep 8, 2016
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 6, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

7 participants