MCPcopy Create free account
hub / github.com/SyntaxUI/syntaxui / rehypeAddMDXExports

Function rehypeAddMDXExports

src/mdx/rehype.mjs:31–59  ·  view source on GitHub ↗
(getExports)

Source from the content-addressed store, hash-verified

29}
30
31function rehypeAddMDXExports(getExports) {
32 return (tree) => {
33 let exports = Object.entries(getExports(tree))
34
35 for (let [name, value] of exports) {
36 for (let node of tree.children) {
37 if (
38 node.type === 'mdxjsEsm' &&
39 new RegExp(`export\\s+const\\s+${name}\\s*=`).test(node.value)
40 ) {
41 return
42 }
43 }
44
45 let exportStr = `export const ${name} = ${value}`
46
47 tree.children.push({
48 type: 'mdxjsEsm',
49 value: exportStr,
50 data: {
51 estree: acorn.parse(exportStr, {
52 sourceType: 'module',
53 ecmaVersion: 'latest',
54 }),
55 },
56 })
57 }
58 }
59}
60
61function getSections(node) {
62 let sections = []

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected