Skip to content

Re-implement :has(> by marking first selector isRoot - #148

Open
lukaw3d wants to merge 5 commits into
estools:masterfrom
lukaw3d:reimplement-has-child
Open

Re-implement :has(> by marking first selector isRoot#148
lukaw3d wants to merge 5 commits into
estools:masterfrom
lukaw3d:reimplement-has-child

Conversation

@lukaw3d

@lukaw3d lukaw3d commented Aug 6, 2024

Copy link
Copy Markdown

Re-implements #145 to fix #146 :has(>BlockStatement>ExpressionStatement)

but this approach isn't extendable to support :has(~
and I don't know if it has unintended consequences if > is used outside :has(>

brettz9 added a commit to brettz9/esquery that referenced this pull request Aug 5, 2026
 estools#148

hasSelector previously parsed a leading combinator (e.g. `> A > B`)
by taking the whole remainder as an independent selector and
wrapping it once with exactNode, producing a right-nested structure
instead of the left-associative chain used by top-level selectors.
This caused false negatives (`X:has(> A > B)` not matching valid
nested structures) and false positives (matching when the :has()
subject itself satisfied an inner constraint).

Rebuild the chain the same way the `selector` rule does, seeding
the left-associative fold with exactNode for the leading combinator.

Regenerate parser.js from grammar.pegjs and add regression tests.
brettz9 added a commit to brettz9/esquery that referenced this pull request Aug 5, 2026
 estools#148

hasSelector previously parsed a leading combinator (e.g. `> A > B`)
by taking the whole remainder as an independent selector and
wrapping it once with exactNode, producing a right-nested structure
instead of the left-associative chain used by top-level selectors.
This caused false negatives (`X:has(> A > B)` not matching valid
nested structures) and false positives (matching when the :has()
subject itself satisfied an inner constraint).

Rebuild the chain the same way the `selector` rule does, seeding
the left-associative fold with exactNode for the leading combinator.

Regenerate parser.js from grammar.pegjs and add regression tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant