Skip to content

Conversation

@developit
Copy link
Contributor

Summary

This PR adds a comprehensive test suite for selector parsing/matching and implements the missing :not() pseudo-class. While adding tests I uncovered and fixed several selector matcher bugs so selectors now behave much closer to CSS semantics.

What I changed

  • Tests

    • Added a focused test suite for selector parsing and matching (27 tests).
    • Tests cover class matching, universal selector, :not(), combinators (descendant, sibling), and node-type handling.
  • Implementation

    • Implemented :not() pseudo-class support in packages/polyfill/source/selectors.ts.
    • Fixed class matching to correctly handle elements with multiple classes.
    • Added universal selector (*) support.
    • Fixed sibling combinator behavior to skip non-element nodes when traversing siblings.
    • Fixed descendant and sibling matching logic for correct tree traversal.
    • Ensured full type safety for selector code paths.

Why this change

The repository previously had no tests for the selector parser/matcher, and the :not() selector was unimplemented. Adding tests found edge cases and bugs; this PR fixes them and ensures selectors match according to expected behavior.

Files of interest

  • packages/polyfill/source/selectors.ts (implementation changes: :not(), universal selector, matching fixes)
  • test/... (new selector parsing/matching test file(s) — 27 tests total)

Testing

  • All selector tests pass locally (27 tests).
  • Run the project test suite (e.g., yarn test or npm test) to verify.

Notes for reviewers

  • Review selectors.ts for the :not() implementation and the adjusted traversal logic for combinators.
  • The changes are intended to be behavior fixes (aligning with CSS semantics), not API additions. There should be no breaking API changes.

Commit

  • 0290d56 — Add comprehensive selector tests and implement :not() selector

Co-authored-by: Claude [email protected]

@github-actions

This comment has been minimized.

@developit developit requested a review from JoviDeCroock August 28, 2025 19:21
Copy link
Member

@lemonmade lemonmade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a patch changeset, then this looks good to go 👍

@JoviDeCroock JoviDeCroock force-pushed the cx-add-selector-tests-implement-not branch from 0290d56 to 0be84e0 Compare August 29, 2025 14:41
- Added comprehensive test suite for selector parsing and matching (27 tests)
- Implemented missing :not() pseudo-class selector functionality
- Fixed class matching bug (now properly handles multiple classes)
- Added universal selector (*) support
- Fixed sibling combinators to skip non-element nodes
- Fixed descendant/sibling matching logic for proper tree traversal
- All selector tests pass with full type safety

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@JoviDeCroock JoviDeCroock force-pushed the cx-add-selector-tests-implement-not branch from 0be84e0 to d176f24 Compare August 29, 2025 14:42
@JoviDeCroock JoviDeCroock merged commit 61f5cba into main Aug 29, 2025
6 checks passed
@JoviDeCroock JoviDeCroock deleted the cx-add-selector-tests-implement-not branch August 29, 2025 14:44
Copy link

@waseembahralaseel-cell waseembahralaseel-cell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool

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.

4 participants