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

未关闭
#1,928 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@manav4u 已经在做这个了。

开始于 2026年11月6日。

  • #1937 来自 @manav4u —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
backend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
TypeScript
星标
636
派生
85
平均合并
1 分钟
30 天内合并 PR
13

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

fb55/css-select 的其他 Issue

查看 fb55/css-select 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。