fix(javascript): unify runtime module declarations

This commit is contained in:
morluto
2026-10-27 09:23:15 +08:00
parent 01484bc95c
commit e2da92f5d2
6 changed files with 65 additions and 69 deletions
@@ -30,6 +30,17 @@ export const isTypeOnlyExportDeclaration = (
node.declaration != null &&
isErasedJavaScriptDeclaration(node.declaration));
/** Runtime static module source, shared by source and captured-script consumers. */
export const semanticStaticModuleSource = (
node: t.Node,
): t.StringLiteral | null => {
if (t.isImportDeclaration(node))
return isTypeOnlyImportDeclaration(node) ? null : node.source;
if (t.isExportAllDeclaration(node) || t.isExportNamedDeclaration(node))
return isTypeOnlyExportDeclaration(node) ? null : (node.source ?? null);
return null;
};
/**
* Runtime external-module target for a value import-equals declaration;
* `import type X = require("m")` is erased and declares no dependency.