@@ -187,10 +187,10 @@ namespace ts {
187187 const onWatchStatusChange = reportWatchStatus || createWatchStatusReporter ( system ) ;
188188 return {
189189 onWatchStatusChange,
190- watchFile : system . watchFile ? ( ( path , callback , pollingInterval ) => system . watchFile ! ( path , callback , pollingInterval ) ) : ( ) => noopFileWatcher ,
191- watchDirectory : system . watchDirectory ? ( ( path , callback , recursive ) => system . watchDirectory ! ( path , callback , recursive ) ) : ( ) => noopFileWatcher ,
192- setTimeout : system . setTimeout ? ( ( callback , ms , ... args : any [ ] ) => system . setTimeout ! . call ( system , callback , ms , ... args ) ) : noop ,
193- clearTimeout : system . clearTimeout ? ( timeoutId => system . clearTimeout ! ( timeoutId ) ) : noop
190+ watchFile : maybeBind ( system , system . watchFile ) || ( ( ) => noopFileWatcher ) ,
191+ watchDirectory : maybeBind ( system , system . watchDirectory ) || ( ( ) => noopFileWatcher ) ,
192+ setTimeout : maybeBind ( system , system . setTimeout ) || noop ,
193+ clearTimeout : maybeBind ( system , system . clearTimeout ) || noop
194194 } ;
195195 }
196196
@@ -217,6 +217,7 @@ namespace ts {
217217
218218 export function createCompilerHostFromProgramHost ( host : ProgramHost < any > , getCompilerOptions : ( ) => CompilerOptions , directoryStructureHost : DirectoryStructureHost = host ) : CompilerHost {
219219 const useCaseSensitiveFileNames = host . useCaseSensitiveFileNames ( ) ;
220+ const hostGetNewLine = memoize ( ( ) => host . getNewLine ( ) ) ;
220221 return {
221222 getSourceFile : ( fileName , languageVersion , onError ) => {
222223 let text : string | undefined ;
@@ -235,22 +236,22 @@ namespace ts {
235236
236237 return text !== undefined ? createSourceFile ( fileName , text , languageVersion ) : undefined ;
237238 } ,
238- getDefaultLibLocation : host . getDefaultLibLocation && ( ( ) => host . getDefaultLibLocation ! ( ) ) ,
239+ getDefaultLibLocation : maybeBind ( host , host . getDefaultLibLocation ) ,
239240 getDefaultLibFileName : options => host . getDefaultLibFileName ( options ) ,
240241 writeFile,
241242 getCurrentDirectory : memoize ( ( ) => host . getCurrentDirectory ( ) ) ,
242243 useCaseSensitiveFileNames : ( ) => useCaseSensitiveFileNames ,
243244 getCanonicalFileName : createGetCanonicalFileName ( useCaseSensitiveFileNames ) ,
244- getNewLine : memoize ( ( ) => getNewLineCharacter ( getCompilerOptions ( ) , ( ) => host . getNewLine ( ) ) ) ,
245+ getNewLine : ( ) => getNewLineCharacter ( getCompilerOptions ( ) , hostGetNewLine ) ,
245246 fileExists : f => host . fileExists ( f ) ,
246247 readFile : f => host . readFile ( f ) ,
247- trace : host . trace && ( s => host . trace ! ( s ) ) ,
248- directoryExists : directoryStructureHost . directoryExists && ( path => directoryStructureHost . directoryExists ! ( path ) ) ,
249- getDirectories : ( directoryStructureHost . getDirectories && ( ( path : string ) => directoryStructureHost . getDirectories ! ( path ) ) ) ! , // TODO: GH#18217
250- realpath : host . realpath && ( s => host . realpath ! ( s ) ) ,
251- getEnvironmentVariable : host . getEnvironmentVariable ? ( name => host . getEnvironmentVariable ! ( name ) ) : ( ( ) => "" ) ,
252- createHash : host . createHash && ( data => host . createHash ! ( data ) ) ,
253- readDirectory : ( path , extensions , exclude , include , depth ? ) => directoryStructureHost . readDirectory ! ( path , extensions , exclude , include , depth ) ,
248+ trace : maybeBind ( host , host . trace ) ,
249+ directoryExists : maybeBind ( directoryStructureHost , directoryStructureHost . directoryExists ) ,
250+ getDirectories : maybeBind ( directoryStructureHost , directoryStructureHost . getDirectories ) ,
251+ realpath : maybeBind ( host , host . realpath ) ,
252+ getEnvironmentVariable : maybeBind ( host , host . getEnvironmentVariable ) || ( ( ) => "" ) ,
253+ createHash : maybeBind ( host , host . createHash ) ,
254+ readDirectory : maybeBind ( host , host . readDirectory ) ,
254255 } ;
255256
256257 function ensureDirectoriesExist ( directoryPath : string ) {
@@ -297,13 +298,13 @@ namespace ts {
297298 directoryExists : path => system . directoryExists ( path ) ,
298299 getDirectories : path => system . getDirectories ( path ) ,
299300 readDirectory : ( path , extensions , exclude , include , depth ) => system . readDirectory ( path , extensions , exclude , include , depth ) ,
300- realpath : system . realpath && ( path => system . realpath ! ( path ) ) ,
301- getEnvironmentVariable : system . getEnvironmentVariable && ( name => system . getEnvironmentVariable ( name ) ) ,
301+ realpath : maybeBind ( system , system . realpath ) ,
302+ getEnvironmentVariable : maybeBind ( system , system . getEnvironmentVariable ) ,
302303 trace : s => system . write ( s + system . newLine ) ,
303304 createDirectory : path => system . createDirectory ( path ) ,
304305 writeFile : ( path , data , writeByteOrderMark ) => system . writeFile ( path , data , writeByteOrderMark ) ,
305306 onCachedDirectoryStructureHostCreate : cacheHost => host = cacheHost || system ,
306- createHash : system . createHash && ( s => system . createHash ! ( s ) ) ,
307+ createHash : maybeBind ( system , system . createHash ) ,
307308 createProgram
308309 } ;
309310 }
@@ -758,7 +759,7 @@ namespace ts {
758759
759760 // Create new source file if requested or the versions dont match
760761 if ( ! hostSourceFile || shouldCreateNewSourceFile || ! isFilePresentOnHost ( hostSourceFile ) || hostSourceFile . version . toString ( ) !== hostSourceFile . sourceFile . version ) {
761- const sourceFile = getNewSourceFile . call ( compilerHost , fileName , languageVersion , onError ) ;
762+ const sourceFile = getNewSourceFile ( fileName , languageVersion , onError ) ;
762763 if ( hostSourceFile ) {
763764 if ( shouldCreateNewSourceFile ) {
764765 hostSourceFile . version ++ ;
0 commit comments