babel: Better error output for await in non-async functions

Issue originally reported by @danez in babel/babylon#113

Issue originally made by @SystemParadox on babel/babel#2387

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.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

The output is now await is a reserved word (2:4) and #7727 might have an effect on this.

Closing as I think the output is better now.

@aulisius awesome! feel to free to join us on slack if you haven’t already!

How’s the progress on this one? I’d like to give it a shot!

Cool! I’ll like to take a crack at it, then 😄 !