jsx.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. {
  83. if (node.typeArguments) {
  84. this.print(node.typeArguments);
  85. }
  86. this.print(node.typeParameters);
  87. }
  88. if (node.attributes.length > 0) {
  89. this.space();
  90. this.printJoin(node.attributes, undefined, undefined, spaceSeparator);
  91. }
  92. if (node.selfClosing) {
  93. this.space();
  94. this.tokenChar(47);
  95. }
  96. this.tokenChar(62);
  97. }
  98. function JSXClosingElement(node) {
  99. this.tokenChar(60);
  100. this.tokenChar(47);
  101. this.print(node.name);
  102. this.tokenChar(62);
  103. }
  104. function JSXEmptyExpression() {
  105. this.printInnerComments();
  106. }
  107. function JSXFragment(node) {
  108. this.print(node.openingFragment);
  109. this.indent();
  110. for (const child of node.children) {
  111. this.print(child);
  112. }
  113. this.dedent();
  114. this.print(node.closingFragment);
  115. }
  116. function JSXOpeningFragment() {
  117. this.tokenChar(60);
  118. this.tokenChar(62);
  119. }
  120. function JSXClosingFragment() {
  121. this.token("</");
  122. this.tokenChar(62);
  123. }
  124. //# sourceMappingURL=jsx.js.map