You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would love it if the Node class had more methods. That way, we wouldn't have to write our own helper functions. We write these helper functions using node.descendants(). An example of a helper function that is useful is to take the current Node and return all of the children nodes or descendant nodes with a particular type.
function getDescendantsWithType(node: Node, targetType: NodeType): Node[]
function getDirectChildrenWithType(node: Node, targetType: NodeType): Node[]
The text was updated successfully, but these errors were encountered:
Since these are simple enough to implement on top of descendants, and the precise form they take will be different per use case (sometimes you need just the node, sometimes the node and its position, sometimes its parent, etc), I feel it's fine to have people implement these as custom functions in their own codebase.
I would love it if the Node class had more methods. That way, we wouldn't have to write our own helper functions. We write these helper functions using node.descendants(). An example of a helper function that is useful is to take the current Node and return all of the children nodes or descendant nodes with a particular type.
function getDescendantsWithType(node: Node, targetType: NodeType): Node[]
function getDirectChildrenWithType(node: Node, targetType: NodeType): Node[]
The text was updated successfully, but these errors were encountered: