@@ -503,6 +503,7 @@ namespace ts {
503
503
/*@internal */ setBlocking ?( ) : void ;
504
504
base64decode ?( input : string ) : string ;
505
505
base64encode ?( input : string ) : string ;
506
+ /*@internal */ bufferFrom ?( input : string , encoding ?: string ) : Buffer ;
506
507
}
507
508
508
509
export interface FileWatcher {
@@ -558,7 +559,7 @@ namespace ts {
558
559
getEnvironmentVariable ?( name : string ) : string ;
559
560
} ;
560
561
561
- // TODO: this is used as if it's certainly defined in many places.
562
+ // TODO: GH#18217 this is used as if it's certainly defined in many places.
562
563
export let sys : System = ( ( ) => {
563
564
// NodeJS detects "\uFEFF" at the start of the string and *replaces* it with the actual
564
565
// byte order mark from the specified encoding. Using any other byte order mark does
@@ -675,19 +676,19 @@ namespace ts {
675
676
process . stdout . _handle . setBlocking ( true ) ;
676
677
}
677
678
} ,
678
- base64decode : Buffer . from ? input => {
679
- return Buffer . from ! ( input , "base64" ) . toString ( "utf8" ) ;
680
- } : input => {
681
- return new Buffer ( input , "base64" ) . toString ( "utf8" ) ;
682
- } ,
683
- base64encode : Buffer . from ? input => {
684
- return Buffer . from ! ( input ) . toString ( "base64" ) ;
685
- } : input => {
686
- return new Buffer ( input ) . toString ( "base64" ) ;
687
- }
679
+ bufferFrom,
680
+ base64decode : input => bufferFrom ( input , "base64" ) . toString ( "utf8" ) ,
681
+ base64encode : input => bufferFrom ( input ) . toString ( "base64" ) ,
688
682
} ;
689
683
return nodeSystem ;
690
684
685
+ function bufferFrom ( input : string , encoding ?: string ) : Buffer {
686
+ // See https://github.com/Microsoft/TypeScript/issues/25652
687
+ return Buffer . from && ( Buffer . from as Function ) !== Int8Array . from
688
+ ? Buffer . from ( input , encoding )
689
+ : new Buffer ( input , encoding ) ;
690
+ }
691
+
691
692
function isFileSystemCaseSensitive ( ) : boolean {
692
693
// win32\win64 are case insensitive platforms
693
694
if ( platform === "win32" || platform === "win64" ) {
0 commit comments