* Adds supports for removing empty nested @media elements.
==================
* Adds simplified and more advanced text escaping / restoring via `EscapeStore` class.
+* Adds simplified and much faster empty elements removal.
1.1.6 / 2013-10-26
==================
var ShorthandNotations = require('./properties/shorthand-notations');
var ImportInliner = require('./imports/inliner');
var UrlRebase = require('./images/url-rebase');
+var EmptyRemoval = require('./selectors/empty-removal');
var CommentsProcessor = require('./text/comments');
var ExpressionsProcessor = require('./text/expressions');
});
if (options.removeEmpty) {
- // empty elements
- replace(/[^\{\}]+\{\}/g, '');
-
- // empty @media declarations
- replace(/@media [^\{]+\{\}/g, '');
+ replace(function removeEmptySelectors() {
+ data = new EmptyRemoval(data).process();
+ });
}
// trim spaces at beginning and end
--- /dev/null
+module.exports = function EmptyRemoval(data) {
+ var stripEmpty = function(cssData) {
+ var tempData = [];
+ var nextEmpty = 0;
+ var cursor = 0;
+
+ for (; nextEmpty < cssData.length; ) {
+ nextEmpty = cssData.indexOf('{}', cursor);
+ if (nextEmpty == -1)
+ break;
+
+ var startsAt = nextEmpty - 1;
+ while (cssData[startsAt] && cssData[startsAt] != '}' && cssData[startsAt] != '{')
+ startsAt--;
+
+ tempData.push(cssData.substring(cursor, startsAt + 1));
+ cursor = nextEmpty + 2;
+ }
+
+ return tempData.length > 0 ?
+ stripEmpty(tempData.join('') + cssData.substring(cursor, cssData.length)) :
+ cssData;
+ };
+
+ return {
+ process: function() {
+ return stripEmpty(data);
+ }
+ };
+};
"@media screen { .test {} } .test1 { color: green; }",
".test1{color:green}"
],
+ 'inside nested @media': [
+ '@media screen { @media (orientation:landscape) { @media (max-width:999px) { .test {} } } }',
+ ''
+ ],
'inside not empty @media': [
"@media screen { .test {} .some { display:none } }",
"@media screen{.some{display:none}}"
+ ],
+ 'inside nested not empty @media': [
+ '@media screen { @media (orientation:landscape) { @media (max-width:999px) { .test {} } a {color:red} } }',
+ '@media screen{@media (orientation:landscape){a{color:red}}}'
]
}, { removeEmpty: true }),
'empty @media': cssContext({