From b1abf33e09bf451dfcc47e4f327891f6075b0062 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Wed, 23 Jul 2025 00:59:03 +0900 Subject: [PATCH 1/5] Optimize join --- .../extract_global_style_from_expression.rs | 6 ++-- .../extract_keyframes_from_expression.rs | 3 +- .../extract_style_from_expression.rs | 3 +- libs/extractor/src/utils.rs | 3 +- libs/extractor/src/visit.rs | 5 ++- libs/sheet/src/lib.rs | 24 +++++-------- libs/sheet/src/theme.rs | 34 ++++++++----------- 7 files changed, 29 insertions(+), 49 deletions(-) diff --git a/libs/extractor/src/extractor/extract_global_style_from_expression.rs b/libs/extractor/src/extractor/extract_global_style_from_expression.rs index 31e924f2..c3ed41a2 100644 --- a/libs/extractor/src/extractor/extract_global_style_from_expression.rs +++ b/libs/extractor/src/extractor/extract_global_style_from_expression.rs @@ -29,8 +29,7 @@ pub fn extract_global_style_from_expression<'a>( t.quasis .iter() .map(|q| q.value.raw.as_str()) - .collect::>() - .join("") + .collect::() } else { continue; }; @@ -46,8 +45,7 @@ pub fn extract_global_style_from_expression<'a>( t.quasis .iter() .map(|q| q.value.raw.as_str()) - .collect::>() - .join("") + .collect::() .trim() .to_string() } else { diff --git a/libs/extractor/src/extractor/extract_keyframes_from_expression.rs b/libs/extractor/src/extractor/extract_keyframes_from_expression.rs index 5d20ac82..a3916c4e 100644 --- a/libs/extractor/src/extractor/extract_keyframes_from_expression.rs +++ b/libs/extractor/src/extractor/extract_keyframes_from_expression.rs @@ -27,8 +27,7 @@ pub fn extract_keyframes_from_expression<'a>( t.quasis .iter() .map(|q| q.value.raw.as_str()) - .collect::>() - .join("") + .collect::() } else if let PropertyKey::NumericLiteral(n) = &o.key { n.value.to_string() } else { diff --git a/libs/extractor/src/extractor/extract_style_from_expression.rs b/libs/extractor/src/extractor/extract_style_from_expression.rs index 72902ffe..a9f886e1 100644 --- a/libs/extractor/src/extractor/extract_style_from_expression.rs +++ b/libs/extractor/src/extractor/extract_style_from_expression.rs @@ -144,8 +144,7 @@ pub fn extract_style_from_expression<'a>( &tmp.quasis .iter() .map(|q| q.value.raw.as_str()) - .collect::>() - .join(""), + .collect::(), level, selector, ), diff --git a/libs/extractor/src/utils.rs b/libs/extractor/src/utils.rs index 34ac567e..e1c2170c 100644 --- a/libs/extractor/src/utils.rs +++ b/libs/extractor/src/utils.rs @@ -207,8 +207,7 @@ pub(super) fn get_number_by_literal_expression(expr: &Expression) -> Option .quasis .iter() .map(|q| q.value.raw.to_string()) - .collect::>() - .join("") + .collect::() .parse::() .ok(), Expression::NumericLiteral(num) => Some(num.value), diff --git a/libs/extractor/src/visit.rs b/libs/extractor/src/visit.rs index dc3909f5..76f7ef57 100644 --- a/libs/extractor/src/visit.rs +++ b/libs/extractor/src/visit.rs @@ -229,9 +229,8 @@ impl<'a> VisitMut<'a> for DevupVisitor<'a> { .quasi .quasis .iter() - .map(|quasi| quasi.value.raw.as_str()) - .collect::>() - .join(""); + .map(|quasi| quasi.value.raw.to_string()) + .collect::(); match css_type.as_ref() { UtilType::Css => { let mut styles = css_to_style(&css_str, 0, &None); diff --git a/libs/sheet/src/lib.rs b/libs/sheet/src/lib.rs index a538272c..1810ed8c 100644 --- a/libs/sheet/src/lib.rs +++ b/libs/sheet/src/lib.rs @@ -269,21 +269,18 @@ impl StyleSheet { color_keys .into_iter() .map(|key| format!("{}:null;", convert_interface_key(&format!("${key}")))) - .collect::>() - .join(""), + .collect::(), typography_interface_name, typography_keys .into_iter() .map(|key| format!("{}:null;", convert_interface_key(&key))) - .collect::>() - .join(""), + .collect::(), theme_interface_name, theme_keys .into_iter() // key to pascal .map(|key| format!("{}:null;", convert_interface_key(&key))) - .collect::>() - .join("") + .collect::() ) } } @@ -294,8 +291,7 @@ impl StyleSheet { .values() .flatten() .map(|import| format!("@import \"{import}\";")) - .collect::>() - .join(""); + .collect::(); css.push_str(&self.theme.to_css()); for (name, map) in self.keyframes.iter() { @@ -310,8 +306,7 @@ impl StyleSheet { .collect::>() .join(";") )) - .collect::>() - .join("") + .collect::() )); } @@ -368,8 +363,7 @@ impl StyleSheet { let inner_css = global_props .into_iter() .map(ExtractStyle::extract) - .collect::>() - .join(""); + .collect::(); css.push_str( if let Some(break_point) = break_point { format!("@media(min-width:{break_point}px){{{inner_css}}}") @@ -384,8 +378,7 @@ impl StyleSheet { let inner_css = sorted_props .into_iter() .map(ExtractStyle::extract) - .collect::>() - .join(""); + .collect::(); css.push_str( if let Some(break_point) = break_point { format!("@media(min-width:{break_point}px){{{inner_css}}}") @@ -399,8 +392,7 @@ impl StyleSheet { let inner_css = props .into_iter() .map(ExtractStyle::extract) - .collect::>() - .join(""); + .collect::(); css.push_str( if let Some(break_point) = break_point { format!("@media(min-width:{break_point}px)and {media}{{{inner_css}}}") diff --git a/libs/sheet/src/theme.rs b/libs/sheet/src/theme.rs index d0342293..f1b3f22b 100644 --- a/libs/sheet/src/theme.rs +++ b/libs/sheet/src/theme.rs @@ -180,8 +180,7 @@ impl Theme { Some(theme_name) }; if let Some(theme_key) = theme_key { - theme_declaration - .push_str(format!(":root[data-theme={theme_key}]{{").as_str()); + theme_declaration.push_str(format!(":root[data-theme={theme_key}]{{").as_str()); css_contents.push("color-scheme:dark".to_string()); } else { theme_declaration.push_str(":root{".to_string().as_str()); @@ -193,10 +192,8 @@ impl Theme { let optimized_value = optimize_value(value); if theme_key.is_some() { if other_theme_key.is_none() - && let Some(default_value) = self - .colors - .get(&default_theme_key) - .and_then(|v| { + && let Some(default_value) = + self.colors.get(&default_theme_key).and_then(|v| { v.0.get(prop).and_then(|v| { if optimize_value(v) == optimized_value { None @@ -209,21 +206,18 @@ impl Theme { css_color_contents.push(format!("--{prop}:{default_value}")); } } else { - let other_theme_value = other_theme_key - .as_ref() - .and_then(|other_theme_key| { - self.colors - .get(other_theme_key) - .and_then(|v| { - v.0.get(prop).and_then(|v| { - let other_theme_value = optimize_value(v.as_str()); - if other_theme_value == optimized_value { - None - } else { - Some(other_theme_value) - } - }) + let other_theme_value = + other_theme_key.as_ref().and_then(|other_theme_key| { + self.colors.get(other_theme_key).and_then(|v| { + v.0.get(prop).and_then(|v| { + let other_theme_value = optimize_value(v.as_str()); + if other_theme_value == optimized_value { + None + } else { + Some(other_theme_value) + } }) + }) }); // default theme css_color_contents.push(format!( From 6c55a7b1b8d6e31a12756b48041f18a39b78d765 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Wed, 23 Jul 2025 01:08:46 +0900 Subject: [PATCH 2/5] Add rust lint --- bindings/devup-ui-wasm/src/lib.rs | 6 +++--- .../src/extract_style/extract_dynamic_style.rs | 4 ++-- .../src/extract_style/extract_static_style.rs | 5 +---- libs/sheet/benches/my_benchmark.rs | 2 +- libs/sheet/src/lib.rs | 13 +++++-------- package.json | 2 +- 6 files changed, 13 insertions(+), 19 deletions(-) diff --git a/bindings/devup-ui-wasm/src/lib.rs b/bindings/devup-ui-wasm/src/lib.rs index 7edfb2bf..404ca6d3 100644 --- a/bindings/devup-ui-wasm/src/lib.rs +++ b/bindings/devup-ui-wasm/src/lib.rs @@ -640,11 +640,11 @@ mod tests { #[test] #[serial] fn test_debug() { - assert_eq!(is_debug(), false); + assert!(!is_debug()); set_debug(true); - assert_eq!(is_debug(), true); + assert!(is_debug()); set_debug(false); - assert_eq!(is_debug(), false); + assert!(!is_debug()); } #[test] diff --git a/libs/extractor/src/extract_style/extract_dynamic_style.rs b/libs/extractor/src/extract_style/extract_dynamic_style.rs index d49f37f0..675cf7f1 100644 --- a/libs/extractor/src/extract_style/extract_dynamic_style.rs +++ b/libs/extractor/src/extract_style/extract_dynamic_style.rs @@ -1,6 +1,6 @@ use css::{ - optimize_value::optimize_value, sheet_to_classname, - sheet_to_variable_name, style_selector::StyleSelector, + optimize_value::optimize_value, sheet_to_classname, sheet_to_variable_name, + style_selector::StyleSelector, }; use crate::extract_style::{ExtractStyleProperty, style_property::StyleProperty}; diff --git a/libs/extractor/src/extract_style/extract_static_style.rs b/libs/extractor/src/extract_style/extract_static_style.rs index ed6b964f..cae59357 100644 --- a/libs/extractor/src/extract_style/extract_static_style.rs +++ b/libs/extractor/src/extract_style/extract_static_style.rs @@ -1,7 +1,4 @@ -use css::{ - optimize_value::optimize_value, sheet_to_classname, - style_selector::StyleSelector, -}; +use css::{optimize_value::optimize_value, sheet_to_classname, style_selector::StyleSelector}; use crate::{ extract_style::{ diff --git a/libs/sheet/benches/my_benchmark.rs b/libs/sheet/benches/my_benchmark.rs index c0dce865..03c8983a 100644 --- a/libs/sheet/benches/my_benchmark.rs +++ b/libs/sheet/benches/my_benchmark.rs @@ -1,4 +1,4 @@ -use criterion::{criterion_group, criterion_main, Criterion}; +use criterion::{Criterion, criterion_group, criterion_main}; use once_cell::sync::Lazy; use regex::Regex; use std::hint::black_box; diff --git a/libs/sheet/src/lib.rs b/libs/sheet/src/lib.rs index 1810ed8c..b7f45bcb 100644 --- a/libs/sheet/src/lib.rs +++ b/libs/sheet/src/lib.rs @@ -755,13 +755,10 @@ mod tests { "my", 0, "40px", - Some( - &StyleSelector::Media { - query: "(min-width: 1024px)".to_string(), - selector: Some("&:hover".to_string()), - } - .into(), - ), + Some(&StyleSelector::Media { + query: "(min-width: 1024px)".to_string(), + selector: Some("&:hover".to_string()), + }), None, ); @@ -937,7 +934,7 @@ mod tests { "background-color", 0, "red", - Some(&StyleSelector::Selector("&:hover".to_string()).into()), + Some(&StyleSelector::Selector("&:hover".to_string())), Some(255), ); diff --git a/package.json b/package.json index 4c17e1e4..79368fba 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "description": "devup-ui", "type": "module", "scripts": { - "lint": "pnpm -F @devup-ui/* lint", + "lint": "pnpm -F @devup-ui/* lint && cargo fmt --all -- --check && cargo clippy --all-targets --all-features -- -D warnings", "pretest": "pnpm -F @devup-ui/vite-plugin build", "test": "cargo tarpaulin --out xml --out stdout --out html --all-targets && vitest test --coverage --run && pnpm -r test", "build": "pnpm -F @devup-ui/* build", From 25e0986ac23e00db141ca36004a3d9e137be636a Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Wed, 23 Jul 2025 01:23:39 +0900 Subject: [PATCH 3/5] Fix coverage issue --- .github/workflows/publish.yml | 3 +++ libs/css/src/lib.rs | 4 +-- libs/css/src/optimize_value.rs | 2 +- libs/extractor/src/css_utils.rs | 2 +- libs/extractor/src/gen_class_name.rs | 2 +- libs/extractor/src/lib.rs | 40 ++++------------------------ 6 files changed, 13 insertions(+), 40 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2e9889c1..6f9ff293 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -40,6 +40,9 @@ jobs: - run: | pnpm build pnpm lint + # rust coverage issue + echo "max_width = 1000\ntab_spaces = 4\nnewline_style = \"Unix\"\nfn_call_width = 1000\nfn_params_layout = \"Compressed\"\nchain_width = 1000\nmerge_derives = true\nuse_small_heuristics = \"Default\"\n" > .rustfmt.toml + cargo fmt pnpm test - name: Benchmark run: pnpm benchmark diff --git a/libs/css/src/lib.rs b/libs/css/src/lib.rs index ee99ba0a..c09cdd3d 100644 --- a/libs/css/src/lib.rs +++ b/libs/css/src/lib.rs @@ -454,7 +454,7 @@ mod tests { "cls", Some(&StyleSelector::Media { query: "print".to_string(), - selector: None, + selector: None }) ), ".cls" @@ -465,7 +465,7 @@ mod tests { "cls", Some(&StyleSelector::Media { query: "print".to_string(), - selector: Some("&:hover".to_string()), + selector: Some("&:hover".to_string()) }) ), ".cls:hover" diff --git a/libs/css/src/optimize_value.rs b/libs/css/src/optimize_value.rs index d4b2ef55..cc0bc949 100644 --- a/libs/css/src/optimize_value.rs +++ b/libs/css/src/optimize_value.rs @@ -114,7 +114,7 @@ pub fn optimize_value(value: &str) -> String { } fn optimize_color(value: &str) -> String { - let mut ret = value.to_string().to_uppercase(); + let mut ret = value.to_uppercase(); if ret.len() == 6 { let ch = ret.chars().collect::>(); diff --git a/libs/extractor/src/css_utils.rs b/libs/extractor/src/css_utils.rs index b4f422fc..ae1aaa82 100644 --- a/libs/extractor/src/css_utils.rs +++ b/libs/extractor/src/css_utils.rs @@ -157,7 +157,7 @@ pub fn optimize_css_block(css: &str) -> String { .split(";") .map(|s| { if !s.contains(":") { - s.to_string().trim().to_string() + s.trim().to_string() } else { let mut iter = s.split(":"); let property = iter.next().unwrap().trim(); diff --git a/libs/extractor/src/gen_class_name.rs b/libs/extractor/src/gen_class_name.rs index 33ebb489..b49f9d61 100644 --- a/libs/extractor/src/gen_class_name.rs +++ b/libs/extractor/src/gen_class_name.rs @@ -124,7 +124,7 @@ pub fn merge_expression_for_class_name<'a>( let mut unknown_expr = vec![]; for expr in expressions { if let Expression::StringLiteral(str) = &expr { - class_names.push(str.value.to_string().trim().to_string()) + class_names.push(str.value.trim().to_string()) } else { unknown_expr.push(expr); } diff --git a/libs/extractor/src/lib.rs b/libs/extractor/src/lib.rs index 46a02df4..70313e09 100644 --- a/libs/extractor/src/lib.rs +++ b/libs/extractor/src/lib.rs @@ -200,10 +200,7 @@ mod tests { r#"import {Box} from '@devup-ui/core' {}} aria-valuenow={24} key={2} tabIndex={1} id="id" /> "#, - ExtractOption { - package: "@devup-ui/core".to_string(), - css_file: None - } + ExtractOption { package: "@devup-ui/core".to_string(), css_file: None } ) .unwrap() )); @@ -2595,37 +2592,13 @@ e(o, { className: "a", bg: variable, style: { color: "blue" }, ...props }) #[serial] fn support_transpile_cjs() { reset_class_map(); - assert_debug_snapshot!(ToBTreeSet::from(extract( - "test.cjs", - r#""use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("@devup-ui/react");function t(){return e.jsxs("div",{children:[e.jsx(r.Box,{_hover:{bg:"blue"},bg:"$text",color:"red",children:"hello"}),e.jsx(r.Text,{typography:"header",children:"typo"}),e.jsx(r.Flex,{as:"section",mt:2,children:"section"})]})}exports.Lib=t;"#, - ExtractOption { - package: "@devup-ui/react".to_string(), - css_file: None - } - ) - .unwrap())); + assert_debug_snapshot!(ToBTreeSet::from(extract("test.cjs", r#""use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("@devup-ui/react");function t(){return e.jsxs("div",{children:[e.jsx(r.Box,{_hover:{bg:"blue"},bg:"$text",color:"red",children:"hello"}),e.jsx(r.Text,{typography:"header",children:"typo"}),e.jsx(r.Flex,{as:"section",mt:2,children:"section"})]})}exports.Lib=t;"#, ExtractOption { package: "@devup-ui/react".to_string(), css_file: None }).unwrap())); reset_class_map(); - assert_debug_snapshot!(ToBTreeSet::from(extract( - "test.cjs", - r#""use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const {jsx:e1, jsxs:e2}=require("react/jsx-runtime"),r=require("@devup-ui/react");function t(){return e2("div",{children:[e1(r.Box,{_hover:{bg:"blue"},bg:"$text",color:"red",children:"hello"}),e1(r.Text,{typography:"header",children:"typo"}),e1(r.Flex,{as:"section",mt:2,children:"section"})]})}exports.Lib=t;"#, - ExtractOption { - package: "@devup-ui/react".to_string(), - css_file: None - } - ) - .unwrap())); + assert_debug_snapshot!(ToBTreeSet::from(extract("test.cjs", r#""use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const {jsx:e1, jsxs:e2}=require("react/jsx-runtime"),r=require("@devup-ui/react");function t(){return e2("div",{children:[e1(r.Box,{_hover:{bg:"blue"},bg:"$text",color:"red",children:"hello"}),e1(r.Text,{typography:"header",children:"typo"}),e1(r.Flex,{as:"section",mt:2,children:"section"})]})}exports.Lib=t;"#, ExtractOption { package: "@devup-ui/react".to_string(), css_file: None }).unwrap())); reset_class_map(); - assert_debug_snapshot!(ToBTreeSet::from(extract( - "test.js", - r#""use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("@devup-ui/react");function t(){return e.jsxs("div",{children:[e.jsx(r.Box,{_hover:{bg:"blue"},bg:"$text",color:"red",children:"hello"}),e.jsx(r.Text,{typography:"header",children:"typo"}),e.jsx(r.Flex,{as:"section",mt:2,children:"section"})]})}exports.Lib=t;"#, - ExtractOption { - package: "@devup-ui/react".to_string(), - css_file: None - } - ) - .unwrap())); + assert_debug_snapshot!(ToBTreeSet::from(extract("test.js", r#""use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("@devup-ui/react");function t(){return e.jsxs("div",{children:[e.jsx(r.Box,{_hover:{bg:"blue"},bg:"$text",color:"red",children:"hello"}),e.jsx(r.Text,{typography:"header",children:"typo"}),e.jsx(r.Flex,{as:"section",mt:2,children:"section"})]})}exports.Lib=t;"#, ExtractOption { package: "@devup-ui/react".to_string(), css_file: None }).unwrap())); } #[test] @@ -2638,10 +2611,7 @@ e(o, { className: "a", bg: variable, style: { color: "blue" }, ...props }) r#"import {Flex} from '@devup-ui/core' "#, - ExtractOption { - package: "@devup-ui/core".to_string(), - css_file: None - } + ExtractOption { package: "@devup-ui/core".to_string(), css_file: None } ) .unwrap() )); From ffbad1776c232b13e75c30f16056610048085735 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Wed, 23 Jul 2025 01:28:03 +0900 Subject: [PATCH 4/5] Fix coverage issue --- .github/workflows/publish.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6f9ff293..5e022a85 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -41,7 +41,14 @@ jobs: pnpm build pnpm lint # rust coverage issue - echo "max_width = 1000\ntab_spaces = 4\nnewline_style = \"Unix\"\nfn_call_width = 1000\nfn_params_layout = \"Compressed\"\nchain_width = 1000\nmerge_derives = true\nuse_small_heuristics = \"Default\"\n" > .rustfmt.toml + echo 'max_width = 1000' > .rustfmt.toml + echo 'tab_spaces = 4' >> .rustfmt.toml + echo 'newline_style = "Unix"' >> .rustfmt.toml + echo 'fn_call_width = 1000' >> .rustfmt.toml + echo 'fn_params_layout = "Compressed"' >> .rustfmt.toml + echo 'chain_width = 1000' >> .rustfmt.toml + echo 'merge_derives = true' >> .rustfmt.toml + echo 'use_small_heuristics = "Default"' >> .rustfmt.toml cargo fmt pnpm test - name: Benchmark From 87ebd4b2ce633b4896c3435322bfbd838166091e Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Wed, 23 Jul 2025 01:53:03 +0900 Subject: [PATCH 5/5] Fix coverage issue --- libs/extractor/src/css_utils.rs | 9 ++++ libs/extractor/src/gen_style.rs | 42 +++++++++---------- libs/extractor/src/lib.rs | 22 ++++++++++ ...ractor__tests__extract_wrong_keyframs.snap | 33 +++++++++++++++ 4 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 libs/extractor/src/snapshots/extractor__tests__extract_wrong_keyframs.snap diff --git a/libs/extractor/src/css_utils.rs b/libs/extractor/src/css_utils.rs index ae1aaa82..7832be21 100644 --- a/libs/extractor/src/css_utils.rs +++ b/libs/extractor/src/css_utils.rs @@ -470,11 +470,20 @@ mod tests { ("50%", vec![("color", "red"), ("background", "blue")]), ], )] + // error case + #[case( + "50% { color: red ; background: blue ", + vec![ + ], + )] fn test_keyframes_to_keyframes_style( #[case] input: &str, #[case] expected: Vec<(&str, Vec<(&str, &str)>)>, ) { let styles = keyframes_to_keyframes_style(input); + if styles.len() != expected.len() { + panic!("styles.len() != expected.len()"); + } for (expected_key, expected_styles) in styles.iter() { let styles = expected_styles; let mut result: Vec<(&str, &str)> = styles diff --git a/libs/extractor/src/gen_style.rs b/libs/extractor/src/gen_style.rs index 4a20b67e..3fab89b2 100644 --- a/libs/extractor/src/gen_style.rs +++ b/libs/extractor/src/gen_style.rs @@ -32,29 +32,25 @@ fn gen_style<'a>( let mut properties = vec![]; match style { ExtractStyleProp::Static(st) => { - if let Some(ex) = st.extract() { - match ex { - StyleProperty::ClassName(_) => {} - StyleProperty::Variable { - variable_name, - identifier, - .. - } => { - properties.push(ast_builder.object_property_kind_object_property( - SPAN, - PropertyKind::Init, - PropertyKey::StringLiteral(ast_builder.alloc_string_literal( - SPAN, - ast_builder.atom(&variable_name), - None, - )), - ast_builder.expression_identifier(SPAN, ast_builder.atom(&identifier)), - false, - false, - false, - )); - } - } + if let Some(StyleProperty::Variable { + variable_name, + identifier, + .. + }) = st.extract() + { + properties.push(ast_builder.object_property_kind_object_property( + SPAN, + PropertyKind::Init, + PropertyKey::StringLiteral(ast_builder.alloc_string_literal( + SPAN, + ast_builder.atom(&variable_name), + None, + )), + ast_builder.expression_identifier(SPAN, ast_builder.atom(&identifier)), + false, + false, + false, + )); } } ExtractStyleProp::StaticArray(res) => { diff --git a/libs/extractor/src/lib.rs b/libs/extractor/src/lib.rs index 70313e09..bab7330a 100644 --- a/libs/extractor/src/lib.rs +++ b/libs/extractor/src/lib.rs @@ -4981,6 +4981,28 @@ keyframes({ [`50%`]: { opacity: 0.5 }, [`100%`]: { opacity: 1 } }) +"#, + ExtractOption { + package: "@devup-ui/core".to_string(), + css_file: None + } + ) + .unwrap() + )); + } + #[test] + #[serial] + fn extract_wrong_keyframs() { + reset_class_map(); + assert_debug_snapshot!(ToBTreeSet::from( + extract( + "test.tsx", + r#"import { keyframes } from "@devup-ui/core"; +keyframes({ + from: { opacity: 0 }, + [true]: { opacity: 0.5 }, + to: { opacity: 1, color: dy } +}) "#, ExtractOption { package: "@devup-ui/core".to_string(), diff --git a/libs/extractor/src/snapshots/extractor__tests__extract_wrong_keyframs.snap b/libs/extractor/src/snapshots/extractor__tests__extract_wrong_keyframs.snap new file mode 100644 index 00000000..510849eb --- /dev/null +++ b/libs/extractor/src/snapshots/extractor__tests__extract_wrong_keyframs.snap @@ -0,0 +1,33 @@ +--- +source: libs/extractor/src/lib.rs +expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import { keyframes } from \"@devup-ui/core\";\nkeyframes({\n from: { opacity: 0 },\n [true]: { opacity: 0.5 },\n to: { opacity: 1 }\n})\n\"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())" +--- +ToBTreeSet { + styles: { + Keyframes( + ExtractKeyframes { + keyframes: { + "from": [ + ExtractStaticStyle { + property: "opacity", + value: "0", + level: 0, + selector: None, + style_order: None, + }, + ], + "to": [ + ExtractStaticStyle { + property: "opacity", + value: "1", + level: 0, + selector: None, + style_order: None, + }, + ], + }, + }, + ), + }, + code: "import \"@devup-ui/core/devup-ui.css\";\n\"k0\";\n", +}