The problem is that the query matcher prefers to fill up the wildcard, so with the following code only the first let is captured in @lets:
let a = 1;
let b = 2;
let c = 3;
let d = 4;
function f() {
}
function g() {
}
Here lets contains let a = 1; and rest contains the rest of the file.
Adding a . after (_)+ @rest allows lets to capture all the lets, but then only the last wildcard node (function g() {}) is captured as rest. function f() {} is not captured in that case.
Expected behaviour:(lexical_declaration)+ captures as many nodes as it can and subsequent (_)+ captures whatever is left.
Actual behaviour:(lexical_declaration)+ captures as little as possible and subsequent (_)+ captures whatever is left.
Is this the intended behaviour of mixing named and wildcard quantifiers? Intuitively it seems like the first quantifier should capture as many as it can and only then should the wildcard take over.
I have the following query to capture any
let
s at the beginning of a JS file, as well as the rest of the file:The problem is that the query matcher prefers to fill up the wildcard, so with the following code only the first
let
is captured in@lets
:Here
lets
containslet a = 1;
andrest
contains the rest of the file.Adding a
.
after(_)+ @rest
allowslets
to capture all thelet
s, but then only the last wildcard node (function g() {}
) is captured asrest
.function f() {}
is not captured in that case.Expected behaviour:
(lexical_declaration)+
captures as many nodes as it can and subsequent(_)+
captures whatever is left.Actual behaviour:
(lexical_declaration)+
captures as little as possible and subsequent(_)+
captures whatever is left.Is this the intended behaviour of mixing named and wildcard quantifiers? Intuitively it seems like the first quantifier should capture as many as it can and only then should the wildcard take over.