From: Jakub Pawlowicz Date: Thu, 2 Oct 2014 13:55:17 +0000 (+0100) Subject: Fixes rebuilding flat blocks in SelectorOptimizer. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=7026dc8b8e47b46b911242547d9cedde393ab508;p=clean-css.git Fixes rebuilding flat blocks in SelectorOptimizer. --- diff --git a/lib/selectors/optimizer.js b/lib/selectors/optimizer.js index 3e0b6b40..7b13c8af 100644 --- a/lib/selectors/optimizer.js +++ b/lib/selectors/optimizer.js @@ -9,7 +9,9 @@ function SelectorsOptimizer(options, context) { this.context = context || {}; } -function rebuild(tokens, keepBreaks) { +function rebuild(tokens, keepBreaks, isFlatBlock) { + var joinCharacter = isFlatBlock ? ';' : (keepBreaks ? lineBreak : ''); + return tokens .map(function (token) { if (typeof token === 'string') @@ -28,7 +30,7 @@ function rebuild(tokens, keepBreaks) { } }) .filter(function (value) { return value.length > 0; }) - .join(keepBreaks ? lineBreak : '') + .join(joinCharacter) .trim(); } @@ -39,7 +41,7 @@ SelectorsOptimizer.prototype.process = function (data) { if (!this.options.noAdvanced) new AdvancedOptimizer(this.options, this.context).optimize(tokens); - return rebuild(tokens, this.options.keepBreaks); + return rebuild(tokens, this.options.keepBreaks, false); }; module.exports = SelectorsOptimizer; diff --git a/lib/selectors/tokenizer.js b/lib/selectors/tokenizer.js index 357d7421..83857ca7 100644 --- a/lib/selectors/tokenizer.js +++ b/lib/selectors/tokenizer.js @@ -141,7 +141,7 @@ function tokenize(context) { context.mode = oldMode; - tokenized.push({ block: block, body: specialBody }); + tokenized.push({ block: block, body: specialBody, isFlatBlock: isFlat }); } } else if (what == 'escape') { nextEnd = chunk.indexOf('__', nextSpecial + 1); diff --git a/test/selectors/tokenizer-test.js b/test/selectors/tokenizer-test.js index 4c077357..39e77a73 100644 --- a/test/selectors/tokenizer-test.js +++ b/test/selectors/tokenizer-test.js @@ -70,19 +70,19 @@ vows.describe(Tokenizer) ], 'media query': [ '@media (min-width:980px){}', - [{ block: '@media (min-width:980px)', body: [] }] + [{ block: '@media (min-width:980px)', body: [], isFlatBlock: false }] ], 'media query with selectors': [ '@media (min-width:980px){a{color:red}}', - [{ block: '@media (min-width:980px)', body: [{ selector: ['a'], body: ['color:red'] }] }] + [{ block: '@media (min-width:980px)', body: [{ selector: ['a'], body: ['color:red'] }], isFlatBlock: false }] ], 'media query spanning more than one chunk': [ '@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}}', - [{ block: '@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)', body: [{ selector: ['a'], body: ['color:#000'] }] }] + [{ block: '@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)', body: [{ selector: ['a'], body: ['color:#000'] }], isFlatBlock: false }] ], 'font-face': [ '@font-face{font-family: fontName;font-size:12px}', - [{ block: '@font-face', body: ['font-family:fontName', 'font-size:12px'] }] + [{ block: '@font-face', body: ['font-family:fontName', 'font-size:12px'], isFlatBlock: true }] ], 'charset': [ '@charset \'utf-8\';a{color:red}',