2024-01-16 21:26:16 +08:00
|
|
|
var { isNodeChildrenList } = require('./utils');
|
|
|
|
|
|
|
|
function isSafeOperator(node) {
|
|
|
|
return node.type === 'Operator' && node.value !== '+' && node.value !== '-';
|
|
|
|
}
|
|
|
|
|
2023-12-18 13:12:25 +08:00
|
|
|
module.exports = function cleanWhitespace(node, item, list) {
|
|
|
|
// remove when first or last item in sequence
|
|
|
|
if (item.next === null || item.prev === null) {
|
|
|
|
list.remove(item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-16 21:26:16 +08:00
|
|
|
// white space in stylesheet or block children
|
|
|
|
if (isNodeChildrenList(this.stylesheet, list) ||
|
|
|
|
isNodeChildrenList(this.block, list)) {
|
|
|
|
list.remove(item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.next.data.type === 'WhiteSpace') {
|
2023-12-18 13:12:25 +08:00
|
|
|
list.remove(item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-16 21:26:16 +08:00
|
|
|
if (isSafeOperator(item.prev.data) || isSafeOperator(item.next.data)) {
|
2023-12-18 13:12:25 +08:00
|
|
|
list.remove(item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|