jsx.js 3.0 KB

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