@@ -7,29 +7,29 @@ import { type BinaryNode } from './types'
77const indexCache = new WeakMap < BinaryNode , Map < string , BinaryNode [ ] > > ( )
88
99export const getBinaryNodeChildren = ( node : BinaryNode | undefined , childTag : string ) => {
10- if ( ! node || ! Array . isArray ( node . content ) ) return [ ]
10+ if ( ! node || ! Array . isArray ( node . content ) ) return [ ]
1111
12- let index = indexCache . get ( node )
12+ let index = indexCache . get ( node )
1313
14- // Build the index once per node
15- if ( ! index ) {
16- index = new Map < string , BinaryNode [ ] > ( )
14+ // Build the index once per node
15+ if ( ! index ) {
16+ index = new Map < string , BinaryNode [ ] > ( )
1717
18- for ( const child of node . content ) {
19- let arr = index . get ( child . tag )
20- if ( ! arr ) index . set ( child . tag , ( arr = [ ] ) )
21- arr . push ( child )
22- }
18+ for ( const child of node . content ) {
19+ let arr = index . get ( child . tag )
20+ if ( ! arr ) index . set ( child . tag , ( arr = [ ] ) )
21+ arr . push ( child )
22+ }
2323
24- indexCache . set ( node , index )
25- }
24+ indexCache . set ( node , index )
25+ }
2626
27- // Return first matching child
28- return index . get ( childTag ) || [ ]
27+ // Return first matching child
28+ return index . get ( childTag ) || [ ]
2929}
3030
3131export const getBinaryNodeChild = ( node : BinaryNode | undefined , childTag : string ) => {
32- return getBinaryNodeChildren ( node , childTag ) [ 0 ]
32+ return getBinaryNodeChildren ( node , childTag ) [ 0 ]
3333}
3434
3535export const getAllBinaryNodeChildren = ( { content } : BinaryNode ) => {
0 commit comments