-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Google currently use this in lit, specifically here.
There's some flexibility in changing interface i think as i can contribute back to lit to get those changes made.
Suggested migration/support:
function | summary | migration/action |
---|---|---|
filter | filters an iterable by a predicate | probably unnecessary, only used internally in parse5-utils |
getAttr | gets the string value of an attribute by name | use getAttribute |
getTextContent | gets the text contents of a node | use getTextContent |
setAttr | sets an attribute by name | use setAttribute |
insertBefore | inserts a node before another node | use tree adapter insertBefore |
insertNode | inserts a node at a given position, optionally replacing | use spliceChildren |
isElement | determines if a node is an element | use isElementNode |
isCommentNode | determines if a node is a comment | same |
isDocumentFragment | determines if a node is a document fragment | same |
isTextNode | determines if a node is a text node | same |
defaultChildNodes/GetChildNodes | helper passed to other functions to assist in retrieving child nodes | probably can be dropped |
depthFirst | traverses the tree of a node depth-first, as an iterable | use queryAll |
nodeWalkAll | traverses the tree of a node depth-first, as an array | use queryAll |
removeFakeRootElements | removes parse5's fix-up elements (e.g. missing body tags) | TBD |
removeNode | removes a given node | use tree adapter (detachNode ) |
removeNodeSaveChildren | replaces a node with its children | TBD |
setTextContent | sets the text content of a node | use setTextContent |
newTextNode | creates a new text node | use createTextNode |
traverse | traverses the tree of a node depth-first using a visitor | use traverse |
Gaps to discuss in compatibility
There are a couple of compatibility gaps we need to decide on:
removeFakeRootElements
This is used by lit to remove the missing root elements parse5 adds when producing an AST (e.g. missing body tags).
It works by finding all elements without a location and replacing them with their children.
- Option 1 - implement this or a very similar function (e.g.
removeByQuery
might be a little more generic, and the lit team specify a query for locationless nodes) - Option 2 - don't implement this, just keep it in the lit repo
removeNodeSaveChildren
Only really used by lit during the previously explained removeFakeRootElements
call.
It replaces a node with its children (removing a level in the hierarchy).
Could still be useful to people though as its own standalone function, so i think we should at least ship something similar (no clue of any better name though 😬 ).