* Also disables shorthand compacting for source maps as it is not defined well enough, yet.
* Adds more granular control over compatibility settings.
* Adds support for @counter-style at-rule.
+* Adds `--skip-shorthand-compacting`/`shorthandComacting` option for disabling shorthand compacting.
* Allows `target` option to be a path to a folder instead of a file.
* Allows disabling rounding precision. By [@superlukas](https://github.com/superlukas).
* Breaks 2.x compatibility for using CleanCSS as a function.
--skip-advanced Disable advanced optimizations - selector & property merging,
reduction, etc.
--skip-aggressive-merging Disable properties merging based on their order
+--skip-shorthand-compacting Disable shorthand compacting
--rounding-precision [N] Rounds to `N` decimal places. Defaults to 2. -1 disables rounding.
-c, --compatibility [ie7|ie8] Force compatibility mode (see Readme for advanced examples)
-d, --debug Shows debug information (minification time & compression efficiency)
* `relativeTo` - path to __resolve__ relative `@import` rules and URLs
* `root` - path to __resolve__ absolute `@import` rules and __rebase__ relative URLs
* `roundingPrecision` - rounding precision; defaults to `2`; `-1` disables rounding
+* `shorthandCompacting` - set to false to skip shorthand compacting (default is true unless sourceMap is set when it's false)
* `sourceMap` - exposes source map under `sourceMap` property, e.g. `new CleanCSS().minify(source).sourceMap` (default is false)
* `target` - path to a folder or an output file to which __rebase__ all URLs
.option('--skip-rebase', 'Disable URLs rebasing')
.option('--skip-advanced', 'Disable advanced optimizations - selector & property merging, reduction, etc.')
.option('--skip-aggressive-merging', 'Disable properties merging based on their order')
+ .option('--skip-shorthand-compacting', 'Disable shorthand compacting')
.option('--rounding-precision [n]', 'Rounds to `N` decimal places. Defaults to 2. -1 disables rounding.', parseInt)
.option('-c, --compatibility [ie7|ie8]', 'Force compatibility mode (see Readme for advanced examples)')
.option('-t, --timeout [seconds]', 'Per connection timeout when fetching remote @imports (defaults to 5 seconds)')
cleanOptions.advanced = false;
if (commands.skipAggressiveMerging)
cleanOptions.aggressiveMerging = false;
+if (commands.skipShorthandCompacting)
+ cleanOptions.shorthandCompacting = false;
if (commands.compatibility)
cleanOptions.compatibility = commands.compatibility;
if (commands.roundingPrecision !== undefined)
relativeTo: options.relativeTo,
root: options.root,
roundingPrecision: options.roundingPrecision,
+ shorthandCompacting: !!options.sourceMap ? false : (undefined === options.shorthandCompacting ? true : !!options.shorthandCompacting),
sourceMap: !!options.sourceMap,
target: options.target
};
function valueMapper(object) { return object.value; }
-module.exports = function Optimizer(compatibility, aggressiveMerging, context) {
+module.exports = function Optimizer(options, context) {
var overridable = {
'animation-delay': ['animation'],
'animation-direction': ['animation'],
'-webkit-transition-timing-function': ['-webkit-transition']
};
+ var compatibility = options.compatibility;
+ var aggressiveMerging = options.aggressiveMerging;
+ var shorthandCompacting = options.shorthandCompacting;
+
var IE_BACKSLASH_HACK = '\\9';
var processable = processableInfo.processable(compatibility);
var optimized = optimize(tokenized, allowAdjacent);
var rebuilt = rebuild(optimized);
- return compactProperties && rebuilt.compactFurther ?
+ return shorthandCompacting && compactProperties && rebuilt.compactFurther ?
compact(rebuilt.tokenized) :
rebuilt;
}
function AdvancedOptimizer(options, context) {
this.options = options;
this.minificationsMade = [];
- this.propertyOptimizer = new PropertyOptimizer(this.options.compatibility, this.options.aggressiveMerging, context);
+ this.propertyOptimizer = new PropertyOptimizer(this.options, context);
}
function changeBodyOf(token, newBody) {
assert.equal(stdout, 'a{display:block;background:#fff}');
}
})
+ },
+ 'shorthand compacting': {
+ 'of (yet) unmergeable properties': pipedContext('a{background:url(image.png);background-color:red}', '--skip-shorthand-compacting', {
+ 'gets right result': function(error, stdout) {
+ assert.equal(stdout, 'a{background:url(image.png);background-color:red}');
+ }
+ })
}
});
var context = {};
options = options || {};
+ options.shorthandCompacting = true;
options.compatibility = new Compatibility(options.compatibility).toOptions();
function optimized(target) {
};
assert.deepEqual(mapping, minified.sourceMap._mappings[6]);
}
- }
+ },
+ 'shorthands': {
+ 'topic': new CleanCSS({ sourceMap: true }).minify('a{background:url(image.png);background-color:red}'),
+ 'should have 3 mappings': function(minified) {
+ assert.equal(3, minified.sourceMap._mappings.length);
+ },
+ 'should have selector mapping': function (minified) {
+ var mapping = {
+ generatedLine: 1,
+ generatedColumn: 1,
+ originalLine: 1,
+ originalColumn: 1,
+ source: '__stdin__.css',
+ name: 'a'
+ };
+ assert.deepEqual(mapping, minified.sourceMap._mappings[0]);
+ },
+ 'should have _background_ mapping': function (minified) {
+ var mapping = {
+ generatedLine: 1,
+ generatedColumn: 3,
+ originalLine: 1,
+ originalColumn: 3,
+ source: '__stdin__.css',
+ name: 'background:url(image.png)'
+ };
+ assert.deepEqual(mapping, minified.sourceMap._mappings[1]);
+ },
+ 'should have _background-color_ mapping': function (minified) {
+ var mapping = {
+ generatedLine: 1,
+ generatedColumn: 29,
+ originalLine: 1,
+ originalColumn: 29,
+ source: '__stdin__.css',
+ name: 'background-color:red'
+ };
+ assert.deepEqual(mapping, minified.sourceMap._mappings[2]);
+ }
+ },
})
.export(module);