Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cuddly-showers-shine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/wasm": patch
---

Support void 0
21 changes: 18 additions & 3 deletions libs/extractor/src/extractor/extract_style_from_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use oxc_ast::{
AstBuilder,
ast::{
BinaryOperator, Expression, LogicalOperator, ObjectPropertyKind, PropertyKey,
TemplateElementValue,
TemplateElementValue, UnaryOperator,
},
};
use oxc_span::SPAN;
Expand All @@ -37,6 +37,7 @@ pub fn extract_style_from_expression<'a>(
selector: &Option<StyleSelector>,
) -> ExtractResult<'a> {
let mut typo = false;
println!("expression: {:?}", expression);

if name.is_none() && selector.is_none() {
let mut style_order = None;
Expand Down Expand Up @@ -287,8 +288,22 @@ pub fn extract_style_from_expression<'a>(
}
} else {
match expression {
Expression::UnaryExpression(_)
| Expression::BinaryExpression(_)
Expression::UnaryExpression(un) => ExtractResult {
styles: if un.operator == UnaryOperator::Void {
vec![]
} else {
vec![ExtractStyleProp::Static(ExtractStyleValue::Dynamic(
ExtractDynamicStyle::new(
name.unwrap(),
level,
&expression_to_code(expression),
selector.clone(),
),
))]
},
..ExtractResult::default()
},
Expression::BinaryExpression(_)
| Expression::StaticMemberExpression(_)
| Expression::CallExpression(_) => ExtractResult {
styles: vec![ExtractStyleProp::Static(ExtractStyleValue::Dynamic(
Expand Down
17 changes: 17 additions & 0 deletions libs/extractor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,23 @@ import clsx from 'clsx'
"test.tsx",
r#"import { Box } from "@devup-ui/core";
<Box margin={a === b ? undefined : null} />;
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
css_dir: "@devup-ui/core".to_string(),
single_css: true,
import_main_css: false
}
)
.unwrap()
));

reset_class_map();
assert_debug_snapshot!(ToBTreeSet::from(
extract(
"test.tsx",
r#"import { Box } from "@devup-ui/core";
<Box _hover={b ? void 0 : { bg: "blue" }} />;
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
source: libs/extractor/src/lib.rs
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())"
---
ToBTreeSet {
styles: {
Static(
ExtractStaticStyle {
property: "background",
value: "blue",
level: 0,
selector: Some(
Selector(
"&:hover",
),
),
style_order: None,
},
),
},
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={b ? \"\" : \"a\"} />;\n",
}
Loading