Skip to content

Commit 5d556a5

Browse files
committed
Merge branch 'main' into LFOP-12
2 parents 58c2a1d + 02106b5 commit 5d556a5

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

.changeset/cuddly-showers-shine.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 void 0

libs/extractor/src/extractor/extract_style_from_expression.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use oxc_ast::{
2222
AstBuilder,
2323
ast::{
2424
BinaryOperator, Expression, LogicalOperator, ObjectPropertyKind, PropertyKey,
25-
TemplateElementValue,
25+
TemplateElementValue, UnaryOperator,
2626
},
2727
};
2828
use oxc_span::SPAN;
@@ -37,6 +37,7 @@ pub fn extract_style_from_expression<'a>(
3737
selector: &Option<StyleSelector>,
3838
) -> ExtractResult<'a> {
3939
let mut typo = false;
40+
println!("expression: {:?}", expression);
4041

4142
if name.is_none() && selector.is_none() {
4243
let mut style_order = None;
@@ -287,8 +288,22 @@ pub fn extract_style_from_expression<'a>(
287288
}
288289
} else {
289290
match expression {
290-
Expression::UnaryExpression(_)
291-
| Expression::BinaryExpression(_)
291+
Expression::UnaryExpression(un) => ExtractResult {
292+
styles: if un.operator == UnaryOperator::Void {
293+
vec![]
294+
} else {
295+
vec![ExtractStyleProp::Static(ExtractStyleValue::Dynamic(
296+
ExtractDynamicStyle::new(
297+
name.unwrap(),
298+
level,
299+
&expression_to_code(expression),
300+
selector.clone(),
301+
),
302+
))]
303+
},
304+
..ExtractResult::default()
305+
},
306+
Expression::BinaryExpression(_)
292307
| Expression::StaticMemberExpression(_)
293308
| Expression::CallExpression(_) => ExtractResult {
294309
styles: vec![ExtractStyleProp::Static(ExtractStyleValue::Dynamic(

libs/extractor/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,23 @@ import clsx from 'clsx'
15131513
"test.tsx",
15141514
r#"import { Box } from "@devup-ui/core";
15151515
<Box margin={a === b ? undefined : null} />;
1516+
"#,
1517+
ExtractOption {
1518+
package: "@devup-ui/core".to_string(),
1519+
css_dir: "@devup-ui/core".to_string(),
1520+
single_css: true,
1521+
import_main_css: false
1522+
}
1523+
)
1524+
.unwrap()
1525+
));
1526+
1527+
reset_class_map();
1528+
assert_debug_snapshot!(ToBTreeSet::from(
1529+
extract(
1530+
"test.tsx",
1531+
r#"import { Box } from "@devup-ui/core";
1532+
<Box _hover={b ? void 0 : { bg: "blue" }} />;
15161533
"#,
15171534
ExtractOption {
15181535
package: "@devup-ui/core".to_string(),
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import { Box } from \"@devup-ui/core\";\n<Box _hover={b ? void 0 : { bg: \"blue\" }} />;\n\"#,\nExtractOption\n{\n package: \"@devup-ui/core\".to_string(), css_dir:\n \"@devup-ui/core\".to_string(), single_css: true, import_main_css: false\n}).unwrap())"
4+
---
5+
ToBTreeSet {
6+
styles: {
7+
Static(
8+
ExtractStaticStyle {
9+
property: "background",
10+
value: "blue",
11+
level: 0,
12+
selector: Some(
13+
Selector(
14+
"&:hover",
15+
),
16+
),
17+
style_order: None,
18+
},
19+
),
20+
},
21+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={b ? \"\" : \"a\"} />;\n",
22+
}

0 commit comments

Comments
 (0)