Skip to content

Commit

Permalink
fix space and universal removal
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Feb 7, 2017
1 parent 6aa9e69 commit 773c377
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
19 changes: 8 additions & 11 deletions lib/compressor/clean/Space.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
function canCleanWhitespace(node) {
if (node.type !== 'Operator') {
return false;
module.exports = function cleanWhitespace(node, item, list) {
if (node.value === '+' || node.value === '-') {
return;
}

return node.value !== '+' && node.value !== '-';
}

module.exports = function cleanWhitespace(node, item, list) {
var prev = item.prev && item.prev.data;
var next = item.next && item.next.data;
if (item.prev !== null && item.prev.data.type === 'Space') {
list.remove(item.prev);
}

if (canCleanWhitespace(prev) || canCleanWhitespace(next)) {
list.remove(item);
if (item.next !== null && item.next.data.type === 'Space') {
list.remove(item.next);
}
};
13 changes: 9 additions & 4 deletions lib/compressor/clean/TypeSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
module.exports = function cleanType(node, item, list) {
var name = item.data.name;

// check it's a universal selector
if (name.charAt(name.length - 1) !== '*') {
// check it's a non-namespaced universal selector
if (name !== '*') {
return;
}

// remove when universal selector isn't last or before combinator
if (item.next !== null && item.next.data.type !== 'Combinator') {
// remove when universal selector before other selectors
var nextType = item.next && item.next.data.type;
if (nextType === 'IdSelector' ||
nextType === 'ClassSelector' ||
nextType === 'AttributeSelector' ||
nextType === 'PseudoClassSelector' ||
nextType === 'PseudoElementSelector') {
list.remove(item);
}
};
4 changes: 2 additions & 2 deletions lib/compressor/clean/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var walk = require('css-tree').walkUp;
var handlers = {
Space: require('./Space'),
Atrule: require('./Atrule'),
Rule: require('./Rule'),
Declaration: require('./Declaration'),
TypeSelector: require('./TypeSelector'),
Comment: require('./Comment')
Comment: require('./Comment'),
Operator: require('./Space')
};

module.exports = function(ast, usageData) {
Expand Down

0 comments on commit 773c377

Please sign in to comment.