Improve error message when reserved word is used as identifier

Signed-off-by: Sergey Tychinin <stychinin@bloomberg.net>
This commit is contained in:
Sergey Tychinin
2019-10-01 10:48:17 -04:00
committed by Joey Watts
parent 7be7cba050
commit ab879939df
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 {