Skip to content

Commit b0bf887

Browse files
committed
remove identity checks from compressed compiler
1 parent 6ffde6c commit b0bf887

File tree

1 file changed

+21
-98
lines changed

1 file changed

+21
-98
lines changed

lib/compress.js

Lines changed: 21 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ module.exports = Compiler;
1111

1212
function Compiler(options) {
1313
options = options || {};
14-
this.compress = options.compress;
15-
this.indentation = options.indent;
1614
}
1715

1816
/**
@@ -22,7 +20,7 @@ function Compiler(options) {
2220
Compiler.prototype.compile = function(node){
2321
return node.stylesheet
2422
.rules.map(this.visit, this)
25-
.join(this.compress ? '' : '\n\n');
23+
.join('');
2624
};
2725

2826
/**
@@ -39,7 +37,6 @@ Compiler.prototype.visit = function(node){
3937

4038
Compiler.prototype.comment = function(node){
4139
if (this.compress) return '';
42-
return this.indent() + '/*' + node.comment + '*/';
4340
};
4441

4542
/**
@@ -55,21 +52,11 @@ Compiler.prototype.import = function(node){
5552
*/
5653

5754
Compiler.prototype.media = function(node){
58-
if (this.compress) {
59-
return '@media '
60-
+ node.media
61-
+ '{'
62-
+ node.rules.map(this.visit, this).join('')
63-
+ '}';
64-
}
65-
6655
return '@media '
6756
+ node.media
68-
+ ' {\n'
69-
+ this.indent(1)
70-
+ node.rules.map(this.visit, this).join('\n\n')
71-
+ this.indent(-1)
72-
+ '\n}';
57+
+ '{'
58+
+ node.rules.map(this.visit, this).join('')
59+
+ '}';
7360
};
7461

7562
/**
@@ -79,31 +66,18 @@ Compiler.prototype.media = function(node){
7966
Compiler.prototype.document = function(node){
8067
var doc = '@' + (node.vendor || '') + 'document ' + node.document;
8168

82-
if (this.compress) {
83-
return doc
84-
+ '{'
85-
+ node.rules.map(this.visit, this).join('')
86-
+ '}';
87-
}
88-
89-
return doc + ' '
90-
+ ' {\n'
91-
+ this.indent(1)
92-
+ node.rules.map(this.visit, this).join('\n\n')
93-
+ this.indent(-1)
94-
+ '\n}';
69+
return doc
70+
+ '{'
71+
+ node.rules.map(this.visit, this).join('')
72+
+ '}';
9573
};
9674

9775
/**
9876
* Visit charset node.
9977
*/
10078

10179
Compiler.prototype.charset = function(node){
102-
if (this.compress) {
103-
return '@charset ' + node.charset + ';';
104-
}
105-
106-
return '@charset ' + node.charset + ';\n';
80+
return '@charset ' + node.charset + ';';
10781
};
10882

10983
/**
@@ -125,24 +99,12 @@ Compiler.prototype.supports = function(node){
12599
*/
126100

127101
Compiler.prototype.keyframes = function(node){
128-
if (this.compress) {
129-
return '@'
130-
+ (node.vendor || '')
131-
+ 'keyframes '
132-
+ node.name
133-
+ '{'
134-
+ node.keyframes.map(this.visit, this).join('')
135-
+ '}';
136-
}
137-
138102
return '@'
139103
+ (node.vendor || '')
140104
+ 'keyframes '
141105
+ node.name
142-
+ ' {\n'
143-
+ this.indent(1)
144-
+ node.keyframes.map(this.visit, this).join('\n')
145-
+ this.indent(-1)
106+
+ '{'
107+
+ node.keyframes.map(this.visit, this).join('')
146108
+ '}';
147109
};
148110

@@ -153,20 +115,10 @@ Compiler.prototype.keyframes = function(node){
153115
Compiler.prototype.keyframe = function(node){
154116
var decls = node.declarations;
155117

156-
if (this.compress) {
157-
return node.values.join(',')
158-
+ '{'
159-
+ decls.map(this.visit, this).join('')
160-
+ '}';
161-
}
162-
163-
return this.indent()
164-
+ node.values.join(', ')
165-
+ ' {\n'
166-
+ this.indent(1)
167-
+ decls.map(this.visit, this).join('\n')
168-
+ this.indent(-1)
169-
+ '\n' + this.indent() + '}\n';
118+
return node.values.join(',')
119+
+ '{'
120+
+ decls.map(this.visit, this).join('')
121+
+ '}';
170122
};
171123

172124
/**
@@ -191,49 +143,20 @@ Compiler.prototype.page = function(node){
191143
*/
192144

193145
Compiler.prototype.rule = function(node){
194-
var indent = this.indent();
195146
var decls = node.declarations;
147+
if (!decls.length) return '';
196148

197-
if (this.compress) {
198-
if (!decls.length) return '';
199-
200-
return node.selectors.join(',')
201-
+ '{'
202-
+ decls.map(this.visit, this).join('')
203-
+ '}';
204-
}
205-
206-
return node.selectors.map(function(s){ return indent + s }).join(',\n')
207-
+ ' {\n'
208-
+ this.indent(1)
209-
+ decls.map(this.visit, this).join('\n')
210-
+ this.indent(-1)
211-
+ '\n' + this.indent() + '}';
149+
return node.selectors.join(',')
150+
+ '{'
151+
+ decls.map(this.visit, this).join('')
152+
+ '}';
212153
};
213154

214155
/**
215156
* Visit declaration node.
216157
*/
217158

218159
Compiler.prototype.declaration = function(node){
219-
if (this.compress) {
220-
return node.property + ':' + node.value + ';';
221-
}
222-
223-
return this.indent() + node.property + ': ' + node.value + ';';
160+
return node.property + ':' + node.value + ';';
224161
};
225162

226-
/**
227-
* Increase, decrease or return current indentation.
228-
*/
229-
230-
Compiler.prototype.indent = function(level) {
231-
this.level = this.level || 1;
232-
233-
if (null != level) {
234-
this.level += level;
235-
return '';
236-
}
237-
238-
return Array(this.level).join(this.indentation || ' ');
239-
};

0 commit comments

Comments
 (0)