From 6df61272f3058db3c13f820009f8a2595d47a5a7 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Fri, 3 Aug 2018 17:54:15 +0200 Subject: [PATCH] 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 --- src/compiler/program.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c70477b4a17..14063029c59 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -951,8 +951,11 @@ namespace ts { // If we change our policy of rechecking failed lookups on each program create, // we should adjust the value returned here. function moduleNameResolvesToAmbientModuleInNonModifiedFile(moduleName: string, oldProgramState: OldProgramState): boolean { + if (!oldProgramState.program) { + return false; + } const resolutionToFile = getResolvedModule(oldProgramState.oldSourceFile!, moduleName); // TODO: GH#18217 - const resolvedFile = resolutionToFile && oldProgramState.program && oldProgramState.program.getSourceFile(resolutionToFile.resolvedFileName); + const resolvedFile = resolutionToFile && oldProgramState.program.getSourceFile(resolutionToFile.resolvedFileName); if (resolutionToFile && resolvedFile && !resolvedFile.externalModuleIndicator) { // In the old program, we resolved to an ambient module that was in the same // place as we expected to find an actual module file. @@ -960,16 +963,11 @@ namespace ts { // because the normal module resolution algorithm will find this anyway. return false; } - const ambientModule = oldProgramState.program && oldProgramState.program.getTypeChecker().tryFindAmbientModuleWithoutAugmentations(moduleName); - if (!(ambientModule && ambientModule.declarations)) { - return false; - } // at least one of declarations should come from non-modified source file - const firstUnmodifiedFile = forEach(ambientModule.declarations, d => { - const f = getSourceFileOfNode(d); - return !contains(oldProgramState.modifiedFilePaths, f.path) && f; - }); + const firstUnmodifiedFile = oldProgramState.program.getSourceFiles().find( + f => !contains(oldProgramState.modifiedFilePaths, f.path) && contains(f.ambientModuleNames, moduleName) + ); if (!firstUnmodifiedFile) { return false;