Refactor selector formatting with improved function organization#225
Merged
Conversation
Splits the old print_simple_selector/print_inline_selector_list/format_selector tangle into small, single-purpose functions named after what they actually print: print_an_plus_b, print_nth_of, print_combinator, print_attribute_selector, print_pseudo_selector, print_selector_component, print_selector, print_selector_argument and print_selector_list. Combinators are no longer handled inside a function called "simple selector". The internal single-line list printer (print_selector_list) is renamed and separated from the unrelated multi-line rule-prelude printer (formerly also named print_selector_list, now print_rule_selectors), which no longer round-trips through the public format_selector API to print each selector. format_selector and format_selector_list keep their public signatures and behavior; only the internal structure changed.
Bundle ReportChanges will increase total bundle size by 1.58kB (8.45%) ⬆️
Affected Assets, Files, and Routes:view changes for bundle: formatCss-esmAssets Changed:
Files in
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #225 +/- ##
==========================================
+ Coverage 97.07% 97.14% +0.06%
==========================================
Files 2 2
Lines 376 385 +9
Branches 136 137 +1
==========================================
+ Hits 365 374 +9
Misses 10 10
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the selector formatting code to improve clarity and maintainability by breaking down complex functions into smaller, more focused utilities with clear responsibilities and comprehensive documentation.
Key Changes
Renamed and documented core functions:
print_nth()→print_an_plus_b()with JSDoc explaining the An+B microsyntaxprint_simple_selector()→print_selector_component()to better reflect its role in printing individual selector partsprint_inline_selector_list()→print_selector_list()for consistencyprint_selector_list()(internal) →print_rule_selectors()to distinguish from the exported functionExtracted specialized formatting functions:
print_combinator()- Handles combinator printing (,>,+,~,||) with special logic for descendant combinatorsprint_attribute_selector()- Dedicated function for attribute selector formatting (e.g.,[href^="https://" i])print_pseudo_selector()- Handles pseudo-class and pseudo-element formatting with support for functional formsprint_selector_argument()- Prints individual items in comma-separated selector positions, handling special forms like:nth-child(2n+1 of .foo)print_selector()- Prints a complete complex selectorImproved code organization:
Updated imports:
CombinatorandAttributeSelectortype imports for better type safetyNotable Implementation Details
print_combinator()function preserves descendant combinators (whitespace-only) as single spaces even when minifying, preventing selector mergingprint_pseudo_selector()function handles both legacy pseudo-elements (before,after) and actual pseudo-elements with appropriate double-colon syntaxprint_selector_argument()function acts as a dispatcher for different selector argument types (nth, nth-of, lang, or regular selectors)https://claude.ai/code/session_01K2xJ3CLyZ8QvobBkwyNG1k