@@ -37,11 +37,15 @@ import {position} from 'unist-util-position'
3737import { webNamespaces } from 'web-namespaces'
3838import { zwitch } from 'zwitch'
3939
40+ const ns = /** @type {Record<string, string> } */ ( webNamespaces )
41+
4042const own = { } . hasOwnProperty
4143
4244const one = zwitch ( 'type' , {
45+ // @ts -expect-error: hush.
4346 handlers : { root, element, text, comment, doctype} ,
4447 invalid,
48+ // @ts -expect-error: hush.
4549 unknown
4650} )
4751
@@ -65,7 +69,6 @@ function unknown(value) {
6569 */
6670export function toXast ( tree , options ) {
6771 const space = typeof options === 'string' ? options : ( options || { } ) . space
68- // @ts -ignore types are wrong.
6972 return one ( tree , { schema : space === 'svg' ? svg : html , ns : null } )
7073}
7174
@@ -138,7 +141,7 @@ function element(node, parentConfig) {
138141 /** @type {Context } */
139142 const config = Object . assign ( { } , parentConfig , {
140143 schema,
141- ns : webNamespaces [ schema . space ]
144+ ns : schema . space ? ns [ schema . space ] : undefined
142145 } )
143146
144147 if ( parentConfig . ns !== config . ns ) {
@@ -182,7 +185,6 @@ function element(node, parentConfig) {
182185 attributes [ info . attribute ] = value
183186 }
184187
185- // @ts -ignore Assume no `doctypes` in `element.`
186188 return patch (
187189 node ,
188190 /** @type {XastElement } */ ( {
@@ -214,7 +216,7 @@ function all(origin, config) {
214216 }
215217
216218 while ( ++ index < origin . children . length ) {
217- // @ts -ignore `zwitch` types are wrong.
219+ // @ts -expect-error `zwitch` types are wrong.
218220 result [ index ] = one ( origin . children [ index ] , config )
219221 }
220222
0 commit comments