addSemicolonForEditInfo.cjs 987 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // NOTICE: This file is generated by Rollup. To modify it,
  2. // please instead edit the ESM counterpart and rebuild with Rollup (npm run build).
  3. 'use strict';
  4. const typeGuards = require('./typeGuards.cjs');
  5. /** @import { Node as PostcssNode } from 'postcss' */
  6. /**
  7. * Adjust the text in EditInfo to include a semicolon when needed.
  8. *
  9. * @param {PostcssNode} node
  10. * @param {{range: [number, number], text: string}} fixData
  11. * @returns {{range: [number, number], text: string}}
  12. */
  13. function addSemicolonForEditInfo(node, fixData) {
  14. const { parent } = node;
  15. if (!parent) return fixData;
  16. if (node.type === 'decl') {
  17. if (parent.raws.semicolon || parent.last !== node) {
  18. return {
  19. ...fixData,
  20. text: `${fixData.text};`,
  21. };
  22. }
  23. }
  24. if (typeGuards.isAtRule(node)) {
  25. if (!node.nodes && (parent.raws.semicolon || parent.last !== node)) {
  26. return {
  27. ...fixData,
  28. text: `${fixData.text};`,
  29. };
  30. }
  31. }
  32. return fixData;
  33. }
  34. module.exports = addSemicolonForEditInfo;