Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@tanstack/router-utils

Package Overview
Dependencies
Maintainers
5
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tanstack/router-utils - npm Package Compare versions

Comparing version
1.162.0
to
1.162.1
+410
dist/cjs/compiler-helpers.cjs
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
let _babel_types = require("@babel/types");
_babel_types = require_runtime.__toESM(_babel_types);
//#region src/compiler-helpers.ts
function getModuleExportName(node) {
return _babel_types.isIdentifier(node) ? node.name : node.value;
}
function addVariableDeclarationModuleInfo(declaration, bindings, exportMap) {
for (const declarator of declaration.declarations) for (const name of collectIdentifiersFromPattern(declarator.id)) {
bindings.set(name, {
type: "var",
init: declarator.init ?? null
});
exportMap?.set(name, name);
}
}
function addDeclarationModuleInfo(declaration, bindings, exportMap) {
if (_babel_types.isVariableDeclaration(declaration)) {
addVariableDeclarationModuleInfo(declaration, bindings, exportMap);
return;
}
if ((_babel_types.isFunctionDeclaration(declaration) || _babel_types.isClassDeclaration(declaration)) && declaration.id) {
bindings.set(declaration.id.name, {
type: "var",
init: null
});
exportMap?.set(declaration.id.name, declaration.id.name);
}
}
function hasIdentifierBinding(scopes, name) {
for (let i = scopes.length - 1; i >= 0; i--) if (scopes[i].bindings.has(name)) return true;
return false;
}
function currentIdentifierScope(scopes) {
return scopes[scopes.length - 1];
}
function nearestFunctionIdentifierScope(scopes) {
for (let i = scopes.length - 1; i >= 0; i--) {
const scope = scopes[i];
if (scope.kind === "function" || scope.kind === "program") return scope;
}
return currentIdentifierScope(scopes);
}
function addIdentifierPatternBindings(pattern, scope) {
for (const name of collectIdentifiersFromPattern(pattern)) scope.bindings.add(name);
}
function addIdentifierDeclarationBindings(declaration, scopes) {
if (_babel_types.isVariableDeclaration(declaration)) {
const scope = declaration.kind === "var" ? nearestFunctionIdentifierScope(scopes) : currentIdentifierScope(scopes);
for (const declarator of declaration.declarations) addIdentifierPatternBindings(declarator.id, scope);
return;
}
if ((_babel_types.isFunctionDeclaration(declaration) || _babel_types.isClassDeclaration(declaration) || _babel_types.isTSTypeAliasDeclaration(declaration) || _babel_types.isTSInterfaceDeclaration(declaration) || _babel_types.isTSEnumDeclaration(declaration)) && declaration.id) currentIdentifierScope(scopes).bindings.add(declaration.id.name);
}
function addIdentifierImportBindings(node, scope) {
for (const specifier of node.specifiers) scope.bindings.add(specifier.local.name);
}
function createNestedIdentifierScope(kind, scopes) {
return [...scopes, {
kind,
bindings: /* @__PURE__ */ new Set()
}];
}
function addIdentifierBlockBindings(body, scopes) {
for (const statement of body) if (_babel_types.isImportDeclaration(statement)) addIdentifierImportBindings(statement, currentIdentifierScope(scopes));
else if (_babel_types.isExportNamedDeclaration(statement) && statement.declaration) addIdentifierDeclarationBindings(statement.declaration, scopes);
else addIdentifierDeclarationBindings(statement, scopes);
}
function walkIdentifierChildren(current, parent, scopes, ids) {
for (const key of _babel_types.VISITOR_KEYS[current.type] ?? []) {
const child = current[key];
if (Array.isArray(child)) {
for (const item of child) if (item && typeof item.type === "string") walkIdentifierNode(item, current, parent, key, scopes, ids);
} else if (child && typeof child.type === "string") walkIdentifierNode(child, current, parent, key, scopes, ids);
}
}
function walkIdentifierNode(current, parent, grandparent, parentKey, scopes, ids) {
if (!current) return;
if (_babel_types.isIdentifier(current)) {
if ((!parent || _babel_types.isReferenced(current, parent, grandparent)) && !hasIdentifierBinding(scopes, current.name)) ids.add(current.name);
return;
}
if (_babel_types.isJSXIdentifier(current)) {
if (parent && _babel_types.isJSXAttribute(parent) && parentKey === "name") return;
if (parent && _babel_types.isJSXMemberExpression(parent) && parentKey === "property") return;
const first = current.name[0];
if (first && first === first.toLowerCase()) return;
if (!hasIdentifierBinding(scopes, current.name)) ids.add(current.name);
return;
}
if (_babel_types.isProgram(current)) {
const nestedScopes = createNestedIdentifierScope("program", scopes);
addIdentifierBlockBindings(current.body, nestedScopes);
for (const child of current.body) walkIdentifierNode(child, current, parent, "body", nestedScopes, ids);
return;
}
if (_babel_types.isBlockStatement(current)) {
const nestedScopes = createNestedIdentifierScope("block", scopes);
addIdentifierBlockBindings(current.body, nestedScopes);
for (const child of current.body) walkIdentifierNode(child, current, parent, "body", nestedScopes, ids);
return;
}
if (_babel_types.isFunctionDeclaration(current) || _babel_types.isFunctionExpression(current) || _babel_types.isArrowFunctionExpression(current) || _babel_types.isObjectMethod(current) || _babel_types.isClassMethod(current) || _babel_types.isClassPrivateMethod(current)) {
if (_babel_types.isFunctionDeclaration(current) && current.id) currentIdentifierScope(scopes).bindings.add(current.id.name);
const nestedScopes = createNestedIdentifierScope("function", scopes);
if ((_babel_types.isFunctionDeclaration(current) || _babel_types.isFunctionExpression(current)) && current.id) currentIdentifierScope(nestedScopes).bindings.add(current.id.name);
for (const param of current.params) addIdentifierPatternBindings(param, currentIdentifierScope(nestedScopes));
walkIdentifierChildren(current, parent, nestedScopes, ids);
return;
}
if (_babel_types.isCatchClause(current)) {
const nestedScopes = createNestedIdentifierScope("block", scopes);
addIdentifierPatternBindings(current.param, currentIdentifierScope(nestedScopes));
walkIdentifierNode(current.param, current, parent, "param", nestedScopes, ids);
walkIdentifierNode(current.body, current, parent, "body", nestedScopes, ids);
return;
}
if (_babel_types.isImportDeclaration(current)) {
addIdentifierImportBindings(current, currentIdentifierScope(scopes));
return;
}
if (_babel_types.isClassDeclaration(current) || _babel_types.isClassExpression(current)) {
if (_babel_types.isClassDeclaration(current) && current.id) currentIdentifierScope(scopes).bindings.add(current.id.name);
const nestedScopes = current.id ? createNestedIdentifierScope("block", scopes) : scopes;
if (current.id) currentIdentifierScope(nestedScopes).bindings.add(current.id.name);
walkIdentifierChildren(current, parent, nestedScopes, ids);
return;
}
if (_babel_types.isVariableDeclaration(current)) addIdentifierDeclarationBindings(current, scopes);
else if (_babel_types.isVariableDeclarator(current)) {
const scope = parent && _babel_types.isVariableDeclaration(parent) && parent.kind === "var" ? nearestFunctionIdentifierScope(scopes) : currentIdentifierScope(scopes);
addIdentifierPatternBindings(current.id, scope);
} else if (_babel_types.isTSTypeAliasDeclaration(current) || _babel_types.isTSInterfaceDeclaration(current) || _babel_types.isTSEnumDeclaration(current)) currentIdentifierScope(scopes).bindings.add(current.id.name);
walkIdentifierChildren(current, parent, scopes, ids);
}
/**
* Recursively walk an AST node and collect referenced identifier-like names.
* This avoids Babel path/scope allocation for module-level dependency scans.
*/
function collectIdentifiersFromNode(node) {
const ids = /* @__PURE__ */ new Set();
walkIdentifierNode(node, void 0, void 0, void 0, [{
kind: "program",
bindings: /* @__PURE__ */ new Set()
}], ids);
return ids;
}
function collectIdentifiersFromPattern(node) {
if (!node) return [];
if (_babel_types.isIdentifier(node)) return [node.name];
if (_babel_types.isAssignmentPattern(node)) return collectIdentifiersFromPattern(node.left);
if (_babel_types.isRestElement(node)) return collectIdentifiersFromPattern(node.argument);
if (_babel_types.isObjectPattern(node)) return node.properties.flatMap((prop) => {
if (_babel_types.isObjectProperty(prop)) return collectIdentifiersFromPattern(prop.value);
if (_babel_types.isRestElement(prop)) return collectIdentifiersFromPattern(prop.argument);
return [];
});
if (_babel_types.isArrayPattern(node)) return node.elements.flatMap((element) => collectIdentifiersFromPattern(element));
return [];
}
function collectLocalBindingsFromStatement(node, bindings) {
const declaration = _babel_types.isExportNamedDeclaration(node) && node.declaration ? node.declaration : _babel_types.isExportDefaultDeclaration(node) ? node.declaration : node;
if (_babel_types.isVariableDeclaration(declaration)) for (const declarator of declaration.declarations) for (const name of collectIdentifiersFromPattern(declarator.id)) bindings.add(name);
else if (_babel_types.isFunctionDeclaration(declaration) && declaration.id) bindings.add(declaration.id.name);
else if (_babel_types.isClassDeclaration(declaration) && declaration.id) bindings.add(declaration.id.name);
}
function extractModuleInfoFromAst(ast) {
const bindings = /* @__PURE__ */ new Map();
const exportMap = /* @__PURE__ */ new Map();
const reExportAllSources = [];
for (const node of ast.program.body) {
if (_babel_types.isImportDeclaration(node)) {
const source = node.source.value;
for (const specifier of node.specifiers) if (_babel_types.isImportSpecifier(specifier)) bindings.set(specifier.local.name, {
type: "import",
source,
importedName: getModuleExportName(specifier.imported)
});
else if (_babel_types.isImportDefaultSpecifier(specifier)) bindings.set(specifier.local.name, {
type: "import",
source,
importedName: "default"
});
else if (_babel_types.isImportNamespaceSpecifier(specifier)) bindings.set(specifier.local.name, {
type: "import",
source,
importedName: "*"
});
continue;
}
if (_babel_types.isVariableDeclaration(node)) {
addVariableDeclarationModuleInfo(node, bindings);
continue;
}
if (_babel_types.isFunctionDeclaration(node) || _babel_types.isClassDeclaration(node)) {
addDeclarationModuleInfo(node, bindings);
continue;
}
if (_babel_types.isExportNamedDeclaration(node)) {
if (node.declaration) addDeclarationModuleInfo(node.declaration, bindings, exportMap);
for (const specifier of node.specifiers) if (_babel_types.isExportNamespaceSpecifier(specifier)) {
const exported = getModuleExportName(specifier.exported);
exportMap.set(exported, exported);
if (node.source) bindings.set(exported, {
type: "import",
source: node.source.value,
importedName: "*"
});
} else if (_babel_types.isExportSpecifier(specifier)) {
const local = getModuleExportName(specifier.local);
const exported = getModuleExportName(specifier.exported);
exportMap.set(exported, local);
if (node.source) bindings.set(local, {
type: "import",
source: node.source.value,
importedName: local
});
}
continue;
}
if (_babel_types.isExportDefaultDeclaration(node)) {
const declaration = node.declaration;
if (_babel_types.isIdentifier(declaration)) exportMap.set("default", declaration.name);
else if ((_babel_types.isFunctionDeclaration(declaration) || _babel_types.isClassDeclaration(declaration)) && declaration.id) {
bindings.set(declaration.id.name, {
type: "var",
init: null
});
exportMap.set("default", declaration.id.name);
} else {
const synth = "__default_export__";
bindings.set(synth, {
type: "var",
init: _babel_types.isExpression(declaration) ? declaration : null
});
exportMap.set("default", synth);
}
continue;
}
if (_babel_types.isExportAllDeclaration(node)) reExportAllSources.push(node.source.value);
}
return {
bindings,
exports: exportMap,
reExportAllSources
};
}
function buildDeclarationMap(ast) {
const map = /* @__PURE__ */ new Map();
for (const statement of ast.program.body) {
const declaration = _babel_types.isExportNamedDeclaration(statement) && statement.declaration ? statement.declaration : _babel_types.isExportDefaultDeclaration(statement) ? statement.declaration : statement;
if (_babel_types.isVariableDeclaration(declaration)) for (const declarator of declaration.declarations) for (const name of collectIdentifiersFromPattern(declarator.id)) map.set(name, declarator);
else if (_babel_types.isFunctionDeclaration(declaration) && declaration.id) map.set(declaration.id.name, declaration);
else if (_babel_types.isClassDeclaration(declaration) && declaration.id) map.set(declaration.id.name, declaration);
}
return map;
}
function buildDependencyGraph(declarationMap, localBindings) {
const graph = /* @__PURE__ */ new Map();
for (const [name, declarationNode] of declarationMap) {
if (!localBindings.has(name)) continue;
const dependencies = /* @__PURE__ */ new Set();
for (const id of collectIdentifiersFromNode(declarationNode)) if (id !== name && localBindings.has(id)) dependencies.add(id);
graph.set(name, dependencies);
}
return graph;
}
function collectModuleLevelRefsFromNode(node, localModuleLevelBindings) {
const refs = /* @__PURE__ */ new Set();
for (const name of collectIdentifiersFromNode(node)) if (localModuleLevelBindings.has(name)) refs.add(name);
return refs;
}
function expandTransitively(bindings, dependencyGraph) {
const queue = [...bindings];
const visited = /* @__PURE__ */ new Set();
while (queue.length > 0) {
const name = queue.pop();
if (visited.has(name)) continue;
visited.add(name);
const dependencies = dependencyGraph.get(name);
if (!dependencies) continue;
for (const dependency of dependencies) if (!bindings.has(dependency)) {
bindings.add(dependency);
queue.push(dependency);
}
}
}
function expandSharedDestructuredDeclarators(ast, refsByGroup, sharedBindings) {
for (const statement of ast.program.body) {
const declaration = _babel_types.isExportNamedDeclaration(statement) && statement.declaration ? statement.declaration : statement;
if (!_babel_types.isVariableDeclaration(declaration)) continue;
for (const declarator of declaration.declarations) {
if (!_babel_types.isObjectPattern(declarator.id) && !_babel_types.isArrayPattern(declarator.id)) continue;
const names = collectIdentifiersFromPattern(declarator.id);
const usedGroups = /* @__PURE__ */ new Set();
for (const name of names) {
const groups = refsByGroup.get(name);
if (!groups) continue;
for (const group of groups) usedGroups.add(group);
}
if (usedGroups.size >= 2) for (const name of names) sharedBindings.add(name);
}
}
}
function expandDestructuredDeclarations(ast, bindings) {
for (const statement of ast.program.body) {
const declaration = _babel_types.isExportNamedDeclaration(statement) && statement.declaration ? statement.declaration : statement;
if (!_babel_types.isVariableDeclaration(declaration)) continue;
for (const declarator of declaration.declarations) {
if (!_babel_types.isObjectPattern(declarator.id) && !_babel_types.isArrayPattern(declarator.id)) continue;
const names = collectIdentifiersFromPattern(declarator.id);
if (names.some((name) => bindings.has(name))) for (const name of names) bindings.add(name);
}
}
}
function removeBindingsTransitivelyDependingOn(bindings, dependencyGraph, roots) {
const reverseGraph = /* @__PURE__ */ new Map();
for (const [name, dependencies] of dependencyGraph) for (const dependency of dependencies) {
let parents = reverseGraph.get(dependency);
if (!parents) {
parents = /* @__PURE__ */ new Set();
reverseGraph.set(dependency, parents);
}
parents.add(name);
}
const visited = /* @__PURE__ */ new Set();
const queue = [...roots];
while (queue.length > 0) {
const current = queue.pop();
if (visited.has(current)) continue;
visited.add(current);
const parents = reverseGraph.get(current);
if (!parents) continue;
for (const parent of parents) if (!visited.has(parent)) queue.push(parent);
}
for (const name of [...bindings]) if (visited.has(name)) bindings.delete(name);
}
function removeModuleLevelBindings(ast, namesToRemove) {
ast.program.body = ast.program.body.filter((statement) => {
const declaration = _babel_types.isExportNamedDeclaration(statement) && statement.declaration ? statement.declaration : statement;
if (_babel_types.isVariableDeclaration(declaration)) {
declaration.declarations = declaration.declarations.filter((declarator) => !collectIdentifiersFromPattern(declarator.id).some((name) => namesToRemove.has(name)));
return declaration.declarations.length > 0;
}
if (_babel_types.isFunctionDeclaration(declaration) && declaration.id) return !namesToRemove.has(declaration.id.name);
if (_babel_types.isClassDeclaration(declaration) && declaration.id) return !namesToRemove.has(declaration.id.name);
if (_babel_types.isExportDefaultDeclaration(statement)) {
const defaultDeclaration = statement.declaration;
if ((_babel_types.isFunctionDeclaration(defaultDeclaration) || _babel_types.isClassDeclaration(defaultDeclaration)) && defaultDeclaration.id) return !namesToRemove.has(defaultDeclaration.id.name);
}
return true;
});
}
function retainModuleLevelDeclarations(ast, bindingsToKeep) {
ast.program.body = ast.program.body.filter((statement) => {
if (_babel_types.isImportDeclaration(statement)) return true;
const declaration = _babel_types.isExportNamedDeclaration(statement) && statement.declaration ? statement.declaration : statement;
if (_babel_types.isVariableDeclaration(declaration)) {
declaration.declarations = declaration.declarations.filter((declarator) => collectIdentifiersFromPattern(declarator.id).some((name) => bindingsToKeep.has(name)));
return declaration.declarations.length > 0;
}
if (_babel_types.isFunctionDeclaration(declaration) && declaration.id) return bindingsToKeep.has(declaration.id.name);
if (_babel_types.isClassDeclaration(declaration) && declaration.id) return bindingsToKeep.has(declaration.id.name);
return false;
});
}
function unwrapExportedDeclarations(ast) {
const body = [];
for (const statement of ast.program.body) {
if (_babel_types.isExportNamedDeclaration(statement)) {
if (statement.declaration) body.push(statement.declaration);
continue;
}
if (_babel_types.isExportDefaultDeclaration(statement)) {
const declaration = statement.declaration;
if ((_babel_types.isFunctionDeclaration(declaration) || _babel_types.isClassDeclaration(declaration)) && declaration.id) body.push(declaration);
continue;
}
if (_babel_types.isExportAllDeclaration(statement)) continue;
body.push(statement);
}
ast.program.body = body;
}
function stripUnreferencedTopLevelExpressionStatements(ast) {
const locallyBound = /* @__PURE__ */ new Set();
for (const statement of ast.program.body) collectLocalBindingsFromStatement(statement, locallyBound);
ast.program.body = ast.program.body.filter((statement) => {
if (!_babel_types.isExpressionStatement(statement)) return true;
for (const name of collectIdentifiersFromNode(statement)) if (locallyBound.has(name)) return true;
return false;
});
}
//#endregion
exports.buildDeclarationMap = buildDeclarationMap;
exports.buildDependencyGraph = buildDependencyGraph;
exports.collectIdentifiersFromNode = collectIdentifiersFromNode;
exports.collectIdentifiersFromPattern = collectIdentifiersFromPattern;
exports.collectLocalBindingsFromStatement = collectLocalBindingsFromStatement;
exports.collectModuleLevelRefsFromNode = collectModuleLevelRefsFromNode;
exports.expandDestructuredDeclarations = expandDestructuredDeclarations;
exports.expandSharedDestructuredDeclarators = expandSharedDestructuredDeclarators;
exports.expandTransitively = expandTransitively;
exports.extractModuleInfoFromAst = extractModuleInfoFromAst;
exports.removeBindingsTransitivelyDependingOn = removeBindingsTransitivelyDependingOn;
exports.removeModuleLevelBindings = removeModuleLevelBindings;
exports.retainModuleLevelDeclarations = retainModuleLevelDeclarations;
exports.stripUnreferencedTopLevelExpressionStatements = stripUnreferencedTopLevelExpressionStatements;
exports.unwrapExportedDeclarations = unwrapExportedDeclarations;
//# sourceMappingURL=compiler-helpers.cjs.map
{"version":3,"file":"compiler-helpers.cjs","names":[],"sources":["../../src/compiler-helpers.ts"],"sourcesContent":["import * as t from '@babel/types'\n\ntype IdentifierScopeFrame = {\n kind: 'program' | 'function' | 'block'\n bindings: Set<string>\n}\ntype IdentifierScopeStack = Array<IdentifierScopeFrame>\n\nexport type ModuleInfoBinding =\n | {\n type: 'import'\n source: string\n importedName: string\n }\n | {\n type: 'var'\n init: t.Expression | null\n }\n\nexport interface ExtractedModuleInfo {\n bindings: Map<string, ModuleInfoBinding>\n exports: Map<string, string>\n reExportAllSources: Array<string>\n}\n\nfunction getModuleExportName(node: t.Identifier | t.StringLiteral) {\n return t.isIdentifier(node) ? node.name : node.value\n}\n\nfunction addVariableDeclarationModuleInfo(\n declaration: t.VariableDeclaration,\n bindings: Map<string, ModuleInfoBinding>,\n exportMap?: Map<string, string>,\n) {\n for (const declarator of declaration.declarations) {\n for (const name of collectIdentifiersFromPattern(declarator.id)) {\n bindings.set(name, {\n type: 'var',\n init: declarator.init ?? null,\n })\n exportMap?.set(name, name)\n }\n }\n}\n\nfunction addDeclarationModuleInfo(\n declaration: t.Declaration,\n bindings: Map<string, ModuleInfoBinding>,\n exportMap?: Map<string, string>,\n) {\n if (t.isVariableDeclaration(declaration)) {\n addVariableDeclarationModuleInfo(declaration, bindings, exportMap)\n return\n }\n\n if (\n (t.isFunctionDeclaration(declaration) ||\n t.isClassDeclaration(declaration)) &&\n declaration.id\n ) {\n bindings.set(declaration.id.name, {\n type: 'var',\n init: null,\n })\n exportMap?.set(declaration.id.name, declaration.id.name)\n }\n}\n\nfunction hasIdentifierBinding(scopes: IdentifierScopeStack, name: string) {\n for (let i = scopes.length - 1; i >= 0; i--) {\n if (scopes[i]!.bindings.has(name)) {\n return true\n }\n }\n return false\n}\n\nfunction currentIdentifierScope(scopes: IdentifierScopeStack) {\n return scopes[scopes.length - 1]!\n}\n\nfunction nearestFunctionIdentifierScope(scopes: IdentifierScopeStack) {\n for (let i = scopes.length - 1; i >= 0; i--) {\n const scope = scopes[i]!\n if (scope.kind === 'function' || scope.kind === 'program') {\n return scope\n }\n }\n return currentIdentifierScope(scopes)\n}\n\nfunction addIdentifierPatternBindings(\n pattern: t.LVal | t.Node | null | undefined,\n scope: IdentifierScopeFrame,\n) {\n for (const name of collectIdentifiersFromPattern(pattern)) {\n scope.bindings.add(name)\n }\n}\n\nfunction addIdentifierDeclarationBindings(\n declaration: t.Node,\n scopes: IdentifierScopeStack,\n) {\n if (t.isVariableDeclaration(declaration)) {\n const scope =\n declaration.kind === 'var'\n ? nearestFunctionIdentifierScope(scopes)\n : currentIdentifierScope(scopes)\n for (const declarator of declaration.declarations) {\n addIdentifierPatternBindings(declarator.id, scope)\n }\n return\n }\n\n if (\n (t.isFunctionDeclaration(declaration) ||\n t.isClassDeclaration(declaration) ||\n t.isTSTypeAliasDeclaration(declaration) ||\n t.isTSInterfaceDeclaration(declaration) ||\n t.isTSEnumDeclaration(declaration)) &&\n declaration.id\n ) {\n currentIdentifierScope(scopes).bindings.add(declaration.id.name)\n }\n}\n\nfunction addIdentifierImportBindings(\n node: t.ImportDeclaration,\n scope: IdentifierScopeFrame,\n) {\n for (const specifier of node.specifiers) {\n scope.bindings.add(specifier.local.name)\n }\n}\n\nfunction createNestedIdentifierScope(\n kind: IdentifierScopeFrame['kind'],\n scopes: IdentifierScopeStack,\n): IdentifierScopeStack {\n return [...scopes, { kind, bindings: new Set() }]\n}\n\nfunction addIdentifierBlockBindings(\n body: Array<t.Node>,\n scopes: IdentifierScopeStack,\n) {\n for (const statement of body) {\n if (t.isImportDeclaration(statement)) {\n addIdentifierImportBindings(statement, currentIdentifierScope(scopes))\n } else if (t.isExportNamedDeclaration(statement) && statement.declaration) {\n addIdentifierDeclarationBindings(statement.declaration, scopes)\n } else {\n addIdentifierDeclarationBindings(statement, scopes)\n }\n }\n}\n\nfunction walkIdentifierChildren(\n current: t.Node,\n parent: t.Node | undefined,\n scopes: IdentifierScopeStack,\n ids: Set<string>,\n) {\n for (const key of t.VISITOR_KEYS[current.type] ?? []) {\n const child = (current as any)[key]\n if (Array.isArray(child)) {\n for (const item of child) {\n if (item && typeof item.type === 'string') {\n walkIdentifierNode(item, current, parent, key, scopes, ids)\n }\n }\n } else if (child && typeof child.type === 'string') {\n walkIdentifierNode(child, current, parent, key, scopes, ids)\n }\n }\n}\n\nfunction walkIdentifierNode(\n current: t.Node | null | undefined,\n parent: t.Node | undefined,\n grandparent: t.Node | undefined,\n parentKey: string | undefined,\n scopes: IdentifierScopeStack,\n ids: Set<string>,\n) {\n if (!current) return\n\n if (t.isIdentifier(current)) {\n if (\n (!parent || t.isReferenced(current, parent, grandparent)) &&\n !hasIdentifierBinding(scopes, current.name)\n ) {\n ids.add(current.name)\n }\n return\n }\n\n if (t.isJSXIdentifier(current)) {\n if (parent && t.isJSXAttribute(parent) && parentKey === 'name') {\n return\n }\n\n if (parent && t.isJSXMemberExpression(parent) && parentKey === 'property') {\n return\n }\n\n const first = current.name[0]\n if (first && first === first.toLowerCase()) {\n return\n }\n\n if (!hasIdentifierBinding(scopes, current.name)) {\n ids.add(current.name)\n }\n return\n }\n\n if (t.isProgram(current)) {\n const nestedScopes = createNestedIdentifierScope('program', scopes)\n addIdentifierBlockBindings(current.body, nestedScopes)\n for (const child of current.body) {\n walkIdentifierNode(child, current, parent, 'body', nestedScopes, ids)\n }\n return\n }\n\n if (t.isBlockStatement(current)) {\n const nestedScopes = createNestedIdentifierScope('block', scopes)\n addIdentifierBlockBindings(current.body, nestedScopes)\n for (const child of current.body) {\n walkIdentifierNode(child, current, parent, 'body', nestedScopes, ids)\n }\n return\n }\n\n if (\n t.isFunctionDeclaration(current) ||\n t.isFunctionExpression(current) ||\n t.isArrowFunctionExpression(current) ||\n t.isObjectMethod(current) ||\n t.isClassMethod(current) ||\n t.isClassPrivateMethod(current)\n ) {\n if (t.isFunctionDeclaration(current) && current.id) {\n currentIdentifierScope(scopes).bindings.add(current.id.name)\n }\n\n const nestedScopes = createNestedIdentifierScope('function', scopes)\n if (\n (t.isFunctionDeclaration(current) || t.isFunctionExpression(current)) &&\n current.id\n ) {\n currentIdentifierScope(nestedScopes).bindings.add(current.id.name)\n }\n for (const param of current.params) {\n addIdentifierPatternBindings(param, currentIdentifierScope(nestedScopes))\n }\n\n walkIdentifierChildren(current, parent, nestedScopes, ids)\n return\n }\n\n if (t.isCatchClause(current)) {\n const nestedScopes = createNestedIdentifierScope('block', scopes)\n addIdentifierPatternBindings(\n current.param,\n currentIdentifierScope(nestedScopes),\n )\n walkIdentifierNode(\n current.param,\n current,\n parent,\n 'param',\n nestedScopes,\n ids,\n )\n walkIdentifierNode(current.body, current, parent, 'body', nestedScopes, ids)\n return\n }\n\n if (t.isImportDeclaration(current)) {\n addIdentifierImportBindings(current, currentIdentifierScope(scopes))\n return\n }\n\n if (t.isClassDeclaration(current) || t.isClassExpression(current)) {\n if (t.isClassDeclaration(current) && current.id) {\n currentIdentifierScope(scopes).bindings.add(current.id.name)\n }\n\n const nestedScopes = current.id\n ? createNestedIdentifierScope('block', scopes)\n : scopes\n if (current.id) {\n currentIdentifierScope(nestedScopes).bindings.add(current.id.name)\n }\n\n walkIdentifierChildren(current, parent, nestedScopes, ids)\n return\n }\n\n if (t.isVariableDeclaration(current)) {\n addIdentifierDeclarationBindings(current, scopes)\n } else if (t.isVariableDeclarator(current)) {\n const scope =\n parent && t.isVariableDeclaration(parent) && parent.kind === 'var'\n ? nearestFunctionIdentifierScope(scopes)\n : currentIdentifierScope(scopes)\n addIdentifierPatternBindings(current.id, scope)\n } else if (\n t.isTSTypeAliasDeclaration(current) ||\n t.isTSInterfaceDeclaration(current) ||\n t.isTSEnumDeclaration(current)\n ) {\n currentIdentifierScope(scopes).bindings.add(current.id.name)\n }\n\n walkIdentifierChildren(current, parent, scopes, ids)\n}\n\n/**\n * Recursively walk an AST node and collect referenced identifier-like names.\n * This avoids Babel path/scope allocation for module-level dependency scans.\n */\nexport function collectIdentifiersFromNode(node: t.Node): Set<string> {\n const ids = new Set<string>()\n walkIdentifierNode(\n node,\n undefined,\n undefined,\n undefined,\n [{ kind: 'program', bindings: new Set() }],\n ids,\n )\n return ids\n}\n\nexport function collectIdentifiersFromPattern(\n node: t.LVal | t.Node | null | undefined,\n): Array<string> {\n if (!node) {\n return []\n }\n\n if (t.isIdentifier(node)) {\n return [node.name]\n }\n\n if (t.isAssignmentPattern(node)) {\n return collectIdentifiersFromPattern(node.left)\n }\n\n if (t.isRestElement(node)) {\n return collectIdentifiersFromPattern(node.argument)\n }\n\n if (t.isObjectPattern(node)) {\n return node.properties.flatMap((prop) => {\n if (t.isObjectProperty(prop)) {\n return collectIdentifiersFromPattern(prop.value as t.LVal)\n }\n if (t.isRestElement(prop)) {\n return collectIdentifiersFromPattern(prop.argument)\n }\n return []\n })\n }\n\n if (t.isArrayPattern(node)) {\n return node.elements.flatMap((element) =>\n collectIdentifiersFromPattern(element),\n )\n }\n\n return []\n}\n\nexport function collectLocalBindingsFromStatement(\n node: t.Statement | t.ModuleDeclaration,\n bindings: Set<string>,\n) {\n const declaration =\n t.isExportNamedDeclaration(node) && node.declaration\n ? node.declaration\n : t.isExportDefaultDeclaration(node)\n ? node.declaration\n : node\n\n if (t.isVariableDeclaration(declaration)) {\n for (const declarator of declaration.declarations) {\n for (const name of collectIdentifiersFromPattern(declarator.id)) {\n bindings.add(name)\n }\n }\n } else if (t.isFunctionDeclaration(declaration) && declaration.id) {\n bindings.add(declaration.id.name)\n } else if (t.isClassDeclaration(declaration) && declaration.id) {\n bindings.add(declaration.id.name)\n }\n}\n\nexport function extractModuleInfoFromAst(ast: t.File): ExtractedModuleInfo {\n const bindings = new Map<string, ModuleInfoBinding>()\n const exportMap = new Map<string, string>()\n const reExportAllSources: Array<string> = []\n\n for (const node of ast.program.body) {\n if (t.isImportDeclaration(node)) {\n const source = node.source.value\n for (const specifier of node.specifiers) {\n if (t.isImportSpecifier(specifier)) {\n bindings.set(specifier.local.name, {\n type: 'import',\n source,\n importedName: getModuleExportName(specifier.imported),\n })\n } else if (t.isImportDefaultSpecifier(specifier)) {\n bindings.set(specifier.local.name, {\n type: 'import',\n source,\n importedName: 'default',\n })\n } else if (t.isImportNamespaceSpecifier(specifier)) {\n bindings.set(specifier.local.name, {\n type: 'import',\n source,\n importedName: '*',\n })\n }\n }\n continue\n }\n\n if (t.isVariableDeclaration(node)) {\n addVariableDeclarationModuleInfo(node, bindings)\n continue\n }\n\n if (t.isFunctionDeclaration(node) || t.isClassDeclaration(node)) {\n addDeclarationModuleInfo(node, bindings)\n continue\n }\n\n if (t.isExportNamedDeclaration(node)) {\n if (node.declaration) {\n addDeclarationModuleInfo(node.declaration, bindings, exportMap)\n }\n\n for (const specifier of node.specifiers) {\n if (t.isExportNamespaceSpecifier(specifier)) {\n const exported = getModuleExportName(specifier.exported)\n exportMap.set(exported, exported)\n if (node.source) {\n bindings.set(exported, {\n type: 'import',\n source: node.source.value,\n importedName: '*',\n })\n }\n } else if (t.isExportSpecifier(specifier)) {\n const local = getModuleExportName(specifier.local)\n const exported = getModuleExportName(specifier.exported)\n exportMap.set(exported, local)\n\n if (node.source) {\n bindings.set(local, {\n type: 'import',\n source: node.source.value,\n importedName: local,\n })\n }\n }\n }\n continue\n }\n\n if (t.isExportDefaultDeclaration(node)) {\n const declaration = node.declaration\n if (t.isIdentifier(declaration)) {\n exportMap.set('default', declaration.name)\n } else if (\n (t.isFunctionDeclaration(declaration) ||\n t.isClassDeclaration(declaration)) &&\n declaration.id\n ) {\n bindings.set(declaration.id.name, {\n type: 'var',\n init: null,\n })\n exportMap.set('default', declaration.id.name)\n } else {\n const synth = '__default_export__'\n bindings.set(synth, {\n type: 'var',\n init: t.isExpression(declaration) ? declaration : null,\n })\n exportMap.set('default', synth)\n }\n continue\n }\n\n if (t.isExportAllDeclaration(node)) {\n reExportAllSources.push(node.source.value)\n }\n }\n\n return {\n bindings,\n exports: exportMap,\n reExportAllSources,\n }\n}\n\nexport function buildDeclarationMap(ast: t.File): Map<string, t.Node> {\n const map = new Map<string, t.Node>()\n\n for (const statement of ast.program.body) {\n const declaration =\n t.isExportNamedDeclaration(statement) && statement.declaration\n ? statement.declaration\n : t.isExportDefaultDeclaration(statement)\n ? statement.declaration\n : statement\n\n if (t.isVariableDeclaration(declaration)) {\n for (const declarator of declaration.declarations) {\n for (const name of collectIdentifiersFromPattern(declarator.id)) {\n map.set(name, declarator)\n }\n }\n } else if (t.isFunctionDeclaration(declaration) && declaration.id) {\n map.set(declaration.id.name, declaration)\n } else if (t.isClassDeclaration(declaration) && declaration.id) {\n map.set(declaration.id.name, declaration)\n }\n }\n\n return map\n}\n\nexport function buildDependencyGraph(\n declarationMap: Map<string, t.Node>,\n localBindings: Set<string>,\n): Map<string, Set<string>> {\n const graph = new Map<string, Set<string>>()\n\n for (const [name, declarationNode] of declarationMap) {\n if (!localBindings.has(name)) continue\n\n const dependencies = new Set<string>()\n for (const id of collectIdentifiersFromNode(declarationNode)) {\n if (id !== name && localBindings.has(id)) {\n dependencies.add(id)\n }\n }\n graph.set(name, dependencies)\n }\n\n return graph\n}\n\nexport function collectModuleLevelRefsFromNode(\n node: t.Node,\n localModuleLevelBindings: Set<string>,\n): Set<string> {\n const refs = new Set<string>()\n\n for (const name of collectIdentifiersFromNode(node)) {\n if (localModuleLevelBindings.has(name)) {\n refs.add(name)\n }\n }\n\n return refs\n}\n\nexport function expandTransitively(\n bindings: Set<string>,\n dependencyGraph: Map<string, Set<string>>,\n) {\n const queue = [...bindings]\n const visited = new Set<string>()\n\n while (queue.length > 0) {\n const name = queue.pop()!\n if (visited.has(name)) continue\n visited.add(name)\n\n const dependencies = dependencyGraph.get(name)\n if (!dependencies) continue\n\n for (const dependency of dependencies) {\n if (!bindings.has(dependency)) {\n bindings.add(dependency)\n queue.push(dependency)\n }\n }\n }\n}\n\nexport function expandSharedDestructuredDeclarators(\n ast: t.File,\n refsByGroup: Map<string, Set<number>>,\n sharedBindings: Set<string>,\n) {\n for (const statement of ast.program.body) {\n const declaration =\n t.isExportNamedDeclaration(statement) && statement.declaration\n ? statement.declaration\n : statement\n\n if (!t.isVariableDeclaration(declaration)) continue\n\n for (const declarator of declaration.declarations) {\n if (\n !t.isObjectPattern(declarator.id) &&\n !t.isArrayPattern(declarator.id)\n ) {\n continue\n }\n\n const names = collectIdentifiersFromPattern(declarator.id)\n const usedGroups = new Set<number>()\n\n for (const name of names) {\n const groups = refsByGroup.get(name)\n if (!groups) continue\n for (const group of groups) {\n usedGroups.add(group)\n }\n }\n\n if (usedGroups.size >= 2) {\n for (const name of names) {\n sharedBindings.add(name)\n }\n }\n }\n }\n}\n\nexport function expandDestructuredDeclarations(\n ast: t.File,\n bindings: Set<string>,\n) {\n for (const statement of ast.program.body) {\n const declaration =\n t.isExportNamedDeclaration(statement) && statement.declaration\n ? statement.declaration\n : statement\n\n if (!t.isVariableDeclaration(declaration)) continue\n\n for (const declarator of declaration.declarations) {\n if (\n !t.isObjectPattern(declarator.id) &&\n !t.isArrayPattern(declarator.id)\n ) {\n continue\n }\n\n const names = collectIdentifiersFromPattern(declarator.id)\n if (names.some((name) => bindings.has(name))) {\n for (const name of names) {\n bindings.add(name)\n }\n }\n }\n }\n}\n\nexport function removeBindingsTransitivelyDependingOn(\n bindings: Set<string>,\n dependencyGraph: Map<string, Set<string>>,\n roots: Iterable<string>,\n) {\n const reverseGraph = new Map<string, Set<string>>()\n\n for (const [name, dependencies] of dependencyGraph) {\n for (const dependency of dependencies) {\n let parents = reverseGraph.get(dependency)\n if (!parents) {\n parents = new Set()\n reverseGraph.set(dependency, parents)\n }\n parents.add(name)\n }\n }\n\n const visited = new Set<string>()\n const queue = [...roots]\n\n while (queue.length > 0) {\n const current = queue.pop()!\n if (visited.has(current)) continue\n visited.add(current)\n\n const parents = reverseGraph.get(current)\n if (!parents) continue\n\n for (const parent of parents) {\n if (!visited.has(parent)) {\n queue.push(parent)\n }\n }\n }\n\n for (const name of [...bindings]) {\n if (visited.has(name)) {\n bindings.delete(name)\n }\n }\n}\n\nexport function removeModuleLevelBindings(\n ast: t.File,\n namesToRemove: Set<string>,\n) {\n ast.program.body = ast.program.body.filter((statement) => {\n const declaration =\n t.isExportNamedDeclaration(statement) && statement.declaration\n ? statement.declaration\n : statement\n\n if (t.isVariableDeclaration(declaration)) {\n declaration.declarations = declaration.declarations.filter(\n (declarator) =>\n !collectIdentifiersFromPattern(declarator.id).some((name) =>\n namesToRemove.has(name),\n ),\n )\n return declaration.declarations.length > 0\n }\n\n if (t.isFunctionDeclaration(declaration) && declaration.id) {\n return !namesToRemove.has(declaration.id.name)\n }\n\n if (t.isClassDeclaration(declaration) && declaration.id) {\n return !namesToRemove.has(declaration.id.name)\n }\n\n if (t.isExportDefaultDeclaration(statement)) {\n const defaultDeclaration = statement.declaration\n if (\n (t.isFunctionDeclaration(defaultDeclaration) ||\n t.isClassDeclaration(defaultDeclaration)) &&\n defaultDeclaration.id\n ) {\n return !namesToRemove.has(defaultDeclaration.id.name)\n }\n }\n\n return true\n })\n}\n\nexport function retainModuleLevelDeclarations(\n ast: t.File,\n bindingsToKeep: Set<string>,\n) {\n ast.program.body = ast.program.body.filter((statement) => {\n if (t.isImportDeclaration(statement)) return true\n\n const declaration =\n t.isExportNamedDeclaration(statement) && statement.declaration\n ? statement.declaration\n : statement\n\n if (t.isVariableDeclaration(declaration)) {\n declaration.declarations = declaration.declarations.filter((declarator) =>\n collectIdentifiersFromPattern(declarator.id).some((name) =>\n bindingsToKeep.has(name),\n ),\n )\n return declaration.declarations.length > 0\n }\n\n if (t.isFunctionDeclaration(declaration) && declaration.id) {\n return bindingsToKeep.has(declaration.id.name)\n }\n\n if (t.isClassDeclaration(declaration) && declaration.id) {\n return bindingsToKeep.has(declaration.id.name)\n }\n\n return false\n })\n}\n\nexport function unwrapExportedDeclarations(ast: t.File) {\n const body: Array<t.Statement | t.ModuleDeclaration> = []\n\n for (const statement of ast.program.body) {\n if (t.isExportNamedDeclaration(statement)) {\n if (statement.declaration) {\n body.push(statement.declaration)\n }\n continue\n }\n\n if (t.isExportDefaultDeclaration(statement)) {\n const declaration = statement.declaration\n if (\n (t.isFunctionDeclaration(declaration) ||\n t.isClassDeclaration(declaration)) &&\n declaration.id\n ) {\n body.push(declaration)\n }\n continue\n }\n\n if (t.isExportAllDeclaration(statement)) {\n continue\n }\n\n body.push(statement)\n }\n\n ast.program.body = body\n}\n\nexport function stripUnreferencedTopLevelExpressionStatements(ast: t.File) {\n const locallyBound = new Set<string>()\n\n for (const statement of ast.program.body) {\n collectLocalBindingsFromStatement(statement, locallyBound)\n }\n\n ast.program.body = ast.program.body.filter((statement) => {\n if (!t.isExpressionStatement(statement)) return true\n\n for (const name of collectIdentifiersFromNode(statement)) {\n if (locallyBound.has(name)) {\n return true\n }\n }\n\n return false\n })\n}\n"],"mappings":";;;;AAyBA,SAAS,oBAAoB,MAAsC;AACjE,QAAO,aAAE,aAAa,KAAK,GAAG,KAAK,OAAO,KAAK;;AAGjD,SAAS,iCACP,aACA,UACA,WACA;AACA,MAAK,MAAM,cAAc,YAAY,aACnC,MAAK,MAAM,QAAQ,8BAA8B,WAAW,GAAG,EAAE;AAC/D,WAAS,IAAI,MAAM;GACjB,MAAM;GACN,MAAM,WAAW,QAAQ;GAC1B,CAAC;AACF,aAAW,IAAI,MAAM,KAAK;;;AAKhC,SAAS,yBACP,aACA,UACA,WACA;AACA,KAAI,aAAE,sBAAsB,YAAY,EAAE;AACxC,mCAAiC,aAAa,UAAU,UAAU;AAClE;;AAGF,MACG,aAAE,sBAAsB,YAAY,IACnC,aAAE,mBAAmB,YA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Q,MAAM;AACxC,MAAI,aAAE,yBAAyB,UAAU,EAAE;AACzC,OAAI,UAAU,YACZ,MAAK,KAAK,UAAU,YAAY;AAElC;;AAGF,MAAI,aAAE,2BAA2B,UAAU,EAAE;GAC3C,MAAM,cAAc,UAAU;AAC9B,QACG,aAAE,sBAAsB,YAAY,IACnC,aAAE,mBAAmB,YAAY,KACnC,YAAY,GAEZ,MAAK,KAAK,YAAY;AAExB;;AAGF,MAAI,aAAE,uBAAuB,UAAU,CACrC;AAGF,OAAK,KAAK,UAAU;;AAGtB,KAAI,QAAQ,OAAO;;AAGrB,SAAgB,8CAA8C,KAAa;CACzE,MAAM,+BAAe,IAAI,KAAa;AAEtC,MAAK,MAAM,aAAa,IAAI,QAAQ,KAClC,mCAAkC,WAAW,aAAa;AAG5D,KAAI,QAAQ,OAAO,IAAI,QAAQ,KAAK,QAAQ,cAAc;AACxD,MAAI,CAAC,aAAE,sBAAsB,UAAU,CAAE,QAAO;AAEhD,OAAK,MAAM,QAAQ,2BAA2B,UAAU,CACtD,KAAI,aAAa,IAAI,KAAK,CACxB,QAAO;AAIX,SAAO;GACP"}
import * as t from '@babel/types';
export type ModuleInfoBinding = {
type: 'import';
source: string;
importedName: string;
} | {
type: 'var';
init: t.Expression | null;
};
export interface ExtractedModuleInfo {
bindings: Map<string, ModuleInfoBinding>;
exports: Map<string, string>;
reExportAllSources: Array<string>;
}
/**
* Recursively walk an AST node and collect referenced identifier-like names.
* This avoids Babel path/scope allocation for module-level dependency scans.
*/
export declare function collectIdentifiersFromNode(node: t.Node): Set<string>;
export declare function collectIdentifiersFromPattern(node: t.LVal | t.Node | null | undefined): Array<string>;
export declare function collectLocalBindingsFromStatement(node: t.Statement | t.ModuleDeclaration, bindings: Set<string>): void;
export declare function extractModuleInfoFromAst(ast: t.File): ExtractedModuleInfo;
export declare function buildDeclarationMap(ast: t.File): Map<string, t.Node>;
export declare function buildDependencyGraph(declarationMap: Map<string, t.Node>, localBindings: Set<string>): Map<string, Set<string>>;
export declare function collectModuleLevelRefsFromNode(node: t.Node, localModuleLevelBindings: Set<string>): Set<string>;
export declare function expandTransitively(bindings: Set<string>, dependencyGraph: Map<string, Set<string>>): void;
export declare function expandSharedDestructuredDeclarators(ast: t.File, refsByGroup: Map<string, Set<number>>, sharedBindings: Set<string>): void;
export declare function expandDestructuredDeclarations(ast: t.File, bindings: Set<string>): void;
export declare function removeBindingsTransitivelyDependingOn(bindings: Set<string>, dependencyGraph: Map<string, Set<string>>, roots: Iterable<string>): void;
export declare function removeModuleLevelBindings(ast: t.File, namesToRemove: Set<string>): void;
export declare function retainModuleLevelDeclarations(ast: t.File, bindingsToKeep: Set<string>): void;
export declare function unwrapExportedDeclarations(ast: t.File): void;
export declare function stripUnreferencedTopLevelExpressionStatements(ast: t.File): void;
//#region src/path-ids.ts
function createIdentifier(strings) {
if (strings.length === 0) throw new Error("Cannot create an identifier from an empty array");
let safeString = [...strings].sort().join("---").replace(/\//g, "--slash--");
safeString = safeString.replace(/\\/g, "--backslash--");
safeString = safeString.replace(/\?/g, "--question--");
safeString = safeString.replace(/%/g, "--percent--");
safeString = safeString.replace(/#/g, "--hash--");
safeString = safeString.replace(/\+/g, "--plus--");
safeString = safeString.replace(/=/g, "--equals--");
safeString = safeString.replace(/&/g, "--ampersand--");
safeString = safeString.replace(/\s/g, "_");
return safeString;
}
function decodeIdentifier(identifier) {
if (!identifier) return [];
let combinedString = identifier.replace(/--slash--/g, "/");
combinedString = combinedString.replace(/--backslash--/g, "\\");
combinedString = combinedString.replace(/--question--/g, "?");
combinedString = combinedString.replace(/--percent--/g, "%");
combinedString = combinedString.replace(/--hash--/g, "#");
combinedString = combinedString.replace(/--plus--/g, "+");
combinedString = combinedString.replace(/--equals--/g, "=");
combinedString = combinedString.replace(/--ampersand--/g, "&");
combinedString = combinedString.replace(/_/g, " ");
return combinedString.split("---");
}
//#endregion
exports.createIdentifier = createIdentifier;
exports.decodeIdentifier = decodeIdentifier;
//# sourceMappingURL=path-ids.cjs.map
{"version":3,"file":"path-ids.cjs","names":[],"sources":["../../src/path-ids.ts"],"sourcesContent":["export function createIdentifier(strings: Array<string>): string {\n if (strings.length === 0) {\n throw new Error('Cannot create an identifier from an empty array')\n }\n\n const sortedStrings = [...strings].sort()\n const combinedString = sortedStrings.join('---') // Delimiter\n\n // Replace unsafe characters\n let safeString = combinedString.replace(/\\//g, '--slash--')\n safeString = safeString.replace(/\\\\/g, '--backslash--')\n safeString = safeString.replace(/\\?/g, '--question--')\n safeString = safeString.replace(/%/g, '--percent--')\n safeString = safeString.replace(/#/g, '--hash--')\n safeString = safeString.replace(/\\+/g, '--plus--')\n safeString = safeString.replace(/=/g, '--equals--')\n safeString = safeString.replace(/&/g, '--ampersand--')\n safeString = safeString.replace(/\\s/g, '_') // Replace spaces with underscores\n\n return safeString\n}\n\nexport function decodeIdentifier(identifier: string): Array<string> {\n if (!identifier) {\n return []\n }\n\n let combinedString = identifier.replace(/--slash--/g, '/')\n combinedString = combinedString.replace(/--backslash--/g, '\\\\')\n combinedString = combinedString.replace(/--question--/g, '?')\n combinedString = combinedString.replace(/--percent--/g, '%')\n combinedString = combinedString.replace(/--hash--/g, '#')\n combinedString = combinedString.replace(/--plus--/g, '+')\n combinedString = combinedString.replace(/--equals--/g, '=')\n combinedString = combinedString.replace(/--ampersand--/g, '&')\n combinedString = combinedString.replace(/_/g, ' ') // Restore spaces\n\n return combinedString.split('---')\n}\n"],"mappings":";AAAA,SAAgB,iBAAiB,SAAgC;AAC/D,KAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MAAM,kDAAkD;CAOpE,IAAI,aAJkB,CAAC,GAAG,QAAQ,CAAC,MAAM,CACJ,KAAK,MAAM,CAGhB,QAAQ,OAAO,YAAY;AAC3D,cAAa,WAAW,QAAQ,OAAO,gBAAgB;AACvD,cAAa,WAAW,QAAQ,OAAO,eAAe;AACtD,cAAa,WAAW,QAAQ,MAAM,cAAc;AACpD,cAAa,WAAW,QAAQ,MAAM,WAAW;AACjD,cAAa,WAAW,QAAQ,OAAO,WAAW;AAClD,cAAa,WAAW,QAAQ,MAAM,aAAa;AACnD,cAAa,WAAW,QAAQ,MAAM,gBAAgB;AACtD,cAAa,WAAW,QAAQ,OAAO,IAAI;AAE3C,QAAO;;AAGT,SAAgB,iBAAiB,YAAmC;AAClE,KAAI,CAAC,WACH,QAAO,EAAE;CAGX,IAAI,iBAAiB,WAAW,QAAQ,cAAc,IAAI;AAC1D,kBAAiB,eAAe,QAAQ,kBAAkB,KAAK;AAC/D,kBAAiB,eAAe,QAAQ,iBAAiB,IAAI;AAC7D,kBAAiB,eAAe,QAAQ,gBAAgB,IAAI;AAC5D,kBAAiB,eAAe,QAAQ,aAAa,IAAI;AACzD,kBAAiB,eAAe,QAAQ,aAAa,IAAI;AACzD,kBAAiB,eAAe,QAAQ,eAAe,IAAI;AAC3D,kBAAiB,eAAe,QAAQ,kBAAkB,IAAI;AAC9D,kBAAiB,eAAe,QAAQ,MAAM,IAAI;AAElD,QAAO,eAAe,MAAM,MAAM"}
export declare function createIdentifier(strings: Array<string>): string;
export declare function decodeIdentifier(identifier: string): Array<string>;
import * as t from '@babel/types';
export type ModuleInfoBinding = {
type: 'import';
source: string;
importedName: string;
} | {
type: 'var';
init: t.Expression | null;
};
export interface ExtractedModuleInfo {
bindings: Map<string, ModuleInfoBinding>;
exports: Map<string, string>;
reExportAllSources: Array<string>;
}
/**
* Recursively walk an AST node and collect referenced identifier-like names.
* This avoids Babel path/scope allocation for module-level dependency scans.
*/
export declare function collectIdentifiersFromNode(node: t.Node): Set<string>;
export declare function collectIdentifiersFromPattern(node: t.LVal | t.Node | null | undefined): Array<string>;
export declare function collectLocalBindingsFromStatement(node: t.Statement | t.ModuleDeclaration, bindings: Set<string>): void;
export declare function extractModuleInfoFromAst(ast: t.File): ExtractedModuleInfo;
export declare function buildDeclarationMap(ast: t.File): Map<string, t.Node>;
export declare function buildDependencyGraph(declarationMap: Map<string, t.Node>, localBindings: Set<string>): Map<string, Set<string>>;
export declare function collectModuleLevelRefsFromNode(node: t.Node, localModuleLevelBindings: Set<string>): Set<string>;
export declare function expandTransitively(bindings: Set<string>, dependencyGraph: Map<string, Set<string>>): void;
export declare function expandSharedDestructuredDeclarators(ast: t.File, refsByGroup: Map<string, Set<number>>, sharedBindings: Set<string>): void;
export declare function expandDestructuredDeclarations(ast: t.File, bindings: Set<string>): void;
export declare function removeBindingsTransitivelyDependingOn(bindings: Set<string>, dependencyGraph: Map<string, Set<string>>, roots: Iterable<string>): void;
export declare function removeModuleLevelBindings(ast: t.File, namesToRemove: Set<string>): void;
export declare function retainModuleLevelDeclarations(ast: t.File, bindingsToKeep: Set<string>): void;
export declare function unwrapExportedDeclarations(ast: t.File): void;
export declare function stripUnreferencedTopLevelExpressionStatements(ast: t.File): void;
import * as t from "@babel/types";
//#region src/compiler-helpers.ts
function getModuleExportName(node) {
return t.isIdentifier(node) ? node.name : node.value;
}
function addVariableDeclarationModuleInfo(declaration, bindings, exportMap) {
for (const declarator of declaration.declarations) for (const name of collectIdentifiersFromPattern(declarator.id)) {
bindings.set(name, {
type: "var",
init: declarator.init ?? null
});
exportMap?.set(name, name);
}
}
function addDeclarationModuleInfo(declaration, bindings, exportMap) {
if (t.isVariableDeclaration(declaration)) {
addVariableDeclarationModuleInfo(declaration, bindings, exportMap);
return;
}
if ((t.isFunctionDeclaration(declaration) || t.isClassDeclaration(declaration)) && declaration.id) {
bindings.set(declaration.id.name, {
type: "var",
init: null
});
exportMap?.set(declaration.id.name, declaration.id.name);
}
}
function hasIdentifierBinding(scopes, name) {
for (let i = scopes.length - 1; i >= 0; i--) if (scopes[i].bindings.has(name)) return true;
return false;
}
function currentIdentifierScope(scopes) {
return scopes[scopes.length - 1];
}
function nearestFunctionIdentifierScope(scopes) {
for (let i = scopes.length - 1; i >= 0; i--) {
const scope = scopes[i];
if (scope.kind === "function" || scope.kind === "program") return scope;
}
return currentIdentifierScope(scopes);
}
function addIdentifierPatternBindings(pattern, scope) {
for (const name of collectIdentifiersFromPattern(pattern)) scope.bindings.add(name);
}
function addIdentifierDeclarationBindings(declaration, scopes) {
if (t.isVariableDeclaration(declaration)) {
const scope = declaration.kind === "var" ? nearestFunctionIdentifierScope(scopes) : currentIdentifierScope(scopes);
for (const declarator of declaration.declarations) addIdentifierPatternBindings(declarator.id, scope);
return;
}
if ((t.isFunctionDeclaration(declaration) || t.isClassDeclaration(declaration) || t.isTSTypeAliasDeclaration(declaration) || t.isTSInterfaceDeclaration(declaration) || t.isTSEnumDeclaration(declaration)) && declaration.id) currentIdentifierScope(scopes).bindings.add(declaration.id.name);
}
function addIdentifierImportBindings(node, scope) {
for (const specifier of node.specifiers) scope.bindings.add(specifier.local.name);
}
function createNestedIdentifierScope(kind, scopes) {
return [...scopes, {
kind,
bindings: /* @__PURE__ */ new Set()
}];
}
function addIdentifierBlockBindings(body, scopes) {
for (const statement of body) if (t.isImportDeclaration(statement)) addIdentifierImportBindings(statement, currentIdentifierScope(scopes));
else if (t.isExportNamedDeclaration(statement) && statement.declaration) addIdentifierDeclarationBindings(statement.declaration, scopes);
else addIdentifierDeclarationBindings(statement, scopes);
}
function walkIdentifierChildren(current, parent, scopes, ids) {
for (const key of t.VISITOR_KEYS[current.type] ?? []) {
const child = current[key];
if (Array.isArray(child)) {
for (const item of child) if (item && typeof item.type === "string") walkIdentifierNode(item, current, parent, key, scopes, ids);
} else if (child && typeof child.type === "string") walkIdentifierNode(child, current, parent, key, scopes, ids);
}
}
function walkIdentifierNode(current, parent, grandparent, parentKey, scopes, ids) {
if (!current) return;
if (t.isIdentifier(current)) {
if ((!parent || t.isReferenced(current, parent, grandparent)) && !hasIdentifierBinding(scopes, current.name)) ids.add(current.name);
return;
}
if (t.isJSXIdentifier(current)) {
if (parent && t.isJSXAttribute(parent) && parentKey === "name") return;
if (parent && t.isJSXMemberExpression(parent) && parentKey === "property") return;
const first = current.name[0];
if (first && first === first.toLowerCase()) return;
if (!hasIdentifierBinding(scopes, current.name)) ids.add(current.name);
return;
}
if (t.isProgram(current)) {
const nestedScopes = createNestedIdentifierScope("program", scopes);
addIdentifierBlockBindings(current.body, nestedScopes);
for (const child of current.body) walkIdentifierNode(child, current, parent, "body", nestedScopes, ids);
return;
}
if (t.isBlockStatement(current)) {
const nestedScopes = createNestedIdentifierScope("block", scopes);
addIdentifierBlockBindings(current.body, nestedScopes);
for (const child of current.body) walkIdentifierNode(child, current, parent, "body", nestedScopes, ids);
return;
}
if (t.isFunctionDeclaration(current) || t.isFunctionExpression(current) || t.isArrowFunctionExpression(current) || t.isObjectMethod(current) || t.isClassMethod(current) || t.isClassPrivateMethod(current)) {
if (t.isFunctionDeclaration(current) && current.id) currentIdentifierScope(scopes).bindings.add(current.id.name);
const nestedScopes = createNestedIdentifierScope("function", scopes);
if ((t.isFunctionDeclaration(current) || t.isFunctionExpression(current)) && current.id) currentIdentifierScope(nestedScopes).bindings.add(current.id.name);
for (const param of current.params) addIdentifierPatternBindings(param, currentIdentifierScope(nestedScopes));
walkIdentifierChildren(current, parent, nestedScopes, ids);
return;
}
if (t.isCatchClause(current)) {
const nestedScopes = createNestedIdentifierScope("block", scopes);
addIdentifierPatternBindings(current.param, currentIdentifierScope(nestedScopes));
walkIdentifierNode(current.param, current, parent, "param", nestedScopes, ids);
walkIdentifierNode(current.body, current, parent, "body", nestedScopes, ids);
return;
}
if (t.isImportDeclaration(current)) {
addIdentifierImportBindings(current, currentIdentifierScope(scopes));
return;
}
if (t.isClassDeclaration(current) || t.isClassExpression(current)) {
if (t.isClassDeclaration(current) && current.id) currentIdentifierScope(scopes).bindings.add(current.id.name);
const nestedScopes = current.id ? createNestedIdentifierScope("block", scopes) : scopes;
if (current.id) currentIdentifierScope(nestedScopes).bindings.add(current.id.name);
walkIdentifierChildren(current, parent, nestedScopes, ids);
return;
}
if (t.isVariableDeclaration(current)) addIdentifierDeclarationBindings(current, scopes);
else if (t.isVariableDeclarator(current)) {
const scope = parent && t.isVariableDeclaration(parent) && parent.kind === "var" ? nearestFunctionIdentifierScope(scopes) : currentIdentifierScope(scopes);
addIdentifierPatternBindings(current.id, scope);
} else if (t.isTSTypeAliasDeclaration(current) || t.isTSInterfaceDeclaration(current) || t.isTSEnumDeclaration(current)) currentIdentifierScope(scopes).bindings.add(current.id.name);
walkIdentifierChildren(current, parent, scopes, ids);
}
/**
* Recursively walk an AST node and collect referenced identifier-like names.
* This avoids Babel path/scope allocation for module-level dependency scans.
*/
function collectIdentifiersFromNode(node) {
const ids = /* @__PURE__ */ new Set();
walkIdentifierNode(node, void 0, void 0, void 0, [{
kind: "program",
bindings: /* @__PURE__ */ new Set()
}], ids);
return ids;
}
function collectIdentifiersFromPattern(node) {
if (!node) return [];
if (t.isIdentifier(node)) return [node.name];
if (t.isAssignmentPattern(node)) return collectIdentifiersFromPattern(node.left);
if (t.isRestElement(node)) return collectIdentifiersFromPattern(node.argument);
if (t.isObjectPattern(node)) return node.properties.flatMap((prop) => {
if (t.isObjectProperty(prop)) return collectIdentifiersFromPattern(prop.value);
if (t.isRestElement(prop)) return collectIdentifiersFromPattern(prop.argument);
return [];
});
if (t.isArrayPattern(node)) return node.elements.flatMap((element) => collectIdentifiersFromPattern(element));
return [];
}
function collectLocalBindingsFromStatement(node, bindings) {
const declaration = t.isExportNamedDeclaration(node) && node.declaration ? node.declaration : t.isExportDefaultDeclaration(node) ? node.declaration : node;
if (t.isVariableDeclaration(declaration)) for (const declarator of declaration.declarations) for (const name of collectIdentifiersFromPattern(declarator.id)) bindings.add(name);
else if (t.isFunctionDeclaration(declaration) && declaration.id) bindings.add(declaration.id.name);
else if (t.isClassDeclaration(declaration) && declaration.id) bindings.add(declaration.id.name);
}
function extractModuleInfoFromAst(ast) {
const bindings = /* @__PURE__ */ new Map();
const exportMap = /* @__PURE__ */ new Map();
const reExportAllSources = [];
for (const node of ast.program.body) {
if (t.isImportDeclaration(node)) {
const source = node.source.value;
for (const specifier of node.specifiers) if (t.isImportSpecifier(specifier)) bindings.set(specifier.local.name, {
type: "import",
source,
importedName: getModuleExportName(specifier.imported)
});
else if (t.isImportDefaultSpecifier(specifier)) bindings.set(specifier.local.name, {
type: "import",
source,
importedName: "default"
});
else if (t.isImportNamespaceSpecifier(specifier)) bindings.set(specifier.local.name, {
type: "import",
source,
importedName: "*"
});
continue;
}
if (t.isVariableDeclaration(node)) {
addVariableDeclarationModuleInfo(node, bindings);
continue;
}
if (t.isFunctionDeclaration(node) || t.isClassDeclaration(node)) {
addDeclarationModuleInfo(node, bindings);
continue;
}
if (t.isExportNamedDeclaration(node)) {
if (node.declaration) addDeclarationModuleInfo(node.declaration, bindings, exportMap);
for (const specifier of node.specifiers) if (t.isExportNamespaceSpecifier(specifier)) {
const exported = getModuleExportName(specifier.exported);
exportMap.set(exported, exported);
if (node.source) bindings.set(exported, {
type: "import",
source: node.source.value,
importedName: "*"
});
} else if (t.isExportSpecifier(specifier)) {
const local = getModuleExportName(specifier.local);
const exported = getModuleExportName(specifier.exported);
exportMap.set(exported, local);
if (node.source) bindings.set(local, {
type: "import",
source: node.source.value,
importedName: local
});
}
continue;
}
if (t.isExportDefaultDeclaration(node)) {
const declaration = node.declaration;
if (t.isIdentifier(declaration)) exportMap.set("default", declaration.name);
else if ((t.isFunctionDeclaration(declaration) || t.isClassDeclaration(declaration)) && declaration.id) {
bindings.set(declaration.id.name, {
type: "var",
init: null
});
exportMap.set("default", declaration.id.name);
} else {
const synth = "__default_export__";
bindings.set(synth, {
type: "var",
init: t.isExpression(declaration) ? declaration : null
});
exportMap.set("default", synth);
}
continue;
}
if (t.isExportAllDeclaration(node)) reExportAllSources.push(node.source.value);
}
return {
bindings,
exports: exportMap,
reExportAllSources
};
}
function buildDeclarationMap(ast) {
const map = /* @__PURE__ */ new Map();
for (const statement of ast.program.body) {
const declaration = t.isExportNamedDeclaration(statement) && statement.declaration ? statement.declaration : t.isExportDefaultDeclaration(statement) ? statement.declaration : statement;
if (t.isVariableDeclaration(declaration)) for (const declarator of declaration.declarations) for (const name of collectIdentifiersFromPattern(declarator.id)) map.set(name, declarator);
else if (t.isFunctionDeclaration(declaration) && declaration.id) map.set(declaration.id.name, declaration);
else if (t.isClassDeclaration(declaration) && declaration.id) map.set(declaration.id.name, declaration);
}
return map;
}
function buildDependencyGraph(declarationMap, localBindings) {
const graph = /* @__PURE__ */ new Map();
for (const [name, declarationNode] of declarationMap) {
if (!localBindings.has(name)) continue;
const dependencies = /* @__PURE__ */ new Set();
for (const id of collectIdentifiersFromNode(declarationNode)) if (id !== name && localBindings.has(id)) dependencies.add(id);
graph.set(name, dependencies);
}
return graph;
}
function collectModuleLevelRefsFromNode(node, localModuleLevelBindings) {
const refs = /* @__PURE__ */ new Set();
for (const name of collectIdentifiersFromNode(node)) if (localModuleLevelBindings.has(name)) refs.add(name);
return refs;
}
function expandTransitively(bindings, dependencyGraph) {
const queue = [...bindings];
const visited = /* @__PURE__ */ new Set();
while (queue.length > 0) {
const name = queue.pop();
if (visited.has(name)) continue;
visited.add(name);
const dependencies = dependencyGraph.get(name);
if (!dependencies) continue;
for (const dependency of dependencies) if (!bindings.has(dependency)) {
bindings.add(dependency);
queue.push(dependency);
}
}
}
function expandSharedDestructuredDeclarators(ast, refsByGroup, sharedBindings) {
for (const statement of ast.program.body) {
const declaration = t.isExportNamedDeclaration(statement) && statement.declaration ? statement.declaration : statement;
if (!t.isVariableDeclaration(declaration)) continue;
for (const declarator of declaration.declarations) {
if (!t.isObjectPattern(declarator.id) && !t.isArrayPattern(declarator.id)) continue;
const names = collectIdentifiersFromPattern(declarator.id);
const usedGroups = /* @__PURE__ */ new Set();
for (const name of names) {
const groups = refsByGroup.get(name);
if (!groups) continue;
for (const group of groups) usedGroups.add(group);
}
if (usedGroups.size >= 2) for (const name of names) sharedBindings.add(name);
}
}
}
function expandDestructuredDeclarations(ast, bindings) {
for (const statement of ast.program.body) {
const declaration = t.isExportNamedDeclaration(statement) && statement.declaration ? statement.declaration : statement;
if (!t.isVariableDeclaration(declaration)) continue;
for (const declarator of declaration.declarations) {
if (!t.isObjectPattern(declarator.id) && !t.isArrayPattern(declarator.id)) continue;
const names = collectIdentifiersFromPattern(declarator.id);
if (names.some((name) => bindings.has(name))) for (const name of names) bindings.add(name);
}
}
}
function removeBindingsTransitivelyDependingOn(bindings, dependencyGraph, roots) {
const reverseGraph = /* @__PURE__ */ new Map();
for (const [name, dependencies] of dependencyGraph) for (const dependency of dependencies) {
let parents = reverseGraph.get(dependency);
if (!parents) {
parents = /* @__PURE__ */ new Set();
reverseGraph.set(dependency, parents);
}
parents.add(name);
}
const visited = /* @__PURE__ */ new Set();
const queue = [...roots];
while (queue.length > 0) {
const current = queue.pop();
if (visited.has(current)) continue;
visited.add(current);
const parents = reverseGraph.get(current);
if (!parents) continue;
for (const parent of parents) if (!visited.has(parent)) queue.push(parent);
}
for (const name of [...bindings]) if (visited.has(name)) bindings.delete(name);
}
function removeModuleLevelBindings(ast, namesToRemove) {
ast.program.body = ast.program.body.filter((statement) => {
const declaration = t.isExportNamedDeclaration(statement) && statement.declaration ? statement.declaration : statement;
if (t.isVariableDeclaration(declaration)) {
declaration.declarations = declaration.declarations.filter((declarator) => !collectIdentifiersFromPattern(declarator.id).some((name) => namesToRemove.has(name)));
return declaration.declarations.length > 0;
}
if (t.isFunctionDeclaration(declaration) && declaration.id) return !namesToRemove.has(declaration.id.name);
if (t.isClassDeclaration(declaration) && declaration.id) return !namesToRemove.has(declaration.id.name);
if (t.isExportDefaultDeclaration(statement)) {
const defaultDeclaration = statement.declaration;
if ((t.isFunctionDeclaration(defaultDeclaration) || t.isClassDeclaration(defaultDeclaration)) && defaultDeclaration.id) return !namesToRemove.has(defaultDeclaration.id.name);
}
return true;
});
}
function retainModuleLevelDeclarations(ast, bindingsToKeep) {
ast.program.body = ast.program.body.filter((statement) => {
if (t.isImportDeclaration(statement)) return true;
const declaration = t.isExportNamedDeclaration(statement) && statement.declaration ? statement.declaration : statement;
if (t.isVariableDeclaration(declaration)) {
declaration.declarations = declaration.declarations.filter((declarator) => collectIdentifiersFromPattern(declarator.id).some((name) => bindingsToKeep.has(name)));
return declaration.declarations.length > 0;
}
if (t.isFunctionDeclaration(declaration) && declaration.id) return bindingsToKeep.has(declaration.id.name);
if (t.isClassDeclaration(declaration) && declaration.id) return bindingsToKeep.has(declaration.id.name);
return false;
});
}
function unwrapExportedDeclarations(ast) {
const body = [];
for (const statement of ast.program.body) {
if (t.isExportNamedDeclaration(statement)) {
if (statement.declaration) body.push(statement.declaration);
continue;
}
if (t.isExportDefaultDeclaration(statement)) {
const declaration = statement.declaration;
if ((t.isFunctionDeclaration(declaration) || t.isClassDeclaration(declaration)) && declaration.id) body.push(declaration);
continue;
}
if (t.isExportAllDeclaration(statement)) continue;
body.push(statement);
}
ast.program.body = body;
}
function stripUnreferencedTopLevelExpressionStatements(ast) {
const locallyBound = /* @__PURE__ */ new Set();
for (const statement of ast.program.body) collectLocalBindingsFromStatement(statement, locallyBound);
ast.program.body = ast.program.body.filter((statement) => {
if (!t.isExpressionStatement(statement)) return true;
for (const name of collectIdentifiersFromNode(statement)) if (locallyBound.has(name)) return true;
return false;
});
}
//#endregion
export { buildDeclarationMap, buildDependencyGraph, collectIdentifiersFromNode, collectIdentifiersFromPattern, collectLocalBindingsFromStatement, collectModuleLevelRefsFromNode, expandDestructuredDeclarations, expandSharedDestructuredDeclarators, expandTransitively, extractModuleInfoFromAst, removeBindingsTransitivelyDependingOn, removeModuleLevelBindings, retainModuleLevelDeclarations, stripUnreferencedTopLevelExpressionStatements, unwrapExportedDeclarations };
//# sourceMappingURL=compiler-helpers.js.map
{"version":3,"file":"compiler-helpers.js","names":[],"sources":["../../src/compiler-helpers.ts"],"sourcesContent":["import * as t from '@babel/types'\n\ntype IdentifierScopeFrame = {\n kind: 'program' | 'function' | 'block'\n bindings: Set<string>\n}\ntype IdentifierScopeStack = Array<IdentifierScopeFrame>\n\nexport type ModuleInfoBinding =\n | {\n type: 'import'\n source: string\n importedName: string\n }\n | {\n type: 'var'\n init: t.Expression | null\n }\n\nexport interface ExtractedModuleInfo {\n bindings: Map<string, ModuleInfoBinding>\n exports: Map<string, string>\n reExportAllSources: Array<string>\n}\n\nfunction getModuleExportName(node: t.Identifier | t.StringLiteral) {\n return t.isIdentifier(node) ? node.name : node.value\n}\n\nfunction addVariableDeclarationModuleInfo(\n declaration: t.VariableDeclaration,\n bindings: Map<string, ModuleInfoBinding>,\n exportMap?: Map<string, string>,\n) {\n for (const declarator of declaration.declarations) {\n for (const name of collectIdentifiersFromPattern(declarator.id)) {\n bindings.set(name, {\n type: 'var',\n init: declarator.init ?? null,\n })\n exportMap?.set(name, name)\n }\n }\n}\n\nfunction addDeclarationModuleInfo(\n declaration: t.Declaration,\n bindings: Map<string, ModuleInfoBinding>,\n exportMap?: Map<string, string>,\n) {\n if (t.isVariableDeclaration(declaration)) {\n addVariableDeclarationModuleInfo(declaration, bindings, exportMap)\n return\n }\n\n if (\n (t.isFunctionDeclaration(declaration) ||\n t.isClassDeclaration(declaration)) &&\n declaration.id\n ) {\n bindings.set(declaration.id.name, {\n type: 'var',\n init: null,\n })\n exportMap?.set(declaration.id.name, declaration.id.name)\n }\n}\n\nfunction hasIdentifierBinding(scopes: IdentifierScopeStack, name: string) {\n for (let i = scopes.length - 1; i >= 0; i--) {\n if (scopes[i]!.bindings.has(name)) {\n return true\n }\n }\n return false\n}\n\nfunction currentIdentifierScope(scopes: IdentifierScopeStack) {\n return scopes[scopes.length - 1]!\n}\n\nfunction nearestFunctionIdentifierScope(scopes: IdentifierScopeStack) {\n for (let i = scopes.length - 1; i >= 0; i--) {\n const scope = scopes[i]!\n if (scope.kind === 'function' || scope.kind === 'program') {\n return scope\n }\n }\n return currentIdentifierScope(scopes)\n}\n\nfunction addIdentifierPatternBindings(\n pattern: t.LVal | t.Node | null | undefined,\n scope: IdentifierScopeFrame,\n) {\n for (const name of collectIdentifiersFromPattern(pattern)) {\n scope.bindings.add(name)\n }\n}\n\nfunction addIdentifierDeclarationBindings(\n declaration: t.Node,\n scopes: IdentifierScopeStack,\n) {\n if (t.isVariableDeclaration(declaration)) {\n const scope =\n declaration.kind === 'var'\n ? nearestFunctionIdentifierScope(scopes)\n : currentIdentifierScope(scopes)\n for (const declarator of declaration.declarations) {\n addIdentifierPatternBindings(declarator.id, scope)\n }\n return\n }\n\n if (\n (t.isFunctionDeclaration(declaration) ||\n t.isClassDeclaration(declaration) ||\n t.isTSTypeAliasDeclaration(declaration) ||\n t.isTSInterfaceDeclaration(declaration) ||\n t.isTSEnumDeclaration(declaration)) &&\n declaration.id\n ) {\n currentIdentifierScope(scopes).bindings.add(declaration.id.name)\n }\n}\n\nfunction addIdentifierImportBindings(\n node: t.ImportDeclaration,\n scope: IdentifierScopeFrame,\n) {\n for (const specifier of node.specifiers) {\n scope.bindings.add(specifier.local.name)\n }\n}\n\nfunction createNestedIdentifierScope(\n kind: IdentifierScopeFrame['kind'],\n scopes: IdentifierScopeStack,\n): IdentifierScopeStack {\n return [...scopes, { kind, bindings: new Set() }]\n}\n\nfunction addIdentifierBlockBindings(\n body: Array<t.Node>,\n scopes: IdentifierScopeStack,\n) {\n for (const statement of body) {\n if (t.isImportDeclaration(statement)) {\n addIdentifierImportBindings(statement, currentIdentifierScope(scopes))\n } else if (t.isExportNamedDeclaration(statement) && statement.declaration) {\n addIdentifierDeclarationBindings(statement.declaration, scopes)\n } else {\n addIdentifierDeclarationBindings(statement, scopes)\n }\n }\n}\n\nfunction walkIdentifierChildren(\n current: t.Node,\n parent: t.Node | undefined,\n scopes: IdentifierScopeStack,\n ids: Set<string>,\n) {\n for (const key of t.VISITOR_KEYS[current.type] ?? []) {\n const child = (current as any)[key]\n if (Array.isArray(child)) {\n for (const item of child) {\n if (item && typeof item.type === 'string') {\n walkIdentifierNode(item, current, parent, key, scopes, ids)\n }\n }\n } else if (child && typeof child.type === 'string') {\n walkIdentifierNode(child, current, parent, key, scopes, ids)\n }\n }\n}\n\nfunction walkIdentifierNode(\n current: t.Node | null | undefined,\n parent: t.Node | undefined,\n grandparent: t.Node | undefined,\n parentKey: string | undefined,\n scopes: IdentifierScopeStack,\n ids: Set<string>,\n) {\n if (!current) return\n\n if (t.isIdentifier(current)) {\n if (\n (!parent || t.isReferenced(current, parent, grandparent)) &&\n !hasIdentifierBinding(scopes, current.name)\n ) {\n ids.add(current.name)\n }\n return\n }\n\n if (t.isJSXIdentifier(current)) {\n if (parent && t.isJSXAttribute(parent) && parentKey === 'name') {\n return\n }\n\n if (parent && t.isJSXMemberExpression(parent) && parentKey === 'property') {\n return\n }\n\n const first = current.name[0]\n if (first && first === first.toLowerCase()) {\n return\n }\n\n if (!hasIdentifierBinding(scopes, current.name)) {\n ids.add(current.name)\n }\n return\n }\n\n if (t.isProgram(current)) {\n const nestedScopes = createNestedIdentifierScope('program', scopes)\n addIdentifierBlockBindings(current.body, nestedScopes)\n for (const child of current.body) {\n walkIdentifierNode(child, current, parent, 'body', nestedScopes, ids)\n }\n return\n }\n\n if (t.isBlockStatement(current)) {\n const nestedScopes = createNestedIdentifierScope('block', scopes)\n addIdentifierBlockBindings(current.body, nestedScopes)\n for (const child of current.body) {\n walkIdentifierNode(child, current, parent, 'body', nestedScopes, ids)\n }\n return\n }\n\n if (\n t.isFunctionDeclaration(current) ||\n t.isFunctionExpression(current) ||\n t.isArrowFunctionExpression(current) ||\n t.isObjectMethod(current) ||\n t.isClassMethod(current) ||\n t.isClassPrivateMethod(current)\n ) {\n if (t.isFunctionDeclaration(current) && current.id) {\n currentIdentifierScope(scopes).bindings.add(current.id.name)\n }\n\n const nestedScopes = createNestedIdentifierScope('function', scopes)\n if (\n (t.isFunctionDeclaration(current) || t.isFunctionExpression(current)) &&\n current.id\n ) {\n currentIdentifierScope(nestedScopes).bindings.add(current.id.name)\n }\n for (const param of current.params) {\n addIdentifierPatternBindings(param, currentIdentifierScope(nestedScopes))\n }\n\n walkIdentifierChildren(current, parent, nestedScopes, ids)\n return\n }\n\n if (t.isCatchClause(current)) {\n const nestedScopes = createNestedIdentifierScope('block', scopes)\n addIdentifierPatternBindings(\n current.param,\n currentIdentifierScope(nestedScopes),\n )\n walkIdentifierNode(\n current.param,\n current,\n parent,\n 'param',\n nestedScopes,\n ids,\n )\n walkIdentifierNode(current.body, current, parent, 'body', nestedScopes, ids)\n return\n }\n\n if (t.isImportDeclaration(current)) {\n addIdentifierImportBindings(current, currentIdentifierScope(scopes))\n return\n }\n\n if (t.isClassDeclaration(current) || t.isClassExpression(current)) {\n if (t.isClassDeclaration(current) && current.id) {\n currentIdentifierScope(scopes).bindings.add(current.id.name)\n }\n\n const nestedScopes = current.id\n ? createNestedIdentifierScope('block', scopes)\n : scopes\n if (current.id) {\n currentIdentifierScope(nestedScopes).bindings.add(current.id.name)\n }\n\n walkIdentifierChildren(current, parent, nestedScopes, ids)\n return\n }\n\n if (t.isVariableDeclaration(current)) {\n addIdentifierDeclarationBindings(current, scopes)\n } else if (t.isVariableDeclarator(current)) {\n const scope =\n parent && t.isVariableDeclaration(parent) && parent.kind === 'var'\n ? nearestFunctionIdentifierScope(scopes)\n : currentIdentifierScope(scopes)\n addIdentifierPatternBindings(current.id, scope)\n } else if (\n t.isTSTypeAliasDeclaration(current) ||\n t.isTSInterfaceDeclaration(current) ||\n t.isTSEnumDeclaration(current)\n ) {\n currentIdentifierScope(scopes).bindings.add(current.id.name)\n }\n\n walkIdentifierChildren(current, parent, scopes, ids)\n}\n\n/**\n * Recursively walk an AST node and collect referenced identifier-like names.\n * This avoids Babel path/scope allocation for module-level dependency scans.\n */\nexport function collectIdentifiersFromNode(node: t.Node): Set<string> {\n const ids = new Set<string>()\n walkIdentifierNode(\n node,\n undefined,\n undefined,\n undefined,\n [{ kind: 'program', bindings: new Set() }],\n ids,\n )\n return ids\n}\n\nexport function collectIdentifiersFromPattern(\n node: t.LVal | t.Node | null | undefined,\n): Array<string> {\n if (!node) {\n return []\n }\n\n if (t.isIdentifier(node)) {\n return [node.name]\n }\n\n if (t.isAssignmentPattern(node)) {\n return collectIdentifiersFromPattern(node.left)\n }\n\n if (t.isRestElement(node)) {\n return collectIdentifiersFromPattern(node.argument)\n }\n\n if (t.isObjectPattern(node)) {\n return node.properties.flatMap((prop) => {\n if (t.isObjectProperty(prop)) {\n return collectIdentifiersFromPattern(prop.value as t.LVal)\n }\n if (t.isRestElement(prop)) {\n return collectIdentifiersFromPattern(prop.argument)\n }\n return []\n })\n }\n\n if (t.isArrayPattern(node)) {\n return node.elements.flatMap((element) =>\n collectIdentifiersFromPattern(element),\n )\n }\n\n return []\n}\n\nexport function collectLocalBindingsFromStatement(\n node: t.Statement | t.ModuleDeclaration,\n bindings: Set<string>,\n) {\n const declaration =\n t.isExportNamedDeclaration(node) && node.declaration\n ? node.declaration\n : t.isExportDefaultDeclaration(node)\n ? node.declaration\n : node\n\n if (t.isVariableDeclaration(declaration)) {\n for (const declarator of declaration.declarations) {\n for (const name of collectIdentifiersFromPattern(declarator.id)) {\n bindings.add(name)\n }\n }\n } else if (t.isFunctionDeclaration(declaration) && declaration.id) {\n bindings.add(declaration.id.name)\n } else if (t.isClassDeclaration(declaration) && declaration.id) {\n bindings.add(declaration.id.name)\n }\n}\n\nexport function extractModuleInfoFromAst(ast: t.File): ExtractedModuleInfo {\n const bindings = new Map<string, ModuleInfoBinding>()\n const exportMap = new Map<string, string>()\n const reExportAllSources: Array<string> = []\n\n for (const node of ast.program.body) {\n if (t.isImportDeclaration(node)) {\n const source = node.source.value\n for (const specifier of node.specifiers) {\n if (t.isImportSpecifier(specifier)) {\n bindings.set(specifier.local.name, {\n type: 'import',\n source,\n importedName: getModuleExportName(specifier.imported),\n })\n } else if (t.isImportDefaultSpecifier(specifier)) {\n bindings.set(specifier.local.name, {\n type: 'import',\n source,\n importedName: 'default',\n })\n } else if (t.isImportNamespaceSpecifier(specifier)) {\n bindings.set(specifier.local.name, {\n type: 'import',\n source,\n importedName: '*',\n })\n }\n }\n continue\n }\n\n if (t.isVariableDeclaration(node)) {\n addVariableDeclarationModuleInfo(node, bindings)\n continue\n }\n\n if (t.isFunctionDeclaration(node) || t.isClassDeclaration(node)) {\n addDeclarationModuleInfo(node, bindings)\n continue\n }\n\n if (t.isExportNamedDeclaration(node)) {\n if (node.declaration) {\n addDeclarationModuleInfo(node.declaration, bindings, exportMap)\n }\n\n for (const specifier of node.specifiers) {\n if (t.isExportNamespaceSpecifier(specifier)) {\n const exported = getModuleExportName(specifier.exported)\n exportMap.set(exported, exported)\n if (node.source) {\n bindings.set(exported, {\n type: 'import',\n source: node.source.value,\n importedName: '*',\n })\n }\n } else if (t.isExportSpecifier(specifier)) {\n const local = getModuleExportName(specifier.local)\n const exported = getModuleExportName(specifier.exported)\n exportMap.set(exported, local)\n\n if (node.source) {\n bindings.set(local, {\n type: 'import',\n source: node.source.value,\n importedName: local,\n })\n }\n }\n }\n continue\n }\n\n if (t.isExportDefaultDeclaration(node)) {\n const declaration = node.declaration\n if (t.isIdentifier(declaration)) {\n exportMap.set('default', declaration.name)\n } else if (\n (t.isFunctionDeclaration(declaration) ||\n t.isClassDeclaration(declaration)) &&\n declaration.id\n ) {\n bindings.set(declaration.id.name, {\n type: 'var',\n init: null,\n })\n exportMap.set('default', declaration.id.name)\n } else {\n const synth = '__default_export__'\n bindings.set(synth, {\n type: 'var',\n init: t.isExpression(declaration) ? declaration : null,\n })\n exportMap.set('default', synth)\n }\n continue\n }\n\n if (t.isExportAllDeclaration(node)) {\n reExportAllSources.push(node.source.value)\n }\n }\n\n return {\n bindings,\n exports: exportMap,\n reExportAllSources,\n }\n}\n\nexport function buildDeclarationMap(ast: t.File): Map<string, t.Node> {\n const map = new Map<string, t.Node>()\n\n for (const statement of ast.program.body) {\n const declaration =\n t.isExportNamedDeclaration(statement) && statement.declaration\n ? statement.declaration\n : t.isExportDefaultDeclaration(statement)\n ? statement.declaration\n : statement\n\n if (t.isVariableDeclaration(declaration)) {\n for (const declarator of declaration.declarations) {\n for (const name of collectIdentifiersFromPattern(declarator.id)) {\n map.set(name, declarator)\n }\n }\n } else if (t.isFunctionDeclaration(declaration) && declaration.id) {\n map.set(declaration.id.name, declaration)\n } else if (t.isClassDeclaration(declaration) && declaration.id) {\n map.set(declaration.id.name, declaration)\n }\n }\n\n return map\n}\n\nexport function buildDependencyGraph(\n declarationMap: Map<string, t.Node>,\n localBindings: Set<string>,\n): Map<string, Set<string>> {\n const graph = new Map<string, Set<string>>()\n\n for (const [name, declarationNode] of declarationMap) {\n if (!localBindings.has(name)) continue\n\n const dependencies = new Set<string>()\n for (const id of collectIdentifiersFromNode(declarationNode)) {\n if (id !== name && localBindings.has(id)) {\n dependencies.add(id)\n }\n }\n graph.set(name, dependencies)\n }\n\n return graph\n}\n\nexport function collectModuleLevelRefsFromNode(\n node: t.Node,\n localModuleLevelBindings: Set<string>,\n): Set<string> {\n const refs = new Set<string>()\n\n for (const name of collectIdentifiersFromNode(node)) {\n if (localModuleLevelBindings.has(name)) {\n refs.add(name)\n }\n }\n\n return refs\n}\n\nexport function expandTransitively(\n bindings: Set<string>,\n dependencyGraph: Map<string, Set<string>>,\n) {\n const queue = [...bindings]\n const visited = new Set<string>()\n\n while (queue.length > 0) {\n const name = queue.pop()!\n if (visited.has(name)) continue\n visited.add(name)\n\n const dependencies = dependencyGraph.get(name)\n if (!dependencies) continue\n\n for (const dependency of dependencies) {\n if (!bindings.has(dependency)) {\n bindings.add(dependency)\n queue.push(dependency)\n }\n }\n }\n}\n\nexport function expandSharedDestructuredDeclarators(\n ast: t.File,\n refsByGroup: Map<string, Set<number>>,\n sharedBindings: Set<string>,\n) {\n for (const statement of ast.program.body) {\n const declaration =\n t.isExportNamedDeclaration(statement) && statement.declaration\n ? statement.declaration\n : statement\n\n if (!t.isVariableDeclaration(declaration)) continue\n\n for (const declarator of declaration.declarations) {\n if (\n !t.isObjectPattern(declarator.id) &&\n !t.isArrayPattern(declarator.id)\n ) {\n continue\n }\n\n const names = collectIdentifiersFromPattern(declarator.id)\n const usedGroups = new Set<number>()\n\n for (const name of names) {\n const groups = refsByGroup.get(name)\n if (!groups) continue\n for (const group of groups) {\n usedGroups.add(group)\n }\n }\n\n if (usedGroups.size >= 2) {\n for (const name of names) {\n sharedBindings.add(name)\n }\n }\n }\n }\n}\n\nexport function expandDestructuredDeclarations(\n ast: t.File,\n bindings: Set<string>,\n) {\n for (const statement of ast.program.body) {\n const declaration =\n t.isExportNamedDeclaration(statement) && statement.declaration\n ? statement.declaration\n : statement\n\n if (!t.isVariableDeclaration(declaration)) continue\n\n for (const declarator of declaration.declarations) {\n if (\n !t.isObjectPattern(declarator.id) &&\n !t.isArrayPattern(declarator.id)\n ) {\n continue\n }\n\n const names = collectIdentifiersFromPattern(declarator.id)\n if (names.some((name) => bindings.has(name))) {\n for (const name of names) {\n bindings.add(name)\n }\n }\n }\n }\n}\n\nexport function removeBindingsTransitivelyDependingOn(\n bindings: Set<string>,\n dependencyGraph: Map<string, Set<string>>,\n roots: Iterable<string>,\n) {\n const reverseGraph = new Map<string, Set<string>>()\n\n for (const [name, dependencies] of dependencyGraph) {\n for (const dependency of dependencies) {\n let parents = reverseGraph.get(dependency)\n if (!parents) {\n parents = new Set()\n reverseGraph.set(dependency, parents)\n }\n parents.add(name)\n }\n }\n\n const visited = new Set<string>()\n const queue = [...roots]\n\n while (queue.length > 0) {\n const current = queue.pop()!\n if (visited.has(current)) continue\n visited.add(current)\n\n const parents = reverseGraph.get(current)\n if (!parents) continue\n\n for (const parent of parents) {\n if (!visited.has(parent)) {\n queue.push(parent)\n }\n }\n }\n\n for (const name of [...bindings]) {\n if (visited.has(name)) {\n bindings.delete(name)\n }\n }\n}\n\nexport function removeModuleLevelBindings(\n ast: t.File,\n namesToRemove: Set<string>,\n) {\n ast.program.body = ast.program.body.filter((statement) => {\n const declaration =\n t.isExportNamedDeclaration(statement) && statement.declaration\n ? statement.declaration\n : statement\n\n if (t.isVariableDeclaration(declaration)) {\n declaration.declarations = declaration.declarations.filter(\n (declarator) =>\n !collectIdentifiersFromPattern(declarator.id).some((name) =>\n namesToRemove.has(name),\n ),\n )\n return declaration.declarations.length > 0\n }\n\n if (t.isFunctionDeclaration(declaration) && declaration.id) {\n return !namesToRemove.has(declaration.id.name)\n }\n\n if (t.isClassDeclaration(declaration) && declaration.id) {\n return !namesToRemove.has(declaration.id.name)\n }\n\n if (t.isExportDefaultDeclaration(statement)) {\n const defaultDeclaration = statement.declaration\n if (\n (t.isFunctionDeclaration(defaultDeclaration) ||\n t.isClassDeclaration(defaultDeclaration)) &&\n defaultDeclaration.id\n ) {\n return !namesToRemove.has(defaultDeclaration.id.name)\n }\n }\n\n return true\n })\n}\n\nexport function retainModuleLevelDeclarations(\n ast: t.File,\n bindingsToKeep: Set<string>,\n) {\n ast.program.body = ast.program.body.filter((statement) => {\n if (t.isImportDeclaration(statement)) return true\n\n const declaration =\n t.isExportNamedDeclaration(statement) && statement.declaration\n ? statement.declaration\n : statement\n\n if (t.isVariableDeclaration(declaration)) {\n declaration.declarations = declaration.declarations.filter((declarator) =>\n collectIdentifiersFromPattern(declarator.id).some((name) =>\n bindingsToKeep.has(name),\n ),\n )\n return declaration.declarations.length > 0\n }\n\n if (t.isFunctionDeclaration(declaration) && declaration.id) {\n return bindingsToKeep.has(declaration.id.name)\n }\n\n if (t.isClassDeclaration(declaration) && declaration.id) {\n return bindingsToKeep.has(declaration.id.name)\n }\n\n return false\n })\n}\n\nexport function unwrapExportedDeclarations(ast: t.File) {\n const body: Array<t.Statement | t.ModuleDeclaration> = []\n\n for (const statement of ast.program.body) {\n if (t.isExportNamedDeclaration(statement)) {\n if (statement.declaration) {\n body.push(statement.declaration)\n }\n continue\n }\n\n if (t.isExportDefaultDeclaration(statement)) {\n const declaration = statement.declaration\n if (\n (t.isFunctionDeclaration(declaration) ||\n t.isClassDeclaration(declaration)) &&\n declaration.id\n ) {\n body.push(declaration)\n }\n continue\n }\n\n if (t.isExportAllDeclaration(statement)) {\n continue\n }\n\n body.push(statement)\n }\n\n ast.program.body = body\n}\n\nexport function stripUnreferencedTopLevelExpressionStatements(ast: t.File) {\n const locallyBound = new Set<string>()\n\n for (const statement of ast.program.body) {\n collectLocalBindingsFromStatement(statement, locallyBound)\n }\n\n ast.program.body = ast.program.body.filter((statement) => {\n if (!t.isExpressionStatement(statement)) return true\n\n for (const name of collectIdentifiersFromNode(statement)) {\n if (locallyBound.has(name)) {\n return true\n }\n }\n\n return false\n })\n}\n"],"mappings":";;AAyBA,SAAS,oBAAoB,MAAsC;AACjE,QAAO,EAAE,aAAa,KAAK,GAAG,KAAK,OAAO,KAAK;;AAGjD,SAAS,iCACP,aACA,UACA,WACA;AACA,MAAK,MAAM,cAAc,YAAY,aACnC,MAAK,MAAM,QAAQ,8BAA8B,WAAW,GAAG,EAAE;AAC/D,WAAS,IAAI,MAAM;GACjB,MAAM;GACN,MAAM,WAAW,QAAQ;GAC1B,CAAC;AACF,aAAW,IAAI,MAAM,KAAK;;;AAKhC,SAAS,yBACP,aACA,UACA,WACA;AACA,KAAI,EAAE,sBAAsB,YAAY,EAAE;AACxC,mCAAiC,aAAa,UAAU,UAAU;AAClE;;AAGF,MACG,EAAE,sBAAsB,YAAY,IACnC,EAAE,mBAAmB,YAAY,KACnC,YAAY,IACZ;AACA,WAAS,IAAI,YAAY,GAAG,MAAM;GAChC,MAAM;GACN,MAAM;GACP,CAAC;AACF,aAAW,IAAI,YAAY,GAAG,MAAM,YAAY,GAAG,KAAK;;;AAI5D,SAAS,qBAAqB,QAA8B,MAAc;AACxE,MAAK,IAAI,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,IACtC,KAAI,OAAO,GAAI,SAAS,IAAI,KAAK,CAC/B,QAAO;AAGX,QAAO;;AAGT,SAAS,uBAAuB,QAA8B;AAC5D,QAAO,OAAO,OAAO,SAAS;;AAGhC,SAAS,+BAA+B,QAA8B;AACpE,MAAK,IAAI,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,KAAK;EAC3C,MAAM,QAAQ,OAAO;AACrB,MAAI,MAAM,SAAS,cAAc,MAAM,SAAS,UAC9C,QAAO;;AAGX,QAAO,uBAAuB,OAAO;;AAGvC,SAAS,6BACP,SACA,OACA;AACA,MAAK,MAAM,QAAQ,8BAA8B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2BAA2B,UAAU,CACtD,KAAI,aAAa,IAAI,KAAK,CACxB,QAAO;AAIX,SAAO;GACP"}
export declare function createIdentifier(strings: Array<string>): string;
export declare function decodeIdentifier(identifier: string): Array<string>;
//#region src/path-ids.ts
function createIdentifier(strings) {
if (strings.length === 0) throw new Error("Cannot create an identifier from an empty array");
let safeString = [...strings].sort().join("---").replace(/\//g, "--slash--");
safeString = safeString.replace(/\\/g, "--backslash--");
safeString = safeString.replace(/\?/g, "--question--");
safeString = safeString.replace(/%/g, "--percent--");
safeString = safeString.replace(/#/g, "--hash--");
safeString = safeString.replace(/\+/g, "--plus--");
safeString = safeString.replace(/=/g, "--equals--");
safeString = safeString.replace(/&/g, "--ampersand--");
safeString = safeString.replace(/\s/g, "_");
return safeString;
}
function decodeIdentifier(identifier) {
if (!identifier) return [];
let combinedString = identifier.replace(/--slash--/g, "/");
combinedString = combinedString.replace(/--backslash--/g, "\\");
combinedString = combinedString.replace(/--question--/g, "?");
combinedString = combinedString.replace(/--percent--/g, "%");
combinedString = combinedString.replace(/--hash--/g, "#");
combinedString = combinedString.replace(/--plus--/g, "+");
combinedString = combinedString.replace(/--equals--/g, "=");
combinedString = combinedString.replace(/--ampersand--/g, "&");
combinedString = combinedString.replace(/_/g, " ");
return combinedString.split("---");
}
//#endregion
export { createIdentifier, decodeIdentifier };
//# sourceMappingURL=path-ids.js.map
{"version":3,"file":"path-ids.js","names":[],"sources":["../../src/path-ids.ts"],"sourcesContent":["export function createIdentifier(strings: Array<string>): string {\n if (strings.length === 0) {\n throw new Error('Cannot create an identifier from an empty array')\n }\n\n const sortedStrings = [...strings].sort()\n const combinedString = sortedStrings.join('---') // Delimiter\n\n // Replace unsafe characters\n let safeString = combinedString.replace(/\\//g, '--slash--')\n safeString = safeString.replace(/\\\\/g, '--backslash--')\n safeString = safeString.replace(/\\?/g, '--question--')\n safeString = safeString.replace(/%/g, '--percent--')\n safeString = safeString.replace(/#/g, '--hash--')\n safeString = safeString.replace(/\\+/g, '--plus--')\n safeString = safeString.replace(/=/g, '--equals--')\n safeString = safeString.replace(/&/g, '--ampersand--')\n safeString = safeString.replace(/\\s/g, '_') // Replace spaces with underscores\n\n return safeString\n}\n\nexport function decodeIdentifier(identifier: string): Array<string> {\n if (!identifier) {\n return []\n }\n\n let combinedString = identifier.replace(/--slash--/g, '/')\n combinedString = combinedString.replace(/--backslash--/g, '\\\\')\n combinedString = combinedString.replace(/--question--/g, '?')\n combinedString = combinedString.replace(/--percent--/g, '%')\n combinedString = combinedString.replace(/--hash--/g, '#')\n combinedString = combinedString.replace(/--plus--/g, '+')\n combinedString = combinedString.replace(/--equals--/g, '=')\n combinedString = combinedString.replace(/--ampersand--/g, '&')\n combinedString = combinedString.replace(/_/g, ' ') // Restore spaces\n\n return combinedString.split('---')\n}\n"],"mappings":";AAAA,SAAgB,iBAAiB,SAAgC;AAC/D,KAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MAAM,kDAAkD;CAOpE,IAAI,aAJkB,CAAC,GAAG,QAAQ,CAAC,MAAM,CACJ,KAAK,MAAM,CAGhB,QAAQ,OAAO,YAAY;AAC3D,cAAa,WAAW,QAAQ,OAAO,gBAAgB;AACvD,cAAa,WAAW,QAAQ,OAAO,eAAe;AACtD,cAAa,WAAW,QAAQ,MAAM,cAAc;AACpD,cAAa,WAAW,QAAQ,MAAM,WAAW;AACjD,cAAa,WAAW,QAAQ,OAAO,WAAW;AAClD,cAAa,WAAW,QAAQ,MAAM,aAAa;AACnD,cAAa,WAAW,QAAQ,MAAM,gBAAgB;AACtD,cAAa,WAAW,QAAQ,OAAO,IAAI;AAE3C,QAAO;;AAGT,SAAgB,iBAAiB,YAAmC;AAClE,KAAI,CAAC,WACH,QAAO,EAAE;CAGX,IAAI,iBAAiB,WAAW,QAAQ,cAAc,IAAI;AAC1D,kBAAiB,eAAe,QAAQ,kBAAkB,KAAK;AAC/D,kBAAiB,eAAe,QAAQ,iBAAiB,IAAI;AAC7D,kBAAiB,eAAe,QAAQ,gBAAgB,IAAI;AAC5D,kBAAiB,eAAe,QAAQ,aAAa,IAAI;AACzD,kBAAiB,eAAe,QAAQ,aAAa,IAAI;AACzD,kBAAiB,eAAe,QAAQ,eAAe,IAAI;AAC3D,kBAAiB,eAAe,QAAQ,kBAAkB,IAAI;AAC9D,kBAAiB,eAAe,QAAQ,MAAM,IAAI;AAElD,QAAO,eAAe,MAAM,MAAM"}
import * as t from '@babel/types'
type IdentifierScopeFrame = {
kind: 'program' | 'function' | 'block'
bindings: Set<string>
}
type IdentifierScopeStack = Array<IdentifierScopeFrame>
export type ModuleInfoBinding =
| {
type: 'import'
source: string
importedName: string
}
| {
type: 'var'
init: t.Expression | null
}
export interface ExtractedModuleInfo {
bindings: Map<string, ModuleInfoBinding>
exports: Map<string, string>
reExportAllSources: Array<string>
}
function getModuleExportName(node: t.Identifier | t.StringLiteral) {
return t.isIdentifier(node) ? node.name : node.value
}
function addVariableDeclarationModuleInfo(
declaration: t.VariableDeclaration,
bindings: Map<string, ModuleInfoBinding>,
exportMap?: Map<string, string>,
) {
for (const declarator of declaration.declarations) {
for (const name of collectIdentifiersFromPattern(declarator.id)) {
bindings.set(name, {
type: 'var',
init: declarator.init ?? null,
})
exportMap?.set(name, name)
}
}
}
function addDeclarationModuleInfo(
declaration: t.Declaration,
bindings: Map<string, ModuleInfoBinding>,
exportMap?: Map<string, string>,
) {
if (t.isVariableDeclaration(declaration)) {
addVariableDeclarationModuleInfo(declaration, bindings, exportMap)
return
}
if (
(t.isFunctionDeclaration(declaration) ||
t.isClassDeclaration(declaration)) &&
declaration.id
) {
bindings.set(declaration.id.name, {
type: 'var',
init: null,
})
exportMap?.set(declaration.id.name, declaration.id.name)
}
}
function hasIdentifierBinding(scopes: IdentifierScopeStack, name: string) {
for (let i = scopes.length - 1; i >= 0; i--) {
if (scopes[i]!.bindings.has(name)) {
return true
}
}
return false
}
function currentIdentifierScope(scopes: IdentifierScopeStack) {
return scopes[scopes.length - 1]!
}
function nearestFunctionIdentifierScope(scopes: IdentifierScopeStack) {
for (let i = scopes.length - 1; i >= 0; i--) {
const scope = scopes[i]!
if (scope.kind === 'function' || scope.kind === 'program') {
return scope
}
}
return currentIdentifierScope(scopes)
}
function addIdentifierPatternBindings(
pattern: t.LVal | t.Node | null | undefined,
scope: IdentifierScopeFrame,
) {
for (const name of collectIdentifiersFromPattern(pattern)) {
scope.bindings.add(name)
}
}
function addIdentifierDeclarationBindings(
declaration: t.Node,
scopes: IdentifierScopeStack,
) {
if (t.isVariableDeclaration(declaration)) {
const scope =
declaration.kind === 'var'
? nearestFunctionIdentifierScope(scopes)
: currentIdentifierScope(scopes)
for (const declarator of declaration.declarations) {
addIdentifierPatternBindings(declarator.id, scope)
}
return
}
if (
(t.isFunctionDeclaration(declaration) ||
t.isClassDeclaration(declaration) ||
t.isTSTypeAliasDeclaration(declaration) ||
t.isTSInterfaceDeclaration(declaration) ||
t.isTSEnumDeclaration(declaration)) &&
declaration.id
) {
currentIdentifierScope(scopes).bindings.add(declaration.id.name)
}
}
function addIdentifierImportBindings(
node: t.ImportDeclaration,
scope: IdentifierScopeFrame,
) {
for (const specifier of node.specifiers) {
scope.bindings.add(specifier.local.name)
}
}
function createNestedIdentifierScope(
kind: IdentifierScopeFrame['kind'],
scopes: IdentifierScopeStack,
): IdentifierScopeStack {
return [...scopes, { kind, bindings: new Set() }]
}
function addIdentifierBlockBindings(
body: Array<t.Node>,
scopes: IdentifierScopeStack,
) {
for (const statement of body) {
if (t.isImportDeclaration(statement)) {
addIdentifierImportBindings(statement, currentIdentifierScope(scopes))
} else if (t.isExportNamedDeclaration(statement) && statement.declaration) {
addIdentifierDeclarationBindings(statement.declaration, scopes)
} else {
addIdentifierDeclarationBindings(statement, scopes)
}
}
}
function walkIdentifierChildren(
current: t.Node,
parent: t.Node | undefined,
scopes: IdentifierScopeStack,
ids: Set<string>,
) {
for (const key of t.VISITOR_KEYS[current.type] ?? []) {
const child = (current as any)[key]
if (Array.isArray(child)) {
for (const item of child) {
if (item && typeof item.type === 'string') {
walkIdentifierNode(item, current, parent, key, scopes, ids)
}
}
} else if (child && typeof child.type === 'string') {
walkIdentifierNode(child, current, parent, key, scopes, ids)
}
}
}
function walkIdentifierNode(
current: t.Node | null | undefined,
parent: t.Node | undefined,
grandparent: t.Node | undefined,
parentKey: string | undefined,
scopes: IdentifierScopeStack,
ids: Set<string>,
) {
if (!current) return
if (t.isIdentifier(current)) {
if (
(!parent || t.isReferenced(current, parent, grandparent)) &&
!hasIdentifierBinding(scopes, current.name)
) {
ids.add(current.name)
}
return
}
if (t.isJSXIdentifier(current)) {
if (parent && t.isJSXAttribute(parent) && parentKey === 'name') {
return
}
if (parent && t.isJSXMemberExpression(parent) && parentKey === 'property') {
return
}
const first = current.name[0]
if (first && first === first.toLowerCase()) {
return
}
if (!hasIdentifierBinding(scopes, current.name)) {
ids.add(current.name)
}
return
}
if (t.isProgram(current)) {
const nestedScopes = createNestedIdentifierScope('program', scopes)
addIdentifierBlockBindings(current.body, nestedScopes)
for (const child of current.body) {
walkIdentifierNode(child, current, parent, 'body', nestedScopes, ids)
}
return
}
if (t.isBlockStatement(current)) {
const nestedScopes = createNestedIdentifierScope('block', scopes)
addIdentifierBlockBindings(current.body, nestedScopes)
for (const child of current.body) {
walkIdentifierNode(child, current, parent, 'body', nestedScopes, ids)
}
return
}
if (
t.isFunctionDeclaration(current) ||
t.isFunctionExpression(current) ||
t.isArrowFunctionExpression(current) ||
t.isObjectMethod(current) ||
t.isClassMethod(current) ||
t.isClassPrivateMethod(current)
) {
if (t.isFunctionDeclaration(current) && current.id) {
currentIdentifierScope(scopes).bindings.add(current.id.name)
}
const nestedScopes = createNestedIdentifierScope('function', scopes)
if (
(t.isFunctionDeclaration(current) || t.isFunctionExpression(current)) &&
current.id
) {
currentIdentifierScope(nestedScopes).bindings.add(current.id.name)
}
for (const param of current.params) {
addIdentifierPatternBindings(param, currentIdentifierScope(nestedScopes))
}
walkIdentifierChildren(current, parent, nestedScopes, ids)
return
}
if (t.isCatchClause(current)) {
const nestedScopes = createNestedIdentifierScope('block', scopes)
addIdentifierPatternBindings(
current.param,
currentIdentifierScope(nestedScopes),
)
walkIdentifierNode(
current.param,
current,
parent,
'param',
nestedScopes,
ids,
)
walkIdentifierNode(current.body, current, parent, 'body', nestedScopes, ids)
return
}
if (t.isImportDeclaration(current)) {
addIdentifierImportBindings(current, currentIdentifierScope(scopes))
return
}
if (t.isClassDeclaration(current) || t.isClassExpression(current)) {
if (t.isClassDeclaration(current) && current.id) {
currentIdentifierScope(scopes).bindings.add(current.id.name)
}
const nestedScopes = current.id
? createNestedIdentifierScope('block', scopes)
: scopes
if (current.id) {
currentIdentifierScope(nestedScopes).bindings.add(current.id.name)
}
walkIdentifierChildren(current, parent, nestedScopes, ids)
return
}
if (t.isVariableDeclaration(current)) {
addIdentifierDeclarationBindings(current, scopes)
} else if (t.isVariableDeclarator(current)) {
const scope =
parent && t.isVariableDeclaration(parent) && parent.kind === 'var'
? nearestFunctionIdentifierScope(scopes)
: currentIdentifierScope(scopes)
addIdentifierPatternBindings(current.id, scope)
} else if (
t.isTSTypeAliasDeclaration(current) ||
t.isTSInterfaceDeclaration(current) ||
t.isTSEnumDeclaration(current)
) {
currentIdentifierScope(scopes).bindings.add(current.id.name)
}
walkIdentifierChildren(current, parent, scopes, ids)
}
/**
* Recursively walk an AST node and collect referenced identifier-like names.
* This avoids Babel path/scope allocation for module-level dependency scans.
*/
export function collectIdentifiersFromNode(node: t.Node): Set<string> {
const ids = new Set<string>()
walkIdentifierNode(
node,
undefined,
undefined,
undefined,
[{ kind: 'program', bindings: new Set() }],
ids,
)
return ids
}
export function collectIdentifiersFromPattern(
node: t.LVal | t.Node | null | undefined,
): Array<string> {
if (!node) {
return []
}
if (t.isIdentifier(node)) {
return [node.name]
}
if (t.isAssignmentPattern(node)) {
return collectIdentifiersFromPattern(node.left)
}
if (t.isRestElement(node)) {
return collectIdentifiersFromPattern(node.argument)
}
if (t.isObjectPattern(node)) {
return node.properties.flatMap((prop) => {
if (t.isObjectProperty(prop)) {
return collectIdentifiersFromPattern(prop.value as t.LVal)
}
if (t.isRestElement(prop)) {
return collectIdentifiersFromPattern(prop.argument)
}
return []
})
}
if (t.isArrayPattern(node)) {
return node.elements.flatMap((element) =>
collectIdentifiersFromPattern(element),
)
}
return []
}
export function collectLocalBindingsFromStatement(
node: t.Statement | t.ModuleDeclaration,
bindings: Set<string>,
) {
const declaration =
t.isExportNamedDeclaration(node) && node.declaration
? node.declaration
: t.isExportDefaultDeclaration(node)
? node.declaration
: node
if (t.isVariableDeclaration(declaration)) {
for (const declarator of declaration.declarations) {
for (const name of collectIdentifiersFromPattern(declarator.id)) {
bindings.add(name)
}
}
} else if (t.isFunctionDeclaration(declaration) && declaration.id) {
bindings.add(declaration.id.name)
} else if (t.isClassDeclaration(declaration) && declaration.id) {
bindings.add(declaration.id.name)
}
}
export function extractModuleInfoFromAst(ast: t.File): ExtractedModuleInfo {
const bindings = new Map<string, ModuleInfoBinding>()
const exportMap = new Map<string, string>()
const reExportAllSources: Array<string> = []
for (const node of ast.program.body) {
if (t.isImportDeclaration(node)) {
const source = node.source.value
for (const specifier of node.specifiers) {
if (t.isImportSpecifier(specifier)) {
bindings.set(specifier.local.name, {
type: 'import',
source,
importedName: getModuleExportName(specifier.imported),
})
} else if (t.isImportDefaultSpecifier(specifier)) {
bindings.set(specifier.local.name, {
type: 'import',
source,
importedName: 'default',
})
} else if (t.isImportNamespaceSpecifier(specifier)) {
bindings.set(specifier.local.name, {
type: 'import',
source,
importedName: '*',
})
}
}
continue
}
if (t.isVariableDeclaration(node)) {
addVariableDeclarationModuleInfo(node, bindings)
continue
}
if (t.isFunctionDeclaration(node) || t.isClassDeclaration(node)) {
addDeclarationModuleInfo(node, bindings)
continue
}
if (t.isExportNamedDeclaration(node)) {
if (node.declaration) {
addDeclarationModuleInfo(node.declaration, bindings, exportMap)
}
for (const specifier of node.specifiers) {
if (t.isExportNamespaceSpecifier(specifier)) {
const exported = getModuleExportName(specifier.exported)
exportMap.set(exported, exported)
if (node.source) {
bindings.set(exported, {
type: 'import',
source: node.source.value,
importedName: '*',
})
}
} else if (t.isExportSpecifier(specifier)) {
const local = getModuleExportName(specifier.local)
const exported = getModuleExportName(specifier.exported)
exportMap.set(exported, local)
if (node.source) {
bindings.set(local, {
type: 'import',
source: node.source.value,
importedName: local,
})
}
}
}
continue
}
if (t.isExportDefaultDeclaration(node)) {
const declaration = node.declaration
if (t.isIdentifier(declaration)) {
exportMap.set('default', declaration.name)
} else if (
(t.isFunctionDeclaration(declaration) ||
t.isClassDeclaration(declaration)) &&
declaration.id
) {
bindings.set(declaration.id.name, {
type: 'var',
init: null,
})
exportMap.set('default', declaration.id.name)
} else {
const synth = '__default_export__'
bindings.set(synth, {
type: 'var',
init: t.isExpression(declaration) ? declaration : null,
})
exportMap.set('default', synth)
}
continue
}
if (t.isExportAllDeclaration(node)) {
reExportAllSources.push(node.source.value)
}
}
return {
bindings,
exports: exportMap,
reExportAllSources,
}
}
export function buildDeclarationMap(ast: t.File): Map<string, t.Node> {
const map = new Map<string, t.Node>()
for (const statement of ast.program.body) {
const declaration =
t.isExportNamedDeclaration(statement) && statement.declaration
? statement.declaration
: t.isExportDefaultDeclaration(statement)
? statement.declaration
: statement
if (t.isVariableDeclaration(declaration)) {
for (const declarator of declaration.declarations) {
for (const name of collectIdentifiersFromPattern(declarator.id)) {
map.set(name, declarator)
}
}
} else if (t.isFunctionDeclaration(declaration) && declaration.id) {
map.set(declaration.id.name, declaration)
} else if (t.isClassDeclaration(declaration) && declaration.id) {
map.set(declaration.id.name, declaration)
}
}
return map
}
export function buildDependencyGraph(
declarationMap: Map<string, t.Node>,
localBindings: Set<string>,
): Map<string, Set<string>> {
const graph = new Map<string, Set<string>>()
for (const [name, declarationNode] of declarationMap) {
if (!localBindings.has(name)) continue
const dependencies = new Set<string>()
for (const id of collectIdentifiersFromNode(declarationNode)) {
if (id !== name && localBindings.has(id)) {
dependencies.add(id)
}
}
graph.set(name, dependencies)
}
return graph
}
export function collectModuleLevelRefsFromNode(
node: t.Node,
localModuleLevelBindings: Set<string>,
): Set<string> {
const refs = new Set<string>()
for (const name of collectIdentifiersFromNode(node)) {
if (localModuleLevelBindings.has(name)) {
refs.add(name)
}
}
return refs
}
export function expandTransitively(
bindings: Set<string>,
dependencyGraph: Map<string, Set<string>>,
) {
const queue = [...bindings]
const visited = new Set<string>()
while (queue.length > 0) {
const name = queue.pop()!
if (visited.has(name)) continue
visited.add(name)
const dependencies = dependencyGraph.get(name)
if (!dependencies) continue
for (const dependency of dependencies) {
if (!bindings.has(dependency)) {
bindings.add(dependency)
queue.push(dependency)
}
}
}
}
export function expandSharedDestructuredDeclarators(
ast: t.File,
refsByGroup: Map<string, Set<number>>,
sharedBindings: Set<string>,
) {
for (const statement of ast.program.body) {
const declaration =
t.isExportNamedDeclaration(statement) && statement.declaration
? statement.declaration
: statement
if (!t.isVariableDeclaration(declaration)) continue
for (const declarator of declaration.declarations) {
if (
!t.isObjectPattern(declarator.id) &&
!t.isArrayPattern(declarator.id)
) {
continue
}
const names = collectIdentifiersFromPattern(declarator.id)
const usedGroups = new Set<number>()
for (const name of names) {
const groups = refsByGroup.get(name)
if (!groups) continue
for (const group of groups) {
usedGroups.add(group)
}
}
if (usedGroups.size >= 2) {
for (const name of names) {
sharedBindings.add(name)
}
}
}
}
}
export function expandDestructuredDeclarations(
ast: t.File,
bindings: Set<string>,
) {
for (const statement of ast.program.body) {
const declaration =
t.isExportNamedDeclaration(statement) && statement.declaration
? statement.declaration
: statement
if (!t.isVariableDeclaration(declaration)) continue
for (const declarator of declaration.declarations) {
if (
!t.isObjectPattern(declarator.id) &&
!t.isArrayPattern(declarator.id)
) {
continue
}
const names = collectIdentifiersFromPattern(declarator.id)
if (names.some((name) => bindings.has(name))) {
for (const name of names) {
bindings.add(name)
}
}
}
}
}
export function removeBindingsTransitivelyDependingOn(
bindings: Set<string>,
dependencyGraph: Map<string, Set<string>>,
roots: Iterable<string>,
) {
const reverseGraph = new Map<string, Set<string>>()
for (const [name, dependencies] of dependencyGraph) {
for (const dependency of dependencies) {
let parents = reverseGraph.get(dependency)
if (!parents) {
parents = new Set()
reverseGraph.set(dependency, parents)
}
parents.add(name)
}
}
const visited = new Set<string>()
const queue = [...roots]
while (queue.length > 0) {
const current = queue.pop()!
if (visited.has(current)) continue
visited.add(current)
const parents = reverseGraph.get(current)
if (!parents) continue
for (const parent of parents) {
if (!visited.has(parent)) {
queue.push(parent)
}
}
}
for (const name of [...bindings]) {
if (visited.has(name)) {
bindings.delete(name)
}
}
}
export function removeModuleLevelBindings(
ast: t.File,
namesToRemove: Set<string>,
) {
ast.program.body = ast.program.body.filter((statement) => {
const declaration =
t.isExportNamedDeclaration(statement) && statement.declaration
? statement.declaration
: statement
if (t.isVariableDeclaration(declaration)) {
declaration.declarations = declaration.declarations.filter(
(declarator) =>
!collectIdentifiersFromPattern(declarator.id).some((name) =>
namesToRemove.has(name),
),
)
return declaration.declarations.length > 0
}
if (t.isFunctionDeclaration(declaration) && declaration.id) {
return !namesToRemove.has(declaration.id.name)
}
if (t.isClassDeclaration(declaration) && declaration.id) {
return !namesToRemove.has(declaration.id.name)
}
if (t.isExportDefaultDeclaration(statement)) {
const defaultDeclaration = statement.declaration
if (
(t.isFunctionDeclaration(defaultDeclaration) ||
t.isClassDeclaration(defaultDeclaration)) &&
defaultDeclaration.id
) {
return !namesToRemove.has(defaultDeclaration.id.name)
}
}
return true
})
}
export function retainModuleLevelDeclarations(
ast: t.File,
bindingsToKeep: Set<string>,
) {
ast.program.body = ast.program.body.filter((statement) => {
if (t.isImportDeclaration(statement)) return true
const declaration =
t.isExportNamedDeclaration(statement) && statement.declaration
? statement.declaration
: statement
if (t.isVariableDeclaration(declaration)) {
declaration.declarations = declaration.declarations.filter((declarator) =>
collectIdentifiersFromPattern(declarator.id).some((name) =>
bindingsToKeep.has(name),
),
)
return declaration.declarations.length > 0
}
if (t.isFunctionDeclaration(declaration) && declaration.id) {
return bindingsToKeep.has(declaration.id.name)
}
if (t.isClassDeclaration(declaration) && declaration.id) {
return bindingsToKeep.has(declaration.id.name)
}
return false
})
}
export function unwrapExportedDeclarations(ast: t.File) {
const body: Array<t.Statement | t.ModuleDeclaration> = []
for (const statement of ast.program.body) {
if (t.isExportNamedDeclaration(statement)) {
if (statement.declaration) {
body.push(statement.declaration)
}
continue
}
if (t.isExportDefaultDeclaration(statement)) {
const declaration = statement.declaration
if (
(t.isFunctionDeclaration(declaration) ||
t.isClassDeclaration(declaration)) &&
declaration.id
) {
body.push(declaration)
}
continue
}
if (t.isExportAllDeclaration(statement)) {
continue
}
body.push(statement)
}
ast.program.body = body
}
export function stripUnreferencedTopLevelExpressionStatements(ast: t.File) {
const locallyBound = new Set<string>()
for (const statement of ast.program.body) {
collectLocalBindingsFromStatement(statement, locallyBound)
}
ast.program.body = ast.program.body.filter((statement) => {
if (!t.isExpressionStatement(statement)) return true
for (const name of collectIdentifiersFromNode(statement)) {
if (locallyBound.has(name)) {
return true
}
}
return false
})
}
export function createIdentifier(strings: Array<string>): string {
if (strings.length === 0) {
throw new Error('Cannot create an identifier from an empty array')
}
const sortedStrings = [...strings].sort()
const combinedString = sortedStrings.join('---') // Delimiter
// Replace unsafe characters
let safeString = combinedString.replace(/\//g, '--slash--')
safeString = safeString.replace(/\\/g, '--backslash--')
safeString = safeString.replace(/\?/g, '--question--')
safeString = safeString.replace(/%/g, '--percent--')
safeString = safeString.replace(/#/g, '--hash--')
safeString = safeString.replace(/\+/g, '--plus--')
safeString = safeString.replace(/=/g, '--equals--')
safeString = safeString.replace(/&/g, '--ampersand--')
safeString = safeString.replace(/\s/g, '_') // Replace spaces with underscores
return safeString
}
export function decodeIdentifier(identifier: string): Array<string> {
if (!identifier) {
return []
}
let combinedString = identifier.replace(/--slash--/g, '/')
combinedString = combinedString.replace(/--backslash--/g, '\\')
combinedString = combinedString.replace(/--question--/g, '?')
combinedString = combinedString.replace(/--percent--/g, '%')
combinedString = combinedString.replace(/--hash--/g, '#')
combinedString = combinedString.replace(/--plus--/g, '+')
combinedString = combinedString.replace(/--equals--/g, '=')
combinedString = combinedString.replace(/--ampersand--/g, '&')
combinedString = combinedString.replace(/_/g, ' ') // Restore spaces
return combinedString.split('---')
}
+19
-0

@@ -6,5 +6,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });

const require_copy_files_plugin = require("./copy-files-plugin.cjs");
const require_path_ids = require("./path-ids.cjs");
const require_compiler_helpers = require("./compiler-helpers.cjs");
let babel_dead_code_elimination = require("babel-dead-code-elimination");
exports.buildDeclarationMap = require_compiler_helpers.buildDeclarationMap;
exports.buildDependencyGraph = require_compiler_helpers.buildDependencyGraph;
exports.collectIdentifiersFromNode = require_compiler_helpers.collectIdentifiersFromNode;
exports.collectIdentifiersFromPattern = require_compiler_helpers.collectIdentifiersFromPattern;
exports.collectLocalBindingsFromStatement = require_compiler_helpers.collectLocalBindingsFromStatement;
exports.collectModuleLevelRefsFromNode = require_compiler_helpers.collectModuleLevelRefsFromNode;
exports.copyFilesPlugin = require_copy_files_plugin.copyFilesPlugin;
exports.createIdentifier = require_path_ids.createIdentifier;
exports.deadCodeElimination = require_ast.deadCodeElimination;
exports.decodeIdentifier = require_path_ids.decodeIdentifier;
exports.expandDestructuredDeclarations = require_compiler_helpers.expandDestructuredDeclarations;
exports.expandSharedDestructuredDeclarators = require_compiler_helpers.expandSharedDestructuredDeclarators;
exports.expandTransitively = require_compiler_helpers.expandTransitively;
exports.extractModuleInfoFromAst = require_compiler_helpers.extractModuleInfoFromAst;
exports.findReferencedIdentifiers = babel_dead_code_elimination.findReferencedIdentifiers;

@@ -14,2 +28,7 @@ exports.generateFromAst = require_ast.generateFromAst;

exports.parseAst = require_ast.parseAst;
exports.removeBindingsTransitivelyDependingOn = require_compiler_helpers.removeBindingsTransitivelyDependingOn;
exports.removeModuleLevelBindings = require_compiler_helpers.removeModuleLevelBindings;
exports.retainModuleLevelDeclarations = require_compiler_helpers.retainModuleLevelDeclarations;
exports.stripTypeExports = require_ast.stripTypeExports;
exports.stripUnreferencedTopLevelExpressionStatements = require_compiler_helpers.stripUnreferencedTopLevelExpressionStatements;
exports.unwrapExportedDeclarations = require_compiler_helpers.unwrapExportedDeclarations;
+3
-0

@@ -5,1 +5,4 @@ export { parseAst, generateFromAst, deadCodeElimination, findReferencedIdentifiers, stripTypeExports, } from './ast.cjs';

export { copyFilesPlugin } from './copy-files-plugin.cjs';
export { createIdentifier, decodeIdentifier } from './path-ids.cjs';
export { buildDeclarationMap, buildDependencyGraph, collectIdentifiersFromNode, collectIdentifiersFromPattern, collectLocalBindingsFromStatement, collectModuleLevelRefsFromNode, expandDestructuredDeclarations, expandSharedDestructuredDeclarators, expandTransitively, extractModuleInfoFromAst, removeBindingsTransitivelyDependingOn, removeModuleLevelBindings, retainModuleLevelDeclarations, stripUnreferencedTopLevelExpressionStatements, unwrapExportedDeclarations, } from './compiler-helpers.cjs';
export type { ExtractedModuleInfo, ModuleInfoBinding } from './compiler-helpers.cjs';

@@ -5,1 +5,4 @@ export { parseAst, generateFromAst, deadCodeElimination, findReferencedIdentifiers, stripTypeExports, } from './ast.js';

export { copyFilesPlugin } from './copy-files-plugin.js';
export { createIdentifier, decodeIdentifier } from './path-ids.js';
export { buildDeclarationMap, buildDependencyGraph, collectIdentifiersFromNode, collectIdentifiersFromPattern, collectLocalBindingsFromStatement, collectModuleLevelRefsFromNode, expandDestructuredDeclarations, expandSharedDestructuredDeclarators, expandTransitively, extractModuleInfoFromAst, removeBindingsTransitivelyDependingOn, removeModuleLevelBindings, retainModuleLevelDeclarations, stripUnreferencedTopLevelExpressionStatements, unwrapExportedDeclarations, } from './compiler-helpers.js';
export type { ExtractedModuleInfo, ModuleInfoBinding } from './compiler-helpers.js';
+3
-1
import { deadCodeElimination, findReferencedIdentifiers, generateFromAst, parseAst, stripTypeExports } from "./ast.js";
import { logDiff } from "./logger.js";
import { copyFilesPlugin } from "./copy-files-plugin.js";
export { copyFilesPlugin, deadCodeElimination, findReferencedIdentifiers, generateFromAst, logDiff, parseAst, stripTypeExports };
import { createIdentifier, decodeIdentifier } from "./path-ids.js";
import { buildDeclarationMap, buildDependencyGraph, collectIdentifiersFromNode, collectIdentifiersFromPattern, collectLocalBindingsFromStatement, collectModuleLevelRefsFromNode, expandDestructuredDeclarations, expandSharedDestructuredDeclarators, expandTransitively, extractModuleInfoFromAst, removeBindingsTransitivelyDependingOn, removeModuleLevelBindings, retainModuleLevelDeclarations, stripUnreferencedTopLevelExpressionStatements, unwrapExportedDeclarations } from "./compiler-helpers.js";
export { buildDeclarationMap, buildDependencyGraph, collectIdentifiersFromNode, collectIdentifiersFromPattern, collectLocalBindingsFromStatement, collectModuleLevelRefsFromNode, copyFilesPlugin, createIdentifier, deadCodeElimination, decodeIdentifier, expandDestructuredDeclarations, expandSharedDestructuredDeclarators, expandTransitively, extractModuleInfoFromAst, findReferencedIdentifiers, generateFromAst, logDiff, parseAst, removeBindingsTransitivelyDependingOn, removeModuleLevelBindings, retainModuleLevelDeclarations, stripTypeExports, stripUnreferencedTopLevelExpressionStatements, unwrapExportedDeclarations };
{
"name": "@tanstack/router-utils",
"version": "1.162.0",
"version": "1.162.1",
"description": "Modern and scalable routing for React applications",

@@ -5,0 +5,0 @@ "author": "Tanner Linsley",

@@ -12,1 +12,22 @@ export {

export { copyFilesPlugin } from './copy-files-plugin'
export { createIdentifier, decodeIdentifier } from './path-ids'
export {
buildDeclarationMap,
buildDependencyGraph,
collectIdentifiersFromNode,
collectIdentifiersFromPattern,
collectLocalBindingsFromStatement,
collectModuleLevelRefsFromNode,
expandDestructuredDeclarations,
expandSharedDestructuredDeclarators,
expandTransitively,
extractModuleInfoFromAst,
removeBindingsTransitivelyDependingOn,
removeModuleLevelBindings,
retainModuleLevelDeclarations,
stripUnreferencedTopLevelExpressionStatements,
unwrapExportedDeclarations,
} from './compiler-helpers'
export type { ExtractedModuleInfo, ModuleInfoBinding } from './compiler-helpers'