1212 * @typedef {import('./types.js').MdastRoot } MdastRoot
1313 */
1414
15- import { hasProperty } from 'hast-util-has-property'
1615// @ts -expect-error: next.
1716import minifyWhitespace from 'rehype-minify-whitespace'
1817import { convert } from 'unist-util-is'
@@ -97,7 +96,16 @@ export function toMdast(tree, options = {}) {
9796 }
9897 )
9998
100- visit ( tree , 'element' , onelement )
99+ visit ( tree , 'element' , ( node ) => {
100+ const id =
101+ node . properties &&
102+ 'id' in node . properties &&
103+ String ( node . properties . id ) . toUpperCase ( )
104+
105+ if ( id && ! own . call ( byId , id ) ) {
106+ byId [ id ] = node
107+ }
108+ } )
101109
102110 minifyWhitespace ( { newlines : options . newlines === true } ) ( tree )
103111
@@ -115,17 +123,6 @@ export function toMdast(tree, options = {}) {
115123
116124 return mdast
117125
118- /** @type {import('unist-util-visit').Visitor<Element> } */
119- function onelement ( node ) {
120- const id =
121- // @ts -expect-error: `hasProperty` just checked it.
122- hasProperty ( node , 'id' ) && String ( node . properties . id ) . toUpperCase ( )
123-
124- if ( id && ! own . call ( byId , id ) ) {
125- byId [ id ] = node
126- }
127- }
128-
129126 /**
130127 * Collapse text nodes, and fix whitespace.
131128 * Most of this is taken care of by `rehype-minify-whitespace`, but
0 commit comments