@danielx/civet 0.7.2 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -1320,8 +1320,8 @@ ${input.slice(result.pos)}
1320
1320
  function replaceBlockExpression(node, child, replacement) {
1321
1321
  let found = false;
1322
1322
  const { expressions } = node;
1323
- for (let i = 0, l = expressions.length; i < l; i++) {
1324
- const statement = expressions[i];
1323
+ for (let i1 = 0, len2 = expressions.length; i1 < len2; i1++) {
1324
+ const statement = expressions[i1];
1325
1325
  const [, s] = statement;
1326
1326
  if (s === child) {
1327
1327
  statement[1] = replacement;
@@ -1382,9 +1382,9 @@ ${input.slice(result.pos)}
1382
1382
  }
1383
1383
  function insertSemicolon(statements) {
1384
1384
  const l = statements.length;
1385
- for (let i1 = 0, len2 = statements.length; i1 < len2; i1++) {
1386
- const i = i1;
1387
- const s = statements[i1];
1385
+ for (let i2 = 0, len1 = statements.length; i2 < len1; i2++) {
1386
+ const i = i2;
1387
+ const s = statements[i2];
1388
1388
  if (i < l - 1) {
1389
1389
  if (needsPrecedingSemicolon(statements[i + 1][1])) {
1390
1390
  const delim = s[2];
@@ -1402,8 +1402,8 @@ ${input.slice(result.pos)}
1402
1402
  return false;
1403
1403
  }
1404
1404
  if (Array.isArray(exp)) {
1405
- for (let i2 = 0, len1 = exp.length; i2 < len1; i2++) {
1406
- const child = exp[i2];
1405
+ for (let i3 = 0, len2 = exp.length; i3 < len2; i3++) {
1406
+ const child = exp[i3];
1407
1407
  if (!(child != null)) {
1408
1408
  continue;
1409
1409
  }
@@ -1464,9 +1464,12 @@ ${input.slice(result.pos)}
1464
1464
  return;
1465
1465
  }
1466
1466
  node = node;
1467
- node.parent = parent;
1467
+ if (parent != null) {
1468
+ node.parent = parent;
1469
+ }
1468
1470
  if (node.children) {
1469
- for (const child of node.children) {
1471
+ for (let ref1 = node.children, i1 = 0, len2 = ref1.length; i1 < len2; i1++) {
1472
+ const child = ref1[i1];
1470
1473
  addParentPointers(child, node);
1471
1474
  }
1472
1475
  }
@@ -1476,10 +1479,9 @@ ${input.slice(result.pos)}
1476
1479
  return deepCopy(node);
1477
1480
  }
1478
1481
  function removeParentPointers(node) {
1479
- if (node == null)
1480
- return;
1481
- if (typeof node !== "object")
1482
+ if (!(node != null && typeof node === "object")) {
1482
1483
  return;
1484
+ }
1483
1485
  if (Array.isArray(node)) {
1484
1486
  for (const child of node) {
1485
1487
  removeParentPointers(child);
@@ -1523,7 +1525,8 @@ ${input.slice(result.pos)}
1523
1525
  if (node?.type !== "BlockStatement")
1524
1526
  return false;
1525
1527
  const { bare, expressions } = node;
1526
- return bare && (expressions.length === 0 || expressions.length === 1 && expressions[0][1]?.type === "EmptyStatement");
1528
+ return bare && //expressions is like [], [, {type: "EmptyStatement"}]
1529
+ (expressions.length === 0 || expressions.length === 1 && expressions[0][1]?.type === "EmptyStatement");
1527
1530
  }
1528
1531
  function isFunction(node) {
1529
1532
  const { type } = node;
@@ -1571,8 +1574,8 @@ ${input.slice(result.pos)}
1571
1574
  if (!(node != null)) {
1572
1575
  return false;
1573
1576
  }
1574
- let ref1;
1575
1577
  let ref2;
1578
+ let ref3;
1576
1579
  switch (node.type) {
1577
1580
  case "ReturnStatement":
1578
1581
  case "ThrowStatement":
@@ -1581,10 +1584,10 @@ ${input.slice(result.pos)}
1581
1584
  return true;
1582
1585
  }
1583
1586
  case "IfStatement": {
1584
- return isExit(node.then) && isExit((ref1 = node.else)?.[ref1.length - 1]);
1587
+ return isExit(node.then) && isExit((ref2 = node.else)?.[ref2.length - 1]);
1585
1588
  }
1586
1589
  case "BlockStatement": {
1587
- return isExit((ref2 = node.expressions)[ref2.length - 1]?.[1]);
1590
+ return isExit((ref3 = node.expressions)[ref3.length - 1]?.[1]);
1588
1591
  }
1589
1592
  case "IterationStatement": {
1590
1593
  return node.condition?.type === "ParenthesizedExpression" && node.condition.expression?.type === "Literal" && node.condition.expression?.raw === "true" && gatherRecursiveWithinFunction(
@@ -1880,8 +1883,8 @@ ${input.slice(result.pos)}
1880
1883
  return;
1881
1884
  }
1882
1885
  if (Array.isArray(node)) {
1883
- for (let i1 = 0, len2 = node.length; i1 < len2; i1++) {
1884
- const child = node[i1];
1886
+ for (let i2 = 0, len1 = node.length; i2 < len1; i2++) {
1887
+ const child = node[i2];
1885
1888
  updateParentPointers(child, parent, depth);
1886
1889
  }
1887
1890
  return;
@@ -1891,8 +1894,8 @@ ${input.slice(result.pos)}
1891
1894
  node.parent = parent;
1892
1895
  }
1893
1896
  if (depth && isParent(node)) {
1894
- for (let ref3 = node.children, i2 = 0, len1 = ref3.length; i2 < len1; i2++) {
1895
- const child = ref3[i2];
1897
+ for (let ref4 = node.children, i3 = 0, len2 = ref4.length; i3 < len2; i3++) {
1898
+ const child = ref4[i3];
1896
1899
  updateParentPointers(child, node, depth - 1);
1897
1900
  }
1898
1901
  }
@@ -2022,9 +2025,9 @@ ${input.slice(result.pos)}
2022
2025
  }
2023
2026
  function flatJoin(array, separator) {
2024
2027
  const result = [];
2025
- for (let i3 = 0, len2 = array.length; i3 < len2; i3++) {
2026
- const i = i3;
2027
- const items = array[i3];
2028
+ for (let i4 = 0, len3 = array.length; i4 < len3; i4++) {
2029
+ const i = i4;
2030
+ const items = array[i4];
2028
2031
  if (i) {
2029
2032
  result.push(separator);
2030
2033
  }
@@ -2075,8 +2078,9 @@ ${input.slice(result.pos)}
2075
2078
  return { ancestor: void 0, child: node };
2076
2079
  }
2077
2080
  function gatherNodes(node, predicate) {
2078
- if (node == null)
2081
+ if (node == null || typeof node === "string") {
2079
2082
  return [];
2083
+ }
2080
2084
  if (Array.isArray(node)) {
2081
2085
  return node.flatMap((n) => gatherNodes(n, predicate));
2082
2086
  }
@@ -2084,24 +2088,30 @@ ${input.slice(result.pos)}
2084
2088
  return [node];
2085
2089
  }
2086
2090
  switch (node.type) {
2087
- case "BlockStatement":
2091
+ case "BlockStatement": {
2088
2092
  return [];
2089
- case "ForStatement":
2093
+ }
2094
+ case "ForStatement": {
2090
2095
  const isDec = node.declaration?.type === "Declaration";
2091
2096
  return node.children.flatMap((n) => {
2092
- if (isDec && n === node.declaration)
2097
+ if (isDec && n === node.declaration) {
2093
2098
  return [];
2094
- return gatherNodes(n, predicate);
2099
+ } else {
2100
+ return gatherNodes(n, predicate);
2101
+ }
2095
2102
  });
2096
- default:
2103
+ }
2104
+ default: {
2097
2105
  return gatherNodes(node.children, predicate);
2106
+ }
2098
2107
  }
2099
2108
  }
2100
2109
  function gatherRecursive(node, predicate, skipPredicate) {
2101
- if (node == null)
2110
+ if (node == null || typeof node === "string") {
2102
2111
  return [];
2112
+ }
2103
2113
  if (Array.isArray(node)) {
2104
- return node.flatMap((n) => gatherRecursive(n, predicate, skipPredicate));
2114
+ return node.flatMap(($) => gatherRecursive($, predicate, skipPredicate));
2105
2115
  }
2106
2116
  if (skipPredicate?.(node))
2107
2117
  return [];
@@ -2111,8 +2121,9 @@ ${input.slice(result.pos)}
2111
2121
  return gatherRecursive(node.children, predicate, skipPredicate);
2112
2122
  }
2113
2123
  function gatherRecursiveAll(node, predicate) {
2114
- if (node == null)
2124
+ if (node == null || typeof node === "string") {
2115
2125
  return [];
2126
+ }
2116
2127
  if (Array.isArray(node)) {
2117
2128
  return node.flatMap((n) => gatherRecursiveAll(n, predicate));
2118
2129
  }
@@ -2842,21 +2853,9 @@ ${input.slice(result.pos)}
2842
2853
  const { children, name, value } = p;
2843
2854
  const [ws] = children;
2844
2855
  switch (value && value.type) {
2845
- case "ArrayBindingPattern": {
2846
- let bindings = nonMatcherBindings(value);
2847
- if (!bindings.length) {
2848
- bindings = void 0;
2849
- }
2850
- return {
2851
- ...p,
2852
- children: [ws, name, bindings && ": ", bindings, p.delim]
2853
- };
2854
- }
2856
+ case "ArrayBindingPattern":
2855
2857
  case "ObjectBindingPattern": {
2856
- let bindings = nonMatcherBindings(value);
2857
- if (!bindings.properties.length) {
2858
- bindings = void 0;
2859
- }
2858
+ const bindings = nonMatcherBindings(value);
2860
2859
  return {
2861
2860
  ...p,
2862
2861
  children: [ws, name, bindings && ": ", bindings, p.delim]
@@ -3173,9 +3172,12 @@ ${input.slice(result.pos)}
3173
3172
  rootCondition.blockPrefix = getPatternBlockPrefix(pattern, ref, decl, suffix);
3174
3173
  }
3175
3174
  function processDeclarationConditions(node) {
3176
- gatherRecursiveAll(node, (n) => {
3177
- return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
3178
- }).forEach((s) => {
3175
+ gatherRecursiveAll(
3176
+ node,
3177
+ (n) => {
3178
+ return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
3179
+ }
3180
+ ).forEach((s) => {
3179
3181
  return processDeclarationConditionStatement(s);
3180
3182
  });
3181
3183
  }
@@ -4080,19 +4082,17 @@ ${input.slice(result.pos)}
4080
4082
  }
4081
4083
  var generate_default = gen;
4082
4084
  function prune(node) {
4083
- if (node === null || node === void 0) {
4085
+ if (!(node != null)) {
4084
4086
  return;
4085
4087
  }
4086
- if (node.length === 0) {
4088
+ if (typeof node === "string" && node.length === 0) {
4087
4089
  return;
4088
4090
  }
4089
4091
  if (node.parent != null) {
4090
4092
  delete node.parent;
4091
4093
  }
4092
4094
  if (Array.isArray(node)) {
4093
- const a = node.map(function(n) {
4094
- return prune(n);
4095
- }).filter(($) => !!$);
4095
+ const a = node.map(prune).filter(($) => $);
4096
4096
  if (a.length > 1) {
4097
4097
  return a;
4098
4098
  }
@@ -5810,6 +5810,7 @@ ${input.slice(result.pos)}
5810
5810
  NonPipelineArgumentPart,
5811
5811
  BinaryOpExpression,
5812
5812
  BinaryOpRHS,
5813
+ IsLike,
5813
5814
  WRHS,
5814
5815
  SingleLineBinaryOpRHS,
5815
5816
  RHS,
@@ -7225,22 +7226,12 @@ ${input.slice(result.pos)}
7225
7226
  function BinaryOpExpression(ctx, state2) {
7226
7227
  return (0, import_lib2.$EVENT)(ctx, state2, "BinaryOpExpression", BinaryOpExpression$0);
7227
7228
  }
7228
- var BinaryOpRHS$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$C)((0, import_lib2.$E)(_), IndentedFurther, Nested), (0, import_lib2.$S)(Is, (0, import_lib2.$E)(_), (0, import_lib2.$E)((0, import_lib2.$S)(Not, (0, import_lib2.$E)(_))), Like), (0, import_lib2.$E)(_), PatternExpressionList), function($skip, $loc, $0, $1, $2, $3, $4) {
7229
+ var BinaryOpRHS$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$C)((0, import_lib2.$E)(_), IndentedFurther, Nested), IsLike, (0, import_lib2.$E)(_), PatternExpressionList), function($skip, $loc, $0, $1, $2, $3, $4) {
7229
7230
  var ws1 = $1;
7230
7231
  var op = $2;
7231
7232
  var ws2 = $3;
7232
7233
  var patterns = $4;
7233
- return [
7234
- ws1,
7235
- {
7236
- type: "PatternTest",
7237
- children: op,
7238
- special: true,
7239
- negated: !!op[2]
7240
- },
7241
- ws2,
7242
- patterns
7243
- ];
7234
+ return [ws1, op, ws2, patterns];
7244
7235
  });
7245
7236
  var BinaryOpRHS$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(BinaryOp, RHS), function($skip, $loc, $0, $1, $2) {
7246
7237
  var op = $1;
@@ -7259,6 +7250,18 @@ ${input.slice(result.pos)}
7259
7250
  function BinaryOpRHS(ctx, state2) {
7260
7251
  return (0, import_lib2.$EVENT_C)(ctx, state2, "BinaryOpRHS", BinaryOpRHS$$);
7261
7252
  }
7253
+ var IsLike$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(Is, (0, import_lib2.$E)(_), (0, import_lib2.$E)((0, import_lib2.$S)(Not, (0, import_lib2.$E)(_))), Like), function($skip, $loc, $0, $1, $2, $3, $4) {
7254
+ var not = $3;
7255
+ return {
7256
+ type: "PatternTest",
7257
+ children: $0,
7258
+ special: true,
7259
+ negated: !!not
7260
+ };
7261
+ });
7262
+ function IsLike(ctx, state2) {
7263
+ return (0, import_lib2.$EVENT)(ctx, state2, "IsLike", IsLike$0);
7264
+ }
7262
7265
  var WRHS$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(PushIndent, (0, import_lib2.$E)((0, import_lib2.$S)(Nested, RHS)), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
7263
7266
  var wrhs = $2;
7264
7267
  if (!wrhs)
@@ -7280,8 +7283,8 @@ ${input.slice(result.pos)}
7280
7283
  function SingleLineBinaryOpRHS(ctx, state2) {
7281
7284
  return (0, import_lib2.$EVENT)(ctx, state2, "SingleLineBinaryOpRHS", SingleLineBinaryOpRHS$0);
7282
7285
  }
7283
- var RHS$0 = UnaryExpression;
7284
- var RHS$1 = ExpressionizedStatementWithTrailingCallExpressions;
7286
+ var RHS$0 = ExpressionizedStatementWithTrailingCallExpressions;
7287
+ var RHS$1 = UnaryExpression;
7285
7288
  var RHS$$ = [RHS$0, RHS$1];
7286
7289
  function RHS(ctx, state2) {
7287
7290
  return (0, import_lib2.$EVENT_C)(ctx, state2, "RHS", RHS$$);
@@ -9275,7 +9278,28 @@ ${input.slice(result.pos)}
9275
9278
  expression: fn
9276
9279
  };
9277
9280
  });
9278
- var FunctionExpression$4 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, __, (0, import_lib2.$N)((0, import_lib2.$EXPECT)($R13, "FunctionExpression /\\+\\+|--|[\\+\\-&]\\S/")), BinaryOp, __, NonPipelineAssignmentExpression, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
9281
+ var FunctionExpression$4 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, __, IsLike, __, PatternExpressionList, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
9282
+ var open = $1;
9283
+ var ws1 = $2;
9284
+ var op = $3;
9285
+ var ws2 = $4;
9286
+ var rhs = $5;
9287
+ var close = $6;
9288
+ const refA = makeRef("a");
9289
+ const fn = makeAmpersandFunction({
9290
+ ref: refA,
9291
+ body: processBinaryOpExpression([refA, [
9292
+ [ws1, op, ws2, rhs]
9293
+ // BinaryOpRHS
9294
+ ]])
9295
+ });
9296
+ return {
9297
+ type: "ParenthesizedExpression",
9298
+ children: [open, fn, close],
9299
+ expression: fn
9300
+ };
9301
+ });
9302
+ var FunctionExpression$5 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, __, (0, import_lib2.$N)((0, import_lib2.$EXPECT)($R13, "FunctionExpression /\\+\\+|--|[\\+\\-&]\\S/")), BinaryOp, __, NonPipelineAssignmentExpression, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
9279
9303
  var open = $1;
9280
9304
  var ws1 = $2;
9281
9305
  var op = $4;
@@ -9296,7 +9320,7 @@ ${input.slice(result.pos)}
9296
9320
  expression: fn
9297
9321
  };
9298
9322
  });
9299
- var FunctionExpression$$ = [FunctionExpression$0, FunctionExpression$1, FunctionExpression$2, FunctionExpression$3, FunctionExpression$4];
9323
+ var FunctionExpression$$ = [FunctionExpression$0, FunctionExpression$1, FunctionExpression$2, FunctionExpression$3, FunctionExpression$4, FunctionExpression$5];
9300
9324
  function FunctionExpression(ctx, state2) {
9301
9325
  return (0, import_lib2.$EVENT_C)(ctx, state2, "FunctionExpression", FunctionExpression$$);
9302
9326
  }
@@ -13516,7 +13540,7 @@ ${input.slice(result.pos)}
13516
13540
  function Comma(ctx, state2) {
13517
13541
  return (0, import_lib2.$EVENT)(ctx, state2, "Comma", Comma$0);
13518
13542
  }
13519
- var Comptime$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L138, 'Comptime "comptime"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
13543
+ var Comptime$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L138, 'Comptime "comptime"'), NonIdContinue, (0, import_lib2.$N)((0, import_lib2.$EXPECT)($L15, 'Comptime ":"'))), function($skip, $loc, $0, $1, $2, $3) {
13520
13544
  return { $loc, token: $1 };
13521
13545
  });
13522
13546
  function Comptime(ctx, state2) {
@@ -16658,10 +16682,18 @@ ${counts}`;
16658
16682
  if (options.ast) {
16659
16683
  return ast;
16660
16684
  }
16685
+ function checkErrors() {
16686
+ if (options.errors?.length) {
16687
+ throw new Error(`Parse errors: ${options.errors.map(($) => $.message).join("\n")} `);
16688
+ }
16689
+ ;
16690
+ return;
16691
+ }
16661
16692
  if (options.sourceMap || options.inlineMap) {
16662
16693
  const sm = SourceMap2(src);
16663
16694
  options.updateSourceMap = sm.updateSourceMap;
16664
16695
  const code = generate_default(ast, options);
16696
+ checkErrors();
16665
16697
  if (options.inlineMap) {
16666
16698
  return SourceMap2.remap(code, sm, filename, filename + ".tsx");
16667
16699
  } else {
@@ -16672,9 +16704,7 @@ ${counts}`;
16672
16704
  }
16673
16705
  }
16674
16706
  const result = generate_default(ast, options);
16675
- if (options.errors?.length) {
16676
- throw new Error(`Parse errors: ${options.errors.map(($) => $.message).join("\n")} `);
16677
- }
16707
+ checkErrors();
16678
16708
  return result;
16679
16709
  };
16680
16710
  var makeCache = function({ hits, trace } = {}) {
package/dist/main.js CHANGED
@@ -1313,8 +1313,8 @@ function makeBlockFragment() {
1313
1313
  function replaceBlockExpression(node, child, replacement) {
1314
1314
  let found = false;
1315
1315
  const { expressions } = node;
1316
- for (let i = 0, l = expressions.length; i < l; i++) {
1317
- const statement = expressions[i];
1316
+ for (let i1 = 0, len2 = expressions.length; i1 < len2; i1++) {
1317
+ const statement = expressions[i1];
1318
1318
  const [, s] = statement;
1319
1319
  if (s === child) {
1320
1320
  statement[1] = replacement;
@@ -1375,9 +1375,9 @@ function processBlocks(statements) {
1375
1375
  }
1376
1376
  function insertSemicolon(statements) {
1377
1377
  const l = statements.length;
1378
- for (let i1 = 0, len2 = statements.length; i1 < len2; i1++) {
1379
- const i = i1;
1380
- const s = statements[i1];
1378
+ for (let i2 = 0, len1 = statements.length; i2 < len1; i2++) {
1379
+ const i = i2;
1380
+ const s = statements[i2];
1381
1381
  if (i < l - 1) {
1382
1382
  if (needsPrecedingSemicolon(statements[i + 1][1])) {
1383
1383
  const delim = s[2];
@@ -1395,8 +1395,8 @@ function needsPrecedingSemicolon(exp) {
1395
1395
  return false;
1396
1396
  }
1397
1397
  if (Array.isArray(exp)) {
1398
- for (let i2 = 0, len1 = exp.length; i2 < len1; i2++) {
1399
- const child = exp[i2];
1398
+ for (let i3 = 0, len2 = exp.length; i3 < len2; i3++) {
1399
+ const child = exp[i3];
1400
1400
  if (!(child != null)) {
1401
1401
  continue;
1402
1402
  }
@@ -1457,9 +1457,12 @@ function addParentPointers(node, parent) {
1457
1457
  return;
1458
1458
  }
1459
1459
  node = node;
1460
- node.parent = parent;
1460
+ if (parent != null) {
1461
+ node.parent = parent;
1462
+ }
1461
1463
  if (node.children) {
1462
- for (const child of node.children) {
1464
+ for (let ref1 = node.children, i1 = 0, len2 = ref1.length; i1 < len2; i1++) {
1465
+ const child = ref1[i1];
1463
1466
  addParentPointers(child, node);
1464
1467
  }
1465
1468
  }
@@ -1469,10 +1472,9 @@ function clone(node) {
1469
1472
  return deepCopy(node);
1470
1473
  }
1471
1474
  function removeParentPointers(node) {
1472
- if (node == null)
1473
- return;
1474
- if (typeof node !== "object")
1475
+ if (!(node != null && typeof node === "object")) {
1475
1476
  return;
1477
+ }
1476
1478
  if (Array.isArray(node)) {
1477
1479
  for (const child of node) {
1478
1480
  removeParentPointers(child);
@@ -1516,7 +1518,8 @@ function isEmptyBareBlock(node) {
1516
1518
  if (node?.type !== "BlockStatement")
1517
1519
  return false;
1518
1520
  const { bare, expressions } = node;
1519
- return bare && (expressions.length === 0 || expressions.length === 1 && expressions[0][1]?.type === "EmptyStatement");
1521
+ return bare && //expressions is like [], [, {type: "EmptyStatement"}]
1522
+ (expressions.length === 0 || expressions.length === 1 && expressions[0][1]?.type === "EmptyStatement");
1520
1523
  }
1521
1524
  function isFunction(node) {
1522
1525
  const { type } = node;
@@ -1564,8 +1567,8 @@ function isExit(node) {
1564
1567
  if (!(node != null)) {
1565
1568
  return false;
1566
1569
  }
1567
- let ref1;
1568
1570
  let ref2;
1571
+ let ref3;
1569
1572
  switch (node.type) {
1570
1573
  case "ReturnStatement":
1571
1574
  case "ThrowStatement":
@@ -1574,10 +1577,10 @@ function isExit(node) {
1574
1577
  return true;
1575
1578
  }
1576
1579
  case "IfStatement": {
1577
- return isExit(node.then) && isExit((ref1 = node.else)?.[ref1.length - 1]);
1580
+ return isExit(node.then) && isExit((ref2 = node.else)?.[ref2.length - 1]);
1578
1581
  }
1579
1582
  case "BlockStatement": {
1580
- return isExit((ref2 = node.expressions)[ref2.length - 1]?.[1]);
1583
+ return isExit((ref3 = node.expressions)[ref3.length - 1]?.[1]);
1581
1584
  }
1582
1585
  case "IterationStatement": {
1583
1586
  return node.condition?.type === "ParenthesizedExpression" && node.condition.expression?.type === "Literal" && node.condition.expression?.raw === "true" && gatherRecursiveWithinFunction(
@@ -1873,8 +1876,8 @@ function updateParentPointers(node, parent, depth = 1) {
1873
1876
  return;
1874
1877
  }
1875
1878
  if (Array.isArray(node)) {
1876
- for (let i1 = 0, len2 = node.length; i1 < len2; i1++) {
1877
- const child = node[i1];
1879
+ for (let i2 = 0, len1 = node.length; i2 < len1; i2++) {
1880
+ const child = node[i2];
1878
1881
  updateParentPointers(child, parent, depth);
1879
1882
  }
1880
1883
  return;
@@ -1884,8 +1887,8 @@ function updateParentPointers(node, parent, depth = 1) {
1884
1887
  node.parent = parent;
1885
1888
  }
1886
1889
  if (depth && isParent(node)) {
1887
- for (let ref3 = node.children, i2 = 0, len1 = ref3.length; i2 < len1; i2++) {
1888
- const child = ref3[i2];
1890
+ for (let ref4 = node.children, i3 = 0, len2 = ref4.length; i3 < len2; i3++) {
1891
+ const child = ref4[i3];
1889
1892
  updateParentPointers(child, node, depth - 1);
1890
1893
  }
1891
1894
  }
@@ -2015,9 +2018,9 @@ function wrapWithReturn(expression) {
2015
2018
  }
2016
2019
  function flatJoin(array, separator) {
2017
2020
  const result = [];
2018
- for (let i3 = 0, len2 = array.length; i3 < len2; i3++) {
2019
- const i = i3;
2020
- const items = array[i3];
2021
+ for (let i4 = 0, len3 = array.length; i4 < len3; i4++) {
2022
+ const i = i4;
2023
+ const items = array[i4];
2021
2024
  if (i) {
2022
2025
  result.push(separator);
2023
2026
  }
@@ -2068,8 +2071,9 @@ function findAncestor(node, predicate, stopPredicate) {
2068
2071
  return { ancestor: void 0, child: node };
2069
2072
  }
2070
2073
  function gatherNodes(node, predicate) {
2071
- if (node == null)
2074
+ if (node == null || typeof node === "string") {
2072
2075
  return [];
2076
+ }
2073
2077
  if (Array.isArray(node)) {
2074
2078
  return node.flatMap((n) => gatherNodes(n, predicate));
2075
2079
  }
@@ -2077,24 +2081,30 @@ function gatherNodes(node, predicate) {
2077
2081
  return [node];
2078
2082
  }
2079
2083
  switch (node.type) {
2080
- case "BlockStatement":
2084
+ case "BlockStatement": {
2081
2085
  return [];
2082
- case "ForStatement":
2086
+ }
2087
+ case "ForStatement": {
2083
2088
  const isDec = node.declaration?.type === "Declaration";
2084
2089
  return node.children.flatMap((n) => {
2085
- if (isDec && n === node.declaration)
2090
+ if (isDec && n === node.declaration) {
2086
2091
  return [];
2087
- return gatherNodes(n, predicate);
2092
+ } else {
2093
+ return gatherNodes(n, predicate);
2094
+ }
2088
2095
  });
2089
- default:
2096
+ }
2097
+ default: {
2090
2098
  return gatherNodes(node.children, predicate);
2099
+ }
2091
2100
  }
2092
2101
  }
2093
2102
  function gatherRecursive(node, predicate, skipPredicate) {
2094
- if (node == null)
2103
+ if (node == null || typeof node === "string") {
2095
2104
  return [];
2105
+ }
2096
2106
  if (Array.isArray(node)) {
2097
- return node.flatMap((n) => gatherRecursive(n, predicate, skipPredicate));
2107
+ return node.flatMap(($) => gatherRecursive($, predicate, skipPredicate));
2098
2108
  }
2099
2109
  if (skipPredicate?.(node))
2100
2110
  return [];
@@ -2104,8 +2114,9 @@ function gatherRecursive(node, predicate, skipPredicate) {
2104
2114
  return gatherRecursive(node.children, predicate, skipPredicate);
2105
2115
  }
2106
2116
  function gatherRecursiveAll(node, predicate) {
2107
- if (node == null)
2117
+ if (node == null || typeof node === "string") {
2108
2118
  return [];
2119
+ }
2109
2120
  if (Array.isArray(node)) {
2110
2121
  return node.flatMap((n) => gatherRecursiveAll(n, predicate));
2111
2122
  }
@@ -2835,21 +2846,9 @@ function elideMatchersFromPropertyBindings(properties) {
2835
2846
  const { children, name, value } = p;
2836
2847
  const [ws] = children;
2837
2848
  switch (value && value.type) {
2838
- case "ArrayBindingPattern": {
2839
- let bindings = nonMatcherBindings(value);
2840
- if (!bindings.length) {
2841
- bindings = void 0;
2842
- }
2843
- return {
2844
- ...p,
2845
- children: [ws, name, bindings && ": ", bindings, p.delim]
2846
- };
2847
- }
2849
+ case "ArrayBindingPattern":
2848
2850
  case "ObjectBindingPattern": {
2849
- let bindings = nonMatcherBindings(value);
2850
- if (!bindings.properties.length) {
2851
- bindings = void 0;
2852
- }
2851
+ const bindings = nonMatcherBindings(value);
2853
2852
  return {
2854
2853
  ...p,
2855
2854
  children: [ws, name, bindings && ": ", bindings, p.delim]
@@ -3166,9 +3165,12 @@ function processDeclarationCondition(condition, rootCondition, parent) {
3166
3165
  rootCondition.blockPrefix = getPatternBlockPrefix(pattern, ref, decl, suffix);
3167
3166
  }
3168
3167
  function processDeclarationConditions(node) {
3169
- gatherRecursiveAll(node, (n) => {
3170
- return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
3171
- }).forEach((s) => {
3168
+ gatherRecursiveAll(
3169
+ node,
3170
+ (n) => {
3171
+ return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
3172
+ }
3173
+ ).forEach((s) => {
3172
3174
  return processDeclarationConditionStatement(s);
3173
3175
  });
3174
3176
  }
@@ -4073,19 +4075,17 @@ function gen(node, options) {
4073
4075
  }
4074
4076
  var generate_default = gen;
4075
4077
  function prune(node) {
4076
- if (node === null || node === void 0) {
4078
+ if (!(node != null)) {
4077
4079
  return;
4078
4080
  }
4079
- if (node.length === 0) {
4081
+ if (typeof node === "string" && node.length === 0) {
4080
4082
  return;
4081
4083
  }
4082
4084
  if (node.parent != null) {
4083
4085
  delete node.parent;
4084
4086
  }
4085
4087
  if (Array.isArray(node)) {
4086
- const a = node.map(function(n) {
4087
- return prune(n);
4088
- }).filter(($) => !!$);
4088
+ const a = node.map(prune).filter(($) => $);
4089
4089
  if (a.length > 1) {
4090
4090
  return a;
4091
4091
  }
@@ -5803,6 +5803,7 @@ var grammar = {
5803
5803
  NonPipelineArgumentPart,
5804
5804
  BinaryOpExpression,
5805
5805
  BinaryOpRHS,
5806
+ IsLike,
5806
5807
  WRHS,
5807
5808
  SingleLineBinaryOpRHS,
5808
5809
  RHS,
@@ -7218,22 +7219,12 @@ var BinaryOpExpression$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(UnaryExpress
7218
7219
  function BinaryOpExpression(ctx, state2) {
7219
7220
  return (0, import_lib2.$EVENT)(ctx, state2, "BinaryOpExpression", BinaryOpExpression$0);
7220
7221
  }
7221
- var BinaryOpRHS$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$C)((0, import_lib2.$E)(_), IndentedFurther, Nested), (0, import_lib2.$S)(Is, (0, import_lib2.$E)(_), (0, import_lib2.$E)((0, import_lib2.$S)(Not, (0, import_lib2.$E)(_))), Like), (0, import_lib2.$E)(_), PatternExpressionList), function($skip, $loc, $0, $1, $2, $3, $4) {
7222
+ var BinaryOpRHS$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$C)((0, import_lib2.$E)(_), IndentedFurther, Nested), IsLike, (0, import_lib2.$E)(_), PatternExpressionList), function($skip, $loc, $0, $1, $2, $3, $4) {
7222
7223
  var ws1 = $1;
7223
7224
  var op = $2;
7224
7225
  var ws2 = $3;
7225
7226
  var patterns = $4;
7226
- return [
7227
- ws1,
7228
- {
7229
- type: "PatternTest",
7230
- children: op,
7231
- special: true,
7232
- negated: !!op[2]
7233
- },
7234
- ws2,
7235
- patterns
7236
- ];
7227
+ return [ws1, op, ws2, patterns];
7237
7228
  });
7238
7229
  var BinaryOpRHS$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(BinaryOp, RHS), function($skip, $loc, $0, $1, $2) {
7239
7230
  var op = $1;
@@ -7252,6 +7243,18 @@ var BinaryOpRHS$$ = [BinaryOpRHS$0, BinaryOpRHS$1, BinaryOpRHS$2, BinaryOpRHS$3]
7252
7243
  function BinaryOpRHS(ctx, state2) {
7253
7244
  return (0, import_lib2.$EVENT_C)(ctx, state2, "BinaryOpRHS", BinaryOpRHS$$);
7254
7245
  }
7246
+ var IsLike$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(Is, (0, import_lib2.$E)(_), (0, import_lib2.$E)((0, import_lib2.$S)(Not, (0, import_lib2.$E)(_))), Like), function($skip, $loc, $0, $1, $2, $3, $4) {
7247
+ var not = $3;
7248
+ return {
7249
+ type: "PatternTest",
7250
+ children: $0,
7251
+ special: true,
7252
+ negated: !!not
7253
+ };
7254
+ });
7255
+ function IsLike(ctx, state2) {
7256
+ return (0, import_lib2.$EVENT)(ctx, state2, "IsLike", IsLike$0);
7257
+ }
7255
7258
  var WRHS$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(PushIndent, (0, import_lib2.$E)((0, import_lib2.$S)(Nested, RHS)), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
7256
7259
  var wrhs = $2;
7257
7260
  if (!wrhs)
@@ -7273,8 +7276,8 @@ var SingleLineBinaryOpRHS$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, impor
7273
7276
  function SingleLineBinaryOpRHS(ctx, state2) {
7274
7277
  return (0, import_lib2.$EVENT)(ctx, state2, "SingleLineBinaryOpRHS", SingleLineBinaryOpRHS$0);
7275
7278
  }
7276
- var RHS$0 = UnaryExpression;
7277
- var RHS$1 = ExpressionizedStatementWithTrailingCallExpressions;
7279
+ var RHS$0 = ExpressionizedStatementWithTrailingCallExpressions;
7280
+ var RHS$1 = UnaryExpression;
7278
7281
  var RHS$$ = [RHS$0, RHS$1];
7279
7282
  function RHS(ctx, state2) {
7280
7283
  return (0, import_lib2.$EVENT_C)(ctx, state2, "RHS", RHS$$);
@@ -9268,7 +9271,28 @@ var FunctionExpression$3 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, (
9268
9271
  expression: fn
9269
9272
  };
9270
9273
  });
9271
- var FunctionExpression$4 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, __, (0, import_lib2.$N)((0, import_lib2.$EXPECT)($R13, "FunctionExpression /\\+\\+|--|[\\+\\-&]\\S/")), BinaryOp, __, NonPipelineAssignmentExpression, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
9274
+ var FunctionExpression$4 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, __, IsLike, __, PatternExpressionList, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
9275
+ var open = $1;
9276
+ var ws1 = $2;
9277
+ var op = $3;
9278
+ var ws2 = $4;
9279
+ var rhs = $5;
9280
+ var close = $6;
9281
+ const refA = makeRef("a");
9282
+ const fn = makeAmpersandFunction({
9283
+ ref: refA,
9284
+ body: processBinaryOpExpression([refA, [
9285
+ [ws1, op, ws2, rhs]
9286
+ // BinaryOpRHS
9287
+ ]])
9288
+ });
9289
+ return {
9290
+ type: "ParenthesizedExpression",
9291
+ children: [open, fn, close],
9292
+ expression: fn
9293
+ };
9294
+ });
9295
+ var FunctionExpression$5 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, __, (0, import_lib2.$N)((0, import_lib2.$EXPECT)($R13, "FunctionExpression /\\+\\+|--|[\\+\\-&]\\S/")), BinaryOp, __, NonPipelineAssignmentExpression, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
9272
9296
  var open = $1;
9273
9297
  var ws1 = $2;
9274
9298
  var op = $4;
@@ -9289,7 +9313,7 @@ var FunctionExpression$4 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, _
9289
9313
  expression: fn
9290
9314
  };
9291
9315
  });
9292
- var FunctionExpression$$ = [FunctionExpression$0, FunctionExpression$1, FunctionExpression$2, FunctionExpression$3, FunctionExpression$4];
9316
+ var FunctionExpression$$ = [FunctionExpression$0, FunctionExpression$1, FunctionExpression$2, FunctionExpression$3, FunctionExpression$4, FunctionExpression$5];
9293
9317
  function FunctionExpression(ctx, state2) {
9294
9318
  return (0, import_lib2.$EVENT_C)(ctx, state2, "FunctionExpression", FunctionExpression$$);
9295
9319
  }
@@ -13509,7 +13533,7 @@ var Comma$0 = (0, import_lib2.$TV)((0, import_lib2.$EXPECT)($L25, 'Comma ","'),
13509
13533
  function Comma(ctx, state2) {
13510
13534
  return (0, import_lib2.$EVENT)(ctx, state2, "Comma", Comma$0);
13511
13535
  }
13512
- var Comptime$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L138, 'Comptime "comptime"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
13536
+ var Comptime$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L138, 'Comptime "comptime"'), NonIdContinue, (0, import_lib2.$N)((0, import_lib2.$EXPECT)($L15, 'Comptime ":"'))), function($skip, $loc, $0, $1, $2, $3) {
13513
13537
  return { $loc, token: $1 };
13514
13538
  });
13515
13539
  function Comptime(ctx, state2) {
@@ -16651,10 +16675,18 @@ ${counts}`;
16651
16675
  if (options.ast) {
16652
16676
  return ast;
16653
16677
  }
16678
+ function checkErrors() {
16679
+ if (options.errors?.length) {
16680
+ throw new Error(`Parse errors: ${options.errors.map(($) => $.message).join("\n")} `);
16681
+ }
16682
+ ;
16683
+ return;
16684
+ }
16654
16685
  if (options.sourceMap || options.inlineMap) {
16655
16686
  const sm = SourceMap2(src);
16656
16687
  options.updateSourceMap = sm.updateSourceMap;
16657
16688
  const code = generate_default(ast, options);
16689
+ checkErrors();
16658
16690
  if (options.inlineMap) {
16659
16691
  return SourceMap2.remap(code, sm, filename, filename + ".tsx");
16660
16692
  } else {
@@ -16665,9 +16697,7 @@ ${counts}`;
16665
16697
  }
16666
16698
  }
16667
16699
  const result = generate_default(ast, options);
16668
- if (options.errors?.length) {
16669
- throw new Error(`Parse errors: ${options.errors.map(($) => $.message).join("\n")} `);
16670
- }
16700
+ checkErrors();
16671
16701
  return result;
16672
16702
  };
16673
16703
  var makeCache = function({ hits, trace } = {}) {
package/dist/main.mjs CHANGED
@@ -1297,8 +1297,8 @@ function makeBlockFragment() {
1297
1297
  function replaceBlockExpression(node, child, replacement) {
1298
1298
  let found = false;
1299
1299
  const { expressions } = node;
1300
- for (let i = 0, l = expressions.length; i < l; i++) {
1301
- const statement = expressions[i];
1300
+ for (let i1 = 0, len2 = expressions.length; i1 < len2; i1++) {
1301
+ const statement = expressions[i1];
1302
1302
  const [, s] = statement;
1303
1303
  if (s === child) {
1304
1304
  statement[1] = replacement;
@@ -1359,9 +1359,9 @@ function processBlocks(statements) {
1359
1359
  }
1360
1360
  function insertSemicolon(statements) {
1361
1361
  const l = statements.length;
1362
- for (let i1 = 0, len2 = statements.length; i1 < len2; i1++) {
1363
- const i = i1;
1364
- const s = statements[i1];
1362
+ for (let i2 = 0, len1 = statements.length; i2 < len1; i2++) {
1363
+ const i = i2;
1364
+ const s = statements[i2];
1365
1365
  if (i < l - 1) {
1366
1366
  if (needsPrecedingSemicolon(statements[i + 1][1])) {
1367
1367
  const delim = s[2];
@@ -1379,8 +1379,8 @@ function needsPrecedingSemicolon(exp) {
1379
1379
  return false;
1380
1380
  }
1381
1381
  if (Array.isArray(exp)) {
1382
- for (let i2 = 0, len1 = exp.length; i2 < len1; i2++) {
1383
- const child = exp[i2];
1382
+ for (let i3 = 0, len2 = exp.length; i3 < len2; i3++) {
1383
+ const child = exp[i3];
1384
1384
  if (!(child != null)) {
1385
1385
  continue;
1386
1386
  }
@@ -1441,9 +1441,12 @@ function addParentPointers(node, parent) {
1441
1441
  return;
1442
1442
  }
1443
1443
  node = node;
1444
- node.parent = parent;
1444
+ if (parent != null) {
1445
+ node.parent = parent;
1446
+ }
1445
1447
  if (node.children) {
1446
- for (const child of node.children) {
1448
+ for (let ref1 = node.children, i1 = 0, len2 = ref1.length; i1 < len2; i1++) {
1449
+ const child = ref1[i1];
1447
1450
  addParentPointers(child, node);
1448
1451
  }
1449
1452
  }
@@ -1453,10 +1456,9 @@ function clone(node) {
1453
1456
  return deepCopy(node);
1454
1457
  }
1455
1458
  function removeParentPointers(node) {
1456
- if (node == null)
1457
- return;
1458
- if (typeof node !== "object")
1459
+ if (!(node != null && typeof node === "object")) {
1459
1460
  return;
1461
+ }
1460
1462
  if (Array.isArray(node)) {
1461
1463
  for (const child of node) {
1462
1464
  removeParentPointers(child);
@@ -1500,7 +1502,8 @@ function isEmptyBareBlock(node) {
1500
1502
  if (node?.type !== "BlockStatement")
1501
1503
  return false;
1502
1504
  const { bare, expressions } = node;
1503
- return bare && (expressions.length === 0 || expressions.length === 1 && expressions[0][1]?.type === "EmptyStatement");
1505
+ return bare && //expressions is like [], [, {type: "EmptyStatement"}]
1506
+ (expressions.length === 0 || expressions.length === 1 && expressions[0][1]?.type === "EmptyStatement");
1504
1507
  }
1505
1508
  function isFunction(node) {
1506
1509
  const { type } = node;
@@ -1548,8 +1551,8 @@ function isExit(node) {
1548
1551
  if (!(node != null)) {
1549
1552
  return false;
1550
1553
  }
1551
- let ref1;
1552
1554
  let ref2;
1555
+ let ref3;
1553
1556
  switch (node.type) {
1554
1557
  case "ReturnStatement":
1555
1558
  case "ThrowStatement":
@@ -1558,10 +1561,10 @@ function isExit(node) {
1558
1561
  return true;
1559
1562
  }
1560
1563
  case "IfStatement": {
1561
- return isExit(node.then) && isExit((ref1 = node.else)?.[ref1.length - 1]);
1564
+ return isExit(node.then) && isExit((ref2 = node.else)?.[ref2.length - 1]);
1562
1565
  }
1563
1566
  case "BlockStatement": {
1564
- return isExit((ref2 = node.expressions)[ref2.length - 1]?.[1]);
1567
+ return isExit((ref3 = node.expressions)[ref3.length - 1]?.[1]);
1565
1568
  }
1566
1569
  case "IterationStatement": {
1567
1570
  return node.condition?.type === "ParenthesizedExpression" && node.condition.expression?.type === "Literal" && node.condition.expression?.raw === "true" && gatherRecursiveWithinFunction(
@@ -1857,8 +1860,8 @@ function updateParentPointers(node, parent, depth = 1) {
1857
1860
  return;
1858
1861
  }
1859
1862
  if (Array.isArray(node)) {
1860
- for (let i1 = 0, len2 = node.length; i1 < len2; i1++) {
1861
- const child = node[i1];
1863
+ for (let i2 = 0, len1 = node.length; i2 < len1; i2++) {
1864
+ const child = node[i2];
1862
1865
  updateParentPointers(child, parent, depth);
1863
1866
  }
1864
1867
  return;
@@ -1868,8 +1871,8 @@ function updateParentPointers(node, parent, depth = 1) {
1868
1871
  node.parent = parent;
1869
1872
  }
1870
1873
  if (depth && isParent(node)) {
1871
- for (let ref3 = node.children, i2 = 0, len1 = ref3.length; i2 < len1; i2++) {
1872
- const child = ref3[i2];
1874
+ for (let ref4 = node.children, i3 = 0, len2 = ref4.length; i3 < len2; i3++) {
1875
+ const child = ref4[i3];
1873
1876
  updateParentPointers(child, node, depth - 1);
1874
1877
  }
1875
1878
  }
@@ -1999,9 +2002,9 @@ function wrapWithReturn(expression) {
1999
2002
  }
2000
2003
  function flatJoin(array, separator) {
2001
2004
  const result = [];
2002
- for (let i3 = 0, len2 = array.length; i3 < len2; i3++) {
2003
- const i = i3;
2004
- const items = array[i3];
2005
+ for (let i4 = 0, len3 = array.length; i4 < len3; i4++) {
2006
+ const i = i4;
2007
+ const items = array[i4];
2005
2008
  if (i) {
2006
2009
  result.push(separator);
2007
2010
  }
@@ -2052,8 +2055,9 @@ function findAncestor(node, predicate, stopPredicate) {
2052
2055
  return { ancestor: void 0, child: node };
2053
2056
  }
2054
2057
  function gatherNodes(node, predicate) {
2055
- if (node == null)
2058
+ if (node == null || typeof node === "string") {
2056
2059
  return [];
2060
+ }
2057
2061
  if (Array.isArray(node)) {
2058
2062
  return node.flatMap((n) => gatherNodes(n, predicate));
2059
2063
  }
@@ -2061,24 +2065,30 @@ function gatherNodes(node, predicate) {
2061
2065
  return [node];
2062
2066
  }
2063
2067
  switch (node.type) {
2064
- case "BlockStatement":
2068
+ case "BlockStatement": {
2065
2069
  return [];
2066
- case "ForStatement":
2070
+ }
2071
+ case "ForStatement": {
2067
2072
  const isDec = node.declaration?.type === "Declaration";
2068
2073
  return node.children.flatMap((n) => {
2069
- if (isDec && n === node.declaration)
2074
+ if (isDec && n === node.declaration) {
2070
2075
  return [];
2071
- return gatherNodes(n, predicate);
2076
+ } else {
2077
+ return gatherNodes(n, predicate);
2078
+ }
2072
2079
  });
2073
- default:
2080
+ }
2081
+ default: {
2074
2082
  return gatherNodes(node.children, predicate);
2083
+ }
2075
2084
  }
2076
2085
  }
2077
2086
  function gatherRecursive(node, predicate, skipPredicate) {
2078
- if (node == null)
2087
+ if (node == null || typeof node === "string") {
2079
2088
  return [];
2089
+ }
2080
2090
  if (Array.isArray(node)) {
2081
- return node.flatMap((n) => gatherRecursive(n, predicate, skipPredicate));
2091
+ return node.flatMap(($) => gatherRecursive($, predicate, skipPredicate));
2082
2092
  }
2083
2093
  if (skipPredicate?.(node))
2084
2094
  return [];
@@ -2088,8 +2098,9 @@ function gatherRecursive(node, predicate, skipPredicate) {
2088
2098
  return gatherRecursive(node.children, predicate, skipPredicate);
2089
2099
  }
2090
2100
  function gatherRecursiveAll(node, predicate) {
2091
- if (node == null)
2101
+ if (node == null || typeof node === "string") {
2092
2102
  return [];
2103
+ }
2093
2104
  if (Array.isArray(node)) {
2094
2105
  return node.flatMap((n) => gatherRecursiveAll(n, predicate));
2095
2106
  }
@@ -2819,21 +2830,9 @@ function elideMatchersFromPropertyBindings(properties) {
2819
2830
  const { children, name, value } = p;
2820
2831
  const [ws] = children;
2821
2832
  switch (value && value.type) {
2822
- case "ArrayBindingPattern": {
2823
- let bindings = nonMatcherBindings(value);
2824
- if (!bindings.length) {
2825
- bindings = void 0;
2826
- }
2827
- return {
2828
- ...p,
2829
- children: [ws, name, bindings && ": ", bindings, p.delim]
2830
- };
2831
- }
2833
+ case "ArrayBindingPattern":
2832
2834
  case "ObjectBindingPattern": {
2833
- let bindings = nonMatcherBindings(value);
2834
- if (!bindings.properties.length) {
2835
- bindings = void 0;
2836
- }
2835
+ const bindings = nonMatcherBindings(value);
2837
2836
  return {
2838
2837
  ...p,
2839
2838
  children: [ws, name, bindings && ": ", bindings, p.delim]
@@ -3150,9 +3149,12 @@ function processDeclarationCondition(condition, rootCondition, parent) {
3150
3149
  rootCondition.blockPrefix = getPatternBlockPrefix(pattern, ref, decl, suffix);
3151
3150
  }
3152
3151
  function processDeclarationConditions(node) {
3153
- gatherRecursiveAll(node, (n) => {
3154
- return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
3155
- }).forEach((s) => {
3152
+ gatherRecursiveAll(
3153
+ node,
3154
+ (n) => {
3155
+ return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
3156
+ }
3157
+ ).forEach((s) => {
3156
3158
  return processDeclarationConditionStatement(s);
3157
3159
  });
3158
3160
  }
@@ -4057,19 +4059,17 @@ function gen(node, options) {
4057
4059
  }
4058
4060
  var generate_default = gen;
4059
4061
  function prune(node) {
4060
- if (node === null || node === void 0) {
4062
+ if (!(node != null)) {
4061
4063
  return;
4062
4064
  }
4063
- if (node.length === 0) {
4065
+ if (typeof node === "string" && node.length === 0) {
4064
4066
  return;
4065
4067
  }
4066
4068
  if (node.parent != null) {
4067
4069
  delete node.parent;
4068
4070
  }
4069
4071
  if (Array.isArray(node)) {
4070
- const a = node.map(function(n) {
4071
- return prune(n);
4072
- }).filter(($) => !!$);
4072
+ const a = node.map(prune).filter(($) => $);
4073
4073
  if (a.length > 1) {
4074
4074
  return a;
4075
4075
  }
@@ -5787,6 +5787,7 @@ var grammar = {
5787
5787
  NonPipelineArgumentPart,
5788
5788
  BinaryOpExpression,
5789
5789
  BinaryOpRHS,
5790
+ IsLike,
5790
5791
  WRHS,
5791
5792
  SingleLineBinaryOpRHS,
5792
5793
  RHS,
@@ -7202,22 +7203,12 @@ var BinaryOpExpression$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(UnaryExpress
7202
7203
  function BinaryOpExpression(ctx, state2) {
7203
7204
  return (0, import_lib2.$EVENT)(ctx, state2, "BinaryOpExpression", BinaryOpExpression$0);
7204
7205
  }
7205
- var BinaryOpRHS$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$C)((0, import_lib2.$E)(_), IndentedFurther, Nested), (0, import_lib2.$S)(Is, (0, import_lib2.$E)(_), (0, import_lib2.$E)((0, import_lib2.$S)(Not, (0, import_lib2.$E)(_))), Like), (0, import_lib2.$E)(_), PatternExpressionList), function($skip, $loc, $0, $1, $2, $3, $4) {
7206
+ var BinaryOpRHS$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$C)((0, import_lib2.$E)(_), IndentedFurther, Nested), IsLike, (0, import_lib2.$E)(_), PatternExpressionList), function($skip, $loc, $0, $1, $2, $3, $4) {
7206
7207
  var ws1 = $1;
7207
7208
  var op = $2;
7208
7209
  var ws2 = $3;
7209
7210
  var patterns = $4;
7210
- return [
7211
- ws1,
7212
- {
7213
- type: "PatternTest",
7214
- children: op,
7215
- special: true,
7216
- negated: !!op[2]
7217
- },
7218
- ws2,
7219
- patterns
7220
- ];
7211
+ return [ws1, op, ws2, patterns];
7221
7212
  });
7222
7213
  var BinaryOpRHS$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(BinaryOp, RHS), function($skip, $loc, $0, $1, $2) {
7223
7214
  var op = $1;
@@ -7236,6 +7227,18 @@ var BinaryOpRHS$$ = [BinaryOpRHS$0, BinaryOpRHS$1, BinaryOpRHS$2, BinaryOpRHS$3]
7236
7227
  function BinaryOpRHS(ctx, state2) {
7237
7228
  return (0, import_lib2.$EVENT_C)(ctx, state2, "BinaryOpRHS", BinaryOpRHS$$);
7238
7229
  }
7230
+ var IsLike$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(Is, (0, import_lib2.$E)(_), (0, import_lib2.$E)((0, import_lib2.$S)(Not, (0, import_lib2.$E)(_))), Like), function($skip, $loc, $0, $1, $2, $3, $4) {
7231
+ var not = $3;
7232
+ return {
7233
+ type: "PatternTest",
7234
+ children: $0,
7235
+ special: true,
7236
+ negated: !!not
7237
+ };
7238
+ });
7239
+ function IsLike(ctx, state2) {
7240
+ return (0, import_lib2.$EVENT)(ctx, state2, "IsLike", IsLike$0);
7241
+ }
7239
7242
  var WRHS$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(PushIndent, (0, import_lib2.$E)((0, import_lib2.$S)(Nested, RHS)), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
7240
7243
  var wrhs = $2;
7241
7244
  if (!wrhs)
@@ -7257,8 +7260,8 @@ var SingleLineBinaryOpRHS$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, impor
7257
7260
  function SingleLineBinaryOpRHS(ctx, state2) {
7258
7261
  return (0, import_lib2.$EVENT)(ctx, state2, "SingleLineBinaryOpRHS", SingleLineBinaryOpRHS$0);
7259
7262
  }
7260
- var RHS$0 = UnaryExpression;
7261
- var RHS$1 = ExpressionizedStatementWithTrailingCallExpressions;
7263
+ var RHS$0 = ExpressionizedStatementWithTrailingCallExpressions;
7264
+ var RHS$1 = UnaryExpression;
7262
7265
  var RHS$$ = [RHS$0, RHS$1];
7263
7266
  function RHS(ctx, state2) {
7264
7267
  return (0, import_lib2.$EVENT_C)(ctx, state2, "RHS", RHS$$);
@@ -9252,7 +9255,28 @@ var FunctionExpression$3 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, (
9252
9255
  expression: fn
9253
9256
  };
9254
9257
  });
9255
- var FunctionExpression$4 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, __, (0, import_lib2.$N)((0, import_lib2.$EXPECT)($R13, "FunctionExpression /\\+\\+|--|[\\+\\-&]\\S/")), BinaryOp, __, NonPipelineAssignmentExpression, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
9258
+ var FunctionExpression$4 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, __, IsLike, __, PatternExpressionList, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
9259
+ var open = $1;
9260
+ var ws1 = $2;
9261
+ var op = $3;
9262
+ var ws2 = $4;
9263
+ var rhs = $5;
9264
+ var close = $6;
9265
+ const refA = makeRef("a");
9266
+ const fn = makeAmpersandFunction({
9267
+ ref: refA,
9268
+ body: processBinaryOpExpression([refA, [
9269
+ [ws1, op, ws2, rhs]
9270
+ // BinaryOpRHS
9271
+ ]])
9272
+ });
9273
+ return {
9274
+ type: "ParenthesizedExpression",
9275
+ children: [open, fn, close],
9276
+ expression: fn
9277
+ };
9278
+ });
9279
+ var FunctionExpression$5 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, __, (0, import_lib2.$N)((0, import_lib2.$EXPECT)($R13, "FunctionExpression /\\+\\+|--|[\\+\\-&]\\S/")), BinaryOp, __, NonPipelineAssignmentExpression, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
9256
9280
  var open = $1;
9257
9281
  var ws1 = $2;
9258
9282
  var op = $4;
@@ -9273,7 +9297,7 @@ var FunctionExpression$4 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, _
9273
9297
  expression: fn
9274
9298
  };
9275
9299
  });
9276
- var FunctionExpression$$ = [FunctionExpression$0, FunctionExpression$1, FunctionExpression$2, FunctionExpression$3, FunctionExpression$4];
9300
+ var FunctionExpression$$ = [FunctionExpression$0, FunctionExpression$1, FunctionExpression$2, FunctionExpression$3, FunctionExpression$4, FunctionExpression$5];
9277
9301
  function FunctionExpression(ctx, state2) {
9278
9302
  return (0, import_lib2.$EVENT_C)(ctx, state2, "FunctionExpression", FunctionExpression$$);
9279
9303
  }
@@ -13493,7 +13517,7 @@ var Comma$0 = (0, import_lib2.$TV)((0, import_lib2.$EXPECT)($L25, 'Comma ","'),
13493
13517
  function Comma(ctx, state2) {
13494
13518
  return (0, import_lib2.$EVENT)(ctx, state2, "Comma", Comma$0);
13495
13519
  }
13496
- var Comptime$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L138, 'Comptime "comptime"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
13520
+ var Comptime$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L138, 'Comptime "comptime"'), NonIdContinue, (0, import_lib2.$N)((0, import_lib2.$EXPECT)($L15, 'Comptime ":"'))), function($skip, $loc, $0, $1, $2, $3) {
13497
13521
  return { $loc, token: $1 };
13498
13522
  });
13499
13523
  function Comptime(ctx, state2) {
@@ -16635,10 +16659,18 @@ ${counts}`;
16635
16659
  if (options.ast) {
16636
16660
  return ast;
16637
16661
  }
16662
+ function checkErrors() {
16663
+ if (options.errors?.length) {
16664
+ throw new Error(`Parse errors: ${options.errors.map(($) => $.message).join("\n")} `);
16665
+ }
16666
+ ;
16667
+ return;
16668
+ }
16638
16669
  if (options.sourceMap || options.inlineMap) {
16639
16670
  const sm = SourceMap2(src);
16640
16671
  options.updateSourceMap = sm.updateSourceMap;
16641
16672
  const code = generate_default(ast, options);
16673
+ checkErrors();
16642
16674
  if (options.inlineMap) {
16643
16675
  return SourceMap2.remap(code, sm, filename, filename + ".tsx");
16644
16676
  } else {
@@ -16649,9 +16681,7 @@ ${counts}`;
16649
16681
  }
16650
16682
  }
16651
16683
  const result = generate_default(ast, options);
16652
- if (options.errors?.length) {
16653
- throw new Error(`Parse errors: ${options.errors.map(($) => $.message).join("\n")} `);
16654
- }
16684
+ checkErrors();
16655
16685
  return result;
16656
16686
  };
16657
16687
  var makeCache = function({ hits, trace } = {}) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.7.2",
4
+ "version": "0.7.4",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",