classes.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.ClassDeclaration = ClassDeclaration;
  4. exports.ClassBody = ClassBody;
  5. exports.ClassProperty = ClassProperty;
  6. exports.ClassMethod = ClassMethod;
  7. function ClassDeclaration(node) {
  8. this.printJoin(node.decorators, node);
  9. this.word("class");
  10. if (node.id) {
  11. this.space();
  12. this.print(node.id, node);
  13. }
  14. this.print(node.typeParameters, node);
  15. if (node.superClass) {
  16. this.space();
  17. this.word("extends");
  18. this.space();
  19. this.print(node.superClass, node);
  20. this.print(node.superTypeParameters, node);
  21. }
  22. if (node.implements) {
  23. this.space();
  24. this.word("implements");
  25. this.space();
  26. this.printList(node.implements, node);
  27. }
  28. this.space();
  29. this.print(node.body, node);
  30. }
  31. exports.ClassExpression = ClassDeclaration;
  32. function ClassBody(node) {
  33. this.token("{");
  34. this.printInnerComments(node);
  35. if (node.body.length === 0) {
  36. this.token("}");
  37. } else {
  38. this.newline();
  39. this.indent();
  40. this.printSequence(node.body, node);
  41. this.dedent();
  42. if (!this.endsWith("\n")) this.newline();
  43. this.rightBrace();
  44. }
  45. }
  46. function ClassProperty(node) {
  47. this.printJoin(node.decorators, node);
  48. if (node.static) {
  49. this.word("static");
  50. this.space();
  51. }
  52. if (node.computed) {
  53. this.token("[");
  54. this.print(node.key, node);
  55. this.token("]");
  56. } else {
  57. this._variance(node);
  58. this.print(node.key, node);
  59. }
  60. this.print(node.typeAnnotation, node);
  61. if (node.value) {
  62. this.space();
  63. this.token("=");
  64. this.space();
  65. this.print(node.value, node);
  66. }
  67. this.semicolon();
  68. }
  69. function ClassMethod(node) {
  70. this.printJoin(node.decorators, node);
  71. if (node.static) {
  72. this.word("static");
  73. this.space();
  74. }
  75. if (node.kind === "constructorCall") {
  76. this.word("call");
  77. this.space();
  78. }
  79. this._method(node);
  80. }