@@ -1163,21 +1163,20 @@ namespace ts {
11631163
11641164 // The originalFileName could not be actual source file name if file found was d.ts from referecned project
11651165 // So in this case try to look up if this is output from referenced project, if it is use the redirected project in that case
1166- const resultFromDts = getRedirectReferenceForResolutionFromSourceOfProject ( file . originalFileName , file . path ) ;
1166+ const resultFromDts = getRedirectReferenceForResolutionFromSourceOfProject ( file . path ) ;
11671167 if ( resultFromDts ) return resultFromDts ;
11681168
11691169 // If preserveSymlinks is true, module resolution wont jump the symlink
11701170 // but the resolved real path may be the .d.ts from project reference
11711171 // Note:: Currently we try the real path only if the
11721172 // file is from node_modules to avoid having to run real path on all file paths
11731173 if ( ! host . realpath || ! options . preserveSymlinks || ! stringContains ( file . originalFileName , nodeModulesPathPart ) ) return undefined ;
1174- const realDeclarationFileName = host . realpath ( file . originalFileName ) ;
1175- const realDeclarationPath = toPath ( realDeclarationFileName ) ;
1176- return realDeclarationPath === file . path ? undefined : getRedirectReferenceForResolutionFromSourceOfProject ( realDeclarationFileName , realDeclarationPath ) ;
1174+ const realDeclarationPath = toPath ( host . realpath ( file . originalFileName ) ) ;
1175+ return realDeclarationPath === file . path ? undefined : getRedirectReferenceForResolutionFromSourceOfProject ( realDeclarationPath ) ;
11771176 }
11781177
1179- function getRedirectReferenceForResolutionFromSourceOfProject ( fileName : string , filePath : Path ) {
1180- const source = getSourceOfProjectReferenceRedirect ( fileName ) ;
1178+ function getRedirectReferenceForResolutionFromSourceOfProject ( filePath : Path ) {
1179+ const source = getSourceOfProjectReferenceRedirect ( filePath ) ;
11811180 if ( isString ( source ) ) return getResolvedProjectReferenceToRedirect ( source ) ;
11821181 if ( ! source ) return undefined ;
11831182 // Output of .d.ts file so return resolved ref that matches the out file name
@@ -2472,7 +2471,7 @@ namespace ts {
24722471 function processSourceFile ( fileName : string , isDefaultLib : boolean , ignoreNoDefaultLib : boolean , packageId : PackageId | undefined , reason : FileIncludeReason ) : void {
24732472 getSourceFileFromReferenceWorker (
24742473 fileName ,
2475- fileName => findSourceFile ( fileName , toPath ( fileName ) , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) , // TODO: GH#18217
2474+ fileName => findSourceFile ( fileName , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) , // TODO: GH#18217
24762475 ( diagnostic , ...args ) => addFilePreprocessingFileExplainingDiagnostic ( /*file*/ undefined , reason , diagnostic , args ) ,
24772476 reason
24782477 ) ;
@@ -2514,20 +2513,21 @@ namespace ts {
25142513 }
25152514
25162515 // Get source file from normalized fileName
2517- function findSourceFile ( fileName : string , path : Path , isDefaultLib : boolean , ignoreNoDefaultLib : boolean , reason : FileIncludeReason , packageId : PackageId | undefined ) : SourceFile | undefined {
2516+ function findSourceFile ( fileName : string , isDefaultLib : boolean , ignoreNoDefaultLib : boolean , reason : FileIncludeReason , packageId : PackageId | undefined ) : SourceFile | undefined {
25182517 tracing ?. push ( tracing . Phase . Program , "findSourceFile" , {
25192518 fileName,
25202519 isDefaultLib : isDefaultLib || undefined ,
25212520 fileIncludeKind : ( FileIncludeKind as any ) [ reason . kind ] ,
25222521 } ) ;
2523- const result = findSourceFileWorker ( fileName , path , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) ;
2522+ const result = findSourceFileWorker ( fileName , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) ;
25242523 tracing ?. pop ( ) ;
25252524 return result ;
25262525 }
25272526
2528- function findSourceFileWorker ( fileName : string , path : Path , isDefaultLib : boolean , ignoreNoDefaultLib : boolean , reason : FileIncludeReason , packageId : PackageId | undefined ) : SourceFile | undefined {
2527+ function findSourceFileWorker ( fileName : string , isDefaultLib : boolean , ignoreNoDefaultLib : boolean , reason : FileIncludeReason , packageId : PackageId | undefined ) : SourceFile | undefined {
2528+ const path = toPath ( fileName ) ;
25292529 if ( useSourceOfProjectReferenceRedirect ) {
2530- let source = getSourceOfProjectReferenceRedirect ( fileName ) ;
2530+ let source = getSourceOfProjectReferenceRedirect ( path ) ;
25312531 // If preserveSymlinks is true, module resolution wont jump the symlink
25322532 // but the resolved real path may be the .d.ts from project reference
25332533 // Note:: Currently we try the real path only if the
@@ -2537,12 +2537,12 @@ namespace ts {
25372537 options . preserveSymlinks &&
25382538 isDeclarationFileName ( fileName ) &&
25392539 stringContains ( fileName , nodeModulesPathPart ) ) {
2540- const realPath = host . realpath ( fileName ) ;
2541- if ( realPath !== fileName ) source = getSourceOfProjectReferenceRedirect ( realPath ) ;
2540+ const realPath = toPath ( host . realpath ( fileName ) ) ;
2541+ if ( realPath !== path ) source = getSourceOfProjectReferenceRedirect ( realPath ) ;
25422542 }
25432543 if ( source ) {
25442544 const file = isString ( source ) ?
2545- findSourceFile ( source , toPath ( source ) , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) :
2545+ findSourceFile ( source , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) :
25462546 undefined ;
25472547 if ( file ) addFileToFilesByName ( file , path , /*redirectedPath*/ undefined ) ;
25482548 return file ;
@@ -2750,8 +2750,8 @@ namespace ts {
27502750 return ts . forEachResolvedProjectReference ( resolvedProjectReferences , cb ) ;
27512751 }
27522752
2753- function getSourceOfProjectReferenceRedirect ( file : string ) {
2754- if ( ! isDeclarationFileName ( file ) ) return undefined ;
2753+ function getSourceOfProjectReferenceRedirect ( path : Path ) {
2754+ if ( ! isDeclarationFileName ( path ) ) return undefined ;
27552755 if ( mapFromToProjectReferenceRedirectSource === undefined ) {
27562756 mapFromToProjectReferenceRedirectSource = new Map ( ) ;
27572757 forEachResolvedProjectReference ( resolvedRef => {
@@ -2772,7 +2772,7 @@ namespace ts {
27722772 }
27732773 } ) ;
27742774 }
2775- return mapFromToProjectReferenceRedirectSource . get ( toPath ( file ) ) ;
2775+ return mapFromToProjectReferenceRedirectSource . get ( path ) ;
27762776 }
27772777
27782778 function isSourceOfProjectReferenceRedirect ( fileName : string ) {
@@ -2954,10 +2954,8 @@ namespace ts {
29542954 modulesWithElidedImports . set ( file . path , true ) ;
29552955 }
29562956 else if ( shouldAddFile ) {
2957- const path = toPath ( resolvedFileName ) ;
29582957 findSourceFile (
29592958 resolvedFileName ,
2960- path ,
29612959 /*isDefaultLib*/ false ,
29622960 /*ignoreNoDefaultLib*/ false ,
29632961 { kind : FileIncludeKind . Import , file : file . path , index, } ,
@@ -3691,7 +3689,7 @@ namespace ts {
36913689 useSourceOfProjectReferenceRedirect : boolean ;
36923690 toPath ( fileName : string ) : Path ;
36933691 getResolvedProjectReferences ( ) : readonly ( ResolvedProjectReference | undefined ) [ ] | undefined ;
3694- getSourceOfProjectReferenceRedirect ( fileName : string ) : SourceOfProjectReferenceRedirect | undefined ;
3692+ getSourceOfProjectReferenceRedirect ( path : Path ) : SourceOfProjectReferenceRedirect | undefined ;
36953693 forEachResolvedProjectReference < T > ( cb : ( resolvedProjectReference : ResolvedProjectReference ) => T | undefined ) : T | undefined ;
36963694 }
36973695
@@ -3778,9 +3776,9 @@ namespace ts {
37783776 }
37793777
37803778 function fileExistsIfProjectReferenceDts ( file : string ) {
3781- const source = host . getSourceOfProjectReferenceRedirect ( file ) ;
3779+ const source = host . getSourceOfProjectReferenceRedirect ( host . toPath ( file ) ) ;
37823780 return source !== undefined ?
3783- isString ( source ) ? originalFileExists . call ( host . compilerHost , source ) : true :
3781+ isString ( source ) ? originalFileExists . call ( host . compilerHost , source ) as boolean : true :
37843782 undefined ;
37853783 }
37863784
0 commit comments