jsx.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.JSXAttribute = JSXAttribute;
  6. exports.JSXClosingElement = JSXClosingElement;
  7. exports.JSXClosingFragment = JSXClosingFragment;
  8. exports.JSXElement = JSXElement;
  9. exports.JSXEmptyExpression = JSXEmptyExpression;
  10. exports.JSXExpressionContainer = JSXExpressionContainer;
  11. exports.JSXFragment = JSXFragment;
  12. exports.JSXIdentifier = JSXIdentifier;
  13. exports.JSXMemberExpression = JSXMemberExpression;
  14. exports.JSXNamespacedName = JSXNamespacedName;
  15. exports.JSXOpeningElement = JSXOpeningElement;
  16. exports.JSXOpeningFragment = JSXOpeningFragment;
  17. exports.JSXSpreadAttribute = JSXSpreadAttribute;
  18. exports.JSXSpreadChild = JSXSpreadChild;
  19. exports.JSXText = JSXText;
  20. function JSXAttribute(node) {
  21. this.print(node.name);
  22. if (node.value) {
  23. this.tokenChar(61);
  24. this.print(node.value);
  25. }
  26. }
  27. function JSXIdentifier(node) {
  28. this.word(node.name);
  29. }
  30. function JSXNamespacedName(node) {
  31. this.print(node.namespace);
  32. this.tokenChar(58);
  33. this.print(node.name);
  34. }
  35. function JSXMemberExpression(node) {
  36. this.print(node.object);
  37. this.tokenChar(46);
  38. this.print(node.property);
  39. }
  40. function JSXSpreadAttribute(node) {
  41. this.tokenChar(123);
  42. this.token("...");
  43. this.print(node.argument);
  44. this.rightBrace(node);
  45. }
  46. function JSXExpressionContainer(node) {
  47. this.tokenChar(123);
  48. this.print(node.expression);
  49. this.rightBrace(node);
  50. }
  51. function JSXSpreadChild(node) {
  52. this.tokenChar(123);
  53. this.token("...");
  54. this.print(node.expression);
  55. this.rightBrace(node);
  56. }
  57. function JSXText(node) {
  58. const raw = this.getPossibleRaw(node);
  59. if (raw !== undefined) {
  60. this.token(raw, true);
  61. } else {
  62. this.token(node.value, true);
  63. }
  64. }
  65. function JSXElement(node) {
  66. const open = node.openingElement;
  67. this.print(open);
  68. if (open.selfClosing) return;
  69. this.indent();
  70. for (const child of node.children) {
  71. this.print(child);
  72. }
  73. this.dedent();
  74. this.print(node.closingElement);
  75. }
  76. function spaceSeparator() {
  77. this.space();
  78. }
  79. function JSXOpeningElement(node) {
  80. this.tokenChar(60);
  81. this.print(node.name);
  82. this.print(node.typeParameters);
  83. if (node.attributes.length > 0) {
  84. this.space();
  85. this.printJoin(node.attributes, undefined, undefined, spaceSeparator);
  86. }
  87. if (node.selfClosing) {
  88. this.space();
  89. this.tokenChar(47);
  90. }
  91. this.tokenChar(62);
  92. }
  93. function JSXClosingElement(node) {
  94. this.tokenChar(60);
  95. this.tokenChar(47);
  96. this.print(node.name);
  97. this.tokenChar(62);
  98. }
  99. function JSXEmptyExpression() {
  100. this.printInnerComments();
  101. }
  102. function JSXFragment(node) {
  103. this.print(node.openingFragment);
  104. this.indent();
  105. for (const child of node.children) {
  106. this.print(child);
  107. }
  108. this.dedent();
  109. this.print(node.closingFragment);
  110. }
  111. function JSXOpeningFragment() {
  112. this.tokenChar(60);
  113. this.tokenChar(62);
  114. }
  115. function JSXClosingFragment() {
  116. this.token("</");
  117. this.tokenChar(62);
  118. }
  119. //# sourceMappingURL=jsx.js.map