@@ -43,6 +43,7 @@ namespace ts {
4343 reScanJsxToken ( ) : JsxTokenSyntaxKind ;
4444 reScanLessThanToken ( ) : SyntaxKind ;
4545 reScanQuestionToken ( ) : SyntaxKind ;
46+ reScanInvalidIdentifier ( ) : SyntaxKind ;
4647 scanJsxToken ( ) : JsxTokenSyntaxKind ;
4748 scanJsDocToken ( ) : JSDocSyntaxKind ;
4849 scan ( ) : SyntaxKind ;
@@ -966,6 +967,7 @@ namespace ts {
966967 reScanJsxToken,
967968 reScanLessThanToken,
968969 reScanQuestionToken,
970+ reScanInvalidIdentifier,
969971 scanJsxToken,
970972 scanJsDocToken,
971973 scan,
@@ -2041,14 +2043,9 @@ namespace ts {
20412043 }
20422044 return token = SyntaxKind . PrivateIdentifier ;
20432045 default :
2044- if ( isIdentifierStart ( ch , languageVersion ) ) {
2045- pos += charSize ( ch ) ;
2046- while ( pos < end && isIdentifierPart ( ch = codePointAt ( text , pos ) , languageVersion ) ) pos += charSize ( ch ) ;
2047- tokenValue = text . substring ( tokenPos , pos ) ;
2048- if ( ch === CharacterCodes . backslash ) {
2049- tokenValue += scanIdentifierParts ( ) ;
2050- }
2051- return token = getIdentifierToken ( ) ;
2046+ const identifierKind = scanIdentifier ( ch , languageVersion ) ;
2047+ if ( identifierKind ) {
2048+ return token = identifierKind ;
20522049 }
20532050 else if ( isWhiteSpaceSingleLine ( ch ) ) {
20542051 pos += charSize ( ch ) ;
@@ -2066,6 +2063,32 @@ namespace ts {
20662063 }
20672064 }
20682065
2066+ function reScanInvalidIdentifier ( ) : SyntaxKind {
2067+ Debug . assert ( token === SyntaxKind . Unknown , "'reScanInvalidIdentifier' should only be called when the current token is 'SyntaxKind.Unknown'." ) ;
2068+ pos = tokenPos = startPos ;
2069+ tokenFlags = 0 ;
2070+ const ch = codePointAt ( text , pos ) ;
2071+ const identifierKind = scanIdentifier ( ch , ScriptTarget . ESNext ) ;
2072+ if ( identifierKind ) {
2073+ return token = identifierKind ;
2074+ }
2075+ pos += charSize ( ch ) ;
2076+ return token ; // Still `SyntaKind.Unknown`
2077+ }
2078+
2079+ function scanIdentifier ( startCharacter : number , languageVersion : ScriptTarget ) {
2080+ let ch = startCharacter ;
2081+ if ( isIdentifierStart ( ch , languageVersion ) ) {
2082+ pos += charSize ( ch ) ;
2083+ while ( pos < end && isIdentifierPart ( ch = codePointAt ( text , pos ) , languageVersion ) ) pos += charSize ( ch ) ;
2084+ tokenValue = text . substring ( tokenPos , pos ) ;
2085+ if ( ch === CharacterCodes . backslash ) {
2086+ tokenValue += scanIdentifierParts ( ) ;
2087+ }
2088+ return getIdentifierToken ( ) ;
2089+ }
2090+ }
2091+
20692092 function reScanGreaterToken ( ) : SyntaxKind {
20702093 if ( token === SyntaxKind . GreaterThanToken ) {
20712094 if ( text . charCodeAt ( pos ) === CharacterCodes . greaterThan ) {
0 commit comments