1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.AnyTypeAnnotation = AnyTypeAnnotation;
|
---|
7 | exports.ArrayTypeAnnotation = ArrayTypeAnnotation;
|
---|
8 | exports.BooleanTypeAnnotation = BooleanTypeAnnotation;
|
---|
9 | exports.BooleanLiteralTypeAnnotation = BooleanLiteralTypeAnnotation;
|
---|
10 | exports.NullLiteralTypeAnnotation = NullLiteralTypeAnnotation;
|
---|
11 | exports.DeclareClass = DeclareClass;
|
---|
12 | exports.DeclareFunction = DeclareFunction;
|
---|
13 | exports.InferredPredicate = InferredPredicate;
|
---|
14 | exports.DeclaredPredicate = DeclaredPredicate;
|
---|
15 | exports.DeclareInterface = DeclareInterface;
|
---|
16 | exports.DeclareModule = DeclareModule;
|
---|
17 | exports.DeclareModuleExports = DeclareModuleExports;
|
---|
18 | exports.DeclareTypeAlias = DeclareTypeAlias;
|
---|
19 | exports.DeclareOpaqueType = DeclareOpaqueType;
|
---|
20 | exports.DeclareVariable = DeclareVariable;
|
---|
21 | exports.DeclareExportDeclaration = DeclareExportDeclaration;
|
---|
22 | exports.DeclareExportAllDeclaration = DeclareExportAllDeclaration;
|
---|
23 | exports.EnumDeclaration = EnumDeclaration;
|
---|
24 | exports.EnumBooleanBody = EnumBooleanBody;
|
---|
25 | exports.EnumNumberBody = EnumNumberBody;
|
---|
26 | exports.EnumStringBody = EnumStringBody;
|
---|
27 | exports.EnumSymbolBody = EnumSymbolBody;
|
---|
28 | exports.EnumDefaultedMember = EnumDefaultedMember;
|
---|
29 | exports.EnumBooleanMember = EnumBooleanMember;
|
---|
30 | exports.EnumNumberMember = EnumNumberMember;
|
---|
31 | exports.EnumStringMember = EnumStringMember;
|
---|
32 | exports.ExistsTypeAnnotation = ExistsTypeAnnotation;
|
---|
33 | exports.FunctionTypeAnnotation = FunctionTypeAnnotation;
|
---|
34 | exports.FunctionTypeParam = FunctionTypeParam;
|
---|
35 | exports.GenericTypeAnnotation = exports.ClassImplements = exports.InterfaceExtends = InterfaceExtends;
|
---|
36 | exports._interfaceish = _interfaceish;
|
---|
37 | exports._variance = _variance;
|
---|
38 | exports.InterfaceDeclaration = InterfaceDeclaration;
|
---|
39 | exports.InterfaceTypeAnnotation = InterfaceTypeAnnotation;
|
---|
40 | exports.IntersectionTypeAnnotation = IntersectionTypeAnnotation;
|
---|
41 | exports.MixedTypeAnnotation = MixedTypeAnnotation;
|
---|
42 | exports.EmptyTypeAnnotation = EmptyTypeAnnotation;
|
---|
43 | exports.NullableTypeAnnotation = NullableTypeAnnotation;
|
---|
44 | exports.NumberTypeAnnotation = NumberTypeAnnotation;
|
---|
45 | exports.StringTypeAnnotation = StringTypeAnnotation;
|
---|
46 | exports.ThisTypeAnnotation = ThisTypeAnnotation;
|
---|
47 | exports.TupleTypeAnnotation = TupleTypeAnnotation;
|
---|
48 | exports.TypeofTypeAnnotation = TypeofTypeAnnotation;
|
---|
49 | exports.TypeAlias = TypeAlias;
|
---|
50 | exports.TypeAnnotation = TypeAnnotation;
|
---|
51 | exports.TypeParameterDeclaration = exports.TypeParameterInstantiation = TypeParameterInstantiation;
|
---|
52 | exports.TypeParameter = TypeParameter;
|
---|
53 | exports.OpaqueType = OpaqueType;
|
---|
54 | exports.ObjectTypeAnnotation = ObjectTypeAnnotation;
|
---|
55 | exports.ObjectTypeInternalSlot = ObjectTypeInternalSlot;
|
---|
56 | exports.ObjectTypeCallProperty = ObjectTypeCallProperty;
|
---|
57 | exports.ObjectTypeIndexer = ObjectTypeIndexer;
|
---|
58 | exports.ObjectTypeProperty = ObjectTypeProperty;
|
---|
59 | exports.ObjectTypeSpreadProperty = ObjectTypeSpreadProperty;
|
---|
60 | exports.QualifiedTypeIdentifier = QualifiedTypeIdentifier;
|
---|
61 | exports.SymbolTypeAnnotation = SymbolTypeAnnotation;
|
---|
62 | exports.UnionTypeAnnotation = UnionTypeAnnotation;
|
---|
63 | exports.TypeCastExpression = TypeCastExpression;
|
---|
64 | exports.Variance = Variance;
|
---|
65 | exports.VoidTypeAnnotation = VoidTypeAnnotation;
|
---|
66 | exports.IndexedAccessType = IndexedAccessType;
|
---|
67 | exports.OptionalIndexedAccessType = OptionalIndexedAccessType;
|
---|
68 | Object.defineProperty(exports, "NumberLiteralTypeAnnotation", {
|
---|
69 | enumerable: true,
|
---|
70 | get: function () {
|
---|
71 | return _types2.NumericLiteral;
|
---|
72 | }
|
---|
73 | });
|
---|
74 | Object.defineProperty(exports, "StringLiteralTypeAnnotation", {
|
---|
75 | enumerable: true,
|
---|
76 | get: function () {
|
---|
77 | return _types2.StringLiteral;
|
---|
78 | }
|
---|
79 | });
|
---|
80 |
|
---|
81 | var t = require("@babel/types");
|
---|
82 |
|
---|
83 | var _modules = require("./modules");
|
---|
84 |
|
---|
85 | var _types2 = require("./types");
|
---|
86 |
|
---|
87 | function AnyTypeAnnotation() {
|
---|
88 | this.word("any");
|
---|
89 | }
|
---|
90 |
|
---|
91 | function ArrayTypeAnnotation(node) {
|
---|
92 | this.print(node.elementType, node);
|
---|
93 | this.token("[");
|
---|
94 | this.token("]");
|
---|
95 | }
|
---|
96 |
|
---|
97 | function BooleanTypeAnnotation() {
|
---|
98 | this.word("boolean");
|
---|
99 | }
|
---|
100 |
|
---|
101 | function BooleanLiteralTypeAnnotation(node) {
|
---|
102 | this.word(node.value ? "true" : "false");
|
---|
103 | }
|
---|
104 |
|
---|
105 | function NullLiteralTypeAnnotation() {
|
---|
106 | this.word("null");
|
---|
107 | }
|
---|
108 |
|
---|
109 | function DeclareClass(node, parent) {
|
---|
110 | if (!t.isDeclareExportDeclaration(parent)) {
|
---|
111 | this.word("declare");
|
---|
112 | this.space();
|
---|
113 | }
|
---|
114 |
|
---|
115 | this.word("class");
|
---|
116 | this.space();
|
---|
117 |
|
---|
118 | this._interfaceish(node);
|
---|
119 | }
|
---|
120 |
|
---|
121 | function DeclareFunction(node, parent) {
|
---|
122 | if (!t.isDeclareExportDeclaration(parent)) {
|
---|
123 | this.word("declare");
|
---|
124 | this.space();
|
---|
125 | }
|
---|
126 |
|
---|
127 | this.word("function");
|
---|
128 | this.space();
|
---|
129 | this.print(node.id, node);
|
---|
130 | this.print(node.id.typeAnnotation.typeAnnotation, node);
|
---|
131 |
|
---|
132 | if (node.predicate) {
|
---|
133 | this.space();
|
---|
134 | this.print(node.predicate, node);
|
---|
135 | }
|
---|
136 |
|
---|
137 | this.semicolon();
|
---|
138 | }
|
---|
139 |
|
---|
140 | function InferredPredicate() {
|
---|
141 | this.token("%");
|
---|
142 | this.word("checks");
|
---|
143 | }
|
---|
144 |
|
---|
145 | function DeclaredPredicate(node) {
|
---|
146 | this.token("%");
|
---|
147 | this.word("checks");
|
---|
148 | this.token("(");
|
---|
149 | this.print(node.value, node);
|
---|
150 | this.token(")");
|
---|
151 | }
|
---|
152 |
|
---|
153 | function DeclareInterface(node) {
|
---|
154 | this.word("declare");
|
---|
155 | this.space();
|
---|
156 | this.InterfaceDeclaration(node);
|
---|
157 | }
|
---|
158 |
|
---|
159 | function DeclareModule(node) {
|
---|
160 | this.word("declare");
|
---|
161 | this.space();
|
---|
162 | this.word("module");
|
---|
163 | this.space();
|
---|
164 | this.print(node.id, node);
|
---|
165 | this.space();
|
---|
166 | this.print(node.body, node);
|
---|
167 | }
|
---|
168 |
|
---|
169 | function DeclareModuleExports(node) {
|
---|
170 | this.word("declare");
|
---|
171 | this.space();
|
---|
172 | this.word("module");
|
---|
173 | this.token(".");
|
---|
174 | this.word("exports");
|
---|
175 | this.print(node.typeAnnotation, node);
|
---|
176 | }
|
---|
177 |
|
---|
178 | function DeclareTypeAlias(node) {
|
---|
179 | this.word("declare");
|
---|
180 | this.space();
|
---|
181 | this.TypeAlias(node);
|
---|
182 | }
|
---|
183 |
|
---|
184 | function DeclareOpaqueType(node, parent) {
|
---|
185 | if (!t.isDeclareExportDeclaration(parent)) {
|
---|
186 | this.word("declare");
|
---|
187 | this.space();
|
---|
188 | }
|
---|
189 |
|
---|
190 | this.OpaqueType(node);
|
---|
191 | }
|
---|
192 |
|
---|
193 | function DeclareVariable(node, parent) {
|
---|
194 | if (!t.isDeclareExportDeclaration(parent)) {
|
---|
195 | this.word("declare");
|
---|
196 | this.space();
|
---|
197 | }
|
---|
198 |
|
---|
199 | this.word("var");
|
---|
200 | this.space();
|
---|
201 | this.print(node.id, node);
|
---|
202 | this.print(node.id.typeAnnotation, node);
|
---|
203 | this.semicolon();
|
---|
204 | }
|
---|
205 |
|
---|
206 | function DeclareExportDeclaration(node) {
|
---|
207 | this.word("declare");
|
---|
208 | this.space();
|
---|
209 | this.word("export");
|
---|
210 | this.space();
|
---|
211 |
|
---|
212 | if (node.default) {
|
---|
213 | this.word("default");
|
---|
214 | this.space();
|
---|
215 | }
|
---|
216 |
|
---|
217 | FlowExportDeclaration.apply(this, arguments);
|
---|
218 | }
|
---|
219 |
|
---|
220 | function DeclareExportAllDeclaration() {
|
---|
221 | this.word("declare");
|
---|
222 | this.space();
|
---|
223 |
|
---|
224 | _modules.ExportAllDeclaration.apply(this, arguments);
|
---|
225 | }
|
---|
226 |
|
---|
227 | function EnumDeclaration(node) {
|
---|
228 | const {
|
---|
229 | id,
|
---|
230 | body
|
---|
231 | } = node;
|
---|
232 | this.word("enum");
|
---|
233 | this.space();
|
---|
234 | this.print(id, node);
|
---|
235 | this.print(body, node);
|
---|
236 | }
|
---|
237 |
|
---|
238 | function enumExplicitType(context, name, hasExplicitType) {
|
---|
239 | if (hasExplicitType) {
|
---|
240 | context.space();
|
---|
241 | context.word("of");
|
---|
242 | context.space();
|
---|
243 | context.word(name);
|
---|
244 | }
|
---|
245 |
|
---|
246 | context.space();
|
---|
247 | }
|
---|
248 |
|
---|
249 | function enumBody(context, node) {
|
---|
250 | const {
|
---|
251 | members
|
---|
252 | } = node;
|
---|
253 | context.token("{");
|
---|
254 | context.indent();
|
---|
255 | context.newline();
|
---|
256 |
|
---|
257 | for (const member of members) {
|
---|
258 | context.print(member, node);
|
---|
259 | context.newline();
|
---|
260 | }
|
---|
261 |
|
---|
262 | if (node.hasUnknownMembers) {
|
---|
263 | context.token("...");
|
---|
264 | context.newline();
|
---|
265 | }
|
---|
266 |
|
---|
267 | context.dedent();
|
---|
268 | context.token("}");
|
---|
269 | }
|
---|
270 |
|
---|
271 | function EnumBooleanBody(node) {
|
---|
272 | const {
|
---|
273 | explicitType
|
---|
274 | } = node;
|
---|
275 | enumExplicitType(this, "boolean", explicitType);
|
---|
276 | enumBody(this, node);
|
---|
277 | }
|
---|
278 |
|
---|
279 | function EnumNumberBody(node) {
|
---|
280 | const {
|
---|
281 | explicitType
|
---|
282 | } = node;
|
---|
283 | enumExplicitType(this, "number", explicitType);
|
---|
284 | enumBody(this, node);
|
---|
285 | }
|
---|
286 |
|
---|
287 | function EnumStringBody(node) {
|
---|
288 | const {
|
---|
289 | explicitType
|
---|
290 | } = node;
|
---|
291 | enumExplicitType(this, "string", explicitType);
|
---|
292 | enumBody(this, node);
|
---|
293 | }
|
---|
294 |
|
---|
295 | function EnumSymbolBody(node) {
|
---|
296 | enumExplicitType(this, "symbol", true);
|
---|
297 | enumBody(this, node);
|
---|
298 | }
|
---|
299 |
|
---|
300 | function EnumDefaultedMember(node) {
|
---|
301 | const {
|
---|
302 | id
|
---|
303 | } = node;
|
---|
304 | this.print(id, node);
|
---|
305 | this.token(",");
|
---|
306 | }
|
---|
307 |
|
---|
308 | function enumInitializedMember(context, node) {
|
---|
309 | const {
|
---|
310 | id,
|
---|
311 | init
|
---|
312 | } = node;
|
---|
313 | context.print(id, node);
|
---|
314 | context.space();
|
---|
315 | context.token("=");
|
---|
316 | context.space();
|
---|
317 | context.print(init, node);
|
---|
318 | context.token(",");
|
---|
319 | }
|
---|
320 |
|
---|
321 | function EnumBooleanMember(node) {
|
---|
322 | enumInitializedMember(this, node);
|
---|
323 | }
|
---|
324 |
|
---|
325 | function EnumNumberMember(node) {
|
---|
326 | enumInitializedMember(this, node);
|
---|
327 | }
|
---|
328 |
|
---|
329 | function EnumStringMember(node) {
|
---|
330 | enumInitializedMember(this, node);
|
---|
331 | }
|
---|
332 |
|
---|
333 | function FlowExportDeclaration(node) {
|
---|
334 | if (node.declaration) {
|
---|
335 | const declar = node.declaration;
|
---|
336 | this.print(declar, node);
|
---|
337 | if (!t.isStatement(declar)) this.semicolon();
|
---|
338 | } else {
|
---|
339 | this.token("{");
|
---|
340 |
|
---|
341 | if (node.specifiers.length) {
|
---|
342 | this.space();
|
---|
343 | this.printList(node.specifiers, node);
|
---|
344 | this.space();
|
---|
345 | }
|
---|
346 |
|
---|
347 | this.token("}");
|
---|
348 |
|
---|
349 | if (node.source) {
|
---|
350 | this.space();
|
---|
351 | this.word("from");
|
---|
352 | this.space();
|
---|
353 | this.print(node.source, node);
|
---|
354 | }
|
---|
355 |
|
---|
356 | this.semicolon();
|
---|
357 | }
|
---|
358 | }
|
---|
359 |
|
---|
360 | function ExistsTypeAnnotation() {
|
---|
361 | this.token("*");
|
---|
362 | }
|
---|
363 |
|
---|
364 | function FunctionTypeAnnotation(node, parent) {
|
---|
365 | this.print(node.typeParameters, node);
|
---|
366 | this.token("(");
|
---|
367 |
|
---|
368 | if (node.this) {
|
---|
369 | this.word("this");
|
---|
370 | this.token(":");
|
---|
371 | this.space();
|
---|
372 | this.print(node.this.typeAnnotation, node);
|
---|
373 |
|
---|
374 | if (node.params.length || node.rest) {
|
---|
375 | this.token(",");
|
---|
376 | this.space();
|
---|
377 | }
|
---|
378 | }
|
---|
379 |
|
---|
380 | this.printList(node.params, node);
|
---|
381 |
|
---|
382 | if (node.rest) {
|
---|
383 | if (node.params.length) {
|
---|
384 | this.token(",");
|
---|
385 | this.space();
|
---|
386 | }
|
---|
387 |
|
---|
388 | this.token("...");
|
---|
389 | this.print(node.rest, node);
|
---|
390 | }
|
---|
391 |
|
---|
392 | this.token(")");
|
---|
393 |
|
---|
394 | if (parent.type === "ObjectTypeCallProperty" || parent.type === "DeclareFunction" || parent.type === "ObjectTypeProperty" && parent.method) {
|
---|
395 | this.token(":");
|
---|
396 | } else {
|
---|
397 | this.space();
|
---|
398 | this.token("=>");
|
---|
399 | }
|
---|
400 |
|
---|
401 | this.space();
|
---|
402 | this.print(node.returnType, node);
|
---|
403 | }
|
---|
404 |
|
---|
405 | function FunctionTypeParam(node) {
|
---|
406 | this.print(node.name, node);
|
---|
407 | if (node.optional) this.token("?");
|
---|
408 |
|
---|
409 | if (node.name) {
|
---|
410 | this.token(":");
|
---|
411 | this.space();
|
---|
412 | }
|
---|
413 |
|
---|
414 | this.print(node.typeAnnotation, node);
|
---|
415 | }
|
---|
416 |
|
---|
417 | function InterfaceExtends(node) {
|
---|
418 | this.print(node.id, node);
|
---|
419 | this.print(node.typeParameters, node);
|
---|
420 | }
|
---|
421 |
|
---|
422 | function _interfaceish(node) {
|
---|
423 | var _node$extends;
|
---|
424 |
|
---|
425 | this.print(node.id, node);
|
---|
426 | this.print(node.typeParameters, node);
|
---|
427 |
|
---|
428 | if ((_node$extends = node.extends) != null && _node$extends.length) {
|
---|
429 | this.space();
|
---|
430 | this.word("extends");
|
---|
431 | this.space();
|
---|
432 | this.printList(node.extends, node);
|
---|
433 | }
|
---|
434 |
|
---|
435 | if (node.mixins && node.mixins.length) {
|
---|
436 | this.space();
|
---|
437 | this.word("mixins");
|
---|
438 | this.space();
|
---|
439 | this.printList(node.mixins, node);
|
---|
440 | }
|
---|
441 |
|
---|
442 | if (node.implements && node.implements.length) {
|
---|
443 | this.space();
|
---|
444 | this.word("implements");
|
---|
445 | this.space();
|
---|
446 | this.printList(node.implements, node);
|
---|
447 | }
|
---|
448 |
|
---|
449 | this.space();
|
---|
450 | this.print(node.body, node);
|
---|
451 | }
|
---|
452 |
|
---|
453 | function _variance(node) {
|
---|
454 | if (node.variance) {
|
---|
455 | if (node.variance.kind === "plus") {
|
---|
456 | this.token("+");
|
---|
457 | } else if (node.variance.kind === "minus") {
|
---|
458 | this.token("-");
|
---|
459 | }
|
---|
460 | }
|
---|
461 | }
|
---|
462 |
|
---|
463 | function InterfaceDeclaration(node) {
|
---|
464 | this.word("interface");
|
---|
465 | this.space();
|
---|
466 |
|
---|
467 | this._interfaceish(node);
|
---|
468 | }
|
---|
469 |
|
---|
470 | function andSeparator() {
|
---|
471 | this.space();
|
---|
472 | this.token("&");
|
---|
473 | this.space();
|
---|
474 | }
|
---|
475 |
|
---|
476 | function InterfaceTypeAnnotation(node) {
|
---|
477 | this.word("interface");
|
---|
478 |
|
---|
479 | if (node.extends && node.extends.length) {
|
---|
480 | this.space();
|
---|
481 | this.word("extends");
|
---|
482 | this.space();
|
---|
483 | this.printList(node.extends, node);
|
---|
484 | }
|
---|
485 |
|
---|
486 | this.space();
|
---|
487 | this.print(node.body, node);
|
---|
488 | }
|
---|
489 |
|
---|
490 | function IntersectionTypeAnnotation(node) {
|
---|
491 | this.printJoin(node.types, node, {
|
---|
492 | separator: andSeparator
|
---|
493 | });
|
---|
494 | }
|
---|
495 |
|
---|
496 | function MixedTypeAnnotation() {
|
---|
497 | this.word("mixed");
|
---|
498 | }
|
---|
499 |
|
---|
500 | function EmptyTypeAnnotation() {
|
---|
501 | this.word("empty");
|
---|
502 | }
|
---|
503 |
|
---|
504 | function NullableTypeAnnotation(node) {
|
---|
505 | this.token("?");
|
---|
506 | this.print(node.typeAnnotation, node);
|
---|
507 | }
|
---|
508 |
|
---|
509 | function NumberTypeAnnotation() {
|
---|
510 | this.word("number");
|
---|
511 | }
|
---|
512 |
|
---|
513 | function StringTypeAnnotation() {
|
---|
514 | this.word("string");
|
---|
515 | }
|
---|
516 |
|
---|
517 | function ThisTypeAnnotation() {
|
---|
518 | this.word("this");
|
---|
519 | }
|
---|
520 |
|
---|
521 | function TupleTypeAnnotation(node) {
|
---|
522 | this.token("[");
|
---|
523 | this.printList(node.types, node);
|
---|
524 | this.token("]");
|
---|
525 | }
|
---|
526 |
|
---|
527 | function TypeofTypeAnnotation(node) {
|
---|
528 | this.word("typeof");
|
---|
529 | this.space();
|
---|
530 | this.print(node.argument, node);
|
---|
531 | }
|
---|
532 |
|
---|
533 | function TypeAlias(node) {
|
---|
534 | this.word("type");
|
---|
535 | this.space();
|
---|
536 | this.print(node.id, node);
|
---|
537 | this.print(node.typeParameters, node);
|
---|
538 | this.space();
|
---|
539 | this.token("=");
|
---|
540 | this.space();
|
---|
541 | this.print(node.right, node);
|
---|
542 | this.semicolon();
|
---|
543 | }
|
---|
544 |
|
---|
545 | function TypeAnnotation(node) {
|
---|
546 | this.token(":");
|
---|
547 | this.space();
|
---|
548 | if (node.optional) this.token("?");
|
---|
549 | this.print(node.typeAnnotation, node);
|
---|
550 | }
|
---|
551 |
|
---|
552 | function TypeParameterInstantiation(node) {
|
---|
553 | this.token("<");
|
---|
554 | this.printList(node.params, node, {});
|
---|
555 | this.token(">");
|
---|
556 | }
|
---|
557 |
|
---|
558 | function TypeParameter(node) {
|
---|
559 | this._variance(node);
|
---|
560 |
|
---|
561 | this.word(node.name);
|
---|
562 |
|
---|
563 | if (node.bound) {
|
---|
564 | this.print(node.bound, node);
|
---|
565 | }
|
---|
566 |
|
---|
567 | if (node.default) {
|
---|
568 | this.space();
|
---|
569 | this.token("=");
|
---|
570 | this.space();
|
---|
571 | this.print(node.default, node);
|
---|
572 | }
|
---|
573 | }
|
---|
574 |
|
---|
575 | function OpaqueType(node) {
|
---|
576 | this.word("opaque");
|
---|
577 | this.space();
|
---|
578 | this.word("type");
|
---|
579 | this.space();
|
---|
580 | this.print(node.id, node);
|
---|
581 | this.print(node.typeParameters, node);
|
---|
582 |
|
---|
583 | if (node.supertype) {
|
---|
584 | this.token(":");
|
---|
585 | this.space();
|
---|
586 | this.print(node.supertype, node);
|
---|
587 | }
|
---|
588 |
|
---|
589 | if (node.impltype) {
|
---|
590 | this.space();
|
---|
591 | this.token("=");
|
---|
592 | this.space();
|
---|
593 | this.print(node.impltype, node);
|
---|
594 | }
|
---|
595 |
|
---|
596 | this.semicolon();
|
---|
597 | }
|
---|
598 |
|
---|
599 | function ObjectTypeAnnotation(node) {
|
---|
600 | if (node.exact) {
|
---|
601 | this.token("{|");
|
---|
602 | } else {
|
---|
603 | this.token("{");
|
---|
604 | }
|
---|
605 |
|
---|
606 | const props = [...node.properties, ...(node.callProperties || []), ...(node.indexers || []), ...(node.internalSlots || [])];
|
---|
607 |
|
---|
608 | if (props.length) {
|
---|
609 | this.space();
|
---|
610 | this.printJoin(props, node, {
|
---|
611 | addNewlines(leading) {
|
---|
612 | if (leading && !props[0]) return 1;
|
---|
613 | },
|
---|
614 |
|
---|
615 | indent: true,
|
---|
616 | statement: true,
|
---|
617 | iterator: () => {
|
---|
618 | if (props.length !== 1 || node.inexact) {
|
---|
619 | this.token(",");
|
---|
620 | this.space();
|
---|
621 | }
|
---|
622 | }
|
---|
623 | });
|
---|
624 | this.space();
|
---|
625 | }
|
---|
626 |
|
---|
627 | if (node.inexact) {
|
---|
628 | this.indent();
|
---|
629 | this.token("...");
|
---|
630 |
|
---|
631 | if (props.length) {
|
---|
632 | this.newline();
|
---|
633 | }
|
---|
634 |
|
---|
635 | this.dedent();
|
---|
636 | }
|
---|
637 |
|
---|
638 | if (node.exact) {
|
---|
639 | this.token("|}");
|
---|
640 | } else {
|
---|
641 | this.token("}");
|
---|
642 | }
|
---|
643 | }
|
---|
644 |
|
---|
645 | function ObjectTypeInternalSlot(node) {
|
---|
646 | if (node.static) {
|
---|
647 | this.word("static");
|
---|
648 | this.space();
|
---|
649 | }
|
---|
650 |
|
---|
651 | this.token("[");
|
---|
652 | this.token("[");
|
---|
653 | this.print(node.id, node);
|
---|
654 | this.token("]");
|
---|
655 | this.token("]");
|
---|
656 | if (node.optional) this.token("?");
|
---|
657 |
|
---|
658 | if (!node.method) {
|
---|
659 | this.token(":");
|
---|
660 | this.space();
|
---|
661 | }
|
---|
662 |
|
---|
663 | this.print(node.value, node);
|
---|
664 | }
|
---|
665 |
|
---|
666 | function ObjectTypeCallProperty(node) {
|
---|
667 | if (node.static) {
|
---|
668 | this.word("static");
|
---|
669 | this.space();
|
---|
670 | }
|
---|
671 |
|
---|
672 | this.print(node.value, node);
|
---|
673 | }
|
---|
674 |
|
---|
675 | function ObjectTypeIndexer(node) {
|
---|
676 | if (node.static) {
|
---|
677 | this.word("static");
|
---|
678 | this.space();
|
---|
679 | }
|
---|
680 |
|
---|
681 | this._variance(node);
|
---|
682 |
|
---|
683 | this.token("[");
|
---|
684 |
|
---|
685 | if (node.id) {
|
---|
686 | this.print(node.id, node);
|
---|
687 | this.token(":");
|
---|
688 | this.space();
|
---|
689 | }
|
---|
690 |
|
---|
691 | this.print(node.key, node);
|
---|
692 | this.token("]");
|
---|
693 | this.token(":");
|
---|
694 | this.space();
|
---|
695 | this.print(node.value, node);
|
---|
696 | }
|
---|
697 |
|
---|
698 | function ObjectTypeProperty(node) {
|
---|
699 | if (node.proto) {
|
---|
700 | this.word("proto");
|
---|
701 | this.space();
|
---|
702 | }
|
---|
703 |
|
---|
704 | if (node.static) {
|
---|
705 | this.word("static");
|
---|
706 | this.space();
|
---|
707 | }
|
---|
708 |
|
---|
709 | if (node.kind === "get" || node.kind === "set") {
|
---|
710 | this.word(node.kind);
|
---|
711 | this.space();
|
---|
712 | }
|
---|
713 |
|
---|
714 | this._variance(node);
|
---|
715 |
|
---|
716 | this.print(node.key, node);
|
---|
717 | if (node.optional) this.token("?");
|
---|
718 |
|
---|
719 | if (!node.method) {
|
---|
720 | this.token(":");
|
---|
721 | this.space();
|
---|
722 | }
|
---|
723 |
|
---|
724 | this.print(node.value, node);
|
---|
725 | }
|
---|
726 |
|
---|
727 | function ObjectTypeSpreadProperty(node) {
|
---|
728 | this.token("...");
|
---|
729 | this.print(node.argument, node);
|
---|
730 | }
|
---|
731 |
|
---|
732 | function QualifiedTypeIdentifier(node) {
|
---|
733 | this.print(node.qualification, node);
|
---|
734 | this.token(".");
|
---|
735 | this.print(node.id, node);
|
---|
736 | }
|
---|
737 |
|
---|
738 | function SymbolTypeAnnotation() {
|
---|
739 | this.word("symbol");
|
---|
740 | }
|
---|
741 |
|
---|
742 | function orSeparator() {
|
---|
743 | this.space();
|
---|
744 | this.token("|");
|
---|
745 | this.space();
|
---|
746 | }
|
---|
747 |
|
---|
748 | function UnionTypeAnnotation(node) {
|
---|
749 | this.printJoin(node.types, node, {
|
---|
750 | separator: orSeparator
|
---|
751 | });
|
---|
752 | }
|
---|
753 |
|
---|
754 | function TypeCastExpression(node) {
|
---|
755 | this.token("(");
|
---|
756 | this.print(node.expression, node);
|
---|
757 | this.print(node.typeAnnotation, node);
|
---|
758 | this.token(")");
|
---|
759 | }
|
---|
760 |
|
---|
761 | function Variance(node) {
|
---|
762 | if (node.kind === "plus") {
|
---|
763 | this.token("+");
|
---|
764 | } else {
|
---|
765 | this.token("-");
|
---|
766 | }
|
---|
767 | }
|
---|
768 |
|
---|
769 | function VoidTypeAnnotation() {
|
---|
770 | this.word("void");
|
---|
771 | }
|
---|
772 |
|
---|
773 | function IndexedAccessType(node) {
|
---|
774 | this.print(node.objectType, node);
|
---|
775 | this.token("[");
|
---|
776 | this.print(node.indexType, node);
|
---|
777 | this.token("]");
|
---|
778 | }
|
---|
779 |
|
---|
780 | function OptionalIndexedAccessType(node) {
|
---|
781 | this.print(node.objectType, node);
|
---|
782 |
|
---|
783 | if (node.optional) {
|
---|
784 | this.token("?.");
|
---|
785 | }
|
---|
786 |
|
---|
787 | this.token("[");
|
---|
788 | this.print(node.indexType, node);
|
---|
789 | this.token("]");
|
---|
790 | } |
---|