Skip to content
Source
Sign inSign up

mdast-util-to-hast@13.2.1.patch

44 lines1.2 KB

1diff --git a/lib/state.js b/lib/state.js
2index 0d9c9df..1279783 100644
3--- a/lib/state.js
4+++ b/lib/state.js
5@@ -176,7 +176,6 @@
6 */
7
8 import structuredClone from '@ungap/structured-clone'
9-import {visit} from 'unist-util-visit'
10 import {position} from 'unist-util-position'
11 import {handlers as defaultHandlers} from './handlers/index.js'
13@@ -223,7 +222,16 @@ export function createState(tree, options) {
14 wrap
15 }
17- visit(tree, function (node) {
18+ // A plain walk in the same order: `visit` costs more than the rest of this setup.
19+ collectDefinitions(tree)
21+ return state
23+ /**
24+ * @param {MdastNodes} node
25+ * @returns {undefined}
26+ */
27+ function collectDefinitions(node) {
28 if (node.type === 'definition' || node.type === 'footnoteDefinition') {
29 const map = node.type === 'definition' ? definitionById : footnoteById
30 const id = String(node.identifier).toUpperCase()
31@@ -235,9 +243,11 @@ export function createState(tree, options) {
32 map.set(id, node)
33 }
34 }
35- })
37- return state
38+ if ('children' in node) {
39+ for (const child of node.children) collectDefinitions(child)
40+ }
41+ }
43 /**
44 * Transform an mdast node into a hast node.