Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(emotion): Convert css input from raw template literal to a string value first #260

Merged
merged 9 commits into from
Jan 31, 2024
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
40 changes: 20 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Plugins for SWC, written in Rust
- [`jest`](packages/jest)
- [`loadable-components`](packages/loadable-components)
- [`noop`](packages/noop) for testing Wasm plugin system itself
- [`loadable-components`](packages/loadable-components)
- [`react-remove-properties`](packages/react-remove-properties)
- [`relay`](packages/relay)
- [`remove-console`](packages/remove-console)
Expand Down
6 changes: 6 additions & 0 deletions packages/emotion/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @swc/plugin-emotion

## 2.5.116

### Patch Changes

- 47db290: Fix string escaping issue

## 2.5.115

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/emotion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_plugin_emotion"
publish = false
version = "0.18.2"
version = "0.18.3"

[lib]
crate-type = ["cdylib", "rlib"]
Expand Down
6 changes: 6 additions & 0 deletions packages/emotion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ Source code for plugin itself (not transforms) are copied from https://github.co

# @swc/plugin-emotion

## 2.5.116

### Patch Changes

- 47db290: Fix string escaping issue

## 2.5.115

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/emotion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-emotion",
"version": "2.5.115",
"version": "2.5.116",
"description": "SWC plugin for emotion css-in-js library",
"main": "swc_plugin_emotion.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/emotion/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_emotion"
repository = "https://github.com/swc-project/plugins.git"
version = "0.72.1"
version = "0.72.2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
14 changes: 13 additions & 1 deletion packages/emotion/transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,19 @@ impl<C: Comments> EmotionTransformer<C> {
if index % 2 == 0 {
if let Some(q) = tagged_tpl.quasis.get_mut(i) {
let q = q.take();
let minified = minify_css_string(&q.raw, index == 0, index == args_len - 1);
let css_input = q
.raw
.replace("\\`", "`")
.replace("\\$", "$")
.replace("\\b", "\u{0008}")
.replace("\\f", "\u{000C}")
.replace("\\n", "\n")
.replace("\\r", "\r")
.replace("\\t", "\t")
.replace("\\v", "\u{000B}")
.replace("\\\\", "\\");

let minified = minify_css_string(&css_input, index == 0, index == args_len - 1);
// Compress one more spaces into one space
if minified.replace(' ', "").is_empty() {
if index != 0 && index != args_len - 1 {
Expand Down
26 changes: 26 additions & 0 deletions packages/emotion/transform/tests/fixture/next/40385/1/input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import styled from "@emotion/styled";

export default function IndexPage() {
return (
<>
<h1>IndexPage</h1>
<IconWrapper className={"icon-chat"} />
<IconWrapper className={"icon-check"} />
</>
);
}

const IconWrapper = styled.div`
&[class^="icon-"],
[class*=" icon-"] {
color: red;
}

&.icon-chat:before {
content: "\\e904";
}

&.icon-check:before {
content: "\\e905";
}
`;
21 changes: 21 additions & 0 deletions packages/emotion/transform/tests/fixture/next/40385/1/output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import styled from "@emotion/styled";
export default function IndexPage() {
return /*#__PURE__*/ _jsxs(_Fragment, {
children: [
/*#__PURE__*/ _jsx("h1", {
children: "IndexPage"
}),
/*#__PURE__*/ _jsx(IconWrapper, {
className: "icon-chat"
}),
/*#__PURE__*/ _jsx(IconWrapper, {
className: "icon-check"
})
]
});
}
const IconWrapper = /*#__PURE__*/ styled("div", {
target: "ewuh3ed0",
label: "IconWrapper"
})('&[class^="icon-"],[class*=" icon-"]{color:red;}&.icon-chat:before{content:"\\e904";}&.icon-check:before{content:"\\e905";}', "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQudHMiLCJzb3VyY2VzIjpbImlucHV0LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBzdHlsZWQgZnJvbSBcIkBlbW90aW9uL3N0eWxlZFwiO1xuXG5leHBvcnQgZGVmYXVsdCBmdW5jdGlvbiBJbmRleFBhZ2UoKSB7XG4gIHJldHVybiAoXG4gICAgPD5cbiAgICAgIDxoMT5JbmRleFBhZ2U8L2gxPlxuICAgICAgPEljb25XcmFwcGVyIGNsYXNzTmFtZT17XCJpY29uLWNoYXRcIn0gLz5cbiAgICAgIDxJY29uV3JhcHBlciBjbGFzc05hbWU9e1wiaWNvbi1jaGVja1wifSAvPlxuICAgIDwvPlxuICApO1xufVxuXG5jb25zdCBJY29uV3JhcHBlciA9IHN0eWxlZC5kaXZgXG4gICZbY2xhc3NePVwiaWNvbi1cIl0sXG4gIFtjbGFzcyo9XCIgaWNvbi1cIl0ge1xuICAgIGNvbG9yOiByZWQ7XG4gIH1cblxuICAmLmljb24tY2hhdDpiZWZvcmUge1xuICAgIGNvbnRlbnQ6IFwiXFxcXGU5MDRcIjtcbiAgfVxuXG4gICYuaWNvbi1jaGVjazpiZWZvcmUge1xuICAgIGNvbnRlbnQ6IFwiXFxcXGU5MDVcIjtcbiAgfVxuYDtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFZb0IifQ== */");
2 changes: 1 addition & 1 deletion packages/jest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_plugin_jest"
publish = false
version = "0.31.1"
version = "0.31.2"

[lib]
crate-type = ["cdylib", "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion packages/loadable-components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_plugin_loadable_components"
publish = false
version = "0.18.1"
version = "0.18.2"

[lib]
crate-type = ["cdylib", "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion packages/noop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_plugin_noop"
publish = false
version = "0.18.1"
version = "0.18.2"

[lib]
crate-type = ["cdylib", "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion packages/react-remove-properties/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_plugin_react_remove_properties"
publish = false
version = "0.19.1"
version = "0.19.2"

[lib]
crate-type = ["cdylib", "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion packages/react-remove-properties/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "react_remove_properties"
repository = "https://github.com/swc-project/plugins.git"
version = "0.24.1"
version = "0.24.2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion packages/relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_plugin_relay"
publish = false
version = "0.7.1"
version = "0.7.2"

[lib]
crate-type = ["cdylib", "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_relay"
repository = "https://github.com/swc-project/plugins.git"
version = "0.44.1"
version = "0.44.2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion packages/remove-console/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_plugin_remove_console"
publish = false
version = "0.19.1"
version = "0.19.2"

[lib]
crate-type = ["cdylib", "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion packages/remove-console/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "remove_console"
repository = "https://github.com/swc-project/plugins.git"
version = "0.25.1"
version = "0.25.2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion packages/styled-components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_plugin_styled_components"
publish = false
version = "0.40.1"
version = "0.40.2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
Expand Down
Loading
Loading