mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 19:16:17 -06:00
Instead of iterating over resolutions to invalidate per global cache pass, invalidate them at usage site
This commit is contained in:
parent
4f34cae519
commit
3234d102ed
@ -764,6 +764,9 @@ export function createResolutionCache(
|
||||
hasInvalidatedResolutions: path =>
|
||||
customHasInvalidatedResolutions(path) ||
|
||||
allModuleAndTypeResolutionsAreInvalidated ||
|
||||
resolutionsWithGlobalCachePassAreInvalidated ||
|
||||
resolutionsWithoutGlobalCachePassAreInvalidated ||
|
||||
unresolvedResolutionsWithGlobalCachePassAreInvalidated ||
|
||||
!!collected?.has(path),
|
||||
hasInvalidatedLibResolutions: libFileName =>
|
||||
customHasInvalidatedLibResolutions(libFileName) ||
|
||||
@ -800,6 +803,9 @@ export function createResolutionCache(
|
||||
|
||||
function finishCachingPerDirectoryResolution(newProgram: Program | undefined, oldProgram: Program | undefined) {
|
||||
allModuleAndTypeResolutionsAreInvalidated = false;
|
||||
resolutionsWithGlobalCachePassAreInvalidated = false;
|
||||
resolutionsWithoutGlobalCachePassAreInvalidated = false;
|
||||
unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
|
||||
watchFailedLookupLocationOfNonRelativeModuleResolutions();
|
||||
// Update file watches
|
||||
if (newProgram !== oldProgram) {
|
||||
@ -857,6 +863,13 @@ export function createResolutionCache(
|
||||
}
|
||||
}
|
||||
|
||||
function isResolutionInvalidatedPerGlobalCacheOptions(resolution: ResolutionWithFailedLookupLocations) {
|
||||
if (resolutionsWithGlobalCachePassAreInvalidated && resolution.globalCacheResolution) return true;
|
||||
if (resolutionsWithoutGlobalCachePassAreInvalidated && resolution.globalCacheResolution === false) return true;
|
||||
if (unresolvedResolutionsWithGlobalCachePassAreInvalidated && resolution.globalCacheResolution && isUnresolvedOrResolvedToJs(resolution as ResolvedModuleWithFailedLookupLocations)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
interface ResolveNamesWithLocalCacheInput<Entry, SourceFile, T extends ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName> {
|
||||
entries: readonly Entry[];
|
||||
containingFile: string;
|
||||
@ -902,7 +915,13 @@ export function createResolutionCache(
|
||||
// Resolution is valid if it is present and not invalidated
|
||||
if (
|
||||
!seenNamesInFile.has(name, mode) &&
|
||||
(allModuleAndTypeResolutionsAreInvalidated || unmatchedRedirects || !resolution || resolution.isInvalidated)
|
||||
(
|
||||
allModuleAndTypeResolutionsAreInvalidated ||
|
||||
unmatchedRedirects ||
|
||||
!resolution ||
|
||||
resolution.isInvalidated ||
|
||||
isResolutionInvalidatedPerGlobalCacheOptions(resolution)
|
||||
)
|
||||
) {
|
||||
const existingResolution = resolution;
|
||||
resolution = loader.resolve(name, mode);
|
||||
@ -1591,9 +1610,6 @@ export function createResolutionCache(
|
||||
startsWithPathChecks = undefined;
|
||||
isInDirectoryChecks = undefined;
|
||||
affectingPathChecks = undefined;
|
||||
resolutionsWithGlobalCachePassAreInvalidated = false;
|
||||
resolutionsWithoutGlobalCachePassAreInvalidated = false;
|
||||
unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
|
||||
return true;
|
||||
}
|
||||
let invalidated = false;
|
||||
@ -1607,11 +1623,7 @@ export function createResolutionCache(
|
||||
affectingPathChecksForFile = undefined;
|
||||
}
|
||||
|
||||
if (
|
||||
!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks &&
|
||||
!resolutionsWithGlobalCachePassAreInvalidated && !resolutionsWithoutGlobalCachePassAreInvalidated &&
|
||||
!unresolvedResolutionsWithGlobalCachePassAreInvalidated
|
||||
) {
|
||||
if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks) {
|
||||
return invalidated;
|
||||
}
|
||||
|
||||
@ -1622,9 +1634,6 @@ export function createResolutionCache(
|
||||
isInDirectoryChecks = undefined;
|
||||
invalidated = invalidateResolutions(resolutionsWithOnlyAffectingLocations, canInvalidatedFailedLookupResolutionWithAffectingLocation) || invalidated;
|
||||
affectingPathChecks = undefined;
|
||||
resolutionsWithGlobalCachePassAreInvalidated = false;
|
||||
resolutionsWithoutGlobalCachePassAreInvalidated = false;
|
||||
unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
|
||||
return invalidated;
|
||||
}
|
||||
|
||||
@ -1644,9 +1653,6 @@ export function createResolutionCache(
|
||||
}
|
||||
|
||||
function canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution: ResolutionWithFailedLookupLocations) {
|
||||
if (resolutionsWithGlobalCachePassAreInvalidated && resolution.globalCacheResolution) return true;
|
||||
if (resolutionsWithoutGlobalCachePassAreInvalidated && resolution.globalCacheResolution === false) return true;
|
||||
if (unresolvedResolutionsWithGlobalCachePassAreInvalidated && resolution.globalCacheResolution && isUnresolvedOrResolvedToJs(resolution as ResolvedModuleWithFailedLookupLocations)) return true;
|
||||
return !!affectingPathChecks && resolution.affectingLocations?.some(location => affectingPathChecks!.has(location));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user