@danielx/civet 0.4.19-pre.3 → 0.4.19-pre.5
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 +1 -2
- package/dist/browser.js +261 -46
- package/dist/esm.mjs +1 -1
- package/dist/main.js +261 -46
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,7 +86,7 @@ Things Kept from CoffeeScript
|
|
|
86
86
|
- Late assignment `x + y = z` -> `x + (y = z)`
|
|
87
87
|
- Braceless inline objects `x = coolStory: true`
|
|
88
88
|
- Simplified number method calls `1.toFixed()` -> `1..toFixed()`
|
|
89
|
-
- `if`/`switch` expressions
|
|
89
|
+
- `if`/`switch`/`for`/`loop`/`while`/`throw` expressions
|
|
90
90
|
- Destructuring object assignment doesn't require being wrapped in parens at the statement level `{a, b} = c` -> `({a, b} = c)`
|
|
91
91
|
- JSX 😿
|
|
92
92
|
|
|
@@ -115,7 +115,6 @@ Civet.
|
|
|
115
115
|
- Backtick embedded JS (replaced by template literals)
|
|
116
116
|
- Will likely add later
|
|
117
117
|
- Optional assignment `x?.y = 3` -> `x != null ? x.y = 3 : undefined`
|
|
118
|
-
- Loop expressions (at least in compatibility mode)
|
|
119
118
|
- Conditional assignment `a?[x] = 3` -> `a ? a[x] = 3 : undefined`
|
|
120
119
|
- Might add later
|
|
121
120
|
- `///` Heregexp
|
package/dist/browser.js
CHANGED
|
@@ -490,6 +490,7 @@ var Civet = (() => {
|
|
|
490
490
|
ThinArrowFunction,
|
|
491
491
|
Arrow,
|
|
492
492
|
Block,
|
|
493
|
+
ThenClause,
|
|
493
494
|
BracedOrEmptyBlock,
|
|
494
495
|
EmptyBlock,
|
|
495
496
|
BracedBlock,
|
|
@@ -543,6 +544,7 @@ var Civet = (() => {
|
|
|
543
544
|
EmptyStatement,
|
|
544
545
|
BlockStatement,
|
|
545
546
|
IfStatement,
|
|
547
|
+
ElseClause,
|
|
546
548
|
IfClause,
|
|
547
549
|
UnlessClause,
|
|
548
550
|
IfExpression,
|
|
@@ -550,6 +552,7 @@ var Civet = (() => {
|
|
|
550
552
|
NestedBlockExpressions,
|
|
551
553
|
NestedBlockExpression,
|
|
552
554
|
IterationStatement,
|
|
555
|
+
IterationExpression,
|
|
553
556
|
LoopStatement,
|
|
554
557
|
LoopClause,
|
|
555
558
|
DoWhileStatement,
|
|
@@ -560,12 +563,14 @@ var Civet = (() => {
|
|
|
560
563
|
ForStatementControl,
|
|
561
564
|
WhenCondition,
|
|
562
565
|
CoffeeForStatementParameters,
|
|
566
|
+
CoffeeForIndex,
|
|
563
567
|
CoffeeForDeclaration,
|
|
564
568
|
ForStatementParameters,
|
|
565
569
|
ForInOfDeclaration,
|
|
566
570
|
ForDeclaration,
|
|
567
571
|
ForBinding,
|
|
568
572
|
SwitchStatement,
|
|
573
|
+
EmptyCondition,
|
|
569
574
|
SwitchExpression,
|
|
570
575
|
CaseBlock,
|
|
571
576
|
NestedCaseClauses,
|
|
@@ -971,7 +976,7 @@ var Civet = (() => {
|
|
|
971
976
|
var $L153 = $L("civet");
|
|
972
977
|
var $L154 = $L(" ");
|
|
973
978
|
var $L155 = $L(" ");
|
|
974
|
-
var $R0 = $R(new RegExp("(of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])", "suy"));
|
|
979
|
+
var $R0 = $R(new RegExp("(for|of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])", "suy"));
|
|
975
980
|
var $R1 = $R(new RegExp("[&]", "suy"));
|
|
976
981
|
var $R2 = $R(new RegExp("[!~+-]+", "suy"));
|
|
977
982
|
var $R3 = $R(new RegExp("(?:\\p{ID_Start}|[_$])(?:\\p{ID_Continue}|[\\u200C\\u200D$])*", "suy"));
|
|
@@ -1059,13 +1064,14 @@ var Civet = (() => {
|
|
|
1059
1064
|
}
|
|
1060
1065
|
var ExpressionizedStatement$0 = DebuggerExpression;
|
|
1061
1066
|
var ExpressionizedStatement$1 = IfExpression;
|
|
1062
|
-
var ExpressionizedStatement$2 =
|
|
1063
|
-
var ExpressionizedStatement$3 =
|
|
1067
|
+
var ExpressionizedStatement$2 = IterationExpression;
|
|
1068
|
+
var ExpressionizedStatement$3 = SwitchExpression;
|
|
1069
|
+
var ExpressionizedStatement$4 = ThrowExpression;
|
|
1064
1070
|
function ExpressionizedStatement(state) {
|
|
1065
1071
|
if (state.tokenize) {
|
|
1066
|
-
return $TOKEN("ExpressionizedStatement", state, ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state));
|
|
1072
|
+
return $TOKEN("ExpressionizedStatement", state, ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state) || ExpressionizedStatement$4(state));
|
|
1067
1073
|
} else {
|
|
1068
|
-
return ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state);
|
|
1074
|
+
return ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state) || ExpressionizedStatement$4(state);
|
|
1069
1075
|
}
|
|
1070
1076
|
}
|
|
1071
1077
|
var Expression$0 = $TS($S(AssignmentExpression, $Q($S(__, Comma, AssignmentExpression))), function($skip, $loc, $0, $1, $2) {
|
|
@@ -1772,7 +1778,7 @@ var Civet = (() => {
|
|
|
1772
1778
|
return NonNullAssertion$0(state);
|
|
1773
1779
|
}
|
|
1774
1780
|
}
|
|
1775
|
-
var AdditionalReservedWords$0 = $R$0($EXPECT($R0, fail, "AdditionalReservedWords /(of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])/"));
|
|
1781
|
+
var AdditionalReservedWords$0 = $R$0($EXPECT($R0, fail, "AdditionalReservedWords /(for|of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])/"));
|
|
1776
1782
|
function AdditionalReservedWords(state) {
|
|
1777
1783
|
if (state.verbose)
|
|
1778
1784
|
console.log("ENTER:", "AdditionalReservedWords");
|
|
@@ -2385,12 +2391,8 @@ var Civet = (() => {
|
|
|
2385
2391
|
var exps = value[2];
|
|
2386
2392
|
return { "type": "BlockStatement", "expressions": exps, "children": value };
|
|
2387
2393
|
});
|
|
2388
|
-
var Block$2 =
|
|
2389
|
-
|
|
2390
|
-
});
|
|
2391
|
-
var Block$3 = $T($S($E(Then), __, Statement), function(value) {
|
|
2392
|
-
return [value[1], value[2]];
|
|
2393
|
-
});
|
|
2394
|
+
var Block$2 = ThenClause;
|
|
2395
|
+
var Block$3 = $S($Q(TrailingComment), Statement);
|
|
2394
2396
|
function Block(state) {
|
|
2395
2397
|
if (state.tokenize) {
|
|
2396
2398
|
return $TOKEN("Block", state, Block$0(state) || Block$1(state) || Block$2(state) || Block$3(state));
|
|
@@ -2398,6 +2400,18 @@ var Civet = (() => {
|
|
|
2398
2400
|
return Block$0(state) || Block$1(state) || Block$2(state) || Block$3(state);
|
|
2399
2401
|
}
|
|
2400
2402
|
}
|
|
2403
|
+
var ThenClause$0 = $T($S(Then, $Q(TrailingComment), Statement), function(value) {
|
|
2404
|
+
return [value[1], value[2]];
|
|
2405
|
+
});
|
|
2406
|
+
function ThenClause(state) {
|
|
2407
|
+
if (state.verbose)
|
|
2408
|
+
console.log("ENTER:", "ThenClause");
|
|
2409
|
+
if (state.tokenize) {
|
|
2410
|
+
return $TOKEN("ThenClause", state, ThenClause$0(state));
|
|
2411
|
+
} else {
|
|
2412
|
+
return ThenClause$0(state);
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2401
2415
|
var BracedOrEmptyBlock$0 = BracedBlock;
|
|
2402
2416
|
var BracedOrEmptyBlock$1 = EmptyBlock;
|
|
2403
2417
|
function BracedOrEmptyBlock(state) {
|
|
@@ -3273,16 +3287,20 @@ var Civet = (() => {
|
|
|
3273
3287
|
var ws = $2;
|
|
3274
3288
|
var post = $3;
|
|
3275
3289
|
if (post) {
|
|
3276
|
-
let
|
|
3277
|
-
if (post.
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
block = statement;
|
|
3282
|
-
}
|
|
3290
|
+
let children, expressions;
|
|
3291
|
+
if (post.blockPrefix?.length) {
|
|
3292
|
+
let indent = post.blockPrefix[0][0];
|
|
3293
|
+
expressions = [...post.blockPrefix, [indent, statement]];
|
|
3294
|
+
children = [" {\n", ...expressions, "\n", indent?.slice?.(0, -2), "}"];
|
|
3283
3295
|
} else {
|
|
3284
|
-
|
|
3296
|
+
expressions = [["", statement]];
|
|
3297
|
+
children = [" { ", ...expressions, " }"];
|
|
3285
3298
|
}
|
|
3299
|
+
const block = {
|
|
3300
|
+
type: "BlockStatement",
|
|
3301
|
+
children,
|
|
3302
|
+
expressions
|
|
3303
|
+
};
|
|
3286
3304
|
post.block = block;
|
|
3287
3305
|
post.children.push(block);
|
|
3288
3306
|
if (!module.isWhitespaceOrEmpty(ws))
|
|
@@ -3351,7 +3369,7 @@ var Civet = (() => {
|
|
|
3351
3369
|
return BlockStatement$0(state);
|
|
3352
3370
|
}
|
|
3353
3371
|
}
|
|
3354
|
-
var IfStatement$0 = $TS($S($C(IfClause, UnlessClause), Block, $E(
|
|
3372
|
+
var IfStatement$0 = $TS($S($C(IfClause, UnlessClause), Block, $E(ElseClause)), function($skip, $loc, $0, $1, $2, $3) {
|
|
3355
3373
|
var clause = $1;
|
|
3356
3374
|
var block = $2;
|
|
3357
3375
|
var e = $3;
|
|
@@ -3369,6 +3387,17 @@ var Civet = (() => {
|
|
|
3369
3387
|
return IfStatement$0(state);
|
|
3370
3388
|
}
|
|
3371
3389
|
}
|
|
3390
|
+
var ElseClause$0 = $T($S($Y(EOS), Samedent, Else, Block), function(value) {
|
|
3391
|
+
return [value[1], value[2], value[3]];
|
|
3392
|
+
});
|
|
3393
|
+
var ElseClause$1 = $S($Q(TrailingComment), Else, Block);
|
|
3394
|
+
function ElseClause(state) {
|
|
3395
|
+
if (state.tokenize) {
|
|
3396
|
+
return $TOKEN("ElseClause", state, ElseClause$0(state) || ElseClause$1(state));
|
|
3397
|
+
} else {
|
|
3398
|
+
return ElseClause$0(state) || ElseClause$1(state);
|
|
3399
|
+
}
|
|
3400
|
+
}
|
|
3372
3401
|
var IfClause$0 = $T($S(If, Condition), function(value) {
|
|
3373
3402
|
return { "type": "IfStatement", "children": value };
|
|
3374
3403
|
});
|
|
@@ -3480,9 +3509,22 @@ var Civet = (() => {
|
|
|
3480
3509
|
return IterationStatement$0(state) || IterationStatement$1(state) || IterationStatement$2(state) || IterationStatement$3(state);
|
|
3481
3510
|
}
|
|
3482
3511
|
}
|
|
3512
|
+
var IterationExpression$0 = $TS($S(IterationStatement), function($skip, $loc, $0, $1) {
|
|
3513
|
+
return module.expressionizeIteration($1);
|
|
3514
|
+
});
|
|
3515
|
+
function IterationExpression(state) {
|
|
3516
|
+
if (state.verbose)
|
|
3517
|
+
console.log("ENTER:", "IterationExpression");
|
|
3518
|
+
if (state.tokenize) {
|
|
3519
|
+
return $TOKEN("IterationExpression", state, IterationExpression$0(state));
|
|
3520
|
+
} else {
|
|
3521
|
+
return IterationExpression$0(state);
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3483
3524
|
var LoopStatement$0 = $TS($S(LoopClause, Block), function($skip, $loc, $0, $1, $2) {
|
|
3484
3525
|
var clause = $1;
|
|
3485
3526
|
var block = $2;
|
|
3527
|
+
clause.block = block;
|
|
3486
3528
|
clause.children.push(block);
|
|
3487
3529
|
return clause;
|
|
3488
3530
|
});
|
|
@@ -3496,7 +3538,7 @@ var Civet = (() => {
|
|
|
3496
3538
|
}
|
|
3497
3539
|
}
|
|
3498
3540
|
var LoopClause$0 = $T($S(Loop), function(value) {
|
|
3499
|
-
return { "type": "IterationStatement", "children": value };
|
|
3541
|
+
return { "type": "IterationStatement", "children": [value[0]], "block": null };
|
|
3500
3542
|
});
|
|
3501
3543
|
function LoopClause(state) {
|
|
3502
3544
|
if (state.verbose)
|
|
@@ -3508,7 +3550,8 @@ var Civet = (() => {
|
|
|
3508
3550
|
}
|
|
3509
3551
|
}
|
|
3510
3552
|
var DoWhileStatement$0 = $T($S(Do, BracedBlock, __, WhileClause), function(value) {
|
|
3511
|
-
|
|
3553
|
+
var block = value[1];
|
|
3554
|
+
return { "type": "IterationStatement", "children": value, "block": block };
|
|
3512
3555
|
});
|
|
3513
3556
|
function DoWhileStatement(state) {
|
|
3514
3557
|
if (state.verbose)
|
|
@@ -3522,6 +3565,7 @@ var Civet = (() => {
|
|
|
3522
3565
|
var WhileStatement$0 = $TS($S(WhileClause, Block), function($skip, $loc, $0, $1, $2) {
|
|
3523
3566
|
var clause = $1;
|
|
3524
3567
|
var block = $2;
|
|
3568
|
+
clause.block = block;
|
|
3525
3569
|
clause.children.push(block);
|
|
3526
3570
|
return clause;
|
|
3527
3571
|
});
|
|
@@ -3545,7 +3589,8 @@ var Civet = (() => {
|
|
|
3545
3589
|
}
|
|
3546
3590
|
return {
|
|
3547
3591
|
type: "IterationStatement",
|
|
3548
|
-
children: $0
|
|
3592
|
+
children: $0,
|
|
3593
|
+
block: null
|
|
3549
3594
|
};
|
|
3550
3595
|
});
|
|
3551
3596
|
function WhileClause(state) {
|
|
@@ -3631,13 +3676,14 @@ var Civet = (() => {
|
|
|
3631
3676
|
return WhenCondition$0(state);
|
|
3632
3677
|
}
|
|
3633
3678
|
}
|
|
3634
|
-
var CoffeeForStatementParameters$0 = $TS($S($E($S(Await, __)), InsertOpenParen, CoffeeForDeclaration, __, $C(In, Of, From), ExtendedExpression, $E($S(__, By, ExtendedExpression)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8) {
|
|
3679
|
+
var CoffeeForStatementParameters$0 = $TS($S($E($S(Await, __)), InsertOpenParen, CoffeeForDeclaration, $E(CoffeeForIndex), __, $C(In, Of, From), ExtendedExpression, $E($S(__, By, ExtendedExpression)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
|
|
3635
3680
|
var open = $2;
|
|
3636
3681
|
var declaration = $3;
|
|
3637
|
-
var
|
|
3638
|
-
var
|
|
3639
|
-
var
|
|
3640
|
-
var
|
|
3682
|
+
var index = $4;
|
|
3683
|
+
var kind = $6;
|
|
3684
|
+
var exp = $7;
|
|
3685
|
+
var step = $8;
|
|
3686
|
+
var close = $9;
|
|
3641
3687
|
let blockPrefix = [];
|
|
3642
3688
|
const indent = "".padStart((module.currentIndent + 1) * 2);
|
|
3643
3689
|
if (kind.token === "from") {
|
|
@@ -3747,10 +3793,17 @@ var Civet = (() => {
|
|
|
3747
3793
|
children: ["let ", ...expRefDec, counterRef, " = 0, ", lenRef, " = ", expRef, ".length"],
|
|
3748
3794
|
names: []
|
|
3749
3795
|
};
|
|
3796
|
+
let indexAssignment;
|
|
3797
|
+
let assignmentNames = [...varRef.names];
|
|
3798
|
+
if (index) {
|
|
3799
|
+
module.insertTrimmingSpace(index, "");
|
|
3800
|
+
indexAssignment = [index, "="];
|
|
3801
|
+
assignmentNames.push(...index.names);
|
|
3802
|
+
}
|
|
3750
3803
|
blockPrefix.push([{
|
|
3751
3804
|
type: "AssignmentExpression",
|
|
3752
|
-
children: [indent, varRef, " = ", expRef, "[", counterRef, "]\n"],
|
|
3753
|
-
names:
|
|
3805
|
+
children: [indent, varRef, " = ", expRef, "[", indexAssignment, counterRef, "]\n"],
|
|
3806
|
+
names: assignmentNames
|
|
3754
3807
|
}]);
|
|
3755
3808
|
return {
|
|
3756
3809
|
declaration,
|
|
@@ -3773,6 +3826,20 @@ var Civet = (() => {
|
|
|
3773
3826
|
return CoffeeForStatementParameters$0(state);
|
|
3774
3827
|
}
|
|
3775
3828
|
}
|
|
3829
|
+
var CoffeeForIndex$0 = $TS($S($Q(TrailingComment), Comma, $Q(TrailingComment), BindingIdentifier), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
3830
|
+
var id = $4;
|
|
3831
|
+
id.children.unshift(...$1, ...$3);
|
|
3832
|
+
return id;
|
|
3833
|
+
});
|
|
3834
|
+
function CoffeeForIndex(state) {
|
|
3835
|
+
if (state.verbose)
|
|
3836
|
+
console.log("ENTER:", "CoffeeForIndex");
|
|
3837
|
+
if (state.tokenize) {
|
|
3838
|
+
return $TOKEN("CoffeeForIndex", state, CoffeeForIndex$0(state));
|
|
3839
|
+
} else {
|
|
3840
|
+
return CoffeeForIndex$0(state);
|
|
3841
|
+
}
|
|
3842
|
+
}
|
|
3776
3843
|
var CoffeeForDeclaration$0 = $TS($S($E($S(__, $EXPECT($L76, fail, 'CoffeeForDeclaration "own"'))), ForBinding), function($skip, $loc, $0, $1, $2) {
|
|
3777
3844
|
var own = $1;
|
|
3778
3845
|
var binding = $2;
|
|
@@ -3805,14 +3872,14 @@ var Civet = (() => {
|
|
|
3805
3872
|
children: $0
|
|
3806
3873
|
};
|
|
3807
3874
|
});
|
|
3808
|
-
var ForStatementParameters$2 = $TS($S($E($S(Await, __)), OpenParen, __, ForInOfDeclaration, __, $C(In, Of),
|
|
3875
|
+
var ForStatementParameters$2 = $TS($S($E($S(Await, __)), OpenParen, __, ForInOfDeclaration, __, $C(In, Of), ExpressionWithIndentedApplicationSuppressed, __, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
|
|
3809
3876
|
var declaration = $4;
|
|
3810
3877
|
return {
|
|
3811
3878
|
declaration,
|
|
3812
3879
|
children: $0
|
|
3813
3880
|
};
|
|
3814
3881
|
});
|
|
3815
|
-
var ForStatementParameters$3 = $TS($S($E($S(Await, __)), InsertOpenParen, ForInOfDeclaration, __, $C(In, Of),
|
|
3882
|
+
var ForStatementParameters$3 = $TS($S($E($S(Await, __)), InsertOpenParen, ForInOfDeclaration, __, $C(In, Of), ExpressionWithIndentedApplicationSuppressed, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
|
|
3816
3883
|
var declaration = $3;
|
|
3817
3884
|
return {
|
|
3818
3885
|
declaration,
|
|
@@ -3877,8 +3944,30 @@ var Civet = (() => {
|
|
|
3877
3944
|
return ForBinding$0(state) || ForBinding$1(state);
|
|
3878
3945
|
}
|
|
3879
3946
|
}
|
|
3880
|
-
var SwitchStatement$0 = $
|
|
3881
|
-
|
|
3947
|
+
var SwitchStatement$0 = $TS($S(Switch, $C(EmptyCondition, Condition), CaseBlock), function($skip, $loc, $0, $1, $2, $3) {
|
|
3948
|
+
var condition = $2;
|
|
3949
|
+
var caseBlock = $3;
|
|
3950
|
+
if (condition.type === "EmptyCondition") {
|
|
3951
|
+
caseBlock.clauses.forEach(({ cases }) => {
|
|
3952
|
+
if (cases) {
|
|
3953
|
+
cases.forEach((c) => {
|
|
3954
|
+
const exp = c[1];
|
|
3955
|
+
switch (exp.type) {
|
|
3956
|
+
case "Identifier":
|
|
3957
|
+
case "Literal":
|
|
3958
|
+
c.splice(1, 0, "!");
|
|
3959
|
+
break;
|
|
3960
|
+
default:
|
|
3961
|
+
c.splice(1, 1, "!(", exp, ")");
|
|
3962
|
+
}
|
|
3963
|
+
});
|
|
3964
|
+
}
|
|
3965
|
+
});
|
|
3966
|
+
}
|
|
3967
|
+
return {
|
|
3968
|
+
type: "SwitchStatement",
|
|
3969
|
+
children: $0
|
|
3970
|
+
};
|
|
3882
3971
|
});
|
|
3883
3972
|
function SwitchStatement(state) {
|
|
3884
3973
|
if (state.verbose)
|
|
@@ -3889,11 +3978,29 @@ var Civet = (() => {
|
|
|
3889
3978
|
return SwitchStatement$0(state);
|
|
3890
3979
|
}
|
|
3891
3980
|
}
|
|
3981
|
+
var EmptyCondition$0 = $TV($Y(EOS), function($skip, $loc, $0, $1) {
|
|
3982
|
+
return {
|
|
3983
|
+
type: "EmptyCondition",
|
|
3984
|
+
children: [{
|
|
3985
|
+
$loc,
|
|
3986
|
+
token: " (false)"
|
|
3987
|
+
}]
|
|
3988
|
+
};
|
|
3989
|
+
});
|
|
3990
|
+
function EmptyCondition(state) {
|
|
3991
|
+
if (state.verbose)
|
|
3992
|
+
console.log("ENTER:", "EmptyCondition");
|
|
3993
|
+
if (state.tokenize) {
|
|
3994
|
+
return $TOKEN("EmptyCondition", state, EmptyCondition$0(state));
|
|
3995
|
+
} else {
|
|
3996
|
+
return EmptyCondition$0(state);
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3892
3999
|
var SwitchExpression$0 = $TV(SwitchStatement, function($skip, $loc, $0, $1) {
|
|
3893
4000
|
var e = $0;
|
|
3894
4001
|
module.addImplicitReturns(e.children[2]);
|
|
3895
4002
|
e.type = "SwitchExpression";
|
|
3896
|
-
e.children = ["(
|
|
4003
|
+
e.children = ["(()=>{", e.children, "})()"];
|
|
3897
4004
|
return e;
|
|
3898
4005
|
});
|
|
3899
4006
|
function SwitchExpression(state) {
|
|
@@ -3959,18 +4066,20 @@ var Civet = (() => {
|
|
|
3959
4066
|
}
|
|
3960
4067
|
}
|
|
3961
4068
|
var CaseClause$0 = $T($S(Case, CaseExpressionList, $C(NestedBlockStatements, NoExpressions)), function(value) {
|
|
3962
|
-
var
|
|
3963
|
-
|
|
4069
|
+
var cases = value[1];
|
|
4070
|
+
var expressions = value[2];
|
|
4071
|
+
return { "type": "CaseClause", "cases": cases, "expressions": expressions, "children": value };
|
|
3964
4072
|
});
|
|
3965
|
-
var CaseClause$1 = $T($S(When, CaseExpressionList, NestedBlockStatements, InsertBreak), function(value) {
|
|
3966
|
-
var
|
|
3967
|
-
|
|
4073
|
+
var CaseClause$1 = $T($S(When, CaseExpressionList, $C(ThenClause, NestedBlockStatements), InsertBreak), function(value) {
|
|
4074
|
+
var cases = value[1];
|
|
4075
|
+
var expressions = value[2];
|
|
4076
|
+
return { "type": "WhenClause", "cases": cases, "expressions": expressions, "children": value };
|
|
3968
4077
|
});
|
|
3969
4078
|
var CaseClause$2 = $T($S(Default, ImpliedColon, $C(NestedBlockStatements, NoExpressions)), function(value) {
|
|
3970
4079
|
var exps = value[2];
|
|
3971
4080
|
return { "type": "DefaultClause", "expressions": exps, "children": value };
|
|
3972
4081
|
});
|
|
3973
|
-
var CaseClause$3 = $TS($S(Else, ImpliedColon, NestedBlockStatements), function($skip, $loc, $0, $1, $2, $3) {
|
|
4082
|
+
var CaseClause$3 = $TS($S(Else, ImpliedColon, $C(NestedBlockStatements, $S($Q(TrailingComment), Statement))), function($skip, $loc, $0, $1, $2, $3) {
|
|
3974
4083
|
var exps = $3;
|
|
3975
4084
|
$1.token = "default";
|
|
3976
4085
|
return {
|
|
@@ -4174,7 +4283,7 @@ var Civet = (() => {
|
|
|
4174
4283
|
var DebuggerExpression$0 = $TS($S($EXPECT($L80, fail, 'DebuggerExpression "debugger"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
|
|
4175
4284
|
return {
|
|
4176
4285
|
type: "DebuggerExpression",
|
|
4177
|
-
children: ["(
|
|
4286
|
+
children: ["(()=>{", $1, "})()"]
|
|
4178
4287
|
};
|
|
4179
4288
|
});
|
|
4180
4289
|
function DebuggerExpression(state) {
|
|
@@ -4189,7 +4298,7 @@ var Civet = (() => {
|
|
|
4189
4298
|
var ThrowExpression$0 = $TS($S(Throw, ExtendedExpression), function($skip, $loc, $0, $1, $2) {
|
|
4190
4299
|
return {
|
|
4191
4300
|
type: "ThrowExpression",
|
|
4192
|
-
children: ["(
|
|
4301
|
+
children: ["(()=>{", $0, "})()"]
|
|
4193
4302
|
};
|
|
4194
4303
|
});
|
|
4195
4304
|
function ThrowExpression(state) {
|
|
@@ -7003,6 +7112,110 @@ var Civet = (() => {
|
|
|
7003
7112
|
Object.assign(module.config, directive.config);
|
|
7004
7113
|
}
|
|
7005
7114
|
});
|
|
7115
|
+
module.expressionizeIteration = function(statement) {
|
|
7116
|
+
const resultsRef = {
|
|
7117
|
+
type: "Ref",
|
|
7118
|
+
base: "results"
|
|
7119
|
+
};
|
|
7120
|
+
insertPush(statement.block, resultsRef);
|
|
7121
|
+
return {
|
|
7122
|
+
type: "IterationExpression",
|
|
7123
|
+
children: ["((", resultsRef, ")=>{", statement, "; return ", resultsRef, "})([])"]
|
|
7124
|
+
};
|
|
7125
|
+
};
|
|
7126
|
+
function wrapIterationReturningResults(statement, outerRef) {
|
|
7127
|
+
const resultsRef = {
|
|
7128
|
+
type: "Ref",
|
|
7129
|
+
base: "results"
|
|
7130
|
+
};
|
|
7131
|
+
const declaration = {
|
|
7132
|
+
type: "Declaration",
|
|
7133
|
+
children: ["const ", resultsRef, "=[];"]
|
|
7134
|
+
};
|
|
7135
|
+
insertPush(statement.block, resultsRef);
|
|
7136
|
+
statement.children.unshift(declaration);
|
|
7137
|
+
if (outerRef) {
|
|
7138
|
+
statement.children.push(";", outerRef, ".push(", resultsRef, ");");
|
|
7139
|
+
} else {
|
|
7140
|
+
statement.children.push(";return ", resultsRef, ";");
|
|
7141
|
+
}
|
|
7142
|
+
}
|
|
7143
|
+
function insertPush(node, ref) {
|
|
7144
|
+
if (!node)
|
|
7145
|
+
return;
|
|
7146
|
+
switch (node.type) {
|
|
7147
|
+
case "AssignmentExpression":
|
|
7148
|
+
node.children.unshift(ref, ".push(");
|
|
7149
|
+
node.children.push(")");
|
|
7150
|
+
return;
|
|
7151
|
+
case "Identifier":
|
|
7152
|
+
node.children.unshift(ref, ".push(");
|
|
7153
|
+
node.children.push(")");
|
|
7154
|
+
return;
|
|
7155
|
+
case "BlockStatement":
|
|
7156
|
+
insertPush(node.expressions[node.expressions.length - 1], ref);
|
|
7157
|
+
return;
|
|
7158
|
+
case "ObjectExpression":
|
|
7159
|
+
module.insertTrimmingSpace(node.children[0], "");
|
|
7160
|
+
node.children.unshift(ref, ".push(");
|
|
7161
|
+
node.children.push(")");
|
|
7162
|
+
return;
|
|
7163
|
+
case "CaseBlock":
|
|
7164
|
+
node.clauses.forEach((clause) => {
|
|
7165
|
+
insertPush(clause, ref);
|
|
7166
|
+
});
|
|
7167
|
+
return;
|
|
7168
|
+
case "CaseClause":
|
|
7169
|
+
return;
|
|
7170
|
+
case "WhenClause":
|
|
7171
|
+
insertPush(node.expressions[node.expressions.length - 1], ref);
|
|
7172
|
+
return;
|
|
7173
|
+
case "DefaultClause":
|
|
7174
|
+
insertPush(node.expressions[node.expressions.length - 1], ref);
|
|
7175
|
+
return;
|
|
7176
|
+
}
|
|
7177
|
+
if (!Array.isArray(node))
|
|
7178
|
+
return;
|
|
7179
|
+
const [, exp] = node;
|
|
7180
|
+
if (!exp)
|
|
7181
|
+
return;
|
|
7182
|
+
let indent = node[0];
|
|
7183
|
+
if (Array.isArray(indent))
|
|
7184
|
+
indent = indent[indent.length - 1];
|
|
7185
|
+
switch (exp.type) {
|
|
7186
|
+
case "BreakStatement":
|
|
7187
|
+
case "ContinueStatement":
|
|
7188
|
+
case "DebuggerStatement":
|
|
7189
|
+
case "EmptyStatement":
|
|
7190
|
+
case "ReturnStatement":
|
|
7191
|
+
case "ThrowStatement":
|
|
7192
|
+
case "Declaration":
|
|
7193
|
+
return;
|
|
7194
|
+
case "ForStatement":
|
|
7195
|
+
case "IterationStatement":
|
|
7196
|
+
wrapIterationReturningResults(exp, ref);
|
|
7197
|
+
return;
|
|
7198
|
+
case "BlockStatement":
|
|
7199
|
+
insertPush(exp.expressions[exp.expressions.length - 1], ref);
|
|
7200
|
+
return;
|
|
7201
|
+
case "IfStatement":
|
|
7202
|
+
insertPush(exp.children[2], ref);
|
|
7203
|
+
if (exp.children[3])
|
|
7204
|
+
insertPush(exp.children[3][2], ref);
|
|
7205
|
+
else
|
|
7206
|
+
exp.children.push([" else {\n", indent, ref, ".push(undefined)\n", indent, "}"]);
|
|
7207
|
+
return;
|
|
7208
|
+
case "SwitchStatement":
|
|
7209
|
+
insertPush(exp.children[2], ref);
|
|
7210
|
+
return;
|
|
7211
|
+
case "TryStatement":
|
|
7212
|
+
insertPush(exp.children[1], ref);
|
|
7213
|
+
insertPush(exp.children[2][3], ref);
|
|
7214
|
+
return;
|
|
7215
|
+
}
|
|
7216
|
+
node.splice(1, 0, ref, ".push(");
|
|
7217
|
+
node.push(")");
|
|
7218
|
+
}
|
|
7006
7219
|
function insertReturn(node) {
|
|
7007
7220
|
if (!node)
|
|
7008
7221
|
return;
|
|
@@ -7048,12 +7261,14 @@ var Civet = (() => {
|
|
|
7048
7261
|
case "ContinueStatement":
|
|
7049
7262
|
case "DebuggerStatement":
|
|
7050
7263
|
case "EmptyStatement":
|
|
7051
|
-
case "ForStatement":
|
|
7052
|
-
case "IterationStatement":
|
|
7053
7264
|
case "ReturnStatement":
|
|
7054
7265
|
case "ThrowStatement":
|
|
7055
7266
|
case "Declaration":
|
|
7056
7267
|
return;
|
|
7268
|
+
case "ForStatement":
|
|
7269
|
+
case "IterationStatement":
|
|
7270
|
+
wrapIterationReturningResults(exp);
|
|
7271
|
+
return;
|
|
7057
7272
|
case "BlockStatement":
|
|
7058
7273
|
insertReturn(exp.expressions[exp.expressions.length - 1]);
|
|
7059
7274
|
return;
|
package/dist/esm.mjs
CHANGED
package/dist/main.js
CHANGED
|
@@ -489,6 +489,7 @@ var require_parser = __commonJS({
|
|
|
489
489
|
ThinArrowFunction,
|
|
490
490
|
Arrow,
|
|
491
491
|
Block,
|
|
492
|
+
ThenClause,
|
|
492
493
|
BracedOrEmptyBlock,
|
|
493
494
|
EmptyBlock,
|
|
494
495
|
BracedBlock,
|
|
@@ -542,6 +543,7 @@ var require_parser = __commonJS({
|
|
|
542
543
|
EmptyStatement,
|
|
543
544
|
BlockStatement,
|
|
544
545
|
IfStatement,
|
|
546
|
+
ElseClause,
|
|
545
547
|
IfClause,
|
|
546
548
|
UnlessClause,
|
|
547
549
|
IfExpression,
|
|
@@ -549,6 +551,7 @@ var require_parser = __commonJS({
|
|
|
549
551
|
NestedBlockExpressions,
|
|
550
552
|
NestedBlockExpression,
|
|
551
553
|
IterationStatement,
|
|
554
|
+
IterationExpression,
|
|
552
555
|
LoopStatement,
|
|
553
556
|
LoopClause,
|
|
554
557
|
DoWhileStatement,
|
|
@@ -559,12 +562,14 @@ var require_parser = __commonJS({
|
|
|
559
562
|
ForStatementControl,
|
|
560
563
|
WhenCondition,
|
|
561
564
|
CoffeeForStatementParameters,
|
|
565
|
+
CoffeeForIndex,
|
|
562
566
|
CoffeeForDeclaration,
|
|
563
567
|
ForStatementParameters,
|
|
564
568
|
ForInOfDeclaration,
|
|
565
569
|
ForDeclaration,
|
|
566
570
|
ForBinding,
|
|
567
571
|
SwitchStatement,
|
|
572
|
+
EmptyCondition,
|
|
568
573
|
SwitchExpression,
|
|
569
574
|
CaseBlock,
|
|
570
575
|
NestedCaseClauses,
|
|
@@ -970,7 +975,7 @@ var require_parser = __commonJS({
|
|
|
970
975
|
var $L153 = $L("civet");
|
|
971
976
|
var $L154 = $L(" ");
|
|
972
977
|
var $L155 = $L(" ");
|
|
973
|
-
var $R0 = $R(new RegExp("(of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])", "suy"));
|
|
978
|
+
var $R0 = $R(new RegExp("(for|of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])", "suy"));
|
|
974
979
|
var $R1 = $R(new RegExp("[&]", "suy"));
|
|
975
980
|
var $R2 = $R(new RegExp("[!~+-]+", "suy"));
|
|
976
981
|
var $R3 = $R(new RegExp("(?:\\p{ID_Start}|[_$])(?:\\p{ID_Continue}|[\\u200C\\u200D$])*", "suy"));
|
|
@@ -1058,13 +1063,14 @@ var require_parser = __commonJS({
|
|
|
1058
1063
|
}
|
|
1059
1064
|
var ExpressionizedStatement$0 = DebuggerExpression;
|
|
1060
1065
|
var ExpressionizedStatement$1 = IfExpression;
|
|
1061
|
-
var ExpressionizedStatement$2 =
|
|
1062
|
-
var ExpressionizedStatement$3 =
|
|
1066
|
+
var ExpressionizedStatement$2 = IterationExpression;
|
|
1067
|
+
var ExpressionizedStatement$3 = SwitchExpression;
|
|
1068
|
+
var ExpressionizedStatement$4 = ThrowExpression;
|
|
1063
1069
|
function ExpressionizedStatement(state) {
|
|
1064
1070
|
if (state.tokenize) {
|
|
1065
|
-
return $TOKEN("ExpressionizedStatement", state, ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state));
|
|
1071
|
+
return $TOKEN("ExpressionizedStatement", state, ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state) || ExpressionizedStatement$4(state));
|
|
1066
1072
|
} else {
|
|
1067
|
-
return ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state);
|
|
1073
|
+
return ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state) || ExpressionizedStatement$4(state);
|
|
1068
1074
|
}
|
|
1069
1075
|
}
|
|
1070
1076
|
var Expression$0 = $TS($S(AssignmentExpression, $Q($S(__, Comma, AssignmentExpression))), function($skip, $loc, $0, $1, $2) {
|
|
@@ -1771,7 +1777,7 @@ var require_parser = __commonJS({
|
|
|
1771
1777
|
return NonNullAssertion$0(state);
|
|
1772
1778
|
}
|
|
1773
1779
|
}
|
|
1774
|
-
var AdditionalReservedWords$0 = $R$0($EXPECT($R0, fail, "AdditionalReservedWords /(of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])/"));
|
|
1780
|
+
var AdditionalReservedWords$0 = $R$0($EXPECT($R0, fail, "AdditionalReservedWords /(for|of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])/"));
|
|
1775
1781
|
function AdditionalReservedWords(state) {
|
|
1776
1782
|
if (state.verbose)
|
|
1777
1783
|
console.log("ENTER:", "AdditionalReservedWords");
|
|
@@ -2384,12 +2390,8 @@ var require_parser = __commonJS({
|
|
|
2384
2390
|
var exps = value[2];
|
|
2385
2391
|
return { "type": "BlockStatement", "expressions": exps, "children": value };
|
|
2386
2392
|
});
|
|
2387
|
-
var Block$2 =
|
|
2388
|
-
|
|
2389
|
-
});
|
|
2390
|
-
var Block$3 = $T($S($E(Then), __, Statement), function(value) {
|
|
2391
|
-
return [value[1], value[2]];
|
|
2392
|
-
});
|
|
2393
|
+
var Block$2 = ThenClause;
|
|
2394
|
+
var Block$3 = $S($Q(TrailingComment), Statement);
|
|
2393
2395
|
function Block(state) {
|
|
2394
2396
|
if (state.tokenize) {
|
|
2395
2397
|
return $TOKEN("Block", state, Block$0(state) || Block$1(state) || Block$2(state) || Block$3(state));
|
|
@@ -2397,6 +2399,18 @@ var require_parser = __commonJS({
|
|
|
2397
2399
|
return Block$0(state) || Block$1(state) || Block$2(state) || Block$3(state);
|
|
2398
2400
|
}
|
|
2399
2401
|
}
|
|
2402
|
+
var ThenClause$0 = $T($S(Then, $Q(TrailingComment), Statement), function(value) {
|
|
2403
|
+
return [value[1], value[2]];
|
|
2404
|
+
});
|
|
2405
|
+
function ThenClause(state) {
|
|
2406
|
+
if (state.verbose)
|
|
2407
|
+
console.log("ENTER:", "ThenClause");
|
|
2408
|
+
if (state.tokenize) {
|
|
2409
|
+
return $TOKEN("ThenClause", state, ThenClause$0(state));
|
|
2410
|
+
} else {
|
|
2411
|
+
return ThenClause$0(state);
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2400
2414
|
var BracedOrEmptyBlock$0 = BracedBlock;
|
|
2401
2415
|
var BracedOrEmptyBlock$1 = EmptyBlock;
|
|
2402
2416
|
function BracedOrEmptyBlock(state) {
|
|
@@ -3272,16 +3286,20 @@ var require_parser = __commonJS({
|
|
|
3272
3286
|
var ws = $2;
|
|
3273
3287
|
var post = $3;
|
|
3274
3288
|
if (post) {
|
|
3275
|
-
let
|
|
3276
|
-
if (post.
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
block = statement;
|
|
3281
|
-
}
|
|
3289
|
+
let children, expressions;
|
|
3290
|
+
if (post.blockPrefix?.length) {
|
|
3291
|
+
let indent = post.blockPrefix[0][0];
|
|
3292
|
+
expressions = [...post.blockPrefix, [indent, statement]];
|
|
3293
|
+
children = [" {\n", ...expressions, "\n", indent?.slice?.(0, -2), "}"];
|
|
3282
3294
|
} else {
|
|
3283
|
-
|
|
3295
|
+
expressions = [["", statement]];
|
|
3296
|
+
children = [" { ", ...expressions, " }"];
|
|
3284
3297
|
}
|
|
3298
|
+
const block = {
|
|
3299
|
+
type: "BlockStatement",
|
|
3300
|
+
children,
|
|
3301
|
+
expressions
|
|
3302
|
+
};
|
|
3285
3303
|
post.block = block;
|
|
3286
3304
|
post.children.push(block);
|
|
3287
3305
|
if (!module2.isWhitespaceOrEmpty(ws))
|
|
@@ -3350,7 +3368,7 @@ var require_parser = __commonJS({
|
|
|
3350
3368
|
return BlockStatement$0(state);
|
|
3351
3369
|
}
|
|
3352
3370
|
}
|
|
3353
|
-
var IfStatement$0 = $TS($S($C(IfClause, UnlessClause), Block, $E(
|
|
3371
|
+
var IfStatement$0 = $TS($S($C(IfClause, UnlessClause), Block, $E(ElseClause)), function($skip, $loc, $0, $1, $2, $3) {
|
|
3354
3372
|
var clause = $1;
|
|
3355
3373
|
var block = $2;
|
|
3356
3374
|
var e = $3;
|
|
@@ -3368,6 +3386,17 @@ var require_parser = __commonJS({
|
|
|
3368
3386
|
return IfStatement$0(state);
|
|
3369
3387
|
}
|
|
3370
3388
|
}
|
|
3389
|
+
var ElseClause$0 = $T($S($Y(EOS), Samedent, Else, Block), function(value) {
|
|
3390
|
+
return [value[1], value[2], value[3]];
|
|
3391
|
+
});
|
|
3392
|
+
var ElseClause$1 = $S($Q(TrailingComment), Else, Block);
|
|
3393
|
+
function ElseClause(state) {
|
|
3394
|
+
if (state.tokenize) {
|
|
3395
|
+
return $TOKEN("ElseClause", state, ElseClause$0(state) || ElseClause$1(state));
|
|
3396
|
+
} else {
|
|
3397
|
+
return ElseClause$0(state) || ElseClause$1(state);
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3371
3400
|
var IfClause$0 = $T($S(If, Condition), function(value) {
|
|
3372
3401
|
return { "type": "IfStatement", "children": value };
|
|
3373
3402
|
});
|
|
@@ -3479,9 +3508,22 @@ var require_parser = __commonJS({
|
|
|
3479
3508
|
return IterationStatement$0(state) || IterationStatement$1(state) || IterationStatement$2(state) || IterationStatement$3(state);
|
|
3480
3509
|
}
|
|
3481
3510
|
}
|
|
3511
|
+
var IterationExpression$0 = $TS($S(IterationStatement), function($skip, $loc, $0, $1) {
|
|
3512
|
+
return module2.expressionizeIteration($1);
|
|
3513
|
+
});
|
|
3514
|
+
function IterationExpression(state) {
|
|
3515
|
+
if (state.verbose)
|
|
3516
|
+
console.log("ENTER:", "IterationExpression");
|
|
3517
|
+
if (state.tokenize) {
|
|
3518
|
+
return $TOKEN("IterationExpression", state, IterationExpression$0(state));
|
|
3519
|
+
} else {
|
|
3520
|
+
return IterationExpression$0(state);
|
|
3521
|
+
}
|
|
3522
|
+
}
|
|
3482
3523
|
var LoopStatement$0 = $TS($S(LoopClause, Block), function($skip, $loc, $0, $1, $2) {
|
|
3483
3524
|
var clause = $1;
|
|
3484
3525
|
var block = $2;
|
|
3526
|
+
clause.block = block;
|
|
3485
3527
|
clause.children.push(block);
|
|
3486
3528
|
return clause;
|
|
3487
3529
|
});
|
|
@@ -3495,7 +3537,7 @@ var require_parser = __commonJS({
|
|
|
3495
3537
|
}
|
|
3496
3538
|
}
|
|
3497
3539
|
var LoopClause$0 = $T($S(Loop), function(value) {
|
|
3498
|
-
return { "type": "IterationStatement", "children": value };
|
|
3540
|
+
return { "type": "IterationStatement", "children": [value[0]], "block": null };
|
|
3499
3541
|
});
|
|
3500
3542
|
function LoopClause(state) {
|
|
3501
3543
|
if (state.verbose)
|
|
@@ -3507,7 +3549,8 @@ var require_parser = __commonJS({
|
|
|
3507
3549
|
}
|
|
3508
3550
|
}
|
|
3509
3551
|
var DoWhileStatement$0 = $T($S(Do, BracedBlock, __, WhileClause), function(value) {
|
|
3510
|
-
|
|
3552
|
+
var block = value[1];
|
|
3553
|
+
return { "type": "IterationStatement", "children": value, "block": block };
|
|
3511
3554
|
});
|
|
3512
3555
|
function DoWhileStatement(state) {
|
|
3513
3556
|
if (state.verbose)
|
|
@@ -3521,6 +3564,7 @@ var require_parser = __commonJS({
|
|
|
3521
3564
|
var WhileStatement$0 = $TS($S(WhileClause, Block), function($skip, $loc, $0, $1, $2) {
|
|
3522
3565
|
var clause = $1;
|
|
3523
3566
|
var block = $2;
|
|
3567
|
+
clause.block = block;
|
|
3524
3568
|
clause.children.push(block);
|
|
3525
3569
|
return clause;
|
|
3526
3570
|
});
|
|
@@ -3544,7 +3588,8 @@ var require_parser = __commonJS({
|
|
|
3544
3588
|
}
|
|
3545
3589
|
return {
|
|
3546
3590
|
type: "IterationStatement",
|
|
3547
|
-
children: $0
|
|
3591
|
+
children: $0,
|
|
3592
|
+
block: null
|
|
3548
3593
|
};
|
|
3549
3594
|
});
|
|
3550
3595
|
function WhileClause(state) {
|
|
@@ -3630,13 +3675,14 @@ var require_parser = __commonJS({
|
|
|
3630
3675
|
return WhenCondition$0(state);
|
|
3631
3676
|
}
|
|
3632
3677
|
}
|
|
3633
|
-
var CoffeeForStatementParameters$0 = $TS($S($E($S(Await, __)), InsertOpenParen, CoffeeForDeclaration, __, $C(In, Of, From), ExtendedExpression, $E($S(__, By, ExtendedExpression)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8) {
|
|
3678
|
+
var CoffeeForStatementParameters$0 = $TS($S($E($S(Await, __)), InsertOpenParen, CoffeeForDeclaration, $E(CoffeeForIndex), __, $C(In, Of, From), ExtendedExpression, $E($S(__, By, ExtendedExpression)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
|
|
3634
3679
|
var open = $2;
|
|
3635
3680
|
var declaration = $3;
|
|
3636
|
-
var
|
|
3637
|
-
var
|
|
3638
|
-
var
|
|
3639
|
-
var
|
|
3681
|
+
var index = $4;
|
|
3682
|
+
var kind = $6;
|
|
3683
|
+
var exp = $7;
|
|
3684
|
+
var step = $8;
|
|
3685
|
+
var close = $9;
|
|
3640
3686
|
let blockPrefix = [];
|
|
3641
3687
|
const indent = "".padStart((module2.currentIndent + 1) * 2);
|
|
3642
3688
|
if (kind.token === "from") {
|
|
@@ -3746,10 +3792,17 @@ var require_parser = __commonJS({
|
|
|
3746
3792
|
children: ["let ", ...expRefDec, counterRef, " = 0, ", lenRef, " = ", expRef, ".length"],
|
|
3747
3793
|
names: []
|
|
3748
3794
|
};
|
|
3795
|
+
let indexAssignment;
|
|
3796
|
+
let assignmentNames = [...varRef.names];
|
|
3797
|
+
if (index) {
|
|
3798
|
+
module2.insertTrimmingSpace(index, "");
|
|
3799
|
+
indexAssignment = [index, "="];
|
|
3800
|
+
assignmentNames.push(...index.names);
|
|
3801
|
+
}
|
|
3749
3802
|
blockPrefix.push([{
|
|
3750
3803
|
type: "AssignmentExpression",
|
|
3751
|
-
children: [indent, varRef, " = ", expRef, "[", counterRef, "]\n"],
|
|
3752
|
-
names:
|
|
3804
|
+
children: [indent, varRef, " = ", expRef, "[", indexAssignment, counterRef, "]\n"],
|
|
3805
|
+
names: assignmentNames
|
|
3753
3806
|
}]);
|
|
3754
3807
|
return {
|
|
3755
3808
|
declaration,
|
|
@@ -3772,6 +3825,20 @@ var require_parser = __commonJS({
|
|
|
3772
3825
|
return CoffeeForStatementParameters$0(state);
|
|
3773
3826
|
}
|
|
3774
3827
|
}
|
|
3828
|
+
var CoffeeForIndex$0 = $TS($S($Q(TrailingComment), Comma, $Q(TrailingComment), BindingIdentifier), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
3829
|
+
var id = $4;
|
|
3830
|
+
id.children.unshift(...$1, ...$3);
|
|
3831
|
+
return id;
|
|
3832
|
+
});
|
|
3833
|
+
function CoffeeForIndex(state) {
|
|
3834
|
+
if (state.verbose)
|
|
3835
|
+
console.log("ENTER:", "CoffeeForIndex");
|
|
3836
|
+
if (state.tokenize) {
|
|
3837
|
+
return $TOKEN("CoffeeForIndex", state, CoffeeForIndex$0(state));
|
|
3838
|
+
} else {
|
|
3839
|
+
return CoffeeForIndex$0(state);
|
|
3840
|
+
}
|
|
3841
|
+
}
|
|
3775
3842
|
var CoffeeForDeclaration$0 = $TS($S($E($S(__, $EXPECT($L76, fail, 'CoffeeForDeclaration "own"'))), ForBinding), function($skip, $loc, $0, $1, $2) {
|
|
3776
3843
|
var own = $1;
|
|
3777
3844
|
var binding = $2;
|
|
@@ -3804,14 +3871,14 @@ var require_parser = __commonJS({
|
|
|
3804
3871
|
children: $0
|
|
3805
3872
|
};
|
|
3806
3873
|
});
|
|
3807
|
-
var ForStatementParameters$2 = $TS($S($E($S(Await, __)), OpenParen, __, ForInOfDeclaration, __, $C(In, Of),
|
|
3874
|
+
var ForStatementParameters$2 = $TS($S($E($S(Await, __)), OpenParen, __, ForInOfDeclaration, __, $C(In, Of), ExpressionWithIndentedApplicationSuppressed, __, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
|
|
3808
3875
|
var declaration = $4;
|
|
3809
3876
|
return {
|
|
3810
3877
|
declaration,
|
|
3811
3878
|
children: $0
|
|
3812
3879
|
};
|
|
3813
3880
|
});
|
|
3814
|
-
var ForStatementParameters$3 = $TS($S($E($S(Await, __)), InsertOpenParen, ForInOfDeclaration, __, $C(In, Of),
|
|
3881
|
+
var ForStatementParameters$3 = $TS($S($E($S(Await, __)), InsertOpenParen, ForInOfDeclaration, __, $C(In, Of), ExpressionWithIndentedApplicationSuppressed, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
|
|
3815
3882
|
var declaration = $3;
|
|
3816
3883
|
return {
|
|
3817
3884
|
declaration,
|
|
@@ -3876,8 +3943,30 @@ var require_parser = __commonJS({
|
|
|
3876
3943
|
return ForBinding$0(state) || ForBinding$1(state);
|
|
3877
3944
|
}
|
|
3878
3945
|
}
|
|
3879
|
-
var SwitchStatement$0 = $
|
|
3880
|
-
|
|
3946
|
+
var SwitchStatement$0 = $TS($S(Switch, $C(EmptyCondition, Condition), CaseBlock), function($skip, $loc, $0, $1, $2, $3) {
|
|
3947
|
+
var condition = $2;
|
|
3948
|
+
var caseBlock = $3;
|
|
3949
|
+
if (condition.type === "EmptyCondition") {
|
|
3950
|
+
caseBlock.clauses.forEach(({ cases }) => {
|
|
3951
|
+
if (cases) {
|
|
3952
|
+
cases.forEach((c) => {
|
|
3953
|
+
const exp = c[1];
|
|
3954
|
+
switch (exp.type) {
|
|
3955
|
+
case "Identifier":
|
|
3956
|
+
case "Literal":
|
|
3957
|
+
c.splice(1, 0, "!");
|
|
3958
|
+
break;
|
|
3959
|
+
default:
|
|
3960
|
+
c.splice(1, 1, "!(", exp, ")");
|
|
3961
|
+
}
|
|
3962
|
+
});
|
|
3963
|
+
}
|
|
3964
|
+
});
|
|
3965
|
+
}
|
|
3966
|
+
return {
|
|
3967
|
+
type: "SwitchStatement",
|
|
3968
|
+
children: $0
|
|
3969
|
+
};
|
|
3881
3970
|
});
|
|
3882
3971
|
function SwitchStatement(state) {
|
|
3883
3972
|
if (state.verbose)
|
|
@@ -3888,11 +3977,29 @@ var require_parser = __commonJS({
|
|
|
3888
3977
|
return SwitchStatement$0(state);
|
|
3889
3978
|
}
|
|
3890
3979
|
}
|
|
3980
|
+
var EmptyCondition$0 = $TV($Y(EOS), function($skip, $loc, $0, $1) {
|
|
3981
|
+
return {
|
|
3982
|
+
type: "EmptyCondition",
|
|
3983
|
+
children: [{
|
|
3984
|
+
$loc,
|
|
3985
|
+
token: " (false)"
|
|
3986
|
+
}]
|
|
3987
|
+
};
|
|
3988
|
+
});
|
|
3989
|
+
function EmptyCondition(state) {
|
|
3990
|
+
if (state.verbose)
|
|
3991
|
+
console.log("ENTER:", "EmptyCondition");
|
|
3992
|
+
if (state.tokenize) {
|
|
3993
|
+
return $TOKEN("EmptyCondition", state, EmptyCondition$0(state));
|
|
3994
|
+
} else {
|
|
3995
|
+
return EmptyCondition$0(state);
|
|
3996
|
+
}
|
|
3997
|
+
}
|
|
3891
3998
|
var SwitchExpression$0 = $TV(SwitchStatement, function($skip, $loc, $0, $1) {
|
|
3892
3999
|
var e = $0;
|
|
3893
4000
|
module2.addImplicitReturns(e.children[2]);
|
|
3894
4001
|
e.type = "SwitchExpression";
|
|
3895
|
-
e.children = ["(
|
|
4002
|
+
e.children = ["(()=>{", e.children, "})()"];
|
|
3896
4003
|
return e;
|
|
3897
4004
|
});
|
|
3898
4005
|
function SwitchExpression(state) {
|
|
@@ -3958,18 +4065,20 @@ var require_parser = __commonJS({
|
|
|
3958
4065
|
}
|
|
3959
4066
|
}
|
|
3960
4067
|
var CaseClause$0 = $T($S(Case, CaseExpressionList, $C(NestedBlockStatements, NoExpressions)), function(value) {
|
|
3961
|
-
var
|
|
3962
|
-
|
|
4068
|
+
var cases = value[1];
|
|
4069
|
+
var expressions = value[2];
|
|
4070
|
+
return { "type": "CaseClause", "cases": cases, "expressions": expressions, "children": value };
|
|
3963
4071
|
});
|
|
3964
|
-
var CaseClause$1 = $T($S(When, CaseExpressionList, NestedBlockStatements, InsertBreak), function(value) {
|
|
3965
|
-
var
|
|
3966
|
-
|
|
4072
|
+
var CaseClause$1 = $T($S(When, CaseExpressionList, $C(ThenClause, NestedBlockStatements), InsertBreak), function(value) {
|
|
4073
|
+
var cases = value[1];
|
|
4074
|
+
var expressions = value[2];
|
|
4075
|
+
return { "type": "WhenClause", "cases": cases, "expressions": expressions, "children": value };
|
|
3967
4076
|
});
|
|
3968
4077
|
var CaseClause$2 = $T($S(Default, ImpliedColon, $C(NestedBlockStatements, NoExpressions)), function(value) {
|
|
3969
4078
|
var exps = value[2];
|
|
3970
4079
|
return { "type": "DefaultClause", "expressions": exps, "children": value };
|
|
3971
4080
|
});
|
|
3972
|
-
var CaseClause$3 = $TS($S(Else, ImpliedColon, NestedBlockStatements), function($skip, $loc, $0, $1, $2, $3) {
|
|
4081
|
+
var CaseClause$3 = $TS($S(Else, ImpliedColon, $C(NestedBlockStatements, $S($Q(TrailingComment), Statement))), function($skip, $loc, $0, $1, $2, $3) {
|
|
3973
4082
|
var exps = $3;
|
|
3974
4083
|
$1.token = "default";
|
|
3975
4084
|
return {
|
|
@@ -4173,7 +4282,7 @@ var require_parser = __commonJS({
|
|
|
4173
4282
|
var DebuggerExpression$0 = $TS($S($EXPECT($L80, fail, 'DebuggerExpression "debugger"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
|
|
4174
4283
|
return {
|
|
4175
4284
|
type: "DebuggerExpression",
|
|
4176
|
-
children: ["(
|
|
4285
|
+
children: ["(()=>{", $1, "})()"]
|
|
4177
4286
|
};
|
|
4178
4287
|
});
|
|
4179
4288
|
function DebuggerExpression(state) {
|
|
@@ -4188,7 +4297,7 @@ var require_parser = __commonJS({
|
|
|
4188
4297
|
var ThrowExpression$0 = $TS($S(Throw, ExtendedExpression), function($skip, $loc, $0, $1, $2) {
|
|
4189
4298
|
return {
|
|
4190
4299
|
type: "ThrowExpression",
|
|
4191
|
-
children: ["(
|
|
4300
|
+
children: ["(()=>{", $0, "})()"]
|
|
4192
4301
|
};
|
|
4193
4302
|
});
|
|
4194
4303
|
function ThrowExpression(state) {
|
|
@@ -7002,6 +7111,110 @@ var require_parser = __commonJS({
|
|
|
7002
7111
|
Object.assign(module2.config, directive.config);
|
|
7003
7112
|
}
|
|
7004
7113
|
});
|
|
7114
|
+
module2.expressionizeIteration = function(statement) {
|
|
7115
|
+
const resultsRef = {
|
|
7116
|
+
type: "Ref",
|
|
7117
|
+
base: "results"
|
|
7118
|
+
};
|
|
7119
|
+
insertPush(statement.block, resultsRef);
|
|
7120
|
+
return {
|
|
7121
|
+
type: "IterationExpression",
|
|
7122
|
+
children: ["((", resultsRef, ")=>{", statement, "; return ", resultsRef, "})([])"]
|
|
7123
|
+
};
|
|
7124
|
+
};
|
|
7125
|
+
function wrapIterationReturningResults(statement, outerRef) {
|
|
7126
|
+
const resultsRef = {
|
|
7127
|
+
type: "Ref",
|
|
7128
|
+
base: "results"
|
|
7129
|
+
};
|
|
7130
|
+
const declaration = {
|
|
7131
|
+
type: "Declaration",
|
|
7132
|
+
children: ["const ", resultsRef, "=[];"]
|
|
7133
|
+
};
|
|
7134
|
+
insertPush(statement.block, resultsRef);
|
|
7135
|
+
statement.children.unshift(declaration);
|
|
7136
|
+
if (outerRef) {
|
|
7137
|
+
statement.children.push(";", outerRef, ".push(", resultsRef, ");");
|
|
7138
|
+
} else {
|
|
7139
|
+
statement.children.push(";return ", resultsRef, ";");
|
|
7140
|
+
}
|
|
7141
|
+
}
|
|
7142
|
+
function insertPush(node, ref) {
|
|
7143
|
+
if (!node)
|
|
7144
|
+
return;
|
|
7145
|
+
switch (node.type) {
|
|
7146
|
+
case "AssignmentExpression":
|
|
7147
|
+
node.children.unshift(ref, ".push(");
|
|
7148
|
+
node.children.push(")");
|
|
7149
|
+
return;
|
|
7150
|
+
case "Identifier":
|
|
7151
|
+
node.children.unshift(ref, ".push(");
|
|
7152
|
+
node.children.push(")");
|
|
7153
|
+
return;
|
|
7154
|
+
case "BlockStatement":
|
|
7155
|
+
insertPush(node.expressions[node.expressions.length - 1], ref);
|
|
7156
|
+
return;
|
|
7157
|
+
case "ObjectExpression":
|
|
7158
|
+
module2.insertTrimmingSpace(node.children[0], "");
|
|
7159
|
+
node.children.unshift(ref, ".push(");
|
|
7160
|
+
node.children.push(")");
|
|
7161
|
+
return;
|
|
7162
|
+
case "CaseBlock":
|
|
7163
|
+
node.clauses.forEach((clause) => {
|
|
7164
|
+
insertPush(clause, ref);
|
|
7165
|
+
});
|
|
7166
|
+
return;
|
|
7167
|
+
case "CaseClause":
|
|
7168
|
+
return;
|
|
7169
|
+
case "WhenClause":
|
|
7170
|
+
insertPush(node.expressions[node.expressions.length - 1], ref);
|
|
7171
|
+
return;
|
|
7172
|
+
case "DefaultClause":
|
|
7173
|
+
insertPush(node.expressions[node.expressions.length - 1], ref);
|
|
7174
|
+
return;
|
|
7175
|
+
}
|
|
7176
|
+
if (!Array.isArray(node))
|
|
7177
|
+
return;
|
|
7178
|
+
const [, exp] = node;
|
|
7179
|
+
if (!exp)
|
|
7180
|
+
return;
|
|
7181
|
+
let indent = node[0];
|
|
7182
|
+
if (Array.isArray(indent))
|
|
7183
|
+
indent = indent[indent.length - 1];
|
|
7184
|
+
switch (exp.type) {
|
|
7185
|
+
case "BreakStatement":
|
|
7186
|
+
case "ContinueStatement":
|
|
7187
|
+
case "DebuggerStatement":
|
|
7188
|
+
case "EmptyStatement":
|
|
7189
|
+
case "ReturnStatement":
|
|
7190
|
+
case "ThrowStatement":
|
|
7191
|
+
case "Declaration":
|
|
7192
|
+
return;
|
|
7193
|
+
case "ForStatement":
|
|
7194
|
+
case "IterationStatement":
|
|
7195
|
+
wrapIterationReturningResults(exp, ref);
|
|
7196
|
+
return;
|
|
7197
|
+
case "BlockStatement":
|
|
7198
|
+
insertPush(exp.expressions[exp.expressions.length - 1], ref);
|
|
7199
|
+
return;
|
|
7200
|
+
case "IfStatement":
|
|
7201
|
+
insertPush(exp.children[2], ref);
|
|
7202
|
+
if (exp.children[3])
|
|
7203
|
+
insertPush(exp.children[3][2], ref);
|
|
7204
|
+
else
|
|
7205
|
+
exp.children.push([" else {\n", indent, ref, ".push(undefined)\n", indent, "}"]);
|
|
7206
|
+
return;
|
|
7207
|
+
case "SwitchStatement":
|
|
7208
|
+
insertPush(exp.children[2], ref);
|
|
7209
|
+
return;
|
|
7210
|
+
case "TryStatement":
|
|
7211
|
+
insertPush(exp.children[1], ref);
|
|
7212
|
+
insertPush(exp.children[2][3], ref);
|
|
7213
|
+
return;
|
|
7214
|
+
}
|
|
7215
|
+
node.splice(1, 0, ref, ".push(");
|
|
7216
|
+
node.push(")");
|
|
7217
|
+
}
|
|
7005
7218
|
function insertReturn(node) {
|
|
7006
7219
|
if (!node)
|
|
7007
7220
|
return;
|
|
@@ -7047,12 +7260,14 @@ var require_parser = __commonJS({
|
|
|
7047
7260
|
case "ContinueStatement":
|
|
7048
7261
|
case "DebuggerStatement":
|
|
7049
7262
|
case "EmptyStatement":
|
|
7050
|
-
case "ForStatement":
|
|
7051
|
-
case "IterationStatement":
|
|
7052
7263
|
case "ReturnStatement":
|
|
7053
7264
|
case "ThrowStatement":
|
|
7054
7265
|
case "Declaration":
|
|
7055
7266
|
return;
|
|
7267
|
+
case "ForStatement":
|
|
7268
|
+
case "IterationStatement":
|
|
7269
|
+
wrapIterationReturningResults(exp);
|
|
7270
|
+
return;
|
|
7056
7271
|
case "BlockStatement":
|
|
7057
7272
|
insertReturn(exp.expressions[exp.expressions.length - 1]);
|
|
7058
7273
|
return;
|