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
*/

View File

@@ -0,0 +1,21 @@
/main.mts(1,16): error TS2307: Cannot find module 'double-asterisk/a/*/b/*/c/*' or its corresponding type declarations.
==== /node_modules/double-asterisk/package.json (0 errors) ====
{
"name": "double-asterisk",
"version": "1.0.0",
"type": "module",
"exports": {
"./a/*/b/*/c/*": "./example.js"
}
}
==== /node_modules/double-asterisk/example.d.ts (0 errors) ====
export {};
==== /main.mts (1 errors) ====
import {} from "double-asterisk/a/*/b/*/c/*";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'double-asterisk/a/*/b/*/c/*' or its corresponding type declarations.

View File

@@ -0,0 +1,19 @@
// @module: nodenext
// @noTypesAndSymbols: true
// @noEmit: true
// @Filename: /node_modules/double-asterisk/package.json
{
"name": "double-asterisk",
"version": "1.0.0",
"type": "module",
"exports": {
"./a/*/b/*/c/*": "./example.js"
}
}
// @Filename: /node_modules/double-asterisk/example.d.ts
export {};
// @Filename: /main.mts
import {} from "double-asterisk/a/*/b/*/c/*";