jsx.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. "use strict";
  2. exports.__esModule = true;
  3. var _getIterator2 = require("babel-runtime/core-js/get-iterator");
  4. var _getIterator3 = _interopRequireDefault(_getIterator2);
  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. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  18. function JSXAttribute(node) {
  19. this.print(node.name, node);
  20. if (node.value) {
  21. this.token("=");
  22. this.print(node.value, node);
  23. }
  24. }
  25. function JSXIdentifier(node) {
  26. this.word(node.name);
  27. }
  28. function JSXNamespacedName(node) {
  29. this.print(node.namespace, node);
  30. this.token(":");
  31. this.print(node.name, node);
  32. }
  33. function JSXMemberExpression(node) {
  34. this.print(node.object, node);
  35. this.token(".");
  36. this.print(node.property, node);
  37. }
  38. function JSXSpreadAttribute(node) {
  39. this.token("{");
  40. this.token("...");
  41. this.print(node.argument, node);
  42. this.token("}");
  43. }
  44. function JSXExpressionContainer(node) {
  45. this.token("{");
  46. this.print(node.expression, node);
  47. this.token("}");
  48. }
  49. function JSXSpreadChild(node) {
  50. this.token("{");
  51. this.token("...");
  52. this.print(node.expression, node);
  53. this.token("}");
  54. }
  55. function JSXText(node) {
  56. this.token(node.value);
  57. }
  58. function JSXElement(node) {
  59. var open = node.openingElement;
  60. this.print(open, node);
  61. if (open.selfClosing) return;
  62. this.indent();
  63. for (var _iterator = node.children, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
  64. var _ref;
  65. if (_isArray) {
  66. if (_i >= _iterator.length) break;
  67. _ref = _iterator[_i++];
  68. } else {
  69. _i = _iterator.next();
  70. if (_i.done) break;
  71. _ref = _i.value;
  72. }
  73. var child = _ref;
  74. this.print(child, node);
  75. }
  76. this.dedent();
  77. this.print(node.closingElement, node);
  78. }
  79. function spaceSeparator() {
  80. this.space();
  81. }
  82. function JSXOpeningElement(node) {
  83. this.token("<");
  84. this.print(node.name, node);
  85. if (node.attributes.length > 0) {
  86. this.space();
  87. this.printJoin(node.attributes, node, { separator: spaceSeparator });
  88. }
  89. if (node.selfClosing) {
  90. this.space();
  91. this.token("/>");
  92. } else {
  93. this.token(">");
  94. }
  95. }
  96. function JSXClosingElement(node) {
  97. this.token("</");
  98. this.print(node.name, node);
  99. this.token(">");
  100. }
  101. function JSXEmptyExpression() {}