Skip to content

Commit fbb8ccc

Browse files
committed
fix(transformer/styled-components): do not insert space when removing block comments in CSS minification
1 parent 17636b0 commit fbb8ccc

File tree

3 files changed

+7
-32
lines changed

3 files changed

+7
-32
lines changed

crates/oxc_transformer/src/plugins/styled_components.rs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -920,26 +920,11 @@ fn minify_template_literal<'a>(lit: &mut TemplateLiteral<'a>, ast: AstBuilder<'a
920920

921921
// Find end of comment
922922
let start_index = if is_block_comment {
923-
let Some(mut pos) = bytes.windows(2).position(|q| q == b"*/") else {
923+
let Some(pos) = bytes.windows(2).position(|q| q == b"*/") else {
924924
// Comment contains whole of this quasi
925925
continue;
926926
};
927-
928-
pos += 2;
929-
if pos == bytes.len() {
930-
// Comment ends at end of quasi
931-
comment_type = None;
932-
continue;
933-
}
934-
935-
// Add a space when this is a own line block comment
936-
if !bytes[pos].is_ascii_whitespace()
937-
&& output.last().is_some_and(|&last| last != b' ')
938-
{
939-
output.push(b' ');
940-
}
941-
942-
pos
927+
pos + 2
943928
} else {
944929
let Some(pos) = bytes.iter().position(|&b| matches!(b, b'\n' | b'\r')) else {
945930
// Comment contains whole of this quasi
@@ -1019,18 +1004,6 @@ fn minify_template_literal<'a>(lit: &mut TemplateLiteral<'a>, ast: AstBuilder<'a
10191004
bytes[i + 2..].windows(2).position(|q| q == b"*/");
10201005
if let Some(end_index) = end_index {
10211006
i += end_index + 4; // After `*/`
1022-
1023-
if i == bytes.len() {
1024-
// Comment ends at end of quasi
1025-
break;
1026-
}
1027-
1028-
// Add a space when this is a own line block comment
1029-
if !bytes[i].is_ascii_whitespace()
1030-
&& output.last().is_some_and(|&last| last != b' ')
1031-
{
1032-
output.push(b' ');
1033-
}
10341007
continue;
10351008
}
10361009

@@ -1223,7 +1196,7 @@ mod tests {
12231196
#[test]
12241197
fn removes_multi_line_comments() {
12251198
let input = "this is a/* ignore me please */test";
1226-
let expected = "this is a test";
1199+
let expected = "this is atest";
12271200
let actual = minify_raw(input);
12281201
debug_assert_eq!(actual, expected);
12291202
}

tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-comments/input.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ const Bar = styled.div`
1414

1515
const Qux = styled.div`
1616
color: /* blah */ red;
17+
width/* big */: 1000px;
1718
.a /* blah */ { color: blue; }
1819
`;
1920

2021
const Bing = styled.div`
2122
color: /* ${123} */ red;
23+
width/* ${'big'} */: 1000px;
2224
.a /* ${123} */ { color: blue; }
2325
`;

tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-comments/output.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import styled from 'styled-components';
22
const Button = styled.div`${x}${z}`;
33
const Foo = styled.div`.a{color:red;}`;
44
const Bar = styled.div`.a{color:red;}`;
5-
const Qux = styled.div`color:red;.a{color:blue;}`;
6-
const Bing = styled.div`color:red;.a{color:blue;}`;
5+
const Qux = styled.div`color:red;width:1000px;.a{color:blue;}`;
6+
const Bing = styled.div`color:red;width:1000px;.a{color:blue;}`;

0 commit comments

Comments
 (0)