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,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,10 +446,10 @@ function mapComponentDeclaration(node, options) {
|
|
|
493
446
|
forwardRefDetails
|
|
494
447
|
};
|
|
495
448
|
}
|
|
496
|
-
|
|
497
449
|
function mapDeclareHook(node) {
|
|
498
450
|
return {
|
|
499
451
|
type: 'DeclareFunction',
|
|
452
|
+
implicitDeclare: false,
|
|
500
453
|
id: {
|
|
501
454
|
type: 'Identifier',
|
|
502
455
|
name: node.id.name,
|
|
@@ -528,10 +481,8 @@ function mapDeclareHook(node) {
|
|
|
528
481
|
predicate: null
|
|
529
482
|
};
|
|
530
483
|
}
|
|
531
|
-
|
|
532
484
|
function mapHookDeclaration(node) {
|
|
533
485
|
var _node$async2;
|
|
534
|
-
|
|
535
486
|
const comp = {
|
|
536
487
|
type: 'FunctionDeclaration',
|
|
537
488
|
id: node.id && (0, _astNodeMutationHelpers.shallowCloneNode)(node.id),
|
|
@@ -549,12 +500,10 @@ function mapHookDeclaration(node) {
|
|
|
549
500
|
};
|
|
550
501
|
return comp;
|
|
551
502
|
}
|
|
552
|
-
|
|
553
503
|
function scanForFirstComponentReference(compName, bodyList) {
|
|
554
504
|
for (let i = 0; i < bodyList.length; i++) {
|
|
555
505
|
const bodyNode = bodyList[i];
|
|
556
506
|
let referencePos = null;
|
|
557
|
-
|
|
558
507
|
_SimpleTraverser.SimpleTraverser.traverse(bodyNode, {
|
|
559
508
|
enter(node) {
|
|
560
509
|
switch (node.type) {
|
|
@@ -567,49 +516,36 @@ function scanForFirstComponentReference(compName, bodyList) {
|
|
|
567
516
|
}
|
|
568
517
|
}
|
|
569
518
|
},
|
|
570
|
-
|
|
571
519
|
leave(_node) {}
|
|
572
|
-
|
|
573
520
|
});
|
|
574
|
-
|
|
575
521
|
if (referencePos != null) {
|
|
576
522
|
return referencePos;
|
|
577
523
|
}
|
|
578
524
|
}
|
|
579
|
-
|
|
580
525
|
return null;
|
|
581
526
|
}
|
|
582
|
-
|
|
583
527
|
function mapComponentDeclarationIntoList(node, newBody, options, insertExport) {
|
|
584
528
|
const {
|
|
585
529
|
comp,
|
|
586
530
|
forwardRefDetails
|
|
587
531
|
} = mapComponentDeclaration(node, options);
|
|
588
|
-
|
|
589
532
|
if (forwardRefDetails != null) {
|
|
590
533
|
const referencePos = scanForFirstComponentReference(forwardRefDetails.forwardRefCompId.name, newBody);
|
|
591
|
-
|
|
592
534
|
if (referencePos != null) {
|
|
593
535
|
newBody.splice(referencePos, 0, forwardRefDetails.forwardRefStatement);
|
|
594
536
|
} else {
|
|
595
537
|
newBody.push(forwardRefDetails.forwardRefStatement);
|
|
596
538
|
}
|
|
597
|
-
|
|
598
539
|
newBody.push(comp);
|
|
599
|
-
|
|
600
540
|
if (insertExport != null) {
|
|
601
541
|
newBody.push(insertExport(forwardRefDetails.forwardRefCompId));
|
|
602
542
|
}
|
|
603
|
-
|
|
604
543
|
return;
|
|
605
544
|
}
|
|
606
|
-
|
|
607
545
|
newBody.push(insertExport != null ? insertExport(comp) : comp);
|
|
608
546
|
}
|
|
609
|
-
|
|
610
547
|
function mapStatementList(stmts, options) {
|
|
611
548
|
const newBody = [];
|
|
612
|
-
|
|
613
549
|
for (const node of stmts) {
|
|
614
550
|
switch (node.type) {
|
|
615
551
|
case 'ComponentDeclaration':
|
|
@@ -617,18 +553,15 @@ function mapStatementList(stmts, options) {
|
|
|
617
553
|
mapComponentDeclarationIntoList(node, newBody, options);
|
|
618
554
|
break;
|
|
619
555
|
}
|
|
620
|
-
|
|
621
556
|
case 'HookDeclaration':
|
|
622
557
|
{
|
|
623
558
|
const decl = mapHookDeclaration(node);
|
|
624
559
|
newBody.push(decl);
|
|
625
560
|
break;
|
|
626
561
|
}
|
|
627
|
-
|
|
628
562
|
case 'ExportNamedDeclaration':
|
|
629
563
|
{
|
|
630
564
|
var _node$declaration, _node$declaration2;
|
|
631
|
-
|
|
632
565
|
if (((_node$declaration = node.declaration) == null ? void 0 : _node$declaration.type) === 'ComponentDeclaration') {
|
|
633
566
|
mapComponentDeclarationIntoList(node.declaration, newBody, options, componentOrRef => {
|
|
634
567
|
switch (componentOrRef.type) {
|
|
@@ -638,7 +571,6 @@ function mapStatementList(stmts, options) {
|
|
|
638
571
|
declaration: componentOrRef
|
|
639
572
|
});
|
|
640
573
|
}
|
|
641
|
-
|
|
642
574
|
case 'Identifier':
|
|
643
575
|
{
|
|
644
576
|
return {
|
|
@@ -663,7 +595,6 @@ function mapStatementList(stmts, options) {
|
|
|
663
595
|
});
|
|
664
596
|
break;
|
|
665
597
|
}
|
|
666
|
-
|
|
667
598
|
if (((_node$declaration2 = node.declaration) == null ? void 0 : _node$declaration2.type) === 'HookDeclaration') {
|
|
668
599
|
const comp = mapHookDeclaration(node.declaration);
|
|
669
600
|
newBody.push(nodeWith(node, {
|
|
@@ -671,22 +602,18 @@ function mapStatementList(stmts, options) {
|
|
|
671
602
|
}));
|
|
672
603
|
break;
|
|
673
604
|
}
|
|
674
|
-
|
|
675
605
|
newBody.push(node);
|
|
676
606
|
break;
|
|
677
607
|
}
|
|
678
|
-
|
|
679
608
|
case 'ExportDefaultDeclaration':
|
|
680
609
|
{
|
|
681
610
|
var _node$declaration3, _node$declaration4;
|
|
682
|
-
|
|
683
611
|
if (((_node$declaration3 = node.declaration) == null ? void 0 : _node$declaration3.type) === 'ComponentDeclaration') {
|
|
684
612
|
mapComponentDeclarationIntoList(node.declaration, newBody, options, componentOrRef => nodeWith(node, {
|
|
685
613
|
declaration: componentOrRef
|
|
686
614
|
}));
|
|
687
615
|
break;
|
|
688
616
|
}
|
|
689
|
-
|
|
690
617
|
if (((_node$declaration4 = node.declaration) == null ? void 0 : _node$declaration4.type) === 'HookDeclaration') {
|
|
691
618
|
const comp = mapHookDeclaration(node.declaration);
|
|
692
619
|
newBody.push(nodeWith(node, {
|
|
@@ -694,21 +621,17 @@ function mapStatementList(stmts, options) {
|
|
|
694
621
|
}));
|
|
695
622
|
break;
|
|
696
623
|
}
|
|
697
|
-
|
|
698
624
|
newBody.push(node);
|
|
699
625
|
break;
|
|
700
626
|
}
|
|
701
|
-
|
|
702
627
|
default:
|
|
703
628
|
{
|
|
704
629
|
newBody.push(node);
|
|
705
630
|
}
|
|
706
631
|
}
|
|
707
632
|
}
|
|
708
|
-
|
|
709
633
|
return newBody;
|
|
710
634
|
}
|
|
711
|
-
|
|
712
635
|
function transformProgram(program, options) {
|
|
713
636
|
return _SimpleTransform.SimpleTransform.transformProgram(program, {
|
|
714
637
|
transform(node) {
|
|
@@ -717,12 +640,10 @@ function transformProgram(program, options) {
|
|
|
717
640
|
{
|
|
718
641
|
return mapDeclareComponent(node);
|
|
719
642
|
}
|
|
720
|
-
|
|
721
643
|
case 'DeclareHook':
|
|
722
644
|
{
|
|
723
645
|
return mapDeclareHook(node);
|
|
724
646
|
}
|
|
725
|
-
|
|
726
647
|
case 'Program':
|
|
727
648
|
case 'BlockStatement':
|
|
728
649
|
{
|
|
@@ -730,7 +651,6 @@ function transformProgram(program, options) {
|
|
|
730
651
|
body: mapStatementList(node.body, options)
|
|
731
652
|
});
|
|
732
653
|
}
|
|
733
|
-
|
|
734
654
|
case 'SwitchCase':
|
|
735
655
|
{
|
|
736
656
|
const consequent = mapStatementList(node.consequent, options);
|
|
@@ -738,27 +658,21 @@ function transformProgram(program, options) {
|
|
|
738
658
|
consequent
|
|
739
659
|
});
|
|
740
660
|
}
|
|
741
|
-
|
|
742
661
|
case 'ComponentDeclaration':
|
|
743
662
|
{
|
|
744
663
|
var _node$parent;
|
|
745
|
-
|
|
746
664
|
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
665
|
}
|
|
748
|
-
|
|
749
666
|
case 'HookDeclaration':
|
|
750
667
|
{
|
|
751
668
|
var _node$parent2;
|
|
752
|
-
|
|
753
669
|
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
670
|
}
|
|
755
|
-
|
|
756
671
|
default:
|
|
757
672
|
{
|
|
758
673
|
return node;
|
|
759
674
|
}
|
|
760
675
|
}
|
|
761
676
|
}
|
|
762
|
-
|
|
763
677
|
});
|
|
764
678
|
}
|
|
@@ -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
|
}
|