From 9256c696f91b460319005042bb9448dd46d3a238 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Fri, 8 Nov 2013 18:39:54 +0200 Subject: [PATCH] Minor style changes. --- lib/clean.js | 4 ++-- lib/images/url-rebase.js | 4 +--- lib/images/url-rewriter.js | 2 +- lib/imports/inliner.js | 8 +++----- lib/selectors/empty-removal.js | 2 +- lib/selectors/optimizer.js | 14 ++++++++------ lib/text/comments.js | 2 +- lib/text/expressions.js | 4 ++-- lib/text/free.js | 2 +- lib/text/urls.js | 2 +- test/bench.js | 2 +- test/module-test.js | 7 +++++-- test/unit-test.js | 24 +++++++++++++++++------- 13 files changed, 44 insertions(+), 33 deletions(-) diff --git a/lib/clean.js b/lib/clean.js index af9c7e04..9b1f4ffc 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -63,7 +63,7 @@ module.exports = function(options) { 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); }; } @@ -92,7 +92,7 @@ module.exports = function(options) { }); // 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) { diff --git a/lib/images/url-rebase.js b/lib/images/url-rebase.js index 5b249544..8d5c59b6 100644 --- a/lib/images/url-rebase.js +++ b/lib/images/url-rebase.js @@ -28,7 +28,5 @@ module.exports = function UrlRebase(options, context) { return UrlRewriter.process(data, rebaseOpts); }; - return { - process: process - }; + return { process: process }; }; diff --git a/lib/images/url-rewriter.js b/lib/images/url-rewriter.js index b41056fd..14df441e 100644 --- a/lib/images/url-rewriter.js +++ b/lib/images/url-rewriter.js @@ -7,7 +7,7 @@ module.exports = { var nextEnd = 0; var cursor = 0; - for (; nextEnd < data.length; ) { + for (; nextEnd < data.length;) { nextStart = data.indexOf('url(', nextEnd); if (nextStart == -1) break; diff --git a/lib/imports/inliner.js b/lib/imports/inliner.js index f0c793ae..acd5d71c 100644 --- a/lib/imports/inliner.js +++ b/lib/imports/inliner.js @@ -15,7 +15,7 @@ module.exports = function Inliner(context) { 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; @@ -137,8 +137,6 @@ module.exports = function Inliner(context) { 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 }; }; diff --git a/lib/selectors/empty-removal.js b/lib/selectors/empty-removal.js index ee193c16..7af188d4 100644 --- a/lib/selectors/empty-removal.js +++ b/lib/selectors/empty-removal.js @@ -4,7 +4,7 @@ module.exports = function EmptyRemoval(data) { var nextEmpty = 0; var cursor = 0; - for (; nextEmpty < cssData.length; ) { + for (; nextEmpty < cssData.length;) { nextEmpty = cssData.indexOf('{}', cursor); if (nextEmpty == -1) break; diff --git a/lib/selectors/optimizer.js b/lib/selectors/optimizer.js index 2d406d70..8a344e9f 100644 --- a/lib/selectors/optimizer.js +++ b/lib/selectors/optimizer.js @@ -32,7 +32,7 @@ module.exports = function Optimizer(data, options) { 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; @@ -48,7 +48,9 @@ module.exports = function Optimizer(data, options) { } } - 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); } @@ -61,7 +63,7 @@ module.exports = function Optimizer(data, options) { 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) { @@ -94,7 +96,7 @@ module.exports = function Optimizer(data, options) { token = tokens[i]; selector = token.selector; - if (typeof(token) == 'string' || token.block) + if (typeof token == 'string' || token.block) continue; selectors = selector.split(','); @@ -131,7 +133,7 @@ module.exports = function Optimizer(data, options) { 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; } @@ -180,7 +182,7 @@ module.exports = function Optimizer(data, options) { }; 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]; diff --git a/lib/text/comments.js b/lib/text/comments.js index 5667e7ec..8aa7d3c3 100644 --- a/lib/text/comments.js +++ b/lib/text/comments.js @@ -13,7 +13,7 @@ module.exports = function Comments(keepSpecialComments, keepBreaks, lineBreak) { 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) diff --git a/lib/text/expressions.js b/lib/text/expressions.js index 2ca193bc..da1f52e3 100644 --- a/lib/text/expressions.js +++ b/lib/text/expressions.js @@ -8,7 +8,7 @@ module.exports = function Expressions() { var level = 0; var quoted = false; - while(true) { + while (true) { var next = data[end++]; if (quoted) { @@ -43,7 +43,7 @@ module.exports = function Expressions() { var cursor = 0; var tempData = []; - for (; nextEnd < data.length; ) { + for (; nextEnd < data.length;) { nextStart = data.indexOf('expression(', nextEnd); if (nextStart == -1) break; diff --git a/lib/text/free.js b/lib/text/free.js index 7ffee633..ea303686 100644 --- a/lib/text/free.js +++ b/lib/text/free.js @@ -33,7 +33,7 @@ module.exports = function Free() { 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); diff --git a/lib/text/urls.js b/lib/text/urls.js index 007e41d2..8f7fee8b 100644 --- a/lib/text/urls.js +++ b/lib/text/urls.js @@ -13,7 +13,7 @@ module.exports = function Urls() { var cursor = 0; var tempData = []; - for (; nextEnd < data.length; ) { + for (; nextEnd < data.length;) { nextStart = data.indexOf('url(', nextEnd); if (nextStart == -1) break; diff --git a/test/bench.js b/test/bench.js index 93e24f5b..f09e1839 100644 --- a/test/bench.js +++ b/test/bench.js @@ -13,4 +13,4 @@ var start = process.hrtime(); 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); diff --git a/test/module-test.js b/test/module-test.js index 16302e27..eac87a4b 100644 --- a/test/module-test.js +++ b/test/module-test.js @@ -52,7 +52,10 @@ vows.describe('module tests').addBatch({ }, '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; }, @@ -82,5 +85,5 @@ vows.describe('module tests').addBatch({ assert.equal(minifier.errors.length, 1); assert.equal(minifier.errors[0], 'Broken @import declaration of "/some/fake/file"'); } - }, + } }).export(module); diff --git a/test/unit-test.js b/test/unit-test.js index 76dfc4fa..9faaa436 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -171,8 +171,8 @@ vows.describe('clean-units').addBatch({ '@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"}' @@ -709,7 +709,10 @@ path")}', '@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}', @@ -723,7 +726,10 @@ path")}', '@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}', @@ -737,7 +743,11 @@ path")}', '@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': [ @@ -1192,8 +1202,8 @@ title']{display:block}", '.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({ -- 2.34.1