jsx.js 2.6 KB

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