flow-parser 0.321.0 → 0.323.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.
- package/README.md +25 -32
- package/dist/FlowParser.js +3 -53
- package/dist/FlowParserDeserializer.js +3 -41
- package/dist/FlowParserNodeDeserializers.js +0 -7
- package/dist/FlowParserWASM.js +1 -1
- package/dist/HermesParserDecodeUTF8String.js +0 -9
- package/dist/ParserOptions.js +1 -2
- package/dist/babel/TransformESTreeToBabel.js +9 -157
- package/dist/estree/StripFlowTypes.js +0 -26
- package/dist/estree/StripFlowTypesForBabel.js +0 -24
- package/dist/estree/TransformComponentSyntax.js +1 -87
- package/dist/estree/TransformComponentSyntax.js.flow +1 -0
- package/dist/estree/TransformEnumSyntax.js +0 -12
- package/dist/estree/TransformMatchSyntax.js +3 -99
- package/dist/estree/TransformRecordSyntax.js +3 -31
- package/dist/getModuleDocblock.js +0 -21
- package/dist/index.js +25 -99
- package/dist/transform/SimpleTransform.js +0 -21
- package/dist/transform/astArrayMutationHelpers.js +0 -9
- package/dist/transform/astNodeMutationHelpers.js +4 -26
- package/dist/traverse/SimpleTraverser.js +2 -22
- package/dist/traverse/getVisitorKeys.js +3 -9
- package/dist/utils/Builders.js +1 -17
- package/dist/utils/GenID.js +0 -7
- package/dist/utils/createSyntaxError.js +0 -1
- package/dist/utils/isReservedWord.js +0 -2
- package/dist/utils/mutateESTreeASTForPrettier.js +6 -21
- package/package.json +2 -2
- package/dist/transform/print/comments/comments.js +0 -245
- package/dist/transform/print/comments/comments.js.flow +0 -330
- package/dist/transform/print/comments/prettier/common/util.js +0 -235
- package/dist/transform/print/comments/prettier/language-js/comments.js +0 -663
- package/dist/transform/print/comments/prettier/language-js/loc.js +0 -30
- package/dist/transform/print/comments/prettier/language-js/printer-estree.js +0 -23
- package/dist/transform/print/comments/prettier/language-js/utils.js +0 -89
- package/dist/transform/print/comments/prettier/main/comments.js +0 -374
- package/dist/transform/print/comments/prettier/utils/get-last.js +0 -5
- package/dist/transform/print/detachedNodeTypes.js +0 -1
- package/dist/transform/print/detachedNodeTypes.js.flow +0 -24
- package/dist/transform/print/print.js +0 -68
- package/dist/transform/print/print.js.flow +0 -87
|
@@ -4,23 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.transformProgram = transformProgram;
|
|
7
|
-
|
|
8
7
|
var _SimpleTransform = require("../transform/SimpleTransform");
|
|
9
|
-
|
|
10
8
|
var _SimpleTraverser = require("../traverse/SimpleTraverser");
|
|
11
|
-
|
|
12
9
|
var _ESTreeVisitorKeys = _interopRequireDefault(require("../generated/ESTreeVisitorKeys"));
|
|
13
|
-
|
|
14
10
|
var _createSyntaxError = require("../utils/createSyntaxError");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
default: obj
|
|
11
|
+
function _interopRequireDefault(e) {
|
|
12
|
+
return e && e.__esModule ? e : {
|
|
13
|
+
default: e
|
|
19
14
|
};
|
|
20
15
|
}
|
|
21
|
-
|
|
22
16
|
const EMPTY_PARENT = null;
|
|
23
|
-
const FlowESTreeAndBabelVisitorKeys = {
|
|
17
|
+
const FlowESTreeAndBabelVisitorKeys = {
|
|
18
|
+
..._ESTreeVisitorKeys.default,
|
|
24
19
|
BigIntLiteral: [],
|
|
25
20
|
BlockStatement: ['directives', ..._ESTreeVisitorKeys.default.BlockStatement],
|
|
26
21
|
BooleanLiteral: [],
|
|
@@ -51,40 +46,31 @@ const FlowESTreeAndBabelVisitorKeys = { ..._ESTreeVisitorKeys.default,
|
|
|
51
46
|
CommentBlock: [],
|
|
52
47
|
CommentLine: []
|
|
53
48
|
};
|
|
54
|
-
|
|
55
49
|
function nodeWith(node, overrideProps) {
|
|
56
50
|
return _SimpleTransform.SimpleTransform.nodeWith(node, overrideProps, FlowESTreeAndBabelVisitorKeys);
|
|
57
51
|
}
|
|
58
|
-
|
|
59
52
|
function fixSourceLocation(node, _options) {
|
|
60
53
|
const loc = node.loc;
|
|
61
|
-
|
|
62
54
|
if (loc == null) {
|
|
63
55
|
return;
|
|
64
56
|
}
|
|
65
|
-
|
|
66
57
|
node.loc = {
|
|
67
58
|
start: loc.start,
|
|
68
59
|
end: loc.end
|
|
69
60
|
};
|
|
70
|
-
|
|
71
61
|
if (node.type === 'Identifier') {
|
|
72
62
|
node.loc.identifierName = node.name;
|
|
73
63
|
}
|
|
74
|
-
|
|
75
64
|
node.start = node.range[0];
|
|
76
65
|
node.end = node.range[1];
|
|
77
66
|
delete node.range;
|
|
78
67
|
delete node.parent;
|
|
79
68
|
}
|
|
80
|
-
|
|
81
69
|
function mapNodeWithDirectives(node) {
|
|
82
70
|
if (node.directives != null) {
|
|
83
71
|
return node;
|
|
84
72
|
}
|
|
85
|
-
|
|
86
73
|
const directives = [];
|
|
87
|
-
|
|
88
74
|
for (const child of node.body) {
|
|
89
75
|
if (child.type === 'ExpressionStatement' && child.directive != null) {
|
|
90
76
|
directives.push({
|
|
@@ -108,16 +94,13 @@ function mapNodeWithDirectives(node) {
|
|
|
108
94
|
break;
|
|
109
95
|
}
|
|
110
96
|
}
|
|
111
|
-
|
|
112
97
|
return nodeWith(node, {
|
|
113
98
|
directives,
|
|
114
99
|
body: directives.length === 0 ? node.body : node.body.slice(directives.length)
|
|
115
100
|
});
|
|
116
101
|
}
|
|
117
|
-
|
|
118
102
|
function mapProgram(node) {
|
|
119
103
|
var _program$directives;
|
|
120
|
-
|
|
121
104
|
const program = mapNodeWithDirectives(node);
|
|
122
105
|
const startLoc = {
|
|
123
106
|
line: 1,
|
|
@@ -125,16 +108,13 @@ function mapProgram(node) {
|
|
|
125
108
|
};
|
|
126
109
|
let endLoc = program.loc.end;
|
|
127
110
|
let endRange = program.range[1];
|
|
128
|
-
|
|
129
111
|
if (program.comments.length > 0) {
|
|
130
112
|
const lastComment = program.comments[program.comments.length - 1];
|
|
131
|
-
|
|
132
113
|
if (lastComment.range[1] > endRange) {
|
|
133
114
|
endLoc = lastComment.loc.end;
|
|
134
115
|
endRange = lastComment.range[1];
|
|
135
116
|
}
|
|
136
117
|
}
|
|
137
|
-
|
|
138
118
|
const loc = {
|
|
139
119
|
start: startLoc,
|
|
140
120
|
end: endLoc
|
|
@@ -151,7 +131,6 @@ function mapProgram(node) {
|
|
|
151
131
|
range: comment.range
|
|
152
132
|
};
|
|
153
133
|
}
|
|
154
|
-
|
|
155
134
|
case 'Block':
|
|
156
135
|
{
|
|
157
136
|
return {
|
|
@@ -181,7 +160,6 @@ function mapProgram(node) {
|
|
|
181
160
|
parent: EMPTY_PARENT
|
|
182
161
|
};
|
|
183
162
|
}
|
|
184
|
-
|
|
185
163
|
function mapTemplateElement(node) {
|
|
186
164
|
const startCharsToExclude = 1;
|
|
187
165
|
const endCharsToExclude = node.tail ? 1 : 2;
|
|
@@ -198,16 +176,13 @@ function mapTemplateElement(node) {
|
|
|
198
176
|
node.range = [node.range[0] + startCharsToExclude, node.range[1] - endCharsToExclude];
|
|
199
177
|
return node;
|
|
200
178
|
}
|
|
201
|
-
|
|
202
179
|
function mapProperty(node) {
|
|
203
180
|
const key = node.key;
|
|
204
181
|
const value = node.value;
|
|
205
|
-
|
|
206
182
|
if (node.method || node.kind !== 'init') {
|
|
207
183
|
if (value.type !== 'FunctionExpression') {
|
|
208
184
|
throw (0, _createSyntaxError.createSyntaxError)(node, `Invalid method property, the value must be a "FunctionExpression" or "ArrowFunctionExpression. Instead got "${value.type}".`);
|
|
209
185
|
}
|
|
210
|
-
|
|
211
186
|
const newNode = {
|
|
212
187
|
type: 'ObjectMethod',
|
|
213
188
|
kind: node.kind === 'init' ? 'method' : node.kind,
|
|
@@ -225,14 +200,11 @@ function mapProperty(node) {
|
|
|
225
200
|
range: node.range,
|
|
226
201
|
parent: node.parent
|
|
227
202
|
};
|
|
228
|
-
|
|
229
203
|
if (node.kind !== 'init') {
|
|
230
204
|
newNode.variance = null;
|
|
231
205
|
}
|
|
232
|
-
|
|
233
206
|
return newNode;
|
|
234
207
|
}
|
|
235
|
-
|
|
236
208
|
const propertyValue = value;
|
|
237
209
|
return {
|
|
238
210
|
type: 'ObjectProperty',
|
|
@@ -246,7 +218,6 @@ function mapProperty(node) {
|
|
|
246
218
|
parent: node.parent
|
|
247
219
|
};
|
|
248
220
|
}
|
|
249
|
-
|
|
250
221
|
function mapMethodDefinition(node) {
|
|
251
222
|
const value = node.value;
|
|
252
223
|
const BaseClassMethod = {
|
|
@@ -266,18 +237,17 @@ function mapMethodDefinition(node) {
|
|
|
266
237
|
range: node.range,
|
|
267
238
|
parent: node.parent
|
|
268
239
|
};
|
|
269
|
-
|
|
270
240
|
if (node.key.type === 'PrivateIdentifier') {
|
|
271
|
-
return {
|
|
241
|
+
return {
|
|
242
|
+
...BaseClassMethod,
|
|
272
243
|
type: 'ClassPrivateMethod'
|
|
273
244
|
};
|
|
274
245
|
}
|
|
275
|
-
|
|
276
|
-
|
|
246
|
+
return {
|
|
247
|
+
...BaseClassMethod,
|
|
277
248
|
type: 'ClassMethod'
|
|
278
249
|
};
|
|
279
250
|
}
|
|
280
|
-
|
|
281
251
|
function mapExportAllDeclaration(node) {
|
|
282
252
|
if (node.exported != null) {
|
|
283
253
|
return {
|
|
@@ -303,18 +273,14 @@ function mapExportAllDeclaration(node) {
|
|
|
303
273
|
parent: node.parent
|
|
304
274
|
};
|
|
305
275
|
}
|
|
306
|
-
|
|
307
276
|
delete node.exported;
|
|
308
277
|
return node;
|
|
309
278
|
}
|
|
310
|
-
|
|
311
279
|
function mapRestElement(node) {
|
|
312
280
|
const argument = node.argument;
|
|
313
|
-
|
|
314
281
|
if ((argument.type === 'Identifier' || argument.type === 'ObjectPattern' || argument.type === 'ArrayPattern') && argument.typeAnnotation != null) {
|
|
315
282
|
const argumentRange = argument.range;
|
|
316
283
|
let argumentLoc = argument.loc;
|
|
317
|
-
|
|
318
284
|
if (argument.type === 'Identifier') {
|
|
319
285
|
argumentRange[1] = argumentRange[0] + argument.name.length;
|
|
320
286
|
argumentLoc = {
|
|
@@ -325,7 +291,6 @@ function mapRestElement(node) {
|
|
|
325
291
|
}
|
|
326
292
|
};
|
|
327
293
|
}
|
|
328
|
-
|
|
329
294
|
return nodeWith(node, {
|
|
330
295
|
typeAnnotation: argument.typeAnnotation,
|
|
331
296
|
argument: nodeWith(argument, {
|
|
@@ -335,10 +300,8 @@ function mapRestElement(node) {
|
|
|
335
300
|
})
|
|
336
301
|
});
|
|
337
302
|
}
|
|
338
|
-
|
|
339
303
|
return node;
|
|
340
304
|
}
|
|
341
|
-
|
|
342
305
|
function mapImportExpression(node) {
|
|
343
306
|
return {
|
|
344
307
|
type: 'CallExpression',
|
|
@@ -360,7 +323,6 @@ function mapImportExpression(node) {
|
|
|
360
323
|
parent: node.parent
|
|
361
324
|
};
|
|
362
325
|
}
|
|
363
|
-
|
|
364
326
|
function mapPrivateIdentifier(node) {
|
|
365
327
|
return {
|
|
366
328
|
type: 'PrivateName',
|
|
@@ -384,7 +346,6 @@ function mapPrivateIdentifier(node) {
|
|
|
384
346
|
parent: node.parent
|
|
385
347
|
};
|
|
386
348
|
}
|
|
387
|
-
|
|
388
349
|
function mapPropertyDefinition(node) {
|
|
389
350
|
if (node.key.type === 'PrivateIdentifier') {
|
|
390
351
|
return {
|
|
@@ -399,7 +360,6 @@ function mapPropertyDefinition(node) {
|
|
|
399
360
|
parent: node.parent
|
|
400
361
|
};
|
|
401
362
|
}
|
|
402
|
-
|
|
403
363
|
return {
|
|
404
364
|
type: 'ClassProperty',
|
|
405
365
|
key: node.key,
|
|
@@ -415,10 +375,8 @@ function mapPropertyDefinition(node) {
|
|
|
415
375
|
parent: node.parent
|
|
416
376
|
};
|
|
417
377
|
}
|
|
418
|
-
|
|
419
378
|
function mapTypeofTypeAnnotation(node) {
|
|
420
379
|
delete node.typeArguments;
|
|
421
|
-
|
|
422
380
|
if (node.argument.type !== 'GenericTypeAnnotation') {
|
|
423
381
|
return nodeWith(node, {
|
|
424
382
|
argument: {
|
|
@@ -431,43 +389,33 @@ function mapTypeofTypeAnnotation(node) {
|
|
|
431
389
|
}
|
|
432
390
|
});
|
|
433
391
|
}
|
|
434
|
-
|
|
435
392
|
return node;
|
|
436
393
|
}
|
|
437
|
-
|
|
438
394
|
function mapDeclareVariable(node) {
|
|
439
395
|
var _babelNode$declaratio;
|
|
440
|
-
|
|
441
396
|
const babelNode = node;
|
|
442
|
-
|
|
443
397
|
if (babelNode.id == null && Array.isArray(babelNode.declarations) && ((_babelNode$declaratio = babelNode.declarations[0]) == null ? void 0 : _babelNode$declaratio.id) != null) {
|
|
444
398
|
babelNode.id = babelNode.declarations[0].id;
|
|
445
399
|
}
|
|
446
|
-
|
|
447
400
|
delete babelNode.declarations;
|
|
448
401
|
delete babelNode.kind;
|
|
449
402
|
delete babelNode.implicitDeclare;
|
|
450
403
|
return babelNode;
|
|
451
404
|
}
|
|
452
|
-
|
|
453
405
|
function mapJSXElement(node) {
|
|
454
406
|
if (node.openingElement.typeArguments != null) {
|
|
455
407
|
delete node.openingElement.typeArguments;
|
|
456
408
|
}
|
|
457
|
-
|
|
458
409
|
return node;
|
|
459
410
|
}
|
|
460
|
-
|
|
461
411
|
function mapChainExpressionInnerNode(node) {
|
|
462
412
|
switch (node.type) {
|
|
463
413
|
case 'MemberExpression':
|
|
464
414
|
{
|
|
465
415
|
const innerObject = mapChainExpressionInnerNode(node.object);
|
|
466
|
-
|
|
467
416
|
if (!node.optional && innerObject.type !== 'OptionalMemberExpression' && innerObject.type !== 'OptionalCallExpression') {
|
|
468
417
|
return node;
|
|
469
418
|
}
|
|
470
|
-
|
|
471
419
|
return {
|
|
472
420
|
type: 'OptionalMemberExpression',
|
|
473
421
|
object: innerObject,
|
|
@@ -479,15 +427,12 @@ function mapChainExpressionInnerNode(node) {
|
|
|
479
427
|
parent: node.parent
|
|
480
428
|
};
|
|
481
429
|
}
|
|
482
|
-
|
|
483
430
|
case 'CallExpression':
|
|
484
431
|
{
|
|
485
432
|
const innerCallee = mapChainExpressionInnerNode(node.callee);
|
|
486
|
-
|
|
487
433
|
if (!node.optional && innerCallee.type !== 'OptionalMemberExpression' && innerCallee.type !== 'OptionalCallExpression') {
|
|
488
434
|
return node;
|
|
489
435
|
}
|
|
490
|
-
|
|
491
436
|
return {
|
|
492
437
|
type: 'OptionalCallExpression',
|
|
493
438
|
callee: innerCallee,
|
|
@@ -499,25 +444,21 @@ function mapChainExpressionInnerNode(node) {
|
|
|
499
444
|
parent: node.parent
|
|
500
445
|
};
|
|
501
446
|
}
|
|
502
|
-
|
|
503
447
|
default:
|
|
504
448
|
{
|
|
505
449
|
return node;
|
|
506
450
|
}
|
|
507
451
|
}
|
|
508
452
|
}
|
|
509
|
-
|
|
510
453
|
function mapChainExpression(node) {
|
|
511
454
|
return mapChainExpressionInnerNode(node.expression);
|
|
512
455
|
}
|
|
513
|
-
|
|
514
456
|
function mapLiteral(node) {
|
|
515
457
|
const base = {
|
|
516
458
|
loc: node.loc,
|
|
517
459
|
range: node.range,
|
|
518
460
|
parent: node.parent
|
|
519
461
|
};
|
|
520
|
-
|
|
521
462
|
switch (node.literalType) {
|
|
522
463
|
case 'string':
|
|
523
464
|
{
|
|
@@ -531,7 +472,6 @@ function mapLiteral(node) {
|
|
|
531
472
|
...base
|
|
532
473
|
};
|
|
533
474
|
}
|
|
534
|
-
|
|
535
475
|
case 'numeric':
|
|
536
476
|
{
|
|
537
477
|
return {
|
|
@@ -544,7 +484,6 @@ function mapLiteral(node) {
|
|
|
544
484
|
...base
|
|
545
485
|
};
|
|
546
486
|
}
|
|
547
|
-
|
|
548
487
|
case 'bigint':
|
|
549
488
|
{
|
|
550
489
|
return {
|
|
@@ -557,7 +496,6 @@ function mapLiteral(node) {
|
|
|
557
496
|
...base
|
|
558
497
|
};
|
|
559
498
|
}
|
|
560
|
-
|
|
561
499
|
case 'boolean':
|
|
562
500
|
{
|
|
563
501
|
return {
|
|
@@ -566,7 +504,6 @@ function mapLiteral(node) {
|
|
|
566
504
|
...base
|
|
567
505
|
};
|
|
568
506
|
}
|
|
569
|
-
|
|
570
507
|
case 'null':
|
|
571
508
|
{
|
|
572
509
|
return {
|
|
@@ -574,7 +511,6 @@ function mapLiteral(node) {
|
|
|
574
511
|
...base
|
|
575
512
|
};
|
|
576
513
|
}
|
|
577
|
-
|
|
578
514
|
case 'regexp':
|
|
579
515
|
{
|
|
580
516
|
return {
|
|
@@ -589,90 +525,72 @@ function mapLiteral(node) {
|
|
|
589
525
|
}
|
|
590
526
|
}
|
|
591
527
|
}
|
|
592
|
-
|
|
593
528
|
function transformNode(node) {
|
|
594
529
|
switch (node.type) {
|
|
595
530
|
case 'Program':
|
|
596
531
|
{
|
|
597
532
|
var _node$parent;
|
|
598
|
-
|
|
599
533
|
if (((_node$parent = node.parent) == null ? void 0 : _node$parent.type) === 'File') {
|
|
600
534
|
return node;
|
|
601
535
|
}
|
|
602
|
-
|
|
603
536
|
return mapProgram(node);
|
|
604
537
|
}
|
|
605
|
-
|
|
606
538
|
case 'BlockStatement':
|
|
607
539
|
{
|
|
608
540
|
return mapNodeWithDirectives(node);
|
|
609
541
|
}
|
|
610
|
-
|
|
611
542
|
case 'Property':
|
|
612
543
|
{
|
|
613
544
|
return mapProperty(node);
|
|
614
545
|
}
|
|
615
|
-
|
|
616
546
|
case 'TemplateElement':
|
|
617
547
|
{
|
|
618
548
|
return mapTemplateElement(node);
|
|
619
549
|
}
|
|
620
|
-
|
|
621
550
|
case 'MethodDefinition':
|
|
622
551
|
{
|
|
623
552
|
return mapMethodDefinition(node);
|
|
624
553
|
}
|
|
625
|
-
|
|
626
554
|
case 'ExportAllDeclaration':
|
|
627
555
|
{
|
|
628
556
|
return mapExportAllDeclaration(node);
|
|
629
557
|
}
|
|
630
|
-
|
|
631
558
|
case 'RestElement':
|
|
632
559
|
{
|
|
633
560
|
return mapRestElement(node);
|
|
634
561
|
}
|
|
635
|
-
|
|
636
562
|
case 'ImportExpression':
|
|
637
563
|
{
|
|
638
564
|
return mapImportExpression(node);
|
|
639
565
|
}
|
|
640
|
-
|
|
641
566
|
case 'PrivateIdentifier':
|
|
642
567
|
{
|
|
643
568
|
return mapPrivateIdentifier(node);
|
|
644
569
|
}
|
|
645
|
-
|
|
646
570
|
case 'PropertyDefinition':
|
|
647
571
|
{
|
|
648
572
|
return mapPropertyDefinition(node);
|
|
649
573
|
}
|
|
650
|
-
|
|
651
574
|
case 'TypeofTypeAnnotation':
|
|
652
575
|
{
|
|
653
576
|
return mapTypeofTypeAnnotation(node);
|
|
654
577
|
}
|
|
655
|
-
|
|
656
578
|
case 'DeclareVariable':
|
|
657
579
|
{
|
|
658
580
|
return mapDeclareVariable(node);
|
|
659
581
|
}
|
|
660
|
-
|
|
661
582
|
case 'JSXElement':
|
|
662
583
|
{
|
|
663
584
|
return mapJSXElement(node);
|
|
664
585
|
}
|
|
665
|
-
|
|
666
586
|
case 'Literal':
|
|
667
587
|
{
|
|
668
588
|
return mapLiteral(node);
|
|
669
589
|
}
|
|
670
|
-
|
|
671
590
|
case 'ChainExpression':
|
|
672
591
|
{
|
|
673
592
|
return mapChainExpression(node);
|
|
674
593
|
}
|
|
675
|
-
|
|
676
594
|
case 'TypeCastExpression':
|
|
677
595
|
{
|
|
678
596
|
node.loc.start.column = node.loc.start.column + 1;
|
|
@@ -680,7 +598,6 @@ function transformNode(node) {
|
|
|
680
598
|
node.range = [node.range[0] + 1, node.range[1] - 1];
|
|
681
599
|
return node;
|
|
682
600
|
}
|
|
683
|
-
|
|
684
601
|
case 'AsExpression':
|
|
685
602
|
{
|
|
686
603
|
const {
|
|
@@ -695,12 +612,10 @@ function transformNode(node) {
|
|
|
695
612
|
};
|
|
696
613
|
return node;
|
|
697
614
|
}
|
|
698
|
-
|
|
699
615
|
case 'AsConstExpression':
|
|
700
616
|
{
|
|
701
617
|
return node.expression;
|
|
702
618
|
}
|
|
703
|
-
|
|
704
619
|
case 'NumberLiteralTypeAnnotation':
|
|
705
620
|
{
|
|
706
621
|
node.extra = {
|
|
@@ -710,7 +625,6 @@ function transformNode(node) {
|
|
|
710
625
|
delete node.raw;
|
|
711
626
|
return node;
|
|
712
627
|
}
|
|
713
|
-
|
|
714
628
|
case 'StringLiteralTypeAnnotation':
|
|
715
629
|
{
|
|
716
630
|
node.extra = {
|
|
@@ -720,7 +634,6 @@ function transformNode(node) {
|
|
|
720
634
|
delete node.raw;
|
|
721
635
|
return node;
|
|
722
636
|
}
|
|
723
|
-
|
|
724
637
|
case 'BigIntLiteralTypeAnnotation':
|
|
725
638
|
{
|
|
726
639
|
node.extra = {
|
|
@@ -731,13 +644,11 @@ function transformNode(node) {
|
|
|
731
644
|
delete node.raw;
|
|
732
645
|
return node;
|
|
733
646
|
}
|
|
734
|
-
|
|
735
647
|
case 'BooleanLiteralTypeAnnotation':
|
|
736
648
|
{
|
|
737
649
|
delete node.raw;
|
|
738
650
|
return node;
|
|
739
651
|
}
|
|
740
|
-
|
|
741
652
|
case 'TupleTypeAnnotation':
|
|
742
653
|
{
|
|
743
654
|
delete node.inexact;
|
|
@@ -745,7 +656,6 @@ function transformNode(node) {
|
|
|
745
656
|
delete node.elementTypes;
|
|
746
657
|
return node;
|
|
747
658
|
}
|
|
748
|
-
|
|
749
659
|
case 'UnknownTypeAnnotation':
|
|
750
660
|
{
|
|
751
661
|
return {
|
|
@@ -765,7 +675,6 @@ function transformNode(node) {
|
|
|
765
675
|
parent: EMPTY_PARENT
|
|
766
676
|
};
|
|
767
677
|
}
|
|
768
|
-
|
|
769
678
|
case 'NeverTypeAnnotation':
|
|
770
679
|
{
|
|
771
680
|
return {
|
|
@@ -785,7 +694,6 @@ function transformNode(node) {
|
|
|
785
694
|
parent: EMPTY_PARENT
|
|
786
695
|
};
|
|
787
696
|
}
|
|
788
|
-
|
|
789
697
|
case 'UndefinedTypeAnnotation':
|
|
790
698
|
{
|
|
791
699
|
return {
|
|
@@ -805,7 +713,6 @@ function transformNode(node) {
|
|
|
805
713
|
parent: EMPTY_PARENT
|
|
806
714
|
};
|
|
807
715
|
}
|
|
808
|
-
|
|
809
716
|
case 'JSXText':
|
|
810
717
|
{
|
|
811
718
|
node.extra = {
|
|
@@ -815,249 +722,194 @@ function transformNode(node) {
|
|
|
815
722
|
delete node.raw;
|
|
816
723
|
return node;
|
|
817
724
|
}
|
|
818
|
-
|
|
819
725
|
case 'Identifier':
|
|
820
726
|
{
|
|
821
727
|
if (node.optional === false || node.optional == null) {
|
|
822
728
|
delete node.optional;
|
|
823
729
|
}
|
|
824
|
-
|
|
825
730
|
if (node.typeAnnotation == null) {
|
|
826
731
|
delete node.typeAnnotation;
|
|
827
732
|
}
|
|
828
|
-
|
|
829
733
|
return node;
|
|
830
734
|
}
|
|
831
|
-
|
|
832
735
|
case 'CallExpression':
|
|
833
736
|
{
|
|
834
737
|
if (node.optional === false) {
|
|
835
738
|
delete node.optional;
|
|
836
739
|
}
|
|
837
|
-
|
|
838
740
|
if (node.typeArguments == null) {
|
|
839
741
|
delete node.typeArguments;
|
|
840
742
|
}
|
|
841
|
-
|
|
842
743
|
return node;
|
|
843
744
|
}
|
|
844
|
-
|
|
845
745
|
case 'OptionalCallExpression':
|
|
846
746
|
{
|
|
847
747
|
if (node.typeArguments == null) {
|
|
848
748
|
delete node.typeArguments;
|
|
849
749
|
}
|
|
850
|
-
|
|
851
750
|
return node;
|
|
852
751
|
}
|
|
853
|
-
|
|
854
752
|
case 'MemberExpression':
|
|
855
753
|
{
|
|
856
754
|
delete node.optional;
|
|
857
755
|
return node;
|
|
858
756
|
}
|
|
859
|
-
|
|
860
757
|
case 'ExpressionStatement':
|
|
861
758
|
{
|
|
862
759
|
delete node.directive;
|
|
863
760
|
return node;
|
|
864
761
|
}
|
|
865
|
-
|
|
866
762
|
case 'ObjectPattern':
|
|
867
763
|
case 'ArrayPattern':
|
|
868
764
|
{
|
|
869
765
|
if (node.typeAnnotation == null) {
|
|
870
766
|
delete node.typeAnnotation;
|
|
871
767
|
}
|
|
872
|
-
|
|
873
768
|
return node;
|
|
874
769
|
}
|
|
875
|
-
|
|
876
770
|
case 'FunctionDeclaration':
|
|
877
771
|
case 'FunctionExpression':
|
|
878
772
|
case 'ArrowFunctionExpression':
|
|
879
773
|
case 'ClassMethod':
|
|
880
774
|
{
|
|
881
775
|
delete node.expression;
|
|
882
|
-
|
|
883
776
|
if (node.predicate == null) {
|
|
884
777
|
delete node.predicate;
|
|
885
778
|
}
|
|
886
|
-
|
|
887
779
|
if (node.returnType == null) {
|
|
888
780
|
delete node.returnType;
|
|
889
781
|
}
|
|
890
|
-
|
|
891
782
|
if (node.typeParameters == null) {
|
|
892
783
|
delete node.typeParameters;
|
|
893
784
|
}
|
|
894
|
-
|
|
895
785
|
return node;
|
|
896
786
|
}
|
|
897
|
-
|
|
898
787
|
case 'ObjectMethod':
|
|
899
788
|
{
|
|
900
789
|
if (node.returnType == null) {
|
|
901
790
|
delete node.returnType;
|
|
902
791
|
}
|
|
903
|
-
|
|
904
792
|
if (node.typeParameters == null) {
|
|
905
793
|
delete node.typeParameters;
|
|
906
794
|
}
|
|
907
|
-
|
|
908
795
|
return node;
|
|
909
796
|
}
|
|
910
|
-
|
|
911
797
|
case 'ClassPrivateMethod':
|
|
912
798
|
{
|
|
913
799
|
if (node.computed === false) {
|
|
914
800
|
delete node.computed;
|
|
915
801
|
}
|
|
916
|
-
|
|
917
802
|
if (node.predicate == null) {
|
|
918
803
|
delete node.predicate;
|
|
919
804
|
}
|
|
920
|
-
|
|
921
805
|
if (node.returnType == null) {
|
|
922
806
|
delete node.returnType;
|
|
923
807
|
}
|
|
924
|
-
|
|
925
808
|
if (node.typeParameters == null) {
|
|
926
809
|
delete node.typeParameters;
|
|
927
810
|
}
|
|
928
|
-
|
|
929
811
|
return node;
|
|
930
812
|
}
|
|
931
|
-
|
|
932
813
|
case 'ClassExpression':
|
|
933
814
|
case 'ClassDeclaration':
|
|
934
815
|
{
|
|
935
816
|
if (node.decorators == null || node.decorators.length === 0) {
|
|
936
817
|
delete node.decorators;
|
|
937
818
|
}
|
|
938
|
-
|
|
939
819
|
if (node.implements == null || node.implements.length === 0) {
|
|
940
820
|
delete node.implements;
|
|
941
821
|
}
|
|
942
|
-
|
|
943
822
|
if (node.superTypeArguments == null) {
|
|
944
823
|
delete node.superTypeArguments;
|
|
945
824
|
} else {
|
|
946
825
|
node.superTypeParameters = node.superTypeArguments;
|
|
947
826
|
delete node.superTypeArguments;
|
|
948
827
|
}
|
|
949
|
-
|
|
950
828
|
if (node.typeParameters == null) {
|
|
951
829
|
delete node.typeParameters;
|
|
952
830
|
}
|
|
953
|
-
|
|
954
831
|
return node;
|
|
955
832
|
}
|
|
956
|
-
|
|
957
833
|
case 'ClassProperty':
|
|
958
834
|
{
|
|
959
835
|
if (node.optional === false) {
|
|
960
836
|
delete node.optional;
|
|
961
837
|
}
|
|
962
|
-
|
|
963
838
|
if (node.declare === false) {
|
|
964
839
|
delete node.declare;
|
|
965
840
|
}
|
|
966
|
-
|
|
967
841
|
if (node.typeAnnotation == null) {
|
|
968
842
|
delete node.typeAnnotation;
|
|
969
843
|
}
|
|
970
|
-
|
|
971
844
|
return node;
|
|
972
845
|
}
|
|
973
|
-
|
|
974
846
|
case 'ClassPrivateProperty':
|
|
975
847
|
{
|
|
976
848
|
if (node.typeAnnotation == null) {
|
|
977
849
|
delete node.typeAnnotation;
|
|
978
850
|
}
|
|
979
|
-
|
|
980
851
|
return node;
|
|
981
852
|
}
|
|
982
|
-
|
|
983
853
|
case 'ExportNamedDeclaration':
|
|
984
854
|
{
|
|
985
855
|
if (node.declaration == null) {
|
|
986
856
|
delete node.declaration;
|
|
987
857
|
}
|
|
988
|
-
|
|
989
858
|
return node;
|
|
990
859
|
}
|
|
991
|
-
|
|
992
860
|
case 'ImportDeclaration':
|
|
993
861
|
{
|
|
994
862
|
if (node.attributes == null || node.attributes.length === 0) {
|
|
995
863
|
delete node.attributes;
|
|
996
864
|
}
|
|
997
|
-
|
|
998
865
|
return node;
|
|
999
866
|
}
|
|
1000
|
-
|
|
1001
867
|
case 'ArrayExpression':
|
|
1002
868
|
{
|
|
1003
869
|
delete node.trailingComma;
|
|
1004
870
|
return node;
|
|
1005
871
|
}
|
|
1006
|
-
|
|
1007
872
|
case 'JSXOpeningElement':
|
|
1008
873
|
{
|
|
1009
874
|
if (node.typeArguments == null) {
|
|
1010
875
|
delete node.typeArguments;
|
|
1011
876
|
}
|
|
1012
|
-
|
|
1013
877
|
return node;
|
|
1014
878
|
}
|
|
1015
|
-
|
|
1016
879
|
case 'DeclareOpaqueType':
|
|
1017
880
|
case 'OpaqueType':
|
|
1018
881
|
{
|
|
1019
882
|
if (node.lowerBound != null) {
|
|
1020
883
|
delete node.lowerBound;
|
|
1021
884
|
}
|
|
1022
|
-
|
|
1023
885
|
if (node.upperBound != null) {
|
|
1024
886
|
delete node.upperBound;
|
|
1025
887
|
}
|
|
1026
|
-
|
|
1027
888
|
return node;
|
|
1028
889
|
}
|
|
1029
|
-
|
|
1030
890
|
default:
|
|
1031
891
|
{
|
|
1032
892
|
return node;
|
|
1033
893
|
}
|
|
1034
894
|
}
|
|
1035
895
|
}
|
|
1036
|
-
|
|
1037
896
|
function transformProgram(program, options) {
|
|
1038
897
|
var _resultNode$type;
|
|
1039
|
-
|
|
1040
898
|
const resultNode = _SimpleTransform.SimpleTransform.transform(program, {
|
|
1041
899
|
transform(node) {
|
|
1042
900
|
return transformNode(node);
|
|
1043
901
|
},
|
|
1044
|
-
|
|
1045
902
|
visitorKeys: FlowESTreeAndBabelVisitorKeys
|
|
1046
903
|
});
|
|
1047
|
-
|
|
1048
904
|
_SimpleTraverser.SimpleTraverser.traverse(resultNode, {
|
|
1049
905
|
enter(node) {
|
|
1050
906
|
fixSourceLocation(node, options);
|
|
1051
907
|
},
|
|
1052
|
-
|
|
1053
908
|
leave() {},
|
|
1054
|
-
|
|
1055
909
|
visitorKeys: FlowESTreeAndBabelVisitorKeys
|
|
1056
910
|
});
|
|
1057
|
-
|
|
1058
911
|
if ((resultNode == null ? void 0 : resultNode.type) === 'File') {
|
|
1059
912
|
return resultNode;
|
|
1060
913
|
}
|
|
1061
|
-
|
|
1062
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`);
|
|
1063
915
|
}
|