Skip to content

Commit

Permalink
feat(styled-components): Implement transpileTemplateLiterals (swc-p…
Browse files Browse the repository at this point in the history
…roject#237)

This implements `transpileTemplateLiterals` option in styled-components plugin.

cf. vercel/next.js#30802
  • Loading branch information
ciffelia committed Nov 25, 2023
1 parent f3d55f4 commit 1fd7c3d
Show file tree
Hide file tree
Showing 34 changed files with 291 additions and 135 deletions.
47 changes: 23 additions & 24 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion packages/constify/package.json
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-constify",
"version": "0.1.31",
"version": "0.1.32",
"description": "SWC plugin for optimization",
"main": "swc_plugin_constify.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/constify/transform/Cargo.toml
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_constify"
repository = "https://github.com/swc-project/plugins.git"
version = "0.26.0"
version = "0.27.0"

# 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/emotion/package.json
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-emotion",
"version": "2.5.101",
"version": "2.5.102",
"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
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.62.0"
version = "0.63.0"

# 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/jest/package.json
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-jest",
"version": "1.5.101",
"version": "1.5.102",
"description": "SWC plugin for jest",
"main": "swc_plugin_jest.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/loadable-components/package.json
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-loadable-components",
"version": "0.3.101",
"version": "0.3.102",
"description": "SWC plugin for `@loadable/components`",
"main": "swc_plugin_loadable_components.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/noop/package.json
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-noop",
"version": "1.5.99",
"version": "1.5.100",
"description": "Noop SWC plugin, for debugging",
"main": "swc_plugin_noop.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-remove-properties/package.json
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-react-remove-properties",
"version": "1.5.101",
"version": "1.5.102",
"description": "SWC plugin for https://www.npmjs.com/package/babel-plugin-react-remove-properties",
"main": "swc_plugin_react_remove_properties.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-remove-properties/transform/Cargo.toml
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.14.0"
version = "0.15.0"

# 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/package.json
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-relay",
"version": "1.5.101",
"version": "1.5.102",
"description": "SWC plugin for relay",
"main": "swc_plugin_relay.wasm",
"types": "./types.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/transform/Cargo.toml
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.34.0"
version = "0.35.0"

# 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/package.json
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-remove-console",
"version": "1.5.101",
"version": "1.5.102",
"description": "SWC plugin for https://www.npmjs.com/package/babel-plugin-remove-console",
"main": "swc_plugin_remove_console.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/remove-console/transform/Cargo.toml
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.15.0"
version = "0.16.0"

# 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/package.json
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-styled-components",
"version": "1.5.101",
"version": "1.5.102",
"description": "SWC plugin for styled-components",
"main": "swc_plugin_styled_components.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/styled-components/transform/Cargo.toml
Expand Up @@ -6,7 +6,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0"
name = "styled_components"
repository = "https://github.com/swc-project/plugins.git"
version = "0.86.0"
version = "0.87.0"

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

Expand Down
11 changes: 7 additions & 4 deletions packages/styled-components/transform/src/lib.rs
Expand Up @@ -11,7 +11,7 @@ pub use crate::{
utils::{analyze, analyzer, State},
visitors::{
display_name_and_id::display_name_and_id, minify::visitor::minify,
transpile_css_prop::transpile::transpile_css_prop,
template_literals::template_literals, transpile_css_prop::transpile::transpile_css_prop,
},
};

Expand Down Expand Up @@ -72,8 +72,7 @@ impl Config {

/// NOTE: **This is not complete**.
///
/// Only [transpile_css_prop], [minify] and [display_name_and_id] is
/// implemented.
/// [pure] is not implemented.
pub fn styled_components(
file_name: FileName,
src_file_hash: u128,
Expand All @@ -92,6 +91,10 @@ pub fn styled_components(
enabled: config.minify,
visitor: minify(state.clone())
},
display_name_and_id(file_name, src_file_hash, config.clone(), state)
display_name_and_id(file_name, src_file_hash, config.clone(), state.clone()),
Optional {
enabled: config.transpile_template_literals,
visitor: template_literals(state)
}
)
}
1 change: 1 addition & 0 deletions packages/styled-components/transform/src/visitors/mod.rs
@@ -1,4 +1,5 @@
pub mod assign_style_required;
pub mod display_name_and_id;
pub mod minify;
pub mod template_literals;
pub mod transpile_css_prop;

0 comments on commit 1fd7c3d

Please sign in to comment.