fix(lib): restrict pattern_map optimization when a wildcard step has an immediate first child
Co-authored-by: Amaan Qureshi <amaanq12@gmail.com>
This commit is contained in:
parent
9d1ac21392
commit
9610a84600
2 changed files with 18 additions and 1 deletions
|
|
@ -5171,3 +5171,20 @@ fn test_query_compiler_oob_access() {
|
|||
// UBSAN should not report any OOB access
|
||||
assert!(Query::new(&language, "(package_declaration _ (_) @name _)").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_wildcard_with_immediate_first_child() {
|
||||
let language = get_language("javascript");
|
||||
let query = Query::new(&language, "(_ . (identifier) @firstChild)").unwrap();
|
||||
let source = "function name(one, two, three) { }";
|
||||
|
||||
assert_query_matches(
|
||||
&language,
|
||||
&query,
|
||||
source,
|
||||
&[
|
||||
(0, vec![("firstChild", "name")]),
|
||||
(0, vec![("firstChild", "one")]),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2740,7 +2740,7 @@ TSQuery *ts_query_new(
|
|||
// there is a parent node, and capture it if necessary.
|
||||
if (step->symbol == WILDCARD_SYMBOL && step->depth == 0 && !step->field) {
|
||||
QueryStep *second_step = &self->steps.contents[start_step_index + 1];
|
||||
if (second_step->symbol != WILDCARD_SYMBOL && second_step->depth == 1) {
|
||||
if (second_step->symbol != WILDCARD_SYMBOL && second_step->depth == 1 && !second_step->is_immediate) {
|
||||
wildcard_root_alternative_index = step->alternative_index;
|
||||
start_step_index += 1;
|
||||
step = second_step;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue