-
-
Notifications
You must be signed in to change notification settings - Fork 722
fix(transformer/styled-components): remove unnecessary whitespace when removing block comments in CSS minification #13390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #13390 will degrade performances by 11.86%Comparing Summary
Benchmarks breakdown
Footnotes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes CSS minification issues in the styled-components transformer related to block comment handling. It removes unnecessary spaces when removing block comments after certain characters while preserving necessary spaces when comments separate interpolations.
- Simplifies comment removal logic by treating comments as whitespace
- Fixes unnecessary space insertion after characters like
{when removing comments - Ensures proper spacing between interpolations when comments are the only content between them
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
crates/oxc_transformer/src/plugins/styled_components.rs |
Refactored comment removal logic to use insert_space_if_required function consistently |
tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-comments/input.js |
Added test cases with comments after { character |
tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-comments/output.js |
Updated expected output to show proper minification without unnecessary spaces |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Merge activity
|
…n removing block comments in CSS minification (#13390) Remove special logic for inserting spaces when removing comments. Instead, treat comments as equivalent to whitespace, and apply the same rules. This fixes 2 problems: 1. Don't add unnecessary space when a block comment appears after a character like `{`. 2. *Do* add a space when a block comment is the whole quasi between 2 interpolations, to prevent them being merged. Simplifying this logic also gives 1%-2% speed-up on transformer benchmarks. Input: ```js styled.div`.a {/* blah */color: green; }`; styled.div`${x}/* blah */${y}`; ``` Previous output post-minification: ```js styled.div`.a{ color:green;}`; styled.div`${x}${y}`; ``` After this PR: ```js styled.div`.a{color:green;}`; styled.div`${x} ${y}`; ```
ac79d7a to
cf5175c
Compare

Remove special logic for inserting spaces when removing comments. Instead, treat comments as equivalent to whitespace, and apply the same rules.
This fixes 2 problems:
{.Simplifying this logic also gives 1%-2% speed-up on transformer benchmarks.
Input:
Previous output post-minification:
After this PR: