4
0

getNextNonSharedLineCommentNode.mjs 695 B

12345678910111213141516171819202122232425262728293031323334
  1. /** @typedef {import('postcss').Node} Node */
  2. /**
  3. * @param {Node | void} node
  4. */
  5. function getNodeLine(node) {
  6. return node && node.source && node.source.start && node.source.start.line;
  7. }
  8. /**
  9. * @param {Node | void} node
  10. * @returns {Node | void}
  11. */
  12. export default function getNextNonSharedLineCommentNode(node) {
  13. if (node === undefined) {
  14. return undefined;
  15. }
  16. /** @type {Node | void} */
  17. const nextNode = node.next();
  18. if (!nextNode || nextNode.type !== 'comment') {
  19. return nextNode;
  20. }
  21. if (
  22. getNodeLine(node) === getNodeLine(nextNode) ||
  23. getNodeLine(nextNode) === getNodeLine(nextNode.next())
  24. ) {
  25. return getNextNonSharedLineCommentNode(nextNode);
  26. }
  27. return nextNode;
  28. }