1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.ClassExpression = exports.ClassDeclaration = ClassDeclaration;
|
---|
7 | exports.ClassBody = ClassBody;
|
---|
8 | exports.ClassProperty = ClassProperty;
|
---|
9 | exports.ClassPrivateProperty = ClassPrivateProperty;
|
---|
10 | exports.ClassMethod = ClassMethod;
|
---|
11 | exports.ClassPrivateMethod = ClassPrivateMethod;
|
---|
12 | exports._classMethodHead = _classMethodHead;
|
---|
13 | exports.StaticBlock = StaticBlock;
|
---|
14 |
|
---|
15 | var t = require("@babel/types");
|
---|
16 |
|
---|
17 | function ClassDeclaration(node, parent) {
|
---|
18 | if (!this.format.decoratorsBeforeExport || !t.isExportDefaultDeclaration(parent) && !t.isExportNamedDeclaration(parent)) {
|
---|
19 | this.printJoin(node.decorators, node);
|
---|
20 | }
|
---|
21 |
|
---|
22 | if (node.declare) {
|
---|
23 | this.word("declare");
|
---|
24 | this.space();
|
---|
25 | }
|
---|
26 |
|
---|
27 | if (node.abstract) {
|
---|
28 | this.word("abstract");
|
---|
29 | this.space();
|
---|
30 | }
|
---|
31 |
|
---|
32 | this.word("class");
|
---|
33 |
|
---|
34 | if (node.id) {
|
---|
35 | this.space();
|
---|
36 | this.print(node.id, node);
|
---|
37 | }
|
---|
38 |
|
---|
39 | this.print(node.typeParameters, node);
|
---|
40 |
|
---|
41 | if (node.superClass) {
|
---|
42 | this.space();
|
---|
43 | this.word("extends");
|
---|
44 | this.space();
|
---|
45 | this.print(node.superClass, node);
|
---|
46 | this.print(node.superTypeParameters, node);
|
---|
47 | }
|
---|
48 |
|
---|
49 | if (node.implements) {
|
---|
50 | this.space();
|
---|
51 | this.word("implements");
|
---|
52 | this.space();
|
---|
53 | this.printList(node.implements, node);
|
---|
54 | }
|
---|
55 |
|
---|
56 | this.space();
|
---|
57 | this.print(node.body, node);
|
---|
58 | }
|
---|
59 |
|
---|
60 | function ClassBody(node) {
|
---|
61 | this.token("{");
|
---|
62 | this.printInnerComments(node);
|
---|
63 |
|
---|
64 | if (node.body.length === 0) {
|
---|
65 | this.token("}");
|
---|
66 | } else {
|
---|
67 | this.newline();
|
---|
68 | this.indent();
|
---|
69 | this.printSequence(node.body, node);
|
---|
70 | this.dedent();
|
---|
71 | if (!this.endsWith("\n")) this.newline();
|
---|
72 | this.rightBrace();
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | function ClassProperty(node) {
|
---|
77 | this.printJoin(node.decorators, node);
|
---|
78 | this.source("end", node.key.loc);
|
---|
79 | this.tsPrintClassMemberModifiers(node, true);
|
---|
80 |
|
---|
81 | if (node.computed) {
|
---|
82 | this.token("[");
|
---|
83 | this.print(node.key, node);
|
---|
84 | this.token("]");
|
---|
85 | } else {
|
---|
86 | this._variance(node);
|
---|
87 |
|
---|
88 | this.print(node.key, node);
|
---|
89 | }
|
---|
90 |
|
---|
91 | if (node.optional) {
|
---|
92 | this.token("?");
|
---|
93 | }
|
---|
94 |
|
---|
95 | if (node.definite) {
|
---|
96 | this.token("!");
|
---|
97 | }
|
---|
98 |
|
---|
99 | this.print(node.typeAnnotation, node);
|
---|
100 |
|
---|
101 | if (node.value) {
|
---|
102 | this.space();
|
---|
103 | this.token("=");
|
---|
104 | this.space();
|
---|
105 | this.print(node.value, node);
|
---|
106 | }
|
---|
107 |
|
---|
108 | this.semicolon();
|
---|
109 | }
|
---|
110 |
|
---|
111 | function ClassPrivateProperty(node) {
|
---|
112 | this.printJoin(node.decorators, node);
|
---|
113 |
|
---|
114 | if (node.static) {
|
---|
115 | this.word("static");
|
---|
116 | this.space();
|
---|
117 | }
|
---|
118 |
|
---|
119 | this.print(node.key, node);
|
---|
120 | this.print(node.typeAnnotation, node);
|
---|
121 |
|
---|
122 | if (node.value) {
|
---|
123 | this.space();
|
---|
124 | this.token("=");
|
---|
125 | this.space();
|
---|
126 | this.print(node.value, node);
|
---|
127 | }
|
---|
128 |
|
---|
129 | this.semicolon();
|
---|
130 | }
|
---|
131 |
|
---|
132 | function ClassMethod(node) {
|
---|
133 | this._classMethodHead(node);
|
---|
134 |
|
---|
135 | this.space();
|
---|
136 | this.print(node.body, node);
|
---|
137 | }
|
---|
138 |
|
---|
139 | function ClassPrivateMethod(node) {
|
---|
140 | this._classMethodHead(node);
|
---|
141 |
|
---|
142 | this.space();
|
---|
143 | this.print(node.body, node);
|
---|
144 | }
|
---|
145 |
|
---|
146 | function _classMethodHead(node) {
|
---|
147 | this.printJoin(node.decorators, node);
|
---|
148 | this.source("end", node.key.loc);
|
---|
149 | this.tsPrintClassMemberModifiers(node, false);
|
---|
150 |
|
---|
151 | this._methodHead(node);
|
---|
152 | }
|
---|
153 |
|
---|
154 | function StaticBlock(node) {
|
---|
155 | this.word("static");
|
---|
156 | this.space();
|
---|
157 | this.token("{");
|
---|
158 |
|
---|
159 | if (node.body.length === 0) {
|
---|
160 | this.token("}");
|
---|
161 | } else {
|
---|
162 | this.newline();
|
---|
163 | this.printSequence(node.body, node, {
|
---|
164 | indent: true
|
---|
165 | });
|
---|
166 | this.rightBrace();
|
---|
167 | }
|
---|
168 | } |
---|