Skip to content

:has(selector) matches nodes matched by selector #122

@mdjermanovic

Description

@mdjermanovic

esquery v1.4.0

const literal = espree.parse("1").body[0].expression;
const selector = esquery.parse(":has(Literal)");

esquery.matches(literal, selector); // true

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 a Literal node. Is this the intended behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions