Skip to content

Commit 4bd8b9b

Browse files
committed
Swap the keys for map
1 parent 5f7bc05 commit 4bd8b9b

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/compiler/program.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ namespace ts {
168168
const originalDirectoryExists = host.directoryExists;
169169
const originalCreateDirectory = host.createDirectory;
170170
const originalWriteFile = host.writeFile;
171-
const readFileCache = new Map<string, string | false>();
172-
const fileExistsCache = new Map<string, boolean>();
173-
const directoryExistsCache = new Map<string, boolean>();
174-
const sourceFileCache = new Map<string, ESMap<SourceFile["impliedNodeFormat"], SourceFile>>();
171+
const readFileCache = new Map<Path, string | false>();
172+
const fileExistsCache = new Map<Path, boolean>();
173+
const directoryExistsCache = new Map<Path, boolean>();
174+
const sourceFileCache = new Map<SourceFile["impliedNodeFormat"], ESMap<Path, SourceFile>>();
175175

176176
const readFileWithCache = (fileName: string): string | undefined => {
177177
const key = toPath(fileName);
@@ -199,13 +199,13 @@ namespace ts {
199199
const getSourceFileWithCache: CompilerHost["getSourceFile"] | undefined = getSourceFile ? (fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => {
200200
const key = toPath(fileName);
201201
const impliedNodeFormat: SourceFile["impliedNodeFormat"] = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions.impliedNodeFormat : undefined;
202-
const forPath = sourceFileCache.get(key);
203-
const value = forPath?.get(impliedNodeFormat);
202+
const forImpliedNodeFormat = sourceFileCache.get(impliedNodeFormat);
203+
const value = forImpliedNodeFormat?.get(key);
204204
if (value) return value;
205205

206206
const sourceFile = getSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile);
207207
if (sourceFile && (isDeclarationFileName(fileName) || fileExtensionIs(fileName, Extension.Json))) {
208-
sourceFileCache.set(key, (forPath || new Map()).set(impliedNodeFormat, sourceFile));
208+
sourceFileCache.set(impliedNodeFormat, (forImpliedNodeFormat || new Map()).set(key, sourceFile));
209209
}
210210
return sourceFile;
211211
} : undefined;
@@ -227,14 +227,15 @@ namespace ts {
227227
const value = readFileCache.get(key);
228228
if (value !== undefined && value !== data) {
229229
readFileCache.delete(key);
230-
sourceFileCache.delete(key);
230+
sourceFileCache.forEach(map => map.delete(key));
231231
}
232232
else if (getSourceFileWithCache) {
233-
const sourceFileMap = sourceFileCache.get(key);
234-
const sourceFile = sourceFileMap && firstDefinedIterator(sourceFileMap.values(), identity);
235-
if (sourceFile && sourceFile.text !== data) {
236-
sourceFileCache.delete(key);
237-
}
233+
sourceFileCache.forEach(map => {
234+
const sourceFile = map.get(key);
235+
if (sourceFile && sourceFile.text !== data) {
236+
map.delete(key);
237+
}
238+
});
238239
}
239240
originalWriteFile.call(host, fileName, data, ...rest);
240241
};

0 commit comments

Comments
 (0)