Skip to content

Commit 7347b8b

Browse files
author
Brett Stimmerman
committed
Fix whitespace and indentation in the Compressed compiler.
Before this change the Compressed compiler errored when processing @page and @supports blocks, and the tests did not cover this. This change fixes @page and @supports compression in the Compressed compiler, fixes the tests to fully flex the Compressed compiler, and adds missing fixtures to flesh out the test suite.
1 parent 5097e31 commit 7347b8b

9 files changed

+23
-19
lines changed

lib/compress.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Compiler.prototype.visit = function(node){
3636
*/
3737

3838
Compiler.prototype.comment = function(node){
39-
if (this.compress) return '';
39+
return '';
4040
};
4141

4242
/**
@@ -95,11 +95,9 @@ Compiler.prototype.namespace = function(node){
9595
Compiler.prototype.supports = function(node){
9696
return '@supports '
9797
+ node.supports
98-
+ ' {\n'
99-
+ this.indent(1)
100-
+ node.rules.map(this.visit, this).join('\n\n')
101-
+ this.indent(-1)
102-
+ '\n}';
98+
+ '{'
99+
+ node.rules.map(this.visit, this).join('')
100+
+ '}';
103101
};
104102

105103
/**
@@ -135,15 +133,13 @@ Compiler.prototype.keyframe = function(node){
135133

136134
Compiler.prototype.page = function(node){
137135
var sel = node.selectors.length
138-
? node.selectors.join(', ') + ' '
136+
? node.selectors.join(', ')
139137
: '';
140138

141139
return '@page ' + sel
142-
+ '{\n'
143-
+ this.indent(1)
144-
+ node.declarations.map(this.visit, this).join('\n')
145-
+ this.indent(-1)
146-
+ '\n}';
140+
+ '{'
141+
+ node.declarations.map(this.visit, this).join('')
142+
+ '}';
147143
};
148144

149145
/**

test/cases/document.compressed.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@-moz-document url-prefix(){.icon-spin{height:.9em;}.btn .icon-spin{height:auto;}.icon-spin.icon-large{height:1.25em;}.btn .icon-spin.icon-large{height:.75em;}}

test/cases/media.compressed.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@media screen, projection{html{background:#fffef0;color:#300;}body{max-width:35em;margin:0 auto;}}@media print{html{background:#fff;color:#000;}body{padding:1in;border:0.5pt solid #666;}}

test/cases/page.compressed.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@page {margin:2.5cm;}@page :left{margin-left:5cm;}@page :right{margin-right:5cm;}@page :first{margin-top:8cm;}

test/cases/rules.compressed.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tobi{name:'tobi';age:2;}loki{name:'loki';age:1;}

test/cases/selectors.compressed.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo,bar,baz{color:'black';}

test/cases/supports.compressed.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@supports (display: flex){div{display:flex;}div{something:else;}}

test/cases/supports.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
@supports (display: flex) {
32
div {
43
display: flex;

test/css-stringify.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ var stringify = require('..')
1212

1313
describe('stringify(obj)', function(){
1414
readdir('test/cases').forEach(function(file){
15-
var compress = ~file.indexOf('compress');
16-
file = path.basename(file, '.css');
17-
it('should stringify ' + file, function(){
18-
var css = read(path.join('test', 'cases', file + '.css'), 'utf8');
19-
if (compress) file = file.replace('.compress', '');
15+
var compress = ~file.indexOf('.compressed');
16+
it('should stringify ' + path.basename(file), function(){
17+
var expect;
18+
if (compress) {
19+
expect = read(path.join('test', 'cases', file), 'utf8');
20+
file = file.replace('.compressed', '');
21+
}
22+
var css = read(path.join('test', 'cases', file), 'utf8');
2023
var ret = stringify(parse(css), { compress: compress });
21-
ret.trim().should.equal(css.trim());
24+
ret.trim().should.equal((expect || css).trim());
2225
});
2326
});
2427
});

0 commit comments

Comments
 (0)