From: Jakub Pawlowicz Date: Fri, 10 Oct 2014 06:29:07 +0000 (+0100) Subject: Renames `noAdvanced` option into `advanced`. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=83373edf990144a82de1bdb6349e6121e154b7cc;p=clean-css.git Renames `noAdvanced` option into `advanced`. --- diff --git a/History.md b/History.md index 18ab4c0c..4cbb4b16 100644 --- a/History.md +++ b/History.md @@ -5,6 +5,7 @@ * Breaks 2.x compatibility for using CleanCSS as a function. * Reworks minification to tokenize first then minify. See [changes](https://github.com/jakubpawlowicz/clean-css/compare/b06f37d...dd8c14a). +* Renames `noAdvanced` option into `advanced`. * Speeds up advanced processing by shortening optimize loop. * Fixed issue [#360](https://github.com/GoalSmashers/clean-css/issues/360) - adds 7 extra CSS colors. diff --git a/README.md b/README.md index d30bfef8..ac506bee 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,14 @@ Node.js 0.8.0+ (tested on CentOS, Ubuntu, OS X 10.6+, and Windows 7+) npm install clean-css ``` +### How to upgrade clean-css from 2.x to 3.x? + +#### Command-line interface (CLI) - no breaking changes. + +#### Module interface + +* `noAdvanced` became `advanced` - make sure to reverse the value; + ### How to upgrade clean-css from 1.x to 2.x? #### Command-line interface (CLI) @@ -121,13 +129,13 @@ var minimized = new CleanCSS().minify(source); CleanCSS constructor accepts a hash as a parameter, i.e., `new CleanCSS(options).minify(source)` with the following options available: +* `advanced` - set to false to disable advanced optimizations - selector & property merging, reduction, etc. * `benchmark` - turns on benchmarking mode measuring time spent on cleaning up (run `npm run bench` to see example) * `compatibility` - Force compatibility mode to `ie7` or `ie8`. Defaults to not set. * `debug` - set to true to get minification statistics under `stats` property (see `test/custom-test.js` for examples) * `inliner` - a hash of options for `@import` inliner, see test/protocol-imports-test.js for examples * `keepBreaks` - whether to keep line breaks (default is false) * `keepSpecialComments` - `*` for keeping all (default), `1` for keeping first one only, `0` for removing all -* `noAdvanced` - set to true to disable advanced optimizations - selector & property merging, reduction, etc. * `noAggressiveMerging` - set to true to disable aggressive merging of properties. * `noRebase` - whether to skip URLs rebasing * `processImport` - whether to process `@import` rules diff --git a/bin/cleancss b/bin/cleancss index 35e9837a..ace2f255 100755 --- a/bin/cleancss +++ b/bin/cleancss @@ -75,7 +75,7 @@ if (commands.skipImport) if (commands.skipRebase) cleanOptions.noRebase = true; if (commands.skipAdvanced) - cleanOptions.noAdvanced = true; + cleanOptions.advanced = false; if (commands.skipAggressiveMerging) cleanOptions.noAggressiveMerging = true; if (commands.compatibility) diff --git a/lib/clean.js b/lib/clean.js index ff72fc29..c6712aae 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -18,13 +18,13 @@ var CleanCSS = module.exports = function CleanCSS(options) { options = options || {}; this.options = { + advanced: options.advanced === undefined ? true : false, benchmark: options.benchmark, compatibility: options.compatibility, debug: options.debug, inliner: options.inliner, keepBreaks: options.keepBreaks || false, keepSpecialComments: 'keepSpecialComments' in options ? options.keepSpecialComments : '*', - noAdvanced: options.noAdvanced, noAggressiveMerging: options.noAggressiveMerging, noRebase: options.noRebase, processImport: undefined === options.processImport ? true : false, @@ -118,7 +118,7 @@ function minify(data) { var urlRebase = new UrlRebase(options, context); var selectorsOptimizer = new SelectorsOptimizer({ keepBreaks: options.keepBreaks, - noAdvanced: options.noAdvanced, + advanced: options.advanced, compatibility: options.compatibility, aggressiveMerging: !options.noAggressiveMerging, roundingPrecision: options.roundingPrecision diff --git a/lib/selectors/optimizer.js b/lib/selectors/optimizer.js index 2ec661f9..e33c87b4 100644 --- a/lib/selectors/optimizer.js +++ b/lib/selectors/optimizer.js @@ -41,7 +41,7 @@ SelectorsOptimizer.prototype.process = function (data) { var tokens = new Tokenizer(this.context).toTokens(data); new SimpleOptimizer(this.options).optimize(tokens); - if (!this.options.noAdvanced) + if (this.options.advanced) new AdvancedOptimizer(this.options, this.context).optimize(tokens); return rebuild(tokens, this.options.keepBreaks, false).trim(); diff --git a/test/integration-test.js b/test/integration-test.js index 73c143ac..1eef650d 100644 --- a/test/integration-test.js +++ b/test/integration-test.js @@ -8,6 +8,7 @@ var CleanCSS = require('../index'); var lineBreak = process.platform == 'win32' ? '\r\n' : '\n'; var cssContext = function(groups, options) { var context = {}; + var clean = function(expectedCss) { return function(css) { var minifiedCss = new CleanCSS(options).minify(css); @@ -1460,19 +1461,19 @@ title']{display:block}", '@import url(//fonts.googleapis.com/css?family=Domine:700);body h1{font-family:Domine}' ], 'no empty body': '@import url(//fonts.googleapis.com/css?family=Domine:700);body{color:red}body h1{font-family:Domine}' - }, { processImport: false, noAdvanced: true }), + }, { processImport: false, advanced: false }), 'duplicate selectors with disabled advanced processing': cssContext({ 'of a duplicate selector': [ 'a,a{color:red}', 'a{color:red}' ] - }, { noAdvanced: true }), + }, { advanced: false }), 'line breaks with disabled advanced processing': cssContext({ 'should be applied': [ 'a{color:red}p{display:block}', 'a{color:red}' + lineBreak + 'p{display:block}' ] - }, { noAdvanced: true, keepBreaks: true }), + }, { advanced: false, keepBreaks: true }), 'invalid data tokenization': cssContext({ 'extra top-level closing brace': [ 'a{color:red}}p{width:auto}', diff --git a/test/selectors/optimizer-test.js b/test/selectors/optimizer-test.js index b37c0429..5ec0ddd0 100644 --- a/test/selectors/optimizer-test.js +++ b/test/selectors/optimizer-test.js @@ -148,7 +148,7 @@ vows.describe(SelectorsOptimizer) 'a{padding:10px;margin:0;color:red}.one{color:red}a,p{color:red;padding:0}', 'a{margin:0}.one{color:red}a,p{color:red;padding:0}' ] - }, { noAdvanced: false, aggressiveMerging: true }) + }, { advanced: true, aggressiveMerging: true }) ) .addBatch( optimizerContext('advanced on & aggressive merging off', { @@ -160,7 +160,7 @@ vows.describe(SelectorsOptimizer) 'a{padding:10px;margin:0;color:red}.one{color:red}a,p{color:red;padding:0}', 'a{padding:10px;margin:0}.one{color:red}a,p{color:red;padding:0}' ] - }, { noAdvanced: false, aggressiveMerging: false }) + }, { advanced: true, aggressiveMerging: false }) ) .addBatch( optimizerContext('advanced off', { @@ -184,7 +184,7 @@ vows.describe(SelectorsOptimizer) 'a{color:red;display:block}.one{font-size:12px}a{color:#fff;margin:2px}', 'a{color:red;display:block}.one{font-size:12px}a{color:#fff;margin:2px}' ] - }, { noAdvanced: true }) + }, { advanced: false }) ) .addBatch( optimizerContext('@charset', {