@mintlify/common
Version:
Commonly shared code within Mintlify
33 lines (32 loc) • 1.24 kB
JavaScript
import { visit } from 'unist-util-visit';
import { nodeIncludesExport } from '../snippets/index.js';
import { isExportNode } from '../utils.js';
export const findExportedNodes = (tree, ...type) => {
const exports = [];
visit(tree, 'mdxjsEsm', (node) => {
var _a;
if (!nodeIncludesExport(node))
return;
const body = node.data.estree.body;
for (const bodyChild of body) {
if (isExportNode(bodyChild)) {
if (bodyChild.type === 'ExportAllDeclaration')
continue;
if (((_a = bodyChild.declaration) === null || _a === void 0 ? void 0 : _a.type) !== 'VariableDeclaration')
continue;
const declaration = bodyChild.declaration.declarations[0];
if (declaration == undefined)
continue;
const init = declaration.init;
if (init == null)
continue;
if (!type.includes(init.type))
continue;
if (declaration.id.type !== 'Identifier')
continue;
exports.push(declaration.id.name);
}
}
});
return exports;
};