classes.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.ClassExpression = exports.ClassDeclaration = ClassDeclaration;
  6. exports.ClassBody = ClassBody;
  7. exports.ClassProperty = ClassProperty;
  8. exports.ClassPrivateProperty = ClassPrivateProperty;
  9. exports.ClassMethod = ClassMethod;
  10. exports.ClassPrivateMethod = ClassPrivateMethod;
  11. exports._classMethodHead = _classMethodHead;
  12. function t() {
  13. const data = _interopRequireWildcard(require("@babel/types"));
  14. t = function () {
  15. return data;
  16. };
  17. return data;
  18. }
  19. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
  20. function ClassDeclaration(node, parent) {
  21. if (!this.format.decoratorsBeforeExport || !t().isExportDefaultDeclaration(parent) && !t().isExportNamedDeclaration(parent)) {
  22. this.printJoin(node.decorators, node);
  23. }
  24. if (node.declare) {
  25. this.word("declare");
  26. this.space();
  27. }
  28. if (node.abstract) {
  29. this.word("abstract");
  30. this.space();
  31. }
  32. this.word("class");
  33. if (node.id) {
  34. this.space();
  35. this.print(node.id, node);
  36. }
  37. this.print(node.typeParameters, node);
  38. if (node.superClass) {
  39. this.space();
  40. this.word("extends");
  41. this.space();
  42. this.print(node.superClass, node);
  43. this.print(node.superTypeParameters, node);
  44. }
  45. if (node.implements) {
  46. this.space();
  47. this.word("implements");
  48. this.space();
  49. this.printList(node.implements, node);
  50. }
  51. this.space();
  52. this.print(node.body, node);
  53. }
  54. function ClassBody(node) {
  55. this.token("{");
  56. this.printInnerComments(node);
  57. if (node.body.length === 0) {
  58. this.token("}");
  59. } else {
  60. this.newline();
  61. this.indent();
  62. this.printSequence(node.body, node);
  63. this.dedent();
  64. if (!this.endsWith("\n")) this.newline();
  65. this.rightBrace();
  66. }
  67. }
  68. function ClassProperty(node) {
  69. this.printJoin(node.decorators, node);
  70. if (node.accessibility) {
  71. this.word(node.accessibility);
  72. this.space();
  73. }
  74. if (node.static) {
  75. this.word("static");
  76. this.space();
  77. }
  78. if (node.abstract) {
  79. this.word("abstract");
  80. this.space();
  81. }
  82. if (node.readonly) {
  83. this.word("readonly");
  84. this.space();
  85. }
  86. if (node.computed) {
  87. this.token("[");
  88. this.print(node.key, node);
  89. this.token("]");
  90. } else {
  91. this._variance(node);
  92. this.print(node.key, node);
  93. }
  94. if (node.optional) {
  95. this.token("?");
  96. }
  97. if (node.definite) {
  98. this.token("!");
  99. }
  100. this.print(node.typeAnnotation, node);
  101. if (node.value) {
  102. this.space();
  103. this.token("=");
  104. this.space();
  105. this.print(node.value, node);
  106. }
  107. this.semicolon();
  108. }
  109. function ClassPrivateProperty(node) {
  110. if (node.static) {
  111. this.word("static");
  112. this.space();
  113. }
  114. this.print(node.key, node);
  115. this.print(node.typeAnnotation, node);
  116. if (node.value) {
  117. this.space();
  118. this.token("=");
  119. this.space();
  120. this.print(node.value, node);
  121. }
  122. this.semicolon();
  123. }
  124. function ClassMethod(node) {
  125. this._classMethodHead(node);
  126. this.space();
  127. this.print(node.body, node);
  128. }
  129. function ClassPrivateMethod(node) {
  130. this._classMethodHead(node);
  131. this.space();
  132. this.print(node.body, node);
  133. }
  134. function _classMethodHead(node) {
  135. this.printJoin(node.decorators, node);
  136. if (node.accessibility) {
  137. this.word(node.accessibility);
  138. this.space();
  139. }
  140. if (node.abstract) {
  141. this.word("abstract");
  142. this.space();
  143. }
  144. if (node.static) {
  145. this.word("static");
  146. this.space();
  147. }
  148. this._methodHead(node);
  149. }