Skip to content

Commit 5a6c758

Browse files
authored
Merge pull request #159 from dev-five-git/static-member
Fix static member expression
2 parents 608e8d1 + b9b4700 commit 5a6c758

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

.changeset/dull-doors-nail.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+
Support static member expression

libs/extractor/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,32 @@ mod tests {
505505
"test.tsx",
506506
r#"import { Box } from "@devup-ui/core";
507507
<Box padding={Math.abs(5)} />;
508+
"#,
509+
ExtractOption {
510+
package: "@devup-ui/core".to_string(),
511+
css_file: None
512+
}
513+
)
514+
.unwrap());
515+
516+
reset_class_map();
517+
assert_debug_snapshot!(extract(
518+
"test.tsx",
519+
r#"import { Box } from "@devup-ui/core";
520+
<Box bg={data.buttonBgColor} />;
521+
"#,
522+
ExtractOption {
523+
package: "@devup-ui/core".to_string(),
524+
css_file: None
525+
}
526+
)
527+
.unwrap());
528+
529+
reset_class_map();
530+
assert_debug_snapshot!(extract(
531+
"test.tsx",
532+
r#"import { Box } from "@devup-ui/core";
533+
<Box bg={data.a.b.buttonBgColor} />;
508534
"#,
509535
ExtractOption {
510536
package: "@devup-ui/core".to_string(),
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "extract(\"test.tsx\",\nr#\"import { Box } from \"@devup-ui/core\";\n<Box bg={data.buttonBgColor} />;\n\"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap()"
4+
---
5+
ExtractOutput {
6+
styles: [
7+
Dynamic(
8+
ExtractDynamicStyle {
9+
property: "background",
10+
level: 0,
11+
identifier: "data.buttonBgColor",
12+
selector: None,
13+
style_order: None,
14+
},
15+
),
16+
],
17+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"d0\" style={{ \"--d1\": data.buttonBgColor }} />;\n",
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "extract(\"test.tsx\",\nr#\"import { Box } from \"@devup-ui/core\";\n<Box bg={data.a.b.buttonBgColor} />;\n\"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap()"
4+
---
5+
ExtractOutput {
6+
styles: [
7+
Dynamic(
8+
ExtractDynamicStyle {
9+
property: "background",
10+
level: 0,
11+
identifier: "data.a.b.buttonBgColor",
12+
selector: None,
13+
style_order: None,
14+
},
15+
),
16+
],
17+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"d0\" style={{ \"--d1\": data.a.b.buttonBgColor }} />;\n",
18+
}

libs/extractor/src/style_extractor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ pub fn extract_style_from_expression<'a>(
329329
match expression {
330330
Expression::UnaryExpression(_)
331331
| Expression::BinaryExpression(_)
332+
| Expression::StaticMemberExpression(_)
332333
| Expression::CallExpression(_) => ExtractResult::Extract {
333334
styles: Some(vec![ExtractStyleProp::Static(Dynamic(
334335
ExtractDynamicStyle::new(

0 commit comments

Comments
 (0)