Skip to content

Commit 8c7a861

Browse files
Fixes #695 - edge case in shorthand overriding.
A longhand value should not be overriden by a shorthand with a function value, e.g. ```css div { background-color: red; background: linear-gradient(red, blue); } ```
1 parent cdeab50 commit 8c7a861

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

History.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
[3.4.7 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.6...3.4)
2+
==================
3+
4+
* Fixed issue [#695](https://github.com/jakubpawlowicz/clean-css/issues/695) - shorthand overriding edge case.
5+
16
[3.4.6 / 2015-10-14](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.5...v3.4.6)
27
==================
38

lib/properties/override-compactor.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ function moreSameShorthands(properties, startAt, name) {
122122
return count > 1;
123123
}
124124

125-
function mergingIntoFunction(left, right, validator) {
126-
for (var i = 0, l = left.components.length; i < l; i++) {
127-
if (anyValue(validator.isValidFunction, left.components[i]))
125+
function overridingFunction(shorthand, validator) {
126+
for (var i = 0, l = shorthand.components.length; i < l; i++) {
127+
if (anyValue(validator.isValidFunction, shorthand.components[i]))
128128
return true;
129129
}
130130

@@ -260,6 +260,9 @@ function compactOverrides(properties, compatibility, validator) {
260260
if (!sameVendorPrefixesIn([left], right.components))
261261
continue;
262262

263+
if (!anyValue(validator.isValidFunction, left) && overridingFunction(right, validator))
264+
continue;
265+
263266
component = right.components.filter(nameMatchFilter(left))[0];
264267
mayOverride = (compactable[left.name] && compactable[left.name].canOverride) || canOverride.sameValue;
265268
if (everyCombination(mayOverride, left, component, validator)) {
@@ -274,7 +277,7 @@ function compactOverrides(properties, compatibility, validator) {
274277
if (moreSameShorthands(properties, i - 1, left.name))
275278
continue;
276279

277-
if (mergingIntoFunction(left, right, validator))
280+
if (overridingFunction(left, validator))
278281
continue;
279282

280283
component = left.components.filter(nameMatchFilter(right))[0];

test/properties/override-compacting-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ vows.describe(optimize)
8181
]);
8282
}
8383
},
84+
'longhand then shorthand - with unprefixed function 123': {
85+
'topic': 'p{background-color:red;background:linear-gradient(red,blue)}',
86+
'into': function (topic) {
87+
assert.deepEqual(_optimize(topic), [
88+
[['background-color'], ['red']],
89+
[['background'], ['linear-gradient(red,blue)']]
90+
]);
91+
}
92+
},
8493
'shorthand then longhand': {
8594
'topic': 'p{background:__ESCAPED_URL_CLEAN_CSS0__ repeat;background-repeat:no-repeat}',
8695
'into': function (topic) {

0 commit comments

Comments
 (0)