Skip to content
Merged
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
6 changes: 6 additions & 0 deletions crates/oxc_transformer/src/plugins/styled_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,12 @@ fn minify_template_literal<'a>(lit: &mut TemplateLiteral<'a>, ast: AstBuilder<'a
}
// Skip line comments, but be careful not to break URLs like `https://...`
b'/' if paren_depth == 0 && (i == 0 || bytes[i - 1] != b':') => {
// Remove trailing space before comment.
// Comment will end with a line break, so space will be added again if required.
if output.last().is_some_and(|&last| last == b' ') {
output.pop();
}

let end_index =
bytes[i + 2..].iter().position(|&b| matches!(b, b'\n' | b'\r'));
if let Some(end_index) = end_index {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import styled from 'styled-components';

const Button = styled.div`${x}/* ${y} */${z}`;

const Foo = styled.div`
.a // comment
{ color: red; }
`;

const Bar = styled.div`
.a // ${123}
{ color: red; }
`;
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
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;}`;
Loading