@@ -21,27 +21,27 @@ const DOCUMENT_FRAGMENT_NODE = 11
2121
2222/**
2323 * @param {Node } node
24- * @returns {HastNode|null }
24+ * @returns {HastNode|undefined }
2525 */
2626function transform ( node ) {
2727 switch ( node . nodeType ) {
2828 case ELEMENT_NODE :
29- // @ts -ignore TypeScript is wrong.
29+ // @ts -expect-error TypeScript is wrong.
3030 return element ( node )
3131 case DOCUMENT_NODE :
3232 case DOCUMENT_FRAGMENT_NODE :
33- // @ts -ignore TypeScript is wrong.
33+ // @ts -expect-error TypeScript is wrong.
3434 return root ( node )
3535 case TEXT_NODE :
36- // @ts -ignore TypeScript is wrong.
36+ // @ts -expect-error TypeScript is wrong.
3737 return text ( node )
3838 case COMMENT_NODE :
39- // @ts -ignore TypeScript is wrong.
39+ // @ts -expect-error TypeScript is wrong.
4040 return comment ( node )
4141 case DOCUMENT_TYPE_NODE :
4242 return doctype ( )
4343 default :
44- return null
44+ return undefined
4545 }
4646}
4747
@@ -61,7 +61,7 @@ function root(node) {
6161 * @returns {HastDoctype }
6262 */
6363function doctype ( ) {
64- // @ts -ignore hast types out of date.
64+ // @ts -expect-error hast types out of date.
6565 return { type : 'doctype' }
6666}
6767
@@ -72,7 +72,7 @@ function doctype() {
7272 * @returns {HastText }
7373 */
7474function text ( node ) {
75- return { type : 'text' , value : node . nodeValue }
75+ return { type : 'text' , value : node . nodeValue || '' }
7676}
7777
7878/**
@@ -82,7 +82,7 @@ function text(node) {
8282 * @returns {HastComment }
8383 */
8484function comment ( node ) {
85- return { type : 'comment' , value : node . nodeValue }
85+ return { type : 'comment' , value : node . nodeValue || '' }
8686}
8787
8888/**
@@ -98,15 +98,15 @@ function element(node) {
9898 space === webNamespaces . html ? node . tagName . toLowerCase ( ) : node . tagName
9999 /** @type {DocumentFragment|Element } */
100100 const content =
101- // @ts -ignore Types are wrong.
101+ // @ts -expect-error Types are wrong.
102102 space === webNamespaces . html && tagName === 'template' ? node . content : node
103103 const attributes = node . getAttributeNames ( )
104104 /** @type {Object.<string, string> } */
105105 const props = { }
106106 let index = - 1
107107
108108 while ( ++ index < attributes . length ) {
109- props [ attributes [ index ] ] = node . getAttribute ( attributes [ index ] )
109+ props [ attributes [ index ] ] = node . getAttribute ( attributes [ index ] ) || ''
110110 }
111111
112112 return fn ( tagName , props , all ( content ) )
@@ -127,8 +127,8 @@ function all(node) {
127127 while ( ++ index < nodes . length ) {
128128 const child = transform ( nodes [ index ] )
129129
130- if ( child !== null ) {
131- // @ts -ignore Assume no document inside document.
130+ if ( child !== undefined ) {
131+ // @ts -expect-error Assume no document inside document.
132132 children . push ( child )
133133 }
134134 }
@@ -141,6 +141,5 @@ function all(node) {
141141 * @returns {HastNode }
142142 */
143143export function fromDom ( node ) {
144- // @ts -ignore Code can handle empty “node”.
145144 return transform ( node || { } ) || { type : 'root' , children : [ ] }
146145}
0 commit comments