@@ -328,7 +328,6 @@ import {
328
328
WriteFileCallback ,
329
329
WriteFileCallbackData ,
330
330
writeFileEnsuringDirectories ,
331
- zipToModeAwareCache ,
332
331
} from "./_namespaces/ts" ;
333
332
import * as performance from "./_namespaces/ts.performance" ;
334
333
@@ -1514,9 +1513,9 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
1514
1513
let resolvedLibProcessing : Map < string , LibResolution > | undefined ;
1515
1514
1516
1515
let resolvedModules : Map < Path , ModeAwareCache < ResolvedModuleWithFailedLookupLocations > > | undefined ;
1517
- let resolvedModulesProcessing : Map < Path , ModeAwareCache < ResolvedModuleWithFailedLookupLocations > > | undefined ;
1516
+ let resolvedModulesProcessing : Map < Path , readonly ResolvedModuleWithFailedLookupLocations [ ] > | undefined ;
1518
1517
let resolvedTypeReferenceDirectiveNames : Map < Path , ModeAwareCache < ResolvedTypeReferenceDirectiveWithFailedLookupLocations > > | undefined ;
1519
- let resolvedTypeReferenceDirectiveNamesProcessing : Map < Path , ModeAwareCache < ResolvedTypeReferenceDirectiveWithFailedLookupLocations > > | undefined ;
1518
+ let resolvedTypeReferenceDirectiveNamesProcessing : Map < Path , readonly ResolvedTypeReferenceDirectiveWithFailedLookupLocations [ ] > | undefined ;
1520
1519
1521
1520
let packageMap : Map < string , boolean > | undefined ;
1522
1521
@@ -2095,23 +2094,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
2095
2094
return resolveModuleNamesWorker ( moduleNames , file , /*reusedNames*/ undefined ) ;
2096
2095
}
2097
2096
2098
- const alreadyComputedResolutions = resolvedModulesProcessing ?. get ( file . path ) ;
2099
- if ( alreadyComputedResolutions ) {
2100
- // `file` was created for the new program.
2101
- //
2102
- // We only set `file.resolvedModules` via work from the current function,
2103
- // so it is defined iff we already called the current function on `file`.
2104
- // That call happened no later than the creation of the `file` object,
2105
- // which per above occurred during the current program creation.
2106
- // Since we assume the filesystem does not change during program creation,
2107
- // it is safe to reuse resolutions from the earlier call.
2108
- const result : ResolvedModuleWithFailedLookupLocations [ ] = [ ] ;
2109
- for ( const moduleName of moduleNames ) {
2110
- const resolvedModule = alreadyComputedResolutions . get ( moduleName . text , getModeForUsageLocation ( file , moduleName ) ) ! ;
2111
- result . push ( resolvedModule ) ;
2112
- }
2113
- return result ;
2114
- }
2115
2097
// At this point, we know at least one of the following hold:
2116
2098
// - file has local declarations for ambient modules
2117
2099
// - old program state is available
@@ -2240,33 +2222,12 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
2240
2222
return resolveTypeReferenceDirectiveNamesWorker ( typeDirectiveNames , containingFile , /*reusedNames*/ undefined ) ;
2241
2223
}
2242
2224
2243
- const oldSourceFile = ! isString ( containingFile ) ? oldProgram && oldProgram . getSourceFile ( containingFile . fileName ) : undefined ;
2244
- if ( ! isString ( containingFile ) ) {
2245
- const alreadyComputedResolutions = resolvedTypeReferenceDirectiveNamesProcessing ?. get ( containingFile . path ) ;
2246
- if ( alreadyComputedResolutions ) {
2247
- // `file` was created for the new program.
2248
- //
2249
- // We only set `file.resolvedTypeReferenceDirectiveNames` via work from the current function,
2250
- // so it is defined iff we already called the current function on `file`.
2251
- // That call happened no later than the creation of the `file` object,
2252
- // which per above occurred during the current program creation.
2253
- // Since we assume the filesystem does not change during program creation,
2254
- // it is safe to reuse resolutions from the earlier call.
2255
- const result : ResolvedTypeReferenceDirectiveWithFailedLookupLocations [ ] = [ ] ;
2256
- for ( const typeDirectiveName of typeDirectiveNames as readonly FileReference [ ] ) {
2257
- // We lower-case all type references because npm automatically lowercases all packages. See GH#9824.
2258
- const resolvedTypeReferenceDirective = alreadyComputedResolutions . get ( getTypeReferenceResolutionName ( typeDirectiveName ) , getModeForFileReference ( typeDirectiveName , containingFile . impliedNodeFormat ) ) ! ;
2259
- result . push ( resolvedTypeReferenceDirective ) ;
2260
- }
2261
- return result ;
2262
- }
2263
- }
2264
-
2265
2225
/** An ordered list of module names for which we cannot recover the resolution. */
2266
2226
let unknownTypeReferenceDirectiveNames : T [ ] | undefined ;
2267
2227
let result : ResolvedTypeReferenceDirectiveWithFailedLookupLocations [ ] | undefined ;
2268
2228
let reusedNames : T [ ] | undefined ;
2269
2229
const containingSourceFile = ! isString ( containingFile ) ? containingFile : undefined ;
2230
+ const oldSourceFile = ! isString ( containingFile ) ? oldProgram && oldProgram . getSourceFile ( containingFile . fileName ) : undefined ;
2270
2231
const canReuseResolutions = ! isString ( containingFile ) ?
2271
2232
containingFile === oldSourceFile && ! hasInvalidatedResolutions ( containingFile . path ) :
2272
2233
! hasInvalidatedResolutions ( toPath ( containingFile ) ) ;
@@ -2516,24 +2477,19 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
2516
2477
for ( const newSourceFile of modifiedSourceFiles ) {
2517
2478
const moduleNames = getModuleNames ( newSourceFile ) ;
2518
2479
const resolutions = resolveModuleNamesReusingOldState ( moduleNames , newSourceFile ) ;
2480
+ ( resolvedModulesProcessing ??= new Map ( ) ) . set ( newSourceFile . path , resolutions ) ;
2519
2481
const oldResolutions = oldProgram . resolvedModules ?. get ( newSourceFile . path ) ;
2520
2482
// ensure that module resolution results are still correct
2521
2483
const resolutionsChanged = hasChangesInResolutions ( moduleNames , newSourceFile , resolutions , oldResolutions , moduleResolutionIsEqualTo , moduleResolutionNameAndModeGetter ) ;
2522
- if ( resolutionsChanged ) {
2523
- structureIsReused = StructureIsReused . SafeModules ;
2524
- ( resolvedModulesProcessing ??= new Map ( ) ) . set ( newSourceFile . path , zipToModeAwareCache ( newSourceFile , moduleNames , resolutions , moduleResolutionNameAndModeGetter ) ) ;
2525
- }
2526
- else if ( oldResolutions ) {
2527
- ( resolvedModulesProcessing ??= new Map ( ) ) . set ( newSourceFile . path , oldResolutions ) ;
2528
- }
2484
+ if ( resolutionsChanged ) structureIsReused = StructureIsReused . SafeModules ;
2529
2485
const typesReferenceDirectives = newSourceFile . typeReferenceDirectives ;
2530
2486
const typeReferenceResolutions = resolveTypeReferenceDirectiveNamesReusingOldState ( typesReferenceDirectives , newSourceFile ) ;
2487
+ ( resolvedTypeReferenceDirectiveNamesProcessing ??= new Map ( ) ) . set ( newSourceFile . path , typeReferenceResolutions ) ;
2531
2488
// ensure that types resolutions are still correct
2532
2489
const oldTypeResolutions = oldProgram . resolvedTypeReferenceDirectiveNames ?. get ( newSourceFile . path ) ;
2533
2490
const typeReferenceResolutionsChanged = hasChangesInResolutions ( typesReferenceDirectives , newSourceFile , typeReferenceResolutions , oldTypeResolutions , typeDirectiveIsEqualTo , typeReferenceResolutionNameAndModeGetter ) ;
2534
2491
if ( typeReferenceResolutionsChanged ) {
2535
2492
structureIsReused = StructureIsReused . SafeModules ;
2536
- ( resolvedTypeReferenceDirectiveNamesProcessing ??= new Map ( ) ) . set ( newSourceFile . path , zipToModeAwareCache ( newSourceFile , typesReferenceDirectives , typeReferenceResolutions , typeReferenceResolutionNameAndModeGetter ) ) ;
2537
2493
}
2538
2494
else if ( oldTypeResolutions ) {
2539
2495
( resolvedTypeReferenceDirectiveNamesProcessing ??= new Map ( ) ) . set ( newSourceFile . path , oldTypeResolutions ) ;
@@ -3844,7 +3800,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3844
3800
const typeDirectives = file . typeReferenceDirectives ;
3845
3801
if ( ! typeDirectives . length ) return ;
3846
3802
3847
- const resolutions = resolveTypeReferenceDirectiveNamesReusingOldState ( typeDirectives , file ) ;
3803
+ const resolutions = resolvedTypeReferenceDirectiveNamesProcessing ?. get ( file . path ) ||
3804
+ resolveTypeReferenceDirectiveNamesReusingOldState ( typeDirectives , file ) ;
3848
3805
const resolutionsInFile = createModeAwareCache < ResolvedTypeReferenceDirectiveWithFailedLookupLocations > ( ) ;
3849
3806
( resolvedTypeReferenceDirectiveNames ??= new Map ( ) ) . set ( file . path , resolutionsInFile ) ;
3850
3807
for ( let index = 0 ; index < typeDirectives . length ; index ++ ) {
@@ -4020,7 +3977,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
4020
3977
if ( file . imports . length || file . moduleAugmentations . length ) {
4021
3978
// Because global augmentation doesn't have string literal name, we can check for global augmentation as such.
4022
3979
const moduleNames = getModuleNames ( file ) ;
4023
- const resolutions = resolveModuleNamesReusingOldState ( moduleNames , file ) ;
3980
+ const resolutions = resolvedModulesProcessing ?. get ( file . path ) ||
3981
+ resolveModuleNamesReusingOldState ( moduleNames , file ) ;
4024
3982
Debug . assert ( resolutions . length === moduleNames . length ) ;
4025
3983
const optionsForFile = ( useSourceOfProjectReferenceRedirect ? getRedirectReferenceForResolution ( file ) ?. commandLine . options : undefined ) || options ;
4026
3984
const resolutionsInFile = createModeAwareCache < ResolutionWithFailedLookupLocations > ( ) ;
0 commit comments