Fix auto import path mapping when first pattern fails (#54868)

This commit is contained in:
Andrew Branch 2023-07-03 15:02:13 -07:00 committed by GitHub
parent 88d59e40e4
commit f4d372aef4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -775,7 +775,9 @@ function tryGetModuleNameFromPaths(relativeToBaseUrl: string, paths: MapLike<rea
validateEnding({ ending, value })
) {
const matchedStar = value.substring(prefix.length, value.length - suffix.length);
return pathIsRelative(matchedStar) ? undefined : key.replace("*", matchedStar);
if (!pathIsRelative(matchedStar)) {
return key.replace("*", matchedStar);
}
}
}
}

View File

@ -0,0 +1,25 @@
/// <reference path="fourslash.ts" />
// @Filename: /package1/jsconfig.json
//// {
//// "compilerOptions": {
//// checkJs: true,
//// "paths": {
//// "package1/*": ["./*"],
//// "package2/*": ["../package2/*"]
//// },
//// "baseUrl": "."
//// },
//// "include": [
//// ".",
//// "../package2"
//// ]
//// }
// @Filename: /package1/file1.js
//// bar/**/
// @Filename: /package2/file1.js
//// export const bar = 0;
verify.importFixModuleSpecifiers("", ["package2/file1"], { importModuleSpecifierPreference: "shortest" });