:has(.a .b) matches with the :has() element itself as .a

Aperta
#1,928 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@manav4u ci sta già lavorando.

Dal 6/11/2026.

  • #1937 di @manav4u — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, typescript
Ambito
backend

Direzione di ricerca

Start in css-select's subselects.has and follow how it calls compileToken with [PLACEHOLDER_ELEMENT]; inspect the _flexibleDescendant condition described in the issue. Reproduce the supplied selector case on css-select 7.0.0, then verify that matching agrees with the expected false result and that relevant tests pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The argument of .a:has(.a .b) absolutizes to :scope .a .b, so the .a has to be inside the :has() element. css-select also accepts the element itself.

import { compile } from 'css-select';
import { parseDocument } from 'htmlparser2';
import { findOne } from 'domutils';

const doc = parseDocument('<div class="a" id="t"><i class="b"></i></div>');
const t = findOne((e) => e.attribs.id === 't', doc.children, true);

console.log(compile('.a:has(.a .b)', { xmlMode: false })(t));
// true, where Chrome 152's t.matches('.a:has(.a .b)') is false

Cause. subselects.has passes an array context, [PLACEHOLDER_ELEMENT], so compileToken replaces the descendant combinator after :scope with _flexibleDescendant, which includes the element itself. Its comment says "only used while querying an array", and here the array is only how has swaps the element in.

What was tried. Adding finalContext[0] !== PLACEHOLDER_ELEMENT to that condition, on a copy of 7.0.0, makes the example answer false.

Run on css-select 7.0.0. master at 2b69f6c has the same lines, which I checked by reading it, not by running it.

Lingua principale
TypeScript
Stelle
636
Fork
85
Merge medio
1m
PR unite (30g)
13

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di fb55/css-select

Tutte le issue di fb55/css-select

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.