Skip to content

Commit

Permalink
fix: ImportType node children do not transform (fixes #150)
Browse files Browse the repository at this point in the history
  • Loading branch information
nonara committed Oct 20, 2022
1 parent 56ce003 commit 70871d2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/visitor.ts
Expand Up @@ -60,6 +60,7 @@ export function nodeVisitor(this: VisitorContext, node: ts.Node): ts.Node | unde
);
tsInstance.addSyntheticLeadingComment(p, kind, caption, hasTrailingNewLine);
}

return res;
});

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

return resolvePathAndUpdateNode(this, node, text, (p) =>
const res = resolvePathAndUpdateNode(this, node, text, (p) =>
factory.updateImportTypeNode(
node,
factory.updateLiteralTypeNode(argument, p),
Expand All @@ -95,6 +97,8 @@ export function nodeVisitor(this: VisitorContext, node: ts.Node): ts.Node | unde
node.isTypeOf
)
);

return tsInstance.visitEachChild(res, this.getVisitor(), transformationContext);
}

/**
Expand Down
1 change: 1 addition & 0 deletions test/projects/specific/src/packages/pkg-a/index.d.ts
@@ -1,2 +1,3 @@
export type PackageAType = null;
export declare const packageAConst: PackageAType;
export type PassThru<T> = T | string
2 changes: 2 additions & 0 deletions test/projects/specific/src/sub-packages.ts
Expand Up @@ -11,3 +11,5 @@ export { packageCConst as C3 } from "#packages/pkg-c/main.js";
export { subPackageConst as C4 } from "#packages/pkg-a/sub-pkg/main";
// This path should resolve to './packages/pkg-a/sub-pkg/main.js', due to explicit extension
export { subPackageConst as C5 } from "#packages/pkg-a/sub-pkg/main.js";

export type ImportWithChildren = import("#packages/pkg-a").PassThru<import("#packages/pkg-b").PackageBType>
7 changes: 7 additions & 0 deletions test/tests/transformer/specific.test.ts
Expand Up @@ -237,6 +237,13 @@ describe(`Specific Tests`, () => {
);
});

(!skipDts && tsVersion >= 38 ? test : test.skip)(`Resolves nested imports`, () => {
expect(subPackagesFile).transformedMatches(
`export declare type ImportWithChildren = import("./packages/pkg-a").PassThru<import("./packages/pkg-b").PackageBType>`,
{ kind: ["dts"] }
);
});

(!skipDts ? test : test.skip)(`Resolves module augmentation`, () => {
expect(moduleAugmentFile).transformedMatches(`declare module "./general" {`, { kind: ["dts"] });
expect(moduleAugmentFile).transformedMatches(`declare module "./excluded-file" {`, { kind: ["dts"] });
Expand Down

0 comments on commit 70871d2

Please sign in to comment.