Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 30, 2025

This PR implements support for the universal selector (*) in the CSSOM selector parser and matching implementation, addressing a core CSS feature that was missing from JSAR's CSS processing.

What's Changed

The universal selector (*) is a fundamental CSS selector that matches any element. This implementation adds complete support for parsing and matching universal selectors in all contexts:

/* Basic universal selector */
* { color: red; }

/* Compound selectors with universal */
*.class { background: blue; }
*#myid { font-size: 16px; }

/* Combinators with universal */
div * { margin: 10px; }
section > * { padding: 5px; }
h1 + * { border-top: 1px solid; }

/* Pseudo-classes with universal */
*:hover { cursor: pointer; }
*:focus { outline: 2px solid blue; }

Implementation Details

The changes follow the existing codebase patterns and are minimal:

  1. Added ComponentType::kUniversal to the component type enum
  2. Added isUniversal() method to the Component class for type checking
  3. Enhanced parseComponent() to recognize and parse the * character
  4. Updated matching logic so universal selectors match any element (always return true)
  5. Added string representation for universal selectors in serialization

Testing

Comprehensive test coverage includes:

  • Basic universal selector parsing and matching
  • Compound selectors combining universal with classes, IDs, and pseudo-classes
  • Universal selectors with all combinator types (descendant, child, sibling)
  • Multiple selector lists containing universal selectors
  • String representation validation
  • Visual HTML test fixture at fixtures/html/universal-selector-test.html demonstrating all features

All changes maintain backward compatibility and pass existing formatting checks.

Fixes #260.


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

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copilot AI changed the title [WIP] Support universal selector (*) in CSSOM selector parser and matching Support universal selector (*) in CSSOM selector parser and matching Aug 30, 2025
Copilot AI requested a review from yorkie August 30, 2025 10:44
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 Add a html at fixtures/html to test this feature

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

Copilot AI commented Aug 30, 2025

@copilot Add a html at fixtures/html to test this feature

Added comprehensive HTML test file at fixtures/html/universal-selector-test.html that demonstrates all universal selector features including basic usage, compound selectors, combinators, pseudo-classes, and edge cases. The test file provides visual validation of the universal selector implementation. (6ed75f9)

Copilot AI requested a review from yorkie August 30, 2025 11:04
@yorkie yorkie marked this pull request as ready for review August 30, 2025 11:07
@yorkie yorkie merged commit 99b7458 into main Aug 30, 2025
4 checks passed
@yorkie yorkie deleted the copilot/fix-260 branch August 30, 2025 11:09
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.

Support universal selector (*) in CSSOM selector parser and matching

2 participants