diff --git a/Cargo.lock b/Cargo.lock index 9507a630f..525564b2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1716,7 +1716,7 @@ dependencies = [ [[package]] name = "react_remove_properties" -version = "0.12.0" +version = "0.13.0" dependencies = [ "serde", "swc_atoms", @@ -1791,7 +1791,7 @@ checksum = "c707298afce11da2efef2f600116fa93ffa7a032b5d7b628aa17711ec81383ca" [[package]] name = "remove_console" -version = "0.13.0" +version = "0.14.0" dependencies = [ "serde", "swc_atoms", @@ -2167,7 +2167,7 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "styled_components" -version = "0.84.0" +version = "0.85.0" dependencies = [ "Inflector", "once_cell", @@ -2188,7 +2188,7 @@ dependencies = [ [[package]] name = "styled_jsx" -version = "0.61.0" +version = "0.62.0" dependencies = [ "easy-error", "lightningcss", @@ -2330,7 +2330,7 @@ dependencies = [ [[package]] name = "swc_constify" -version = "0.24.0" +version = "0.25.0" dependencies = [ "once_cell", "rustc-hash", @@ -2795,7 +2795,7 @@ dependencies = [ [[package]] name = "swc_emotion" -version = "0.60.0" +version = "0.61.0" dependencies = [ "base64", "byteorder", @@ -2871,7 +2871,7 @@ dependencies = [ [[package]] name = "swc_magic" -version = "0.7.0" +version = "0.8.0" dependencies = [ "serde", "swc_atoms", @@ -3108,7 +3108,7 @@ dependencies = [ [[package]] name = "swc_relay" -version = "0.32.0" +version = "0.33.0" dependencies = [ "once_cell", "regex", diff --git a/packages/constify/package.json b/packages/constify/package.json index b5d0c6c25..d6917580d 100644 --- a/packages/constify/package.json +++ b/packages/constify/package.json @@ -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": { diff --git a/packages/constify/transform/Cargo.toml b/packages/constify/transform/Cargo.toml index d39e09d05..7a65e09a2 100644 --- a/packages/constify/transform/Cargo.toml +++ b/packages/constify/transform/Cargo.toml @@ -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 diff --git a/packages/emotion/package.json b/packages/emotion/package.json index 8f4e00caa..8dbc8334d 100644 --- a/packages/emotion/package.json +++ b/packages/emotion/package.json @@ -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": { diff --git a/packages/emotion/transform/Cargo.toml b/packages/emotion/transform/Cargo.toml index 37abf16d0..5220524ae 100644 --- a/packages/emotion/transform/Cargo.toml +++ b/packages/emotion/transform/Cargo.toml @@ -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 diff --git a/packages/jest/package.json b/packages/jest/package.json index 3f62d4c2c..1c4e4cd7c 100644 --- a/packages/jest/package.json +++ b/packages/jest/package.json @@ -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": { diff --git a/packages/loadable-components/package.json b/packages/loadable-components/package.json index 7c29dfeca..184362d31 100644 --- a/packages/loadable-components/package.json +++ b/packages/loadable-components/package.json @@ -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": { diff --git a/packages/noop/package.json b/packages/noop/package.json index 76b860256..84a9edcea 100644 --- a/packages/noop/package.json +++ b/packages/noop/package.json @@ -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": { diff --git a/packages/react-remove-properties/package.json b/packages/react-remove-properties/package.json index 94f45dc24..52f069d75 100644 --- a/packages/react-remove-properties/package.json +++ b/packages/react-remove-properties/package.json @@ -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": { diff --git a/packages/react-remove-properties/transform/Cargo.toml b/packages/react-remove-properties/transform/Cargo.toml index 2e73144f7..9d2e0b66d 100644 --- a/packages/react-remove-properties/transform/Cargo.toml +++ b/packages/react-remove-properties/transform/Cargo.toml @@ -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 diff --git a/packages/relay/package.json b/packages/relay/package.json index 871ee02f1..73c626abe 100644 --- a/packages/relay/package.json +++ b/packages/relay/package.json @@ -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", diff --git a/packages/relay/transform/Cargo.toml b/packages/relay/transform/Cargo.toml index d03792590..8d14826e2 100644 --- a/packages/relay/transform/Cargo.toml +++ b/packages/relay/transform/Cargo.toml @@ -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 diff --git a/packages/remove-console/package.json b/packages/remove-console/package.json index 67b13c654..109ee9f80 100644 --- a/packages/remove-console/package.json +++ b/packages/remove-console/package.json @@ -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": { diff --git a/packages/remove-console/transform/Cargo.toml b/packages/remove-console/transform/Cargo.toml index aa45fc92b..57180c3cd 100644 --- a/packages/remove-console/transform/Cargo.toml +++ b/packages/remove-console/transform/Cargo.toml @@ -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 diff --git a/packages/styled-components/package.json b/packages/styled-components/package.json index 03bae765e..8ac7616c1 100644 --- a/packages/styled-components/package.json +++ b/packages/styled-components/package.json @@ -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": { diff --git a/packages/styled-components/transform/Cargo.toml b/packages/styled-components/transform/Cargo.toml index 43da540b7..e174d6794 100644 --- a/packages/styled-components/transform/Cargo.toml +++ b/packages/styled-components/transform/Cargo.toml @@ -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 diff --git a/packages/styled-components/transform/src/lib.rs b/packages/styled-components/transform/src/lib.rs index b9b29fc2b..ee81cd464 100644 --- a/packages/styled-components/transform/src/lib.rs +++ b/packages/styled-components/transform/src/lib.rs @@ -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, }, }; @@ -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, @@ -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) ) } diff --git a/packages/styled-components/transform/src/utils/mod.rs b/packages/styled-components/transform/src/utils/mod.rs index 72593ea25..2050b33c4 100644 --- a/packages/styled-components/transform/src/utils/mod.rs +++ b/packages/styled-components/transform/src/utils/mod.rs @@ -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) diff --git a/packages/styled-components/transform/src/visitors/minify.rs b/packages/styled-components/transform/src/visitors/minify.rs deleted file mode 100644 index 8b1378917..000000000 --- a/packages/styled-components/transform/src/visitors/minify.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/styled-components/transform/src/visitors/minify/css.rs b/packages/styled-components/transform/src/visitors/minify/css.rs new file mode 100644 index 000000000..de929a066 --- /dev/null +++ b/packages/styled-components/transform/src/visitors/minify/css.rs @@ -0,0 +1,289 @@ +//! Port of https://github.com/styled-components/babel-plugin-styled-components/blob/4e2eb388d9c90f2921c306c760657d059d01a518/src/minify/index.js + +use std::collections::HashSet; + +use once_cell::sync::Lazy; +use regex::Regex; +use swc_atoms::Atom; + +use super::{ + css_placeholder::{make_placeholder, split_by_placeholders, PLACEHOLDER_REGEX}, + regex_util::split_keep, +}; + +fn inject_unique_placeholders(str_arr: impl IntoIterator>) -> String { + let mut result = String::new(); + + for (i, s) in str_arr.into_iter().enumerate() { + if i > 0 { + result.push_str(&make_placeholder(i - 1)); + } + result.push_str(s.as_ref()); + } + + result +} + +static LINEBREAK_REGEX_RAW: Lazy = + Lazy::new(|| Regex::new(r"(?:\\r|\\n|\r|\n)\s*").unwrap()); +static MULTILINE_COMMENT_REGEX: Lazy = + Lazy::new(|| Regex::new(r"(?s)/\*[^!].*?\*/").unwrap()); +static SYMBOL_REGEX: Lazy = Lazy::new(|| Regex::new(r"\s*[;:{},]\s*").unwrap()); + +/// Counts occurrences of a character inside string +fn count_occurrences(s: impl AsRef, c: char) -> usize { + s.as_ref().split(c).count() - 1 +} + +/// Joins substrings until predicate returns true +fn reduce_substr( + substrs: impl IntoIterator>, + join: impl AsRef, + predicate: impl Fn(&str) -> bool, +) -> String { + let mut res = "".to_string(); + + for (i, substr) in substrs.into_iter().enumerate() { + if i == 0 { + res.push_str(substr.as_ref()); + continue; + } + if predicate(&res) { + break; + } + res.push_str(join.as_ref()); + res.push_str(substr.as_ref()); + } + + res +} + +/// Joins at comment starts when it's inside a string or parentheses +/// effectively removing line comments +fn strip_line_comment(line: impl AsRef) -> String { + reduce_substr(line.as_ref().split("//"), "//", |str| { + !str.ends_with(':') // NOTE: This is another guard against urls, if they're not inside strings or parantheses. + && count_occurrences(str, '\'') % 2 == 0 + && count_occurrences(str, '"') % 2 == 0 + && count_occurrences(str, '(') == count_occurrences(str, ')') + }) +} + +fn compress_symbols(code: impl AsRef) -> String { + split_keep(&SYMBOL_REGEX, code.as_ref()) + .into_iter() + .enumerate() + .fold("".to_string(), |str, (index, fragment)| { + // Even-indices are non-symbol fragments + if index % 2 == 0 { + return str + fragment; + } + + // Only manipulate symbols outside of strings + if count_occurrences(&str, '\'') % 2 != 0 || count_occurrences(&str, '"') % 2 != 0 { + return str + fragment; + } + + // Preserve whitespace preceding colon, to avoid joining selectors. + if !fragment.starts_with(':') && fragment.trim_start().starts_with(':') { + return str + " " + fragment.trim(); + } + + str + fragment.trim() + }) +} + +/// Detects lines that are exclusively line comments +fn is_line_comment(s: impl AsRef) -> bool { + s.as_ref().trim_start().starts_with("//") +} + +/// Minifies a string of CSS code +fn minify(code: impl AsRef, linebreak_regex: &Regex) -> String { + // Remove multiline comments + let code = MULTILINE_COMMENT_REGEX.replace_all(code.as_ref(), "\n"); + + let code = linebreak_regex + .split(&code) // Split at newlines + .filter(|line| !line.is_empty() && !is_line_comment(line)) // Removes lines containing only line comments + .map(strip_line_comment) // Remove line comments inside text + .collect::>() + .join(" "); // Rejoin all lines + + compress_symbols(code) +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct MinifyResult { + pub values: Vec, + + /// Indices of expressions that are not eliminated (i.e. not in comments). + pub retained_expression_indices: HashSet, +} + +/// Minifies template literal quasis +fn minify_values( + values: impl IntoIterator>, + linebreak_regex: &Regex, +) -> MinifyResult { + let code = inject_unique_placeholders(values); + let minified_code = minify(code, linebreak_regex); + + let minified_values = split_by_placeholders(&minified_code) + .into_iter() + .map(Atom::from) + .collect(); + + let retained_expression_indices: HashSet = PLACEHOLDER_REGEX + .captures_iter(&minified_code) + .map(|captures| captures[1].parse().unwrap()) + .collect(); + + MinifyResult { + values: minified_values, + retained_expression_indices, + } +} + +pub fn minify_raw_values(values: impl IntoIterator) -> MinifyResult { + minify_values(values, &LINEBREAK_REGEX_RAW) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_inject_unique_placeholders() { + assert_eq!( + inject_unique_placeholders(vec!["a", "b", "c"]), + "a__PLACEHOLDER_0__b__PLACEHOLDER_1__c" + ); + } + + #[test] + fn test_count_occurrences() { + assert_eq!(count_occurrences("abbbcc", 'a'), 1); + assert_eq!(count_occurrences("abbbcc", 'b'), 3); + assert_eq!(count_occurrences("abbbcc", 'c'), 2); + assert_eq!(count_occurrences("abbbcc", 'd'), 0); + } + + #[test] + fn test_strip_line_comment() { + // splits a line by potential comment starts and joins until one is an actual + // comment + assert_eq!(strip_line_comment("abc def//ghi//jkl"), "abc def"); + + // ignores comment markers that are inside strings + assert_eq!( + strip_line_comment(r#"abc def"//"ghi'//'jkl//the end"#), + r#"abc def"//"ghi'//'jkl"# + ); + + // ignores comment markers that are inside parantheses + assert_eq!( + strip_line_comment(r#"bla (//) bla//the end"#), + r#"bla (//) bla"# + ); + + // ignores even unescaped URLs + assert_eq!( + strip_line_comment(r#"https://test.com// comment//"#), + r#"https://test.com"# + ); + } + + #[test] + fn test_compress_symbols() { + // removes spaces around symbols + // The whitespace preceding the colon is removed here as part of the + // trailing whitespace on the semi-colon. Contrast to the "preserves" + // test below. + assert_eq!(compress_symbols("; : { } , ; "), ";:{},;"); + + // ignores symbols inside strings + assert_eq!(compress_symbols(r#"; " : " ' : ' ;"#), r#";" : " ' : ';"#); + + // preserves whitespace preceding colons + assert_eq!( + compress_symbols(r#"& :last-child { color: blue; }"#), + r#"& :last-child{color:blue;}"# + ); + } + + #[test] + fn test_minify() { + fn test(description: &str, code: &str, expected: &str) { + // test minify() + assert_eq!( + minify(code, &LINEBREAK_REGEX_RAW), + expected, + "{}: minify", + description + ); + + // test minify_values() + assert_eq!( + minify_values(vec![code], &LINEBREAK_REGEX_RAW), + MinifyResult { + values: vec![expected.into()], + retained_expression_indices: HashSet::new(), + }, + "{}: minify_css_quasis", + description + ); + } + + test( + "Removes multi-line comments", + "this is a/* ignore me please */test", + "this is a test", + ); + + test( + "Joins all lines of code", + "this\nis\na/* ignore me \n please */\ntest", + "this is a test", + ); + + test( + "Removes line comments filling an entire line", + "line one\n// remove this comment\nline two", + "line one line two", + ); + + test( + "Removes line comments at the end of lines of code", + "valid line with // a comment\nout comments", + "valid line with out comments", + ); + + test( + "Preserves multi-line comments starting with /*!", + "this is a /*! dont ignore me please */ test/* but you can ignore me */", + "this is a /*! dont ignore me please */ test", + ); + + test( + "works with raw escape codes", + "this\\nis\\na/* ignore me \\n please */\\ntest", + "this is a test", + ); + } + + #[test] + fn test_minify_values() { + // Returns the indices of retained placeholders (expressions) + assert_eq!( + minify_values( + vec!["this is some\ninput with ", " and // ignored ", ""], + &LINEBREAK_REGEX_RAW + ), + MinifyResult { + values: vec!["this is some input with ".into(), " and ".into()], + retained_expression_indices: vec![0].into_iter().collect(), + } + ); + } +} diff --git a/packages/styled-components/transform/src/visitors/minify/css_placeholder.rs b/packages/styled-components/transform/src/visitors/minify/css_placeholder.rs new file mode 100644 index 000000000..8bccff4d7 --- /dev/null +++ b/packages/styled-components/transform/src/visitors/minify/css_placeholder.rs @@ -0,0 +1,15 @@ +//! Port of https://github.com/styled-components/babel-plugin-styled-components/blob/main/src/css/placeholderUtils.js + +use once_cell::sync::Lazy; +use regex::Regex; + +pub static PLACEHOLDER_REGEX: Lazy = + Lazy::new(|| Regex::new(r"__PLACEHOLDER_(\d+)__").unwrap()); + +pub fn make_placeholder(index: usize) -> String { + format!("__PLACEHOLDER_{}__", index) +} + +pub fn split_by_placeholders(input: &str) -> Vec<&str> { + PLACEHOLDER_REGEX.split(input).collect() +} diff --git a/packages/styled-components/transform/src/visitors/minify/mod.rs b/packages/styled-components/transform/src/visitors/minify/mod.rs new file mode 100644 index 000000000..ad7f7b424 --- /dev/null +++ b/packages/styled-components/transform/src/visitors/minify/mod.rs @@ -0,0 +1,4 @@ +mod css; +mod css_placeholder; +mod regex_util; +pub mod visitor; diff --git a/packages/styled-components/transform/src/visitors/minify/regex_util.rs b/packages/styled-components/transform/src/visitors/minify/regex_util.rs new file mode 100644 index 000000000..0beeb8565 --- /dev/null +++ b/packages/styled-components/transform/src/visitors/minify/regex_util.rs @@ -0,0 +1,33 @@ +use regex::Regex; + +/// Split string by regex, keeping the delimiters. +pub fn split_keep<'a>(r: &Regex, text: &'a str) -> Vec<&'a str> { + let mut result = Vec::new(); + let mut last = 0; + for m in r.find_iter(text) { + result.push(&text[last..m.start()]); + result.push(m.as_str()); + last = m.start() + m.len(); + } + result.push(&text[last..]); + result +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_split_keep() { + assert_eq!( + split_keep(&Regex::new("[ ,.]+").unwrap(), "this... is a, test"), + vec!["this", "... ", "is", " ", "a", ", ", "test"] + ); + + // Produces empty string when there are consecutive delimiters. + assert_eq!( + split_keep(&Regex::new("[.,]").unwrap(), ",.ab,."), + vec!["", ",", "", ".", "ab", ",", "", ".", ""] + ); + } +} diff --git a/packages/styled-components/transform/src/visitors/minify/visitor.rs b/packages/styled-components/transform/src/visitors/minify/visitor.rs new file mode 100644 index 000000000..fb9972d18 --- /dev/null +++ b/packages/styled-components/transform/src/visitors/minify/visitor.rs @@ -0,0 +1,68 @@ +//! Port of https://github.com/styled-components/babel-plugin-styled-components/blob/4e2eb388d9c90f2921c306c760657d059d01a518/src/visitors/minify.js + +use std::{cell::RefCell, rc::Rc}; + +use swc_common::DUMMY_SP; +use swc_ecma_ast::*; +use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; + +use super::css::{minify_raw_values, MinifyResult}; +use crate::utils::State; + +pub fn minify(state: Rc>) -> impl Fold + VisitMut { + as_folder(Minify { state }) +} + +#[derive(Debug)] +struct Minify { + state: Rc>, +} + +impl VisitMut for Minify { + noop_visit_mut_type!(); + + fn visit_mut_expr(&mut self, expr: &mut Expr) { + expr.visit_mut_children_with(self); + + let Expr::TaggedTpl(tagged) = expr else { + return; + }; + if !self.state.borrow().is_styled(&tagged.tag) + && !self.state.borrow().is_helper(&tagged.tag) + { + return; + } + + let MinifyResult { + values: raw_values_minified, + retained_expression_indices, + } = minify_raw_values(tagged.tpl.quasis.iter().map(|q| q.raw.clone())); + + tagged.tpl.quasis = raw_values_minified + .into_iter() + .map(|raw| TplElement { + span: DUMMY_SP, + tail: false, + // Omitting `cooked` field since swc_ecma_codegen doesn't use it. If this breaks + // other plugins, we may need to set some value. + // https://rustdoc.swc.rs/swc_ecma_ast/struct.TplElement.html#structfield.cooked + cooked: None, + raw, + }) + .collect(); + if let Some(q) = tagged.tpl.quasis.last_mut() { + q.tail = true; + } + + // Remove expressions that were removed by minification. + // NOTE: Here we assume that the expressions don't have side effects, as + // babel-plugin-styled-components does. + { + let mut idx: usize = 0; + tagged.tpl.exprs.retain(|_| { + idx += 1; + retained_expression_indices.contains(&(idx - 1)) + }); + } + } +} diff --git a/packages/styled-components/transform/tests/fixtures/.minify-css-to-use-with-transpilation/.babelrc b/packages/styled-components/transform/tests/fixtures/.minify-css-to-use-with-transpilation/.babelrc deleted file mode 100644 index 65e9aafd4..000000000 --- a/packages/styled-components/transform/tests/fixtures/.minify-css-to-use-with-transpilation/.babelrc +++ /dev/null @@ -1,15 +0,0 @@ -{ - "presets": [ - "@babel/preset-env" - ], - "plugins": [ - [ - "../../../src", - { - "ssr": false, - "displayName": false, - "transpileTemplateLiterals": false - } - ] - ] -} \ No newline at end of file diff --git a/packages/styled-components/transform/tests/fixtures/.minify-css-to-use-with-transpilation/output.js b/packages/styled-components/transform/tests/fixtures/.minify-css-to-use-with-transpilation/output.js deleted file mode 100644 index 9e95d2f24..000000000 --- a/packages/styled-components/transform/tests/fixtures/.minify-css-to-use-with-transpilation/output.js +++ /dev/null @@ -1,23 +0,0 @@ -"use strict"; - -var _styledComponents = _interopRequireDefault(require("styled-components")); - -var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } - -function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } - -var Simple = _styledComponents["default"].div(_templateObject || (_templateObject = _taggedTemplateLiteral(["width:100%;"]))); - -var Interpolation = _styledComponents["default"].div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["content:\" ", " \";"])), function (props) { - return props.text; -}); - -var SpecialCharacters = _styledComponents["default"].div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["content:\" ", " \";color:red;"])), function (props) { - return props.text; -}); - -var Comment = _styledComponents["default"].div(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["color:red;"]))); - -var Parens = _styledComponents["default"].div(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["&:hover{color:blue;}"]))); diff --git a/packages/styled-components/transform/tests/fixtures/.minify-css-to-use-without-transpilation/.babelrc b/packages/styled-components/transform/tests/fixtures/.minify-css-to-use-without-transpilation/.babelrc deleted file mode 100644 index e170b2be5..000000000 --- a/packages/styled-components/transform/tests/fixtures/.minify-css-to-use-without-transpilation/.babelrc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "plugins": [ - [ - "../../../src", - { - "ssr": false, - "displayName": false, - "transpileTemplateLiterals": false - } - ] - ] -} \ No newline at end of file diff --git a/packages/styled-components/transform/tests/fixtures/.minify-single-line-comments-with-interpolations/.babelrc b/packages/styled-components/transform/tests/fixtures/.minify-single-line-comments-with-interpolations/.babelrc deleted file mode 100644 index b64d0b655..000000000 --- a/packages/styled-components/transform/tests/fixtures/.minify-single-line-comments-with-interpolations/.babelrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "plugins": [ - [ - "../../../src", - { - "minify": true - } - ] - ] -} \ No newline at end of file diff --git a/packages/styled-components/transform/tests/fixtures/.minify-single-line-comments-with-interpolations/output.js b/packages/styled-components/transform/tests/fixtures/.minify-single-line-comments-with-interpolations/output.js deleted file mode 100644 index db4b692d8..000000000 --- a/packages/styled-components/transform/tests/fixtures/.minify-single-line-comments-with-interpolations/output.js +++ /dev/null @@ -1,29 +0,0 @@ -import styled from 'styled-components'; -const Test1 = styled.div.withConfig({ - displayName: "code__Test1", - componentId: "sc-kc0mjf-0" -})(["width:100%;"]); -const Test2 = styled.div.withConfig({ - displayName: "code__Test2", - componentId: "sc-kc0mjf-1" -})(["width:100%;"]); -const Test3 = styled.div.withConfig({ - displayName: "code__Test3", - componentId: "sc-kc0mjf-2" -})(["width:100%;", ";"], 'red'); -const Test4 = styled.div.withConfig({ - displayName: "code__Test4", - componentId: "sc-kc0mjf-3" -})(["width:100%;"]); -const Test5 = styled.div.withConfig({ - displayName: "code__Test5", - componentId: "sc-kc0mjf-4" -})(["width:100%;"]); -const Test6 = styled.div.withConfig({ - displayName: "code__Test6", - componentId: "sc-kc0mjf-5" -})(["background:url(\"https://google.com\");width:100%;", " "], 'green'); -const Test7 = styled.div.withConfig({ - displayName: "code__Test7", - componentId: "sc-kc0mjf-6" -})(["background:url(\"https://google.com\");width:", ";", " height:", ";"], p => p.props.width, 'green', p => p.props.height); diff --git a/packages/styled-components/transform/tests/fixtures/.minify-css-to-use-with-transpilation/code.js b/packages/styled-components/transform/tests/fixtures/minify-css-to-use-with-transpilation/code.js similarity index 100% rename from packages/styled-components/transform/tests/fixtures/.minify-css-to-use-with-transpilation/code.js rename to packages/styled-components/transform/tests/fixtures/minify-css-to-use-with-transpilation/code.js diff --git a/packages/styled-components/transform/tests/fixtures/minify-css-to-use-with-transpilation/config.json b/packages/styled-components/transform/tests/fixtures/minify-css-to-use-with-transpilation/config.json new file mode 100644 index 000000000..ea04750a8 --- /dev/null +++ b/packages/styled-components/transform/tests/fixtures/minify-css-to-use-with-transpilation/config.json @@ -0,0 +1,6 @@ +{ + "ssr": false, + "displayName": false, + "transpileTemplateLiterals": true, + "minify": true +} diff --git a/packages/styled-components/transform/tests/fixtures/minify-css-to-use-with-transpilation/output.js b/packages/styled-components/transform/tests/fixtures/minify-css-to-use-with-transpilation/output.js new file mode 100644 index 000000000..2b3112d1b --- /dev/null +++ b/packages/styled-components/transform/tests/fixtures/minify-css-to-use-with-transpilation/output.js @@ -0,0 +1,6 @@ +import styled from 'styled-components'; +const Simple = styled.div`width:100%;`; +const Interpolation = styled.div`content:" ${(props)=>props.text} ";`; +const SpecialCharacters = styled.div`content:" ${(props)=>props.text} ";color:red;`; +const Comment = styled.div`color:red;`; +const Parens = styled.div`&:hover{color:blue;}`; diff --git a/packages/styled-components/transform/tests/fixtures/.minify-css-to-use-without-transpilation/code.js b/packages/styled-components/transform/tests/fixtures/minify-css-to-use-without-transpilation/code.js similarity index 100% rename from packages/styled-components/transform/tests/fixtures/.minify-css-to-use-without-transpilation/code.js rename to packages/styled-components/transform/tests/fixtures/minify-css-to-use-without-transpilation/code.js diff --git a/packages/styled-components/transform/tests/fixtures/minify-css-to-use-without-transpilation/config.json b/packages/styled-components/transform/tests/fixtures/minify-css-to-use-without-transpilation/config.json new file mode 100644 index 000000000..ea04750a8 --- /dev/null +++ b/packages/styled-components/transform/tests/fixtures/minify-css-to-use-without-transpilation/config.json @@ -0,0 +1,6 @@ +{ + "ssr": false, + "displayName": false, + "transpileTemplateLiterals": true, + "minify": true +} diff --git a/packages/styled-components/transform/tests/fixtures/.minify-css-to-use-without-transpilation/output.js b/packages/styled-components/transform/tests/fixtures/minify-css-to-use-without-transpilation/output.js similarity index 100% rename from packages/styled-components/transform/tests/fixtures/.minify-css-to-use-without-transpilation/output.js rename to packages/styled-components/transform/tests/fixtures/minify-css-to-use-without-transpilation/output.js diff --git a/packages/styled-components/transform/tests/fixtures/.minify-single-line-comments-with-interpolations/code.js b/packages/styled-components/transform/tests/fixtures/minify-single-line-comments-with-interpolations/code.js similarity index 100% rename from packages/styled-components/transform/tests/fixtures/.minify-single-line-comments-with-interpolations/code.js rename to packages/styled-components/transform/tests/fixtures/minify-single-line-comments-with-interpolations/code.js diff --git a/packages/styled-components/transform/tests/fixtures/minify-single-line-comments-with-interpolations/config.json b/packages/styled-components/transform/tests/fixtures/minify-single-line-comments-with-interpolations/config.json new file mode 100644 index 000000000..998b45899 --- /dev/null +++ b/packages/styled-components/transform/tests/fixtures/minify-single-line-comments-with-interpolations/config.json @@ -0,0 +1,4 @@ +{ + "transpileTemplateLiterals": true, + "minify": true +} diff --git a/packages/styled-components/transform/tests/fixtures/minify-single-line-comments-with-interpolations/output.js b/packages/styled-components/transform/tests/fixtures/minify-single-line-comments-with-interpolations/output.js new file mode 100644 index 000000000..eb1927db1 --- /dev/null +++ b/packages/styled-components/transform/tests/fixtures/minify-single-line-comments-with-interpolations/output.js @@ -0,0 +1,29 @@ +import styled from 'styled-components'; +const Test1 = styled.div.withConfig({ + displayName: "code__Test1", + componentId: "sc-bfa13f91-0" +})`width:100%;`; +const Test2 = styled.div.withConfig({ + displayName: "code__Test2", + componentId: "sc-bfa13f91-1" +})`width:100%;`; +const Test3 = styled.div.withConfig({ + displayName: "code__Test3", + componentId: "sc-bfa13f91-2" +})`width:100%;${'red'};`; +const Test4 = styled.div.withConfig({ + displayName: "code__Test4", + componentId: "sc-bfa13f91-3" +})`width:100%;`; +const Test5 = styled.div.withConfig({ + displayName: "code__Test5", + componentId: "sc-bfa13f91-4" +})`width:100%;`; +const Test6 = styled.div.withConfig({ + displayName: "code__Test6", + componentId: "sc-bfa13f91-5" +})`background:url("https://google.com");width:100%;${'green'} `; +const Test7 = styled.div.withConfig({ + displayName: "code__Test7", + componentId: "sc-bfa13f91-6" +})`background:url("https://google.com");width:${(p)=>p.props.width};${'green'} height:${(p)=>p.props.height};`; diff --git a/packages/styled-components/transform/tests/fixtures/transpile-css-prop-all-options-on/output.js b/packages/styled-components/transform/tests/fixtures/transpile-css-prop-all-options-on/output.js index 00f099d98..adac803bc 100644 --- a/packages/styled-components/transform/tests/fixtures/transpile-css-prop-all-options-on/output.js +++ b/packages/styled-components/transform/tests/fixtures/transpile-css-prop-all-options-on/output.js @@ -6,15 +6,11 @@ const { SomeOtherComponent } = require('../SomeOtherComponentPath'); */ const Thing = styled.div.withConfig({ displayName: "code__Thing", componentId: "sc-867225be-0" -})` - color: red; -`; +})`color:red;`; const Thing2 = styled(Thing).withConfig({ displayName: "code__Thing2", componentId: "sc-867225be-1" -})` - background: blue; -`; +})`background:blue;`; /* * Basic fixtures */ const StaticString = (p)=><_StyledP>A; @@ -86,9 +82,7 @@ const SpreadObjectPropMixedInputs = (p)=>{ const Thing3 = styled.div.withConfig({ displayName: "code__Thing3", componentId: "sc-867225be-2" -})` - color: blue; -`; +})`color:blue;`; var _StyledThing6 = styled(Thing3).withConfig({ displayName: "code___StyledThing6", componentId: "sc-867225be-3" @@ -122,7 +116,7 @@ var _StyledThing3 = styled(Thing3).withConfig({ var _StyledThing = styled(Thing3).withConfig({ displayName: "code___StyledThing", componentId: "sc-867225be-7" -})`color: red;`; +})`color:red;`; const EarlyUsageComponent2 = (p)=><_StyledThing2/>; function Thing4(props1) { return
; @@ -182,25 +176,23 @@ const ObjectPropWithSpread = ()=>{ var _StyledSomeComponent = styled(SomeComponent).withConfig({ displayName: "code___StyledSomeComponent", componentId: "sc-867225be-8" -})`color: red;`; +})`color:red;`; var _StyledSomeOtherComponent = styled(SomeOtherComponent).withConfig({ displayName: "code___StyledSomeOtherComponent", componentId: "sc-867225be-9" -})`color: red;`; +})`color:red;`; var _StyledThing2 = styled(Thing4).withConfig({ displayName: "code___StyledThing2", componentId: "sc-867225be-10" -})`color: red;`; +})`color:red;`; var _StyledP = styled("p").withConfig({ displayName: "code___StyledP", componentId: "sc-867225be-11" -})`flex: 1;`; +})`flex:1;`; var _StyledP2 = styled("p").withConfig({ displayName: "code___StyledP2", componentId: "sc-867225be-12" -})` - flex: 1; - `; +})`flex:1;`; var _StyledP3 = styled("p").withConfig({ displayName: "code___StyledP3", componentId: "sc-867225be-13" @@ -210,17 +202,15 @@ var _StyledP3 = styled("p").withConfig({ var _StyledP4 = styled("p").withConfig({ displayName: "code___StyledP4", componentId: "sc-867225be-14" -})`flex: 1;`; +})`flex:1;`; var _StyledP5 = styled("p").withConfig({ displayName: "code___StyledP5", componentId: "sc-867225be-15" -})` - color: blue; - `; +})`color:blue;`; var _StyledParagraph = styled(Paragraph).withConfig({ displayName: "code___StyledParagraph", componentId: "sc-867225be-16" -})`flex: 1`; +})`flex:1`; var _StyledP6 = styled("p").withConfig({ displayName: "code___StyledP6", componentId: "sc-867225be-17" @@ -228,49 +218,39 @@ var _StyledP6 = styled("p").withConfig({ var _StyledP7 = styled("p").withConfig({ displayName: "code___StyledP7", componentId: "sc-867225be-18" -})` - background: ${(p)=>p.$_css2}; - `; +})`background:${(p)=>p.$_css2};`; var _StyledP8 = styled("p").withConfig({ displayName: "code___StyledP8", componentId: "sc-867225be-19" -})` - color: ${(props1)=>props1.theme.a}; - `; +})`color:${(props1)=>props1.theme.a};`; var _StyledP9 = styled("p").withConfig({ displayName: "code___StyledP9", componentId: "sc-867225be-20" -})` - border-radius: ${radius}px; - `; +})`border-radius:${radius}px;`; var _StyledP10 = styled("p").withConfig({ displayName: "code___StyledP10", componentId: "sc-867225be-21" -})` - color: ${(p)=>p.$_css3}; - `; +})`color:${(p)=>p.$_css3};`; var _StyledP11 = styled("p").withConfig({ displayName: "code___StyledP11", componentId: "sc-867225be-22" -})` - color: ${(props1)=>props1.theme.color}; - `; +})`color:${(props1)=>props1.theme.color};`; var _StyledButtonGhost = styled(Button.Ghost).withConfig({ displayName: "code___StyledButtonGhost", componentId: "sc-867225be-23" -})`flex: 1`; +})`flex:1`; var _StyledButtonGhostNew = styled(Button.Ghost.New).withConfig({ displayName: "code___StyledButtonGhostNew", componentId: "sc-867225be-24" -})`flex: 1`; +})`flex:1`; var _StyledButtonGhost2 = styled(button.ghost).withConfig({ displayName: "code___StyledButtonGhost2", componentId: "sc-867225be-25" -})`flex: 1`; +})`flex:1`; var _StyledButtonGhost3 = styled("button-ghost").withConfig({ displayName: "code___StyledButtonGhost3", componentId: "sc-867225be-26" -})`flex: 1`; +})`flex:1`; var _StyledP12 = styled("p").withConfig({ displayName: "code___StyledP12", componentId: "sc-867225be-27" diff --git a/packages/styled-jsx/package.json b/packages/styled-jsx/package.json index 1e59311dd..211357fb8 100644 --- a/packages/styled-jsx/package.json +++ b/packages/styled-jsx/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-styled-jsx", - "version": "1.5.99", + "version": "1.5.100", "description": "SWC plugin for styled-jsx", "main": "swc_plugin_styled_jsx.wasm", "scripts": { diff --git a/packages/styled-jsx/transform/Cargo.toml b/packages/styled-jsx/transform/Cargo.toml index 51544eeae..4212c9390 100644 --- a/packages/styled-jsx/transform/Cargo.toml +++ b/packages/styled-jsx/transform/Cargo.toml @@ -4,7 +4,7 @@ description = "AST transforms visitor for styled-jsx" edition = "2021" license = "Apache-2.0" name = "styled_jsx" -version = "0.61.0" +version = "0.62.0" [features] custom_transform = ["swc_common/concurrent"] diff --git a/packages/swc-magic/package.json b/packages/swc-magic/package.json index 22e019630..50d6549c8 100644 --- a/packages/swc-magic/package.json +++ b/packages/swc-magic/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-swc-magic", - "version": "1.5.99", + "version": "1.5.100", "description": "SWC plugin for swc-magic", "main": "swc_plugin_swc_magic.wasm", "scripts": { diff --git a/packages/swc-magic/transform/Cargo.toml b/packages/swc-magic/transform/Cargo.toml index 19a77f298..5e4f53235 100644 --- a/packages/swc-magic/transform/Cargo.toml +++ b/packages/swc-magic/transform/Cargo.toml @@ -4,7 +4,7 @@ description = "AST transforms visitor for swc-magic" edition = "2021" license = "Apache-2.0" name = "swc_magic" -version = "0.7.0" +version = "0.8.0" [dependencies] serde = { version = "1.0.189", features = ["derive"] } diff --git a/packages/transform-imports/package.json b/packages/transform-imports/package.json index ae40f9d2f..4cdbe2c5a 100644 --- a/packages/transform-imports/package.json +++ b/packages/transform-imports/package.json @@ -1,6 +1,6 @@ { "name": "@swc/plugin-transform-imports", - "version": "1.5.99", + "version": "1.5.100", "description": "SWC plugin for https://www.npmjs.com/package/babel-plugin-transform-imports", "main": "swc_plugin_transform_imports.wasm", "scripts": {