@@ -21,27 +21,27 @@ const DOCUMENT_FRAGMENT_NODE = 11
21
21
22
22
/**
23
23
* @param {Node } node
24
- * @returns {HastNode|null }
24
+ * @returns {HastNode|undefined }
25
25
*/
26
26
function transform ( node ) {
27
27
switch ( node . nodeType ) {
28
28
case ELEMENT_NODE :
29
- // @ts -ignore TypeScript is wrong.
29
+ // @ts -expect-error TypeScript is wrong.
30
30
return element ( node )
31
31
case DOCUMENT_NODE :
32
32
case DOCUMENT_FRAGMENT_NODE :
33
- // @ts -ignore TypeScript is wrong.
33
+ // @ts -expect-error TypeScript is wrong.
34
34
return root ( node )
35
35
case TEXT_NODE :
36
- // @ts -ignore TypeScript is wrong.
36
+ // @ts -expect-error TypeScript is wrong.
37
37
return text ( node )
38
38
case COMMENT_NODE :
39
- // @ts -ignore TypeScript is wrong.
39
+ // @ts -expect-error TypeScript is wrong.
40
40
return comment ( node )
41
41
case DOCUMENT_TYPE_NODE :
42
42
return doctype ( )
43
43
default :
44
- return null
44
+ return undefined
45
45
}
46
46
}
47
47
@@ -61,7 +61,7 @@ function root(node) {
61
61
* @returns {HastDoctype }
62
62
*/
63
63
function doctype ( ) {
64
- // @ts -ignore hast types out of date.
64
+ // @ts -expect-error hast types out of date.
65
65
return { type : 'doctype' }
66
66
}
67
67
@@ -72,7 +72,7 @@ function doctype() {
72
72
* @returns {HastText }
73
73
*/
74
74
function text ( node ) {
75
- return { type : 'text' , value : node . nodeValue }
75
+ return { type : 'text' , value : node . nodeValue || '' }
76
76
}
77
77
78
78
/**
@@ -82,7 +82,7 @@ function text(node) {
82
82
* @returns {HastComment }
83
83
*/
84
84
function comment ( node ) {
85
- return { type : 'comment' , value : node . nodeValue }
85
+ return { type : 'comment' , value : node . nodeValue || '' }
86
86
}
87
87
88
88
/**
@@ -98,15 +98,15 @@ function element(node) {
98
98
space === webNamespaces . html ? node . tagName . toLowerCase ( ) : node . tagName
99
99
/** @type {DocumentFragment|Element } */
100
100
const content =
101
- // @ts -ignore Types are wrong.
101
+ // @ts -expect-error Types are wrong.
102
102
space === webNamespaces . html && tagName === 'template' ? node . content : node
103
103
const attributes = node . getAttributeNames ( )
104
104
/** @type {Object.<string, string> } */
105
105
const props = { }
106
106
let index = - 1
107
107
108
108
while ( ++ index < attributes . length ) {
109
- props [ attributes [ index ] ] = node . getAttribute ( attributes [ index ] )
109
+ props [ attributes [ index ] ] = node . getAttribute ( attributes [ index ] ) || ''
110
110
}
111
111
112
112
return fn ( tagName , props , all ( content ) )
@@ -127,8 +127,8 @@ function all(node) {
127
127
while ( ++ index < nodes . length ) {
128
128
const child = transform ( nodes [ index ] )
129
129
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.
132
132
children . push ( child )
133
133
}
134
134
}
@@ -141,6 +141,5 @@ function all(node) {
141
141
* @returns {HastNode }
142
142
*/
143
143
export function fromDom ( node ) {
144
- // @ts -ignore Code can handle empty “node”.
145
144
return transform ( node || { } ) || { type : 'root' , children : [ ] }
146
145
}
0 commit comments