Closed KevinVerre closed 2 months ago
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[]