@@ -1469,6 +1469,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
1469
1469
let automaticTypeDirectiveNames : string [ ] | undefined ;
1470
1470
let automaticTypeDirectiveResolutions : ModeAwareCache < ResolvedTypeReferenceDirectiveWithFailedLookupLocations > ;
1471
1471
1472
+ let resolvedLibReferences : Map < string , string > | undefined ;
1473
+
1472
1474
// The below settings are to track if a .js file should be add to the program if loaded via searching under node_modules.
1473
1475
// This works as imported modules are discovered recursively in a depth first manner, specifically:
1474
1476
// - For each root file, findSourceFile is called.
@@ -1813,6 +1815,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
1813
1815
sourceFileToPackageName,
1814
1816
redirectTargetsMap,
1815
1817
usesUriStyleNodeCoreModules,
1818
+ resolvedLibReferences,
1816
1819
isEmittedFile,
1817
1820
getConfigFileParsingDiagnostics,
1818
1821
getProjectReferences,
@@ -2481,6 +2484,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
2481
2484
sourceFileToPackageName = oldProgram . sourceFileToPackageName ;
2482
2485
redirectTargetsMap = oldProgram . redirectTargetsMap ;
2483
2486
usesUriStyleNodeCoreModules = oldProgram . usesUriStyleNodeCoreModules ;
2487
+ resolvedLibReferences = oldProgram . resolvedLibReferences ;
2484
2488
2485
2489
return StructureIsReused . Completely ;
2486
2490
}
@@ -2596,7 +2600,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
2596
2600
return equalityComparer ( file . fileName , getDefaultLibraryFileName ( ) ) ;
2597
2601
}
2598
2602
else {
2599
- return some ( options . lib , libFileName => equalityComparer ( file . fileName , pathForLibFile ( libFileName ) ) ) ;
2603
+ return some ( options . lib , libFileName => equalityComparer ( file . fileName , resolvedLibReferences ! . get ( libFileName ) ! ) ) ;
2600
2604
}
2601
2605
}
2602
2606
@@ -3313,7 +3317,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3313
3317
const libName = toFileNameLowerCase ( ref . fileName ) ;
3314
3318
const libFileName = libMap . get ( libName ) ;
3315
3319
if ( libFileName ) {
3316
- return getSourceFile ( pathForLibFile ( libFileName ) ) ;
3320
+ return getSourceFile ( resolvedLibReferences ?. get ( libFileName ) ! ) ;
3317
3321
}
3318
3322
}
3319
3323
@@ -3810,6 +3814,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3810
3814
}
3811
3815
3812
3816
function pathForLibFile ( libFileName : string ) : string {
3817
+ const existing = resolvedLibReferences ?. get ( libFileName ) ;
3818
+ if ( existing ) return existing ;
3813
3819
// Support resolving to lib.dom.d.ts -> @typescript/lib-dom, and
3814
3820
// lib.dom.iterable.d.ts -> @typescript/lib-dom/iterable
3815
3821
// lib.es2015.symbol.wellknown.d.ts -> @typescript/lib-es2015/symbol-wellknown
@@ -3823,10 +3829,11 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3823
3829
const containingDirectory = options . configFilePath ? getDirectoryPath ( options . configFilePath ) : currentDirectory ;
3824
3830
const resolveFrom = combinePaths ( containingDirectory , `__lib_node_modules_lookup_${ libFileName } __.ts` ) ;
3825
3831
const localOverrideModuleResult = resolveModuleName ( "@typescript/lib-" + path , resolveFrom , { moduleResolution : ModuleResolutionKind . Node10 , traceResolution : options . traceResolution } , host , moduleResolutionCache ) ;
3826
- if ( localOverrideModuleResult ?. resolvedModule ) {
3827
- return localOverrideModuleResult . resolvedModule . resolvedFileName ;
3828
- }
3829
- return combinePaths ( defaultLibraryPath , libFileName ) ;
3832
+ const result = localOverrideModuleResult ?. resolvedModule ?
3833
+ localOverrideModuleResult . resolvedModule . resolvedFileName :
3834
+ combinePaths ( defaultLibraryPath , libFileName ) ;
3835
+ ( resolvedLibReferences ??= new Map ( ) ) . set ( libFileName , result ) ;
3836
+ return result ;
3830
3837
}
3831
3838
3832
3839
function processLibReferenceDirectives ( file : SourceFile ) {
0 commit comments