Open mdjermanovic opened 3 years ago
Can still reproduce this, e.g. if (y) { y += 'z'; }
matches BlockStatement:has(BlockStatement:has(BlockStatement))
The cause is https://github.com/estools/esquery/blob/07ee329d6aaa6e468114687468e5c6f28a7b7beb/esquery.js#L179-L191
enter and leave visit node
too. A simple fix is https://github.com/estools/esquery/compare/master...lukaw3d:esquery:remove-parent-from-has
estraverse.traverse(node, {
enter (descendant, parent) {
if (node === descendant) return;
...
leave (descendant) {
if (node === descendant) return;
...
esquery v1.4.0
Or. in the esquery demo, enter
1
as code,:has(Literal)
as selector. It finds"Program"
,"ExpressionStatement"
, and"Literal"
.I was expecting that selectors in
:has()
can match only descendants of the node, but in the above examples:has(Literal)
matches aLiteral
node. Is this the intended behavior?