From: Jakub Pawlowicz Date: Wed, 4 Jan 2017 17:06:29 +0000 (+0100) Subject: Reuses `rulesOverlap` helper. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=2c84a273990a4a89b35fe144b29853bef9e31dc1;p=clean-css.git Reuses `rulesOverlap` helper. Why: * It's used in more than one place and the code was not reused. --- diff --git a/lib/optimizer/reorderable.js b/lib/optimizer/reorderable.js index f6d1a631..415e8b85 100644 --- a/lib/optimizer/reorderable.js +++ b/lib/optimizer/reorderable.js @@ -1,5 +1,7 @@ // TODO: it'd be great to merge it with the other canReorder functionality +var rulesOverlap = require('./rules-overlap'); + var FLEX_PROPERTIES = /align\-items|box\-align|box\-pack|flex|justify/; var BORDER_PROPERTIES = /^border\-(top|right|bottom|left|color|style|width|radius)/; @@ -46,7 +48,7 @@ function canReorderSingle(left, right) { return true; if (leftName != rightName && leftNameRoot == rightNameRoot && leftValue == rightValue) return true; - if (rightInSpecificSelector && leftInSpecificSelector && !inheritable(leftNameRoot) && !inheritable(rightNameRoot) && selectorsDoNotOverlap(rightSelector, leftSelector)) + if (rightInSpecificSelector && leftInSpecificSelector && !inheritable(leftNameRoot) && !inheritable(rightNameRoot) && !rulesOverlap(rightSelector, leftSelector, false)) return true; return false; @@ -76,17 +78,6 @@ function withDifferentVendorPrefix(value1, value2) { return vendorPrefixed(value1) && vendorPrefixed(value2) && value1.split('-')[1] != value2.split('-')[2]; } -function selectorsDoNotOverlap(s1, s2) { - for (var i = 0, l = s1.length; i < l; i++) { - for (var j = 0, m = s2.length; j < m; j++) { - if (s1[i][1] == s2[j][1]) - return false; - } - } - - return true; -} - function inheritable(name) { // According to http://www.w3.org/TR/CSS21/propidx.html // Others will be catched by other, preceeding rules