Skip to content

Commit b54d7fb

Browse files
committed
Fix coverage
1 parent 80f815c commit b54d7fb

File tree

4 files changed

+39
-41
lines changed

4 files changed

+39
-41
lines changed

libs/css/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,17 @@ mod tests {
487487
),
488488
".cls:hover"
489489
);
490+
491+
assert_eq!(
492+
merge_selector(
493+
"cls",
494+
Some(&StyleSelector::Global(
495+
"&".to_string(),
496+
"file.ts".to_string()
497+
))
498+
),
499+
"&"
500+
);
490501
}
491502

492503
#[test]

libs/extractor/src/css_utils.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ pub fn keyframes_to_keyframes_style<'a>(
135135
let rest = &input[start + 1..];
136136
if let Some(end) = rest.find('}') {
137137
let block = &rest[..end];
138-
let mut styles = css_to_style(block, 0, &None)
139-
.into_iter()
140-
.collect::<Vec<_>>();
138+
let mut styles = css_to_style(block, 0, &None);
141139

142140
styles.sort_by_key(|a| {
143141
if let crate::ExtractStyleProp::Static(crate::ExtractStyleValue::Static(a)) = a {

libs/extractor/src/extractor/extract_global_style_from_expression.rs

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -71,38 +71,24 @@ pub fn extract_global_style_from_expression<'a>(
7171
if let Expression::ArrayExpression(arr) = &o.value {
7272
for p in arr.elements.iter() {
7373
if let ArrayExpressionElement::ObjectExpression(o) = p {
74-
styles.push(ExtractStyleProp::Static(ExtractStyleValue::FontFace(
75-
ExtractFontFace {
76-
properties: BTreeMap::from_iter(
77-
o.properties.iter().filter_map(|p| {
74+
styles.push(ExtractStyleProp::Static(ExtractStyleValue::FontFace(ExtractFontFace {
75+
properties: BTreeMap::from_iter(
76+
o.properties
77+
.iter()
78+
.filter_map(|p| {
7879
if let ObjectPropertyKind::ObjectProperty(o) = p
79-
&& let PropertyKey::StaticIdentifier(ident) =
80-
&o.key
81-
&& let Some(s) =
82-
get_string_by_literal_expression(&o.value)
80+
&& let PropertyKey::StaticIdentifier(ident) = &o.key
81+
&& let Some(s) = get_string_by_literal_expression(&o.value)
8382
{
84-
Some(
85-
disassemble_property(&ident.name)
86-
.iter()
87-
.map(|p| {
88-
(p.to_string(), if check_multi_css_optimize(p) {
89-
optimize_mutli_css_value(
90-
&s
91-
)
92-
} else {
93-
s.clone()
94-
})
95-
})
96-
.collect::<Vec<_>>(),
97-
)
83+
Some(disassemble_property(&ident.name).iter().map(|p| (p.to_string(), if check_multi_css_optimize(p) { optimize_mutli_css_value(&s) } else { s.clone() })).collect::<Vec<_>>())
9884
} else {
9985
None
10086
}
101-
}).flatten()
102-
),
103-
file: file.to_string(),
104-
},
105-
)));
87+
})
88+
.flatten(),
89+
),
90+
file: file.to_string(),
91+
})));
10692
} else if let ArrayExpressionElement::TemplateLiteral(t) = p {
10793
let css_styles = css_to_style(
10894
t.quasis

libs/extractor/src/extractor/extract_keyframes_from_expression.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,24 @@ pub fn extract_keyframes_from_expression<'a>(
1818

1919
if let Expression::ObjectExpression(obj) = expression {
2020
for p in obj.properties.iter_mut() {
21-
if let ObjectPropertyKind::ObjectProperty(o) = p {
22-
let name = if let PropertyKey::StaticIdentifier(ident) = &o.key {
23-
ident.name.to_string()
21+
if let ObjectPropertyKind::ObjectProperty(o) = p
22+
&& let Some(name) = if let PropertyKey::StaticIdentifier(ident) = &o.key {
23+
Some(ident.name.to_string())
2424
} else if let PropertyKey::StringLiteral(s) = &o.key {
25-
s.value.to_string()
25+
Some(s.value.to_string())
2626
} else if let PropertyKey::TemplateLiteral(t) = &o.key {
27-
t.quasis
28-
.iter()
29-
.map(|q| q.value.raw.as_str())
30-
.collect::<String>()
27+
Some(
28+
t.quasis
29+
.iter()
30+
.map(|q| q.value.raw.as_str())
31+
.collect::<String>(),
32+
)
3133
} else if let PropertyKey::NumericLiteral(n) = &o.key {
32-
n.value.to_string()
34+
Some(n.value.to_string())
3335
} else {
34-
continue;
35-
};
36+
None
37+
}
38+
{
3639
let mut styles =
3740
extract_style_from_expression(ast_builder, None, &mut o.value, 0, &None)
3841
.styles

0 commit comments

Comments
 (0)