Skip to content

Commit ccd8b1d

Browse files
authored
Allow exports map entries to point at .ts source files (#48563)
* Probably works * Add tests * Update baselines for module option rename
1 parent ba38fe1 commit ccd8b1d

9 files changed

+306
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations.
2+
tests/cases/conformance/node/index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary.
3+
4+
5+
==== tests/cases/conformance/node/index.ts (2 errors) ====
6+
// esm format file
7+
import { Thing } from "inner/other";
8+
~~~~~~~~~~~~~
9+
!!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations.
10+
export const a = (await import("inner")).x();
11+
~
12+
!!! error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary.
13+
import {a as a2} from "package";
14+
==== tests/cases/conformance/node/node_modules/inner/index.ts (0 errors) ====
15+
// esm format file
16+
export { x } from "./other.js";
17+
==== tests/cases/conformance/node/node_modules/inner/other.ts (0 errors) ====
18+
// esm format file
19+
export interface Thing {}
20+
export const x: () => Thing = null as any;
21+
==== tests/cases/conformance/node/package.json (0 errors) ====
22+
{
23+
"name": "package",
24+
"private": true,
25+
"type": "module",
26+
"exports": "./index.ts"
27+
}
28+
==== tests/cases/conformance/node/node_modules/inner/package.json (0 errors) ====
29+
{
30+
"name": "inner",
31+
"private": true,
32+
"type": "module",
33+
"exports": "./index.ts"
34+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//// [tests/cases/conformance/node/nodeModulesExportsSourceTs.ts] ////
2+
3+
//// [index.ts]
4+
// esm format file
5+
import { Thing } from "inner/other";
6+
export const a = (await import("inner")).x();
7+
import {a as a2} from "package";
8+
//// [index.ts]
9+
// esm format file
10+
export { x } from "./other.js";
11+
//// [other.ts]
12+
// esm format file
13+
export interface Thing {}
14+
export const x: () => Thing = null as any;
15+
//// [package.json]
16+
{
17+
"name": "package",
18+
"private": true,
19+
"type": "module",
20+
"exports": "./index.ts"
21+
}
22+
//// [package.json]
23+
{
24+
"name": "inner",
25+
"private": true,
26+
"type": "module",
27+
"exports": "./index.ts"
28+
}
29+
30+
//// [other.js]
31+
export const x = null;
32+
//// [index.js]
33+
// esm format file
34+
export { x } from "./other.js";
35+
//// [index.js]
36+
export const a = (await import("inner")).x();
37+
38+
39+
//// [other.d.ts]
40+
export interface Thing {
41+
}
42+
export declare const x: () => Thing;
43+
//// [index.d.ts]
44+
export { x } from "./other.js";
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/conformance/node/index.ts ===
2+
// esm format file
3+
import { Thing } from "inner/other";
4+
>Thing : Symbol(Thing, Decl(index.ts, 1, 8))
5+
6+
export const a = (await import("inner")).x();
7+
>a : Symbol(a, Decl(index.ts, 2, 12))
8+
>(await import("inner")).x : Symbol(x, Decl(index.ts, 1, 8))
9+
>"inner" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.ts, 0, 0))
10+
>x : Symbol(x, Decl(index.ts, 1, 8))
11+
12+
import {a as a2} from "package";
13+
>a : Symbol(a, Decl(index.ts, 2, 12))
14+
>a2 : Symbol(a2, Decl(index.ts, 3, 8))
15+
16+
=== tests/cases/conformance/node/node_modules/inner/index.ts ===
17+
// esm format file
18+
export { x } from "./other.js";
19+
>x : Symbol(x, Decl(index.ts, 1, 8))
20+
21+
=== tests/cases/conformance/node/node_modules/inner/other.ts ===
22+
// esm format file
23+
export interface Thing {}
24+
>Thing : Symbol(Thing, Decl(other.ts, 0, 0))
25+
26+
export const x: () => Thing = null as any;
27+
>x : Symbol(x, Decl(other.ts, 2, 12))
28+
>Thing : Symbol(Thing, Decl(other.ts, 0, 0))
29+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=== tests/cases/conformance/node/index.ts ===
2+
// esm format file
3+
import { Thing } from "inner/other";
4+
>Thing : any
5+
6+
export const a = (await import("inner")).x();
7+
>a : import("tests/cases/conformance/node/node_modules/inner/other").Thing
8+
>(await import("inner")).x() : import("tests/cases/conformance/node/node_modules/inner/other").Thing
9+
>(await import("inner")).x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing
10+
>(await import("inner")) : typeof import("tests/cases/conformance/node/node_modules/inner/index")
11+
>await import("inner") : typeof import("tests/cases/conformance/node/node_modules/inner/index")
12+
>import("inner") : Promise<typeof import("tests/cases/conformance/node/node_modules/inner/index")>
13+
>"inner" : "inner"
14+
>x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing
15+
16+
import {a as a2} from "package";
17+
>a : import("tests/cases/conformance/node/node_modules/inner/other").Thing
18+
>a2 : import("tests/cases/conformance/node/node_modules/inner/other").Thing
19+
20+
=== tests/cases/conformance/node/node_modules/inner/index.ts ===
21+
// esm format file
22+
export { x } from "./other.js";
23+
>x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing
24+
25+
=== tests/cases/conformance/node/node_modules/inner/other.ts ===
26+
// esm format file
27+
export interface Thing {}
28+
export const x: () => Thing = null as any;
29+
>x : () => Thing
30+
>null as any : any
31+
>null : null
32+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations.
2+
tests/cases/conformance/node/index.ts(3,14): error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary.
3+
4+
5+
==== tests/cases/conformance/node/index.ts (2 errors) ====
6+
// esm format file
7+
import { Thing } from "inner/other";
8+
~~~~~~~~~~~~~
9+
!!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations.
10+
export const a = (await import("inner")).x();
11+
~
12+
!!! error TS2742: The inferred type of 'a' cannot be named without a reference to './node_modules/inner/other.js'. This is likely not portable. A type annotation is necessary.
13+
import {a as a2} from "package";
14+
==== tests/cases/conformance/node/node_modules/inner/index.ts (0 errors) ====
15+
// esm format file
16+
export { x } from "./other.js";
17+
==== tests/cases/conformance/node/node_modules/inner/other.ts (0 errors) ====
18+
// esm format file
19+
export interface Thing {}
20+
export const x: () => Thing = null as any;
21+
==== tests/cases/conformance/node/package.json (0 errors) ====
22+
{
23+
"name": "package",
24+
"private": true,
25+
"type": "module",
26+
"exports": "./index.ts"
27+
}
28+
==== tests/cases/conformance/node/node_modules/inner/package.json (0 errors) ====
29+
{
30+
"name": "inner",
31+
"private": true,
32+
"type": "module",
33+
"exports": "./index.ts"
34+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//// [tests/cases/conformance/node/nodeModulesExportsSourceTs.ts] ////
2+
3+
//// [index.ts]
4+
// esm format file
5+
import { Thing } from "inner/other";
6+
export const a = (await import("inner")).x();
7+
import {a as a2} from "package";
8+
//// [index.ts]
9+
// esm format file
10+
export { x } from "./other.js";
11+
//// [other.ts]
12+
// esm format file
13+
export interface Thing {}
14+
export const x: () => Thing = null as any;
15+
//// [package.json]
16+
{
17+
"name": "package",
18+
"private": true,
19+
"type": "module",
20+
"exports": "./index.ts"
21+
}
22+
//// [package.json]
23+
{
24+
"name": "inner",
25+
"private": true,
26+
"type": "module",
27+
"exports": "./index.ts"
28+
}
29+
30+
//// [other.js]
31+
export const x = null;
32+
//// [index.js]
33+
// esm format file
34+
export { x } from "./other.js";
35+
//// [index.js]
36+
export const a = (await import("inner")).x();
37+
38+
39+
//// [other.d.ts]
40+
export interface Thing {
41+
}
42+
export declare const x: () => Thing;
43+
//// [index.d.ts]
44+
export { x } from "./other.js";
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/conformance/node/index.ts ===
2+
// esm format file
3+
import { Thing } from "inner/other";
4+
>Thing : Symbol(Thing, Decl(index.ts, 1, 8))
5+
6+
export const a = (await import("inner")).x();
7+
>a : Symbol(a, Decl(index.ts, 2, 12))
8+
>(await import("inner")).x : Symbol(x, Decl(index.ts, 1, 8))
9+
>"inner" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.ts, 0, 0))
10+
>x : Symbol(x, Decl(index.ts, 1, 8))
11+
12+
import {a as a2} from "package";
13+
>a : Symbol(a, Decl(index.ts, 2, 12))
14+
>a2 : Symbol(a2, Decl(index.ts, 3, 8))
15+
16+
=== tests/cases/conformance/node/node_modules/inner/index.ts ===
17+
// esm format file
18+
export { x } from "./other.js";
19+
>x : Symbol(x, Decl(index.ts, 1, 8))
20+
21+
=== tests/cases/conformance/node/node_modules/inner/other.ts ===
22+
// esm format file
23+
export interface Thing {}
24+
>Thing : Symbol(Thing, Decl(other.ts, 0, 0))
25+
26+
export const x: () => Thing = null as any;
27+
>x : Symbol(x, Decl(other.ts, 2, 12))
28+
>Thing : Symbol(Thing, Decl(other.ts, 0, 0))
29+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=== tests/cases/conformance/node/index.ts ===
2+
// esm format file
3+
import { Thing } from "inner/other";
4+
>Thing : any
5+
6+
export const a = (await import("inner")).x();
7+
>a : import("tests/cases/conformance/node/node_modules/inner/other").Thing
8+
>(await import("inner")).x() : import("tests/cases/conformance/node/node_modules/inner/other").Thing
9+
>(await import("inner")).x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing
10+
>(await import("inner")) : typeof import("tests/cases/conformance/node/node_modules/inner/index")
11+
>await import("inner") : typeof import("tests/cases/conformance/node/node_modules/inner/index")
12+
>import("inner") : Promise<typeof import("tests/cases/conformance/node/node_modules/inner/index")>
13+
>"inner" : "inner"
14+
>x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing
15+
16+
import {a as a2} from "package";
17+
>a : import("tests/cases/conformance/node/node_modules/inner/other").Thing
18+
>a2 : import("tests/cases/conformance/node/node_modules/inner/other").Thing
19+
20+
=== tests/cases/conformance/node/node_modules/inner/index.ts ===
21+
// esm format file
22+
export { x } from "./other.js";
23+
>x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing
24+
25+
=== tests/cases/conformance/node/node_modules/inner/other.ts ===
26+
// esm format file
27+
export interface Thing {}
28+
export const x: () => Thing = null as any;
29+
>x : () => Thing
30+
>null as any : any
31+
>null : null
32+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// @module: node16,nodenext
2+
// @declaration: true
3+
// @filename: index.ts
4+
// esm format file
5+
import { Thing } from "inner/other";
6+
export const a = (await import("inner")).x();
7+
import {a as a2} from "package";
8+
// @filename: node_modules/inner/index.ts
9+
// esm format file
10+
export { x } from "./other.js";
11+
// @filename: node_modules/inner/other.ts
12+
// esm format file
13+
export interface Thing {}
14+
export const x: () => Thing = null as any;
15+
// @filename: package.json
16+
{
17+
"name": "package",
18+
"private": true,
19+
"type": "module",
20+
"exports": "./index.ts"
21+
}
22+
// @filename: node_modules/inner/package.json
23+
{
24+
"name": "inner",
25+
"private": true,
26+
"type": "module",
27+
"exports": "./index.ts"
28+
}

0 commit comments

Comments
 (0)