Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow naked binaryOp at the start of a has selector #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

richsilv
Copy link

@richsilv richsilv commented Dec 6, 2022

Fixes #132, allowing users to write selectors with naked binary operators inside blocks, like FunctionExpression:has(> [name="foo"]).

This is achieved in two steps:

  1. Update to the Peg.js grammar.
  2. Handling the case of a missing left-hand selector inside a has block, by injecting a selector corresponding to the node which is then sub-traversed, using a new exactNode type.

@moniuch
Copy link

moniuch commented Mar 11, 2023

I would love this PR to get a review from the maintainers...

@@ -35,7 +35,7 @@ selectors = s:selector ss:(_ "," _ selector)* {
}

selector
= a:sequence ops:(binaryOp sequence)* {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too permissive. Instead, I would have just allowed an optional binaryOp in the has production.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can’t go directly in the has production, because that would cause problems if the second alternative has a root operator (:has(> a, > b)). I have resolved this in #145

@AustinGrey
Copy link

@richsilv Is there any appetite for addressing the reviewer's comments and resubmitting? This downstream affects ts-query which I need for another project, and I unfortunately do not know pegjs to try and submit my own PR.

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.

:has(> child) is not supported
5 participants