Skip to content

Commit 28b91fb

Browse files
authored
Add regression test for 1328 (#1341)
1 parent eda2b28 commit 28b91fb

File tree

4 files changed

+164
-0
lines changed

4 files changed

+164
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//// [tests/cases/compiler/subpathImportDeclarationEmit.ts] ////
2+
3+
//// [package.json]
4+
{
5+
"name": "pkg",
6+
"type": "module",
7+
"imports": {
8+
"#subpath": "./src/subpath.ts"
9+
},
10+
"exports": {
11+
"./*": "./dist/*"
12+
}
13+
}
14+
15+
//// [subpath.ts]
16+
async function bar(): Promise<string> {
17+
return "bar";
18+
}
19+
export const barrel = { bar };
20+
21+
//// [indirect.ts]
22+
import { barrel } from "#subpath";
23+
const { bar } = barrel;
24+
export { bar };
25+
26+
//// [main.ts]
27+
import { bar } from "./indirect.js";
28+
console.log(await bar());
29+
30+
31+
//// [subpath.js]
32+
async function bar() {
33+
return "bar";
34+
}
35+
export const barrel = { bar };
36+
//// [indirect.js]
37+
import { barrel } from "#subpath";
38+
const { bar } = barrel;
39+
export { bar };
40+
//// [main.js]
41+
import { bar } from "./indirect.js";
42+
console.log(await bar());
43+
44+
45+
//// [subpath.d.ts]
46+
declare function bar(): Promise<string>;
47+
export declare const barrel: {
48+
bar: typeof bar;
49+
};
50+
export {};
51+
//// [indirect.d.ts]
52+
declare const bar: () => Promise<string>;
53+
export { bar };
54+
//// [main.d.ts]
55+
export {};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//// [tests/cases/compiler/subpathImportDeclarationEmit.ts] ////
2+
3+
=== /src/main.ts ===
4+
import { bar } from "./indirect.js";
5+
>bar : Symbol(bar, Decl(main.ts, 0, 8))
6+
7+
console.log(await bar());
8+
>console.log : Symbol(log, Decl(lib.dom.d.ts, --, --))
9+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
10+
>log : Symbol(log, Decl(lib.dom.d.ts, --, --))
11+
>bar : Symbol(bar, Decl(main.ts, 0, 8))
12+
13+
=== /src/subpath.ts ===
14+
async function bar(): Promise<string> {
15+
>bar : Symbol(bar, Decl(subpath.ts, 0, 0))
16+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
17+
18+
return "bar";
19+
}
20+
export const barrel = { bar };
21+
>barrel : Symbol(barrel, Decl(subpath.ts, 3, 12))
22+
>bar : Symbol(bar, Decl(subpath.ts, 3, 23))
23+
24+
=== /src/indirect.ts ===
25+
import { barrel } from "#subpath";
26+
>barrel : Symbol(barrel, Decl(indirect.ts, 0, 8))
27+
28+
const { bar } = barrel;
29+
>bar : Symbol(bar, Decl(indirect.ts, 1, 7))
30+
>barrel : Symbol(barrel, Decl(indirect.ts, 0, 8))
31+
32+
export { bar };
33+
>bar : Symbol(bar, Decl(indirect.ts, 2, 8))
34+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//// [tests/cases/compiler/subpathImportDeclarationEmit.ts] ////
2+
3+
=== /src/main.ts ===
4+
import { bar } from "./indirect.js";
5+
>bar : () => Promise<string>
6+
7+
console.log(await bar());
8+
>console.log(await bar()) : void
9+
>console.log : (...data: any[]) => void
10+
>console : Console
11+
>log : (...data: any[]) => void
12+
>await bar() : string
13+
>bar() : Promise<string>
14+
>bar : () => Promise<string>
15+
16+
=== /src/subpath.ts ===
17+
async function bar(): Promise<string> {
18+
>bar : () => Promise<string>
19+
20+
return "bar";
21+
>"bar" : "bar"
22+
}
23+
export const barrel = { bar };
24+
>barrel : { bar: () => Promise<string>; }
25+
>{ bar } : { bar: () => Promise<string>; }
26+
>bar : () => Promise<string>
27+
28+
=== /src/indirect.ts ===
29+
import { barrel } from "#subpath";
30+
>barrel : { bar: () => Promise<string>; }
31+
32+
const { bar } = barrel;
33+
>bar : () => Promise<string>
34+
>barrel : { bar: () => Promise<string>; }
35+
36+
export { bar };
37+
>bar : () => Promise<string>
38+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @Filename: /tsconfig.json
2+
{
3+
"compilerOptions": {
4+
"module": "nodenext",
5+
"outDir": "dist",
6+
"rootDir": "src",
7+
"declaration": true,
8+
},
9+
"files": ["src/main.ts"]
10+
}
11+
12+
// @Filename: /package.json
13+
{
14+
"name": "pkg",
15+
"type": "module",
16+
"imports": {
17+
"#subpath": "./src/subpath.ts"
18+
},
19+
"exports": {
20+
"./*": "./dist/*"
21+
}
22+
}
23+
24+
// @Filename: /src/subpath.ts
25+
async function bar(): Promise<string> {
26+
return "bar";
27+
}
28+
export const barrel = { bar };
29+
30+
// @Filename: /src/indirect.ts
31+
import { barrel } from "#subpath";
32+
const { bar } = barrel;
33+
export { bar };
34+
35+
// @Filename: /src/main.ts
36+
import { bar } from "./indirect.js";
37+
console.log(await bar());

0 commit comments

Comments
 (0)