fix(lib)!: child_containing_descendant now returns direct children
Previously, `child_containing_descendant` would return `null` when called on a node's direct parent. In my opinion, this doesn't make much sense; it seems like a node would contain itself. This (breaking) commit changes the function so that it can return direct children.
This commit is contained in:
parent
6b1ebd3d29
commit
b36ef4b7f4
2 changed files with 22 additions and 6 deletions
|
|
@ -550,7 +550,7 @@ TSNode ts_node_parent(TSNode self) {
|
|||
|
||||
while (true) {
|
||||
TSNode next_node = ts_node_child_containing_descendant(node, self);
|
||||
if (ts_node_is_null(next_node)) break;
|
||||
if (next_node.id == self.id) break;
|
||||
node = next_node;
|
||||
}
|
||||
|
||||
|
|
@ -567,10 +567,12 @@ TSNode ts_node_child_containing_descendant(TSNode self, TSNode subnode) {
|
|||
if (
|
||||
!ts_node_child_iterator_next(&iter, &self)
|
||||
|| ts_node_start_byte(self) > start_byte
|
||||
|| self.id == subnode.id
|
||||
) {
|
||||
return ts_node__null();
|
||||
}
|
||||
if (self.id == subnode.id) {
|
||||
return self;
|
||||
}
|
||||
|
||||
// Here we check the current self node and *all* of its zero-width token siblings that follow.
|
||||
// If any of these nodes contain the target subnode, we return that node. Otherwise, we restore the node we started at
|
||||
|
|
@ -585,7 +587,7 @@ TSNode ts_node_child_containing_descendant(TSNode self, TSNode subnode) {
|
|||
}
|
||||
ts_node_child_iterator_next(&iter, &self);
|
||||
if (self.id == subnode.id) {
|
||||
return ts_node__null();
|
||||
return self;
|
||||
}
|
||||
}
|
||||
self = old;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue