From ac7473d3f256cecceaa812983a9e175cd08b3d64 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Thu, 27 Aug 2015 07:37:29 +0100 Subject: [PATCH] Fixes removing unused items. Items should be removed by position as it is not guaranteed that there are no comments somewhere in between. Affects both modes - source maps on & off. --- lib/properties/remove-unused.js | 6 ++++-- test/properties/remove-unused-test.js | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/properties/remove-unused.js b/lib/properties/remove-unused.js index 9d8cf644..08cb9b6a 100644 --- a/lib/properties/remove-unused.js +++ b/lib/properties/remove-unused.js @@ -1,7 +1,9 @@ function removeUnused(properties) { for (var i = properties.length - 1; i >= 0; i--) { - if (properties[i].unused) - properties[i].all.splice(i, 1); + var property = properties[i]; + + if (property.unused) + property.all.splice(property.position, 1); } } diff --git a/test/properties/remove-unused-test.js b/test/properties/remove-unused-test.js index 59dbd7b3..82ab47cc 100644 --- a/test/properties/remove-unused-test.js +++ b/test/properties/remove-unused-test.js @@ -22,6 +22,25 @@ vows.describe(removeUnused) assert.lengthOf(properties, 1); assert.equal(properties[0][0], 'color'); } + }, + 'it respects comments': { + 'topic': function () { + var properties = [ + [['background'], ['none']], + '__ESCAPED_COMMENT_CLEAN_CSS0__', + [['color'], ['red']] + ]; + var _properties = wrapForOptimizing(properties); + _properties[1].unused = true; + + removeUnused(_properties); + return properties; + }, + 'it has one property left': function (properties) { + assert.lengthOf(properties, 2); + assert.equal(properties[0][0], 'background'); + assert.equal(properties[1], '__ESCAPED_COMMENT_CLEAN_CSS0__'); + } } }) .export(module); -- 2.34.1