Skip to content

Commit e7de404

Browse files
committed
Fix Rollup by removing recursion
Closes GH-3.
1 parent 81eaf3a commit e7de404

File tree

3 files changed

+28
-40
lines changed

3 files changed

+28
-40
lines changed

lib/all.js

-38
This file was deleted.

lib/element.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @typedef {import('./index.js').State} State
44
*/
55

6-
import {all} from './all.js'
6+
import {all} from './one.js'
77
import {name} from './name.js'
88
import {value} from './value.js'
99

lib/one.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
/**
2+
* @typedef {import('unist').Parent} UnistParent
23
* @typedef {import('xast').Root} Root
34
* @typedef {import('xast').RootChildMap} RootChildMap
45
* @typedef {import('./index.js').State} State
56
*/
67

78
/**
89
* @typedef {Root | RootChildMap[keyof RootChildMap]} Node
10+
* @typedef {Extract<Node, UnistParent>} Parent
11+
* @typedef {Parent['children'][number]} Child
912
*/
1013

11-
import {all} from './all.js'
1214
import {element} from './element.js'
1315
import {text} from './text.js'
1416
import {comment} from './comment.js'
@@ -57,3 +59,27 @@ export function one(node, state) {
5759

5860
return result
5961
}
62+
63+
/**
64+
* Serialize all children of `parent`.
65+
*
66+
* @param {Parent} parent
67+
* xast parent node.
68+
* @param {State} state
69+
* Info passed around about the current state.
70+
* @returns {string}
71+
* Serialized XML.
72+
*/
73+
export function all(parent, state) {
74+
/** @type {Array<Child>} */
75+
const children = (parent && parent.children) || []
76+
let index = -1
77+
/** @type {Array<string>} */
78+
const results = []
79+
80+
while (++index < children.length) {
81+
results[index] = one(children[index], state)
82+
}
83+
84+
return results.join('')
85+
}

0 commit comments

Comments
 (0)