Skip to content

Commit 92bf32d

Browse files
committed
Revert "Revert the fix"
This reverts commit 5c98b9c.
1 parent 2c22989 commit 92bf32d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/compiler/program.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ namespace ts {
171171
const readFileCache = new Map<string, string | false>();
172172
const fileExistsCache = new Map<string, boolean>();
173173
const directoryExistsCache = new Map<string, boolean>();
174-
const sourceFileCache = new Map<string, SourceFile>();
174+
const sourceFileCache = new Map<string, ESMap<SourceFile["impliedNodeFormat"], SourceFile>>();
175175

176176
const readFileWithCache = (fileName: string): string | undefined => {
177177
const key = toPath(fileName);
@@ -196,14 +196,16 @@ namespace ts {
196196
return setReadFileCache(key, fileName);
197197
};
198198

199-
const getSourceFileWithCache: CompilerHost["getSourceFile"] | undefined = getSourceFile ? (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
199+
const getSourceFileWithCache: CompilerHost["getSourceFile"] | undefined = getSourceFile ? (fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => {
200200
const key = toPath(fileName);
201-
const value = sourceFileCache.get(key);
201+
const impliedNodeFormat: SourceFile["impliedNodeFormat"] = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions.impliedNodeFormat : undefined;
202+
const forPath = sourceFileCache.get(key);
203+
const value = forPath?.get(impliedNodeFormat);
202204
if (value) return value;
203205

204-
const sourceFile = getSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile);
206+
const sourceFile = getSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile);
205207
if (sourceFile && (isDeclarationFileName(fileName) || fileExtensionIs(fileName, Extension.Json))) {
206-
sourceFileCache.set(key, sourceFile);
208+
sourceFileCache.set(key, (forPath || new Map()).set(impliedNodeFormat, sourceFile));
207209
}
208210
return sourceFile;
209211
} : undefined;
@@ -228,7 +230,8 @@ namespace ts {
228230
sourceFileCache.delete(key);
229231
}
230232
else if (getSourceFileWithCache) {
231-
const sourceFile = sourceFileCache.get(key);
233+
const sourceFileMap = sourceFileCache.get(key);
234+
const sourceFile = sourceFileMap && firstDefinedIterator(sourceFileMap.values(), identity);
232235
if (sourceFile && sourceFile.text !== data) {
233236
sourceFileCache.delete(key);
234237
}

0 commit comments

Comments
 (0)