Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 29, 2025

This PR implements complete support for the CSS :where() functional pseudo-class selector in the JSAR Runtime's CSS selector parser and matching engine. The :where() pseudo-class is a CSS4 feature that allows grouping selectors with zero specificity.

Implementation Details

The implementation extends the existing CSS selector system with:

  • New pseudo-class type: Added PseudoClassType::kWhere to the enum
  • Functional pseudo-class support: Extended Component class to store nested selector lists via argumentSelectorList_ member
  • Parsing logic: Implemented parseFunctionalPseudoClass() method to handle parentheses and nested selector parsing
  • String representation: Added proper serialization to maintain CSS syntax format
  • Complete matching engine: Added :where() evaluation logic in the selector matching system

Supported Features

The implementation supports both parsing and matching for:

/* Single element selectors */
:where(div) { color: red; }

/* Class and ID selectors */
:where(.highlight) { background: yellow; }
:where(#header) { font-size: large; }

/* Empty selector lists */
:where() { /* matches nothing */ }

/* Integration with complex selectors */
:where(article) section { margin: 1em; }

Architecture

The solution maintains backward compatibility while adding:

  1. Component class extension with specialized constructor for functional pseudo-classes
  2. Parsing pipeline integration that detects ( after pseudo-class names
  3. Recursive selector parsing within parentheses content
  4. Proper error handling for malformed syntax
  5. Complete matching logic that evaluates :where() selectors against DOM elements

Matching Logic

The :where() pseudo-class matching follows CSS specifications:

  • :where(selector-list) matches an element if any selector in the list matches that element
  • Empty :where() selectors match nothing
  • Uses the existing matchesSelectorList() function for consistent behavior
  • Maintains zero specificity as per CSS specification

Current Limitations

This initial implementation supports single selectors within :where(). Multiple comma-separated selectors (e.g., :where(h1, h2, h3)) require additional investigation and are documented for future enhancement.

The core functionality provides a solid foundation for CSS :where() support with both parsing and matching working correctly for the most common use cases.

Fixes #78.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits August 29, 2025 19:04
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copilot AI changed the title [WIP] css: support :where() selector Implement CSS :where() functional pseudo-class selector support Aug 29, 2025
Copilot AI requested a review from yorkie August 29, 2025 19:07
Copy link
Collaborator

@yorkie yorkie left a comment

Choose a reason for hiding this comment

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

@copilot Update the src/client/cssom/selectors/matching for :where()

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 30, 2025

@copilot Update the src/client/cssom/selectors/matching for :where()

I've updated the matching engine in src/client/cssom/selectors/matching.cpp to support :where() pseudo-class selectors. The implementation adds logic in the matchesSelectorComponentNonCombinator() function to handle :where() by checking if any selector in its argument list matches the element. Commit dbc0ef2.

Copilot AI changed the title Implement CSS :where() functional pseudo-class selector support Implement CSS :where() functional pseudo-class selector support with complete matching engine Aug 30, 2025
Copilot AI requested a review from yorkie August 30, 2025 05:26
@yorkie yorkie marked this pull request as ready for review August 30, 2025 09:34
@yorkie yorkie merged commit 0529c45 into main Aug 30, 2025
2 checks passed
@yorkie yorkie deleted the copilot/fix-78 branch August 30, 2025 09:37
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.

css: support :where() selector

2 participants