From: Jakub Pawlowicz Date: Mon, 5 Mar 2018 11:37:26 +0000 (+0100) Subject: Fixes #988 - edge case in dropping `animation-duration`. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=c7fc1d1af99d62d1792220971a6b74da355e9f60;p=clean-css.git Fixes #988 - edge case in dropping `animation-duration`. When `animation-duration` is default but `animation-delay` isn't we shouldn't drop the former as both need to be given. --- diff --git a/History.md b/History.md index 0f4bbb5f..a847168f 100644 --- a/History.md +++ b/History.md @@ -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) ================== diff --git a/lib/optimizer/level-2/compactable.js b/lib/optimizer/level-2/compactable.js index 81c3f17e..57a58635 100644 --- a/lib/optimizer/level-2/compactable.js +++ b/lib/optimizer/level-2/compactable.js @@ -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; } diff --git a/lib/optimizer/level-2/restore.js b/lib/optimizer/level-2/restore.js index 13f12e49..f9c2f0d3 100644 --- a/lib/optimizer/level-2/restore.js +++ b/lib/optimizer/level-2/restore.js @@ -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, diff --git a/test/optimizer/level-2/restore-test.js b/test/optimizer/level-2/restore-test.js index b37c4bcb..d39182ee 100644 --- a/test/optimizer/level-2/restore-test.js +++ b/test/optimizer/level-2/restore-test.js @@ -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);