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

Annotate more errors with expected token #172

Merged
merged 1 commit into from
Oct 14, 2016

Conversation

motiz88
Copy link
Contributor

@motiz88 motiz88 commented Oct 14, 2016

Expanding on #150, this allows unexpected() to accept the expected token type instead of a message string. This overload is then used in a couple more places (that essentially reimplement expect()) to construct an Unexpected token, expected FOO message.

I can imagine a future enhancement to unexpected() in which it would similarly take an array of token types; then we could say expected FOO or BAR or BAZ where it makes sense.

Expanding on babel#150, this allows `unexpected()` to accept the expected token type instead of a message string.
This overload is then used in a couple more places (that independently implement a logic similar to `expect()`'s) to construct an `Unexpected token, expected FOO` message.
@@ -67,18 +67,22 @@ pp.isLineTerminator = function () {
// pretend that there is a semicolon at this position.

pp.semicolon = function () {
if (!this.isLineTerminator()) this.unexpected();
if (!this.isLineTerminator()) this.unexpected(null, tt.semi);
Copy link
Member

@danez danez Oct 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a newline would be expected here I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Do you have a preference as to the message here? Expected ; or newline?

@danez
Copy link
Member

danez commented Oct 14, 2016

@motiz88 Can you have a look and see why the babel tests now fail with this PR? One sems fine, but have no idea about the other failure.

@motiz88
Copy link
Contributor Author

motiz88 commented Oct 14, 2016

@danez Those are both assertions on messages that have changed in this PR. Not sure why one of them (transformation/errors/syntax) doesn't say so in the log and instead just throws the SyntaxError.

PR to make Babel tests pass with the new messages: babel/babel#4727

motiz88 added a commit to motiz88/babel that referenced this pull request Oct 14, 2016
@hzoo hzoo merged commit d3af158 into babel:master Oct 14, 2016
hzoo pushed a commit to babel/babel that referenced this pull request Oct 14, 2016
@motiz88 motiz88 mentioned this pull request Oct 14, 2016
hzoo pushed a commit that referenced this pull request Oct 14, 2016
* Update two esprima tests to the new "expected TOKEN" messages

* Update dynamic-import to use "expected (" error message
chrisprice pushed a commit to chrisprice/babel that referenced this pull request Oct 18, 2016
kristofdegrave pushed a commit to kristofdegrave/babylon that referenced this pull request Oct 27, 2016
Expanding on babel#150, this allows `unexpected()` to accept the expected token type instead of a message string.
This overload is then used in a couple more places (that independently implement a logic similar to `expect()`'s) to construct an `Unexpected token, expected FOO` message.
kristofdegrave pushed a commit to kristofdegrave/babylon that referenced this pull request Oct 27, 2016
* Update two esprima tests to the new "expected TOKEN" messages

* Update dynamic-import to use "expected (" error message
panagosg7 pushed a commit to panagosg7/babel that referenced this pull request Jan 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants