Program cannot be reused if the missing file is now present
Also dont update filesByName array just to update missing file paths
This commit is contained in:
parent
273569f6fe
commit
94a589b3bb
|
@ -473,6 +473,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
const filesByName = createMap<SourceFile | undefined>();
|
const filesByName = createMap<SourceFile | undefined>();
|
||||||
|
let missingFilePaths: Path[];
|
||||||
// stores 'filename -> file association' ignoring case
|
// stores 'filename -> file association' ignoring case
|
||||||
// used to track cases when two file names differ only in casing
|
// used to track cases when two file names differ only in casing
|
||||||
const filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? createMap<SourceFile>() : undefined;
|
const filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? createMap<SourceFile>() : undefined;
|
||||||
|
@ -511,9 +512,9 @@ namespace ts {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const missingFilePaths = arrayFrom(filesByName.keys(), p => <Path>p).filter(p => !filesByName.get(p));
|
missingFilePaths = arrayFrom(filesByName.keys(), p => <Path>p).filter(p => !filesByName.get(p));
|
||||||
|
}
|
||||||
|
|
||||||
// unconditionally set moduleResolutionCache to undefined to avoid unnecessary leaks
|
// unconditionally set moduleResolutionCache to undefined to avoid unnecessary leaks
|
||||||
moduleResolutionCache = undefined;
|
moduleResolutionCache = undefined;
|
||||||
|
@ -773,6 +774,13 @@ namespace ts {
|
||||||
const modifiedSourceFiles: { oldFile: SourceFile, newFile: SourceFile }[] = [];
|
const modifiedSourceFiles: { oldFile: SourceFile, newFile: SourceFile }[] = [];
|
||||||
oldProgram.structureIsReused = StructureIsReused.Completely;
|
oldProgram.structureIsReused = StructureIsReused.Completely;
|
||||||
|
|
||||||
|
// If the missing file paths are now present, it can change the progam structure,
|
||||||
|
// and hence cant reuse the structure.
|
||||||
|
// This is same as how we dont reuse the structure if one of the file from old program is now missing
|
||||||
|
if (oldProgram.getMissingFilePaths().some(missingFilePath => host.fileExists(missingFilePath))) {
|
||||||
|
return oldProgram.structureIsReused = StructureIsReused.Not;
|
||||||
|
}
|
||||||
|
|
||||||
for (const oldSourceFile of oldProgram.getSourceFiles()) {
|
for (const oldSourceFile of oldProgram.getSourceFiles()) {
|
||||||
const newSourceFile = host.getSourceFileByPath
|
const newSourceFile = host.getSourceFileByPath
|
||||||
? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.path, options.target)
|
? host.getSourceFileByPath(oldSourceFile.fileName, oldSourceFile.path, options.target)
|
||||||
|
@ -869,20 +877,7 @@ namespace ts {
|
||||||
return oldProgram.structureIsReused;
|
return oldProgram.structureIsReused;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a file has ceased to be missing, then we need to discard some of the old
|
missingFilePaths = oldProgram.getMissingFilePaths();
|
||||||
// structure in order to pick it up.
|
|
||||||
// Caution: if the file has created and then deleted between since it was discovered to
|
|
||||||
// be missing, then the corresponding file watcher will have been closed and no new one
|
|
||||||
// will be created until we encounter a change that prevents complete structure reuse.
|
|
||||||
// During this interval, creation of the file will go unnoticed. We expect this to be
|
|
||||||
// both rare and low-impact.
|
|
||||||
if (oldProgram.getMissingFilePaths().some(missingFilePath => host.fileExists(missingFilePath))) {
|
|
||||||
return oldProgram.structureIsReused = StructureIsReused.SafeModules;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const p of oldProgram.getMissingFilePaths()) {
|
|
||||||
filesByName.set(p, undefined);
|
|
||||||
}
|
|
||||||
|
|
||||||
// update fileName -> file mapping
|
// update fileName -> file mapping
|
||||||
for (let i = 0; i < newSourceFiles.length; i++) {
|
for (let i = 0; i < newSourceFiles.length; i++) {
|
||||||
|
|
|
@ -338,7 +338,7 @@ namespace ts {
|
||||||
const program_2 = updateProgram(program_1, ["a.ts"], options, noop, newTexts);
|
const program_2 = updateProgram(program_1, ["a.ts"], options, noop, newTexts);
|
||||||
assert.deepEqual(emptyArray, program_2.getMissingFilePaths());
|
assert.deepEqual(emptyArray, program_2.getMissingFilePaths());
|
||||||
|
|
||||||
assert.equal(StructureIsReused.SafeModules, program_1.structureIsReused);
|
assert.equal(StructureIsReused.Not, program_1.structureIsReused);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("resolution cache follows imports", () => {
|
it("resolution cache follows imports", () => {
|
||||||
|
|
Loading…
Reference in a new issue