File tree 3 files changed +28
-40
lines changed
3 files changed +28
-40
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 3
3
* @typedef {import('./index.js').State } State
4
4
*/
5
5
6
- import { all } from './all .js'
6
+ import { all } from './one .js'
7
7
import { name } from './name.js'
8
8
import { value } from './value.js'
9
9
Original file line number Diff line number Diff line change 1
1
/**
2
+ * @typedef {import('unist').Parent } UnistParent
2
3
* @typedef {import('xast').Root } Root
3
4
* @typedef {import('xast').RootChildMap } RootChildMap
4
5
* @typedef {import('./index.js').State } State
5
6
*/
6
7
7
8
/**
8
9
* @typedef {Root | RootChildMap[keyof RootChildMap] } Node
10
+ * @typedef {Extract<Node, UnistParent> } Parent
11
+ * @typedef {Parent['children'][number] } Child
9
12
*/
10
13
11
- import { all } from './all.js'
12
14
import { element } from './element.js'
13
15
import { text } from './text.js'
14
16
import { comment } from './comment.js'
@@ -57,3 +59,27 @@ export function one(node, state) {
57
59
58
60
return result
59
61
}
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
+ }
You can’t perform that action at this time.
0 commit comments