fix(tooling): ignore inline type-only re-exports

This commit is contained in:
Vincent Koc
2026-05-30 09:35:00 +02:00
parent 731a7af9c5
commit 78f4a5c05f
2 changed files with 37 additions and 1 deletions
+10 -1
View File
@@ -41,7 +41,16 @@ function isTypeOnlyImportDeclaration(node) {
}
function isTypeOnlyExportDeclaration(node) {
return node.isTypeOnly === true;
if (node.isTypeOnly === true) {
return true;
}
const clause = node.exportClause;
return (
Boolean(clause) &&
ts.isNamedExports(clause) &&
clause.elements.length > 0 &&
clause.elements.every((element) => element.isTypeOnly)
);
}
function readDeclarationName(node) {
@@ -54,6 +54,33 @@ describe("check-dynamic-import-warts", () => {
expect(findDynamicImportAdvisories(source)).toStrictEqual([]);
});
it("ignores inline type-only static re-exports", () => {
const source = `
export { type Runtime, type RuntimeOptions } from "./runtime.js";
export async function start() {
return (await import("./runtime.js")).createRuntime();
}
`;
expect(findDynamicImportAdvisories(source)).toStrictEqual([]);
});
it("flags mixed runtime and inline type-only static re-exports", () => {
const source = `
let runtimePromise: Promise<typeof import("./runtime.js")> | undefined;
function loadRuntime() {
runtimePromise ??= import("./runtime.js");
return runtimePromise;
}
export { type Runtime, createRuntime } from "./runtime.js";
`;
expect(findDynamicImportAdvisories(source)).toEqual([
{
line: 4,
reason: 'runtime static + dynamic import of "./runtime.js" (static line 7)',
},
]);
});
it("ignores local export declarations without module specifiers", () => {
const source = `
const run = true;