Fix handling of queries with field names at the roots of patterns
Fixes #1018
This commit is contained in:
parent
6e8b5e7643
commit
72143b17ff
2 changed files with 21 additions and 2 deletions
|
|
@ -991,6 +991,24 @@ fn test_query_matches_with_negated_fields() {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_with_field_at_root() {
|
||||
allocations::record(|| {
|
||||
let language = get_language("javascript");
|
||||
let query = Query::new(language, "name: (identifier) @name").unwrap();
|
||||
assert_query_matches(
|
||||
language,
|
||||
&query,
|
||||
"
|
||||
a();
|
||||
function b() {}
|
||||
class c extends d {}
|
||||
",
|
||||
&[(0, vec![("name", "b")]), (0, vec![("name", "c")])],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_matches_with_repeated_leaf_nodes() {
|
||||
allocations::record(|| {
|
||||
|
|
|
|||
|
|
@ -2756,8 +2756,9 @@ static inline bool ts_query_cursor__advance(
|
|||
do {
|
||||
// If this node matches the first step of the pattern, then add a new
|
||||
// state at the start of this pattern.
|
||||
if (step->field && field_id != step->field) continue;
|
||||
ts_query_cursor__add_state(self, pattern);
|
||||
if (!step->field || field_id == step->field) {
|
||||
ts_query_cursor__add_state(self, pattern);
|
||||
}
|
||||
|
||||
// Advance to the next pattern whose root node matches this node.
|
||||
i++;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue