mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 11:24:49 -05:00
Add error message for keywords with escapes in them (#32718)
* Add error message for keywords with escapes in them * Move check into parser during advance to next token to utilize context for contextual keywords * git add . * Add tests for extended escapes * Better error courtesy of @DanielRossenwaser * Add test of browser-inconsistent case and alter condition to match spec * Merge adjacent conditions * Use seperate functions for checking keywords vs not * Use flags to track unicode escape presence * Adjust error text
This commit is contained in:
@@ -1086,10 +1086,19 @@ namespace ts {
|
||||
return currentToken;
|
||||
}
|
||||
|
||||
function nextToken(): SyntaxKind {
|
||||
function nextTokenWithoutCheck() {
|
||||
return currentToken = scanner.scan();
|
||||
}
|
||||
|
||||
function nextToken(): SyntaxKind {
|
||||
// if the keyword had an escape
|
||||
if (isKeyword(currentToken) && (scanner.hasUnicodeEscape() || scanner.hasExtendedUnicodeEscape())) {
|
||||
// issue a parse error for the escape
|
||||
parseErrorAt(scanner.getTokenPos(), scanner.getTextPos(), Diagnostics.Keywords_cannot_contain_escape_characters);
|
||||
}
|
||||
return nextTokenWithoutCheck();
|
||||
}
|
||||
|
||||
function nextTokenJSDoc(): JSDocSyntaxKind {
|
||||
return currentToken = scanner.scanJsDocToken();
|
||||
}
|
||||
@@ -1380,7 +1389,7 @@ namespace ts {
|
||||
node.originalKeywordKind = token();
|
||||
}
|
||||
node.escapedText = escapeLeadingUnderscores(internIdentifier(scanner.getTokenValue()));
|
||||
nextToken();
|
||||
nextTokenWithoutCheck();
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user