@@ -847,6 +847,7 @@ namespace ts {
847847 const cachedBindAndCheckDiagnosticsForFile : DiagnosticCache < Diagnostic > = { } ;
848848 const cachedDeclarationDiagnosticsForFile : DiagnosticCache < DiagnosticWithLocation > = { } ;
849849
850+ let automaticTypeDirectiveNames : string [ ] | undefined ;
850851 let resolvedTypeReferenceDirectives = new Map < string , ResolvedTypeReferenceDirectiveWithFailedLookupLocations > ( ) ;
851852 let fileProcessingDiagnostics : FilePreprocessingDiagnostic [ ] | undefined ;
852853
@@ -1023,16 +1024,16 @@ namespace ts {
10231024 tracing ?. pop ( ) ;
10241025
10251026 // load type declarations specified via 'types' argument or implicitly from types/ and node_modules/@types folders
1026- const typeReferences : string [ ] = rootNames . length ? getAutomaticTypeDirectiveNames ( options , host ) : emptyArray ;
1027+ automaticTypeDirectiveNames || = rootNames . length ? getAutomaticTypeDirectiveNames ( options , host ) : emptyArray ;
10271028
1028- if ( typeReferences . length ) {
1029- tracing ?. push ( tracing . Phase . Program , "processTypeReferences" , { count : typeReferences . length } ) ;
1029+ if ( automaticTypeDirectiveNames . length ) {
1030+ tracing ?. push ( tracing . Phase . Program , "processTypeReferences" , { count : automaticTypeDirectiveNames . length } ) ;
10301031 // This containingFilename needs to match with the one used in managed-side
10311032 const containingDirectory = options . configFilePath ? getDirectoryPath ( options . configFilePath ) : host . getCurrentDirectory ( ) ;
10321033 const containingFilename = combinePaths ( containingDirectory , inferredTypesContainingFile ) ;
1033- const resolutions = resolveTypeReferenceDirectiveNamesWorker ( typeReferences , containingFilename ) ;
1034- for ( let i = 0 ; i < typeReferences . length ; i ++ ) {
1035- processTypeReferenceDirective ( typeReferences [ i ] , resolutions [ i ] , { kind : FileIncludeKind . AutomaticTypeDirectiveFile , typeReference : typeReferences [ i ] , packageId : resolutions [ i ] ?. resolvedTypeReferenceDirective ?. packageId } ) ;
1034+ const resolutions = resolveTypeReferenceDirectiveNamesWorker ( automaticTypeDirectiveNames , containingFilename ) ;
1035+ for ( let i = 0 ; i < automaticTypeDirectiveNames . length ; i ++ ) {
1036+ processTypeReferenceDirective ( automaticTypeDirectiveNames [ i ] , resolutions [ i ] , { kind : FileIncludeKind . AutomaticTypeDirectiveFile , typeReference : automaticTypeDirectiveNames [ i ] , packageId : resolutions [ i ] ?. resolvedTypeReferenceDirective ?. packageId } ) ;
10361037 }
10371038 tracing ?. pop ( ) ;
10381039 }
@@ -1136,6 +1137,7 @@ namespace ts {
11361137 getRelationCacheSizes : ( ) => getDiagnosticsProducingTypeChecker ( ) . getRelationCacheSizes ( ) ,
11371138 getFileProcessingDiagnostics : ( ) => fileProcessingDiagnostics ,
11381139 getResolvedTypeReferenceDirectives : ( ) => resolvedTypeReferenceDirectives ,
1140+ getAutomaticTypeDirectiveNames : ( ) => automaticTypeDirectiveNames ! ,
11391141 isSourceFileFromExternalLibrary,
11401142 isSourceFileFromExternalLibraryPath,
11411143 isSourceFileDefaultLibrary,
@@ -1680,10 +1682,21 @@ namespace ts {
16801682 return structureIsReused ;
16811683 }
16821684
1683- if ( changesAffectingProgramStructure ( oldOptions , options ) || host . hasChangedAutomaticTypeDirectiveNames ?. ( ) ) {
1685+ if ( changesAffectingProgramStructure ( oldOptions , options ) ) {
16841686 return StructureIsReused . SafeModules ;
16851687 }
16861688
1689+ if ( host . hasChangedAutomaticTypeDirectiveNames ) {
1690+ if ( host . hasChangedAutomaticTypeDirectiveNames ( ) ) return StructureIsReused . SafeModules ;
1691+ }
1692+ else {
1693+ // See if auto type reference directives have changed
1694+ automaticTypeDirectiveNames = rootNames . length ? getAutomaticTypeDirectiveNames ( options , host ) : emptyArray ;
1695+ if ( ! arrayIsEqualTo ( automaticTypeDirectiveNames , oldProgram . getAutomaticTypeDirectiveNames ( ) || emptyArray ) ) {
1696+ return StructureIsReused . SafeModules ;
1697+ }
1698+ }
1699+
16871700 // update fileName -> file mapping
16881701 for ( let index = 0 ; index < newSourceFiles . length ; index ++ ) {
16891702 const newSourceFile = newSourceFiles [ index ] ;
@@ -1726,6 +1739,7 @@ namespace ts {
17261739 fileReasons = oldProgram . getFileIncludeReasons ( ) ;
17271740 fileProcessingDiagnostics = oldProgram . getFileProcessingDiagnostics ( ) ;
17281741 resolvedTypeReferenceDirectives = oldProgram . getResolvedTypeReferenceDirectives ( ) ;
1742+ automaticTypeDirectiveNames = oldProgram . getAutomaticTypeDirectiveNames ( ) || emptyArray ;
17291743
17301744 sourceFileToPackageName = oldProgram . sourceFileToPackageName ;
17311745 redirectTargetsMap = oldProgram . redirectTargetsMap ;
0 commit comments