Skip to content

Commit

Permalink
More detailed error message in ambiguous cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Oct 3, 2017
1 parent 210de1f commit ffcf461
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 11 deletions.
11 changes: 9 additions & 2 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,15 @@ pp.parseStatement = function (declaration, topLevel) {
try {
return this.parseBlock();
} catch (err) {
if (objParseError && objParseError.pos >= err.pos) {
throw objParseError;
if (objParseError) {
if (objParseError.pos > err.pos) {
throw objParseError;
} else if (objParseError.pos < err.pos) {
throw err;
} else {
objParseError.message = "Cannot parse brace-delimited construct as an object or as a block. When parsed as an object, the error is: " + objParseError.message;
throw objParseError;
}
} else {
throw err;
}
Expand Down
11 changes: 9 additions & 2 deletions test/fixtures/core/uncategorised/345/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"throws": "Unexpected token (1:1)"
}
"alternatives": {
"all": {
"throws": "Cannot parse brace-delimited construct as an object or as a block. When parsed as an object, the error is: Unexpected token (1:1)"
},
"noLsc": {
"throws": "Unexpected token (1:1)"
}
}
}
11 changes: 9 additions & 2 deletions test/fixtures/core/uncategorised/386/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"throws": "Unexpected token (4:1)"
}
"alternatives": {
"all": {
"throws": "Cannot parse brace-delimited construct as an object or as a block. When parsed as an object, the error is: Unexpected token (4:1)"
},
"noLsc": {
"throws": "Unexpected token (4:1)"
}
}
}
11 changes: 9 additions & 2 deletions test/fixtures/esprima/invalid-syntax/migrated_0000/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"throws": "Unexpected token (1:1)"
}
"alternatives": {
"all": {
"throws": "Cannot parse brace-delimited construct as an object or as a block. When parsed as an object, the error is: Unexpected token (1:1)"
},
"noLsc": {
"throws": "Unexpected token (1:1)"
}
}
}
11 changes: 9 additions & 2 deletions test/fixtures/esprima/invalid-syntax/migrated_0069/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"throws": "Unexpected token (1:1)"
}
"alternatives": {
"all": {
"throws": "Cannot parse brace-delimited construct as an object or as a block. When parsed as an object, the error is: Unexpected token (1:1)"
},
"noLsc": {
"throws": "Unexpected token (1:1)"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"alternatives": {
"all": {
"throws": "Unexpected token, expected } (1:26)"
"throws": "Cannot parse brace-delimited construct as an object or as a block. When parsed as an object, the error is: Unexpected token, expected } (1:26)"
},
"noSeqExprParens": {
"allPlugins": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
a = b
x&
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"alternatives": {
"all": {
"throws": "Cannot parse brace-delimited construct as an object or as a block. When parsed as an object, the error is: Unexpected token, expected , (3:3)"
},
"whiteblockOnly": {
"throws": "Unexpected token, expected , (3:3)"
},
"braceblock": {
"throws": "Unexpected token, expected , (3:3)"
}
}
}

0 comments on commit ffcf461

Please sign in to comment.