@@ -574,7 +574,7 @@ namespace ts {
574
574
let diagnosticsProducingTypeChecker : TypeChecker ;
575
575
let noDiagnosticsTypeChecker : TypeChecker ;
576
576
let classifiableNames : UnderscoreEscapedMap < true > ;
577
- let modifiedFilePaths : Path [ ] | undefined ;
577
+ let unmodifiedSourceFilesWithAmbientModules : SourceFile [ ] | undefined ;
578
578
579
579
const cachedSemanticDiagnosticsForFile : DiagnosticCache < Diagnostic > = { } ;
580
580
const cachedDeclarationDiagnosticsForFile : DiagnosticCache < DiagnosticWithLocation > = { } ;
@@ -850,21 +850,14 @@ namespace ts {
850
850
return classifiableNames ;
851
851
}
852
852
853
- interface OldProgramState {
854
- program : Program | undefined ;
855
- oldSourceFile : SourceFile | undefined ;
856
- /** The collection of paths modified *since* the old program. */
857
- modifiedFilePaths : Path [ ] | undefined ;
858
- }
859
-
860
- function resolveModuleNamesReusingOldState ( moduleNames : string [ ] , containingFile : string , file : SourceFile , oldProgramState : OldProgramState ) {
853
+ function resolveModuleNamesReusingOldState ( moduleNames : string [ ] , containingFile : string , file : SourceFile ) {
861
854
if ( structuralIsReused === StructureIsReused . Not && ! file . ambientModuleNames . length ) {
862
855
// If the old program state does not permit reusing resolutions and `file` does not contain locally defined ambient modules,
863
856
// the best we can do is fallback to the default logic.
864
857
return resolveModuleNamesWorker ( moduleNames , containingFile ) ;
865
858
}
866
859
867
- const oldSourceFile = oldProgramState . program && oldProgramState . program . getSourceFile ( containingFile ) ;
860
+ const oldSourceFile = oldProgram && oldProgram . getSourceFile ( containingFile ) ;
868
861
if ( oldSourceFile !== file && file . resolvedModules ) {
869
862
// `file` was created for the new program.
870
863
//
@@ -928,7 +921,7 @@ namespace ts {
928
921
}
929
922
}
930
923
else {
931
- resolvesToAmbientModuleInNonModifiedFile = moduleNameResolvesToAmbientModuleInNonModifiedFile ( moduleName , oldProgramState ) ;
924
+ resolvesToAmbientModuleInNonModifiedFile = moduleNameResolvesToAmbientModuleInNonModifiedFile ( moduleName ) ;
932
925
}
933
926
934
927
if ( resolvesToAmbientModuleInNonModifiedFile ) {
@@ -971,12 +964,9 @@ namespace ts {
971
964
972
965
// If we change our policy of rechecking failed lookups on each program create,
973
966
// we should adjust the value returned here.
974
- function moduleNameResolvesToAmbientModuleInNonModifiedFile ( moduleName : string , oldProgramState : OldProgramState ) : boolean {
975
- if ( ! oldProgramState . program ) {
976
- return false ;
977
- }
978
- const resolutionToFile = getResolvedModule ( oldProgramState . oldSourceFile ! , moduleName ) ; // TODO: GH#18217
979
- const resolvedFile = resolutionToFile && oldProgramState . program . getSourceFile ( resolutionToFile . resolvedFileName ) ;
967
+ function moduleNameResolvesToAmbientModuleInNonModifiedFile ( moduleName : string ) : boolean {
968
+ const resolutionToFile = getResolvedModule ( oldSourceFile ! , moduleName ) ;
969
+ const resolvedFile = resolutionToFile && oldProgram ! . getSourceFile ( resolutionToFile . resolvedFileName ) ;
980
970
if ( resolutionToFile && resolvedFile && ! resolvedFile . externalModuleIndicator ) {
981
971
// In the old program, we resolved to an ambient module that was in the same
982
972
// place as we expected to find an actual module file.
@@ -986,8 +976,8 @@ namespace ts {
986
976
}
987
977
988
978
// at least one of declarations should come from non-modified source file
989
- const firstUnmodifiedFile = oldProgramState . program . getSourceFiles ( ) . find (
990
- f => ! contains ( oldProgramState . modifiedFilePaths , f . path ) && contains ( f . ambientModuleNames , moduleName )
979
+ const firstUnmodifiedFile = unmodifiedSourceFilesWithAmbientModules && unmodifiedSourceFilesWithAmbientModules . find (
980
+ f => contains ( f . ambientModuleNames , moduleName )
991
981
) ;
992
982
993
983
if ( ! firstUnmodifiedFile ) {
@@ -1188,14 +1178,14 @@ namespace ts {
1188
1178
return oldProgram . structureIsReused ;
1189
1179
}
1190
1180
1191
- modifiedFilePaths = modifiedSourceFiles . map ( f => f . newFile . path ) ;
1181
+ const modifiedFiles = modifiedSourceFiles . map ( f => f . oldFile ) ;
1182
+ unmodifiedSourceFilesWithAmbientModules = oldSourceFiles . filter ( ( f ) => ! ! f . ambientModuleNames . length && ! contains ( modifiedFiles , f ) ) ;
1192
1183
// try to verify results of module resolution
1193
1184
for ( const { oldFile : oldSourceFile , newFile : newSourceFile } of modifiedSourceFiles ) {
1194
1185
const newSourceFilePath = getNormalizedAbsolutePath ( newSourceFile . originalFileName , currentDirectory ) ;
1195
1186
if ( resolveModuleNamesWorker ) {
1196
1187
const moduleNames = getModuleNames ( newSourceFile ) ;
1197
- const oldProgramState : OldProgramState = { program : oldProgram , oldSourceFile, modifiedFilePaths } ;
1198
- const resolutions = resolveModuleNamesReusingOldState ( moduleNames , newSourceFilePath , newSourceFile , oldProgramState ) ;
1188
+ const resolutions = resolveModuleNamesReusingOldState ( moduleNames , newSourceFilePath , newSourceFile ) ;
1199
1189
// ensure that module resolution results are still correct
1200
1190
const resolutionsChanged = hasChangesInResolutions ( moduleNames , resolutions , oldSourceFile . resolvedModules , moduleResolutionIsEqualTo ) ;
1201
1191
if ( resolutionsChanged ) {
@@ -2308,8 +2298,7 @@ namespace ts {
2308
2298
if ( file . imports . length || file . moduleAugmentations . length ) {
2309
2299
// Because global augmentation doesn't have string literal name, we can check for global augmentation as such.
2310
2300
const moduleNames = getModuleNames ( file ) ;
2311
- const oldProgramState : OldProgramState = { program : oldProgram , oldSourceFile : oldProgram && oldProgram . getSourceFile ( file . fileName ) , modifiedFilePaths } ;
2312
- const resolutions = resolveModuleNamesReusingOldState ( moduleNames , getNormalizedAbsolutePath ( file . originalFileName , currentDirectory ) , file , oldProgramState ) ;
2301
+ const resolutions = resolveModuleNamesReusingOldState ( moduleNames , getNormalizedAbsolutePath ( file . originalFileName , currentDirectory ) , file ) ;
2313
2302
Debug . assert ( resolutions . length === moduleNames . length ) ;
2314
2303
for ( let i = 0 ; i < moduleNames . length ; i ++ ) {
2315
2304
const resolution = resolutions [ i ] ;
0 commit comments