Skip to content

Commit 21a5df0

Browse files
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.
1 parent 5f6cbc6 commit 21a5df0

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

History.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
[4.1.10 / 2018-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.9...4.1)
2+
==================
3+
4+
* Fixed issue [#988](https://github.com/jakubpawlowicz/clean-css/issues/988) - edge case in dropping default animation-duration.
5+
16
[4.1.9 / 2017-09-19](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.8...v4.1.9)
27
==================
38

lib/optimizer/level-2/compactable.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ var compactable = {
9999
],
100100
defaultValue: '0s',
101101
intoMultiplexMode: 'real',
102+
keepUnlessDefault: 'animation-delay',
102103
vendorPrefixes: [
103104
'-moz-',
104105
'-o-',
@@ -955,6 +956,10 @@ function cloneDescriptor(propertyName, prefix) {
955956
});
956957
}
957958

959+
if ('keepUnlessDefault' in clonedDescriptor) {
960+
clonedDescriptor.keepUnlessDefault = prefix + clonedDescriptor.keepUnlessDefault;
961+
}
962+
958963
return clonedDescriptor;
959964
}
960965

lib/optimizer/level-2/restore.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,9 @@ function withoutDefaults(property, compactable) {
264264
var component = components[i];
265265
var descriptor = compactable[component.name];
266266

267-
if (component.value[0][1] != descriptor.defaultValue)
267+
if (component.value[0][1] != descriptor.defaultValue || ('keepUnlessDefault' in descriptor) && !isDefault(components, compactable, descriptor.keepUnlessDefault)) {
268268
restored.unshift(component.value[0]);
269+
}
269270
}
270271

271272
if (restored.length === 0)
@@ -277,6 +278,21 @@ function withoutDefaults(property, compactable) {
277278
return restored;
278279
}
279280

281+
function isDefault(components, compactable, propertyName) {
282+
var component;
283+
var i, l;
284+
285+
for (i = 0, l = components.length; i < l; i++) {
286+
component = components[i];
287+
288+
if (component.name == propertyName && component.value[0][1] == compactable[propertyName].defaultValue) {
289+
return true;
290+
}
291+
}
292+
293+
return false;
294+
}
295+
280296
module.exports = {
281297
background: background,
282298
borderRadius: borderRadius,

test/optimizer/level-2/restore-test.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,78 @@ vows.describe(restore)
979979
]);
980980
}
981981
}
982+
},
983+
'animation': {
984+
'with two time units where both are default': {
985+
'topic': function () {
986+
return _restore(
987+
_breakUp([
988+
'property',
989+
['property-name', 'animation'],
990+
['property-value', '0s'],
991+
['property-value', 'ease-out'],
992+
['property-value', '0s'],
993+
['property-value', 'forwards'],
994+
['property-value', 'test-name']
995+
])
996+
);
997+
},
998+
'gives right value back': function (restoredValue) {
999+
assert.deepEqual(restoredValue, [
1000+
['property-value', 'ease-out'],
1001+
['property-value', 'forwards'],
1002+
['property-value', 'test-name']
1003+
]);
1004+
}
1005+
},
1006+
'with two time units where first is default': {
1007+
'topic': function () {
1008+
return _restore(
1009+
_breakUp([
1010+
'property',
1011+
['property-name', 'animation'],
1012+
['property-value', '0s'],
1013+
['property-value', 'ease-out'],
1014+
['property-value', '5s'],
1015+
['property-value', 'forwards'],
1016+
['property-value', 'test-name']
1017+
])
1018+
);
1019+
},
1020+
'gives right value back': function (restoredValue) {
1021+
assert.deepEqual(restoredValue, [
1022+
['property-value', '0s'],
1023+
['property-value', 'ease-out'],
1024+
['property-value', '5s'],
1025+
['property-value', 'forwards'],
1026+
['property-value', 'test-name']
1027+
]);
1028+
}
1029+
},
1030+
'with two vendor-prefixed time units where first is default': {
1031+
'topic': function () {
1032+
return _restore(
1033+
_breakUp([
1034+
'property',
1035+
['property-name', '-webkit-animation'],
1036+
['property-value', '0s'],
1037+
['property-value', 'ease-out'],
1038+
['property-value', '5s'],
1039+
['property-value', 'forwards'],
1040+
['property-value', 'test-name']
1041+
])
1042+
);
1043+
},
1044+
'gives right value back': function (restoredValue) {
1045+
assert.deepEqual(restoredValue, [
1046+
['property-value', '0s'],
1047+
['property-value', 'ease-out'],
1048+
['property-value', '5s'],
1049+
['property-value', 'forwards'],
1050+
['property-value', 'test-name']
1051+
]);
1052+
}
1053+
}
9821054
}
9831055
})
9841056
.export(module);

0 commit comments

Comments
 (0)