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:
Wesley Wigham
2019-08-12 16:00:38 -07:00
committed by GitHub
parent 51411c1f8b
commit 4ab85bbf35
14 changed files with 341 additions and 12 deletions

View File

@@ -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);
}