Skip to content

Commit 155cbf9

Browse files
committed
Some more updates to module resolution reuse
1 parent e5b2755 commit 155cbf9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/compiler/program.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ namespace ts {
851851
});
852852

853853
const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles(oldProgram, options);
854-
// We set `structuralIsReused` to `undefined` because `tryReuseStructureFromOldProgram` calls `tryReuseStructureFromOldProgram` which checks
854+
// We set `structuralIsReused` to `undefined` because `tryReuseStructureFromOldProgram` calls `resolveModuleNamesReusingOldState` which checks
855855
// `structuralIsReused`, which would be a TDZ violation if it was not set in advance to `undefined`.
856856
let structureIsReused: StructureIsReused;
857857
structureIsReused = tryReuseStructureFromOldProgram(); // eslint-disable-line prefer-const
@@ -1184,7 +1184,7 @@ namespace ts {
11841184
for (let i = 0; i < moduleNames.length; i++) {
11851185
const moduleName = moduleNames[i];
11861186
// If the source file is unchanged and doesnt have invalidated resolution, reuse the module resolutions
1187-
if (file === oldSourceFile && !hasInvalidatedResolution(oldSourceFile.path)) {
1187+
if (oldSourceFile && file.version === oldSourceFile.version && !hasInvalidatedResolution(oldSourceFile.path)) {
11881188
const oldResolvedModule = oldProgram!.getPerFileModuleResolutions().get(file.path)?.get(moduleName);
11891189
if (oldResolvedModule?.resolvedModule) {
11901190
if (isTraceEnabled(options, host)) {
@@ -1473,7 +1473,9 @@ namespace ts {
14731473
(modifiedSourceFiles ||= []).push(newSourceFile);
14741474
}
14751475
else {
1476-
for (const moduleName of oldSourceFile.ambientModuleNames) {
1476+
// Ensure imports are calculated if the file version didnt change so but its different instance of file
1477+
collectExternalModuleReferences(newSourceFile);
1478+
for (const moduleName of newSourceFile.ambientModuleNames) {
14771479
(ambientModuleNameToUnmodifiedFileNameUsingOldProgram ||= new Map()).set(moduleName, oldSourceFile.fileName);
14781480
}
14791481
}
@@ -1544,8 +1546,6 @@ namespace ts {
15441546
}
15451547
else {
15461548
filesByName.set(newSourceFile.path, newSourceFile);
1547-
// Ensure imports are calculated if the file version didnt change so but its different instance of file
1548-
collectExternalModuleReferences(newSourceFile);
15491549
}
15501550
});
15511551
const oldFilesByNameMap = oldProgram.getFilesByNameMap();

0 commit comments

Comments
 (0)