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
13 changes: 11 additions & 2 deletions crates/oxc_transformer/src/plugins/styled_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,16 @@ fn minify_template_literal<'a>(lit: &mut TemplateLiteral<'a>, ast: AstBuilder<'a
}
// Skip and compress whitespace.
_ if cur_byte.is_ascii_whitespace() => {
i += 1;
// Consume any following whitespace
let mut next_byte;
loop {
i += 1;
next_byte = bytes.get(i);
if next_byte.is_none_or(|&b| !b.is_ascii_whitespace()) {
break;
}
}

// Decide whether to preserve this whitespace character.
// CSS allows removing spaces around certain delimiters without changing meaning:
// - `color: red` -> `color:red` (spaces around colons)
Expand All @@ -1085,7 +1094,7 @@ fn minify_template_literal<'a>(lit: &mut TemplateLiteral<'a>, ast: AstBuilder<'a
// are significant in CSS. ` :hover` (descendant pseudo-selector) is different
// from `:hover` (direct pseudo-selector). Example: `.parent :hover` selects any
// hovered descendant, while `.parent:hover` selects the parent when hovered.
&& bytes.get(i).is_none_or(|&next| !matches!(next, b'{' | b'}' | b',' | b';'))
&& next_byte.is_none_or(|&next| !matches!(next, b'{' | b'}' | b',' | b';'))
{
// Preserve this space character.
// Examples:
Expand Down
4 changes: 2 additions & 2 deletions tasks/transform_conformance/snapshots/oxc.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 41d96516

Passed: 183/306
Passed: 184/307

# All Passed:
* babel-plugin-transform-class-static-block
Expand Down Expand Up @@ -1612,7 +1612,7 @@ after transform: ["Function", "babelHelpers"]
rebuilt : ["babelHelpers", "dec"]


# plugin-styled-components (21/36)
# plugin-styled-components (22/37)
* styled-components/add-identifier-with-top-level-import-paths/input.js
x Output mismatch

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import styled from 'styled-components';

const A = styled.div`
.a { }
.b { }
.c
{
}
`;

const B = styled.div`
str: "x y";
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"targets": "defaults"
}
]
],
"plugins": [
["styled-components", {
"ssr": false,
"displayName": false,
"transpileTemplateLiterals": false
}]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import styled from 'styled-components';
const A = styled.div`.a{}.b{}.c{}`;
const B = styled.div`str:"x y";`;
Loading