-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dom: Add types to clean-node-list #30412
Conversation
Size Change: +12 B (0%) Total Size: 1.42 MB
ℹ️ View Unchanged
|
const tag = node.nodeName.toLowerCase(); | ||
|
||
// It's a valid child, if the tag exists in the schema without an isMatch | ||
// function, or with an isMatch function that matches the node. | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
! 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the optional chaining will do a good job here 👍
) { | ||
if ( node.nodeType === node.ELEMENT_NODE ) { | ||
if ( isElement( node ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a type guard that does the same thing as the previous check but also refines the type to Element
from Node
.
@@ -11,15 +11,17 @@ export default function isEmpty( element ) { | |||
case element.TEXT_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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodeValue
could be null
so this defaults it to ''
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work with this one 👍
@tyxla Can I get a review when you have a chance? 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing more to add here. Looks great from my perspective 🚢
const tag = node.nodeName.toLowerCase(); | ||
|
||
// It's a valid child, if the tag exists in the schema without an isMatch | ||
// function, or with an isMatch function that matches the node. | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.js
files for terms that need renaming or removal).