mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-10 01:43:59 -05:00
cache results of fileExists check in default compiler host
This commit is contained in:
@@ -209,6 +209,7 @@ namespace ts {
|
||||
export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost {
|
||||
let currentDirectory: string;
|
||||
let existingDirectories: Map<boolean> = {};
|
||||
let existingFiles: Map<boolean> = {};
|
||||
|
||||
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)
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user