Skip to content

Add support for :host pseudo-class#1765

Open
RedZapdos123 wants to merge 1 commit intofb55:masterfrom
RedZapdos123:fix-issue-1374-host-pseudo
Open

Add support for :host pseudo-class#1765
RedZapdos123 wants to merge 1 commit intofb55:masterfrom
RedZapdos123:fix-issue-1374-host-pseudo

Conversation

@RedZapdos123
Copy link
Copy Markdown

@RedZapdos123 RedZapdos123 commented Apr 5, 2026

Description:

  • Add support for :host by aliasing it to :scope.
  • Add regression tests that verify :host matches the root element and context elements.
  • Document :host support in the README selector list.

Verification:

  • npm run test:vi
  • npm run build
  • node --input-type=module -e "import * as CSSselect from './dist/index.js'; import { parseDocument } from 'htmlparser2'; const dom = parseDocument('
    ').children; console.log(CSSselect.selectAll(':host', dom).length);"

Fixes #1374

The screenshot of the tests run, for validation:

image

Summary by CodeRabbit

  • New Features
    • The :host pseudo-class selector is now supported. It selects elements in the current context and operates as an alias to :scope, offering an alternative syntax for context-aware selection.

Signed-off-by: Mridankan Mandal <xerontitan90@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

📝 Walkthrough

Walkthrough

Added support for the :host pseudo-class by creating an alias to :scope. Changes include documentation updates, a new alias mapping in the pseudo-selectors module, and corresponding tests verifying root element and context matching behavior.

Changes

Cohort / File(s) Summary
Documentation
README.md
Updated "Supported selectors" section to document :host as an alias of :scope.
Implementation
src/pseudo-selectors/aliases.ts
Added new alias mapping: host: ":scope".
Testing
test/pseudo-classes.ts
Added test suite for :host pseudo-class verifying root element selection and context-aware matching.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A little :host hops into place,
As :scope's trusty alias in the race,
Through DOM trees it bounds so free,
Selecting context, one, two, three! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR successfully addresses issue #1374 by implementing :host pseudo-class support, adding regression tests, and documenting the change in the README.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing :host support: the alias mapping, tests, and documentation. No unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title 'Add support for :host pseudo-class' directly and clearly summarizes the main change in the pull request, which adds :host pseudo-class support.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@RedZapdos123 RedZapdos123 changed the title fix: add support for :host pseudo-class Add support for :host pseudo-class Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for :host pseudo class

2 participants