Skip to content

Commit 9a05530

Browse files
committed
Fix selector
1 parent dfebd9c commit 9a05530

File tree

5 files changed

+103
-11
lines changed

5 files changed

+103
-11
lines changed

libs/css/src/style_selector.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ impl Ord for StyleSelector {
6767
if c == Ordering::Equal { aa.cmp(bb) } else { c }
6868
}
6969
(StyleSelector::Selector(a), StyleSelector::Selector(b)) => {
70-
get_selector_order(a).cmp(&get_selector_order(b))
70+
let order_cmp = get_selector_order(a).cmp(&get_selector_order(b));
71+
if order_cmp == Ordering::Equal {
72+
a.cmp(b)
73+
} else {
74+
order_cmp
75+
}
7176
}
7277
(
7378
StyleSelector::Media {
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 _hover={{\n selectors: {\n \"&::placeholder, &:active\": {\n color: \"blue\"\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 _hover={{\n selectors: {\n \"&::placeholder, &:active\": {\n color: \"blue\"\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::placeholder,&:hover:active",
14+
"&:hover::placeholder",
15+
),
16+
),
17+
style_order: None,
18+
},
19+
),
20+
Static(
21+
ExtractStaticStyle {
22+
property: "color",
23+
value: "blue",
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
}

libs/extractor/src/snapshots/extractor__tests__extract_nested_selector-3.snap

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 _hover={{\n selectors: {\n \"&::placeholder\": {\n color: \"red\"\n },\n \"&::placeholder, &:active\": {\n color: \"blue\"\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 _hover={{\n selectors: {\n \"&::placeholder\": {\n color: \"red\"\n },\n \"&::placeholder, &:active\": {\n color: \"blue\"\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,7 +11,20 @@ ToBTreeSet {
1111
level: 0,
1212
selector: Some(
1313
Selector(
14-
"&:hover::placeholder,&:hover:active",
14+
"&:hover::placeholder",
15+
),
16+
),
17+
style_order: None,
18+
},
19+
),
20+
Static(
21+
ExtractStaticStyle {
22+
property: "color",
23+
value: "blue",
24+
level: 0,
25+
selector: Some(
26+
Selector(
27+
"&:hover:active",
1528
),
1629
),
1730
style_order: None,
@@ -31,5 +44,5 @@ ToBTreeSet {
3144
},
3245
),
3346
},
34-
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b\" />;\n",
47+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b c\" />;\n",
3548
}
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 \"& .a, & .b\": {\n bg: \"$primary\"\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",
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",
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+
}

libs/extractor/src/snapshots/extractor__tests__extract_selector-9.snap

Lines changed: 30 additions & 4 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 \"&:nth-last-child(2), &:nth-last-child(3)\": {\n mx: 1\n },\n _nthLastChild: {\n mx: 2\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 \"&:nth-last-child(2), &:nth-last-child(3)\": {\n mx: 1\n },\n _nthLastChild: {\n mx: 2\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,7 +11,20 @@ ToBTreeSet {
1111
level: 0,
1212
selector: Some(
1313
Selector(
14-
"&:nth-last-child(2),&:nth-last-child(3)",
14+
"&:nth-last-child(2)",
15+
),
16+
),
17+
style_order: None,
18+
},
19+
),
20+
Static(
21+
ExtractStaticStyle {
22+
property: "margin-left",
23+
value: "4px",
24+
level: 0,
25+
selector: Some(
26+
Selector(
27+
"&:nth-last-child(3)",
1528
),
1629
),
1730
style_order: None,
@@ -37,7 +50,20 @@ ToBTreeSet {
3750
level: 0,
3851
selector: Some(
3952
Selector(
40-
"&:nth-last-child(2),&:nth-last-child(3)",
53+
"&:nth-last-child(2)",
54+
),
55+
),
56+
style_order: None,
57+
},
58+
),
59+
Static(
60+
ExtractStaticStyle {
61+
property: "margin-right",
62+
value: "4px",
63+
level: 0,
64+
selector: Some(
65+
Selector(
66+
"&:nth-last-child(3)",
4167
),
4268
),
4369
style_order: None,
@@ -57,5 +83,5 @@ ToBTreeSet {
5783
},
5884
),
5985
},
60-
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b c d\" />;\n",
86+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b c d e f\" />;\n",
6187
}

0 commit comments

Comments
 (0)