From: Jakub Pawlowicz Date: Sun, 1 Mar 2015 09:36:19 +0000 (+0000) Subject: Refixes #471 - correct order after restructuring. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=21080b94ed0ee458db760edce44d0c273af37346;p=clean-css.git Refixes #471 - correct order after restructuring. Apparently multiple important comments were not factored in. --- diff --git a/History.md b/History.md index 4aabe32d..e3b51cb0 100644 --- a/History.md +++ b/History.md @@ -3,6 +3,11 @@ * Fixed issue [#396](https://github.com/jakubpawlowicz/clean-css/issues/396) - better input source maps tracking. +[3.1.2 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.1.1...3.1) +================== + +* Refixed issue [#471](https://github.com/jakubpawlowicz/clean-css/issues/471) - correct order after restructuring. + [3.1.1 / 2015-02-27](https://github.com/jakubpawlowicz/clean-css/compare/v3.1.0...v3.1.1) ================== diff --git a/lib/selectors/optimizers/advanced.js b/lib/selectors/optimizers/advanced.js index 67ad133e..030ee9fc 100644 --- a/lib/selectors/optimizers/advanced.js +++ b/lib/selectors/optimizers/advanced.js @@ -632,15 +632,11 @@ AdvancedOptimizer.prototype.restructure = function (tokens) { } } - var position = 0; - var isCharsetFirst = tokens[0] && tokens[0].kind == 'at-rule' && tokens[0].value.indexOf('@charset') === 0; - var isCommentFirst = !isCharsetFirst && tokens[0] && tokens[0].kind == 'text' && tokens[0].value.indexOf('__ESCAPED_COMMENT_SPECIAL') === 0; - var isCommentSecond = isCharsetFirst && tokens[1] && tokens[1].kind == 'text' && tokens[1].value.indexOf('__ESCAPED_COMMENT_SPECIAL') === 0; - - if (isCharsetFirst || isCommentFirst) - position = 1; - if (isCommentSecond) - position = 2; + var position = tokens[0] && tokens[0].kind == 'at-rule' && tokens[0].value.indexOf('@charset') === 0 ? 1 : 0; + for (; position < tokens.length - 1; position++) { + if (!tokens[position] || tokens[position].kind != 'text' || tokens[position].value.indexOf('__ESCAPED_COMMENT_SPECIAL') !== 0) + break; + } for (i = 0; i < movedProperties.length; i++) { dropPropertiesAt(position, movedProperties[i]); diff --git a/test/selectors/optimizer-test.js b/test/selectors/optimizer-test.js index 2fa55905..70937361 100644 --- a/test/selectors/optimizer-test.js +++ b/test/selectors/optimizer-test.js @@ -189,10 +189,14 @@ vows.describe(SelectorsOptimizer) '@-moz-keyframes test{0%{transform:scale3d(1,1,1);opacity:1}100%{transform:scale3d(.5,.5,.5);opacity:1}}', '@-moz-keyframes test{0%{transform:scale3d(1,1,1);opacity:1}100%{transform:scale3d(.5,.5,.5);opacity:1}}' ], - 'with important comment': [ + 'with one important comment': [ '__ESCAPED_COMMENT_SPECIAL_CLEAN_CSS0__a{width:100px}div{color:red}.one{display:block}.two{display:inline;color:red}', '__ESCAPED_COMMENT_SPECIAL_CLEAN_CSS0__.two,div{color:red}a{width:100px}.one{display:block}.two{display:inline}' ], + 'with many important comments': [ + '__ESCAPED_COMMENT_SPECIAL_CLEAN_CSS0____ESCAPED_COMMENT_SPECIAL_CLEAN_CSS1__a{width:100px}div{color:red}.one{display:block}.two{display:inline;color:red}', + '__ESCAPED_COMMENT_SPECIAL_CLEAN_CSS0____ESCAPED_COMMENT_SPECIAL_CLEAN_CSS1__.two,div{color:red}a{width:100px}.one{display:block}.two{display:inline}' + ], 'with important comment and charset': [ '@charset "utf-8";__ESCAPED_COMMENT_SPECIAL_CLEAN_CSS0__a{width:100px}div{color:red}.one{display:block}.two{display:inline;color:red}', '@charset "utf-8";__ESCAPED_COMMENT_SPECIAL_CLEAN_CSS0__.two,div{color:red}a{width:100px}.one{display:block}.two{display:inline}'