Skip to content

Bug: X > Y > Z matches Z, but X:has(> Y > Z) does not match X #152

@mxxk

Description

@mxxk

Given the following minimal example program,

import js from "@eslint/js";

the ESQuery expression Program > ImportDeclaration > Literal matches the Literal node as expected,

{
  type: 'Literal',
  start: 15,
  end: 27,
  value: '@eslint/js',
  raw: '"@eslint/js"',
}

but the expression Program:has(> ImportDeclaration > Literal) does not match the Program node.

This seems odd, as the simpler selector Program:has(> ImportDeclaration) matches the Program node.

And to sanity-check this, here's an equivalent example using CSS selectors which behaves as expected:

const doc = new DOMParser().parseFromString('<span>Hello, world!</span>', 'text/html');
console.log(doc.querySelector('html > body > span'));
console.log(doc.querySelector('html:has( > body > span)'));

// Output:
// <span>Hello, world!</span>
// <html>...</html>

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