Skip to content

Commit d416a39

Browse files
committed
Support conditional selector
1 parent 5f3b736 commit d416a39

File tree

5 files changed

+163
-99
lines changed

5 files changed

+163
-99
lines changed

Cargo.lock

Lines changed: 31 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/extractor/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
oxc_parser = "0.51.0"
8-
oxc_syntax = "0.51.0"
9-
oxc_span = "0.51.0"
10-
oxc_allocator = "0.51.0"
11-
oxc_ast = "0.51.0"
12-
oxc_codegen = "0.51.0"
7+
oxc_parser = "0.52.0"
8+
oxc_syntax = "0.52.0"
9+
oxc_span = "0.52.0"
10+
oxc_allocator = "0.52.0"
11+
oxc_ast = "0.52.0"
12+
oxc_codegen = "0.52.0"
1313
css = { path = "../css" }
1414
once_cell = "1.20.3"
1515

libs/extractor/src/lib.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,69 @@ mod tests {
914914
.unwrap());
915915
}
916916

917+
#[test]
918+
#[serial]
919+
fn extract_conditional_selector() {
920+
reset_class_map();
921+
assert_debug_snapshot!(extract(
922+
"test.tsx",
923+
r"import {Box} from '@devup-ui/core'
924+
<Box _hover={a===b ? undefined : {
925+
mx: 1
926+
}} />
927+
",
928+
ExtractOption {
929+
package: "@devup-ui/core".to_string(),
930+
css_file: None
931+
}
932+
)
933+
.unwrap());
934+
935+
reset_class_map();
936+
assert_debug_snapshot!(extract(
937+
"test.tsx",
938+
r"import {Box} from '@devup-ui/core'
939+
<Box _hover={a===b && {
940+
mx: 1
941+
}} />
942+
",
943+
ExtractOption {
944+
package: "@devup-ui/core".to_string(),
945+
css_file: None
946+
}
947+
)
948+
.unwrap());
949+
950+
reset_class_map();
951+
assert_debug_snapshot!(extract(
952+
"test.tsx",
953+
r"import {Box} from '@devup-ui/core'
954+
<Box _hover={a===b && {}} />
955+
",
956+
ExtractOption {
957+
package: "@devup-ui/core".to_string(),
958+
css_file: None
959+
}
960+
)
961+
.unwrap());
962+
963+
reset_class_map();
964+
assert_debug_snapshot!(extract(
965+
"test.tsx",
966+
r"import {Box} from '@devup-ui/core'
967+
<Box _hover={a===b && {
968+
mx: 1,
969+
my: 1
970+
}} />
971+
",
972+
ExtractOption {
973+
package: "@devup-ui/core".to_string(),
974+
css_file: None
975+
}
976+
)
977+
.unwrap());
978+
}
979+
917980
#[test]
918981
#[serial]
919982
fn extract_selector_with_responsive() {

libs/extractor/src/style_extractor.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -466,21 +466,19 @@ pub fn extract_style_from_expression<'a>(
466466
}
467467
}
468468
Expression::LogicalExpression(logical) => {
469-
let res = name.and_then(|name| {
470-
match extract_style_from_expression(
471-
ast_builder,
472-
Some(name),
473-
&mut logical.right,
474-
level,
475-
selector,
476-
) {
477-
ExtractResult::Extract {
478-
styles: Some(styles),
479-
..
480-
} => Some(Box::new(ExtractStyleProp::StaticArray(styles))),
481-
_ => None,
482-
}
483-
});
469+
let res = match extract_style_from_expression(
470+
ast_builder,
471+
name,
472+
&mut logical.right,
473+
level,
474+
selector,
475+
) {
476+
ExtractResult::Extract {
477+
styles: Some(styles),
478+
..
479+
} => Some(Box::new(ExtractStyleProp::StaticArray(styles))),
480+
_ => None,
481+
};
484482
match logical.operator {
485483
LogicalOperator::Or => ExtractResult::Extract {
486484
styles: Some(vec![ExtractStyleProp::Conditional {

0 commit comments

Comments
 (0)