Skip to content

Commit af75214

Browse files
committed
Replaces the default index resolver with '/index' instead of '' when handling dts bundles'
1 parent d897646 commit af75214

File tree

5 files changed

+153
-1
lines changed

5 files changed

+153
-1
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5340,7 +5340,10 @@ namespace ts {
53405340
specifierCompilerOptions,
53415341
contextFile,
53425342
moduleResolverHost,
5343-
{ importModuleSpecifierPreference: isBundle ? "non-relative" : "relative" },
5343+
{
5344+
importModuleSpecifierPreference: isBundle ? "non-relative" : "relative",
5345+
importModuleSpecifierEnding: isBundle ? "index" : undefined
5346+
},
53445347
));
53455348
links.specifierCache ??= new Map();
53465349
links.specifierCache.set(contextFile.path, specifier);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//// [tests/cases/compiler/bundledDtsInternalImports.ts] ////
2+
3+
//// [index.ts]
4+
export * from "./nested";
5+
6+
//// [base.ts]
7+
import { B } from "./shared";
8+
9+
export function f() {
10+
return new B();
11+
}
12+
13+
//// [derived.ts]
14+
import { f } from "./base";
15+
16+
export function g() {
17+
return f();
18+
}
19+
20+
//// [index.ts]
21+
export * from "./base";
22+
export * from "./derived";
23+
export * from "./shared";
24+
25+
//// [shared.ts]
26+
export class B {}
27+
28+
29+
30+
31+
//// [out.d.ts]
32+
declare module "nested/shared" {
33+
export class B {
34+
}
35+
}
36+
declare module "nested/base" {
37+
import { B } from "nested/shared";
38+
export function f(): B;
39+
}
40+
declare module "nested/derived" {
41+
export function g(): import("index").B;
42+
}
43+
declare module "nested/index" {
44+
export * from "nested/base";
45+
export * from "nested/derived";
46+
export * from "nested/shared";
47+
}
48+
declare module "index" {
49+
export * from "nested/index";
50+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
=== tests/cases/compiler/index.ts ===
2+
export * from "./nested";
3+
No type information for this code.
4+
No type information for this code.=== tests/cases/compiler/nested/base.ts ===
5+
import { B } from "./shared";
6+
>B : Symbol(B, Decl(base.ts, 0, 8))
7+
8+
export function f() {
9+
>f : Symbol(f, Decl(base.ts, 0, 29))
10+
11+
return new B();
12+
>B : Symbol(B, Decl(base.ts, 0, 8))
13+
}
14+
15+
=== tests/cases/compiler/nested/derived.ts ===
16+
import { f } from "./base";
17+
>f : Symbol(f, Decl(derived.ts, 0, 8))
18+
19+
export function g() {
20+
>g : Symbol(g, Decl(derived.ts, 0, 27))
21+
22+
return f();
23+
>f : Symbol(f, Decl(derived.ts, 0, 8))
24+
}
25+
26+
=== tests/cases/compiler/nested/index.ts ===
27+
export * from "./base";
28+
No type information for this code.export * from "./derived";
29+
No type information for this code.export * from "./shared";
30+
No type information for this code.
31+
No type information for this code.=== tests/cases/compiler/nested/shared.ts ===
32+
export class B {}
33+
>B : Symbol(B, Decl(shared.ts, 0, 0))
34+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
=== tests/cases/compiler/index.ts ===
2+
export * from "./nested";
3+
No type information for this code.
4+
No type information for this code.=== tests/cases/compiler/nested/base.ts ===
5+
import { B } from "./shared";
6+
>B : typeof B
7+
8+
export function f() {
9+
>f : () => B
10+
11+
return new B();
12+
>new B() : B
13+
>B : typeof B
14+
}
15+
16+
=== tests/cases/compiler/nested/derived.ts ===
17+
import { f } from "./base";
18+
>f : () => import("tests/cases/compiler/index").B
19+
20+
export function g() {
21+
>g : () => import("tests/cases/compiler/index").B
22+
23+
return f();
24+
>f() : import("tests/cases/compiler/index").B
25+
>f : () => import("tests/cases/compiler/index").B
26+
}
27+
28+
=== tests/cases/compiler/nested/index.ts ===
29+
export * from "./base";
30+
No type information for this code.export * from "./derived";
31+
No type information for this code.export * from "./shared";
32+
No type information for this code.
33+
No type information for this code.=== tests/cases/compiler/nested/shared.ts ===
34+
export class B {}
35+
>B : B
36+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// @module: commonjs
2+
// @declaration: true
3+
// @emitDeclarationOnly: true
4+
// @outFile: ./dist/out.d.ts
5+
6+
// @Filename: index.ts
7+
export * from "./nested";
8+
9+
// @Filename: nested/base.ts
10+
import { B } from "./shared";
11+
12+
export function f() {
13+
return new B();
14+
}
15+
16+
// @Filename: nested/derived.ts
17+
import { f } from "./base";
18+
19+
export function g() {
20+
return f();
21+
}
22+
23+
// @Filename: nested/index.ts
24+
export * from "./base";
25+
export * from "./derived";
26+
export * from "./shared";
27+
28+
// @Filename: nested/shared.ts
29+
export class B {}

0 commit comments

Comments
 (0)