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, true, true, separator, true);
|
---|
65 | exit();
|
---|
66 | if (!this.endsWith(10)) this.newline();
|
---|
67 | this.rightBrace(node);
|
---|
68 | }
|
---|
69 | }
|
---|
70 | function classBodyEmptySemicolonsPrinter(printer, node) {
|
---|
71 | if (!printer.tokenMap || node.start == null || node.end == null) {
|
---|
72 | return null;
|
---|
73 | }
|
---|
74 | const indexes = printer.tokenMap.getIndexes(node);
|
---|
75 | if (!indexes) return null;
|
---|
76 | let k = 1;
|
---|
77 | let occurrenceCount = 0;
|
---|
78 | let nextLocIndex = 0;
|
---|
79 | const advanceNextLocIndex = () => {
|
---|
80 | while (nextLocIndex < node.body.length && node.body[nextLocIndex].start == null) {
|
---|
81 | nextLocIndex++;
|
---|
82 | }
|
---|
83 | };
|
---|
84 | advanceNextLocIndex();
|
---|
85 | return i => {
|
---|
86 | if (nextLocIndex <= i) {
|
---|
87 | nextLocIndex = i + 1;
|
---|
88 | advanceNextLocIndex();
|
---|
89 | }
|
---|
90 | const end = nextLocIndex === node.body.length ? node.end : node.body[nextLocIndex].start;
|
---|
91 | let tok;
|
---|
92 | while (k < indexes.length && printer.tokenMap.matchesOriginal(tok = printer._tokens[indexes[k]], ";") && tok.start < end) {
|
---|
93 | printer.token(";", undefined, occurrenceCount++);
|
---|
94 | k++;
|
---|
95 | }
|
---|
96 | };
|
---|
97 | }
|
---|
98 | function ClassProperty(node) {
|
---|
99 | this.printJoin(node.decorators);
|
---|
100 | if (!node.static && !this.format.preserveFormat) {
|
---|
101 | var _node$key$loc;
|
---|
102 | const endLine = (_node$key$loc = node.key.loc) == null || (_node$key$loc = _node$key$loc.end) == null ? void 0 : _node$key$loc.line;
|
---|
103 | if (endLine) this.catchUp(endLine);
|
---|
104 | }
|
---|
105 | this.tsPrintClassMemberModifiers(node);
|
---|
106 | if (node.computed) {
|
---|
107 | this.tokenChar(91);
|
---|
108 | this.print(node.key);
|
---|
109 | this.tokenChar(93);
|
---|
110 | } else {
|
---|
111 | this._variance(node);
|
---|
112 | this.print(node.key);
|
---|
113 | }
|
---|
114 | if (node.optional) {
|
---|
115 | this.tokenChar(63);
|
---|
116 | }
|
---|
117 | if (node.definite) {
|
---|
118 | this.tokenChar(33);
|
---|
119 | }
|
---|
120 | this.print(node.typeAnnotation);
|
---|
121 | if (node.value) {
|
---|
122 | this.space();
|
---|
123 | this.tokenChar(61);
|
---|
124 | this.space();
|
---|
125 | this.print(node.value);
|
---|
126 | }
|
---|
127 | this.semicolon();
|
---|
128 | }
|
---|
129 | function ClassAccessorProperty(node) {
|
---|
130 | var _node$key$loc2;
|
---|
131 | this.printJoin(node.decorators);
|
---|
132 | const endLine = (_node$key$loc2 = node.key.loc) == null || (_node$key$loc2 = _node$key$loc2.end) == null ? void 0 : _node$key$loc2.line;
|
---|
133 | if (endLine) this.catchUp(endLine);
|
---|
134 | this.tsPrintClassMemberModifiers(node);
|
---|
135 | this.word("accessor", true);
|
---|
136 | this.space();
|
---|
137 | if (node.computed) {
|
---|
138 | this.tokenChar(91);
|
---|
139 | this.print(node.key);
|
---|
140 | this.tokenChar(93);
|
---|
141 | } else {
|
---|
142 | this._variance(node);
|
---|
143 | this.print(node.key);
|
---|
144 | }
|
---|
145 | if (node.optional) {
|
---|
146 | this.tokenChar(63);
|
---|
147 | }
|
---|
148 | if (node.definite) {
|
---|
149 | this.tokenChar(33);
|
---|
150 | }
|
---|
151 | this.print(node.typeAnnotation);
|
---|
152 | if (node.value) {
|
---|
153 | this.space();
|
---|
154 | this.tokenChar(61);
|
---|
155 | this.space();
|
---|
156 | this.print(node.value);
|
---|
157 | }
|
---|
158 | this.semicolon();
|
---|
159 | }
|
---|
160 | function ClassPrivateProperty(node) {
|
---|
161 | this.printJoin(node.decorators);
|
---|
162 | if (node.static) {
|
---|
163 | this.word("static");
|
---|
164 | this.space();
|
---|
165 | }
|
---|
166 | this.print(node.key);
|
---|
167 | this.print(node.typeAnnotation);
|
---|
168 | if (node.value) {
|
---|
169 | this.space();
|
---|
170 | this.tokenChar(61);
|
---|
171 | this.space();
|
---|
172 | this.print(node.value);
|
---|
173 | }
|
---|
174 | this.semicolon();
|
---|
175 | }
|
---|
176 | function ClassMethod(node) {
|
---|
177 | this._classMethodHead(node);
|
---|
178 | this.space();
|
---|
179 | this.print(node.body);
|
---|
180 | }
|
---|
181 | function ClassPrivateMethod(node) {
|
---|
182 | this._classMethodHead(node);
|
---|
183 | this.space();
|
---|
184 | this.print(node.body);
|
---|
185 | }
|
---|
186 | function _classMethodHead(node) {
|
---|
187 | this.printJoin(node.decorators);
|
---|
188 | if (!this.format.preserveFormat) {
|
---|
189 | var _node$key$loc3;
|
---|
190 | const endLine = (_node$key$loc3 = node.key.loc) == null || (_node$key$loc3 = _node$key$loc3.end) == null ? void 0 : _node$key$loc3.line;
|
---|
191 | if (endLine) this.catchUp(endLine);
|
---|
192 | }
|
---|
193 | this.tsPrintClassMemberModifiers(node);
|
---|
194 | this._methodHead(node);
|
---|
195 | }
|
---|
196 | function StaticBlock(node) {
|
---|
197 | this.word("static");
|
---|
198 | this.space();
|
---|
199 | this.tokenChar(123);
|
---|
200 | if (node.body.length === 0) {
|
---|
201 | this.tokenChar(125);
|
---|
202 | } else {
|
---|
203 | this.newline();
|
---|
204 | this.printSequence(node.body, true);
|
---|
205 | this.rightBrace(node);
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | //# sourceMappingURL=classes.js.map
|
---|