@danielx/civet 0.7.9 → 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/browser.js CHANGED
@@ -38,9 +38,9 @@ var Civet = (() => {
38
38
  ));
39
39
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
40
 
41
- // ../Hera/dist/machine.js
41
+ // node_modules/@danielx/hera/dist/machine.js
42
42
  var require_machine = __commonJS({
43
- "../Hera/dist/machine.js"(exports, module) {
43
+ "node_modules/@danielx/hera/dist/machine.js"(exports, module) {
44
44
  "use strict";
45
45
  var __defProp2 = Object.defineProperty;
46
46
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
@@ -79,6 +79,7 @@ var Civet = (() => {
79
79
  $TS: () => $TS2,
80
80
  $TV: () => $TV2,
81
81
  $Y: () => $Y2,
82
+ ParseError: () => ParseError2,
82
83
  Validator: () => Validator2
83
84
  });
84
85
  module.exports = __toCommonJS2(machine_exports);
@@ -445,11 +446,10 @@ ${input.slice(result.pos)}
445
446
  hint = JSON.stringify(hint);
446
447
  else
447
448
  hint = "EOF";
448
- const error = new ParseError(`${filename2}:${line}:${column} Failed to parse
449
- Expected:
449
+ const error = new ParseError2("Failed to parse", `Expected:
450
450
  ${expectations.join("\n ")}
451
451
  Found: ${hint}
452
- `, "ParseError", filename2, line, column, maxFailPos);
452
+ `, filename2, line, column, maxFailPos);
453
453
  throw error;
454
454
  }
455
455
  if (result) {
@@ -472,15 +472,21 @@ ${input.slice(result.pos)}
472
472
  reset
473
473
  };
474
474
  }
475
- var ParseError = class extends Error {
476
- constructor(message, name, filename2, line, column, offset) {
475
+ var ParseError2 = class extends Error {
476
+ constructor(header, body, filename2, line, column, offset) {
477
+ let message = `${filename2}:${line}:${column} ${header}`;
478
+ if (body)
479
+ message += `
480
+ ${body}`;
477
481
  super(message);
478
- this.message = message;
479
- this.name = name;
482
+ this.header = header;
483
+ this.body = body;
480
484
  this.filename = filename2;
481
485
  this.line = line;
482
486
  this.column = column;
483
487
  this.offset = offset;
488
+ this.name = "ParseError";
489
+ this.message = message;
484
490
  }
485
491
  };
486
492
  }
@@ -489,7 +495,9 @@ ${input.slice(result.pos)}
489
495
  // source/main.civet
490
496
  var main_exports = {};
491
497
  __export(main_exports, {
498
+ ParseError: () => import_lib3.ParseError,
492
499
  ParseErrors: () => ParseErrors,
500
+ SourceMap: () => SourceMap2,
493
501
  compile: () => compile,
494
502
  default: () => main_default,
495
503
  generate: () => generate_default,
@@ -498,7 +506,7 @@ ${input.slice(result.pos)}
498
506
  parse: () => parse,
499
507
  parseProgram: () => parseProgram,
500
508
  prune: () => prune,
501
- util: () => util_exports
509
+ sourcemap: () => sourcemap_exports
502
510
  });
503
511
 
504
512
  // source/parser.hera
@@ -553,6 +561,7 @@ ${input.slice(result.pos)}
553
561
  processAssignmentDeclaration: () => processAssignmentDeclaration,
554
562
  processBinaryOpExpression: () => processBinaryOpExpression,
555
563
  processCallMemberExpression: () => processCallMemberExpression,
564
+ processCoffeeDo: () => processCoffeeDo,
556
565
  processCoffeeInterpolation: () => processCoffeeInterpolation,
557
566
  processForInOf: () => processForInOf,
558
567
  processProgram: () => processProgram,
@@ -1254,6 +1263,56 @@ ${input.slice(result.pos)}
1254
1263
  }
1255
1264
  return false;
1256
1265
  }
1266
+ function processCoffeeDo(ws, expression) {
1267
+ ws = insertTrimmingSpace(ws, "");
1268
+ const args = [];
1269
+ if (typeof expression === "object" && expression != null && "type" in expression && expression.type === "ArrowFunction" || typeof expression === "object" && expression != null && "type" in expression && expression.type === "FunctionExpression") {
1270
+ const { parameters } = expression;
1271
+ const newParameters = {
1272
+ ...parameters,
1273
+ children: (() => {
1274
+ const results = [];
1275
+ for (let ref6 = parameters.children, i1 = 0, len3 = ref6.length; i1 < len3; i1++) {
1276
+ let parameter = ref6[i1];
1277
+ if (typeof parameter === "object" && parameter != null && "type" in parameter && parameter.type === "Parameter") {
1278
+ let ref7;
1279
+ if (ref7 = parameter.initializer) {
1280
+ const initializer = ref7;
1281
+ args.push(initializer.expression, parameter.delim);
1282
+ parameter = {
1283
+ ...parameter,
1284
+ initializer: void 0,
1285
+ children: parameter.children.filter((a2) => a2 !== initializer)
1286
+ };
1287
+ } else {
1288
+ args.push(parameter.children.filter(
1289
+ (a3) => a3 !== parameter.typeSuffix
1290
+ ));
1291
+ }
1292
+ }
1293
+ results.push(parameter);
1294
+ }
1295
+ return results;
1296
+ })()
1297
+ };
1298
+ expression = {
1299
+ ...expression,
1300
+ parameters: newParameters,
1301
+ children: expression.children.map(($) => $ === parameters ? newParameters : $)
1302
+ };
1303
+ }
1304
+ return {
1305
+ type: "CallExpression",
1306
+ children: [
1307
+ makeLeftHandSideExpression(expression),
1308
+ {
1309
+ type: "Call",
1310
+ args,
1311
+ children: ["(", args, ")"]
1312
+ }
1313
+ ]
1314
+ };
1315
+ }
1257
1316
 
1258
1317
  // source/parser/block.civet
1259
1318
  function blockWithPrefix(prefixStatements, block) {
@@ -1414,6 +1473,9 @@ ${input.slice(result.pos)}
1414
1473
  }
1415
1474
  return false;
1416
1475
  }
1476
+ if (isToken(exp)) {
1477
+ exp = exp.token;
1478
+ }
1417
1479
  if (typeof exp === "string") {
1418
1480
  return /^\s*[\(\[\`\+\-\/]/.test(exp);
1419
1481
  }
@@ -1849,24 +1911,29 @@ ${input.slice(result.pos)}
1849
1911
  }
1850
1912
  return fn;
1851
1913
  }
1914
+ var skipParens = /* @__PURE__ */ new Set([
1915
+ "AmpersandRef",
1916
+ "CallExpression",
1917
+ "Identifier",
1918
+ "JSXElement",
1919
+ "JSXFragment",
1920
+ "Literal",
1921
+ "MemberExpression",
1922
+ "NewExpression",
1923
+ "ParenthesizedExpression",
1924
+ "Ref",
1925
+ "Placeholder",
1926
+ "StatementExpression"
1927
+ // wrapIIFE
1928
+ ]);
1852
1929
  function makeLeftHandSideExpression(expression) {
1853
- if (expression.parenthesized) {
1854
- return expression;
1855
- }
1856
- switch (expression.type) {
1857
- case "AmpersandRef":
1858
- case "CallExpression":
1859
- case "Identifier":
1860
- case "JSXElement":
1861
- case "JSXFragment":
1862
- case "Literal":
1863
- case "MemberExpression":
1864
- case "NewExpression":
1865
- case "ParenthesizedExpression":
1866
- case "Ref":
1867
- case "Placeholder":
1868
- case "StatementExpression":
1930
+ if (isASTNodeObject(expression)) {
1931
+ if (expression.parenthesized) {
1869
1932
  return expression;
1933
+ }
1934
+ if (skipParens.has(expression.type)) {
1935
+ return expression;
1936
+ }
1870
1937
  }
1871
1938
  return makeNode({
1872
1939
  type: "ParenthesizedExpression",
@@ -3239,7 +3306,6 @@ ${input.slice(result.pos)}
3239
3306
  if (s.negated) {
3240
3307
  let m;
3241
3308
  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")) {
3242
- console.log(condition.expression);
3243
3309
  throw new Error("Unsupported negated condition");
3244
3310
  }
3245
3311
  const { children } = condition.expression.children[1];
@@ -4147,49 +4213,71 @@ ${input.slice(result.pos)}
4147
4213
  return `${node}`;
4148
4214
  }
4149
4215
  }
4150
- function gen(node, options) {
4151
- if (node === null || node === void 0) {
4152
- return "";
4153
- }
4154
- if (typeof node === "string") {
4155
- options?.updateSourceMap?.(node);
4156
- return node;
4157
- }
4158
- if (Array.isArray(node)) {
4159
- return node.map(function(child) {
4160
- return gen(child, options);
4161
- }).join("");
4162
- }
4163
- if (typeof node === "object") {
4164
- if (options.js && node.ts) {
4165
- return "";
4166
- }
4167
- if (!options.js && node.js) {
4216
+ function gen(root, options) {
4217
+ const updateSourceMap = options?.sourceMap?.updateSourceMap;
4218
+ return recurse(root);
4219
+ function recurse(node) {
4220
+ if (!(node != null)) {
4168
4221
  return "";
4169
4222
  }
4170
- if (node.type === "Error") {
4171
- options.errors ??= [];
4172
- options.errors.push(node);
4173
- return "";
4223
+ if (typeof node === "string") {
4224
+ updateSourceMap?.(node);
4225
+ return node;
4174
4226
  }
4175
- if (node.$loc != null) {
4176
- const { token, $loc } = node;
4177
- options?.updateSourceMap?.(token, $loc.pos);
4178
- return token;
4227
+ if (Array.isArray(node)) {
4228
+ return node.map(recurse).join("");
4179
4229
  }
4180
- if (!node.children) {
4181
- switch (node.type) {
4182
- case "Ref": {
4183
- throw new Error(`Unpopulated ref ${stringify(node)}`);
4230
+ if (typeof node === "object") {
4231
+ if (options.js && node.ts) {
4232
+ return "";
4233
+ }
4234
+ if (!options.js && node.js) {
4235
+ return "";
4236
+ }
4237
+ if (node.type === "Error") {
4238
+ const filename2 = options?.filename ?? "unknown";
4239
+ let line = "?";
4240
+ let column = "?";
4241
+ let offset;
4242
+ if (options && typeof options === "object" && "sourceMap" in options) {
4243
+ const { sourceMap } = options;
4244
+ line = sourceMap.data.srcLine + 1;
4245
+ column = sourceMap.data.srcColumn + 1;
4246
+ offset = sourceMap.data.srcOffset;
4247
+ }
4248
+ options.errors ??= [];
4249
+ options.errors.push(new import_lib3.ParseError(
4250
+ node.message,
4251
+ void 0,
4252
+ // body
4253
+ filename2,
4254
+ line,
4255
+ column,
4256
+ offset
4257
+ ));
4258
+ return "";
4259
+ }
4260
+ if (node.$loc != null) {
4261
+ const { token, $loc } = node;
4262
+ updateSourceMap?.(token, $loc.pos);
4263
+ return token;
4264
+ }
4265
+ if (!node.children) {
4266
+ switch (node.type) {
4267
+ case "Ref": {
4268
+ throw new Error(`Unpopulated ref ${stringify(node)}`);
4269
+ }
4184
4270
  }
4271
+ debugger;
4272
+ throw new Error(`Unknown node ${stringify(node)}`);
4185
4273
  }
4186
- debugger;
4187
- throw new Error(`Unknown node ${stringify(node)}`);
4274
+ return recurse(node.children);
4188
4275
  }
4189
- return gen(node.children, options);
4276
+ debugger;
4277
+ throw new Error(`Unknown node ${stringify(node)}`);
4190
4278
  }
4191
- debugger;
4192
- throw new Error(`Unknown node ${stringify(node)}`);
4279
+ ;
4280
+ return recurse;
4193
4281
  }
4194
4282
  var generate_default = gen;
4195
4283
  function prune(node) {
@@ -5293,7 +5381,8 @@ ${js}`
5293
5381
  while (expr.type === "ParenthesizedExpression") {
5294
5382
  expr = expr.expression;
5295
5383
  }
5296
- if (expr.type === "AssignmentExpression" || expr.type === "UpdateExpression") {
5384
+ let m;
5385
+ if (m = expr.type, m === "AssignmentExpression" || m === "UpdateExpression") {
5297
5386
  if (expr.type === "UpdateExpression" && expr.children[0] === expr.assigned) {
5298
5387
  pre.push("(");
5299
5388
  post.push([", ", lhs, ")"]);
@@ -5307,26 +5396,31 @@ ${js}`
5307
5396
  return;
5308
5397
  }
5309
5398
  const pre = [], post = [];
5399
+ let ref4;
5310
5400
  switch (exp.type) {
5311
- case "AssignmentExpression":
5401
+ case "AssignmentExpression": {
5312
5402
  if (!exp.lhs)
5313
5403
  return;
5314
5404
  exp.lhs.forEach((lhsPart, i) => {
5315
- let newLhs2 = extractAssignment(lhsPart[1]);
5316
- if (newLhs2) {
5317
- return lhsPart[1] = newLhs2;
5405
+ let ref5;
5406
+ if (ref5 = extractAssignment(lhsPart[1])) {
5407
+ const newLhs = ref5;
5408
+ return lhsPart[1] = newLhs;
5318
5409
  }
5319
5410
  ;
5320
5411
  return;
5321
5412
  });
5322
5413
  break;
5323
- case "UpdateExpression":
5324
- let newLhs = extractAssignment(exp.assigned);
5325
- if (newLhs) {
5414
+ }
5415
+ case "UpdateExpression": {
5416
+ if (ref4 = extractAssignment(exp.assigned)) {
5417
+ const newLhs = ref4;
5326
5418
  const i = exp.children.indexOf(exp.assigned);
5327
5419
  exp.assigned = exp.children[i] = newLhs;
5328
5420
  }
5421
+ ;
5329
5422
  break;
5423
+ }
5330
5424
  }
5331
5425
  if (pre.length)
5332
5426
  exp.children.unshift(...pre);
@@ -5336,13 +5430,7 @@ ${js}`
5336
5430
  const { assigned } = exp;
5337
5431
  const ref = makeRef();
5338
5432
  const newMemberExp = unchainOptionalMemberExpression(assigned, ref, (children) => {
5339
- return exp.children.map((c) => {
5340
- if (c === assigned) {
5341
- return children;
5342
- } else {
5343
- return c;
5344
- }
5345
- });
5433
+ return exp.children.map(($) => $ === assigned ? children : $);
5346
5434
  });
5347
5435
  if (newMemberExp !== assigned) {
5348
5436
  if (newMemberExp.usesRef) {
@@ -5364,38 +5452,34 @@ ${js}`
5364
5452
  statements,
5365
5453
  (n) => n.type === "AssignmentExpression" && n.names === null,
5366
5454
  (exp) => {
5367
- let { lhs: $1, expression: $2 } = exp, tail = [], i = 0, len3 = $1.length;
5455
+ let { lhs: $1, expression: $2 } = exp, tail = [], len3 = $1.length;
5368
5456
  let block;
5369
- let ref4;
5370
- if (exp.parent?.type === "BlockStatement" && !(ref4 = $1[$1.length - 1])?.[ref4.length - 1]?.special) {
5457
+ let ref6;
5458
+ if (exp.parent?.type === "BlockStatement" && !(ref6 = $1[$1.length - 1])?.[ref6.length - 1]?.special) {
5371
5459
  block = makeBlockFragment();
5372
- let ref5;
5373
- if (ref5 = prependStatementExpressionBlock(
5460
+ let ref7;
5461
+ if (ref7 = prependStatementExpressionBlock(
5374
5462
  { type: "Initializer", expression: $2, children: [void 0, void 0, $2] },
5375
5463
  block
5376
5464
  )) {
5377
- const ref = ref5;
5378
- exp.children = exp.children.map(function(c) {
5379
- if (c === $2)
5380
- return ref;
5381
- else
5382
- return c;
5383
- });
5465
+ const ref = ref7;
5466
+ exp.children = exp.children.map(($3) => $3 === $2 ? ref : $3);
5384
5467
  $2 = ref;
5385
5468
  } else {
5386
5469
  block = void 0;
5387
5470
  }
5388
5471
  }
5389
- if ($1.some((left) => left[left.length - 1].special)) {
5472
+ let ref8;
5473
+ if ($1.some(($4) => (ref8 = $4)[ref8.length - 1].special)) {
5390
5474
  if ($1.length !== 1)
5391
5475
  throw new Error("Only one assignment with id= is allowed");
5392
5476
  const [, lhs, , op] = $1[0];
5393
5477
  const { call, omitLhs } = op;
5394
- const index2 = exp.children.indexOf($2);
5395
- if (index2 < 0)
5478
+ const index = exp.children.indexOf($2);
5479
+ if (index < 0)
5396
5480
  throw new Error("Assertion error: exp not in AssignmentExpression");
5397
5481
  exp.children.splice(
5398
- index2,
5482
+ index,
5399
5483
  1,
5400
5484
  exp.expression = $2 = [call, "(", lhs, ", ", $2, ")"]
5401
5485
  );
@@ -5404,12 +5488,15 @@ ${js}`
5404
5488
  }
5405
5489
  }
5406
5490
  let wrapped = false;
5491
+ let i = 0;
5407
5492
  while (i < len3) {
5408
5493
  const lastAssignment = $1[i++];
5409
5494
  const [, lhs, , op] = lastAssignment;
5410
- if (op.token !== "=")
5495
+ if (!(op.token === "=")) {
5411
5496
  continue;
5412
- if (lhs.type === "ObjectExpression" || lhs.type === "ObjectBindingPattern") {
5497
+ }
5498
+ let m1;
5499
+ if (m1 = lhs.type, m1 === "ObjectExpression" || m1 === "ObjectBindingPattern") {
5413
5500
  if (!wrapped) {
5414
5501
  wrapped = true;
5415
5502
  lhs.children.splice(0, 0, "(");
@@ -5422,6 +5509,7 @@ ${js}`
5422
5509
  const lastAssignment = $1[i];
5423
5510
  if (lastAssignment[3].token === "=") {
5424
5511
  const lhs = lastAssignment[1];
5512
+ let m2;
5425
5513
  if (lhs.type === "MemberExpression") {
5426
5514
  const members = lhs.children;
5427
5515
  const lastMember = members[members.length - 1];
@@ -5445,9 +5533,9 @@ ${js}`
5445
5533
  }
5446
5534
  exp.children = [$1];
5447
5535
  exp.names = [];
5448
- return exp;
5536
+ break;
5449
5537
  }
5450
- } else if (lhs.type === "ObjectBindingPattern" || lhs.type === "ArrayBindingPattern") {
5538
+ } else if (m2 = lhs.type, m2 === "ObjectBindingPattern" || m2 === "ArrayBindingPattern") {
5451
5539
  processBindingPatternLHS(lhs, tail);
5452
5540
  }
5453
5541
  }
@@ -5480,10 +5568,12 @@ ${js}`
5480
5568
  i--;
5481
5569
  }
5482
5570
  exp.names = $1.flatMap(([, l]) => l.names || []);
5483
- const index = exp.children.indexOf($2);
5484
- if (index < 0)
5485
- throw new Error("Assertion error: exp not in AssignmentExpression");
5486
- exp.children.splice(index + 1, 0, ...tail);
5571
+ if (tail.length) {
5572
+ const index = exp.children.indexOf($2);
5573
+ if (index < 0)
5574
+ throw new Error("Assertion error: exp not in AssignmentExpression");
5575
+ exp.children.splice(index + 1, 0, ...tail);
5576
+ }
5487
5577
  if (block) {
5488
5578
  block.parent = exp.parent;
5489
5579
  block.expressions.push(["", exp]);
@@ -5542,9 +5632,9 @@ ${js}`
5542
5632
  }
5543
5633
  j++;
5544
5634
  }
5545
- let ref6;
5546
- if (ref6 = conditions.length) {
5547
- const l = ref6;
5635
+ let ref9;
5636
+ if (ref9 = conditions.length) {
5637
+ const l = ref9;
5548
5638
  const cs = flatJoin(conditions, " && ");
5549
5639
  return {
5550
5640
  ...exp,
@@ -5581,8 +5671,8 @@ ${js}`
5581
5671
  return gatherRecursiveAll(node, (n) => n.type === "UnaryType").forEach((unary) => {
5582
5672
  let last;
5583
5673
  let count = 0;
5584
- let ref7;
5585
- while (unary.suffix.length && (ref7 = unary.suffix)[ref7.length - 1]?.token === "?") {
5674
+ let ref10;
5675
+ while (unary.suffix.length && (ref10 = unary.suffix)[ref10.length - 1]?.token === "?") {
5586
5676
  last = unary.suffix.pop();
5587
5677
  count++;
5588
5678
  }
@@ -5613,14 +5703,14 @@ ${js}`
5613
5703
  });
5614
5704
  }
5615
5705
  function processStatementExpressions(statements) {
5616
- gatherRecursiveAll(statements, ($) => $.type === "StatementExpression").forEach((_exp) => {
5706
+ gatherRecursiveAll(statements, ($5) => $5.type === "StatementExpression").forEach((_exp) => {
5617
5707
  const exp = _exp;
5618
5708
  const { statement } = exp;
5619
- let ref8;
5709
+ let ref11;
5620
5710
  switch (statement.type) {
5621
5711
  case "IfStatement": {
5622
- if (ref8 = expressionizeIfStatement(statement)) {
5623
- const expression = ref8;
5712
+ if (ref11 = expressionizeIfStatement(statement)) {
5713
+ const expression = ref11;
5624
5714
  return replaceNode(statement, expression, exp);
5625
5715
  } else {
5626
5716
  return replaceNode(statement, wrapIIFE([["", statement]]), exp);
@@ -5662,7 +5752,7 @@ ${js}`
5662
5752
  }
5663
5753
  } else if (index > start + 1) {
5664
5754
  ref = makeRef();
5665
- subexp = children.splice(start, index);
5755
+ subexp = children.splice(start, index - start);
5666
5756
  } else {
5667
5757
  throw new Error("Invalid parse tree for negative index access");
5668
5758
  }
@@ -5671,7 +5761,7 @@ ${js}`
5671
5761
  exp.hoistDec = hoistDec;
5672
5762
  children.splice(start, 0, makeLeftHandSideExpression(refAssignment));
5673
5763
  }
5674
- return exp.len.children = [
5764
+ exp.len.children = [
5675
5765
  ref,
5676
5766
  ".length"
5677
5767
  ];
@@ -5743,11 +5833,11 @@ ${js}`
5743
5833
  function processPlaceholders(statements) {
5744
5834
  const placeholderMap = /* @__PURE__ */ new Map();
5745
5835
  const liftedIfs = /* @__PURE__ */ new Set();
5746
- gatherRecursiveAll(statements, ($3) => $3.type === "Placeholder").forEach((_exp) => {
5836
+ gatherRecursiveAll(statements, ($6) => $6.type === "Placeholder").forEach((_exp) => {
5747
5837
  const exp = _exp;
5748
5838
  let ancestor;
5749
5839
  if (exp.subtype === ".") {
5750
- ({ ancestor } = findAncestor(exp, ($4) => $4.type === "Call"));
5840
+ ({ ancestor } = findAncestor(exp, ($7) => $7.type === "Call"));
5751
5841
  ancestor = ancestor?.parent;
5752
5842
  while (ancestor?.parent?.type === "UnaryExpression" || ancestor?.parent?.type === "NewExpression") {
5753
5843
  ancestor = ancestor.parent;
@@ -5766,10 +5856,10 @@ ${js}`
5766
5856
  if (type === "IfStatement") {
5767
5857
  liftedIfs.add(ancestor2);
5768
5858
  }
5769
- let m;
5770
- let m1;
5859
+ let m3;
5860
+ let m4;
5771
5861
  return type === "Call" || // Block, except for if/else blocks when condition already lifted
5772
- 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
5862
+ 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
5773
5863
  type === "Initializer" || // Right-hand side of assignment
5774
5864
  type === "AssignmentExpression" && findChildIndex(ancestor2, child2) === ancestor2.children.indexOf(ancestor2.expression) || type === "ReturnStatement" || type === "YieldExpression";
5775
5865
  }));
@@ -5848,8 +5938,8 @@ ${js}`
5848
5938
  for (let i4 = 0, len3 = placeholders.length; i4 < len3; i4++) {
5849
5939
  const placeholder = placeholders[i4];
5850
5940
  typeSuffix ??= placeholder.typeSuffix;
5851
- let ref9;
5852
- replaceNode((ref9 = placeholder.children)[ref9.length - 1], ref);
5941
+ let ref12;
5942
+ replaceNode((ref12 = placeholder.children)[ref12.length - 1], ref);
5853
5943
  }
5854
5944
  const { parent } = ancestor;
5855
5945
  const body = maybeUnwrap(ancestor);
@@ -5880,9 +5970,9 @@ ${js}`
5880
5970
  fnExp = makeLeftHandSideExpression(fnExp);
5881
5971
  }
5882
5972
  replaceNode(ancestor, fnExp, parent);
5883
- let ref10;
5884
- if (ref10 = getTrimmingSpace(body)) {
5885
- const ws = ref10;
5973
+ let ref13;
5974
+ if (ref13 = getTrimmingSpace(body)) {
5975
+ const ws = ref13;
5886
5976
  inplaceInsertTrimmingSpace(body, "");
5887
5977
  inplacePrepend(ws, fnExp);
5888
5978
  }
@@ -5907,43 +5997,39 @@ ${js}`
5907
5997
  children: props,
5908
5998
  names
5909
5999
  };
5910
- } else if (restCount === 1) {
5911
- let after = props.slice(restIndex + 1);
5912
- let rest = props[restIndex];
5913
- props = props.slice(0, restIndex);
5914
- if (after.length) {
5915
- const { delim: restDelim } = rest, lastAfterProp = after[after.length - 1], { delim: lastDelim, children: lastAfterChildren } = lastAfterProp;
5916
- rest = {
5917
- ...rest,
5918
- delim: lastDelim,
5919
- children: [...rest.children.slice(0, -1), lastDelim]
5920
- };
5921
- after = [
5922
- ...after.slice(0, -1),
5923
- {
5924
- ...lastAfterProp,
5925
- delim: restDelim,
5926
- children: [...lastAfterChildren.slice(0, -1), restDelim]
5927
- }
5928
- ];
5929
- }
5930
- let ref11;
5931
- if (Array.isArray(rest.delim) && (ref11 = rest.delim)[ref11.length - 1]?.token === ",") {
5932
- rest.delim = rest.delim.slice(0, -1);
5933
- rest.children = [...rest.children.slice(0, -1), rest.delim];
5934
- }
5935
- const children = [...props, ...after, rest];
5936
- return {
5937
- children,
5938
- names
6000
+ }
6001
+ let after = props.slice(restIndex + 1);
6002
+ let rest = props[restIndex];
6003
+ props = props.slice(0, restIndex);
6004
+ if (after.length) {
6005
+ const { delim: restDelim } = rest, lastAfterProp = after[after.length - 1], { delim: lastDelim, children: lastAfterChildren } = lastAfterProp;
6006
+ rest = {
6007
+ ...rest,
6008
+ delim: lastDelim,
6009
+ children: [...rest.children.slice(0, -1), lastDelim]
5939
6010
  };
6011
+ after = [
6012
+ ...after.slice(0, -1),
6013
+ {
6014
+ ...lastAfterProp,
6015
+ delim: restDelim,
6016
+ children: [...lastAfterChildren.slice(0, -1), restDelim]
6017
+ }
6018
+ ];
5940
6019
  }
5941
- return {
5942
- children: [{
6020
+ let ref14;
6021
+ if (Array.isArray(rest.delim) && (ref14 = rest.delim)[ref14.length - 1]?.token === ",") {
6022
+ rest.delim = rest.delim.slice(0, -1);
6023
+ rest.children = [...rest.children.slice(0, -1), rest.delim];
6024
+ }
6025
+ const children = [...props, ...after, rest];
6026
+ if (restCount > 1) {
6027
+ children.push({
5943
6028
  type: "Error",
5944
6029
  message: "Multiple rest properties in object pattern"
5945
- }, props]
5946
- };
6030
+ });
6031
+ }
6032
+ return { children, names };
5947
6033
  }
5948
6034
  function replaceNodes(root, predicate, replacer) {
5949
6035
  if (!(root != null)) {
@@ -6126,6 +6212,7 @@ ${js}`
6126
6212
  YieldExpression,
6127
6213
  ArrowFunction,
6128
6214
  FatArrow,
6215
+ FatArrowToken,
6129
6216
  TrailingDeclaration,
6130
6217
  TrailingPipe,
6131
6218
  FatArrowBody,
@@ -6246,9 +6333,11 @@ ${js}`
6246
6333
  NoCommaBracedOrEmptyBlock,
6247
6334
  NoPostfixBracedOrEmptyBlock,
6248
6335
  EmptyBlock,
6336
+ BlockOrEmptyStatement,
6249
6337
  BlockOrEmpty,
6250
- EmptyBareBlock,
6251
6338
  EmptyStatementBareBlock,
6339
+ EmptyBareBlock,
6340
+ NoBlock,
6252
6341
  BracedBlock,
6253
6342
  NoPostfixBracedBlock,
6254
6343
  NoCommaBracedBlock,
@@ -7267,13 +7356,14 @@ ${js}`
7267
7356
  }
7268
7357
  var StatementExpression$0 = DebuggerStatement;
7269
7358
  var StatementExpression$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(IfStatement), function($skip, $loc, $0, $1) {
7270
- if (!$1.else && isEmptyBareBlock($1.then))
7359
+ if (!$1.else && $1.then.implicit)
7271
7360
  return $skip;
7272
7361
  return $1;
7273
7362
  });
7274
7363
  var StatementExpression$2 = (0, import_lib3.$TS)((0, import_lib3.$S)(IterationExpression), function($skip, $loc, $0, $1) {
7275
- if (isEmptyBareBlock($1.block))
7364
+ if ($1.block.implicit && $1.subtype !== "DoStatement" && $1.subtype !== "ComptimeStatement") {
7276
7365
  return $skip;
7366
+ }
7277
7367
  return $1;
7278
7368
  });
7279
7369
  var StatementExpression$3 = SwitchStatement;
@@ -7364,7 +7454,7 @@ ${js}`
7364
7454
  return $0;
7365
7455
  return $skip;
7366
7456
  });
7367
- var ForbiddenImplicitCalls$7 = (0, import_lib3.$S)(PostfixStatement, EmptyStatementBareBlock);
7457
+ var ForbiddenImplicitCalls$7 = (0, import_lib3.$S)(PostfixStatement, NoBlock);
7368
7458
  var ForbiddenImplicitCalls$8 = (0, import_lib3.$EXPECT)($L5, 'ForbiddenImplicitCalls "... "');
7369
7459
  var ForbiddenImplicitCalls$$ = [ForbiddenImplicitCalls$0, ForbiddenImplicitCalls$1, ForbiddenImplicitCalls$2, ForbiddenImplicitCalls$3, ForbiddenImplicitCalls$4, ForbiddenImplicitCalls$5, ForbiddenImplicitCalls$6, ForbiddenImplicitCalls$7, ForbiddenImplicitCalls$8];
7370
7460
  function ForbiddenImplicitCalls(ctx, state2) {
@@ -7589,11 +7679,10 @@ ${js}`
7589
7679
  var post = $3;
7590
7680
  return processUnaryExpression(pre, exp, post);
7591
7681
  });
7592
- 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) {
7682
+ 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) {
7593
7683
  var ws = $3;
7594
7684
  var exp = $4;
7595
- ws = insertTrimmingSpace(ws, "");
7596
- return ["(", ...ws, exp, ")()"];
7685
+ return processCoffeeDo(ws, exp);
7597
7686
  });
7598
7687
  var UnaryExpression$$ = [UnaryExpression$0, UnaryExpression$1];
7599
7688
  function UnaryExpression(ctx, state2) {
@@ -7815,6 +7904,7 @@ ${js}`
7815
7904
  var async = $1;
7816
7905
  var parameters = $2;
7817
7906
  var suffix = $3;
7907
+ var arrow = $4;
7818
7908
  var expOrBlock = $5;
7819
7909
  if (hasAwait(expOrBlock) && !async) {
7820
7910
  async = "async ";
@@ -7839,22 +7929,29 @@ ${js}`
7839
7929
  ts: false,
7840
7930
  async,
7841
7931
  block: expOrBlock,
7842
- children: [async, $0.slice(1), error]
7932
+ children: [async, parameters, suffix, arrow, error, expOrBlock]
7843
7933
  };
7844
7934
  });
7845
7935
  var ArrowFunction$$ = [ArrowFunction$0, ArrowFunction$1];
7846
7936
  function ArrowFunction(ctx, state2) {
7847
7937
  return (0, import_lib3.$EVENT_C)(ctx, state2, "ArrowFunction", ArrowFunction$$);
7848
7938
  }
7849
- 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) {
7939
+ var FatArrow$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$E)(_), FatArrowToken), function($skip, $loc, $0, $1, $2) {
7850
7940
  var ws = $1;
7941
+ var arrow = $2;
7851
7942
  if (!ws)
7852
- return " =>";
7853
- return [$1, "=>"];
7943
+ ws = " ";
7944
+ return [ws, arrow];
7854
7945
  });
7855
7946
  function FatArrow(ctx, state2) {
7856
7947
  return (0, import_lib3.$EVENT)(ctx, state2, "FatArrow", FatArrow$0);
7857
7948
  }
7949
+ 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) {
7950
+ return { $loc, token: "=>" };
7951
+ });
7952
+ function FatArrowToken(ctx, state2) {
7953
+ return (0, import_lib3.$EVENT)(ctx, state2, "FatArrowToken", FatArrowToken$0);
7954
+ }
7858
7955
  var TrailingDeclaration$0 = (0, import_lib3.$S)((0, import_lib3.$E)(_), (0, import_lib3.$C)(ConstAssignment, LetAssignment));
7859
7956
  function TrailingDeclaration(ctx, state2) {
7860
7957
  return (0, import_lib3.$EVENT)(ctx, state2, "TrailingDeclaration", TrailingDeclaration$0);
@@ -8366,7 +8463,13 @@ ${js}`
8366
8463
  children: [at, {
8367
8464
  type: "PropertyAccess",
8368
8465
  name: id,
8369
- children: [".", id]
8466
+ children: [".", {
8467
+ $loc: {
8468
+ pos: $loc.pos + 1,
8469
+ length: $loc.length - 1
8470
+ },
8471
+ token: id
8472
+ }]
8370
8473
  }],
8371
8474
  thisShorthand: true
8372
8475
  };
@@ -9038,11 +9141,17 @@ ${js}`
9038
9141
  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) {
9039
9142
  var accessModifier = $2;
9040
9143
  var binding = $4;
9144
+ var typeSuffix = $5;
9145
+ var initializer = $6;
9146
+ var delim = $7;
9041
9147
  return {
9042
9148
  type: "Parameter",
9043
9149
  children: $0,
9044
9150
  names: binding.names,
9045
- accessModifier
9151
+ typeSuffix,
9152
+ accessModifier,
9153
+ initializer,
9154
+ delim
9046
9155
  };
9047
9156
  });
9048
9157
  function ParameterElement(ctx, state2) {
@@ -9904,43 +10013,62 @@ ${js}`
9904
10013
  expressions,
9905
10014
  children: [$1, expressions, $2],
9906
10015
  bare: false,
9907
- empty: true
10016
+ empty: true,
10017
+ implicit: true
9908
10018
  };
9909
10019
  });
9910
10020
  function EmptyBlock(ctx, state2) {
9911
10021
  return (0, import_lib3.$EVENT)(ctx, state2, "EmptyBlock", EmptyBlock$0);
9912
10022
  }
10023
+ var BlockOrEmptyStatement$0 = Block;
10024
+ var BlockOrEmptyStatement$1 = (0, import_lib3.$T)((0, import_lib3.$S)(NoBlock, EmptyStatementBareBlock), function(value) {
10025
+ return value[1];
10026
+ });
10027
+ var BlockOrEmptyStatement$$ = [BlockOrEmptyStatement$0, BlockOrEmptyStatement$1];
10028
+ function BlockOrEmptyStatement(ctx, state2) {
10029
+ return (0, import_lib3.$EVENT_C)(ctx, state2, "BlockOrEmptyStatement", BlockOrEmptyStatement$$);
10030
+ }
9913
10031
  var BlockOrEmpty$0 = Block;
9914
- var BlockOrEmpty$1 = EmptyStatementBareBlock;
10032
+ var BlockOrEmpty$1 = (0, import_lib3.$T)((0, import_lib3.$S)(NoBlock, EmptyBlock), function(value) {
10033
+ return value[1];
10034
+ });
9915
10035
  var BlockOrEmpty$$ = [BlockOrEmpty$0, BlockOrEmpty$1];
9916
10036
  function BlockOrEmpty(ctx, state2) {
9917
10037
  return (0, import_lib3.$EVENT_C)(ctx, state2, "BlockOrEmpty", BlockOrEmpty$$);
9918
10038
  }
9919
- var EmptyBareBlock$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L0, 'EmptyBareBlock ""'), function($skip, $loc, $0, $1) {
9920
- const expressions = [];
10039
+ var EmptyStatementBareBlock$0 = (0, import_lib3.$TV)(InsertEmptyStatement, function($skip, $loc, $0, $1) {
10040
+ var s = $0;
10041
+ const expressions = [["", s]];
9921
10042
  return {
9922
10043
  type: "BlockStatement",
9923
10044
  expressions,
9924
10045
  children: [expressions],
9925
- bare: true
10046
+ bare: true,
10047
+ empty: true,
10048
+ implicit: true,
10049
+ semicolon: s.children[0]
9926
10050
  };
9927
10051
  });
9928
- function EmptyBareBlock(ctx, state2) {
9929
- return (0, import_lib3.$EVENT)(ctx, state2, "EmptyBareBlock", EmptyBareBlock$0);
10052
+ function EmptyStatementBareBlock(ctx, state2) {
10053
+ return (0, import_lib3.$EVENT)(ctx, state2, "EmptyStatementBareBlock", EmptyStatementBareBlock$0);
9930
10054
  }
9931
- 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) {
9932
- var s = $3;
9933
- const expressions = [["", s]];
10055
+ var EmptyBareBlock$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L0, 'EmptyBareBlock ""'), function($skip, $loc, $0, $1) {
10056
+ const expressions = [];
9934
10057
  return {
9935
10058
  type: "BlockStatement",
9936
10059
  expressions,
9937
10060
  children: [expressions],
9938
10061
  bare: true,
9939
- semicolon: s.children[0]
10062
+ empty: true,
10063
+ implicit: true
9940
10064
  };
9941
10065
  });
9942
- function EmptyStatementBareBlock(ctx, state2) {
9943
- return (0, import_lib3.$EVENT)(ctx, state2, "EmptyStatementBareBlock", EmptyStatementBareBlock$0);
10066
+ function EmptyBareBlock(ctx, state2) {
10067
+ return (0, import_lib3.$EVENT)(ctx, state2, "EmptyBareBlock", EmptyBareBlock$0);
10068
+ }
10069
+ var NoBlock$0 = (0, import_lib3.$S)((0, import_lib3.$Y)(EOS), (0, import_lib3.$N)(IndentedFurther));
10070
+ function NoBlock(ctx, state2) {
10071
+ return (0, import_lib3.$EVENT)(ctx, state2, "NoBlock", NoBlock$0);
9944
10072
  }
9945
10073
  var BracedBlock$0 = NonSingleBracedBlock;
9946
10074
  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) {
@@ -11792,7 +11920,7 @@ ${js}`
11792
11920
  function IterationExpression(ctx, state2) {
11793
11921
  return (0, import_lib3.$EVENT)(ctx, state2, "IterationExpression", IterationExpression$0);
11794
11922
  }
11795
- var LoopStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(LoopClause, BlockOrEmpty), function($skip, $loc, $0, $1, $2) {
11923
+ var LoopStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(LoopClause, BlockOrEmptyStatement), function($skip, $loc, $0, $1, $2) {
11796
11924
  var clause = $1;
11797
11925
  var block = $2;
11798
11926
  return {
@@ -11870,7 +11998,7 @@ ${js}`
11870
11998
  function ComptimeStatement(ctx, state2) {
11871
11999
  return (0, import_lib3.$EVENT)(ctx, state2, "ComptimeStatement", ComptimeStatement$0);
11872
12000
  }
11873
- var WhileStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(WhileClause, BlockOrEmpty), function($skip, $loc, $0, $1, $2) {
12001
+ var WhileStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(WhileClause, BlockOrEmptyStatement), function($skip, $loc, $0, $1, $2) {
11874
12002
  var clause = $1;
11875
12003
  var block = $2;
11876
12004
  return {
@@ -11901,7 +12029,7 @@ ${js}`
11901
12029
  function WhileClause(ctx, state2) {
11902
12030
  return (0, import_lib3.$EVENT)(ctx, state2, "WhileClause", WhileClause$0);
11903
12031
  }
11904
- var ForStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(ForClause, BlockOrEmpty), function($skip, $loc, $0, $1, $2) {
12032
+ var ForStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(ForClause, BlockOrEmptyStatement), function($skip, $loc, $0, $1, $2) {
11905
12033
  var clause = $1;
11906
12034
  var block = $2;
11907
12035
  block = blockWithPrefix(clause.blockPrefix, block);
@@ -16479,33 +16607,20 @@ ${js}`
16479
16607
  }
16480
16608
  }
16481
16609
 
16482
- // source/util.civet
16483
- var util_exports = {};
16484
- __export(util_exports, {
16610
+ // source/sourcemap.civet
16611
+ var sourcemap_exports = {};
16612
+ __export(sourcemap_exports, {
16485
16613
  SourceMap: () => SourceMap,
16486
16614
  base64Encode: () => base64Encode,
16487
16615
  locationTable: () => locationTable,
16488
16616
  lookupLineColumn: () => lookupLineColumn
16489
16617
  });
16490
- var smRegexp;
16491
- var prettySourceExcerpt;
16492
- var VLQ_SHIFT;
16493
- var VLQ_CONTINUATION_BIT;
16494
- var VLQ_VALUE_MASK;
16495
- var encodeVlq;
16496
- var BASE64_CHARS;
16497
- var encodeBase64;
16498
- var vlqTable;
16499
- var vlqChars;
16500
- var decodeError;
16501
- var decodeVLQ;
16502
- var remapPosition;
16503
16618
  var locationTable = function(input) {
16504
- var linesRe, lines, line, pos, result;
16505
- linesRe = /([^\r\n]*)(\r\n|\r|\n|$)/y;
16506
- lines = [];
16507
- line = 0;
16508
- pos = 0;
16619
+ const linesRe = /([^\r\n]*)(\r\n|\r|\n|$)/y;
16620
+ const lines = [];
16621
+ let line = 0;
16622
+ let pos = 0;
16623
+ let result;
16509
16624
  while (result = linesRe.exec(input)) {
16510
16625
  pos += result[0].length;
16511
16626
  lines[line++] = pos;
@@ -16516,39 +16631,35 @@ ${js}`
16516
16631
  return lines;
16517
16632
  };
16518
16633
  var lookupLineColumn = function(table, pos) {
16519
- var l, prevEnd;
16520
- l = 0;
16521
- prevEnd = 0;
16634
+ let l = 0;
16635
+ let prevEnd = 0;
16522
16636
  while (table[l] <= pos) {
16523
16637
  prevEnd = table[l++];
16524
16638
  }
16525
16639
  return [l, pos - prevEnd];
16526
16640
  };
16527
16641
  var SourceMap = function(sourceString) {
16528
- var srcTable, sm, EOL2;
16529
- srcTable = locationTable(sourceString);
16530
- sm = {
16642
+ const srcTable = locationTable(sourceString);
16643
+ const sm = {
16531
16644
  lines: [[]],
16532
- lineNum: 0,
16533
- colOffset: 0,
16645
+ line: 0,
16646
+ column: 0,
16647
+ srcLine: 0,
16648
+ srcColumn: 0,
16649
+ srcOffset: 0,
16534
16650
  srcTable
16535
16651
  };
16536
- EOL2 = /\r?\n|\r/;
16652
+ const EOL2 = /\r?\n|\r/;
16537
16653
  return {
16538
16654
  data: sm,
16539
- source: function() {
16540
- return sourceString;
16541
- },
16542
16655
  renderMappings: function() {
16543
- var lastSourceLine, lastSourceColumn;
16544
- lastSourceLine = 0;
16545
- lastSourceColumn = 0;
16656
+ let lastSourceLine = 0;
16657
+ let lastSourceColumn = 0;
16546
16658
  return sm.lines.map(function(line) {
16547
16659
  return line.map(function(entry) {
16548
- var colDelta, sourceFileIndex, srcLine, srcCol, lineDelta;
16549
16660
  if (entry.length === 4) {
16550
- [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16551
- lineDelta = srcLine - lastSourceLine;
16661
+ let [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16662
+ const lineDelta = srcLine - lastSourceLine;
16552
16663
  colDelta = srcCol - lastSourceColumn;
16553
16664
  lastSourceLine = srcLine;
16554
16665
  lastSourceColumn = srcCol;
@@ -16572,26 +16683,31 @@ ${js}`
16572
16683
  }
16573
16684
  };
16574
16685
  },
16575
- updateSourceMap: function(outputStr, inputPos) {
16576
- var outLines, srcLine, srcCol;
16577
- outLines = outputStr.split(EOL2);
16686
+ updateSourceMap: function(outputStr, inputPos, colOffset = 0) {
16687
+ const outLines = outputStr.split(EOL2);
16688
+ let srcLine, srcCol;
16578
16689
  if (inputPos != null) {
16579
16690
  [srcLine, srcCol] = lookupLineColumn(srcTable, inputPos);
16691
+ srcCol += colOffset;
16692
+ sm.srcLine = srcLine;
16693
+ sm.srcColumn = srcCol;
16694
+ sm.srcOffset = inputPos + outputStr.length;
16580
16695
  }
16581
16696
  outLines.forEach(function(line, i) {
16582
- var l;
16583
16697
  if (i > 0) {
16584
- sm.lineNum++;
16585
- sm.colOffset = 0;
16586
- sm.lines[sm.lineNum] = [];
16587
- srcCol = 0;
16698
+ sm.line++;
16699
+ sm.srcLine++;
16700
+ sm.column = 0;
16701
+ sm.lines[sm.line] = [];
16702
+ sm.srcColumn = srcCol = colOffset;
16588
16703
  }
16589
- l = sm.colOffset;
16590
- sm.colOffset = line.length;
16704
+ const l = sm.column;
16705
+ sm.column += line.length;
16706
+ sm.srcColumn += line.length;
16591
16707
  if (inputPos != null) {
16592
- return sm.lines[sm.lineNum].push([l, 0, srcLine + i, srcCol]);
16593
- } else if (l !== 0) {
16594
- return sm.lines[sm.lineNum].push([l]);
16708
+ return sm.lines[sm.line].push([l, 0, srcLine + i, srcCol]);
16709
+ } else if (l != 0) {
16710
+ return sm.lines[sm.line].push([l]);
16595
16711
  }
16596
16712
  ;
16597
16713
  return;
@@ -16600,74 +16716,36 @@ ${js}`
16600
16716
  }
16601
16717
  };
16602
16718
  };
16603
- SourceMap.parseWithLines = function(base64encodedJSONstr) {
16604
- var json, sourceLine, sourceColumn, lines;
16605
- json = JSON.parse(Buffer.from(base64encodedJSONstr, "base64").toString("utf8"));
16606
- sourceLine = 0;
16607
- sourceColumn = 0;
16608
- lines = json.mappings.split(";").map(function(line) {
16609
- if (line.length === 0) {
16610
- return [];
16611
- }
16612
- return line.split(",").map(function(entry) {
16613
- var result;
16614
- result = decodeVLQ(entry);
16615
- switch (result.length) {
16616
- case 1: {
16617
- return [result[0]];
16618
- }
16619
- case 4: {
16620
- return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3]];
16621
- }
16622
- case 5: {
16623
- return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3], result[4]];
16624
- }
16625
- default: {
16626
- throw new Error("Unknown source map entry", result);
16627
- }
16628
- }
16629
- });
16719
+ var smRegexp = /\n\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,([+a-zA-Z0-9\/]*=?=?)$/;
16720
+ var remap = function(codeWithSourceMap, upstreamMap, sourcePath, targetPath) {
16721
+ let sourceMapText;
16722
+ const codeWithoutSourceMap = codeWithSourceMap.replace(smRegexp, (match, sm) => {
16723
+ sourceMapText = sm;
16724
+ return "";
16630
16725
  });
16631
- json.lines = lines;
16632
- return json;
16633
- };
16634
- smRegexp = /\n\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,([+a-zA-Z0-9\/]*=?=?)$/;
16635
- SourceMap.remap = function(codeWithSourceMap, upstreamMap, sourcePath, targetPath) {
16636
- var sourceMapText, codeWithoutSourceMap, remappedSourceMapJSON, newSourceMap, remappedCodeWithSourceMap, parsed, composedLines;
16637
- sourceMapText = null;
16638
- codeWithoutSourceMap = codeWithSourceMap.replace(
16639
- smRegexp,
16640
- (match, sm) => {
16641
- sourceMapText = sm;
16642
- return "";
16643
- }
16644
- );
16645
16726
  if (sourceMapText) {
16646
- parsed = SourceMap.parseWithLines(sourceMapText);
16647
- composedLines = SourceMap.composeLines(upstreamMap.data.lines, parsed.lines);
16727
+ const parsed = parseWithLines(sourceMapText);
16728
+ const composedLines = composeLines(upstreamMap.data.lines, parsed.lines);
16648
16729
  upstreamMap.data.lines = composedLines;
16649
16730
  }
16650
- remappedSourceMapJSON = upstreamMap.json(sourcePath, targetPath);
16651
- newSourceMap = `${"sourceMapping"}URL=data:application/json;charset=utf-8;base64,${base64Encode(JSON.stringify(remappedSourceMapJSON))}`;
16652
- remappedCodeWithSourceMap = `${codeWithoutSourceMap}
16731
+ const remappedSourceMapJSON = upstreamMap.json(sourcePath, targetPath);
16732
+ const newSourceMap = `${"sourceMapping"}URL=data:application/json;charset=utf-8;base64,${base64Encode(JSON.stringify(remappedSourceMapJSON))}`;
16733
+ const remappedCodeWithSourceMap = `${codeWithoutSourceMap}
16653
16734
  //# ${newSourceMap}`;
16654
16735
  return remappedCodeWithSourceMap;
16655
16736
  };
16656
- SourceMap.composeLines = function(upstreamMapping, lines) {
16657
- return lines.map(function(line, l) {
16737
+ var composeLines = function(upstreamMapping, lines) {
16738
+ return lines.map(function(line) {
16658
16739
  return line.map(function(entry) {
16659
- var colDelta, sourceFileIndex, srcLine, srcCol, srcPos, upstreamLine, upstreamCol;
16660
16740
  if (entry.length === 1) {
16661
16741
  return entry;
16662
16742
  }
16663
- ;
16664
- [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16665
- srcPos = remapPosition([srcLine, srcCol], upstreamMapping);
16743
+ const [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16744
+ const srcPos = remapPosition([srcLine, srcCol], upstreamMapping);
16666
16745
  if (!srcPos) {
16667
16746
  return [entry[0]];
16668
16747
  }
16669
- ;
16670
- [upstreamLine, upstreamCol] = srcPos;
16748
+ const [upstreamLine, upstreamCol] = srcPos;
16671
16749
  if (entry.length === 4) {
16672
16750
  return [colDelta, sourceFileIndex, upstreamLine, upstreamCol];
16673
16751
  }
@@ -16675,44 +16753,50 @@ ${js}`
16675
16753
  });
16676
16754
  });
16677
16755
  };
16678
- prettySourceExcerpt = function(source, location, length) {
16679
- var lines, lineNum, colNum, i, line, lineNumStr;
16680
- lines = source.split(/\r?\n|\r/);
16681
- lineNum = location.line;
16682
- colNum = location.column;
16683
- for (let start = lineNum - 2, end = lineNum + 2, i1 = i = start, asc = start <= end; asc ? i1 <= end : i1 >= end; i = asc ? ++i1 : --i1) {
16684
- if (i < 0 || i >= lines.length) {
16685
- continue;
16686
- }
16687
- line = lines[i];
16688
- lineNumStr = (i + 1).toString();
16689
- while (lineNumStr.length < 4) {
16690
- lineNumStr = " " + lineNumStr;
16691
- }
16692
- if (i === lineNum) {
16693
- console.log(`${lineNumStr}: ${line}`);
16694
- console.log(" ".repeat(lineNumStr.length + 2 + colNum) + "^".repeat(length));
16695
- } else {
16696
- console.log(`${lineNumStr}: ${line}`);
16756
+ var parseWithLines = function(base64encodedJSONstr) {
16757
+ const json = JSON.parse(Buffer.from(base64encodedJSONstr, "base64").toString("utf8"));
16758
+ let sourceLine = 0;
16759
+ let sourceColumn = 0;
16760
+ const lines = json.mappings.split(";").map(function(line) {
16761
+ if (line.length === 0) {
16762
+ return [];
16697
16763
  }
16698
- }
16699
- return;
16764
+ return line.split(",").map(function(entry) {
16765
+ const result = decodeVLQ(entry);
16766
+ switch (result.length) {
16767
+ case 1: {
16768
+ return [result[0]];
16769
+ }
16770
+ case 4: {
16771
+ return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3]];
16772
+ }
16773
+ case 5: {
16774
+ return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3], result[4]];
16775
+ }
16776
+ default: {
16777
+ throw new Error("Unknown source map entry", result);
16778
+ }
16779
+ }
16780
+ });
16781
+ });
16782
+ json.lines = lines;
16783
+ return json;
16700
16784
  };
16701
- VLQ_SHIFT = 5;
16702
- VLQ_CONTINUATION_BIT = 1 << VLQ_SHIFT;
16703
- VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - 1;
16704
- encodeVlq = function(value) {
16705
- var answer, valueToEncode, signBit, nextChunk;
16706
- answer = "";
16785
+ Object.assign(SourceMap, { remap, parseWithLines, composeLines });
16786
+ var VLQ_SHIFT = 5;
16787
+ var VLQ_CONTINUATION_BIT = 1 << VLQ_SHIFT;
16788
+ var VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - 1;
16789
+ var encodeVlq = function(value) {
16790
+ let answer = "";
16707
16791
  let ref;
16708
16792
  if (value < 0)
16709
16793
  ref = 1;
16710
16794
  else
16711
16795
  ref = 0;
16712
- signBit = ref;
16713
- valueToEncode = (Math.abs(value) << 1) + signBit;
16796
+ const signBit = ref;
16797
+ let valueToEncode = (Math.abs(value) << 1) + signBit;
16714
16798
  while (valueToEncode || !answer) {
16715
- nextChunk = valueToEncode & VLQ_VALUE_MASK;
16799
+ let nextChunk = valueToEncode & VLQ_VALUE_MASK;
16716
16800
  valueToEncode = valueToEncode >> VLQ_SHIFT;
16717
16801
  if (valueToEncode) {
16718
16802
  nextChunk |= VLQ_CONTINUATION_BIT;
@@ -16721,21 +16805,20 @@ ${js}`
16721
16805
  }
16722
16806
  return answer;
16723
16807
  };
16724
- BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16725
- encodeBase64 = function(value) {
16808
+ var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16809
+ var encodeBase64 = function(value) {
16726
16810
  return BASE64_CHARS[value] || (() => {
16727
- throw new Error(`Cannot Base64 encode value: ${value}`);
16811
+ throw new Error("Cannot Base64 encode value: ${value}");
16728
16812
  })();
16729
16813
  };
16730
16814
  var base64Encode = function(src) {
16731
16815
  return Buffer.from(src).toString("base64");
16732
16816
  };
16733
- vlqTable = new Uint8Array(128);
16734
- vlqChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16817
+ var vlqTable = new Uint8Array(128);
16818
+ var vlqChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16735
16819
  (function() {
16736
- var i, l;
16737
- i = 0;
16738
- l = vlqTable.length;
16820
+ let i = 0;
16821
+ let l = vlqTable.length;
16739
16822
  while (i < l) {
16740
16823
  vlqTable[i] = 255;
16741
16824
  i++;
@@ -16750,28 +16833,28 @@ ${js}`
16750
16833
  ;
16751
16834
  return results;
16752
16835
  })();
16753
- decodeError = function(message) {
16836
+ var decodeError = function(message) {
16754
16837
  throw new Error(message);
16755
16838
  };
16756
- decodeVLQ = function(mapping) {
16757
- var i, l, result, shift, vlq, c, index, v;
16758
- i = 0;
16759
- l = mapping.length;
16760
- result = [];
16839
+ var decodeVLQ = function(mapping) {
16840
+ let i = 0;
16841
+ let l = mapping.length;
16842
+ let result = [];
16761
16843
  while (i < l) {
16762
- shift = 0;
16763
- vlq = 0;
16844
+ let shift = 0;
16845
+ let vlq = 0;
16846
+ let v = 0;
16764
16847
  while (true) {
16765
16848
  if (i >= l) {
16766
16849
  decodeError("Unexpected early end of mapping data");
16767
16850
  }
16768
- c = mapping.charCodeAt(i);
16769
- if ((c & 127) !== c) {
16770
- decodeError(`Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}`);
16851
+ const c = mapping.charCodeAt(i);
16852
+ if ((c & 127) != c) {
16853
+ decodeError("Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}");
16771
16854
  }
16772
- index = vlqTable[c & 127];
16855
+ const index = vlqTable[c & 127];
16773
16856
  if (index === 255) {
16774
- decodeError(`Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}`);
16857
+ decodeError("Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}");
16775
16858
  }
16776
16859
  i++;
16777
16860
  vlq |= (index & 31) << shift;
@@ -16789,20 +16872,19 @@ ${js}`
16789
16872
  }
16790
16873
  return result;
16791
16874
  };
16792
- remapPosition = function(position, sourcemapLines) {
16793
- var line, character, textLine, i, p, l, lastMapping, lastMappingPosition, mapping;
16794
- [line, character] = position;
16795
- textLine = sourcemapLines[line];
16875
+ var remapPosition = function(position, sourcemapLines) {
16876
+ const [line, character] = position;
16877
+ const textLine = sourcemapLines[line];
16796
16878
  if (!textLine?.length) {
16797
16879
  return void 0;
16798
16880
  }
16799
- i = 0;
16800
- p = 0;
16801
- l = textLine.length;
16802
- lastMapping = void 0;
16803
- lastMappingPosition = 0;
16881
+ let i = 0;
16882
+ let p = 0;
16883
+ const l = textLine.length;
16884
+ let lastMapping = void 0;
16885
+ let lastMappingPosition = 0;
16804
16886
  while (i < l) {
16805
- mapping = textLine[i];
16887
+ const mapping = textLine[i];
16806
16888
  p += mapping[0];
16807
16889
  if (mapping.length === 4) {
16808
16890
  lastMapping = mapping;
@@ -16813,7 +16895,7 @@ ${js}`
16813
16895
  }
16814
16896
  i++;
16815
16897
  }
16816
- if (character - lastMappingPosition !== 0) {
16898
+ if (character - lastMappingPosition != 0) {
16817
16899
  return void 0;
16818
16900
  }
16819
16901
  if (lastMapping) {
@@ -16864,20 +16946,15 @@ ${js}`
16864
16946
  };
16865
16947
 
16866
16948
  // source/main.civet
16867
- var { SourceMap: SourceMap2 } = util_exports;
16949
+ var { SourceMap: SourceMap2 } = sourcemap_exports;
16868
16950
  var ParseErrors = class extends Error {
16869
16951
  name = "ParseErrors";
16870
- filename;
16871
- line;
16872
- column;
16873
- offset;
16874
- constructor(message, filename1, line1, column1, offset1) {
16875
- super(message);
16876
- this.filename = filename1;
16877
- this.line = line1;
16878
- this.column = column1;
16879
- this.offset = offset1;
16952
+ errors;
16953
+ constructor(errors) {
16954
+ const message = errors.map(($) => $.message).join("\n");
16955
+ super(errors.map(($1) => $1.message).join("\n"));
16880
16956
  this.message = message;
16957
+ this.errors = errors;
16881
16958
  }
16882
16959
  };
16883
16960
  var uncacheable = /* @__PURE__ */ new Set([
@@ -16979,6 +17056,7 @@ ${counts}`;
16979
17056
  });
16980
17057
  }
16981
17058
  }
17059
+ const throwOnErrors = options.errors == null;
16982
17060
  function rest(ast2) {
16983
17061
  options = options;
16984
17062
  if (!(options.ast === "raw")) {
@@ -16988,28 +17066,36 @@ ${counts}`;
16988
17066
  return ast2;
16989
17067
  }
16990
17068
  function checkErrors() {
17069
+ if (!throwOnErrors) {
17070
+ return;
17071
+ }
17072
+ options = options;
16991
17073
  if (options.errors?.length) {
16992
- throw new ParseErrors(options.errors.map(($) => $.message).join("\n"));
17074
+ throw new ParseErrors(options.errors);
16993
17075
  }
16994
17076
  ;
16995
17077
  return;
16996
17078
  }
16997
17079
  if (options.sourceMap || options.inlineMap) {
16998
- const sm = SourceMap2(src);
16999
- options.updateSourceMap = sm.updateSourceMap;
17080
+ options.sourceMap = SourceMap2(src);
17000
17081
  const code = generate_default(ast2, options);
17001
17082
  checkErrors();
17002
17083
  if (options.inlineMap) {
17003
- return SourceMap2.remap(code, sm, filename2, filename2 + ".tsx");
17084
+ return SourceMap2.remap(code, options.sourceMap, filename2, filename2 + ".tsx");
17004
17085
  } else {
17005
17086
  return {
17006
17087
  code,
17007
- sourceMap: sm
17088
+ sourceMap: options.sourceMap
17008
17089
  };
17009
17090
  }
17010
17091
  }
17011
17092
  const result = generate_default(ast2, options);
17012
- checkErrors();
17093
+ if (options.errors?.length) {
17094
+ delete options.errors;
17095
+ options.sourceMap = SourceMap2(src);
17096
+ generate_default(ast2, options);
17097
+ checkErrors();
17098
+ }
17013
17099
  return result;
17014
17100
  }
17015
17101
  if (ast.then != null) {
@@ -17081,9 +17167,8 @@ ${counts}`;
17081
17167
  return events;
17082
17168
  };
17083
17169
  var isCompileError = function(err) {
17084
- return err instanceof Error && //@ts-ignore
17085
- [err.message, err.name, err.filename, err.line, err.column, err.offset].every(($1) => $1 !== void 0);
17170
+ return err instanceof import_lib3.ParseError || err instanceof ParseErrors;
17086
17171
  };
17087
- var main_default = { parse, parseProgram, generate: generate_default, util: util_exports, compile, isCompileError };
17172
+ var main_default = { parse, parseProgram, ParseError: import_lib3.ParseError, ParseErrors, generate: generate_default, sourcemap: sourcemap_exports, SourceMap: SourceMap2, compile, isCompileError };
17088
17173
  return __toCommonJS(main_exports);
17089
17174
  })();