esquery
esquery copied to clipboard
Bug: `X > Y > Z` matches `Z`, but `X:has(> Y > Z)` does not match `X`
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>