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 selector within :has() #145

Merged
merged 3 commits into from
Jul 8, 2024

Conversation

c-harding
Copy link
Contributor

@c-harding c-harding commented Mar 26, 2024

Based on #133, rebased and updated to handle @michaelficarra’s PR feedback

Fixes #132

c-harding and others added 2 commits March 26, 2024 17:01
Co-authored-by: Richard Silverton <richard@reinfer.io>
@c-harding
Copy link
Contributor Author

@michaelficarra please could you have a look at this?

Copy link
Member

@michaelficarra michaelficarra left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. This looks great! Thanks for the contribution, @c-harding.

@michaelficarra michaelficarra changed the title Allow naked binaryOp at the start of a selector allow naked binaryOp at the start of a selector within :has() Jul 8, 2024
@michaelficarra michaelficarra merged commit 00448e0 into estools:master Jul 8, 2024
5 checks passed
@c-harding c-harding deleted the has-with-naked-operator branch July 8, 2024 16:48
const deepChildMatches = esquery(conditional, 'IfStatement:has(> Identifier[name="x"])');
assert.equal(0, deepChildMatches.length);

const shallowChildMatches = esquery(conditional, 'IfStatement:has(> LogicalExpression.test, > Identifier[name="x"])');
Copy link

Choose a reason for hiding this comment

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

hey I tried to use a more complex version of this:

    it('fails repeated and nested', function () {
        const matches = esquery(
            esprima.parse(`
                if (x) foo; // Target
                if (x) { foo; }
                if (y) { foo; }
                if (x) bar;
            `),
            'IfStatement:has(>Identifier[name="x"]):has(>ExpressionStatement>Identifier[name="foo"])'
        );
        assert.equal(1, matches.length);
    });

and it doesn't work. Any ideas why, in case this is still fresh on your mind? I found this as a workaround in the mean time:

    it('workaround', function () {
        const matches = esquery(
            esprima.parse(`
                if (x) foo; // Target
                if (x) { foo; }
                if (y) { foo; }
                if (x) bar;
            `),
            'IfStatement:has(>Identifier[name="x"]):has(>ExpressionStatement:has(>Identifier[name="foo"]))'
        );
        assert.equal(1, matches.length);
    });

and extracted a simpler to reproduce test case into #146

This comment was marked as resolved.

This comment was marked as resolved.

Copy link

Choose a reason for hiding this comment

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

An attempt to fix the complex queries #148

lukaw3d added a commit to lukaw3d/esquery that referenced this pull request Aug 6, 2024
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
3 participants