Adds support for Polymer / Web Components selectors.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 24 Aug 2015 04:36:30 +0000 (05:36 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 24 Aug 2015 04:36:30 +0000 (05:36 +0100)
These include
* :host and ::content for Polymer
* /deep/ and ::shadow for Web Components

See #648.

History.md
lib/utils/compatibility.js
test/integration-test.js

index a2781ef..2d6946d 100644 (file)
@@ -3,6 +3,7 @@
 
 * Adds unit compatibility switches to disable length optimizations.
 * Adds inferring proxy settings from HTTP_PROXY environment variable.
+* Adds support for Polymer / Web Components special selectors.
 * Unifies wrappers for simple & advanced optimizations.
 * Fixed issue [#596](https://github.com/jakubpawlowicz/clean-css/issues/596) - support for !ie IE<8 hack.
 * Fixed issue [#599](https://github.com/jakubpawlowicz/clean-css/issues/599) - support for inlined source maps.
index 1f8aecb..34a8269 100644 (file)
@@ -21,7 +21,7 @@ var DEFAULTS = {
     selectors: {
       adjacentSpace: false, // div+ nav Android stock browser hack
       ie7Hack: false, // *+html hack
-      special: /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:dir\([a-z-]*\)|:first(?![a-z-])|:fullscreen|:left|:read-only|:read-write|:right|:placeholder)/ // special selectors which prevent merging
+      special: /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:dir\([a-z-]*\)|:first(?![a-z-])|:fullscreen|:left|:read-only|:read-write|:right|:placeholder|:host|::content|\/deep\/|::shadow)/ // special selectors which prevent merging
     },
     units: {
       ch: true,
@@ -56,7 +56,7 @@ var DEFAULTS = {
     selectors: {
       adjacentSpace: false,
       ie7Hack: false,
-      special: /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:root|:nth|:first\-of|:last|:only|:empty|:target|:checked|::selection|:enabled|:disabled|:not|:placeholder)/
+      special: /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:root|:nth|:first\-of|:last|:only|:empty|:target|:checked|::selection|:enabled|:disabled|:not|:placeholder|:host|::content|\/deep\/|::shadow)/
     },
     units: {
       ch: false,
@@ -91,7 +91,7 @@ var DEFAULTS = {
     selectors: {
       adjacentSpace: false,
       ie7Hack: true,
-      special: /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:focus|:before|:after|:root|:nth|:first\-of|:last|:only|:empty|:target|:checked|::selection|:enabled|:disabled|:not|:placeholder)/
+      special: /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:focus|:before|:after|:root|:nth|:first\-of|:last|:only|:empty|:target|:checked|::selection|:enabled|:disabled|:not|:placeholder|:host|::content|\/deep\/|::shadow)/
     },
     units: {
       ch: false,
index 7212901..b6ec0b5 100644 (file)
@@ -2379,6 +2379,22 @@ vows.describe('integration tests')
       'rules with not-so-well-supported pseudo classes should not be merged #5': [
         ':placeholder{color:red}b{color:red}',
         ':placeholder{color:red}b{color:red}'
+      ],
+      'rules with :host Polymer pseudo class should not be merged into': [
+        ':host{color:red}b{color:red}',
+        ':host{color:red}b{color:red}'
+      ],
+      'rules with ::content Polymer pseudo element should not be merged into': [
+        '.wrapper ::content a{color:red}b{color:red}',
+        '.wrapper ::content a{color:red}b{color:red}'
+      ],
+      'rules with /deep/ Polymer combinator not be merged into': [
+        '.wrapper /deep/ a{color:red}b{color:red}',
+        '.wrapper /deep/ a{color:red}b{color:red}'
+      ],
+      'rules with ::shadow Polymer combinator not be merged into': [
+        '.wrapper ::shadow a{color:red}b{color:red}',
+        '.wrapper ::shadow a{color:red}b{color:red}'
       ]
     })
   )