Skip to content

perf: shorten some print functons && use string concat directly in some places#179

Merged
bartveneman merged 1 commit intomainfrom
claude/reduce-bundle-size-50hA8
Mar 23, 2026
Merged

perf: shorten some print functons && use string concat directly in some places#179
bartveneman merged 1 commit intomainfrom
claude/reduce-bundle-size-50hA8

Conversation

@bartveneman
Copy link
Member

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 rules
  • print_declaration(): Changed important from array to string, simplified the logic for extracting and formatting the !important flag
  • print_nth(): Replaced parts array with direct string concatenation and template literals
  • print_nth_of(): Converted from array building to direct string concatenation
  • print_compound_selector(): Simplified to use map().join() instead of manual forEach loop
  • print_rule(): Moved block_has_content calculation to the top to avoid duplication, simplified block rendering logic
  • print_atrule(): Refactored name building from array to string concatenation, consolidated block_has_content logic to avoid recalculation, simplified return statements

Notable Implementation Details

  • All changes maintain the exact same output formatting and CSS specification compliance
  • The refactoring reduces intermediate array allocations and simplifies control flow
  • Comments explaining CSS specification requirements (e.g., spacing around + and - operators) are preserved

https://claude.ai/code/session_01P6rhwrSj4m7rKSqqsPUqgz

…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
@codecov
Copy link

codecov bot commented Mar 22, 2026

Bundle Report

Changes will decrease total bundle size by 472 bytes (-1.72%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
formatCss-esm 12.93kB -472 bytes (-3.52%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: formatCss-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.js -472 bytes 12.37kB -3.68%

Files in index.js:

  • ./src/lib/index.ts → Total Size: 12.24kB

@codecov
Copy link

codecov bot commented Mar 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.78%. Comparing base (be22838) to head (dcb7d92).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bartveneman bartveneman changed the title Refactor string building to use direct concatenation instead of arrays Shorten some print functons && use string concat directly in some places Mar 23, 2026
@bartveneman bartveneman changed the title Shorten some print functons && use string concat directly in some places perf: shorten some print functons && use string concat directly in some places Mar 23, 2026
@bartveneman bartveneman merged commit fd197fe into main Mar 23, 2026
7 of 8 checks passed
@bartveneman bartveneman deleted the claude/reduce-bundle-size-50hA8 branch March 23, 2026 11:51
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.

2 participants