@@ -503,6 +503,7 @@ namespace ts {
503503 /*@internal */ setBlocking ?( ) : void ;
504504 base64decode ?( input : string ) : string ;
505505 base64encode ?( input : string ) : string ;
506+ /*@internal */ bufferFrom ?( input : string , encoding ?: string ) : Buffer ;
506507 }
507508
508509 export interface FileWatcher {
@@ -558,7 +559,7 @@ namespace ts {
558559 getEnvironmentVariable ?( name : string ) : string ;
559560 } ;
560561
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.
562563 export let sys : System = ( ( ) => {
563564 // NodeJS detects "\uFEFF" at the start of the string and *replaces* it with the actual
564565 // byte order mark from the specified encoding. Using any other byte order mark does
@@ -675,19 +676,19 @@ namespace ts {
675676 process . stdout . _handle . setBlocking ( true ) ;
676677 }
677678 } ,
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" ) ,
688682 } ;
689683 return nodeSystem ;
690684
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+
691692 function isFileSystemCaseSensitive ( ) : boolean {
692693 // win32\win64 are case insensitive platforms
693694 if ( platform === "win32" || platform === "win64" ) {
0 commit comments