1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.ClassAccessorProperty = ClassAccessorProperty;
|
---|
7 | exports.ClassBody = ClassBody;
|
---|
8 | exports.ClassExpression = exports.ClassDeclaration = ClassDeclaration;
|
---|
9 | exports.ClassMethod = ClassMethod;
|
---|
10 | exports.ClassPrivateMethod = ClassPrivateMethod;
|
---|
11 | exports.ClassPrivateProperty = ClassPrivateProperty;
|
---|
12 | exports.ClassProperty = ClassProperty;
|
---|
13 | exports.StaticBlock = StaticBlock;
|
---|
14 | exports._classMethodHead = _classMethodHead;
|
---|
15 | var _t = require("@babel/types");
|
---|
16 | const {
|
---|
17 | isExportDefaultDeclaration,
|
---|
18 | isExportNamedDeclaration
|
---|
19 | } = _t;
|
---|
20 | function ClassDeclaration(node, parent) {
|
---|
21 | const inExport = isExportDefaultDeclaration(parent) || isExportNamedDeclaration(parent);
|
---|
22 | if (!inExport || !this._shouldPrintDecoratorsBeforeExport(parent)) {
|
---|
23 | this.printJoin(node.decorators);
|
---|
24 | }
|
---|
25 | if (node.declare) {
|
---|
26 | this.word("declare");
|
---|
27 | this.space();
|
---|
28 | }
|
---|
29 | if (node.abstract) {
|
---|
30 | this.word("abstract");
|
---|
31 | this.space();
|
---|
32 | }
|
---|
33 | this.word("class");
|
---|
34 | if (node.id) {
|
---|
35 | this.space();
|
---|
36 | this.print(node.id);
|
---|
37 | }
|
---|
38 | this.print(node.typeParameters);
|
---|
39 | if (node.superClass) {
|
---|
40 | this.space();
|
---|
41 | this.word("extends");
|
---|
42 | this.space();
|
---|
43 | this.print(node.superClass);
|
---|
44 | this.print(node.superTypeParameters);
|
---|
45 | }
|
---|
46 | if (node.implements) {
|
---|
47 | this.space();
|
---|
48 | this.word("implements");
|
---|
49 | this.space();
|
---|
50 | this.printList(node.implements);
|
---|
51 | }
|
---|
52 | this.space();
|
---|
53 | this.print(node.body);
|
---|
54 | }
|
---|
55 | function ClassBody(node) {
|
---|
56 | this.tokenChar(123);
|
---|
57 | if (node.body.length === 0) {
|
---|
58 | this.tokenChar(125);
|
---|
59 | } else {
|
---|
60 | this.newline();
|
---|
61 | const separator = classBodyEmptySemicolonsPrinter(this, node);
|
---|
62 | separator == null || separator(-1);
|
---|
63 | const exit = this.enterDelimited();
|
---|
64 | this.printJoin(node.body, {
|
---|
65 | statement: true,
|
---|
66 | indent: true,
|
---|
67 | separator,
|
---|
68 | printTrailingSeparator: true
|
---|
69 | });
|
---|
70 | exit();
|
---|
71 | if (!this.endsWith(10)) this.newline();
|
---|
72 | this.rightBrace(node);
|
---|
73 | }
|
---|
74 | }
|
---|
75 | function classBodyEmptySemicolonsPrinter(printer, node) {
|
---|
76 | if (!printer.tokenMap || node.start == null || node.end == null) {
|
---|
77 | return null;
|
---|
78 | }
|
---|
79 | const indexes = printer.tokenMap.getIndexes(node);
|
---|
80 | if (!indexes) return null;
|
---|
81 | let k = 1;
|
---|
82 | let occurrenceCount = 0;
|
---|
83 | let nextLocIndex = 0;
|
---|
84 | const advanceNextLocIndex = () => {
|
---|
85 | while (nextLocIndex < node.body.length && node.body[nextLocIndex].start == null) {
|
---|
86 | nextLocIndex++;
|
---|
87 | }
|
---|
88 | };
|
---|
89 | advanceNextLocIndex();
|
---|
90 | return i => {
|
---|
91 | if (nextLocIndex <= i) {
|
---|
92 | nextLocIndex = i + 1;
|
---|
93 | advanceNextLocIndex();
|
---|
94 | }
|
---|
95 | const end = nextLocIndex === node.body.length ? node.end : node.body[nextLocIndex].start;
|
---|
96 | let tok;
|
---|
97 | while (k < indexes.length && printer.tokenMap.matchesOriginal(tok = printer._tokens[indexes[k]], ";") && tok.start < end) {
|
---|
98 | printer.token(";", undefined, occurrenceCount++);
|
---|
99 | k++;
|
---|
100 | }
|
---|
101 | };
|
---|
102 | }
|
---|
103 | function ClassProperty(node) {
|
---|
104 | this.printJoin(node.decorators);
|
---|
105 | if (!node.static && !this.format.preserveFormat) {
|
---|
106 | var _node$key$loc;
|
---|
107 | const endLine = (_node$key$loc = node.key.loc) == null || (_node$key$loc = _node$key$loc.end) == null ? void 0 : _node$key$loc.line;
|
---|
108 | if (endLine) this.catchUp(endLine);
|
---|
109 | }
|
---|
110 | this.tsPrintClassMemberModifiers(node);
|
---|
111 | if (node.computed) {
|
---|
112 | this.tokenChar(91);
|
---|
113 | this.print(node.key);
|
---|
114 | this.tokenChar(93);
|
---|
115 | } else {
|
---|
116 | this._variance(node);
|
---|
117 | this.print(node.key);
|
---|
118 | }
|
---|
119 | if (node.optional) {
|
---|
120 | this.tokenChar(63);
|
---|
121 | }
|
---|
122 | if (node.definite) {
|
---|
123 | this.tokenChar(33);
|
---|
124 | }
|
---|
125 | this.print(node.typeAnnotation);
|
---|
126 | if (node.value) {
|
---|
127 | this.space();
|
---|
128 | this.tokenChar(61);
|
---|
129 | this.space();
|
---|
130 | this.print(node.value);
|
---|
131 | }
|
---|
132 | this.semicolon();
|
---|
133 | }
|
---|
134 | function ClassAccessorProperty(node) {
|
---|
135 | var _node$key$loc2;
|
---|
136 | this.printJoin(node.decorators);
|
---|
137 | const endLine = (_node$key$loc2 = node.key.loc) == null || (_node$key$loc2 = _node$key$loc2.end) == null ? void 0 : _node$key$loc2.line;
|
---|
138 | if (endLine) this.catchUp(endLine);
|
---|
139 | this.tsPrintClassMemberModifiers(node);
|
---|
140 | this.word("accessor", true);
|
---|
141 | this.space();
|
---|
142 | if (node.computed) {
|
---|
143 | this.tokenChar(91);
|
---|
144 | this.print(node.key);
|
---|
145 | this.tokenChar(93);
|
---|
146 | } else {
|
---|
147 | this._variance(node);
|
---|
148 | this.print(node.key);
|
---|
149 | }
|
---|
150 | if (node.optional) {
|
---|
151 | this.tokenChar(63);
|
---|
152 | }
|
---|
153 | if (node.definite) {
|
---|
154 | this.tokenChar(33);
|
---|
155 | }
|
---|
156 | this.print(node.typeAnnotation);
|
---|
157 | if (node.value) {
|
---|
158 | this.space();
|
---|
159 | this.tokenChar(61);
|
---|
160 | this.space();
|
---|
161 | this.print(node.value);
|
---|
162 | }
|
---|
163 | this.semicolon();
|
---|
164 | }
|
---|
165 | function ClassPrivateProperty(node) {
|
---|
166 | this.printJoin(node.decorators);
|
---|
167 | if (node.static) {
|
---|
168 | this.word("static");
|
---|
169 | this.space();
|
---|
170 | }
|
---|
171 | this.print(node.key);
|
---|
172 | this.print(node.typeAnnotation);
|
---|
173 | if (node.value) {
|
---|
174 | this.space();
|
---|
175 | this.tokenChar(61);
|
---|
176 | this.space();
|
---|
177 | this.print(node.value);
|
---|
178 | }
|
---|
179 | this.semicolon();
|
---|
180 | }
|
---|
181 | function ClassMethod(node) {
|
---|
182 | this._classMethodHead(node);
|
---|
183 | this.space();
|
---|
184 | this.print(node.body);
|
---|
185 | }
|
---|
186 | function ClassPrivateMethod(node) {
|
---|
187 | this._classMethodHead(node);
|
---|
188 | this.space();
|
---|
189 | this.print(node.body);
|
---|
190 | }
|
---|
191 | function _classMethodHead(node) {
|
---|
192 | this.printJoin(node.decorators);
|
---|
193 | if (!this.format.preserveFormat) {
|
---|
194 | var _node$key$loc3;
|
---|
195 | const endLine = (_node$key$loc3 = node.key.loc) == null || (_node$key$loc3 = _node$key$loc3.end) == null ? void 0 : _node$key$loc3.line;
|
---|
196 | if (endLine) this.catchUp(endLine);
|
---|
197 | }
|
---|
198 | this.tsPrintClassMemberModifiers(node);
|
---|
199 | this._methodHead(node);
|
---|
200 | }
|
---|
201 | function StaticBlock(node) {
|
---|
202 | this.word("static");
|
---|
203 | this.space();
|
---|
204 | this.tokenChar(123);
|
---|
205 | if (node.body.length === 0) {
|
---|
206 | this.tokenChar(125);
|
---|
207 | } else {
|
---|
208 | this.newline();
|
---|
209 | this.printSequence(node.body, {
|
---|
210 | indent: true
|
---|
211 | });
|
---|
212 | this.rightBrace(node);
|
---|
213 | }
|
---|
214 | }
|
---|
215 |
|
---|
216 | //# sourceMappingURL=classes.js.map
|
---|