From: Jakub Pawlowicz Date: Mon, 10 Feb 2014 21:53:36 +0000 (+0000) Subject: Fixes #235 - adds IE7 compatibility mode. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=9ae2050df2e3682366a87363a600989ac7d03727;p=clean-css.git Fixes #235 - adds IE7 compatibility mode. :focus, :after, and :before selectors are not supported in IE7 so we can't merge selectors using them. --- diff --git a/History.md b/History.md index 3aa02c6f..9d4701ed 100644 --- a/History.md +++ b/History.md @@ -21,6 +21,7 @@ * Fixed issue [#226](https://github.com/GoalSmashers/clean-css/issues/226) - don't minify border:none to border:0. * Fixed issue [#229](https://github.com/GoalSmashers/clean-css/issues/229) - improved processing of fraction numbers. * Fixed issue [#230](https://github.com/GoalSmashers/clean-css/issues/230) - better handling of zero values. +* Fixed issue [#235](https://github.com/GoalSmashers/clean-css/issues/235) - IE7 compatibility mode. * Fixed issue [#236](https://github.com/GoalSmashers/clean-css/issues/236) - incorrect rebasing with nested `import`s. [2.0.8 / 2014-02-07](https://github.com/GoalSmashers/clean-css/compare/v2.0.7...v2.0.8) diff --git a/README.md b/README.md index 3846d1eb..8a616ec7 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ cleancss [options] --skip-advanced Disable advanced optimizations - selector & property merging, reduction, etc. --selectors-merge-mode [ie8|*] DEPRECATED: Use --compatibility switch --c, --compatibility [ie8] Force compatibility mode +-c, --compatibility [ie7|ie8] Force compatibility mode -d, --debug Shows debug information (minification time & compression efficiency) ``` @@ -149,7 +149,7 @@ First clone the source, then run: 1. Fork it. 2. Add test(s) veryfying the problem. 3. Fix the problem. -4. Make sure all tests still pass (`npm test`). +4. Make sure all tests still pass (`npm test`). 5. Make sure your code doesn't break style rules (`npm run check`). 6. Send a PR. diff --git a/bin/cleancss b/bin/cleancss index c5f80dbc..a093926e 100755 --- a/bin/cleancss +++ b/bin/cleancss @@ -27,7 +27,7 @@ commands .option('--skip-rebase', 'Disable URLs rebasing') .option('--skip-advanced', 'Disable advanced optimizations - selector & property merging, reduction, etc.') .option('--selectors-merge-mode [ie8|*]', 'DEPRECATED: Use --compatibility switch') - .option('-c, --compatibility [ie8]', 'Force compatibility mode') + .option('-c, --compatibility [ie7|ie8]', 'Force compatibility mode') .option('-t, --timeout [seconds]', 'Per connection timeout when fetching remote @imports (defaults to 5 seconds)') .option('-d, --debug', 'Shows debug information (minification time & compression efficiency)'); diff --git a/lib/clean.js b/lib/clean.js index e977ef0f..24b84c3c 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -281,7 +281,7 @@ var minify = function(data, callback) { // zero + unit to zero var units = ['px', 'em', 'ex', 'cm', 'mm', 'in', 'pt', 'pc', '%']; - if ('ie8' != options.compatibility) + if (['ie7', 'ie8'].indexOf(options.compatibility) == -1) units.push('rem'); replace(new RegExp('(\\s|:|,)\\-?0(?:' + units.join('|') + ')', 'g'), '$1' + '0'); @@ -336,10 +336,13 @@ var minify = function(data, callback) { replace(/\}/g, '}' + lineBreak); } else { replace(function optimizeSelectors() { + var mergeMode = ['ie7', 'ie8'].indexOf(options.compatibility) > -1 ? + options.compatibility : + '*'; data = new SelectorsOptimizer(data, context, { keepBreaks: options.keepBreaks, lineBreak: lineBreak, - selectorsMergeMode: options.compatibility == 'ie8' ? 'ie8' : '*' + selectorsMergeMode: mergeMode }).process(); }); } diff --git a/lib/selectors/optimizer.js b/lib/selectors/optimizer.js index 3fbef0d3..38950fae 100644 --- a/lib/selectors/optimizer.js +++ b/lib/selectors/optimizer.js @@ -4,7 +4,8 @@ var PropertyOptimizer = require('../properties/optimizer'); module.exports = function Optimizer(data, context, options) { var specialSelectors = { '*': /\-(moz|ms|o|webkit)\-/, - 'ie8': /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:not|:target|:visited|:empty|:first\-of|:last|:nth|:only|:root)/ + 'ie8': /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:not|:target|:visited|:empty|:first\-of|:last|:nth|:only|:root)/, + 'ie7': /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:not|:target|:visited|:empty|:first\-of|:last|:nth|:only|:root|:after|:before|:focus)/ }; var minificationsMade = []; diff --git a/test/unit-test.js b/test/unit-test.js index 3054c242..c238eb35 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -1455,6 +1455,14 @@ title']{display:block}", 'of supported and unsupported selector': '.one:first-child{color:red}.two:last-child{color:red}', 'of two unsupported selectors': '.one:nth-child(5){color:red}.two:last-child{color:red}' }, { compatibility: 'ie8' }), + 'same bodies - IE7 compat': cssContext({ + 'of two supported selectors': [ + '.one{color:red}.two>.three{color:red}', + '.one,.two>.three{color:red}' + ], + 'of supported and unsupported selector': '.one{color:red}.two:last-child{color:red}', + 'of two unsupported selectors': '.one:before{color:red}.two:last-child{color:red}' + }, { compatibility: 'ie7' }), 'redefined more granular properties': redefineContext({ 'animation-delay': ['animation'], 'animation-direction': ['animation'],