Skip to content

Commit 83c3538

Browse files
committed
Update Coverage
1 parent 2fe1d7c commit 83c3538

File tree

5 files changed

+39
-69
lines changed

5 files changed

+39
-69
lines changed

.github/workflows/publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ jobs:
4141
pnpm build
4242
pnpm lint
4343
# rust coverage issue
44-
echo 'max_width = 1000' > .rustfmt.toml
44+
echo 'max_width = 100000' > .rustfmt.toml
4545
echo 'tab_spaces = 4' >> .rustfmt.toml
4646
echo 'newline_style = "Unix"' >> .rustfmt.toml
47-
echo 'fn_call_width = 1000' >> .rustfmt.toml
47+
echo 'fn_call_width = 100000' >> .rustfmt.toml
4848
echo 'fn_params_layout = "Compressed"' >> .rustfmt.toml
49-
echo 'chain_width = 1000' >> .rustfmt.toml
49+
echo 'chain_width = 100000' >> .rustfmt.toml
5050
echo 'merge_derives = true' >> .rustfmt.toml
5151
echo 'use_small_heuristics = "Default"' >> .rustfmt.toml
5252
cargo fmt

libs/extractor/src/css_utils.rs

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@ use css::{
66
style_selector::StyleSelector,
77
};
88

9-
use crate::{
10-
ExtractStyleProp,
11-
extract_style::{
12-
extract_static_style::ExtractStaticStyle, extract_style_value::ExtractStyleValue,
13-
},
14-
};
9+
use crate::extract_style::extract_static_style::ExtractStaticStyle;
1510

1611
pub fn css_to_style<'a>(
1712
css: &str,
1813
level: u8,
1914
selector: &Option<StyleSelector>,
20-
) -> Vec<ExtractStyleProp<'a>> {
15+
) -> Vec<ExtractStaticStyle> {
2116
let mut styles = vec![];
2217
let mut input = css;
2318

@@ -86,21 +81,15 @@ pub fn css_to_style<'a>(
8681
styles.extend(css_to_style_block(input, level, selector));
8782
}
8883

89-
styles.sort_by_key(|a| {
90-
if let crate::ExtractStyleProp::Static(crate::ExtractStyleValue::Static(a)) = a {
91-
a.property().to_string()
92-
} else {
93-
"".to_string()
94-
}
95-
});
84+
styles.sort_by_key(|a| a.property().to_string());
9685
styles
9786
}
9887

9988
fn css_to_style_block<'a>(
10089
css: &str,
10190
level: u8,
10291
selector: &Option<StyleSelector>,
103-
) -> Vec<ExtractStyleProp<'a>> {
92+
) -> Vec<ExtractStaticStyle> {
10493
rm_css_comment(css)
10594
.split(";")
10695
.filter_map(|s| {
@@ -116,17 +105,20 @@ fn css_to_style_block<'a>(
116105
} else {
117106
value.to_string()
118107
};
119-
Some(ExtractStyleProp::Static(ExtractStyleValue::Static(
120-
ExtractStaticStyle::new(property, &value, level, selector.clone()),
121-
)))
108+
Some(ExtractStaticStyle::new(
109+
property,
110+
&value,
111+
level,
112+
selector.clone(),
113+
))
122114
}
123115
})
124116
.collect()
125117
}
126118

127119
pub fn keyframes_to_keyframes_style<'a>(
128120
keyframes: &str,
129-
) -> BTreeMap<String, Vec<ExtractStyleProp<'a>>> {
121+
) -> BTreeMap<String, Vec<ExtractStaticStyle>> {
130122
let mut map = BTreeMap::new();
131123
let mut input = keyframes;
132124

@@ -137,13 +129,7 @@ pub fn keyframes_to_keyframes_style<'a>(
137129
let block = &rest[..end];
138130
let mut styles = css_to_style(block, 0, &None);
139131

140-
styles.sort_by_key(|a| {
141-
if let crate::ExtractStyleProp::Static(crate::ExtractStyleValue::Static(a)) = a {
142-
a.property().to_string()
143-
} else {
144-
"".to_string()
145-
}
146-
});
132+
styles.sort_by_key(|a| a.property().to_string());
147133
map.insert(key, styles);
148134
input = &rest[end + 1..];
149135
} else {
@@ -489,14 +475,7 @@ mod tests {
489475
let styles = css_to_style(input, 0, &None);
490476
let mut result: Vec<(&str, &str, Option<StyleSelector>)> = styles
491477
.iter()
492-
.filter_map(|prop| {
493-
if let crate::ExtractStyleProp::Static(crate::ExtractStyleValue::Static(st)) = prop
494-
{
495-
Some((st.property(), st.value(), st.selector().cloned()))
496-
} else {
497-
None
498-
}
499-
})
478+
.map(|prop| (prop.property(), prop.value(), prop.selector().cloned()))
500479
.collect();
501480
result.sort();
502481
let mut expected_sorted = expected.clone();
@@ -567,15 +546,7 @@ mod tests {
567546
let styles = expected_styles;
568547
let mut result: Vec<(&str, &str)> = styles
569548
.iter()
570-
.filter_map(|prop| {
571-
if let crate::ExtractStyleProp::Static(crate::ExtractStyleValue::Static(st)) =
572-
prop
573-
{
574-
Some((st.property(), st.value()))
575-
} else {
576-
None
577-
}
578-
})
549+
.map(|prop| (prop.property(), prop.value()))
579550
.collect();
580551
result.sort();
581552
let mut expected_sorted = expected

libs/extractor/src/extractor/extract_global_style_from_expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub fn extract_global_style_from_expression<'a>(
106106
&None,
107107
)
108108
.into_iter()
109-
.flat_map(|p| p.extract())
109+
.map(|p| ExtractStyleValue::Static(p))
110110
.collect::<Vec<_>>();
111111
styles.push(ExtractStyleProp::Static(ExtractStyleValue::FontFace(
112112
ExtractFontFace {

libs/extractor/src/extractor/extract_style_from_expression.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ pub fn extract_style_from_expression<'a>(
148148
.collect::<String>(),
149149
level,
150150
selector,
151-
),
151+
)
152+
.into_iter()
153+
.map(|ex| ExtractStyleProp::Static(ExtractStyleValue::Static(ex)))
154+
.collect(),
152155
..ExtractResult::default()
153156
},
154157
_ => ExtractResult::default(),
@@ -268,7 +271,10 @@ pub fn extract_style_from_expression<'a>(
268271
}
269272
} else {
270273
ExtractResult {
271-
styles: css_to_style(&value, level, selector),
274+
styles: css_to_style(&value, level, selector)
275+
.into_iter()
276+
.map(|ex| ExtractStyleProp::Static(ExtractStyleValue::Static(ex)))
277+
.collect(),
272278
..ExtractResult::default()
273279
}
274280
}

libs/extractor/src/visit.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,17 @@ impl<'a> VisitMut<'a> for DevupVisitor<'a> {
226226
.collect::<String>();
227227
match css_type.as_ref() {
228228
UtilType::Css => {
229-
let mut styles = css_to_style(&css_str, 0, &None);
230-
let class_name = gen_class_names(&self.ast, &mut styles, None);
229+
let styles = css_to_style(&css_str, 0, &None);
230+
let class_name = gen_class_names(
231+
&self.ast,
232+
&mut styles
233+
.iter()
234+
.map(|ex| {
235+
ExtractStyleProp::Static(ExtractStyleValue::Static(ex.clone()))
236+
})
237+
.collect::<Vec<_>>(),
238+
None,
239+
);
231240

232241
if let Some(cls) = class_name {
233242
*it = cls;
@@ -238,29 +247,13 @@ impl<'a> VisitMut<'a> for DevupVisitor<'a> {
238247
}
239248
// already set style order
240249
self.styles
241-
.extend(styles.into_iter().flat_map(|ex| ex.extract()));
250+
.extend(styles.into_iter().map(|ex| ExtractStyleValue::Static(ex)));
242251
}
243252
UtilType::Keyframes => {
244253
let keyframes = ExtractKeyframes {
245254
keyframes: keyframes_to_keyframes_style(&css_str)
246255
.into_iter()
247-
.map(|(k, v)| {
248-
(
249-
k,
250-
v.into_iter()
251-
.filter_map(|ex| {
252-
if let crate::ExtractStyleProp::Static(
253-
crate::ExtractStyleValue::Static(st),
254-
) = ex
255-
{
256-
Some(st)
257-
} else {
258-
None
259-
}
260-
})
261-
.collect(),
262-
)
263-
})
256+
.map(|(k, v)| (k, v))
264257
.collect(),
265258
};
266259
let name = keyframes.extract().to_string();

0 commit comments

Comments
 (0)