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

feat(styled-components): Implement minification #235

Merged
merged 25 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
494d891
implement minify
ciffelia Nov 21, 2023
4141a1a
enable disabled test fixtures for minify
ciffelia Nov 21, 2023
9131eec
replace .babelrc with config.json
ciffelia Nov 21, 2023
4f96bd4
update test fixtures output
ciffelia Nov 21, 2023
07b438c
Merge branch 'main' into feat-styled-components-minify
kdy1 Nov 22, 2023
ccee7bc
Bump npm package: ./packages/constify
kdy1 Nov 23, 2023
f5ad940
Bump npm package: ./packages/emotion
kdy1 Nov 23, 2023
8e65dca
Bump npm package: ./packages/jest
kdy1 Nov 23, 2023
3ad2e34
Bump npm package: ./packages/loadable-components
kdy1 Nov 23, 2023
2574045
Bump npm package: ./packages/noop
kdy1 Nov 23, 2023
0bbb0f8
Bump npm package: ./packages/react-remove-properties
kdy1 Nov 23, 2023
f69cf46
Bump npm package: ./packages/relay
kdy1 Nov 23, 2023
c2e7aeb
Bump npm package: ./packages/remove-console
kdy1 Nov 23, 2023
1a1fefe
Bump npm package: ./packages/styled-components
kdy1 Nov 23, 2023
8ed7e1c
Bump npm package: ./packages/styled-jsx
kdy1 Nov 23, 2023
2b81976
Bump npm package: ./packages/swc-magic
kdy1 Nov 23, 2023
bc0f2cd
Bump npm package: ./packages/transform-imports
kdy1 Nov 23, 2023
e5e694e
Bump cargo crate: react_remove_properties
kdy1 Nov 23, 2023
168a428
Bump cargo crate: remove_console
kdy1 Nov 23, 2023
7738f5b
Bump cargo crate: styled_components
kdy1 Nov 23, 2023
f053758
Bump cargo crate: styled_jsx
kdy1 Nov 23, 2023
7f18c2d
Bump cargo crate: swc_constify
kdy1 Nov 23, 2023
8770611
Bump cargo crate: swc_emotion
kdy1 Nov 23, 2023
227c297
Bump cargo crate: swc_magic
kdy1 Nov 23, 2023
e412f28
Bump cargo crate: swc_relay
kdy1 Nov 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-constify",
"version": "0.1.29",
"version": "0.1.30",
"description": "SWC plugin for optimization",
"main": "swc_plugin_constify.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/constify/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_constify"
repository = "https://github.com/swc-project/plugins.git"
version = "0.24.0"
version = "0.25.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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-emotion",
"version": "2.5.99",
"version": "2.5.100",
"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.60.0"
version = "0.61.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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-jest",
"version": "1.5.99",
"version": "1.5.100",
"description": "SWC plugin for jest",
"main": "swc_plugin_jest.wasm",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/loadable-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-loadable-components",
"version": "0.3.99",
"version": "0.3.100",
"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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-noop",
"version": "1.5.97",
"version": "1.5.98",
"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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-react-remove-properties",
"version": "1.5.99",
"version": "1.5.100",
"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
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.12.0"
version = "0.13.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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-relay",
"version": "1.5.99",
"version": "1.5.100",
"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
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.32.0"
version = "0.33.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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-remove-console",
"version": "1.5.99",
"version": "1.5.100",
"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
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.13.0"
version = "0.14.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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swc/plugin-styled-components",
"version": "1.5.99",
"version": "1.5.100",
"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
Original file line number Diff line number Diff line change
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.84.0"
version = "0.85.0"

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

Expand Down
10 changes: 8 additions & 2 deletions packages/styled-components/transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use swc_ecma_visit::{Fold, VisitMut};
pub use crate::{
utils::{analyze, analyzer, State},
visitors::{
display_name_and_id::display_name_and_id, transpile_css_prop::transpile::transpile_css_prop,
display_name_and_id::display_name_and_id, minify::visitor::minify,
transpile_css_prop::transpile::transpile_css_prop,
},
};

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

/// NOTE: **This is not complete**.
///
/// Only [analyzer] and [display_name_and_id] is implemented.
/// Only [transpile_css_prop], [minify] and [display_name_and_id] is
/// implemented.
pub fn styled_components(
file_name: FileName,
src_file_hash: u128,
Expand All @@ -86,6 +88,10 @@ pub fn styled_components(
enabled: config.css_prop,
visitor: transpile_css_prop(state.clone())
},
Optional {
enabled: config.minify,
visitor: minify(state.clone())
},
display_name_and_id(file_name, src_file_hash, config.clone(), state)
)
}
2 changes: 1 addition & 1 deletion packages/styled-components/transform/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl State {
self.imported_local_name = Some(id);
}

fn is_helper(&self, e: &Expr) -> bool {
pub(crate) fn is_helper(&self, e: &Expr) -> bool {
self.is_create_global_style_helper(e)
|| self.is_css_helper(e)
|| self.is_inject_global_helper(e)
Expand Down

This file was deleted.