@@ -847,6 +847,7 @@ namespace ts {
847
847
const cachedBindAndCheckDiagnosticsForFile : DiagnosticCache < Diagnostic > = { } ;
848
848
const cachedDeclarationDiagnosticsForFile : DiagnosticCache < DiagnosticWithLocation > = { } ;
849
849
850
+ let automaticTypeDirectiveNames : string [ ] | undefined ;
850
851
let resolvedTypeReferenceDirectives = new Map < string , ResolvedTypeReferenceDirectiveWithFailedLookupLocations > ( ) ;
851
852
let fileProcessingDiagnostics : FilePreprocessingDiagnostic [ ] | undefined ;
852
853
@@ -1023,16 +1024,16 @@ namespace ts {
1023
1024
tracing ?. pop ( ) ;
1024
1025
1025
1026
// 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 ;
1027
1028
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 } ) ;
1030
1031
// This containingFilename needs to match with the one used in managed-side
1031
1032
const containingDirectory = options . configFilePath ? getDirectoryPath ( options . configFilePath ) : host . getCurrentDirectory ( ) ;
1032
1033
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 } ) ;
1036
1037
}
1037
1038
tracing ?. pop ( ) ;
1038
1039
}
@@ -1136,6 +1137,7 @@ namespace ts {
1136
1137
getRelationCacheSizes : ( ) => getDiagnosticsProducingTypeChecker ( ) . getRelationCacheSizes ( ) ,
1137
1138
getFileProcessingDiagnostics : ( ) => fileProcessingDiagnostics ,
1138
1139
getResolvedTypeReferenceDirectives : ( ) => resolvedTypeReferenceDirectives ,
1140
+ getAutomaticTypeDirectiveNames : ( ) => automaticTypeDirectiveNames ! ,
1139
1141
isSourceFileFromExternalLibrary,
1140
1142
isSourceFileFromExternalLibraryPath,
1141
1143
isSourceFileDefaultLibrary,
@@ -1680,10 +1682,21 @@ namespace ts {
1680
1682
return structureIsReused ;
1681
1683
}
1682
1684
1683
- if ( changesAffectingProgramStructure ( oldOptions , options ) || host . hasChangedAutomaticTypeDirectiveNames ?. ( ) ) {
1685
+ if ( changesAffectingProgramStructure ( oldOptions , options ) ) {
1684
1686
return StructureIsReused . SafeModules ;
1685
1687
}
1686
1688
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
+
1687
1700
// update fileName -> file mapping
1688
1701
for ( let index = 0 ; index < newSourceFiles . length ; index ++ ) {
1689
1702
const newSourceFile = newSourceFiles [ index ] ;
@@ -1726,6 +1739,7 @@ namespace ts {
1726
1739
fileReasons = oldProgram . getFileIncludeReasons ( ) ;
1727
1740
fileProcessingDiagnostics = oldProgram . getFileProcessingDiagnostics ( ) ;
1728
1741
resolvedTypeReferenceDirectives = oldProgram . getResolvedTypeReferenceDirectives ( ) ;
1742
+ automaticTypeDirectiveNames = oldProgram . getAutomaticTypeDirectiveNames ( ) || emptyArray ;
1729
1743
1730
1744
sourceFileToPackageName = oldProgram . sourceFileToPackageName ;
1731
1745
redirectTargetsMap = oldProgram . redirectTargetsMap ;
0 commit comments