@@ -1768,18 +1768,6 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
17681768
17691769 const ch = codePointAt ( text , pos ) ;
17701770 if ( pos === 0 ) {
1771- // If a file isn't valid text at all, it will usually be apparent
1772- // in the first few characters because UTF-8 decode will fail and produce U+FFFD.
1773- // If that happens, just issue one error and refuse to try to scan further;
1774- // this is likely a binary file that cannot be parsed.
1775- //
1776- // It's safe to slice the text; U+FFFD can only be produced by an invalid decode,
1777- // so even if we cut a surrogate pair in half, they wouldn't be U+FFFD.
1778- if ( text . slice ( 0 , 256 ) . includes ( "\uFFFD" ) ) {
1779- error ( Diagnostics . File_appears_to_be_binary ) ;
1780- pos = end ;
1781- return token = SyntaxKind . NonTextFileMarkerTrivia ;
1782- }
17831771 // Special handling for shebang
17841772 if ( ch === CharacterCodes . hash && isShebangTrivia ( text , pos ) ) {
17851773 pos = scanShebangTrivia ( text , pos ) ;
@@ -2242,6 +2230,10 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
22422230 error ( Diagnostics . Invalid_character , pos ++ , charSize ( ch ) ) ;
22432231 }
22442232 return token = SyntaxKind . PrivateIdentifier ;
2233+ case CharacterCodes . replacementCharacter :
2234+ error ( Diagnostics . File_appears_to_be_binary , 0 , 0 ) ;
2235+ pos = end ;
2236+ return token = SyntaxKind . NonTextFileMarkerTrivia ;
22452237 default :
22462238 const identifierKind = scanIdentifier ( ch , languageVersion ) ;
22472239 if ( identifierKind ) {
0 commit comments