@@ -32,8 +32,11 @@ import {toH} from 'hast-to-hyperscript'
3232import { webNamespaces } from 'web-namespaces'
3333import { zwitch } from 'zwitch'
3434
35+ const ns = /** @type {Record<string, string> } */ ( webNamespaces )
36+
3537const own = { } . hasOwnProperty
3638
39+ // @ts -expect-error: hush.
3740const one = zwitch ( 'type' , { handlers : { root, element, text, comment, doctype} } )
3841
3942/**
@@ -44,7 +47,7 @@ const one = zwitch('type', {handlers: {root, element, text, comment, doctype}})
4447 * @returns {P5Node }
4548 */
4649export function toParse5 ( tree , space ) {
47- // @ts -ignore Types are wrong.
50+ // @ts -expect-error Types are wrong.
4851 return one ( tree , space === 'svg' ? svg : html )
4952}
5053
@@ -60,7 +63,7 @@ function root(node, schema) {
6063 mode : ( node . data || { } ) . quirksMode ? 'quirks' : 'no-quirks' ,
6164 childNodes : [ ]
6265 }
63- // @ts -ignore Assume correct children.
66+ // @ts -expect-error Assume correct children.
6467 p5 . childNodes = all ( node . children , p5 , schema )
6568 return patch ( node , p5 )
6669}
@@ -73,7 +76,7 @@ function root(node, schema) {
7376function fragment ( node , schema ) {
7477 /** @type {P5Fragment } */
7578 const p5 = { nodeName : '#document-fragment' , childNodes : [ ] }
76- // @ts -ignore Assume correct children.
79+ // @ts -expect-error Assume correct children.
7780 p5 . childNodes = all ( node . children , p5 , schema )
7881 return patch ( node , p5 )
7982}
@@ -99,11 +102,15 @@ function doctype(node) {
99102 * @returns {P5Text }
100103 */
101104function text ( node ) {
102- return patch ( node , {
103- nodeName : '#text' ,
104- value : node . value ,
105- parentNode : undefined
106- } )
105+ return patch (
106+ node ,
107+ // @ts -expect-error: no `parentNode`
108+ /** @type {P5Text } */ ( {
109+ nodeName : '#text' ,
110+ value : node . value ,
111+ parentNode : undefined
112+ } )
113+ )
107114}
108115
109116/**
@@ -112,11 +119,15 @@ function text(node) {
112119 * @returns {P5Comment }
113120 */
114121function comment ( node ) {
115- return patch ( node , {
116- nodeName : '#comment' ,
117- data : node . value ,
118- parentNode : undefined
119- } )
122+ return patch (
123+ node ,
124+ // @ts -expect-error: no `parentNode`
125+ /** @type {P5Comment } */ ( {
126+ nodeName : '#comment' ,
127+ data : node . value ,
128+ parentNode : undefined
129+ } )
130+ )
120131}
121132
122133/**
@@ -126,7 +137,7 @@ function comment(node) {
126137 */
127138function element ( node , schema ) {
128139 /** @type {Space } */
129- // @ts -ignore Assume space.
140+ // @ts -expect-error Assume space.
130141 const space = schema . space
131142 return toH ( h , Object . assign ( { } , node , { children : [ ] } ) , { space} )
132143
@@ -167,7 +178,7 @@ function element(node, schema) {
167178 value . prefix = key . slice ( 0 , index )
168179 }
169180
170- value . namespace = webNamespaces [ info . space ]
181+ value . namespace = ns [ info . space ]
171182 }
172183
173184 values . push ( value )
@@ -176,19 +187,24 @@ function element(node, schema) {
176187 if ( schema . space === 'html' && node . tagName === 'svg' ) schema = svg
177188
178189 /** @type {P5Element } */
179- const p5 = patch ( node , {
180- nodeName : name ,
181- tagName : name ,
182- attrs : values ,
183- namespaceURI : webNamespaces [ schema . space ] ,
184- childNodes : [ ] ,
185- parentNode : undefined
186- } )
187-
188- // @ts -ignore Assume correct children.
190+ const p5 = patch (
191+ node ,
192+ // @ts -expect-error: no `parentNode`
193+ /** @type {P5Element } */ ( {
194+ nodeName : name ,
195+ tagName : name ,
196+ attrs : values ,
197+ // @ts -expect-error: html and svg both have a space.
198+ namespaceURI : ns [ schema . space ] ,
199+ childNodes : [ ] ,
200+ parentNode : undefined
201+ } )
202+ )
203+
204+ // @ts -expect-error Assume correct children.
189205 p5 . childNodes = all ( node . children , p5 , schema )
190206
191- // @ts -ignore Types are wrong.
207+ // @ts -expect-error Types are wrong.
192208 if ( name === 'template' ) p5 . content = fragment ( node . content , schema )
193209
194210 return p5
@@ -209,10 +225,10 @@ function all(children, p5, schema) {
209225 if ( children ) {
210226 while ( ++ index < children . length ) {
211227 /** @type {P5Child } */
212- // @ts -ignore Assume child.
228+ // @ts -expect-error Assume child.
213229 const child = one ( children [ index ] , schema )
214230
215- // @ts -ignore types are wrong.
231+ // @ts -expect-error types are wrong.
216232 child . parentNode = p5
217233
218234 result . push ( child )
@@ -234,7 +250,7 @@ function patch(node, p5) {
234250 const position = node . position
235251
236252 if ( position && position . start && position . end ) {
237- // @ts -ignore Types are wrong.
253+ // @ts -expect-error Types are wrong.
238254 p5 . sourceCodeLocation = {
239255 startLine : position . start . line ,
240256 startCol : position . start . column ,
0 commit comments