Revert "Revert the fix"

This reverts commit 5c98b9cfc1.
This commit is contained in:
Sheetal Nandi
2022-10-31 10:22:42 -07:00
parent 2c22989bd5
commit 92bf32dcf5
+9 -6
View File
@@ -171,7 +171,7 @@ namespace ts {
const readFileCache = new Map<string, string | false>();
const fileExistsCache = new Map<string, boolean>();
const directoryExistsCache = new Map<string, boolean>();
const sourceFileCache = new Map<string, SourceFile>();
const sourceFileCache = new Map<string, ESMap<SourceFile["impliedNodeFormat"], SourceFile>>();
const readFileWithCache = (fileName: string): string | undefined => {
const key = toPath(fileName);
@@ -196,14 +196,16 @@ namespace ts {
return setReadFileCache(key, fileName);
};
const getSourceFileWithCache: CompilerHost["getSourceFile"] | undefined = getSourceFile ? (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
const getSourceFileWithCache: CompilerHost["getSourceFile"] | undefined = getSourceFile ? (fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => {
const key = toPath(fileName);
const value = sourceFileCache.get(key);
const impliedNodeFormat: SourceFile["impliedNodeFormat"] = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions.impliedNodeFormat : undefined;
const forPath = sourceFileCache.get(key);
const value = forPath?.get(impliedNodeFormat);
if (value) return value;
const sourceFile = getSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile);
const sourceFile = getSourceFile(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile);
if (sourceFile && (isDeclarationFileName(fileName) || fileExtensionIs(fileName, Extension.Json))) {
sourceFileCache.set(key, sourceFile);
sourceFileCache.set(key, (forPath || new Map()).set(impliedNodeFormat, sourceFile));
}
return sourceFile;
} : undefined;
@@ -228,7 +230,8 @@ namespace ts {
sourceFileCache.delete(key);
}
else if (getSourceFileWithCache) {
const sourceFile = sourceFileCache.get(key);
const sourceFileMap = sourceFileCache.get(key);
const sourceFile = sourceFileMap && firstDefinedIterator(sourceFileMap.values(), identity);
if (sourceFile && sourceFile.text !== data) {
sourceFileCache.delete(key);
}