@danielx/civet 0.6.13 → 0.6.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -209,7 +209,7 @@ var Civet = (() => {
209
209
  ref.children = [makeLeftHandSideExpression(arg)];
210
210
  return {
211
211
  type: "UnwrappedExpression",
212
- children: [skipIfOnlyWS(fn.leadingComment), ...body, skipIfOnlyWS(fn.trailingComment)]
212
+ children: [skipIfOnlyWS(fn.leadingComment), body, skipIfOnlyWS(fn.trailingComment)]
213
213
  };
214
214
  }
215
215
  expr = fn.expr;
@@ -631,12 +631,20 @@ var Civet = (() => {
631
631
  children
632
632
  };
633
633
  }
634
+ function isExistence(exp) {
635
+ if (exp.type === "ParenthesizedExpression" && exp.implicit) {
636
+ exp = exp.expression;
637
+ }
638
+ if (exp.type === "Existence") {
639
+ return exp;
640
+ }
641
+ }
634
642
  function expandChainedComparisons([first, binops]) {
635
643
  const relationalOps = ["==", "===", "!=", "!==", "<", "<=", ">", ">=", "in"];
636
644
  const lowerPrecedenceOps = ["??", "&&", "||", "&", "|", "^"];
637
645
  let results = [];
638
646
  let i = 0;
639
- let l = binops.length;
647
+ const l = binops.length;
640
648
  let start = 0;
641
649
  let chains = [];
642
650
  while (i < l) {
@@ -652,12 +660,15 @@ var Civet = (() => {
652
660
  processChains();
653
661
  return results;
654
662
  function processChains() {
663
+ first = expandExistence(first);
655
664
  if (chains.length > 1) {
656
665
  chains.forEach((index, k) => {
657
666
  if (k > 0) {
658
667
  results.push(" ", "&&", " ");
659
668
  }
660
- const [pre, op, post, exp] = binops[index];
669
+ const binop = binops[index];
670
+ let [pre, op, post, exp] = binop;
671
+ exp = binop[3] = expandExistence(exp);
661
672
  let endIndex;
662
673
  if (k < chains.length - 1) {
663
674
  endIndex = chains[k + 1];
@@ -674,6 +685,14 @@ var Civet = (() => {
674
685
  }
675
686
  chains.length = 0;
676
687
  }
688
+ function expandExistence(exp) {
689
+ const existence = isExistence(exp);
690
+ if (existence) {
691
+ results.push(existence, " ", "&&", " ");
692
+ return existence.expression;
693
+ }
694
+ return exp;
695
+ }
677
696
  }
678
697
  function processParams(f) {
679
698
  const { type, parameters, block } = f;
@@ -1126,6 +1145,7 @@ var Civet = (() => {
1126
1145
  function makeLeftHandSideExpression(expression) {
1127
1146
  switch (expression.type) {
1128
1147
  case "Ref":
1148
+ case "AmpersandRef":
1129
1149
  case "Identifier":
1130
1150
  case "Literal":
1131
1151
  case "CallExpression":
@@ -1140,7 +1160,8 @@ var Civet = (() => {
1140
1160
  return {
1141
1161
  type: "ParenthesizedExpression",
1142
1162
  children: ["(", expression, ")"],
1143
- expression
1163
+ expression,
1164
+ implicit: true
1144
1165
  };
1145
1166
  }
1146
1167
  }
@@ -2248,27 +2269,20 @@ var Civet = (() => {
2248
2269
  if (post?.token === "?") {
2249
2270
  post = {
2250
2271
  $loc: post.$loc,
2251
- token: " != null"
2272
+ token: "!="
2252
2273
  };
2253
- switch (exp.type) {
2254
- case "Identifier":
2255
- case "Literal":
2256
- case "AmpersandRef":
2257
- return {
2258
- ...exp,
2259
- children: [...pre, ...exp.children, post]
2260
- };
2261
- default:
2262
- const expression = {
2263
- ...exp,
2264
- children: [...pre, "(", exp.children, ")", post]
2265
- };
2266
- return {
2267
- type: "ParenthesizedExpression",
2268
- children: ["(", expression, ")"],
2269
- expression
2270
- };
2274
+ if (pre.length) {
2275
+ exp = {
2276
+ type: "UnaryExpression",
2277
+ children: [...pre, exp, void 0]
2278
+ };
2271
2279
  }
2280
+ const existence = {
2281
+ type: "Existence",
2282
+ expression: exp,
2283
+ children: [exp, " ", post, " ", "null"]
2284
+ };
2285
+ return makeLeftHandSideExpression(existence);
2272
2286
  }
2273
2287
  if (exp.type === "Literal") {
2274
2288
  if (pre.length === 1 && pre[0].token === "-") {
@@ -3141,6 +3155,7 @@ ${input.slice(result.pos)}
3141
3155
  OperatorAssignmentOp,
3142
3156
  AssignmentOpSymbol,
3143
3157
  CoffeeWordAssignmentOp,
3158
+ NotDedentedBinaryOp,
3144
3159
  BinaryOp,
3145
3160
  BinaryOpSymbol,
3146
3161
  Xor,
@@ -3499,6 +3514,7 @@ ${input.slice(result.pos)}
3499
3514
  TypeIndex,
3500
3515
  TypeSuffix,
3501
3516
  ReturnTypeSuffix,
3517
+ ReturnType,
3502
3518
  TypePredicate,
3503
3519
  Type,
3504
3520
  TypeBinary,
@@ -3803,7 +3819,7 @@ ${input.slice(result.pos)}
3803
3819
  var $R6 = $R(new RegExp("[!+-]", "suy"));
3804
3820
  var $R7 = $R(new RegExp("<(?!\\p{ID_Start}|[_$])", "suy"));
3805
3821
  var $R8 = $R(new RegExp("!\\^\\^?", "suy"));
3806
- var $R9 = $R(new RegExp("(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*&)", "suy"));
3822
+ var $R9 = $R(new RegExp("(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*[&.])", "suy"));
3807
3823
  var $R10 = $R(new RegExp("(?=[\\s\\)])", "suy"));
3808
3824
  var $R11 = $R(new RegExp('[^;"\\s]+', "suy"));
3809
3825
  var $R12 = $R(new RegExp("(?:0|[1-9](?:_[0-9]|[0-9])*)n", "suy"));
@@ -4684,9 +4700,9 @@ ${input.slice(result.pos)}
4684
4700
  var rhs = $2;
4685
4701
  return [[], op, [], rhs];
4686
4702
  });
4687
- var BinaryOpRHS$1 = $T($S(NewlineBinaryOpAllowed, $S(NotDedented, BinaryOp, $C(_, $S(EOS, __)), RHS)), function(value) {
4688
- var rhs = value[1];
4689
- return rhs;
4703
+ var BinaryOpRHS$1 = $TS($S(NewlineBinaryOpAllowed, $S(NotDedentedBinaryOp, $C(_, $S(EOS, __)), RHS)), function($skip, $loc, $0, $1, $2) {
4704
+ var rhs = $2;
4705
+ return [...rhs[0], ...rhs.slice(1)];
4690
4706
  });
4691
4707
  var BinaryOpRHS$2 = $T($S($N(NewlineBinaryOpAllowed), SingleLineBinaryOpRHS), function(value) {
4692
4708
  return value[1];
@@ -4825,10 +4841,7 @@ ${input.slice(result.pos)}
4825
4841
  }
4826
4842
  }
4827
4843
  var UnaryPostfix$0 = QuestionMark;
4828
- var UnaryPostfix$1 = $T($P($S(__, As, Type)), function(value) {
4829
- return { "ts": true, "children": value };
4830
- });
4831
- var UnaryPostfix$2 = $T($P($S(__, Satisfies, Type)), function(value) {
4844
+ var UnaryPostfix$1 = $T($P($S(__, $C(As, Satisfies), Type)), function(value) {
4832
4845
  return { "ts": true, "children": value };
4833
4846
  });
4834
4847
  function UnaryPostfix(state) {
@@ -4842,12 +4855,12 @@ ${input.slice(result.pos)}
4842
4855
  }
4843
4856
  }
4844
4857
  if (state.tokenize) {
4845
- const result = $TOKEN("UnaryPostfix", state, UnaryPostfix$0(state) || UnaryPostfix$1(state) || UnaryPostfix$2(state));
4858
+ const result = $TOKEN("UnaryPostfix", state, UnaryPostfix$0(state) || UnaryPostfix$1(state));
4846
4859
  if (state.events)
4847
4860
  state.events.exit?.("UnaryPostfix", state, result, eventData);
4848
4861
  return result;
4849
4862
  } else {
4850
- const result = UnaryPostfix$0(state) || UnaryPostfix$1(state) || UnaryPostfix$2(state);
4863
+ const result = UnaryPostfix$0(state) || UnaryPostfix$1(state);
4851
4864
  if (state.events)
4852
4865
  state.events.exit?.("UnaryPostfix", state, result, eventData);
4853
4866
  return result;
@@ -5458,6 +5471,15 @@ ${input.slice(result.pos)}
5458
5471
  switch (exp.type) {
5459
5472
  case "IterationExpression":
5460
5473
  return exp;
5474
+ case "ParenthesizedExpression":
5475
+ if (exp.implicit) {
5476
+ return {
5477
+ ...exp,
5478
+ children: [open, exp.expression, ws, close],
5479
+ implicit: false
5480
+ };
5481
+ }
5482
+ break;
5461
5483
  }
5462
5484
  return {
5463
5485
  type: "ParenthesizedExpression",
@@ -7898,17 +7920,29 @@ ${input.slice(result.pos)}
7898
7920
  return $skip;
7899
7921
  let body, ref;
7900
7922
  if (!rhs) {
7901
- ref = {
7923
+ body = ref = {
7902
7924
  type: "Ref",
7903
7925
  base: "$",
7904
7926
  id: "$"
7905
7927
  };
7906
- body = [prefix, ref];
7907
7928
  } else {
7908
- ({ ref } = rhs);
7909
- body = [prefix, rhs];
7929
+ let exp = rhs;
7930
+ while (!exp.ref && exp.expression) {
7931
+ exp = exp.expression;
7932
+ }
7933
+ ({ ref } = exp);
7934
+ if (!ref) {
7935
+ throw new Error("Could not find ref in ampersand shorthand block");
7936
+ }
7937
+ body = rhs;
7938
+ }
7939
+ if (prefix) {
7940
+ body = {
7941
+ type: "UnaryExpression",
7942
+ children: [prefix, body, void 0]
7943
+ };
7910
7944
  }
7911
- const children = [ref, " => ", ...body];
7945
+ const children = [ref, " => ", body];
7912
7946
  if (hasAwait(body)) {
7913
7947
  children.unshift("async ");
7914
7948
  }
@@ -8068,7 +8102,7 @@ ${input.slice(result.pos)}
8068
8102
  var callExpRest = $1;
8069
8103
  var unaryPostfix = $2;
8070
8104
  var binopRHS = $3;
8071
- if (!callExpRest && !binopRHS)
8105
+ if (!callExpRest && !binopRHS && !unaryPostfix)
8072
8106
  return $skip;
8073
8107
  const ref = {
8074
8108
  type: "Ref",
@@ -10572,6 +10606,42 @@ ${input.slice(result.pos)}
10572
10606
  return result;
10573
10607
  }
10574
10608
  }
10609
+ var NotDedentedBinaryOp$0 = $TS($S($E(IndentedFurther), $E(_), BinaryOp), function($skip, $loc, $0, $1, $2, $3) {
10610
+ const ws = [];
10611
+ if ($1)
10612
+ ws.push(...$1);
10613
+ if ($2)
10614
+ ws.push(...$2);
10615
+ return [ws, $3];
10616
+ });
10617
+ var NotDedentedBinaryOp$1 = $TS($S(Samedent, $E(_), $N(Identifier), BinaryOp), function($skip, $loc, $0, $1, $2, $3, $4) {
10618
+ const ws = [...$1];
10619
+ if ($2)
10620
+ ws.push(...$2);
10621
+ return [ws, $4];
10622
+ });
10623
+ function NotDedentedBinaryOp(state) {
10624
+ let eventData;
10625
+ if (state.events) {
10626
+ const result = state.events.enter?.("NotDedentedBinaryOp", state);
10627
+ if (result) {
10628
+ if (result.cache)
10629
+ return result.cache;
10630
+ eventData = result.data;
10631
+ }
10632
+ }
10633
+ if (state.tokenize) {
10634
+ const result = $TOKEN("NotDedentedBinaryOp", state, NotDedentedBinaryOp$0(state) || NotDedentedBinaryOp$1(state));
10635
+ if (state.events)
10636
+ state.events.exit?.("NotDedentedBinaryOp", state, result, eventData);
10637
+ return result;
10638
+ } else {
10639
+ const result = NotDedentedBinaryOp$0(state) || NotDedentedBinaryOp$1(state);
10640
+ if (state.events)
10641
+ state.events.exit?.("NotDedentedBinaryOp", state, result, eventData);
10642
+ return result;
10643
+ }
10644
+ }
10575
10645
  var BinaryOp$0 = $TS($S(BinaryOpSymbol), function($skip, $loc, $0, $1) {
10576
10646
  if (typeof $1 === "string")
10577
10647
  return { $loc, token: $1 };
@@ -10901,7 +10971,7 @@ ${input.slice(result.pos)}
10901
10971
  return result;
10902
10972
  }
10903
10973
  }
10904
- var UnaryOp$0 = $TR($EXPECT($R9, fail, "UnaryOp /(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*&)/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
10974
+ var UnaryOp$0 = $TR($EXPECT($R9, fail, "UnaryOp /(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*[&.])/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
10905
10975
  return { $loc, token: $0 };
10906
10976
  });
10907
10977
  var UnaryOp$1 = AwaitOp;
@@ -11390,6 +11460,8 @@ ${input.slice(result.pos)}
11390
11460
  var kind = $1;
11391
11461
  var condition = $2;
11392
11462
  kind = { ...kind, token: "if" };
11463
+ kind.token += getTrimmingSpace(condition);
11464
+ condition = insertTrimmingSpace(condition, "");
11393
11465
  return {
11394
11466
  type: "IfStatement",
11395
11467
  children: [kind, ["(!", condition, ")"]],
@@ -21159,27 +21231,54 @@ ${input.slice(result.pos)}
21159
21231
  return result;
21160
21232
  }
21161
21233
  }
21162
- var ReturnTypeSuffix$0 = $TS($S($E(_), Colon, $E($S(__, $EXPECT($L202, fail, 'ReturnTypeSuffix "asserts"'), NonIdContinue)), TypePredicate), function($skip, $loc, $0, $1, $2, $3, $4) {
21163
- var asserts = $3;
21164
- var t = $4;
21234
+ var ReturnTypeSuffix$0 = $TS($S($E(_), Colon, ReturnType), function($skip, $loc, $0, $1, $2, $3) {
21235
+ var t = $3;
21236
+ return { ...t, children: [$1, $2, ...t.children] };
21237
+ });
21238
+ function ReturnTypeSuffix(state) {
21239
+ let eventData;
21240
+ if (state.events) {
21241
+ const result = state.events.enter?.("ReturnTypeSuffix", state);
21242
+ if (result) {
21243
+ if (result.cache)
21244
+ return result.cache;
21245
+ eventData = result.data;
21246
+ }
21247
+ }
21248
+ if (state.tokenize) {
21249
+ const result = $TOKEN("ReturnTypeSuffix", state, ReturnTypeSuffix$0(state));
21250
+ if (state.events)
21251
+ state.events.exit?.("ReturnTypeSuffix", state, result, eventData);
21252
+ return result;
21253
+ } else {
21254
+ const result = ReturnTypeSuffix$0(state);
21255
+ if (state.events)
21256
+ state.events.exit?.("ReturnTypeSuffix", state, result, eventData);
21257
+ return result;
21258
+ }
21259
+ }
21260
+ var ReturnType$0 = $TS($S($E($S(__, $EXPECT($L202, fail, 'ReturnType "asserts"'), NonIdContinue)), TypePredicate), function($skip, $loc, $0, $1, $2) {
21261
+ var asserts = $1;
21262
+ var t = $2;
21165
21263
  if (asserts) {
21166
21264
  t = {
21167
21265
  type: "AssertsType",
21168
21266
  t,
21169
- children: [asserts[0], asserts[1], t]
21267
+ children: [asserts[0], asserts[1], t],
21268
+ ts: true
21170
21269
  };
21171
21270
  }
21172
21271
  return {
21173
21272
  type: "ReturnTypeAnnotation",
21174
- children: [$1, $2, t],
21273
+ children: [t],
21175
21274
  t,
21176
21275
  ts: true
21177
21276
  };
21178
21277
  });
21179
- function ReturnTypeSuffix(state) {
21278
+ function ReturnType(state) {
21180
21279
  let eventData;
21181
21280
  if (state.events) {
21182
- const result = state.events.enter?.("ReturnTypeSuffix", state);
21281
+ const result = state.events.enter?.("ReturnType", state);
21183
21282
  if (result) {
21184
21283
  if (result.cache)
21185
21284
  return result.cache;
@@ -21187,14 +21286,14 @@ ${input.slice(result.pos)}
21187
21286
  }
21188
21287
  }
21189
21288
  if (state.tokenize) {
21190
- const result = $TOKEN("ReturnTypeSuffix", state, ReturnTypeSuffix$0(state));
21289
+ const result = $TOKEN("ReturnType", state, ReturnType$0(state));
21191
21290
  if (state.events)
21192
- state.events.exit?.("ReturnTypeSuffix", state, result, eventData);
21291
+ state.events.exit?.("ReturnType", state, result, eventData);
21193
21292
  return result;
21194
21293
  } else {
21195
- const result = ReturnTypeSuffix$0(state);
21294
+ const result = ReturnType$0(state);
21196
21295
  if (state.events)
21197
- state.events.exit?.("ReturnTypeSuffix", state, result, eventData);
21296
+ state.events.exit?.("ReturnType", state, result, eventData);
21198
21297
  return result;
21199
21298
  }
21200
21299
  }
@@ -21851,7 +21950,7 @@ ${input.slice(result.pos)}
21851
21950
  return result;
21852
21951
  }
21853
21952
  }
21854
- var FunctionType$0 = $TS($S($E($S(New, $E(_))), Parameters, __, TypeArrowFunction, $E(Type)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
21953
+ var FunctionType$0 = $TS($S($E($S($E($S(Abstract, $E(_))), New, $E(_))), Parameters, __, TypeArrowFunction, $E(ReturnType)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
21855
21954
  var type = $5;
21856
21955
  if (type) {
21857
21956
  return $0;
package/dist/main.js CHANGED
@@ -208,7 +208,7 @@ var require_lib = __commonJS({
208
208
  ref.children = [makeLeftHandSideExpression(arg)];
209
209
  return {
210
210
  type: "UnwrappedExpression",
211
- children: [skipIfOnlyWS(fn.leadingComment), ...body, skipIfOnlyWS(fn.trailingComment)]
211
+ children: [skipIfOnlyWS(fn.leadingComment), body, skipIfOnlyWS(fn.trailingComment)]
212
212
  };
213
213
  }
214
214
  expr = fn.expr;
@@ -630,12 +630,20 @@ var require_lib = __commonJS({
630
630
  children
631
631
  };
632
632
  }
633
+ function isExistence(exp) {
634
+ if (exp.type === "ParenthesizedExpression" && exp.implicit) {
635
+ exp = exp.expression;
636
+ }
637
+ if (exp.type === "Existence") {
638
+ return exp;
639
+ }
640
+ }
633
641
  function expandChainedComparisons([first, binops]) {
634
642
  const relationalOps = ["==", "===", "!=", "!==", "<", "<=", ">", ">=", "in"];
635
643
  const lowerPrecedenceOps = ["??", "&&", "||", "&", "|", "^"];
636
644
  let results = [];
637
645
  let i = 0;
638
- let l = binops.length;
646
+ const l = binops.length;
639
647
  let start = 0;
640
648
  let chains = [];
641
649
  while (i < l) {
@@ -651,12 +659,15 @@ var require_lib = __commonJS({
651
659
  processChains();
652
660
  return results;
653
661
  function processChains() {
662
+ first = expandExistence(first);
654
663
  if (chains.length > 1) {
655
664
  chains.forEach((index, k) => {
656
665
  if (k > 0) {
657
666
  results.push(" ", "&&", " ");
658
667
  }
659
- const [pre, op, post, exp] = binops[index];
668
+ const binop = binops[index];
669
+ let [pre, op, post, exp] = binop;
670
+ exp = binop[3] = expandExistence(exp);
660
671
  let endIndex;
661
672
  if (k < chains.length - 1) {
662
673
  endIndex = chains[k + 1];
@@ -673,6 +684,14 @@ var require_lib = __commonJS({
673
684
  }
674
685
  chains.length = 0;
675
686
  }
687
+ function expandExistence(exp) {
688
+ const existence = isExistence(exp);
689
+ if (existence) {
690
+ results.push(existence, " ", "&&", " ");
691
+ return existence.expression;
692
+ }
693
+ return exp;
694
+ }
676
695
  }
677
696
  function processParams(f) {
678
697
  const { type, parameters, block } = f;
@@ -1125,6 +1144,7 @@ var require_lib = __commonJS({
1125
1144
  function makeLeftHandSideExpression(expression) {
1126
1145
  switch (expression.type) {
1127
1146
  case "Ref":
1147
+ case "AmpersandRef":
1128
1148
  case "Identifier":
1129
1149
  case "Literal":
1130
1150
  case "CallExpression":
@@ -1139,7 +1159,8 @@ var require_lib = __commonJS({
1139
1159
  return {
1140
1160
  type: "ParenthesizedExpression",
1141
1161
  children: ["(", expression, ")"],
1142
- expression
1162
+ expression,
1163
+ implicit: true
1143
1164
  };
1144
1165
  }
1145
1166
  }
@@ -2247,27 +2268,20 @@ var require_lib = __commonJS({
2247
2268
  if (post?.token === "?") {
2248
2269
  post = {
2249
2270
  $loc: post.$loc,
2250
- token: " != null"
2271
+ token: "!="
2251
2272
  };
2252
- switch (exp.type) {
2253
- case "Identifier":
2254
- case "Literal":
2255
- case "AmpersandRef":
2256
- return {
2257
- ...exp,
2258
- children: [...pre, ...exp.children, post]
2259
- };
2260
- default:
2261
- const expression = {
2262
- ...exp,
2263
- children: [...pre, "(", exp.children, ")", post]
2264
- };
2265
- return {
2266
- type: "ParenthesizedExpression",
2267
- children: ["(", expression, ")"],
2268
- expression
2269
- };
2273
+ if (pre.length) {
2274
+ exp = {
2275
+ type: "UnaryExpression",
2276
+ children: [...pre, exp, void 0]
2277
+ };
2270
2278
  }
2279
+ const existence = {
2280
+ type: "Existence",
2281
+ expression: exp,
2282
+ children: [exp, " ", post, " ", "null"]
2283
+ };
2284
+ return makeLeftHandSideExpression(existence);
2271
2285
  }
2272
2286
  if (exp.type === "Literal") {
2273
2287
  if (pre.length === 1 && pre[0].token === "-") {
@@ -3140,6 +3154,7 @@ ${input.slice(result.pos)}
3140
3154
  OperatorAssignmentOp,
3141
3155
  AssignmentOpSymbol,
3142
3156
  CoffeeWordAssignmentOp,
3157
+ NotDedentedBinaryOp,
3143
3158
  BinaryOp,
3144
3159
  BinaryOpSymbol,
3145
3160
  Xor,
@@ -3498,6 +3513,7 @@ ${input.slice(result.pos)}
3498
3513
  TypeIndex,
3499
3514
  TypeSuffix,
3500
3515
  ReturnTypeSuffix,
3516
+ ReturnType,
3501
3517
  TypePredicate,
3502
3518
  Type,
3503
3519
  TypeBinary,
@@ -3802,7 +3818,7 @@ ${input.slice(result.pos)}
3802
3818
  var $R6 = $R(new RegExp("[!+-]", "suy"));
3803
3819
  var $R7 = $R(new RegExp("<(?!\\p{ID_Start}|[_$])", "suy"));
3804
3820
  var $R8 = $R(new RegExp("!\\^\\^?", "suy"));
3805
- var $R9 = $R(new RegExp("(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*&)", "suy"));
3821
+ var $R9 = $R(new RegExp("(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*[&.])", "suy"));
3806
3822
  var $R10 = $R(new RegExp("(?=[\\s\\)])", "suy"));
3807
3823
  var $R11 = $R(new RegExp('[^;"\\s]+', "suy"));
3808
3824
  var $R12 = $R(new RegExp("(?:0|[1-9](?:_[0-9]|[0-9])*)n", "suy"));
@@ -4683,9 +4699,9 @@ ${input.slice(result.pos)}
4683
4699
  var rhs = $2;
4684
4700
  return [[], op, [], rhs];
4685
4701
  });
4686
- var BinaryOpRHS$1 = $T($S(NewlineBinaryOpAllowed, $S(NotDedented, BinaryOp, $C(_, $S(EOS, __)), RHS)), function(value) {
4687
- var rhs = value[1];
4688
- return rhs;
4702
+ var BinaryOpRHS$1 = $TS($S(NewlineBinaryOpAllowed, $S(NotDedentedBinaryOp, $C(_, $S(EOS, __)), RHS)), function($skip, $loc, $0, $1, $2) {
4703
+ var rhs = $2;
4704
+ return [...rhs[0], ...rhs.slice(1)];
4689
4705
  });
4690
4706
  var BinaryOpRHS$2 = $T($S($N(NewlineBinaryOpAllowed), SingleLineBinaryOpRHS), function(value) {
4691
4707
  return value[1];
@@ -4824,10 +4840,7 @@ ${input.slice(result.pos)}
4824
4840
  }
4825
4841
  }
4826
4842
  var UnaryPostfix$0 = QuestionMark;
4827
- var UnaryPostfix$1 = $T($P($S(__, As, Type)), function(value) {
4828
- return { "ts": true, "children": value };
4829
- });
4830
- var UnaryPostfix$2 = $T($P($S(__, Satisfies, Type)), function(value) {
4843
+ var UnaryPostfix$1 = $T($P($S(__, $C(As, Satisfies), Type)), function(value) {
4831
4844
  return { "ts": true, "children": value };
4832
4845
  });
4833
4846
  function UnaryPostfix(state) {
@@ -4841,12 +4854,12 @@ ${input.slice(result.pos)}
4841
4854
  }
4842
4855
  }
4843
4856
  if (state.tokenize) {
4844
- const result = $TOKEN("UnaryPostfix", state, UnaryPostfix$0(state) || UnaryPostfix$1(state) || UnaryPostfix$2(state));
4857
+ const result = $TOKEN("UnaryPostfix", state, UnaryPostfix$0(state) || UnaryPostfix$1(state));
4845
4858
  if (state.events)
4846
4859
  state.events.exit?.("UnaryPostfix", state, result, eventData);
4847
4860
  return result;
4848
4861
  } else {
4849
- const result = UnaryPostfix$0(state) || UnaryPostfix$1(state) || UnaryPostfix$2(state);
4862
+ const result = UnaryPostfix$0(state) || UnaryPostfix$1(state);
4850
4863
  if (state.events)
4851
4864
  state.events.exit?.("UnaryPostfix", state, result, eventData);
4852
4865
  return result;
@@ -5457,6 +5470,15 @@ ${input.slice(result.pos)}
5457
5470
  switch (exp.type) {
5458
5471
  case "IterationExpression":
5459
5472
  return exp;
5473
+ case "ParenthesizedExpression":
5474
+ if (exp.implicit) {
5475
+ return {
5476
+ ...exp,
5477
+ children: [open, exp.expression, ws, close],
5478
+ implicit: false
5479
+ };
5480
+ }
5481
+ break;
5460
5482
  }
5461
5483
  return {
5462
5484
  type: "ParenthesizedExpression",
@@ -7897,17 +7919,29 @@ ${input.slice(result.pos)}
7897
7919
  return $skip;
7898
7920
  let body, ref;
7899
7921
  if (!rhs) {
7900
- ref = {
7922
+ body = ref = {
7901
7923
  type: "Ref",
7902
7924
  base: "$",
7903
7925
  id: "$"
7904
7926
  };
7905
- body = [prefix, ref];
7906
7927
  } else {
7907
- ({ ref } = rhs);
7908
- body = [prefix, rhs];
7928
+ let exp = rhs;
7929
+ while (!exp.ref && exp.expression) {
7930
+ exp = exp.expression;
7931
+ }
7932
+ ({ ref } = exp);
7933
+ if (!ref) {
7934
+ throw new Error("Could not find ref in ampersand shorthand block");
7935
+ }
7936
+ body = rhs;
7937
+ }
7938
+ if (prefix) {
7939
+ body = {
7940
+ type: "UnaryExpression",
7941
+ children: [prefix, body, void 0]
7942
+ };
7909
7943
  }
7910
- const children = [ref, " => ", ...body];
7944
+ const children = [ref, " => ", body];
7911
7945
  if (hasAwait(body)) {
7912
7946
  children.unshift("async ");
7913
7947
  }
@@ -8067,7 +8101,7 @@ ${input.slice(result.pos)}
8067
8101
  var callExpRest = $1;
8068
8102
  var unaryPostfix = $2;
8069
8103
  var binopRHS = $3;
8070
- if (!callExpRest && !binopRHS)
8104
+ if (!callExpRest && !binopRHS && !unaryPostfix)
8071
8105
  return $skip;
8072
8106
  const ref = {
8073
8107
  type: "Ref",
@@ -10571,6 +10605,42 @@ ${input.slice(result.pos)}
10571
10605
  return result;
10572
10606
  }
10573
10607
  }
10608
+ var NotDedentedBinaryOp$0 = $TS($S($E(IndentedFurther), $E(_), BinaryOp), function($skip, $loc, $0, $1, $2, $3) {
10609
+ const ws = [];
10610
+ if ($1)
10611
+ ws.push(...$1);
10612
+ if ($2)
10613
+ ws.push(...$2);
10614
+ return [ws, $3];
10615
+ });
10616
+ var NotDedentedBinaryOp$1 = $TS($S(Samedent, $E(_), $N(Identifier), BinaryOp), function($skip, $loc, $0, $1, $2, $3, $4) {
10617
+ const ws = [...$1];
10618
+ if ($2)
10619
+ ws.push(...$2);
10620
+ return [ws, $4];
10621
+ });
10622
+ function NotDedentedBinaryOp(state) {
10623
+ let eventData;
10624
+ if (state.events) {
10625
+ const result = state.events.enter?.("NotDedentedBinaryOp", state);
10626
+ if (result) {
10627
+ if (result.cache)
10628
+ return result.cache;
10629
+ eventData = result.data;
10630
+ }
10631
+ }
10632
+ if (state.tokenize) {
10633
+ const result = $TOKEN("NotDedentedBinaryOp", state, NotDedentedBinaryOp$0(state) || NotDedentedBinaryOp$1(state));
10634
+ if (state.events)
10635
+ state.events.exit?.("NotDedentedBinaryOp", state, result, eventData);
10636
+ return result;
10637
+ } else {
10638
+ const result = NotDedentedBinaryOp$0(state) || NotDedentedBinaryOp$1(state);
10639
+ if (state.events)
10640
+ state.events.exit?.("NotDedentedBinaryOp", state, result, eventData);
10641
+ return result;
10642
+ }
10643
+ }
10574
10644
  var BinaryOp$0 = $TS($S(BinaryOpSymbol), function($skip, $loc, $0, $1) {
10575
10645
  if (typeof $1 === "string")
10576
10646
  return { $loc, token: $1 };
@@ -10900,7 +10970,7 @@ ${input.slice(result.pos)}
10900
10970
  return result;
10901
10971
  }
10902
10972
  }
10903
- var UnaryOp$0 = $TR($EXPECT($R9, fail, "UnaryOp /(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*&)/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
10973
+ var UnaryOp$0 = $TR($EXPECT($R9, fail, "UnaryOp /(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*[&.])/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
10904
10974
  return { $loc, token: $0 };
10905
10975
  });
10906
10976
  var UnaryOp$1 = AwaitOp;
@@ -11389,6 +11459,8 @@ ${input.slice(result.pos)}
11389
11459
  var kind = $1;
11390
11460
  var condition = $2;
11391
11461
  kind = { ...kind, token: "if" };
11462
+ kind.token += getTrimmingSpace(condition);
11463
+ condition = insertTrimmingSpace(condition, "");
11392
11464
  return {
11393
11465
  type: "IfStatement",
11394
11466
  children: [kind, ["(!", condition, ")"]],
@@ -21158,27 +21230,54 @@ ${input.slice(result.pos)}
21158
21230
  return result;
21159
21231
  }
21160
21232
  }
21161
- var ReturnTypeSuffix$0 = $TS($S($E(_), Colon, $E($S(__, $EXPECT($L202, fail, 'ReturnTypeSuffix "asserts"'), NonIdContinue)), TypePredicate), function($skip, $loc, $0, $1, $2, $3, $4) {
21162
- var asserts = $3;
21163
- var t = $4;
21233
+ var ReturnTypeSuffix$0 = $TS($S($E(_), Colon, ReturnType), function($skip, $loc, $0, $1, $2, $3) {
21234
+ var t = $3;
21235
+ return { ...t, children: [$1, $2, ...t.children] };
21236
+ });
21237
+ function ReturnTypeSuffix(state) {
21238
+ let eventData;
21239
+ if (state.events) {
21240
+ const result = state.events.enter?.("ReturnTypeSuffix", state);
21241
+ if (result) {
21242
+ if (result.cache)
21243
+ return result.cache;
21244
+ eventData = result.data;
21245
+ }
21246
+ }
21247
+ if (state.tokenize) {
21248
+ const result = $TOKEN("ReturnTypeSuffix", state, ReturnTypeSuffix$0(state));
21249
+ if (state.events)
21250
+ state.events.exit?.("ReturnTypeSuffix", state, result, eventData);
21251
+ return result;
21252
+ } else {
21253
+ const result = ReturnTypeSuffix$0(state);
21254
+ if (state.events)
21255
+ state.events.exit?.("ReturnTypeSuffix", state, result, eventData);
21256
+ return result;
21257
+ }
21258
+ }
21259
+ var ReturnType$0 = $TS($S($E($S(__, $EXPECT($L202, fail, 'ReturnType "asserts"'), NonIdContinue)), TypePredicate), function($skip, $loc, $0, $1, $2) {
21260
+ var asserts = $1;
21261
+ var t = $2;
21164
21262
  if (asserts) {
21165
21263
  t = {
21166
21264
  type: "AssertsType",
21167
21265
  t,
21168
- children: [asserts[0], asserts[1], t]
21266
+ children: [asserts[0], asserts[1], t],
21267
+ ts: true
21169
21268
  };
21170
21269
  }
21171
21270
  return {
21172
21271
  type: "ReturnTypeAnnotation",
21173
- children: [$1, $2, t],
21272
+ children: [t],
21174
21273
  t,
21175
21274
  ts: true
21176
21275
  };
21177
21276
  });
21178
- function ReturnTypeSuffix(state) {
21277
+ function ReturnType(state) {
21179
21278
  let eventData;
21180
21279
  if (state.events) {
21181
- const result = state.events.enter?.("ReturnTypeSuffix", state);
21280
+ const result = state.events.enter?.("ReturnType", state);
21182
21281
  if (result) {
21183
21282
  if (result.cache)
21184
21283
  return result.cache;
@@ -21186,14 +21285,14 @@ ${input.slice(result.pos)}
21186
21285
  }
21187
21286
  }
21188
21287
  if (state.tokenize) {
21189
- const result = $TOKEN("ReturnTypeSuffix", state, ReturnTypeSuffix$0(state));
21288
+ const result = $TOKEN("ReturnType", state, ReturnType$0(state));
21190
21289
  if (state.events)
21191
- state.events.exit?.("ReturnTypeSuffix", state, result, eventData);
21290
+ state.events.exit?.("ReturnType", state, result, eventData);
21192
21291
  return result;
21193
21292
  } else {
21194
- const result = ReturnTypeSuffix$0(state);
21293
+ const result = ReturnType$0(state);
21195
21294
  if (state.events)
21196
- state.events.exit?.("ReturnTypeSuffix", state, result, eventData);
21295
+ state.events.exit?.("ReturnType", state, result, eventData);
21197
21296
  return result;
21198
21297
  }
21199
21298
  }
@@ -21850,7 +21949,7 @@ ${input.slice(result.pos)}
21850
21949
  return result;
21851
21950
  }
21852
21951
  }
21853
- var FunctionType$0 = $TS($S($E($S(New, $E(_))), Parameters, __, TypeArrowFunction, $E(Type)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
21952
+ var FunctionType$0 = $TS($S($E($S($E($S(Abstract, $E(_))), New, $E(_))), Parameters, __, TypeArrowFunction, $E(ReturnType)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
21854
21953
  var type = $5;
21855
21954
  if (type) {
21856
21955
  return $0;
package/dist/main.mjs CHANGED
@@ -206,7 +206,7 @@ var require_lib = __commonJS({
206
206
  ref.children = [makeLeftHandSideExpression(arg)];
207
207
  return {
208
208
  type: "UnwrappedExpression",
209
- children: [skipIfOnlyWS(fn.leadingComment), ...body, skipIfOnlyWS(fn.trailingComment)]
209
+ children: [skipIfOnlyWS(fn.leadingComment), body, skipIfOnlyWS(fn.trailingComment)]
210
210
  };
211
211
  }
212
212
  expr = fn.expr;
@@ -628,12 +628,20 @@ var require_lib = __commonJS({
628
628
  children
629
629
  };
630
630
  }
631
+ function isExistence(exp) {
632
+ if (exp.type === "ParenthesizedExpression" && exp.implicit) {
633
+ exp = exp.expression;
634
+ }
635
+ if (exp.type === "Existence") {
636
+ return exp;
637
+ }
638
+ }
631
639
  function expandChainedComparisons([first, binops]) {
632
640
  const relationalOps = ["==", "===", "!=", "!==", "<", "<=", ">", ">=", "in"];
633
641
  const lowerPrecedenceOps = ["??", "&&", "||", "&", "|", "^"];
634
642
  let results = [];
635
643
  let i = 0;
636
- let l = binops.length;
644
+ const l = binops.length;
637
645
  let start = 0;
638
646
  let chains = [];
639
647
  while (i < l) {
@@ -649,12 +657,15 @@ var require_lib = __commonJS({
649
657
  processChains();
650
658
  return results;
651
659
  function processChains() {
660
+ first = expandExistence(first);
652
661
  if (chains.length > 1) {
653
662
  chains.forEach((index, k) => {
654
663
  if (k > 0) {
655
664
  results.push(" ", "&&", " ");
656
665
  }
657
- const [pre, op, post, exp] = binops[index];
666
+ const binop = binops[index];
667
+ let [pre, op, post, exp] = binop;
668
+ exp = binop[3] = expandExistence(exp);
658
669
  let endIndex;
659
670
  if (k < chains.length - 1) {
660
671
  endIndex = chains[k + 1];
@@ -671,6 +682,14 @@ var require_lib = __commonJS({
671
682
  }
672
683
  chains.length = 0;
673
684
  }
685
+ function expandExistence(exp) {
686
+ const existence = isExistence(exp);
687
+ if (existence) {
688
+ results.push(existence, " ", "&&", " ");
689
+ return existence.expression;
690
+ }
691
+ return exp;
692
+ }
674
693
  }
675
694
  function processParams(f) {
676
695
  const { type, parameters, block } = f;
@@ -1123,6 +1142,7 @@ var require_lib = __commonJS({
1123
1142
  function makeLeftHandSideExpression(expression) {
1124
1143
  switch (expression.type) {
1125
1144
  case "Ref":
1145
+ case "AmpersandRef":
1126
1146
  case "Identifier":
1127
1147
  case "Literal":
1128
1148
  case "CallExpression":
@@ -1137,7 +1157,8 @@ var require_lib = __commonJS({
1137
1157
  return {
1138
1158
  type: "ParenthesizedExpression",
1139
1159
  children: ["(", expression, ")"],
1140
- expression
1160
+ expression,
1161
+ implicit: true
1141
1162
  };
1142
1163
  }
1143
1164
  }
@@ -2245,27 +2266,20 @@ var require_lib = __commonJS({
2245
2266
  if (post?.token === "?") {
2246
2267
  post = {
2247
2268
  $loc: post.$loc,
2248
- token: " != null"
2269
+ token: "!="
2249
2270
  };
2250
- switch (exp.type) {
2251
- case "Identifier":
2252
- case "Literal":
2253
- case "AmpersandRef":
2254
- return {
2255
- ...exp,
2256
- children: [...pre, ...exp.children, post]
2257
- };
2258
- default:
2259
- const expression = {
2260
- ...exp,
2261
- children: [...pre, "(", exp.children, ")", post]
2262
- };
2263
- return {
2264
- type: "ParenthesizedExpression",
2265
- children: ["(", expression, ")"],
2266
- expression
2267
- };
2271
+ if (pre.length) {
2272
+ exp = {
2273
+ type: "UnaryExpression",
2274
+ children: [...pre, exp, void 0]
2275
+ };
2268
2276
  }
2277
+ const existence = {
2278
+ type: "Existence",
2279
+ expression: exp,
2280
+ children: [exp, " ", post, " ", "null"]
2281
+ };
2282
+ return makeLeftHandSideExpression(existence);
2269
2283
  }
2270
2284
  if (exp.type === "Literal") {
2271
2285
  if (pre.length === 1 && pre[0].token === "-") {
@@ -3138,6 +3152,7 @@ ${input.slice(result.pos)}
3138
3152
  OperatorAssignmentOp,
3139
3153
  AssignmentOpSymbol,
3140
3154
  CoffeeWordAssignmentOp,
3155
+ NotDedentedBinaryOp,
3141
3156
  BinaryOp,
3142
3157
  BinaryOpSymbol,
3143
3158
  Xor,
@@ -3496,6 +3511,7 @@ ${input.slice(result.pos)}
3496
3511
  TypeIndex,
3497
3512
  TypeSuffix,
3498
3513
  ReturnTypeSuffix,
3514
+ ReturnType,
3499
3515
  TypePredicate,
3500
3516
  Type,
3501
3517
  TypeBinary,
@@ -3800,7 +3816,7 @@ ${input.slice(result.pos)}
3800
3816
  var $R6 = $R(new RegExp("[!+-]", "suy"));
3801
3817
  var $R7 = $R(new RegExp("<(?!\\p{ID_Start}|[_$])", "suy"));
3802
3818
  var $R8 = $R(new RegExp("!\\^\\^?", "suy"));
3803
- var $R9 = $R(new RegExp("(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*&)", "suy"));
3819
+ var $R9 = $R(new RegExp("(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*[&.])", "suy"));
3804
3820
  var $R10 = $R(new RegExp("(?=[\\s\\)])", "suy"));
3805
3821
  var $R11 = $R(new RegExp('[^;"\\s]+', "suy"));
3806
3822
  var $R12 = $R(new RegExp("(?:0|[1-9](?:_[0-9]|[0-9])*)n", "suy"));
@@ -4681,9 +4697,9 @@ ${input.slice(result.pos)}
4681
4697
  var rhs = $2;
4682
4698
  return [[], op, [], rhs];
4683
4699
  });
4684
- var BinaryOpRHS$1 = $T($S(NewlineBinaryOpAllowed, $S(NotDedented, BinaryOp, $C(_, $S(EOS, __)), RHS)), function(value) {
4685
- var rhs = value[1];
4686
- return rhs;
4700
+ var BinaryOpRHS$1 = $TS($S(NewlineBinaryOpAllowed, $S(NotDedentedBinaryOp, $C(_, $S(EOS, __)), RHS)), function($skip, $loc, $0, $1, $2) {
4701
+ var rhs = $2;
4702
+ return [...rhs[0], ...rhs.slice(1)];
4687
4703
  });
4688
4704
  var BinaryOpRHS$2 = $T($S($N(NewlineBinaryOpAllowed), SingleLineBinaryOpRHS), function(value) {
4689
4705
  return value[1];
@@ -4822,10 +4838,7 @@ ${input.slice(result.pos)}
4822
4838
  }
4823
4839
  }
4824
4840
  var UnaryPostfix$0 = QuestionMark;
4825
- var UnaryPostfix$1 = $T($P($S(__, As, Type)), function(value) {
4826
- return { "ts": true, "children": value };
4827
- });
4828
- var UnaryPostfix$2 = $T($P($S(__, Satisfies, Type)), function(value) {
4841
+ var UnaryPostfix$1 = $T($P($S(__, $C(As, Satisfies), Type)), function(value) {
4829
4842
  return { "ts": true, "children": value };
4830
4843
  });
4831
4844
  function UnaryPostfix(state) {
@@ -4839,12 +4852,12 @@ ${input.slice(result.pos)}
4839
4852
  }
4840
4853
  }
4841
4854
  if (state.tokenize) {
4842
- const result = $TOKEN("UnaryPostfix", state, UnaryPostfix$0(state) || UnaryPostfix$1(state) || UnaryPostfix$2(state));
4855
+ const result = $TOKEN("UnaryPostfix", state, UnaryPostfix$0(state) || UnaryPostfix$1(state));
4843
4856
  if (state.events)
4844
4857
  state.events.exit?.("UnaryPostfix", state, result, eventData);
4845
4858
  return result;
4846
4859
  } else {
4847
- const result = UnaryPostfix$0(state) || UnaryPostfix$1(state) || UnaryPostfix$2(state);
4860
+ const result = UnaryPostfix$0(state) || UnaryPostfix$1(state);
4848
4861
  if (state.events)
4849
4862
  state.events.exit?.("UnaryPostfix", state, result, eventData);
4850
4863
  return result;
@@ -5455,6 +5468,15 @@ ${input.slice(result.pos)}
5455
5468
  switch (exp.type) {
5456
5469
  case "IterationExpression":
5457
5470
  return exp;
5471
+ case "ParenthesizedExpression":
5472
+ if (exp.implicit) {
5473
+ return {
5474
+ ...exp,
5475
+ children: [open, exp.expression, ws, close],
5476
+ implicit: false
5477
+ };
5478
+ }
5479
+ break;
5458
5480
  }
5459
5481
  return {
5460
5482
  type: "ParenthesizedExpression",
@@ -7895,17 +7917,29 @@ ${input.slice(result.pos)}
7895
7917
  return $skip;
7896
7918
  let body, ref;
7897
7919
  if (!rhs) {
7898
- ref = {
7920
+ body = ref = {
7899
7921
  type: "Ref",
7900
7922
  base: "$",
7901
7923
  id: "$"
7902
7924
  };
7903
- body = [prefix, ref];
7904
7925
  } else {
7905
- ({ ref } = rhs);
7906
- body = [prefix, rhs];
7926
+ let exp = rhs;
7927
+ while (!exp.ref && exp.expression) {
7928
+ exp = exp.expression;
7929
+ }
7930
+ ({ ref } = exp);
7931
+ if (!ref) {
7932
+ throw new Error("Could not find ref in ampersand shorthand block");
7933
+ }
7934
+ body = rhs;
7935
+ }
7936
+ if (prefix) {
7937
+ body = {
7938
+ type: "UnaryExpression",
7939
+ children: [prefix, body, void 0]
7940
+ };
7907
7941
  }
7908
- const children = [ref, " => ", ...body];
7942
+ const children = [ref, " => ", body];
7909
7943
  if (hasAwait(body)) {
7910
7944
  children.unshift("async ");
7911
7945
  }
@@ -8065,7 +8099,7 @@ ${input.slice(result.pos)}
8065
8099
  var callExpRest = $1;
8066
8100
  var unaryPostfix = $2;
8067
8101
  var binopRHS = $3;
8068
- if (!callExpRest && !binopRHS)
8102
+ if (!callExpRest && !binopRHS && !unaryPostfix)
8069
8103
  return $skip;
8070
8104
  const ref = {
8071
8105
  type: "Ref",
@@ -10569,6 +10603,42 @@ ${input.slice(result.pos)}
10569
10603
  return result;
10570
10604
  }
10571
10605
  }
10606
+ var NotDedentedBinaryOp$0 = $TS($S($E(IndentedFurther), $E(_), BinaryOp), function($skip, $loc, $0, $1, $2, $3) {
10607
+ const ws = [];
10608
+ if ($1)
10609
+ ws.push(...$1);
10610
+ if ($2)
10611
+ ws.push(...$2);
10612
+ return [ws, $3];
10613
+ });
10614
+ var NotDedentedBinaryOp$1 = $TS($S(Samedent, $E(_), $N(Identifier), BinaryOp), function($skip, $loc, $0, $1, $2, $3, $4) {
10615
+ const ws = [...$1];
10616
+ if ($2)
10617
+ ws.push(...$2);
10618
+ return [ws, $4];
10619
+ });
10620
+ function NotDedentedBinaryOp(state) {
10621
+ let eventData;
10622
+ if (state.events) {
10623
+ const result = state.events.enter?.("NotDedentedBinaryOp", state);
10624
+ if (result) {
10625
+ if (result.cache)
10626
+ return result.cache;
10627
+ eventData = result.data;
10628
+ }
10629
+ }
10630
+ if (state.tokenize) {
10631
+ const result = $TOKEN("NotDedentedBinaryOp", state, NotDedentedBinaryOp$0(state) || NotDedentedBinaryOp$1(state));
10632
+ if (state.events)
10633
+ state.events.exit?.("NotDedentedBinaryOp", state, result, eventData);
10634
+ return result;
10635
+ } else {
10636
+ const result = NotDedentedBinaryOp$0(state) || NotDedentedBinaryOp$1(state);
10637
+ if (state.events)
10638
+ state.events.exit?.("NotDedentedBinaryOp", state, result, eventData);
10639
+ return result;
10640
+ }
10641
+ }
10572
10642
  var BinaryOp$0 = $TS($S(BinaryOpSymbol), function($skip, $loc, $0, $1) {
10573
10643
  if (typeof $1 === "string")
10574
10644
  return { $loc, token: $1 };
@@ -10898,7 +10968,7 @@ ${input.slice(result.pos)}
10898
10968
  return result;
10899
10969
  }
10900
10970
  }
10901
- var UnaryOp$0 = $TR($EXPECT($R9, fail, "UnaryOp /(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*&)/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
10971
+ var UnaryOp$0 = $TR($EXPECT($R9, fail, "UnaryOp /(?!\\+\\+|--)[!~+-](?!\\s|[!~+-]*[&.])/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
10902
10972
  return { $loc, token: $0 };
10903
10973
  });
10904
10974
  var UnaryOp$1 = AwaitOp;
@@ -11387,6 +11457,8 @@ ${input.slice(result.pos)}
11387
11457
  var kind = $1;
11388
11458
  var condition = $2;
11389
11459
  kind = { ...kind, token: "if" };
11460
+ kind.token += getTrimmingSpace(condition);
11461
+ condition = insertTrimmingSpace(condition, "");
11390
11462
  return {
11391
11463
  type: "IfStatement",
11392
11464
  children: [kind, ["(!", condition, ")"]],
@@ -21156,27 +21228,54 @@ ${input.slice(result.pos)}
21156
21228
  return result;
21157
21229
  }
21158
21230
  }
21159
- var ReturnTypeSuffix$0 = $TS($S($E(_), Colon, $E($S(__, $EXPECT($L202, fail, 'ReturnTypeSuffix "asserts"'), NonIdContinue)), TypePredicate), function($skip, $loc, $0, $1, $2, $3, $4) {
21160
- var asserts = $3;
21161
- var t = $4;
21231
+ var ReturnTypeSuffix$0 = $TS($S($E(_), Colon, ReturnType), function($skip, $loc, $0, $1, $2, $3) {
21232
+ var t = $3;
21233
+ return { ...t, children: [$1, $2, ...t.children] };
21234
+ });
21235
+ function ReturnTypeSuffix(state) {
21236
+ let eventData;
21237
+ if (state.events) {
21238
+ const result = state.events.enter?.("ReturnTypeSuffix", state);
21239
+ if (result) {
21240
+ if (result.cache)
21241
+ return result.cache;
21242
+ eventData = result.data;
21243
+ }
21244
+ }
21245
+ if (state.tokenize) {
21246
+ const result = $TOKEN("ReturnTypeSuffix", state, ReturnTypeSuffix$0(state));
21247
+ if (state.events)
21248
+ state.events.exit?.("ReturnTypeSuffix", state, result, eventData);
21249
+ return result;
21250
+ } else {
21251
+ const result = ReturnTypeSuffix$0(state);
21252
+ if (state.events)
21253
+ state.events.exit?.("ReturnTypeSuffix", state, result, eventData);
21254
+ return result;
21255
+ }
21256
+ }
21257
+ var ReturnType$0 = $TS($S($E($S(__, $EXPECT($L202, fail, 'ReturnType "asserts"'), NonIdContinue)), TypePredicate), function($skip, $loc, $0, $1, $2) {
21258
+ var asserts = $1;
21259
+ var t = $2;
21162
21260
  if (asserts) {
21163
21261
  t = {
21164
21262
  type: "AssertsType",
21165
21263
  t,
21166
- children: [asserts[0], asserts[1], t]
21264
+ children: [asserts[0], asserts[1], t],
21265
+ ts: true
21167
21266
  };
21168
21267
  }
21169
21268
  return {
21170
21269
  type: "ReturnTypeAnnotation",
21171
- children: [$1, $2, t],
21270
+ children: [t],
21172
21271
  t,
21173
21272
  ts: true
21174
21273
  };
21175
21274
  });
21176
- function ReturnTypeSuffix(state) {
21275
+ function ReturnType(state) {
21177
21276
  let eventData;
21178
21277
  if (state.events) {
21179
- const result = state.events.enter?.("ReturnTypeSuffix", state);
21278
+ const result = state.events.enter?.("ReturnType", state);
21180
21279
  if (result) {
21181
21280
  if (result.cache)
21182
21281
  return result.cache;
@@ -21184,14 +21283,14 @@ ${input.slice(result.pos)}
21184
21283
  }
21185
21284
  }
21186
21285
  if (state.tokenize) {
21187
- const result = $TOKEN("ReturnTypeSuffix", state, ReturnTypeSuffix$0(state));
21286
+ const result = $TOKEN("ReturnType", state, ReturnType$0(state));
21188
21287
  if (state.events)
21189
- state.events.exit?.("ReturnTypeSuffix", state, result, eventData);
21288
+ state.events.exit?.("ReturnType", state, result, eventData);
21190
21289
  return result;
21191
21290
  } else {
21192
- const result = ReturnTypeSuffix$0(state);
21291
+ const result = ReturnType$0(state);
21193
21292
  if (state.events)
21194
- state.events.exit?.("ReturnTypeSuffix", state, result, eventData);
21293
+ state.events.exit?.("ReturnType", state, result, eventData);
21195
21294
  return result;
21196
21295
  }
21197
21296
  }
@@ -21848,7 +21947,7 @@ ${input.slice(result.pos)}
21848
21947
  return result;
21849
21948
  }
21850
21949
  }
21851
- var FunctionType$0 = $TS($S($E($S(New, $E(_))), Parameters, __, TypeArrowFunction, $E(Type)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
21950
+ var FunctionType$0 = $TS($S($E($S($E($S(Abstract, $E(_))), New, $E(_))), Parameters, __, TypeArrowFunction, $E(ReturnType)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
21852
21951
  var type = $5;
21853
21952
  if (type) {
21854
21953
  return $0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.6.13",
3
+ "version": "0.6.14",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "module": "dist/main.mjs",