@danielx/civet 0.7.8 → 0.7.10

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
@@ -28,9 +28,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  mod
29
29
  ));
30
30
 
31
- // node_modules/.pnpm/@danielx+hera@0.8.13/node_modules/@danielx/hera/dist/machine.js
31
+ // node_modules/@danielx/hera/dist/machine.js
32
32
  var require_machine = __commonJS({
33
- "node_modules/.pnpm/@danielx+hera@0.8.13/node_modules/@danielx/hera/dist/machine.js"(exports, module) {
33
+ "node_modules/@danielx/hera/dist/machine.js"(exports, module) {
34
34
  "use strict";
35
35
  var __defProp2 = Object.defineProperty;
36
36
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
@@ -69,6 +69,7 @@ var require_machine = __commonJS({
69
69
  $TS: () => $TS2,
70
70
  $TV: () => $TV2,
71
71
  $Y: () => $Y2,
72
+ ParseError: () => ParseError2,
72
73
  Validator: () => Validator2
73
74
  });
74
75
  module.exports = __toCommonJS(machine_exports);
@@ -435,11 +436,10 @@ ${input.slice(result.pos)}
435
436
  hint = JSON.stringify(hint);
436
437
  else
437
438
  hint = "EOF";
438
- const error = new ParseError(`${filename2}:${line}:${column} Failed to parse
439
- Expected:
439
+ const error = new ParseError2("Failed to parse", `Expected:
440
440
  ${expectations.join("\n ")}
441
441
  Found: ${hint}
442
- `, "ParseError", filename2, line, column, maxFailPos);
442
+ `, filename2, line, column, maxFailPos);
443
443
  throw error;
444
444
  }
445
445
  if (result) {
@@ -462,15 +462,21 @@ ${input.slice(result.pos)}
462
462
  reset
463
463
  };
464
464
  }
465
- var ParseError = class extends Error {
466
- constructor(message, name, filename2, line, column, offset) {
465
+ var ParseError2 = class extends Error {
466
+ constructor(header, body, filename2, line, column, offset) {
467
+ let message = `${filename2}:${line}:${column} ${header}`;
468
+ if (body)
469
+ message += `
470
+ ${body}`;
467
471
  super(message);
468
- this.message = message;
469
- this.name = name;
472
+ this.header = header;
473
+ this.body = body;
470
474
  this.filename = filename2;
471
475
  this.line = line;
472
476
  this.column = column;
473
477
  this.offset = offset;
478
+ this.name = "ParseError";
479
+ this.message = message;
474
480
  }
475
481
  };
476
482
  }
@@ -528,6 +534,7 @@ __export(lib_exports, {
528
534
  processAssignmentDeclaration: () => processAssignmentDeclaration,
529
535
  processBinaryOpExpression: () => processBinaryOpExpression,
530
536
  processCallMemberExpression: () => processCallMemberExpression,
537
+ processCoffeeDo: () => processCoffeeDo,
531
538
  processCoffeeInterpolation: () => processCoffeeInterpolation,
532
539
  processForInOf: () => processForInOf,
533
540
  processProgram: () => processProgram,
@@ -1229,6 +1236,56 @@ function skipImplicitArguments(args) {
1229
1236
  }
1230
1237
  return false;
1231
1238
  }
1239
+ function processCoffeeDo(ws, expression) {
1240
+ ws = insertTrimmingSpace(ws, "");
1241
+ const args = [];
1242
+ if (typeof expression === "object" && expression != null && "type" in expression && expression.type === "ArrowFunction" || typeof expression === "object" && expression != null && "type" in expression && expression.type === "FunctionExpression") {
1243
+ const { parameters } = expression;
1244
+ const newParameters = {
1245
+ ...parameters,
1246
+ children: (() => {
1247
+ const results = [];
1248
+ for (let ref6 = parameters.children, i1 = 0, len3 = ref6.length; i1 < len3; i1++) {
1249
+ let parameter = ref6[i1];
1250
+ if (typeof parameter === "object" && parameter != null && "type" in parameter && parameter.type === "Parameter") {
1251
+ let ref7;
1252
+ if (ref7 = parameter.initializer) {
1253
+ const initializer = ref7;
1254
+ args.push(initializer.expression, parameter.delim);
1255
+ parameter = {
1256
+ ...parameter,
1257
+ initializer: void 0,
1258
+ children: parameter.children.filter((a2) => a2 !== initializer)
1259
+ };
1260
+ } else {
1261
+ args.push(parameter.children.filter(
1262
+ (a3) => a3 !== parameter.typeSuffix
1263
+ ));
1264
+ }
1265
+ }
1266
+ results.push(parameter);
1267
+ }
1268
+ return results;
1269
+ })()
1270
+ };
1271
+ expression = {
1272
+ ...expression,
1273
+ parameters: newParameters,
1274
+ children: expression.children.map(($) => $ === parameters ? newParameters : $)
1275
+ };
1276
+ }
1277
+ return {
1278
+ type: "CallExpression",
1279
+ children: [
1280
+ makeLeftHandSideExpression(expression),
1281
+ {
1282
+ type: "Call",
1283
+ args,
1284
+ children: ["(", args, ")"]
1285
+ }
1286
+ ]
1287
+ };
1288
+ }
1232
1289
 
1233
1290
  // source/parser/block.civet
1234
1291
  function blockWithPrefix(prefixStatements, block) {
@@ -1389,6 +1446,9 @@ function needsPrecedingSemicolon(exp) {
1389
1446
  }
1390
1447
  return false;
1391
1448
  }
1449
+ if (isToken(exp)) {
1450
+ exp = exp.token;
1451
+ }
1392
1452
  if (typeof exp === "string") {
1393
1453
  return /^\s*[\(\[\`\+\-\/]/.test(exp);
1394
1454
  }
@@ -1824,24 +1884,29 @@ function makeAmpersandFunction(rhs) {
1824
1884
  }
1825
1885
  return fn;
1826
1886
  }
1887
+ var skipParens = /* @__PURE__ */ new Set([
1888
+ "AmpersandRef",
1889
+ "CallExpression",
1890
+ "Identifier",
1891
+ "JSXElement",
1892
+ "JSXFragment",
1893
+ "Literal",
1894
+ "MemberExpression",
1895
+ "NewExpression",
1896
+ "ParenthesizedExpression",
1897
+ "Ref",
1898
+ "Placeholder",
1899
+ "StatementExpression"
1900
+ // wrapIIFE
1901
+ ]);
1827
1902
  function makeLeftHandSideExpression(expression) {
1828
- if (expression.parenthesized) {
1829
- return expression;
1830
- }
1831
- switch (expression.type) {
1832
- case "AmpersandRef":
1833
- case "CallExpression":
1834
- case "Identifier":
1835
- case "JSXElement":
1836
- case "JSXFragment":
1837
- case "Literal":
1838
- case "MemberExpression":
1839
- case "NewExpression":
1840
- case "ParenthesizedExpression":
1841
- case "Ref":
1842
- case "Placeholder":
1843
- case "StatementExpression":
1903
+ if (isASTNodeObject(expression)) {
1904
+ if (expression.parenthesized) {
1844
1905
  return expression;
1906
+ }
1907
+ if (skipParens.has(expression.type)) {
1908
+ return expression;
1909
+ }
1845
1910
  }
1846
1911
  return makeNode({
1847
1912
  type: "ParenthesizedExpression",
@@ -3214,7 +3279,6 @@ function processDeclarationConditionStatement(s) {
3214
3279
  if (s.negated) {
3215
3280
  let m;
3216
3281
  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) && m.children[0] === "!" && typeof m.children[1] === "object" && m.children[1] != null && "type" in m.children[1] && m.children[1].type === "ParenthesizedExpression")) {
3217
- console.log(condition.expression);
3218
3282
  throw new Error("Unsupported negated condition");
3219
3283
  }
3220
3284
  const { children } = condition.expression.children[1];
@@ -4107,49 +4171,71 @@ function stringify(node) {
4107
4171
  return `${node}`;
4108
4172
  }
4109
4173
  }
4110
- function gen(node, options) {
4111
- if (node === null || node === void 0) {
4112
- return "";
4113
- }
4114
- if (typeof node === "string") {
4115
- options?.updateSourceMap?.(node);
4116
- return node;
4117
- }
4118
- if (Array.isArray(node)) {
4119
- return node.map(function(child) {
4120
- return gen(child, options);
4121
- }).join("");
4122
- }
4123
- if (typeof node === "object") {
4124
- if (options.js && node.ts) {
4125
- return "";
4126
- }
4127
- if (!options.js && node.js) {
4174
+ function gen(root, options) {
4175
+ const updateSourceMap = options?.sourceMap?.updateSourceMap;
4176
+ return recurse(root);
4177
+ function recurse(node) {
4178
+ if (!(node != null)) {
4128
4179
  return "";
4129
4180
  }
4130
- if (node.type === "Error") {
4131
- options.errors ??= [];
4132
- options.errors.push(node);
4133
- return "";
4181
+ if (typeof node === "string") {
4182
+ updateSourceMap?.(node);
4183
+ return node;
4134
4184
  }
4135
- if (node.$loc != null) {
4136
- const { token, $loc } = node;
4137
- options?.updateSourceMap?.(token, $loc.pos);
4138
- return token;
4185
+ if (Array.isArray(node)) {
4186
+ return node.map(recurse).join("");
4139
4187
  }
4140
- if (!node.children) {
4141
- switch (node.type) {
4142
- case "Ref": {
4143
- throw new Error(`Unpopulated ref ${stringify(node)}`);
4188
+ if (typeof node === "object") {
4189
+ if (options.js && node.ts) {
4190
+ return "";
4191
+ }
4192
+ if (!options.js && node.js) {
4193
+ return "";
4194
+ }
4195
+ if (node.type === "Error") {
4196
+ const filename2 = options?.filename ?? "unknown";
4197
+ let line = "?";
4198
+ let column = "?";
4199
+ let offset;
4200
+ if (options && typeof options === "object" && "sourceMap" in options) {
4201
+ const { sourceMap } = options;
4202
+ line = sourceMap.data.srcLine + 1;
4203
+ column = sourceMap.data.srcColumn + 1;
4204
+ offset = sourceMap.data.srcOffset;
4205
+ }
4206
+ options.errors ??= [];
4207
+ options.errors.push(new import_lib3.ParseError(
4208
+ node.message,
4209
+ void 0,
4210
+ // body
4211
+ filename2,
4212
+ line,
4213
+ column,
4214
+ offset
4215
+ ));
4216
+ return "";
4217
+ }
4218
+ if (node.$loc != null) {
4219
+ const { token, $loc } = node;
4220
+ updateSourceMap?.(token, $loc.pos);
4221
+ return token;
4222
+ }
4223
+ if (!node.children) {
4224
+ switch (node.type) {
4225
+ case "Ref": {
4226
+ throw new Error(`Unpopulated ref ${stringify(node)}`);
4227
+ }
4144
4228
  }
4229
+ debugger;
4230
+ throw new Error(`Unknown node ${stringify(node)}`);
4145
4231
  }
4146
- debugger;
4147
- throw new Error(`Unknown node ${stringify(node)}`);
4232
+ return recurse(node.children);
4148
4233
  }
4149
- return gen(node.children, options);
4234
+ debugger;
4235
+ throw new Error(`Unknown node ${stringify(node)}`);
4150
4236
  }
4151
- debugger;
4152
- throw new Error(`Unknown node ${stringify(node)}`);
4237
+ ;
4238
+ return recurse;
4153
4239
  }
4154
4240
  var generate_default = gen;
4155
4241
  function prune(node) {
@@ -5253,7 +5339,8 @@ function processAssignments(statements) {
5253
5339
  while (expr.type === "ParenthesizedExpression") {
5254
5340
  expr = expr.expression;
5255
5341
  }
5256
- if (expr.type === "AssignmentExpression" || expr.type === "UpdateExpression") {
5342
+ let m;
5343
+ if (m = expr.type, m === "AssignmentExpression" || m === "UpdateExpression") {
5257
5344
  if (expr.type === "UpdateExpression" && expr.children[0] === expr.assigned) {
5258
5345
  pre.push("(");
5259
5346
  post.push([", ", lhs, ")"]);
@@ -5267,26 +5354,31 @@ function processAssignments(statements) {
5267
5354
  return;
5268
5355
  }
5269
5356
  const pre = [], post = [];
5357
+ let ref4;
5270
5358
  switch (exp.type) {
5271
- case "AssignmentExpression":
5359
+ case "AssignmentExpression": {
5272
5360
  if (!exp.lhs)
5273
5361
  return;
5274
5362
  exp.lhs.forEach((lhsPart, i) => {
5275
- let newLhs2 = extractAssignment(lhsPart[1]);
5276
- if (newLhs2) {
5277
- return lhsPart[1] = newLhs2;
5363
+ let ref5;
5364
+ if (ref5 = extractAssignment(lhsPart[1])) {
5365
+ const newLhs = ref5;
5366
+ return lhsPart[1] = newLhs;
5278
5367
  }
5279
5368
  ;
5280
5369
  return;
5281
5370
  });
5282
5371
  break;
5283
- case "UpdateExpression":
5284
- let newLhs = extractAssignment(exp.assigned);
5285
- if (newLhs) {
5372
+ }
5373
+ case "UpdateExpression": {
5374
+ if (ref4 = extractAssignment(exp.assigned)) {
5375
+ const newLhs = ref4;
5286
5376
  const i = exp.children.indexOf(exp.assigned);
5287
5377
  exp.assigned = exp.children[i] = newLhs;
5288
5378
  }
5379
+ ;
5289
5380
  break;
5381
+ }
5290
5382
  }
5291
5383
  if (pre.length)
5292
5384
  exp.children.unshift(...pre);
@@ -5296,13 +5388,7 @@ function processAssignments(statements) {
5296
5388
  const { assigned } = exp;
5297
5389
  const ref = makeRef();
5298
5390
  const newMemberExp = unchainOptionalMemberExpression(assigned, ref, (children) => {
5299
- return exp.children.map((c) => {
5300
- if (c === assigned) {
5301
- return children;
5302
- } else {
5303
- return c;
5304
- }
5305
- });
5391
+ return exp.children.map(($) => $ === assigned ? children : $);
5306
5392
  });
5307
5393
  if (newMemberExp !== assigned) {
5308
5394
  if (newMemberExp.usesRef) {
@@ -5324,38 +5410,34 @@ function processAssignments(statements) {
5324
5410
  statements,
5325
5411
  (n) => n.type === "AssignmentExpression" && n.names === null,
5326
5412
  (exp) => {
5327
- let { lhs: $1, expression: $2 } = exp, tail = [], i = 0, len3 = $1.length;
5413
+ let { lhs: $1, expression: $2 } = exp, tail = [], len3 = $1.length;
5328
5414
  let block;
5329
- let ref4;
5330
- if (exp.parent?.type === "BlockStatement" && !(ref4 = $1[$1.length - 1])?.[ref4.length - 1]?.special) {
5415
+ let ref6;
5416
+ if (exp.parent?.type === "BlockStatement" && !(ref6 = $1[$1.length - 1])?.[ref6.length - 1]?.special) {
5331
5417
  block = makeBlockFragment();
5332
- let ref5;
5333
- if (ref5 = prependStatementExpressionBlock(
5418
+ let ref7;
5419
+ if (ref7 = prependStatementExpressionBlock(
5334
5420
  { type: "Initializer", expression: $2, children: [void 0, void 0, $2] },
5335
5421
  block
5336
5422
  )) {
5337
- const ref = ref5;
5338
- exp.children = exp.children.map(function(c) {
5339
- if (c === $2)
5340
- return ref;
5341
- else
5342
- return c;
5343
- });
5423
+ const ref = ref7;
5424
+ exp.children = exp.children.map(($3) => $3 === $2 ? ref : $3);
5344
5425
  $2 = ref;
5345
5426
  } else {
5346
5427
  block = void 0;
5347
5428
  }
5348
5429
  }
5349
- if ($1.some((left) => left[left.length - 1].special)) {
5430
+ let ref8;
5431
+ if ($1.some(($4) => (ref8 = $4)[ref8.length - 1].special)) {
5350
5432
  if ($1.length !== 1)
5351
5433
  throw new Error("Only one assignment with id= is allowed");
5352
5434
  const [, lhs, , op] = $1[0];
5353
5435
  const { call, omitLhs } = op;
5354
- const index2 = exp.children.indexOf($2);
5355
- if (index2 < 0)
5436
+ const index = exp.children.indexOf($2);
5437
+ if (index < 0)
5356
5438
  throw new Error("Assertion error: exp not in AssignmentExpression");
5357
5439
  exp.children.splice(
5358
- index2,
5440
+ index,
5359
5441
  1,
5360
5442
  exp.expression = $2 = [call, "(", lhs, ", ", $2, ")"]
5361
5443
  );
@@ -5364,12 +5446,15 @@ function processAssignments(statements) {
5364
5446
  }
5365
5447
  }
5366
5448
  let wrapped = false;
5449
+ let i = 0;
5367
5450
  while (i < len3) {
5368
5451
  const lastAssignment = $1[i++];
5369
5452
  const [, lhs, , op] = lastAssignment;
5370
- if (op.token !== "=")
5453
+ if (!(op.token === "=")) {
5371
5454
  continue;
5372
- if (lhs.type === "ObjectExpression" || lhs.type === "ObjectBindingPattern") {
5455
+ }
5456
+ let m1;
5457
+ if (m1 = lhs.type, m1 === "ObjectExpression" || m1 === "ObjectBindingPattern") {
5373
5458
  if (!wrapped) {
5374
5459
  wrapped = true;
5375
5460
  lhs.children.splice(0, 0, "(");
@@ -5382,6 +5467,7 @@ function processAssignments(statements) {
5382
5467
  const lastAssignment = $1[i];
5383
5468
  if (lastAssignment[3].token === "=") {
5384
5469
  const lhs = lastAssignment[1];
5470
+ let m2;
5385
5471
  if (lhs.type === "MemberExpression") {
5386
5472
  const members = lhs.children;
5387
5473
  const lastMember = members[members.length - 1];
@@ -5405,9 +5491,9 @@ function processAssignments(statements) {
5405
5491
  }
5406
5492
  exp.children = [$1];
5407
5493
  exp.names = [];
5408
- return exp;
5494
+ break;
5409
5495
  }
5410
- } else if (lhs.type === "ObjectBindingPattern" || lhs.type === "ArrayBindingPattern") {
5496
+ } else if (m2 = lhs.type, m2 === "ObjectBindingPattern" || m2 === "ArrayBindingPattern") {
5411
5497
  processBindingPatternLHS(lhs, tail);
5412
5498
  }
5413
5499
  }
@@ -5440,10 +5526,12 @@ function processAssignments(statements) {
5440
5526
  i--;
5441
5527
  }
5442
5528
  exp.names = $1.flatMap(([, l]) => l.names || []);
5443
- const index = exp.children.indexOf($2);
5444
- if (index < 0)
5445
- throw new Error("Assertion error: exp not in AssignmentExpression");
5446
- exp.children.splice(index + 1, 0, ...tail);
5529
+ if (tail.length) {
5530
+ const index = exp.children.indexOf($2);
5531
+ if (index < 0)
5532
+ throw new Error("Assertion error: exp not in AssignmentExpression");
5533
+ exp.children.splice(index + 1, 0, ...tail);
5534
+ }
5447
5535
  if (block) {
5448
5536
  block.parent = exp.parent;
5449
5537
  block.expressions.push(["", exp]);
@@ -5502,9 +5590,9 @@ function unchainOptionalMemberExpression(exp, ref, innerExp) {
5502
5590
  }
5503
5591
  j++;
5504
5592
  }
5505
- let ref6;
5506
- if (ref6 = conditions.length) {
5507
- const l = ref6;
5593
+ let ref9;
5594
+ if (ref9 = conditions.length) {
5595
+ const l = ref9;
5508
5596
  const cs = flatJoin(conditions, " && ");
5509
5597
  return {
5510
5598
  ...exp,
@@ -5541,8 +5629,8 @@ function processTypes(node) {
5541
5629
  return gatherRecursiveAll(node, (n) => n.type === "UnaryType").forEach((unary) => {
5542
5630
  let last;
5543
5631
  let count = 0;
5544
- let ref7;
5545
- while (unary.suffix.length && (ref7 = unary.suffix)[ref7.length - 1]?.token === "?") {
5632
+ let ref10;
5633
+ while (unary.suffix.length && (ref10 = unary.suffix)[ref10.length - 1]?.token === "?") {
5546
5634
  last = unary.suffix.pop();
5547
5635
  count++;
5548
5636
  }
@@ -5573,14 +5661,14 @@ function processTypes(node) {
5573
5661
  });
5574
5662
  }
5575
5663
  function processStatementExpressions(statements) {
5576
- gatherRecursiveAll(statements, ($) => $.type === "StatementExpression").forEach((_exp) => {
5664
+ gatherRecursiveAll(statements, ($5) => $5.type === "StatementExpression").forEach((_exp) => {
5577
5665
  const exp = _exp;
5578
5666
  const { statement } = exp;
5579
- let ref8;
5667
+ let ref11;
5580
5668
  switch (statement.type) {
5581
5669
  case "IfStatement": {
5582
- if (ref8 = expressionizeIfStatement(statement)) {
5583
- const expression = ref8;
5670
+ if (ref11 = expressionizeIfStatement(statement)) {
5671
+ const expression = ref11;
5584
5672
  return replaceNode(statement, expression, exp);
5585
5673
  } else {
5586
5674
  return replaceNode(statement, wrapIIFE([["", statement]]), exp);
@@ -5622,7 +5710,7 @@ function processNegativeIndexAccess(statements) {
5622
5710
  }
5623
5711
  } else if (index > start + 1) {
5624
5712
  ref = makeRef();
5625
- subexp = children.splice(start, index);
5713
+ subexp = children.splice(start, index - start);
5626
5714
  } else {
5627
5715
  throw new Error("Invalid parse tree for negative index access");
5628
5716
  }
@@ -5631,7 +5719,7 @@ function processNegativeIndexAccess(statements) {
5631
5719
  exp.hoistDec = hoistDec;
5632
5720
  children.splice(start, 0, makeLeftHandSideExpression(refAssignment));
5633
5721
  }
5634
- return exp.len.children = [
5722
+ exp.len.children = [
5635
5723
  ref,
5636
5724
  ".length"
5637
5725
  ];
@@ -5703,11 +5791,11 @@ function populateRefs(statements) {
5703
5791
  function processPlaceholders(statements) {
5704
5792
  const placeholderMap = /* @__PURE__ */ new Map();
5705
5793
  const liftedIfs = /* @__PURE__ */ new Set();
5706
- gatherRecursiveAll(statements, ($3) => $3.type === "Placeholder").forEach((_exp) => {
5794
+ gatherRecursiveAll(statements, ($6) => $6.type === "Placeholder").forEach((_exp) => {
5707
5795
  const exp = _exp;
5708
5796
  let ancestor;
5709
5797
  if (exp.subtype === ".") {
5710
- ({ ancestor } = findAncestor(exp, ($4) => $4.type === "Call"));
5798
+ ({ ancestor } = findAncestor(exp, ($7) => $7.type === "Call"));
5711
5799
  ancestor = ancestor?.parent;
5712
5800
  while (ancestor?.parent?.type === "UnaryExpression" || ancestor?.parent?.type === "NewExpression") {
5713
5801
  ancestor = ancestor.parent;
@@ -5726,10 +5814,10 @@ function processPlaceholders(statements) {
5726
5814
  if (type === "IfStatement") {
5727
5815
  liftedIfs.add(ancestor2);
5728
5816
  }
5729
- let m;
5730
- let m1;
5817
+ let m3;
5818
+ let m4;
5731
5819
  return type === "Call" || // Block, except for if/else blocks when condition already lifted
5732
- type === "BlockStatement" && !((m = ancestor2.parent, typeof m === "object" && m != null && "type" in m && m.type === "IfStatement") && liftedIfs.has(ancestor2.parent)) && !((m1 = ancestor2.parent, typeof m1 === "object" && m1 != null && "type" in m1 && m1.type === "ElseClause" && "parent" in m1 && typeof m1.parent === "object" && m1.parent != null && "type" in m1.parent && m1.parent.type === "IfStatement") && liftedIfs.has(ancestor2.parent.parent)) || type === "PipelineExpression" || // Declaration
5820
+ type === "BlockStatement" && !((m3 = ancestor2.parent, typeof m3 === "object" && m3 != null && "type" in m3 && m3.type === "IfStatement") && liftedIfs.has(ancestor2.parent)) && !((m4 = ancestor2.parent, typeof m4 === "object" && m4 != null && "type" in m4 && m4.type === "ElseClause" && "parent" in m4 && typeof m4.parent === "object" && m4.parent != null && "type" in m4.parent && m4.parent.type === "IfStatement") && liftedIfs.has(ancestor2.parent.parent)) || type === "PipelineExpression" || // Declaration
5733
5821
  type === "Initializer" || // Right-hand side of assignment
5734
5822
  type === "AssignmentExpression" && findChildIndex(ancestor2, child2) === ancestor2.children.indexOf(ancestor2.expression) || type === "ReturnStatement" || type === "YieldExpression";
5735
5823
  }));
@@ -5808,8 +5896,8 @@ function processPlaceholders(statements) {
5808
5896
  for (let i4 = 0, len3 = placeholders.length; i4 < len3; i4++) {
5809
5897
  const placeholder = placeholders[i4];
5810
5898
  typeSuffix ??= placeholder.typeSuffix;
5811
- let ref9;
5812
- replaceNode((ref9 = placeholder.children)[ref9.length - 1], ref);
5899
+ let ref12;
5900
+ replaceNode((ref12 = placeholder.children)[ref12.length - 1], ref);
5813
5901
  }
5814
5902
  const { parent } = ancestor;
5815
5903
  const body = maybeUnwrap(ancestor);
@@ -5840,9 +5928,9 @@ function processPlaceholders(statements) {
5840
5928
  fnExp = makeLeftHandSideExpression(fnExp);
5841
5929
  }
5842
5930
  replaceNode(ancestor, fnExp, parent);
5843
- let ref10;
5844
- if (ref10 = getTrimmingSpace(body)) {
5845
- const ws = ref10;
5931
+ let ref13;
5932
+ if (ref13 = getTrimmingSpace(body)) {
5933
+ const ws = ref13;
5846
5934
  inplaceInsertTrimmingSpace(body, "");
5847
5935
  inplacePrepend(ws, fnExp);
5848
5936
  }
@@ -5867,43 +5955,39 @@ function reorderBindingRestProperty(props) {
5867
5955
  children: props,
5868
5956
  names
5869
5957
  };
5870
- } else if (restCount === 1) {
5871
- let after = props.slice(restIndex + 1);
5872
- let rest = props[restIndex];
5873
- props = props.slice(0, restIndex);
5874
- if (after.length) {
5875
- const { delim: restDelim } = rest, lastAfterProp = after[after.length - 1], { delim: lastDelim, children: lastAfterChildren } = lastAfterProp;
5876
- rest = {
5877
- ...rest,
5878
- delim: lastDelim,
5879
- children: [...rest.children.slice(0, -1), lastDelim]
5880
- };
5881
- after = [
5882
- ...after.slice(0, -1),
5883
- {
5884
- ...lastAfterProp,
5885
- delim: restDelim,
5886
- children: [...lastAfterChildren.slice(0, -1), restDelim]
5887
- }
5888
- ];
5889
- }
5890
- let ref11;
5891
- if (Array.isArray(rest.delim) && (ref11 = rest.delim)[ref11.length - 1]?.token === ",") {
5892
- rest.delim = rest.delim.slice(0, -1);
5893
- rest.children = [...rest.children.slice(0, -1), rest.delim];
5894
- }
5895
- const children = [...props, ...after, rest];
5896
- return {
5897
- children,
5898
- names
5958
+ }
5959
+ let after = props.slice(restIndex + 1);
5960
+ let rest = props[restIndex];
5961
+ props = props.slice(0, restIndex);
5962
+ if (after.length) {
5963
+ const { delim: restDelim } = rest, lastAfterProp = after[after.length - 1], { delim: lastDelim, children: lastAfterChildren } = lastAfterProp;
5964
+ rest = {
5965
+ ...rest,
5966
+ delim: lastDelim,
5967
+ children: [...rest.children.slice(0, -1), lastDelim]
5899
5968
  };
5969
+ after = [
5970
+ ...after.slice(0, -1),
5971
+ {
5972
+ ...lastAfterProp,
5973
+ delim: restDelim,
5974
+ children: [...lastAfterChildren.slice(0, -1), restDelim]
5975
+ }
5976
+ ];
5900
5977
  }
5901
- return {
5902
- children: [{
5978
+ let ref14;
5979
+ if (Array.isArray(rest.delim) && (ref14 = rest.delim)[ref14.length - 1]?.token === ",") {
5980
+ rest.delim = rest.delim.slice(0, -1);
5981
+ rest.children = [...rest.children.slice(0, -1), rest.delim];
5982
+ }
5983
+ const children = [...props, ...after, rest];
5984
+ if (restCount > 1) {
5985
+ children.push({
5903
5986
  type: "Error",
5904
5987
  message: "Multiple rest properties in object pattern"
5905
- }, props]
5906
- };
5988
+ });
5989
+ }
5990
+ return { children, names };
5907
5991
  }
5908
5992
  function replaceNodes(root, predicate, replacer) {
5909
5993
  if (!(root != null)) {
@@ -6086,6 +6170,7 @@ var grammar = {
6086
6170
  YieldExpression,
6087
6171
  ArrowFunction,
6088
6172
  FatArrow,
6173
+ FatArrowToken,
6089
6174
  TrailingDeclaration,
6090
6175
  TrailingPipe,
6091
6176
  FatArrowBody,
@@ -6206,9 +6291,11 @@ var grammar = {
6206
6291
  NoCommaBracedOrEmptyBlock,
6207
6292
  NoPostfixBracedOrEmptyBlock,
6208
6293
  EmptyBlock,
6294
+ BlockOrEmptyStatement,
6209
6295
  BlockOrEmpty,
6210
- EmptyBareBlock,
6211
6296
  EmptyStatementBareBlock,
6297
+ EmptyBareBlock,
6298
+ NoBlock,
6212
6299
  BracedBlock,
6213
6300
  NoPostfixBracedBlock,
6214
6301
  NoCommaBracedBlock,
@@ -6995,7 +7082,7 @@ var $R2 = (0, import_lib3.$R)(new RegExp("(as|of|satisfies|then|when|implements|
6995
7082
  var $R3 = (0, import_lib3.$R)(new RegExp("[0-9]", "suy"));
6996
7083
  var $R4 = (0, import_lib3.$R)(new RegExp("(?!\\p{ID_Start}|[_$0-9(\\[{])", "suy"));
6997
7084
  var $R5 = (0, import_lib3.$R)(new RegExp("[ \\t]", "suy"));
6998
- var $R6 = (0, import_lib3.$R)(new RegExp("(?:\\p{ID_Continue}|[\\u200C\\u200D$.])", "suy"));
7085
+ var $R6 = (0, import_lib3.$R)(new RegExp("(?:\\p{ID_Continue}|[\\u200C\\u200D$.#])", "suy"));
6999
7086
  var $R7 = (0, import_lib3.$R)(new RegExp("[&=]", "suy"));
7000
7087
  var $R8 = (0, import_lib3.$R)(new RegExp("(?=['\"`])", "suy"));
7001
7088
  var $R9 = (0, import_lib3.$R)(new RegExp("(?=[\\/?])", "suy"));
@@ -7227,13 +7314,14 @@ function ExpressionizedStatement(ctx, state2) {
7227
7314
  }
7228
7315
  var StatementExpression$0 = DebuggerStatement;
7229
7316
  var StatementExpression$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(IfStatement), function($skip, $loc, $0, $1) {
7230
- if (!$1.else && isEmptyBareBlock($1.then))
7317
+ if (!$1.else && $1.then.implicit)
7231
7318
  return $skip;
7232
7319
  return $1;
7233
7320
  });
7234
7321
  var StatementExpression$2 = (0, import_lib3.$TS)((0, import_lib3.$S)(IterationExpression), function($skip, $loc, $0, $1) {
7235
- if (isEmptyBareBlock($1.block))
7322
+ if ($1.block.implicit && $1.subtype !== "DoStatement" && $1.subtype !== "ComptimeStatement") {
7236
7323
  return $skip;
7324
+ }
7237
7325
  return $1;
7238
7326
  });
7239
7327
  var StatementExpression$3 = SwitchStatement;
@@ -7324,7 +7412,7 @@ var ForbiddenImplicitCalls$6 = (0, import_lib3.$TS)((0, import_lib3.$S)(OmittedN
7324
7412
  return $0;
7325
7413
  return $skip;
7326
7414
  });
7327
- var ForbiddenImplicitCalls$7 = (0, import_lib3.$S)(PostfixStatement, EmptyStatementBareBlock);
7415
+ var ForbiddenImplicitCalls$7 = (0, import_lib3.$S)(PostfixStatement, NoBlock);
7328
7416
  var ForbiddenImplicitCalls$8 = (0, import_lib3.$EXPECT)($L5, 'ForbiddenImplicitCalls "... "');
7329
7417
  var ForbiddenImplicitCalls$$ = [ForbiddenImplicitCalls$0, ForbiddenImplicitCalls$1, ForbiddenImplicitCalls$2, ForbiddenImplicitCalls$3, ForbiddenImplicitCalls$4, ForbiddenImplicitCalls$5, ForbiddenImplicitCalls$6, ForbiddenImplicitCalls$7, ForbiddenImplicitCalls$8];
7330
7418
  function ForbiddenImplicitCalls(ctx, state2) {
@@ -7549,11 +7637,10 @@ var UnaryExpression$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3
7549
7637
  var post = $3;
7550
7638
  return processUnaryExpression(pre, exp, post);
7551
7639
  });
7552
- var UnaryExpression$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(CoffeeDoEnabled, Do, __, (0, import_lib3.$C)((0, import_lib3.$S)(LeftHandSideExpression, (0, import_lib3.$N)((0, import_lib3.$S)(__, AssignmentOpSymbol))), ArrowFunction, ExtendedExpression)), function($skip, $loc, $0, $1, $2, $3, $4) {
7640
+ var UnaryExpression$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(CoffeeDoEnabled, Do, __, (0, import_lib3.$C)(ArrowFunction, (0, import_lib3.$S)(LeftHandSideExpression, (0, import_lib3.$N)((0, import_lib3.$S)(__, AssignmentOpSymbol))), ExtendedExpression)), function($skip, $loc, $0, $1, $2, $3, $4) {
7553
7641
  var ws = $3;
7554
7642
  var exp = $4;
7555
- ws = insertTrimmingSpace(ws, "");
7556
- return ["(", ...ws, exp, ")()"];
7643
+ return processCoffeeDo(ws, exp);
7557
7644
  });
7558
7645
  var UnaryExpression$$ = [UnaryExpression$0, UnaryExpression$1];
7559
7646
  function UnaryExpression(ctx, state2) {
@@ -7775,6 +7862,7 @@ var ArrowFunction$1 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$
7775
7862
  var async = $1;
7776
7863
  var parameters = $2;
7777
7864
  var suffix = $3;
7865
+ var arrow = $4;
7778
7866
  var expOrBlock = $5;
7779
7867
  if (hasAwait(expOrBlock) && !async) {
7780
7868
  async = "async ";
@@ -7799,22 +7887,29 @@ var ArrowFunction$1 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$
7799
7887
  ts: false,
7800
7888
  async,
7801
7889
  block: expOrBlock,
7802
- children: [async, $0.slice(1), error]
7890
+ children: [async, parameters, suffix, arrow, error, expOrBlock]
7803
7891
  };
7804
7892
  });
7805
7893
  var ArrowFunction$$ = [ArrowFunction$0, ArrowFunction$1];
7806
7894
  function ArrowFunction(ctx, state2) {
7807
7895
  return (0, import_lib3.$EVENT_C)(ctx, state2, "ArrowFunction", ArrowFunction$$);
7808
7896
  }
7809
- var FatArrow$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$E)(_), (0, import_lib3.$C)((0, import_lib3.$EXPECT)($L13, 'FatArrow "=>"'), (0, import_lib3.$EXPECT)($L14, 'FatArrow "\u21D2"'))), function($skip, $loc, $0, $1, $2) {
7897
+ var FatArrow$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$E)(_), FatArrowToken), function($skip, $loc, $0, $1, $2) {
7810
7898
  var ws = $1;
7899
+ var arrow = $2;
7811
7900
  if (!ws)
7812
- return " =>";
7813
- return [$1, "=>"];
7901
+ ws = " ";
7902
+ return [ws, arrow];
7814
7903
  });
7815
7904
  function FatArrow(ctx, state2) {
7816
7905
  return (0, import_lib3.$EVENT)(ctx, state2, "FatArrow", FatArrow$0);
7817
7906
  }
7907
+ var FatArrowToken$0 = (0, import_lib3.$TV)((0, import_lib3.$C)((0, import_lib3.$EXPECT)($L13, 'FatArrowToken "=>"'), (0, import_lib3.$EXPECT)($L14, 'FatArrowToken "\u21D2"')), function($skip, $loc, $0, $1) {
7908
+ return { $loc, token: "=>" };
7909
+ });
7910
+ function FatArrowToken(ctx, state2) {
7911
+ return (0, import_lib3.$EVENT)(ctx, state2, "FatArrowToken", FatArrowToken$0);
7912
+ }
7818
7913
  var TrailingDeclaration$0 = (0, import_lib3.$S)((0, import_lib3.$E)(_), (0, import_lib3.$C)(ConstAssignment, LetAssignment));
7819
7914
  function TrailingDeclaration(ctx, state2) {
7820
7915
  return (0, import_lib3.$EVENT)(ctx, state2, "TrailingDeclaration", TrailingDeclaration$0);
@@ -7969,7 +8064,7 @@ var ParenthesizedExpression$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(OpenPar
7969
8064
  function ParenthesizedExpression(ctx, state2) {
7970
8065
  return (0, import_lib3.$EVENT)(ctx, state2, "ParenthesizedExpression", ParenthesizedExpression$0);
7971
8066
  }
7972
- var Placeholder$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Dot, (0, import_lib3.$N)((0, import_lib3.$EXPECT)($R6, "Placeholder /(?:\\p{ID_Continue}|[\\u200C\\u200D$.])/")), (0, import_lib3.$E)(PlaceholderTypeSuffix)), function($skip, $loc, $0, $1, $2, $3) {
8067
+ var Placeholder$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Dot, (0, import_lib3.$N)((0, import_lib3.$EXPECT)($R6, "Placeholder /(?:\\p{ID_Continue}|[\\u200C\\u200D$.#])/")), (0, import_lib3.$E)(PlaceholderTypeSuffix)), function($skip, $loc, $0, $1, $2, $3) {
7973
8068
  var dot = $1;
7974
8069
  var typeSuffix = $3;
7975
8070
  return {
@@ -8326,7 +8421,13 @@ var ThisLiteral$2 = (0, import_lib3.$TS)((0, import_lib3.$S)(AtThis, (0, import_
8326
8421
  children: [at, {
8327
8422
  type: "PropertyAccess",
8328
8423
  name: id,
8329
- children: [".", id]
8424
+ children: [".", {
8425
+ $loc: {
8426
+ pos: $loc.pos + 1,
8427
+ length: $loc.length - 1
8428
+ },
8429
+ token: id
8430
+ }]
8330
8431
  }],
8331
8432
  thisShorthand: true
8332
8433
  };
@@ -8998,11 +9099,17 @@ function FunctionRestParameter(ctx, state2) {
8998
9099
  var ParameterElement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$E)(_), (0, import_lib3.$E)(AccessModifier), (0, import_lib3.$E)(_), (0, import_lib3.$C)(NWBindingIdentifier, BindingPattern), (0, import_lib3.$E)(TypeSuffix), (0, import_lib3.$E)(Initializer), ParameterElementDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
8999
9100
  var accessModifier = $2;
9000
9101
  var binding = $4;
9102
+ var typeSuffix = $5;
9103
+ var initializer = $6;
9104
+ var delim = $7;
9001
9105
  return {
9002
9106
  type: "Parameter",
9003
9107
  children: $0,
9004
9108
  names: binding.names,
9005
- accessModifier
9109
+ typeSuffix,
9110
+ accessModifier,
9111
+ initializer,
9112
+ delim
9006
9113
  };
9007
9114
  });
9008
9115
  function ParameterElement(ctx, state2) {
@@ -9864,43 +9971,62 @@ var EmptyBlock$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(InsertOpenBrace, Ins
9864
9971
  expressions,
9865
9972
  children: [$1, expressions, $2],
9866
9973
  bare: false,
9867
- empty: true
9974
+ empty: true,
9975
+ implicit: true
9868
9976
  };
9869
9977
  });
9870
9978
  function EmptyBlock(ctx, state2) {
9871
9979
  return (0, import_lib3.$EVENT)(ctx, state2, "EmptyBlock", EmptyBlock$0);
9872
9980
  }
9981
+ var BlockOrEmptyStatement$0 = Block;
9982
+ var BlockOrEmptyStatement$1 = (0, import_lib3.$T)((0, import_lib3.$S)(NoBlock, EmptyStatementBareBlock), function(value) {
9983
+ return value[1];
9984
+ });
9985
+ var BlockOrEmptyStatement$$ = [BlockOrEmptyStatement$0, BlockOrEmptyStatement$1];
9986
+ function BlockOrEmptyStatement(ctx, state2) {
9987
+ return (0, import_lib3.$EVENT_C)(ctx, state2, "BlockOrEmptyStatement", BlockOrEmptyStatement$$);
9988
+ }
9873
9989
  var BlockOrEmpty$0 = Block;
9874
- var BlockOrEmpty$1 = EmptyStatementBareBlock;
9990
+ var BlockOrEmpty$1 = (0, import_lib3.$T)((0, import_lib3.$S)(NoBlock, EmptyBlock), function(value) {
9991
+ return value[1];
9992
+ });
9875
9993
  var BlockOrEmpty$$ = [BlockOrEmpty$0, BlockOrEmpty$1];
9876
9994
  function BlockOrEmpty(ctx, state2) {
9877
9995
  return (0, import_lib3.$EVENT_C)(ctx, state2, "BlockOrEmpty", BlockOrEmpty$$);
9878
9996
  }
9879
- var EmptyBareBlock$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L0, 'EmptyBareBlock ""'), function($skip, $loc, $0, $1) {
9880
- const expressions = [];
9997
+ var EmptyStatementBareBlock$0 = (0, import_lib3.$TV)(InsertEmptyStatement, function($skip, $loc, $0, $1) {
9998
+ var s = $0;
9999
+ const expressions = [["", s]];
9881
10000
  return {
9882
10001
  type: "BlockStatement",
9883
10002
  expressions,
9884
10003
  children: [expressions],
9885
- bare: true
10004
+ bare: true,
10005
+ empty: true,
10006
+ implicit: true,
10007
+ semicolon: s.children[0]
9886
10008
  };
9887
10009
  });
9888
- function EmptyBareBlock(ctx, state2) {
9889
- return (0, import_lib3.$EVENT)(ctx, state2, "EmptyBareBlock", EmptyBareBlock$0);
10010
+ function EmptyStatementBareBlock(ctx, state2) {
10011
+ return (0, import_lib3.$EVENT)(ctx, state2, "EmptyStatementBareBlock", EmptyStatementBareBlock$0);
9890
10012
  }
9891
- var EmptyStatementBareBlock$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$Y)(EOS), (0, import_lib3.$N)(IndentedFurther), InsertEmptyStatement), function($skip, $loc, $0, $1, $2, $3) {
9892
- var s = $3;
9893
- const expressions = [["", s]];
10013
+ var EmptyBareBlock$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L0, 'EmptyBareBlock ""'), function($skip, $loc, $0, $1) {
10014
+ const expressions = [];
9894
10015
  return {
9895
10016
  type: "BlockStatement",
9896
10017
  expressions,
9897
10018
  children: [expressions],
9898
10019
  bare: true,
9899
- semicolon: s.children[0]
10020
+ empty: true,
10021
+ implicit: true
9900
10022
  };
9901
10023
  });
9902
- function EmptyStatementBareBlock(ctx, state2) {
9903
- return (0, import_lib3.$EVENT)(ctx, state2, "EmptyStatementBareBlock", EmptyStatementBareBlock$0);
10024
+ function EmptyBareBlock(ctx, state2) {
10025
+ return (0, import_lib3.$EVENT)(ctx, state2, "EmptyBareBlock", EmptyBareBlock$0);
10026
+ }
10027
+ var NoBlock$0 = (0, import_lib3.$S)((0, import_lib3.$Y)(EOS), (0, import_lib3.$N)(IndentedFurther));
10028
+ function NoBlock(ctx, state2) {
10029
+ return (0, import_lib3.$EVENT)(ctx, state2, "NoBlock", NoBlock$0);
9904
10030
  }
9905
10031
  var BracedBlock$0 = NonSingleBracedBlock;
9906
10032
  var BracedBlock$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(InsertOpenBrace, (0, import_lib3.$N)(EOS), PostfixedSingleLineStatements, InsertSpace, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
@@ -11752,7 +11878,7 @@ var IterationExpression$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_
11752
11878
  function IterationExpression(ctx, state2) {
11753
11879
  return (0, import_lib3.$EVENT)(ctx, state2, "IterationExpression", IterationExpression$0);
11754
11880
  }
11755
- var LoopStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(LoopClause, BlockOrEmpty), function($skip, $loc, $0, $1, $2) {
11881
+ var LoopStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(LoopClause, BlockOrEmptyStatement), function($skip, $loc, $0, $1, $2) {
11756
11882
  var clause = $1;
11757
11883
  var block = $2;
11758
11884
  return {
@@ -11830,7 +11956,7 @@ var ComptimeStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Comptime, NoP
11830
11956
  function ComptimeStatement(ctx, state2) {
11831
11957
  return (0, import_lib3.$EVENT)(ctx, state2, "ComptimeStatement", ComptimeStatement$0);
11832
11958
  }
11833
- var WhileStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(WhileClause, BlockOrEmpty), function($skip, $loc, $0, $1, $2) {
11959
+ var WhileStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(WhileClause, BlockOrEmptyStatement), function($skip, $loc, $0, $1, $2) {
11834
11960
  var clause = $1;
11835
11961
  var block = $2;
11836
11962
  return {
@@ -11861,7 +11987,7 @@ var WhileClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$C)
11861
11987
  function WhileClause(ctx, state2) {
11862
11988
  return (0, import_lib3.$EVENT)(ctx, state2, "WhileClause", WhileClause$0);
11863
11989
  }
11864
- var ForStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(ForClause, BlockOrEmpty), function($skip, $loc, $0, $1, $2) {
11990
+ var ForStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(ForClause, BlockOrEmptyStatement), function($skip, $loc, $0, $1, $2) {
11865
11991
  var clause = $1;
11866
11992
  var block = $2;
11867
11993
  block = blockWithPrefix(clause.blockPrefix, block);
@@ -16439,33 +16565,20 @@ function parseProgram(input, options) {
16439
16565
  }
16440
16566
  }
16441
16567
 
16442
- // source/util.civet
16443
- var util_exports = {};
16444
- __export(util_exports, {
16568
+ // source/sourcemap.civet
16569
+ var sourcemap_exports = {};
16570
+ __export(sourcemap_exports, {
16445
16571
  SourceMap: () => SourceMap,
16446
16572
  base64Encode: () => base64Encode,
16447
16573
  locationTable: () => locationTable,
16448
16574
  lookupLineColumn: () => lookupLineColumn
16449
16575
  });
16450
- var smRegexp;
16451
- var prettySourceExcerpt;
16452
- var VLQ_SHIFT;
16453
- var VLQ_CONTINUATION_BIT;
16454
- var VLQ_VALUE_MASK;
16455
- var encodeVlq;
16456
- var BASE64_CHARS;
16457
- var encodeBase64;
16458
- var vlqTable;
16459
- var vlqChars;
16460
- var decodeError;
16461
- var decodeVLQ;
16462
- var remapPosition;
16463
16576
  var locationTable = function(input) {
16464
- var linesRe, lines, line, pos, result;
16465
- linesRe = /([^\r\n]*)(\r\n|\r|\n|$)/y;
16466
- lines = [];
16467
- line = 0;
16468
- pos = 0;
16577
+ const linesRe = /([^\r\n]*)(\r\n|\r|\n|$)/y;
16578
+ const lines = [];
16579
+ let line = 0;
16580
+ let pos = 0;
16581
+ let result;
16469
16582
  while (result = linesRe.exec(input)) {
16470
16583
  pos += result[0].length;
16471
16584
  lines[line++] = pos;
@@ -16476,39 +16589,35 @@ var locationTable = function(input) {
16476
16589
  return lines;
16477
16590
  };
16478
16591
  var lookupLineColumn = function(table, pos) {
16479
- var l, prevEnd;
16480
- l = 0;
16481
- prevEnd = 0;
16592
+ let l = 0;
16593
+ let prevEnd = 0;
16482
16594
  while (table[l] <= pos) {
16483
16595
  prevEnd = table[l++];
16484
16596
  }
16485
16597
  return [l, pos - prevEnd];
16486
16598
  };
16487
16599
  var SourceMap = function(sourceString) {
16488
- var srcTable, sm, EOL2;
16489
- srcTable = locationTable(sourceString);
16490
- sm = {
16600
+ const srcTable = locationTable(sourceString);
16601
+ const sm = {
16491
16602
  lines: [[]],
16492
- lineNum: 0,
16493
- colOffset: 0,
16603
+ line: 0,
16604
+ column: 0,
16605
+ srcLine: 0,
16606
+ srcColumn: 0,
16607
+ srcOffset: 0,
16494
16608
  srcTable
16495
16609
  };
16496
- EOL2 = /\r?\n|\r/;
16610
+ const EOL2 = /\r?\n|\r/;
16497
16611
  return {
16498
16612
  data: sm,
16499
- source: function() {
16500
- return sourceString;
16501
- },
16502
16613
  renderMappings: function() {
16503
- var lastSourceLine, lastSourceColumn;
16504
- lastSourceLine = 0;
16505
- lastSourceColumn = 0;
16614
+ let lastSourceLine = 0;
16615
+ let lastSourceColumn = 0;
16506
16616
  return sm.lines.map(function(line) {
16507
16617
  return line.map(function(entry) {
16508
- var colDelta, sourceFileIndex, srcLine, srcCol, lineDelta;
16509
16618
  if (entry.length === 4) {
16510
- [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16511
- lineDelta = srcLine - lastSourceLine;
16619
+ let [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16620
+ const lineDelta = srcLine - lastSourceLine;
16512
16621
  colDelta = srcCol - lastSourceColumn;
16513
16622
  lastSourceLine = srcLine;
16514
16623
  lastSourceColumn = srcCol;
@@ -16532,26 +16641,31 @@ var SourceMap = function(sourceString) {
16532
16641
  }
16533
16642
  };
16534
16643
  },
16535
- updateSourceMap: function(outputStr, inputPos) {
16536
- var outLines, srcLine, srcCol;
16537
- outLines = outputStr.split(EOL2);
16644
+ updateSourceMap: function(outputStr, inputPos, colOffset = 0) {
16645
+ const outLines = outputStr.split(EOL2);
16646
+ let srcLine, srcCol;
16538
16647
  if (inputPos != null) {
16539
16648
  [srcLine, srcCol] = lookupLineColumn(srcTable, inputPos);
16649
+ srcCol += colOffset;
16650
+ sm.srcLine = srcLine;
16651
+ sm.srcColumn = srcCol;
16652
+ sm.srcOffset = inputPos + outputStr.length;
16540
16653
  }
16541
16654
  outLines.forEach(function(line, i) {
16542
- var l;
16543
16655
  if (i > 0) {
16544
- sm.lineNum++;
16545
- sm.colOffset = 0;
16546
- sm.lines[sm.lineNum] = [];
16547
- srcCol = 0;
16656
+ sm.line++;
16657
+ sm.srcLine++;
16658
+ sm.column = 0;
16659
+ sm.lines[sm.line] = [];
16660
+ sm.srcColumn = srcCol = colOffset;
16548
16661
  }
16549
- l = sm.colOffset;
16550
- sm.colOffset = line.length;
16662
+ const l = sm.column;
16663
+ sm.column += line.length;
16664
+ sm.srcColumn += line.length;
16551
16665
  if (inputPos != null) {
16552
- return sm.lines[sm.lineNum].push([l, 0, srcLine + i, srcCol]);
16553
- } else if (l !== 0) {
16554
- return sm.lines[sm.lineNum].push([l]);
16666
+ return sm.lines[sm.line].push([l, 0, srcLine + i, srcCol]);
16667
+ } else if (l != 0) {
16668
+ return sm.lines[sm.line].push([l]);
16555
16669
  }
16556
16670
  ;
16557
16671
  return;
@@ -16560,74 +16674,36 @@ var SourceMap = function(sourceString) {
16560
16674
  }
16561
16675
  };
16562
16676
  };
16563
- SourceMap.parseWithLines = function(base64encodedJSONstr) {
16564
- var json, sourceLine, sourceColumn, lines;
16565
- json = JSON.parse(Buffer.from(base64encodedJSONstr, "base64").toString("utf8"));
16566
- sourceLine = 0;
16567
- sourceColumn = 0;
16568
- lines = json.mappings.split(";").map(function(line) {
16569
- if (line.length === 0) {
16570
- return [];
16571
- }
16572
- return line.split(",").map(function(entry) {
16573
- var result;
16574
- result = decodeVLQ(entry);
16575
- switch (result.length) {
16576
- case 1: {
16577
- return [result[0]];
16578
- }
16579
- case 4: {
16580
- return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3]];
16581
- }
16582
- case 5: {
16583
- return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3], result[4]];
16584
- }
16585
- default: {
16586
- throw new Error("Unknown source map entry", result);
16587
- }
16588
- }
16589
- });
16677
+ var smRegexp = /\n\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,([+a-zA-Z0-9\/]*=?=?)$/;
16678
+ var remap = function(codeWithSourceMap, upstreamMap, sourcePath, targetPath) {
16679
+ let sourceMapText;
16680
+ const codeWithoutSourceMap = codeWithSourceMap.replace(smRegexp, (match, sm) => {
16681
+ sourceMapText = sm;
16682
+ return "";
16590
16683
  });
16591
- json.lines = lines;
16592
- return json;
16593
- };
16594
- smRegexp = /\n\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,([+a-zA-Z0-9\/]*=?=?)$/;
16595
- SourceMap.remap = function(codeWithSourceMap, upstreamMap, sourcePath, targetPath) {
16596
- var sourceMapText, codeWithoutSourceMap, remappedSourceMapJSON, newSourceMap, remappedCodeWithSourceMap, parsed, composedLines;
16597
- sourceMapText = null;
16598
- codeWithoutSourceMap = codeWithSourceMap.replace(
16599
- smRegexp,
16600
- (match, sm) => {
16601
- sourceMapText = sm;
16602
- return "";
16603
- }
16604
- );
16605
16684
  if (sourceMapText) {
16606
- parsed = SourceMap.parseWithLines(sourceMapText);
16607
- composedLines = SourceMap.composeLines(upstreamMap.data.lines, parsed.lines);
16685
+ const parsed = parseWithLines(sourceMapText);
16686
+ const composedLines = composeLines(upstreamMap.data.lines, parsed.lines);
16608
16687
  upstreamMap.data.lines = composedLines;
16609
16688
  }
16610
- remappedSourceMapJSON = upstreamMap.json(sourcePath, targetPath);
16611
- newSourceMap = `${"sourceMapping"}URL=data:application/json;charset=utf-8;base64,${base64Encode(JSON.stringify(remappedSourceMapJSON))}`;
16612
- remappedCodeWithSourceMap = `${codeWithoutSourceMap}
16689
+ const remappedSourceMapJSON = upstreamMap.json(sourcePath, targetPath);
16690
+ const newSourceMap = `${"sourceMapping"}URL=data:application/json;charset=utf-8;base64,${base64Encode(JSON.stringify(remappedSourceMapJSON))}`;
16691
+ const remappedCodeWithSourceMap = `${codeWithoutSourceMap}
16613
16692
  //# ${newSourceMap}`;
16614
16693
  return remappedCodeWithSourceMap;
16615
16694
  };
16616
- SourceMap.composeLines = function(upstreamMapping, lines) {
16617
- return lines.map(function(line, l) {
16695
+ var composeLines = function(upstreamMapping, lines) {
16696
+ return lines.map(function(line) {
16618
16697
  return line.map(function(entry) {
16619
- var colDelta, sourceFileIndex, srcLine, srcCol, srcPos, upstreamLine, upstreamCol;
16620
16698
  if (entry.length === 1) {
16621
16699
  return entry;
16622
16700
  }
16623
- ;
16624
- [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16625
- srcPos = remapPosition([srcLine, srcCol], upstreamMapping);
16701
+ const [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16702
+ const srcPos = remapPosition([srcLine, srcCol], upstreamMapping);
16626
16703
  if (!srcPos) {
16627
16704
  return [entry[0]];
16628
16705
  }
16629
- ;
16630
- [upstreamLine, upstreamCol] = srcPos;
16706
+ const [upstreamLine, upstreamCol] = srcPos;
16631
16707
  if (entry.length === 4) {
16632
16708
  return [colDelta, sourceFileIndex, upstreamLine, upstreamCol];
16633
16709
  }
@@ -16635,44 +16711,50 @@ SourceMap.composeLines = function(upstreamMapping, lines) {
16635
16711
  });
16636
16712
  });
16637
16713
  };
16638
- prettySourceExcerpt = function(source, location, length) {
16639
- var lines, lineNum, colNum, i, line, lineNumStr;
16640
- lines = source.split(/\r?\n|\r/);
16641
- lineNum = location.line;
16642
- colNum = location.column;
16643
- for (let start = lineNum - 2, end = lineNum + 2, i1 = i = start, asc = start <= end; asc ? i1 <= end : i1 >= end; i = asc ? ++i1 : --i1) {
16644
- if (i < 0 || i >= lines.length) {
16645
- continue;
16646
- }
16647
- line = lines[i];
16648
- lineNumStr = (i + 1).toString();
16649
- while (lineNumStr.length < 4) {
16650
- lineNumStr = " " + lineNumStr;
16651
- }
16652
- if (i === lineNum) {
16653
- console.log(`${lineNumStr}: ${line}`);
16654
- console.log(" ".repeat(lineNumStr.length + 2 + colNum) + "^".repeat(length));
16655
- } else {
16656
- console.log(`${lineNumStr}: ${line}`);
16714
+ var parseWithLines = function(base64encodedJSONstr) {
16715
+ const json = JSON.parse(Buffer.from(base64encodedJSONstr, "base64").toString("utf8"));
16716
+ let sourceLine = 0;
16717
+ let sourceColumn = 0;
16718
+ const lines = json.mappings.split(";").map(function(line) {
16719
+ if (line.length === 0) {
16720
+ return [];
16657
16721
  }
16658
- }
16659
- return;
16722
+ return line.split(",").map(function(entry) {
16723
+ const result = decodeVLQ(entry);
16724
+ switch (result.length) {
16725
+ case 1: {
16726
+ return [result[0]];
16727
+ }
16728
+ case 4: {
16729
+ return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3]];
16730
+ }
16731
+ case 5: {
16732
+ return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3], result[4]];
16733
+ }
16734
+ default: {
16735
+ throw new Error("Unknown source map entry", result);
16736
+ }
16737
+ }
16738
+ });
16739
+ });
16740
+ json.lines = lines;
16741
+ return json;
16660
16742
  };
16661
- VLQ_SHIFT = 5;
16662
- VLQ_CONTINUATION_BIT = 1 << VLQ_SHIFT;
16663
- VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - 1;
16664
- encodeVlq = function(value) {
16665
- var answer, valueToEncode, signBit, nextChunk;
16666
- answer = "";
16743
+ Object.assign(SourceMap, { remap, parseWithLines, composeLines });
16744
+ var VLQ_SHIFT = 5;
16745
+ var VLQ_CONTINUATION_BIT = 1 << VLQ_SHIFT;
16746
+ var VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - 1;
16747
+ var encodeVlq = function(value) {
16748
+ let answer = "";
16667
16749
  let ref;
16668
16750
  if (value < 0)
16669
16751
  ref = 1;
16670
16752
  else
16671
16753
  ref = 0;
16672
- signBit = ref;
16673
- valueToEncode = (Math.abs(value) << 1) + signBit;
16754
+ const signBit = ref;
16755
+ let valueToEncode = (Math.abs(value) << 1) + signBit;
16674
16756
  while (valueToEncode || !answer) {
16675
- nextChunk = valueToEncode & VLQ_VALUE_MASK;
16757
+ let nextChunk = valueToEncode & VLQ_VALUE_MASK;
16676
16758
  valueToEncode = valueToEncode >> VLQ_SHIFT;
16677
16759
  if (valueToEncode) {
16678
16760
  nextChunk |= VLQ_CONTINUATION_BIT;
@@ -16681,21 +16763,20 @@ encodeVlq = function(value) {
16681
16763
  }
16682
16764
  return answer;
16683
16765
  };
16684
- BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16685
- encodeBase64 = function(value) {
16766
+ var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16767
+ var encodeBase64 = function(value) {
16686
16768
  return BASE64_CHARS[value] || (() => {
16687
- throw new Error(`Cannot Base64 encode value: ${value}`);
16769
+ throw new Error("Cannot Base64 encode value: ${value}");
16688
16770
  })();
16689
16771
  };
16690
16772
  var base64Encode = function(src) {
16691
16773
  return Buffer.from(src).toString("base64");
16692
16774
  };
16693
- vlqTable = new Uint8Array(128);
16694
- vlqChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16775
+ var vlqTable = new Uint8Array(128);
16776
+ var vlqChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16695
16777
  (function() {
16696
- var i, l;
16697
- i = 0;
16698
- l = vlqTable.length;
16778
+ let i = 0;
16779
+ let l = vlqTable.length;
16699
16780
  while (i < l) {
16700
16781
  vlqTable[i] = 255;
16701
16782
  i++;
@@ -16710,28 +16791,28 @@ vlqChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16710
16791
  ;
16711
16792
  return results;
16712
16793
  })();
16713
- decodeError = function(message) {
16794
+ var decodeError = function(message) {
16714
16795
  throw new Error(message);
16715
16796
  };
16716
- decodeVLQ = function(mapping) {
16717
- var i, l, result, shift, vlq, c, index, v;
16718
- i = 0;
16719
- l = mapping.length;
16720
- result = [];
16797
+ var decodeVLQ = function(mapping) {
16798
+ let i = 0;
16799
+ let l = mapping.length;
16800
+ let result = [];
16721
16801
  while (i < l) {
16722
- shift = 0;
16723
- vlq = 0;
16802
+ let shift = 0;
16803
+ let vlq = 0;
16804
+ let v = 0;
16724
16805
  while (true) {
16725
16806
  if (i >= l) {
16726
16807
  decodeError("Unexpected early end of mapping data");
16727
16808
  }
16728
- c = mapping.charCodeAt(i);
16729
- if ((c & 127) !== c) {
16730
- decodeError(`Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}`);
16809
+ const c = mapping.charCodeAt(i);
16810
+ if ((c & 127) != c) {
16811
+ decodeError("Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}");
16731
16812
  }
16732
- index = vlqTable[c & 127];
16813
+ const index = vlqTable[c & 127];
16733
16814
  if (index === 255) {
16734
- decodeError(`Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}`);
16815
+ decodeError("Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}");
16735
16816
  }
16736
16817
  i++;
16737
16818
  vlq |= (index & 31) << shift;
@@ -16749,20 +16830,19 @@ decodeVLQ = function(mapping) {
16749
16830
  }
16750
16831
  return result;
16751
16832
  };
16752
- remapPosition = function(position, sourcemapLines) {
16753
- var line, character, textLine, i, p, l, lastMapping, lastMappingPosition, mapping;
16754
- [line, character] = position;
16755
- textLine = sourcemapLines[line];
16833
+ var remapPosition = function(position, sourcemapLines) {
16834
+ const [line, character] = position;
16835
+ const textLine = sourcemapLines[line];
16756
16836
  if (!textLine?.length) {
16757
16837
  return void 0;
16758
16838
  }
16759
- i = 0;
16760
- p = 0;
16761
- l = textLine.length;
16762
- lastMapping = void 0;
16763
- lastMappingPosition = 0;
16839
+ let i = 0;
16840
+ let p = 0;
16841
+ const l = textLine.length;
16842
+ let lastMapping = void 0;
16843
+ let lastMappingPosition = 0;
16764
16844
  while (i < l) {
16765
- mapping = textLine[i];
16845
+ const mapping = textLine[i];
16766
16846
  p += mapping[0];
16767
16847
  if (mapping.length === 4) {
16768
16848
  lastMapping = mapping;
@@ -16773,7 +16853,7 @@ remapPosition = function(position, sourcemapLines) {
16773
16853
  }
16774
16854
  i++;
16775
16855
  }
16776
- if (character - lastMappingPosition !== 0) {
16856
+ if (character - lastMappingPosition != 0) {
16777
16857
  return void 0;
16778
16858
  }
16779
16859
  if (lastMapping) {
@@ -16824,20 +16904,15 @@ var StateCache = class {
16824
16904
  };
16825
16905
 
16826
16906
  // source/main.civet
16827
- var { SourceMap: SourceMap2 } = util_exports;
16907
+ var { SourceMap: SourceMap2 } = sourcemap_exports;
16828
16908
  var ParseErrors = class extends Error {
16829
16909
  name = "ParseErrors";
16830
- filename;
16831
- line;
16832
- column;
16833
- offset;
16834
- constructor(message, filename1, line1, column1, offset1) {
16835
- super(message);
16836
- this.filename = filename1;
16837
- this.line = line1;
16838
- this.column = column1;
16839
- this.offset = offset1;
16910
+ errors;
16911
+ constructor(errors) {
16912
+ const message = errors.map(($) => $.message).join("\n");
16913
+ super(errors.map(($1) => $1.message).join("\n"));
16840
16914
  this.message = message;
16915
+ this.errors = errors;
16841
16916
  }
16842
16917
  };
16843
16918
  var uncacheable = /* @__PURE__ */ new Set([
@@ -16939,6 +17014,7 @@ ${counts}`;
16939
17014
  });
16940
17015
  }
16941
17016
  }
17017
+ const throwOnErrors = options.errors == null;
16942
17018
  function rest(ast2) {
16943
17019
  options = options;
16944
17020
  if (!(options.ast === "raw")) {
@@ -16948,28 +17024,36 @@ ${counts}`;
16948
17024
  return ast2;
16949
17025
  }
16950
17026
  function checkErrors() {
17027
+ if (!throwOnErrors) {
17028
+ return;
17029
+ }
17030
+ options = options;
16951
17031
  if (options.errors?.length) {
16952
- throw new ParseErrors(options.errors.map(($) => $.message).join("\n"));
17032
+ throw new ParseErrors(options.errors);
16953
17033
  }
16954
17034
  ;
16955
17035
  return;
16956
17036
  }
16957
17037
  if (options.sourceMap || options.inlineMap) {
16958
- const sm = SourceMap2(src);
16959
- options.updateSourceMap = sm.updateSourceMap;
17038
+ options.sourceMap = SourceMap2(src);
16960
17039
  const code = generate_default(ast2, options);
16961
17040
  checkErrors();
16962
17041
  if (options.inlineMap) {
16963
- return SourceMap2.remap(code, sm, filename2, filename2 + ".tsx");
17042
+ return SourceMap2.remap(code, options.sourceMap, filename2, filename2 + ".tsx");
16964
17043
  } else {
16965
17044
  return {
16966
17045
  code,
16967
- sourceMap: sm
17046
+ sourceMap: options.sourceMap
16968
17047
  };
16969
17048
  }
16970
17049
  }
16971
17050
  const result = generate_default(ast2, options);
16972
- checkErrors();
17051
+ if (options.errors?.length) {
17052
+ delete options.errors;
17053
+ options.sourceMap = SourceMap2(src);
17054
+ generate_default(ast2, options);
17055
+ checkErrors();
17056
+ }
16973
17057
  return result;
16974
17058
  }
16975
17059
  if (ast.then != null) {
@@ -17041,12 +17125,14 @@ var makeCache = function({ hits, trace } = {}) {
17041
17125
  return events;
17042
17126
  };
17043
17127
  var isCompileError = function(err) {
17044
- return err instanceof Error && //@ts-ignore
17045
- [err.message, err.name, err.filename, err.line, err.column, err.offset].every(($1) => $1 !== void 0);
17128
+ return err instanceof import_lib3.ParseError || err instanceof ParseErrors;
17046
17129
  };
17047
- var main_default = { parse, parseProgram, generate: generate_default, util: util_exports, compile, isCompileError };
17130
+ var main_default = { parse, parseProgram, ParseError: import_lib3.ParseError, ParseErrors, generate: generate_default, sourcemap: sourcemap_exports, SourceMap: SourceMap2, compile, isCompileError };
17131
+ var export_ParseError = import_lib3.ParseError;
17048
17132
  export {
17133
+ export_ParseError as ParseError,
17049
17134
  ParseErrors,
17135
+ SourceMap2 as SourceMap,
17050
17136
  compile,
17051
17137
  main_default as default,
17052
17138
  generate_default as generate,
@@ -17055,5 +17141,5 @@ export {
17055
17141
  parse,
17056
17142
  parseProgram,
17057
17143
  prune,
17058
- util_exports as util
17144
+ sourcemap_exports as sourcemap
17059
17145
  };