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>
Given the following minimal example program,
the ESQuery expression
Program > ImportDeclaration > Literalmatches theLiteralnode as expected,but the expression
Program:has(> ImportDeclaration > Literal)does not match theProgramnode.This seems odd, as the simpler selector
Program:has(> ImportDeclaration)matches theProgramnode.And to sanity-check this, here's an equivalent example using CSS selectors which behaves as expected: