Skip to content

Commit 246f464

Browse files
committed
Fix underscore issue
1 parent 8312bdf commit 246f464

File tree

6 files changed

+67
-10
lines changed

6 files changed

+67
-10
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 selectors normialized class when including underscore(_)",
4+
"date": "2025-11-18T08:18:08.445637Z"
5+
}

libs/css/src/selector_separator.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::constant::DOUBLE_SEPARATOR;
55
pub enum SelectorSeparator {
66
Single,
77
Double,
8+
Space,
89
None,
910
}
1011
impl Display for SelectorSeparator {
@@ -15,17 +16,24 @@ impl Display for SelectorSeparator {
1516
match self {
1617
SelectorSeparator::Single => ":",
1718
SelectorSeparator::Double => "::",
19+
SelectorSeparator::Space => " ",
1820
SelectorSeparator::None => "",
1921
}
2022
)
2123
}
2224
}
2325
impl From<&str> for SelectorSeparator {
2426
fn from(value: &str) -> Self {
25-
if value.starts_with(":") || value.is_empty() || value.starts_with("[") {
27+
if value.starts_with(":")
28+
|| value.is_empty()
29+
|| value.starts_with("[")
30+
|| value.starts_with(" ")
31+
{
2632
SelectorSeparator::None
2733
} else if DOUBLE_SEPARATOR.contains(value) {
2834
SelectorSeparator::Double
35+
} else if value.starts_with("#") || value.starts_with(".") || value.starts_with("*") {
36+
SelectorSeparator::Space
2937
} else {
3038
SelectorSeparator::Single
3139
}

libs/extractor/src/css_utils.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,24 +149,20 @@ pub fn optimize_css_block(css: &str) -> String {
149149
.join("}")
150150
.split(";")
151151
.map(|s| {
152-
println!("s: {}", s);
153152
let parts = s.split("{").collect::<Vec<&str>>();
154153
let first_part = if parts.len() == 1 {
155154
"".to_string()
156155
} else {
157156
format!("{}{{", parts.first().unwrap().trim())
158157
};
159-
println!("first_part: {}", first_part);
160158
let last_part = parts.last().unwrap().trim();
161159
if !last_part.contains(":") {
162-
println!("last_part: {}", last_part);
163160
format!("{first_part}{last_part}")
164161
} else {
165162
let mut iter = last_part.split(":");
166163
let property = iter.next().unwrap().trim();
167164
let value = iter.next().unwrap().trim();
168165

169-
println!("property: {}, value: {}", property, value);
170166
let value = if check_multi_css_optimize(property.split("{").last().unwrap()) {
171167
optimize_mutli_css_value(value)
172168
} else {

libs/extractor/src/extractor/extract_style_from_expression.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,30 @@ pub fn extract_style_from_expression<'a>(
204204
if name.starts_with("_") {
205205
if name.starts_with("_theme") {
206206
StyleSelector::from([
207-
to_kebab_case(name.replace("_", "").as_str()).as_str(),
207+
to_kebab_case(name.strip_prefix("_").unwrap_or(name))
208+
.as_str(),
208209
&selector.to_string(),
209210
])
210211
.to_string()
211212
} else {
212213
StyleSelector::from([
213214
&selector.to_string(),
214-
to_kebab_case(name.replace("_", "").as_str()).as_str(),
215+
to_kebab_case(name.strip_prefix("_").unwrap_or(name))
216+
.as_str(),
215217
])
216218
.to_string()
217219
}
218220
} else {
219221
name.replace("&", &selector.to_string())
220222
}
221223
} else if name.starts_with("_") {
222-
StyleSelector::from(to_kebab_case(&name.replace("_", "")).as_str())
223-
.to_string()
224+
StyleSelector::from(
225+
to_kebab_case(name.strip_prefix("_").unwrap_or(name)).as_str(),
226+
)
227+
.to_string()
224228
} else {
225-
StyleSelector::from(name.replace("_", "").as_str()).to_string()
229+
StyleSelector::from(name.strip_prefix("_").unwrap_or(name))
230+
.to_string()
226231
}
227232
})
228233
.collect::<Vec<_>>()

libs/extractor/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,6 +2289,27 @@ import clsx from 'clsx'
22892289
)
22902290
.unwrap()
22912291
));
2292+
2293+
reset_class_map();
2294+
assert_debug_snapshot!(ToBTreeSet::from(
2295+
extract(
2296+
"test.tsx",
2297+
r#"import {Box} from '@devup-ui/core'
2298+
<Box selectors={{
2299+
".test-picker__day--keyboard-selected": {
2300+
bg: "$primary"
2301+
}
2302+
}} />
2303+
"#,
2304+
ExtractOption {
2305+
package: "@devup-ui/core".to_string(),
2306+
css_dir: "@devup-ui/core".to_string(),
2307+
single_css: true,
2308+
import_main_css: false
2309+
}
2310+
)
2311+
.unwrap()
2312+
));
22922313
}
22932314

22942315
#[test]
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 selectors={{\n \".test-picker__day--keyboard-selected\": {\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+
"& .test-picker__day--keyboard-selected",
15+
),
16+
),
17+
style_order: None,
18+
},
19+
),
20+
},
21+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a\" />;\n",
22+
}

0 commit comments

Comments
 (0)