You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
808 B

4 years ago
  1. var { isNodeChildrenList } = require('./utils');
  2. function isSafeOperator(node) {
  3. return node.type === 'Operator' && node.value !== '+' && node.value !== '-';
  4. }
  5. module.exports = function cleanWhitespace(node, item, list) {
  6. // remove when first or last item in sequence
  7. if (item.next === null || item.prev === null) {
  8. list.remove(item);
  9. return;
  10. }
  11. // white space in stylesheet or block children
  12. if (isNodeChildrenList(this.stylesheet, list) ||
  13. isNodeChildrenList(this.block, list)) {
  14. list.remove(item);
  15. return;
  16. }
  17. if (item.next.data.type === 'WhiteSpace') {
  18. list.remove(item);
  19. return;
  20. }
  21. if (isSafeOperator(item.prev.data) || isSafeOperator(item.next.data)) {
  22. list.remove(item);
  23. return;
  24. }
  25. };