Skip to content

Commit 30095a2

Browse files
authored
Do not populate exports pattern keys if more than one * exists (microsoft#58123)
1 parent b6351c6 commit 30095a2

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/compiler/moduleNameResolver.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2703,7 +2703,7 @@ function loadModuleFromImportsOrExports(extensions: Extensions, state: ModuleRes
27032703
const target = (lookupTable as { [idx: string]: unknown; })[moduleName];
27042704
return loadModuleFromTargetImportOrExport(target, /*subpath*/ "", /*pattern*/ false, moduleName);
27052705
}
2706-
const expandingKeys = sort(filter(getOwnKeys(lookupTable as MapLike<unknown>), k => k.includes("*") || endsWith(k, "/")), comparePatternKeys);
2706+
const expandingKeys = sort(filter(getOwnKeys(lookupTable as MapLike<unknown>), k => hasOneAsterisk(k) || endsWith(k, "/")), comparePatternKeys);
27072707
for (const potentialTarget of expandingKeys) {
27082708
if (state.features & NodeResolutionFeatures.ExportsPatternTrailers && matchesPatternWithTrailer(potentialTarget, moduleName)) {
27092709
const target = (lookupTable as { [idx: string]: unknown; })[potentialTarget];
@@ -2731,6 +2731,11 @@ function loadModuleFromImportsOrExports(extensions: Extensions, state: ModuleRes
27312731
}
27322732
}
27332733

2734+
function hasOneAsterisk(patternKey: string): boolean {
2735+
const firstStar = patternKey.indexOf("*");
2736+
return firstStar !== -1 && firstStar === patternKey.lastIndexOf("*");
2737+
}
2738+
27342739
/**
27352740
* Gets the self-recursive function specialized to retrieving the targeted import/export element for the given resolution configuration
27362741
*/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/main.mts(1,16): error TS2307: Cannot find module 'double-asterisk/a/*/b/*/c/*' or its corresponding type declarations.
2+
3+
4+
==== /node_modules/double-asterisk/package.json (0 errors) ====
5+
{
6+
"name": "double-asterisk",
7+
"version": "1.0.0",
8+
"type": "module",
9+
"exports": {
10+
"./a/*/b/*/c/*": "./example.js"
11+
}
12+
}
13+
14+
==== /node_modules/double-asterisk/example.d.ts (0 errors) ====
15+
export {};
16+
17+
==== /main.mts (1 errors) ====
18+
import {} from "double-asterisk/a/*/b/*/c/*";
19+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20+
!!! error TS2307: Cannot find module 'double-asterisk/a/*/b/*/c/*' or its corresponding type declarations.
21+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @module: nodenext
2+
// @noTypesAndSymbols: true
3+
// @noEmit: true
4+
5+
// @Filename: /node_modules/double-asterisk/package.json
6+
{
7+
"name": "double-asterisk",
8+
"version": "1.0.0",
9+
"type": "module",
10+
"exports": {
11+
"./a/*/b/*/c/*": "./example.js"
12+
}
13+
}
14+
15+
// @Filename: /node_modules/double-asterisk/example.d.ts
16+
export {};
17+
18+
// @Filename: /main.mts
19+
import {} from "double-asterisk/a/*/b/*/c/*";

0 commit comments

Comments
 (0)