Skip to content

Allow export map entries to remap back to input files for a program #47925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 140 additions & 8 deletions src/compiler/moduleNameResolver.ts

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4355,6 +4355,16 @@ namespace ts {
Extension.Dts;
}

/**
* This function is an inverse of `getDeclarationEmitExtensionForPath`.
*/
export function getPossibleOriginalInputExtensionForExtension(path: string) {
return fileExtensionIsOneOf(path, [Extension.Dmts, Extension.Mjs, Extension.Mts]) ? [Extension.Mts, Extension.Mjs] :
fileExtensionIsOneOf(path, [Extension.Dcts, Extension.Cjs, Extension.Cts]) ? [Extension.Cts, Extension.Cjs]:
fileExtensionIsOneOf(path, [`.json.d.ts`]) ? [Extension.Json] :
[Extension.Tsx, Extension.Ts, Extension.Jsx, Extension.Js];
}

export function outFile(options: CompilerOptions) {
return options.outFile || options.out;
}
Expand Down
22 changes: 22 additions & 0 deletions tests/baselines/reference/nodeNextPackageSelfNameWithOutDir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//// [tests/cases/compiler/nodeNextPackageSelfNameWithOutDir.ts] ////

//// [package.json]
{
"name": "@this/package",
"type": "module",
"exports": {
".": "./dist/index.js"
}
}
//// [index.ts]
import * as me from "@this/package";

me.thing();

export function thing(): void {}


//// [index.js]
import * as me from "@this/package";
me.thing();
export function thing() { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/compiler/index.ts ===
import * as me from "@this/package";
>me : Symbol(me, Decl(index.ts, 0, 6))

me.thing();
>me.thing : Symbol(thing, Decl(index.ts, 2, 11))
>me : Symbol(me, Decl(index.ts, 0, 6))
>thing : Symbol(thing, Decl(index.ts, 2, 11))

export function thing(): void {}
>thing : Symbol(thing, Decl(index.ts, 2, 11))

13 changes: 13 additions & 0 deletions tests/baselines/reference/nodeNextPackageSelfNameWithOutDir.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/compiler/index.ts ===
import * as me from "@this/package";
>me : typeof me

me.thing();
>me.thing() : void
>me.thing : () => void
>me : typeof me
>thing : () => void

export function thing(): void {}
>thing : () => void

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [tests/cases/compiler/nodeNextPackageSelfNameWithOutDirDeclDir.ts] ////

//// [package.json]
{
"name": "@this/package",
"type": "module",
"exports": {
".": {
"default": "./dist/index.js",
"types": "./types/index.d.ts"
}
}
}
//// [index.ts]
import * as me from "@this/package";

me.thing();

export function thing(): void {}


//// [index.js]
import * as me from "@this/package";
me.thing();
export function thing() { }


//// [index.d.ts]
export declare function thing(): void;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/compiler/index.ts ===
import * as me from "@this/package";
>me : Symbol(me, Decl(index.ts, 0, 6))

me.thing();
>me.thing : Symbol(thing, Decl(index.ts, 2, 11))
>me : Symbol(me, Decl(index.ts, 0, 6))
>thing : Symbol(thing, Decl(index.ts, 2, 11))

export function thing(): void {}
>thing : Symbol(thing, Decl(index.ts, 2, 11))

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/compiler/index.ts ===
import * as me from "@this/package";
>me : typeof me

me.thing();
>me.thing() : void
>me.thing : () => void
>me : typeof me
>thing : () => void

export function thing(): void {}
>thing : () => void

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [tests/cases/compiler/nodeNextPackageSelfNameWithOutDirDeclDirComposite.ts] ////

//// [package.json]
{
"name": "@this/package",
"type": "module",
"exports": {
".": {
"default": "./dist/index.js",
"types": "./types/index.d.ts"
}
}
}
//// [index.ts]
import * as me from "@this/package";

me.thing();

export function thing(): void {}


//// [index.js]
import * as me from "@this/package";
me.thing();
export function thing() { }


//// [index.d.ts]
export declare function thing(): void;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/compiler/index.ts ===
import * as me from "@this/package";
>me : Symbol(me, Decl(index.ts, 0, 6))

me.thing();
>me.thing : Symbol(thing, Decl(index.ts, 2, 11))
>me : Symbol(me, Decl(index.ts, 0, 6))
>thing : Symbol(thing, Decl(index.ts, 2, 11))

export function thing(): void {}
>thing : Symbol(thing, Decl(index.ts, 2, 11))

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/compiler/index.ts ===
import * as me from "@this/package";
>me : typeof me

me.thing();
>me.thing() : void
>me.thing : () => void
>me : typeof me
>thing : () => void

export function thing(): void {}
>thing : () => void

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//// [tests/cases/compiler/nodeNextPackageSelfNameWithOutDirDeclDirCompositeNestedDirs.ts] ////

//// [package.json]
{
"name": "@this/package",
"type": "module",
"exports": {
".": {
"default": "./dist/index.js",
"types": "./types/index.d.ts"
}
}
}
//// [index.ts]
export {srcthing as thing} from "./src/thing.js";
//// [thing.ts]
// The following import should cause `index.ts`
// to be included in the build, which will,
// in turn, cause the common src directory to not be `src`
// (the harness is wierd here in that noImplicitReferences makes only
// this file get loaded as an entrypoint and emitted, while on the
// real command-line we'll crawl the imports for that set - a limitation
// of the harness, I suppose)
import * as me from "@this/package";

me.thing();

export function srcthing(): void {}



//// [thing.js]
// The following import should cause `index.ts`
// to be included in the build, which will,
// in turn, cause the common src directory to not be `src`
// (the harness is wierd here in that noImplicitReferences makes only
// this file get loaded as an entrypoint and emitted, while on the
// real command-line we'll crawl the imports for that set - a limitation
// of the harness, I suppose)
import * as me from "@this/package";
me.thing();
export function srcthing() { }


//// [thing.d.ts]
export declare function srcthing(): void;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=== tests/cases/compiler/src/thing.ts ===
// The following import should cause `index.ts`
// to be included in the build, which will,
// in turn, cause the common src directory to not be `src`
// (the harness is wierd here in that noImplicitReferences makes only
// this file get loaded as an entrypoint and emitted, while on the
// real command-line we'll crawl the imports for that set - a limitation
// of the harness, I suppose)
import * as me from "@this/package";
>me : Symbol(me, Decl(thing.ts, 7, 6))

me.thing();
>me.thing : Symbol(me.thing, Decl(index.ts, 0, 8))
>me : Symbol(me, Decl(thing.ts, 7, 6))
>thing : Symbol(me.thing, Decl(index.ts, 0, 8))

export function srcthing(): void {}
>srcthing : Symbol(srcthing, Decl(thing.ts, 9, 11))


=== tests/cases/compiler/index.ts ===
export {srcthing as thing} from "./src/thing.js";
>srcthing : Symbol(srcthing, Decl(thing.ts, 9, 11))
>thing : Symbol(thing, Decl(index.ts, 0, 8))

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=== tests/cases/compiler/src/thing.ts ===
// The following import should cause `index.ts`
// to be included in the build, which will,
// in turn, cause the common src directory to not be `src`
// (the harness is wierd here in that noImplicitReferences makes only
// this file get loaded as an entrypoint and emitted, while on the
// real command-line we'll crawl the imports for that set - a limitation
// of the harness, I suppose)
import * as me from "@this/package";
>me : typeof me

me.thing();
>me.thing() : void
>me.thing : () => void
>me : typeof me
>thing : () => void

export function srcthing(): void {}
>srcthing : () => void


=== tests/cases/compiler/index.ts ===
export {srcthing as thing} from "./src/thing.js";
>srcthing : () => void
>thing : () => void

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//// [tests/cases/compiler/nodeNextPackageSelfNameWithOutDirDeclDirNestedDirs.ts] ////

//// [package.json]
{
"name": "@this/package",
"type": "module",
"exports": {
".": {
"default": "./dist/index.js",
"types": "./types/index.d.ts"
}
}
}
//// [index.ts]
export {srcthing as thing} from "./src/thing.js";
//// [thing.ts]
// The following import should cause `index.ts`
// to be included in the build, which will,
// in turn, cause the common src directory to not be `src`
// (the harness is wierd here in that noImplicitReferences makes only
// this file get loaded as an entrypoint and emitted, while on the
// real command-line we'll crawl the imports for that set - a limitation
// of the harness, I suppose)
import * as me from "@this/package";

me.thing();

export function srcthing(): void {}



//// [thing.js]
// The following import should cause `index.ts`
// to be included in the build, which will,
// in turn, cause the common src directory to not be `src`
// (the harness is wierd here in that noImplicitReferences makes only
// this file get loaded as an entrypoint and emitted, while on the
// real command-line we'll crawl the imports for that set - a limitation
// of the harness, I suppose)
import * as me from "@this/package";
me.thing();
export function srcthing() { }


//// [thing.d.ts]
export declare function srcthing(): void;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=== tests/cases/compiler/src/thing.ts ===
// The following import should cause `index.ts`
// to be included in the build, which will,
// in turn, cause the common src directory to not be `src`
// (the harness is wierd here in that noImplicitReferences makes only
// this file get loaded as an entrypoint and emitted, while on the
// real command-line we'll crawl the imports for that set - a limitation
// of the harness, I suppose)
import * as me from "@this/package";
>me : Symbol(me, Decl(thing.ts, 7, 6))

me.thing();
>me.thing : Symbol(me.thing, Decl(index.ts, 0, 8))
>me : Symbol(me, Decl(thing.ts, 7, 6))
>thing : Symbol(me.thing, Decl(index.ts, 0, 8))

export function srcthing(): void {}
>srcthing : Symbol(srcthing, Decl(thing.ts, 9, 11))


=== tests/cases/compiler/index.ts ===
export {srcthing as thing} from "./src/thing.js";
>srcthing : Symbol(srcthing, Decl(thing.ts, 9, 11))
>thing : Symbol(thing, Decl(index.ts, 0, 8))

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=== tests/cases/compiler/src/thing.ts ===
// The following import should cause `index.ts`
// to be included in the build, which will,
// in turn, cause the common src directory to not be `src`
// (the harness is wierd here in that noImplicitReferences makes only
// this file get loaded as an entrypoint and emitted, while on the
// real command-line we'll crawl the imports for that set - a limitation
// of the harness, I suppose)
import * as me from "@this/package";
>me : typeof me

me.thing();
>me.thing() : void
>me.thing : () => void
>me : typeof me
>thing : () => void

export function srcthing(): void {}
>srcthing : () => void


=== tests/cases/compiler/index.ts ===
export {srcthing as thing} from "./src/thing.js";
>srcthing : () => void
>thing : () => void

Loading