Skip to content

fix: support root :scope selectors#5266

Open
puneetdixit200 wants to merge 1 commit into
cheeriojs:mainfrom
puneetdixit200:fix/root-scope-selector
Open

fix: support root :scope selectors#5266
puneetdixit200 wants to merge 1 commit into
cheeriojs:mainfrom
puneetdixit200:fix/root-scope-selector

Conversation

@puneetdixit200
Copy link
Copy Markdown

Fixes #4509.

This updates root-scoped selector handling so :scope > ... works when the current Cheerio selection is the document root. The document root cannot be matched directly by the underlying element-only selector path, so the root :scope case is rewritten to select from top-level root elements while keeping the existing element-scoped path unchanged.

I added a regression test that includes a nested matching element to make sure :scope > ... only matches direct children of the document root.

Validated with:

  • npm run test:vi -- src/api/traversing.spec.ts -t ":scope on the document root"
  • npm run test:vi -- src/api/traversing.spec.ts
  • npm run test:vi
  • npm run lint:ts
  • npm run lint:biome
  • npx eslint src/api/traversing.ts src/api/traversing.spec.ts
  • npm run build

Note: I also tried npm run test; it currently stops during repo-wide ESLint while linting website/src/content.config.ts because astro/tsconfigs/strict is not available from the root install.

@puneetdixit200 puneetdixit200 force-pushed the fix/root-scope-selector branch from 13d67a6 to b850196 Compare May 24, 2026 16:20
@fb55
Copy link
Copy Markdown
Member

fb55 commented May 29, 2026

Hi @puneetdixit200, this change really should be split across the dependencies, not implemented exclusively in Cheerio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

:scope selector not working on root node

2 participants