Fixes #267 - incorrect non-adjacent selector merging.
authorJakub Pawlowicz <jakub@goalsmashers.com>
Fri, 28 Mar 2014 18:30:36 +0000 (18:30 +0000)
committerJakub Pawlowicz <jakub@goalsmashers.com>
Fri, 28 Mar 2014 19:10:42 +0000 (19:10 +0000)
History.md
lib/selectors/optimizer.js
test/unit-test.js

index 76c8ce6..fb50ebe 100644 (file)
 * Fixed issue [#247](https://github.com/GoalSmashers/clean-css/issues/247) - removes deprecated `selectorsMergeMode` switch.
 * Refixed issue [#250](https://github.com/GoalSmashers/clean-css/issues/250) - based on new quotation marks removal.
 
+[2.1.8 / 2014-xx-xx (UNRELEASED)](https://github.com/GoalSmashers/clean-css/compare/v2.1.7...v2.1.8)
+==================
+
+* Fixed issue [#267](https://github.com/GoalSmashers/clean-css/issues/267) - incorrect non-adjacent selector merging.
+
 [2.1.7 / 2014-03-24](https://github.com/GoalSmashers/clean-css/compare/v2.1.6...v2.1.7)
 ==================
 
index 0838e96..25f1c31 100644 (file)
@@ -233,6 +233,7 @@ module.exports = function Optimizer(data, context, options) {
   var _reduceSelector = function(tokens, selector, data, options) {
     var bodies = [];
     var joinsAt = [];
+    var splitBodies = [];
     var processedTokens = [];
 
     for (var j = data.length - 1, m = 0; j >= 0; j--) {
@@ -243,12 +244,13 @@ module.exports = function Optimizer(data, context, options) {
       var token = tokens[where];
       var body = token.body;
       bodies.push(body);
+      splitBodies.push(body.split(';'));
       processedTokens.push(where);
     }
 
     for (j = 0, m = bodies.length; j < m; j++) {
       if (bodies[j].length > 0)
-        joinsAt.push((joinsAt[j - 1] || 0) + bodies[j].split(';').length);
+        joinsAt.push((joinsAt[j - 1] || 0) + splitBodies[j].length);
     }
 
     var optimizedBody = propertyOptimizer.process(bodies.join(';'), joinsAt, true);
@@ -259,7 +261,7 @@ module.exports = function Optimizer(data, context, options) {
     var tokenIdx = processedCount - 1;
 
     while (tokenIdx >= 0) {
-      if ((tokenIdx === 0 || bodies[tokenIdx].indexOf(optimizedProperties[propertyIdx]) > -1) && propertyIdx > -1) {
+      if ((tokenIdx === 0 || splitBodies[tokenIdx].indexOf(optimizedProperties[propertyIdx]) > -1) && propertyIdx > -1) {
         propertyIdx--;
         continue;
       }
index 6fe1eeb..1501a2f 100644 (file)
@@ -1485,7 +1485,8 @@ title']{display:block}",
     'when same browser specific selector more than once': [
       'a,::-moz-selection{color:red}p{display:block}a,::-moz-selection{color:#fff}',
       'p{display:block}::-moz-selection,a{color:#fff}'
-    ]
+    ],
+    'with full property comparison': '.one{height:7rem}.two{height:auto}.one{line-height:7rem;color:red}'
   }),
   'rerun optimizers': cssContext({
     'selectors reducible once': [