@@ -1768,18 +1768,6 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
1768
1768
1769
1769
const ch = codePointAt ( text , pos ) ;
1770
1770
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
- }
1783
1771
// Special handling for shebang
1784
1772
if ( ch === CharacterCodes . hash && isShebangTrivia ( text , pos ) ) {
1785
1773
pos = scanShebangTrivia ( text , pos ) ;
@@ -2242,6 +2230,10 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
2242
2230
error ( Diagnostics . Invalid_character , pos ++ , charSize ( ch ) ) ;
2243
2231
}
2244
2232
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 ;
2245
2237
default :
2246
2238
const identifierKind = scanIdentifier ( ch , languageVersion ) ;
2247
2239
if ( identifierKind ) {
0 commit comments