@@ -158,24 +158,30 @@ const FRAGMENT_NODE = 11
158
158
159
159
const ELEMENT_REGEXP = / ^ ( ( H T M L | S V G ) \w * ) ? E l e m e n t $ /
160
160
161
+ const isCustomElement = ( val : any ) => {
162
+ const { tagName} = val
163
+ return Boolean (
164
+ ( typeof tagName === 'string' && tagName . includes ( '-' ) ) ||
165
+ ( typeof val . hasAttribute === 'function' && val . hasAttribute ( 'is' ) ) ,
166
+ )
167
+ }
168
+
161
169
const testNode = ( val : any ) => {
162
170
const constructorName = val . constructor . name
163
- const { nodeType, tagName} = val
164
- const isCustomElement =
165
- ( typeof tagName === 'string' && tagName . includes ( '-' ) ) ||
166
- ( typeof val . hasAttribute === 'function' && val . hasAttribute ( 'is' ) )
171
+
172
+ const { nodeType} = val
167
173
168
174
return (
169
175
( nodeType === ELEMENT_NODE &&
170
- ( ELEMENT_REGEXP . test ( constructorName ) || isCustomElement ) ) ||
176
+ ( ELEMENT_REGEXP . test ( constructorName ) || isCustomElement ( val ) ) ) ||
171
177
( nodeType === TEXT_NODE && constructorName === 'Text' ) ||
172
178
( nodeType === COMMENT_NODE && constructorName === 'Comment' ) ||
173
179
( nodeType === FRAGMENT_NODE && constructorName === 'DocumentFragment' )
174
180
)
175
181
}
176
182
177
183
export const test : NewPlugin [ 'test' ] = ( val : any ) =>
178
- val ?. constructor ?. name && testNode ( val )
184
+ ( val ?. constructor ?. name || isCustomElement ( val ) ) && testNode ( val )
179
185
180
186
type HandledType = Element | Text | Comment | DocumentFragment
181
187
@@ -195,7 +201,8 @@ export default function createDOMElementFilter(
195
201
filterNode : ( node : Node ) => boolean ,
196
202
) : NewPlugin {
197
203
return {
198
- test : ( val : any ) => val ?. constructor ?. name && testNode ( val ) ,
204
+ test : ( val : any ) =>
205
+ ( val ?. constructor ?. name || isCustomElement ( val ) ) && testNode ( val ) ,
199
206
serialize : (
200
207
node : HandledType ,
201
208
config : Config ,
0 commit comments