diff --git a/crates/oxc_transformer/src/plugins/styled_components.rs b/crates/oxc_transformer/src/plugins/styled_components.rs index 967a4a41fbe25..2f80bc17e3ef6 100644 --- a/crates/oxc_transformer/src/plugins/styled_components.rs +++ b/crates/oxc_transformer/src/plugins/styled_components.rs @@ -989,9 +989,7 @@ fn minify_template_literal<'a>(lit: &mut TemplateLiteral<'a>, ast: AstBuilder<'a continue; } b'n' | b'r' if string_quote == NOT_IN_STRING => { - if output.last().is_some_and(|&last| last != b' ') { - output.push(b' '); - } + insert_space_if_required(&mut output, quasi_index); i += 2; continue; } diff --git a/tasks/transform_conformance/snapshots/oxc.snap.md b/tasks/transform_conformance/snapshots/oxc.snap.md index 91bb1f304cf39..91c1d9a0a006f 100644 --- a/tasks/transform_conformance/snapshots/oxc.snap.md +++ b/tasks/transform_conformance/snapshots/oxc.snap.md @@ -1,6 +1,6 @@ commit: 41d96516 -Passed: 185/308 +Passed: 186/309 # All Passed: * babel-plugin-transform-class-static-block @@ -1612,7 +1612,7 @@ after transform: ["Function", "babelHelpers"] rebuilt : ["babelHelpers", "dec"] -# plugin-styled-components (23/38) +# plugin-styled-components (24/39) * minify-comments/input.js Unresolved references mismatch: after transform: ["x", "y", "z"] diff --git a/tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-escaped-line-breaks/input.js b/tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-escaped-line-breaks/input.js new file mode 100644 index 0000000000000..3ca2d6ab6e0d3 --- /dev/null +++ b/tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-escaped-line-breaks/input.js @@ -0,0 +1,18 @@ +import styled from 'styled-components'; + +// Leading or trailing line breaks +const A = styled.div`\r\ncolor: blue;\r\n`; + +// Line breaks in removal position +const B = styled.div` + color:\r\nblue; + .a\r\n{\r\n} +`; + +// Line breaks in non-removal position +const C = styled.div`thing\r\n:hover;`; + +// Line breaks before and after interpolations +const D = styled.div` + foo\r\n${'blue'}\r\n:blah; +`; diff --git a/tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-escaped-line-breaks/options.json b/tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-escaped-line-breaks/options.json new file mode 100644 index 0000000000000..92abfec80959e --- /dev/null +++ b/tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-escaped-line-breaks/options.json @@ -0,0 +1,18 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "modules": false, + "targets": "defaults" + } + ] + ], + "plugins": [ + ["styled-components", { + "ssr": false, + "displayName": false, + "transpileTemplateLiterals": false + }] + ] +} diff --git a/tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-escaped-line-breaks/output.js b/tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-escaped-line-breaks/output.js new file mode 100644 index 0000000000000..af3a6a93c9c55 --- /dev/null +++ b/tasks/transform_conformance/tests/plugin-styled-components/test/fixtures/minify-escaped-line-breaks/output.js @@ -0,0 +1,5 @@ +import styled from 'styled-components'; +const A = styled.div`color:blue;`; +const B = styled.div`color:blue;.a{}`; +const C = styled.div`thing :hover;`; +const D = styled.div`foo ${'blue'} :blah;`;