@@ -1163,21 +1163,20 @@ namespace ts {
1163
1163
1164
1164
// The originalFileName could not be actual source file name if file found was d.ts from referecned project
1165
1165
// 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 ) ;
1167
1167
if ( resultFromDts ) return resultFromDts ;
1168
1168
1169
1169
// If preserveSymlinks is true, module resolution wont jump the symlink
1170
1170
// but the resolved real path may be the .d.ts from project reference
1171
1171
// Note:: Currently we try the real path only if the
1172
1172
// file is from node_modules to avoid having to run real path on all file paths
1173
1173
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 ) ;
1177
1176
}
1178
1177
1179
- function getRedirectReferenceForResolutionFromSourceOfProject ( fileName : string , filePath : Path ) {
1180
- const source = getSourceOfProjectReferenceRedirect ( fileName ) ;
1178
+ function getRedirectReferenceForResolutionFromSourceOfProject ( filePath : Path ) {
1179
+ const source = getSourceOfProjectReferenceRedirect ( filePath ) ;
1181
1180
if ( isString ( source ) ) return getResolvedProjectReferenceToRedirect ( source ) ;
1182
1181
if ( ! source ) return undefined ;
1183
1182
// Output of .d.ts file so return resolved ref that matches the out file name
@@ -2472,7 +2471,7 @@ namespace ts {
2472
2471
function processSourceFile ( fileName : string , isDefaultLib : boolean , ignoreNoDefaultLib : boolean , packageId : PackageId | undefined , reason : FileIncludeReason ) : void {
2473
2472
getSourceFileFromReferenceWorker (
2474
2473
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
2476
2475
( diagnostic , ...args ) => addFilePreprocessingFileExplainingDiagnostic ( /*file*/ undefined , reason , diagnostic , args ) ,
2477
2476
reason
2478
2477
) ;
@@ -2514,20 +2513,21 @@ namespace ts {
2514
2513
}
2515
2514
2516
2515
// 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 {
2518
2517
tracing ?. push ( tracing . Phase . Program , "findSourceFile" , {
2519
2518
fileName,
2520
2519
isDefaultLib : isDefaultLib || undefined ,
2521
2520
fileIncludeKind : ( FileIncludeKind as any ) [ reason . kind ] ,
2522
2521
} ) ;
2523
- const result = findSourceFileWorker ( fileName , path , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) ;
2522
+ const result = findSourceFileWorker ( fileName , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) ;
2524
2523
tracing ?. pop ( ) ;
2525
2524
return result ;
2526
2525
}
2527
2526
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 ) ;
2529
2529
if ( useSourceOfProjectReferenceRedirect ) {
2530
- let source = getSourceOfProjectReferenceRedirect ( fileName ) ;
2530
+ let source = getSourceOfProjectReferenceRedirect ( path ) ;
2531
2531
// If preserveSymlinks is true, module resolution wont jump the symlink
2532
2532
// but the resolved real path may be the .d.ts from project reference
2533
2533
// Note:: Currently we try the real path only if the
@@ -2537,12 +2537,12 @@ namespace ts {
2537
2537
options . preserveSymlinks &&
2538
2538
isDeclarationFileName ( fileName ) &&
2539
2539
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 ) ;
2542
2542
}
2543
2543
if ( source ) {
2544
2544
const file = isString ( source ) ?
2545
- findSourceFile ( source , toPath ( source ) , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) :
2545
+ findSourceFile ( source , isDefaultLib , ignoreNoDefaultLib , reason , packageId ) :
2546
2546
undefined ;
2547
2547
if ( file ) addFileToFilesByName ( file , path , /*redirectedPath*/ undefined ) ;
2548
2548
return file ;
@@ -2750,8 +2750,8 @@ namespace ts {
2750
2750
return ts . forEachResolvedProjectReference ( resolvedProjectReferences , cb ) ;
2751
2751
}
2752
2752
2753
- function getSourceOfProjectReferenceRedirect ( file : string ) {
2754
- if ( ! isDeclarationFileName ( file ) ) return undefined ;
2753
+ function getSourceOfProjectReferenceRedirect ( path : Path ) {
2754
+ if ( ! isDeclarationFileName ( path ) ) return undefined ;
2755
2755
if ( mapFromToProjectReferenceRedirectSource === undefined ) {
2756
2756
mapFromToProjectReferenceRedirectSource = new Map ( ) ;
2757
2757
forEachResolvedProjectReference ( resolvedRef => {
@@ -2772,7 +2772,7 @@ namespace ts {
2772
2772
}
2773
2773
} ) ;
2774
2774
}
2775
- return mapFromToProjectReferenceRedirectSource . get ( toPath ( file ) ) ;
2775
+ return mapFromToProjectReferenceRedirectSource . get ( path ) ;
2776
2776
}
2777
2777
2778
2778
function isSourceOfProjectReferenceRedirect ( fileName : string ) {
@@ -2954,10 +2954,8 @@ namespace ts {
2954
2954
modulesWithElidedImports . set ( file . path , true ) ;
2955
2955
}
2956
2956
else if ( shouldAddFile ) {
2957
- const path = toPath ( resolvedFileName ) ;
2958
2957
findSourceFile (
2959
2958
resolvedFileName ,
2960
- path ,
2961
2959
/*isDefaultLib*/ false ,
2962
2960
/*ignoreNoDefaultLib*/ false ,
2963
2961
{ kind : FileIncludeKind . Import , file : file . path , index, } ,
@@ -3691,7 +3689,7 @@ namespace ts {
3691
3689
useSourceOfProjectReferenceRedirect : boolean ;
3692
3690
toPath ( fileName : string ) : Path ;
3693
3691
getResolvedProjectReferences ( ) : readonly ( ResolvedProjectReference | undefined ) [ ] | undefined ;
3694
- getSourceOfProjectReferenceRedirect ( fileName : string ) : SourceOfProjectReferenceRedirect | undefined ;
3692
+ getSourceOfProjectReferenceRedirect ( path : Path ) : SourceOfProjectReferenceRedirect | undefined ;
3695
3693
forEachResolvedProjectReference < T > ( cb : ( resolvedProjectReference : ResolvedProjectReference ) => T | undefined ) : T | undefined ;
3696
3694
}
3697
3695
@@ -3778,9 +3776,9 @@ namespace ts {
3778
3776
}
3779
3777
3780
3778
function fileExistsIfProjectReferenceDts ( file : string ) {
3781
- const source = host . getSourceOfProjectReferenceRedirect ( file ) ;
3779
+ const source = host . getSourceOfProjectReferenceRedirect ( host . toPath ( file ) ) ;
3782
3780
return source !== undefined ?
3783
- isString ( source ) ? originalFileExists . call ( host . compilerHost , source ) : true :
3781
+ isString ( source ) ? originalFileExists . call ( host . compilerHost , source ) as boolean : true :
3784
3782
undefined ;
3785
3783
}
3786
3784
0 commit comments