@@ -406,7 +406,7 @@ namespace ts {
406
406
}
407
407
}
408
408
409
- function loadWithLocalCache < T > ( names : string [ ] , containingFile : string , loader : ( name : string , containingFile : string ) => T ) : T [ ] {
409
+ function loadWithLocalCache < T > ( names : string [ ] , containingFile : string , redirectedReference : ResolvedProjectReference | undefined , loader : ( name : string , containingFile : string , redirectedReference : ResolvedProjectReference | undefined ) => T ) : T [ ] {
410
410
if ( names . length === 0 ) {
411
411
return [ ] ;
412
412
}
@@ -418,7 +418,7 @@ namespace ts {
418
418
result = cache . get ( name ) ! ;
419
419
}
420
420
else {
421
- cache . set ( name , result = loader ( name , containingFile ) ) ;
421
+ cache . set ( name , result = loader ( name , containingFile , redirectedReference ) ) ;
422
422
}
423
423
resolutions . push ( result ) ;
424
424
}
@@ -638,10 +638,10 @@ namespace ts {
638
638
let _referencesArrayLiteralSyntax : ArrayLiteralExpression | null | undefined ;
639
639
640
640
let moduleResolutionCache : ModuleResolutionCache | undefined ;
641
- let resolveModuleNamesWorker : ( moduleNames : string [ ] , containingFile : string , reusedNames ?: string [ ] ) => ResolvedModuleFull [ ] ;
641
+ let resolveModuleNamesWorker : ( moduleNames : string [ ] , containingFile : string , reusedNames ?: string [ ] , redirectedReference ?: ResolvedProjectReference ) => ResolvedModuleFull [ ] ;
642
642
const hasInvalidatedResolution = host . hasInvalidatedResolution || returnFalse ;
643
643
if ( host . resolveModuleNames ) {
644
- resolveModuleNamesWorker = ( moduleNames , containingFile , reusedNames ) => host . resolveModuleNames ! ( Debug . assertEachDefined ( moduleNames ) , containingFile , reusedNames ) . map ( resolved => {
644
+ resolveModuleNamesWorker = ( moduleNames , containingFile , reusedNames , redirectedReference ) => host . resolveModuleNames ! ( Debug . assertEachDefined ( moduleNames ) , containingFile , reusedNames , redirectedReference ) . map ( resolved => {
645
645
// An older host may have omitted extension, in which case we should infer it from the file extension of resolvedFileName.
646
646
if ( ! resolved || ( resolved as ResolvedModuleFull ) . extension !== undefined ) {
647
647
return resolved as ResolvedModuleFull ;
@@ -653,17 +653,17 @@ namespace ts {
653
653
}
654
654
else {
655
655
moduleResolutionCache = createModuleResolutionCache ( currentDirectory , x => host . getCanonicalFileName ( x ) ) ;
656
- const loader = ( moduleName : string , containingFile : string ) => resolveModuleName ( moduleName , containingFile , options , host , moduleResolutionCache ) . resolvedModule ! ; // TODO: GH#18217
657
- resolveModuleNamesWorker = ( moduleNames , containingFile ) => loadWithLocalCache < ResolvedModuleFull > ( Debug . assertEachDefined ( moduleNames ) , containingFile , loader ) ;
656
+ const loader = ( moduleName : string , containingFile : string , redirectedReference : ResolvedProjectReference | undefined ) => resolveModuleName ( moduleName , containingFile , options , host , moduleResolutionCache , redirectedReference ) . resolvedModule ! ; // TODO: GH#18217
657
+ resolveModuleNamesWorker = ( moduleNames , containingFile , _reusedNames , redirectedReference ) => loadWithLocalCache < ResolvedModuleFull > ( Debug . assertEachDefined ( moduleNames ) , containingFile , redirectedReference , loader ) ;
658
658
}
659
659
660
- let resolveTypeReferenceDirectiveNamesWorker : ( typeDirectiveNames : string [ ] , containingFile : string ) => ResolvedTypeReferenceDirective [ ] ;
660
+ let resolveTypeReferenceDirectiveNamesWorker : ( typeDirectiveNames : string [ ] , containingFile : string , redirectedReference ?: ResolvedProjectReference ) => ResolvedTypeReferenceDirective [ ] ;
661
661
if ( host . resolveTypeReferenceDirectives ) {
662
- resolveTypeReferenceDirectiveNamesWorker = ( typeDirectiveNames , containingFile ) => host . resolveTypeReferenceDirectives ! ( Debug . assertEachDefined ( typeDirectiveNames ) , containingFile ) ;
662
+ resolveTypeReferenceDirectiveNamesWorker = ( typeDirectiveNames , containingFile , redirectedReference ) => host . resolveTypeReferenceDirectives ! ( Debug . assertEachDefined ( typeDirectiveNames ) , containingFile , redirectedReference ) ;
663
663
}
664
664
else {
665
- const loader = ( typesRef : string , containingFile : string ) => resolveTypeReferenceDirective ( typesRef , containingFile , options , host ) . resolvedTypeReferenceDirective ! ; // TODO: GH#18217
666
- resolveTypeReferenceDirectiveNamesWorker = ( typeReferenceDirectiveNames , containingFile ) => loadWithLocalCache < ResolvedTypeReferenceDirective > ( Debug . assertEachDefined ( typeReferenceDirectiveNames ) , containingFile , loader ) ;
665
+ const loader = ( typesRef : string , containingFile : string , redirectedReference : ResolvedProjectReference | undefined ) => resolveTypeReferenceDirective ( typesRef , containingFile , options , host , redirectedReference ) . resolvedTypeReferenceDirective ! ; // TODO: GH#18217
666
+ resolveTypeReferenceDirectiveNamesWorker = ( typeReferenceDirectiveNames , containingFile , redirectedReference ) => loadWithLocalCache < ResolvedTypeReferenceDirective > ( Debug . assertEachDefined ( typeReferenceDirectiveNames ) , containingFile , redirectedReference , loader ) ;
667
667
}
668
668
669
669
// Map from a stringified PackageId to the source file with that id.
@@ -760,12 +760,6 @@ namespace ts {
760
760
761
761
// unconditionally set oldProgram to undefined to prevent it from being captured in closure
762
762
oldProgram = undefined ;
763
- // Do not use our own command line for projectReferenceRedirects
764
- if ( projectReferenceRedirects ) {
765
- Debug . assert ( ! ! options . configFilePath ) ;
766
- const path = toPath ( options . configFilePath ! ) ;
767
- projectReferenceRedirects . delete ( path ) ;
768
- }
769
763
770
764
program = {
771
765
getRootFileNames : ( ) => rootNames ,
@@ -887,7 +881,7 @@ namespace ts {
887
881
if ( structuralIsReused === StructureIsReused . Not && ! file . ambientModuleNames . length ) {
888
882
// If the old program state does not permit reusing resolutions and `file` does not contain locally defined ambient modules,
889
883
// the best we can do is fallback to the default logic.
890
- return resolveModuleNamesWorker ( moduleNames , containingFile ) ;
884
+ return resolveModuleNamesWorker ( moduleNames , containingFile , /*reusedNames*/ undefined , getProjectReferenceRedirectProject ( file . originalFileName ) ) ;
891
885
}
892
886
893
887
const oldSourceFile = oldProgramState . program && oldProgramState . program . getSourceFile ( containingFile ) ;
@@ -967,7 +961,7 @@ namespace ts {
967
961
}
968
962
969
963
const resolutions = unknownModuleNames && unknownModuleNames . length
970
- ? resolveModuleNamesWorker ( unknownModuleNames , containingFile , reusedNames )
964
+ ? resolveModuleNamesWorker ( unknownModuleNames , containingFile , reusedNames , getProjectReferenceRedirectProject ( file . originalFileName ) )
971
965
: emptyArray ;
972
966
973
967
// Combine results of resolutions and predicted results
@@ -1248,7 +1242,7 @@ namespace ts {
1248
1242
if ( resolveTypeReferenceDirectiveNamesWorker ) {
1249
1243
// We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
1250
1244
const typesReferenceDirectives = map ( newSourceFile . typeReferenceDirectives , ref => ref . fileName . toLocaleLowerCase ( ) ) ;
1251
- const resolutions = resolveTypeReferenceDirectiveNamesWorker ( typesReferenceDirectives , newSourceFilePath ) ;
1245
+ const resolutions = resolveTypeReferenceDirectiveNamesWorker ( typesReferenceDirectives , newSourceFilePath , getProjectReferenceRedirectProject ( newSourceFile . originalFileName ) ) ;
1252
1246
// ensure that types resolutions are still correct
1253
1247
const resolutionsChanged = hasChangesInResolutions ( typesReferenceDirectives , resolutions , oldSourceFile . resolvedTypeReferenceDirectiveNames , typeDirectiveIsEqualTo ) ;
1254
1248
if ( resolutionsChanged ) {
@@ -2219,16 +2213,35 @@ namespace ts {
2219
2213
2220
2214
// If this file is produced by a referenced project, we need to rewrite it to
2221
2215
// look in the output folder of the referenced project rather than the input
2216
+ const referencedProject = getProjectReferenceRedirectProject ( fileName ) ;
2217
+ if ( ! referencedProject ) {
2218
+ return undefined ;
2219
+ }
2220
+
2221
+ const out = referencedProject . commandLine . options . outFile || referencedProject . commandLine . options . out ;
2222
+ return out ?
2223
+ changeExtension ( out , Extension . Dts ) :
2224
+ getOutputDeclarationFileName ( fileName , referencedProject . commandLine ) ;
2225
+ }
2226
+
2227
+ /**
2228
+ * Get the referenced project if the file is input file from that reference project
2229
+ */
2230
+ function getProjectReferenceRedirectProject ( fileName : string ) {
2231
+ if ( ! resolvedProjectReferences || ! resolvedProjectReferences . length ) {
2232
+ return undefined ;
2233
+ }
2234
+
2235
+ // If this file is input file of the referenced projec
2222
2236
return forEachEntry ( projectReferenceRedirects ! , referencedProject => {
2223
2237
// not input file from the referenced project, ignore
2224
- if ( ! referencedProject || ! contains ( referencedProject . commandLine . fileNames , fileName , isSameFile ) ) {
2238
+ if ( ! referencedProject ||
2239
+ options . configFilePath === referencedProject . commandLine . options . configFilePath ||
2240
+ ! contains ( referencedProject . commandLine . fileNames , fileName , isSameFile ) ) {
2225
2241
return undefined ;
2226
2242
}
2227
2243
2228
- const out = referencedProject . commandLine . options . outFile || referencedProject . commandLine . options . out ;
2229
- return out ?
2230
- changeExtension ( out , Extension . Dts ) :
2231
- getOutputDeclarationFileName ( fileName , referencedProject . commandLine ) ;
2244
+ return referencedProject ;
2232
2245
} ) ;
2233
2246
}
2234
2247
@@ -2246,7 +2259,7 @@ namespace ts {
2246
2259
return ;
2247
2260
}
2248
2261
2249
- const resolutions = resolveTypeReferenceDirectiveNamesWorker ( typeDirectives , file . originalFileName ) ;
2262
+ const resolutions = resolveTypeReferenceDirectiveNamesWorker ( typeDirectives , file . originalFileName , getProjectReferenceRedirectProject ( file . originalFileName ) ) ;
2250
2263
2251
2264
for ( let i = 0 ; i < typeDirectives . length ; i ++ ) {
2252
2265
const ref = file . typeReferenceDirectives [ i ] ;
0 commit comments