Skip to content

Commit e5426d0

Browse files
fix: also respect compilerOptions.moduleResolution for ending preferences
1 parent bbb8348 commit e5426d0

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

src/compiler/utilities.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9139,7 +9139,9 @@ export function usesExtensionsOnImports({ imports }: SourceFile, hasExtension: (
91399139

91409140
/** @internal */
91419141
export function getModuleSpecifierEndingPreference(preference: UserPreferences["importModuleSpecifierEnding"], resolutionMode: ResolutionMode, compilerOptions: CompilerOptions, sourceFile: SourceFile): ModuleSpecifierEnding {
9142-
if (preference === "js" || resolutionMode === ModuleKind.ESNext) {
9142+
if (preference === "js" ||
9143+
resolutionMode === ModuleKind.ESNext ||
9144+
[ModuleResolutionKind.Node16, ModuleResolutionKind.NodeNext].includes(compilerOptions.moduleResolution!)) {
91439145
// Extensions are explicitly requested or required. Now choose between .js and .ts.
91449146
if (!shouldAllowImportingTsExtension(compilerOptions)) {
91459147
return ModuleSpecifierEnding.JsExtension;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// @Filename: /tsconfig.json
4+
////{
5+
//// "compilerOptions": {
6+
//// "moduleResolution": "Node16",
7+
//// }
8+
////}
9+
10+
// @Filename: /src/main.ts
11+
////[|export function someLibFn(): string {
12+
//// return main();
13+
////}|]
14+
////
15+
////function main(): string {
16+
//// return "hello world!";
17+
////}
18+
////console.log(someLibFn());
19+
20+
// @Filename: /other.ts
21+
////import { someLibFn } from "./src/main.js";
22+
////
23+
////function someOtherFn(): string {
24+
//// return someLibFn();
25+
////}
26+
27+
// @Filename: /act/action.ts
28+
////import { someLibFn } from "../src/main.js";
29+
////
30+
////function doAction(): string {
31+
//// return someLibFn();
32+
////}
33+
34+
35+
verify.moveToNewFile({
36+
newFileContents: {
37+
"/src/main.ts":
38+
`import { someLibFn } from "./someLibFn.js";
39+
40+
export function main(): string {
41+
return "hello world!";
42+
}
43+
console.log(someLibFn());`,
44+
45+
"/src/someLibFn.ts":
46+
`import { main } from "./main.js";
47+
48+
export function someLibFn(): string {
49+
return main();
50+
}
51+
`,
52+
53+
"/other.ts":
54+
`import { someLibFn } from "./src/someLibFn.js";
55+
56+
function someOtherFn(): string {
57+
return someLibFn();
58+
}`,
59+
60+
"/act/action.ts":
61+
`import { someLibFn } from "../src/someLibFn.js";
62+
63+
function doAction(): string {
64+
return someLibFn();
65+
}`,
66+
}
67+
});

0 commit comments

Comments
 (0)