Skip to content

Commit

Permalink
use exact error message
Browse files Browse the repository at this point in the history
  • Loading branch information
lala7573 committed Jul 1, 2021
1 parent 36d770c commit 76abdb1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 31 deletions.
9 changes: 4 additions & 5 deletions packages/babel-parser/src/plugins/typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ const TSErrors = makeErrorTemplates(
EmptyTypeParameters: "Type parameter list cannot be empty.",
ExpectedAmbientAfterExportDeclare:
"'export declare' must be followed by an ambient declaration.",
IdentifierExpected: "Identifier expected.",
ImportAliasHasImportType: "An import alias can not use 'import type'.",
IncompatibleModifiers: "'%0' modifier cannot be used with '%1' modifier.",
IndexSignatureHasAbstract:
Expand Down Expand Up @@ -2138,13 +2137,13 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
}

if (isOptionalCall) {
return this.raise(node.start, TSErrors.IdentifierExpected);
}

this.unexpected();
});

if (!result && isOptionalCall) {
this.unexpected(this.state.pos, tt.parenL);
}

if (result) return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f?.<string>[1];
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sourceType": "module",
"plugins": [
"typescript"
],
"throws": "Unexpected token, expected \"(\" (1:4)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ f?.<Q>();
f?.<Q, W>();
f
?.<Q>();
f?.<string>[1];
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"type": "File",
"start":0,"end":49,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":15}},
"errors": [
"SyntaxError: Identifier expected. (5:0)"
],
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":8}},
"program": {
"type": "Program",
"start":0,"end":49,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":15}},
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":8}},
"sourceType": "module",
"interpreter": null,
"body": [
Expand Down Expand Up @@ -108,26 +105,6 @@
},
"optional": false
}
},
{
"type": "ExpressionStatement",
"start":34,"end":49,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":15}},
"expression": {
"type": "OptionalMemberExpression",
"start":34,"end":48,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":14}},
"object": "SyntaxError: Identifier expected. (5:0)",
"computed": true,
"property": {
"type": "NumericLiteral",
"start":46,"end":47,"loc":{"start":{"line":5,"column":12},"end":{"line":5,"column":13}},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
},
"optional": false
}
}
],
"directives": []
Expand Down

0 comments on commit 76abdb1

Please sign in to comment.