Skip to content

Commit

Permalink
Revert "Revert the fix"
Browse files Browse the repository at this point in the history
This reverts commit 5c98b9c.
  • Loading branch information
sheetalkamat committed Oct 31, 2022
1 parent 2c22989 commit 92bf32d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit 92bf32d

Please sign in to comment.