Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Better error messaging for unexpected tokens #230

Closed
kaicataldo opened this issue Nov 20, 2016 · 5 comments
Closed

Better error messaging for unexpected tokens #230

kaicataldo opened this issue Nov 20, 2016 · 5 comments

Comments

@kaicataldo
Copy link
Member

kaicataldo commented Nov 20, 2016

Currently, when an error is thrown for an unexpected token, it looks like this: SyntaxError: Unexpected token, expected ; (2:7). It looks like the error message is malformed or something is buggy in Babylon - can we make this better? Haven't looked into implementing yet, but some initial ideas:

  • Just report the "unexpected token" and remove the "expected" part (Even if just this change was made, I think it would make more sense than the current output): SyntaxError: Unexpected token (2:7)
  • Report the token that was unexpected (not sure how difficult this would be): SyntaxError: Unexpected token foo (2:7)

Input Code

Not a bug, but an example of when this error is shown is:

  onst foo = 1;

Babylon/Babel Configuration

N/A

Expected Behavior

To output a more complete error message. Perhaps print out which token was unexpected?

Current Behavior

The error that currently gets thrown is SyntaxError: Unexpected token, expected ; (2:7), which looks like unfinished behavior/a bug.

Your Environment

software version
Babylon Master branch
node v6.9.1
npm v3.10.9
Operating System OSX
@danez
Copy link
Member

danez commented Nov 20, 2016

This was just changed so that the expected ; in #150. What do you think is buggy here?

@kaicataldo
Copy link
Member Author

Unexpected token, expected ; is a really confusing message. Seems to me like the error message should just be Unexpected token in those cases where there isn't an expected value.

@kaicataldo
Copy link
Member Author

kaicataldo commented Nov 20, 2016

Ohhhh okay, I see now. This read to me like "Unexpected token, expected {missing token value};", but I see that ; is the token value.

I wonder if we can make this clearer (I think the comma also makes it grammatically confusing at the moment). Thoughts on having it read like this?

Unexpected token; expected token ";". (2:7)

Happy to make a PR for this if others like the idea!

@hzoo
Copy link
Member

hzoo commented Sep 12, 2017

Yeah we can add quotes if that's more readable

@babel-bot
Copy link

This issue has been moved to babel/babel#6715.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants