1414 * @typedef {import('xast').Doctype } Doctype
1515 * @typedef {import('xast').Element } Element
1616 * @typedef {import('xast').Instruction } Instruction
17+ * @typedef {import('xast').Nodes } Nodes
1718 * @typedef {import('xast').Root } Root
19+ * @typedef {import('xast').RootContent } RootContent
1820 * @typedef {import('xast').Text } Text
1921 */
2022
2325 * Nodes that occur in XML documents (`parse-xml`).
2426 * @typedef {XmlContent | XmlDocument } XmlNode
2527 * 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`).
3028 *
3129 * @typedef State
3230 * Info passed around.
@@ -47,7 +45,6 @@ import {VFileMessage} from 'vfile-message'
4745 * xast root.
4846 */
4947export function fromXml ( value ) {
50- // @ts -expect-error: to do: update.
5148 const loc = location ( value )
5249 /** @type {XmlDocument } */
5350 let xmlDocument
@@ -68,7 +65,6 @@ export function fromXml(value) {
6865 } catch ( error_ ) {
6966 const error = /** @type {XmlError } */ ( error_ )
7067 const point = loc . toPoint ( error . pos )
71- // @ts -expect-error: to do: update.
7268 throw new VFileMessage ( error . message , point , 'xast-util-from-xml:error' )
7369 }
7470
@@ -82,7 +78,7 @@ export function fromXml(value) {
8278 * Transform CDATA.
8379 *
8480 * @param {XmlCdata } node
85- * @returns {Content }
81+ * @returns {Cdata }
8682 */
8783function transformCdata ( node ) {
8884 return { type : 'cdata' , value : node . text }
@@ -93,7 +89,7 @@ function transformCdata(node) {
9389 *
9490 * @param {XmlComment } node
9591 * XML node (`parse-xml`).
96- * @returns {Content }
92+ * @returns {Comment }
9793 * xast node.
9894 */
9995function transformComment ( node ) {
@@ -120,17 +116,15 @@ function transformDocument(node, state) {
120116 *
121117 * @param {XmlDocumentType } node
122118 * XML node (`parse-xml`).
123- * @returns {Content }
119+ * @returns {Doctype }
124120 * xast node.
125121 */
126122function transformDoctype ( node ) {
127123 return {
128124 type : 'doctype' ,
129125 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
134128 }
135129}
136130
@@ -141,7 +135,7 @@ function transformDoctype(node) {
141135 * XML node (`parse-xml`).
142136 * @param {State } state
143137 * Info passed around.
144- * @returns {Content }
138+ * @returns {Element }
145139 * xast node.
146140 */
147141function transformElement ( node , state ) {
@@ -160,7 +154,7 @@ function transformElement(node, state) {
160154 *
161155 * @param {XmlProcessingInstruction } node
162156 * XML node (`parse-xml`).
163- * @returns {Content }
157+ * @returns {Instruction }
164158 * xast node.
165159 */
166160function transformInstruction ( node ) {
@@ -172,7 +166,7 @@ function transformInstruction(node) {
172166 *
173167 * @param {XmlText } node
174168 * XML node (`parse-xml`).
175- * @returns {Content }
169+ * @returns {Text }
176170 * xast node.
177171 */
178172function transformText ( node ) {
@@ -184,7 +178,7 @@ function transformText(node) {
184178 *
185179 * @param {XmlDeclaration } node
186180 * XML node (`parse-xml`).
187- * @returns {Content }
181+ * @returns {Instruction }
188182 * xast node.
189183 */
190184function transformXmlDeclaration ( node ) {
@@ -222,17 +216,17 @@ function transformXmlDeclaration(node) {
222216 * Nodes to transform (`parse-xml`).
223217 * @param {State } state
224218 * Info passed around.
225- * @returns {Array<Content > }
219+ * @returns {Array<RootContent > }
226220 * xast nodes.
227221 */
228222function transformChildren ( children , state ) {
229- /** @type {Array<Content > } */
223+ /** @type {Array<RootContent > } */
230224 const results = [ ]
231225 let index = - 1
232226
233227 while ( ++ index < children . length ) {
234228 const from = children [ index ]
235- /** @type {Content | undefined } */
229+ /** @type {RootContent | undefined } */
236230 let to
237231
238232 if ( from . type === 'cdata' ) {
@@ -273,7 +267,7 @@ function transformChildren(children, state) {
273267 *
274268 * @param {XmlNode } from
275269 * XML node (`parse-xml`).
276- * @param {Node } to
270+ * @param {Nodes } to
277271 * xast node.
278272 * @param {State } state
279273 * Info passed around.
@@ -292,7 +286,6 @@ function patch(from, to, state) {
292286 from . end === - 1 ? undefined : state . location . toPoint ( from . end )
293287
294288 if ( start && end ) {
295- // @ts -expect-error: to do: update.
296289 to . position = { start, end}
297290 }
298291}
0 commit comments