Skip to content

Commit 66b3cfa

Browse files
author
Andy Hanson
committed
wip
1 parent 79e2628 commit 66b3cfa

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/compiler/moduleSpecifiers.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,10 @@ namespace ts.moduleSpecifiers {
105105

106106
const importRelativeToBaseUrl = removeExtensionAndIndexPostFix(relativeToBaseUrl, moduleResolutionKind, addJsExtension);
107107
const fromPaths = paths && tryGetModuleNameFromPaths(removeFileExtension(relativeToBaseUrl), importRelativeToBaseUrl, paths);
108-
if (fromPaths) {
109-
return [fromPaths];
110-
}
108+
const nonRelative = fromPaths === undefined ? importRelativeToBaseUrl : fromPaths;
111109

112110
if (preferences.importModuleSpecifierPreference === "non-relative") {
113-
return [importRelativeToBaseUrl];
111+
return [nonRelative];
114112
}
115113

116114
if (preferences.importModuleSpecifierPreference !== undefined) Debug.assertNever(preferences.importModuleSpecifierPreference);
@@ -120,8 +118,8 @@ namespace ts.moduleSpecifiers {
120118
}
121119

122120
// Prefer a relative import over a baseUrl import if it has fewer components.
123-
const relativeFirst = countPathComponents(relativePath) < countPathComponents(importRelativeToBaseUrl);
124-
return relativeFirst ? [relativePath, importRelativeToBaseUrl] : [importRelativeToBaseUrl, relativePath];
121+
const relativeFirst = countPathComponents(relativePath) < countPathComponents(nonRelative);
122+
return relativeFirst ? [relativePath, nonRelative] : [nonRelative, relativePath];
125123
}
126124

127125
function countPathComponents(path: string): number {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /tsconfig.json
4+
////{
5+
//// "compilerOptions": {
6+
//// "baseUrl": "./src",
7+
//// "paths": {
8+
//// "features/*": ["features/*"]
9+
//// }
10+
//// }
11+
////}
12+
13+
// @Filename: /src/features/feature1/file1.ts
14+
////foo;
15+
16+
// @Filename: /src/features/feature1/file2.ts
17+
////export const foo = 0;
18+
19+
goTo.file("/src/features/feature1/file1.ts");
20+
verify.importFixAtPosition([
21+
`import { foo } from "./file2";
22+
23+
foo;`,
24+
`import { foo } from "features/feature1/file2";
25+
26+
foo;`,
27+
]);

0 commit comments

Comments
 (0)