@@ -173,6 +173,18 @@ export interface Register {
173173 getTypeInfo ( code : string , fileName : string , position : number ) : TypeInfo
174174}
175175
176+ function cachedLookup ( fn : ( arg : string ) => boolean ) : ( arg : string ) => boolean {
177+ const cache = new Map < string , boolean > ( )
178+
179+ return ( arg : string ) => {
180+ if ( ! cache . has ( arg ) ) {
181+ cache . set ( arg , fn ( arg ) )
182+ }
183+
184+ return cache . get ( arg ) || false
185+ }
186+ }
187+
176188/**
177189 * Register TypeScript compiler.
178190 */
@@ -303,11 +315,11 @@ export function register (opts: Options = {}): Register {
303315
304316 return ts . ScriptSnapshot . fromString ( contents )
305317 } ,
306- fileExists : debugFn ( 'fileExists' , fileExists ) ,
318+ fileExists : cachedLookup ( debugFn ( 'fileExists' , fileExists ) ) ,
307319 readFile : debugFn ( 'readFile' , readFile ) ,
308320 readDirectory : debugFn ( 'readDirectory' , ts . sys . readDirectory ) ,
309321 getDirectories : debugFn ( 'getDirectories' , ts . sys . getDirectories ) ,
310- directoryExists : debugFn ( 'directoryExists' , ts . sys . directoryExists ) ,
322+ directoryExists : cachedLookup ( debugFn ( 'directoryExists' , ts . sys . directoryExists ) ) ,
311323 realpath : debugFn ( 'realpath' , ts . sys . realpath ! ) ,
312324 getNewLine : ( ) => ts . sys . newLine ,
313325 useCaseSensitiveFileNames : ( ) => ts . sys . useCaseSensitiveFileNames ,
0 commit comments