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,44 +4,32 @@ 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 _createSyntaxError = require("../utils/createSyntaxError");
|
|
13
|
-
|
|
14
10
|
var _Builders = require("../utils/Builders");
|
|
15
|
-
|
|
16
11
|
var _GenID = _interopRequireDefault(require("../utils/GenID"));
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
default: obj
|
|
12
|
+
function _interopRequireDefault(e) {
|
|
13
|
+
return e && e.__esModule ? e : {
|
|
14
|
+
default: e
|
|
21
15
|
};
|
|
22
16
|
}
|
|
23
|
-
|
|
24
17
|
let genID = null;
|
|
25
|
-
|
|
26
18
|
function genIdent() {
|
|
27
19
|
if (genID == null) {
|
|
28
20
|
throw Error('GenID must be initialized at the start of the transform.');
|
|
29
21
|
}
|
|
30
|
-
|
|
31
22
|
return (0, _Builders.ident)(genID.id());
|
|
32
23
|
}
|
|
33
|
-
|
|
34
24
|
function objKeyToString(node) {
|
|
35
25
|
switch (node.type) {
|
|
36
26
|
case 'Identifier':
|
|
37
27
|
return node.name;
|
|
38
|
-
|
|
39
28
|
case 'Literal':
|
|
40
29
|
{
|
|
41
30
|
const {
|
|
42
31
|
value
|
|
43
32
|
} = node;
|
|
44
|
-
|
|
45
33
|
if (typeof value === 'number') {
|
|
46
34
|
return String(value);
|
|
47
35
|
} else if (typeof value === 'string') {
|
|
@@ -52,7 +40,6 @@ function objKeyToString(node) {
|
|
|
52
40
|
}
|
|
53
41
|
}
|
|
54
42
|
}
|
|
55
|
-
|
|
56
43
|
function convertMemberPattern(pattern) {
|
|
57
44
|
const {
|
|
58
45
|
base,
|
|
@@ -61,7 +48,6 @@ function convertMemberPattern(pattern) {
|
|
|
61
48
|
range
|
|
62
49
|
} = pattern;
|
|
63
50
|
const object = base.type === 'MatchIdentifierPattern' ? base.id : convertMemberPattern(base);
|
|
64
|
-
|
|
65
51
|
if (property.type === 'Identifier') {
|
|
66
52
|
return {
|
|
67
53
|
type: 'MemberExpression',
|
|
@@ -88,21 +74,17 @@ function convertMemberPattern(pattern) {
|
|
|
88
74
|
};
|
|
89
75
|
}
|
|
90
76
|
}
|
|
91
|
-
|
|
92
77
|
function checkDuplicateBindingName(seenBindingNames, node, name) {
|
|
93
78
|
if (seenBindingNames.has(name)) {
|
|
94
79
|
throw (0, _createSyntaxError.createSyntaxError)(node, `Duplicate variable name '${name}' in match case pattern.`);
|
|
95
80
|
}
|
|
96
|
-
|
|
97
81
|
seenBindingNames.add(name);
|
|
98
82
|
}
|
|
99
|
-
|
|
100
83
|
function checkBindingKind(node, kind) {
|
|
101
84
|
if (kind === 'var') {
|
|
102
85
|
throw (0, _createSyntaxError.createSyntaxError)(node, `'var' bindings are not allowed. Use 'const' or 'let'.`);
|
|
103
86
|
}
|
|
104
87
|
}
|
|
105
|
-
|
|
106
88
|
function needsPropExistsCond(pattern) {
|
|
107
89
|
switch (pattern.type) {
|
|
108
90
|
case 'MatchWildcardPattern':
|
|
@@ -110,14 +92,12 @@ function needsPropExistsCond(pattern) {
|
|
|
110
92
|
case 'MatchIdentifierPattern':
|
|
111
93
|
case 'MatchMemberPattern':
|
|
112
94
|
return true;
|
|
113
|
-
|
|
114
95
|
case 'MatchLiteralPattern':
|
|
115
96
|
case 'MatchUnaryPattern':
|
|
116
97
|
case 'MatchObjectPattern':
|
|
117
98
|
case 'MatchInstancePattern':
|
|
118
99
|
case 'MatchArrayPattern':
|
|
119
100
|
return false;
|
|
120
|
-
|
|
121
101
|
case 'MatchAsPattern':
|
|
122
102
|
{
|
|
123
103
|
const {
|
|
@@ -125,7 +105,6 @@ function needsPropExistsCond(pattern) {
|
|
|
125
105
|
} = pattern;
|
|
126
106
|
return needsPropExistsCond(asPattern);
|
|
127
107
|
}
|
|
128
|
-
|
|
129
108
|
case 'MatchOrPattern':
|
|
130
109
|
{
|
|
131
110
|
const {
|
|
@@ -135,7 +114,6 @@ function needsPropExistsCond(pattern) {
|
|
|
135
114
|
}
|
|
136
115
|
}
|
|
137
116
|
}
|
|
138
|
-
|
|
139
117
|
function analyzeProperties(key, pattern, seenBindingNames, properties, rest) {
|
|
140
118
|
const conditions = [];
|
|
141
119
|
const bindings = [];
|
|
@@ -148,14 +126,11 @@ function analyzeProperties(key, pattern, seenBindingNames, properties, rest) {
|
|
|
148
126
|
} = prop;
|
|
149
127
|
objKeys.push(objKey);
|
|
150
128
|
const name = objKeyToString(objKey);
|
|
151
|
-
|
|
152
129
|
if (seenNames.has(name)) {
|
|
153
130
|
throw (0, _createSyntaxError.createSyntaxError)(propPattern, `Duplicate property name '${name}' in match object pattern.`);
|
|
154
131
|
}
|
|
155
|
-
|
|
156
132
|
seenNames.add(name);
|
|
157
133
|
const propKey = key.concat(objKey);
|
|
158
|
-
|
|
159
134
|
if (needsPropExistsCond(propPattern)) {
|
|
160
135
|
conditions.push({
|
|
161
136
|
type: 'prop-exists',
|
|
@@ -163,7 +138,6 @@ function analyzeProperties(key, pattern, seenBindingNames, properties, rest) {
|
|
|
163
138
|
propName: name
|
|
164
139
|
});
|
|
165
140
|
}
|
|
166
|
-
|
|
167
141
|
const {
|
|
168
142
|
conditions: childConditions,
|
|
169
143
|
bindings: childBindings
|
|
@@ -171,7 +145,6 @@ function analyzeProperties(key, pattern, seenBindingNames, properties, rest) {
|
|
|
171
145
|
conditions.push(...childConditions);
|
|
172
146
|
bindings.push(...childBindings);
|
|
173
147
|
});
|
|
174
|
-
|
|
175
148
|
if (rest != null && rest.argument != null) {
|
|
176
149
|
const {
|
|
177
150
|
id,
|
|
@@ -187,23 +160,19 @@ function analyzeProperties(key, pattern, seenBindingNames, properties, rest) {
|
|
|
187
160
|
id
|
|
188
161
|
});
|
|
189
162
|
}
|
|
190
|
-
|
|
191
163
|
return {
|
|
192
164
|
conditions,
|
|
193
165
|
bindings
|
|
194
166
|
};
|
|
195
167
|
}
|
|
196
|
-
|
|
197
168
|
function constructorExpression(constructor) {
|
|
198
169
|
switch (constructor.type) {
|
|
199
170
|
case 'MatchIdentifierPattern':
|
|
200
171
|
return constructor.id;
|
|
201
|
-
|
|
202
172
|
case 'MatchMemberPattern':
|
|
203
173
|
return convertMemberPattern(constructor);
|
|
204
174
|
}
|
|
205
175
|
}
|
|
206
|
-
|
|
207
176
|
function analyzePattern(pattern, key, seenBindingNames) {
|
|
208
177
|
switch (pattern.type) {
|
|
209
178
|
case 'MatchWildcardPattern':
|
|
@@ -213,7 +182,6 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
213
182
|
bindings: []
|
|
214
183
|
};
|
|
215
184
|
}
|
|
216
|
-
|
|
217
185
|
case 'MatchLiteralPattern':
|
|
218
186
|
{
|
|
219
187
|
const {
|
|
@@ -229,7 +197,6 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
229
197
|
bindings: []
|
|
230
198
|
};
|
|
231
199
|
}
|
|
232
|
-
|
|
233
200
|
case 'MatchUnaryPattern':
|
|
234
201
|
{
|
|
235
202
|
const {
|
|
@@ -238,11 +205,9 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
238
205
|
loc,
|
|
239
206
|
range
|
|
240
207
|
} = pattern;
|
|
241
|
-
|
|
242
208
|
if (argument.value === 0) {
|
|
243
209
|
throw (0, _createSyntaxError.createSyntaxError)(pattern, `'+0' and '-0' are not yet supported in match unary patterns.`);
|
|
244
210
|
}
|
|
245
|
-
|
|
246
211
|
const arg = {
|
|
247
212
|
type: 'UnaryExpression',
|
|
248
213
|
operator,
|
|
@@ -263,7 +228,6 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
263
228
|
bindings: []
|
|
264
229
|
};
|
|
265
230
|
}
|
|
266
|
-
|
|
267
231
|
case 'MatchIdentifierPattern':
|
|
268
232
|
{
|
|
269
233
|
const {
|
|
@@ -282,7 +246,6 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
282
246
|
bindings: []
|
|
283
247
|
};
|
|
284
248
|
}
|
|
285
|
-
|
|
286
249
|
case 'MatchMemberPattern':
|
|
287
250
|
{
|
|
288
251
|
const arg = convertMemberPattern(pattern);
|
|
@@ -296,7 +259,6 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
296
259
|
bindings: []
|
|
297
260
|
};
|
|
298
261
|
}
|
|
299
|
-
|
|
300
262
|
case 'MatchBindingPattern':
|
|
301
263
|
{
|
|
302
264
|
const {
|
|
@@ -316,18 +278,15 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
316
278
|
bindings: [binding]
|
|
317
279
|
};
|
|
318
280
|
}
|
|
319
|
-
|
|
320
281
|
case 'MatchAsPattern':
|
|
321
282
|
{
|
|
322
283
|
const {
|
|
323
284
|
pattern: asPattern,
|
|
324
285
|
target
|
|
325
286
|
} = pattern;
|
|
326
|
-
|
|
327
287
|
if (asPattern.type === 'MatchBindingPattern') {
|
|
328
288
|
throw (0, _createSyntaxError.createSyntaxError)(pattern, `Match 'as' patterns are not allowed directly on binding patterns.`);
|
|
329
289
|
}
|
|
330
|
-
|
|
331
290
|
const {
|
|
332
291
|
conditions,
|
|
333
292
|
bindings
|
|
@@ -347,7 +306,6 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
347
306
|
bindings: bindings.concat(binding)
|
|
348
307
|
};
|
|
349
308
|
}
|
|
350
|
-
|
|
351
309
|
case 'MatchArrayPattern':
|
|
352
310
|
{
|
|
353
311
|
const {
|
|
@@ -371,7 +329,6 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
371
329
|
conditions.push(...childConditions);
|
|
372
330
|
bindings.push(...childBindings);
|
|
373
331
|
});
|
|
374
|
-
|
|
375
332
|
if (rest != null && rest.argument != null) {
|
|
376
333
|
const {
|
|
377
334
|
id,
|
|
@@ -387,13 +344,11 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
387
344
|
id
|
|
388
345
|
});
|
|
389
346
|
}
|
|
390
|
-
|
|
391
347
|
return {
|
|
392
348
|
conditions,
|
|
393
349
|
bindings
|
|
394
350
|
};
|
|
395
351
|
}
|
|
396
|
-
|
|
397
352
|
case 'MatchObjectPattern':
|
|
398
353
|
{
|
|
399
354
|
const {
|
|
@@ -413,7 +368,6 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
413
368
|
bindings
|
|
414
369
|
};
|
|
415
370
|
}
|
|
416
|
-
|
|
417
371
|
case 'MatchInstancePattern':
|
|
418
372
|
{
|
|
419
373
|
const {
|
|
@@ -437,7 +391,6 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
437
391
|
bindings
|
|
438
392
|
};
|
|
439
393
|
}
|
|
440
|
-
|
|
441
394
|
case 'MatchOrPattern':
|
|
442
395
|
{
|
|
443
396
|
const {
|
|
@@ -449,25 +402,20 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
449
402
|
conditions,
|
|
450
403
|
bindings
|
|
451
404
|
} = analyzePattern(subpattern, key, seenBindingNames);
|
|
452
|
-
|
|
453
405
|
if (bindings.length > 0) {
|
|
454
406
|
throw (0, _createSyntaxError.createSyntaxError)(pattern, `Bindings in match 'or' patterns are not yet supported.`);
|
|
455
407
|
}
|
|
456
|
-
|
|
457
408
|
if (conditions.length === 0) {
|
|
458
409
|
hasWildcard = true;
|
|
459
410
|
}
|
|
460
|
-
|
|
461
411
|
return conditions;
|
|
462
412
|
});
|
|
463
|
-
|
|
464
413
|
if (hasWildcard) {
|
|
465
414
|
return {
|
|
466
415
|
conditions: [],
|
|
467
416
|
bindings: []
|
|
468
417
|
};
|
|
469
418
|
}
|
|
470
|
-
|
|
471
419
|
return {
|
|
472
420
|
conditions: [{
|
|
473
421
|
type: 'or',
|
|
@@ -478,7 +426,6 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
478
426
|
}
|
|
479
427
|
}
|
|
480
428
|
}
|
|
481
|
-
|
|
482
429
|
function expressionOfKey(root, key) {
|
|
483
430
|
return key.reduce((acc, prop) => prop.type === 'Identifier' ? {
|
|
484
431
|
type: 'MemberExpression',
|
|
@@ -496,7 +443,6 @@ function expressionOfKey(root, key) {
|
|
|
496
443
|
...(0, _Builders.etc)()
|
|
497
444
|
}, (0, _astNodeMutationHelpers.deepCloneNode)(root));
|
|
498
445
|
}
|
|
499
|
-
|
|
500
446
|
function testsOfCondition(root, condition) {
|
|
501
447
|
switch (condition.type) {
|
|
502
448
|
case 'eq':
|
|
@@ -513,7 +459,6 @@ function testsOfCondition(root, condition) {
|
|
|
513
459
|
...(0, _Builders.etc)()
|
|
514
460
|
}];
|
|
515
461
|
}
|
|
516
|
-
|
|
517
462
|
case 'is-nan':
|
|
518
463
|
{
|
|
519
464
|
const {
|
|
@@ -529,7 +474,6 @@ function testsOfCondition(root, condition) {
|
|
|
529
474
|
};
|
|
530
475
|
return [(0, _Builders.callExpression)(callee, [expressionOfKey(root, key)])];
|
|
531
476
|
}
|
|
532
|
-
|
|
533
477
|
case 'array':
|
|
534
478
|
{
|
|
535
479
|
const {
|
|
@@ -562,7 +506,6 @@ function testsOfCondition(root, condition) {
|
|
|
562
506
|
};
|
|
563
507
|
return [isArray, lengthCheck];
|
|
564
508
|
}
|
|
565
|
-
|
|
566
509
|
case 'object':
|
|
567
510
|
{
|
|
568
511
|
const {
|
|
@@ -579,7 +522,6 @@ function testsOfCondition(root, condition) {
|
|
|
579
522
|
};
|
|
580
523
|
return [(0, _Builders.disjunction)([(0, _Builders.conjunction)([typeofObject, notNull]), typeofFunction])];
|
|
581
524
|
}
|
|
582
|
-
|
|
583
525
|
case 'instanceof':
|
|
584
526
|
{
|
|
585
527
|
const {
|
|
@@ -594,7 +536,6 @@ function testsOfCondition(root, condition) {
|
|
|
594
536
|
...(0, _Builders.etc)()
|
|
595
537
|
}];
|
|
596
538
|
}
|
|
597
|
-
|
|
598
539
|
case 'prop-exists':
|
|
599
540
|
{
|
|
600
541
|
const {
|
|
@@ -610,7 +551,6 @@ function testsOfCondition(root, condition) {
|
|
|
610
551
|
};
|
|
611
552
|
return [inObject];
|
|
612
553
|
}
|
|
613
|
-
|
|
614
554
|
case 'or':
|
|
615
555
|
{
|
|
616
556
|
const {
|
|
@@ -621,11 +561,9 @@ function testsOfCondition(root, condition) {
|
|
|
621
561
|
}
|
|
622
562
|
}
|
|
623
563
|
}
|
|
624
|
-
|
|
625
564
|
function testsOfConditions(root, conditions) {
|
|
626
565
|
return conditions.flatMap(condition => testsOfCondition(root, condition));
|
|
627
566
|
}
|
|
628
|
-
|
|
629
567
|
function statementsOfBindings(root, bindings) {
|
|
630
568
|
return bindings.map(binding => {
|
|
631
569
|
switch (binding.type) {
|
|
@@ -638,7 +576,6 @@ function statementsOfBindings(root, bindings) {
|
|
|
638
576
|
} = binding;
|
|
639
577
|
return (0, _Builders.variableDeclaration)(kind, id, expressionOfKey(root, key));
|
|
640
578
|
}
|
|
641
|
-
|
|
642
579
|
case 'array-rest':
|
|
643
580
|
{
|
|
644
581
|
const {
|
|
@@ -657,7 +594,6 @@ function statementsOfBindings(root, bindings) {
|
|
|
657
594
|
}, [(0, _Builders.numberLiteral)(exclude)]);
|
|
658
595
|
return (0, _Builders.variableDeclaration)(kind, id, init);
|
|
659
596
|
}
|
|
660
|
-
|
|
661
597
|
case 'object-rest':
|
|
662
598
|
{
|
|
663
599
|
const {
|
|
@@ -701,9 +637,7 @@ function statementsOfBindings(root, bindings) {
|
|
|
701
637
|
}
|
|
702
638
|
});
|
|
703
639
|
}
|
|
704
|
-
|
|
705
640
|
const fallthroughErrorMsgText = `Match: No case succesfully matched. Make exhaustive or add a wildcard case using '_'.`;
|
|
706
|
-
|
|
707
641
|
function fallthroughErrorMsg(value) {
|
|
708
642
|
return {
|
|
709
643
|
type: 'BinaryExpression',
|
|
@@ -713,17 +647,14 @@ function fallthroughErrorMsg(value) {
|
|
|
713
647
|
...(0, _Builders.etc)()
|
|
714
648
|
};
|
|
715
649
|
}
|
|
716
|
-
|
|
717
650
|
function fallthroughError(value) {
|
|
718
651
|
return (0, _Builders.throwStatement)(fallthroughErrorMsg(value));
|
|
719
652
|
}
|
|
720
|
-
|
|
721
653
|
function calculateSimpleArgument(node) {
|
|
722
654
|
switch (node.type) {
|
|
723
655
|
case 'Identifier':
|
|
724
656
|
case 'Super':
|
|
725
657
|
return true;
|
|
726
|
-
|
|
727
658
|
case 'MemberExpression':
|
|
728
659
|
{
|
|
729
660
|
const {
|
|
@@ -731,24 +662,19 @@ function calculateSimpleArgument(node) {
|
|
|
731
662
|
property,
|
|
732
663
|
computed
|
|
733
664
|
} = node;
|
|
734
|
-
|
|
735
665
|
if (computed && property.type !== 'Literal') {
|
|
736
666
|
return false;
|
|
737
667
|
}
|
|
738
|
-
|
|
739
668
|
return calculateSimpleArgument(object);
|
|
740
669
|
}
|
|
741
|
-
|
|
742
670
|
default:
|
|
743
671
|
return false;
|
|
744
672
|
}
|
|
745
673
|
}
|
|
746
|
-
|
|
747
674
|
function analyzeCases(cases) {
|
|
748
675
|
let hasBindings = false;
|
|
749
676
|
let hasWildcard = false;
|
|
750
677
|
const analyses = [];
|
|
751
|
-
|
|
752
678
|
for (let i = 0; i < cases.length; i++) {
|
|
753
679
|
const {
|
|
754
680
|
pattern,
|
|
@@ -766,20 +692,17 @@ function analyzeCases(cases) {
|
|
|
766
692
|
guard,
|
|
767
693
|
body
|
|
768
694
|
});
|
|
769
|
-
|
|
770
695
|
if (conditions.length === 0 && guard == null) {
|
|
771
696
|
hasWildcard = true;
|
|
772
697
|
break;
|
|
773
698
|
}
|
|
774
699
|
}
|
|
775
|
-
|
|
776
700
|
return {
|
|
777
701
|
hasBindings,
|
|
778
702
|
hasWildcard,
|
|
779
703
|
analyses
|
|
780
704
|
};
|
|
781
705
|
}
|
|
782
|
-
|
|
783
706
|
function mapMatchExpression(node) {
|
|
784
707
|
const {
|
|
785
708
|
argument,
|
|
@@ -793,7 +716,6 @@ function mapMatchExpression(node) {
|
|
|
793
716
|
const isSimpleArgument = !hasBindings && calculateSimpleArgument(argument);
|
|
794
717
|
const genRoot = !isSimpleArgument ? genIdent() : null;
|
|
795
718
|
const root = genRoot == null ? argument : genRoot;
|
|
796
|
-
|
|
797
719
|
if (isSimpleArgument) {
|
|
798
720
|
const wildcardAnalaysis = hasWildcard ? analyses.pop() : null;
|
|
799
721
|
const lastBody = wildcardAnalaysis != null ? wildcardAnalaysis.body : (0, _Builders.iife)([fallthroughError((0, _astNodeMutationHelpers.shallowCloneNode)(root))]);
|
|
@@ -804,11 +726,9 @@ function mapMatchExpression(node) {
|
|
|
804
726
|
body
|
|
805
727
|
} = analysis;
|
|
806
728
|
const tests = testsOfConditions(root, conditions);
|
|
807
|
-
|
|
808
729
|
if (guard != null) {
|
|
809
730
|
tests.push(guard);
|
|
810
731
|
}
|
|
811
|
-
|
|
812
732
|
return {
|
|
813
733
|
type: 'ConditionalExpression',
|
|
814
734
|
test: (0, _Builders.conjunction)(tests),
|
|
@@ -818,7 +738,6 @@ function mapMatchExpression(node) {
|
|
|
818
738
|
};
|
|
819
739
|
}, lastBody);
|
|
820
740
|
}
|
|
821
|
-
|
|
822
741
|
const statements = analyses.map(({
|
|
823
742
|
conditions,
|
|
824
743
|
bindings,
|
|
@@ -838,7 +757,6 @@ function mapMatchExpression(node) {
|
|
|
838
757
|
};
|
|
839
758
|
const bindingNodes = statementsOfBindings(root, bindings);
|
|
840
759
|
const caseBody = bindingNodes.concat(bodyNode);
|
|
841
|
-
|
|
842
760
|
if (conditions.length > 0) {
|
|
843
761
|
const tests = testsOfConditions(root, conditions);
|
|
844
762
|
return {
|
|
@@ -863,15 +781,12 @@ function mapMatchExpression(node) {
|
|
|
863
781
|
}
|
|
864
782
|
}
|
|
865
783
|
});
|
|
866
|
-
|
|
867
784
|
if (!hasWildcard) {
|
|
868
785
|
statements.push(fallthroughError((0, _astNodeMutationHelpers.shallowCloneNode)(root)));
|
|
869
786
|
}
|
|
870
|
-
|
|
871
787
|
const [params, args] = genRoot == null ? [[], []] : [[genRoot], [argument]];
|
|
872
788
|
return (0, _Builders.iife)(statements, params, args);
|
|
873
789
|
}
|
|
874
|
-
|
|
875
790
|
function mapMatchStatement(node) {
|
|
876
791
|
const {
|
|
877
792
|
argument,
|
|
@@ -887,11 +802,9 @@ function mapMatchStatement(node) {
|
|
|
887
802
|
const genRoot = !isSimpleArgument ? genIdent() : null;
|
|
888
803
|
const root = genRoot == null ? argument : genRoot;
|
|
889
804
|
const statements = [];
|
|
890
|
-
|
|
891
805
|
if (genRoot != null) {
|
|
892
806
|
statements.push((0, _Builders.variableDeclaration)('const', genRoot, argument));
|
|
893
807
|
}
|
|
894
|
-
|
|
895
808
|
analyses.forEach(({
|
|
896
809
|
conditions,
|
|
897
810
|
bindings,
|
|
@@ -916,7 +829,6 @@ function mapMatchStatement(node) {
|
|
|
916
829
|
}];
|
|
917
830
|
const bindingNodes = statementsOfBindings(root, bindings);
|
|
918
831
|
const caseBody = bindingNodes.concat(guardedBodyStatements);
|
|
919
|
-
|
|
920
832
|
if (conditions.length > 0) {
|
|
921
833
|
const tests = testsOfConditions(root, conditions);
|
|
922
834
|
statements.push({
|
|
@@ -937,11 +849,9 @@ function mapMatchStatement(node) {
|
|
|
937
849
|
});
|
|
938
850
|
}
|
|
939
851
|
});
|
|
940
|
-
|
|
941
852
|
if (!hasWildcard) {
|
|
942
853
|
statements.push(fallthroughError((0, _astNodeMutationHelpers.shallowCloneNode)(root)));
|
|
943
854
|
}
|
|
944
|
-
|
|
945
855
|
return {
|
|
946
856
|
type: 'LabeledStatement',
|
|
947
857
|
label: topLabel,
|
|
@@ -953,7 +863,6 @@ function mapMatchStatement(node) {
|
|
|
953
863
|
...(0, _Builders.etc)()
|
|
954
864
|
};
|
|
955
865
|
}
|
|
956
|
-
|
|
957
866
|
function transformProgram(program, _options) {
|
|
958
867
|
genID = new _GenID.default('m');
|
|
959
868
|
return _SimpleTransform.SimpleTransform.transformProgram(program, {
|
|
@@ -963,28 +872,23 @@ function transformProgram(program, _options) {
|
|
|
963
872
|
{
|
|
964
873
|
return mapMatchExpression(node);
|
|
965
874
|
}
|
|
966
|
-
|
|
967
875
|
case 'MatchStatement':
|
|
968
876
|
{
|
|
969
877
|
return mapMatchStatement(node);
|
|
970
878
|
}
|
|
971
|
-
|
|
972
879
|
case 'Identifier':
|
|
973
880
|
{
|
|
974
881
|
if (genID == null) {
|
|
975
882
|
throw Error('GenID must be initialized at the start of the transform.');
|
|
976
883
|
}
|
|
977
|
-
|
|
978
884
|
genID.addUsage(node.name);
|
|
979
885
|
return node;
|
|
980
886
|
}
|
|
981
|
-
|
|
982
887
|
default:
|
|
983
888
|
{
|
|
984
889
|
return node;
|
|
985
890
|
}
|
|
986
891
|
}
|
|
987
892
|
}
|
|
988
|
-
|
|
989
893
|
});
|
|
990
894
|
}
|