Simplifies value extraction in `can-override`.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 12 Apr 2015 13:56:44 +0000 (14:56 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 12 Apr 2015 16:58:11 +0000 (17:58 +0100)
We now pass wrapped properties only so there's no need anymore to
do an array check.

lib/properties/can-override.js

index eda0274..5d0555a 100644 (file)
@@ -5,10 +5,6 @@
 // The generic idea is that properties that have wider browser support are 'more understandable'
 // than others and that 'less understandable' values can't override more understandable ones.
 
-function _valueOf(property) {
-  return Array.isArray(property.value[0]) ? property.value[0][0] : property.value[0];
-}
-
 // Use when two tokens of the same property can always be merged
 function always() {
   return true;
@@ -19,8 +15,8 @@ function backgroundImage(property1, property2, validator) {
   // Understandability: (none | url | inherit) > (same function) > (same value)
 
   // (none | url)
-  var image1 = _valueOf(property1);
-  var image2 = _valueOf(property2);
+  var image1 = property1.value[0][0];
+  var image2 = property2.value[0][0];
 
   if (image2 == 'none' || image2 == 'inherit' || validator.isValidUrl(image2))
     return true;
@@ -41,8 +37,8 @@ function color(property1, property2, validator) {
   // Understandability: (hex | named) > (rgba | hsla) > (same function name) > anything else
   // NOTE: at this point rgb and hsl are replaced by hex values by clean-css
 
-  var color1 = _valueOf(property1);
-  var color2 = _valueOf(property2);
+  var color1 = property1.value[0][0];
+  var color2 = property2.value[0][0];
 
   // (hex | named)
   if (validator.isValidNamedColor(color2) || validator.isValidHexColor(color2))
@@ -61,22 +57,22 @@ function color(property1, property2, validator) {
 }
 
 function twoOptionalFunctions(property1, property2, validator) {
-  var value1 = _valueOf(property1);
-  var value2 = _valueOf(property2);
+  var value1 = property1.value[0][0];
+  var value2 = property2.value[0][0];
 
   return !(validator.isValidFunction(value1) ^ validator.isValidFunction(value2));
 }
 
 function sameValue(property1, property2) {
-  var value1 = _valueOf(property1);
-  var value2 = _valueOf(property2);
+  var value1 = property1.value[0][0];
+  var value2 = property2.value[0][0];
 
   return value1 === value2;
 }
 
 function sameFunctionOrValue(property1, property2, validator) {
-  var value1 = _valueOf(property1);
-  var value2 = _valueOf(property2);
+  var value1 = property1.value[0][0];
+  var value2 = property2.value[0][0];
 
   // Functions with the same name can override each other
   if (validator.areSameFunction(value1, value2))
@@ -92,8 +88,8 @@ function unit(property1, property2, validator) {
   // NOTE: there is no point in having different vendor-specific functions override each other or standard functions,
   //       or having standard functions override vendor-specific functions, but standard functions can override each other
   // NOTE: vendor-specific property values are not taken into consideration here at the moment
-  var value1 = _valueOf(property1);
-  var value2 = _valueOf(property2);
+  var value1 = property1.value[0][0];
+  var value2 = property2.value[0][0];
 
   if (validator.isValidAndCompatibleUnitWithoutFunction(value1) && !validator.isValidAndCompatibleUnitWithoutFunction(value2))
     return false;