Skip to content

Commit 96ea996

Browse files
committed
Merge @Keyframes with same name and prefixes
1 parent 949eb13 commit 96ea996

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/lib.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7257,6 +7257,39 @@ mod tests {
72577257
..Browsers::default()
72587258
},
72597259
);
7260+
7261+
minify_test(
7262+
r#"
7263+
@keyframes test {
7264+
100% {
7265+
background: blue
7266+
}
7267+
}
7268+
7269+
@keyframes test {
7270+
100% {
7271+
background: red
7272+
}
7273+
}
7274+
"#,
7275+
"@keyframes test{to{background:red}}",
7276+
);
7277+
minify_test(
7278+
r#"
7279+
@keyframes test {
7280+
100% {
7281+
background: blue
7282+
}
7283+
}
7284+
7285+
@-webkit-keyframes test {
7286+
100% {
7287+
background: red
7288+
}
7289+
}
7290+
"#,
7291+
"@keyframes test{to{background:#00f}}@-webkit-keyframes test{to{background:red}}",
7292+
);
72607293
}
72617294

72627295
#[test]

src/rules/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,15 @@ impl<'i, T: Clone> CssRuleList<'i, T> {
519519
};
520520
}
521521

522-
// If there is an existing rule with the same name and identical keyframes,
523-
// merge the vendor prefixes from this rule into it.
522+
// Merge @keyframes rules with the same name.
524523
if let Some(existing_idx) = keyframe_rules.get(&keyframes.name) {
525524
if let Some(CssRule::Keyframes(existing)) = &mut rules.get_mut(*existing_idx) {
525+
// If the existing rule has the same vendor prefixes, replace it with this rule.
526+
if existing.vendor_prefix == keyframes.vendor_prefix {
527+
*existing = keyframes.clone();
528+
continue;
529+
}
530+
// Otherwise, if the keyframes are identical, merge the prefixes.
526531
if existing.keyframes == keyframes.keyframes {
527532
existing.vendor_prefix |= keyframes.vendor_prefix;
528533
set_prefix!(existing);

0 commit comments

Comments
 (0)