dom: Add types to clean-node-list#30412
Conversation
|
Size Change: +12 B (0%) Total Size: 1.42 MB
ℹ️ View Unchanged
|
| if ( | ||
| schema.hasOwnProperty( tag ) && | ||
| ( ! schema[ tag ].isMatch || schema[ tag ].isMatch( node ) ) | ||
| ( ! schema[ tag ].isMatch || schema[ tag ].isMatch?.( node ) ) |
There was a problem hiding this comment.
! schema[ tag ].isMatch || doesn't all the way refine isMatch's presence. There might be a better way to do this but I'm not sure about it 🤔
There was a problem hiding this comment.
I think the optional chaining will do a good job here 👍
| ( ! schema[ tag ].isMatch || schema[ tag ].isMatch?.( node ) ) | ||
| ) { | ||
| if ( node.nodeType === node.ELEMENT_NODE ) { | ||
| if ( isElement( node ) ) { |
There was a problem hiding this comment.
This is a type guard that does the same thing as the previous check but also refines the type to Element from Node.
| // We cannot use \s since it includes special spaces which we want | ||
| // to preserve. | ||
| return /^[ \f\n\r\t\v\u00a0]*$/.test( element.nodeValue ); | ||
| return /^[ \f\n\r\t\v\u00a0]*$/.test( element.nodeValue || '' ); |
There was a problem hiding this comment.
nodeValue could be null so this defaults it to ''.
|
@tyxla Can I get a review when you have a chance? 🙂 |
tyxla
left a comment
There was a problem hiding this comment.
Nothing more to add here. Looks great from my perspective 🚢
| if ( | ||
| schema.hasOwnProperty( tag ) && | ||
| ( ! schema[ tag ].isMatch || schema[ tag ].isMatch( node ) ) | ||
| ( ! schema[ tag ].isMatch || schema[ tag ].isMatch?.( node ) ) |
There was a problem hiding this comment.
I think the optional chaining will do a good job here 👍
Description
Adds types to
clean-node-list. There are a few runtime changes, I've annotated each with the reason why they're necessary.Part of #18838
How has this been tested?
Type checks pass and e2e and unit tests pass
Types of changes
Non-breaking changes.
Checklist:
*.native.jsfiles for terms that need renaming or removal).