diff --git a/src/compiler/program.ts b/src/compiler/program.ts index d76e7585d15..85a43ac537f 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -209,6 +209,7 @@ namespace ts { export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost { let currentDirectory: string; let existingDirectories: Map = {}; + let existingFiles: Map = {}; function getCanonicalFileName(fileName: string): string { // if underlying system can distinguish between two files whose names differs only in cases then file name already in canonical form. @@ -249,6 +250,14 @@ namespace ts { return false; } + function fileExists(fileName: string): boolean { + if (hasProperty(existingFiles, fileName)) { + return existingFiles[fileName]; + } + + return existingFiles[fileName] = sys.fileExists(fileName); + } + function ensureDirectoriesExist(directoryPath: string) { if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) { let parentDirectory = getDirectoryPath(directoryPath); @@ -281,7 +290,7 @@ namespace ts { useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames, getCanonicalFileName, getNewLine: () => newLine, - fileExists: fileName => sys.fileExists(fileName), + fileExists, readFile: fileName => sys.readFile(fileName) }; }