* Old behavior allowed line breaks within selector, like 'a\np{}'.
* Adds basic optimizer removing duplicate selectors from a list.
* Adds merging duplicate properties within a single selector's body.
* Adds merging adjacent selectors within a scope (single and multiple ones).
+* Changes behavior of `--keep-line-breaks`/`keepBreaks` option to keep breaks after trailing braces only.
1.1.7 / 2013-10-28
==================
});
// line breaks
- if (!options.keepBreaks)
- replace(/[\r]?\n/g, ' ');
+ replace(/[\r]?\n/g, ' ');
// multiple whitespace
replace(/[\t ]+/g, ' ');
});
replace(function optimizeSelectors() {
- data = new SelectorsOptimizer(data).process();
+ data = new SelectorsOptimizer(data, options.keepBreaks, lineBreak).process();
});
replace(function restoreUrls() {
// reattach first charset and remove all subsequent
data = firstCharset +
(options.keepBreaks ? lineBreak : '') +
- data.replace(new RegExp('@charset [^;]+;(' + lineBreak + ')?', 'g'), '');
+ data.replace(new RegExp('@charset [^;]+;(' + lineBreak + ')?', 'g'), '').trim();
});
replace(function removeEmptySelectors() {
var Tokenizer = require('./tokenizer');
-module.exports = function Optimizer(data) {
+module.exports = function Optimizer(data, keepBreaks, lineBreak) {
var stripRepeats = function(selectors) {
var plain = [];
selectors = selectors.split(',');
else
return token.selector + '{' + token.body + '}';
})
- .join('');
+ .join(keepBreaks ? lineBreak : '');
};
return {
context.cursor = nextEnd + 1;
} else {
nextEnd = data.indexOf('{', nextSpecial + 1);
- var block = data.substring(context.cursor, nextEnd);
+ var block = data.substring(context.cursor, nextEnd).trim();
var isFlat = fragment.indexOf('@font-face') === 0;
oldMode = context.mode;
context.cursor = nextEnd + 2;
} else if (what == 'bodyStart') {
- var selector = data.substring(context.cursor, nextSpecial);
+ var selector = data.substring(context.cursor, nextSpecial).trim();
oldMode = context.mode;
context.cursor = nextSpecial + 1;
'line breaks': cssContext({
'line breaks': [
'div\na\r\n{width:500px}',
- 'div' + lineBreak + 'a' + lineBreak + '{width:500px}'
+ 'div a{width:500px}'
],
'line breaks #2': [
'div\na\r\n,p{width:500px}',
- 'div' + lineBreak + 'a' + lineBreak + ',p{width:500px}'
+ 'div a,p{width:500px}'
],
'multiple line breaks #2': [
'div \r\n\r\na\r\n,p{width:500px}',
- 'div' + lineBreak + 'a' + lineBreak + ',p{width:500px}'
+ 'div a,p{width:500px}'
],
'line breaks with whitespace lines': [
'div \n \t\n \na\r\n, p { width:500px }',
- 'div' + lineBreak + 'a' + lineBreak + ',p{width:500px}'
+ 'div a,p{width:500px}'
+ ],
+ 'line breaks with multiple selectors': [
+ 'p{width:500px}a{color:red}span{font-style:italic}',
+ 'p{width:500px}' + lineBreak + 'a{color:red}' + lineBreak + 'span{font-style:italic}'
],
'charset not at beginning': [
"a{ color: #f10; }\n@charset 'utf-8';\nb { font-weight: bolder}",