forked from ashi009/node-fast-html-parser
    
        
        - 
                Notifications
    You must be signed in to change notification settings 
- Fork 116
Closed
Description
The docs say firstChild is undefined if the node has no children. https://github.com/taoqf/node-html-parser#firstchild
In fact, if I'm understanding correctly, parse wraps the provided markup in a tagless HTMLElement.
That's reasonable. It's a nice way of handling parse('<div></div> <div></div>').
But it means, at least in the possibilities I've tried,
- firstChildis never undefined
- firstChildis the outermost element (not what I'd think of as a "child"), if the provided HTML has one outermost element.
(2) is sort of implied in the docs (https://github.com/taoqf/node-html-parser#usage)
const root = parse('<ul id="list"><li>Hello World</li></ul>');
console.log(root.firstChild.structure);
// ul#list
//   li
//     #textbut it tripped me up: what I thought would be
const root = parse('<div my-attribute></div>')
root.attributeshas to be
const root = parse('<div my-attribute></div>')
root.firstChild.attributesRepro: https://stackblitz.com/edit/node-html-parser-285?file=index.js
Don't know if the firstChild docs need more nuance, or if some other parts of the docs could use a warning (or even if this is a bug).
Metadata
Metadata
Assignees
Labels
No labels