From: Jakub Pawlowicz Date: Fri, 28 Mar 2014 18:30:36 +0000 (+0000) Subject: Fixes #267 - incorrect non-adjacent selector merging. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=60746616d21af126fd2c6fa8e264ccffdd600053;p=clean-css.git Fixes #267 - incorrect non-adjacent selector merging. --- diff --git a/History.md b/History.md index 76c8ce6b..fb50ebe0 100644 --- a/History.md +++ b/History.md @@ -13,6 +13,11 @@ * 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) ================== diff --git a/lib/selectors/optimizer.js b/lib/selectors/optimizer.js index 0838e96e..25f1c310 100644 --- a/lib/selectors/optimizer.js +++ b/lib/selectors/optimizer.js @@ -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; } diff --git a/test/unit-test.js b/test/unit-test.js index 6fe1eeb9..1501a2f0 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -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': [