Skip to content

Commit 01d97c2

Browse files
committed
Fix selector
1 parent 9a05530 commit 01d97c2

9 files changed

+209
-45
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"changes": { "bindings/devup-ui-wasm/package.json": "Patch" },
3+
"note": "Fix selector issue",
4+
"date": "2025-11-19T07:56:23.681473700Z"
5+
}

libs/extractor/src/lib.rs

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,39 +2331,63 @@ import clsx from 'clsx'
23312331
)
23322332
.unwrap()
23332333
));
2334-
}
23352334

2336-
// #[test]
2337-
// #[serial]
2338-
// fn optimize_func1() {
2339-
// reset_class_map();
2340-
// assert_debug_snapshot!(ToBTreeSet::from(
2341-
// extract(
2342-
// "test.tsx",
2343-
// r#"import {Box} from '@devup-ui/core'
2344-
// <Box selectors={{
2345-
// ".test-picker__day--keyboard-selected": {
2346-
// _hover: {
2347-
// bg: "$primary"
2348-
// },
2349-
// selectors: {
2350-
// "&:active": {
2351-
// bg: "$primary"
2352-
// }
2353-
// }
2354-
// }
2355-
// }} />
2356-
// "#,
2357-
// ExtractOption {
2358-
// package: "@devup-ui/core".to_string(),
2359-
// css_dir: "@devup-ui/core".to_string(),
2360-
// single_css: true,
2361-
// import_main_css: false
2362-
// }
2363-
// )
2364-
// .unwrap()
2365-
// ));
2366-
// }
2335+
reset_class_map();
2336+
assert_debug_snapshot!(ToBTreeSet::from(
2337+
extract(
2338+
"test.tsx",
2339+
r#"import {Box} from '@devup-ui/core'
2340+
<Box selectors={{
2341+
".test-picker__day--keyboard-selected": {
2342+
_hover: {
2343+
bg: "$primary"
2344+
},
2345+
selectors: {
2346+
"&:active": {
2347+
bg: "$primary"
2348+
}
2349+
}
2350+
}
2351+
}} />
2352+
"#,
2353+
ExtractOption {
2354+
package: "@devup-ui/core".to_string(),
2355+
css_dir: "@devup-ui/core".to_string(),
2356+
single_css: true,
2357+
import_main_css: false
2358+
}
2359+
)
2360+
.unwrap()
2361+
));
2362+
2363+
reset_class_map();
2364+
assert_debug_snapshot!(ToBTreeSet::from(
2365+
extract(
2366+
"test.tsx",
2367+
r#"import {Box} from '@devup-ui/core'
2368+
<Box selectors={{
2369+
".a, .b": {
2370+
_hover: {
2371+
bg: "$primary"
2372+
},
2373+
selectors: {
2374+
"&:active": {
2375+
bg: "$secondary"
2376+
}
2377+
}
2378+
}
2379+
}} />
2380+
"#,
2381+
ExtractOption {
2382+
package: "@devup-ui/core".to_string(),
2383+
css_dir: "@devup-ui/core".to_string(),
2384+
single_css: true,
2385+
import_main_css: false
2386+
}
2387+
)
2388+
.unwrap()
2389+
));
2390+
}
23672391

23682392
#[test]
23692393
#[serial]
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: libs/extractor/src/lib.rs
3-
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box \n selectors={{\n _hover: {\n selectors: {\n \"_themeDark,_active\": {\n color: \"red\",\n }\n }\n }\n }}\n />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
3+
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box \n selectors={{\n _hover: {\n selectors: {\n \"_themeDark,_active\": {\n color: \"red\",\n }\n }\n }\n }}\n />\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())"
44
---
55
ToBTreeSet {
66
styles: {
@@ -11,12 +11,25 @@ ToBTreeSet {
1111
level: 0,
1212
selector: Some(
1313
Selector(
14-
":root[data-theme=dark] &:hover,&:hover:active",
14+
":root[data-theme=dark] &:hover",
15+
),
16+
),
17+
style_order: None,
18+
},
19+
),
20+
Static(
21+
ExtractStaticStyle {
22+
property: "color",
23+
value: "red",
24+
level: 0,
25+
selector: Some(
26+
Selector(
27+
"&:hover:active",
1528
),
1629
),
1730
style_order: None,
1831
},
1932
),
2033
},
21-
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a\" />;\n",
34+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b\" />;\n",
2235
}
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: libs/extractor/src/lib.rs
3-
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box \n selectors={{\n _hover: {\n selectors: {\n \"_themeDark,_placeholder\": {\n color: \"red\",\n }\n }\n }\n }}\n />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
3+
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box \n selectors={{\n _hover: {\n selectors: {\n \"_themeDark,_placeholder\": {\n color: \"red\",\n }\n }\n }\n }}\n />\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())"
44
---
55
ToBTreeSet {
66
styles: {
@@ -11,12 +11,25 @@ ToBTreeSet {
1111
level: 0,
1212
selector: Some(
1313
Selector(
14-
":root[data-theme=dark] &:hover,&:hover::placeholder",
14+
":root[data-theme=dark] &:hover",
15+
),
16+
),
17+
style_order: None,
18+
},
19+
),
20+
Static(
21+
ExtractStaticStyle {
22+
property: "color",
23+
value: "red",
24+
level: 0,
25+
selector: Some(
26+
Selector(
27+
"&:hover::placeholder",
1528
),
1629
),
1730
style_order: None,
1831
},
1932
),
2033
},
21-
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a\" />;\n",
34+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b\" />;\n",
2235
}
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: libs/extractor/src/lib.rs
3-
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box \n selectors={{\n _hover: {\n selectors: {\n \"&:active, _hover\": {\n color: \"red\",\n }\n }\n }\n }}\n />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
3+
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box \n selectors={{\n _hover: {\n selectors: {\n \"&:active, _hover\": {\n color: \"red\",\n }\n }\n }\n }}\n />\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())"
44
---
55
ToBTreeSet {
66
styles: {
@@ -11,12 +11,25 @@ ToBTreeSet {
1111
level: 0,
1212
selector: Some(
1313
Selector(
14-
"&:hover:active,&:hover:hover",
14+
"&:hover:active",
15+
),
16+
),
17+
style_order: None,
18+
},
19+
),
20+
Static(
21+
ExtractStaticStyle {
22+
property: "color",
23+
value: "red",
24+
level: 0,
25+
selector: Some(
26+
Selector(
27+
"&:hover:hover",
1528
),
1629
),
1730
style_order: None,
1831
},
1932
),
2033
},
21-
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a\" />;\n",
34+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b\" />;\n",
2235
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box selectors={{\n \".test-picker__day--keyboard-selected\": {\n _hover: {\n bg: \"$primary\"\n },\n selectors: {\n \"&:active\": {\n bg: \"$primary\"\n }\n }\n }\n }} />\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: "$primary",
11+
level: 0,
12+
selector: Some(
13+
Selector(
14+
"& .test-picker__day--keyboard-selected:active",
15+
),
16+
),
17+
style_order: None,
18+
},
19+
),
20+
Static(
21+
ExtractStaticStyle {
22+
property: "background",
23+
value: "$primary",
24+
level: 0,
25+
selector: Some(
26+
Selector(
27+
"& .test-picker__day--keyboard-selected:hover",
28+
),
29+
),
30+
style_order: None,
31+
},
32+
),
33+
},
34+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b\" />;\n",
35+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box selectors={{\n \".a, .b\": {\n _hover: {\n bg: \"$primary\"\n },\n selectors: {\n \"&:active\": {\n bg: \"$secondary\"\n }\n }\n }\n }} />\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: "$primary",
11+
level: 0,
12+
selector: Some(
13+
Selector(
14+
"& .a:hover",
15+
),
16+
),
17+
style_order: None,
18+
},
19+
),
20+
Static(
21+
ExtractStaticStyle {
22+
property: "background",
23+
value: "$primary",
24+
level: 0,
25+
selector: Some(
26+
Selector(
27+
"& .b:hover",
28+
),
29+
),
30+
style_order: None,
31+
},
32+
),
33+
Static(
34+
ExtractStaticStyle {
35+
property: "background",
36+
value: "$secondary",
37+
level: 0,
38+
selector: Some(
39+
Selector(
40+
"& .a:active",
41+
),
42+
),
43+
style_order: None,
44+
},
45+
),
46+
Static(
47+
ExtractStaticStyle {
48+
property: "background",
49+
value: "$secondary",
50+
level: 0,
51+
selector: Some(
52+
Selector(
53+
"& .b:active",
54+
),
55+
),
56+
style_order: None,
57+
},
58+
),
59+
},
60+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b c d\" />;\n",
61+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
source: libs/sheet/src/lib.rs
3-
expression: sheet.create_css()
3+
expression: "sheet.create_css(None, false).split(\"*/\").nth(1).unwrap()"
44
---
5-
"*[role=group]:focus-visible .test{background:blue}*:hover .test{background:red}"
5+
"*:hover .test{background:red}*[role=group]:focus-visible .test{background:blue}"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
source: libs/sheet/src/lib.rs
3-
expression: sheet.create_css()
3+
expression: "sheet.create_css(None, false).split(\"*/\").nth(1).unwrap()"
44
---
5-
":root[data-theme=dark] .test{margin-bottom:40px}:root[data-theme=dark] .test{margin-left:40px}:root[data-theme=light] .test{margin-left:50px}:root[data-theme=dark] .test{margin-right:40px}:root[data-theme=light] .test{margin-right:50px}:root[data-theme=dark] .test{margin-top:40px}"
5+
":root[data-theme=dark] .test{margin-bottom:40px}:root[data-theme=dark] .test{margin-left:40px}:root[data-theme=dark] .test{margin-right:40px}:root[data-theme=dark] .test{margin-top:40px}:root[data-theme=light] .test{margin-left:50px}:root[data-theme=light] .test{margin-right:50px}"

0 commit comments

Comments
 (0)