@danielx/civet 0.4.19-pre.4 → 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 +195 -32
- package/dist/esm.mjs +1 -1
- package/dist/main.js +195 -32
- 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
|
@@ -544,6 +544,7 @@ var Civet = (() => {
|
|
|
544
544
|
EmptyStatement,
|
|
545
545
|
BlockStatement,
|
|
546
546
|
IfStatement,
|
|
547
|
+
ElseClause,
|
|
547
548
|
IfClause,
|
|
548
549
|
UnlessClause,
|
|
549
550
|
IfExpression,
|
|
@@ -551,6 +552,7 @@ var Civet = (() => {
|
|
|
551
552
|
NestedBlockExpressions,
|
|
552
553
|
NestedBlockExpression,
|
|
553
554
|
IterationStatement,
|
|
555
|
+
IterationExpression,
|
|
554
556
|
LoopStatement,
|
|
555
557
|
LoopClause,
|
|
556
558
|
DoWhileStatement,
|
|
@@ -561,6 +563,7 @@ var Civet = (() => {
|
|
|
561
563
|
ForStatementControl,
|
|
562
564
|
WhenCondition,
|
|
563
565
|
CoffeeForStatementParameters,
|
|
566
|
+
CoffeeForIndex,
|
|
564
567
|
CoffeeForDeclaration,
|
|
565
568
|
ForStatementParameters,
|
|
566
569
|
ForInOfDeclaration,
|
|
@@ -973,7 +976,7 @@ var Civet = (() => {
|
|
|
973
976
|
var $L153 = $L("civet");
|
|
974
977
|
var $L154 = $L(" ");
|
|
975
978
|
var $L155 = $L(" ");
|
|
976
|
-
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"));
|
|
977
980
|
var $R1 = $R(new RegExp("[&]", "suy"));
|
|
978
981
|
var $R2 = $R(new RegExp("[!~+-]+", "suy"));
|
|
979
982
|
var $R3 = $R(new RegExp("(?:\\p{ID_Start}|[_$])(?:\\p{ID_Continue}|[\\u200C\\u200D$])*", "suy"));
|
|
@@ -1061,13 +1064,14 @@ var Civet = (() => {
|
|
|
1061
1064
|
}
|
|
1062
1065
|
var ExpressionizedStatement$0 = DebuggerExpression;
|
|
1063
1066
|
var ExpressionizedStatement$1 = IfExpression;
|
|
1064
|
-
var ExpressionizedStatement$2 =
|
|
1065
|
-
var ExpressionizedStatement$3 =
|
|
1067
|
+
var ExpressionizedStatement$2 = IterationExpression;
|
|
1068
|
+
var ExpressionizedStatement$3 = SwitchExpression;
|
|
1069
|
+
var ExpressionizedStatement$4 = ThrowExpression;
|
|
1066
1070
|
function ExpressionizedStatement(state) {
|
|
1067
1071
|
if (state.tokenize) {
|
|
1068
|
-
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));
|
|
1069
1073
|
} else {
|
|
1070
|
-
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);
|
|
1071
1075
|
}
|
|
1072
1076
|
}
|
|
1073
1077
|
var Expression$0 = $TS($S(AssignmentExpression, $Q($S(__, Comma, AssignmentExpression))), function($skip, $loc, $0, $1, $2) {
|
|
@@ -1774,7 +1778,7 @@ var Civet = (() => {
|
|
|
1774
1778
|
return NonNullAssertion$0(state);
|
|
1775
1779
|
}
|
|
1776
1780
|
}
|
|
1777
|
-
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$])/"));
|
|
1778
1782
|
function AdditionalReservedWords(state) {
|
|
1779
1783
|
if (state.verbose)
|
|
1780
1784
|
console.log("ENTER:", "AdditionalReservedWords");
|
|
@@ -3283,16 +3287,20 @@ var Civet = (() => {
|
|
|
3283
3287
|
var ws = $2;
|
|
3284
3288
|
var post = $3;
|
|
3285
3289
|
if (post) {
|
|
3286
|
-
let
|
|
3287
|
-
if (post.
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
block = statement;
|
|
3292
|
-
}
|
|
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), "}"];
|
|
3293
3295
|
} else {
|
|
3294
|
-
|
|
3296
|
+
expressions = [["", statement]];
|
|
3297
|
+
children = [" { ", ...expressions, " }"];
|
|
3295
3298
|
}
|
|
3299
|
+
const block = {
|
|
3300
|
+
type: "BlockStatement",
|
|
3301
|
+
children,
|
|
3302
|
+
expressions
|
|
3303
|
+
};
|
|
3296
3304
|
post.block = block;
|
|
3297
3305
|
post.children.push(block);
|
|
3298
3306
|
if (!module.isWhitespaceOrEmpty(ws))
|
|
@@ -3361,7 +3369,7 @@ var Civet = (() => {
|
|
|
3361
3369
|
return BlockStatement$0(state);
|
|
3362
3370
|
}
|
|
3363
3371
|
}
|
|
3364
|
-
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) {
|
|
3365
3373
|
var clause = $1;
|
|
3366
3374
|
var block = $2;
|
|
3367
3375
|
var e = $3;
|
|
@@ -3379,6 +3387,17 @@ var Civet = (() => {
|
|
|
3379
3387
|
return IfStatement$0(state);
|
|
3380
3388
|
}
|
|
3381
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
|
+
}
|
|
3382
3401
|
var IfClause$0 = $T($S(If, Condition), function(value) {
|
|
3383
3402
|
return { "type": "IfStatement", "children": value };
|
|
3384
3403
|
});
|
|
@@ -3490,9 +3509,22 @@ var Civet = (() => {
|
|
|
3490
3509
|
return IterationStatement$0(state) || IterationStatement$1(state) || IterationStatement$2(state) || IterationStatement$3(state);
|
|
3491
3510
|
}
|
|
3492
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
|
+
}
|
|
3493
3524
|
var LoopStatement$0 = $TS($S(LoopClause, Block), function($skip, $loc, $0, $1, $2) {
|
|
3494
3525
|
var clause = $1;
|
|
3495
3526
|
var block = $2;
|
|
3527
|
+
clause.block = block;
|
|
3496
3528
|
clause.children.push(block);
|
|
3497
3529
|
return clause;
|
|
3498
3530
|
});
|
|
@@ -3506,7 +3538,7 @@ var Civet = (() => {
|
|
|
3506
3538
|
}
|
|
3507
3539
|
}
|
|
3508
3540
|
var LoopClause$0 = $T($S(Loop), function(value) {
|
|
3509
|
-
return { "type": "IterationStatement", "children": value };
|
|
3541
|
+
return { "type": "IterationStatement", "children": [value[0]], "block": null };
|
|
3510
3542
|
});
|
|
3511
3543
|
function LoopClause(state) {
|
|
3512
3544
|
if (state.verbose)
|
|
@@ -3518,7 +3550,8 @@ var Civet = (() => {
|
|
|
3518
3550
|
}
|
|
3519
3551
|
}
|
|
3520
3552
|
var DoWhileStatement$0 = $T($S(Do, BracedBlock, __, WhileClause), function(value) {
|
|
3521
|
-
|
|
3553
|
+
var block = value[1];
|
|
3554
|
+
return { "type": "IterationStatement", "children": value, "block": block };
|
|
3522
3555
|
});
|
|
3523
3556
|
function DoWhileStatement(state) {
|
|
3524
3557
|
if (state.verbose)
|
|
@@ -3532,6 +3565,7 @@ var Civet = (() => {
|
|
|
3532
3565
|
var WhileStatement$0 = $TS($S(WhileClause, Block), function($skip, $loc, $0, $1, $2) {
|
|
3533
3566
|
var clause = $1;
|
|
3534
3567
|
var block = $2;
|
|
3568
|
+
clause.block = block;
|
|
3535
3569
|
clause.children.push(block);
|
|
3536
3570
|
return clause;
|
|
3537
3571
|
});
|
|
@@ -3555,7 +3589,8 @@ var Civet = (() => {
|
|
|
3555
3589
|
}
|
|
3556
3590
|
return {
|
|
3557
3591
|
type: "IterationStatement",
|
|
3558
|
-
children: $0
|
|
3592
|
+
children: $0,
|
|
3593
|
+
block: null
|
|
3559
3594
|
};
|
|
3560
3595
|
});
|
|
3561
3596
|
function WhileClause(state) {
|
|
@@ -3641,13 +3676,14 @@ var Civet = (() => {
|
|
|
3641
3676
|
return WhenCondition$0(state);
|
|
3642
3677
|
}
|
|
3643
3678
|
}
|
|
3644
|
-
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) {
|
|
3645
3680
|
var open = $2;
|
|
3646
3681
|
var declaration = $3;
|
|
3647
|
-
var
|
|
3648
|
-
var
|
|
3649
|
-
var
|
|
3650
|
-
var
|
|
3682
|
+
var index = $4;
|
|
3683
|
+
var kind = $6;
|
|
3684
|
+
var exp = $7;
|
|
3685
|
+
var step = $8;
|
|
3686
|
+
var close = $9;
|
|
3651
3687
|
let blockPrefix = [];
|
|
3652
3688
|
const indent = "".padStart((module.currentIndent + 1) * 2);
|
|
3653
3689
|
if (kind.token === "from") {
|
|
@@ -3757,10 +3793,17 @@ var Civet = (() => {
|
|
|
3757
3793
|
children: ["let ", ...expRefDec, counterRef, " = 0, ", lenRef, " = ", expRef, ".length"],
|
|
3758
3794
|
names: []
|
|
3759
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
|
+
}
|
|
3760
3803
|
blockPrefix.push([{
|
|
3761
3804
|
type: "AssignmentExpression",
|
|
3762
|
-
children: [indent, varRef, " = ", expRef, "[", counterRef, "]\n"],
|
|
3763
|
-
names:
|
|
3805
|
+
children: [indent, varRef, " = ", expRef, "[", indexAssignment, counterRef, "]\n"],
|
|
3806
|
+
names: assignmentNames
|
|
3764
3807
|
}]);
|
|
3765
3808
|
return {
|
|
3766
3809
|
declaration,
|
|
@@ -3783,6 +3826,20 @@ var Civet = (() => {
|
|
|
3783
3826
|
return CoffeeForStatementParameters$0(state);
|
|
3784
3827
|
}
|
|
3785
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
|
+
}
|
|
3786
3843
|
var CoffeeForDeclaration$0 = $TS($S($E($S(__, $EXPECT($L76, fail, 'CoffeeForDeclaration "own"'))), ForBinding), function($skip, $loc, $0, $1, $2) {
|
|
3787
3844
|
var own = $1;
|
|
3788
3845
|
var binding = $2;
|
|
@@ -3815,14 +3872,14 @@ var Civet = (() => {
|
|
|
3815
3872
|
children: $0
|
|
3816
3873
|
};
|
|
3817
3874
|
});
|
|
3818
|
-
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) {
|
|
3819
3876
|
var declaration = $4;
|
|
3820
3877
|
return {
|
|
3821
3878
|
declaration,
|
|
3822
3879
|
children: $0
|
|
3823
3880
|
};
|
|
3824
3881
|
});
|
|
3825
|
-
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) {
|
|
3826
3883
|
var declaration = $3;
|
|
3827
3884
|
return {
|
|
3828
3885
|
declaration,
|
|
@@ -3943,7 +4000,7 @@ var Civet = (() => {
|
|
|
3943
4000
|
var e = $0;
|
|
3944
4001
|
module.addImplicitReturns(e.children[2]);
|
|
3945
4002
|
e.type = "SwitchExpression";
|
|
3946
|
-
e.children = ["(
|
|
4003
|
+
e.children = ["(()=>{", e.children, "})()"];
|
|
3947
4004
|
return e;
|
|
3948
4005
|
});
|
|
3949
4006
|
function SwitchExpression(state) {
|
|
@@ -4226,7 +4283,7 @@ var Civet = (() => {
|
|
|
4226
4283
|
var DebuggerExpression$0 = $TS($S($EXPECT($L80, fail, 'DebuggerExpression "debugger"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
|
|
4227
4284
|
return {
|
|
4228
4285
|
type: "DebuggerExpression",
|
|
4229
|
-
children: ["(
|
|
4286
|
+
children: ["(()=>{", $1, "})()"]
|
|
4230
4287
|
};
|
|
4231
4288
|
});
|
|
4232
4289
|
function DebuggerExpression(state) {
|
|
@@ -4241,7 +4298,7 @@ var Civet = (() => {
|
|
|
4241
4298
|
var ThrowExpression$0 = $TS($S(Throw, ExtendedExpression), function($skip, $loc, $0, $1, $2) {
|
|
4242
4299
|
return {
|
|
4243
4300
|
type: "ThrowExpression",
|
|
4244
|
-
children: ["(
|
|
4301
|
+
children: ["(()=>{", $0, "})()"]
|
|
4245
4302
|
};
|
|
4246
4303
|
});
|
|
4247
4304
|
function ThrowExpression(state) {
|
|
@@ -7055,6 +7112,110 @@ var Civet = (() => {
|
|
|
7055
7112
|
Object.assign(module.config, directive.config);
|
|
7056
7113
|
}
|
|
7057
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
|
+
}
|
|
7058
7219
|
function insertReturn(node) {
|
|
7059
7220
|
if (!node)
|
|
7060
7221
|
return;
|
|
@@ -7100,12 +7261,14 @@ var Civet = (() => {
|
|
|
7100
7261
|
case "ContinueStatement":
|
|
7101
7262
|
case "DebuggerStatement":
|
|
7102
7263
|
case "EmptyStatement":
|
|
7103
|
-
case "ForStatement":
|
|
7104
|
-
case "IterationStatement":
|
|
7105
7264
|
case "ReturnStatement":
|
|
7106
7265
|
case "ThrowStatement":
|
|
7107
7266
|
case "Declaration":
|
|
7108
7267
|
return;
|
|
7268
|
+
case "ForStatement":
|
|
7269
|
+
case "IterationStatement":
|
|
7270
|
+
wrapIterationReturningResults(exp);
|
|
7271
|
+
return;
|
|
7109
7272
|
case "BlockStatement":
|
|
7110
7273
|
insertReturn(exp.expressions[exp.expressions.length - 1]);
|
|
7111
7274
|
return;
|
package/dist/esm.mjs
CHANGED
package/dist/main.js
CHANGED
|
@@ -543,6 +543,7 @@ var require_parser = __commonJS({
|
|
|
543
543
|
EmptyStatement,
|
|
544
544
|
BlockStatement,
|
|
545
545
|
IfStatement,
|
|
546
|
+
ElseClause,
|
|
546
547
|
IfClause,
|
|
547
548
|
UnlessClause,
|
|
548
549
|
IfExpression,
|
|
@@ -550,6 +551,7 @@ var require_parser = __commonJS({
|
|
|
550
551
|
NestedBlockExpressions,
|
|
551
552
|
NestedBlockExpression,
|
|
552
553
|
IterationStatement,
|
|
554
|
+
IterationExpression,
|
|
553
555
|
LoopStatement,
|
|
554
556
|
LoopClause,
|
|
555
557
|
DoWhileStatement,
|
|
@@ -560,6 +562,7 @@ var require_parser = __commonJS({
|
|
|
560
562
|
ForStatementControl,
|
|
561
563
|
WhenCondition,
|
|
562
564
|
CoffeeForStatementParameters,
|
|
565
|
+
CoffeeForIndex,
|
|
563
566
|
CoffeeForDeclaration,
|
|
564
567
|
ForStatementParameters,
|
|
565
568
|
ForInOfDeclaration,
|
|
@@ -972,7 +975,7 @@ var require_parser = __commonJS({
|
|
|
972
975
|
var $L153 = $L("civet");
|
|
973
976
|
var $L154 = $L(" ");
|
|
974
977
|
var $L155 = $L(" ");
|
|
975
|
-
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"));
|
|
976
979
|
var $R1 = $R(new RegExp("[&]", "suy"));
|
|
977
980
|
var $R2 = $R(new RegExp("[!~+-]+", "suy"));
|
|
978
981
|
var $R3 = $R(new RegExp("(?:\\p{ID_Start}|[_$])(?:\\p{ID_Continue}|[\\u200C\\u200D$])*", "suy"));
|
|
@@ -1060,13 +1063,14 @@ var require_parser = __commonJS({
|
|
|
1060
1063
|
}
|
|
1061
1064
|
var ExpressionizedStatement$0 = DebuggerExpression;
|
|
1062
1065
|
var ExpressionizedStatement$1 = IfExpression;
|
|
1063
|
-
var ExpressionizedStatement$2 =
|
|
1064
|
-
var ExpressionizedStatement$3 =
|
|
1066
|
+
var ExpressionizedStatement$2 = IterationExpression;
|
|
1067
|
+
var ExpressionizedStatement$3 = SwitchExpression;
|
|
1068
|
+
var ExpressionizedStatement$4 = ThrowExpression;
|
|
1065
1069
|
function ExpressionizedStatement(state) {
|
|
1066
1070
|
if (state.tokenize) {
|
|
1067
|
-
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));
|
|
1068
1072
|
} else {
|
|
1069
|
-
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);
|
|
1070
1074
|
}
|
|
1071
1075
|
}
|
|
1072
1076
|
var Expression$0 = $TS($S(AssignmentExpression, $Q($S(__, Comma, AssignmentExpression))), function($skip, $loc, $0, $1, $2) {
|
|
@@ -1773,7 +1777,7 @@ var require_parser = __commonJS({
|
|
|
1773
1777
|
return NonNullAssertion$0(state);
|
|
1774
1778
|
}
|
|
1775
1779
|
}
|
|
1776
|
-
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$])/"));
|
|
1777
1781
|
function AdditionalReservedWords(state) {
|
|
1778
1782
|
if (state.verbose)
|
|
1779
1783
|
console.log("ENTER:", "AdditionalReservedWords");
|
|
@@ -3282,16 +3286,20 @@ var require_parser = __commonJS({
|
|
|
3282
3286
|
var ws = $2;
|
|
3283
3287
|
var post = $3;
|
|
3284
3288
|
if (post) {
|
|
3285
|
-
let
|
|
3286
|
-
if (post.
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
block = statement;
|
|
3291
|
-
}
|
|
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), "}"];
|
|
3292
3294
|
} else {
|
|
3293
|
-
|
|
3295
|
+
expressions = [["", statement]];
|
|
3296
|
+
children = [" { ", ...expressions, " }"];
|
|
3294
3297
|
}
|
|
3298
|
+
const block = {
|
|
3299
|
+
type: "BlockStatement",
|
|
3300
|
+
children,
|
|
3301
|
+
expressions
|
|
3302
|
+
};
|
|
3295
3303
|
post.block = block;
|
|
3296
3304
|
post.children.push(block);
|
|
3297
3305
|
if (!module2.isWhitespaceOrEmpty(ws))
|
|
@@ -3360,7 +3368,7 @@ var require_parser = __commonJS({
|
|
|
3360
3368
|
return BlockStatement$0(state);
|
|
3361
3369
|
}
|
|
3362
3370
|
}
|
|
3363
|
-
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) {
|
|
3364
3372
|
var clause = $1;
|
|
3365
3373
|
var block = $2;
|
|
3366
3374
|
var e = $3;
|
|
@@ -3378,6 +3386,17 @@ var require_parser = __commonJS({
|
|
|
3378
3386
|
return IfStatement$0(state);
|
|
3379
3387
|
}
|
|
3380
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
|
+
}
|
|
3381
3400
|
var IfClause$0 = $T($S(If, Condition), function(value) {
|
|
3382
3401
|
return { "type": "IfStatement", "children": value };
|
|
3383
3402
|
});
|
|
@@ -3489,9 +3508,22 @@ var require_parser = __commonJS({
|
|
|
3489
3508
|
return IterationStatement$0(state) || IterationStatement$1(state) || IterationStatement$2(state) || IterationStatement$3(state);
|
|
3490
3509
|
}
|
|
3491
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
|
+
}
|
|
3492
3523
|
var LoopStatement$0 = $TS($S(LoopClause, Block), function($skip, $loc, $0, $1, $2) {
|
|
3493
3524
|
var clause = $1;
|
|
3494
3525
|
var block = $2;
|
|
3526
|
+
clause.block = block;
|
|
3495
3527
|
clause.children.push(block);
|
|
3496
3528
|
return clause;
|
|
3497
3529
|
});
|
|
@@ -3505,7 +3537,7 @@ var require_parser = __commonJS({
|
|
|
3505
3537
|
}
|
|
3506
3538
|
}
|
|
3507
3539
|
var LoopClause$0 = $T($S(Loop), function(value) {
|
|
3508
|
-
return { "type": "IterationStatement", "children": value };
|
|
3540
|
+
return { "type": "IterationStatement", "children": [value[0]], "block": null };
|
|
3509
3541
|
});
|
|
3510
3542
|
function LoopClause(state) {
|
|
3511
3543
|
if (state.verbose)
|
|
@@ -3517,7 +3549,8 @@ var require_parser = __commonJS({
|
|
|
3517
3549
|
}
|
|
3518
3550
|
}
|
|
3519
3551
|
var DoWhileStatement$0 = $T($S(Do, BracedBlock, __, WhileClause), function(value) {
|
|
3520
|
-
|
|
3552
|
+
var block = value[1];
|
|
3553
|
+
return { "type": "IterationStatement", "children": value, "block": block };
|
|
3521
3554
|
});
|
|
3522
3555
|
function DoWhileStatement(state) {
|
|
3523
3556
|
if (state.verbose)
|
|
@@ -3531,6 +3564,7 @@ var require_parser = __commonJS({
|
|
|
3531
3564
|
var WhileStatement$0 = $TS($S(WhileClause, Block), function($skip, $loc, $0, $1, $2) {
|
|
3532
3565
|
var clause = $1;
|
|
3533
3566
|
var block = $2;
|
|
3567
|
+
clause.block = block;
|
|
3534
3568
|
clause.children.push(block);
|
|
3535
3569
|
return clause;
|
|
3536
3570
|
});
|
|
@@ -3554,7 +3588,8 @@ var require_parser = __commonJS({
|
|
|
3554
3588
|
}
|
|
3555
3589
|
return {
|
|
3556
3590
|
type: "IterationStatement",
|
|
3557
|
-
children: $0
|
|
3591
|
+
children: $0,
|
|
3592
|
+
block: null
|
|
3558
3593
|
};
|
|
3559
3594
|
});
|
|
3560
3595
|
function WhileClause(state) {
|
|
@@ -3640,13 +3675,14 @@ var require_parser = __commonJS({
|
|
|
3640
3675
|
return WhenCondition$0(state);
|
|
3641
3676
|
}
|
|
3642
3677
|
}
|
|
3643
|
-
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) {
|
|
3644
3679
|
var open = $2;
|
|
3645
3680
|
var declaration = $3;
|
|
3646
|
-
var
|
|
3647
|
-
var
|
|
3648
|
-
var
|
|
3649
|
-
var
|
|
3681
|
+
var index = $4;
|
|
3682
|
+
var kind = $6;
|
|
3683
|
+
var exp = $7;
|
|
3684
|
+
var step = $8;
|
|
3685
|
+
var close = $9;
|
|
3650
3686
|
let blockPrefix = [];
|
|
3651
3687
|
const indent = "".padStart((module2.currentIndent + 1) * 2);
|
|
3652
3688
|
if (kind.token === "from") {
|
|
@@ -3756,10 +3792,17 @@ var require_parser = __commonJS({
|
|
|
3756
3792
|
children: ["let ", ...expRefDec, counterRef, " = 0, ", lenRef, " = ", expRef, ".length"],
|
|
3757
3793
|
names: []
|
|
3758
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
|
+
}
|
|
3759
3802
|
blockPrefix.push([{
|
|
3760
3803
|
type: "AssignmentExpression",
|
|
3761
|
-
children: [indent, varRef, " = ", expRef, "[", counterRef, "]\n"],
|
|
3762
|
-
names:
|
|
3804
|
+
children: [indent, varRef, " = ", expRef, "[", indexAssignment, counterRef, "]\n"],
|
|
3805
|
+
names: assignmentNames
|
|
3763
3806
|
}]);
|
|
3764
3807
|
return {
|
|
3765
3808
|
declaration,
|
|
@@ -3782,6 +3825,20 @@ var require_parser = __commonJS({
|
|
|
3782
3825
|
return CoffeeForStatementParameters$0(state);
|
|
3783
3826
|
}
|
|
3784
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
|
+
}
|
|
3785
3842
|
var CoffeeForDeclaration$0 = $TS($S($E($S(__, $EXPECT($L76, fail, 'CoffeeForDeclaration "own"'))), ForBinding), function($skip, $loc, $0, $1, $2) {
|
|
3786
3843
|
var own = $1;
|
|
3787
3844
|
var binding = $2;
|
|
@@ -3814,14 +3871,14 @@ var require_parser = __commonJS({
|
|
|
3814
3871
|
children: $0
|
|
3815
3872
|
};
|
|
3816
3873
|
});
|
|
3817
|
-
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) {
|
|
3818
3875
|
var declaration = $4;
|
|
3819
3876
|
return {
|
|
3820
3877
|
declaration,
|
|
3821
3878
|
children: $0
|
|
3822
3879
|
};
|
|
3823
3880
|
});
|
|
3824
|
-
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) {
|
|
3825
3882
|
var declaration = $3;
|
|
3826
3883
|
return {
|
|
3827
3884
|
declaration,
|
|
@@ -3942,7 +3999,7 @@ var require_parser = __commonJS({
|
|
|
3942
3999
|
var e = $0;
|
|
3943
4000
|
module2.addImplicitReturns(e.children[2]);
|
|
3944
4001
|
e.type = "SwitchExpression";
|
|
3945
|
-
e.children = ["(
|
|
4002
|
+
e.children = ["(()=>{", e.children, "})()"];
|
|
3946
4003
|
return e;
|
|
3947
4004
|
});
|
|
3948
4005
|
function SwitchExpression(state) {
|
|
@@ -4225,7 +4282,7 @@ var require_parser = __commonJS({
|
|
|
4225
4282
|
var DebuggerExpression$0 = $TS($S($EXPECT($L80, fail, 'DebuggerExpression "debugger"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
|
|
4226
4283
|
return {
|
|
4227
4284
|
type: "DebuggerExpression",
|
|
4228
|
-
children: ["(
|
|
4285
|
+
children: ["(()=>{", $1, "})()"]
|
|
4229
4286
|
};
|
|
4230
4287
|
});
|
|
4231
4288
|
function DebuggerExpression(state) {
|
|
@@ -4240,7 +4297,7 @@ var require_parser = __commonJS({
|
|
|
4240
4297
|
var ThrowExpression$0 = $TS($S(Throw, ExtendedExpression), function($skip, $loc, $0, $1, $2) {
|
|
4241
4298
|
return {
|
|
4242
4299
|
type: "ThrowExpression",
|
|
4243
|
-
children: ["(
|
|
4300
|
+
children: ["(()=>{", $0, "})()"]
|
|
4244
4301
|
};
|
|
4245
4302
|
});
|
|
4246
4303
|
function ThrowExpression(state) {
|
|
@@ -7054,6 +7111,110 @@ var require_parser = __commonJS({
|
|
|
7054
7111
|
Object.assign(module2.config, directive.config);
|
|
7055
7112
|
}
|
|
7056
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
|
+
}
|
|
7057
7218
|
function insertReturn(node) {
|
|
7058
7219
|
if (!node)
|
|
7059
7220
|
return;
|
|
@@ -7099,12 +7260,14 @@ var require_parser = __commonJS({
|
|
|
7099
7260
|
case "ContinueStatement":
|
|
7100
7261
|
case "DebuggerStatement":
|
|
7101
7262
|
case "EmptyStatement":
|
|
7102
|
-
case "ForStatement":
|
|
7103
|
-
case "IterationStatement":
|
|
7104
7263
|
case "ReturnStatement":
|
|
7105
7264
|
case "ThrowStatement":
|
|
7106
7265
|
case "Declaration":
|
|
7107
7266
|
return;
|
|
7267
|
+
case "ForStatement":
|
|
7268
|
+
case "IterationStatement":
|
|
7269
|
+
wrapIterationReturningResults(exp);
|
|
7270
|
+
return;
|
|
7108
7271
|
case "BlockStatement":
|
|
7109
7272
|
insertReturn(exp.expressions[exp.expressions.length - 1]);
|
|
7110
7273
|
return;
|