Do not populate exports pattern keys if more than one * exists (#58123)

This commit is contained in:
Andrew Branch
2024-04-10 10:12:02 -07:00
committed by GitHub
parent b6351c6136
commit 30095a225c
3 changed files with 46 additions and 1 deletions

View File

@@ -2703,7 +2703,7 @@ function loadModuleFromImportsOrExports(extensions: Extensions, state: ModuleRes
const target = (lookupTable as { [idx: string]: unknown; })[moduleName];
return loadModuleFromTargetImportOrExport(target, /*subpath*/ "", /*pattern*/ false, moduleName);
}
const expandingKeys = sort(filter(getOwnKeys(lookupTable as MapLike<unknown>), k => k.includes("*") || endsWith(k, "/")), comparePatternKeys);
const expandingKeys = sort(filter(getOwnKeys(lookupTable as MapLike<unknown>), k => hasOneAsterisk(k) || endsWith(k, "/")), comparePatternKeys);
for (const potentialTarget of expandingKeys) {
if (state.features & NodeResolutionFeatures.ExportsPatternTrailers && matchesPatternWithTrailer(potentialTarget, moduleName)) {
const target = (lookupTable as { [idx: string]: unknown; })[potentialTarget];
@@ -2731,6 +2731,11 @@ function loadModuleFromImportsOrExports(extensions: Extensions, state: ModuleRes
}
}
function hasOneAsterisk(patternKey: string): boolean {
const firstStar = patternKey.indexOf("*");
return firstStar !== -1 && firstStar === patternKey.lastIndexOf("*");
}
/**
* Gets the self-recursive function specialized to retrieving the targeted import/export element for the given resolution configuration
*/