Skip to content

Commit 3e824f1

Browse files
authored
Don’t offer non-relative non-paths path when baseUrl is undefined (#40813)
1 parent 343a0a0 commit 3e824f1

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/compiler/moduleSpecifiers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ namespace ts.moduleSpecifiers {
174174
const bundledPkgReference = bundledPackageName ? combinePaths(bundledPackageName, relativeToBaseUrl) : relativeToBaseUrl;
175175
const importRelativeToBaseUrl = removeExtensionAndIndexPostFix(bundledPkgReference, ending, compilerOptions);
176176
const fromPaths = paths && tryGetModuleNameFromPaths(removeFileExtension(bundledPkgReference), importRelativeToBaseUrl, paths);
177-
const nonRelative = fromPaths === undefined ? importRelativeToBaseUrl : fromPaths;
177+
const nonRelative = fromPaths === undefined && baseUrl !== undefined ? importRelativeToBaseUrl : fromPaths;
178+
if (!nonRelative) {
179+
return relativePath;
180+
}
178181

179182
if (relativePreference === RelativePreference.NonRelative) {
180183
return nonRelative;

tests/cases/fourslash/importNameCodeFix_pathsWithoutBaseUrl.ts renamed to tests/cases/fourslash/importNameCodeFix_pathsWithoutBaseUrl1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//// "compilerOptions": {
66
//// "module": "commonjs",
77
//// "paths": {
8-
//// "@app/*": ["lib/*"]
8+
//// "@app/*": ["./lib/*"]
99
//// }
1010
//// }
1111
//// }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /packages/test-package-1/tsconfig.json
4+
//// {
5+
//// "compilerOptions": {
6+
//// "module": "commonjs",
7+
//// "paths": {
8+
//// "test-package-2/*": ["../test-package-2/src/*"]
9+
//// }
10+
//// }
11+
//// }
12+
13+
// @Filename: /packages/test-package-1/src/common/logging.ts
14+
//// export class Logger {};
15+
16+
// @Filename: /packages/test-package-1/src/something/index.ts
17+
//// Logger/**/
18+
19+
20+
goTo.marker("");
21+
verify.importFixAtPosition([`import { Logger } from "../common/logging";\n\nLogger`]);

0 commit comments

Comments
 (0)