classes.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.ClassMethod = ClassMethod;
  9. exports._classMethodHead = _classMethodHead;
  10. function t() {
  11. var data = _interopRequireWildcard(require("@babel/types"));
  12. t = function t() {
  13. return data;
  14. };
  15. return data;
  16. }
  17. 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; } }
  18. function ClassDeclaration(node, parent) {
  19. if (!t().isExportDefaultDeclaration(parent) && !t().isExportNamedDeclaration(parent)) {
  20. this.printJoin(node.decorators, node);
  21. }
  22. if (node.declare) {
  23. this.word("declare");
  24. this.space();
  25. }
  26. if (node.abstract) {
  27. this.word("abstract");
  28. this.space();
  29. }
  30. this.word("class");
  31. if (node.id) {
  32. this.space();
  33. this.print(node.id, node);
  34. }
  35. this.print(node.typeParameters, node);
  36. if (node.superClass) {
  37. this.space();
  38. this.word("extends");
  39. this.space();
  40. this.print(node.superClass, node);
  41. this.print(node.superTypeParameters, node);
  42. }
  43. if (node.implements) {
  44. this.space();
  45. this.word("implements");
  46. this.space();
  47. this.printList(node.implements, node);
  48. }
  49. this.space();
  50. this.print(node.body, node);
  51. }
  52. function ClassBody(node) {
  53. this.token("{");
  54. this.printInnerComments(node);
  55. if (node.body.length === 0) {
  56. this.token("}");
  57. } else {
  58. this.newline();
  59. this.indent();
  60. this.printSequence(node.body, node);
  61. this.dedent();
  62. if (!this.endsWith("\n")) this.newline();
  63. this.rightBrace();
  64. }
  65. }
  66. function ClassProperty(node) {
  67. this.printJoin(node.decorators, node);
  68. if (node.accessibility) {
  69. this.word(node.accessibility);
  70. this.space();
  71. }
  72. if (node.static) {
  73. this.word("static");
  74. this.space();
  75. }
  76. if (node.abstract) {
  77. this.word("abstract");
  78. this.space();
  79. }
  80. if (node.readonly) {
  81. this.word("readonly");
  82. this.space();
  83. }
  84. if (node.computed) {
  85. this.token("[");
  86. this.print(node.key, node);
  87. this.token("]");
  88. } else {
  89. this._variance(node);
  90. this.print(node.key, node);
  91. }
  92. if (node.optional) {
  93. this.token("?");
  94. }
  95. if (node.definite) {
  96. this.token("!");
  97. }
  98. this.print(node.typeAnnotation, node);
  99. if (node.value) {
  100. this.space();
  101. this.token("=");
  102. this.space();
  103. this.print(node.value, node);
  104. }
  105. this.semicolon();
  106. }
  107. function ClassMethod(node) {
  108. this._classMethodHead(node);
  109. this.space();
  110. this.print(node.body, node);
  111. }
  112. function _classMethodHead(node) {
  113. this.printJoin(node.decorators, node);
  114. if (node.accessibility) {
  115. this.word(node.accessibility);
  116. this.space();
  117. }
  118. if (node.abstract) {
  119. this.word("abstract");
  120. this.space();
  121. }
  122. if (node.static) {
  123. this.word("static");
  124. this.space();
  125. }
  126. this._methodHead(node);
  127. }