@danielx/civet 0.11.0 → 0.11.1

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/CHANGELOG.md CHANGED
@@ -4,6 +4,9 @@ This changelog is generated automatically by [`build/changelog.civet`](build/cha
4
4
  For each version of Civet, it lists and links to all incorporated PRs,
5
5
  as well as a full diff and commit list.
6
6
 
7
+ ## 0.11.1 (2025-12-05, [diff](https://github.com/DanielXMoore/Civet/compare/v0.11.0...v0.11.1), [commits](https://github.com/DanielXMoore/Civet/commits/v0.11.1))
8
+ * Don't unwrap statement expressions that might be short-circuited [[#1821](https://github.com/DanielXMoore/Civet/pull/1821)]
9
+
7
10
  ## 0.11.0 (2025-11-03, [diff](https://github.com/DanielXMoore/Civet/compare/v0.10.7...v0.11.0), [commits](https://github.com/DanielXMoore/Civet/commits/v0.11.0))
8
11
  * Fix missing space in terse `get`/`set` definitions [[#1802](https://github.com/DanielXMoore/Civet/pull/1802)]
9
12
  * Dynamic `import` expressions support `*`, `default`; they and globs support strings and computed names [[#1806](https://github.com/DanielXMoore/Civet/pull/1806)]
package/dist/browser.js CHANGED
@@ -3494,6 +3494,12 @@ ${js}`
3494
3494
  throw new Error(`Unknown operator: ${op}`);
3495
3495
  })() : op.type === "PatternTest" ? precedenceRelational : typeof op.prec == "number" ? op.prec : precedenceMap.get(op.prec ?? op.token) ?? (op.relational ? precedenceRelational : precedenceCustomDefault);
3496
3496
  }
3497
+ function isShortCircuitOp(op) {
3498
+ if (op && typeof op == "object" && "token" in op) {
3499
+ let { token } = op;
3500
+ return isShortCircuitOp(token);
3501
+ } else return typeof op == "string" ? (op.endsWith("=") && !op.endsWith("==") && (op = op.slice(0, -1)), op === "||" || op === "&&" || op === "??") : !1;
3502
+ }
3497
3503
  function processBinaryOpExpression($0) {
3498
3504
  return processExpandedBinaryOpExpression(expandChainedComparisons($0));
3499
3505
  }
@@ -5992,15 +5998,15 @@ ${js}`
5992
5998
  let exp = ref12[i7];
5993
5999
  if (exp.names !== null)
5994
6000
  continue;
5995
- let { lhs: $1, expression: $2 } = exp, tail = [], len3 = $1.length, block, ref13;
5996
- if (blockContainingStatement(exp) && !(ref13 = $1[$1.length - 1])?.[ref13.length - 1]?.special) {
6001
+ let { lhs: $1, expression: $2 } = exp, tail = [], len3 = $1.length, block, ref13, ref14;
6002
+ if (blockContainingStatement(exp) && !(ref13 = $1[$1.length - 1])?.[ref13.length - 1]?.special && !isShortCircuitOp((ref14 = $1[$1.length - 1])?.[ref14.length - 1])) {
5997
6003
  block = makeBlockFragment();
5998
- let ref14;
5999
- if (ref14 = prependStatementExpressionBlock(
6004
+ let ref15;
6005
+ if (ref15 = prependStatementExpressionBlock(
6000
6006
  { type: "Initializer", expression: $2, children: [void 0, void 0, $2] },
6001
6007
  block
6002
6008
  )) {
6003
- let ref = ref14;
6009
+ let ref = ref15;
6004
6010
  exp.children = exp.children.map(($7) => $7 === $2 ? ref : $7), $2 = ref;
6005
6011
  } else
6006
6012
  block = void 0;
@@ -6103,9 +6109,9 @@ ${js}`
6103
6109
  }
6104
6110
  j++;
6105
6111
  }
6106
- let ref15;
6107
- if (ref15 = conditions.length) {
6108
- let l = ref15, cs = flatJoin(conditions, " && ");
6112
+ let ref16;
6113
+ if (ref16 = conditions.length) {
6114
+ let l = ref16, cs = flatJoin(conditions, " && ");
6109
6115
  return {
6110
6116
  ...exp,
6111
6117
  children: [...cs, " ? ", innerExp(children), " : void 0"],
@@ -6137,8 +6143,8 @@ ${js}`
6137
6143
  }
6138
6144
  function processTypes(node) {
6139
6145
  let results1 = [];
6140
- for (let ref16 = gatherRecursiveAll(node, ($11) => $11.type === "TypeUnary"), i8 = 0, len7 = ref16.length; i8 < len7; i8++) {
6141
- let unary = ref16[i8], suffixIndex = unary.suffix.length - 1, results2 = [];
6146
+ for (let ref17 = gatherRecursiveAll(node, ($11) => $11.type === "TypeUnary"), i8 = 0, len7 = ref17.length; i8 < len7; i8++) {
6147
+ let unary = ref17[i8], suffixIndex = unary.suffix.length - 1, results2 = [];
6142
6148
  for (; suffixIndex >= 0; ) {
6143
6149
  let suffix = unary.suffix[suffixIndex];
6144
6150
  if (typeof suffix == "object" && suffix != null && "token" in suffix && suffix.token === "?") {
@@ -6199,9 +6205,9 @@ ${js}`
6199
6205
  unary.prefix = [], unary.children = unary.children.filter((a2) => a2 !== prefix);
6200
6206
  let outer = unary.suffix.splice(suffixIndex + 1, 1 / 0), space = getTrimmingSpace(unary);
6201
6207
  inplaceInsertTrimmingSpace(unary, "");
6202
- let ref17;
6203
- unary.suffix.length ? ref17 = unary : ref17 = unary.t;
6204
- let t = ref17, argArray = [makeNode({
6208
+ let ref18;
6209
+ unary.suffix.length ? ref18 = unary : ref18 = unary.t;
6210
+ let t = ref18, argArray = [makeNode({
6205
6211
  type: "TypeArgument",
6206
6212
  ts: !0,
6207
6213
  t,
@@ -6237,16 +6243,16 @@ ${js}`
6237
6243
  return results1;
6238
6244
  }
6239
6245
  function processStatementExpressions(statements) {
6240
- for (let ref18 = gatherRecursiveAll(statements, ($12) => $12.type === "StatementExpression"), i9 = 0, len8 = ref18.length; i9 < len8; i9++) {
6241
- let exp = ref18[i9], { maybe, statement } = exp;
6246
+ for (let ref19 = gatherRecursiveAll(statements, ($12) => $12.type === "StatementExpression"), i9 = 0, len8 = ref19.length; i9 < len8; i9++) {
6247
+ let exp = ref19[i9], { maybe, statement } = exp;
6242
6248
  if ((maybe || statement.type === "ThrowStatement") && blockContainingStatement(exp)) {
6243
6249
  replaceNode(exp, statement);
6244
6250
  continue;
6245
6251
  }
6246
- let ref19;
6252
+ let ref20;
6247
6253
  switch (statement.type) {
6248
6254
  case "IfStatement": {
6249
- (ref19 = expressionizeIfStatement(statement)) ? replaceNode(statement, ref19, exp) : replaceNode(statement, wrapIIFE([["", statement]]), exp);
6255
+ (ref20 = expressionizeIfStatement(statement)) ? replaceNode(statement, ref20, exp) : replaceNode(statement, wrapIIFE([["", statement]]), exp);
6250
6256
  break;
6251
6257
  }
6252
6258
  case "IterationExpression": {
@@ -6287,11 +6293,11 @@ ${js}`
6287
6293
  });
6288
6294
  }
6289
6295
  function processFinallyClauses(statements) {
6290
- for (let ref20 = gatherRecursiveAll(statements, ($) => $.type === "FinallyClause" && $.parent?.type !== "TryStatement"), i10 = 0, len9 = ref20.length; i10 < len9; i10++) {
6291
- let f = ref20[i10], ref21;
6292
- if (!((ref21 = blockContainingStatement(f)) && typeof ref21 == "object" && "block" in ref21 && "index" in ref21))
6296
+ for (let ref21 = gatherRecursiveAll(statements, ($) => $.type === "FinallyClause" && $.parent?.type !== "TryStatement"), i10 = 0, len9 = ref21.length; i10 < len9; i10++) {
6297
+ let f = ref21[i10], ref22;
6298
+ if (!((ref22 = blockContainingStatement(f)) && typeof ref22 == "object" && "block" in ref22 && "index" in ref22))
6293
6299
  throw new Error("finally clause must be inside try statement or block");
6294
- let { block, index } = ref21, indent = block.expressions[index][0], expressions = block.expressions.slice(index + 1), t = makeNode({
6300
+ let { block, index } = ref22, indent = block.expressions[index][0], expressions = block.expressions.slice(index + 1), t = makeNode({
6295
6301
  type: "BlockStatement",
6296
6302
  expressions,
6297
6303
  children: ["{", expressions, "}"],
@@ -6351,8 +6357,8 @@ ${js}`
6351
6357
  }
6352
6358
  }
6353
6359
  function processCoffeeClasses(statements) {
6354
- for (let ref22 = gatherRecursiveAll(statements, ($13) => $13.type === "ClassExpression"), i11 = 0, len10 = ref22.length; i11 < len10; i11++) {
6355
- let ce = ref22[i11], { expressions } = ce.body, indent = expressions[0]?.[0] ?? `
6360
+ for (let ref23 = gatherRecursiveAll(statements, ($13) => $13.type === "ClassExpression"), i11 = 0, len10 = ref23.length; i11 < len10; i11++) {
6361
+ let ce = ref23[i11], { expressions } = ce.body, indent = expressions[0]?.[0] ?? `
6356
6362
  `, autoBinds = expressions.filter(($14) => $14[1]?.autoBind);
6357
6363
  if (autoBinds.length) {
6358
6364
  let construct;
@@ -6452,23 +6458,23 @@ ${js}`
6452
6458
  }
6453
6459
  function processRepl(root, rootIIFE) {
6454
6460
  let topBlock = gatherRecursive(rootIIFE, ($21) => $21.type === "BlockStatement")[0], i = 0;
6455
- for (let ref23 = gatherRecursiveWithinFunction(topBlock, ($22) => $22.type === "Declaration"), i14 = 0, len12 = ref23.length; i14 < len12; i14++) {
6456
- let decl = ref23[i14];
6461
+ for (let ref24 = gatherRecursiveWithinFunction(topBlock, ($22) => $22.type === "Declaration"), i14 = 0, len12 = ref24.length; i14 < len12; i14++) {
6462
+ let decl = ref24[i14];
6457
6463
  decl.names?.length && (decl.parent === topBlock || decl.decl === "var") && (decl.children.shift(), decl.bindings[0]?.pattern?.type === "ObjectBindingPattern" && (decl.children.unshift("("), decl.children.push(")")), root.expressions.splice(i++, 0, ["", `var ${decl.names.join(",")}`, ";"]));
6458
6464
  }
6459
- for (let ref24 = gatherRecursive(topBlock, ($23) => $23.type === "FunctionExpression"), i15 = 0, len13 = ref24.length; i15 < len13; i15++) {
6460
- let func = ref24[i15];
6465
+ for (let ref25 = gatherRecursive(topBlock, ($23) => $23.type === "FunctionExpression"), i15 = 0, len13 = ref25.length; i15 < len13; i15++) {
6466
+ let func = ref25[i15];
6461
6467
  func.name && func.parent?.type === "BlockStatement" && (func.parent === topBlock ? (replaceNode(func, void 0), root.expressions.splice(i++, 0, ["", func]), func.parent = root) : (func.children.unshift(func.name, "="), root.expressions.splice(i++, 0, ["", `var ${func.name}`, ";"])));
6462
6468
  }
6463
- for (let ref25 = gatherRecursiveWithinFunction(topBlock, ($24) => $24.type === "ClassExpression"), i16 = 0, len14 = ref25.length; i16 < len14; i16++) {
6464
- let classExp = ref25[i16], m8;
6469
+ for (let ref26 = gatherRecursiveWithinFunction(topBlock, ($24) => $24.type === "ClassExpression"), i16 = 0, len14 = ref26.length; i16 < len14; i16++) {
6470
+ let classExp = ref26[i16], m8;
6465
6471
  (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)) && (classExp.children.unshift(classExp.name, "="), root.expressions.splice(i++, 0, ["", `var ${classExp.name}`, ";"]));
6466
6472
  }
6467
6473
  }
6468
6474
  function processPlaceholders(statements) {
6469
6475
  let placeholderMap = /* @__PURE__ */ new Map(), liftedIfs = /* @__PURE__ */ new Set();
6470
- for (let ref26 = gatherRecursiveAll(statements, ($25) => $25.type === "Placeholder"), i17 = 0, len15 = ref26.length; i17 < len15; i17++) {
6471
- let exp = ref26[i17], ancestor;
6476
+ for (let ref27 = gatherRecursiveAll(statements, ($25) => $25.type === "Placeholder"), i17 = 0, len15 = ref27.length; i17 < len15; i17++) {
6477
+ let exp = ref27[i17], ancestor;
6472
6478
  if (exp.subtype === ".") {
6473
6479
  ({ ancestor } = findAncestor(
6474
6480
  exp,
@@ -6540,8 +6546,8 @@ ${js}`
6540
6546
  for (let i18 = 0, len16 = placeholders.length; i18 < len16; i18++) {
6541
6547
  let placeholder = placeholders[i18];
6542
6548
  typeSuffix ??= placeholder.typeSuffix;
6543
- let ref27;
6544
- (ref27 = placeholder.children)[ref27.length - 1] = ref;
6549
+ let ref28;
6550
+ (ref28 = placeholder.children)[ref28.length - 1] = ref;
6545
6551
  }
6546
6552
  let { parent } = ancestor, body = maybeUnwrap(ancestor), fnExp = makeAmpersandFunction({ ref, typeSuffix, body }), outer;
6547
6553
  switch (parent?.type) {
@@ -6558,8 +6564,8 @@ ${js}`
6558
6564
  break;
6559
6565
  }
6560
6566
  case "PipelineExpression": {
6561
- let i = findChildIndex(parent, ancestor), ref28;
6562
- i === 1 ? ref28 = ancestor === parent.children[i] : i === 2 ? ref28 = ancestor === parent.children[i][findChildIndex(parent.children[i], ancestor)][3] : ref28 = void 0, outer = ref28;
6567
+ let i = findChildIndex(parent, ancestor), ref29;
6568
+ i === 1 ? ref29 = ancestor === parent.children[i] : i === 2 ? ref29 = ancestor === parent.children[i][findChildIndex(parent.children[i], ancestor)][3] : ref29 = void 0, outer = ref29;
6563
6569
  break;
6564
6570
  }
6565
6571
  case "AssignmentExpression":
@@ -6571,9 +6577,9 @@ ${js}`
6571
6577
  }
6572
6578
  }
6573
6579
  outer || (fnExp = makeLeftHandSideExpression(fnExp)), replaceNode(ancestor, fnExp, parent), 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 === !0 && "body" in parent.parent && parent.parent.body === body && (parent.parent.body = fnExp);
6574
- let ref29;
6575
- if (ref29 = getTrimmingSpace(body)) {
6576
- let ws = ref29;
6580
+ let ref30;
6581
+ if (ref30 = getTrimmingSpace(body)) {
6582
+ let ws = ref30;
6577
6583
  inplaceInsertTrimmingSpace(body, ""), inplacePrepend(ws, fnExp);
6578
6584
  }
6579
6585
  }
@@ -6604,8 +6610,8 @@ ${js}`
6604
6610
  }
6605
6611
  ];
6606
6612
  }
6607
- let ref30;
6608
- Array.isArray(rest.delim) && (ref30 = rest.delim)[ref30.length - 1]?.token === "," && (rest.delim = rest.delim.slice(0, -1), rest.children = [...rest.children.slice(0, -1), rest.delim]);
6613
+ let ref31;
6614
+ Array.isArray(rest.delim) && (ref31 = rest.delim)[ref31.length - 1]?.token === "," && (rest.delim = rest.delim.slice(0, -1), rest.children = [...rest.children.slice(0, -1), rest.delim]);
6609
6615
  let children = [...props, ...after, rest];
6610
6616
  return restCount > 1 && children.push({
6611
6617
  type: "Error",
package/dist/main.js CHANGED
@@ -4588,6 +4588,19 @@ function getPrecedence(op) {
4588
4588
  return precedenceMap.get(op.prec ?? op.token) ?? (op.relational ? precedenceRelational : precedenceCustomDefault);
4589
4589
  }
4590
4590
  }
4591
+ function isShortCircuitOp(op) {
4592
+ if (op && typeof op === "object" && "token" in op) {
4593
+ const { token } = op;
4594
+ return isShortCircuitOp(token);
4595
+ } else if (typeof op === "string") {
4596
+ if (op.endsWith("=") && !op.endsWith("==")) {
4597
+ op = op.slice(0, -1);
4598
+ }
4599
+ return op === "||" || op === "&&" || op === "??";
4600
+ } else {
4601
+ return false;
4602
+ }
4603
+ }
4591
4604
  function processBinaryOpExpression($0) {
4592
4605
  return processExpandedBinaryOpExpression(expandChainedComparisons($0));
4593
4606
  }
@@ -8078,14 +8091,15 @@ function processAssignments(statements) {
8078
8091
  let { lhs: $1, expression: $2 } = exp, tail = [], len3 = $1.length;
8079
8092
  let block;
8080
8093
  let ref13;
8081
- if (blockContainingStatement(exp) && !(ref13 = $1[$1.length - 1])?.[ref13.length - 1]?.special) {
8094
+ let ref14;
8095
+ if (blockContainingStatement(exp) && !(ref13 = $1[$1.length - 1])?.[ref13.length - 1]?.special && !isShortCircuitOp((ref14 = $1[$1.length - 1])?.[ref14.length - 1])) {
8082
8096
  block = makeBlockFragment();
8083
- let ref14;
8084
- if (ref14 = prependStatementExpressionBlock(
8097
+ let ref15;
8098
+ if (ref15 = prependStatementExpressionBlock(
8085
8099
  { type: "Initializer", expression: $2, children: [void 0, void 0, $2] },
8086
8100
  block
8087
8101
  )) {
8088
- const ref = ref14;
8102
+ const ref = ref15;
8089
8103
  exp.children = exp.children.map(($7) => $7 === $2 ? ref : $7);
8090
8104
  $2 = ref;
8091
8105
  } else {
@@ -8266,9 +8280,9 @@ function unchainOptionalMemberExpression(exp, ref, innerExp) {
8266
8280
  }
8267
8281
  j++;
8268
8282
  }
8269
- let ref15;
8270
- if (ref15 = conditions.length) {
8271
- const l = ref15;
8283
+ let ref16;
8284
+ if (ref16 = conditions.length) {
8285
+ const l = ref16;
8272
8286
  const cs = flatJoin(conditions, " && ");
8273
8287
  return {
8274
8288
  ...exp,
@@ -8304,8 +8318,8 @@ function attachPostfixStatementAsExpression(exp, post) {
8304
8318
  }
8305
8319
  function processTypes(node) {
8306
8320
  const results1 = [];
8307
- for (let ref16 = gatherRecursiveAll(node, ($11) => $11.type === "TypeUnary"), i8 = 0, len7 = ref16.length; i8 < len7; i8++) {
8308
- const unary = ref16[i8];
8321
+ for (let ref17 = gatherRecursiveAll(node, ($11) => $11.type === "TypeUnary"), i8 = 0, len7 = ref17.length; i8 < len7; i8++) {
8322
+ const unary = ref17[i8];
8309
8323
  let suffixIndex = unary.suffix.length - 1;
8310
8324
  const results2 = [];
8311
8325
  while (suffixIndex >= 0) {
@@ -8384,10 +8398,10 @@ function processTypes(node) {
8384
8398
  const outer = unary.suffix.splice(suffixIndex + 1, Infinity);
8385
8399
  const space = getTrimmingSpace(unary);
8386
8400
  inplaceInsertTrimmingSpace(unary, "");
8387
- let ref17;
8388
- if (unary.suffix.length) ref17 = unary;
8389
- else ref17 = unary.t;
8390
- const t = ref17;
8401
+ let ref18;
8402
+ if (unary.suffix.length) ref18 = unary;
8403
+ else ref18 = unary.t;
8404
+ const t = ref18;
8391
8405
  const arg = makeNode({
8392
8406
  type: "TypeArgument",
8393
8407
  ts: true,
@@ -8432,18 +8446,18 @@ function processTypes(node) {
8432
8446
  return results1;
8433
8447
  }
8434
8448
  function processStatementExpressions(statements) {
8435
- for (let ref18 = gatherRecursiveAll(statements, ($12) => $12.type === "StatementExpression"), i9 = 0, len8 = ref18.length; i9 < len8; i9++) {
8436
- const exp = ref18[i9];
8449
+ for (let ref19 = gatherRecursiveAll(statements, ($12) => $12.type === "StatementExpression"), i9 = 0, len8 = ref19.length; i9 < len8; i9++) {
8450
+ const exp = ref19[i9];
8437
8451
  const { maybe, statement } = exp;
8438
8452
  if ((maybe || statement.type === "ThrowStatement") && blockContainingStatement(exp)) {
8439
8453
  replaceNode(exp, statement);
8440
8454
  continue;
8441
8455
  }
8442
- let ref19;
8456
+ let ref20;
8443
8457
  switch (statement.type) {
8444
8458
  case "IfStatement": {
8445
- if (ref19 = expressionizeIfStatement(statement)) {
8446
- const expression = ref19;
8459
+ if (ref20 = expressionizeIfStatement(statement)) {
8460
+ const expression = ref20;
8447
8461
  replaceNode(statement, expression, exp);
8448
8462
  } else {
8449
8463
  replaceNode(statement, wrapIIFE([["", statement]]), exp);
@@ -8502,13 +8516,13 @@ function processNegativeIndexAccess(statements) {
8502
8516
  });
8503
8517
  }
8504
8518
  function processFinallyClauses(statements) {
8505
- for (let ref20 = gatherRecursiveAll(statements, ($) => $.type === "FinallyClause" && $.parent?.type !== "TryStatement"), i10 = 0, len9 = ref20.length; i10 < len9; i10++) {
8506
- let f = ref20[i10];
8507
- let ref21;
8508
- if (!((ref21 = blockContainingStatement(f)) && typeof ref21 === "object" && "block" in ref21 && "index" in ref21)) {
8519
+ for (let ref21 = gatherRecursiveAll(statements, ($) => $.type === "FinallyClause" && $.parent?.type !== "TryStatement"), i10 = 0, len9 = ref21.length; i10 < len9; i10++) {
8520
+ let f = ref21[i10];
8521
+ let ref22;
8522
+ if (!((ref22 = blockContainingStatement(f)) && typeof ref22 === "object" && "block" in ref22 && "index" in ref22)) {
8509
8523
  throw new Error("finally clause must be inside try statement or block");
8510
8524
  }
8511
- const { block, index } = ref21;
8525
+ const { block, index } = ref22;
8512
8526
  const indent = block.expressions[index][0];
8513
8527
  const expressions = block.expressions.slice(index + 1);
8514
8528
  const t = makeNode({
@@ -8580,8 +8594,8 @@ function processBreaksContinues(statements) {
8580
8594
  }
8581
8595
  }
8582
8596
  function processCoffeeClasses(statements) {
8583
- for (let ref22 = gatherRecursiveAll(statements, ($13) => $13.type === "ClassExpression"), i11 = 0, len10 = ref22.length; i11 < len10; i11++) {
8584
- const ce = ref22[i11];
8597
+ for (let ref23 = gatherRecursiveAll(statements, ($13) => $13.type === "ClassExpression"), i11 = 0, len10 = ref23.length; i11 < len10; i11++) {
8598
+ const ce = ref23[i11];
8585
8599
  const { expressions } = ce.body;
8586
8600
  const indent = expressions[0]?.[0] ?? "\n";
8587
8601
  const autoBinds = expressions.filter(($14) => $14[1]?.autoBind);
@@ -8741,8 +8755,8 @@ async function processProgramAsync(root) {
8741
8755
  function processRepl(root, rootIIFE) {
8742
8756
  const topBlock = gatherRecursive(rootIIFE, ($21) => $21.type === "BlockStatement")[0];
8743
8757
  let i = 0;
8744
- for (let ref23 = gatherRecursiveWithinFunction(topBlock, ($22) => $22.type === "Declaration"), i14 = 0, len12 = ref23.length; i14 < len12; i14++) {
8745
- const decl = ref23[i14];
8758
+ for (let ref24 = gatherRecursiveWithinFunction(topBlock, ($22) => $22.type === "Declaration"), i14 = 0, len12 = ref24.length; i14 < len12; i14++) {
8759
+ const decl = ref24[i14];
8746
8760
  if (!decl.names?.length) {
8747
8761
  continue;
8748
8762
  }
@@ -8755,8 +8769,8 @@ function processRepl(root, rootIIFE) {
8755
8769
  root.expressions.splice(i++, 0, ["", `var ${decl.names.join(",")}`, ";"]);
8756
8770
  }
8757
8771
  }
8758
- for (let ref24 = gatherRecursive(topBlock, ($23) => $23.type === "FunctionExpression"), i15 = 0, len13 = ref24.length; i15 < len13; i15++) {
8759
- const func = ref24[i15];
8772
+ for (let ref25 = gatherRecursive(topBlock, ($23) => $23.type === "FunctionExpression"), i15 = 0, len13 = ref25.length; i15 < len13; i15++) {
8773
+ const func = ref25[i15];
8760
8774
  if (func.name && func.parent?.type === "BlockStatement") {
8761
8775
  if (func.parent === topBlock) {
8762
8776
  replaceNode(func, void 0);
@@ -8768,8 +8782,8 @@ function processRepl(root, rootIIFE) {
8768
8782
  }
8769
8783
  }
8770
8784
  }
8771
- for (let ref25 = gatherRecursiveWithinFunction(topBlock, ($24) => $24.type === "ClassExpression"), i16 = 0, len14 = ref25.length; i16 < len14; i16++) {
8772
- const classExp = ref25[i16];
8785
+ for (let ref26 = gatherRecursiveWithinFunction(topBlock, ($24) => $24.type === "ClassExpression"), i16 = 0, len14 = ref26.length; i16 < len14; i16++) {
8786
+ const classExp = ref26[i16];
8773
8787
  let m8;
8774
8788
  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)) {
8775
8789
  classExp.children.unshift(classExp.name, "=");
@@ -8780,8 +8794,8 @@ function processRepl(root, rootIIFE) {
8780
8794
  function processPlaceholders(statements) {
8781
8795
  const placeholderMap = /* @__PURE__ */ new Map();
8782
8796
  const liftedIfs = /* @__PURE__ */ new Set();
8783
- for (let ref26 = gatherRecursiveAll(statements, ($25) => $25.type === "Placeholder"), i17 = 0, len15 = ref26.length; i17 < len15; i17++) {
8784
- const exp = ref26[i17];
8797
+ for (let ref27 = gatherRecursiveAll(statements, ($25) => $25.type === "Placeholder"), i17 = 0, len15 = ref27.length; i17 < len15; i17++) {
8798
+ const exp = ref27[i17];
8785
8799
  let ancestor;
8786
8800
  if (exp.subtype === ".") {
8787
8801
  ({ ancestor } = findAncestor(
@@ -8893,8 +8907,8 @@ function processPlaceholders(statements) {
8893
8907
  for (let i18 = 0, len16 = placeholders.length; i18 < len16; i18++) {
8894
8908
  const placeholder = placeholders[i18];
8895
8909
  typeSuffix ??= placeholder.typeSuffix;
8896
- let ref27;
8897
- (ref27 = placeholder.children)[ref27.length - 1] = ref;
8910
+ let ref28;
8911
+ (ref28 = placeholder.children)[ref28.length - 1] = ref;
8898
8912
  }
8899
8913
  const { parent } = ancestor;
8900
8914
  const body = maybeUnwrap(ancestor);
@@ -8915,16 +8929,16 @@ function processPlaceholders(statements) {
8915
8929
  }
8916
8930
  case "PipelineExpression": {
8917
8931
  const i = findChildIndex(parent, ancestor);
8918
- let ref28;
8932
+ let ref29;
8919
8933
  if (i === 1) {
8920
- ref28 = ancestor === parent.children[i];
8934
+ ref29 = ancestor === parent.children[i];
8921
8935
  } else if (i === 2) {
8922
- ref28 = ancestor === parent.children[i][findChildIndex(parent.children[i], ancestor)][3];
8936
+ ref29 = ancestor === parent.children[i][findChildIndex(parent.children[i], ancestor)][3];
8923
8937
  } else {
8924
- ref28 = void 0;
8938
+ ref29 = void 0;
8925
8939
  }
8926
8940
  ;
8927
- outer = ref28;
8941
+ outer = ref29;
8928
8942
  break;
8929
8943
  }
8930
8944
  case "AssignmentExpression":
@@ -8942,9 +8956,9 @@ function processPlaceholders(statements) {
8942
8956
  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) {
8943
8957
  parent.parent.body = fnExp;
8944
8958
  }
8945
- let ref29;
8946
- if (ref29 = getTrimmingSpace(body)) {
8947
- const ws = ref29;
8959
+ let ref30;
8960
+ if (ref30 = getTrimmingSpace(body)) {
8961
+ const ws = ref30;
8948
8962
  inplaceInsertTrimmingSpace(body, "");
8949
8963
  inplacePrepend(ws, fnExp);
8950
8964
  }
@@ -8988,8 +9002,8 @@ function reorderBindingRestProperty(props) {
8988
9002
  }
8989
9003
  ];
8990
9004
  }
8991
- let ref30;
8992
- if (Array.isArray(rest.delim) && (ref30 = rest.delim)[ref30.length - 1]?.token === ",") {
9005
+ let ref31;
9006
+ if (Array.isArray(rest.delim) && (ref31 = rest.delim)[ref31.length - 1]?.token === ",") {
8993
9007
  rest.delim = rest.delim.slice(0, -1);
8994
9008
  rest.children = [...rest.children.slice(0, -1), rest.delim];
8995
9009
  }
package/dist/main.mjs CHANGED
@@ -4568,6 +4568,19 @@ function getPrecedence(op) {
4568
4568
  return precedenceMap.get(op.prec ?? op.token) ?? (op.relational ? precedenceRelational : precedenceCustomDefault);
4569
4569
  }
4570
4570
  }
4571
+ function isShortCircuitOp(op) {
4572
+ if (op && typeof op === "object" && "token" in op) {
4573
+ const { token } = op;
4574
+ return isShortCircuitOp(token);
4575
+ } else if (typeof op === "string") {
4576
+ if (op.endsWith("=") && !op.endsWith("==")) {
4577
+ op = op.slice(0, -1);
4578
+ }
4579
+ return op === "||" || op === "&&" || op === "??";
4580
+ } else {
4581
+ return false;
4582
+ }
4583
+ }
4571
4584
  function processBinaryOpExpression($0) {
4572
4585
  return processExpandedBinaryOpExpression(expandChainedComparisons($0));
4573
4586
  }
@@ -8058,14 +8071,15 @@ function processAssignments(statements) {
8058
8071
  let { lhs: $1, expression: $2 } = exp, tail = [], len3 = $1.length;
8059
8072
  let block;
8060
8073
  let ref13;
8061
- if (blockContainingStatement(exp) && !(ref13 = $1[$1.length - 1])?.[ref13.length - 1]?.special) {
8074
+ let ref14;
8075
+ if (blockContainingStatement(exp) && !(ref13 = $1[$1.length - 1])?.[ref13.length - 1]?.special && !isShortCircuitOp((ref14 = $1[$1.length - 1])?.[ref14.length - 1])) {
8062
8076
  block = makeBlockFragment();
8063
- let ref14;
8064
- if (ref14 = prependStatementExpressionBlock(
8077
+ let ref15;
8078
+ if (ref15 = prependStatementExpressionBlock(
8065
8079
  { type: "Initializer", expression: $2, children: [void 0, void 0, $2] },
8066
8080
  block
8067
8081
  )) {
8068
- const ref = ref14;
8082
+ const ref = ref15;
8069
8083
  exp.children = exp.children.map(($7) => $7 === $2 ? ref : $7);
8070
8084
  $2 = ref;
8071
8085
  } else {
@@ -8246,9 +8260,9 @@ function unchainOptionalMemberExpression(exp, ref, innerExp) {
8246
8260
  }
8247
8261
  j++;
8248
8262
  }
8249
- let ref15;
8250
- if (ref15 = conditions.length) {
8251
- const l = ref15;
8263
+ let ref16;
8264
+ if (ref16 = conditions.length) {
8265
+ const l = ref16;
8252
8266
  const cs = flatJoin(conditions, " && ");
8253
8267
  return {
8254
8268
  ...exp,
@@ -8284,8 +8298,8 @@ function attachPostfixStatementAsExpression(exp, post) {
8284
8298
  }
8285
8299
  function processTypes(node) {
8286
8300
  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];
8301
+ for (let ref17 = gatherRecursiveAll(node, ($11) => $11.type === "TypeUnary"), i8 = 0, len7 = ref17.length; i8 < len7; i8++) {
8302
+ const unary = ref17[i8];
8289
8303
  let suffixIndex = unary.suffix.length - 1;
8290
8304
  const results2 = [];
8291
8305
  while (suffixIndex >= 0) {
@@ -8364,10 +8378,10 @@ function processTypes(node) {
8364
8378
  const outer = unary.suffix.splice(suffixIndex + 1, Infinity);
8365
8379
  const space = getTrimmingSpace(unary);
8366
8380
  inplaceInsertTrimmingSpace(unary, "");
8367
- let ref17;
8368
- if (unary.suffix.length) ref17 = unary;
8369
- else ref17 = unary.t;
8370
- const t = ref17;
8381
+ let ref18;
8382
+ if (unary.suffix.length) ref18 = unary;
8383
+ else ref18 = unary.t;
8384
+ const t = ref18;
8371
8385
  const arg = makeNode({
8372
8386
  type: "TypeArgument",
8373
8387
  ts: true,
@@ -8412,18 +8426,18 @@ function processTypes(node) {
8412
8426
  return results1;
8413
8427
  }
8414
8428
  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];
8429
+ for (let ref19 = gatherRecursiveAll(statements, ($12) => $12.type === "StatementExpression"), i9 = 0, len8 = ref19.length; i9 < len8; i9++) {
8430
+ const exp = ref19[i9];
8417
8431
  const { maybe, statement } = exp;
8418
8432
  if ((maybe || statement.type === "ThrowStatement") && blockContainingStatement(exp)) {
8419
8433
  replaceNode(exp, statement);
8420
8434
  continue;
8421
8435
  }
8422
- let ref19;
8436
+ let ref20;
8423
8437
  switch (statement.type) {
8424
8438
  case "IfStatement": {
8425
- if (ref19 = expressionizeIfStatement(statement)) {
8426
- const expression = ref19;
8439
+ if (ref20 = expressionizeIfStatement(statement)) {
8440
+ const expression = ref20;
8427
8441
  replaceNode(statement, expression, exp);
8428
8442
  } else {
8429
8443
  replaceNode(statement, wrapIIFE([["", statement]]), exp);
@@ -8482,13 +8496,13 @@ function processNegativeIndexAccess(statements) {
8482
8496
  });
8483
8497
  }
8484
8498
  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)) {
8499
+ for (let ref21 = gatherRecursiveAll(statements, ($) => $.type === "FinallyClause" && $.parent?.type !== "TryStatement"), i10 = 0, len9 = ref21.length; i10 < len9; i10++) {
8500
+ let f = ref21[i10];
8501
+ let ref22;
8502
+ if (!((ref22 = blockContainingStatement(f)) && typeof ref22 === "object" && "block" in ref22 && "index" in ref22)) {
8489
8503
  throw new Error("finally clause must be inside try statement or block");
8490
8504
  }
8491
- const { block, index } = ref21;
8505
+ const { block, index } = ref22;
8492
8506
  const indent = block.expressions[index][0];
8493
8507
  const expressions = block.expressions.slice(index + 1);
8494
8508
  const t = makeNode({
@@ -8560,8 +8574,8 @@ function processBreaksContinues(statements) {
8560
8574
  }
8561
8575
  }
8562
8576
  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];
8577
+ for (let ref23 = gatherRecursiveAll(statements, ($13) => $13.type === "ClassExpression"), i11 = 0, len10 = ref23.length; i11 < len10; i11++) {
8578
+ const ce = ref23[i11];
8565
8579
  const { expressions } = ce.body;
8566
8580
  const indent = expressions[0]?.[0] ?? "\n";
8567
8581
  const autoBinds = expressions.filter(($14) => $14[1]?.autoBind);
@@ -8721,8 +8735,8 @@ async function processProgramAsync(root) {
8721
8735
  function processRepl(root, rootIIFE) {
8722
8736
  const topBlock = gatherRecursive(rootIIFE, ($21) => $21.type === "BlockStatement")[0];
8723
8737
  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];
8738
+ for (let ref24 = gatherRecursiveWithinFunction(topBlock, ($22) => $22.type === "Declaration"), i14 = 0, len12 = ref24.length; i14 < len12; i14++) {
8739
+ const decl = ref24[i14];
8726
8740
  if (!decl.names?.length) {
8727
8741
  continue;
8728
8742
  }
@@ -8735,8 +8749,8 @@ function processRepl(root, rootIIFE) {
8735
8749
  root.expressions.splice(i++, 0, ["", `var ${decl.names.join(",")}`, ";"]);
8736
8750
  }
8737
8751
  }
8738
- for (let ref24 = gatherRecursive(topBlock, ($23) => $23.type === "FunctionExpression"), i15 = 0, len13 = ref24.length; i15 < len13; i15++) {
8739
- const func = ref24[i15];
8752
+ for (let ref25 = gatherRecursive(topBlock, ($23) => $23.type === "FunctionExpression"), i15 = 0, len13 = ref25.length; i15 < len13; i15++) {
8753
+ const func = ref25[i15];
8740
8754
  if (func.name && func.parent?.type === "BlockStatement") {
8741
8755
  if (func.parent === topBlock) {
8742
8756
  replaceNode(func, void 0);
@@ -8748,8 +8762,8 @@ function processRepl(root, rootIIFE) {
8748
8762
  }
8749
8763
  }
8750
8764
  }
8751
- for (let ref25 = gatherRecursiveWithinFunction(topBlock, ($24) => $24.type === "ClassExpression"), i16 = 0, len14 = ref25.length; i16 < len14; i16++) {
8752
- const classExp = ref25[i16];
8765
+ for (let ref26 = gatherRecursiveWithinFunction(topBlock, ($24) => $24.type === "ClassExpression"), i16 = 0, len14 = ref26.length; i16 < len14; i16++) {
8766
+ const classExp = ref26[i16];
8753
8767
  let m8;
8754
8768
  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
8769
  classExp.children.unshift(classExp.name, "=");
@@ -8760,8 +8774,8 @@ function processRepl(root, rootIIFE) {
8760
8774
  function processPlaceholders(statements) {
8761
8775
  const placeholderMap = /* @__PURE__ */ new Map();
8762
8776
  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];
8777
+ for (let ref27 = gatherRecursiveAll(statements, ($25) => $25.type === "Placeholder"), i17 = 0, len15 = ref27.length; i17 < len15; i17++) {
8778
+ const exp = ref27[i17];
8765
8779
  let ancestor;
8766
8780
  if (exp.subtype === ".") {
8767
8781
  ({ ancestor } = findAncestor(
@@ -8873,8 +8887,8 @@ function processPlaceholders(statements) {
8873
8887
  for (let i18 = 0, len16 = placeholders.length; i18 < len16; i18++) {
8874
8888
  const placeholder = placeholders[i18];
8875
8889
  typeSuffix ??= placeholder.typeSuffix;
8876
- let ref27;
8877
- (ref27 = placeholder.children)[ref27.length - 1] = ref;
8890
+ let ref28;
8891
+ (ref28 = placeholder.children)[ref28.length - 1] = ref;
8878
8892
  }
8879
8893
  const { parent } = ancestor;
8880
8894
  const body = maybeUnwrap(ancestor);
@@ -8895,16 +8909,16 @@ function processPlaceholders(statements) {
8895
8909
  }
8896
8910
  case "PipelineExpression": {
8897
8911
  const i = findChildIndex(parent, ancestor);
8898
- let ref28;
8912
+ let ref29;
8899
8913
  if (i === 1) {
8900
- ref28 = ancestor === parent.children[i];
8914
+ ref29 = ancestor === parent.children[i];
8901
8915
  } else if (i === 2) {
8902
- ref28 = ancestor === parent.children[i][findChildIndex(parent.children[i], ancestor)][3];
8916
+ ref29 = ancestor === parent.children[i][findChildIndex(parent.children[i], ancestor)][3];
8903
8917
  } else {
8904
- ref28 = void 0;
8918
+ ref29 = void 0;
8905
8919
  }
8906
8920
  ;
8907
- outer = ref28;
8921
+ outer = ref29;
8908
8922
  break;
8909
8923
  }
8910
8924
  case "AssignmentExpression":
@@ -8922,9 +8936,9 @@ function processPlaceholders(statements) {
8922
8936
  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
8937
  parent.parent.body = fnExp;
8924
8938
  }
8925
- let ref29;
8926
- if (ref29 = getTrimmingSpace(body)) {
8927
- const ws = ref29;
8939
+ let ref30;
8940
+ if (ref30 = getTrimmingSpace(body)) {
8941
+ const ws = ref30;
8928
8942
  inplaceInsertTrimmingSpace(body, "");
8929
8943
  inplacePrepend(ws, fnExp);
8930
8944
  }
@@ -8968,8 +8982,8 @@ function reorderBindingRestProperty(props) {
8968
8982
  }
8969
8983
  ];
8970
8984
  }
8971
- let ref30;
8972
- if (Array.isArray(rest.delim) && (ref30 = rest.delim)[ref30.length - 1]?.token === ",") {
8985
+ let ref31;
8986
+ if (Array.isArray(rest.delim) && (ref31 = rest.delim)[ref31.length - 1]?.token === ",") {
8973
8987
  rest.delim = rest.delim.slice(0, -1);
8974
8988
  rest.children = [...rest.children.slice(0, -1), rest.delim];
8975
8989
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.11.0",
4
+ "version": "0.11.1",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",