Skip to content

Commit 6e47cdb

Browse files
committed
Revert serializing animation name as string
Chrome doesn't support it yet.
1 parent 44a402d commit 6e47cdb

File tree

2 files changed

+20
-65
lines changed

2 files changed

+20
-65
lines changed

src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8399,13 +8399,16 @@ mod tests {
83998399
".foo{animation:0s 3s infinite \"unset\",none}",
84008400
);
84018401

8402+
minify_test(".foo { animation: \"infinite\" 2s 1 }", ".foo{animation:2s 1 infinite}");
8403+
minify_test(".foo { animation: \"paused\" 2s }", ".foo{animation:2s running paused}");
84028404
minify_test(
8403-
".foo { animation: \"infinite\" 2s 1 }",
8404-
".foo{animation:2s \"infinite\"}",
8405+
".foo { animation: \"forwards\" 2s }",
8406+
".foo{animation:2s none forwards}",
8407+
);
8408+
minify_test(
8409+
".foo { animation: \"reverse\" 2s }",
8410+
".foo{animation:2s normal reverse}",
84058411
);
8406-
minify_test(".foo { animation: \"paused\" 2s }", ".foo{animation:2s \"paused\"}");
8407-
minify_test(".foo { animation: \"forwards\" 2s }", ".foo{animation:2s \"forwards\"}");
8408-
minify_test(".foo { animation: \"reverse\" 2s }", ".foo{animation:2s \"reverse\"}");
84098412
minify_test(
84108413
".foo { animation: \"reverse\" 2s alternate }",
84118414
".foo{animation:2s alternate reverse}",
@@ -8419,7 +8422,7 @@ mod tests {
84198422
".foo { animation: 3s slidein paused ease 1s 1 reverse both }",
84208423
".foo{animation:3s 1s reverse both paused slidein}",
84218424
);
8422-
minify_test(".foo { animation: 3s ease ease }", ".foo{animation:3s \"ease\"}");
8425+
minify_test(".foo { animation: 3s ease ease }", ".foo{animation:3s ease ease}");
84238426
minify_test(
84248427
".foo { animation: 3s cubic-bezier(0.25, 0.1, 0.25, 1) foo }",
84258428
".foo{animation:3s foo}",

src/properties/animation.rs

Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,6 @@ impl<'i> ToCss for AnimationName<'i> {
8282
}
8383
}
8484

85-
impl<'i> AnimationName<'i> {
86-
fn write_as_string<W>(&self, dest: &mut Printer<W>) -> Result<(), PrinterError>
87-
where
88-
W: std::fmt::Write,
89-
{
90-
match self {
91-
AnimationName::None => dest.write_str("none"),
92-
AnimationName::Ident(CustomIdent(s)) | AnimationName::String(s) => {
93-
if let Some(css_module) = &mut dest.css_module {
94-
css_module.reference(&s, dest.loc.source_index)
95-
}
96-
97-
serialize_string(&s, dest)?;
98-
Ok(())
99-
}
100-
}
101-
}
102-
}
103-
10485
/// A list of animation names.
10586
pub type AnimationNameList<'i> = SmallVec<[AnimationName<'i>; 1]>;
10687

@@ -280,13 +261,13 @@ impl<'i> ToCss for Animation<'i> {
280261
{
281262
match &self.name {
282263
AnimationName::None => {}
283-
_ => {
264+
AnimationName::Ident(CustomIdent(name)) | AnimationName::String(name) => {
284265
if !self.duration.is_zero() || !self.delay.is_zero() {
285266
self.duration.to_css(dest)?;
286267
dest.write_char(' ')?;
287268
}
288269

289-
if !self.is_default_easing() {
270+
if !self.is_default_easing() || EasingFunction::is_ident(&name) {
290271
self.timing_function.to_css(dest)?;
291272
dest.write_char(' ')?;
292273
}
@@ -296,33 +277,33 @@ impl<'i> ToCss for Animation<'i> {
296277
dest.write_char(' ')?;
297278
}
298279

299-
if self.iteration_count != AnimationIterationCount::default() {
280+
if self.iteration_count != AnimationIterationCount::default() || name.as_ref() == "infinite" {
300281
self.iteration_count.to_css(dest)?;
301282
dest.write_char(' ')?;
302283
}
303284

304-
if self.direction != AnimationDirection::default() {
285+
if self.direction != AnimationDirection::default() || AnimationDirection::parse_string(&name).is_ok() {
305286
self.direction.to_css(dest)?;
306287
dest.write_char(' ')?;
307288
}
308289

309-
if self.fill_mode != AnimationFillMode::default() {
290+
if self.fill_mode != AnimationFillMode::default()
291+
|| (!name.eq_ignore_ascii_case("none") && AnimationFillMode::parse_string(&name).is_ok())
292+
{
310293
self.fill_mode.to_css(dest)?;
311294
dest.write_char(' ')?;
312295
}
313296

314-
if self.play_state != AnimationPlayState::default() {
297+
if self.play_state != AnimationPlayState::default() || AnimationPlayState::parse_string(&name).is_ok() {
315298
self.play_state.to_css(dest)?;
316299
dest.write_char(' ')?;
317300
}
318301
}
319302
}
320303

321-
if self.name_conflicts_with_keyword() {
322-
self.name.write_as_string(dest)?;
323-
} else {
324-
self.name.to_css(dest)?;
325-
};
304+
// Eventually we could output a string here to avoid duplicating some properties above.
305+
// Chrome does not yet support strings, however.
306+
self.name.to_css(dest)?;
326307

327308
Ok(())
328309
}
@@ -333,35 +314,6 @@ impl<'i> Animation<'i> {
333314
self.timing_function == EasingFunction::Ease
334315
|| self.timing_function == EasingFunction::CubicBezier(0.25, 0.1, 0.25, 1.0)
335316
}
336-
337-
fn name_conflicts_with_keyword(&self) -> bool {
338-
match &self.name {
339-
AnimationName::Ident(CustomIdent(name)) | AnimationName::String(name) => {
340-
if self.is_default_easing() && EasingFunction::is_ident(&name) {
341-
return true;
342-
}
343-
344-
if self.iteration_count == AnimationIterationCount::default() && name.as_ref() == "infinite" {
345-
return true;
346-
}
347-
348-
if self.direction == AnimationDirection::default() && AnimationDirection::parse_string(&name).is_ok() {
349-
return true;
350-
}
351-
352-
if self.fill_mode == AnimationFillMode::default() && AnimationFillMode::parse_string(&name).is_ok() {
353-
return true;
354-
}
355-
356-
if self.play_state == AnimationPlayState::default() && AnimationPlayState::parse_string(&name).is_ok() {
357-
return true;
358-
}
359-
}
360-
_ => {}
361-
}
362-
363-
false
364-
}
365317
}
366318

367319
/// A list of animations.

0 commit comments

Comments
 (0)