@@ -663,7 +663,7 @@ namespace ts {
663663
664664 // A parallel array to projectReferences storing the results of reading in the referenced tsconfig files
665665 let resolvedProjectReferences : ( ResolvedProjectReference | undefined ) [ ] | undefined = projectReferences ? [ ] : undefined ;
666- const projectReferenceRedirects : Map < string > = createMap ( ) ;
666+ let projectReferenceRedirects : ParsedCommandLine [ ] | undefined ;
667667
668668 const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles ( oldProgram , options ) ;
669669 const structuralIsReused = tryReuseStructureFromOldProgram ( ) ;
@@ -681,7 +681,7 @@ namespace ts {
681681 const dtsOutfile = changeExtension ( out , ".d.ts" ) ;
682682 processSourceFile ( dtsOutfile , /*isDefaultLib*/ false , /*ignoreNoDefaultLib*/ false , /*packageId*/ undefined ) ;
683683 }
684- addProjectReferenceRedirects ( parsedRef . commandLine , projectReferenceRedirects ) ;
684+ addProjectReferenceRedirects ( parsedRef . commandLine ) ;
685685 }
686686 }
687687 }
@@ -1252,7 +1252,7 @@ namespace ts {
12521252 if ( resolvedProjectReferences ) {
12531253 resolvedProjectReferences . forEach ( ref => {
12541254 if ( ref ) {
1255- addProjectReferenceRedirects ( ref . commandLine , projectReferenceRedirects ) ;
1255+ addProjectReferenceRedirects ( ref . commandLine ) ;
12561256 }
12571257 } ) ;
12581258 }
@@ -2179,20 +2179,24 @@ namespace ts {
21792179 }
21802180
21812181 function getProjectReferenceRedirect ( fileName : string ) : string | undefined {
2182- const path = toPath ( fileName ) ;
2182+ // Ignore dts or any of the non ts files
2183+ if ( ! projectReferenceRedirects || fileExtensionIs ( fileName , Extension . Dts ) || ! fileExtensionIsOneOf ( fileName , supportedTSExtensions ) ) {
2184+ return undefined ;
2185+ }
2186+
21832187 // If this file is produced by a referenced project, we need to rewrite it to
21842188 // look in the output folder of the referenced project rather than the input
2185- const normalized = getNormalizedAbsolutePath ( fileName , path ) ;
2186- let result : string | undefined ;
2187- projectReferenceRedirects . forEach ( ( v , k ) => {
2188- if ( result !== undefined ) {
2189+ return forEach ( projectReferenceRedirects , referencedProject => {
2190+ // not input file from the referenced project, ignore
2191+ if ( ! contains ( referencedProject . fileNames , fileName , isSameFile ) ) {
21892192 return undefined ;
21902193 }
2191- if ( normalized . indexOf ( k ) === 0 ) {
2192- result = changeExtension ( fileName . replace ( k , v ) , ".d.ts" ) ;
2193- }
2194+
2195+ const out = referencedProject . options . outFile || referencedProject . options . out ;
2196+ return out ?
2197+ changeExtension ( out , Extension . Dts ) :
2198+ getOutputDeclarationFileName ( fileName , referencedProject ) ;
21942199 } ) ;
2195- return result ;
21962200 }
21972201
21982202 function processReferencedFiles ( file : SourceFile , isDefaultLib : boolean ) {
@@ -2396,15 +2400,8 @@ namespace ts {
23962400 return { commandLine, sourceFile } ;
23972401 }
23982402
2399- function addProjectReferenceRedirects ( referencedProject : ParsedCommandLine , target : Map < string > ) {
2400- const rootDir = normalizePath ( referencedProject . options . rootDir || getDirectoryPath ( referencedProject . options . configFilePath ! ) ) ; // TODO: GH#18217
2401- target . set ( rootDir , getDeclarationOutputDirectory ( referencedProject ) ) ;
2402- }
2403-
2404- function getDeclarationOutputDirectory ( proj : ParsedCommandLine ) {
2405- return proj . options . declarationDir ||
2406- proj . options . outDir ||
2407- getDirectoryPath ( proj . options . configFilePath ! ) ; // TODO: GH#18217
2403+ function addProjectReferenceRedirects ( referencedProject : ParsedCommandLine ) {
2404+ ( projectReferenceRedirects || ( projectReferenceRedirects = [ ] ) ) . push ( referencedProject ) ;
24082405 }
24092406
24102407 function verifyCompilerOptions ( ) {
0 commit comments