fix(lib): peek at the next sibling when iterating to find the child that contains a given descendant

This issue shows up when we have a zero-width token that is the target
descendant node, previously the previous sibling would be returned as
the child that contains the descendant, which is incorrect.

(cherry picked from commit 0a85744eba)
This commit is contained in:
Amaan Qureshi 2024-08-26 23:26:45 -04:00
parent 6813e8d5c1
commit a6b248c1ad
2 changed files with 45 additions and 0 deletions

View file

@ -290,6 +290,16 @@ fn test_parent_of_zero_width_node() {
function_definition
);
assert_eq!(function_definition.child_containing_descendant(block), None);
let code = "<script></script>";
parser.set_language(&get_language("html")).unwrap();
let tree = parser.parse(code, None).unwrap();
let root = tree.root_node();
let script_element = root.child(0).unwrap();
let raw_text = script_element.child(1).unwrap();
let parent = raw_text.parent().unwrap();
assert_eq!(parent, script_element);
}
#[test]