perf: shorten some print functons && use string concat directly in some places#179
Merged
bartveneman merged 1 commit intomainfrom Mar 23, 2026
Merged
Conversation
…ng logic - print_operator: replace array build+join with direct string concat - print_declaration: replace important[] array with a single string variable - print_nth/print_nth_of: replace array build+join with string concat - print_selector: replace forEach+push with map+join (one-liner) - print_atrule: replace name[] and lines[] arrays with string concat; deduplicate block_has_content computation - print_rule: deduplicate block_has_content computation (was computed twice with identical expressions) Net: -46 source lines, fewer array allocations at runtime https://claude.ai/code/session_01P6rhwrSj4m7rKSqqsPUqgz
Bundle ReportChanges will decrease total bundle size by 472 bytes (-1.72%) ⬇️. This is within the configured threshold ✅ Detailed changes
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 #179 +/- ##
==========================================
- Coverage 96.98% 96.78% -0.21%
==========================================
Files 2 2
Lines 365 342 -23
Branches 124 119 -5
==========================================
- Hits 354 331 -23
Misses 10 10
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 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 multiple string-building operations throughout the CSS formatter to use direct string concatenation instead of building arrays and joining them. This simplifies the code and improves readability while maintaining the same functionality.
Key Changes
print_operator(): Replaced array-based building with direct concatenation using ternary operators to determine spacing rulesprint_declaration(): Changedimportantfrom array to string, simplified the logic for extracting and formatting the!importantflagprint_nth(): Replaced parts array with direct string concatenation and template literalsprint_nth_of(): Converted from array building to direct string concatenationprint_compound_selector(): Simplified to usemap().join()instead of manual forEach loopprint_rule(): Movedblock_has_contentcalculation to the top to avoid duplication, simplified block rendering logicprint_atrule(): Refactored name building from array to string concatenation, consolidatedblock_has_contentlogic to avoid recalculation, simplified return statementsNotable Implementation Details
+and-operators) are preservedhttps://claude.ai/code/session_01P6rhwrSj4m7rKSqqsPUqgz