Refixes #471 - correct order after restructuring.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 1 Mar 2015 09:36:19 +0000 (09:36 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 1 Mar 2015 18:07:42 +0000 (18:07 +0000)
Apparently multiple important comments were not factored in.

History.md
lib/selectors/optimizers/advanced.js
test/selectors/optimizer-test.js

index 4aabe32..e3b51cb 100644 (file)
@@ -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)
 ==================
 
index 67ad133..030ee9f 100644 (file)
@@ -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]);
index 2fa5590..7093736 100644 (file)
@@ -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}'