functionCommaSpaceFix.js 853 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. /**
  3. * @param {{
  4. * div: import('postcss-value-parser').DivNode,
  5. * index: number,
  6. * nodes: import('postcss-value-parser').Node[],
  7. * expectation: string,
  8. * position: 'before' | 'after',
  9. * symb: string,
  10. * }} params
  11. * @returns {boolean}
  12. */
  13. module.exports = function functionCommaSpaceFix(params) {
  14. const { div, index, nodes, expectation, position, symb } = params;
  15. if (expectation.startsWith('always')) {
  16. div[position] = symb;
  17. return true;
  18. }
  19. if (expectation.startsWith('never')) {
  20. div[position] = '';
  21. for (let i = index + 1; i < nodes.length; i++) {
  22. const node = nodes[i];
  23. if (node === undefined) {
  24. continue;
  25. }
  26. if (node.type === 'comment') {
  27. continue;
  28. }
  29. if (node.type === 'space') {
  30. node.value = '';
  31. continue;
  32. }
  33. break;
  34. }
  35. return true;
  36. }
  37. return false;
  38. };