Skip to content

Commit 4df1e0e

Browse files
committed
add ignoring of empty rulesets. Closes #7
1 parent b9865cc commit 4df1e0e

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

examples/empty.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
body {
3+
4+
}

examples/empty.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
/**
3+
* Module dependencies.
4+
*/
5+
6+
var parse = require('css-parse')
7+
, stringify = require('..')
8+
, fs = require('fs')
9+
, read = fs.readFileSync
10+
, css = read('examples/empty.css', 'utf8');
11+
12+
console.log(stringify(parse(css), { compress: true }));

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,21 @@ Compiler.prototype.page = function(node){
178178

179179
Compiler.prototype.rule = function(node){
180180
var indent = this.indent();
181+
var decls = node.declarations;
181182

182183
if (this.compress) {
184+
if (!decls.length) return '';
185+
183186
return node.selectors.join(',')
184187
+ '{'
185-
+ node.declarations.map(this.declaration, this).join(';')
188+
+ decls.map(this.declaration, this).join(';')
186189
+ '}';
187190
}
188191

189192
return node.selectors.map(function(s){ return indent + s }).join(',\n')
190193
+ ' {\n'
191194
+ this.indent(1)
192-
+ node.declarations.map(this.declaration, this).join(';\n')
195+
+ decls.map(this.declaration, this).join(';\n')
193196
+ this.indent(-1)
194197
+ '\n' + this.indent() + '}';
195198
};

0 commit comments

Comments
 (0)