@@ -158,24 +158,30 @@ const FRAGMENT_NODE = 11
158158
159159const ELEMENT_REGEXP = / ^ ( ( H T M L | S V G ) \w * ) ? E l e m e n t $ /
160160
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+
161169const testNode = ( val : any ) => {
162170 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
167173
168174 return (
169175 ( nodeType === ELEMENT_NODE &&
170- ( ELEMENT_REGEXP . test ( constructorName ) || isCustomElement ) ) ||
176+ ( ELEMENT_REGEXP . test ( constructorName ) || isCustomElement ( val ) ) ) ||
171177 ( nodeType === TEXT_NODE && constructorName === 'Text' ) ||
172178 ( nodeType === COMMENT_NODE && constructorName === 'Comment' ) ||
173179 ( nodeType === FRAGMENT_NODE && constructorName === 'DocumentFragment' )
174180 )
175181}
176182
177183export const test : NewPlugin [ 'test' ] = ( val : any ) =>
178- val ?. constructor ?. name && testNode ( val )
184+ ( val ?. constructor ?. name || isCustomElement ( val ) ) && testNode ( val )
179185
180186type HandledType = Element | Text | Comment | DocumentFragment
181187
@@ -195,7 +201,8 @@ export default function createDOMElementFilter(
195201 filterNode : ( node : Node ) => boolean ,
196202) : NewPlugin {
197203 return {
198- test : ( val : any ) => val ?. constructor ?. name && testNode ( val ) ,
204+ test : ( val : any ) =>
205+ ( val ?. constructor ?. name || isCustomElement ( val ) ) && testNode ( val ) ,
199206 serialize : (
200207 node : HandledType ,
201208 config : Config ,
0 commit comments