@@ -1052,12 +1052,6 @@ export function loadWithModeAwareCache<Entry, SourceFile, ResolutionCache, Resol
1052
1052
return resolutions ;
1053
1053
}
1054
1054
1055
- function getLibFileName ( libReference : FileReference ) {
1056
- const libName = toFileNameLowerCase ( libReference . fileName ) ;
1057
- const libFileName = libMap . get ( libName ) ;
1058
- return { libName, libFileName } ;
1059
- }
1060
-
1061
1055
/** @internal */
1062
1056
export function forEachResolvedProjectReference < T > (
1063
1057
resolvedProjectReferences : readonly ( ResolvedProjectReference | undefined ) [ ] | undefined ,
@@ -1111,6 +1105,28 @@ export function getInferredLibrarayNameResolveFrom(currentDirectory: string, lib
1111
1105
return combinePaths ( currentDirectory , `__lib_node_modules_lookup_${ libFileName } __.ts` ) ;
1112
1106
}
1113
1107
1108
+ /** @internal */
1109
+ export function getLibraryNameFromLibFileName ( libFileName : string ) {
1110
+ // Support resolving to lib.dom.d.ts -> @typescript/lib-dom, and
1111
+ // lib.dom.iterable.d.ts -> @typescript/lib-dom/iterable
1112
+ // lib.es2015.symbol.wellknown.d.ts -> @typescript/lib-es2015/symbol-wellknown
1113
+ const components = libFileName . split ( "." ) ;
1114
+ let path = components [ 1 ] ;
1115
+ let i = 2 ;
1116
+ while ( components [ i ] && components [ i ] !== "d" ) {
1117
+ path += ( i === 2 ? "/" : "-" ) + components [ i ] ;
1118
+ i ++ ;
1119
+ }
1120
+ return "@typescript/lib-" + path ;
1121
+ }
1122
+
1123
+ /** @internal */
1124
+ export function getLibFileNameFromLibReference ( libReference : FileReference ) {
1125
+ const libName = toFileNameLowerCase ( libReference . fileName ) ;
1126
+ const libFileName = libMap . get ( libName ) ;
1127
+ return { libName, libFileName } ;
1128
+ }
1129
+
1114
1130
interface DiagnosticCache < T extends Diagnostic > {
1115
1131
perFile ?: Map < Path , readonly T [ ] > ;
1116
1132
allDiagnostics ?: readonly T [ ] ;
@@ -1228,7 +1244,7 @@ export function isProgramUptoDate(
1228
1244
return ! sourceFileVersionUptoDate ( sourceFile ) ||
1229
1245
hasInvalidatedResolutions ( sourceFile . path ) ||
1230
1246
some ( sourceFile . libReferenceDirectives , libRef => {
1231
- const { libFileName } = getLibFileName ( libRef ) ;
1247
+ const { libFileName } = getLibFileNameFromLibReference ( libRef ) ;
1232
1248
return ! ! libFileName && hasInvalidatedLibResolutions ( libFileName ) ;
1233
1249
} ) ;
1234
1250
}
@@ -2471,7 +2487,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
2471
2487
// Do this resolution if necessary to determine reconstruction of program
2472
2488
if ( structureIsReused !== StructureIsReused . Completely &&
2473
2489
some ( newSourceFile . libReferenceDirectives , libReference => {
2474
- const { libFileName } = getLibFileName ( libReference ) ;
2490
+ const { libFileName } = getLibFileNameFromLibReference ( libReference ) ;
2475
2491
return ! ! libFileName &&
2476
2492
pathForLibFileWorker ( libFileName ) . actual !== oldProgram ?. resolvedLibReferences ?. get ( libFileName ) ?. actual ;
2477
2493
} ) ) {
@@ -3361,7 +3377,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3361
3377
}
3362
3378
3363
3379
function getLibFileFromReference ( ref : FileReference ) {
3364
- const { libFileName } = getLibFileName ( ref ) ;
3380
+ const { libFileName } = getLibFileNameFromLibReference ( ref ) ;
3365
3381
const actualFileName = libFileName && resolvedLibReferences ?. get ( libFileName ) ?. actual ;
3366
3382
return actualFileName !== undefined ? getSourceFile ( actualFileName ) : undefined ;
3367
3383
}
@@ -3866,20 +3882,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3866
3882
return result . actual ;
3867
3883
}
3868
3884
3869
- function getLibraryName ( libFileName : string ) {
3870
- // Support resolving to lib.dom.d.ts -> @typescript/lib-dom, and
3871
- // lib.dom.iterable.d.ts -> @typescript/lib-dom/iterable
3872
- // lib.es2015.symbol.wellknown.d.ts -> @typescript/lib-es2015/symbol-wellknown
3873
- const components = libFileName . split ( "." ) ;
3874
- let path = components [ 1 ] ;
3875
- let i = 2 ;
3876
- while ( components [ i ] && components [ i ] !== "d" ) {
3877
- path += ( i === 2 ? "/" : "-" ) + components [ i ] ;
3878
- i ++ ;
3879
- }
3880
- return "@typescript/lib-" + path ;
3881
- }
3882
-
3883
3885
function pathForLibFileWorker ( libFileName : string ) : LibResolution {
3884
3886
const existing = resolvedLibProcessing ?. get ( libFileName ) ;
3885
3887
if ( existing ) return existing ;
@@ -3888,7 +3890,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3888
3890
const oldResolution = oldProgram . resolvedLibReferences ?. get ( libFileName ) ;
3889
3891
if ( oldResolution ) {
3890
3892
if ( oldResolution . resolution && isTraceEnabled ( options , host ) ) {
3891
- const libraryName = getLibraryName ( libFileName ) ;
3893
+ const libraryName = getLibraryNameFromLibFileName ( libFileName ) ;
3892
3894
const resolveFrom = getInferredLibrarayNameResolveFrom ( currentDirectory , libFileName ) ;
3893
3895
trace ( host ,
3894
3896
oldResolution . resolution . resolvedModule ?
@@ -3907,7 +3909,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3907
3909
}
3908
3910
}
3909
3911
3910
- const libraryName = getLibraryName ( libFileName ) ;
3912
+ const libraryName = getLibraryNameFromLibFileName ( libFileName ) ;
3911
3913
const resolveFrom = getInferredLibrarayNameResolveFrom ( currentDirectory , libFileName ) ;
3912
3914
const resolution = actualResolveLibrary ( libraryName , resolveFrom , options , libFileName ) ;
3913
3915
const result : LibResolution = {
@@ -3922,7 +3924,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3922
3924
3923
3925
function processLibReferenceDirectives ( file : SourceFile ) {
3924
3926
forEach ( file . libReferenceDirectives , ( libReference , index ) => {
3925
- const { libName, libFileName } = getLibFileName ( libReference ) ;
3927
+ const { libName, libFileName } = getLibFileNameFromLibReference ( libReference ) ;
3926
3928
if ( libFileName ) {
3927
3929
// we ignore any 'no-default-lib' reference set on this file.
3928
3930
processRootFile ( pathForLibFile ( libFileName ) , /*isDefaultLib*/ true , /*ignoreNoDefaultLib*/ true , { kind : FileIncludeKind . LibReferenceDirective , file : file . path , index, } ) ;
0 commit comments