@@ -594,7 +594,7 @@ namespace ts {
594
594
let diagnosticsProducingTypeChecker : TypeChecker ;
595
595
let noDiagnosticsTypeChecker : TypeChecker ;
596
596
let classifiableNames : UnderscoreEscapedMap < true > ;
597
- let modifiedFilePaths : Path [ ] | undefined ;
597
+ let unmodifiedSourceFilesWithAmbientModules : SourceFile [ ] | undefined ;
598
598
599
599
const cachedSemanticDiagnosticsForFile : DiagnosticCache < Diagnostic > = { } ;
600
600
const cachedDeclarationDiagnosticsForFile : DiagnosticCache < DiagnosticWithLocation > = { } ;
@@ -880,21 +880,14 @@ namespace ts {
880
880
return classifiableNames ;
881
881
}
882
882
883
- interface OldProgramState {
884
- program : Program | undefined ;
885
- oldSourceFile : SourceFile | undefined ;
886
- /** The collection of paths modified *since* the old program. */
887
- modifiedFilePaths : Path [ ] | undefined ;
888
- }
889
-
890
- function resolveModuleNamesReusingOldState ( moduleNames : string [ ] , containingFile : string , file : SourceFile , oldProgramState : OldProgramState ) {
883
+ function resolveModuleNamesReusingOldState ( moduleNames : string [ ] , containingFile : string , file : SourceFile ) {
891
884
if ( structuralIsReused === StructureIsReused . Not && ! file . ambientModuleNames . length ) {
892
885
// If the old program state does not permit reusing resolutions and `file` does not contain locally defined ambient modules,
893
886
// the best we can do is fallback to the default logic.
894
887
return resolveModuleNamesWorker ( moduleNames , containingFile , /*reusedNames*/ undefined , getResolvedProjectReferenceToRedirect ( file . originalFileName ) ) ;
895
888
}
896
889
897
- const oldSourceFile = oldProgramState . program && oldProgramState . program . getSourceFile ( containingFile ) ;
890
+ const oldSourceFile = oldProgram && oldProgram . getSourceFile ( containingFile ) ;
898
891
if ( oldSourceFile !== file && file . resolvedModules ) {
899
892
// `file` was created for the new program.
900
893
//
@@ -958,7 +951,7 @@ namespace ts {
958
951
}
959
952
}
960
953
else {
961
- resolvesToAmbientModuleInNonModifiedFile = moduleNameResolvesToAmbientModuleInNonModifiedFile ( moduleName , oldProgramState ) ;
954
+ resolvesToAmbientModuleInNonModifiedFile = moduleNameResolvesToAmbientModuleInNonModifiedFile ( moduleName ) ;
962
955
}
963
956
964
957
if ( resolvesToAmbientModuleInNonModifiedFile ) {
@@ -1001,12 +994,9 @@ namespace ts {
1001
994
1002
995
// If we change our policy of rechecking failed lookups on each program create,
1003
996
// we should adjust the value returned here.
1004
- function moduleNameResolvesToAmbientModuleInNonModifiedFile ( moduleName : string , oldProgramState : OldProgramState ) : boolean {
1005
- if ( ! oldProgramState . program ) {
1006
- return false ;
1007
- }
1008
- const resolutionToFile = getResolvedModule ( oldProgramState . oldSourceFile ! , moduleName ) ; // TODO: GH#18217
1009
- const resolvedFile = resolutionToFile && oldProgramState . program . getSourceFile ( resolutionToFile . resolvedFileName ) ;
997
+ function moduleNameResolvesToAmbientModuleInNonModifiedFile ( moduleName : string ) : boolean {
998
+ const resolutionToFile = getResolvedModule ( oldSourceFile ! , moduleName ) ;
999
+ const resolvedFile = resolutionToFile && oldProgram ! . getSourceFile ( resolutionToFile . resolvedFileName ) ;
1010
1000
if ( resolutionToFile && resolvedFile && ! resolvedFile . externalModuleIndicator ) {
1011
1001
// In the old program, we resolved to an ambient module that was in the same
1012
1002
// place as we expected to find an actual module file.
@@ -1016,8 +1006,8 @@ namespace ts {
1016
1006
}
1017
1007
1018
1008
// at least one of declarations should come from non-modified source file
1019
- const firstUnmodifiedFile = oldProgramState . program . getSourceFiles ( ) . find (
1020
- f => ! contains ( oldProgramState . modifiedFilePaths , f . path ) && contains ( f . ambientModuleNames , moduleName )
1009
+ const firstUnmodifiedFile = unmodifiedSourceFilesWithAmbientModules && unmodifiedSourceFilesWithAmbientModules . find (
1010
+ f => contains ( f . ambientModuleNames , moduleName )
1021
1011
) ;
1022
1012
1023
1013
if ( ! firstUnmodifiedFile ) {
@@ -1213,14 +1203,14 @@ namespace ts {
1213
1203
return oldProgram . structureIsReused ;
1214
1204
}
1215
1205
1216
- modifiedFilePaths = modifiedSourceFiles . map ( f => f . newFile . path ) ;
1206
+ const modifiedFiles = modifiedSourceFiles . map ( f => f . oldFile ) ;
1207
+ unmodifiedSourceFilesWithAmbientModules = oldSourceFiles . filter ( ( f ) => ! ! f . ambientModuleNames . length && ! contains ( modifiedFiles , f ) ) ;
1217
1208
// try to verify results of module resolution
1218
1209
for ( const { oldFile : oldSourceFile , newFile : newSourceFile } of modifiedSourceFiles ) {
1219
1210
const newSourceFilePath = getNormalizedAbsolutePath ( newSourceFile . originalFileName , currentDirectory ) ;
1220
1211
if ( resolveModuleNamesWorker ) {
1221
1212
const moduleNames = getModuleNames ( newSourceFile ) ;
1222
- const oldProgramState : OldProgramState = { program : oldProgram , oldSourceFile, modifiedFilePaths } ;
1223
- const resolutions = resolveModuleNamesReusingOldState ( moduleNames , newSourceFilePath , newSourceFile , oldProgramState ) ;
1213
+ const resolutions = resolveModuleNamesReusingOldState ( moduleNames , newSourceFilePath , newSourceFile ) ;
1224
1214
// ensure that module resolution results are still correct
1225
1215
const resolutionsChanged = hasChangesInResolutions ( moduleNames , resolutions , oldSourceFile . resolvedModules , moduleResolutionIsEqualTo ) ;
1226
1216
if ( resolutionsChanged ) {
@@ -2422,8 +2412,7 @@ namespace ts {
2422
2412
if ( file . imports . length || file . moduleAugmentations . length ) {
2423
2413
// Because global augmentation doesn't have string literal name, we can check for global augmentation as such.
2424
2414
const moduleNames = getModuleNames ( file ) ;
2425
- const oldProgramState : OldProgramState = { program : oldProgram , oldSourceFile : oldProgram && oldProgram . getSourceFile ( file . fileName ) , modifiedFilePaths } ;
2426
- const resolutions = resolveModuleNamesReusingOldState ( moduleNames , getNormalizedAbsolutePath ( file . originalFileName , currentDirectory ) , file , oldProgramState ) ;
2415
+ const resolutions = resolveModuleNamesReusingOldState ( moduleNames , getNormalizedAbsolutePath ( file . originalFileName , currentDirectory ) , file ) ;
2427
2416
Debug . assert ( resolutions . length === moduleNames . length ) ;
2428
2417
for ( let i = 0 ; i < moduleNames . length ; i ++ ) {
2429
2418
const resolution = resolutions [ i ] ;
0 commit comments