Fixes #390 - Exclude all problematic pseudo-classes from rule merge
authorsilverwind <me@silverwind.io>
Mon, 1 Dec 2014 18:14:24 +0000 (19:14 +0100)
committersilverwind <me@silverwind.io>
Mon, 1 Dec 2014 18:14:24 +0000 (19:14 +0100)
lib/utils/compatibility.js
test/integration-test.js
test/utils/compatibility-test.js

index 17fbfb3..9484f0f 100644 (file)
@@ -13,7 +13,7 @@ var DEFAULTS = {
     },
     selectors: {
       ie7Hack: false, // *+html hack
-      special: /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:fullscreen)/ // special selectors which prevent merging
+      special: /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:dir\((ltr|rtl)\)|:first|:fullscreen|:left|:read-only|:read-write|:right)/ // special selectors which prevent merging
     },
     units: {
       rem: true
index 7be2cc0..d31bc10 100644 (file)
@@ -2089,17 +2089,33 @@ title']{display:block}",
       'a{color:red}b{color:red}',
       'a,b{color:red}'
     ],
-    'rules with standard pseudo classes should be merged': [
+    'rules with well-supported pseudo classes should be merged #1': [
       'a:focus{color:red}b{color:red}',
       'a:focus,b{color:red}'
     ],
-    'rules with prefixed pseudo classes should not be merged': [
+    'rules with well-supported pseudo classes should be merged #2': [
+      'a:nth-of-type(1){color:red}b{color:red}',
+      'a:nth-of-type(1),b{color:red}'
+    ],
+    'rules with prefixed pseudo classes should not be merged #1': [
       'a:-moz-full-screen{color:red}b{color:red}',
       'a:-moz-full-screen{color:red}b{color:red}'
     ],
-    'rules with standard, but unimplemented pseudo classes should not be merged': [
+    'rules with prefixed pseudo classes should not be merged #2': [
+      'a:-moz-dir(rtl){color:red}b{color:red}',
+      'a:-moz-dir(rtl){color:red}b{color:red}'
+    ],
+    'rules with not-so-well-supported pseudo classes should not be merged #1': [
       'a:fullscreen{color:red}b{color:red}',
       'a:fullscreen{color:red}b{color:red}'
+    ],
+    'rules with not-so-well-supported pseudo classes should not be merged #2': [
+      'a:dir(ltr){color:red}b{color:red}',
+      'a:dir(ltr){color:red}b{color:red}'
+    ],
+    'rules with not-so-well-supported pseudo classes should not be merged #3': [
+      'a:right{color:red}b{color:red}',
+      'a:right{color:red}b{color:red}'
     ]
   }),
   'complex granular properties': cssContext({
index d0f7324..cbbbcc9 100644 (file)
@@ -14,7 +14,7 @@ vows.describe(Compatibility)
         assert.isTrue(options.properties.merging);
         assert.isTrue(options.units.rem);
         assert.isTrue(options.colors.opacity);
-        assert.deepEqual(options.selectors.special, /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:fullscreen)/);
+        assert.deepEqual(options.selectors.special, /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:dir\((ltr|rtl)\)|:first|:fullscreen|:left|:read-only|:read-write|:right)/);
       }
     },
     'not given': {
@@ -33,7 +33,7 @@ vows.describe(Compatibility)
         assert.isTrue(options.properties.merging);
         assert.isFalse(options.units.rem);
         assert.isTrue(options.colors.opacity);
-        assert.deepEqual(options.selectors.special, /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:fullscreen)/);
+        assert.deepEqual(options.selectors.special, /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:dir\((ltr|rtl)\)|:first|:fullscreen|:left|:read-only|:read-write|:right)/);
       }
     }
   })
@@ -95,7 +95,7 @@ vows.describe(Compatibility)
         assert.isTrue(options.properties.merging);
         assert.isTrue(options.units.rem);
         assert.isTrue(options.colors.opacity);
-        assert.deepEqual(options.selectors.special, /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:fullscreen)/);
+        assert.deepEqual(options.selectors.special, /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:dir\((ltr|rtl)\)|:first|:fullscreen|:left|:read-only|:read-write|:right)/);
       }
     },
     'as a complex string value without group': {
@@ -108,7 +108,7 @@ vows.describe(Compatibility)
         assert.isTrue(options.properties.merging);
         assert.isFalse(options.units.rem);
         assert.isTrue(options.colors.opacity);
-        assert.deepEqual(options.selectors.special, /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:fullscreen)/);
+        assert.deepEqual(options.selectors.special, /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:dir\((ltr|rtl)\)|:first|:fullscreen|:left|:read-only|:read-write|:right)/);
       }
     }
   })