Skip to content

Commit

Permalink
Fixes #988 - edge case in dropping animation-duration.
Browse files Browse the repository at this point in the history
When `animation-duration` is default but `animation-delay` isn't we
shouldn't drop the former as both need to be given.
  • Loading branch information
jakubpawlowicz committed Mar 5, 2018
1 parent 25771a5 commit c7fc1d1
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
5 changes: 5 additions & 0 deletions History.md
Expand Up @@ -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)
==================

Expand Down
5 changes: 5 additions & 0 deletions lib/optimizer/level-2/compactable.js
Expand Up @@ -99,6 +99,7 @@ var compactable = {
],
defaultValue: '0s',
intoMultiplexMode: 'real',
keepUnlessDefault: 'animation-delay',
vendorPrefixes: [
'-moz-',
'-o-',
Expand Down Expand Up @@ -1031,6 +1032,10 @@ function cloneDescriptor(propertyName, prefix) {
});
}

if ('keepUnlessDefault' in clonedDescriptor) {
clonedDescriptor.keepUnlessDefault = prefix + clonedDescriptor.keepUnlessDefault;
}

return clonedDescriptor;
}

Expand Down
18 changes: 17 additions & 1 deletion lib/optimizer/level-2/restore.js
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
72 changes: 72 additions & 0 deletions test/optimizer/level-2/restore-test.js
Expand Up @@ -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);

0 comments on commit c7fc1d1

Please sign in to comment.