Adds `--skip-advanced`/`noAdvanced` switch to disable advanced optimizations.
authorGoalSmashers <jakub@goalsmashers.com>
Fri, 1 Nov 2013 14:11:25 +0000 (15:11 +0100)
committerGoalSmashers <jakub@goalsmashers.com>
Sun, 3 Nov 2013 08:49:23 +0000 (09:49 +0100)
History.md
README.md
bin/cleancss
lib/clean.js
test/binary-test.js
test/unit-test.js

index d4c3448..d87ea81 100644 (file)
@@ -15,6 +15,7 @@
 * Makes all multiple selectors ordered alphabetically (aids merging).
 * Adds property overriding so more coarse properties override more granular ones.
 * Adds reducing non-adjacent selectors.
+* Adds `--skip-advanced`/`noAdvanced` switch to disable advanced optimizations.
 
 1.1.7 / 2013-10-28
 ==================
index c3b3158..fc66c27 100644 (file)
--- a/README.md
+++ b/README.md
@@ -43,6 +43,7 @@ cleancss [options] <source-file>
 -o, --output [output-file]      Use [output-file] as output instead of STDOUT
 -s, --skip-import               Disable @import processing
 --skip-rebase                   Disable URLs rebasing
+--skip-advanced                 Disable advanced optimizations - selector & property merging, reduction, etc.
 --selectors-merge-mode [ie8|*]  Use `ie8` for compatibility mode, `*` for merge all (default).
 -d, --debug                     Shows debug information (minification time & compression efficiency)
 ```
@@ -99,6 +100,7 @@ Process method accepts a hash as a second parameter, i.e.,
 * `relativeTo` - path with which to resolve relative `@import` rules and URLs
 * `processImport` - whether to process `@import` rules
 * `noRebase` - whether to skip URLs rebasing
+* `noAdvanced` - set to true to disable advanced optimizations - selector & property merging, reduction, etc.
 * `selectorsMergeMode` - `ie8` for IE8 compatibility mode, `*` for merging all (default)
 
 ### What are the clean-css' dev commands?
index 7a5aae4..068082c 100755 (executable)
@@ -23,6 +23,7 @@ commands
   .option('-o, --output [output-file]', 'Use [output-file] as output instead of STDOUT')
   .option('-s, --skip-import', 'Disable @import processing')
   .option('--skip-rebase', 'Disable URLs rebasing')
+  .option('--skip-advanced', 'Disable advanced optimizations - selector & property merging, reduction, etc.')
   .option('--selectors-merge-mode [ie8|*]', 'Use `ie8` for compatibility mode, `*` for merge all (default).')
   .option('-d, --debug', 'Shows debug information (minification time & compression efficiency)');
 
@@ -70,6 +71,8 @@ if (commands.skipImport)
   cleanOptions.processImport = false;
 if (commands.skipRebase)
   cleanOptions.noRebase = true;
+if (commands.skipAdvanced)
+  cleanOptions.noAdvanced = true;
 if (commands.selectorsMergeMode)
   cleanOptions.selectorsMergeMode = commands.selectorsMergeMode;
 if (commands.debug)
index 11888d1..ab7084a 100644 (file)
@@ -246,13 +246,15 @@ var CleanCSS = {
       return match.replace(/\+/g, ' + ');
     });
 
-    replace(function optimizeSelectors() {
-      data = new SelectorsOptimizer(data, {
-        keepBreaks: options.keepBreaks,
-        lineBreak: lineBreak,
-        selectorsMergeMode: options.selectorsMergeMode
-      }).process();
-    });
+    if (!options.noAdvanced) {
+      replace(function optimizeSelectors() {
+        data = new SelectorsOptimizer(data, {
+          keepBreaks: options.keepBreaks,
+          lineBreak: lineBreak,
+          selectorsMergeMode: options.selectorsMergeMode
+        }).process();
+      });
+    }
 
     replace(function restoreUrls() {
       data = urlsProcessor.restore(data);
index d306893..0a5017e 100644 (file)
@@ -102,6 +102,11 @@ exports.commandsSuite = vows.describe('binary commands').addBatch({
       deleteFile('debug.css');
     }
   }),
+  'skip advanced optimizations': pipedContext('a{color:red}p{color:red}', '--skip-advanced', {
+    'should do basic optimizations only': function(error, stdout) {
+      assert.equal(stdout, 'a{color:red}p{color:red}');
+    }
+  }),
   'no relative to path': binaryContext('./test/data/partials-absolute/base.css', {
     'should not be able to resolve it fully': function(error, stdout) {
       assert.equal(stdout, '');
index 0fef9fe..c85d78e 100644 (file)
@@ -1066,6 +1066,9 @@ title']{display:block}",
       "@import url(/fake.css);"
     ]
   }, { processImport: false }),
+  'duplicate selectors with disabled advanced processing': cssContext({
+    'of a duplicate selector': 'a,a{color:red}'
+  }, { noAdvanced: true }),
   'duplicate selectors in a list': cssContext({
     'of a duplicate selector': [
       'a,a{color:red}',