@danielx/civet 0.11.0 → 0.11.2

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/main.mjs CHANGED
@@ -1071,6 +1071,60 @@ function literalType(literal) {
1071
1071
  children: [t]
1072
1072
  };
1073
1073
  }
1074
+ function typeOfExpression(expression) {
1075
+ let t;
1076
+ if (!isASTNodeObject(expression)) {
1077
+ return;
1078
+ }
1079
+ switch (expression.type) {
1080
+ case "Literal": {
1081
+ switch (expression.subtype) {
1082
+ case "NullLiteral": {
1083
+ return;
1084
+ }
1085
+ default: {
1086
+ t = literalType(expression);
1087
+ }
1088
+ }
1089
+ ;
1090
+ break;
1091
+ }
1092
+ case "RegularExpressionLiteral":
1093
+ case "TemplateLiteral": {
1094
+ t = literalType(expression);
1095
+ break;
1096
+ }
1097
+ case "Identifier": {
1098
+ if (expression.name === "undefined") {
1099
+ return;
1100
+ }
1101
+ }
1102
+ case "MemberExpression": {
1103
+ t = {
1104
+ type: "TypeTypeof",
1105
+ children: ["typeof ", expression],
1106
+ expression
1107
+ };
1108
+ break;
1109
+ }
1110
+ default: {
1111
+ return;
1112
+ }
1113
+ }
1114
+ return t;
1115
+ }
1116
+ function typeSuffixForExpression(expression) {
1117
+ const t = typeOfExpression(expression);
1118
+ if (!(t != null)) {
1119
+ return;
1120
+ }
1121
+ return {
1122
+ type: "TypeSuffix",
1123
+ ts: true,
1124
+ t,
1125
+ children: [": ", t]
1126
+ };
1127
+ }
1074
1128
  function makeNumericLiteral(n) {
1075
1129
  const s = n.toString();
1076
1130
  return {
@@ -1948,11 +2002,14 @@ function gatherBindingPatternTypeSuffix(pattern) {
1948
2002
  const results1 = [];
1949
2003
  for (let ref7 = pattern.elements, i7 = 0, len6 = ref7.length; i7 < len6; i7++) {
1950
2004
  const elem = ref7[i7];
1951
- let { typeSuffix } = elem;
2005
+ let { typeSuffix, initializer } = elem;
1952
2006
  typeSuffix ??= elem.binding?.typeSuffix;
1953
2007
  if (typeSuffix) {
1954
2008
  count++;
1955
2009
  }
2010
+ if (initializer != null) {
2011
+ typeSuffix ??= typeSuffixForExpression(trimFirstSpace(initializer.expression));
2012
+ }
1956
2013
  let typeElement = [typeSuffix?.t, elem.delim];
1957
2014
  if (typeSuffix?.optional) {
1958
2015
  typeElement[0] = parenthesizeType(typeElement[0]);
@@ -1987,11 +2044,14 @@ function gatherBindingPatternTypeSuffix(pattern) {
1987
2044
  const results2 = [];
1988
2045
  for (let ref8 = pattern.properties, i8 = 0, len7 = ref8.length; i8 < len7; i8++) {
1989
2046
  const prop = ref8[i8];
1990
- let { typeSuffix } = prop;
2047
+ let { typeSuffix, initializer } = prop;
1991
2048
  typeSuffix ??= prop.value?.typeSuffix;
1992
2049
  if (typeSuffix) {
1993
2050
  count++;
1994
2051
  }
2052
+ if (initializer != null) {
2053
+ typeSuffix ??= typeSuffixForExpression(trimFirstSpace(initializer.expression));
2054
+ }
1995
2055
  typeSuffix ??= {
1996
2056
  type: "TypeSuffix",
1997
2057
  ts: true,
@@ -3092,19 +3152,23 @@ function patternBindings(pattern) {
3092
3152
  function assignResults(node, collect) {
3093
3153
  if (!node) return;
3094
3154
  switch (node.type) {
3095
- case "BlockStatement":
3155
+ case "BlockStatement": {
3096
3156
  if (node.expressions.length) {
3097
3157
  let ref5;
3098
3158
  assignResults((ref5 = node.expressions)[ref5.length - 1], collect);
3099
3159
  } else {
3100
3160
  node.expressions.push(["", collect("void 0"), ";"]);
3161
+ updateParentPointers(node);
3101
3162
  }
3102
3163
  return;
3103
- case "CaseBlock":
3104
- node.clauses.forEach((clause) => {
3105
- return assignResults(clause, collect);
3106
- });
3164
+ }
3165
+ case "CaseBlock": {
3166
+ for (let ref6 = node.clauses, i4 = 0, len3 = ref6.length; i4 < len3; i4++) {
3167
+ const clause = ref6[i4];
3168
+ assignResults(clause, collect);
3169
+ }
3107
3170
  return;
3171
+ }
3108
3172
  case "WhenClause":
3109
3173
  case "DefaultClause":
3110
3174
  case "PatternClause": {
@@ -3130,7 +3194,8 @@ function assignResults(node, collect) {
3130
3194
  if (exp.type === "LabelledStatement") {
3131
3195
  exp = exp.statement;
3132
3196
  }
3133
- let ref6;
3197
+ let ref7;
3198
+ let ref8;
3134
3199
  let m1;
3135
3200
  switch (exp.type) {
3136
3201
  case "BreakStatement":
@@ -3142,18 +3207,19 @@ function assignResults(node, collect) {
3142
3207
  return;
3143
3208
  }
3144
3209
  case "Declaration": {
3145
- let ref7;
3210
+ let ref9;
3146
3211
  if (exp.bindings?.length) {
3147
- ref7 = patternAsValue((ref6 = exp.bindings)[ref6.length - 1].pattern);
3212
+ ref9 = patternAsValue((ref7 = exp.bindings)[ref7.length - 1].pattern);
3148
3213
  } else {
3149
- ref7 = "void 0";
3214
+ ref9 = "void 0";
3150
3215
  }
3151
3216
  ;
3152
- const value = ref7;
3217
+ const value = ref9;
3153
3218
  exp.children.push([
3154
3219
  "",
3155
3220
  [";", collect(value)]
3156
3221
  ]);
3222
+ updateParentPointers(exp);
3157
3223
  return;
3158
3224
  }
3159
3225
  case "FunctionExpression": {
@@ -3162,6 +3228,7 @@ function assignResults(node, collect) {
3162
3228
  "",
3163
3229
  [";", collect(exp.id)]
3164
3230
  ]);
3231
+ updateParentPointers(exp);
3165
3232
  return;
3166
3233
  }
3167
3234
  break;
@@ -3177,7 +3244,7 @@ function assignResults(node, collect) {
3177
3244
  if (exp.expressions.some(isExit)) {
3178
3245
  return;
3179
3246
  }
3180
- assignResults(exp.expressions[exp.expressions.length - 1], collect);
3247
+ assignResults((ref8 = exp.expressions)[ref8.length - 1], collect);
3181
3248
  return;
3182
3249
  }
3183
3250
  case "IfStatement": {
@@ -3187,6 +3254,7 @@ function assignResults(node, collect) {
3187
3254
  } else {
3188
3255
  braceBlock(exp.then);
3189
3256
  exp.children.push([" else {", collect("void 0"), "}"]);
3257
+ updateParentPointers(exp);
3190
3258
  }
3191
3259
  return;
3192
3260
  }
@@ -3195,15 +3263,15 @@ function assignResults(node, collect) {
3195
3263
  return;
3196
3264
  }
3197
3265
  case "SwitchStatement": {
3198
- for (let ref8 = exp.caseBlock.clauses, i4 = 0, len3 = ref8.length; i4 < len3; i4++) {
3199
- const clause = ref8[i4];
3266
+ for (let ref10 = exp.caseBlock.clauses, i5 = 0, len4 = ref10.length; i5 < len4; i5++) {
3267
+ const clause = ref10[i5];
3200
3268
  assignResults(clause, collect);
3201
3269
  }
3202
3270
  return;
3203
3271
  }
3204
3272
  case "TryStatement": {
3205
- for (let ref9 = exp.blocks, i5 = 0, len4 = ref9.length; i5 < len4; i5++) {
3206
- const block = ref9[i5];
3273
+ for (let ref11 = exp.blocks, i6 = 0, len5 = ref11.length; i6 < len5; i6++) {
3274
+ const block = ref11[i6];
3207
3275
  assignResults(block, collect);
3208
3276
  }
3209
3277
  return;
@@ -3215,6 +3283,7 @@ function assignResults(node, collect) {
3215
3283
  const semi2 = exp.children.lastIndexOf(";");
3216
3284
  if (0 <= semi2 && semi2 < exp.children.length - 1) {
3217
3285
  exp.children.splice(semi2 + 1, 1 / 0, ...[collect(exp.children.slice(semi2 + 1))]);
3286
+ updateParentPointers(exp);
3218
3287
  return;
3219
3288
  }
3220
3289
  ;
@@ -3224,7 +3293,11 @@ function assignResults(node, collect) {
3224
3293
  if (node[node.length - 1]?.type === "SemicolonDelimiter") {
3225
3294
  return;
3226
3295
  }
3296
+ const parent = node[1].parent;
3227
3297
  node[1] = collect(node[1]);
3298
+ if (parent != null) {
3299
+ updateParentPointers(parent);
3300
+ }
3228
3301
  }
3229
3302
  function insertReturn(node) {
3230
3303
  if (!node) return;
@@ -3255,9 +3328,9 @@ function insertReturn(node) {
3255
3328
  insertReturn(node.block);
3256
3329
  if (!isExit(node.block)) {
3257
3330
  const comment = hasTrailingComment(node.block.expressions);
3258
- let ref10;
3331
+ let ref12;
3259
3332
  node.block.expressions.push([
3260
- comment ? (ref10 = node.block.expressions)[ref10.length - 1][0] || "\n" : "",
3333
+ comment ? (ref12 = node.block.expressions)[ref12.length - 1][0] || "\n" : "",
3261
3334
  wrapWithReturn(void 0, node, !comment)
3262
3335
  ]);
3263
3336
  }
@@ -3283,7 +3356,7 @@ function insertReturn(node) {
3283
3356
  if (exp.type === "LabelledStatement") {
3284
3357
  exp = exp.statement;
3285
3358
  }
3286
- let ref11;
3359
+ let ref13;
3287
3360
  let m3;
3288
3361
  switch (exp.type) {
3289
3362
  case "BreakStatement":
@@ -3295,14 +3368,14 @@ function insertReturn(node) {
3295
3368
  return;
3296
3369
  }
3297
3370
  case "Declaration": {
3298
- let ref12;
3371
+ let ref14;
3299
3372
  if (exp.bindings?.length) {
3300
- ref12 = [" ", patternAsValue((ref11 = exp.bindings)[ref11.length - 1].pattern)];
3373
+ ref14 = [" ", patternAsValue((ref13 = exp.bindings)[ref13.length - 1].pattern)];
3301
3374
  } else {
3302
- ref12 = [];
3375
+ ref14 = [];
3303
3376
  }
3304
3377
  ;
3305
- const value = ref12;
3378
+ const value = ref14;
3306
3379
  const parent = outer.parent;
3307
3380
  const index = findChildIndex(parent?.expressions, outer);
3308
3381
  assert.notEqual(index, -1, "Could not find declaration in parent");
@@ -3362,15 +3435,15 @@ function insertReturn(node) {
3362
3435
  return;
3363
3436
  }
3364
3437
  case "SwitchStatement": {
3365
- for (let ref13 = exp.caseBlock.clauses, i6 = 0, len5 = ref13.length; i6 < len5; i6++) {
3366
- const clause = ref13[i6];
3438
+ for (let ref15 = exp.caseBlock.clauses, i7 = 0, len6 = ref15.length; i7 < len6; i7++) {
3439
+ const clause = ref15[i7];
3367
3440
  insertReturn(clause);
3368
3441
  }
3369
3442
  return;
3370
3443
  }
3371
3444
  case "TryStatement": {
3372
- for (let ref14 = exp.blocks, i7 = 0, len6 = ref14.length; i7 < len6; i7++) {
3373
- const block = ref14[i7];
3445
+ for (let ref16 = exp.blocks, i8 = 0, len7 = ref16.length; i8 < len7; i8++) {
3446
+ const block = ref16[i8];
3374
3447
  insertReturn(block);
3375
3448
  }
3376
3449
  return;
@@ -3622,9 +3695,9 @@ function iterationDefaultBody(statement) {
3622
3695
  }
3623
3696
  const reduction = statement.type === "ForStatement" && statement.reduction;
3624
3697
  function fillBlock(expression) {
3625
- let ref15;
3698
+ let ref17;
3626
3699
  let m5;
3627
- if (m5 = (ref15 = block.expressions)[ref15.length - 1], Array.isArray(m5) && m5.length >= 2 && typeof m5[1] === "object" && m5[1] != null && "type" in m5[1] && m5[1].type === "EmptyStatement" && "implicit" in m5[1] && m5[1].implicit === true) {
3700
+ if (m5 = (ref17 = block.expressions)[ref17.length - 1], Array.isArray(m5) && m5.length >= 2 && typeof m5[1] === "object" && m5[1] != null && "type" in m5[1] && m5[1].type === "EmptyStatement" && "implicit" in m5[1] && m5[1].implicit === true) {
3628
3701
  block.expressions.pop();
3629
3702
  }
3630
3703
  block.expressions.push(expression);
@@ -3694,8 +3767,8 @@ function processParams(f) {
3694
3767
  function append2(p) {
3695
3768
  (rest ? after : before).push(p);
3696
3769
  }
3697
- for (let ref16 = parameters.parameters, i8 = 0, len7 = ref16.length; i8 < len7; i8++) {
3698
- const param = ref16[i8];
3770
+ for (let ref18 = parameters.parameters, i9 = 0, len8 = ref18.length; i9 < len8; i9++) {
3771
+ const param = ref18[i9];
3699
3772
  switch (param.type) {
3700
3773
  case "ThisType": {
3701
3774
  if (tt) {
@@ -3707,8 +3780,8 @@ function processParams(f) {
3707
3780
  } else {
3708
3781
  tt = trimFirstSpace(param);
3709
3782
  if (before.length || rest) {
3710
- let ref17;
3711
- let delim = (ref17 = tt.children)[ref17.length - 1];
3783
+ let ref19;
3784
+ let delim = (ref19 = tt.children)[ref19.length - 1];
3712
3785
  if (Array.isArray(delim)) {
3713
3786
  delim = delim[delim.length - 1];
3714
3787
  }
@@ -3900,14 +3973,14 @@ function processParams(f) {
3900
3973
  index2--;
3901
3974
  }
3902
3975
  const fStatement = classExpressions[index2];
3903
- for (let ref18 = gatherRecursive(parameters, ($14) => $14.type === "Parameter"), i9 = 0, len8 = ref18.length; i9 < len8; i9++) {
3904
- const parameter = ref18[i9];
3976
+ for (let ref20 = gatherRecursive(parameters, ($14) => $14.type === "Parameter"), i10 = 0, len9 = ref20.length; i10 < len9; i10++) {
3977
+ const parameter = ref20[i10];
3905
3978
  const { accessModifier } = parameter;
3906
3979
  if (!(accessModifier || parameter.typeSuffix)) {
3907
3980
  continue;
3908
3981
  }
3909
- for (let ref19 = gatherRecursive(parameter, ($15) => $15.type === "AtBinding"), i10 = 0, len9 = ref19.length; i10 < len9; i10++) {
3910
- const binding = ref19[i10];
3982
+ for (let ref21 = gatherRecursive(parameter, ($15) => $15.type === "AtBinding"), i11 = 0, len10 = ref21.length; i11 < len10; i11++) {
3983
+ const binding = ref21[i11];
3911
3984
  const typeSuffix = binding.parent?.typeSuffix;
3912
3985
  if (!(accessModifier || typeSuffix)) {
3913
3986
  continue;
@@ -3945,8 +4018,8 @@ function processParams(f) {
3945
4018
  decl: "const"
3946
4019
  }));
3947
4020
  }
3948
- for (let ref20 = splices, i11 = 0, len10 = ref20.length; i11 < len10; i11++) {
3949
- const binding = ref20[i11];
4021
+ for (let ref22 = splices, i12 = 0, len11 = ref22.length; i12 < len11; i12++) {
4022
+ const binding = ref22[i12];
3950
4023
  assert.equal(binding.type, "PostRestBindingElements", "splice should be of type Binding");
3951
4024
  prefix.push(makeNode({
3952
4025
  type: "Declaration",
@@ -3998,8 +4071,8 @@ function processSignature(f) {
3998
4071
  f.async.push("async ");
3999
4072
  signature.modifier.async = true;
4000
4073
  } else {
4001
- for (let ref21 = gatherRecursiveWithinFunction(block, ($17) => $17.type === "Await"), i12 = 0, len11 = ref21.length; i12 < len11; i12++) {
4002
- const a = ref21[i12];
4074
+ for (let ref23 = gatherRecursiveWithinFunction(block, ($17) => $17.type === "Await"), i13 = 0, len12 = ref23.length; i13 < len12; i13++) {
4075
+ const a = ref23[i13];
4003
4076
  const i = findChildIndex(a.parent, a);
4004
4077
  a.parent.children.splice(i + 1, 0, {
4005
4078
  type: "Error",
@@ -4013,8 +4086,8 @@ function processSignature(f) {
4013
4086
  f.generator.push("*");
4014
4087
  signature.modifier.generator = true;
4015
4088
  } else {
4016
- for (let ref22 = gatherRecursiveWithinFunction(block, ($18) => $18.type === "YieldExpression"), i13 = 0, len12 = ref22.length; i13 < len12; i13++) {
4017
- const y = ref22[i13];
4089
+ for (let ref24 = gatherRecursiveWithinFunction(block, ($18) => $18.type === "YieldExpression"), i14 = 0, len13 = ref24.length; i14 < len13; i14++) {
4090
+ const y = ref24[i14];
4018
4091
  const i = y.children.findIndex(($19) => $19.type === "Yield");
4019
4092
  y.children.splice(i + 1, 0, {
4020
4093
  type: "Error",
@@ -4032,8 +4105,8 @@ function processSignature(f) {
4032
4105
  }
4033
4106
  }
4034
4107
  function processFunctions(statements, config2) {
4035
- for (let ref23 = gatherRecursiveAll(statements, ($20) => $20.type === "FunctionExpression" || $20.type === "ArrowFunction" || $20.type === "MethodDefinition"), i14 = 0, len13 = ref23.length; i14 < len13; i14++) {
4036
- const f = ref23[i14];
4108
+ for (let ref25 = gatherRecursiveAll(statements, ($20) => $20.type === "FunctionExpression" || $20.type === "ArrowFunction" || $20.type === "MethodDefinition"), i15 = 0, len14 = ref25.length; i15 < len14; i15++) {
4109
+ const f = ref25[i15];
4037
4110
  if (f.type === "FunctionExpression" || f.type === "MethodDefinition") {
4038
4111
  implicitFunctionBlock(f);
4039
4112
  }
@@ -4092,9 +4165,9 @@ function expressionizeIteration(exp) {
4092
4165
  }
4093
4166
  let done;
4094
4167
  if (!async) {
4095
- let ref24;
4096
- if ((ref24 = blockContainingStatement(exp)) && typeof ref24 === "object" && "block" in ref24 && "index" in ref24) {
4097
- const { block: parentBlock, index } = ref24;
4168
+ let ref26;
4169
+ if ((ref26 = blockContainingStatement(exp)) && typeof ref26 === "object" && "block" in ref26 && "index" in ref26) {
4170
+ const { block: parentBlock, index } = ref26;
4098
4171
  statements[0][0] = parentBlock.expressions[index][0];
4099
4172
  parentBlock.expressions.splice(index, index + 1 - index, ...statements);
4100
4173
  updateParentPointers(parentBlock);
@@ -4111,8 +4184,8 @@ function expressionizeIteration(exp) {
4111
4184
  }
4112
4185
  }
4113
4186
  function processIterationExpressions(statements) {
4114
- for (let ref25 = gatherRecursiveAll(statements, ($21) => $21.type === "IterationExpression"), i15 = 0, len14 = ref25.length; i15 < len14; i15++) {
4115
- const s = ref25[i15];
4187
+ for (let ref27 = gatherRecursiveAll(statements, ($21) => $21.type === "IterationExpression"), i16 = 0, len15 = ref27.length; i16 < len15; i16++) {
4188
+ const s = ref27[i16];
4116
4189
  expressionizeIteration(s);
4117
4190
  }
4118
4191
  }
@@ -4136,12 +4209,12 @@ function processCoffeeDo(ws, expression) {
4136
4209
  let { parameters } = expression;
4137
4210
  const parameterList = parameters.parameters;
4138
4211
  const results1 = [];
4139
- for (let i16 = 0, len15 = parameterList.length; i16 < len15; i16++) {
4140
- let parameter = parameterList[i16];
4212
+ for (let i17 = 0, len16 = parameterList.length; i17 < len16; i17++) {
4213
+ let parameter = parameterList[i17];
4141
4214
  if (typeof parameter === "object" && parameter != null && "type" in parameter && parameter.type === "Parameter") {
4142
- let ref26;
4143
- if (ref26 = parameter.initializer) {
4144
- const initializer = ref26;
4215
+ let ref28;
4216
+ if (ref28 = parameter.initializer) {
4217
+ const initializer = ref28;
4145
4218
  args.push(initializer.expression, parameter.delim);
4146
4219
  parameter = {
4147
4220
  ...parameter,
@@ -4271,8 +4344,9 @@ function unbraceBlock(block) {
4271
4344
  if (block.bare) {
4272
4345
  return;
4273
4346
  }
4347
+ let m;
4274
4348
  let ref;
4275
- if (block.children[0] === " {" && (ref = block.children)[ref.length - 1] === "}") {
4349
+ if ((m = block.children[0], m === " {" || m === "{") && (ref = block.children)[ref.length - 1] === "}") {
4276
4350
  block.children.shift();
4277
4351
  block.children.pop();
4278
4352
  block.bare = true;
@@ -4308,17 +4382,6 @@ function makeEmptyBlock() {
4308
4382
  empty: true
4309
4383
  };
4310
4384
  }
4311
- function makeBlockFragment() {
4312
- const expressions = [];
4313
- return {
4314
- type: "BlockStatement",
4315
- children: expressions,
4316
- parent: void 0,
4317
- expressions,
4318
- bare: false,
4319
- root: false
4320
- };
4321
- }
4322
4385
  function replaceBlockExpression(node, child, replacement) {
4323
4386
  let found = false;
4324
4387
  const { expressions } = node;
@@ -4364,22 +4427,44 @@ function hoistRefDecs(statements) {
4364
4427
  });
4365
4428
  }
4366
4429
  function insertHoistDec(block, node, dec) {
4367
- const { expressions } = block;
4368
- const index = findChildIndex(expressions, node);
4430
+ const statement = ["", dec, ";"];
4431
+ insertBeforeInBlock(block, node, statement);
4432
+ }
4433
+ function insertBeforeInBlock(block, node, ...statements) {
4434
+ const index = findChildIndex(block.expressions, node);
4369
4435
  if (index < 0) {
4370
- throw new Error("Couldn't find expression in block for hoistable declaration.");
4436
+ throw new Error("insertBeforeInBlock couldn't find existing statement in block");
4371
4437
  }
4372
- const statement = [expressions[index][0], dec, ";"];
4373
- expressions[index][0] = "";
4374
- expressions.splice(index, 0, statement);
4375
- updateParentPointers(dec, block);
4438
+ insertBlockStatements(block, index, ...statements);
4439
+ }
4440
+ function insertBlockStatements(block, index, ...statements) {
4441
+ if (!statements.length) {
4442
+ return;
4443
+ }
4444
+ const { expressions } = block;
4445
+ const before = expressions[index];
4446
+ if (statements[0][0] && before?.[0]) {
4447
+ if (!Array.isArray(statements[0][0])) {
4448
+ statements[0][0] = [statements[0][0]];
4449
+ }
4450
+ if (!Array.isArray(before[0])) {
4451
+ before[0] = [before[0]];
4452
+ }
4453
+ statements[0][0] = [...before[0], ...statements[0][0]];
4454
+ } else {
4455
+ statements[0][0] ||= before?.[0];
4456
+ }
4457
+ before[0] = "";
4458
+ expressions.splice(index, 0, ...statements);
4459
+ updateParentPointers(block);
4460
+ braceBlock(block);
4376
4461
  }
4377
4462
  function processBlocks(statements) {
4378
4463
  insertSemicolon(statements);
4379
4464
  for (let ref1 = gatherRecursive(statements, ($) => $.type === "BlockStatement"), i2 = 0, len12 = ref1.length; i2 < len12; i2++) {
4380
4465
  const block = ref1[i2];
4381
- let m;
4382
- if (block.unwrapObject && block.expressions.length === 1 && (m = block.expressions[0][1], typeof m === "object" && m != null && "type" in m && m.type === "ParenthesizedExpression" && "implicit" in m && m.implicit === true && "expression" in m && typeof m.expression === "object" && m.expression != null && "type" in m.expression && m.expression.type === "ObjectExpression")) {
4466
+ let m1;
4467
+ if (block.unwrapObject && block.expressions.length === 1 && (m1 = block.expressions[0][1], typeof m1 === "object" && m1 != null && "type" in m1 && m1.type === "ParenthesizedExpression" && "implicit" in m1 && m1.implicit === true && "expression" in m1 && typeof m1.expression === "object" && m1.expression != null && "type" in m1.expression && m1.expression.type === "ObjectExpression")) {
4383
4468
  const object = block.expressions[0][1].expression;
4384
4469
  if (!(() => {
4385
4470
  let results = true;
@@ -4398,8 +4483,8 @@ function processBlocks(statements) {
4398
4483
  for (let ref2 = object.properties, i3 = 0, len22 = ref2.length; i3 < len22; i3++) {
4399
4484
  const i = i3;
4400
4485
  const prop = ref2[i3];
4401
- let m1;
4402
- if (m1 = prop.name, typeof m1 === "object" && m1 != null && "type" in m1 && m1.type === "ComputedPropertyName" && "implicit" in m1 && m1.implicit === true) {
4486
+ let m2;
4487
+ if (m2 = prop.name, typeof m2 === "object" && m2 != null && "type" in m2 && m2.type === "ComputedPropertyName" && "implicit" in m2 && m2.implicit === true) {
4403
4488
  replaceNode(prop.name, prop.name.expression, prop);
4404
4489
  }
4405
4490
  if (prop.delim?.implicit) {
@@ -4492,8 +4577,8 @@ function needsPrecedingSemicolon(exp) {
4492
4577
  function blockContainingStatement(exp) {
4493
4578
  let child = exp;
4494
4579
  let parent = exp.parent;
4495
- let m2;
4496
- while (parent != null && (m2 = parent.type, m2 === "StatementExpression" || m2 === "PipelineExpression" || m2 === "UnwrappedExpression")) {
4580
+ let m3;
4581
+ while (parent != null && (m3 = parent.type, m3 === "StatementExpression" || m3 === "PipelineExpression" || m3 === "UnwrappedExpression")) {
4497
4582
  child = parent;
4498
4583
  parent = parent.parent;
4499
4584
  }
@@ -4568,6 +4653,19 @@ function getPrecedence(op) {
4568
4653
  return precedenceMap.get(op.prec ?? op.token) ?? (op.relational ? precedenceRelational : precedenceCustomDefault);
4569
4654
  }
4570
4655
  }
4656
+ function isShortCircuitOp(op) {
4657
+ if (op && typeof op === "object" && "token" in op) {
4658
+ const { token } = op;
4659
+ return isShortCircuitOp(token);
4660
+ } else if (typeof op === "string") {
4661
+ if (op.endsWith("=") && !op.endsWith("==")) {
4662
+ op = op.slice(0, -1);
4663
+ }
4664
+ return op === "||" || op === "&&" || op === "??";
4665
+ } else {
4666
+ return false;
4667
+ }
4668
+ }
4571
4669
  function processBinaryOpExpression($0) {
4572
4670
  return processExpandedBinaryOpExpression(expandChainedComparisons($0));
4573
4671
  }
@@ -5433,22 +5531,23 @@ function processDeclarations(statements) {
5433
5531
  if (typeSuffix && typeSuffix.optional) {
5434
5532
  if (initializer && !typeSuffix.t) {
5435
5533
  const expression = trimFirstSpace(initializer.expression);
5436
- let m;
5437
- if (m = expression.type, m === "Identifier" || m === "MemberExpression") {
5438
- typeSuffix.children.push(": ", typeSuffix.t = {
5439
- type: "TypeTypeof",
5440
- children: ["typeof ", expression],
5441
- expression
5442
- });
5443
- } else if (expression.type === "Literal" || expression.type === "RegularExpressionLiteral" || expression.type === "TemplateLiteral") {
5444
- typeSuffix.children.push(": ", typeSuffix.t = literalType(expression));
5445
- } else {
5534
+ typeSuffix.t = typeOfExpression(expression);
5535
+ if (!(typeSuffix.t != null)) {
5446
5536
  spliceChild(binding, typeSuffix, 1, {
5447
5537
  type: "Error",
5448
- message: `Optional type can only be inferred from literals or member expressions, not ${expression.type}`
5538
+ message: (() => {
5539
+ if (typeof expression === "object" && expression != null && "type" in expression && expression.type === "Literal" && "subtype" in expression && expression.subtype === "NullLiteral") {
5540
+ return "Optional type can't be inferred from null";
5541
+ } else if (typeof expression === "object" && expression != null && "type" in expression && expression.type === "Identifier" && "name" in expression && expression.name === "undefined") {
5542
+ return "Optional type can't be inferred from undefined";
5543
+ } else {
5544
+ return `Optional type can only be inferred from literals or member expressions, not ${expression.type}`;
5545
+ }
5546
+ })()
5449
5547
  });
5450
5548
  continue;
5451
5549
  }
5550
+ typeSuffix.children.push(": ", typeSuffix.t);
5452
5551
  }
5453
5552
  if (typeSuffix.t) {
5454
5553
  convertOptionalType(typeSuffix);
@@ -5489,16 +5588,16 @@ function processDeclarations(statements) {
5489
5588
  function prependStatementExpressionBlock(initializer, statement) {
5490
5589
  let { expression: exp } = initializer;
5491
5590
  let ws;
5492
- if (Array.isArray(exp)) {
5591
+ if (Array.isArray(exp) && exp.length === 2 && isWhitespaceOrEmpty(exp[0])) {
5493
5592
  ws = exp[0];
5494
5593
  exp = exp[1];
5495
5594
  }
5496
5595
  if (!(typeof exp === "object" && exp != null && "type" in exp && exp.type === "StatementExpression" || typeof exp === "object" && exp != null && "type" in exp && exp.type === "SpreadElement" && "expression" in exp && typeof exp.expression === "object" && exp.expression != null && "type" in exp.expression && exp.expression.type === "StatementExpression")) {
5497
5596
  return;
5498
5597
  }
5499
- const pre = [];
5500
5598
  const statementExp = exp.statement;
5501
5599
  const blockStatement = [ws || "", statementExp, ";"];
5600
+ const pre = [blockStatement];
5502
5601
  let ref;
5503
5602
  if (statementExp.type === "IterationExpression") {
5504
5603
  if (statementExp.async || statementExp.generator) {
@@ -5514,8 +5613,7 @@ function prependStatementExpressionBlock(initializer, statement) {
5514
5613
  assignResults(blockStatement, (resultNode) => {
5515
5614
  return makeNode({
5516
5615
  type: "AssignmentExpression",
5517
- children: [ref, " = ", resultNode],
5518
- parent: statement2
5616
+ children: [ref, " = ", resultNode]
5519
5617
  });
5520
5618
  });
5521
5619
  const refDec = {
@@ -5532,8 +5630,7 @@ function prependStatementExpressionBlock(initializer, statement) {
5532
5630
  assignResults(blockStatement, (resultNode) => {
5533
5631
  return makeNode({
5534
5632
  type: "AssignmentExpression",
5535
- children: [ref, " = ", resultNode],
5536
- parent: statement
5633
+ children: [ref, " = ", resultNode]
5537
5634
  });
5538
5635
  });
5539
5636
  const refDec = {
@@ -5542,8 +5639,12 @@ function prependStatementExpressionBlock(initializer, statement) {
5542
5639
  };
5543
5640
  pre.unshift(["", refDec, ";"]);
5544
5641
  }
5545
- statement.children.unshift(...pre, blockStatement);
5546
- updateParentPointers(blockStatement, statement);
5642
+ let ref3;
5643
+ if (!((ref3 = blockContainingStatement(statement)) && typeof ref3 === "object" && "block" in ref3 && "index" in ref3)) {
5644
+ throw new Error("Couldn't find block in prependStatementExpressionBlock");
5645
+ }
5646
+ const { block, index } = ref3;
5647
+ insertBlockStatements(block, index, ...pre);
5547
5648
  return ref;
5548
5649
  }
5549
5650
  function processDeclarationCondition(condition, rootCondition, parent) {
@@ -5642,8 +5743,8 @@ function processDeclarationConditionStatement(s) {
5642
5743
  if (conditions.length) {
5643
5744
  let children = condition.children;
5644
5745
  if (s.negated) {
5645
- let m1;
5646
- if (!(m1 = condition.expression, typeof m1 === "object" && m1 != null && "type" in m1 && m1.type === "UnaryExpression" && "children" in m1 && Array.isArray(m1.children) && len2(m1.children, 2) && Array.isArray(m1.children[0]) && len2(m1.children[0], 1) && m1.children[0][0] === "!" && typeof m1.children[1] === "object" && m1.children[1] != null && "type" in m1.children[1] && m1.children[1].type === "ParenthesizedExpression")) {
5746
+ let m;
5747
+ if (!(m = condition.expression, typeof m === "object" && m != null && "type" in m && m.type === "UnaryExpression" && "children" in m && Array.isArray(m.children) && len2(m.children, 2) && Array.isArray(m.children[0]) && len2(m.children[0], 1) && m.children[0][0] === "!" && typeof m.children[1] === "object" && m.children[1] != null && "type" in m.children[1] && m.children[1].type === "ParenthesizedExpression")) {
5647
5748
  throw new Error("Unsupported negated condition");
5648
5749
  }
5649
5750
  ;
@@ -5673,11 +5774,11 @@ function processDeclarationConditionStatement(s) {
5673
5774
  ancestor.expressions.splice(index + 1, 0, ...blockPrefix);
5674
5775
  updateParentPointers(ancestor);
5675
5776
  braceBlock(ancestor);
5676
- let ref3;
5777
+ let ref4;
5677
5778
  switch (s.type) {
5678
5779
  case "IfStatement": {
5679
- if (ref3 = s.else?.block) {
5680
- const elseBlock = ref3;
5780
+ if (ref4 = s.else?.block) {
5781
+ const elseBlock = ref4;
5681
5782
  if (elseBlock.bare && !elseBlock.semicolon) {
5682
5783
  elseBlock.children.push(elseBlock.semicolon = ";");
5683
5784
  }
@@ -5729,38 +5830,19 @@ function processDeclarationConditionStatement(s) {
5729
5830
  if (!blockPrefix) {
5730
5831
  return;
5731
5832
  }
5732
- const newCondition = {
5733
- type: "ParenthesizedExpression",
5734
- children: ["(", ref2, ")"],
5735
- expression: ref2,
5736
- parent: s
5737
- };
5738
- s.children = s.children.map(function(c) {
5739
- if (c === s.condition) {
5740
- return newCondition;
5741
- } else {
5742
- return c;
5743
- }
5744
- });
5745
- s.condition = newCondition;
5746
- updateParentPointers(s);
5747
- if (statementDeclaration) {
5748
- const block = makeEmptyBlock();
5749
- replaceBlockExpression(s.parent, s, block);
5750
- block.expressions.push(["", s]);
5751
- s.children.splice(s.children.findIndex(($5) => $5.token === "switch"), 0, blockPrefix);
5752
- s.parent = block;
5753
- } else {
5754
- const block = blockWithPrefix([["", [{
5833
+ replaceNode(s.condition, parenthesizeExpression(ref2), s);
5834
+ if (!statementDeclaration) {
5835
+ const declStatement = ["", [{
5755
5836
  type: "Declaration",
5756
5837
  children: ["let ", ...condition.expression.children]
5757
- }], ";"], ...blockPrefix], makeEmptyBlock());
5758
- updateParentPointers(block, s.parent);
5759
- replaceBlockExpression(s.parent, s, block);
5760
- block.expressions.push(["", s]);
5761
- s.parent = block;
5762
- }
5763
- ;
5838
+ }], ";"];
5839
+ blockPrefix.unshift(declStatement);
5840
+ }
5841
+ const block = blockWithPrefix(blockPrefix, makeEmptyBlock());
5842
+ updateParentPointers(block, s.parent);
5843
+ replaceBlockExpression(s.parent, s, block);
5844
+ block.expressions.push(["", s]);
5845
+ s.parent = block;
5764
5846
  break;
5765
5847
  }
5766
5848
  }
@@ -5768,12 +5850,12 @@ function processDeclarationConditionStatement(s) {
5768
5850
  function dynamizeFromClause(from) {
5769
5851
  from = from.slice(1);
5770
5852
  from = trimFirstSpace(from);
5771
- let ref4;
5772
- if (ref4 = from[from.length - 1]?.assertion) {
5773
- const assert2 = ref4;
5774
- let ref5;
5775
- ref5 = from[from.length - 1];
5776
- ref5.children = ref5.children.filter((a2) => a2 !== assert2);
5853
+ let ref5;
5854
+ if (ref5 = from[from.length - 1]?.assertion) {
5855
+ const assert2 = ref5;
5856
+ let ref6;
5857
+ ref6 = from[from.length - 1];
5858
+ ref6.children = ref6.children.filter((a2) => a2 !== assert2);
5777
5859
  from.push(", {", assert2.keyword, ":", assert2.object, "}");
5778
5860
  }
5779
5861
  return ["(", ...from, ")"];
@@ -5782,20 +5864,20 @@ function dynamizeImportDeclaration(decl) {
5782
5864
  const { imports } = decl;
5783
5865
  let { star, binding, specifiers } = imports;
5784
5866
  const justDefault = binding && !specifiers && !star;
5785
- let ref6;
5867
+ let ref7;
5786
5868
  {
5787
5869
  if (binding) {
5788
5870
  if (specifiers) {
5789
- ref6 = makeRef();
5871
+ ref7 = makeRef();
5790
5872
  } else {
5791
- ref6 = binding;
5873
+ ref7 = binding;
5792
5874
  }
5793
5875
  } else {
5794
- ref6 = convertNamedImportsToObject(imports, true);
5876
+ ref7 = convertNamedImportsToObject(imports, true);
5795
5877
  }
5796
5878
  }
5797
5879
  ;
5798
- const pattern = ref6;
5880
+ const pattern = ref7;
5799
5881
  const c = "const";
5800
5882
  const expression = [
5801
5883
  justDefault ? "(" : void 0,
@@ -6786,7 +6868,7 @@ function processForInOf($0) {
6786
6868
  var concatAssign2 = (lhs, rhs) => (rhs?.[Symbol.isConcatSpreadable] ?? Array.isArray(rhs) ? lhs.push.apply(lhs, rhs) : lhs.push(rhs), lhs);
6787
6869
  function findDecs(statements) {
6788
6870
  const declarations = gatherNodes(statements, ($) => $.type === "Declaration");
6789
- const declarationNames = declarations.flatMap((d) => d.names);
6871
+ const declarationNames = declarations.flatMap(($1) => $1.names);
6790
6872
  const globals = getConfig().globals || [];
6791
6873
  return new Set(globals.concat(declarationNames));
6792
6874
  }
@@ -6794,16 +6876,16 @@ function createConstLetDecs(statements, scopes, letOrConst) {
6794
6876
  function findVarDecs(statements2, decs) {
6795
6877
  const declarationNames = gatherRecursive(statements2, (node) => {
6796
6878
  return node.type === "Declaration" && node.children && node.children.length > 0 && node.children[0].token && node.children[0].token.startsWith("var") || node.type === "FunctionExpression";
6797
- }).filter((node) => node.type === "Declaration").flatMap((node) => node.names);
6879
+ }).filter(($2) => $2.type === "Declaration").flatMap(($3) => $3.names);
6798
6880
  return new Set(declarationNames);
6799
6881
  }
6800
6882
  let declaredIdentifiers = findVarDecs(statements);
6801
6883
  function hasDec(name) {
6802
- return declaredIdentifiers.has(name) || scopes.some(($1) => $1.has(name));
6884
+ return declaredIdentifiers.has(name) || scopes.some(($4) => $4.has(name));
6803
6885
  }
6804
6886
  function gatherBlockOrOther(statement) {
6805
- return gatherNodes(statement, (s) => s.type === "BlockStatement" || s.type === "AssignmentExpression" || s.type === "Declaration").flatMap((node) => {
6806
- if (node.type == "BlockStatement") {
6887
+ return gatherNodes(statement, ($5) => $5.type === "BlockStatement" || $5.type === "AssignmentExpression" || $5.type === "Declaration").flatMap((node) => {
6888
+ if (node.type === "BlockStatement") {
6807
6889
  return node.bare ? gatherBlockOrOther(node.expressions) : node;
6808
6890
  } else if (node.children && node.children.length) {
6809
6891
  return [...gatherBlockOrOther(node.children), node];
@@ -6815,16 +6897,18 @@ function createConstLetDecs(statements, scopes, letOrConst) {
6815
6897
  let currentScope = /* @__PURE__ */ new Set();
6816
6898
  scopes.push(currentScope);
6817
6899
  const fnNodes = gatherNodes(statements, isFunction);
6818
- const forNodes = gatherNodes(statements, (s) => s.type === "ForStatement");
6900
+ const forNodes = gatherNodes(statements, ($6) => $6.type === "ForStatement");
6819
6901
  let targetStatements = [];
6820
- for (const statement of statements) {
6902
+ for (let i1 = 0, len3 = statements.length; i1 < len3; i1++) {
6903
+ const statement = statements[i1];
6821
6904
  const nodes = gatherBlockOrOther(statement);
6822
6905
  let undeclaredIdentifiers = [];
6823
- for (const node of nodes) {
6824
- if (node.type == "BlockStatement") {
6906
+ for (let i2 = 0, len12 = nodes.length; i2 < len12; i2++) {
6907
+ const node = nodes[i2];
6908
+ if (node.type === "BlockStatement") {
6825
6909
  let block = node;
6826
- let fnNode = fnNodes.find((fnNode2) => fnNode2.block === block);
6827
- let forNode = forNodes.find((forNode2) => forNode2.block === block);
6910
+ let fnNode = fnNodes.find(($7) => $7.block === block);
6911
+ let forNode = forNodes.find(($8) => $8.block === block);
6828
6912
  if (fnNode != null) {
6829
6913
  scopes.push(new Set(fnNode.parameters.names));
6830
6914
  createConstLetDecs(block.expressions, scopes, letOrConst);
@@ -6838,21 +6922,26 @@ function createConstLetDecs(statements, scopes, letOrConst) {
6838
6922
  }
6839
6923
  continue;
6840
6924
  }
6841
- if (node.names == null) continue;
6842
- let names = node.names.filter((name) => !hasDec(name));
6843
- if (node.type == "AssignmentExpression") {
6925
+ if (!(node.names != null)) {
6926
+ continue;
6927
+ }
6928
+ const names = node.names.filter((name) => !hasDec(name));
6929
+ if (node.type === "AssignmentExpression") {
6844
6930
  undeclaredIdentifiers.push(...names);
6845
6931
  }
6846
- names.forEach((name) => currentScope.add(name));
6932
+ for (let i3 = 0, len22 = names.length; i3 < len22; i3++) {
6933
+ const name = names[i3];
6934
+ currentScope.add(name);
6935
+ }
6847
6936
  }
6848
- if (undeclaredIdentifiers.length > 0) {
6937
+ if (undeclaredIdentifiers.length) {
6849
6938
  let indent = statement[0];
6850
- let firstIdentifier = gatherNodes(statement[1], (node) => node.type == "Identifier")[0];
6851
- if (undeclaredIdentifiers.length == 1 && statement[1].type == "AssignmentExpression" && statement[1].names.length == 1 && statement[1].names[0] == undeclaredIdentifiers[0] && firstIdentifier && firstIdentifier.names == undeclaredIdentifiers[0] && gatherNodes(statement[1], (node) => node.type === "ObjectBindingPattern").length == 0) {
6939
+ let firstIdentifier = gatherNodes(statement[1], ($9) => $9.type === "Identifier")[0];
6940
+ if (undeclaredIdentifiers.length === 1 && statement[1].type === "AssignmentExpression" && statement[1].names.length === 1 && statement[1].names[0] === undeclaredIdentifiers[0] && firstIdentifier && firstIdentifier.names == undeclaredIdentifiers[0] && gatherNodes(statement[1], ($10) => $10.type === "ObjectBindingPattern").length === 0) {
6852
6941
  statement[1].children.unshift([`${letOrConst} `]);
6853
6942
  } else {
6854
6943
  let tail = "\n";
6855
- if (gatherNodes(indent, (node) => node.token && node.token.endsWith("\n")).length > 0) {
6944
+ if (gatherNodes(indent, ($11) => $11.token && $11.token.endsWith("\n")).length) {
6856
6945
  tail = void 0;
6857
6946
  }
6858
6947
  targetStatements.push([indent, {
@@ -6869,17 +6958,17 @@ function createConstLetDecs(statements, scopes, letOrConst) {
6869
6958
  }
6870
6959
  function createVarDecs(block, scopes, pushVar) {
6871
6960
  function hasDec(name) {
6872
- return scopes.some(($2) => $2.has(name));
6961
+ return scopes.some(($12) => $12.has(name));
6873
6962
  }
6874
6963
  function findAssignments(statements2, decs2) {
6875
- let assignmentStatements2 = gatherNodes(statements2, ($3) => $3.type === "AssignmentExpression");
6964
+ let assignmentStatements2 = gatherNodes(statements2, ($13) => $13.type === "AssignmentExpression");
6876
6965
  if (assignmentStatements2.length) {
6877
6966
  concatAssign2(
6878
6967
  assignmentStatements2,
6879
6968
  findAssignments(assignmentStatements2.map((s) => s.children), decs2)
6880
6969
  );
6881
6970
  }
6882
- return assignmentStatements2.filter(($4) => !($4.parent?.type === "CoffeeClassPublic"));
6971
+ return assignmentStatements2.filter(($14) => !($14.parent?.type === "CoffeeClassPublic"));
6883
6972
  }
6884
6973
  pushVar ??= (name) => {
6885
6974
  varIds.push(name);
@@ -6890,7 +6979,7 @@ function createVarDecs(block, scopes, pushVar) {
6890
6979
  scopes.push(decs);
6891
6980
  const varIds = [];
6892
6981
  const assignmentStatements = findAssignments(statements, scopes);
6893
- const undeclaredIdentifiers = assignmentStatements.flatMap(($5) => $5?.names || []);
6982
+ const undeclaredIdentifiers = assignmentStatements.flatMap(($15) => $15?.names || []);
6894
6983
  undeclaredIdentifiers.filter((x, i, a) => {
6895
6984
  if (!hasDec(x)) return a.indexOf(x) === i;
6896
6985
  return;
@@ -8056,23 +8145,20 @@ function processAssignments(statements) {
8056
8145
  continue;
8057
8146
  }
8058
8147
  let { lhs: $1, expression: $2 } = exp, tail = [], len3 = $1.length;
8059
- let block;
8060
8148
  let ref13;
8061
- if (blockContainingStatement(exp) && !(ref13 = $1[$1.length - 1])?.[ref13.length - 1]?.special) {
8062
- block = makeBlockFragment();
8063
- let ref14;
8064
- if (ref14 = prependStatementExpressionBlock(
8149
+ let ref14;
8150
+ if (blockContainingStatement(exp) && !(ref13 = $1[$1.length - 1])?.[ref13.length - 1]?.special && !isShortCircuitOp((ref14 = $1[$1.length - 1])?.[ref14.length - 1])) {
8151
+ let ref15;
8152
+ if (ref15 = prependStatementExpressionBlock(
8065
8153
  { type: "Initializer", expression: $2, children: [void 0, void 0, $2] },
8066
- block
8154
+ exp
8067
8155
  )) {
8068
- const ref = ref14;
8069
- exp.children = exp.children.map(($7) => $7 === $2 ? ref : $7);
8156
+ const ref = ref15;
8157
+ replaceNode($2, ref, exp);
8070
8158
  $2 = ref;
8071
- } else {
8072
- block = void 0;
8073
8159
  }
8074
8160
  }
8075
- if ($1.some(($8) => $8[$8.length - 1].special)) {
8161
+ if ($1.some(($7) => $7[$7.length - 1].special)) {
8076
8162
  if ($1.length !== 1) throw new Error("Only one assignment with id= is allowed");
8077
8163
  const [, lhs, , op] = $1[0];
8078
8164
  const { call, omitLhs } = op;
@@ -8144,7 +8230,7 @@ function processAssignments(statements) {
8144
8230
  break;
8145
8231
  } else if (m3 = lhs.type, m3 === "ObjectBindingPattern" || m3 === "ArrayBindingPattern" || m3 === "NamedBindingPattern") {
8146
8232
  processBindingPatternLHS(lhs, tail);
8147
- gatherRecursiveAll(lhs, ($9) => $9.type === "Ref").forEach(refsToDeclare.add.bind(refsToDeclare));
8233
+ gatherRecursiveAll(lhs, ($8) => $8.type === "Ref").forEach(refsToDeclare.add.bind(refsToDeclare));
8148
8234
  }
8149
8235
  }
8150
8236
  i--;
@@ -8176,7 +8262,7 @@ function processAssignments(statements) {
8176
8262
  }
8177
8263
  if (refsToDeclare.size) {
8178
8264
  if (exp.hoistDec) {
8179
- exp.hoistDec.children.push([...refsToDeclare].map(($10) => [",", $10]));
8265
+ exp.hoistDec.children.push([...refsToDeclare].map(($9) => [",", $9]));
8180
8266
  } else {
8181
8267
  exp.hoistDec = {
8182
8268
  type: "Declaration",
@@ -8191,11 +8277,6 @@ function processAssignments(statements) {
8191
8277
  if (index < 0) throw new Error("Assertion error: exp not in AssignmentExpression");
8192
8278
  exp.children.splice(index + 1, 0, ...tail);
8193
8279
  }
8194
- if (block) {
8195
- replaceNode(exp, block);
8196
- block.expressions.push(["", exp]);
8197
- exp.parent = block;
8198
- }
8199
8280
  }
8200
8281
  }
8201
8282
  function unchainOptionalMemberExpression(exp, ref, innerExp) {
@@ -8246,9 +8327,9 @@ function unchainOptionalMemberExpression(exp, ref, innerExp) {
8246
8327
  }
8247
8328
  j++;
8248
8329
  }
8249
- let ref15;
8250
- if (ref15 = conditions.length) {
8251
- const l = ref15;
8330
+ let ref16;
8331
+ if (ref16 = conditions.length) {
8332
+ const l = ref16;
8252
8333
  const cs = flatJoin(conditions, " && ");
8253
8334
  return {
8254
8335
  ...exp,
@@ -8284,8 +8365,8 @@ function attachPostfixStatementAsExpression(exp, post) {
8284
8365
  }
8285
8366
  function processTypes(node) {
8286
8367
  const results1 = [];
8287
- for (let ref16 = gatherRecursiveAll(node, ($11) => $11.type === "TypeUnary"), i8 = 0, len7 = ref16.length; i8 < len7; i8++) {
8288
- const unary = ref16[i8];
8368
+ for (let ref17 = gatherRecursiveAll(node, ($10) => $10.type === "TypeUnary"), i8 = 0, len7 = ref17.length; i8 < len7; i8++) {
8369
+ const unary = ref17[i8];
8289
8370
  let suffixIndex = unary.suffix.length - 1;
8290
8371
  const results2 = [];
8291
8372
  while (suffixIndex >= 0) {
@@ -8364,10 +8445,10 @@ function processTypes(node) {
8364
8445
  const outer = unary.suffix.splice(suffixIndex + 1, Infinity);
8365
8446
  const space = getTrimmingSpace(unary);
8366
8447
  inplaceInsertTrimmingSpace(unary, "");
8367
- let ref17;
8368
- if (unary.suffix.length) ref17 = unary;
8369
- else ref17 = unary.t;
8370
- const t = ref17;
8448
+ let ref18;
8449
+ if (unary.suffix.length) ref18 = unary;
8450
+ else ref18 = unary.t;
8451
+ const t = ref18;
8371
8452
  const arg = makeNode({
8372
8453
  type: "TypeArgument",
8373
8454
  ts: true,
@@ -8412,18 +8493,18 @@ function processTypes(node) {
8412
8493
  return results1;
8413
8494
  }
8414
8495
  function processStatementExpressions(statements) {
8415
- for (let ref18 = gatherRecursiveAll(statements, ($12) => $12.type === "StatementExpression"), i9 = 0, len8 = ref18.length; i9 < len8; i9++) {
8416
- const exp = ref18[i9];
8496
+ for (let ref19 = gatherRecursiveAll(statements, ($11) => $11.type === "StatementExpression"), i9 = 0, len8 = ref19.length; i9 < len8; i9++) {
8497
+ const exp = ref19[i9];
8417
8498
  const { maybe, statement } = exp;
8418
8499
  if ((maybe || statement.type === "ThrowStatement") && blockContainingStatement(exp)) {
8419
8500
  replaceNode(exp, statement);
8420
8501
  continue;
8421
8502
  }
8422
- let ref19;
8503
+ let ref20;
8423
8504
  switch (statement.type) {
8424
8505
  case "IfStatement": {
8425
- if (ref19 = expressionizeIfStatement(statement)) {
8426
- const expression = ref19;
8506
+ if (ref20 = expressionizeIfStatement(statement)) {
8507
+ const expression = ref20;
8427
8508
  replaceNode(statement, expression, exp);
8428
8509
  } else {
8429
8510
  replaceNode(statement, wrapIIFE([["", statement]]), exp);
@@ -8482,13 +8563,13 @@ function processNegativeIndexAccess(statements) {
8482
8563
  });
8483
8564
  }
8484
8565
  function processFinallyClauses(statements) {
8485
- for (let ref20 = gatherRecursiveAll(statements, ($) => $.type === "FinallyClause" && $.parent?.type !== "TryStatement"), i10 = 0, len9 = ref20.length; i10 < len9; i10++) {
8486
- let f = ref20[i10];
8487
- let ref21;
8488
- if (!((ref21 = blockContainingStatement(f)) && typeof ref21 === "object" && "block" in ref21 && "index" in ref21)) {
8566
+ for (let ref21 = gatherRecursiveAll(statements, ($) => $.type === "FinallyClause" && $.parent?.type !== "TryStatement"), i10 = 0, len9 = ref21.length; i10 < len9; i10++) {
8567
+ let f = ref21[i10];
8568
+ let ref22;
8569
+ if (!((ref22 = blockContainingStatement(f)) && typeof ref22 === "object" && "block" in ref22 && "index" in ref22)) {
8489
8570
  throw new Error("finally clause must be inside try statement or block");
8490
8571
  }
8491
- const { block, index } = ref21;
8572
+ const { block, index } = ref22;
8492
8573
  const indent = block.expressions[index][0];
8493
8574
  const expressions = block.expressions.slice(index + 1);
8494
8575
  const t = makeNode({
@@ -8560,11 +8641,11 @@ function processBreaksContinues(statements) {
8560
8641
  }
8561
8642
  }
8562
8643
  function processCoffeeClasses(statements) {
8563
- for (let ref22 = gatherRecursiveAll(statements, ($13) => $13.type === "ClassExpression"), i11 = 0, len10 = ref22.length; i11 < len10; i11++) {
8564
- const ce = ref22[i11];
8644
+ for (let ref23 = gatherRecursiveAll(statements, ($12) => $12.type === "ClassExpression"), i11 = 0, len10 = ref23.length; i11 < len10; i11++) {
8645
+ const ce = ref23[i11];
8565
8646
  const { expressions } = ce.body;
8566
8647
  const indent = expressions[0]?.[0] ?? "\n";
8567
- const autoBinds = expressions.filter(($14) => $14[1]?.autoBind);
8648
+ const autoBinds = expressions.filter(($13) => $13[1]?.autoBind);
8568
8649
  if (autoBinds.length) {
8569
8650
  let construct;
8570
8651
  for (const [, c] of expressions) {
@@ -8613,17 +8694,17 @@ function processCoffeeClasses(statements) {
8613
8694
  })()
8614
8695
  );
8615
8696
  }
8616
- const public_static_function_assignments = expressions.filter(($15) => $15[1]?.type === "CoffeeClassPublic" && $15[1].assignment?.expression?.type === "FunctionExpression").map(($16) => $16[1].assignment);
8697
+ const public_static_function_assignments = expressions.filter(($14) => $14[1]?.type === "CoffeeClassPublic" && $14[1].assignment?.expression?.type === "FunctionExpression").map(($15) => $15[1].assignment);
8617
8698
  for (const public_static_function_assignment of public_static_function_assignments) {
8618
8699
  const id = public_static_function_assignment.lhs[0][1];
8619
8700
  replaceNode(public_static_function_assignment, convertFunctionToMethod(id, public_static_function_assignment.expression));
8620
8701
  }
8621
- const public_static_arrow_function_assignments = expressions.filter(($17) => $17[1]?.type === "CoffeeClassPublic" && $17[1].assignment?.expression?.type === "ArrowFunction").map(($18) => $18[1].assignment);
8702
+ const public_static_arrow_function_assignments = expressions.filter(($16) => $16[1]?.type === "CoffeeClassPublic" && $16[1].assignment?.expression?.type === "ArrowFunction").map(($17) => $17[1].assignment);
8622
8703
  for (const public_static_arrow_function_assignment of public_static_arrow_function_assignments) {
8623
8704
  const id = public_static_arrow_function_assignment.lhs[0][1];
8624
8705
  replaceNode(public_static_arrow_function_assignment, convertArrowFunctionToMethod(id, public_static_arrow_function_assignment.expression));
8625
8706
  }
8626
- const privates = expressions.filter(($19) => $19[1]?.type === "CoffeeClassPrivate");
8707
+ const privates = expressions.filter(($18) => $18[1]?.type === "CoffeeClassPrivate");
8627
8708
  if (!privates.length) {
8628
8709
  continue;
8629
8710
  }
@@ -8688,7 +8769,7 @@ function processProgram(root) {
8688
8769
  root.topLevelYield ? "*" : void 0
8689
8770
  );
8690
8771
  statements = [["", rootIIFE]];
8691
- root.children = root.children.map(($20) => $20 === root.expressions ? statements : $20);
8772
+ root.children = root.children.map(($19) => $19 === root.expressions ? statements : $19);
8692
8773
  root.expressions = statements;
8693
8774
  }
8694
8775
  hoistRefDecs(statements);
@@ -8719,10 +8800,10 @@ async function processProgramAsync(root) {
8719
8800
  await processComptime(statements);
8720
8801
  }
8721
8802
  function processRepl(root, rootIIFE) {
8722
- const topBlock = gatherRecursive(rootIIFE, ($21) => $21.type === "BlockStatement")[0];
8803
+ const topBlock = gatherRecursive(rootIIFE, ($20) => $20.type === "BlockStatement")[0];
8723
8804
  let i = 0;
8724
- for (let ref23 = gatherRecursiveWithinFunction(topBlock, ($22) => $22.type === "Declaration"), i14 = 0, len12 = ref23.length; i14 < len12; i14++) {
8725
- const decl = ref23[i14];
8805
+ for (let ref24 = gatherRecursiveWithinFunction(topBlock, ($21) => $21.type === "Declaration"), i14 = 0, len12 = ref24.length; i14 < len12; i14++) {
8806
+ const decl = ref24[i14];
8726
8807
  if (!decl.names?.length) {
8727
8808
  continue;
8728
8809
  }
@@ -8735,8 +8816,8 @@ function processRepl(root, rootIIFE) {
8735
8816
  root.expressions.splice(i++, 0, ["", `var ${decl.names.join(",")}`, ";"]);
8736
8817
  }
8737
8818
  }
8738
- for (let ref24 = gatherRecursive(topBlock, ($23) => $23.type === "FunctionExpression"), i15 = 0, len13 = ref24.length; i15 < len13; i15++) {
8739
- const func = ref24[i15];
8819
+ for (let ref25 = gatherRecursive(topBlock, ($22) => $22.type === "FunctionExpression"), i15 = 0, len13 = ref25.length; i15 < len13; i15++) {
8820
+ const func = ref25[i15];
8740
8821
  if (func.name && func.parent?.type === "BlockStatement") {
8741
8822
  if (func.parent === topBlock) {
8742
8823
  replaceNode(func, void 0);
@@ -8748,8 +8829,8 @@ function processRepl(root, rootIIFE) {
8748
8829
  }
8749
8830
  }
8750
8831
  }
8751
- for (let ref25 = gatherRecursiveWithinFunction(topBlock, ($24) => $24.type === "ClassExpression"), i16 = 0, len14 = ref25.length; i16 < len14; i16++) {
8752
- const classExp = ref25[i16];
8832
+ for (let ref26 = gatherRecursiveWithinFunction(topBlock, ($23) => $23.type === "ClassExpression"), i16 = 0, len14 = ref26.length; i16 < len14; i16++) {
8833
+ const classExp = ref26[i16];
8753
8834
  let m8;
8754
8835
  if (classExp.name && classExp.parent === topBlock || (m8 = classExp.parent, typeof m8 === "object" && m8 != null && "type" in m8 && m8.type === "ReturnStatement" && "parent" in m8 && m8.parent === topBlock)) {
8755
8836
  classExp.children.unshift(classExp.name, "=");
@@ -8760,8 +8841,8 @@ function processRepl(root, rootIIFE) {
8760
8841
  function processPlaceholders(statements) {
8761
8842
  const placeholderMap = /* @__PURE__ */ new Map();
8762
8843
  const liftedIfs = /* @__PURE__ */ new Set();
8763
- for (let ref26 = gatherRecursiveAll(statements, ($25) => $25.type === "Placeholder"), i17 = 0, len15 = ref26.length; i17 < len15; i17++) {
8764
- const exp = ref26[i17];
8844
+ for (let ref27 = gatherRecursiveAll(statements, ($24) => $24.type === "Placeholder"), i17 = 0, len15 = ref27.length; i17 < len15; i17++) {
8845
+ const exp = ref27[i17];
8765
8846
  let ancestor;
8766
8847
  if (exp.subtype === ".") {
8767
8848
  ({ ancestor } = findAncestor(
@@ -8873,8 +8954,8 @@ function processPlaceholders(statements) {
8873
8954
  for (let i18 = 0, len16 = placeholders.length; i18 < len16; i18++) {
8874
8955
  const placeholder = placeholders[i18];
8875
8956
  typeSuffix ??= placeholder.typeSuffix;
8876
- let ref27;
8877
- (ref27 = placeholder.children)[ref27.length - 1] = ref;
8957
+ let ref28;
8958
+ (ref28 = placeholder.children)[ref28.length - 1] = ref;
8878
8959
  }
8879
8960
  const { parent } = ancestor;
8880
8961
  const body = maybeUnwrap(ancestor);
@@ -8895,16 +8976,16 @@ function processPlaceholders(statements) {
8895
8976
  }
8896
8977
  case "PipelineExpression": {
8897
8978
  const i = findChildIndex(parent, ancestor);
8898
- let ref28;
8979
+ let ref29;
8899
8980
  if (i === 1) {
8900
- ref28 = ancestor === parent.children[i];
8981
+ ref29 = ancestor === parent.children[i];
8901
8982
  } else if (i === 2) {
8902
- ref28 = ancestor === parent.children[i][findChildIndex(parent.children[i], ancestor)][3];
8983
+ ref29 = ancestor === parent.children[i][findChildIndex(parent.children[i], ancestor)][3];
8903
8984
  } else {
8904
- ref28 = void 0;
8985
+ ref29 = void 0;
8905
8986
  }
8906
8987
  ;
8907
- outer = ref28;
8988
+ outer = ref29;
8908
8989
  break;
8909
8990
  }
8910
8991
  case "AssignmentExpression":
@@ -8922,9 +9003,9 @@ function processPlaceholders(statements) {
8922
9003
  if (typeof parent === "object" && parent != null && "type" in parent && parent.type === "BlockStatement" && "parent" in parent && typeof parent.parent === "object" && parent.parent != null && "type" in parent.parent && parent.parent.type === "ArrowFunction" && "ampersandBlock" in parent.parent && parent.parent.ampersandBlock === true && "body" in parent.parent && parent.parent.body === body) {
8923
9004
  parent.parent.body = fnExp;
8924
9005
  }
8925
- let ref29;
8926
- if (ref29 = getTrimmingSpace(body)) {
8927
- const ws = ref29;
9006
+ let ref30;
9007
+ if (ref30 = getTrimmingSpace(body)) {
9008
+ const ws = ref30;
8928
9009
  inplaceInsertTrimmingSpace(body, "");
8929
9010
  inplacePrepend(ws, fnExp);
8930
9011
  }
@@ -8968,8 +9049,8 @@ function reorderBindingRestProperty(props) {
8968
9049
  }
8969
9050
  ];
8970
9051
  }
8971
- let ref30;
8972
- if (Array.isArray(rest.delim) && (ref30 = rest.delim)[ref30.length - 1]?.token === ",") {
9052
+ let ref31;
9053
+ if (Array.isArray(rest.delim) && (ref31 = rest.delim)[ref31.length - 1]?.token === ",") {
8973
9054
  rest.delim = rest.delim.slice(0, -1);
8974
9055
  rest.children = [...rest.children.slice(0, -1), rest.delim];
8975
9056
  }
@@ -9045,7 +9126,7 @@ function typeOfJSXFragment(node, config2) {
9045
9126
  if (type.length === 1) {
9046
9127
  return type[0];
9047
9128
  } else {
9048
- type = type.flatMap(($26) => [$26, ", "]);
9129
+ type = type.flatMap(($25) => [$25, ", "]);
9049
9130
  type.pop();
9050
9131
  return ["[", type, "]"];
9051
9132
  }
@@ -9110,6 +9191,7 @@ var grammar = {
9110
9191
  Tuple,
9111
9192
  NWTypePostfix,
9112
9193
  UpdateExpression,
9194
+ UpdateExpressionPattern,
9113
9195
  UpdateExpressionSymbol,
9114
9196
  AssignmentExpression,
9115
9197
  NonPipelineAssignmentExpression,
@@ -9245,7 +9327,7 @@ var grammar = {
9245
9327
  OperatorPrecedence,
9246
9328
  OperatorAssociativity,
9247
9329
  ThinArrowFunction,
9248
- Arrow,
9330
+ ThinArrow,
9249
9331
  ExplicitBlock,
9250
9332
  EmptyBracedContent,
9251
9333
  ImplicitNestedBlock,
@@ -10229,7 +10311,7 @@ var $R71 = (0, import_lib2.$R)(new RegExp("#(?!##(?!#))([^\\r\\n]*)", "suy"));
10229
10311
  var $R72 = (0, import_lib2.$R)(new RegExp("[^]*?###", "suy"));
10230
10312
  var $R73 = (0, import_lib2.$R)(new RegExp("###(?!#)", "suy"));
10231
10313
  var $R74 = (0, import_lib2.$R)(new RegExp("\\/\\*(?:(?!\\*\\/)[^\\r\\n])*\\*\\/", "suy"));
10232
- var $R75 = (0, import_lib2.$R)(new RegExp("(?=[ \\t\\/\\\\])", "suy"));
10314
+ var $R75 = (0, import_lib2.$R)(new RegExp("(?=[ \\t\\/\\\\#])", "suy"));
10233
10315
  var $R76 = (0, import_lib2.$R)(new RegExp("(?=\\s|\\/|#)", "suy"));
10234
10316
  var $R77 = (0, import_lib2.$R)(new RegExp("(?!\\p{ID_Continue})", "suy"));
10235
10317
  var $R78 = (0, import_lib2.$R)(new RegExp("[=:]", "suy"));
@@ -10916,6 +10998,12 @@ var UpdateExpression$$ = [UpdateExpression$0, UpdateExpression$1];
10916
10998
  function UpdateExpression(ctx, state2) {
10917
10999
  return (0, import_lib2.$EVENT_C)(ctx, state2, "UpdateExpression", UpdateExpression$$);
10918
11000
  }
11001
+ var UpdateExpressionPattern$0 = NamedBindingPattern;
11002
+ var UpdateExpressionPattern$1 = UpdateExpression;
11003
+ var UpdateExpressionPattern$$ = [UpdateExpressionPattern$0, UpdateExpressionPattern$1];
11004
+ function UpdateExpressionPattern(ctx, state2) {
11005
+ return (0, import_lib2.$EVENT_C)(ctx, state2, "UpdateExpressionPattern", UpdateExpressionPattern$$);
11006
+ }
10919
11007
  var UpdateExpressionSymbol$0 = (0, import_lib2.$TV)((0, import_lib2.$C)((0, import_lib2.$EXPECT)($L9, 'UpdateExpressionSymbol "++"'), (0, import_lib2.$EXPECT)($L10, 'UpdateExpressionSymbol "--"')), function($skip, $loc, $0, $1) {
10920
11008
  return { $loc, token: $1 };
10921
11009
  });
@@ -10979,7 +11067,7 @@ var NonPipelineAssignmentExpressionTail$$ = [NonPipelineAssignmentExpressionTail
10979
11067
  function NonPipelineAssignmentExpressionTail(ctx, state2) {
10980
11068
  return (0, import_lib2.$EVENT_C)(ctx, state2, "NonPipelineAssignmentExpressionTail", NonPipelineAssignmentExpressionTail$$);
10981
11069
  }
10982
- var ActualAssignment$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$P)((0, import_lib2.$S)(NotDedented, UpdateExpression, WAssignmentOp)), MaybeNestedExpression), function($skip, $loc, $0, $1, $2) {
11070
+ var ActualAssignment$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$P)((0, import_lib2.$S)(NotDedented, UpdateExpressionPattern, WAssignmentOp)), MaybeNestedExpression), function($skip, $loc, $0, $1, $2) {
10983
11071
  $1 = $1.map((x) => [x[0], x[1], ...x[2]]);
10984
11072
  $0 = [$1, $2];
10985
11073
  return {
@@ -10996,7 +11084,7 @@ var ActualAssignment$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib
10996
11084
  function ActualAssignment(ctx, state2) {
10997
11085
  return (0, import_lib2.$EVENT)(ctx, state2, "ActualAssignment", ActualAssignment$0);
10998
11086
  }
10999
- var NonPipelineActualAssignment$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$P)((0, import_lib2.$S)(NotDedented, UpdateExpression, WAssignmentOp)), MaybeNestedNonPipelineExpression), function($skip, $loc, $0, $1, $2) {
11087
+ var NonPipelineActualAssignment$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$P)((0, import_lib2.$S)(NotDedented, UpdateExpressionPattern, WAssignmentOp)), MaybeNestedNonPipelineExpression), function($skip, $loc, $0, $1, $2) {
11000
11088
  $1 = $1.map((x) => [x[0], x[1], ...x[2]]);
11001
11089
  $0 = [$1, $2];
11002
11090
  return {
@@ -11175,8 +11263,14 @@ var PipelineExpressionBody$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(Pipeline
11175
11263
  ...rest.map(([nested, line]) => [nested, ...line]).flat()
11176
11264
  ];
11177
11265
  });
11178
- var PipelineExpressionBody$1 = (0, import_lib2.$P)((0, import_lib2.$S)(NotDedented, Pipe, __, PipelineTailItem));
11179
- var PipelineExpressionBody$$ = [PipelineExpressionBody$0, PipelineExpressionBody$1];
11266
+ var PipelineExpressionBody$1 = (0, import_lib2.$T)((0, import_lib2.$S)(NewlineBinaryOpAllowed, (0, import_lib2.$P)((0, import_lib2.$S)(NotDedented, Pipe, __, PipelineTailItem))), function(value) {
11267
+ return value[1];
11268
+ });
11269
+ var PipelineExpressionBody$2 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$N)(NewlineBinaryOpAllowed), PipelineExpressionBodySameLine), function($skip, $loc, $0, $1, $2) {
11270
+ if (!$2.length) return $skip;
11271
+ return $2;
11272
+ });
11273
+ var PipelineExpressionBody$$ = [PipelineExpressionBody$0, PipelineExpressionBody$1, PipelineExpressionBody$2];
11180
11274
  function PipelineExpressionBody(ctx, state2) {
11181
11275
  return (0, import_lib2.$EVENT_C)(ctx, state2, "PipelineExpressionBody", PipelineExpressionBody$$);
11182
11276
  }
@@ -11207,8 +11301,9 @@ var PipelineTailItem$3 = (0, import_lib2.$TS)((0, import_lib2.$S)(NWTypePostfix,
11207
11301
  body: [" ", $1, ...$2]
11208
11302
  });
11209
11303
  });
11210
- var PipelineTailItem$4 = (0, import_lib2.$T)((0, import_lib2.$S)(PipelineHeadItem), function(value) {
11211
- return value[0];
11304
+ var PipelineTailItem$4 = (0, import_lib2.$TS)((0, import_lib2.$S)(ForbidNewlineBinaryOp, (0, import_lib2.$E)(PipelineHeadItem), RestoreNewlineBinaryOp), function($skip, $loc, $0, $1, $2, $3) {
11305
+ if (!$2) return $skip;
11306
+ return $2;
11212
11307
  });
11213
11308
  var PipelineTailItem$$ = [PipelineTailItem$0, PipelineTailItem$1, PipelineTailItem$2, PipelineTailItem$3, PipelineTailItem$4];
11214
11309
  function PipelineTailItem(ctx, state2) {
@@ -11805,9 +11900,8 @@ var LeftHandSideExpression$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, impo
11805
11900
  expression
11806
11901
  };
11807
11902
  });
11808
- var LeftHandSideExpression$1 = NamedBindingPattern;
11809
- var LeftHandSideExpression$2 = CallExpression;
11810
- var LeftHandSideExpression$$ = [LeftHandSideExpression$0, LeftHandSideExpression$1, LeftHandSideExpression$2];
11903
+ var LeftHandSideExpression$1 = CallExpression;
11904
+ var LeftHandSideExpression$$ = [LeftHandSideExpression$0, LeftHandSideExpression$1];
11811
11905
  function LeftHandSideExpression(ctx, state2) {
11812
11906
  return (0, import_lib2.$EVENT_C)(ctx, state2, "LeftHandSideExpression", LeftHandSideExpression$$);
11813
11907
  }
@@ -13262,14 +13356,21 @@ var OperatorAssociativity$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, impor
13262
13356
  function OperatorAssociativity(ctx, state2) {
13263
13357
  return (0, import_lib2.$EVENT)(ctx, state2, "OperatorAssociativity", OperatorAssociativity$0);
13264
13358
  }
13265
- var ThinArrowFunction$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)((0, import_lib2.$S)(Async, _)), ArrowParameters, (0, import_lib2.$E)(ReturnTypeSuffix), (0, import_lib2.$E)(_), Arrow, (0, import_lib2.$C)(BracedObjectSingleLineStatements, NoCommaBracedOrEmptyBlock)), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
13359
+ var ThinArrowFunction$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)((0, import_lib2.$S)(Async, _)), ArrowParameters, (0, import_lib2.$E)(ReturnTypeSuffix), (0, import_lib2.$E)(_), ThinArrow, (0, import_lib2.$C)(BracedObjectSingleLineStatements, NoCommaBracedOrEmptyBlock)), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
13266
13360
  var async = $1;
13267
13361
  var parameters = $2;
13268
13362
  var returnType = $3;
13363
+ var ws = $4;
13269
13364
  var arrow = $5;
13270
13365
  var block = $6;
13271
13366
  if (!async) async = [];
13272
13367
  const generator = [];
13368
+ if ((!parameters.implicit || returnType || ws) && !block.bare) {
13369
+ const [first, ...rest] = block.children;
13370
+ if (first === " {" || first?.[0]?.token === " ") {
13371
+ block = { ...block, children: [first.slice(1), ...rest] };
13372
+ }
13373
+ }
13273
13374
  return {
13274
13375
  type: "FunctionExpression",
13275
13376
  id: void 0,
@@ -13294,6 +13395,7 @@ var ThinArrowFunction$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_li
13294
13395
  generator,
13295
13396
  parameters,
13296
13397
  returnType,
13398
+ ws,
13297
13399
  block
13298
13400
  ]
13299
13401
  };
@@ -13301,11 +13403,11 @@ var ThinArrowFunction$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_li
13301
13403
  function ThinArrowFunction(ctx, state2) {
13302
13404
  return (0, import_lib2.$EVENT)(ctx, state2, "ThinArrowFunction", ThinArrowFunction$0);
13303
13405
  }
13304
- var Arrow$0 = (0, import_lib2.$TV)((0, import_lib2.$C)((0, import_lib2.$EXPECT)($L35, 'Arrow "->"'), (0, import_lib2.$EXPECT)($L36, 'Arrow "\u2192"')), function($skip, $loc, $0, $1) {
13406
+ var ThinArrow$0 = (0, import_lib2.$TV)((0, import_lib2.$C)((0, import_lib2.$EXPECT)($L35, 'ThinArrow "->"'), (0, import_lib2.$EXPECT)($L36, 'ThinArrow "\u2192"')), function($skip, $loc, $0, $1) {
13305
13407
  return { $loc, token: "->" };
13306
13408
  });
13307
- function Arrow(ctx, state2) {
13308
- return (0, import_lib2.$EVENT)(ctx, state2, "Arrow", Arrow$0);
13409
+ function ThinArrow(ctx, state2) {
13410
+ return (0, import_lib2.$EVENT)(ctx, state2, "ThinArrow", ThinArrow$0);
13309
13411
  }
13310
13412
  var ExplicitBlock$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), OpenBrace, AllowAll, (0, import_lib2.$E)((0, import_lib2.$C)(NestedBlockStatements, SingleLineStatements, EmptyBracedContent)), RestoreAll, __, CloseBrace), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
13311
13413
  var ws1 = $1;
@@ -17963,8 +18065,10 @@ function CoffeeHereCommentStart(ctx, state2) {
17963
18065
  var InlineComment$0 = (0, import_lib2.$TR)((0, import_lib2.$EXPECT)($R74, "InlineComment /\\/\\*(?:(?!\\*\\/)[^\\r\\n])*\\*\\//"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
17964
18066
  return { $loc, token: $0 };
17965
18067
  });
18068
+ var InlineComment$1 = CoffeeMultiLineComment;
18069
+ var InlineComment$$ = [InlineComment$0, InlineComment$1];
17966
18070
  function InlineComment(ctx, state2) {
17967
- return (0, import_lib2.$EVENT)(ctx, state2, "InlineComment", InlineComment$0);
18071
+ return (0, import_lib2.$EVENT_C)(ctx, state2, "InlineComment", InlineComment$$);
17968
18072
  }
17969
18073
  var RestOfLine$0 = (0, import_lib2.$S)((0, import_lib2.$Q)((0, import_lib2.$C)(NonNewlineWhitespace, Comment)), EOL);
17970
18074
  function RestOfLine(ctx, state2) {
@@ -17974,7 +18078,7 @@ var TrailingComment$0 = (0, import_lib2.$S)((0, import_lib2.$E)(_), (0, import_l
17974
18078
  function TrailingComment(ctx, state2) {
17975
18079
  return (0, import_lib2.$EVENT)(ctx, state2, "TrailingComment", TrailingComment$0);
17976
18080
  }
17977
- var _$0 = (0, import_lib2.$T)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($R75, "_ /(?=[ \\t\\/\\\\])/"), (0, import_lib2.$P)((0, import_lib2.$C)(NonNewlineWhitespace, InlineComment))), function(value) {
18081
+ var _$0 = (0, import_lib2.$T)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($R75, "_ /(?=[ \\t\\/\\\\#])/"), (0, import_lib2.$P)((0, import_lib2.$C)(NonNewlineWhitespace, InlineComment))), function(value) {
17978
18082
  return value[1];
17979
18083
  });
17980
18084
  function _(ctx, state2) {
@@ -22149,8 +22253,9 @@ ${counts}`;
22149
22253
  const code = generate_civet_default(ast2, options);
22150
22254
  checkErrors();
22151
22255
  if (options.inlineMap) {
22256
+ const outputFilename = options.outputFilename ?? (options.js ? filename2 + ".jsx" : filename2 + ".tsx");
22152
22257
  return `${code}
22153
- ${options.sourceMap.comment(filename2, filename2 + ".tsx")}`;
22258
+ ${options.sourceMap.comment(filename2, outputFilename)}`;
22154
22259
  } else {
22155
22260
  return {
22156
22261
  code,