Comparing version 4.0.1 to 4.0.2
@@ -0,1 +1,6 @@ | ||
## 4.0.2 (October 28, 2019) | ||
- Fixed clean stage to avoid exceptions when source has unparsed or bad parts (#380) | ||
- Fixed wrong percentage sign removal for zero values (#395) | ||
## 4.0.1 (October 22, 2019) | ||
@@ -2,0 +7,0 @@ |
var resolveKeyword = require('css-tree').keyword; | ||
var { hasNoChildren } = require('./utils'); | ||
@@ -10,3 +11,3 @@ module.exports = function cleanAtrule(node, item, list) { | ||
if (node.block.children.isEmpty()) { | ||
if (hasNoChildren(node.block)) { | ||
list.remove(item); | ||
@@ -19,3 +20,3 @@ return; | ||
case 'charset': | ||
if (!node.prelude || node.prelude.children.isEmpty()) { | ||
if (hasNoChildren(node.prelude)) { | ||
list.remove(item); | ||
@@ -62,3 +63,3 @@ return; | ||
// drop at-rule with no prelude | ||
if (!node.prelude || node.prelude.children.isEmpty()) { | ||
if (hasNoChildren(node.prelude) || hasNoChildren(node.block)) { | ||
list.remove(item); | ||
@@ -65,0 +66,0 @@ } |
var walk = require('css-tree').walk; | ||
var handlers = { | ||
Atrule: require('./Atrule'), | ||
Comment: require('./Comment'), | ||
Declaration: require('./Declaration'), | ||
Raw: require('./Raw'), | ||
Rule: require('./Rule'), | ||
Declaration: require('./Declaration'), | ||
TypeSelector: require('./TypeSelector'), | ||
Comment: require('./Comment'), | ||
Operator: require('./Operator'), | ||
WhiteSpace: require('./WhiteSpace') | ||
@@ -10,0 +10,0 @@ }; |
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var walk = require('css-tree').walk; | ||
var { hasNoChildren } = require('./utils'); | ||
@@ -76,3 +77,8 @@ function cleanUnused(selectorList, usageData) { | ||
module.exports = function cleanRuleset(node, item, list, options) { | ||
module.exports = function cleanRule(node, item, list, options) { | ||
if (hasNoChildren(node.prelude) || hasNoChildren(node.block)) { | ||
list.remove(item); | ||
return; | ||
} | ||
var usageData = options.usage; | ||
@@ -82,8 +88,8 @@ | ||
cleanUnused(node.prelude, usageData); | ||
} | ||
if (node.prelude.children.isEmpty() || | ||
node.block.children.isEmpty()) { | ||
list.remove(item); | ||
if (hasNoChildren(node.prelude)) { | ||
list.remove(item); | ||
return; | ||
} | ||
} | ||
}; |
// remove useless universal selector | ||
module.exports = function cleanType(node, item, list) { | ||
module.exports = function cleanTypeSelector(node, item, list) { | ||
var name = item.data.name; | ||
@@ -4,0 +4,0 @@ |
@@ -0,1 +1,7 @@ | ||
var { isNodeChildrenList } = require('./utils'); | ||
function isSafeOperator(node) { | ||
return node.type === 'Operator' && node.value !== '+' && node.value !== '-'; | ||
} | ||
module.exports = function cleanWhitespace(node, item, list) { | ||
@@ -8,4 +14,5 @@ // remove when first or last item in sequence | ||
// remove when previous node is whitespace | ||
if (item.prev.data.type === 'WhiteSpace') { | ||
// white space in stylesheet or block children | ||
if (isNodeChildrenList(this.stylesheet, list) || | ||
isNodeChildrenList(this.block, list)) { | ||
list.remove(item); | ||
@@ -15,7 +22,11 @@ return; | ||
if ((this.stylesheet !== null && this.stylesheet.children === list) || | ||
(this.block !== null && this.block.children === list)) { | ||
if (item.next.data.type === 'WhiteSpace') { | ||
list.remove(item); | ||
return; | ||
} | ||
if (isSafeOperator(item.prev.data) || isSafeOperator(item.next.data)) { | ||
list.remove(item); | ||
return; | ||
} | ||
}; |
@@ -0,55 +1,30 @@ | ||
var lexer = require('css-tree').lexer; | ||
var packNumber = require('./Number').pack; | ||
var PERCENTAGE_LENGTH_PROPERTY = { | ||
'margin': true, | ||
'margin-top': true, | ||
'margin-left': true, | ||
'margin-bottom': true, | ||
'margin-right': true, | ||
var blacklist = new Set([ | ||
// see https://github.com/jakubpawlowicz/clean-css/issues/957 | ||
'width', | ||
'min-width', | ||
'max-width', | ||
'height', | ||
'min-height', | ||
'max-height' | ||
]); | ||
'padding': true, | ||
'padding-top': true, | ||
'padding-left': true, | ||
'padding-bottom': true, | ||
'padding-right': true, | ||
'top': true, | ||
'left': true, | ||
'bottom': true, | ||
'right': true, | ||
'background-position': true, | ||
'background-position-x': true, | ||
'background-position-y': true, | ||
'background-size': true, | ||
'border': true, | ||
'border-width': true, | ||
'border-top-width': true, | ||
'border-left-width': true, | ||
'border-bottom-width': true, | ||
'border-right-width': true, | ||
'border-image-width': true, | ||
'border-radius': true, | ||
'border-bottom-left-radius': true, | ||
'border-bottom-right-radius': true, | ||
'border-top-left-radius': true, | ||
'border-top-right-radius': true | ||
}; | ||
module.exports = function compressPercentage(node, item) { | ||
var value = packNumber(node.value, item); | ||
var property = this.declaration !== null ? this.declaration.property : null; | ||
node.value = packNumber(node.value, item); | ||
node.value = value; | ||
if (node.value === '0' && this.declaration && !blacklist.has(this.declaration.property)) { | ||
// try to convert a number | ||
item.data = { | ||
type: 'Number', | ||
loc: node.loc, | ||
value: node.value | ||
}; | ||
if (property !== null && PERCENTAGE_LENGTH_PROPERTY.hasOwnProperty(property)) { | ||
if (value === '0') { | ||
item.data = { | ||
type: 'Number', | ||
loc: node.loc, | ||
value: value | ||
}; | ||
// that's ok only when new value matches on length | ||
if (!lexer.matchDeclaration(this.declaration).isType(item.data, 'length')) { | ||
// otherwise rollback changes | ||
item.data = node; | ||
} | ||
} | ||
}; |
{ | ||
"name": "csso", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "CSS minifier with structural optimisations", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/css/csso", |
@@ -22,2 +22,3 @@ [![NPM version](https://img.shields.io/npm/v/csso.svg)](https://www.npmjs.com/package/csso) | ||
- [csso-webpack-plugin](https://github.com/zoobestik/csso-webpack-plugin) – `webpack` plugin | ||
- [CSSO Visual Studio Code plugin](https://marketplace.visualstudio.com/items?itemName=Aneryu.csso) | ||
@@ -24,0 +25,0 @@ ## Install |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
845142
47
373
15683