Skip to content

Commit 873f596

Browse files
committed
Fix duplicate issue
1 parent 1ddbcb3 commit 873f596

22 files changed

+110
-32
lines changed

.changeset/slimy-walls-melt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/wasm": patch
3+
---
4+
5+
Fix duplicate props issue

libs/css/src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,37 @@ pub fn to_kebab_case(value: &str) -> String {
196196
.collect()
197197
}
198198

199+
pub fn to_camel_case(value: &str) -> String {
200+
value
201+
.split('-')
202+
.enumerate()
203+
.map(|(i, s)| {
204+
if i == 0 {
205+
s.to_string()
206+
} else {
207+
format!("{}{}", s[0..1].to_uppercase(), &s[1..])
208+
}
209+
})
210+
.collect()
211+
}
212+
199213
pub fn convert_property(property: &str) -> PropertyType {
200214
GLOBAL_STYLE_PROPERTY
201215
.get(property)
202216
.cloned()
203217
.unwrap_or_else(|| to_kebab_case(property).into())
204218
}
205219

220+
pub fn sort_to_long(property: &str) -> String {
221+
GLOBAL_STYLE_PROPERTY
222+
.get(property)
223+
.map(|v| match v {
224+
PropertyType::Single(value) => to_camel_case(value),
225+
PropertyType::Multi(_) => property.to_string(),
226+
})
227+
.unwrap_or_else(|| property.to_string())
228+
}
229+
206230
pub fn sheet_to_classname(
207231
property: &str,
208232
level: u8,

libs/extractor/src/extract_style/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::utils::convert_value;
22
use crate::StyleProperty;
3-
use css::{css_to_classname, sheet_to_classname, sheet_to_variable_name, StyleSelector};
3+
use css::{
4+
css_to_classname, sheet_to_classname, sheet_to_variable_name, sort_to_long, StyleSelector,
5+
};
46
use once_cell::sync::Lazy;
57
use std::collections::HashSet;
68

@@ -37,7 +39,7 @@ impl ExtractStaticStyle {
3739
} else {
3840
convert_value(value)
3941
},
40-
property: property.to_string(),
42+
property: sort_to_long(property),
4143
level,
4244
selector,
4345
basic: false,
@@ -134,7 +136,7 @@ impl ExtractDynamicStyle {
134136
selector: Option<StyleSelector>,
135137
) -> Self {
136138
Self {
137-
property: property.to_string(),
139+
property: sort_to_long(property),
138140
level,
139141
identifier: identifier.to_string(),
140142
selector,

libs/extractor/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,4 +1312,21 @@ PROCESS_DATA.map(({ id, title, content }, idx) => (
13121312
)
13131313
.unwrap());
13141314
}
1315+
1316+
#[test]
1317+
#[serial]
1318+
fn test_duplicate_style_props() {
1319+
reset_class_map();
1320+
assert_debug_snapshot!(extract(
1321+
"test.js",
1322+
r#"import {Box} from '@devup-ui/core'
1323+
<Box bg="red" background="red" />
1324+
"#,
1325+
ExtractOption {
1326+
package: "@devup-ui/core".to_string(),
1327+
css_file: None
1328+
}
1329+
)
1330+
.unwrap());
1331+
}
13151332
}

libs/extractor/src/snapshots/extractor__tests__backtick_prop-2.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ExtractOutput {
66
styles: [
77
Dynamic(
88
ExtractDynamicStyle {
9-
property: "bg",
9+
property: "background",
1010
level: 0,
1111
identifier: "`${variable}`",
1212
selector: None,

libs/extractor/src/snapshots/extractor__tests__backtick_prop.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ExtractOutput {
66
styles: [
77
Static(
88
ExtractStaticStyle {
9-
property: "bg",
9+
property: "background",
1010
value: "black",
1111
level: 0,
1212
selector: None,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "extract(\"test.js\",\nr#\"import {Box} from '@devup-ui/core'\n <Box bg=\"red\" background=\"red\" />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap()"
4+
---
5+
ExtractOutput {
6+
styles: [
7+
Static(
8+
ExtractStaticStyle {
9+
property: "background",
10+
value: "red",
11+
level: 0,
12+
selector: None,
13+
basic: false,
14+
},
15+
),
16+
],
17+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"d0\" />;\n",
18+
}

libs/extractor/src/snapshots/extractor__tests__extract_compound_responsive_style_props.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ExtractOutput {
3030
),
3131
Static(
3232
ExtractStaticStyle {
33-
property: "bg",
33+
property: "background",
3434
value: "red",
3535
level: 0,
3636
selector: None,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ExtractOutput {
1515
),
1616
Static(
1717
ExtractStaticStyle {
18-
property: "bg",
18+
property: "background",
1919
value: "red",
2020
level: 0,
2121
selector: None,

libs/extractor/src/snapshots/extractor__tests__extract_static_css_class_name_props-4.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ExtractOutput {
66
styles: [
77
Static(
88
ExtractStaticStyle {
9-
property: "bg",
9+
property: "background",
1010
value: "red",
1111
level: 0,
1212
selector: None,

0 commit comments

Comments
 (0)