Handle set! predicate function in queries
This commit is contained in:
parent
ff9a2c1f53
commit
b15e90bd26
5 changed files with 140 additions and 25 deletions
|
|
@ -197,6 +197,23 @@ describe("Query", () => {
|
|||
]
|
||||
);
|
||||
});
|
||||
|
||||
it('handles patterns with properties', () => {
|
||||
tree = parser.parse(`a(b.c);`);
|
||||
query = JavaScript.query(`
|
||||
((call_expression (identifier) @func)
|
||||
(set! foo bar)
|
||||
(set! baz quux))
|
||||
|
||||
(property_identifier) @prop
|
||||
`);
|
||||
|
||||
const captures = query.captures(tree.rootNode);
|
||||
assert.deepEqual(formatCaptures(captures), [
|
||||
{name: 'func', text: 'a', properties: {foo: 'bar', baz: 'quux'}},
|
||||
{name: 'prop', text: 'c'},
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -208,5 +225,10 @@ function formatMatches(matches) {
|
|||
}
|
||||
|
||||
function formatCaptures(captures) {
|
||||
return captures.map(({name, node}) => ({ name, text: node.text }))
|
||||
return captures.map(c => {
|
||||
const node = c.node;
|
||||
delete c.node;
|
||||
c.text = node.text;
|
||||
return c;
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue