You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
3.8 KiB

4 years ago
  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. var t = _interopRequireWildcard(require("@babel/types"));
  13. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  14. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  15. function ClassDeclaration(node, parent) {
  16. if (!this.format.decoratorsBeforeExport || !t.isExportDefaultDeclaration(parent) && !t.isExportNamedDeclaration(parent)) {
  17. this.printJoin(node.decorators, node);
  18. }
  19. if (node.declare) {
  20. this.word("declare");
  21. this.space();
  22. }
  23. if (node.abstract) {
  24. this.word("abstract");
  25. this.space();
  26. }
  27. this.word("class");
  28. if (node.id) {
  29. this.space();
  30. this.print(node.id, node);
  31. }
  32. this.print(node.typeParameters, node);
  33. if (node.superClass) {
  34. this.space();
  35. this.word("extends");
  36. this.space();
  37. this.print(node.superClass, node);
  38. this.print(node.superTypeParameters, node);
  39. }
  40. if (node.implements) {
  41. this.space();
  42. this.word("implements");
  43. this.space();
  44. this.printList(node.implements, node);
  45. }
  46. this.space();
  47. this.print(node.body, node);
  48. }
  49. function ClassBody(node) {
  50. this.token("{");
  51. this.printInnerComments(node);
  52. if (node.body.length === 0) {
  53. this.token("}");
  54. } else {
  55. this.newline();
  56. this.indent();
  57. this.printSequence(node.body, node);
  58. this.dedent();
  59. if (!this.endsWith("\n")) this.newline();
  60. this.rightBrace();
  61. }
  62. }
  63. function ClassProperty(node) {
  64. this.printJoin(node.decorators, node);
  65. this.tsPrintClassMemberModifiers(node, true);
  66. if (node.computed) {
  67. this.token("[");
  68. this.print(node.key, node);
  69. this.token("]");
  70. } else {
  71. this._variance(node);
  72. this.print(node.key, node);
  73. }
  74. if (node.optional) {
  75. this.token("?");
  76. }
  77. if (node.definite) {
  78. this.token("!");
  79. }
  80. this.print(node.typeAnnotation, node);
  81. if (node.value) {
  82. this.space();
  83. this.token("=");
  84. this.space();
  85. this.print(node.value, node);
  86. }
  87. this.semicolon();
  88. }
  89. function ClassPrivateProperty(node) {
  90. if (node.static) {
  91. this.word("static");
  92. this.space();
  93. }
  94. this.print(node.key, node);
  95. this.print(node.typeAnnotation, node);
  96. if (node.value) {
  97. this.space();
  98. this.token("=");
  99. this.space();
  100. this.print(node.value, node);
  101. }
  102. this.semicolon();
  103. }
  104. function ClassMethod(node) {
  105. this._classMethodHead(node);
  106. this.space();
  107. this.print(node.body, node);
  108. }
  109. function ClassPrivateMethod(node) {
  110. this._classMethodHead(node);
  111. this.space();
  112. this.print(node.body, node);
  113. }
  114. function _classMethodHead(node) {
  115. this.printJoin(node.decorators, node);
  116. this.tsPrintClassMemberModifiers(node, false);
  117. this._methodHead(node);
  118. }