Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tame-berries-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/wasm": patch
---

Fix classname order issue
34 changes: 34 additions & 0 deletions libs/extractor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,40 @@ mod tests {
)
.unwrap()
));

reset_class_map();
assert_debug_snapshot!(ToBTreeSet::from(
extract(
"test.tsx",
r#"import {Box as C} from '@devup-ui/core'
<C padding={1} margin={2} className={variable} />
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
css_file: None
}
)
.unwrap()
));

reset_class_map();
assert_debug_snapshot!(ToBTreeSet::from(
extract(
"test.tsx",
r#"import {Box as C} from '@devup-ui/core'
<C padding={1}
_hover={{
borderColor: true ? 'blue' : ``,
}}
className={variable} />
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
css_file: None
}
)
.unwrap()
));
}

#[test]
Expand Down
100 changes: 79 additions & 21 deletions libs/extractor/src/prop_modify_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,40 +205,98 @@
return None;
}
if expressions.len() == 1 {
return Some(expressions[0].clone_in(ast_builder.allocator));
return Some(expressions.first().unwrap().clone_in(ast_builder.allocator));
}

let mut string_literals = vec![];
let mut string_literals: std::vec::Vec<String> = vec![];
let mut other_expressions = vec![];
for ex in expressions {
string_literals.push("".to_string());
if let Expression::StringLiteral(literal) = ex {
string_literals.push(literal.value.trim());
if !string_literals.is_empty() {
string_literals
.last_mut()
.unwrap()
.push_str(&format!(" {}", literal.value.trim()));
} else {
string_literals.push(literal.value.trim().to_string());

Check warning on line 222 in libs/extractor/src/prop_modify_utils.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/prop_modify_utils.rs#L222

Added line #L222 was not covered by tests
}
} else if let Expression::TemplateLiteral(template) = ex {
if !string_literals.is_empty() {
string_literals.last_mut().unwrap().push_str(&format!(
" {}",

Check warning on line 227 in libs/extractor/src/prop_modify_utils.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/prop_modify_utils.rs#L227

Added line #L227 was not covered by tests
template
.quasis
.iter()

Check warning on line 230 in libs/extractor/src/prop_modify_utils.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/prop_modify_utils.rs#L229-L230

Added lines #L229 - L230 were not covered by tests
.map(|q| q.value.raw.trim())
.filter(|q| !q.is_empty())
.collect::<Vec<_>>()
.join(" ")

Check warning on line 234 in libs/extractor/src/prop_modify_utils.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/prop_modify_utils.rs#L233-L234

Added lines #L233 - L234 were not covered by tests
));
} else {
string_literals.push(
template
.quasis
.iter()
.map(|q| q.value.raw.as_str())
.collect::<Vec<_>>()
.join(" "),

Check warning on line 243 in libs/extractor/src/prop_modify_utils.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/prop_modify_utils.rs#L237-L243

Added lines #L237 - L243 were not covered by tests
);
}
other_expressions.extend(template.expressions.clone_in(ast_builder.allocator));
} else {
other_expressions.push(ex);
other_expressions.push(ex.clone_in(ast_builder.allocator));
}
}
if other_expressions.is_empty() {
return Some(Expression::StringLiteral(ast_builder.alloc_string_literal(
SPAN,
ast_builder.atom(&string_literals.join(" ")),
None,
)));
return Some(Expression::StringLiteral(
ast_builder.alloc_string_literal(
SPAN,

Check warning on line 254 in libs/extractor/src/prop_modify_utils.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/prop_modify_utils.rs#L254

Added line #L254 was not covered by tests
ast_builder.atom(
&string_literals
.iter()

Check warning on line 257 in libs/extractor/src/prop_modify_utils.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/prop_modify_utils.rs#L257

Added line #L257 was not covered by tests
.map(|s| s.trim())
.filter(|s| !s.is_empty())
.collect::<Vec<_>>()
.join(" "),

Check warning on line 261 in libs/extractor/src/prop_modify_utils.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/prop_modify_utils.rs#L260-L261

Added lines #L260 - L261 were not covered by tests
),
None,
),
));
}
let literals = oxc_allocator::Vec::from_iter_in(
string_literals.iter().enumerate().map(|(idx, s)| {
ast_builder.template_element(
SPAN,

Check warning on line 270 in libs/extractor/src/prop_modify_utils.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/prop_modify_utils.rs#L270

Added line #L270 was not covered by tests
TemplateElementValue {
raw: ast_builder.atom(&{
let trimmed = s.trim();
if trimmed.is_empty() {
"".to_string()
} else if idx > 0 && idx == string_literals.len() - 1 {
if string_literals.len() == other_expressions.len() {
format!(" {trimmed} ")
} else {
format!(" {trimmed}")
}
} else if idx == string_literals.len() - 1 {
trimmed.to_string()

Check warning on line 283 in libs/extractor/src/prop_modify_utils.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/prop_modify_utils.rs#L283

Added line #L283 was not covered by tests
} else {
format!("{trimmed} ")
}
}),
cooked: None,
},
false,

Check warning on line 290 in libs/extractor/src/prop_modify_utils.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/prop_modify_utils.rs#L290

Added line #L290 was not covered by tests
)
}),
ast_builder.allocator,
);

Some(Expression::TemplateLiteral(
ast_builder.alloc_template_literal(
SPAN,
oxc_allocator::Vec::from_iter_in(
[ast_builder.template_element(
SPAN,
TemplateElementValue {
raw: ast_builder.atom(&format!("{} ", string_literals.join(" "))),
cooked: None,
},
false,
)],
ast_builder.allocator,
),
literals,

Check warning on line 299 in libs/extractor/src/prop_modify_utils.rs

View check run for this annotation

Codecov / codecov/patch

libs/extractor/src/prop_modify_utils.rs#L299

Added line #L299 was not covered by tests
oxc_allocator::Vec::from_iter_in(
other_expressions
.into_iter()
Expand All @@ -264,7 +322,7 @@
ast_builder.alloc_object_expression(
SPAN,
oxc_allocator::Vec::from_iter_in(
expressions.into_iter().map(|ex| {
expressions.iter().map(|ex| {
ObjectPropertyKind::SpreadProperty(
ast_builder.alloc_spread_element(SPAN, ex.clone_in(ast_builder.allocator)),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ ToBTreeSet {
},
),
},
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={`d0 d1 d2 d3 ${\"a\" + \"b\"}`} />;\n",
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={`${\"a\" + \"b\"} d0 d1 d2 d3`} />;\n",
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ ToBTreeSet {
},
),
},
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={`d0 d1 ${\"a\" + \"b\"}`} />;\n",
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={`${\"a\" + \"b\"} d0 d1`} />;\n",
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ ToBTreeSet {
},
),
},
code: "import \"@devup-ui/core/devup-ui.css\";\n<img src=\"/next.svg\" alt=\"Next.js logo\" className={`d0 d1 ${styles.logo}`} />;\n",
code: "import \"@devup-ui/core/devup-ui.css\";\n<img src=\"/next.svg\" alt=\"Next.js logo\" className={`${styles.logo} d0 d1`} />;\n",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
source: libs/extractor/src/lib.rs
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box as C} from '@devup-ui/core'\n <C padding={1} margin={2} className={variable} />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
---
ToBTreeSet {
styles: {
Static(
ExtractStaticStyle {
property: "margin",
value: "8px",
level: 0,
selector: None,
style_order: None,
},
),
Static(
ExtractStaticStyle {
property: "padding",
value: "4px",
level: 0,
selector: None,
style_order: None,
},
),
},
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={`${variable} d0 d1`} />;\n",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
source: libs/extractor/src/lib.rs
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box as C} from '@devup-ui/core'\n <C padding={1} \n _hover={{\n borderColor: true ? 'blue' : ``,\n }}\n className={variable} />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
---
ToBTreeSet {
styles: {
Static(
ExtractStaticStyle {
property: "borderColor",
value: "",
level: 0,
selector: Some(
Selector(
"&:hover",
),
),
style_order: None,
},
),
Static(
ExtractStaticStyle {
property: "borderColor",
value: "blue",
level: 0,
selector: Some(
Selector(
"&:hover",
),
),
style_order: None,
},
),
Static(
ExtractStaticStyle {
property: "padding",
value: "4px",
level: 0,
selector: None,
style_order: None,
},
),
},
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={`${variable} d0 ${true ? \"d1\" : \"d2\"}`} />;\n",
}

This file was deleted.