postcss-merge-rules
Advanced tools
Comparing version
@@ -0,1 +1,7 @@ | ||
# 2.0.7 | ||
* Resolves an issue where merging was not respecting property order, in cases | ||
where both shorthand definitions and longhand definitions existed. Now, | ||
these cases will not be merged (thanks to @11bit). | ||
# 2.0.6 | ||
@@ -2,0 +8,0 @@ |
@@ -86,2 +86,31 @@ 'use strict'; | ||
function splitProp(prop) { | ||
var parts = prop.split('-'); | ||
var base = undefined, | ||
rest = undefined; | ||
if (prop[0] === '-') { | ||
base = parts[1] + parts[2]; | ||
rest = parts.slice(3); | ||
} else { | ||
base = parts[0]; | ||
rest = parts.slice(1); | ||
} | ||
return [base, rest]; | ||
} | ||
function isConflictingProp(propA, propB) { | ||
if (propA === propB) { | ||
return true; | ||
} | ||
var a = splitProp(propA); | ||
var b = splitProp(propB); | ||
return a[0] === b[0] && a[1].length !== b[1].length; | ||
} | ||
function hasConflicts(declProp, notMoved) { | ||
return notMoved.some(function (prop) { | ||
return isConflictingProp(prop, declProp); | ||
}); | ||
} | ||
function partialMerge(first, second) { | ||
@@ -106,2 +135,21 @@ var _this = this; | ||
var difference = different(getDecls(first), getDecls(second)); | ||
var filterConflicts = function filterConflicts(decls, intersectn) { | ||
var willNotMove = []; | ||
return decls.reduce(function (willMove, decl) { | ||
var intersects = ~intersectn.indexOf(decl); | ||
var prop = decl.split(':')[0]; | ||
var base = prop.split('-')[0]; | ||
var canMove = difference.every(function (d) { | ||
return d.split(':')[0] !== base; | ||
}); | ||
if (intersects && canMove && !hasConflicts(prop, willNotMove)) { | ||
willMove.push(decl); | ||
} else { | ||
willNotMove.push(prop); | ||
} | ||
return willMove; | ||
}, []); | ||
}; | ||
intersection = filterConflicts(getDecls(first).reverse(), intersection); | ||
intersection = filterConflicts(getDecls(second), intersection); | ||
var firstClone = (0, _libClone2['default'])(first); | ||
@@ -111,8 +159,3 @@ var secondClone = (0, _libClone2['default'])(second); | ||
return function (decl) { | ||
var intersects = ~intersection.indexOf(String(decl)); | ||
var base = decl.prop.split('-')[0]; | ||
var canMove = difference.every(function (d) { | ||
return d.split(':')[0] !== base; | ||
}); | ||
if (intersects && canMove) { | ||
if (~intersection.indexOf(String(decl))) { | ||
callback.call(_this, decl); | ||
@@ -175,11 +218,17 @@ } | ||
if (cache.selector === rule.selector) { | ||
var toString = String(cache); | ||
rule.walk(function (decl) { | ||
if (~toString.indexOf(String(decl))) { | ||
return decl.remove(); | ||
} | ||
decl.moveTo(cache); | ||
}); | ||
rule.remove(); | ||
return; | ||
var _ret = (function () { | ||
var toString = String(cache); | ||
rule.walk(function (decl) { | ||
if (~toString.indexOf(String(decl))) { | ||
return decl.remove(); | ||
} | ||
decl.moveTo(cache); | ||
}); | ||
rule.remove(); | ||
return { | ||
v: undefined | ||
}; | ||
})(); | ||
if (typeof _ret === 'object') return _ret.v; | ||
} | ||
@@ -186,0 +235,0 @@ // Partial merge: check if the rule contains a subset of the last; if |
@@ -1,3 +0,1 @@ | ||
/* jshint loopfunc:true */ | ||
'use strict'; | ||
@@ -25,4 +23,4 @@ | ||
} else if (value instanceof Array) { | ||
cloned[i] = value.map(function (i) { | ||
return clone(i, cloned); | ||
cloned[i] = value.map(function (j) { | ||
return clone(j, cloned); | ||
}); | ||
@@ -29,0 +27,0 @@ } else { |
{ | ||
"name": "postcss-merge-rules", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"description": "Merge CSS rules with PostCSS.", | ||
@@ -11,2 +11,3 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"pretest": "eslint src", | ||
"prepublish": "babel src --out-dir dist --ignore /__tests__/", | ||
@@ -25,2 +26,4 @@ "test": "babel-tape-runner \"src/**/__tests__/*.js\" | tap-spec" | ||
"babel-tape-runner": "1.2.0", | ||
"eslint": "^2.8.0", | ||
"eslint-config-cssnano": "^2.0.0", | ||
"postcss-discard-comments": "^2.0.4", | ||
@@ -40,3 +43,6 @@ "postcss-simple-vars": "^1.2.0", | ||
"postcss": "^5.0.4" | ||
}, | ||
"eslintConfig": { | ||
"extends": "cssnano" | ||
} | ||
} |
14728
13.85%246
21.78%8
33.33%