@@ -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,
@@ -1675,10 +1677,21 @@ namespace ts {
1675
1677
return structureIsReused ;
1676
1678
}
1677
1679
1678
- if ( changesAffectingProgramStructure ( oldProgram . getCompilerOptions ( ) , options ) || host . hasChangedAutomaticTypeDirectiveNames ?. ( ) ) {
1680
+ if ( changesAffectingProgramStructure ( oldProgram . getCompilerOptions ( ) , options ) ) {
1679
1681
return StructureIsReused . SafeModules ;
1680
1682
}
1681
1683
1684
+ if ( host . hasChangedAutomaticTypeDirectiveNames ) {
1685
+ if ( host . hasChangedAutomaticTypeDirectiveNames ( ) ) return StructureIsReused . SafeModules ;
1686
+ }
1687
+ else {
1688
+ // See if auto type reference directives have changed
1689
+ automaticTypeDirectiveNames = rootNames . length ? getAutomaticTypeDirectiveNames ( options , host ) : emptyArray ;
1690
+ if ( ! arrayIsEqualTo ( automaticTypeDirectiveNames , oldProgram . getAutomaticTypeDirectiveNames ( ) || emptyArray ) ) {
1691
+ return StructureIsReused . SafeModules ;
1692
+ }
1693
+ }
1694
+
1682
1695
// update fileName -> file mapping
1683
1696
for ( let index = 0 ; index < newSourceFiles . length ; index ++ ) {
1684
1697
const newSourceFile = newSourceFiles [ index ] ;
@@ -1721,6 +1734,7 @@ namespace ts {
1721
1734
fileReasons = oldProgram . getFileIncludeReasons ( ) ;
1722
1735
fileProcessingDiagnostics = oldProgram . getFileProcessingDiagnostics ( ) ;
1723
1736
resolvedTypeReferenceDirectives = oldProgram . getResolvedTypeReferenceDirectives ( ) ;
1737
+ automaticTypeDirectiveNames = oldProgram . getAutomaticTypeDirectiveNames ( ) || emptyArray ;
1724
1738
1725
1739
sourceFileToPackageName = oldProgram . sourceFileToPackageName ;
1726
1740
redirectTargetsMap = oldProgram . redirectTargetsMap ;
0 commit comments