Skip to content

Commit d6e4605

Browse files
committed
Add call case
1 parent 87f4f0c commit d6e4605

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

.changeset/fluffy-cups-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/wasm": patch
3+
---
4+
5+
Add call case

libs/css/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,4 +731,12 @@ mod tests {
731731
":root[data-theme=dark] .cls:hover"
732732
);
733733
}
734+
735+
#[test]
736+
fn test_set_class_map() {
737+
let mut map = HashMap::new();
738+
map.insert("background-0-rgba(255,0,0,0.5)-".to_string(), 1);
739+
set_class_map(map);
740+
assert_eq!(get_class_map().len(), 1);
741+
}
734742
}

libs/extractor/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,19 @@ mod tests {
492492
"test.tsx",
493493
r#"import { Box } from "@devup-ui/core";
494494
<Box padding={someStyleVar} margin={someStyleVar2} />;
495+
"#,
496+
ExtractOption {
497+
package: "@devup-ui/core".to_string(),
498+
css_file: None
499+
}
500+
)
501+
.unwrap());
502+
503+
reset_class_map();
504+
assert_debug_snapshot!(extract(
505+
"test.tsx",
506+
r#"import { Box } from "@devup-ui/core";
507+
<Box padding={Math.abs(5)} />;
495508
"#,
496509
ExtractOption {
497510
package: "@devup-ui/core".to_string(),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "extract(\"test.tsx\",\nr#\"import { Box } from \"@devup-ui/core\";\n<Box padding={Math.abs(5)} />;\n\"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap()"
4+
---
5+
ExtractOutput {
6+
styles: [
7+
Dynamic(
8+
ExtractDynamicStyle {
9+
property: "padding",
10+
level: 0,
11+
identifier: "Math.abs(5)",
12+
selector: None,
13+
},
14+
),
15+
],
16+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"d0\" style={{ \"--d1\": Math.abs(5) }} />;\n",
17+
}

libs/extractor/src/style_extractor.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,16 @@ pub fn extract_style_from_expression<'a>(
553553
ExtractResult::ExtractStyle(props)
554554
}
555555
}
556+
Expression::CallExpression(_) => {
557+
ExtractResult::ExtractStyle(vec![ExtractStyleProp::Static(Dynamic(
558+
ExtractDynamicStyle::new(
559+
name.unwrap(),
560+
level,
561+
expression_to_code(expression).as_str(),
562+
selector.map(|s| s.into()),
563+
),
564+
))])
565+
}
556566
// val if let Some(value) = get_number_by_literal_expression(val) => {}
557567
_ => ExtractResult::Maintain,
558568
}

0 commit comments

Comments
 (0)