Skip to content

Commit

Permalink
Allow export map entries to remap back to input files for a program
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Feb 17, 2022
1 parent 67172e4 commit f6dc158
Show file tree
Hide file tree
Showing 26 changed files with 711 additions and 8 deletions.
147 changes: 139 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

0 comments on commit f6dc158

Please sign in to comment.