Skip to content

Commit 43dcfa5

Browse files
committed
Fix classname gen logic
1 parent b12125b commit 43dcfa5

4 files changed

Lines changed: 78 additions & 6 deletions

File tree

.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: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,16 @@ fn merge_string_expressions<'a>(
294294
other_expressions.push(ex.clone_in(ast_builder.allocator));
295295
}
296296
}
297+
println!(
298+
"string_literals: {} {:?}",
299+
string_literals.len(),
300+
string_literals
301+
);
302+
println!(
303+
"other_expressions: {} {:?}",
304+
other_expressions.len(),
305+
other_expressions
306+
);
297307
if other_expressions.is_empty() {
298308
return Some(Expression::StringLiteral(
299309
ast_builder.alloc_string_literal(
@@ -318,19 +328,19 @@ fn merge_string_expressions<'a>(
318328
raw: ast_builder.atom(&{
319329
let trimmed = s.trim();
320330
if trimmed.is_empty() {
321-
"".to_string()
322-
} else if idx == string_literals.len() - 1 {
331+
if idx == 0 {
332+
"".to_string()
333+
} else {
334+
" ".to_string()
335+
}
336+
} else {
323337
let prefix = if idx == 0 { "" } else { " " };
324338
let suffix = if string_literals.len() == other_expressions.len() {
325339
" "
326340
} else {
327341
""
328342
};
329343
format!("{prefix}{trimmed}{suffix}")
330-
} else if idx == string_literals.len() - 1 {
331-
trimmed.to_string()
332-
} else {
333-
format!("{trimmed} ")
334344
}
335345
}),
336346
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)