@@ -1577,7 +1577,10 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
1577
1577
let oldProgram = typeof oldProgramOrOldBuildInfoProgramConstructor === "object" ? oldProgramOrOldBuildInfoProgramConstructor : undefined ;
1578
1578
let oldBuildInfoProgram : OldBuildInfoProgram | undefined ;
1579
1579
if ( ! oldProgram && typeof oldProgramOrOldBuildInfoProgramConstructor === "function" ) {
1580
- oldBuildInfoProgram = oldProgramOrOldBuildInfoProgramConstructor ( host ) ;
1580
+ oldBuildInfoProgram = oldProgramOrOldBuildInfoProgramConstructor ( {
1581
+ fileExists : fileName => host . fileExists ( fileName ) ,
1582
+ getCompilerOptions : ( ) => options ,
1583
+ } ) ;
1581
1584
}
1582
1585
1583
1586
// Map from a stringified PackageId to the source file with that id.
@@ -1810,6 +1813,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
1810
1813
getProjectReferenceRedirect,
1811
1814
getResolvedProjectReferenceToRedirect,
1812
1815
getResolvedProjectReferenceByPath,
1816
+ getRedirectReferenceForResolution,
1813
1817
forEachResolvedProjectReference,
1814
1818
isSourceOfProjectReferenceRedirect,
1815
1819
emitBuildInfo,
@@ -1873,27 +1877,37 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
1873
1877
if ( fromCache ) addResolutionDiagnostics ( fromCache ) ;
1874
1878
}
1875
1879
1876
- function resolveModuleNamesWorker ( moduleNames : readonly StringLiteralLike [ ] , containingFile : SourceFile , reusedNames : readonly StringLiteralLike [ ] | undefined ) : readonly ResolvedModuleWithFailedLookupLocations [ ] {
1880
+ function resolveModuleNamesWorker (
1881
+ moduleNames : readonly StringLiteralLike [ ] ,
1882
+ containingFile : SourceFile ,
1883
+ reusedNames : readonly StringLiteralLike [ ] | undefined ,
1884
+ redirectedReference : ResolvedProjectReference | false | undefined ,
1885
+ ) : readonly ResolvedModuleWithFailedLookupLocations [ ] {
1877
1886
if ( ! moduleNames . length ) return emptyArray ;
1878
1887
const containingFileName = getNormalizedAbsolutePath ( containingFile . originalFileName , currentDirectory ) ;
1879
- const redirectedReference = getRedirectReferenceForResolution ( containingFile ) ;
1888
+ if ( redirectedReference === undefined ) redirectedReference = getRedirectReferenceForResolution ( containingFile ) ;
1880
1889
tracing ?. push ( tracing . Phase . Program , "resolveModuleNamesWorker" , { containingFileName } ) ;
1881
1890
performance . mark ( "beforeResolveModule" ) ;
1882
- const result = actualResolveModuleNamesWorker ( moduleNames , containingFileName , redirectedReference , options , containingFile , reusedNames ) ;
1891
+ const result = actualResolveModuleNamesWorker ( moduleNames , containingFileName , redirectedReference || undefined , options , containingFile , reusedNames ) ;
1883
1892
performance . mark ( "afterResolveModule" ) ;
1884
1893
performance . measure ( "ResolveModule" , "beforeResolveModule" , "afterResolveModule" ) ;
1885
1894
tracing ?. pop ( ) ;
1886
1895
return result ;
1887
1896
}
1888
1897
1889
- function resolveTypeReferenceDirectiveNamesWorker < T extends FileReference | string > ( typeDirectiveNames : T [ ] , containingFile : string | SourceFile , reusedNames : readonly T [ ] | undefined ) : readonly ResolvedTypeReferenceDirectiveWithFailedLookupLocations [ ] {
1898
+ function resolveTypeReferenceDirectiveNamesWorker < T extends FileReference | string > (
1899
+ typeDirectiveNames : T [ ] ,
1900
+ containingFile : string | SourceFile ,
1901
+ reusedNames : readonly T [ ] | undefined ,
1902
+ redirectedReference : ResolvedProjectReference | false | undefined ,
1903
+ ) : readonly ResolvedTypeReferenceDirectiveWithFailedLookupLocations [ ] {
1890
1904
if ( ! typeDirectiveNames . length ) return [ ] ;
1891
1905
const containingSourceFile = ! isString ( containingFile ) ? containingFile : undefined ;
1892
1906
const containingFileName = ! isString ( containingFile ) ? getNormalizedAbsolutePath ( containingFile . originalFileName , currentDirectory ) : containingFile ;
1893
- const redirectedReference = containingSourceFile && getRedirectReferenceForResolution ( containingSourceFile ) ;
1907
+ if ( redirectedReference === undefined && containingSourceFile ) redirectedReference = getRedirectReferenceForResolution ( containingSourceFile ) ;
1894
1908
tracing ?. push ( tracing . Phase . Program , "resolveTypeReferenceDirectiveNamesWorker" , { containingFileName } ) ;
1895
1909
performance . mark ( "beforeResolveTypeReference" ) ;
1896
- const result = actualResolveTypeReferenceDirectiveNamesWorker ( typeDirectiveNames , containingFileName , redirectedReference , options , containingSourceFile , reusedNames ) ;
1910
+ const result = actualResolveTypeReferenceDirectiveNamesWorker ( typeDirectiveNames , containingFileName , redirectedReference || undefined , options , containingSourceFile , reusedNames ) ;
1897
1911
performance . mark ( "afterResolveTypeReference" ) ;
1898
1912
performance . measure ( "ResolveTypeReference" , "beforeResolveTypeReference" , "afterResolveTypeReference" ) ;
1899
1913
tracing ?. pop ( ) ;
@@ -1981,7 +1995,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
1981
1995
if ( structureIsReused === StructureIsReused . Not && ! file . ambientModuleNames . length ) {
1982
1996
// If the old program state does not permit reusing resolutions and `file` does not contain locally defined ambient modules,
1983
1997
// the best we can do is fallback to the default logic.
1984
- return resolveModuleNamesWorker ( moduleNames , file , /*reusedNames*/ undefined ) ;
1998
+ return resolveModuleNamesWorker ( moduleNames , file , /*reusedNames*/ undefined , /*redirectedReference*/ undefined ) ;
1985
1999
}
1986
2000
1987
2001
const oldSourceFile = oldProgram && oldProgram . getSourceFile ( file . fileName ) ;
@@ -2021,6 +2035,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
2021
2035
let reusedNames : StringLiteralLike [ ] | undefined ;
2022
2036
/** A transient placeholder used to mark predicted resolution in the result list. */
2023
2037
const predictedToResolveToAmbientModuleMarker : ResolvedModuleWithFailedLookupLocations = emptyResolution ;
2038
+ let redirectedReference : ResolvedProjectReference | false | undefined ;
2024
2039
2025
2040
for ( let i = 0 ; i < moduleNames . length ; i ++ ) {
2026
2041
const moduleName = moduleNames [ i ] ;
@@ -2029,7 +2044,12 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
2029
2044
const mode = getModeForUsageLocation ( file , moduleName ) ;
2030
2045
const oldResolution = ! oldBuildInfoProgram ?
2031
2046
oldSourceFile ?. resolvedModules ?. get ( moduleName . text , mode ) :
2032
- oldBuildInfoProgram . getResolvedModule ( moduleName . text , mode , getDirectoryPath ( file . path ) ) ;
2047
+ oldBuildInfoProgram . getResolvedModule (
2048
+ moduleName . text ,
2049
+ mode ,
2050
+ getDirectoryPath ( file . path ) ,
2051
+ ( redirectedReference === undefined ? ( redirectedReference = getRedirectReferenceForResolution ( file ) || false ) : redirectedReference ) || undefined ,
2052
+ ) ;
2033
2053
if ( oldResolution ?. resolvedModule ) {
2034
2054
if ( isTraceEnabled ( options , host ) ) {
2035
2055
const fileLocation = getNormalizedAbsolutePath ( file . originalFileName , currentDirectory ) ;
@@ -2087,7 +2107,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
2087
2107
}
2088
2108
2089
2109
const resolutions = unknownModuleNames && unknownModuleNames . length
2090
- ? resolveModuleNamesWorker ( unknownModuleNames , file , reusedNames )
2110
+ ? resolveModuleNamesWorker ( unknownModuleNames , file , reusedNames , redirectedReference )
2091
2111
: emptyArray ;
2092
2112
2093
2113
// Combine results of resolutions and predicted results
@@ -2141,7 +2161,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
2141
2161
if ( structureIsReused === StructureIsReused . Not ) {
2142
2162
// If the old program state does not permit reusing resolutions and `file` does not contain locally defined ambient modules,
2143
2163
// the best we can do is fallback to the default logic.
2144
- return resolveTypeReferenceDirectiveNamesWorker ( typeDirectiveNames , containingFile , /*resuedNames*/ undefined ) ;
2164
+ return resolveTypeReferenceDirectiveNamesWorker ( typeDirectiveNames , containingFile , /*resuedNames*/ undefined , /*redirectedReference*/ undefined ) ;
2145
2165
}
2146
2166
2147
2167
const oldSourceFile = ! isString ( containingFile ) ? oldProgram && oldProgram . getSourceFile ( containingFile . fileName ) : undefined ;
@@ -2170,20 +2190,27 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
2170
2190
let result : ResolvedTypeReferenceDirectiveWithFailedLookupLocations [ ] | undefined ;
2171
2191
let reusedNames : T [ ] | undefined ;
2172
2192
const containingSourceFile = ! isString ( containingFile ) ? containingFile : undefined ;
2193
+ const inferredTypeFile = ! isString ( containingFile ) ? undefined : containingFile ;
2173
2194
const canReuseResolutions = oldBuildInfoProgram || ( ! isString ( containingFile ) ?
2174
2195
containingFile === oldSourceFile && ! hasInvalidatedResolutions ( oldSourceFile . path ) :
2175
2196
! hasInvalidatedResolutions ( toPath ( containingFile ) ) ) ;
2197
+ let redirectedReference : ResolvedProjectReference | false | undefined ;
2176
2198
for ( let i = 0 ; i < typeDirectiveNames . length ; i ++ ) {
2177
2199
const entry = typeDirectiveNames [ i ] ;
2178
2200
if ( canReuseResolutions ) {
2179
2201
const typeDirectiveName = getTypeReferenceResolutionName ( entry ) ;
2180
2202
const mode = getModeForFileReference ( entry , containingSourceFile ?. impliedNodeFormat ) ;
2181
2203
const oldResolution = ! oldBuildInfoProgram ?
2182
- ( ! isString ( containingFile ) ? oldSourceFile ?. resolvedTypeReferenceDirectiveNames : oldProgram ?. getAutomaticTypeDirectiveResolutions ( ) ) ?. get ( typeDirectiveName , mode ) :
2183
- oldBuildInfoProgram . getResolvedTypeReferenceDirective ( typeDirectiveName , mode , getDirectoryPath ( ! isString ( containingFile ) ? containingFile . path : toPath ( containingFile ) ) ) ;
2204
+ ( containingSourceFile ? oldSourceFile ?. resolvedTypeReferenceDirectiveNames : oldProgram ?. getAutomaticTypeDirectiveResolutions ( ) ) ?. get ( typeDirectiveName , mode ) :
2205
+ oldBuildInfoProgram . getResolvedTypeReferenceDirective (
2206
+ typeDirectiveName ,
2207
+ mode ,
2208
+ getDirectoryPath ( containingSourceFile ? containingSourceFile . path : toPath ( inferredTypeFile ! ) ) ,
2209
+ containingSourceFile && ( redirectedReference === undefined ? ( redirectedReference = getRedirectReferenceForResolution ( containingSourceFile ) || false ) : redirectedReference ) || undefined ,
2210
+ ) ;
2184
2211
if ( oldResolution ?. resolvedTypeReferenceDirective ) {
2185
2212
if ( isTraceEnabled ( options , host ) ) {
2186
- const fileLocation = ! isString ( containingFile ) ? getNormalizedAbsolutePath ( containingFile . originalFileName , currentDirectory ) : containingFile ;
2213
+ const fileLocation = containingSourceFile ? getNormalizedAbsolutePath ( containingSourceFile . originalFileName , currentDirectory ) : inferredTypeFile ! ;
2187
2214
if ( ! oldBuildInfoProgram ) {
2188
2215
trace ( host ,
2189
2216
oldResolution . resolvedTypeReferenceDirective . packageId ?
@@ -2222,6 +2249,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
2222
2249
unknownTypeReferenceDirectiveNames ,
2223
2250
containingFile ,
2224
2251
reusedNames ,
2252
+ redirectedReference ,
2225
2253
) ;
2226
2254
2227
2255
// Combine results of resolutions
0 commit comments