flow-parser 0.321.0 → 0.322.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/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 +0 -87
- 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/transform/print/comments/comments.js +2 -51
- package/dist/transform/print/comments/prettier/common/util.js +0 -49
- package/dist/transform/print/comments/prettier/language-js/comments.js +0 -111
- package/dist/transform/print/comments/prettier/language-js/loc.js +0 -6
- package/dist/transform/print/comments/prettier/language-js/printer-estree.js +0 -3
- package/dist/transform/print/comments/prettier/language-js/utils.js +0 -20
- package/dist/transform/print/comments/prettier/main/comments.js +2 -63
- package/dist/transform/print/comments/prettier/utils/get-last.js +0 -1
- package/dist/transform/print/print.js +6 -22
- 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
|
@@ -4,25 +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 _astNodeMutationHelpers = require("../transform/astNodeMutationHelpers");
|
|
11
|
-
|
|
12
9
|
var _SimpleTraverser = require("../traverse/SimpleTraverser");
|
|
13
|
-
|
|
14
10
|
var _createSyntaxError = require("../utils/createSyntaxError");
|
|
15
|
-
|
|
16
11
|
const nodeWith = _SimpleTransform.SimpleTransform.nodeWith;
|
|
17
12
|
const EMPTY_PARENT = null;
|
|
18
|
-
|
|
19
13
|
function createDefaultPosition() {
|
|
20
14
|
return {
|
|
21
15
|
line: 1,
|
|
22
16
|
column: 0
|
|
23
17
|
};
|
|
24
18
|
}
|
|
25
|
-
|
|
26
19
|
function declareVariableDeclarator(id, node) {
|
|
27
20
|
return {
|
|
28
21
|
type: 'VariableDeclarator',
|
|
@@ -33,7 +26,6 @@ function declareVariableDeclarator(id, node) {
|
|
|
33
26
|
parent: EMPTY_PARENT
|
|
34
27
|
};
|
|
35
28
|
}
|
|
36
|
-
|
|
37
29
|
function mapDeclareComponent(node) {
|
|
38
30
|
const id = nodeWith(node.id, {
|
|
39
31
|
typeAnnotation: {
|
|
@@ -59,20 +51,16 @@ function mapDeclareComponent(node) {
|
|
|
59
51
|
parent: node.parent
|
|
60
52
|
};
|
|
61
53
|
}
|
|
62
|
-
|
|
63
54
|
function getComponentParameterName(paramName) {
|
|
64
55
|
switch (paramName.type) {
|
|
65
56
|
case 'Identifier':
|
|
66
57
|
return paramName.name;
|
|
67
|
-
|
|
68
58
|
case 'Literal':
|
|
69
59
|
return paramName.value;
|
|
70
|
-
|
|
71
60
|
default:
|
|
72
61
|
throw (0, _createSyntaxError.createSyntaxError)(paramName, `Unknown Component parameter name type of "${paramName.type}"`);
|
|
73
62
|
}
|
|
74
63
|
}
|
|
75
|
-
|
|
76
64
|
function createPropsTypeAnnotation(propTypes, spread, loc, range) {
|
|
77
65
|
const createParamsTypeLoc = () => ({
|
|
78
66
|
loc: {
|
|
@@ -82,7 +70,6 @@ function createPropsTypeAnnotation(propTypes, spread, loc, range) {
|
|
|
82
70
|
range: range != null ? range : [0, 0],
|
|
83
71
|
parent: EMPTY_PARENT
|
|
84
72
|
});
|
|
85
|
-
|
|
86
73
|
if (spread != null && propTypes.length === 0) {
|
|
87
74
|
return {
|
|
88
75
|
type: 'TypeAnnotation',
|
|
@@ -90,13 +77,10 @@ function createPropsTypeAnnotation(propTypes, spread, loc, range) {
|
|
|
90
77
|
...createParamsTypeLoc()
|
|
91
78
|
};
|
|
92
79
|
}
|
|
93
|
-
|
|
94
80
|
const typeProperties = [...propTypes];
|
|
95
|
-
|
|
96
81
|
if (spread != null) {
|
|
97
82
|
typeProperties.unshift(spread);
|
|
98
83
|
}
|
|
99
|
-
|
|
100
84
|
const propTypeObj = {
|
|
101
85
|
type: 'ObjectTypeAnnotation',
|
|
102
86
|
callProperties: [],
|
|
@@ -128,17 +112,14 @@ function createPropsTypeAnnotation(propTypes, spread, loc, range) {
|
|
|
128
112
|
...createParamsTypeLoc()
|
|
129
113
|
};
|
|
130
114
|
}
|
|
131
|
-
|
|
132
115
|
function mapComponentParameters(params, options) {
|
|
133
116
|
var _options$reactRuntime;
|
|
134
|
-
|
|
135
117
|
if (params.length === 0) {
|
|
136
118
|
return {
|
|
137
119
|
props: null,
|
|
138
120
|
ref: null
|
|
139
121
|
};
|
|
140
122
|
}
|
|
141
|
-
|
|
142
123
|
if (params.length === 1 && params[0].type === 'RestElement' && params[0].argument.type === 'Identifier') {
|
|
143
124
|
const restElementArgument = params[0].argument;
|
|
144
125
|
return {
|
|
@@ -146,14 +127,12 @@ function mapComponentParameters(params, options) {
|
|
|
146
127
|
ref: null
|
|
147
128
|
};
|
|
148
129
|
}
|
|
149
|
-
|
|
150
130
|
let refParam = null;
|
|
151
131
|
const paramsWithoutRef = ((_options$reactRuntime = options.reactRuntimeTarget) != null ? _options$reactRuntime : '18') === '18' ? params.filter(param => {
|
|
152
132
|
if (param.type === 'ComponentParameter' && getComponentParameterName(param.name) === 'ref') {
|
|
153
133
|
refParam = param;
|
|
154
134
|
return false;
|
|
155
135
|
}
|
|
156
|
-
|
|
157
136
|
return true;
|
|
158
137
|
}) : params;
|
|
159
138
|
const [propTypes, spread] = paramsWithoutRef.reduce(([propTypes, spread], param) => {
|
|
@@ -163,10 +142,8 @@ function mapComponentParameters(params, options) {
|
|
|
163
142
|
if (spread != null) {
|
|
164
143
|
throw (0, _createSyntaxError.createSyntaxError)(param, `Invalid state, multiple rest elements found as Component Parameters`);
|
|
165
144
|
}
|
|
166
|
-
|
|
167
145
|
return [propTypes, mapComponentParameterRestElementType(param)];
|
|
168
146
|
}
|
|
169
|
-
|
|
170
147
|
case 'ComponentParameter':
|
|
171
148
|
{
|
|
172
149
|
propTypes.push(mapComponentParameterType(param));
|
|
@@ -176,12 +153,10 @@ function mapComponentParameters(params, options) {
|
|
|
176
153
|
}, [[], null]);
|
|
177
154
|
const propsProperties = paramsWithoutRef.flatMap(mapComponentParameter);
|
|
178
155
|
let props = null;
|
|
179
|
-
|
|
180
156
|
if (propsProperties.length === 0) {
|
|
181
157
|
if (refParam == null) {
|
|
182
158
|
throw new Error('TransformComponentSyntax: Invalid state, ref should always be set at this point if props are empty');
|
|
183
159
|
}
|
|
184
|
-
|
|
185
160
|
const emptyParamsLoc = {
|
|
186
161
|
start: refParam.loc.start,
|
|
187
162
|
end: refParam.loc.start
|
|
@@ -213,22 +188,17 @@ function mapComponentParameters(params, options) {
|
|
|
213
188
|
parent: EMPTY_PARENT
|
|
214
189
|
};
|
|
215
190
|
}
|
|
216
|
-
|
|
217
191
|
let ref = null;
|
|
218
|
-
|
|
219
192
|
if (refParam != null) {
|
|
220
193
|
ref = refParam.local;
|
|
221
194
|
}
|
|
222
|
-
|
|
223
195
|
return {
|
|
224
196
|
props,
|
|
225
197
|
ref
|
|
226
198
|
};
|
|
227
199
|
}
|
|
228
|
-
|
|
229
200
|
function mapComponentParameterType(param) {
|
|
230
201
|
var _typeAnnotation$typeA;
|
|
231
|
-
|
|
232
202
|
const typeAnnotation = param.local.type === 'AssignmentPattern' ? param.local.left.typeAnnotation : param.local.typeAnnotation;
|
|
233
203
|
const optional = param.local.type === 'AssignmentPattern' ? true : param.local.type === 'Identifier' ? param.local.optional : false;
|
|
234
204
|
return {
|
|
@@ -251,14 +221,11 @@ function mapComponentParameterType(param) {
|
|
|
251
221
|
parent: EMPTY_PARENT
|
|
252
222
|
};
|
|
253
223
|
}
|
|
254
|
-
|
|
255
224
|
function mapComponentParameterRestElementType(param) {
|
|
256
225
|
var _param$argument$typeA, _param$argument$typeA2;
|
|
257
|
-
|
|
258
226
|
if (param.argument.type !== 'Identifier' && param.argument.type !== 'ObjectPattern') {
|
|
259
227
|
throw (0, _createSyntaxError.createSyntaxError)(param, `Invalid ${param.argument.type} encountered in restParameter`);
|
|
260
228
|
}
|
|
261
|
-
|
|
262
229
|
return {
|
|
263
230
|
type: 'ObjectTypeSpreadProperty',
|
|
264
231
|
argument: (_param$argument$typeA = (_param$argument$typeA2 = param.argument.typeAnnotation) == null ? void 0 : _param$argument$typeA2.typeAnnotation) != null ? _param$argument$typeA : {
|
|
@@ -272,7 +239,6 @@ function mapComponentParameterRestElementType(param) {
|
|
|
272
239
|
parent: EMPTY_PARENT
|
|
273
240
|
};
|
|
274
241
|
}
|
|
275
|
-
|
|
276
242
|
function mapComponentParameter(param) {
|
|
277
243
|
switch (param.type) {
|
|
278
244
|
case 'RestElement':
|
|
@@ -288,7 +254,6 @@ function mapComponentParameter(param) {
|
|
|
288
254
|
});
|
|
289
255
|
return [a];
|
|
290
256
|
}
|
|
291
|
-
|
|
292
257
|
case 'ObjectPattern':
|
|
293
258
|
{
|
|
294
259
|
return param.argument.properties.map(property => {
|
|
@@ -297,18 +262,15 @@ function mapComponentParameter(param) {
|
|
|
297
262
|
});
|
|
298
263
|
});
|
|
299
264
|
}
|
|
300
|
-
|
|
301
265
|
default:
|
|
302
266
|
{
|
|
303
267
|
throw (0, _createSyntaxError.createSyntaxError)(param, `Unhandled ${param.argument.type} encountered in restParameter`);
|
|
304
268
|
}
|
|
305
269
|
}
|
|
306
270
|
}
|
|
307
|
-
|
|
308
271
|
case 'ComponentParameter':
|
|
309
272
|
{
|
|
310
273
|
let value;
|
|
311
|
-
|
|
312
274
|
if (param.local.type === 'AssignmentPattern') {
|
|
313
275
|
value = nodeWith(param.local, {
|
|
314
276
|
left: nodeWith(param.local.left, {
|
|
@@ -322,7 +284,6 @@ function mapComponentParameter(param) {
|
|
|
322
284
|
optional: false
|
|
323
285
|
});
|
|
324
286
|
}
|
|
325
|
-
|
|
326
287
|
if (param.name.type === 'Identifier' && param.shorthand && (value.type === 'Identifier' || value.type === 'AssignmentPattern')) {
|
|
327
288
|
return [{
|
|
328
289
|
type: 'Property',
|
|
@@ -337,7 +298,6 @@ function mapComponentParameter(param) {
|
|
|
337
298
|
parent: EMPTY_PARENT
|
|
338
299
|
}];
|
|
339
300
|
}
|
|
340
|
-
|
|
341
301
|
return [{
|
|
342
302
|
type: 'Property',
|
|
343
303
|
key: param.name,
|
|
@@ -351,14 +311,12 @@ function mapComponentParameter(param) {
|
|
|
351
311
|
parent: EMPTY_PARENT
|
|
352
312
|
}];
|
|
353
313
|
}
|
|
354
|
-
|
|
355
314
|
default:
|
|
356
315
|
{
|
|
357
316
|
throw (0, _createSyntaxError.createSyntaxError)(param, `Unknown Component parameter type of "${param.type}"`);
|
|
358
317
|
}
|
|
359
318
|
}
|
|
360
319
|
}
|
|
361
|
-
|
|
362
320
|
function createForwardRefWrapper(originalComponent) {
|
|
363
321
|
const internalCompId = {
|
|
364
322
|
type: 'Identifier',
|
|
@@ -423,10 +381,8 @@ function createForwardRefWrapper(originalComponent) {
|
|
|
423
381
|
forwardRefCompId: originalComponent.id
|
|
424
382
|
};
|
|
425
383
|
}
|
|
426
|
-
|
|
427
384
|
function mapComponentDeclaration(node, options) {
|
|
428
385
|
var _node$async;
|
|
429
|
-
|
|
430
386
|
const createRendersTypeLoc = () => ({
|
|
431
387
|
loc: {
|
|
432
388
|
start: node.body.loc.end,
|
|
@@ -435,7 +391,6 @@ function mapComponentDeclaration(node, options) {
|
|
|
435
391
|
range: [node.body.range[1], node.body.range[1]],
|
|
436
392
|
parent: EMPTY_PARENT
|
|
437
393
|
});
|
|
438
|
-
|
|
439
394
|
const returnType = {
|
|
440
395
|
type: 'TypeAnnotation',
|
|
441
396
|
typeAnnotation: {
|
|
@@ -468,11 +423,9 @@ function mapComponentDeclaration(node, options) {
|
|
|
468
423
|
ref
|
|
469
424
|
} = mapComponentParameters(node.params, options);
|
|
470
425
|
let forwardRefDetails = null;
|
|
471
|
-
|
|
472
426
|
if (ref != null) {
|
|
473
427
|
forwardRefDetails = createForwardRefWrapper(node);
|
|
474
428
|
}
|
|
475
|
-
|
|
476
429
|
const comp = {
|
|
477
430
|
type: 'FunctionDeclaration',
|
|
478
431
|
id: forwardRefDetails != null ? (0, _astNodeMutationHelpers.shallowCloneNode)(forwardRefDetails.internalCompId) : (0, _astNodeMutationHelpers.shallowCloneNode)(node.id),
|
|
@@ -493,7 +446,6 @@ function mapComponentDeclaration(node, options) {
|
|
|
493
446
|
forwardRefDetails
|
|
494
447
|
};
|
|
495
448
|
}
|
|
496
|
-
|
|
497
449
|
function mapDeclareHook(node) {
|
|
498
450
|
return {
|
|
499
451
|
type: 'DeclareFunction',
|
|
@@ -528,10 +480,8 @@ function mapDeclareHook(node) {
|
|
|
528
480
|
predicate: null
|
|
529
481
|
};
|
|
530
482
|
}
|
|
531
|
-
|
|
532
483
|
function mapHookDeclaration(node) {
|
|
533
484
|
var _node$async2;
|
|
534
|
-
|
|
535
485
|
const comp = {
|
|
536
486
|
type: 'FunctionDeclaration',
|
|
537
487
|
id: node.id && (0, _astNodeMutationHelpers.shallowCloneNode)(node.id),
|
|
@@ -549,12 +499,10 @@ function mapHookDeclaration(node) {
|
|
|
549
499
|
};
|
|
550
500
|
return comp;
|
|
551
501
|
}
|
|
552
|
-
|
|
553
502
|
function scanForFirstComponentReference(compName, bodyList) {
|
|
554
503
|
for (let i = 0; i < bodyList.length; i++) {
|
|
555
504
|
const bodyNode = bodyList[i];
|
|
556
505
|
let referencePos = null;
|
|
557
|
-
|
|
558
506
|
_SimpleTraverser.SimpleTraverser.traverse(bodyNode, {
|
|
559
507
|
enter(node) {
|
|
560
508
|
switch (node.type) {
|
|
@@ -567,49 +515,36 @@ function scanForFirstComponentReference(compName, bodyList) {
|
|
|
567
515
|
}
|
|
568
516
|
}
|
|
569
517
|
},
|
|
570
|
-
|
|
571
518
|
leave(_node) {}
|
|
572
|
-
|
|
573
519
|
});
|
|
574
|
-
|
|
575
520
|
if (referencePos != null) {
|
|
576
521
|
return referencePos;
|
|
577
522
|
}
|
|
578
523
|
}
|
|
579
|
-
|
|
580
524
|
return null;
|
|
581
525
|
}
|
|
582
|
-
|
|
583
526
|
function mapComponentDeclarationIntoList(node, newBody, options, insertExport) {
|
|
584
527
|
const {
|
|
585
528
|
comp,
|
|
586
529
|
forwardRefDetails
|
|
587
530
|
} = mapComponentDeclaration(node, options);
|
|
588
|
-
|
|
589
531
|
if (forwardRefDetails != null) {
|
|
590
532
|
const referencePos = scanForFirstComponentReference(forwardRefDetails.forwardRefCompId.name, newBody);
|
|
591
|
-
|
|
592
533
|
if (referencePos != null) {
|
|
593
534
|
newBody.splice(referencePos, 0, forwardRefDetails.forwardRefStatement);
|
|
594
535
|
} else {
|
|
595
536
|
newBody.push(forwardRefDetails.forwardRefStatement);
|
|
596
537
|
}
|
|
597
|
-
|
|
598
538
|
newBody.push(comp);
|
|
599
|
-
|
|
600
539
|
if (insertExport != null) {
|
|
601
540
|
newBody.push(insertExport(forwardRefDetails.forwardRefCompId));
|
|
602
541
|
}
|
|
603
|
-
|
|
604
542
|
return;
|
|
605
543
|
}
|
|
606
|
-
|
|
607
544
|
newBody.push(insertExport != null ? insertExport(comp) : comp);
|
|
608
545
|
}
|
|
609
|
-
|
|
610
546
|
function mapStatementList(stmts, options) {
|
|
611
547
|
const newBody = [];
|
|
612
|
-
|
|
613
548
|
for (const node of stmts) {
|
|
614
549
|
switch (node.type) {
|
|
615
550
|
case 'ComponentDeclaration':
|
|
@@ -617,18 +552,15 @@ function mapStatementList(stmts, options) {
|
|
|
617
552
|
mapComponentDeclarationIntoList(node, newBody, options);
|
|
618
553
|
break;
|
|
619
554
|
}
|
|
620
|
-
|
|
621
555
|
case 'HookDeclaration':
|
|
622
556
|
{
|
|
623
557
|
const decl = mapHookDeclaration(node);
|
|
624
558
|
newBody.push(decl);
|
|
625
559
|
break;
|
|
626
560
|
}
|
|
627
|
-
|
|
628
561
|
case 'ExportNamedDeclaration':
|
|
629
562
|
{
|
|
630
563
|
var _node$declaration, _node$declaration2;
|
|
631
|
-
|
|
632
564
|
if (((_node$declaration = node.declaration) == null ? void 0 : _node$declaration.type) === 'ComponentDeclaration') {
|
|
633
565
|
mapComponentDeclarationIntoList(node.declaration, newBody, options, componentOrRef => {
|
|
634
566
|
switch (componentOrRef.type) {
|
|
@@ -638,7 +570,6 @@ function mapStatementList(stmts, options) {
|
|
|
638
570
|
declaration: componentOrRef
|
|
639
571
|
});
|
|
640
572
|
}
|
|
641
|
-
|
|
642
573
|
case 'Identifier':
|
|
643
574
|
{
|
|
644
575
|
return {
|
|
@@ -663,7 +594,6 @@ function mapStatementList(stmts, options) {
|
|
|
663
594
|
});
|
|
664
595
|
break;
|
|
665
596
|
}
|
|
666
|
-
|
|
667
597
|
if (((_node$declaration2 = node.declaration) == null ? void 0 : _node$declaration2.type) === 'HookDeclaration') {
|
|
668
598
|
const comp = mapHookDeclaration(node.declaration);
|
|
669
599
|
newBody.push(nodeWith(node, {
|
|
@@ -671,22 +601,18 @@ function mapStatementList(stmts, options) {
|
|
|
671
601
|
}));
|
|
672
602
|
break;
|
|
673
603
|
}
|
|
674
|
-
|
|
675
604
|
newBody.push(node);
|
|
676
605
|
break;
|
|
677
606
|
}
|
|
678
|
-
|
|
679
607
|
case 'ExportDefaultDeclaration':
|
|
680
608
|
{
|
|
681
609
|
var _node$declaration3, _node$declaration4;
|
|
682
|
-
|
|
683
610
|
if (((_node$declaration3 = node.declaration) == null ? void 0 : _node$declaration3.type) === 'ComponentDeclaration') {
|
|
684
611
|
mapComponentDeclarationIntoList(node.declaration, newBody, options, componentOrRef => nodeWith(node, {
|
|
685
612
|
declaration: componentOrRef
|
|
686
613
|
}));
|
|
687
614
|
break;
|
|
688
615
|
}
|
|
689
|
-
|
|
690
616
|
if (((_node$declaration4 = node.declaration) == null ? void 0 : _node$declaration4.type) === 'HookDeclaration') {
|
|
691
617
|
const comp = mapHookDeclaration(node.declaration);
|
|
692
618
|
newBody.push(nodeWith(node, {
|
|
@@ -694,21 +620,17 @@ function mapStatementList(stmts, options) {
|
|
|
694
620
|
}));
|
|
695
621
|
break;
|
|
696
622
|
}
|
|
697
|
-
|
|
698
623
|
newBody.push(node);
|
|
699
624
|
break;
|
|
700
625
|
}
|
|
701
|
-
|
|
702
626
|
default:
|
|
703
627
|
{
|
|
704
628
|
newBody.push(node);
|
|
705
629
|
}
|
|
706
630
|
}
|
|
707
631
|
}
|
|
708
|
-
|
|
709
632
|
return newBody;
|
|
710
633
|
}
|
|
711
|
-
|
|
712
634
|
function transformProgram(program, options) {
|
|
713
635
|
return _SimpleTransform.SimpleTransform.transformProgram(program, {
|
|
714
636
|
transform(node) {
|
|
@@ -717,12 +639,10 @@ function transformProgram(program, options) {
|
|
|
717
639
|
{
|
|
718
640
|
return mapDeclareComponent(node);
|
|
719
641
|
}
|
|
720
|
-
|
|
721
642
|
case 'DeclareHook':
|
|
722
643
|
{
|
|
723
644
|
return mapDeclareHook(node);
|
|
724
645
|
}
|
|
725
|
-
|
|
726
646
|
case 'Program':
|
|
727
647
|
case 'BlockStatement':
|
|
728
648
|
{
|
|
@@ -730,7 +650,6 @@ function transformProgram(program, options) {
|
|
|
730
650
|
body: mapStatementList(node.body, options)
|
|
731
651
|
});
|
|
732
652
|
}
|
|
733
|
-
|
|
734
653
|
case 'SwitchCase':
|
|
735
654
|
{
|
|
736
655
|
const consequent = mapStatementList(node.consequent, options);
|
|
@@ -738,27 +657,21 @@ function transformProgram(program, options) {
|
|
|
738
657
|
consequent
|
|
739
658
|
});
|
|
740
659
|
}
|
|
741
|
-
|
|
742
660
|
case 'ComponentDeclaration':
|
|
743
661
|
{
|
|
744
662
|
var _node$parent;
|
|
745
|
-
|
|
746
663
|
throw (0, _createSyntaxError.createSyntaxError)(node, `Components must be defined at the top level of a module or within a ` + `BlockStatement, instead got parent of "${(_node$parent = node.parent) == null ? void 0 : _node$parent.type}".`);
|
|
747
664
|
}
|
|
748
|
-
|
|
749
665
|
case 'HookDeclaration':
|
|
750
666
|
{
|
|
751
667
|
var _node$parent2;
|
|
752
|
-
|
|
753
668
|
throw (0, _createSyntaxError.createSyntaxError)(node, `Hooks must be defined at the top level of a module or within a ` + `BlockStatement, instead got parent of "${(_node$parent2 = node.parent) == null ? void 0 : _node$parent2.type}".`);
|
|
754
669
|
}
|
|
755
|
-
|
|
756
670
|
default:
|
|
757
671
|
{
|
|
758
672
|
return node;
|
|
759
673
|
}
|
|
760
674
|
}
|
|
761
675
|
}
|
|
762
|
-
|
|
763
676
|
});
|
|
764
677
|
}
|
|
@@ -4,16 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.transformProgram = transformProgram;
|
|
7
|
-
|
|
8
7
|
var _flowEstree = require("flow-estree");
|
|
9
|
-
|
|
10
8
|
var _SimpleTransform = require("../transform/SimpleTransform");
|
|
11
|
-
|
|
12
9
|
var _Builders = require("../utils/Builders");
|
|
13
|
-
|
|
14
10
|
function mapEnumDeclaration(node, options) {
|
|
15
11
|
var _options$transformOpt, _options$transformOpt2;
|
|
16
|
-
|
|
17
12
|
const {
|
|
18
13
|
body
|
|
19
14
|
} = node;
|
|
@@ -52,7 +47,6 @@ function mapEnumDeclaration(node, options) {
|
|
|
52
47
|
}]);
|
|
53
48
|
return (0, _Builders.variableDeclaration)('const', node.id, enumExpression);
|
|
54
49
|
}
|
|
55
|
-
|
|
56
50
|
function transformProgram(program, options) {
|
|
57
51
|
return _SimpleTransform.SimpleTransform.transformProgram(program, {
|
|
58
52
|
transform(node) {
|
|
@@ -61,32 +55,26 @@ function transformProgram(program, options) {
|
|
|
61
55
|
{
|
|
62
56
|
return mapEnumDeclaration(node, options);
|
|
63
57
|
}
|
|
64
|
-
|
|
65
58
|
case 'ExportDefaultDeclaration':
|
|
66
59
|
{
|
|
67
60
|
const {
|
|
68
61
|
declaration
|
|
69
62
|
} = node;
|
|
70
|
-
|
|
71
63
|
if ((0, _flowEstree.isEnumDeclaration)(declaration)) {
|
|
72
64
|
const enumDeclaration = mapEnumDeclaration(declaration, options);
|
|
73
|
-
|
|
74
65
|
const exportDefault = _SimpleTransform.SimpleTransform.nodeWith(node, {
|
|
75
66
|
declaration: (0, _Builders.ident)(declaration.id.name)
|
|
76
67
|
});
|
|
77
|
-
|
|
78
68
|
return [enumDeclaration, exportDefault];
|
|
79
69
|
} else {
|
|
80
70
|
return node;
|
|
81
71
|
}
|
|
82
72
|
}
|
|
83
|
-
|
|
84
73
|
default:
|
|
85
74
|
{
|
|
86
75
|
return node;
|
|
87
76
|
}
|
|
88
77
|
}
|
|
89
78
|
}
|
|
90
|
-
|
|
91
79
|
});
|
|
92
80
|
}
|