Improve error message when reserved word is used as identifier (#33702)

Improve error message when reserved word is used as identifier
This commit is contained in:
Daniel Rosenwasser
2019-10-01 16:20:28 -04:00
committed by GitHub
14 changed files with 79 additions and 31 deletions
+4
View File
@@ -1043,6 +1043,10 @@
"category": "Error",
"code": 1358
},
"Identifier expected. '{0}' is a reserved word that cannot be used here.": {
"category": "Error",
"code": 1359
},
"The types of '{0}' are incompatible between these types.": {
"category": "Error",
+8 -1
View File
@@ -1401,7 +1401,14 @@ namespace ts {
// Only for end of file because the error gets reported incorrectly on embedded script tags.
const reportAtCurrentPosition = token() === SyntaxKind.EndOfFileToken;
return createMissingNode<Identifier>(SyntaxKind.Identifier, reportAtCurrentPosition, diagnosticMessage || Diagnostics.Identifier_expected);
const isReservedWord = scanner.isReservedWord();
const msgArg = scanner.getTokenText();
const defaultMessage = isReservedWord ?
Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here :
Diagnostics.Identifier_expected;
return createMissingNode<Identifier>(SyntaxKind.Identifier, reportAtCurrentPosition, diagnosticMessage || defaultMessage, msgArg);
}
function parseIdentifier(diagnosticMessage?: DiagnosticMessage): Identifier {