Allow exports map entries to point at .ts source files (#48563)

* Probably works

* Add tests

* Update baselines for module option rename
This commit is contained in:
Wesley Wigham 2022-06-15 11:23:26 -07:00 committed by GitHub
parent ba38fe1df2
commit ccd8b1d27e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 306 additions and 0 deletions

View File

@ -0,0 +1,34 @@
tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations.
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.
==== tests/cases/conformance/node/index.ts (2 errors) ====
// esm format file
import { Thing } from "inner/other";
~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations.
export const a = (await import("inner")).x();
~
!!! 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.
import {a as a2} from "package";
==== tests/cases/conformance/node/node_modules/inner/index.ts (0 errors) ====
// esm format file
export { x } from "./other.js";
==== tests/cases/conformance/node/node_modules/inner/other.ts (0 errors) ====
// esm format file
export interface Thing {}
export const x: () => Thing = null as any;
==== tests/cases/conformance/node/package.json (0 errors) ====
{
"name": "package",
"private": true,
"type": "module",
"exports": "./index.ts"
}
==== tests/cases/conformance/node/node_modules/inner/package.json (0 errors) ====
{
"name": "inner",
"private": true,
"type": "module",
"exports": "./index.ts"
}

View File

@ -0,0 +1,44 @@
//// [tests/cases/conformance/node/nodeModulesExportsSourceTs.ts] ////
//// [index.ts]
// esm format file
import { Thing } from "inner/other";
export const a = (await import("inner")).x();
import {a as a2} from "package";
//// [index.ts]
// esm format file
export { x } from "./other.js";
//// [other.ts]
// esm format file
export interface Thing {}
export const x: () => Thing = null as any;
//// [package.json]
{
"name": "package",
"private": true,
"type": "module",
"exports": "./index.ts"
}
//// [package.json]
{
"name": "inner",
"private": true,
"type": "module",
"exports": "./index.ts"
}
//// [other.js]
export const x = null;
//// [index.js]
// esm format file
export { x } from "./other.js";
//// [index.js]
export const a = (await import("inner")).x();
//// [other.d.ts]
export interface Thing {
}
export declare const x: () => Thing;
//// [index.d.ts]
export { x } from "./other.js";

View File

@ -0,0 +1,29 @@
=== tests/cases/conformance/node/index.ts ===
// esm format file
import { Thing } from "inner/other";
>Thing : Symbol(Thing, Decl(index.ts, 1, 8))
export const a = (await import("inner")).x();
>a : Symbol(a, Decl(index.ts, 2, 12))
>(await import("inner")).x : Symbol(x, Decl(index.ts, 1, 8))
>"inner" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.ts, 0, 0))
>x : Symbol(x, Decl(index.ts, 1, 8))
import {a as a2} from "package";
>a : Symbol(a, Decl(index.ts, 2, 12))
>a2 : Symbol(a2, Decl(index.ts, 3, 8))
=== tests/cases/conformance/node/node_modules/inner/index.ts ===
// esm format file
export { x } from "./other.js";
>x : Symbol(x, Decl(index.ts, 1, 8))
=== tests/cases/conformance/node/node_modules/inner/other.ts ===
// esm format file
export interface Thing {}
>Thing : Symbol(Thing, Decl(other.ts, 0, 0))
export const x: () => Thing = null as any;
>x : Symbol(x, Decl(other.ts, 2, 12))
>Thing : Symbol(Thing, Decl(other.ts, 0, 0))

View File

@ -0,0 +1,32 @@
=== tests/cases/conformance/node/index.ts ===
// esm format file
import { Thing } from "inner/other";
>Thing : any
export const a = (await import("inner")).x();
>a : import("tests/cases/conformance/node/node_modules/inner/other").Thing
>(await import("inner")).x() : import("tests/cases/conformance/node/node_modules/inner/other").Thing
>(await import("inner")).x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing
>(await import("inner")) : typeof import("tests/cases/conformance/node/node_modules/inner/index")
>await import("inner") : typeof import("tests/cases/conformance/node/node_modules/inner/index")
>import("inner") : Promise<typeof import("tests/cases/conformance/node/node_modules/inner/index")>
>"inner" : "inner"
>x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing
import {a as a2} from "package";
>a : import("tests/cases/conformance/node/node_modules/inner/other").Thing
>a2 : import("tests/cases/conformance/node/node_modules/inner/other").Thing
=== tests/cases/conformance/node/node_modules/inner/index.ts ===
// esm format file
export { x } from "./other.js";
>x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing
=== tests/cases/conformance/node/node_modules/inner/other.ts ===
// esm format file
export interface Thing {}
export const x: () => Thing = null as any;
>x : () => Thing
>null as any : any
>null : null

View File

@ -0,0 +1,34 @@
tests/cases/conformance/node/index.ts(2,23): error TS2307: Cannot find module 'inner/other' or its corresponding type declarations.
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.
==== tests/cases/conformance/node/index.ts (2 errors) ====
// esm format file
import { Thing } from "inner/other";
~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'inner/other' or its corresponding type declarations.
export const a = (await import("inner")).x();
~
!!! 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.
import {a as a2} from "package";
==== tests/cases/conformance/node/node_modules/inner/index.ts (0 errors) ====
// esm format file
export { x } from "./other.js";
==== tests/cases/conformance/node/node_modules/inner/other.ts (0 errors) ====
// esm format file
export interface Thing {}
export const x: () => Thing = null as any;
==== tests/cases/conformance/node/package.json (0 errors) ====
{
"name": "package",
"private": true,
"type": "module",
"exports": "./index.ts"
}
==== tests/cases/conformance/node/node_modules/inner/package.json (0 errors) ====
{
"name": "inner",
"private": true,
"type": "module",
"exports": "./index.ts"
}

View File

@ -0,0 +1,44 @@
//// [tests/cases/conformance/node/nodeModulesExportsSourceTs.ts] ////
//// [index.ts]
// esm format file
import { Thing } from "inner/other";
export const a = (await import("inner")).x();
import {a as a2} from "package";
//// [index.ts]
// esm format file
export { x } from "./other.js";
//// [other.ts]
// esm format file
export interface Thing {}
export const x: () => Thing = null as any;
//// [package.json]
{
"name": "package",
"private": true,
"type": "module",
"exports": "./index.ts"
}
//// [package.json]
{
"name": "inner",
"private": true,
"type": "module",
"exports": "./index.ts"
}
//// [other.js]
export const x = null;
//// [index.js]
// esm format file
export { x } from "./other.js";
//// [index.js]
export const a = (await import("inner")).x();
//// [other.d.ts]
export interface Thing {
}
export declare const x: () => Thing;
//// [index.d.ts]
export { x } from "./other.js";

View File

@ -0,0 +1,29 @@
=== tests/cases/conformance/node/index.ts ===
// esm format file
import { Thing } from "inner/other";
>Thing : Symbol(Thing, Decl(index.ts, 1, 8))
export const a = (await import("inner")).x();
>a : Symbol(a, Decl(index.ts, 2, 12))
>(await import("inner")).x : Symbol(x, Decl(index.ts, 1, 8))
>"inner" : Symbol("tests/cases/conformance/node/node_modules/inner/index", Decl(index.ts, 0, 0))
>x : Symbol(x, Decl(index.ts, 1, 8))
import {a as a2} from "package";
>a : Symbol(a, Decl(index.ts, 2, 12))
>a2 : Symbol(a2, Decl(index.ts, 3, 8))
=== tests/cases/conformance/node/node_modules/inner/index.ts ===
// esm format file
export { x } from "./other.js";
>x : Symbol(x, Decl(index.ts, 1, 8))
=== tests/cases/conformance/node/node_modules/inner/other.ts ===
// esm format file
export interface Thing {}
>Thing : Symbol(Thing, Decl(other.ts, 0, 0))
export const x: () => Thing = null as any;
>x : Symbol(x, Decl(other.ts, 2, 12))
>Thing : Symbol(Thing, Decl(other.ts, 0, 0))

View File

@ -0,0 +1,32 @@
=== tests/cases/conformance/node/index.ts ===
// esm format file
import { Thing } from "inner/other";
>Thing : any
export const a = (await import("inner")).x();
>a : import("tests/cases/conformance/node/node_modules/inner/other").Thing
>(await import("inner")).x() : import("tests/cases/conformance/node/node_modules/inner/other").Thing
>(await import("inner")).x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing
>(await import("inner")) : typeof import("tests/cases/conformance/node/node_modules/inner/index")
>await import("inner") : typeof import("tests/cases/conformance/node/node_modules/inner/index")
>import("inner") : Promise<typeof import("tests/cases/conformance/node/node_modules/inner/index")>
>"inner" : "inner"
>x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing
import {a as a2} from "package";
>a : import("tests/cases/conformance/node/node_modules/inner/other").Thing
>a2 : import("tests/cases/conformance/node/node_modules/inner/other").Thing
=== tests/cases/conformance/node/node_modules/inner/index.ts ===
// esm format file
export { x } from "./other.js";
>x : () => import("tests/cases/conformance/node/node_modules/inner/other").Thing
=== tests/cases/conformance/node/node_modules/inner/other.ts ===
// esm format file
export interface Thing {}
export const x: () => Thing = null as any;
>x : () => Thing
>null as any : any
>null : null

View File

@ -0,0 +1,28 @@
// @module: node16,nodenext
// @declaration: true
// @filename: index.ts
// esm format file
import { Thing } from "inner/other";
export const a = (await import("inner")).x();
import {a as a2} from "package";
// @filename: node_modules/inner/index.ts
// esm format file
export { x } from "./other.js";
// @filename: node_modules/inner/other.ts
// esm format file
export interface Thing {}
export const x: () => Thing = null as any;
// @filename: package.json
{
"name": "package",
"private": true,
"type": "module",
"exports": "./index.ts"
}
// @filename: node_modules/inner/package.json
{
"name": "inner",
"private": true,
"type": "module",
"exports": "./index.ts"
}