@@ -187,10 +187,10 @@ namespace ts {
187
187
const onWatchStatusChange = reportWatchStatus || createWatchStatusReporter ( system ) ;
188
188
return {
189
189
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
194
194
} ;
195
195
}
196
196
@@ -217,6 +217,7 @@ namespace ts {
217
217
218
218
export function createCompilerHostFromProgramHost ( host : ProgramHost < any > , getCompilerOptions : ( ) => CompilerOptions , directoryStructureHost : DirectoryStructureHost = host ) : CompilerHost {
219
219
const useCaseSensitiveFileNames = host . useCaseSensitiveFileNames ( ) ;
220
+ const hostGetNewLine = memoize ( ( ) => host . getNewLine ( ) ) ;
220
221
return {
221
222
getSourceFile : ( fileName , languageVersion , onError ) => {
222
223
let text : string | undefined ;
@@ -235,22 +236,22 @@ namespace ts {
235
236
236
237
return text !== undefined ? createSourceFile ( fileName , text , languageVersion ) : undefined ;
237
238
} ,
238
- getDefaultLibLocation : host . getDefaultLibLocation && ( ( ) => host . getDefaultLibLocation ! ( ) ) ,
239
+ getDefaultLibLocation : maybeBind ( host , host . getDefaultLibLocation ) ,
239
240
getDefaultLibFileName : options => host . getDefaultLibFileName ( options ) ,
240
241
writeFile,
241
242
getCurrentDirectory : memoize ( ( ) => host . getCurrentDirectory ( ) ) ,
242
243
useCaseSensitiveFileNames : ( ) => useCaseSensitiveFileNames ,
243
244
getCanonicalFileName : createGetCanonicalFileName ( useCaseSensitiveFileNames ) ,
244
- getNewLine : memoize ( ( ) => getNewLineCharacter ( getCompilerOptions ( ) , ( ) => host . getNewLine ( ) ) ) ,
245
+ getNewLine : ( ) => getNewLineCharacter ( getCompilerOptions ( ) , hostGetNewLine ) ,
245
246
fileExists : f => host . fileExists ( f ) ,
246
247
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 ) ,
254
255
} ;
255
256
256
257
function ensureDirectoriesExist ( directoryPath : string ) {
@@ -297,13 +298,13 @@ namespace ts {
297
298
directoryExists : path => system . directoryExists ( path ) ,
298
299
getDirectories : path => system . getDirectories ( path ) ,
299
300
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 ) ,
302
303
trace : s => system . write ( s + system . newLine ) ,
303
304
createDirectory : path => system . createDirectory ( path ) ,
304
305
writeFile : ( path , data , writeByteOrderMark ) => system . writeFile ( path , data , writeByteOrderMark ) ,
305
306
onCachedDirectoryStructureHostCreate : cacheHost => host = cacheHost || system ,
306
- createHash : system . createHash && ( s => system . createHash ! ( s ) ) ,
307
+ createHash : maybeBind ( system , system . createHash ) ,
307
308
createProgram
308
309
} ;
309
310
}
@@ -758,7 +759,7 @@ namespace ts {
758
759
759
760
// Create new source file if requested or the versions dont match
760
761
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 ) ;
762
763
if ( hostSourceFile ) {
763
764
if ( shouldCreateNewSourceFile ) {
764
765
hostSourceFile . version ++ ;
0 commit comments