Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 3 additions & 30 deletions crates/oxc_transformer/src/plugins/styled_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,26 +920,11 @@ fn minify_template_literal<'a>(lit: &mut TemplateLiteral<'a>, ast: AstBuilder<'a

// Find end of comment
let start_index = if is_block_comment {
let Some(mut pos) = bytes.windows(2).position(|q| q == b"*/") else {
let Some(pos) = bytes.windows(2).position(|q| q == b"*/") else {
// Comment contains whole of this quasi
continue;
};

pos += 2;
if pos == bytes.len() {
// Comment ends at end of quasi
comment_type = None;
continue;
}

// Add a space when this is a own line block comment
if !bytes[pos].is_ascii_whitespace()
&& output.last().is_some_and(|&last| last != b' ')
{
output.push(b' ');
}

pos
pos + 2
} else {
let Some(pos) = bytes.iter().position(|&b| matches!(b, b'\n' | b'\r')) else {
// Comment contains whole of this quasi
Expand Down Expand Up @@ -1019,18 +1004,6 @@ fn minify_template_literal<'a>(lit: &mut TemplateLiteral<'a>, ast: AstBuilder<'a
bytes[i + 2..].windows(2).position(|q| q == b"*/");
if let Some(end_index) = end_index {
i += end_index + 4; // After `*/`

if i == bytes.len() {
// Comment ends at end of quasi
break;
}

// Add a space when this is a own line block comment
if !bytes[i].is_ascii_whitespace()
&& output.last().is_some_and(|&last| last != b' ')
{
output.push(b' ');
}
continue;
}

Expand Down Expand Up @@ -1215,7 +1188,7 @@ mod tests {
#[test]
fn removes_multi_line_comments() {
let input = "this is a/* ignore me please */test";
let expected = "this is a test";
let expected = "this is atest";
let actual = minify_raw(input);
debug_assert_eq!(actual, expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ const Bar = styled.div`

const Qux = styled.div`
color: /* blah */ red;
width/* big */: 1000px;
.a /* blah */ { color: blue; }
`;

const Bing = styled.div`
color: /* ${123} */ red;
width/* ${'big'} */: 1000px;
.a /* ${123} */ { color: blue; }
`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import styled from 'styled-components';
const Button = styled.div`${x}${z}`;
const Foo = styled.div`.a{color:red;}`;
const Bar = styled.div`.a{color:red;}`;
const Qux = styled.div`color:red;.a{color:blue;}`;
const Bing = styled.div`color:red;.a{color:blue;}`;
const Qux = styled.div`color:red;width:1000px;.a{color:blue;}`;
const Bing = styled.div`color:red;width:1000px;.a{color:blue;}`;
Loading