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, node);
|
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, node);
|
37 | }
|
38 | this.print(node.typeParameters, node);
|
39 | if (node.superClass) {
|
40 | this.space();
|
41 | this.word("extends");
|
42 | this.space();
|
43 | this.print(node.superClass, node);
|
44 | this.print(node.superTypeParameters, node);
|
45 | }
|
46 | if (node.implements) {
|
47 | this.space();
|
48 | this.word("implements");
|
49 | this.space();
|
50 | this.printList(node.implements, node);
|
51 | }
|
52 | this.space();
|
53 | this.print(node.body, node);
|
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 | this.printSequence(node.body, node, {
|
62 | indent: true
|
63 | });
|
64 | if (!this.endsWith(10)) this.newline();
|
65 | this.rightBrace(node);
|
66 | }
|
67 | }
|
68 | function ClassProperty(node) {
|
69 | var _node$key$loc;
|
70 | this.printJoin(node.decorators, node);
|
71 | const endLine = (_node$key$loc = node.key.loc) == null || (_node$key$loc = _node$key$loc.end) == null ? void 0 : _node$key$loc.line;
|
72 | if (endLine) this.catchUp(endLine);
|
73 | this.tsPrintClassMemberModifiers(node);
|
74 | if (node.computed) {
|
75 | this.tokenChar(91);
|
76 | this.print(node.key, node);
|
77 | this.tokenChar(93);
|
78 | } else {
|
79 | this._variance(node);
|
80 | this.print(node.key, node);
|
81 | }
|
82 | if (node.optional) {
|
83 | this.tokenChar(63);
|
84 | }
|
85 | if (node.definite) {
|
86 | this.tokenChar(33);
|
87 | }
|
88 | this.print(node.typeAnnotation, node);
|
89 | if (node.value) {
|
90 | this.space();
|
91 | this.tokenChar(61);
|
92 | this.space();
|
93 | this.print(node.value, node);
|
94 | }
|
95 | this.semicolon();
|
96 | }
|
97 | function ClassAccessorProperty(node) {
|
98 | var _node$key$loc2;
|
99 | this.printJoin(node.decorators, node);
|
100 | const endLine = (_node$key$loc2 = node.key.loc) == null || (_node$key$loc2 = _node$key$loc2.end) == null ? void 0 : _node$key$loc2.line;
|
101 | if (endLine) this.catchUp(endLine);
|
102 | this.tsPrintClassMemberModifiers(node);
|
103 | this.word("accessor", true);
|
104 | this.space();
|
105 | if (node.computed) {
|
106 | this.tokenChar(91);
|
107 | this.print(node.key, node);
|
108 | this.tokenChar(93);
|
109 | } else {
|
110 | this._variance(node);
|
111 | this.print(node.key, node);
|
112 | }
|
113 | if (node.optional) {
|
114 | this.tokenChar(63);
|
115 | }
|
116 | if (node.definite) {
|
117 | this.tokenChar(33);
|
118 | }
|
119 | this.print(node.typeAnnotation, node);
|
120 | if (node.value) {
|
121 | this.space();
|
122 | this.tokenChar(61);
|
123 | this.space();
|
124 | this.print(node.value, node);
|
125 | }
|
126 | this.semicolon();
|
127 | }
|
128 | function ClassPrivateProperty(node) {
|
129 | this.printJoin(node.decorators, node);
|
130 | if (node.static) {
|
131 | this.word("static");
|
132 | this.space();
|
133 | }
|
134 | this.print(node.key, node);
|
135 | this.print(node.typeAnnotation, node);
|
136 | if (node.value) {
|
137 | this.space();
|
138 | this.tokenChar(61);
|
139 | this.space();
|
140 | this.print(node.value, node);
|
141 | }
|
142 | this.semicolon();
|
143 | }
|
144 | function ClassMethod(node) {
|
145 | this._classMethodHead(node);
|
146 | this.space();
|
147 | this.print(node.body, node);
|
148 | }
|
149 | function ClassPrivateMethod(node) {
|
150 | this._classMethodHead(node);
|
151 | this.space();
|
152 | this.print(node.body, node);
|
153 | }
|
154 | function _classMethodHead(node) {
|
155 | var _node$key$loc3;
|
156 | this.printJoin(node.decorators, node);
|
157 | const endLine = (_node$key$loc3 = node.key.loc) == null || (_node$key$loc3 = _node$key$loc3.end) == null ? void 0 : _node$key$loc3.line;
|
158 | if (endLine) this.catchUp(endLine);
|
159 | this.tsPrintClassMemberModifiers(node);
|
160 | this._methodHead(node);
|
161 | }
|
162 | function StaticBlock(node) {
|
163 | this.word("static");
|
164 | this.space();
|
165 | this.tokenChar(123);
|
166 | if (node.body.length === 0) {
|
167 | this.tokenChar(125);
|
168 | } else {
|
169 | this.newline();
|
170 | this.printSequence(node.body, node, {
|
171 | indent: true
|
172 | });
|
173 | this.rightBrace(node);
|
174 | }
|
175 | }
|
176 |
|
177 |
|