Skip to content

Commit 8535462

Browse files
committed
Refactor code
1 parent 7c47c02 commit 8535462

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

libs/extractor/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5590,6 +5590,23 @@ export {
55905590
)
55915591
.unwrap()
55925592
));
5593+
5594+
reset_class_map();
5595+
assert_debug_snapshot!(ToBTreeSet::from(
5596+
extract(
5597+
"test.jsx",
5598+
r#"import {Box} from '@devup-ui/core'
5599+
<Box styleVars={{...styleVars}} />
5600+
"#,
5601+
ExtractOption {
5602+
package: "@devup-ui/core".to_string(),
5603+
css_dir: "@devup-ui/core".to_string(),
5604+
single_css: true,
5605+
import_main_css: false
5606+
}
5607+
)
5608+
.unwrap()
5609+
));
55935610
}
55945611

55955612
#[test]

libs/extractor/src/prop_modify_utils.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -347,23 +347,24 @@ fn merge_string_expressions<'a>(
347347
));
348348
}
349349

350+
let q = oxc_allocator::Vec::from_iter_in(
351+
string_literals.iter().enumerate().map(|(idx, s)| {
352+
let tail = idx == string_literals.len() - 1;
353+
ast_builder.template_element(
354+
SPAN,
355+
TemplateElementValue {
356+
raw: ast_builder.atom(s),
357+
cooked: None,
358+
},
359+
tail,
360+
)
361+
}),
362+
ast_builder.allocator,
363+
);
350364
Some(
351365
ast_builder.expression_template_literal(
352366
SPAN,
353-
oxc_allocator::Vec::from_iter_in(
354-
string_literals.iter().enumerate().map(|(idx, s)| {
355-
let tail = idx == string_literals.len() - 1;
356-
ast_builder.template_element(
357-
SPAN,
358-
TemplateElementValue {
359-
raw: ast_builder.atom(s),
360-
cooked: None,
361-
},
362-
tail,
363-
)
364-
}),
365-
ast_builder.allocator,
366-
),
367+
q,
367368
oxc_allocator::Vec::from_iter_in(
368369
other_expressions
369370
.into_iter()
@@ -432,7 +433,7 @@ pub fn convert_style_vars<'a>(
432433
let name = match &p.key {
433434
PropertyKey::StaticIdentifier(ident) => Some(ident.name),
434435
PropertyKey::StringLiteral(ident) => Some(ident.value),
435-
etc => {
436+
_ => {
436437
obj.properties.insert(
437438
idx,
438439
ast_builder.object_property_kind_object_property(
@@ -462,7 +463,7 @@ pub fn convert_style_vars<'a>(
462463
ast_builder.allocator,
463464
),
464465
oxc_allocator::Vec::from_array_in(
465-
[etc.to_expression().clone_in(ast_builder.allocator)],
466+
[p.key.to_expression().clone_in(ast_builder.allocator)],
466467
ast_builder.allocator,
467468
),
468469
)),
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "ToBTreeSet::from(extract(\"test.jsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box styleVars={{...styleVars}} />\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+
code: "<div style={{ ...styleVars }} />;\n",
8+
}

0 commit comments

Comments
 (0)