Skip to content

Commit 84f7d14

Browse files
committed
moduleSpecifiers changes
1 parent 930820f commit 84f7d14

5 files changed

+107
-0
lines changed

src/compiler/moduleSpecifiers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,11 @@ function removeExtensionAndIndexPostFix(fileName: string, ending: Ending, option
10411041
const noExtension = removeFileExtension(fileName);
10421042
if (fileName === noExtension) return fileName;
10431043
if (fileExtensionIsOneOf(fileName, [Extension.Dmts, Extension.Mts, Extension.Dcts, Extension.Cts])) return noExtension + getJSExtensionForFile(fileName, options);
1044+
else if (!fileExtensionIsOneOf(fileName, [Extension.Dts]) && fileExtensionIsOneOf(fileName, [Extension.Ts]) && stringContains(fileName, ".d.")) {
1045+
// `foo.d.json.ts` and the like - remap back to `foo.json`
1046+
const ext = noExtension.substring(noExtension.lastIndexOf("."));
1047+
return noExtension.substring(0, noExtension.indexOf(".d.")) + ext;
1048+
}
10441049
switch (ending) {
10451050
case Ending.Minimal:
10461051
const withoutIndex = removeSuffix(noExtension, "/index");
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//// [tests/cases/compiler/declarationEmitTransitiveImportOfHtmlDeclarationItem.ts] ////
2+
3+
//// [foo.d.html.ts]
4+
export declare class CustomHtmlRepresentationThing {}
5+
6+
//// [reexporter.ts]
7+
import { CustomHtmlRepresentationThing } from "./foo.html";
8+
9+
export function func() {
10+
return new CustomHtmlRepresentationThing();
11+
}
12+
13+
//// [index.ts]
14+
import { func } from "./reexporter";
15+
export const c = func();
16+
17+
18+
//// [reexporter.js]
19+
"use strict";
20+
exports.__esModule = true;
21+
exports.func = void 0;
22+
var foo_html_1 = require("./foo.html");
23+
function func() {
24+
return new foo_html_1.CustomHtmlRepresentationThing();
25+
}
26+
exports.func = func;
27+
//// [index.js]
28+
"use strict";
29+
exports.__esModule = true;
30+
exports.c = void 0;
31+
var reexporter_1 = require("./reexporter");
32+
exports.c = (0, reexporter_1.func)();
33+
34+
35+
//// [reexporter.d.ts]
36+
import { CustomHtmlRepresentationThing } from "./foo.html";
37+
export declare function func(): CustomHtmlRepresentationThing;
38+
//// [index.d.ts]
39+
export declare const c: import("./foo.html").CustomHtmlRepresentationThing;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== tests/cases/compiler/foo.d.html.ts ===
2+
export declare class CustomHtmlRepresentationThing {}
3+
>CustomHtmlRepresentationThing : Symbol(CustomHtmlRepresentationThing, Decl(foo.d.html.ts, 0, 0))
4+
5+
=== tests/cases/compiler/reexporter.ts ===
6+
import { CustomHtmlRepresentationThing } from "./foo.html";
7+
>CustomHtmlRepresentationThing : Symbol(CustomHtmlRepresentationThing, Decl(reexporter.ts, 0, 8))
8+
9+
export function func() {
10+
>func : Symbol(func, Decl(reexporter.ts, 0, 59))
11+
12+
return new CustomHtmlRepresentationThing();
13+
>CustomHtmlRepresentationThing : Symbol(CustomHtmlRepresentationThing, Decl(reexporter.ts, 0, 8))
14+
}
15+
16+
=== tests/cases/compiler/index.ts ===
17+
import { func } from "./reexporter";
18+
>func : Symbol(func, Decl(index.ts, 0, 8))
19+
20+
export const c = func();
21+
>c : Symbol(c, Decl(index.ts, 1, 12))
22+
>func : Symbol(func, Decl(index.ts, 0, 8))
23+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/compiler/foo.d.html.ts ===
2+
export declare class CustomHtmlRepresentationThing {}
3+
>CustomHtmlRepresentationThing : CustomHtmlRepresentationThing
4+
5+
=== tests/cases/compiler/reexporter.ts ===
6+
import { CustomHtmlRepresentationThing } from "./foo.html";
7+
>CustomHtmlRepresentationThing : typeof CustomHtmlRepresentationThing
8+
9+
export function func() {
10+
>func : () => CustomHtmlRepresentationThing
11+
12+
return new CustomHtmlRepresentationThing();
13+
>new CustomHtmlRepresentationThing() : CustomHtmlRepresentationThing
14+
>CustomHtmlRepresentationThing : typeof CustomHtmlRepresentationThing
15+
}
16+
17+
=== tests/cases/compiler/index.ts ===
18+
import { func } from "./reexporter";
19+
>func : () => import("tests/cases/compiler/foo.d.html").CustomHtmlRepresentationThing
20+
21+
export const c = func();
22+
>c : import("tests/cases/compiler/foo.d.html").CustomHtmlRepresentationThing
23+
>func() : import("tests/cases/compiler/foo.d.html").CustomHtmlRepresentationThing
24+
>func : () => import("tests/cases/compiler/foo.d.html").CustomHtmlRepresentationThing
25+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @declaration: true
2+
// @allowNonJsExtensions: true
3+
// @filename: foo.d.html.ts
4+
export declare class CustomHtmlRepresentationThing {}
5+
6+
// @filename: reexporter.ts
7+
import { CustomHtmlRepresentationThing } from "./foo.html";
8+
9+
export function func() {
10+
return new CustomHtmlRepresentationThing();
11+
}
12+
13+
// @filename: index.ts
14+
import { func } from "./reexporter";
15+
export const c = func();

0 commit comments

Comments
 (0)