Skip to content

Commit 434aa17

Browse files
authored
Stringify: allow empty string for indent option (#151)
* test: write tests for indent behavior, including failing empty string test * fix: allow empty string to be used in stringify indent option
1 parent b7f3cb6 commit 434aa17

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/stringify/identity.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = Compiler;
1919
function Compiler(options) {
2020
options = options || {};
2121
Base.call(this, options);
22-
this.indentation = options.indent;
22+
this.indentation = typeof options.indent === 'string' ? options.indent : ' ';
2323
}
2424

2525
/**
@@ -250,5 +250,5 @@ Compiler.prototype.indent = function(level) {
250250
return '';
251251
}
252252

253-
return Array(this.level).join(this.indentation || ' ');
253+
return Array(this.level).join(this.indentation);
254254
};

test/stringify.js

+25
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,28 @@ describe('stringify(obj, {sourcemap: true})', function() {
110110
result.map.should.be.an.instanceOf(SourceMapGenerator);
111111
});
112112
});
113+
114+
describe('stringify(obj, {indent: *})', function() {
115+
var css =
116+
'@media print {\n' +
117+
'\tbody {\n' +
118+
'\t\tbackground: #fff;\n' +
119+
'\t}\n' +
120+
'}';
121+
var stylesheet = parse(css);
122+
123+
it('should default to two-space indent', function(){
124+
var result = stringify(stylesheet);
125+
result.should.eql(css.replace(/\t/g, ' '));
126+
});
127+
128+
it('should indent according to the indent string', function(){
129+
var result = stringify(stylesheet, { indent: '\t' });
130+
result.should.eql(css);
131+
});
132+
133+
it('should accept empty string for indent', function(){
134+
var result = stringify(stylesheet, { indent: '' });
135+
result.should.eql(css.replace(/\t/g, ''));
136+
});
137+
});

0 commit comments

Comments
 (0)