mirror of
https://github.com/morluto/rea
synced 2026-10-27 14:42:18 -04:00
fix(javascript): centralize module syntax and separate erased type dependencies
This commit is contained in:
@@ -28,6 +28,12 @@ import {
|
||||
propertyName,
|
||||
semanticStaticPropertyKey,
|
||||
} from "./javascriptAstValues.js";
|
||||
import {
|
||||
isTypeOnlyExportDeclaration,
|
||||
isTypeOnlyExportSpecifier,
|
||||
isTypeOnlyImportDeclaration,
|
||||
isTypeOnlyImportSpecifier,
|
||||
} from "./javascriptModuleDeclaration.js";
|
||||
|
||||
interface CollectCallableInput {
|
||||
readonly node: t.Node;
|
||||
@@ -75,7 +81,7 @@ export const collectSemanticModuleLink = (
|
||||
addModuleLink(
|
||||
state,
|
||||
{
|
||||
kind: "re-export",
|
||||
kind: isTypeOnlyExportDeclaration(node) ? "type-import" : "re-export",
|
||||
specifier: node.source.value,
|
||||
importedName: "*",
|
||||
localName: null,
|
||||
@@ -108,12 +114,19 @@ const collectImportEquals = (
|
||||
node: t.TSImportEqualsDeclaration,
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): void => {
|
||||
const specifier = semanticImportEqualsSpecifier(node);
|
||||
const moduleReference = node.moduleReference;
|
||||
const specifier =
|
||||
semanticImportEqualsSpecifier(node) ??
|
||||
(node.importKind === "type" &&
|
||||
t.isTSExternalModuleReference(moduleReference) &&
|
||||
t.isStringLiteral(moduleReference.expression)
|
||||
? moduleReference.expression.value
|
||||
: null);
|
||||
if (specifier === null) return;
|
||||
addModuleLink(
|
||||
state,
|
||||
{
|
||||
kind: "require",
|
||||
kind: node.importKind === "type" ? "type-import" : "require",
|
||||
specifier,
|
||||
importedName: null,
|
||||
localName: node.id.name,
|
||||
@@ -287,7 +300,7 @@ const collectImports = (
|
||||
addModuleLink(
|
||||
state,
|
||||
{
|
||||
kind: "import",
|
||||
kind: isTypeOnlyImportDeclaration(node) ? "type-import" : "import",
|
||||
specifier: node.source.value,
|
||||
importedName: null,
|
||||
localName: null,
|
||||
@@ -300,7 +313,12 @@ const collectImports = (
|
||||
addModuleLink(
|
||||
state,
|
||||
{
|
||||
kind: "import",
|
||||
kind:
|
||||
isTypeOnlyImportDeclaration(node) ||
|
||||
(t.isImportSpecifier(specifier) &&
|
||||
isTypeOnlyImportSpecifier(specifier))
|
||||
? "type-import"
|
||||
: "import",
|
||||
specifier: node.source.value,
|
||||
importedName: t.isImportDefaultSpecifier(specifier)
|
||||
? "default"
|
||||
@@ -319,12 +337,13 @@ const collectNamedExports = (
|
||||
node: t.ExportNamedDeclaration,
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): void => {
|
||||
const declarationTypeOnly = isTypeOnlyExportDeclaration(node);
|
||||
if (node.declaration !== null && node.declaration !== undefined)
|
||||
for (const localName of declarationNames(node.declaration))
|
||||
addModuleLink(
|
||||
state,
|
||||
{
|
||||
kind: "export",
|
||||
kind: declarationTypeOnly ? "type-import" : "export",
|
||||
specifier: null,
|
||||
importedName: null,
|
||||
localName,
|
||||
@@ -342,7 +361,14 @@ const collectNamedExports = (
|
||||
addModuleLink(
|
||||
state,
|
||||
{
|
||||
kind: node.source == null ? "export" : "re-export",
|
||||
kind:
|
||||
declarationTypeOnly ||
|
||||
(t.isExportSpecifier(specifier) &&
|
||||
isTypeOnlyExportSpecifier(specifier))
|
||||
? "type-import"
|
||||
: node.source == null
|
||||
? "export"
|
||||
: "re-export",
|
||||
specifier: node.source?.value ?? null,
|
||||
importedName: t.isExportNamespaceSpecifier(specifier)
|
||||
? "*"
|
||||
@@ -745,6 +771,13 @@ const declarationNames = (declaration: t.Declaration): string[] => {
|
||||
t.isIdentifier(declaration.id)
|
||||
)
|
||||
return [declaration.id.name];
|
||||
if (
|
||||
(t.isTSInterfaceDeclaration(declaration) ||
|
||||
t.isTSTypeAliasDeclaration(declaration) ||
|
||||
t.isTSDeclareFunction(declaration)) &&
|
||||
t.isIdentifier(declaration.id)
|
||||
)
|
||||
return [declaration.id.name];
|
||||
if (
|
||||
t.isTSImportEqualsDeclaration(declaration) &&
|
||||
semanticImportEqualsSpecifier(declaration) !== null
|
||||
|
||||
Reference in New Issue
Block a user