Skip to content

Commit 70871d2

Browse files
committed
fix: ImportType node children do not transform (fixes #150)
1 parent 56ce003 commit 70871d2

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

src/visitor.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export function nodeVisitor(this: VisitorContext, node: ts.Node): ts.Node | unde
6060
);
6161
tsInstance.addSyntheticLeadingComment(p, kind, caption, hasTrailingNewLine);
6262
}
63+
6364
return res;
6465
});
6566

@@ -77,6 +78,7 @@ export function nodeVisitor(this: VisitorContext, node: ts.Node): ts.Node | unde
7778
* Update ImportTypeNode
7879
*
7980
* typeof import("./bar");
81+
* import ("package").MyType;
8082
*/
8183
if (tsInstance.isImportTypeNode(node)) {
8284
const argument = node.argument as ts.LiteralTypeNode;
@@ -85,7 +87,7 @@ export function nodeVisitor(this: VisitorContext, node: ts.Node): ts.Node | unde
8587
const { text } = argument.literal;
8688
if (!text) return node;
8789

88-
return resolvePathAndUpdateNode(this, node, text, (p) =>
90+
const res = resolvePathAndUpdateNode(this, node, text, (p) =>
8991
factory.updateImportTypeNode(
9092
node,
9193
factory.updateLiteralTypeNode(argument, p),
@@ -95,6 +97,8 @@ export function nodeVisitor(this: VisitorContext, node: ts.Node): ts.Node | unde
9597
node.isTypeOf
9698
)
9799
);
100+
101+
return tsInstance.visitEachChild(res, this.getVisitor(), transformationContext);
98102
}
99103

100104
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export type PackageAType = null;
22
export declare const packageAConst: PackageAType;
3+
export type PassThru<T> = T | string

test/projects/specific/src/sub-packages.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ export { packageCConst as C3 } from "#packages/pkg-c/main.js";
1111
export { subPackageConst as C4 } from "#packages/pkg-a/sub-pkg/main";
1212
// This path should resolve to './packages/pkg-a/sub-pkg/main.js', due to explicit extension
1313
export { subPackageConst as C5 } from "#packages/pkg-a/sub-pkg/main.js";
14+
15+
export type ImportWithChildren = import("#packages/pkg-a").PassThru<import("#packages/pkg-b").PackageBType>

test/tests/transformer/specific.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ describe(`Specific Tests`, () => {
237237
);
238238
});
239239

240+
(!skipDts && tsVersion >= 38 ? test : test.skip)(`Resolves nested imports`, () => {
241+
expect(subPackagesFile).transformedMatches(
242+
`export declare type ImportWithChildren = import("./packages/pkg-a").PassThru<import("./packages/pkg-b").PackageBType>`,
243+
{ kind: ["dts"] }
244+
);
245+
});
246+
240247
(!skipDts ? test : test.skip)(`Resolves module augmentation`, () => {
241248
expect(moduleAugmentFile).transformedMatches(`declare module "./general" {`, { kind: ["dts"] });
242249
expect(moduleAugmentFile).transformedMatches(`declare module "./excluded-file" {`, { kind: ["dts"] });

0 commit comments

Comments
 (0)