tree-sitter / node-tree-sitter

Node.js bindings for tree-sitter
https://www.npmjs.com/package/tree-sitter
MIT License
649 stars 114 forks source link

Query fails to match optional node when using `#eq?` predicate #107

Closed joaomoreno closed 2 years ago

joaomoreno commented 2 years ago

Using the JavaScript grammar:

{ one: true };
{ one: true, two: true };

And the following query:

(
    (object (pair key: (property_identifier) @a) (pair key: (property_identifier) @b)?)
    (#eq? @a one)
    (#eq? @b two)
)

This library fails to match both objects and only matches the second one.

This works great in the Playground, as well as when using the WASM version of the libraries in Node:

image

joaomoreno commented 2 years ago

Issue in tree-sitter: https://github.com/tree-sitter/tree-sitter/issues/1392 Fix: https://github.com/tree-sitter/tree-sitter/commit/79b2bf1c30c65e8450f3712fcaffa39c6c3301b1