54c98e1fc232b86151278d76208cb05bac8d2efa5fa411e3f6a5fdbfa62668da568d8398f3078a29d96a765717f66bce59e8d7bd34c7a77da0ff36f69d3d6f 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = cleanJSXElementLiteralChild;
  6. var _index = require("../../builders/generated/index.js");
  7. var _index2 = require("../../index.js");
  8. function cleanJSXElementLiteralChild(child, args) {
  9. const lines = child.value.split(/\r\n|\n|\r/);
  10. let lastNonEmptyLine = 0;
  11. for (let i = 0; i < lines.length; i++) {
  12. if (/[^ \t]/.exec(lines[i])) {
  13. lastNonEmptyLine = i;
  14. }
  15. }
  16. let str = "";
  17. for (let i = 0; i < lines.length; i++) {
  18. const line = lines[i];
  19. const isFirstLine = i === 0;
  20. const isLastLine = i === lines.length - 1;
  21. const isLastNonEmptyLine = i === lastNonEmptyLine;
  22. let trimmedLine = line.replace(/\t/g, " ");
  23. if (!isFirstLine) {
  24. trimmedLine = trimmedLine.replace(/^ +/, "");
  25. }
  26. if (!isLastLine) {
  27. trimmedLine = trimmedLine.replace(/ +$/, "");
  28. }
  29. if (trimmedLine) {
  30. if (!isLastNonEmptyLine) {
  31. trimmedLine += " ";
  32. }
  33. str += trimmedLine;
  34. }
  35. }
  36. if (str) args.push((0, _index2.inherits)((0, _index.stringLiteral)(str), child));
  37. }
  38. //# sourceMappingURL=cleanJSXElementLiteralChild.js.map