@@ -813,6 +813,8 @@ namespace ts {
813
813
let resolvedProjectReferences : ReadonlyArray < ResolvedProjectReference | undefined > | undefined ;
814
814
let projectReferenceRedirects : Map < ResolvedProjectReference | false > | undefined ;
815
815
let mapFromFileToProjectReferenceRedirects : Map < Path > | undefined ;
816
+ let mapFromToProjectReferenceRedirectSource : Map < SourceOfProjectReferenceRedirect > | undefined ;
817
+ const useSourceOfReference = host . useSourceInsteadOfReferenceRedirect && host . useSourceInsteadOfReferenceRedirect ( ) ;
816
818
817
819
const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles ( oldProgram , options ) ;
818
820
const structuralIsReused = tryReuseStructureFromOldProgram ( ) ;
@@ -824,17 +826,29 @@ namespace ts {
824
826
if ( ! resolvedProjectReferences ) {
825
827
resolvedProjectReferences = projectReferences . map ( parseProjectReferenceConfigFile ) ;
826
828
}
829
+ if ( host . setGetSourceOfProjectReferenceRedirect ) {
830
+ host . setGetSourceOfProjectReferenceRedirect ( getSourceOfProjectReferenceRedirect ) ;
831
+ }
827
832
if ( rootNames . length ) {
828
833
for ( const parsedRef of resolvedProjectReferences ) {
829
834
if ( ! parsedRef ) continue ;
830
835
const out = parsedRef . commandLine . options . outFile || parsedRef . commandLine . options . out ;
831
- if ( out ) {
832
- processSourceFile ( changeExtension ( out , ".d.ts" ) , /*isDefaultLib*/ false , /*ignoreNoDefaultLib*/ false , /*packageId*/ undefined ) ;
836
+ if ( useSourceOfReference ) {
837
+ if ( out || getEmitModuleKind ( parsedRef . commandLine . options ) === ModuleKind . None ) {
838
+ for ( const fileName of parsedRef . commandLine . fileNames ) {
839
+ processSourceFile ( fileName , /*isDefaultLib*/ false , /*ignoreNoDefaultLib*/ false , /*packageId*/ undefined ) ;
840
+ }
841
+ }
833
842
}
834
- else if ( getEmitModuleKind ( parsedRef . commandLine . options ) === ModuleKind . None ) {
835
- for ( const fileName of parsedRef . commandLine . fileNames ) {
836
- if ( ! fileExtensionIs ( fileName , Extension . Dts ) && hasTSFileExtension ( fileName ) ) {
837
- processSourceFile ( getOutputDeclarationFileName ( fileName , parsedRef . commandLine , ! host . useCaseSensitiveFileNames ( ) ) , /*isDefaultLib*/ false , /*ignoreNoDefaultLib*/ false , /*packageId*/ undefined ) ;
843
+ else {
844
+ if ( out ) {
845
+ processSourceFile ( changeExtension ( out , ".d.ts" ) , /*isDefaultLib*/ false , /*ignoreNoDefaultLib*/ false , /*packageId*/ undefined ) ;
846
+ }
847
+ else if ( getEmitModuleKind ( parsedRef . commandLine . options ) === ModuleKind . None ) {
848
+ for ( const fileName of parsedRef . commandLine . fileNames ) {
849
+ if ( ! fileExtensionIs ( fileName , Extension . Dts ) && hasTSFileExtension ( fileName ) ) {
850
+ processSourceFile ( getOutputDeclarationFileName ( fileName , parsedRef . commandLine , ! host . useCaseSensitiveFileNames ( ) ) , /*isDefaultLib*/ false , /*ignoreNoDefaultLib*/ false , /*packageId*/ undefined ) ;
851
+ }
838
852
}
839
853
}
840
854
}
@@ -1212,6 +1226,9 @@ namespace ts {
1212
1226
}
1213
1227
if ( projectReferences ) {
1214
1228
resolvedProjectReferences = projectReferences . map ( parseProjectReferenceConfigFile ) ;
1229
+ if ( host . setGetSourceOfProjectReferenceRedirect ) {
1230
+ host . setGetSourceOfProjectReferenceRedirect ( getSourceOfProjectReferenceRedirect ) ;
1231
+ }
1215
1232
}
1216
1233
1217
1234
// check if program source files has changed in the way that can affect structure of the program
@@ -2220,6 +2237,14 @@ namespace ts {
2220
2237
2221
2238
// Get source file from normalized fileName
2222
2239
function findSourceFile ( fileName : string , path : Path , isDefaultLib : boolean , ignoreNoDefaultLib : boolean , refFile : SourceFile , refPos : number , refEnd : number , packageId : PackageId | undefined ) : SourceFile | undefined {
2240
+ if ( useSourceOfReference ) {
2241
+ const source = getSourceOfProjectReferenceRedirect ( fileName ) ;
2242
+ if ( source ) {
2243
+ return isString ( source ) ?
2244
+ findSourceFile ( source , toPath ( source ) , isDefaultLib , ignoreNoDefaultLib , refFile , refPos , refEnd , packageId ) :
2245
+ undefined ;
2246
+ }
2247
+ }
2223
2248
const originalFileName = fileName ;
2224
2249
if ( filesByName . has ( path ) ) {
2225
2250
const file = filesByName . get ( path ) ;
@@ -2267,7 +2292,7 @@ namespace ts {
2267
2292
}
2268
2293
2269
2294
let redirectedPath : Path | undefined ;
2270
- if ( refFile ) {
2295
+ if ( refFile && ! useSourceOfReference ) {
2271
2296
const redirectProject = getProjectReferenceRedirectProject ( fileName ) ;
2272
2297
if ( redirectProject ) {
2273
2298
if ( redirectProject . commandLine . options . outFile || redirectProject . commandLine . options . out ) {
@@ -2286,15 +2311,20 @@ namespace ts {
2286
2311
}
2287
2312
2288
2313
// We haven't looked for this file, do so now and cache result
2289
- const file = host . getSourceFile ( fileName , options . target ! , hostErrorMessage => { // TODO: GH#18217
2290
- if ( refFile !== undefined && refPos !== undefined && refEnd !== undefined ) {
2291
- fileProcessingDiagnostics . add ( createFileDiagnostic ( refFile , refPos , refEnd - refPos ,
2292
- Diagnostics . Cannot_read_file_0_Colon_1 , fileName , hostErrorMessage ) ) ;
2293
- }
2294
- else {
2295
- fileProcessingDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_read_file_0_Colon_1 , fileName , hostErrorMessage ) ) ;
2296
- }
2297
- } , shouldCreateNewSourceFile ) ;
2314
+ const file = host . getSourceFile (
2315
+ fileName ,
2316
+ options . target ! ,
2317
+ hostErrorMessage => { // TODO: GH#18217
2318
+ if ( refFile !== undefined && refPos !== undefined && refEnd !== undefined ) {
2319
+ fileProcessingDiagnostics . add ( createFileDiagnostic ( refFile , refPos , refEnd - refPos ,
2320
+ Diagnostics . Cannot_read_file_0_Colon_1 , fileName , hostErrorMessage ) ) ;
2321
+ }
2322
+ else {
2323
+ fileProcessingDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_read_file_0_Colon_1 , fileName , hostErrorMessage ) ) ;
2324
+ }
2325
+ } ,
2326
+ shouldCreateNewSourceFile
2327
+ ) ;
2298
2328
2299
2329
if ( packageId ) {
2300
2330
const packageIdKey = packageIdToString ( packageId ) ;
@@ -2424,6 +2454,30 @@ namespace ts {
2424
2454
} ) ;
2425
2455
}
2426
2456
2457
+ function getSourceOfProjectReferenceRedirect ( file : string ) {
2458
+ if ( ! isDeclarationFileName ( file ) ) return undefined ;
2459
+ if ( mapFromToProjectReferenceRedirectSource === undefined ) {
2460
+ mapFromToProjectReferenceRedirectSource = createMap ( ) ;
2461
+ forEachResolvedProjectReference ( resolvedRef => {
2462
+ if ( resolvedRef ) {
2463
+ const out = resolvedRef . commandLine . options . outFile || resolvedRef . commandLine . options . out ;
2464
+ if ( out ) {
2465
+ // Dont know which source file it means so return true?
2466
+ const outputDts = changeExtension ( out , Extension . Dts ) ;
2467
+ mapFromToProjectReferenceRedirectSource ! . set ( toPath ( outputDts ) , true ) ;
2468
+ }
2469
+ else {
2470
+ forEach ( resolvedRef . commandLine . fileNames , fileName => {
2471
+ const outputDts = getOutputDeclarationFileName ( fileName , resolvedRef . commandLine , host . useCaseSensitiveFileNames ( ) ) ;
2472
+ mapFromToProjectReferenceRedirectSource ! . set ( toPath ( outputDts ) , fileName ) ;
2473
+ } ) ;
2474
+ }
2475
+ }
2476
+ } ) ;
2477
+ }
2478
+ return mapFromToProjectReferenceRedirectSource . get ( toPath ( file ) ) ;
2479
+ }
2480
+
2427
2481
function forEachProjectReference < T > (
2428
2482
projectReferences : ReadonlyArray < ProjectReference > | undefined ,
2429
2483
resolvedProjectReferences : ReadonlyArray < ResolvedProjectReference | undefined > | undefined ,
0 commit comments