Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

node.children is undefined? #462

Open
mindplay-dk opened this issue Mar 15, 2016 · 3 comments
Open

node.children is undefined? #462

mindplay-dk opened this issue Mar 15, 2016 · 3 comments

Comments

@mindplay-dk
Copy link

In this function, did you really mean node or element?

Because Node objects do not have the children property - only Element objects have that.

@mindplay-dk
Copy link
Author

We probably ought to have an extra function to check if a given node is an HTMLElement, and then use that to make an extra assertion before relying on children - something like:

    function isHTMLElement(node) {
        return node instanceof HTMLElement;
    }

    function isEmptyInlineElement(node) {
        if (isHTMLElement(node)) {
            if (node.children.length > 1) {
                return false;
            }
            if (node.children.length === 1 && node.textContent.trim() !== '') {
                return false;
            }
            if (node.children.length === 0) {
                return node.textContent.trim() === '';
            }
            return isEmptyInlineElement(node.children[0]);
        }
        return false;
    }

@rrees rrees self-assigned this Mar 23, 2016
@rrees
Copy link
Contributor

rrees commented Apr 3, 2016

I agree with trying to implement the right check

@katebee
Copy link
Contributor

katebee commented Feb 3, 2017

@rrees adding labels appears to have unassigned you 😢 (that was not intentional)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants