From: Jakub Pawlowicz Date: Mon, 25 Jul 2016 04:28:28 +0000 (+0200) Subject: Fixes #795 - `!important` and override compacting. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=992ca494555faae9c19f2e05d5956b46add4c277;p=clean-css.git Fixes #795 - `!important` and override compacting. There was a broken test rule which didn't catch the bug, which is now fixed. --- diff --git a/History.md b/History.md index 2cc3eb78..543a8f51 100644 --- a/History.md +++ b/History.md @@ -3,6 +3,11 @@ * Requires Node.js 4.0+ to run. +[3.4.19 / 2016-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.18...3.4) +================== + +* Fixed issue [#795](https://github.com/jakubpawlowicz/clean-css/issues/795) - `!important` and override compacting. + [3.4.18 / 2016-06-15](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.17...v3.4.18) ================== diff --git a/lib/properties/override-compactor.js b/lib/properties/override-compactor.js index 3028bfc4..bbf13ed3 100644 --- a/lib/properties/override-compactor.js +++ b/lib/properties/override-compactor.js @@ -273,6 +273,11 @@ function compactOverrides(properties, compatibility, validator) { if (right.important && !left.important) continue; + if (!right.important && left.important) { + right.unused = true; + continue; + } + // Pending more clever algorithm in #527 if (moreSameShorthands(properties, i - 1, left.name)) continue; diff --git a/test/properties/override-compacting-test.js b/test/properties/override-compacting-test.js index 1e039c26..d9bafaef 100644 --- a/test/properties/override-compacting-test.js +++ b/test/properties/override-compacting-test.js @@ -142,10 +142,10 @@ vows.describe(optimize) } }, 'shorthand then longhand - important then non-important': { - 'topic': 'p{background:__ESCAPED_URL_CLEAN_CSS0__ repeat!important;background-repeat:no-repeat}', + 'topic': 'p{background:__ESCAPED_URL_CLEAN_CSS0__ repeat-x!important;background-repeat:no-repeat}', 'into': function (topic) { assert.deepEqual(_optimize(topic), [ - [['background'], ['__ESCAPED_URL_CLEAN_CSS0__'], ['no-repeat!important']] + [['background'], ['__ESCAPED_URL_CLEAN_CSS0__'], ['repeat-x!important']] ]); } }, @@ -713,6 +713,16 @@ vows.describe(optimize) } } }) + .addBatch({ + 'padding !important then not !important': { + 'topic': 'a{padding:0!important;padding-left:3px}', + 'into': function (topic) { + assert.deepEqual(_optimize(topic), [ + [['padding'], ['0!important']] + ]); + } + } + }) .addBatch({ 'overriding !important by a star hack': { 'topic': 'a{color:red!important;display:block;*color:#fff}',