mirror of
https://github.com/morluto/rea.git
synced 2026-11-11 01:13:39 +00:00
fix(javascript): unify runtime module declarations
This commit is contained in:
1 parent
01484bc95c
commit
e2da92f5d2
6 files changed
+65
-69
No files matched your search
@@ -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.
|
||||
|
||||
@@ -72,8 +72,7 @@ import {
|
||||
import { createJavaScriptRpcScan } from "./javascriptRpcEndpoints.js";
|
||||
import {
|
||||
hasUncertainTypeOnlyModuleSideEffect,
|
||||
isTypeOnlyExportDeclaration,
|
||||
isTypeOnlyImportDeclaration,
|
||||
semanticStaticModuleSource,
|
||||
semanticImportEqualsSpecifier,
|
||||
} from "./javascriptModuleDeclaration.js";
|
||||
import {
|
||||
@@ -367,28 +366,16 @@ const inspectNode = (
|
||||
const specifier = semanticImportEqualsSpecifier(node);
|
||||
if (specifier !== null)
|
||||
addReference(findings, { node, kind: "require", specifier });
|
||||
} else if (
|
||||
(t.isImportDeclaration(node) || t.isExportAllDeclaration(node)) &&
|
||||
node.source !== undefined &&
|
||||
!(t.isImportDeclaration(node) && isTypeOnlyImportDeclaration(node)) &&
|
||||
!(t.isExportAllDeclaration(node) && isTypeOnlyExportDeclaration(node))
|
||||
)
|
||||
addReference(findings, {
|
||||
node,
|
||||
kind: "static-import",
|
||||
specifier: node.source.value,
|
||||
});
|
||||
else if (
|
||||
t.isExportNamedDeclaration(node) &&
|
||||
node.source != null &&
|
||||
!isTypeOnlyExportDeclaration(node)
|
||||
)
|
||||
addReference(findings, {
|
||||
node,
|
||||
kind: "static-import",
|
||||
specifier: node.source.value,
|
||||
});
|
||||
else if (t.isImportExpression(node))
|
||||
} else {
|
||||
const moduleSource = semanticStaticModuleSource(node);
|
||||
if (moduleSource !== null)
|
||||
addReference(findings, {
|
||||
node,
|
||||
kind: "static-import",
|
||||
specifier: moduleSource.value,
|
||||
});
|
||||
}
|
||||
if (t.isImportExpression(node))
|
||||
addReference(findings, {
|
||||
node,
|
||||
kind: "dynamic-import",
|
||||
|
||||
Reference in new issue
Block a user