source: trip-planner-front/node_modules/@babel/generator/lib/generators/flow.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 16.0 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.AnyTypeAnnotation = AnyTypeAnnotation;
7exports.ArrayTypeAnnotation = ArrayTypeAnnotation;
8exports.BooleanTypeAnnotation = BooleanTypeAnnotation;
9exports.BooleanLiteralTypeAnnotation = BooleanLiteralTypeAnnotation;
10exports.NullLiteralTypeAnnotation = NullLiteralTypeAnnotation;
11exports.DeclareClass = DeclareClass;
12exports.DeclareFunction = DeclareFunction;
13exports.InferredPredicate = InferredPredicate;
14exports.DeclaredPredicate = DeclaredPredicate;
15exports.DeclareInterface = DeclareInterface;
16exports.DeclareModule = DeclareModule;
17exports.DeclareModuleExports = DeclareModuleExports;
18exports.DeclareTypeAlias = DeclareTypeAlias;
19exports.DeclareOpaqueType = DeclareOpaqueType;
20exports.DeclareVariable = DeclareVariable;
21exports.DeclareExportDeclaration = DeclareExportDeclaration;
22exports.DeclareExportAllDeclaration = DeclareExportAllDeclaration;
23exports.EnumDeclaration = EnumDeclaration;
24exports.EnumBooleanBody = EnumBooleanBody;
25exports.EnumNumberBody = EnumNumberBody;
26exports.EnumStringBody = EnumStringBody;
27exports.EnumSymbolBody = EnumSymbolBody;
28exports.EnumDefaultedMember = EnumDefaultedMember;
29exports.EnumBooleanMember = EnumBooleanMember;
30exports.EnumNumberMember = EnumNumberMember;
31exports.EnumStringMember = EnumStringMember;
32exports.ExistsTypeAnnotation = ExistsTypeAnnotation;
33exports.FunctionTypeAnnotation = FunctionTypeAnnotation;
34exports.FunctionTypeParam = FunctionTypeParam;
35exports.GenericTypeAnnotation = exports.ClassImplements = exports.InterfaceExtends = InterfaceExtends;
36exports._interfaceish = _interfaceish;
37exports._variance = _variance;
38exports.InterfaceDeclaration = InterfaceDeclaration;
39exports.InterfaceTypeAnnotation = InterfaceTypeAnnotation;
40exports.IntersectionTypeAnnotation = IntersectionTypeAnnotation;
41exports.MixedTypeAnnotation = MixedTypeAnnotation;
42exports.EmptyTypeAnnotation = EmptyTypeAnnotation;
43exports.NullableTypeAnnotation = NullableTypeAnnotation;
44exports.NumberTypeAnnotation = NumberTypeAnnotation;
45exports.StringTypeAnnotation = StringTypeAnnotation;
46exports.ThisTypeAnnotation = ThisTypeAnnotation;
47exports.TupleTypeAnnotation = TupleTypeAnnotation;
48exports.TypeofTypeAnnotation = TypeofTypeAnnotation;
49exports.TypeAlias = TypeAlias;
50exports.TypeAnnotation = TypeAnnotation;
51exports.TypeParameterDeclaration = exports.TypeParameterInstantiation = TypeParameterInstantiation;
52exports.TypeParameter = TypeParameter;
53exports.OpaqueType = OpaqueType;
54exports.ObjectTypeAnnotation = ObjectTypeAnnotation;
55exports.ObjectTypeInternalSlot = ObjectTypeInternalSlot;
56exports.ObjectTypeCallProperty = ObjectTypeCallProperty;
57exports.ObjectTypeIndexer = ObjectTypeIndexer;
58exports.ObjectTypeProperty = ObjectTypeProperty;
59exports.ObjectTypeSpreadProperty = ObjectTypeSpreadProperty;
60exports.QualifiedTypeIdentifier = QualifiedTypeIdentifier;
61exports.SymbolTypeAnnotation = SymbolTypeAnnotation;
62exports.UnionTypeAnnotation = UnionTypeAnnotation;
63exports.TypeCastExpression = TypeCastExpression;
64exports.Variance = Variance;
65exports.VoidTypeAnnotation = VoidTypeAnnotation;
66exports.IndexedAccessType = IndexedAccessType;
67exports.OptionalIndexedAccessType = OptionalIndexedAccessType;
68Object.defineProperty(exports, "NumberLiteralTypeAnnotation", {
69 enumerable: true,
70 get: function () {
71 return _types2.NumericLiteral;
72 }
73});
74Object.defineProperty(exports, "StringLiteralTypeAnnotation", {
75 enumerable: true,
76 get: function () {
77 return _types2.StringLiteral;
78 }
79});
80
81var t = require("@babel/types");
82
83var _modules = require("./modules");
84
85var _types2 = require("./types");
86
87function AnyTypeAnnotation() {
88 this.word("any");
89}
90
91function ArrayTypeAnnotation(node) {
92 this.print(node.elementType, node);
93 this.token("[");
94 this.token("]");
95}
96
97function BooleanTypeAnnotation() {
98 this.word("boolean");
99}
100
101function BooleanLiteralTypeAnnotation(node) {
102 this.word(node.value ? "true" : "false");
103}
104
105function NullLiteralTypeAnnotation() {
106 this.word("null");
107}
108
109function 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
121function 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
140function InferredPredicate() {
141 this.token("%");
142 this.word("checks");
143}
144
145function DeclaredPredicate(node) {
146 this.token("%");
147 this.word("checks");
148 this.token("(");
149 this.print(node.value, node);
150 this.token(")");
151}
152
153function DeclareInterface(node) {
154 this.word("declare");
155 this.space();
156 this.InterfaceDeclaration(node);
157}
158
159function 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
169function 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
178function DeclareTypeAlias(node) {
179 this.word("declare");
180 this.space();
181 this.TypeAlias(node);
182}
183
184function DeclareOpaqueType(node, parent) {
185 if (!t.isDeclareExportDeclaration(parent)) {
186 this.word("declare");
187 this.space();
188 }
189
190 this.OpaqueType(node);
191}
192
193function 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
206function 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
220function DeclareExportAllDeclaration() {
221 this.word("declare");
222 this.space();
223
224 _modules.ExportAllDeclaration.apply(this, arguments);
225}
226
227function 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
238function 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
249function 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
271function EnumBooleanBody(node) {
272 const {
273 explicitType
274 } = node;
275 enumExplicitType(this, "boolean", explicitType);
276 enumBody(this, node);
277}
278
279function EnumNumberBody(node) {
280 const {
281 explicitType
282 } = node;
283 enumExplicitType(this, "number", explicitType);
284 enumBody(this, node);
285}
286
287function EnumStringBody(node) {
288 const {
289 explicitType
290 } = node;
291 enumExplicitType(this, "string", explicitType);
292 enumBody(this, node);
293}
294
295function EnumSymbolBody(node) {
296 enumExplicitType(this, "symbol", true);
297 enumBody(this, node);
298}
299
300function EnumDefaultedMember(node) {
301 const {
302 id
303 } = node;
304 this.print(id, node);
305 this.token(",");
306}
307
308function 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
321function EnumBooleanMember(node) {
322 enumInitializedMember(this, node);
323}
324
325function EnumNumberMember(node) {
326 enumInitializedMember(this, node);
327}
328
329function EnumStringMember(node) {
330 enumInitializedMember(this, node);
331}
332
333function 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
360function ExistsTypeAnnotation() {
361 this.token("*");
362}
363
364function 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
405function 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
417function InterfaceExtends(node) {
418 this.print(node.id, node);
419 this.print(node.typeParameters, node);
420}
421
422function _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
453function _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
463function InterfaceDeclaration(node) {
464 this.word("interface");
465 this.space();
466
467 this._interfaceish(node);
468}
469
470function andSeparator() {
471 this.space();
472 this.token("&");
473 this.space();
474}
475
476function 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
490function IntersectionTypeAnnotation(node) {
491 this.printJoin(node.types, node, {
492 separator: andSeparator
493 });
494}
495
496function MixedTypeAnnotation() {
497 this.word("mixed");
498}
499
500function EmptyTypeAnnotation() {
501 this.word("empty");
502}
503
504function NullableTypeAnnotation(node) {
505 this.token("?");
506 this.print(node.typeAnnotation, node);
507}
508
509function NumberTypeAnnotation() {
510 this.word("number");
511}
512
513function StringTypeAnnotation() {
514 this.word("string");
515}
516
517function ThisTypeAnnotation() {
518 this.word("this");
519}
520
521function TupleTypeAnnotation(node) {
522 this.token("[");
523 this.printList(node.types, node);
524 this.token("]");
525}
526
527function TypeofTypeAnnotation(node) {
528 this.word("typeof");
529 this.space();
530 this.print(node.argument, node);
531}
532
533function 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
545function TypeAnnotation(node) {
546 this.token(":");
547 this.space();
548 if (node.optional) this.token("?");
549 this.print(node.typeAnnotation, node);
550}
551
552function TypeParameterInstantiation(node) {
553 this.token("<");
554 this.printList(node.params, node, {});
555 this.token(">");
556}
557
558function 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
575function 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
599function 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
645function 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
666function ObjectTypeCallProperty(node) {
667 if (node.static) {
668 this.word("static");
669 this.space();
670 }
671
672 this.print(node.value, node);
673}
674
675function 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
698function 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
727function ObjectTypeSpreadProperty(node) {
728 this.token("...");
729 this.print(node.argument, node);
730}
731
732function QualifiedTypeIdentifier(node) {
733 this.print(node.qualification, node);
734 this.token(".");
735 this.print(node.id, node);
736}
737
738function SymbolTypeAnnotation() {
739 this.word("symbol");
740}
741
742function orSeparator() {
743 this.space();
744 this.token("|");
745 this.space();
746}
747
748function UnionTypeAnnotation(node) {
749 this.printJoin(node.types, node, {
750 separator: orSeparator
751 });
752}
753
754function TypeCastExpression(node) {
755 this.token("(");
756 this.print(node.expression, node);
757 this.print(node.typeAnnotation, node);
758 this.token(")");
759}
760
761function Variance(node) {
762 if (node.kind === "plus") {
763 this.token("+");
764 } else {
765 this.token("-");
766 }
767}
768
769function VoidTypeAnnotation() {
770 this.word("void");
771}
772
773function IndexedAccessType(node) {
774 this.print(node.objectType, node);
775 this.token("[");
776 this.print(node.indexType, node);
777 this.token("]");
778}
779
780function 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}
Note: See TracBrowser for help on using the repository browser.