14
14
* @typedef {import('xast').Doctype } Doctype
15
15
* @typedef {import('xast').Element } Element
16
16
* @typedef {import('xast').Instruction } Instruction
17
+ * @typedef {import('xast').Nodes } Nodes
17
18
* @typedef {import('xast').Root } Root
19
+ * @typedef {import('xast').RootContent } RootContent
18
20
* @typedef {import('xast').Text } Text
19
21
*/
20
22
23
25
* Nodes that occur in XML documents (`parse-xml`).
24
26
* @typedef {XmlContent | XmlDocument } XmlNode
25
27
* Nodes that occur (`parse-xml`).
26
- * @typedef {Cdata | Comment | Doctype | Element | Instruction | Text } Content
27
- * Nodes that occur in documents (`xast`).
28
- * @typedef {Content | Root } Node
29
- * Nodes that occur (`xast`).
30
28
*
31
29
* @typedef State
32
30
* Info passed around.
@@ -47,7 +45,6 @@ import {VFileMessage} from 'vfile-message'
47
45
* xast root.
48
46
*/
49
47
export function fromXml ( value ) {
50
- // @ts -expect-error: to do: update.
51
48
const loc = location ( value )
52
49
/** @type {XmlDocument } */
53
50
let xmlDocument
@@ -68,7 +65,6 @@ export function fromXml(value) {
68
65
} catch ( error_ ) {
69
66
const error = /** @type {XmlError } */ ( error_ )
70
67
const point = loc . toPoint ( error . pos )
71
- // @ts -expect-error: to do: update.
72
68
throw new VFileMessage ( error . message , point , 'xast-util-from-xml:error' )
73
69
}
74
70
@@ -82,7 +78,7 @@ export function fromXml(value) {
82
78
* Transform CDATA.
83
79
*
84
80
* @param {XmlCdata } node
85
- * @returns {Content }
81
+ * @returns {Cdata }
86
82
*/
87
83
function transformCdata ( node ) {
88
84
return { type : 'cdata' , value : node . text }
@@ -93,7 +89,7 @@ function transformCdata(node) {
93
89
*
94
90
* @param {XmlComment } node
95
91
* XML node (`parse-xml`).
96
- * @returns {Content }
92
+ * @returns {Comment }
97
93
* xast node.
98
94
*/
99
95
function transformComment ( node ) {
@@ -120,17 +116,15 @@ function transformDocument(node, state) {
120
116
*
121
117
* @param {XmlDocumentType } node
122
118
* XML node (`parse-xml`).
123
- * @returns {Content }
119
+ * @returns {Doctype }
124
120
* xast node.
125
121
*/
126
122
function transformDoctype ( node ) {
127
123
return {
128
124
type : 'doctype' ,
129
125
name : node . name ,
130
- // @ts -expect-error: `@types/xast` should allow `null`.
131
- public : node . publicId ,
132
- // @ts -expect-error: `@types/xast` should allow `null`.
133
- system : node . systemId
126
+ public : node . publicId || undefined ,
127
+ system : node . systemId || undefined
134
128
}
135
129
}
136
130
@@ -141,7 +135,7 @@ function transformDoctype(node) {
141
135
* XML node (`parse-xml`).
142
136
* @param {State } state
143
137
* Info passed around.
144
- * @returns {Content }
138
+ * @returns {Element }
145
139
* xast node.
146
140
*/
147
141
function transformElement ( node , state ) {
@@ -160,7 +154,7 @@ function transformElement(node, state) {
160
154
*
161
155
* @param {XmlProcessingInstruction } node
162
156
* XML node (`parse-xml`).
163
- * @returns {Content }
157
+ * @returns {Instruction }
164
158
* xast node.
165
159
*/
166
160
function transformInstruction ( node ) {
@@ -172,7 +166,7 @@ function transformInstruction(node) {
172
166
*
173
167
* @param {XmlText } node
174
168
* XML node (`parse-xml`).
175
- * @returns {Content }
169
+ * @returns {Text }
176
170
* xast node.
177
171
*/
178
172
function transformText ( node ) {
@@ -184,7 +178,7 @@ function transformText(node) {
184
178
*
185
179
* @param {XmlDeclaration } node
186
180
* XML node (`parse-xml`).
187
- * @returns {Content }
181
+ * @returns {Instruction }
188
182
* xast node.
189
183
*/
190
184
function transformXmlDeclaration ( node ) {
@@ -222,17 +216,17 @@ function transformXmlDeclaration(node) {
222
216
* Nodes to transform (`parse-xml`).
223
217
* @param {State } state
224
218
* Info passed around.
225
- * @returns {Array<Content > }
219
+ * @returns {Array<RootContent > }
226
220
* xast nodes.
227
221
*/
228
222
function transformChildren ( children , state ) {
229
- /** @type {Array<Content > } */
223
+ /** @type {Array<RootContent > } */
230
224
const results = [ ]
231
225
let index = - 1
232
226
233
227
while ( ++ index < children . length ) {
234
228
const from = children [ index ]
235
- /** @type {Content | undefined } */
229
+ /** @type {RootContent | undefined } */
236
230
let to
237
231
238
232
if ( from . type === 'cdata' ) {
@@ -273,7 +267,7 @@ function transformChildren(children, state) {
273
267
*
274
268
* @param {XmlNode } from
275
269
* XML node (`parse-xml`).
276
- * @param {Node } to
270
+ * @param {Nodes } to
277
271
* xast node.
278
272
* @param {State } state
279
273
* Info passed around.
@@ -292,7 +286,6 @@ function patch(from, to, state) {
292
286
from . end === - 1 ? undefined : state . location . toPoint ( from . end )
293
287
294
288
if ( start && end ) {
295
- // @ts -expect-error: to do: update.
296
289
to . position = { start, end}
297
290
}
298
291
}
0 commit comments