@danielx/civet 0.4.19-pre.4 → 0.4.19-pre.6

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 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,13 +544,16 @@ var Civet = (() => {
544
544
  EmptyStatement,
545
545
  BlockStatement,
546
546
  IfStatement,
547
+ ElseClause,
547
548
  IfClause,
548
549
  UnlessClause,
549
550
  IfExpression,
551
+ UnlessExpression,
550
552
  ExpressionBlock,
551
553
  NestedBlockExpressions,
552
554
  NestedBlockExpression,
553
555
  IterationStatement,
556
+ IterationExpression,
554
557
  LoopStatement,
555
558
  LoopClause,
556
559
  DoWhileStatement,
@@ -561,6 +564,7 @@ var Civet = (() => {
561
564
  ForStatementControl,
562
565
  WhenCondition,
563
566
  CoffeeForStatementParameters,
567
+ CoffeeForIndex,
564
568
  CoffeeForDeclaration,
565
569
  ForStatementParameters,
566
570
  ForInOfDeclaration,
@@ -973,7 +977,7 @@ var Civet = (() => {
973
977
  var $L153 = $L("civet");
974
978
  var $L154 = $L(" ");
975
979
  var $L155 = $L(" ");
976
- var $R0 = $R(new RegExp("(of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])", "suy"));
980
+ var $R0 = $R(new RegExp("(for|of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])", "suy"));
977
981
  var $R1 = $R(new RegExp("[&]", "suy"));
978
982
  var $R2 = $R(new RegExp("[!~+-]+", "suy"));
979
983
  var $R3 = $R(new RegExp("(?:\\p{ID_Start}|[_$])(?:\\p{ID_Continue}|[\\u200C\\u200D$])*", "suy"));
@@ -1061,13 +1065,15 @@ var Civet = (() => {
1061
1065
  }
1062
1066
  var ExpressionizedStatement$0 = DebuggerExpression;
1063
1067
  var ExpressionizedStatement$1 = IfExpression;
1064
- var ExpressionizedStatement$2 = SwitchExpression;
1065
- var ExpressionizedStatement$3 = ThrowExpression;
1068
+ var ExpressionizedStatement$2 = UnlessExpression;
1069
+ var ExpressionizedStatement$3 = IterationExpression;
1070
+ var ExpressionizedStatement$4 = SwitchExpression;
1071
+ var ExpressionizedStatement$5 = ThrowExpression;
1066
1072
  function ExpressionizedStatement(state) {
1067
1073
  if (state.tokenize) {
1068
- return $TOKEN("ExpressionizedStatement", state, ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state));
1074
+ return $TOKEN("ExpressionizedStatement", state, ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state) || ExpressionizedStatement$4(state) || ExpressionizedStatement$5(state));
1069
1075
  } else {
1070
- return ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state);
1076
+ return ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state) || ExpressionizedStatement$4(state) || ExpressionizedStatement$5(state);
1071
1077
  }
1072
1078
  }
1073
1079
  var Expression$0 = $TS($S(AssignmentExpression, $Q($S(__, Comma, AssignmentExpression))), function($skip, $loc, $0, $1, $2) {
@@ -1247,7 +1253,9 @@ var Civet = (() => {
1247
1253
  var exp = $2;
1248
1254
  var post = $3;
1249
1255
  if (post?.token === "?") {
1250
- return ["(", pre, "(", exp, ") != null)"];
1256
+ return {
1257
+ children: ["(", ...pre, "(", exp, ") != null)"]
1258
+ };
1251
1259
  }
1252
1260
  if (exp.type === "Literal") {
1253
1261
  if (pre.length === 1 && pre[0].token === "-") {
@@ -1267,12 +1275,16 @@ var Civet = (() => {
1267
1275
  exp.unshift(...pre);
1268
1276
  if (post)
1269
1277
  exp.push(post);
1270
- return exp;
1278
+ return {
1279
+ children: exp
1280
+ };
1271
1281
  } else {
1272
1282
  const result = [...pre, exp];
1273
1283
  if (post)
1274
1284
  result.push(post);
1275
- return result;
1285
+ return {
1286
+ children: result
1287
+ };
1276
1288
  }
1277
1289
  });
1278
1290
  var UnaryExpression$1 = $TS($S(CoffeeDoEnabled, Do, __, $C($S(LeftHandSideExpression, $N($S(__, AssignmentOpSymbol))), ArrowFunction, ExtendedExpression)), function($skip, $loc, $0, $1, $2, $3, $4) {
@@ -1564,8 +1576,21 @@ var Civet = (() => {
1564
1576
  return PrimaryExpression$0(state) || PrimaryExpression$1(state) || PrimaryExpression$2(state) || PrimaryExpression$3(state) || PrimaryExpression$4(state) || PrimaryExpression$5(state) || PrimaryExpression$6(state) || PrimaryExpression$7(state) || PrimaryExpression$8(state) || PrimaryExpression$9(state) || PrimaryExpression$10(state) || PrimaryExpression$11(state);
1565
1577
  }
1566
1578
  }
1567
- var ParenthesizedExpression$0 = $TS($S(OpenParen, ExtendedExpression, __, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4) {
1579
+ var ParenthesizedExpression$0 = $TS($S(OpenParen, ExtendedExpression, $E($S($Q(TrailingComment), PostfixStatement)), __, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
1568
1580
  var exp = $2;
1581
+ var post = $3;
1582
+ if (post) {
1583
+ let clause;
1584
+ switch (post[1].type) {
1585
+ case "IterationStatement":
1586
+ case "ForStatement":
1587
+ clause = module.addPostfixStatement(exp, ...post);
1588
+ return module.expressionizeIteration(clause);
1589
+ case "IfStatement":
1590
+ clause = module.expressionizeIfClause(post[1], exp);
1591
+ return clause;
1592
+ }
1593
+ }
1569
1594
  return {
1570
1595
  type: "ParenthesizedExpression",
1571
1596
  expression: exp,
@@ -1774,7 +1799,7 @@ var Civet = (() => {
1774
1799
  return NonNullAssertion$0(state);
1775
1800
  }
1776
1801
  }
1777
- var AdditionalReservedWords$0 = $R$0($EXPECT($R0, fail, "AdditionalReservedWords /(of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])/"));
1802
+ var AdditionalReservedWords$0 = $R$0($EXPECT($R0, fail, "AdditionalReservedWords /(for|of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])/"));
1778
1803
  function AdditionalReservedWords(state) {
1779
1804
  if (state.verbose)
1780
1805
  console.log("ENTER:", "AdditionalReservedWords");
@@ -3278,27 +3303,11 @@ var Civet = (() => {
3278
3303
  }
3279
3304
  }
3280
3305
  var StatementListItem$0 = Declaration;
3281
- var StatementListItem$1 = $TS($S(Statement, $Q(TrailingComment), $E(PostfixStatement)), function($skip, $loc, $0, $1, $2, $3) {
3306
+ var StatementListItem$1 = $TS($S(Statement, $E($S($Q(TrailingComment), PostfixStatement))), function($skip, $loc, $0, $1, $2) {
3282
3307
  var statement = $1;
3283
- var ws = $2;
3284
- var post = $3;
3285
- if (post) {
3286
- let block;
3287
- if (post.type === "ForStatement") {
3288
- if (post.blockPrefix?.length) {
3289
- block = [" {", ...post.blockPrefix, ...statement, " }"];
3290
- } else {
3291
- block = statement;
3292
- }
3293
- } else {
3294
- block = statement;
3295
- }
3296
- post.block = block;
3297
- post.children.push(block);
3298
- if (!module.isWhitespaceOrEmpty(ws))
3299
- post.children.push(ws);
3300
- return post;
3301
- }
3308
+ var post = $2;
3309
+ if (post)
3310
+ return module.addPostfixStatement(statement, ...post);
3302
3311
  return statement;
3303
3312
  });
3304
3313
  function StatementListItem(state) {
@@ -3361,7 +3370,7 @@ var Civet = (() => {
3361
3370
  return BlockStatement$0(state);
3362
3371
  }
3363
3372
  }
3364
- var IfStatement$0 = $TS($S($C(IfClause, UnlessClause), Block, $E($S(__, Else, Block))), function($skip, $loc, $0, $1, $2, $3) {
3373
+ var IfStatement$0 = $TS($S($C(IfClause, UnlessClause), Block, $E(ElseClause)), function($skip, $loc, $0, $1, $2, $3) {
3365
3374
  var clause = $1;
3366
3375
  var block = $2;
3367
3376
  var e = $3;
@@ -3379,6 +3388,17 @@ var Civet = (() => {
3379
3388
  return IfStatement$0(state);
3380
3389
  }
3381
3390
  }
3391
+ var ElseClause$0 = $T($S($Y(EOS), Samedent, Else, Block), function(value) {
3392
+ return [value[1], value[2], value[3]];
3393
+ });
3394
+ var ElseClause$1 = $S($Q(TrailingComment), Else, Block);
3395
+ function ElseClause(state) {
3396
+ if (state.tokenize) {
3397
+ return $TOKEN("ElseClause", state, ElseClause$0(state) || ElseClause$1(state));
3398
+ } else {
3399
+ return ElseClause$0(state) || ElseClause$1(state);
3400
+ }
3401
+ }
3382
3402
  var IfClause$0 = $T($S(If, Condition), function(value) {
3383
3403
  return { "type": "IfStatement", "children": value };
3384
3404
  });
@@ -3415,16 +3435,7 @@ var Civet = (() => {
3415
3435
  var clause = $1;
3416
3436
  var b = $2;
3417
3437
  var e = $3;
3418
- clause.children.shift();
3419
- clause.children.push("?", b, ":");
3420
- if (e) {
3421
- e.splice(1, 1);
3422
- clause.children.push(e);
3423
- } else {
3424
- clause.children.push("void 0");
3425
- }
3426
- clause.type = "IfExpression";
3427
- return clause;
3438
+ return module.expressionizeIfClause(clause, b, e);
3428
3439
  });
3429
3440
  function IfExpression(state) {
3430
3441
  if (state.verbose)
@@ -3435,6 +3446,21 @@ var Civet = (() => {
3435
3446
  return IfExpression$0(state);
3436
3447
  }
3437
3448
  }
3449
+ var UnlessExpression$0 = $TS($S(UnlessClause, ExpressionBlock, $E($S(__, Else, ExpressionBlock))), function($skip, $loc, $0, $1, $2, $3) {
3450
+ var clause = $1;
3451
+ var b = $2;
3452
+ var e = $3;
3453
+ return module.expressionizeIfClause(clause, b, e);
3454
+ });
3455
+ function UnlessExpression(state) {
3456
+ if (state.verbose)
3457
+ console.log("ENTER:", "UnlessExpression");
3458
+ if (state.tokenize) {
3459
+ return $TOKEN("UnlessExpression", state, UnlessExpression$0(state));
3460
+ } else {
3461
+ return UnlessExpression$0(state);
3462
+ }
3463
+ }
3438
3464
  var ExpressionBlock$0 = $TS($S(InsertOpenParen, EOS, NestedBlockExpressions, InsertNewline, InsertIndent, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
3439
3465
  var exps = $3;
3440
3466
  exps[exps.length - 1].pop();
@@ -3490,9 +3516,22 @@ var Civet = (() => {
3490
3516
  return IterationStatement$0(state) || IterationStatement$1(state) || IterationStatement$2(state) || IterationStatement$3(state);
3491
3517
  }
3492
3518
  }
3519
+ var IterationExpression$0 = $TS($S(IterationStatement), function($skip, $loc, $0, $1) {
3520
+ return module.expressionizeIteration($1);
3521
+ });
3522
+ function IterationExpression(state) {
3523
+ if (state.verbose)
3524
+ console.log("ENTER:", "IterationExpression");
3525
+ if (state.tokenize) {
3526
+ return $TOKEN("IterationExpression", state, IterationExpression$0(state));
3527
+ } else {
3528
+ return IterationExpression$0(state);
3529
+ }
3530
+ }
3493
3531
  var LoopStatement$0 = $TS($S(LoopClause, Block), function($skip, $loc, $0, $1, $2) {
3494
3532
  var clause = $1;
3495
3533
  var block = $2;
3534
+ clause.block = block;
3496
3535
  clause.children.push(block);
3497
3536
  return clause;
3498
3537
  });
@@ -3506,7 +3545,7 @@ var Civet = (() => {
3506
3545
  }
3507
3546
  }
3508
3547
  var LoopClause$0 = $T($S(Loop), function(value) {
3509
- return { "type": "IterationStatement", "children": value };
3548
+ return { "type": "IterationStatement", "children": [value[0]], "block": null };
3510
3549
  });
3511
3550
  function LoopClause(state) {
3512
3551
  if (state.verbose)
@@ -3518,7 +3557,8 @@ var Civet = (() => {
3518
3557
  }
3519
3558
  }
3520
3559
  var DoWhileStatement$0 = $T($S(Do, BracedBlock, __, WhileClause), function(value) {
3521
- return { "type": "IterationStatement", "children": value };
3560
+ var block = value[1];
3561
+ return { "type": "IterationStatement", "children": value, "block": block };
3522
3562
  });
3523
3563
  function DoWhileStatement(state) {
3524
3564
  if (state.verbose)
@@ -3532,6 +3572,7 @@ var Civet = (() => {
3532
3572
  var WhileStatement$0 = $TS($S(WhileClause, Block), function($skip, $loc, $0, $1, $2) {
3533
3573
  var clause = $1;
3534
3574
  var block = $2;
3575
+ clause.block = block;
3535
3576
  clause.children.push(block);
3536
3577
  return clause;
3537
3578
  });
@@ -3555,7 +3596,8 @@ var Civet = (() => {
3555
3596
  }
3556
3597
  return {
3557
3598
  type: "IterationStatement",
3558
- children: $0
3599
+ children: $0,
3600
+ block: null
3559
3601
  };
3560
3602
  });
3561
3603
  function WhileClause(state) {
@@ -3614,10 +3656,10 @@ var Civet = (() => {
3614
3656
  if ($3) {
3615
3657
  const indent = "".padStart((module.currentIndent + 1) * 2);
3616
3658
  module.insertTrimmingSpace($3, "");
3617
- $2.blockPrefix.push({
3659
+ $2.blockPrefix.push([indent, {
3618
3660
  type: "IfStatement",
3619
- children: [indent, "if (!(", $3, ")) continue\n"]
3620
- });
3661
+ children: ["if (!(", $3, ")) continue\n"]
3662
+ }]);
3621
3663
  }
3622
3664
  return $2;
3623
3665
  });
@@ -3641,13 +3683,14 @@ var Civet = (() => {
3641
3683
  return WhenCondition$0(state);
3642
3684
  }
3643
3685
  }
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) {
3686
+ 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
3687
  var open = $2;
3646
3688
  var declaration = $3;
3647
- var kind = $5;
3648
- var exp = $6;
3649
- var step = $7;
3650
- var close = $8;
3689
+ var index = $4;
3690
+ var kind = $6;
3691
+ var exp = $7;
3692
+ var step = $8;
3693
+ var close = $9;
3651
3694
  let blockPrefix = [];
3652
3695
  const indent = "".padStart((module.currentIndent + 1) * 2);
3653
3696
  if (kind.token === "from") {
@@ -3726,7 +3769,7 @@ var Civet = (() => {
3726
3769
  children: ["let ", ...startRefDec, ...endRefDec, counterRef, " = ", varRef2, " = ", startRef, ...ascDec],
3727
3770
  names: []
3728
3771
  };
3729
- blockPrefix.push([{
3772
+ blockPrefix.push(["", {
3730
3773
  type: "AssignmentExpression",
3731
3774
  children: [],
3732
3775
  names: varRef2.names
@@ -3757,10 +3800,17 @@ var Civet = (() => {
3757
3800
  children: ["let ", ...expRefDec, counterRef, " = 0, ", lenRef, " = ", expRef, ".length"],
3758
3801
  names: []
3759
3802
  };
3760
- blockPrefix.push([{
3803
+ let indexAssignment;
3804
+ let assignmentNames = [...varRef.names];
3805
+ if (index) {
3806
+ module.insertTrimmingSpace(index, "");
3807
+ indexAssignment = [index, "="];
3808
+ assignmentNames.push(...index.names);
3809
+ }
3810
+ blockPrefix.push([indent, {
3761
3811
  type: "AssignmentExpression",
3762
- children: [indent, varRef, " = ", expRef, "[", counterRef, "]\n"],
3763
- names: varRef.names
3812
+ children: [varRef, " = ", expRef, "[", indexAssignment, counterRef, "]\n"],
3813
+ names: assignmentNames
3764
3814
  }]);
3765
3815
  return {
3766
3816
  declaration,
@@ -3783,6 +3833,20 @@ var Civet = (() => {
3783
3833
  return CoffeeForStatementParameters$0(state);
3784
3834
  }
3785
3835
  }
3836
+ var CoffeeForIndex$0 = $TS($S($Q(TrailingComment), Comma, $Q(TrailingComment), BindingIdentifier), function($skip, $loc, $0, $1, $2, $3, $4) {
3837
+ var id = $4;
3838
+ id.children.unshift(...$1, ...$3);
3839
+ return id;
3840
+ });
3841
+ function CoffeeForIndex(state) {
3842
+ if (state.verbose)
3843
+ console.log("ENTER:", "CoffeeForIndex");
3844
+ if (state.tokenize) {
3845
+ return $TOKEN("CoffeeForIndex", state, CoffeeForIndex$0(state));
3846
+ } else {
3847
+ return CoffeeForIndex$0(state);
3848
+ }
3849
+ }
3786
3850
  var CoffeeForDeclaration$0 = $TS($S($E($S(__, $EXPECT($L76, fail, 'CoffeeForDeclaration "own"'))), ForBinding), function($skip, $loc, $0, $1, $2) {
3787
3851
  var own = $1;
3788
3852
  var binding = $2;
@@ -3815,14 +3879,14 @@ var Civet = (() => {
3815
3879
  children: $0
3816
3880
  };
3817
3881
  });
3818
- var ForStatementParameters$2 = $TS($S($E($S(Await, __)), OpenParen, __, ForInOfDeclaration, __, $C(In, Of), ExtendedExpression, __, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
3882
+ 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
3883
  var declaration = $4;
3820
3884
  return {
3821
3885
  declaration,
3822
3886
  children: $0
3823
3887
  };
3824
3888
  });
3825
- var ForStatementParameters$3 = $TS($S($E($S(Await, __)), InsertOpenParen, ForInOfDeclaration, __, $C(In, Of), ExtendedExpression, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
3889
+ 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
3890
  var declaration = $3;
3827
3891
  return {
3828
3892
  declaration,
@@ -3943,7 +4007,7 @@ var Civet = (() => {
3943
4007
  var e = $0;
3944
4008
  module.addImplicitReturns(e.children[2]);
3945
4009
  e.type = "SwitchExpression";
3946
- e.children = ["($=>{", e.children, "})()"];
4010
+ e.children = ["(()=>{", e.children, "})()"];
3947
4011
  return e;
3948
4012
  });
3949
4013
  function SwitchExpression(state) {
@@ -4226,7 +4290,7 @@ var Civet = (() => {
4226
4290
  var DebuggerExpression$0 = $TS($S($EXPECT($L80, fail, 'DebuggerExpression "debugger"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
4227
4291
  return {
4228
4292
  type: "DebuggerExpression",
4229
- children: ["($=>{", $1, "})()"]
4293
+ children: ["(()=>{", $1, "})()"]
4230
4294
  };
4231
4295
  });
4232
4296
  function DebuggerExpression(state) {
@@ -4241,7 +4305,7 @@ var Civet = (() => {
4241
4305
  var ThrowExpression$0 = $TS($S(Throw, ExtendedExpression), function($skip, $loc, $0, $1, $2) {
4242
4306
  return {
4243
4307
  type: "ThrowExpression",
4244
- children: ["($=>{", ...$0, "})()"]
4308
+ children: ["(()=>{", $0, "})()"]
4245
4309
  };
4246
4310
  });
4247
4311
  function ThrowExpression(state) {
@@ -7055,6 +7119,143 @@ var Civet = (() => {
7055
7119
  Object.assign(module.config, directive.config);
7056
7120
  }
7057
7121
  });
7122
+ module.expressionizeIfClause = function(clause, b, e) {
7123
+ clause.children.shift();
7124
+ clause.children.push("?", b, ":");
7125
+ if (e) {
7126
+ e.splice(1, 1);
7127
+ clause.children.push(e);
7128
+ } else {
7129
+ clause.children.push("void 0");
7130
+ }
7131
+ clause.type = "IfExpression";
7132
+ return clause;
7133
+ };
7134
+ module.addPostfixStatement = function(statement, ws, post) {
7135
+ let children, expressions;
7136
+ if (post.blockPrefix?.length) {
7137
+ let indent = post.blockPrefix[0][0];
7138
+ expressions = [...post.blockPrefix, [indent, statement]];
7139
+ children = [" {\n", ...expressions, "\n", indent?.slice?.(0, -2), "}"];
7140
+ } else {
7141
+ expressions = [["", statement]];
7142
+ children = [" { ", ...expressions, " }"];
7143
+ }
7144
+ const block = {
7145
+ type: "BlockStatement",
7146
+ children,
7147
+ expressions
7148
+ };
7149
+ post.block = block;
7150
+ post.children.push(block);
7151
+ if (!module.isWhitespaceOrEmpty(ws))
7152
+ post.children.push(ws);
7153
+ return post;
7154
+ };
7155
+ module.expressionizeIteration = function(statement) {
7156
+ const resultsRef = {
7157
+ type: "Ref",
7158
+ base: "results"
7159
+ };
7160
+ insertPush(statement.block, resultsRef);
7161
+ return {
7162
+ type: "IterationExpression",
7163
+ children: ["((", resultsRef, ")=>{", statement, "; return ", resultsRef, "})([])"]
7164
+ };
7165
+ };
7166
+ function wrapIterationReturningResults(statement, outerRef) {
7167
+ const resultsRef = {
7168
+ type: "Ref",
7169
+ base: "results"
7170
+ };
7171
+ const declaration = {
7172
+ type: "Declaration",
7173
+ children: ["const ", resultsRef, "=[];"]
7174
+ };
7175
+ insertPush(statement.block, resultsRef);
7176
+ statement.children.unshift(declaration);
7177
+ if (outerRef) {
7178
+ statement.children.push(";", outerRef, ".push(", resultsRef, ");");
7179
+ } else {
7180
+ statement.children.push(";return ", resultsRef, ";");
7181
+ }
7182
+ }
7183
+ function insertPush(node, ref) {
7184
+ if (!node)
7185
+ return;
7186
+ switch (node.type) {
7187
+ case "AssignmentExpression":
7188
+ node.children.unshift(ref, ".push(");
7189
+ node.children.push(")");
7190
+ return;
7191
+ case "Identifier":
7192
+ node.children.unshift(ref, ".push(");
7193
+ node.children.push(")");
7194
+ return;
7195
+ case "BlockStatement":
7196
+ insertPush(node.expressions[node.expressions.length - 1], ref);
7197
+ return;
7198
+ case "ObjectExpression":
7199
+ module.insertTrimmingSpace(node.children[0], "");
7200
+ node.children.unshift(ref, ".push(");
7201
+ node.children.push(")");
7202
+ return;
7203
+ case "CaseBlock":
7204
+ node.clauses.forEach((clause) => {
7205
+ insertPush(clause, ref);
7206
+ });
7207
+ return;
7208
+ case "CaseClause":
7209
+ return;
7210
+ case "WhenClause":
7211
+ insertPush(node.expressions[node.expressions.length - 1], ref);
7212
+ return;
7213
+ case "DefaultClause":
7214
+ insertPush(node.expressions[node.expressions.length - 1], ref);
7215
+ return;
7216
+ }
7217
+ if (!Array.isArray(node))
7218
+ return;
7219
+ const [, exp] = node;
7220
+ if (!exp)
7221
+ return;
7222
+ let indent = node[0];
7223
+ if (Array.isArray(indent))
7224
+ indent = indent[indent.length - 1];
7225
+ switch (exp.type) {
7226
+ case "BreakStatement":
7227
+ case "ContinueStatement":
7228
+ case "DebuggerStatement":
7229
+ case "EmptyStatement":
7230
+ case "ReturnStatement":
7231
+ case "ThrowStatement":
7232
+ case "Declaration":
7233
+ return;
7234
+ case "ForStatement":
7235
+ case "IterationStatement":
7236
+ wrapIterationReturningResults(exp, ref);
7237
+ return;
7238
+ case "BlockStatement":
7239
+ insertPush(exp.expressions[exp.expressions.length - 1], ref);
7240
+ return;
7241
+ case "IfStatement":
7242
+ insertPush(exp.children[2], ref);
7243
+ if (exp.children[3])
7244
+ insertPush(exp.children[3][2], ref);
7245
+ else
7246
+ exp.children.push([" else {\n", indent, ref, ".push(undefined)\n", indent, "}"]);
7247
+ return;
7248
+ case "SwitchStatement":
7249
+ insertPush(exp.children[2], ref);
7250
+ return;
7251
+ case "TryStatement":
7252
+ insertPush(exp.children[1], ref);
7253
+ insertPush(exp.children[2][3], ref);
7254
+ return;
7255
+ }
7256
+ node.splice(1, 0, ref, ".push(");
7257
+ node.push(")");
7258
+ }
7058
7259
  function insertReturn(node) {
7059
7260
  if (!node)
7060
7261
  return;
@@ -7100,12 +7301,14 @@ var Civet = (() => {
7100
7301
  case "ContinueStatement":
7101
7302
  case "DebuggerStatement":
7102
7303
  case "EmptyStatement":
7103
- case "ForStatement":
7104
- case "IterationStatement":
7105
7304
  case "ReturnStatement":
7106
7305
  case "ThrowStatement":
7107
7306
  case "Declaration":
7108
7307
  return;
7308
+ case "ForStatement":
7309
+ case "IterationStatement":
7310
+ wrapIterationReturningResults(exp);
7311
+ return;
7109
7312
  case "BlockStatement":
7110
7313
  insertReturn(exp.expressions[exp.expressions.length - 1]);
7111
7314
  return;
package/dist/esm.mjs CHANGED
@@ -36,7 +36,7 @@ function normalizeSlashes(value) {
36
36
  }
37
37
 
38
38
  function ensureRegister () {
39
- if (registered)return
39
+ if (registered) { return }
40
40
 
41
41
  const installation = {
42
42
  environment: 'node',
package/dist/main.js CHANGED
@@ -543,13 +543,16 @@ 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
+ UnlessExpression,
549
551
  ExpressionBlock,
550
552
  NestedBlockExpressions,
551
553
  NestedBlockExpression,
552
554
  IterationStatement,
555
+ IterationExpression,
553
556
  LoopStatement,
554
557
  LoopClause,
555
558
  DoWhileStatement,
@@ -560,6 +563,7 @@ var require_parser = __commonJS({
560
563
  ForStatementControl,
561
564
  WhenCondition,
562
565
  CoffeeForStatementParameters,
566
+ CoffeeForIndex,
563
567
  CoffeeForDeclaration,
564
568
  ForStatementParameters,
565
569
  ForInOfDeclaration,
@@ -972,7 +976,7 @@ var require_parser = __commonJS({
972
976
  var $L153 = $L("civet");
973
977
  var $L154 = $L(" ");
974
978
  var $L155 = $L(" ");
975
- 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"));
976
980
  var $R1 = $R(new RegExp("[&]", "suy"));
977
981
  var $R2 = $R(new RegExp("[!~+-]+", "suy"));
978
982
  var $R3 = $R(new RegExp("(?:\\p{ID_Start}|[_$])(?:\\p{ID_Continue}|[\\u200C\\u200D$])*", "suy"));
@@ -1060,13 +1064,15 @@ var require_parser = __commonJS({
1060
1064
  }
1061
1065
  var ExpressionizedStatement$0 = DebuggerExpression;
1062
1066
  var ExpressionizedStatement$1 = IfExpression;
1063
- var ExpressionizedStatement$2 = SwitchExpression;
1064
- var ExpressionizedStatement$3 = ThrowExpression;
1067
+ var ExpressionizedStatement$2 = UnlessExpression;
1068
+ var ExpressionizedStatement$3 = IterationExpression;
1069
+ var ExpressionizedStatement$4 = SwitchExpression;
1070
+ var ExpressionizedStatement$5 = ThrowExpression;
1065
1071
  function ExpressionizedStatement(state) {
1066
1072
  if (state.tokenize) {
1067
- return $TOKEN("ExpressionizedStatement", state, ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state));
1073
+ return $TOKEN("ExpressionizedStatement", state, ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state) || ExpressionizedStatement$4(state) || ExpressionizedStatement$5(state));
1068
1074
  } else {
1069
- return ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state);
1075
+ return ExpressionizedStatement$0(state) || ExpressionizedStatement$1(state) || ExpressionizedStatement$2(state) || ExpressionizedStatement$3(state) || ExpressionizedStatement$4(state) || ExpressionizedStatement$5(state);
1070
1076
  }
1071
1077
  }
1072
1078
  var Expression$0 = $TS($S(AssignmentExpression, $Q($S(__, Comma, AssignmentExpression))), function($skip, $loc, $0, $1, $2) {
@@ -1246,7 +1252,9 @@ var require_parser = __commonJS({
1246
1252
  var exp = $2;
1247
1253
  var post = $3;
1248
1254
  if (post?.token === "?") {
1249
- return ["(", pre, "(", exp, ") != null)"];
1255
+ return {
1256
+ children: ["(", ...pre, "(", exp, ") != null)"]
1257
+ };
1250
1258
  }
1251
1259
  if (exp.type === "Literal") {
1252
1260
  if (pre.length === 1 && pre[0].token === "-") {
@@ -1266,12 +1274,16 @@ var require_parser = __commonJS({
1266
1274
  exp.unshift(...pre);
1267
1275
  if (post)
1268
1276
  exp.push(post);
1269
- return exp;
1277
+ return {
1278
+ children: exp
1279
+ };
1270
1280
  } else {
1271
1281
  const result = [...pre, exp];
1272
1282
  if (post)
1273
1283
  result.push(post);
1274
- return result;
1284
+ return {
1285
+ children: result
1286
+ };
1275
1287
  }
1276
1288
  });
1277
1289
  var UnaryExpression$1 = $TS($S(CoffeeDoEnabled, Do, __, $C($S(LeftHandSideExpression, $N($S(__, AssignmentOpSymbol))), ArrowFunction, ExtendedExpression)), function($skip, $loc, $0, $1, $2, $3, $4) {
@@ -1563,8 +1575,21 @@ var require_parser = __commonJS({
1563
1575
  return PrimaryExpression$0(state) || PrimaryExpression$1(state) || PrimaryExpression$2(state) || PrimaryExpression$3(state) || PrimaryExpression$4(state) || PrimaryExpression$5(state) || PrimaryExpression$6(state) || PrimaryExpression$7(state) || PrimaryExpression$8(state) || PrimaryExpression$9(state) || PrimaryExpression$10(state) || PrimaryExpression$11(state);
1564
1576
  }
1565
1577
  }
1566
- var ParenthesizedExpression$0 = $TS($S(OpenParen, ExtendedExpression, __, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4) {
1578
+ var ParenthesizedExpression$0 = $TS($S(OpenParen, ExtendedExpression, $E($S($Q(TrailingComment), PostfixStatement)), __, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
1567
1579
  var exp = $2;
1580
+ var post = $3;
1581
+ if (post) {
1582
+ let clause;
1583
+ switch (post[1].type) {
1584
+ case "IterationStatement":
1585
+ case "ForStatement":
1586
+ clause = module2.addPostfixStatement(exp, ...post);
1587
+ return module2.expressionizeIteration(clause);
1588
+ case "IfStatement":
1589
+ clause = module2.expressionizeIfClause(post[1], exp);
1590
+ return clause;
1591
+ }
1592
+ }
1568
1593
  return {
1569
1594
  type: "ParenthesizedExpression",
1570
1595
  expression: exp,
@@ -1773,7 +1798,7 @@ var require_parser = __commonJS({
1773
1798
  return NonNullAssertion$0(state);
1774
1799
  }
1775
1800
  }
1776
- var AdditionalReservedWords$0 = $R$0($EXPECT($R0, fail, "AdditionalReservedWords /(of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])/"));
1801
+ var AdditionalReservedWords$0 = $R$0($EXPECT($R0, fail, "AdditionalReservedWords /(for|of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])/"));
1777
1802
  function AdditionalReservedWords(state) {
1778
1803
  if (state.verbose)
1779
1804
  console.log("ENTER:", "AdditionalReservedWords");
@@ -3277,27 +3302,11 @@ var require_parser = __commonJS({
3277
3302
  }
3278
3303
  }
3279
3304
  var StatementListItem$0 = Declaration;
3280
- var StatementListItem$1 = $TS($S(Statement, $Q(TrailingComment), $E(PostfixStatement)), function($skip, $loc, $0, $1, $2, $3) {
3305
+ var StatementListItem$1 = $TS($S(Statement, $E($S($Q(TrailingComment), PostfixStatement))), function($skip, $loc, $0, $1, $2) {
3281
3306
  var statement = $1;
3282
- var ws = $2;
3283
- var post = $3;
3284
- if (post) {
3285
- let block;
3286
- if (post.type === "ForStatement") {
3287
- if (post.blockPrefix?.length) {
3288
- block = [" {", ...post.blockPrefix, ...statement, " }"];
3289
- } else {
3290
- block = statement;
3291
- }
3292
- } else {
3293
- block = statement;
3294
- }
3295
- post.block = block;
3296
- post.children.push(block);
3297
- if (!module2.isWhitespaceOrEmpty(ws))
3298
- post.children.push(ws);
3299
- return post;
3300
- }
3307
+ var post = $2;
3308
+ if (post)
3309
+ return module2.addPostfixStatement(statement, ...post);
3301
3310
  return statement;
3302
3311
  });
3303
3312
  function StatementListItem(state) {
@@ -3360,7 +3369,7 @@ var require_parser = __commonJS({
3360
3369
  return BlockStatement$0(state);
3361
3370
  }
3362
3371
  }
3363
- var IfStatement$0 = $TS($S($C(IfClause, UnlessClause), Block, $E($S(__, Else, Block))), function($skip, $loc, $0, $1, $2, $3) {
3372
+ var IfStatement$0 = $TS($S($C(IfClause, UnlessClause), Block, $E(ElseClause)), function($skip, $loc, $0, $1, $2, $3) {
3364
3373
  var clause = $1;
3365
3374
  var block = $2;
3366
3375
  var e = $3;
@@ -3378,6 +3387,17 @@ var require_parser = __commonJS({
3378
3387
  return IfStatement$0(state);
3379
3388
  }
3380
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
+ }
3381
3401
  var IfClause$0 = $T($S(If, Condition), function(value) {
3382
3402
  return { "type": "IfStatement", "children": value };
3383
3403
  });
@@ -3414,16 +3434,7 @@ var require_parser = __commonJS({
3414
3434
  var clause = $1;
3415
3435
  var b = $2;
3416
3436
  var e = $3;
3417
- clause.children.shift();
3418
- clause.children.push("?", b, ":");
3419
- if (e) {
3420
- e.splice(1, 1);
3421
- clause.children.push(e);
3422
- } else {
3423
- clause.children.push("void 0");
3424
- }
3425
- clause.type = "IfExpression";
3426
- return clause;
3437
+ return module2.expressionizeIfClause(clause, b, e);
3427
3438
  });
3428
3439
  function IfExpression(state) {
3429
3440
  if (state.verbose)
@@ -3434,6 +3445,21 @@ var require_parser = __commonJS({
3434
3445
  return IfExpression$0(state);
3435
3446
  }
3436
3447
  }
3448
+ var UnlessExpression$0 = $TS($S(UnlessClause, ExpressionBlock, $E($S(__, Else, ExpressionBlock))), function($skip, $loc, $0, $1, $2, $3) {
3449
+ var clause = $1;
3450
+ var b = $2;
3451
+ var e = $3;
3452
+ return module2.expressionizeIfClause(clause, b, e);
3453
+ });
3454
+ function UnlessExpression(state) {
3455
+ if (state.verbose)
3456
+ console.log("ENTER:", "UnlessExpression");
3457
+ if (state.tokenize) {
3458
+ return $TOKEN("UnlessExpression", state, UnlessExpression$0(state));
3459
+ } else {
3460
+ return UnlessExpression$0(state);
3461
+ }
3462
+ }
3437
3463
  var ExpressionBlock$0 = $TS($S(InsertOpenParen, EOS, NestedBlockExpressions, InsertNewline, InsertIndent, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
3438
3464
  var exps = $3;
3439
3465
  exps[exps.length - 1].pop();
@@ -3489,9 +3515,22 @@ var require_parser = __commonJS({
3489
3515
  return IterationStatement$0(state) || IterationStatement$1(state) || IterationStatement$2(state) || IterationStatement$3(state);
3490
3516
  }
3491
3517
  }
3518
+ var IterationExpression$0 = $TS($S(IterationStatement), function($skip, $loc, $0, $1) {
3519
+ return module2.expressionizeIteration($1);
3520
+ });
3521
+ function IterationExpression(state) {
3522
+ if (state.verbose)
3523
+ console.log("ENTER:", "IterationExpression");
3524
+ if (state.tokenize) {
3525
+ return $TOKEN("IterationExpression", state, IterationExpression$0(state));
3526
+ } else {
3527
+ return IterationExpression$0(state);
3528
+ }
3529
+ }
3492
3530
  var LoopStatement$0 = $TS($S(LoopClause, Block), function($skip, $loc, $0, $1, $2) {
3493
3531
  var clause = $1;
3494
3532
  var block = $2;
3533
+ clause.block = block;
3495
3534
  clause.children.push(block);
3496
3535
  return clause;
3497
3536
  });
@@ -3505,7 +3544,7 @@ var require_parser = __commonJS({
3505
3544
  }
3506
3545
  }
3507
3546
  var LoopClause$0 = $T($S(Loop), function(value) {
3508
- return { "type": "IterationStatement", "children": value };
3547
+ return { "type": "IterationStatement", "children": [value[0]], "block": null };
3509
3548
  });
3510
3549
  function LoopClause(state) {
3511
3550
  if (state.verbose)
@@ -3517,7 +3556,8 @@ var require_parser = __commonJS({
3517
3556
  }
3518
3557
  }
3519
3558
  var DoWhileStatement$0 = $T($S(Do, BracedBlock, __, WhileClause), function(value) {
3520
- return { "type": "IterationStatement", "children": value };
3559
+ var block = value[1];
3560
+ return { "type": "IterationStatement", "children": value, "block": block };
3521
3561
  });
3522
3562
  function DoWhileStatement(state) {
3523
3563
  if (state.verbose)
@@ -3531,6 +3571,7 @@ var require_parser = __commonJS({
3531
3571
  var WhileStatement$0 = $TS($S(WhileClause, Block), function($skip, $loc, $0, $1, $2) {
3532
3572
  var clause = $1;
3533
3573
  var block = $2;
3574
+ clause.block = block;
3534
3575
  clause.children.push(block);
3535
3576
  return clause;
3536
3577
  });
@@ -3554,7 +3595,8 @@ var require_parser = __commonJS({
3554
3595
  }
3555
3596
  return {
3556
3597
  type: "IterationStatement",
3557
- children: $0
3598
+ children: $0,
3599
+ block: null
3558
3600
  };
3559
3601
  });
3560
3602
  function WhileClause(state) {
@@ -3613,10 +3655,10 @@ var require_parser = __commonJS({
3613
3655
  if ($3) {
3614
3656
  const indent = "".padStart((module2.currentIndent + 1) * 2);
3615
3657
  module2.insertTrimmingSpace($3, "");
3616
- $2.blockPrefix.push({
3658
+ $2.blockPrefix.push([indent, {
3617
3659
  type: "IfStatement",
3618
- children: [indent, "if (!(", $3, ")) continue\n"]
3619
- });
3660
+ children: ["if (!(", $3, ")) continue\n"]
3661
+ }]);
3620
3662
  }
3621
3663
  return $2;
3622
3664
  });
@@ -3640,13 +3682,14 @@ var require_parser = __commonJS({
3640
3682
  return WhenCondition$0(state);
3641
3683
  }
3642
3684
  }
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) {
3685
+ 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
3686
  var open = $2;
3645
3687
  var declaration = $3;
3646
- var kind = $5;
3647
- var exp = $6;
3648
- var step = $7;
3649
- var close = $8;
3688
+ var index = $4;
3689
+ var kind = $6;
3690
+ var exp = $7;
3691
+ var step = $8;
3692
+ var close = $9;
3650
3693
  let blockPrefix = [];
3651
3694
  const indent = "".padStart((module2.currentIndent + 1) * 2);
3652
3695
  if (kind.token === "from") {
@@ -3725,7 +3768,7 @@ var require_parser = __commonJS({
3725
3768
  children: ["let ", ...startRefDec, ...endRefDec, counterRef, " = ", varRef2, " = ", startRef, ...ascDec],
3726
3769
  names: []
3727
3770
  };
3728
- blockPrefix.push([{
3771
+ blockPrefix.push(["", {
3729
3772
  type: "AssignmentExpression",
3730
3773
  children: [],
3731
3774
  names: varRef2.names
@@ -3756,10 +3799,17 @@ var require_parser = __commonJS({
3756
3799
  children: ["let ", ...expRefDec, counterRef, " = 0, ", lenRef, " = ", expRef, ".length"],
3757
3800
  names: []
3758
3801
  };
3759
- blockPrefix.push([{
3802
+ let indexAssignment;
3803
+ let assignmentNames = [...varRef.names];
3804
+ if (index) {
3805
+ module2.insertTrimmingSpace(index, "");
3806
+ indexAssignment = [index, "="];
3807
+ assignmentNames.push(...index.names);
3808
+ }
3809
+ blockPrefix.push([indent, {
3760
3810
  type: "AssignmentExpression",
3761
- children: [indent, varRef, " = ", expRef, "[", counterRef, "]\n"],
3762
- names: varRef.names
3811
+ children: [varRef, " = ", expRef, "[", indexAssignment, counterRef, "]\n"],
3812
+ names: assignmentNames
3763
3813
  }]);
3764
3814
  return {
3765
3815
  declaration,
@@ -3782,6 +3832,20 @@ var require_parser = __commonJS({
3782
3832
  return CoffeeForStatementParameters$0(state);
3783
3833
  }
3784
3834
  }
3835
+ var CoffeeForIndex$0 = $TS($S($Q(TrailingComment), Comma, $Q(TrailingComment), BindingIdentifier), function($skip, $loc, $0, $1, $2, $3, $4) {
3836
+ var id = $4;
3837
+ id.children.unshift(...$1, ...$3);
3838
+ return id;
3839
+ });
3840
+ function CoffeeForIndex(state) {
3841
+ if (state.verbose)
3842
+ console.log("ENTER:", "CoffeeForIndex");
3843
+ if (state.tokenize) {
3844
+ return $TOKEN("CoffeeForIndex", state, CoffeeForIndex$0(state));
3845
+ } else {
3846
+ return CoffeeForIndex$0(state);
3847
+ }
3848
+ }
3785
3849
  var CoffeeForDeclaration$0 = $TS($S($E($S(__, $EXPECT($L76, fail, 'CoffeeForDeclaration "own"'))), ForBinding), function($skip, $loc, $0, $1, $2) {
3786
3850
  var own = $1;
3787
3851
  var binding = $2;
@@ -3814,14 +3878,14 @@ var require_parser = __commonJS({
3814
3878
  children: $0
3815
3879
  };
3816
3880
  });
3817
- var ForStatementParameters$2 = $TS($S($E($S(Await, __)), OpenParen, __, ForInOfDeclaration, __, $C(In, Of), ExtendedExpression, __, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
3881
+ 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
3882
  var declaration = $4;
3819
3883
  return {
3820
3884
  declaration,
3821
3885
  children: $0
3822
3886
  };
3823
3887
  });
3824
- var ForStatementParameters$3 = $TS($S($E($S(Await, __)), InsertOpenParen, ForInOfDeclaration, __, $C(In, Of), ExtendedExpression, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
3888
+ 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
3889
  var declaration = $3;
3826
3890
  return {
3827
3891
  declaration,
@@ -3942,7 +4006,7 @@ var require_parser = __commonJS({
3942
4006
  var e = $0;
3943
4007
  module2.addImplicitReturns(e.children[2]);
3944
4008
  e.type = "SwitchExpression";
3945
- e.children = ["($=>{", e.children, "})()"];
4009
+ e.children = ["(()=>{", e.children, "})()"];
3946
4010
  return e;
3947
4011
  });
3948
4012
  function SwitchExpression(state) {
@@ -4225,7 +4289,7 @@ var require_parser = __commonJS({
4225
4289
  var DebuggerExpression$0 = $TS($S($EXPECT($L80, fail, 'DebuggerExpression "debugger"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
4226
4290
  return {
4227
4291
  type: "DebuggerExpression",
4228
- children: ["($=>{", $1, "})()"]
4292
+ children: ["(()=>{", $1, "})()"]
4229
4293
  };
4230
4294
  });
4231
4295
  function DebuggerExpression(state) {
@@ -4240,7 +4304,7 @@ var require_parser = __commonJS({
4240
4304
  var ThrowExpression$0 = $TS($S(Throw, ExtendedExpression), function($skip, $loc, $0, $1, $2) {
4241
4305
  return {
4242
4306
  type: "ThrowExpression",
4243
- children: ["($=>{", ...$0, "})()"]
4307
+ children: ["(()=>{", $0, "})()"]
4244
4308
  };
4245
4309
  });
4246
4310
  function ThrowExpression(state) {
@@ -7054,6 +7118,143 @@ var require_parser = __commonJS({
7054
7118
  Object.assign(module2.config, directive.config);
7055
7119
  }
7056
7120
  });
7121
+ module2.expressionizeIfClause = function(clause, b, e) {
7122
+ clause.children.shift();
7123
+ clause.children.push("?", b, ":");
7124
+ if (e) {
7125
+ e.splice(1, 1);
7126
+ clause.children.push(e);
7127
+ } else {
7128
+ clause.children.push("void 0");
7129
+ }
7130
+ clause.type = "IfExpression";
7131
+ return clause;
7132
+ };
7133
+ module2.addPostfixStatement = function(statement, ws, post) {
7134
+ let children, expressions;
7135
+ if (post.blockPrefix?.length) {
7136
+ let indent = post.blockPrefix[0][0];
7137
+ expressions = [...post.blockPrefix, [indent, statement]];
7138
+ children = [" {\n", ...expressions, "\n", indent?.slice?.(0, -2), "}"];
7139
+ } else {
7140
+ expressions = [["", statement]];
7141
+ children = [" { ", ...expressions, " }"];
7142
+ }
7143
+ const block = {
7144
+ type: "BlockStatement",
7145
+ children,
7146
+ expressions
7147
+ };
7148
+ post.block = block;
7149
+ post.children.push(block);
7150
+ if (!module2.isWhitespaceOrEmpty(ws))
7151
+ post.children.push(ws);
7152
+ return post;
7153
+ };
7154
+ module2.expressionizeIteration = function(statement) {
7155
+ const resultsRef = {
7156
+ type: "Ref",
7157
+ base: "results"
7158
+ };
7159
+ insertPush(statement.block, resultsRef);
7160
+ return {
7161
+ type: "IterationExpression",
7162
+ children: ["((", resultsRef, ")=>{", statement, "; return ", resultsRef, "})([])"]
7163
+ };
7164
+ };
7165
+ function wrapIterationReturningResults(statement, outerRef) {
7166
+ const resultsRef = {
7167
+ type: "Ref",
7168
+ base: "results"
7169
+ };
7170
+ const declaration = {
7171
+ type: "Declaration",
7172
+ children: ["const ", resultsRef, "=[];"]
7173
+ };
7174
+ insertPush(statement.block, resultsRef);
7175
+ statement.children.unshift(declaration);
7176
+ if (outerRef) {
7177
+ statement.children.push(";", outerRef, ".push(", resultsRef, ");");
7178
+ } else {
7179
+ statement.children.push(";return ", resultsRef, ";");
7180
+ }
7181
+ }
7182
+ function insertPush(node, ref) {
7183
+ if (!node)
7184
+ return;
7185
+ switch (node.type) {
7186
+ case "AssignmentExpression":
7187
+ node.children.unshift(ref, ".push(");
7188
+ node.children.push(")");
7189
+ return;
7190
+ case "Identifier":
7191
+ node.children.unshift(ref, ".push(");
7192
+ node.children.push(")");
7193
+ return;
7194
+ case "BlockStatement":
7195
+ insertPush(node.expressions[node.expressions.length - 1], ref);
7196
+ return;
7197
+ case "ObjectExpression":
7198
+ module2.insertTrimmingSpace(node.children[0], "");
7199
+ node.children.unshift(ref, ".push(");
7200
+ node.children.push(")");
7201
+ return;
7202
+ case "CaseBlock":
7203
+ node.clauses.forEach((clause) => {
7204
+ insertPush(clause, ref);
7205
+ });
7206
+ return;
7207
+ case "CaseClause":
7208
+ return;
7209
+ case "WhenClause":
7210
+ insertPush(node.expressions[node.expressions.length - 1], ref);
7211
+ return;
7212
+ case "DefaultClause":
7213
+ insertPush(node.expressions[node.expressions.length - 1], ref);
7214
+ return;
7215
+ }
7216
+ if (!Array.isArray(node))
7217
+ return;
7218
+ const [, exp] = node;
7219
+ if (!exp)
7220
+ return;
7221
+ let indent = node[0];
7222
+ if (Array.isArray(indent))
7223
+ indent = indent[indent.length - 1];
7224
+ switch (exp.type) {
7225
+ case "BreakStatement":
7226
+ case "ContinueStatement":
7227
+ case "DebuggerStatement":
7228
+ case "EmptyStatement":
7229
+ case "ReturnStatement":
7230
+ case "ThrowStatement":
7231
+ case "Declaration":
7232
+ return;
7233
+ case "ForStatement":
7234
+ case "IterationStatement":
7235
+ wrapIterationReturningResults(exp, ref);
7236
+ return;
7237
+ case "BlockStatement":
7238
+ insertPush(exp.expressions[exp.expressions.length - 1], ref);
7239
+ return;
7240
+ case "IfStatement":
7241
+ insertPush(exp.children[2], ref);
7242
+ if (exp.children[3])
7243
+ insertPush(exp.children[3][2], ref);
7244
+ else
7245
+ exp.children.push([" else {\n", indent, ref, ".push(undefined)\n", indent, "}"]);
7246
+ return;
7247
+ case "SwitchStatement":
7248
+ insertPush(exp.children[2], ref);
7249
+ return;
7250
+ case "TryStatement":
7251
+ insertPush(exp.children[1], ref);
7252
+ insertPush(exp.children[2][3], ref);
7253
+ return;
7254
+ }
7255
+ node.splice(1, 0, ref, ".push(");
7256
+ node.push(")");
7257
+ }
7057
7258
  function insertReturn(node) {
7058
7259
  if (!node)
7059
7260
  return;
@@ -7099,12 +7300,14 @@ var require_parser = __commonJS({
7099
7300
  case "ContinueStatement":
7100
7301
  case "DebuggerStatement":
7101
7302
  case "EmptyStatement":
7102
- case "ForStatement":
7103
- case "IterationStatement":
7104
7303
  case "ReturnStatement":
7105
7304
  case "ThrowStatement":
7106
7305
  case "Declaration":
7107
7306
  return;
7307
+ case "ForStatement":
7308
+ case "IterationStatement":
7309
+ wrapIterationReturningResults(exp);
7310
+ return;
7108
7311
  case "BlockStatement":
7109
7312
  insertReturn(exp.expressions[exp.expressions.length - 1]);
7110
7313
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.4.19-pre.4",
3
+ "version": "0.4.19-pre.6",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "exports": {