flow-parser 0.328.0 → 0.330.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,915 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.transformProgram = transformProgram;
7
- var _SimpleTransform = require("../transform/SimpleTransform");
8
- var _SimpleTraverser = require("../traverse/SimpleTraverser");
9
- var _ESTreeVisitorKeys = _interopRequireDefault(require("../generated/ESTreeVisitorKeys"));
10
- var _createSyntaxError = require("../utils/createSyntaxError");
11
- function _interopRequireDefault(e) {
12
- return e && e.__esModule ? e : {
13
- default: e
14
- };
15
- }
16
- const EMPTY_PARENT = null;
17
- const FlowESTreeAndBabelVisitorKeys = {
18
- ..._ESTreeVisitorKeys.default,
19
- BigIntLiteral: [],
20
- BlockStatement: ['directives', ..._ESTreeVisitorKeys.default.BlockStatement],
21
- BooleanLiteral: [],
22
- ClassExpression: ['superTypeParameters', ..._ESTreeVisitorKeys.default.ClassExpression],
23
- ClassDeclaration: ['superTypeParameters', ..._ESTreeVisitorKeys.default.ClassDeclaration],
24
- ClassMethod: ['key', 'params', 'body', 'returnType', 'typeParameters'],
25
- ClassPrivateMethod: ['key', 'params', 'body', 'returnType', 'typeParameters'],
26
- ClassProperty: ['key', 'value', 'typeAnnotation', 'variance'],
27
- ClassPrivateProperty: ['key', 'value', 'typeAnnotation', 'variance'],
28
- DeclareVariable: ['id'],
29
- Directive: ['value'],
30
- DirectiveLiteral: [],
31
- ExportNamespaceSpecifier: ['exported'],
32
- File: ['program', 'comments'],
33
- Import: [],
34
- NullLiteral: [],
35
- NumericLiteral: [],
36
- ObjectMethod: [..._ESTreeVisitorKeys.default.Property, 'params', 'body', 'returnType', 'typeParameters'],
37
- ObjectProperty: _ESTreeVisitorKeys.default.Property,
38
- OptionalCallExpression: ['callee', 'arguments', 'typeArguments'],
39
- OptionalMemberExpression: ['object', 'property'],
40
- PrivateName: ['id'],
41
- Program: ['directives', ..._ESTreeVisitorKeys.default.Program],
42
- RegExpLiteral: [],
43
- RestElement: [..._ESTreeVisitorKeys.default.RestElement, 'typeAnnotation'],
44
- StringLiteral: [],
45
- TupleTypeAnnotation: ['types'],
46
- CommentBlock: [],
47
- CommentLine: []
48
- };
49
- function nodeWith(node, overrideProps) {
50
- return _SimpleTransform.SimpleTransform.nodeWith(node, overrideProps, FlowESTreeAndBabelVisitorKeys);
51
- }
52
- function fixSourceLocation(node, _options) {
53
- const loc = node.loc;
54
- if (loc == null) {
55
- return;
56
- }
57
- node.loc = {
58
- start: loc.start,
59
- end: loc.end
60
- };
61
- if (node.type === 'Identifier') {
62
- node.loc.identifierName = node.name;
63
- }
64
- node.start = node.range[0];
65
- node.end = node.range[1];
66
- delete node.range;
67
- delete node.parent;
68
- }
69
- function mapNodeWithDirectives(node) {
70
- if (node.directives != null) {
71
- return node;
72
- }
73
- const directives = [];
74
- for (const child of node.body) {
75
- if (child.type === 'ExpressionStatement' && child.directive != null) {
76
- directives.push({
77
- type: 'Directive',
78
- value: {
79
- type: 'DirectiveLiteral',
80
- value: child.directive,
81
- extra: {
82
- rawValue: child.directive,
83
- raw: child.expression.type === 'Literal' ? child.expression.raw : ''
84
- },
85
- loc: child.expression.loc,
86
- range: child.expression.range,
87
- parent: EMPTY_PARENT
88
- },
89
- loc: child.loc,
90
- range: child.range,
91
- parent: node
92
- });
93
- } else {
94
- break;
95
- }
96
- }
97
- return nodeWith(node, {
98
- directives,
99
- body: directives.length === 0 ? node.body : node.body.slice(directives.length)
100
- });
101
- }
102
- function mapProgram(node) {
103
- var _program$directives;
104
- const program = mapNodeWithDirectives(node);
105
- const startLoc = {
106
- line: 1,
107
- column: 0
108
- };
109
- let endLoc = program.loc.end;
110
- let endRange = program.range[1];
111
- if (program.comments.length > 0) {
112
- const lastComment = program.comments[program.comments.length - 1];
113
- if (lastComment.range[1] > endRange) {
114
- endLoc = lastComment.loc.end;
115
- endRange = lastComment.range[1];
116
- }
117
- }
118
- const loc = {
119
- start: startLoc,
120
- end: endLoc
121
- };
122
- const range = [0, endRange];
123
- const babelComments = program.comments.map(comment => {
124
- switch (comment.type) {
125
- case 'Line':
126
- {
127
- return {
128
- type: 'CommentLine',
129
- value: comment.value,
130
- loc: comment.loc,
131
- range: comment.range
132
- };
133
- }
134
- case 'Block':
135
- {
136
- return {
137
- type: 'CommentBlock',
138
- value: comment.value,
139
- loc: comment.loc,
140
- range: comment.range
141
- };
142
- }
143
- }
144
- });
145
- return {
146
- type: 'File',
147
- program: {
148
- type: 'Program',
149
- body: program.body,
150
- directives: (_program$directives = program.directives) != null ? _program$directives : [],
151
- sourceType: program.sourceType,
152
- interpreter: program.interpreter,
153
- loc,
154
- range,
155
- parent: EMPTY_PARENT
156
- },
157
- comments: babelComments,
158
- loc,
159
- range,
160
- parent: EMPTY_PARENT
161
- };
162
- }
163
- function mapTemplateElement(node) {
164
- const startCharsToExclude = 1;
165
- const endCharsToExclude = node.tail ? 1 : 2;
166
- node.loc = {
167
- start: {
168
- line: node.loc.start.line,
169
- column: node.loc.start.column + startCharsToExclude
170
- },
171
- end: {
172
- line: node.loc.end.line,
173
- column: node.loc.end.column - endCharsToExclude
174
- }
175
- };
176
- node.range = [node.range[0] + startCharsToExclude, node.range[1] - endCharsToExclude];
177
- return node;
178
- }
179
- function mapProperty(node) {
180
- const key = node.key;
181
- const value = node.value;
182
- if (node.method || node.kind !== 'init') {
183
- if (value.type !== 'FunctionExpression') {
184
- throw (0, _createSyntaxError.createSyntaxError)(node, `Invalid method property, the value must be a "FunctionExpression" or "ArrowFunctionExpression. Instead got "${value.type}".`);
185
- }
186
- const newNode = {
187
- type: 'ObjectMethod',
188
- kind: node.kind === 'init' ? 'method' : node.kind,
189
- method: node.kind === 'init' ? true : false,
190
- computed: node.computed,
191
- key: key,
192
- id: null,
193
- params: value.params,
194
- body: value.body,
195
- async: value.async,
196
- generator: value.generator,
197
- returnType: value.returnType,
198
- typeParameters: value.typeParameters,
199
- loc: node.loc,
200
- range: node.range,
201
- parent: node.parent
202
- };
203
- if (node.kind !== 'init') {
204
- newNode.variance = null;
205
- }
206
- return newNode;
207
- }
208
- const propertyValue = value;
209
- return {
210
- type: 'ObjectProperty',
211
- computed: node.computed,
212
- key: node.key,
213
- value: propertyValue,
214
- method: node.method,
215
- shorthand: node.shorthand,
216
- loc: node.loc,
217
- range: node.range,
218
- parent: node.parent
219
- };
220
- }
221
- function mapMethodDefinition(node) {
222
- const value = node.value;
223
- const BaseClassMethod = {
224
- kind: node.kind,
225
- computed: node.computed,
226
- static: node.static,
227
- key: node.key,
228
- id: null,
229
- params: value.params,
230
- body: value.body,
231
- async: value.async,
232
- generator: value.generator,
233
- returnType: value.returnType,
234
- typeParameters: value.typeParameters,
235
- predicate: null,
236
- loc: node.loc,
237
- range: node.range,
238
- parent: node.parent
239
- };
240
- if (node.key.type === 'PrivateIdentifier') {
241
- return {
242
- ...BaseClassMethod,
243
- type: 'ClassPrivateMethod'
244
- };
245
- }
246
- return {
247
- ...BaseClassMethod,
248
- type: 'ClassMethod'
249
- };
250
- }
251
- function mapExportAllDeclaration(node) {
252
- if (node.exported != null) {
253
- return {
254
- type: 'ExportNamedDeclaration',
255
- declaration: null,
256
- specifiers: [{
257
- type: 'ExportNamespaceSpecifier',
258
- exported: node.exported,
259
- loc: {
260
- start: {
261
- column: node.loc.start.column + 'export '.length,
262
- line: node.loc.start.line
263
- },
264
- end: node.exported.loc.end
265
- },
266
- range: [node.range[0] + 'export '.length, node.exported.range[1]],
267
- parent: EMPTY_PARENT
268
- }],
269
- source: node.source,
270
- exportKind: node.exportKind,
271
- loc: node.loc,
272
- range: node.range,
273
- parent: node.parent
274
- };
275
- }
276
- delete node.exported;
277
- return node;
278
- }
279
- function mapRestElement(node) {
280
- const argument = node.argument;
281
- if ((argument.type === 'Identifier' || argument.type === 'ObjectPattern' || argument.type === 'ArrayPattern') && argument.typeAnnotation != null) {
282
- const argumentRange = argument.range;
283
- let argumentLoc = argument.loc;
284
- if (argument.type === 'Identifier') {
285
- argumentRange[1] = argumentRange[0] + argument.name.length;
286
- argumentLoc = {
287
- start: argumentLoc.start,
288
- end: {
289
- line: argumentLoc.start.line,
290
- column: argumentLoc.start.column + argument.name.length
291
- }
292
- };
293
- }
294
- return nodeWith(node, {
295
- typeAnnotation: argument.typeAnnotation,
296
- argument: nodeWith(argument, {
297
- typeAnnotation: null,
298
- range: argumentRange,
299
- loc: argumentLoc
300
- })
301
- });
302
- }
303
- return node;
304
- }
305
- function mapImportExpression(node) {
306
- return {
307
- type: 'CallExpression',
308
- callee: {
309
- type: 'Import',
310
- loc: {
311
- start: node.loc.start,
312
- end: {
313
- line: node.loc.start.line,
314
- column: node.loc.start.column + 'import'.length
315
- }
316
- },
317
- range: [node.range[0], node.range[0] + 'import'.length],
318
- parent: EMPTY_PARENT
319
- },
320
- arguments: [node.source],
321
- loc: node.loc,
322
- range: node.range,
323
- parent: node.parent
324
- };
325
- }
326
- function mapPrivateIdentifier(node) {
327
- return {
328
- type: 'PrivateName',
329
- id: {
330
- type: 'Identifier',
331
- name: node.name,
332
- optional: false,
333
- typeAnnotation: null,
334
- loc: {
335
- start: {
336
- line: node.loc.start.line,
337
- column: node.loc.start.column + 1
338
- },
339
- end: node.loc.end
340
- },
341
- range: [node.range[0] + 1, node.range[1]],
342
- parent: EMPTY_PARENT
343
- },
344
- loc: node.loc,
345
- range: node.range,
346
- parent: node.parent
347
- };
348
- }
349
- function mapPropertyDefinition(node) {
350
- if (node.key.type === 'PrivateIdentifier') {
351
- return {
352
- type: 'ClassPrivateProperty',
353
- key: mapPrivateIdentifier(node.key),
354
- value: node.value,
355
- typeAnnotation: node.typeAnnotation,
356
- static: node.static,
357
- variance: node.variance,
358
- loc: node.loc,
359
- range: node.range,
360
- parent: node.parent
361
- };
362
- }
363
- return {
364
- type: 'ClassProperty',
365
- key: node.key,
366
- value: node.value,
367
- typeAnnotation: node.typeAnnotation,
368
- static: node.static,
369
- variance: node.variance,
370
- declare: node.declare,
371
- optional: node.optional,
372
- computed: node.computed,
373
- loc: node.loc,
374
- range: node.range,
375
- parent: node.parent
376
- };
377
- }
378
- function mapTypeofTypeAnnotation(node) {
379
- delete node.typeArguments;
380
- if (node.argument.type !== 'GenericTypeAnnotation') {
381
- return nodeWith(node, {
382
- argument: {
383
- type: 'GenericTypeAnnotation',
384
- id: node.argument,
385
- typeParameters: null,
386
- loc: node.argument.loc,
387
- range: node.argument.range,
388
- parent: EMPTY_PARENT
389
- }
390
- });
391
- }
392
- return node;
393
- }
394
- function mapDeclareVariable(node) {
395
- var _babelNode$declaratio;
396
- const babelNode = node;
397
- if (babelNode.id == null && Array.isArray(babelNode.declarations) && ((_babelNode$declaratio = babelNode.declarations[0]) == null ? void 0 : _babelNode$declaratio.id) != null) {
398
- babelNode.id = babelNode.declarations[0].id;
399
- }
400
- delete babelNode.declarations;
401
- delete babelNode.kind;
402
- delete babelNode.implicitDeclare;
403
- return babelNode;
404
- }
405
- function mapJSXElement(node) {
406
- if (node.openingElement.typeArguments != null) {
407
- delete node.openingElement.typeArguments;
408
- }
409
- return node;
410
- }
411
- function mapChainExpressionInnerNode(node) {
412
- switch (node.type) {
413
- case 'MemberExpression':
414
- {
415
- const innerObject = mapChainExpressionInnerNode(node.object);
416
- if (!node.optional && innerObject.type !== 'OptionalMemberExpression' && innerObject.type !== 'OptionalCallExpression') {
417
- return node;
418
- }
419
- return {
420
- type: 'OptionalMemberExpression',
421
- object: innerObject,
422
- property: node.property,
423
- computed: node.computed,
424
- optional: node.optional,
425
- loc: node.loc,
426
- range: node.range,
427
- parent: node.parent
428
- };
429
- }
430
- case 'CallExpression':
431
- {
432
- const innerCallee = mapChainExpressionInnerNode(node.callee);
433
- if (!node.optional && innerCallee.type !== 'OptionalMemberExpression' && innerCallee.type !== 'OptionalCallExpression') {
434
- return node;
435
- }
436
- return {
437
- type: 'OptionalCallExpression',
438
- callee: innerCallee,
439
- optional: node.optional,
440
- arguments: node.arguments,
441
- typeArguments: node.typeArguments,
442
- loc: node.loc,
443
- range: node.range,
444
- parent: node.parent
445
- };
446
- }
447
- default:
448
- {
449
- return node;
450
- }
451
- }
452
- }
453
- function mapChainExpression(node) {
454
- return mapChainExpressionInnerNode(node.expression);
455
- }
456
- function mapLiteral(node) {
457
- const base = {
458
- loc: node.loc,
459
- range: node.range,
460
- parent: node.parent
461
- };
462
- switch (node.literalType) {
463
- case 'string':
464
- {
465
- return {
466
- type: 'StringLiteral',
467
- value: node.value,
468
- extra: {
469
- rawValue: node.value,
470
- raw: node.raw
471
- },
472
- ...base
473
- };
474
- }
475
- case 'numeric':
476
- {
477
- return {
478
- type: 'NumericLiteral',
479
- value: node.value,
480
- extra: {
481
- rawValue: node.value,
482
- raw: node.raw
483
- },
484
- ...base
485
- };
486
- }
487
- case 'bigint':
488
- {
489
- return {
490
- type: 'BigIntLiteral',
491
- value: node.bigint,
492
- extra: {
493
- rawValue: node.bigint,
494
- raw: node.raw
495
- },
496
- ...base
497
- };
498
- }
499
- case 'boolean':
500
- {
501
- return {
502
- type: 'BooleanLiteral',
503
- value: node.value,
504
- ...base
505
- };
506
- }
507
- case 'null':
508
- {
509
- return {
510
- type: 'NullLiteral',
511
- ...base
512
- };
513
- }
514
- case 'regexp':
515
- {
516
- return {
517
- type: 'RegExpLiteral',
518
- extra: {
519
- raw: node.raw
520
- },
521
- pattern: node.regex.pattern,
522
- flags: node.regex.flags,
523
- ...base
524
- };
525
- }
526
- }
527
- }
528
- function transformNode(node) {
529
- switch (node.type) {
530
- case 'Program':
531
- {
532
- var _node$parent;
533
- if (((_node$parent = node.parent) == null ? void 0 : _node$parent.type) === 'File') {
534
- return node;
535
- }
536
- return mapProgram(node);
537
- }
538
- case 'BlockStatement':
539
- {
540
- return mapNodeWithDirectives(node);
541
- }
542
- case 'Property':
543
- {
544
- return mapProperty(node);
545
- }
546
- case 'TemplateElement':
547
- {
548
- return mapTemplateElement(node);
549
- }
550
- case 'MethodDefinition':
551
- {
552
- return mapMethodDefinition(node);
553
- }
554
- case 'ExportAllDeclaration':
555
- {
556
- return mapExportAllDeclaration(node);
557
- }
558
- case 'RestElement':
559
- {
560
- return mapRestElement(node);
561
- }
562
- case 'ImportExpression':
563
- {
564
- return mapImportExpression(node);
565
- }
566
- case 'PrivateIdentifier':
567
- {
568
- return mapPrivateIdentifier(node);
569
- }
570
- case 'PropertyDefinition':
571
- {
572
- return mapPropertyDefinition(node);
573
- }
574
- case 'TypeofTypeAnnotation':
575
- {
576
- return mapTypeofTypeAnnotation(node);
577
- }
578
- case 'DeclareVariable':
579
- {
580
- return mapDeclareVariable(node);
581
- }
582
- case 'JSXElement':
583
- {
584
- return mapJSXElement(node);
585
- }
586
- case 'Literal':
587
- {
588
- return mapLiteral(node);
589
- }
590
- case 'ChainExpression':
591
- {
592
- return mapChainExpression(node);
593
- }
594
- case 'TypeCastExpression':
595
- {
596
- node.loc.start.column = node.loc.start.column + 1;
597
- node.loc.end.column = node.loc.end.column - 1;
598
- node.range = [node.range[0] + 1, node.range[1] - 1];
599
- return node;
600
- }
601
- case 'AsExpression':
602
- {
603
- const {
604
- typeAnnotation
605
- } = node;
606
- node.type = 'TypeCastExpression';
607
- node.typeAnnotation = {
608
- type: 'TypeAnnotation',
609
- typeAnnotation,
610
- loc: typeAnnotation.loc,
611
- range: typeAnnotation.range
612
- };
613
- return node;
614
- }
615
- case 'AsConstExpression':
616
- {
617
- return node.expression;
618
- }
619
- case 'NumberLiteralTypeAnnotation':
620
- {
621
- node.extra = {
622
- rawValue: node.value,
623
- raw: node.raw
624
- };
625
- delete node.raw;
626
- return node;
627
- }
628
- case 'StringLiteralTypeAnnotation':
629
- {
630
- node.extra = {
631
- rawValue: node.value,
632
- raw: node.raw
633
- };
634
- delete node.raw;
635
- return node;
636
- }
637
- case 'BigIntLiteralTypeAnnotation':
638
- {
639
- node.extra = {
640
- rawValue: node.bigint,
641
- raw: node.raw
642
- };
643
- delete node.bigint;
644
- delete node.raw;
645
- return node;
646
- }
647
- case 'BooleanLiteralTypeAnnotation':
648
- {
649
- delete node.raw;
650
- return node;
651
- }
652
- case 'TupleTypeAnnotation':
653
- {
654
- delete node.inexact;
655
- node.types = node.elementTypes;
656
- delete node.elementTypes;
657
- return node;
658
- }
659
- case 'UnknownTypeAnnotation':
660
- {
661
- return {
662
- type: 'GenericTypeAnnotation',
663
- id: {
664
- type: 'Identifier',
665
- name: 'unknown',
666
- optional: false,
667
- typeAnnotation: null,
668
- loc: node.loc,
669
- range: node.range,
670
- parent: EMPTY_PARENT
671
- },
672
- typeParameters: null,
673
- loc: node.loc,
674
- range: node.range,
675
- parent: EMPTY_PARENT
676
- };
677
- }
678
- case 'NeverTypeAnnotation':
679
- {
680
- return {
681
- type: 'GenericTypeAnnotation',
682
- id: {
683
- type: 'Identifier',
684
- name: 'never',
685
- optional: false,
686
- typeAnnotation: null,
687
- loc: node.loc,
688
- range: node.range,
689
- parent: EMPTY_PARENT
690
- },
691
- typeParameters: null,
692
- loc: node.loc,
693
- range: node.range,
694
- parent: EMPTY_PARENT
695
- };
696
- }
697
- case 'UndefinedTypeAnnotation':
698
- {
699
- return {
700
- type: 'GenericTypeAnnotation',
701
- id: {
702
- type: 'Identifier',
703
- name: 'undefined',
704
- optional: false,
705
- typeAnnotation: null,
706
- loc: node.loc,
707
- range: node.range,
708
- parent: EMPTY_PARENT
709
- },
710
- typeParameters: null,
711
- loc: node.loc,
712
- range: node.range,
713
- parent: EMPTY_PARENT
714
- };
715
- }
716
- case 'JSXText':
717
- {
718
- node.extra = {
719
- rawValue: node.value,
720
- raw: node.raw
721
- };
722
- delete node.raw;
723
- return node;
724
- }
725
- case 'Identifier':
726
- {
727
- if (node.optional === false || node.optional == null) {
728
- delete node.optional;
729
- }
730
- if (node.typeAnnotation == null) {
731
- delete node.typeAnnotation;
732
- }
733
- return node;
734
- }
735
- case 'CallExpression':
736
- {
737
- if (node.optional === false) {
738
- delete node.optional;
739
- }
740
- if (node.typeArguments == null) {
741
- delete node.typeArguments;
742
- }
743
- return node;
744
- }
745
- case 'OptionalCallExpression':
746
- {
747
- if (node.typeArguments == null) {
748
- delete node.typeArguments;
749
- }
750
- return node;
751
- }
752
- case 'MemberExpression':
753
- {
754
- delete node.optional;
755
- return node;
756
- }
757
- case 'ExpressionStatement':
758
- {
759
- delete node.directive;
760
- return node;
761
- }
762
- case 'ObjectPattern':
763
- case 'ArrayPattern':
764
- {
765
- if (node.typeAnnotation == null) {
766
- delete node.typeAnnotation;
767
- }
768
- return node;
769
- }
770
- case 'FunctionDeclaration':
771
- case 'FunctionExpression':
772
- case 'ArrowFunctionExpression':
773
- case 'ClassMethod':
774
- {
775
- delete node.expression;
776
- if (node.predicate == null) {
777
- delete node.predicate;
778
- }
779
- if (node.returnType == null) {
780
- delete node.returnType;
781
- }
782
- if (node.typeParameters == null) {
783
- delete node.typeParameters;
784
- }
785
- return node;
786
- }
787
- case 'ObjectMethod':
788
- {
789
- if (node.returnType == null) {
790
- delete node.returnType;
791
- }
792
- if (node.typeParameters == null) {
793
- delete node.typeParameters;
794
- }
795
- return node;
796
- }
797
- case 'ClassPrivateMethod':
798
- {
799
- if (node.computed === false) {
800
- delete node.computed;
801
- }
802
- if (node.predicate == null) {
803
- delete node.predicate;
804
- }
805
- if (node.returnType == null) {
806
- delete node.returnType;
807
- }
808
- if (node.typeParameters == null) {
809
- delete node.typeParameters;
810
- }
811
- return node;
812
- }
813
- case 'ClassExpression':
814
- case 'ClassDeclaration':
815
- {
816
- if (node.decorators == null || node.decorators.length === 0) {
817
- delete node.decorators;
818
- }
819
- if (node.implements == null || node.implements.length === 0) {
820
- delete node.implements;
821
- }
822
- if (node.superTypeArguments == null) {
823
- delete node.superTypeArguments;
824
- } else {
825
- node.superTypeParameters = node.superTypeArguments;
826
- delete node.superTypeArguments;
827
- }
828
- if (node.typeParameters == null) {
829
- delete node.typeParameters;
830
- }
831
- return node;
832
- }
833
- case 'ClassProperty':
834
- {
835
- if (node.optional === false) {
836
- delete node.optional;
837
- }
838
- if (node.declare === false) {
839
- delete node.declare;
840
- }
841
- if (node.typeAnnotation == null) {
842
- delete node.typeAnnotation;
843
- }
844
- return node;
845
- }
846
- case 'ClassPrivateProperty':
847
- {
848
- if (node.typeAnnotation == null) {
849
- delete node.typeAnnotation;
850
- }
851
- return node;
852
- }
853
- case 'ExportNamedDeclaration':
854
- {
855
- if (node.declaration == null) {
856
- delete node.declaration;
857
- }
858
- return node;
859
- }
860
- case 'ImportDeclaration':
861
- {
862
- if (node.attributes == null || node.attributes.length === 0) {
863
- delete node.attributes;
864
- }
865
- return node;
866
- }
867
- case 'ArrayExpression':
868
- {
869
- delete node.trailingComma;
870
- return node;
871
- }
872
- case 'JSXOpeningElement':
873
- {
874
- if (node.typeArguments == null) {
875
- delete node.typeArguments;
876
- }
877
- return node;
878
- }
879
- case 'DeclareOpaqueType':
880
- case 'OpaqueType':
881
- {
882
- if (node.lowerBound != null) {
883
- delete node.lowerBound;
884
- }
885
- if (node.upperBound != null) {
886
- delete node.upperBound;
887
- }
888
- return node;
889
- }
890
- default:
891
- {
892
- return node;
893
- }
894
- }
895
- }
896
- function transformProgram(program, options) {
897
- var _resultNode$type;
898
- const resultNode = _SimpleTransform.SimpleTransform.transform(program, {
899
- transform(node) {
900
- return transformNode(node);
901
- },
902
- visitorKeys: FlowESTreeAndBabelVisitorKeys
903
- });
904
- _SimpleTraverser.SimpleTraverser.traverse(resultNode, {
905
- enter(node) {
906
- fixSourceLocation(node, options);
907
- },
908
- leave() {},
909
- visitorKeys: FlowESTreeAndBabelVisitorKeys
910
- });
911
- if ((resultNode == null ? void 0 : resultNode.type) === 'File') {
912
- return resultNode;
913
- }
914
- throw new Error(`Unknown AST node of type "${(_resultNode$type = resultNode == null ? void 0 : resultNode.type) != null ? _resultNode$type : 'NULL'}" returned from Babel conversion`);
915
- }