@@ -704,7 +704,7 @@ namespace ts {
704
704
705
705
interface OldProgramState {
706
706
program : Program | undefined ;
707
- file : SourceFile ;
707
+ oldSourceFile : SourceFile | undefined ;
708
708
/** The collection of paths modified *since* the old program. */
709
709
modifiedFilePaths : Path [ ] ;
710
710
}
@@ -754,7 +754,6 @@ namespace ts {
754
754
/** A transient placeholder used to mark predicted resolution in the result list. */
755
755
const predictedToResolveToAmbientModuleMarker : ResolvedModuleFull = < any > { } ;
756
756
757
-
758
757
for ( let i = 0 ; i < moduleNames . length ; i ++ ) {
759
758
const moduleName = moduleNames [ i ] ;
760
759
// If the source file is unchanged and doesnt have invalidated resolution, reuse the module resolutions
@@ -825,9 +824,10 @@ namespace ts {
825
824
// If we change our policy of rechecking failed lookups on each program create,
826
825
// we should adjust the value returned here.
827
826
function moduleNameResolvesToAmbientModuleInNonModifiedFile ( moduleName : string , oldProgramState : OldProgramState ) : boolean {
828
- const resolutionToFile = getResolvedModule ( oldProgramState . file , moduleName ) ;
829
- if ( resolutionToFile ) {
830
- // module used to be resolved to file - ignore it
827
+ const resolutionToFile = getResolvedModule ( oldProgramState . oldSourceFile , moduleName ) ;
828
+ const resolvedFile = resolutionToFile && oldProgramState . program && oldProgramState . program . getSourceFile ( resolutionToFile . resolvedFileName ) ;
829
+ if ( resolutionToFile && ! resolvedFile . externalModuleIndicator ) {
830
+ // module used to be resolved to module - ignore it
831
831
return false ;
832
832
}
833
833
const ambientModule = oldProgramState . program && oldProgramState . program . getTypeChecker ( ) . tryFindAmbientModuleWithoutAugmentations ( moduleName ) ;
@@ -1001,7 +1001,7 @@ namespace ts {
1001
1001
const newSourceFilePath = getNormalizedAbsolutePath ( newSourceFile . fileName , currentDirectory ) ;
1002
1002
if ( resolveModuleNamesWorker ) {
1003
1003
const moduleNames = getModuleNames ( newSourceFile ) ;
1004
- const oldProgramState = { program : oldProgram , file : oldSourceFile , modifiedFilePaths } ;
1004
+ const oldProgramState : OldProgramState = { program : oldProgram , oldSourceFile, modifiedFilePaths } ;
1005
1005
const resolutions = resolveModuleNamesReusingOldState ( moduleNames , newSourceFilePath , newSourceFile , oldProgramState ) ;
1006
1006
// ensure that module resolution results are still correct
1007
1007
const resolutionsChanged = hasChangesInResolutions ( moduleNames , resolutions , oldSourceFile . resolvedModules , moduleResolutionIsEqualTo ) ;
@@ -1945,7 +1945,7 @@ namespace ts {
1945
1945
if ( file . imports . length || file . moduleAugmentations . length ) {
1946
1946
// Because global augmentation doesn't have string literal name, we can check for global augmentation as such.
1947
1947
const moduleNames = getModuleNames ( file ) ;
1948
- const oldProgramState = { program : oldProgram , file, modifiedFilePaths } ;
1948
+ const oldProgramState : OldProgramState = { program : oldProgram , oldSourceFile : oldProgram && oldProgram . getSourceFile ( file . fileName ) , modifiedFilePaths } ;
1949
1949
const resolutions = resolveModuleNamesReusingOldState ( moduleNames , getNormalizedAbsolutePath ( file . fileName , currentDirectory ) , file , oldProgramState ) ;
1950
1950
Debug . assert ( resolutions . length === moduleNames . length ) ;
1951
1951
for ( let i = 0 ; i < moduleNames . length ; i ++ ) {
0 commit comments