classes.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. this.print(node.key, node);
  53. this.print(node.typeAnnotation, node);
  54. if (node.value) {
  55. this.space();
  56. this.token("=");
  57. this.space();
  58. this.print(node.value, node);
  59. }
  60. this.semicolon();
  61. }
  62. function ClassMethod(node) {
  63. this.printJoin(node.decorators, node);
  64. if (node.static) {
  65. this.word("static");
  66. this.space();
  67. }
  68. if (node.kind === "constructorCall") {
  69. this.word("call");
  70. this.space();
  71. }
  72. this._method(node);
  73. }