Skip to content

Commit 4649301

Browse files
committed
Simplify modified sourceFiles
1 parent 63226c2 commit 4649301

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/compiler/program.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,7 +2377,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
23772377

23782378
// check if program source files has changed in the way that can affect structure of the program
23792379
const newSourceFiles: SourceFile[] = [];
2380-
const modifiedSourceFiles: { oldFile: SourceFile; newFile: SourceFile; }[] = [];
2380+
const modifiedSourceFiles: SourceFile[] = [];
23812381
structureIsReused = StructureIsReused.Completely;
23822382

23832383
// If the missing file paths are now present, it can change the progam structure,
@@ -2489,14 +2489,19 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
24892489
}
24902490

24912491
// tentatively approve the file
2492-
modifiedSourceFiles.push({ oldFile: oldSourceFile, newFile: newSourceFile });
2492+
modifiedSourceFiles.push(newSourceFile);
24932493
}
24942494
else if (hasInvalidatedResolutions(oldSourceFile.path)) {
24952495
// 'module/types' references could have changed
24962496
structureIsReused = StructureIsReused.SafeModules;
24972497

24982498
// add file to the modified list so that we will resolve it later
2499-
modifiedSourceFiles.push({ oldFile: oldSourceFile, newFile: newSourceFile });
2499+
modifiedSourceFiles.push(newSourceFile);
2500+
}
2501+
else {
2502+
for (const moduleName of oldSourceFile.ambientModuleNames) {
2503+
ambientModuleNameToUnmodifiedFileName.set(moduleName, oldSourceFile.fileName);
2504+
}
25002505
}
25012506

25022507
// if file has passed all checks it should be safe to reuse it
@@ -2507,16 +2512,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
25072512
return structureIsReused;
25082513
}
25092514

2510-
const modifiedFiles = modifiedSourceFiles.map(f => f.oldFile);
2511-
for (const oldFile of oldSourceFiles) {
2512-
if (!contains(modifiedFiles, oldFile)) {
2513-
for (const moduleName of oldFile.ambientModuleNames) {
2514-
ambientModuleNameToUnmodifiedFileName.set(moduleName, oldFile.fileName);
2515-
}
2516-
}
2517-
}
25182515
// try to verify results of module resolution
2519-
for (const { newFile: newSourceFile } of modifiedSourceFiles) {
2516+
for (const newSourceFile of modifiedSourceFiles) {
25202517
const moduleNames = getModuleNames(newSourceFile);
25212518
const resolutions = resolveModuleNamesReusingOldState(moduleNames, newSourceFile);
25222519
const oldResolutions = oldProgram.resolvedModules?.get(newSourceFile.path);

0 commit comments

Comments
 (0)