Fixes #988 - edge case in dropping `animation-duration`.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 5 Mar 2018 11:37:26 +0000 (12:37 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 5 Mar 2018 18:35:56 +0000 (19:35 +0100)
When `animation-duration` is default but `animation-delay` isn't we
shouldn't drop the former as both need to be given.

History.md
lib/optimizer/level-2/compactable.js
lib/optimizer/level-2/restore.js
test/optimizer/level-2/restore-test.js

index 0f4bbb5..a847168 100644 (file)
@@ -6,6 +6,11 @@
 * Fixed issue [#895](https://github.com/jakubpawlowicz/clean-css/issues/895) - ignoring specific styles.
 * Fixed issue [#947](https://github.com/jakubpawlowicz/clean-css/issues/947) - selector based filtering.
 
+[4.1.10 / 2018-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.9...4.1)
+==================
+
+* Fixed issue [#988](https://github.com/jakubpawlowicz/clean-css/issues/988) - edge case in dropping default animation-duration.
+
 [4.1.9 / 2017-09-19](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.8...v4.1.9)
 ==================
 
index 81c3f17..57a5863 100644 (file)
@@ -99,6 +99,7 @@ var compactable = {
     ],
     defaultValue: '0s',
     intoMultiplexMode: 'real',
+    keepUnlessDefault: 'animation-delay',
     vendorPrefixes: [
       '-moz-',
       '-o-',
@@ -1031,6 +1032,10 @@ function cloneDescriptor(propertyName, prefix) {
     });
   }
 
+  if ('keepUnlessDefault' in clonedDescriptor) {
+    clonedDescriptor.keepUnlessDefault = prefix + clonedDescriptor.keepUnlessDefault;
+  }
+
   return clonedDescriptor;
 }
 
index 13f12e4..f9c2f0d 100644 (file)
@@ -264,8 +264,9 @@ function withoutDefaults(property, compactable) {
     var component = components[i];
     var descriptor = compactable[component.name];
 
-    if (component.value[0][1] != descriptor.defaultValue)
+    if (component.value[0][1] != descriptor.defaultValue || ('keepUnlessDefault' in descriptor) && !isDefault(components, compactable, descriptor.keepUnlessDefault)) {
       restored.unshift(component.value[0]);
+    }
   }
 
   if (restored.length === 0)
@@ -277,6 +278,21 @@ function withoutDefaults(property, compactable) {
   return restored;
 }
 
+function isDefault(components, compactable, propertyName) {
+  var component;
+  var i, l;
+
+  for (i = 0, l = components.length; i < l; i++) {
+    component = components[i];
+
+    if (component.name == propertyName && component.value[0][1] == compactable[propertyName].defaultValue) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 module.exports = {
   background: background,
   borderRadius: borderRadius,
index b37c4bc..d39182e 100644 (file)
@@ -979,6 +979,78 @@ vows.describe(restore)
           ]);
         }
       }
+    },
+    'animation': {
+      'with two time units where both are default': {
+        'topic': function () {
+          return _restore(
+            _breakUp([
+              'property',
+              ['property-name', 'animation'],
+              ['property-value', '0s'],
+              ['property-value', 'ease-out'],
+              ['property-value', '0s'],
+              ['property-value', 'forwards'],
+              ['property-value', 'test-name']
+            ])
+          );
+        },
+        'gives right value back': function (restoredValue) {
+          assert.deepEqual(restoredValue, [
+            ['property-value', 'ease-out'],
+            ['property-value', 'forwards'],
+            ['property-value', 'test-name']
+          ]);
+        }
+      },
+      'with two time units where first is default': {
+        'topic': function () {
+          return _restore(
+            _breakUp([
+              'property',
+              ['property-name', 'animation'],
+              ['property-value', '0s'],
+              ['property-value', 'ease-out'],
+              ['property-value', '5s'],
+              ['property-value', 'forwards'],
+              ['property-value', 'test-name']
+            ])
+          );
+        },
+        'gives right value back': function (restoredValue) {
+          assert.deepEqual(restoredValue, [
+            ['property-value', '0s'],
+            ['property-value', 'ease-out'],
+            ['property-value', '5s'],
+            ['property-value', 'forwards'],
+            ['property-value', 'test-name']
+          ]);
+        }
+      },
+      'with two vendor-prefixed time units where first is default': {
+        'topic': function () {
+          return _restore(
+            _breakUp([
+              'property',
+              ['property-name', '-webkit-animation'],
+              ['property-value', '0s'],
+              ['property-value', 'ease-out'],
+              ['property-value', '5s'],
+              ['property-value', 'forwards'],
+              ['property-value', 'test-name']
+            ])
+          );
+        },
+        'gives right value back': function (restoredValue) {
+          assert.deepEqual(restoredValue, [
+            ['property-value', '0s'],
+            ['property-value', 'ease-out'],
+            ['property-value', '5s'],
+            ['property-value', 'forwards'],
+            ['property-value', 'test-name']
+          ]);
+        }
+      }
     }
   })
   .export(module);