Skip to content

Commit cea2849

Browse files
authored
Merge pull request #222 from dev-five-git/fix-classname
Fix classname gen logic
2 parents b12125b + 2765ea7 commit cea2849

File tree

4 files changed

+68
-6
lines changed

4 files changed

+68
-6
lines changed

.changeset/quick-views-guess.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 classname issue

libs/extractor/src/lib.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,39 @@ mod tests {
604604
)
605605
.unwrap()
606606
));
607+
608+
reset_class_map();
609+
assert_debug_snapshot!(ToBTreeSet::from(
610+
extract(
611+
"test.tsx",
612+
r#"import { Box, Button as DevupButton, Center, css } from '@devup-ui/core'
613+
import clsx from 'clsx'
614+
615+
<DevupButton
616+
boxSizing="border-box"
617+
className={clsx(
618+
variants[variant],
619+
isError && variant === 'default' && errorClassNames,
620+
className,
621+
)}
622+
typography={
623+
isPrimary
624+
? {
625+
sm: 'buttonS',
626+
md: 'buttonM',
627+
}[size]
628+
: undefined
629+
}
630+
{...props}
631+
/>
632+
"#,
633+
ExtractOption {
634+
package: "@devup-ui/core".to_string(),
635+
css_file: None
636+
}
637+
)
638+
.unwrap()
639+
));
607640
}
608641

609642
#[test]

libs/extractor/src/prop_modify_utils.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,19 +318,19 @@ fn merge_string_expressions<'a>(
318318
raw: ast_builder.atom(&{
319319
let trimmed = s.trim();
320320
if trimmed.is_empty() {
321-
"".to_string()
322-
} else if idx == string_literals.len() - 1 {
321+
if idx == 0 {
322+
"".to_string()
323+
} else {
324+
" ".to_string()
325+
}
326+
} else {
323327
let prefix = if idx == 0 { "" } else { " " };
324328
let suffix = if string_literals.len() == other_expressions.len() {
325329
" "
326330
} else {
327331
""
328332
};
329333
format!("{prefix}{trimmed}{suffix}")
330-
} else if idx == string_literals.len() - 1 {
331-
trimmed.to_string()
332-
} else {
333-
format!("{trimmed} ")
334334
}
335335
}),
336336
cooked: None,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import { Box, Button as DevupButton, Center, css } from '@devup-ui/core'\nimport clsx from 'clsx'\n\n<DevupButton\n boxSizing=\"border-box\"\n className={clsx(\n variants[variant],\n isError && variant === 'default' && errorClassNames,\n className,\n )}\n typography={\n isPrimary\n ? {\n sm: 'buttonS',\n md: 'buttonM',\n }[size]\n : undefined\n }\n {...props}\n />\n\"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
4+
---
5+
ToBTreeSet {
6+
styles: {
7+
Static(
8+
ExtractStaticStyle {
9+
property: "boxSizing",
10+
value: "border-box",
11+
level: 0,
12+
selector: None,
13+
style_order: None,
14+
},
15+
),
16+
Typography(
17+
"buttonM",
18+
),
19+
Typography(
20+
"buttonS",
21+
),
22+
},
23+
code: "import \"@devup-ui/core/devup-ui.css\";\nimport clsx from \"clsx\";\n<button {...props} className={`${clsx(variants[variant], isError && variant === \"default\" && errorClassNames, className) ?? \"\"} d0 ${isPrimary ? {\n\t\"md\": \"typo-buttonM\",\n\t\"sm\": \"typo-buttonS\"\n}[size] : \"\"} ${props?.className ?? \"\"}`} style={props?.style} />;\n",
24+
}

0 commit comments

Comments
 (0)