Avoid including undefined in return value of Query.matches

Fixes #932
This commit is contained in:
Max Brunsfeld 2021-02-26 15:16:07 -08:00
parent e710a14244
commit 41e9af2456
2 changed files with 32 additions and 4 deletions

View file

@ -81,6 +81,32 @@ describe("Query", () => {
{ pattern: 0, captures: [{ name: "element", text: "g" }] },
]);
});
it("handles predicates that compare the text of capture to literal strings", () => {
tree = parser.parse(`
giraffe(1, 2, []);
helment([false]);
goat(false);
gross(3, []);
hiccup([]);
gaff(5);
`);
// Find all calls to functions beginning with 'g', where one argument
// is an array literal.
query = JavaScript.query(`
(call_expression
function: (identifier) @name
arguments: (arguments (array))
(#match? @name "^g"))
`);
const matches = query.matches(tree.rootNode);
assert.deepEqual(formatMatches(matches), [
{ pattern: 0, captures: [{name: "name", text: "giraffe" }] },
{ pattern: 0, captures: [{name: "name", text: "gross" }] },
]);
});
});
describe(".captures", () => {