Reuses `rulesOverlap` helper.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 4 Jan 2017 17:06:29 +0000 (18:06 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 4 Jan 2017 17:06:29 +0000 (18:06 +0100)
Why:

* It's used in more than one place and the code was not reused.

lib/optimizer/reorderable.js

index f6d1a63..415e8b8 100644 (file)
@@ -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