Skip to content

Commit 3889930

Browse files
committed
code minify
1 parent a13998e commit 3889930

14 files changed

+143
-236
lines changed

libs/extractor/src/css_utils.rs

Lines changed: 49 additions & 172 deletions
Large diffs are not rendered by default.

libs/extractor/src/extractor/extract_style_from_styled.rs

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,15 @@ fn create_styled_component<'a>(
165165
SPAN,
166166
FormalParameterKind::ArrowFormalParameters,
167167
oxc_allocator::Vec::from_iter_in(
168-
vec![ast_builder.formal_parameter(
169-
SPAN,
170-
oxc_allocator::Vec::from_iter_in(vec![], ast_builder.allocator),
171-
ast_builder.binding_pattern(
172-
ast_builder.binding_pattern_kind_object_pattern(
173-
SPAN,
174-
oxc_allocator::Vec::from_iter_in(
175-
vec![
168+
vec![
169+
ast_builder.formal_parameter(
170+
SPAN,
171+
oxc_allocator::Vec::from_iter_in(vec![], ast_builder.allocator),
172+
ast_builder.binding_pattern(
173+
ast_builder.binding_pattern_kind_object_pattern(
174+
SPAN,
175+
oxc_allocator::Vec::from_iter_in(
176+
vec![
176177
ast_builder.binding_property(
177178
SPAN,
178179
ast_builder.property_key_static_identifier(SPAN, "style"),
@@ -210,27 +211,28 @@ fn create_styled_component<'a>(
210211
false,
211212
),
212213
],
213-
ast_builder.allocator,
214-
),
215-
Some(ast_builder.binding_rest_element(
216-
SPAN,
217-
ast_builder.binding_pattern(
218-
ast_builder.binding_pattern_kind_binding_identifier(
219-
SPAN,
220-
ast_builder.atom("rest"),
221-
),
222-
None::<oxc_allocator::Box<oxc_ast::ast::TSTypeAnnotation<'a>>>,
223-
false,
214+
ast_builder.allocator,
224215
),
225-
)),
216+
Some(ast_builder.binding_rest_element(
217+
SPAN,
218+
ast_builder.binding_pattern(
219+
ast_builder.binding_pattern_kind_binding_identifier(
220+
SPAN,
221+
ast_builder.atom("rest"),
222+
),
223+
None::<oxc_allocator::Box<oxc_ast::ast::TSTypeAnnotation<'a>>>,
224+
false,
225+
),
226+
)),
227+
),
228+
None::<oxc_allocator::Box<oxc_ast::ast::TSTypeAnnotation<'a>>>,
229+
false,
226230
),
227-
None::<oxc_allocator::Box<oxc_ast::ast::TSTypeAnnotation<'a>>>,
231+
None,
232+
false,
228233
false,
229234
),
230-
None,
231-
false,
232-
false,
233-
)],
235+
],
234236
ast_builder.allocator,
235237
),
236238
None::<oxc_allocator::Box<oxc_ast::ast::BindingRestElement<'a>>>,
@@ -239,16 +241,20 @@ fn create_styled_component<'a>(
239241
SPAN,
240242
oxc_allocator::Vec::from_iter_in(vec![], ast_builder.allocator),
241243
oxc_allocator::Vec::from_iter_in(
242-
vec![ast_builder.statement_expression(
243-
SPAN,
244-
ast_builder.expression_jsx_element(
244+
vec![
245+
ast_builder.statement_expression(
245246
SPAN,
246-
ast_builder.alloc_jsx_opening_element(
247+
ast_builder.expression_jsx_element(
247248
SPAN,
248-
ast_builder.jsx_element_name_identifier(SPAN, ast_builder.atom(tag_name)),
249-
None::<oxc_allocator::Box<oxc_ast::ast::TSTypeParameterInstantiation<'a>>>,
250-
oxc_allocator::Vec::from_iter_in(
251-
vec![
249+
ast_builder.alloc_jsx_opening_element(
250+
SPAN,
251+
ast_builder
252+
.jsx_element_name_identifier(SPAN, ast_builder.atom(tag_name)),
253+
None::<
254+
oxc_allocator::Box<oxc_ast::ast::TSTypeParameterInstantiation<'a>>,
255+
>,
256+
oxc_allocator::Vec::from_iter_in(
257+
vec![
252258
ast_builder.jsx_attribute_item_spread_attribute(
253259
SPAN,
254260
ast_builder
@@ -327,13 +333,14 @@ fn create_styled_component<'a>(
327333
),
328334
),
329335
],
330-
ast_builder.allocator,
336+
ast_builder.allocator,
337+
),
331338
),
339+
oxc_allocator::Vec::from_iter_in(vec![], ast_builder.allocator),
340+
None::<oxc_allocator::Box<oxc_ast::ast::JSXClosingElement<'a>>>,
332341
),
333-
oxc_allocator::Vec::from_iter_in(vec![], ast_builder.allocator),
334-
None::<oxc_allocator::Box<oxc_ast::ast::JSXClosingElement<'a>>>,
335342
),
336-
)],
343+
],
337344
ast_builder.allocator,
338345
),
339346
);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
source: libs/extractor/src/lib.rs
3-
expression: "ToBTreeSet::from(extract(\"test.jsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box zIndex={-(1+a)} />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
3+
expression: "ToBTreeSet::from(extract(\"test.jsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box zIndex={-(1+a)} />\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())"
44
---
55
ToBTreeSet {
66
styles: {
77
Dynamic(
88
ExtractDynamicStyle {
99
property: "z-index",
1010
level: 0,
11-
identifier: "-(1 + a)",
11+
identifier: "-(1+a)",
1212
selector: None,
1313
style_order: None,
1414
},
1515
),
1616
},
17-
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a\" style={{ \"--b\": -(1 + a) }} />;\n",
17+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a\" style={{ \"--b\": -(1+a) }} />;\n",
1818
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
source: libs/extractor/src/lib.rs
3-
expression: "ToBTreeSet::from(extract(\"test.jsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box zIndex={-1*a} />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
3+
expression: "ToBTreeSet::from(extract(\"test.jsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box zIndex={-1*a} />\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())"
44
---
55
ToBTreeSet {
66
styles: {
77
Dynamic(
88
ExtractDynamicStyle {
99
property: "z-index",
1010
level: 0,
11-
identifier: "-1 * a",
11+
identifier: "-1*a",
1212
selector: None,
1313
style_order: None,
1414
},
1515
),
1616
},
17-
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a\" style={{ \"--b\": -1 * a }} />;\n",
17+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a\" style={{ \"--b\": -1*a }} />;\n",
1818
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: libs/extractor/src/lib.rs
3-
expression: "ToBTreeSet::from(extract(\"test.jsx\",\nr#\"import {Flex} from '@devup-ui/core'\n <Flex opacity={{a:1, b:0.5, ...any}[\"some\"]} />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
3+
expression: "ToBTreeSet::from(extract(\"test.jsx\",\nr#\"import {Flex} from '@devup-ui/core'\n <Flex opacity={{a:1, b:0.5, ...any}[\"some\"]} />\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())"
44
---
55
ToBTreeSet {
66
styles: {
@@ -37,11 +37,11 @@ ToBTreeSet {
3737
ExtractDynamicStyle {
3838
property: "opacity",
3939
level: 0,
40-
identifier: "any[\"some\"]",
40+
identifier: "any[`some`]",
4141
selector: None,
4242
style_order: None,
4343
},
4444
),
4545
},
46-
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={`a b ${{\n\t\"a\": \"d\",\n\t\"b\": \"e\"\n}[\"some\"]}`} style={{ \"--c\": any[\"some\"] }} />;\n",
46+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={`a b ${{\n\t\"a\": \"d\",\n\t\"b\": \"e\"\n}[\"some\"]}`} style={{ \"--c\": any[`some`] }} />;\n",
4747
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
source: libs/extractor/src/lib.rs
3-
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import { Box } from \"@devup-ui/core\";\n<Box bg={`${color}` + \";\"} />\n\"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
3+
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import { Box } from \"@devup-ui/core\";\n<Box bg={`${color}` + \";\"} />\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())"
44
---
55
ToBTreeSet {
66
styles: {
77
Dynamic(
88
ExtractDynamicStyle {
99
property: "background",
1010
level: 0,
11-
identifier: "`${color}` + \"\"",
11+
identifier: "`${color}`+``",
1212
selector: None,
1313
style_order: None,
1414
},
1515
),
1616
},
17-
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a\" style={{ \"--b\": `${color}` + \"\" }} />;\n",
17+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a\" style={{ \"--b\": `${color}`+`` }} />;\n",
1818
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ToBTreeSet {
88
ExtractDynamicStyle {
99
property: "color",
1010
level: 0,
11-
identifier: "((props)=>props.color || \"black\")(rest)",
11+
identifier: "(props=>props.color||`black`)(rest)",
1212
selector: None,
1313
style_order: None,
1414
},
@@ -23,5 +23,5 @@ ToBTreeSet {
2323
},
2424
),
2525
},
26-
code: "import \"@devup-ui/core/devup-ui-0.css\";\nconst fontSize = \"18px\";\nconst StyledComponent = ({ style, className, ...rest }) => <div {...rest} className={[\"a-a a-b\", className].filter(Boolean).join(\" \")} style={{\n\t...{\n\t\t\"--a\": fontSize,\n\t\t\"--b\": ((props)=>props.color || \"black\")(rest)\n\t},\n\t...style\n}} />;\n",
26+
code: "import \"@devup-ui/core/devup-ui-0.css\";\nconst fontSize = \"18px\";\nconst StyledComponent = ({ style, className, ...rest }) => <div {...rest} className={[\"a-a a-b\", className].filter(Boolean).join(\" \")} style={{\n\t...{\n\t\t\"--a\": fontSize,\n\t\t\"--b\": (props=>props.color||`black`)(rest)\n\t},\n\t...style\n}} />;\n",
2727
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ToBTreeSet {
88
ExtractDynamicStyle {
99
property: "background",
1010
level: 0,
11-
identifier: "((props)=>props.bg || \"white\")(rest)",
11+
identifier: "(props=>props.bg||`white`)(rest)",
1212
selector: None,
1313
style_order: None,
1414
},
@@ -32,5 +32,5 @@ ToBTreeSet {
3232
},
3333
),
3434
},
35-
code: "import \"@devup-ui/core/devup-ui-0.css\";\nconst margin = \"10px\";\nconst padding = \"20px\";\nconst StyledDiv = ({ style, className, ...rest }) => <div {...rest} className={[\"a-a a-b a-c\", className].filter(Boolean).join(\" \")} style={{\n\t...{\n\t\t\"--a\": padding,\n\t\t\"--b\": margin,\n\t\t\"--c\": ((props)=>props.bg || \"white\")(rest)\n\t},\n\t...style\n}} />;\n",
35+
code: "import \"@devup-ui/core/devup-ui-0.css\";\nconst margin = \"10px\";\nconst padding = \"20px\";\nconst StyledDiv = ({ style, className, ...rest }) => <div {...rest} className={[\"a-a a-b a-c\", className].filter(Boolean).join(\" \")} style={{\n\t...{\n\t\t\"--a\": padding,\n\t\t\"--b\": margin,\n\t\t\"--c\": (props=>props.bg||`white`)(rest)\n\t},\n\t...style\n}} />;\n",
3636
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ToBTreeSet {
88
ExtractDynamicStyle {
99
property: "color",
1010
level: 0,
11-
identifier: "isActive ? \"red\" : \"blue\"",
11+
identifier: "isActive?`red`:`blue`",
1212
selector: None,
1313
style_order: None,
1414
},
@@ -17,11 +17,11 @@ ToBTreeSet {
1717
ExtractDynamicStyle {
1818
property: "opacity",
1919
level: 0,
20-
identifier: "isActive ? 1 : .5",
20+
identifier: "isActive?1:.5",
2121
selector: None,
2222
style_order: None,
2323
},
2424
),
2525
},
26-
code: "import \"@devup-ui/core/devup-ui-0.css\";\nconst isActive = true;\nconst StyledDiv = ({ style, className, ...rest }) => <div {...rest} className={[\"a-a a-b\", className].filter(Boolean).join(\" \")} style={{\n\t...{\n\t\t\"--a\": isActive ? 1 : .5,\n\t\t\"--b\": isActive ? \"red\" : \"blue\"\n\t},\n\t...style\n}} />;\n",
26+
code: "import \"@devup-ui/core/devup-ui-0.css\";\nconst isActive = true;\nconst StyledDiv = ({ style, className, ...rest }) => <div {...rest} className={[\"a-a a-b\", className].filter(Boolean).join(\" \")} style={{\n\t...{\n\t\t\"--a\": isActive?1:.5,\n\t\t\"--b\": isActive?`red`:`blue`\n\t},\n\t...style\n}} />;\n",
2727
}

libs/extractor/src/snapshots/extractor__tests__styled_with_variable_like_emotion_props.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ ToBTreeSet {
1717
ExtractDynamicStyle {
1818
property: "background",
1919
level: 0,
20-
identifier: "((props)=>props.bg)(rest)",
20+
identifier: "(props=>props.bg)(rest)",
2121
selector: None,
2222
style_order: None,
2323
},
2424
),
2525
},
26-
code: "import \"@devup-ui/core/devup-ui-0.css\";\nconst StyledDiv = ({ style, className, ...rest }) => <div {...rest} className={[\"a-a a-b\", className].filter(Boolean).join(\" \")} style={{\n\t...{ \"--a\": ((props)=>props.bg)(rest) },\n\t...style\n}} />;\n",
26+
code: "import \"@devup-ui/core/devup-ui-0.css\";\nconst StyledDiv = ({ style, className, ...rest }) => <div {...rest} className={[\"a-a a-b\", className].filter(Boolean).join(\" \")} style={{\n\t...{ \"--a\": (props=>props.bg)(rest) },\n\t...style\n}} />;\n",
2727
}

0 commit comments

Comments
 (0)