@danielx/civet 0.6.1 → 0.6.3
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/browser.js +231 -76
- package/dist/main.js +231 -76
- package/dist/main.mjs +231 -76
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -31,6 +31,29 @@ var Civet = (() => {
|
|
|
31
31
|
var require_lib = __commonJS({
|
|
32
32
|
"source/lib.js"(exports, module) {
|
|
33
33
|
"use strict";
|
|
34
|
+
function aliasBinding(p, ref) {
|
|
35
|
+
if (p.type === "Identifier") {
|
|
36
|
+
p.children[0] = ref;
|
|
37
|
+
} else if (p.type === "BindingRestElement") {
|
|
38
|
+
aliasBinding(p.binding, ref);
|
|
39
|
+
} else if (p.value?.type === "Identifier") {
|
|
40
|
+
aliasBinding(p.value, ref);
|
|
41
|
+
} else {
|
|
42
|
+
p.value = ref;
|
|
43
|
+
p.children.push(": ", ref);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function arrayElementHasTrailingComma(elementNode) {
|
|
47
|
+
const { children } = elementNode, { length } = children;
|
|
48
|
+
const lastChild = children[length - 1];
|
|
49
|
+
if (lastChild) {
|
|
50
|
+
const l2 = lastChild.length;
|
|
51
|
+
if (lastChild[l2 - 1]?.token === ",") {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
34
57
|
function blockWithPrefix(prefixStatements, block) {
|
|
35
58
|
if (prefixStatements && prefixStatements.length) {
|
|
36
59
|
const indent = getIndent(block.expressions[0]);
|
|
@@ -173,7 +196,7 @@ var Civet = (() => {
|
|
|
173
196
|
function hoistRefDecs(statements) {
|
|
174
197
|
gatherRecursiveAll(statements, (s) => s.hoistDec).forEach((node) => {
|
|
175
198
|
const { hoistDec } = node;
|
|
176
|
-
|
|
199
|
+
let outer = closest(node, ["IfStatement", "IterationStatement"]);
|
|
177
200
|
if (!outer) {
|
|
178
201
|
node.children.push({
|
|
179
202
|
type: "Error",
|
|
@@ -181,7 +204,11 @@ var Civet = (() => {
|
|
|
181
204
|
});
|
|
182
205
|
return;
|
|
183
206
|
}
|
|
184
|
-
|
|
207
|
+
let block = outer.parent;
|
|
208
|
+
if (block.type === "PatternMatchingStatement") {
|
|
209
|
+
outer = block;
|
|
210
|
+
block = block.parent;
|
|
211
|
+
}
|
|
185
212
|
const { expressions } = block;
|
|
186
213
|
const index = expressions.findIndex(([, s]) => outer === s);
|
|
187
214
|
if (index < 0)
|
|
@@ -608,6 +635,8 @@ var Civet = (() => {
|
|
|
608
635
|
};
|
|
609
636
|
}
|
|
610
637
|
module.exports = {
|
|
638
|
+
aliasBinding,
|
|
639
|
+
arrayElementHasTrailingComma,
|
|
611
640
|
blockWithPrefix,
|
|
612
641
|
clone,
|
|
613
642
|
convertMethodToFunction,
|
|
@@ -1298,6 +1327,8 @@ ${input.slice(result.pos)}
|
|
|
1298
1327
|
NestedCaseClauses,
|
|
1299
1328
|
NestedCaseClause,
|
|
1300
1329
|
CaseClause,
|
|
1330
|
+
PatternExpressionList,
|
|
1331
|
+
ConditionFragment,
|
|
1301
1332
|
CaseExpressionList,
|
|
1302
1333
|
ImpliedColon,
|
|
1303
1334
|
TryStatement,
|
|
@@ -1601,6 +1632,7 @@ ${input.slice(result.pos)}
|
|
|
1601
1632
|
ImportType,
|
|
1602
1633
|
TypeTuple,
|
|
1603
1634
|
TypeList,
|
|
1635
|
+
TypeElement,
|
|
1604
1636
|
NestedTypeList,
|
|
1605
1637
|
NestedType,
|
|
1606
1638
|
TypeConditional,
|
|
@@ -4893,13 +4925,8 @@ ${input.slice(result.pos)}
|
|
|
4893
4925
|
var close = $7;
|
|
4894
4926
|
const names = pes.flatMap((p) => p.names);
|
|
4895
4927
|
if (rest) {
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
restIdentifier = rest.binding.ref;
|
|
4899
|
-
} else {
|
|
4900
|
-
names.push(...rest.names);
|
|
4901
|
-
restIdentifier = rest.names[0];
|
|
4902
|
-
}
|
|
4928
|
+
const restIdentifier = rest.binding.ref || rest.binding;
|
|
4929
|
+
names.push(...rest.names || []);
|
|
4903
4930
|
let blockPrefix;
|
|
4904
4931
|
if (after.length) {
|
|
4905
4932
|
blockPrefix = {
|
|
@@ -4957,7 +4984,7 @@ ${input.slice(result.pos)}
|
|
|
4957
4984
|
type: "FunctionRestParameter",
|
|
4958
4985
|
children: $0,
|
|
4959
4986
|
names: id.names,
|
|
4960
|
-
binding: id
|
|
4987
|
+
binding: id.binding
|
|
4961
4988
|
};
|
|
4962
4989
|
});
|
|
4963
4990
|
function FunctionRestParameter(state) {
|
|
@@ -5721,8 +5748,11 @@ ${input.slice(result.pos)}
|
|
|
5721
5748
|
var dots = $2;
|
|
5722
5749
|
var binding = $3;
|
|
5723
5750
|
return {
|
|
5724
|
-
|
|
5725
|
-
children: [...ws || [], dots,
|
|
5751
|
+
type: "BindingRestElement",
|
|
5752
|
+
children: [...ws || [], dots, binding],
|
|
5753
|
+
binding,
|
|
5754
|
+
name: binding.name,
|
|
5755
|
+
names: binding.names,
|
|
5726
5756
|
rest: true
|
|
5727
5757
|
};
|
|
5728
5758
|
});
|
|
@@ -5731,8 +5761,11 @@ ${input.slice(result.pos)}
|
|
|
5731
5761
|
var binding = $2;
|
|
5732
5762
|
var dots = $3;
|
|
5733
5763
|
return {
|
|
5734
|
-
|
|
5735
|
-
children: [...ws || [], dots,
|
|
5764
|
+
type: "BindingRestElement",
|
|
5765
|
+
children: [...ws || [], dots, binding],
|
|
5766
|
+
binding,
|
|
5767
|
+
name: binding.name,
|
|
5768
|
+
names: binding.names,
|
|
5736
5769
|
rest: true
|
|
5737
5770
|
};
|
|
5738
5771
|
});
|
|
@@ -10610,33 +10643,20 @@ ${input.slice(result.pos)}
|
|
|
10610
10643
|
return result;
|
|
10611
10644
|
}
|
|
10612
10645
|
}
|
|
10613
|
-
var CaseClause$0 = $TS($S(
|
|
10614
|
-
var
|
|
10646
|
+
var CaseClause$0 = $TS($S(PatternExpressionList, $C(ThenClause, NestedBlockStatements, EmptyBareBlock)), function($skip, $loc, $0, $1, $2) {
|
|
10647
|
+
var patterns = $1;
|
|
10615
10648
|
var block = $2;
|
|
10616
10649
|
return {
|
|
10617
10650
|
type: "PatternClause",
|
|
10618
10651
|
children: $0,
|
|
10619
10652
|
block,
|
|
10620
|
-
|
|
10653
|
+
patterns
|
|
10621
10654
|
};
|
|
10622
10655
|
});
|
|
10623
|
-
var CaseClause$1 = $
|
|
10624
|
-
var pattern = $1;
|
|
10625
|
-
var block = $2;
|
|
10626
|
-
return {
|
|
10627
|
-
type: "PatternClause",
|
|
10628
|
-
children: $0,
|
|
10629
|
-
block,
|
|
10630
|
-
pattern: {
|
|
10631
|
-
type: "ConditionFragment",
|
|
10632
|
-
children: pattern
|
|
10633
|
-
}
|
|
10634
|
-
};
|
|
10635
|
-
});
|
|
10636
|
-
var CaseClause$2 = $T($S(Case, CaseExpressionList, $C(NestedBlockStatements, EmptyBareBlock)), function(value) {
|
|
10656
|
+
var CaseClause$1 = $T($S(Case, CaseExpressionList, $C(NestedBlockStatements, EmptyBareBlock)), function(value) {
|
|
10637
10657
|
return { "type": "CaseClause", "children": value };
|
|
10638
10658
|
});
|
|
10639
|
-
var CaseClause$
|
|
10659
|
+
var CaseClause$2 = $TS($S(When, CaseExpressionList, InsertOpenBrace, $C(ThenClause, NestedBlockStatements, EmptyBareBlock), InsertBreak, InsertNewline, InsertIndent, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8) {
|
|
10640
10660
|
var cases = $2;
|
|
10641
10661
|
var block = $4;
|
|
10642
10662
|
var b = $5;
|
|
@@ -10648,7 +10668,7 @@ ${input.slice(result.pos)}
|
|
|
10648
10668
|
children: $0
|
|
10649
10669
|
};
|
|
10650
10670
|
});
|
|
10651
|
-
var CaseClause$
|
|
10671
|
+
var CaseClause$3 = $TS($S(Default, ImpliedColon, $C(NestedBlockStatements, EmptyBareBlock)), function($skip, $loc, $0, $1, $2, $3) {
|
|
10652
10672
|
var block = $3;
|
|
10653
10673
|
return {
|
|
10654
10674
|
type: "DefaultClause",
|
|
@@ -10656,7 +10676,7 @@ ${input.slice(result.pos)}
|
|
|
10656
10676
|
children: $0
|
|
10657
10677
|
};
|
|
10658
10678
|
});
|
|
10659
|
-
var CaseClause$
|
|
10679
|
+
var CaseClause$4 = $TS($S(Else, ImpliedColon, $C(ThenClause, BracedBlock, EmptyBlock)), function($skip, $loc, $0, $1, $2, $3) {
|
|
10660
10680
|
var block = $3;
|
|
10661
10681
|
$1.token = "default";
|
|
10662
10682
|
return {
|
|
@@ -10676,17 +10696,74 @@ ${input.slice(result.pos)}
|
|
|
10676
10696
|
}
|
|
10677
10697
|
}
|
|
10678
10698
|
if (state.tokenize) {
|
|
10679
|
-
const result = $TOKEN("CaseClause", state, CaseClause$0(state) || CaseClause$1(state) || CaseClause$2(state) || CaseClause$3(state) || CaseClause$4(state)
|
|
10699
|
+
const result = $TOKEN("CaseClause", state, CaseClause$0(state) || CaseClause$1(state) || CaseClause$2(state) || CaseClause$3(state) || CaseClause$4(state));
|
|
10680
10700
|
if (state.events)
|
|
10681
10701
|
state.events.exit?.("CaseClause", state, result, eventData);
|
|
10682
10702
|
return result;
|
|
10683
10703
|
} else {
|
|
10684
|
-
const result = CaseClause$0(state) || CaseClause$1(state) || CaseClause$2(state) || CaseClause$3(state) || CaseClause$4(state)
|
|
10704
|
+
const result = CaseClause$0(state) || CaseClause$1(state) || CaseClause$2(state) || CaseClause$3(state) || CaseClause$4(state);
|
|
10685
10705
|
if (state.events)
|
|
10686
10706
|
state.events.exit?.("CaseClause", state, result, eventData);
|
|
10687
10707
|
return result;
|
|
10688
10708
|
}
|
|
10689
10709
|
}
|
|
10710
|
+
var PatternExpressionList$0 = $TS($S(ConditionFragment, $Q($S($E(_), Comma, $E(_), ConditionFragment))), function($skip, $loc, $0, $1, $2) {
|
|
10711
|
+
var first = $1;
|
|
10712
|
+
var rest = $2;
|
|
10713
|
+
return [first, ...rest.map(([, , , p]) => p)];
|
|
10714
|
+
});
|
|
10715
|
+
function PatternExpressionList(state) {
|
|
10716
|
+
let eventData;
|
|
10717
|
+
if (state.events) {
|
|
10718
|
+
const result = state.events.enter?.("PatternExpressionList", state);
|
|
10719
|
+
if (result) {
|
|
10720
|
+
if (result.cache)
|
|
10721
|
+
return result.cache;
|
|
10722
|
+
eventData = result.data;
|
|
10723
|
+
}
|
|
10724
|
+
}
|
|
10725
|
+
if (state.tokenize) {
|
|
10726
|
+
const result = $TOKEN("PatternExpressionList", state, PatternExpressionList$0(state));
|
|
10727
|
+
if (state.events)
|
|
10728
|
+
state.events.exit?.("PatternExpressionList", state, result, eventData);
|
|
10729
|
+
return result;
|
|
10730
|
+
} else {
|
|
10731
|
+
const result = PatternExpressionList$0(state);
|
|
10732
|
+
if (state.events)
|
|
10733
|
+
state.events.exit?.("PatternExpressionList", state, result, eventData);
|
|
10734
|
+
return result;
|
|
10735
|
+
}
|
|
10736
|
+
}
|
|
10737
|
+
var ConditionFragment$0 = BindingPattern;
|
|
10738
|
+
var ConditionFragment$1 = $TV($P(SingleLineBinaryOpRHS), function($skip, $loc, $0, $1) {
|
|
10739
|
+
var pattern = $0;
|
|
10740
|
+
return {
|
|
10741
|
+
type: "ConditionFragment",
|
|
10742
|
+
children: pattern
|
|
10743
|
+
};
|
|
10744
|
+
});
|
|
10745
|
+
function ConditionFragment(state) {
|
|
10746
|
+
let eventData;
|
|
10747
|
+
if (state.events) {
|
|
10748
|
+
const result = state.events.enter?.("ConditionFragment", state);
|
|
10749
|
+
if (result) {
|
|
10750
|
+
if (result.cache)
|
|
10751
|
+
return result.cache;
|
|
10752
|
+
eventData = result.data;
|
|
10753
|
+
}
|
|
10754
|
+
}
|
|
10755
|
+
if (state.tokenize) {
|
|
10756
|
+
const result = $TOKEN("ConditionFragment", state, ConditionFragment$0(state) || ConditionFragment$1(state));
|
|
10757
|
+
if (state.events)
|
|
10758
|
+
state.events.exit?.("ConditionFragment", state, result, eventData);
|
|
10759
|
+
return result;
|
|
10760
|
+
} else {
|
|
10761
|
+
const result = ConditionFragment$0(state) || ConditionFragment$1(state);
|
|
10762
|
+
if (state.events)
|
|
10763
|
+
state.events.exit?.("ConditionFragment", state, result, eventData);
|
|
10764
|
+
return result;
|
|
10765
|
+
}
|
|
10766
|
+
}
|
|
10690
10767
|
var CaseExpressionList$0 = $TS($S(ForbidMultiLineImplicitObjectLiteral, $E($S($Q(_), ExpressionWithIndentedApplicationForbidden, ImpliedColon)), $Q($S(__, Comma, ExpressionWithIndentedApplicationForbidden, ImpliedColon)), RestoreMultiLineImplicitObjectLiteral), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
10691
10768
|
var first = $2;
|
|
10692
10769
|
var rest = $3;
|
|
@@ -19183,7 +19260,7 @@ ${input.slice(result.pos)}
|
|
|
19183
19260
|
return result;
|
|
19184
19261
|
}
|
|
19185
19262
|
}
|
|
19186
|
-
var TypeList$0 = $S(
|
|
19263
|
+
var TypeList$0 = $S(TypeElement, $Q($S(__, Comma, TypeElement)));
|
|
19187
19264
|
function TypeList(state) {
|
|
19188
19265
|
let eventData;
|
|
19189
19266
|
if (state.events) {
|
|
@@ -19206,6 +19283,39 @@ ${input.slice(result.pos)}
|
|
|
19206
19283
|
return result;
|
|
19207
19284
|
}
|
|
19208
19285
|
}
|
|
19286
|
+
var TypeElement$0 = $S($S(__, DotDotDot, __), Type);
|
|
19287
|
+
var TypeElement$1 = $TS($S(Type, $E($S($E(_), DotDotDot))), function($skip, $loc, $0, $1, $2) {
|
|
19288
|
+
var type = $1;
|
|
19289
|
+
var dots = $2;
|
|
19290
|
+
if (!dots)
|
|
19291
|
+
return type;
|
|
19292
|
+
const ws = getTrimmingSpace(type);
|
|
19293
|
+
if (!ws)
|
|
19294
|
+
return [dots[1], dots[0], type];
|
|
19295
|
+
return [ws, dots[1], dots[0], insertTrimmingSpace(type, "")];
|
|
19296
|
+
});
|
|
19297
|
+
function TypeElement(state) {
|
|
19298
|
+
let eventData;
|
|
19299
|
+
if (state.events) {
|
|
19300
|
+
const result = state.events.enter?.("TypeElement", state);
|
|
19301
|
+
if (result) {
|
|
19302
|
+
if (result.cache)
|
|
19303
|
+
return result.cache;
|
|
19304
|
+
eventData = result.data;
|
|
19305
|
+
}
|
|
19306
|
+
}
|
|
19307
|
+
if (state.tokenize) {
|
|
19308
|
+
const result = $TOKEN("TypeElement", state, TypeElement$0(state) || TypeElement$1(state));
|
|
19309
|
+
if (state.events)
|
|
19310
|
+
state.events.exit?.("TypeElement", state, result, eventData);
|
|
19311
|
+
return result;
|
|
19312
|
+
} else {
|
|
19313
|
+
const result = TypeElement$0(state) || TypeElement$1(state);
|
|
19314
|
+
if (state.events)
|
|
19315
|
+
state.events.exit?.("TypeElement", state, result, eventData);
|
|
19316
|
+
return result;
|
|
19317
|
+
}
|
|
19318
|
+
}
|
|
19209
19319
|
var NestedTypeList$0 = $TS($S(PushIndent, $Q(NestedType), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
|
|
19210
19320
|
var types = $2;
|
|
19211
19321
|
if (types.length)
|
|
@@ -21344,20 +21454,27 @@ ${input.slice(result.pos)}
|
|
|
21344
21454
|
module.wrapIIFE = (exp, async) => {
|
|
21345
21455
|
let prefix, suffix;
|
|
21346
21456
|
if (async) {
|
|
21347
|
-
prefix = "(async ()=>
|
|
21348
|
-
suffix = "
|
|
21457
|
+
prefix = "(async ()=>";
|
|
21458
|
+
suffix = ")()";
|
|
21349
21459
|
} else if (hasAwait(exp)) {
|
|
21350
|
-
prefix = "(await (async ()=>
|
|
21351
|
-
suffix = "
|
|
21460
|
+
prefix = "(await (async ()=>";
|
|
21461
|
+
suffix = ")())";
|
|
21352
21462
|
} else {
|
|
21353
|
-
prefix = "(()=>
|
|
21354
|
-
suffix = "
|
|
21355
|
-
}
|
|
21356
|
-
if (Array.isArray(exp)) {
|
|
21357
|
-
return [prefix, ...exp, suffix];
|
|
21358
|
-
} else {
|
|
21359
|
-
return [prefix, exp, suffix];
|
|
21463
|
+
prefix = "(()=>";
|
|
21464
|
+
suffix = ")()";
|
|
21360
21465
|
}
|
|
21466
|
+
const expressions = Array.isArray(exp) ? [[...exp]] : [exp];
|
|
21467
|
+
const block = {
|
|
21468
|
+
type: "BlockStatement",
|
|
21469
|
+
expressions,
|
|
21470
|
+
children: ["{", expressions, "}"],
|
|
21471
|
+
bare: false
|
|
21472
|
+
};
|
|
21473
|
+
return [
|
|
21474
|
+
prefix,
|
|
21475
|
+
block,
|
|
21476
|
+
suffix
|
|
21477
|
+
];
|
|
21361
21478
|
};
|
|
21362
21479
|
function wrapIterationReturningResults(statement, outerRef) {
|
|
21363
21480
|
if (statement.type === "DoStatement") {
|
|
@@ -21795,8 +21912,8 @@ ${input.slice(result.pos)}
|
|
|
21795
21912
|
module.adjustBindingElements = function(elements) {
|
|
21796
21913
|
const names = elements.flatMap((p) => p.names || []), { length } = elements;
|
|
21797
21914
|
let blockPrefix, restIndex = -1, restCount = 0;
|
|
21798
|
-
elements.forEach(({
|
|
21799
|
-
if (
|
|
21915
|
+
elements.forEach(({ type }, i) => {
|
|
21916
|
+
if (type === "BindingRestElement") {
|
|
21800
21917
|
if (restIndex < 0)
|
|
21801
21918
|
restIndex = i;
|
|
21802
21919
|
restCount++;
|
|
@@ -21812,17 +21929,15 @@ ${input.slice(result.pos)}
|
|
|
21812
21929
|
} else if (restCount === 1) {
|
|
21813
21930
|
const rest = elements[restIndex];
|
|
21814
21931
|
const after = elements.slice(restIndex + 1);
|
|
21815
|
-
|
|
21816
|
-
|
|
21817
|
-
|
|
21818
|
-
|
|
21819
|
-
|
|
21820
|
-
|
|
21821
|
-
}
|
|
21822
|
-
if (after.length) {
|
|
21932
|
+
const restIdentifier = rest.binding.ref || rest.binding;
|
|
21933
|
+
names.push(...rest.names || []);
|
|
21934
|
+
let l = after.length;
|
|
21935
|
+
if (l) {
|
|
21936
|
+
if (arrayElementHasTrailingComma(after[l - 1]))
|
|
21937
|
+
l++;
|
|
21823
21938
|
blockPrefix = {
|
|
21824
21939
|
type: "PostRestBindingElements",
|
|
21825
|
-
children: ["[", insertTrimmingSpace(after, ""), "] = ", restIdentifier, ".splice(-",
|
|
21940
|
+
children: ["[", insertTrimmingSpace(after, ""), "] = ", restIdentifier, ".splice(-", l.toString(), ")"],
|
|
21826
21941
|
names: after.flatMap((p) => p.names)
|
|
21827
21942
|
};
|
|
21828
21943
|
}
|
|
@@ -22292,7 +22407,11 @@ ${input.slice(result.pos)}
|
|
|
22292
22407
|
}
|
|
22293
22408
|
}
|
|
22294
22409
|
function elideMatchersFromArrayBindings(elements) {
|
|
22295
|
-
return elements.map((
|
|
22410
|
+
return elements.map((el) => {
|
|
22411
|
+
if (el.type === "BindingRestElement") {
|
|
22412
|
+
return ["", el, void 0];
|
|
22413
|
+
}
|
|
22414
|
+
const { children: [ws, e, sep] } = el;
|
|
22296
22415
|
switch (e.type) {
|
|
22297
22416
|
case "Literal":
|
|
22298
22417
|
case "RegularExpressionLiteral":
|
|
@@ -22339,8 +22458,15 @@ ${input.slice(result.pos)}
|
|
|
22339
22458
|
}
|
|
22340
22459
|
function nonMatcherBindings(pattern) {
|
|
22341
22460
|
switch (pattern.type) {
|
|
22342
|
-
case "ArrayBindingPattern":
|
|
22343
|
-
|
|
22461
|
+
case "ArrayBindingPattern": {
|
|
22462
|
+
const elements = elideMatchersFromArrayBindings(pattern.elements);
|
|
22463
|
+
const children = ["[", elements, "]"];
|
|
22464
|
+
return {
|
|
22465
|
+
...pattern,
|
|
22466
|
+
children,
|
|
22467
|
+
elements
|
|
22468
|
+
};
|
|
22469
|
+
}
|
|
22344
22470
|
case "PostRestBindingElements": {
|
|
22345
22471
|
const els = elideMatchersFromArrayBindings(pattern.children[1]);
|
|
22346
22472
|
return {
|
|
@@ -22360,11 +22486,25 @@ ${input.slice(result.pos)}
|
|
|
22360
22486
|
}
|
|
22361
22487
|
function aggregateDuplicateBindings(bindings) {
|
|
22362
22488
|
const props = gatherRecursiveAll(bindings, (n) => n.type === "BindingProperty");
|
|
22489
|
+
const arrayBindings = gatherRecursiveAll(bindings, (n) => n.type === "ArrayBindingPattern");
|
|
22490
|
+
arrayBindings.forEach((a) => {
|
|
22491
|
+
const { elements } = a;
|
|
22492
|
+
elements.forEach((element) => {
|
|
22493
|
+
if (Array.isArray(element)) {
|
|
22494
|
+
const [, e] = element;
|
|
22495
|
+
if (e.type === "Identifier") {
|
|
22496
|
+
props.push(e);
|
|
22497
|
+
} else if (e.type === "BindingRestElement") {
|
|
22498
|
+
props.push(e);
|
|
22499
|
+
}
|
|
22500
|
+
}
|
|
22501
|
+
});
|
|
22502
|
+
});
|
|
22363
22503
|
const declarations = [];
|
|
22364
22504
|
const propsGroupedByName = /* @__PURE__ */ new Map();
|
|
22365
22505
|
for (const p of props) {
|
|
22366
22506
|
const { name, value } = p;
|
|
22367
|
-
const key = value?.name || name
|
|
22507
|
+
const key = value?.name || name?.name || name;
|
|
22368
22508
|
if (propsGroupedByName.has(key)) {
|
|
22369
22509
|
propsGroupedByName.get(key).push(p);
|
|
22370
22510
|
} else {
|
|
@@ -22384,7 +22524,7 @@ ${input.slice(result.pos)}
|
|
|
22384
22524
|
base: `_${key}`,
|
|
22385
22525
|
id: key
|
|
22386
22526
|
};
|
|
22387
|
-
p
|
|
22527
|
+
aliasBinding(p, ref);
|
|
22388
22528
|
});
|
|
22389
22529
|
return;
|
|
22390
22530
|
}
|
|
@@ -22396,7 +22536,7 @@ ${input.slice(result.pos)}
|
|
|
22396
22536
|
base: key,
|
|
22397
22537
|
id: key
|
|
22398
22538
|
};
|
|
22399
|
-
p
|
|
22539
|
+
aliasBinding(p, ref);
|
|
22400
22540
|
return ref;
|
|
22401
22541
|
});
|
|
22402
22542
|
declarations.push(["const ", key, " = [", ...refs.map((r, i) => {
|
|
@@ -22430,6 +22570,7 @@ ${input.slice(result.pos)}
|
|
|
22430
22570
|
expression = expression.expression;
|
|
22431
22571
|
}
|
|
22432
22572
|
let ref = module.needsRef(expression, "m") || expression;
|
|
22573
|
+
let hoistDec = ref !== expression ? [["", ["const ", ref, " = ", expression], ";"]] : void 0;
|
|
22433
22574
|
let prev = [], root = prev;
|
|
22434
22575
|
const l = clauses.length;
|
|
22435
22576
|
clauses.forEach((c, i) => {
|
|
@@ -22437,18 +22578,28 @@ ${input.slice(result.pos)}
|
|
|
22437
22578
|
prev.push(c.block);
|
|
22438
22579
|
return;
|
|
22439
22580
|
}
|
|
22440
|
-
let {
|
|
22581
|
+
let { patterns, block } = c;
|
|
22582
|
+
let pattern = patterns[0];
|
|
22441
22583
|
const indent = block.expressions?.[0]?.[0] || "";
|
|
22442
|
-
const
|
|
22443
|
-
|
|
22444
|
-
|
|
22445
|
-
|
|
22446
|
-
|
|
22447
|
-
|
|
22584
|
+
const alternativeConditions = patterns.map((pattern2, i2) => {
|
|
22585
|
+
const conditions = [];
|
|
22586
|
+
getPatternConditions(pattern2, ref, conditions);
|
|
22587
|
+
return conditions;
|
|
22588
|
+
});
|
|
22589
|
+
const conditionExpression = alternativeConditions.map((conditions, i2) => {
|
|
22590
|
+
const conditionArray = conditions.map((c2, i3) => {
|
|
22591
|
+
if (i3 === 0)
|
|
22448
22592
|
return c2;
|
|
22449
22593
|
return [" && ", ...c2];
|
|
22450
|
-
})
|
|
22451
|
-
|
|
22594
|
+
});
|
|
22595
|
+
if (i2 === 0)
|
|
22596
|
+
return conditionArray;
|
|
22597
|
+
return [" || ", ...conditionArray];
|
|
22598
|
+
});
|
|
22599
|
+
const condition = {
|
|
22600
|
+
type: "ParenthesizedExpression",
|
|
22601
|
+
children: ["(", conditionExpression, ")"],
|
|
22602
|
+
expression: conditionExpression
|
|
22452
22603
|
};
|
|
22453
22604
|
const prefix = [];
|
|
22454
22605
|
switch (pattern.type) {
|
|
@@ -22482,8 +22633,10 @@ ${input.slice(result.pos)}
|
|
|
22482
22633
|
type: "IfStatement",
|
|
22483
22634
|
children: ["if", condition, block, next],
|
|
22484
22635
|
then: block,
|
|
22485
|
-
else: next
|
|
22636
|
+
else: next,
|
|
22637
|
+
hoistDec
|
|
22486
22638
|
}]);
|
|
22639
|
+
hoistDec = void 0;
|
|
22487
22640
|
prev = next;
|
|
22488
22641
|
});
|
|
22489
22642
|
if (module.config.implicitReturns && s.type === "SwitchExpression") {
|
|
@@ -23162,6 +23315,8 @@ ${input.slice(result.pos)}
|
|
|
23162
23315
|
exports.parse = parse2;
|
|
23163
23316
|
exports.default = { parse: parse2 };
|
|
23164
23317
|
var {
|
|
23318
|
+
aliasBinding,
|
|
23319
|
+
arrayElementHasTrailingComma,
|
|
23165
23320
|
blockWithPrefix,
|
|
23166
23321
|
clone,
|
|
23167
23322
|
convertMethodToFunction,
|
|
@@ -23633,7 +23788,7 @@ ${input.slice(result.pos)}
|
|
|
23633
23788
|
var uncacheable;
|
|
23634
23789
|
({ parse } = import_parser.default);
|
|
23635
23790
|
({ SourceMap: SourceMap2 } = util_exports);
|
|
23636
|
-
uncacheable = /* @__PURE__ */ new Set(["ActualAssignment", "AllowAll", "AllowClassImplicitCall", "AllowIndentedApplication", "AllowMultiLineImplicitObjectLiteral", "AllowNewlineBinaryOp", "AllowTrailingMemberProperty", "AllowedTrailingMemberExpressions", "ApplicationStart", "Arguments", "ArgumentsWithTrailingMemberExpressions", "ArrowFunction", "ArrowFunctionTail", "AssignmentExpression", "AssignmentExpressionTail", "BinaryOpExpression", "BinaryOpRHS", "BracedBlock", "BracedObjectLiteralContent", "BracedOrEmptyBlock", "CallExpression", "CallExpressionRest", "ClassImplicitCallForbidden", "CoffeeCommentEnabled", "CommaDelimiter", "ConditionalExpression", "Declaration", "Debugger", "Dedented", "ElementListWithIndentedApplicationForbidden", "ElseClause", "Expression", "ExpressionStatement", "ExpressionWithIndentedApplicationForbidden", "ExtendedExpression", "FatArrowBody", "ForbidClassImplicitCall", "ForbidIndentedApplication", "ForbidMultiLineImplicitObjectLiteral", "ForbidNewlineBinaryOp", "ForbidTrailingMemberProperty", "FunctionDeclaration", "FunctionExpression", "HoistableDeclaration", "ImplicitArguments", "ImplicitInlineObjectPropertyDelimiter", "ImplicitNestedBlock", "IndentedApplicationAllowed", "IndentedFurther", "IndentedJSXChildExpression", "InlineObjectLiteral", "InsertIndent", "JSXChild", "JSXChildren", "JSXElement", "JSXFragment", "JSXImplicitFragment", "JSXMixedChildren", "JSXNested", "JSXNestedChildren", "JSXOptionalClosingElement", "JSXOptionalClosingFragment", "JSXTag", "LeftHandSideExpression", "MemberExpression", "MemberExpressionRest", "Nested", "NestedBindingElement", "NestedBindingElements", "NestedBlockExpression", "NestedBlockExpression", "NestedBlockStatement", "NestedBlockStatements", "NestedClassSignatureElement", "NestedClassSignatureElements", "NestedDeclareElement", "NestedDeclareElements", "NestedElement", "NestedElementList", "NestedImplicitObjectLiteral", "NestedImplicitPropertyDefinition", "NestedImplicitPropertyDefinitions", "NestedInterfaceProperty", "NestedJSXChildExpression", "NestedModuleItem", "NestedModuleItems", "NestedNonAssignmentExtendedExpression", "NestedObject", "NestedPropertyDefinitions", "NewlineBinaryOpAllowed", "NonSingleBracedBlock", "NotDedented", "ObjectLiteral", "PopIndent", "PopJSXStack", "PostfixedExpression", "PostfixedStatement", "PrimaryExpression", "PushIndent", "PushJSXOpeningElement", "PushJSXOpeningFragment", "RestoreAll", "RestoreClassImplicitCall", "RestoreMultiLineImplicitObjectLiteral", "RestoreIndentedApplication", "RestoreTrailingMemberProperty", "RestoreNewlineBinaryOp", "RHS", "Samedent", "ShortCircuitExpression", "SingleLineAssignmentExpression", "SingleLineBinaryOpRHS", "SingleLineComment", "SingleLineStatements", "SnugNamedProperty", "Statement", "StatementListItem", "SuffixedExpression", "SuffixedStatement", "ThinArrowFunction", "TrackIndented", "TrailingMemberExpressions", "TrailingMemberPropertyAllowed", "TypedJSXElement", "TypedJSXFragment", "UnaryExpression", "UpdateExpression"]);
|
|
23791
|
+
uncacheable = /* @__PURE__ */ new Set(["ActualAssignment", "AllowAll", "AllowClassImplicitCall", "AllowIndentedApplication", "AllowMultiLineImplicitObjectLiteral", "AllowNewlineBinaryOp", "AllowTrailingMemberProperty", "AllowedTrailingMemberExpressions", "ApplicationStart", "Arguments", "ArgumentsWithTrailingMemberExpressions", "ArrowFunction", "ArrowFunctionTail", "AssignmentExpression", "AssignmentExpressionTail", "BinaryOpExpression", "BinaryOpRHS", "BracedBlock", "BracedObjectLiteralContent", "BracedOrEmptyBlock", "CallExpression", "CallExpressionRest", "ClassImplicitCallForbidden", "CoffeeCommentEnabled", "CommaDelimiter", "ConditionalExpression", "ConditionFragment", "Declaration", "Debugger", "Dedented", "ElementListWithIndentedApplicationForbidden", "ElseClause", "Expression", "ExpressionStatement", "ExpressionWithIndentedApplicationForbidden", "ExtendedExpression", "FatArrowBody", "ForbidClassImplicitCall", "ForbidIndentedApplication", "ForbidMultiLineImplicitObjectLiteral", "ForbidNewlineBinaryOp", "ForbidTrailingMemberProperty", "FunctionDeclaration", "FunctionExpression", "HoistableDeclaration", "ImplicitArguments", "ImplicitInlineObjectPropertyDelimiter", "ImplicitNestedBlock", "IndentedApplicationAllowed", "IndentedFurther", "IndentedJSXChildExpression", "InlineObjectLiteral", "InsertIndent", "JSXChild", "JSXChildren", "JSXElement", "JSXFragment", "JSXImplicitFragment", "JSXMixedChildren", "JSXNested", "JSXNestedChildren", "JSXOptionalClosingElement", "JSXOptionalClosingFragment", "JSXTag", "LeftHandSideExpression", "MemberExpression", "MemberExpressionRest", "Nested", "NestedBindingElement", "NestedBindingElements", "NestedBlockExpression", "NestedBlockExpression", "NestedBlockStatement", "NestedBlockStatements", "NestedClassSignatureElement", "NestedClassSignatureElements", "NestedDeclareElement", "NestedDeclareElements", "NestedElement", "NestedElementList", "NestedImplicitObjectLiteral", "NestedImplicitPropertyDefinition", "NestedImplicitPropertyDefinitions", "NestedInterfaceProperty", "NestedJSXChildExpression", "NestedModuleItem", "NestedModuleItems", "NestedNonAssignmentExtendedExpression", "NestedObject", "NestedPropertyDefinitions", "NewlineBinaryOpAllowed", "NonSingleBracedBlock", "NotDedented", "ObjectLiteral", "PatternExpressionList", "PopIndent", "PopJSXStack", "PostfixedExpression", "PostfixedStatement", "PrimaryExpression", "PushIndent", "PushJSXOpeningElement", "PushJSXOpeningFragment", "RestoreAll", "RestoreClassImplicitCall", "RestoreMultiLineImplicitObjectLiteral", "RestoreIndentedApplication", "RestoreTrailingMemberProperty", "RestoreNewlineBinaryOp", "RHS", "Samedent", "ShortCircuitExpression", "SingleLineAssignmentExpression", "SingleLineBinaryOpRHS", "SingleLineComment", "SingleLineStatements", "SnugNamedProperty", "Statement", "StatementListItem", "SuffixedExpression", "SuffixedStatement", "ThinArrowFunction", "TrackIndented", "TrailingMemberExpressions", "TrailingMemberPropertyAllowed", "TypedJSXElement", "TypedJSXFragment", "UnaryExpression", "UpdateExpression"]);
|
|
23637
23792
|
var compile = function(src, options) {
|
|
23638
23793
|
var ast, code, events, filename, ref, result, sm;
|
|
23639
23794
|
if (!options) {
|