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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/parser/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pp.expectRelational = function (op) {
if (this.isRelational(op)) {
this.next();
} else {
this.unexpected();
this.unexpected(null, tt.relational);
}
};

Expand Down Expand Up @@ -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?

};

// Expect a token of a given type. If found, consume it, otherwise,
// raise an unexpected token error at given pos.

pp.expect = function (type, pos) {
return this.eat(type) || this.unexpected(pos, `Unexpected token, expected ${type.label}`);
return this.eat(type) || this.unexpected(pos, type);
};

// Raise an unexpected token error.
// Raise an unexpected token error. Can take the expected token type
// instead of a message string.

pp.unexpected = function (pos, message = "Unexpected token") {
this.raise(pos != null ? pos : this.state.start, message);
pp.unexpected = function (pos, messageOrType = "Unexpected token") {
if (messageOrType && typeof messageOrType === 'object' && messageOrType.label) {
messageOrType = `Unexpected token, expected ${messageOrType.label}`;
}
this.raise(pos != null ? pos : this.state.start, messageOrType);
};
2 changes: 1 addition & 1 deletion test/fixtures/core/uncategorised/388/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:6)"
"throws": "Unexpected token, expected ; (1:6)"
}
2 changes: 1 addition & 1 deletion test/fixtures/core/uncategorised/389/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:6)"
"throws": "Unexpected token, expected ; (1:6)"
}
2 changes: 1 addition & 1 deletion test/fixtures/core/uncategorised/405/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:2)"
"throws": "Unexpected token, expected ; (1:2)"
}
2 changes: 1 addition & 1 deletion test/fixtures/core/uncategorised/407/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:2)"
"throws": "Unexpected token, expected ; (1:2)"
}
2 changes: 1 addition & 1 deletion test/fixtures/core/uncategorised/408/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:2)"
"throws": "Unexpected token, expected ; (1:2)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:8)"
"throws": "Unexpected token, expected ; (1:8)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/201/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:3)"
"throws": "Unexpected token, expected ; (1:3)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/205/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:3)"
"throws": "Unexpected token, expected ; (1:3)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/209/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:3)"
"throws": "Unexpected token, expected ; (1:3)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/210/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:3)"
"throws": "Unexpected token, expected ; (1:3)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/214/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:3)"
"throws": "Unexpected token, expected ; (1:3)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/215/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:3)"
"throws": "Unexpected token, expected ; (1:3)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/224/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (2:4)"
"throws": "Unexpected token, expected ; (2:4)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/225/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (2:6)"
"throws": "Unexpected token, expected ; (2:6)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/253/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:6)"
"throws": "Unexpected token, expected ; (1:6)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/254/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:6)"
"throws": "Unexpected token, expected ; (1:6)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2015/uncategorised/258/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:21)"
"throws": "Unexpected token, expected ; (1:21)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2017/async-functions/10/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (2:4)"
"throws": "Unexpected token, expected ; (2:4)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2017/async-functions/6/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:14)"
"throws": "Unexpected token, expected ; (1:14)"
}
2 changes: 1 addition & 1 deletion test/fixtures/es2017/async-functions/9/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:30)"
"throws": "Unexpected token, expected ; (1:30)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:20)"
"throws": "Unexpected token, expected ; (1:20)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:20)"
"throws": "Unexpected token, expected ; (1:20)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:28)"
"throws": "Unexpected token, expected ; (1:28)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:3)"
"throws": "Unexpected token, expected ; (1:3)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:3)"
"throws": "Unexpected token, expected ; (1:3)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:3)"
"throws": "Unexpected token, expected ; (1:3)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:3)"
"throws": "Unexpected token, expected ; (1:3)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:3)"
"throws": "Unexpected token, expected ; (1:3)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:3)"
"throws": "Unexpected token, expected ; (1:3)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:6)"
"throws": "Unexpected token, expected ; (1:6)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:6)"
"throws": "Unexpected token, expected ; (1:6)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:2)"
"throws": "Unexpected token, expected ; (1:2)"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:16)"
"throws": "Unexpected token, expected ; (1:16)"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"throws": "Unexpected token (3:9)",
"throws": "Unexpected token, expected ; (3:9)",
"plugins": ["classProperties"]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"throws": "Unexpected token (3:8)",
"throws": "Unexpected token, expected ; (3:8)",
"plugins": ["classProperties"]
}