classes.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.ClassAccessorProperty = ClassAccessorProperty;
  6. exports.ClassBody = ClassBody;
  7. exports.ClassExpression = exports.ClassDeclaration = ClassDeclaration;
  8. exports.ClassMethod = ClassMethod;
  9. exports.ClassPrivateMethod = ClassPrivateMethod;
  10. exports.ClassPrivateProperty = ClassPrivateProperty;
  11. exports.ClassProperty = ClassProperty;
  12. exports.StaticBlock = StaticBlock;
  13. exports._classMethodHead = _classMethodHead;
  14. var _t = require("@babel/types");
  15. const {
  16. isExportDefaultDeclaration,
  17. isExportNamedDeclaration
  18. } = _t;
  19. function ClassDeclaration(node, parent) {
  20. const inExport = isExportDefaultDeclaration(parent) || isExportNamedDeclaration(parent);
  21. if (!inExport || !this._shouldPrintDecoratorsBeforeExport(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.tokenChar(123);
  56. if (node.body.length === 0) {
  57. this.tokenChar(125);
  58. } else {
  59. this.newline();
  60. this.printSequence(node.body, node, {
  61. indent: true
  62. });
  63. if (!this.endsWith(10)) this.newline();
  64. this.rightBrace(node);
  65. }
  66. }
  67. function ClassProperty(node) {
  68. var _node$key$loc;
  69. this.printJoin(node.decorators, node);
  70. const endLine = (_node$key$loc = node.key.loc) == null || (_node$key$loc = _node$key$loc.end) == null ? void 0 : _node$key$loc.line;
  71. if (endLine) this.catchUp(endLine);
  72. this.tsPrintClassMemberModifiers(node);
  73. if (node.computed) {
  74. this.tokenChar(91);
  75. this.print(node.key, node);
  76. this.tokenChar(93);
  77. } else {
  78. this._variance(node);
  79. this.print(node.key, node);
  80. }
  81. if (node.optional) {
  82. this.tokenChar(63);
  83. }
  84. if (node.definite) {
  85. this.tokenChar(33);
  86. }
  87. this.print(node.typeAnnotation, node);
  88. if (node.value) {
  89. this.space();
  90. this.tokenChar(61);
  91. this.space();
  92. this.print(node.value, node);
  93. }
  94. this.semicolon();
  95. }
  96. function ClassAccessorProperty(node) {
  97. var _node$key$loc2;
  98. this.printJoin(node.decorators, node);
  99. const endLine = (_node$key$loc2 = node.key.loc) == null || (_node$key$loc2 = _node$key$loc2.end) == null ? void 0 : _node$key$loc2.line;
  100. if (endLine) this.catchUp(endLine);
  101. this.tsPrintClassMemberModifiers(node);
  102. this.word("accessor", true);
  103. this.space();
  104. if (node.computed) {
  105. this.tokenChar(91);
  106. this.print(node.key, node);
  107. this.tokenChar(93);
  108. } else {
  109. this._variance(node);
  110. this.print(node.key, node);
  111. }
  112. if (node.optional) {
  113. this.tokenChar(63);
  114. }
  115. if (node.definite) {
  116. this.tokenChar(33);
  117. }
  118. this.print(node.typeAnnotation, node);
  119. if (node.value) {
  120. this.space();
  121. this.tokenChar(61);
  122. this.space();
  123. this.print(node.value, node);
  124. }
  125. this.semicolon();
  126. }
  127. function ClassPrivateProperty(node) {
  128. this.printJoin(node.decorators, node);
  129. if (node.static) {
  130. this.word("static");
  131. this.space();
  132. }
  133. this.print(node.key, node);
  134. this.print(node.typeAnnotation, node);
  135. if (node.value) {
  136. this.space();
  137. this.tokenChar(61);
  138. this.space();
  139. this.print(node.value, node);
  140. }
  141. this.semicolon();
  142. }
  143. function ClassMethod(node) {
  144. this._classMethodHead(node);
  145. this.space();
  146. this.print(node.body, node);
  147. }
  148. function ClassPrivateMethod(node) {
  149. this._classMethodHead(node);
  150. this.space();
  151. this.print(node.body, node);
  152. }
  153. function _classMethodHead(node) {
  154. var _node$key$loc3;
  155. this.printJoin(node.decorators, node);
  156. const endLine = (_node$key$loc3 = node.key.loc) == null || (_node$key$loc3 = _node$key$loc3.end) == null ? void 0 : _node$key$loc3.line;
  157. if (endLine) this.catchUp(endLine);
  158. this.tsPrintClassMemberModifiers(node);
  159. this._methodHead(node);
  160. }
  161. function StaticBlock(node) {
  162. this.word("static");
  163. this.space();
  164. this.tokenChar(123);
  165. if (node.body.length === 0) {
  166. this.tokenChar(125);
  167. } else {
  168. this.newline();
  169. this.printSequence(node.body, node, {
  170. indent: true
  171. });
  172. this.rightBrace(node);
  173. }
  174. }
  175. //# sourceMappingURL=classes.js.map