WhiteSpace.js 808 B

123456789101112131415161718192021222324252627282930
  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. };