@@ -951,25 +951,23 @@ namespace ts {
951
951
// If we change our policy of rechecking failed lookups on each program create,
952
952
// we should adjust the value returned here.
953
953
function moduleNameResolvesToAmbientModuleInNonModifiedFile ( moduleName : string , oldProgramState : OldProgramState ) : boolean {
954
+ if ( ! oldProgramState . program ) {
955
+ return false ;
956
+ }
954
957
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 ) ;
956
959
if ( resolutionToFile && resolvedFile && ! resolvedFile . externalModuleIndicator ) {
957
960
// In the old program, we resolved to an ambient module that was in the same
958
961
// place as we expected to find an actual module file.
959
962
// We actually need to return 'false' here even though this seems like a 'true' case
960
963
// because the normal module resolution algorithm will find this anyway.
961
964
return false ;
962
965
}
963
- const ambientModule = oldProgramState . program && oldProgramState . program . getTypeChecker ( ) . tryFindAmbientModuleWithoutAugmentations ( moduleName ) ;
964
- if ( ! ( ambientModule && ambientModule . declarations ) ) {
965
- return false ;
966
- }
967
966
968
967
// 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
+ ) ;
973
971
974
972
if ( ! firstUnmodifiedFile ) {
975
973
return false ;
0 commit comments