Skip to content

Commit 0732197

Browse files
authored
fix: avoid parsing animation: "none" to animation: "none" none. (parcel-bundler#295)
1 parent 061c0c2 commit 0732197

File tree

2 files changed

+76
-3
lines changed

2 files changed

+76
-3
lines changed

src/lib.rs

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8195,10 +8195,41 @@ mod tests {
81958195
minify_test(".foo { animation-name: test }", ".foo{animation-name:test}");
81968196
minify_test(".foo { animation-name: \"test\" }", ".foo{animation-name:test}");
81978197
minify_test(".foo { animation-name: foo, bar }", ".foo{animation-name:foo,bar}");
8198-
minify_test(".foo { animation-name: \"revert\" }", ".foo{animation-name:\"revert\"}");
81998198
minify_test(".foo { animation-name: \"none\" }", ".foo{animation-name:\"none\"}");
8199+
minify_test(
8200+
".foo { animation-name: \"none\", foo }",
8201+
".foo{animation-name:\"none\",foo}",
8202+
);
82008203
let name = crate::properties::animation::AnimationName::parse_string("default");
82018204
assert!(matches!(name, Err(..)));
8205+
8206+
minify_test(".foo { animation-name: none }", ".foo{animation-name:none}");
8207+
minify_test(".foo { animation-name: none, none }", ".foo{animation-name:none,none}");
8208+
8209+
// Test CSS-wide keywords
8210+
minify_test(".foo { animation-name: unset }", ".foo{animation-name:unset}");
8211+
minify_test(".foo { animation-name: \"unset\" }", ".foo{animation-name:\"unset\"}");
8212+
minify_test(".foo { animation-name: \"revert\" }", ".foo{animation-name:\"revert\"}");
8213+
minify_test(
8214+
".foo { animation-name: \"unset\", \"revert\"}",
8215+
".foo{animation-name:\"unset\",\"revert\"}",
8216+
);
8217+
minify_test(
8218+
".foo { animation-name: foo, \"revert\"}",
8219+
".foo{animation-name:foo,\"revert\"}",
8220+
);
8221+
minify_test(
8222+
".foo { animation-name: \"string\", \"revert\"}",
8223+
".foo{animation-name:string,\"revert\"}",
8224+
);
8225+
minify_test(
8226+
".foo { animation-name: \"string\", foo, \"revert\"}",
8227+
".foo{animation-name:string,foo,\"revert\"}",
8228+
);
8229+
minify_test(
8230+
".foo { animation-name: \"default\" }",
8231+
".foo{animation-name:\"default\"}",
8232+
);
82028233
minify_test(".foo { animation-duration: 100ms }", ".foo{animation-duration:.1s}");
82038234
minify_test(
82048235
".foo { animation-duration: 100ms, 2000ms }",
@@ -8265,6 +8296,42 @@ mod tests {
82658296
".foo { animation-fill-mode: Backwards,forwards }",
82668297
".foo{animation-fill-mode:backwards,forwards}",
82678298
);
8299+
minify_test(".foo { animation: none }", ".foo{animation:none}");
8300+
minify_test(".foo { animation: \"none\" }", ".foo{animation:\"none\"}");
8301+
minify_test(".foo { animation: \"None\" }", ".foo{animation:\"None\"}");
8302+
minify_test(".foo { animation: \"none\", none }", ".foo{animation:\"none\",none}");
8303+
minify_test(".foo { animation: none, none }", ".foo{animation:none,none}");
8304+
minify_test(".foo { animation: \"none\" none }", ".foo{animation:\"none\"}");
8305+
minify_test(".foo { animation: none none }", ".foo{animation:none}");
8306+
8307+
// Test animation-name + animation-fill-mode
8308+
minify_test(
8309+
".foo { animation: \"none\" 2s both}",
8310+
".foo{animation:\"none\" 2s both}",
8311+
);
8312+
minify_test(
8313+
".foo { animation: both \"none\" 2s}",
8314+
".foo{animation:\"none\" 2s both}",
8315+
);
8316+
minify_test(".foo { animation: \"none\" 2s none}", ".foo{animation:\"none\" 2s}");
8317+
minify_test(".foo { animation: none \"none\" 2s}", ".foo{animation:\"none\" 2s}");
8318+
minify_test(
8319+
".foo { animation: none, \"none\" 2s forwards}",
8320+
".foo{animation:none,\"none\" 2s forwards}",
8321+
);
8322+
8323+
minify_test(".foo { animation: \"unset\" }", ".foo{animation:\"unset\"}");
8324+
minify_test(".foo { animation: \"string\" .5s }", ".foo{animation:string .5s}");
8325+
minify_test(".foo { animation: \"unset\" .5s }", ".foo{animation:\"unset\" .5s}");
8326+
minify_test(
8327+
".foo { animation: none, \"unset\" .5s}",
8328+
".foo{animation:none,\"unset\" .5s}",
8329+
);
8330+
minify_test(
8331+
".foo { animation: \"unset\" 0s 3s infinite, none }",
8332+
".foo{animation:\"unset\" 0s 3s infinite,none}",
8333+
);
8334+
82688335
minify_test(
82698336
".foo { animation: 3s ease-in 1s infinite reverse both running slidein }",
82708337
".foo{animation:slidein 3s ease-in 1s infinite reverse both}",
@@ -8282,7 +8349,6 @@ mod tests {
82828349
".foo { animation: foo 0s 3s infinite }",
82838350
".foo{animation:foo 0s 3s infinite}",
82848351
);
8285-
minify_test(".foo { animation: none }", ".foo{animation:none}");
82868352
test(
82878353
r#"
82888354
.foo {

src/properties/animation.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,14 @@ impl<'i> ToCss for Animation<'i> {
267267
self.direction.to_css(dest)?;
268268
}
269269

270-
if self.fill_mode != AnimationFillMode::None || AnimationFillMode::parse_string(&name).is_ok() {
270+
// Avoid parsing `animation: "none"` to `animation: "none" none`.
271+
let animation_name_is_none = AnimationName::parse_string(&name)
272+
.as_ref()
273+
.map(|n| n == &AnimationName::None)
274+
.unwrap_or(true);
275+
if self.fill_mode == AnimationFillMode::None && animation_name_is_none {
276+
return Ok(());
277+
} else if self.fill_mode != AnimationFillMode::None || AnimationFillMode::parse_string(&name).is_ok() {
271278
dest.write_char(' ')?;
272279
self.fill_mode.to_css(dest)?;
273280
}

0 commit comments

Comments
 (0)