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.
This commit is contained in:
parent
1a6af3fafe
commit
0a85744eba
2 changed files with 45 additions and 0 deletions
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue