Fixes #235 - adds IE7 compatibility mode.
authorJakub Pawlowicz <jakub@goalsmashers.com>
Mon, 10 Feb 2014 21:53:36 +0000 (21:53 +0000)
committerJakub Pawlowicz <jakub@goalsmashers.com>
Mon, 10 Feb 2014 21:53:36 +0000 (21:53 +0000)
:focus, :after, and :before selectors are not supported in IE7 so we can't
merge selectors using them.

History.md
README.md
bin/cleancss
lib/clean.js
lib/selectors/optimizer.js
test/unit-test.js

index 3aa02c6..9d4701e 100644 (file)
@@ -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)
index 3846d1e..8a616ec 100644 (file)
--- a/README.md
+++ b/README.md
@@ -72,7 +72,7 @@ cleancss [options] <source-file>
 --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.
 
index c5f80db..a093926 100755 (executable)
@@ -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)');
 
index e977ef0..24b84c3 100644 (file)
@@ -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();
     });
   }
index 3fbef0d..38950fa 100644 (file)
@@ -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 = [];
index 3054c24..c238eb3 100644 (file)
@@ -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'],