Skip to content

Commit

Permalink
Renames compactShorthands level 2 option to mergeIntoShorthands.
Browse files Browse the repository at this point in the history
Why:

* It better describes what this option does.
  • Loading branch information
jakubpawlowicz committed Jan 18, 2017
1 parent 1c3331f commit aa17ed0
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 23 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ There will be some breaking changes:
* renames `keepSpecialComments` to `specialComments`;
* moves `roundingPrecision` and `specialComments` to level 1 optimizations options, see examples below;
* moves `mediaMerging`, `restructuring`, `semanticMerging`, and `shorthandCompacting` to level 2 optimizations options, see examples below;
* renames `shorthandCompacting` option to `mergeIntoShorthands`;
* level 1 optimizations are the new default, up to 3.x it was level 2;
* `--keep-line-breaks` / `keepBreaks` option is replaced with `--format keep-breaks` / `{ format: 'keep-breaks' }` to ease transition.
* `sourceMap` option is API has to be a boolean from now on. If you want to specify an input source map pass it a 2nd argument to `minify` method or via a hash instead;
Expand Down Expand Up @@ -174,10 +175,10 @@ Level 2 optimizations:

```bash
cleancss -O2 one.css
cleancss -O2 mergeMedia:off;restructureRules:off;mergeSemantically:on;compactShorthands:off one.css
cleancss -O2 mergeMedia:off;restructureRules:off;mergeSemantically:on;mergeIntoShorthands:off one.css
cleancss -O2 all:off;removeDuplicateRules:on one.css
# `compactShorthands` controls shorthand compacting; defaults to `on`
# `mergeAdjacentRules` controls adjacent rules merging; defaults to `on`
# `mergeIntoShorthands` controls merging properties into shorthands; defaults to `on`
# `mergeMedia` controls `@media` merging; defaults to `on`
# `mergeNonAdjacentRules` controls non-adjacent rule merging; defaults to `on`
# `mergeSemantically` controls semantic merging; defaults to `off`
Expand Down Expand Up @@ -302,8 +303,8 @@ new CleanCSS({
new CleanCSS({
level: {
2: {
compactShorthands: true, // controls shorthand compacting; defaults to true
mergeAdjacentRules: true, // controls adjacent rules merging; defaults to true
mergeIntoShorthands: true, // controls merging properties into shorthands; defaults to true
mergeMedia: true, // controls `@media` merging; defaults to true
mergeNonAdjacentRules: true, // controls non-adjacent rule merging; defaults to true
mergeSemantically: false, // controls semantic merging; defaults to false
Expand Down Expand Up @@ -542,7 +543,7 @@ In library mode you can also pass `compatibility` as a hash of options.
All level 2 optimizations are dispatched [here](https://github.com/jakubpawlowicz/clean-css/blob/master/lib/selectors/advanced.js#L59), and this is what they do:

* `recursivelyOptimizeBlocks` - does all the following operations on a block (think `@media` or `@keyframe` at-rules);
* `recursivelyOptimizeProperties` - optimizes properties in rulesets and "flat at-rules" (like @font-face) by splitting them into components (e.g. `margin` into `margin-(*)`), optimizing, and rebuilding them back. You may want to use `compactShorthands` option to control whether you want to turn multiple (long-hand) properties into a shorthand ones;
* `recursivelyOptimizeProperties` - optimizes properties in rulesets and "flat at-rules" (like @font-face) by splitting them into components (e.g. `margin` into `margin-(*)`), optimizing, and rebuilding them back. You may want to use `mergeIntoShorthands` option to control whether you want to turn multiple (long-hand) properties into a shorthand ones;
* `removeDuplicates` - gets rid of duplicate rulesets with exactly the same set of properties (think of including the same Sass / Less partial twice for no good reason);
* `mergeAdjacent` - merges adjacent rulesets with the same selector or rules;
* `reduceNonAdjacent` - identifies which properties are overridden in same-selector non-adjacent rulesets, and removes them;
Expand Down
4 changes: 2 additions & 2 deletions bin/cleancss
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ commands.on('--help', function () {
console.log('');
console.log(' Level 2 optimizations:');
console.log(' %> cleancss -O2 one.css');
console.log(' %> cleancss -O2 mergeMedia:off;restructureRules:off;mergeSemantically:on;compactShorthands:off one.css');
console.log(' %> cleancss -O2 mergeMedia:off;restructureRules:off;mergeSemantically:on;mergeIntoShorthands:off one.css');
console.log(' %> cleancss -O2 all:off;removeDuplicateRules:on one.css');
console.log(' %> # `compactShorthands` controls shorthand compacting; defaults to `on`');
console.log(' %> # `mergeAdjacentRules` controls adjacent rules merging; defaults to `on`');
console.log(' %> # `mergeIntoShorthands` controls merging properties into shorthands; defaults to `on`');
console.log(' %> # `mergeMedia` controls `@media` merging; defaults to `on`');
console.log(' %> # `mergeNonAdjacentRules` controls non-adjacent rule merging; defaults to `on`');
console.log(' %> # `mergeSemantically` controls semantic merging; defaults to `off`');
Expand Down
4 changes: 2 additions & 2 deletions lib/optimizer/level-2/compacting/optimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ function compactorOptimize(selector, properties, withCompacting, overrideOptions
}
}

if (overrideOptions.enabled && context.options.level[OptimizationLevel.Two].compactShorthands) {
if (overrideOptions.enabled && context.options.level[OptimizationLevel.Two].mergeIntoShorthands) {
compactOverrides(_properties, context.options.compatibility, overrideOptions.merging, validator);
}

if (withCompacting && context.options.level[OptimizationLevel.Two].compactShorthands) {
if (withCompacting && context.options.level[OptimizationLevel.Two].mergeIntoShorthands) {
compactShorthands(_properties, validator);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/options/optimization-level.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ DEFAULTS[OptimizationLevel.One] = {
tidySelectors: true
};
DEFAULTS[OptimizationLevel.Two] = {
compactShorthands: true,
mergeAdjacentRules: true,
mergeIntoShorthands: true,
mergeMedia: true,
mergeNonAdjacentRules: true,
mergeSemantically: false,
Expand Down
2 changes: 1 addition & 1 deletion test/binary-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ vows.describe('./bin/cleancss')
})
.addBatch({
'shorthand compacting': {
'of (yet) unmergeable properties': pipedContext('a{background:url(image.png);background-color:red}', '-O2 compactShorthands:off', {
'of (yet) unmergeable properties': pipedContext('a{background:url(image.png);background-color:red}', '-O2 mergeIntoShorthands:off', {
'gets right result': function (error, stdout) {
assert.equal(stdout, 'a{background:url(image.png);background-color:red}');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function _optimize(source) {
mergeMedia: true,
restructureRules: true,
mergeSemantically: false,
compactShorthands: true
mergeIntoShorthands: true
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion test/optimizer/level-2/compacting/optimize-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function _optimize(source, compatibilityOptions) {
mergeMedia: false,
restructureRules: false,
mergeSemantically: false,
compactShorthands: true
mergeIntoShorthands: true
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function _optimize(source, compat) {
compatibility: compat,
level: {
2: {
compactShorthands: true
mergeIntoShorthands: true
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function _optimize(source) {
compatibility: compat,
level: {
2: {
compactShorthands: true
mergeIntoShorthands: true
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion test/optimizer/level-2/reduce-non-adjacent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ vows.describe('remove duplicates')
'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}'
]
}, { level: { 2: { all: false, reduceNonAdjacentRules: true, compactShorthands: true } } })
}, { level: { 2: { all: false, reduceNonAdjacentRules: true, mergeIntoShorthands: true } } })
)
.addBatch(
optimizerContext('level 2 off', {
Expand Down
16 changes: 8 additions & 8 deletions test/options/optimization-level-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ vows.describe(optimizationLevelFrom)
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
compactShorthands: true,
mergeAdjacentRules: true,
mergeIntoShorthands: true,
mergeMedia: true,
mergeNonAdjacentRules: true,
mergeSemantically: false,
Expand Down Expand Up @@ -184,8 +184,8 @@ vows.describe(optimizationLevelFrom)
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
compactShorthands: true,
mergeAdjacentRules: true,
mergeIntoShorthands: true,
mergeMedia: true,
mergeNonAdjacentRules: true,
mergeSemantically: false,
Expand Down Expand Up @@ -303,8 +303,8 @@ vows.describe(optimizationLevelFrom)
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
compactShorthands: false,
mergeAdjacentRules: false,
mergeIntoShorthands: false,
mergeMedia: true,
mergeNonAdjacentRules: false,
mergeSemantically: false,
Expand Down Expand Up @@ -352,8 +352,8 @@ vows.describe(optimizationLevelFrom)
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
compactShorthands: false,
mergeAdjacentRules: false,
mergeIntoShorthands: false,
mergeMedia: true,
mergeNonAdjacentRules: false,
mergeSemantically: false,
Expand Down Expand Up @@ -436,8 +436,8 @@ vows.describe(optimizationLevelFrom)
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
compactShorthands: true,
mergeAdjacentRules: true,
mergeIntoShorthands: true,
mergeMedia: false,
mergeNonAdjacentRules: true,
mergeSemantically: true,
Expand Down Expand Up @@ -485,8 +485,8 @@ vows.describe(optimizationLevelFrom)
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
compactShorthands: true,
mergeAdjacentRules: true,
mergeIntoShorthands: true,
mergeMedia: false,
mergeNonAdjacentRules: true,
mergeSemantically: true,
Expand Down Expand Up @@ -534,8 +534,8 @@ vows.describe(optimizationLevelFrom)
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
compactShorthands: false,
mergeAdjacentRules: false,
mergeIntoShorthands: false,
mergeMedia: true,
mergeNonAdjacentRules: false,
mergeSemantically: true,
Expand Down Expand Up @@ -583,8 +583,8 @@ vows.describe(optimizationLevelFrom)
},
'has level 2 options': function (levelOptions) {
assert.deepEqual(levelOptions['2'], {
compactShorthands: false,
mergeAdjacentRules: false,
mergeIntoShorthands: false,
mergeMedia: true,
mergeNonAdjacentRules: false,
mergeSemantically: true,
Expand Down

0 comments on commit aa17ed0

Please sign in to comment.