originalReplace(pattern, replacement);
var itTook = process.hrtime(start);
- console.log('%d ms: ' + name, 1000 * itTook[0] + itTook[1] / 1000000.0);
+ console.log('%d ms: ' + name, 1000 * itTook[0] + itTook[1] / 1000000);
};
}
});
// replace all escaped line breaks
- replace(/\\(\r\n|\n)/mg, '');
+ replace(/\\(\r\n|\n)/gm, '');
// strip parentheses in urls if possible (no spaces inside)
replace(/url\((['"])([^\)]+)['"]\)/g, function(match, quote, url) {
return UrlRewriter.process(data, rebaseOpts);
};
- return {
- process: process
- };
+ return { process: process };
};
var nextEnd = 0;
var cursor = 0;
- for (; nextEnd < data.length; ) {
+ for (; nextEnd < data.length;) {
nextStart = data.indexOf('url(', nextEnd);
if (nextStart == -1)
break;
options._baseRelativeTo = options._baseRelativeTo || options.relativeTo;
options.visited = options.visited || [];
- for (; nextEnd < data.length; ) {
+ for (; nextEnd < data.length;) {
nextStart = data.indexOf('@import', cursor);
if (nextStart == -1)
break;
inlinedData;
};
- return {
- // Inlines all imports taking care of repetitions, unknown files, and circular dependencies
- process: process
- };
+ // Inlines all imports taking care of repetitions, unknown files, and circular dependencies
+ return { process: process };
};
var nextEmpty = 0;
var cursor = 0;
- for (; nextEmpty < cssData.length; ) {
+ for (; nextEmpty < cssData.length;) {
nextEmpty = cssData.indexOf('{}', cursor);
if (nextEmpty == -1)
break;
var forRemoval = [];
for (var i = 0, l = tokens.length; i < l; i++) {
- if (typeof(tokens[i]) == 'string' || tokens[i].block)
+ if (typeof tokens[i] == 'string' || tokens[i].block)
continue;
var selector = tokens[i].selector;
}
}
- forRemoval = forRemoval.sort(function(a, b) { return a > b ? 1 : -1; });
+ forRemoval = forRemoval.sort(function(a, b) {
+ return a > b ? 1 : -1;
+ });
for (var j = 0, n = forRemoval.length; j < n; j++) {
tokens.splice(forRemoval[j] - j, 1);
}
for (var i = 0, l = tokens.length; i < l; i++) {
var token = tokens[i];
- if (typeof(token) == 'string' || token.block)
+ if (typeof token == 'string' || token.block)
continue;
if (token.selector == lastToken.selector) {
token = tokens[i];
selector = token.selector;
- if (typeof(token) == 'string' || token.block)
+ if (typeof token == 'string' || token.block)
continue;
selectors = selector.split(',');
var currentMatch = matchPositions.length - 1;
while (currentMatch >= 0) {
- if (bodies[currentMatch].indexOf(optimizedTokens[k]) > - 1) {
+ if (bodies[currentMatch].indexOf(optimizedTokens[k]) > -1) {
k -= 1;
continue;
}
};
var optimize = function(tokens) {
- tokens = (Array.isArray(tokens) ? tokens : [tokens]);
+ tokens = Array.isArray(tokens) ? tokens : [tokens];
for (var i = 0, l = tokens.length; i < l; i++) {
var token = tokens[i];
var nextEnd = 0;
var cursor = 0;
- for (; nextEnd < data.length; ) {
+ for (; nextEnd < data.length;) {
nextStart = data.indexOf('/*', nextEnd);
nextEnd = data.indexOf('*/', nextStart + 2);
if (nextStart == -1 || nextEnd == -1)
var level = 0;
var quoted = false;
- while(true) {
+ while (true) {
var next = data[end++];
if (quoted) {
var cursor = 0;
var tempData = [];
- for (; nextEnd < data.length; ) {
+ for (; nextEnd < data.length;) {
nextStart = data.indexOf('expression(', nextEnd);
if (nextStart == -1)
break;
var doubleParenthesis = '"';
var dataLength = data.length;
- for (; nextEnd < data.length; ) {
+ for (; nextEnd < data.length;) {
var nextStartSingle = data.indexOf(singleParenthesis, nextEnd + 1);
var nextStartDouble = data.indexOf(doubleParenthesis, nextEnd + 1);
var cursor = 0;
var tempData = [];
- for (; nextEnd < data.length; ) {
+ for (; nextEnd < data.length;) {
nextStart = data.indexOf('url(', nextEnd);
if (nextStart == -1)
break;
new CleanCSS({ benchmark: true, root: benchDir }).minify(cssData);
var itTook = process.hrtime(start);
-console.log('complete minification: %d ms', 1000 * itTook[0] + itTook[1] / 1000000.0);
+console.log('complete minification: %d ms', 1000 * itTook[0] + itTook[1] / 1000000);
},
'warnings': {
topic: function() {
- var minifier = new CleanCSS({ root: 'test/data', target: 'custom-warnings.css' });
+ var minifier = new CleanCSS({
+ root: 'test/data',
+ target: 'custom-warnings.css'
+ });
minifier.minify('a{color:red}');
return minifier;
},
assert.equal(minifier.errors.length, 1);
assert.equal(minifier.errors[0], 'Broken @import declaration of "/some/fake/file"');
}
- },
+ }
}).export(module);
'@media\nonly screen and (max-width: 1319px) and (min--moz-device-pixel-ratio: 1.5),\nonly screen and (max-width: 1319px) and (-moz-min-device-pixel-ratio: 1.5)\n{ a { color:#000 } }',
'@media only screen and (max-width:1319px) and (min--moz-device-pixel-ratio:1.5),only screen and (max-width:1319px) and (-moz-min-device-pixel-ratio:1.5){a{color:#000}}'
],
- 'in content preceded by #content': '#content{display:block}#foo{content:"\00BB "}',
- 'in content preceded by .content': '.content{display:block}#foo{content:"\00BB "}',
+ 'in content preceded by #content': '#content{display:block}#foo{content:"\0BB "}',
+ 'in content preceded by .content': '.content{display:block}#foo{content:"\0BB "}',
'in content preceded by line break': [
'.content{display:block}#foo{' + lineBreak + 'content:"x"}',
'.content{display:block}#foo{content:"x"}'
'@import url(/test/data/partials-relative/base.css);',
'a{background:url(/test/data/partials/extra/down.gif) 0 0 no-repeat}'
]
- }, { root: process.cwd(), relativeTo: path.join('test', 'data', 'partials-relative') }),
+ }, {
+ root: process.cwd(),
+ relativeTo: path.join('test', 'data', 'partials-relative')
+ }),
'urls rewriting - no root but target': cssContext({
'no @import': [
'a{background:url(../partials/extra/down.gif) 0 0 no-repeat}',
'@import url(/test/data/partials-relative/base.css);',
'a{background:url(test/data/partials/extra/down.gif) 0 0 no-repeat}'
]
- }, { target: path.join(process.cwd(), 'test.css'), relativeTo: path.join('test', 'data', 'partials-relative') }),
+ }, {
+ target: path.join(process.cwd(), 'test.css'),
+ relativeTo: path.join('test', 'data', 'partials-relative')
+ }),
'urls rewriting - root and target': cssContext({
'no @import': [
'a{background:url(../partials/extra/down.gif) 0 0 no-repeat}',
'@import url(/test/data/partials-relative/base.css);',
'a{background:url(/test/data/partials/extra/down.gif) 0 0 no-repeat}'
]
- }, { root: process.cwd(), target: path.join(process.cwd(), 'test.css'), relativeTo: path.join('test', 'data', 'partials-relative') }),
+ }, {
+ root: process.cwd(),
+ target: path.join(process.cwd(), 'test.css'),
+ relativeTo: path.join('test', 'data', 'partials-relative')
+ }),
'fonts': cssContext({
'keep format quotation': "@font-face{font-family:PublicVintage;src:url(/PublicVintage.otf) format('opentype')}",
'remove font family quotation': [
'.one,.two{color:red;line-height:1em}'
],
'two adjacent with hex color definitions': [
- "a:link,a:visited{color:#fff}.one{display:block}a:link,a:visited{color:red}",
- ".one{display:block}a:link,a:visited{color:red}"
+ 'a:link,a:visited{color:#fff}.one{display:block}a:link,a:visited{color:red}',
+ '.one{display:block}a:link,a:visited{color:red}'
]
}),
'same non-adjacent selectors': cssContext({