fix(lib): allow error nodes to match when they are child nodes

(cherry picked from commit 8387101a61)
This commit is contained in:
Amaan Qureshi 2025-08-28 17:10:58 -04:00 committed by Amaan Qureshi
parent 22fa144016
commit 77e5c1c8aa
2 changed files with 28 additions and 1 deletions

View file

@ -5727,3 +5727,25 @@ fn test_query_with_anonymous_error_node() {
vec![(1, vec![("error", "ERROR")]), (0, vec![("error", "ERROR")])]
);
}
#[test]
fn test_query_allows_error_nodes_with_children() {
allocations::record(|| {
let language = get_language("cpp");
let code = "SomeStruct foo{.bar{}};";
let mut parser = Parser::new();
parser.set_language(&language).unwrap();
let tree = parser.parse(code, None).unwrap();
let root = tree.root_node();
let query = Query::new(&language, "(initializer_list (ERROR) @error)").unwrap();
let mut cursor = QueryCursor::new();
let matches = cursor.matches(&query, root, code.as_bytes());
let matches = collect_matches(matches, &query, code);
assert_eq!(matches, &[(0, vec![("error", ".bar")])]);
});
}