Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 68 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8195,10 +8195,41 @@ mod tests {
minify_test(".foo { animation-name: test }", ".foo{animation-name:test}");
minify_test(".foo { animation-name: \"test\" }", ".foo{animation-name:test}");
minify_test(".foo { animation-name: foo, bar }", ".foo{animation-name:foo,bar}");
minify_test(".foo { animation-name: \"revert\" }", ".foo{animation-name:\"revert\"}");
minify_test(".foo { animation-name: \"none\" }", ".foo{animation-name:\"none\"}");
minify_test(
".foo { animation-name: \"none\", foo }",
".foo{animation-name:\"none\",foo}",
);
let name = crate::properties::animation::AnimationName::parse_string("default");
assert!(matches!(name, Err(..)));

minify_test(".foo { animation-name: none }", ".foo{animation-name:none}");
minify_test(".foo { animation-name: none, none }", ".foo{animation-name:none,none}");

// Test CSS-wide keywords
minify_test(".foo { animation-name: unset }", ".foo{animation-name:unset}");
minify_test(".foo { animation-name: \"unset\" }", ".foo{animation-name:\"unset\"}");
minify_test(".foo { animation-name: \"revert\" }", ".foo{animation-name:\"revert\"}");
minify_test(
".foo { animation-name: \"unset\", \"revert\"}",
".foo{animation-name:\"unset\",\"revert\"}",
);
minify_test(
".foo { animation-name: foo, \"revert\"}",
".foo{animation-name:foo,\"revert\"}",
);
minify_test(
".foo { animation-name: \"string\", \"revert\"}",
".foo{animation-name:string,\"revert\"}",
);
minify_test(
".foo { animation-name: \"string\", foo, \"revert\"}",
".foo{animation-name:string,foo,\"revert\"}",
);
minify_test(
".foo { animation-name: \"default\" }",
".foo{animation-name:\"default\"}",
);
minify_test(".foo { animation-duration: 100ms }", ".foo{animation-duration:.1s}");
minify_test(
".foo { animation-duration: 100ms, 2000ms }",
Expand Down Expand Up @@ -8265,6 +8296,42 @@ mod tests {
".foo { animation-fill-mode: Backwards,forwards }",
".foo{animation-fill-mode:backwards,forwards}",
);
minify_test(".foo { animation: none }", ".foo{animation:none}");
minify_test(".foo { animation: \"none\" }", ".foo{animation:\"none\"}");
minify_test(".foo { animation: \"None\" }", ".foo{animation:\"None\"}");
minify_test(".foo { animation: \"none\", none }", ".foo{animation:\"none\",none}");
minify_test(".foo { animation: none, none }", ".foo{animation:none,none}");
minify_test(".foo { animation: \"none\" none }", ".foo{animation:\"none\"}");
minify_test(".foo { animation: none none }", ".foo{animation:none}");

// Test animation-name + animation-fill-mode
minify_test(
".foo { animation: \"none\" 2s both}",
".foo{animation:\"none\" 2s both}",
);
minify_test(
".foo { animation: both \"none\" 2s}",
".foo{animation:\"none\" 2s both}",
);
minify_test(".foo { animation: \"none\" 2s none}", ".foo{animation:\"none\" 2s}");
minify_test(".foo { animation: none \"none\" 2s}", ".foo{animation:\"none\" 2s}");
minify_test(
".foo { animation: none, \"none\" 2s forwards}",
".foo{animation:none,\"none\" 2s forwards}",
);

minify_test(".foo { animation: \"unset\" }", ".foo{animation:\"unset\"}");
minify_test(".foo { animation: \"string\" .5s }", ".foo{animation:string .5s}");
minify_test(".foo { animation: \"unset\" .5s }", ".foo{animation:\"unset\" .5s}");
minify_test(
".foo { animation: none, \"unset\" .5s}",
".foo{animation:none,\"unset\" .5s}",
);
minify_test(
".foo { animation: \"unset\" 0s 3s infinite, none }",
".foo{animation:\"unset\" 0s 3s infinite,none}",
);

minify_test(
".foo { animation: 3s ease-in 1s infinite reverse both running slidein }",
".foo{animation:slidein 3s ease-in 1s infinite reverse both}",
Expand All @@ -8282,7 +8349,6 @@ mod tests {
".foo { animation: foo 0s 3s infinite }",
".foo{animation:foo 0s 3s infinite}",
);
minify_test(".foo { animation: none }", ".foo{animation:none}");
test(
r#"
.foo {
Expand Down
9 changes: 8 additions & 1 deletion src/properties/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,14 @@ impl<'i> ToCss for Animation<'i> {
self.direction.to_css(dest)?;
}

if self.fill_mode != AnimationFillMode::None || AnimationFillMode::parse_string(&name).is_ok() {
// Avoid parsing `animation: "none"` to `animation: "none" none`.
let animation_name_is_none = AnimationName::parse_string(&name)
.as_ref()
.map(|n| n == &AnimationName::None)
.unwrap_or(true);
if self.fill_mode == AnimationFillMode::None && animation_name_is_none {
return Ok(());
} else if self.fill_mode != AnimationFillMode::None || AnimationFillMode::parse_string(&name).is_ok() {
dest.write_char(' ')?;
self.fill_mode.to_css(dest)?;
}
Expand Down