mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
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:
@@ -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",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user