Some final touches and more tests
authorTimur Kristóf <venemo@msn.com>
Fri, 28 Feb 2014 15:27:57 +0000 (16:27 +0100)
committerTimur Kristóf <venemo@msn.com>
Fri, 28 Feb 2014 15:27:57 +0000 (16:27 +0100)
lib/properties/processable.js
lib/properties/shorthand-compactor.js
lib/properties/validator.js
test/unit-test.js

index 91e00e0..8c9a7ac 100644 (file)
@@ -85,7 +85,6 @@ module.exports = (function () {
       // Functions with the same name can override each other; same values can override each other
       return canOverride.sameFunctionOrValue(val1, val2);
     }
-    // TODO: add more
   };
   canOverride = Object.freeze(canOverride);
 
index e116726..177d789 100644 (file)
@@ -132,7 +132,6 @@ module.exports = (function () {
       var compactedLength = Token.getDetokenizedLength(compacted);
       var authenticLength = Token.getDetokenizedLength(realComponents);
 
-      // TODO: unit test for hacked value
       if (realComponents.length === processable[prop].components.length || compactedLength < authenticLength || components.some(isHackValue)) {
         compacted[0].isShorthand = true;
         compacted[0].components = processable[prop].breakUp(compacted[0]);
@@ -183,15 +182,16 @@ module.exports = (function () {
         // Found an instance of a full shorthand
         // NOTE: we should NOT mix together tokens that come before and after the shorthands
 
-        if (token.isImportant === isImportant) {
+        if (token.isImportant === isImportant || (token.isImportant && !isImportant)) {
           // Try to compact what we've found so far
           while (compactSoFar(token.prop)) { }
           // Reset
           initSoFar(token.prop, token, true);
         }
 
-        // TODO: test case for shorthanding boundaries
-        // TODO: what happens if the importantness of the shorthand isn't the same as isImportant parameter?
+        // TODO: when the old optimizer is removed, take care of this corner case:
+        //   div{background-color:#111;background-image:url(aaa);background:linear-gradient(aaa);background-repeat:no-repeat;background-position:1px 2px;background-attachment:scroll}
+        //   -> should not be shorthanded / minified at all because the result wouldn't be equivalent to the original in any browser
       }
       else if (processable[token.prop].componentOf) {
         // Found a component of a shorthand
index b9f4487..5ffce7f 100644 (file)
@@ -22,11 +22,10 @@ module.exports = (function () {
       return s.length > 0 && s.indexOf('hsla(') === 0 && s.indexOf(')') === s.length - 1;
     },
     isValidNamedColor: function (s) {
-      // TODO: we don't really check if it's a valid color value, but allow any letters in it
+      // We don't really check if it's a valid color value, but allow any letters in it
       return s !== 'auto' && (s === 'transparent' || s === 'inherit' || /^[a-zA-Z]+$/.test(s));
     },
     isValidColor: function (s) {
-      // http://www.w3schools.com/cssref/css_colors_legal.asp
       return validator.isValidNamedColor(s) || validator.isValidHexColor(s) || validator.isValidRgbaColor(s) || validator.isValidHslaColor(s);
     },
     isValidUrl: function (s) {
index 4f77319..d580055 100644 (file)
@@ -1630,6 +1630,10 @@ title']{display:block}",
     'should NOT merge outline with inherited outline-width': [
       'a{outline:0;outline-width:inherit}',
       'a{outline:0;outline-width:inherit}'
+    ],
+    'should merge list-style with list-style-type': [
+      'li{list-style-type:disc;list-style:inside}',
+      'li{list-style:inside}'
     ]
   }),
   'shorthand properties': cssContext({
@@ -1660,6 +1664,14 @@ title']{display:block}",
     'shorthand border-radius': [
       '.t{border-top-left-radius:7px;border-bottom-right-radius:6px;border-bottom-left-radius:5px;border-top-right-radius:3px}',
       '.t{border-radius:7px 3px 6px 5px}'
+    ],
+    'shorthand list-style #1': [
+      '.t{list-style-type:circle;list-style-position:outside;list-style-image:url(aaa)}',
+      '.t{list-style:circle url(aaa)}'
+    ],
+    'shorthand list-style #2': [
+      '.t{list-style-image:url(aaa);list-style-type:circle;list-style-position:inside}',
+      '.t{list-style:circle inside url(aaa)}'
     ]
   }),
   'care about understandability of shorthand components': cssContext({