Skip to content

Commit f4d372a

Browse files
authored
Fix auto import path mapping when first pattern fails (#54868)
1 parent 88d59e4 commit f4d372a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/compiler/moduleSpecifiers.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,9 @@ function tryGetModuleNameFromPaths(relativeToBaseUrl: string, paths: MapLike<rea
775775
validateEnding({ ending, value })
776776
) {
777777
const matchedStar = value.substring(prefix.length, value.length - suffix.length);
778-
return pathIsRelative(matchedStar) ? undefined : key.replace("*", matchedStar);
778+
if (!pathIsRelative(matchedStar)) {
779+
return key.replace("*", matchedStar);
780+
}
779781
}
780782
}
781783
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /package1/jsconfig.json
4+
//// {
5+
//// "compilerOptions": {
6+
//// checkJs: true,
7+
//// "paths": {
8+
//// "package1/*": ["./*"],
9+
//// "package2/*": ["../package2/*"]
10+
//// },
11+
//// "baseUrl": "."
12+
//// },
13+
//// "include": [
14+
//// ".",
15+
//// "../package2"
16+
//// ]
17+
//// }
18+
19+
// @Filename: /package1/file1.js
20+
//// bar/**/
21+
22+
// @Filename: /package2/file1.js
23+
//// export const bar = 0;
24+
25+
verify.importFixModuleSpecifiers("", ["package2/file1"], { importModuleSpecifierPreference: "shortest" });

0 commit comments

Comments
 (0)