@@ -32,8 +32,26 @@ module.exports = {
3232
3333 _removeEmptyRulesets : function ( nodeContent ) {
3434 var i = nodeContent . length ;
35+ // Loop through node and try to find a ruleset:
3536 while ( i -- ) {
36- if ( this . _isRuleset ( nodeContent [ i ] ) && this . _isEmptyRuleset ( nodeContent [ i ] ) ) {
37+ var node = nodeContent [ i ] ;
38+ if ( ! this . _isRuleset ( node ) ) continue ;
39+ // If a ruleset is found, try to find its nested rulesets and remove
40+ // all empty ones:
41+ var j = node . length ;
42+ while ( j -- ) {
43+ // Nested rulesets are located inside blocks, that's why look
44+ // for blocks only:
45+ var blockNode = node [ j ] ;
46+ if ( blockNode [ 0 ] !== 'block' ) continue ;
47+ blockNode . shift ( ) ;
48+ this . _processStylesheetContent ( blockNode ) ;
49+ blockNode . unshift ( 'block' ) ;
50+ node [ j ] = blockNode ;
51+ }
52+ // If after removing all empty nested rulesets the parent has also
53+ // become empty, remove it too:
54+ if ( this . _isEmptyRuleset ( node ) ) {
3755 nodeContent . splice ( i , 1 ) ;
3856 }
3957 }
@@ -60,10 +78,10 @@ module.exports = {
6078 } ,
6179
6280 /**
63- * Block considered empty when it has no declarations or comments .
81+ * Block is considered empty when it has nothing but spaces .
6482 */
6583 _isEmptyBlock : function ( node ) {
66- return ! node . some ( this . _isDeclarationOrComment ) ;
84+ return node . length === 1 || ! node . some ( this . _isNotWhitespace ) ;
6785 } ,
6886
6987 _isDeclarationOrComment : function ( node ) {
@@ -82,6 +100,10 @@ module.exports = {
82100 return node [ 0 ] === 's' ;
83101 } ,
84102
103+ _isNotWhitespace : function ( node ) {
104+ return typeof node === 'object' && node [ 0 ] !== 's' ;
105+ } ,
106+
85107 /**
86108 * Detects the value of an option at the tree node.
87109 * This option is treated as `true` by default, but any trailing space would invalidate it.
0 commit comments