Skip to content

Commit 6df6127

Browse files
committed
createProgram: don't use TypeChecker
Avoids using the TypeChecker when trying to reuse the Program structure. This allows SourceFiles contained in the old Program to be updated using ts.updateSourceFile Fixes: #26166
1 parent 9df8831 commit 6df6127

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/compiler/program.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -951,25 +951,23 @@ namespace ts {
951951
// If we change our policy of rechecking failed lookups on each program create,
952952
// we should adjust the value returned here.
953953
function moduleNameResolvesToAmbientModuleInNonModifiedFile(moduleName: string, oldProgramState: OldProgramState): boolean {
954+
if (!oldProgramState.program) {
955+
return false;
956+
}
954957
const resolutionToFile = getResolvedModule(oldProgramState.oldSourceFile!, moduleName); // TODO: GH#18217
955-
const resolvedFile = resolutionToFile && oldProgramState.program && oldProgramState.program.getSourceFile(resolutionToFile.resolvedFileName);
958+
const resolvedFile = resolutionToFile && oldProgramState.program.getSourceFile(resolutionToFile.resolvedFileName);
956959
if (resolutionToFile && resolvedFile && !resolvedFile.externalModuleIndicator) {
957960
// In the old program, we resolved to an ambient module that was in the same
958961
// place as we expected to find an actual module file.
959962
// We actually need to return 'false' here even though this seems like a 'true' case
960963
// because the normal module resolution algorithm will find this anyway.
961964
return false;
962965
}
963-
const ambientModule = oldProgramState.program && oldProgramState.program.getTypeChecker().tryFindAmbientModuleWithoutAugmentations(moduleName);
964-
if (!(ambientModule && ambientModule.declarations)) {
965-
return false;
966-
}
967966

968967
// at least one of declarations should come from non-modified source file
969-
const firstUnmodifiedFile = forEach(ambientModule.declarations, d => {
970-
const f = getSourceFileOfNode(d);
971-
return !contains(oldProgramState.modifiedFilePaths, f.path) && f;
972-
});
968+
const firstUnmodifiedFile = oldProgramState.program.getSourceFiles().find(
969+
f => !contains(oldProgramState.modifiedFilePaths, f.path) && contains(f.ambientModuleNames, moduleName)
970+
);
973971

974972
if (!firstUnmodifiedFile) {
975973
return false;

0 commit comments

Comments
 (0)