@danielx/civet 0.7.9 → 0.7.11

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.js CHANGED
@@ -30,9 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // ../Hera/dist/machine.js
33
+ // node_modules/@danielx/hera/dist/machine.js
34
34
  var require_machine = __commonJS({
35
- "../Hera/dist/machine.js"(exports2, module2) {
35
+ "node_modules/@danielx/hera/dist/machine.js"(exports2, module2) {
36
36
  "use strict";
37
37
  var __defProp2 = Object.defineProperty;
38
38
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
@@ -71,6 +71,7 @@ var require_machine = __commonJS({
71
71
  $TS: () => $TS2,
72
72
  $TV: () => $TV2,
73
73
  $Y: () => $Y2,
74
+ ParseError: () => ParseError2,
74
75
  Validator: () => Validator2
75
76
  });
76
77
  module2.exports = __toCommonJS2(machine_exports);
@@ -437,11 +438,10 @@ ${input.slice(result.pos)}
437
438
  hint = JSON.stringify(hint);
438
439
  else
439
440
  hint = "EOF";
440
- const error = new ParseError(`${filename2}:${line}:${column} Failed to parse
441
- Expected:
441
+ const error = new ParseError2("Failed to parse", `Expected:
442
442
  ${expectations.join("\n ")}
443
443
  Found: ${hint}
444
- `, "ParseError", filename2, line, column, maxFailPos);
444
+ `, filename2, line, column, maxFailPos);
445
445
  throw error;
446
446
  }
447
447
  if (result) {
@@ -464,15 +464,21 @@ ${input.slice(result.pos)}
464
464
  reset
465
465
  };
466
466
  }
467
- var ParseError = class extends Error {
468
- constructor(message, name, filename2, line, column, offset) {
467
+ var ParseError2 = class extends Error {
468
+ constructor(header, body, filename2, line, column, offset) {
469
+ let message = `${filename2}:${line}:${column} ${header}`;
470
+ if (body)
471
+ message += `
472
+ ${body}`;
469
473
  super(message);
470
- this.message = message;
471
- this.name = name;
474
+ this.header = header;
475
+ this.body = body;
472
476
  this.filename = filename2;
473
477
  this.line = line;
474
478
  this.column = column;
475
479
  this.offset = offset;
480
+ this.name = "ParseError";
481
+ this.message = message;
476
482
  }
477
483
  };
478
484
  }
@@ -481,7 +487,9 @@ ${input.slice(result.pos)}
481
487
  // source/main.civet
482
488
  var main_exports = {};
483
489
  __export(main_exports, {
490
+ ParseError: () => import_lib3.ParseError,
484
491
  ParseErrors: () => ParseErrors,
492
+ SourceMap: () => SourceMap2,
485
493
  compile: () => compile,
486
494
  default: () => main_default,
487
495
  generate: () => generate_default,
@@ -490,7 +498,7 @@ __export(main_exports, {
490
498
  parse: () => parse,
491
499
  parseProgram: () => parseProgram,
492
500
  prune: () => prune,
493
- util: () => util_exports
501
+ sourcemap: () => sourcemap_exports
494
502
  });
495
503
  module.exports = __toCommonJS(main_exports);
496
504
 
@@ -546,6 +554,7 @@ __export(lib_exports, {
546
554
  processAssignmentDeclaration: () => processAssignmentDeclaration,
547
555
  processBinaryOpExpression: () => processBinaryOpExpression,
548
556
  processCallMemberExpression: () => processCallMemberExpression,
557
+ processCoffeeDo: () => processCoffeeDo,
549
558
  processCoffeeInterpolation: () => processCoffeeInterpolation,
550
559
  processForInOf: () => processForInOf,
551
560
  processProgram: () => processProgram,
@@ -951,27 +960,49 @@ function assignResults(node, collect) {
951
960
  case "DebuggerStatement":
952
961
  case "EmptyStatement":
953
962
  case "ReturnStatement":
954
- case "ThrowStatement":
963
+ case "ThrowStatement": {
955
964
  return;
956
- case "Declaration":
965
+ }
966
+ case "Declaration": {
967
+ let ref5;
968
+ if (exp.bindings?.length) {
969
+ ref5 = patternAsValue((ref4 = exp.bindings)[ref4.length - 1].pattern);
970
+ } else {
971
+ ref5 = "void 0";
972
+ }
973
+ ;
974
+ const value = ref5;
957
975
  exp.children.push([
958
976
  "",
959
- [";", collect(patternAsValue((ref4 = exp.bindings)[ref4.length - 1].pattern))]
977
+ [";", collect(value)]
960
978
  ]);
961
979
  return;
980
+ }
981
+ case "FunctionExpression": {
982
+ if (exp.id) {
983
+ exp.children.push([
984
+ "",
985
+ [";", collect(exp.id)]
986
+ ]);
987
+ return;
988
+ }
989
+ break;
990
+ }
962
991
  case "ForStatement":
963
992
  case "IterationStatement":
964
993
  case "DoStatement":
965
- case "ComptimeStatement":
994
+ case "ComptimeStatement": {
966
995
  wrapIterationReturningResults(exp, outer, collect);
967
996
  return;
968
- case "BlockStatement":
997
+ }
998
+ case "BlockStatement": {
969
999
  if (node.expressions.some(isExit)) {
970
1000
  return;
971
1001
  }
972
1002
  assignResults(exp.expressions[exp.expressions.length - 1], collect);
973
1003
  return;
974
- case "IfStatement":
1004
+ }
1005
+ case "IfStatement": {
975
1006
  assignResults(exp.then, collect);
976
1007
  if (exp.then.bare && !exp.then.semicolon) {
977
1008
  exp.then.children.push(exp.then.semicolon = ";");
@@ -979,18 +1010,22 @@ function assignResults(node, collect) {
979
1010
  if (exp.else) {
980
1011
  assignResults(exp.else.block, collect);
981
1012
  } else {
982
- exp.children.push([" else {", collect("undefined"), "}"]);
1013
+ exp.children.push([" else {", collect("void 0"), "}"]);
983
1014
  }
984
1015
  return;
985
- case "PatternMatchingStatement":
1016
+ }
1017
+ case "PatternMatchingStatement": {
986
1018
  assignResults(exp.children[0], collect);
987
1019
  return;
988
- case "SwitchStatement":
1020
+ }
1021
+ case "SwitchStatement": {
989
1022
  assignResults(exp.children[2], collect);
990
1023
  return;
991
- case "TryStatement":
1024
+ }
1025
+ case "TryStatement": {
992
1026
  exp.blocks.forEach((block) => assignResults(block, collect));
993
1027
  return;
1028
+ }
994
1029
  }
995
1030
  if (node[node.length - 1]?.type === "SemicolonDelimiter") {
996
1031
  return;
@@ -1001,7 +1036,7 @@ function insertReturn(node, outerNode = node) {
1001
1036
  if (!node)
1002
1037
  return;
1003
1038
  switch (node.type) {
1004
- case "BlockStatement":
1039
+ case "BlockStatement": {
1005
1040
  if (node.expressions.length) {
1006
1041
  if (node.expressions.some(([, exp2]) => isExit(exp2))) {
1007
1042
  return;
@@ -1014,7 +1049,8 @@ function insertReturn(node, outerNode = node) {
1014
1049
  }
1015
1050
  }
1016
1051
  return;
1017
- case "WhenClause":
1052
+ }
1053
+ case "WhenClause": {
1018
1054
  if (node.break) {
1019
1055
  node.children.splice(node.children.indexOf(node.break), 1);
1020
1056
  }
@@ -1024,9 +1060,11 @@ function insertReturn(node, outerNode = node) {
1024
1060
  node.block.expressions.push(wrapWithReturn());
1025
1061
  }
1026
1062
  return;
1027
- case "DefaultClause":
1063
+ }
1064
+ case "DefaultClause": {
1028
1065
  insertReturn(node.block);
1029
1066
  return;
1067
+ }
1030
1068
  }
1031
1069
  if (!Array.isArray(node))
1032
1070
  return;
@@ -1046,23 +1084,36 @@ function insertReturn(node, outerNode = node) {
1046
1084
  exp = exp.statement;
1047
1085
  ({ type } = exp);
1048
1086
  }
1049
- let ref5;
1087
+ let ref6;
1050
1088
  switch (type) {
1051
1089
  case "BreakStatement":
1052
1090
  case "ContinueStatement":
1053
1091
  case "DebuggerStatement":
1054
1092
  case "EmptyStatement":
1055
1093
  case "ReturnStatement":
1056
- case "ThrowStatement":
1094
+ case "ThrowStatement": {
1057
1095
  return;
1058
- case "Declaration":
1096
+ }
1097
+ case "Declaration": {
1098
+ let ref7;
1099
+ if (exp.bindings?.length) {
1100
+ ref7 = [" ", patternAsValue((ref6 = exp.bindings)[ref6.length - 1].pattern)];
1101
+ } else {
1102
+ ref7 = [];
1103
+ }
1104
+ ;
1105
+ const value = ref7;
1059
1106
  exp.children.push(["", {
1060
1107
  type: "ReturnStatement",
1061
- children: [";return ", patternAsValue((ref5 = exp.bindings)[ref5.length - 1].pattern)],
1108
+ children: [
1109
+ ";return",
1110
+ ...value
1111
+ ],
1062
1112
  parent: exp
1063
1113
  }]);
1064
1114
  return;
1065
- case "FunctionExpression":
1115
+ }
1116
+ case "FunctionExpression": {
1066
1117
  if (exp.id) {
1067
1118
  exp.children.push([
1068
1119
  "",
@@ -1075,16 +1126,19 @@ function insertReturn(node, outerNode = node) {
1075
1126
  return;
1076
1127
  }
1077
1128
  break;
1129
+ }
1078
1130
  case "ForStatement":
1079
1131
  case "IterationStatement":
1080
1132
  case "DoStatement":
1081
- case "ComptimeStatement":
1133
+ case "ComptimeStatement": {
1082
1134
  wrapIterationReturningResults(exp, outer);
1083
1135
  return;
1084
- case "BlockStatement":
1136
+ }
1137
+ case "BlockStatement": {
1085
1138
  insertReturn(exp.expressions[exp.expressions.length - 1]);
1086
1139
  return;
1087
- case "IfStatement":
1140
+ }
1141
+ case "IfStatement": {
1088
1142
  insertReturn(exp.then);
1089
1143
  if (exp.else)
1090
1144
  insertReturn(exp.else.block);
@@ -1096,18 +1150,23 @@ function insertReturn(node, outerNode = node) {
1096
1150
  parent: exp
1097
1151
  }]);
1098
1152
  return;
1099
- case "PatternMatchingStatement":
1153
+ }
1154
+ case "PatternMatchingStatement": {
1100
1155
  insertReturn(exp.children[0]);
1101
1156
  return;
1102
- case "SwitchStatement":
1157
+ }
1158
+ case "SwitchStatement": {
1103
1159
  insertSwitchReturns(exp);
1104
1160
  return;
1105
- case "TryStatement":
1161
+ }
1162
+ case "TryStatement": {
1106
1163
  exp.blocks.forEach((block) => insertReturn(block));
1107
1164
  return;
1165
+ }
1108
1166
  }
1109
- if (node[node.length - 1]?.type === "SemicolonDelimiter")
1167
+ if (node[node.length - 1]?.type === "SemicolonDelimiter") {
1110
1168
  return;
1169
+ }
1111
1170
  const returnStatement = wrapWithReturn(node[1]);
1112
1171
  node.splice(1, 1, returnStatement);
1113
1172
  }
@@ -1196,10 +1255,33 @@ function processParams(f) {
1196
1255
  }
1197
1256
  expressions.unshift(...prefix);
1198
1257
  }
1258
+ function processSignature(f) {
1259
+ const { block, signature } = f;
1260
+ if (hasAwait(block) && !f.async?.length) {
1261
+ f.async.push("async ");
1262
+ signature.modifier.async = true;
1263
+ }
1264
+ if (hasYield(block) && !f.generator?.length) {
1265
+ if (f.type === "ArrowFunction") {
1266
+ gatherRecursiveWithinFunction(block, ($) => $.type === "YieldExpression").forEach((y) => {
1267
+ const i = y.children.findIndex(($1) => $1.type === "Yield");
1268
+ return y.children.splice(i + 1, 0, {
1269
+ type: "Error",
1270
+ message: "Can't use yield inside of => arrow function"
1271
+ });
1272
+ });
1273
+ } else {
1274
+ f.generator.push("*");
1275
+ signature.modifier.generator = true;
1276
+ }
1277
+ }
1278
+ }
1199
1279
  function processFunctions(statements, config2) {
1200
1280
  gatherRecursiveAll(statements, ({ type }) => type === "FunctionExpression" || type === "ArrowFunction").forEach((f) => {
1201
- if (f.type === "FunctionExpression")
1281
+ if (f.type === "FunctionExpression") {
1202
1282
  implicitFunctionBlock(f);
1283
+ }
1284
+ processSignature(f);
1203
1285
  processParams(f);
1204
1286
  return processReturn(f, config2.implicitReturns);
1205
1287
  });
@@ -1247,6 +1329,102 @@ function skipImplicitArguments(args) {
1247
1329
  }
1248
1330
  return false;
1249
1331
  }
1332
+ function processCoffeeDo(ws, expression) {
1333
+ ws = insertTrimmingSpace(ws, "");
1334
+ const args = [];
1335
+ if (typeof expression === "object" && expression != null && "type" in expression && expression.type === "ArrowFunction" || typeof expression === "object" && expression != null && "type" in expression && expression.type === "FunctionExpression") {
1336
+ const { parameters } = expression;
1337
+ const newParameters = {
1338
+ ...parameters,
1339
+ children: (() => {
1340
+ const results = [];
1341
+ for (let ref8 = parameters.children, i1 = 0, len3 = ref8.length; i1 < len3; i1++) {
1342
+ let parameter = ref8[i1];
1343
+ if (typeof parameter === "object" && parameter != null && "type" in parameter && parameter.type === "Parameter") {
1344
+ let ref9;
1345
+ if (ref9 = parameter.initializer) {
1346
+ const initializer = ref9;
1347
+ args.push(initializer.expression, parameter.delim);
1348
+ parameter = {
1349
+ ...parameter,
1350
+ initializer: void 0,
1351
+ children: parameter.children.filter((a2) => a2 !== initializer)
1352
+ };
1353
+ } else {
1354
+ args.push(parameter.children.filter(
1355
+ (a3) => a3 !== parameter.typeSuffix
1356
+ ));
1357
+ }
1358
+ }
1359
+ results.push(parameter);
1360
+ }
1361
+ return results;
1362
+ })()
1363
+ };
1364
+ expression = {
1365
+ ...expression,
1366
+ parameters: newParameters,
1367
+ children: expression.children.map(($2) => $2 === parameters ? newParameters : $2)
1368
+ };
1369
+ }
1370
+ return {
1371
+ type: "CallExpression",
1372
+ children: [
1373
+ makeLeftHandSideExpression(expression),
1374
+ {
1375
+ type: "Call",
1376
+ args,
1377
+ children: ["(", args, ")"]
1378
+ }
1379
+ ]
1380
+ };
1381
+ }
1382
+ function makeAmpersandFunction(rhs) {
1383
+ let { ref, typeSuffix, body } = rhs;
1384
+ if (!(ref != null)) {
1385
+ ref = makeRef("$");
1386
+ inplacePrepend(ref, body);
1387
+ }
1388
+ if (body?.type === "ObjectExpression") {
1389
+ body = makeLeftHandSideExpression(body);
1390
+ }
1391
+ const parameters = makeNode({
1392
+ type: "Parameters",
1393
+ children: typeSuffix ? ["(", ref, typeSuffix, ")"] : [ref],
1394
+ names: []
1395
+ });
1396
+ const expressions = [[" ", body]];
1397
+ const block = makeNode({
1398
+ type: "BlockStatement",
1399
+ bare: true,
1400
+ expressions,
1401
+ children: [expressions],
1402
+ implicitlyReturned: true
1403
+ });
1404
+ const async = [];
1405
+ const children = [async, parameters, " =>", block];
1406
+ const fn = makeNode({
1407
+ type: "ArrowFunction",
1408
+ async,
1409
+ signature: {
1410
+ modifier: {
1411
+ async: !!async
1412
+ }
1413
+ },
1414
+ children,
1415
+ ref,
1416
+ block,
1417
+ parameters,
1418
+ ampersandBlock: true,
1419
+ body
1420
+ });
1421
+ if (isStatement(body)) {
1422
+ braceBlock(block);
1423
+ fn.ampersandBlock = false;
1424
+ delete fn.body;
1425
+ }
1426
+ return fn;
1427
+ }
1250
1428
 
1251
1429
  // source/parser/block.civet
1252
1430
  function blockWithPrefix(prefixStatements, block) {
@@ -1407,6 +1585,9 @@ function needsPrecedingSemicolon(exp) {
1407
1585
  }
1408
1586
  return false;
1409
1587
  }
1588
+ if (isToken(exp)) {
1589
+ exp = exp.token;
1590
+ }
1410
1591
  if (typeof exp === "string") {
1411
1592
  return /^\s*[\(\[\`\+\-\/]/.test(exp);
1412
1593
  }
@@ -1467,8 +1648,8 @@ function addParentPointers(node, parent) {
1467
1648
  node.parent = parent;
1468
1649
  }
1469
1650
  if (node.children) {
1470
- for (let ref1 = node.children, i1 = 0, len1 = ref1.length; i1 < len1; i1++) {
1471
- const child = ref1[i1];
1651
+ for (let ref = node.children, i1 = 0, len1 = ref.length; i1 < len1; i1++) {
1652
+ const child = ref[i1];
1472
1653
  addParentPointers(child, node);
1473
1654
  }
1474
1655
  }
@@ -1750,13 +1931,13 @@ function startsWith(target, value) {
1750
1931
  return;
1751
1932
  }
1752
1933
  function hasAwait(exp) {
1753
- return gatherRecursiveWithinFunction(exp, ({ type }) => type === "Await").length > 0;
1934
+ return gatherRecursiveWithinFunction(exp, ($1) => $1.type === "Await").length > 0;
1754
1935
  }
1755
1936
  function hasYield(exp) {
1756
- return gatherRecursiveWithinFunction(exp, ({ type }) => type === "Yield").length > 0;
1937
+ return gatherRecursiveWithinFunction(exp, ($2) => $2.type === "Yield").length > 0;
1757
1938
  }
1758
1939
  function hasImportDeclaration(exp) {
1759
- return gatherRecursiveWithinFunction(exp, ({ type }) => type === "ImportDeclaration").length > 0;
1940
+ return gatherRecursiveWithinFunction(exp, ($3) => $3.type === "ImportDeclaration").length > 0;
1760
1941
  }
1761
1942
  function deepCopy(node) {
1762
1943
  if (node == null)
@@ -1794,72 +1975,29 @@ function removeHoistDecs(node) {
1794
1975
  }
1795
1976
  }
1796
1977
  }
1797
- function makeAmpersandFunction(rhs) {
1798
- let { ref, typeSuffix, body } = rhs;
1799
- if (!(ref != null)) {
1800
- ref = makeRef("$");
1801
- inplacePrepend(ref, body);
1802
- }
1803
- if (body?.type === "ObjectExpression") {
1804
- body = makeLeftHandSideExpression(body);
1805
- }
1806
- const parameters = makeNode({
1807
- type: "Parameters",
1808
- children: typeSuffix ? ["(", ref, typeSuffix, ")"] : [ref],
1809
- names: []
1810
- });
1811
- const expressions = [[" ", body]];
1812
- const block = makeNode({
1813
- type: "BlockStatement",
1814
- bare: true,
1815
- expressions,
1816
- children: [expressions],
1817
- implicitlyReturned: true
1818
- });
1819
- const children = [parameters, " =>", block];
1820
- const async = hasAwait(body);
1821
- if (async) {
1822
- children.unshift("async ");
1823
- }
1824
- const fn = makeNode({
1825
- type: "ArrowFunction",
1826
- signature: {
1827
- modifier: {
1828
- async
1829
- }
1830
- },
1831
- children,
1832
- ref,
1833
- block,
1834
- parameters,
1835
- ampersandBlock: true,
1836
- body
1837
- });
1838
- if (isStatement(body)) {
1839
- braceBlock(block);
1840
- fn.ampersandBlock = false;
1841
- delete fn.body;
1842
- }
1843
- return fn;
1844
- }
1978
+ var skipParens = /* @__PURE__ */ new Set([
1979
+ "AmpersandRef",
1980
+ "CallExpression",
1981
+ "Identifier",
1982
+ "JSXElement",
1983
+ "JSXFragment",
1984
+ "Literal",
1985
+ "MemberExpression",
1986
+ "NewExpression",
1987
+ "ParenthesizedExpression",
1988
+ "Ref",
1989
+ "Placeholder",
1990
+ "StatementExpression"
1991
+ // wrapIIFE
1992
+ ]);
1845
1993
  function makeLeftHandSideExpression(expression) {
1846
- if (expression.parenthesized) {
1847
- return expression;
1848
- }
1849
- switch (expression.type) {
1850
- case "AmpersandRef":
1851
- case "CallExpression":
1852
- case "Identifier":
1853
- case "JSXElement":
1854
- case "JSXFragment":
1855
- case "Literal":
1856
- case "MemberExpression":
1857
- case "NewExpression":
1858
- case "ParenthesizedExpression":
1859
- case "Ref":
1860
- case "Placeholder":
1861
- case "StatementExpression":
1994
+ if (isASTNodeObject(expression)) {
1995
+ if (expression.parenthesized) {
1996
+ return expression;
1997
+ }
1998
+ if (skipParens.has(expression.type)) {
1862
1999
  return expression;
2000
+ }
1863
2001
  }
1864
2002
  return makeNode({
1865
2003
  type: "ParenthesizedExpression",
@@ -1887,8 +2025,8 @@ function updateParentPointers(node, parent, depth = 1) {
1887
2025
  node.parent = parent;
1888
2026
  }
1889
2027
  if (depth && isParent(node)) {
1890
- for (let ref2 = node.children, i3 = 0, len3 = ref2.length; i3 < len3; i3++) {
1891
- const child = ref2[i3];
2028
+ for (let ref1 = node.children, i3 = 0, len3 = ref1.length; i3 < len3; i3++) {
2029
+ const child = ref1[i3];
1892
2030
  updateParentPointers(child, node, depth - 1);
1893
2031
  }
1894
2032
  }
@@ -1959,11 +2097,11 @@ function parenthesizeType(type) {
1959
2097
  }
1960
2098
  function wrapIIFE(expressions, asyncFlag) {
1961
2099
  let prefix;
1962
- let async;
2100
+ const async = [];
1963
2101
  if (asyncFlag) {
1964
- async = "async ";
2102
+ async.push("async ");
1965
2103
  } else if (hasAwait(expressions)) {
1966
- async = "async ";
2104
+ async.push("async ");
1967
2105
  prefix = {
1968
2106
  type: "Await",
1969
2107
  children: ["await "]
@@ -1974,8 +2112,7 @@ function wrapIIFE(expressions, asyncFlag) {
1974
2112
  expressions,
1975
2113
  children: ["{", expressions, "}"],
1976
2114
  bare: false,
1977
- root: false,
1978
- parent: void 0
2115
+ root: false
1979
2116
  });
1980
2117
  const parameters = {
1981
2118
  type: "Parameters",
@@ -1984,7 +2121,7 @@ function wrapIIFE(expressions, asyncFlag) {
1984
2121
  };
1985
2122
  const signature = {
1986
2123
  modifier: {
1987
- async: !!async
2124
+ async: !!async.length
1988
2125
  },
1989
2126
  returnType: void 0
1990
2127
  };
@@ -2327,8 +2464,6 @@ function processBinaryOpExpression($0) {
2327
2464
  }
2328
2465
  return expandedOps;
2329
2466
  }
2330
- ;
2331
- return recurse;
2332
2467
  }
2333
2468
  function dotNumericLiteral(literal) {
2334
2469
  if (literal?.type === "Literal" && /^[+-]?(?:0|[1-9](?:_[0-9]|[0-9])*)$/.test(literal.raw)) {
@@ -2845,7 +2980,13 @@ function getPatternBlockPrefix(pattern, ref, decl = "const ", suffix) {
2845
2980
  thisAssignments = thisAssignments.map(($6) => ["", $6, ";"]);
2846
2981
  const duplicateDeclarations = aggregateDuplicateBindings([patternBindings, splices]);
2847
2982
  return [
2848
- ["", [decl, patternBindings, suffix, " = ", ref, ...splices], ";"],
2983
+ ["", {
2984
+ type: "Declaration",
2985
+ children: [decl, patternBindings, suffix, " = ", ref, ...splices],
2986
+ names: [],
2987
+ bindings: []
2988
+ // avoid implicit return of any bindings
2989
+ }, ";"],
2849
2990
  ...thisAssignments,
2850
2991
  ...duplicateDeclarations.map(($7) => ["", $7, ";"])
2851
2992
  ];
@@ -2993,9 +3134,18 @@ function aggregateDuplicateBindings(bindings) {
2993
3134
  aliasBinding(p, ref);
2994
3135
  return ref;
2995
3136
  });
2996
- return declarations.push(["const ", key, " = [", ...refs.map((r, i) => {
2997
- return i === 0 ? r : [", ", r];
2998
- }), "]"]);
3137
+ return declarations.push({
3138
+ type: "Declaration",
3139
+ children: [
3140
+ "const ",
3141
+ key,
3142
+ " = [",
3143
+ ...refs.map((r, i) => i === 0 ? r : [", ", r]),
3144
+ "]"
3145
+ ],
3146
+ names: [],
3147
+ bindings: []
3148
+ });
2999
3149
  });
3000
3150
  return declarations;
3001
3151
  }
@@ -3232,7 +3382,6 @@ function processDeclarationConditionStatement(s) {
3232
3382
  if (s.negated) {
3233
3383
  let m;
3234
3384
  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")) {
3235
- console.log(condition.expression);
3236
3385
  throw new Error("Unsupported negated condition");
3237
3386
  }
3238
3387
  const { children } = condition.expression.children[1];
@@ -3487,8 +3636,7 @@ function processUnaryExpression(pre, exp, post) {
3487
3636
  token: " != null"
3488
3637
  };
3489
3638
  if (pre.length) {
3490
- let ref;
3491
- const lastPre = (ref = pre)[ref.length - 1];
3639
+ const lastPre = pre[pre.length - 1];
3492
3640
  if (lastPre.token === "!") {
3493
3641
  post.token = " == null";
3494
3642
  pre = pre.slice(0, -1);
@@ -3532,9 +3680,9 @@ function processUnaryExpression(pre, exp, post) {
3532
3680
  }
3533
3681
  }
3534
3682
  }
3535
- let ref1;
3536
- while (ref1 = pre.length) {
3537
- const l = ref1;
3683
+ let ref;
3684
+ while (ref = pre.length) {
3685
+ const l = ref;
3538
3686
  const last = pre[l - 1];
3539
3687
  if (last.type === "Await") {
3540
3688
  if (last.op) {
@@ -4125,49 +4273,69 @@ function stringify(node) {
4125
4273
  return `${node}`;
4126
4274
  }
4127
4275
  }
4128
- function gen(node, options) {
4129
- if (node === null || node === void 0) {
4130
- return "";
4131
- }
4132
- if (typeof node === "string") {
4133
- options?.updateSourceMap?.(node);
4134
- return node;
4135
- }
4136
- if (Array.isArray(node)) {
4137
- return node.map(function(child) {
4138
- return gen(child, options);
4139
- }).join("");
4140
- }
4141
- if (typeof node === "object") {
4142
- if (options.js && node.ts) {
4143
- return "";
4144
- }
4145
- if (!options.js && node.js) {
4276
+ function gen(root, options) {
4277
+ const updateSourceMap = options?.sourceMap?.updateSourceMap;
4278
+ return recurse(root);
4279
+ function recurse(node) {
4280
+ if (!(node != null)) {
4146
4281
  return "";
4147
4282
  }
4148
- if (node.type === "Error") {
4149
- options.errors ??= [];
4150
- options.errors.push(node);
4151
- return "";
4283
+ if (typeof node === "string") {
4284
+ updateSourceMap?.(node);
4285
+ return node;
4152
4286
  }
4153
- if (node.$loc != null) {
4154
- const { token, $loc } = node;
4155
- options?.updateSourceMap?.(token, $loc.pos);
4156
- return token;
4287
+ if (Array.isArray(node)) {
4288
+ return node.map(recurse).join("");
4157
4289
  }
4158
- if (!node.children) {
4159
- switch (node.type) {
4160
- case "Ref": {
4161
- throw new Error(`Unpopulated ref ${stringify(node)}`);
4290
+ if (typeof node === "object") {
4291
+ if (options.js && node.ts) {
4292
+ return "";
4293
+ }
4294
+ if (!options.js && node.js) {
4295
+ return "";
4296
+ }
4297
+ if (node.type === "Error") {
4298
+ const filename2 = options?.filename ?? "unknown";
4299
+ let line = "?";
4300
+ let column = "?";
4301
+ let offset;
4302
+ if (options && typeof options === "object" && "sourceMap" in options) {
4303
+ const { sourceMap } = options;
4304
+ line = sourceMap.data.srcLine + 1;
4305
+ column = sourceMap.data.srcColumn + 1;
4306
+ offset = sourceMap.data.srcOffset;
4162
4307
  }
4308
+ options.errors ??= [];
4309
+ options.errors.push(new import_lib3.ParseError(
4310
+ node.message,
4311
+ void 0,
4312
+ // body
4313
+ filename2,
4314
+ line,
4315
+ column,
4316
+ offset
4317
+ ));
4318
+ return "";
4319
+ }
4320
+ if (node.$loc != null) {
4321
+ const { token, $loc } = node;
4322
+ updateSourceMap?.(token, $loc.pos);
4323
+ return token;
4163
4324
  }
4164
- debugger;
4165
- throw new Error(`Unknown node ${stringify(node)}`);
4325
+ if (!node.children) {
4326
+ switch (node.type) {
4327
+ case "Ref": {
4328
+ throw new Error(`Unpopulated ref ${stringify(node)}`);
4329
+ }
4330
+ }
4331
+ debugger;
4332
+ throw new Error(`Unknown node ${stringify(node)}`);
4333
+ }
4334
+ return recurse(node.children);
4166
4335
  }
4167
- return gen(node.children, options);
4336
+ debugger;
4337
+ throw new Error(`Unknown node ${stringify(node)}`);
4168
4338
  }
4169
- debugger;
4170
- throw new Error(`Unknown node ${stringify(node)}`);
4171
4339
  }
4172
4340
  var generate_default = gen;
4173
4341
  function prune(node) {
@@ -4743,8 +4911,11 @@ function expressionizeBlock(blockOrExpression) {
4743
4911
  }
4744
4912
  if (results.length > 1) {
4745
4913
  return makeLeftHandSideExpression(results);
4914
+ } else if (results.length) {
4915
+ return results;
4916
+ } else {
4917
+ return ["void 0"];
4746
4918
  }
4747
- return results;
4748
4919
  } else {
4749
4920
  return blockOrExpression;
4750
4921
  }
@@ -4771,10 +4942,10 @@ function expressionizeIfStatement(statement) {
4771
4942
  children.push(":void 0");
4772
4943
  }
4773
4944
  children.push(closeParen);
4774
- return {
4945
+ return makeNode({
4775
4946
  type: "IfExpression",
4776
4947
  children
4777
- };
4948
+ });
4778
4949
  }
4779
4950
  function expressionizeTypeIf([ws, ifOp, condition, t, e]) {
4780
4951
  const children = [
@@ -5271,7 +5442,8 @@ function processAssignments(statements) {
5271
5442
  while (expr.type === "ParenthesizedExpression") {
5272
5443
  expr = expr.expression;
5273
5444
  }
5274
- if (expr.type === "AssignmentExpression" || expr.type === "UpdateExpression") {
5445
+ let m;
5446
+ if (m = expr.type, m === "AssignmentExpression" || m === "UpdateExpression") {
5275
5447
  if (expr.type === "UpdateExpression" && expr.children[0] === expr.assigned) {
5276
5448
  pre.push("(");
5277
5449
  post.push([", ", lhs, ")"]);
@@ -5285,26 +5457,31 @@ function processAssignments(statements) {
5285
5457
  return;
5286
5458
  }
5287
5459
  const pre = [], post = [];
5460
+ let ref4;
5288
5461
  switch (exp.type) {
5289
- case "AssignmentExpression":
5462
+ case "AssignmentExpression": {
5290
5463
  if (!exp.lhs)
5291
5464
  return;
5292
5465
  exp.lhs.forEach((lhsPart, i) => {
5293
- let newLhs2 = extractAssignment(lhsPart[1]);
5294
- if (newLhs2) {
5295
- return lhsPart[1] = newLhs2;
5466
+ let ref5;
5467
+ if (ref5 = extractAssignment(lhsPart[1])) {
5468
+ const newLhs = ref5;
5469
+ return lhsPart[1] = newLhs;
5296
5470
  }
5297
5471
  ;
5298
5472
  return;
5299
5473
  });
5300
5474
  break;
5301
- case "UpdateExpression":
5302
- let newLhs = extractAssignment(exp.assigned);
5303
- if (newLhs) {
5475
+ }
5476
+ case "UpdateExpression": {
5477
+ if (ref4 = extractAssignment(exp.assigned)) {
5478
+ const newLhs = ref4;
5304
5479
  const i = exp.children.indexOf(exp.assigned);
5305
5480
  exp.assigned = exp.children[i] = newLhs;
5306
5481
  }
5482
+ ;
5307
5483
  break;
5484
+ }
5308
5485
  }
5309
5486
  if (pre.length)
5310
5487
  exp.children.unshift(...pre);
@@ -5314,13 +5491,7 @@ function processAssignments(statements) {
5314
5491
  const { assigned } = exp;
5315
5492
  const ref = makeRef();
5316
5493
  const newMemberExp = unchainOptionalMemberExpression(assigned, ref, (children) => {
5317
- return exp.children.map((c) => {
5318
- if (c === assigned) {
5319
- return children;
5320
- } else {
5321
- return c;
5322
- }
5323
- });
5494
+ return exp.children.map(($) => $ === assigned ? children : $);
5324
5495
  });
5325
5496
  if (newMemberExp !== assigned) {
5326
5497
  if (newMemberExp.usesRef) {
@@ -5342,38 +5513,34 @@ function processAssignments(statements) {
5342
5513
  statements,
5343
5514
  (n) => n.type === "AssignmentExpression" && n.names === null,
5344
5515
  (exp) => {
5345
- let { lhs: $1, expression: $2 } = exp, tail = [], i = 0, len3 = $1.length;
5516
+ let { lhs: $1, expression: $2 } = exp, tail = [], len3 = $1.length;
5346
5517
  let block;
5347
- let ref4;
5348
- if (exp.parent?.type === "BlockStatement" && !(ref4 = $1[$1.length - 1])?.[ref4.length - 1]?.special) {
5518
+ let ref6;
5519
+ if (exp.parent?.type === "BlockStatement" && !(ref6 = $1[$1.length - 1])?.[ref6.length - 1]?.special) {
5349
5520
  block = makeBlockFragment();
5350
- let ref5;
5351
- if (ref5 = prependStatementExpressionBlock(
5521
+ let ref7;
5522
+ if (ref7 = prependStatementExpressionBlock(
5352
5523
  { type: "Initializer", expression: $2, children: [void 0, void 0, $2] },
5353
5524
  block
5354
5525
  )) {
5355
- const ref = ref5;
5356
- exp.children = exp.children.map(function(c) {
5357
- if (c === $2)
5358
- return ref;
5359
- else
5360
- return c;
5361
- });
5526
+ const ref = ref7;
5527
+ exp.children = exp.children.map(($3) => $3 === $2 ? ref : $3);
5362
5528
  $2 = ref;
5363
5529
  } else {
5364
5530
  block = void 0;
5365
5531
  }
5366
5532
  }
5367
- if ($1.some((left) => left[left.length - 1].special)) {
5533
+ let ref8;
5534
+ if ($1.some(($4) => (ref8 = $4)[ref8.length - 1].special)) {
5368
5535
  if ($1.length !== 1)
5369
5536
  throw new Error("Only one assignment with id= is allowed");
5370
5537
  const [, lhs, , op] = $1[0];
5371
5538
  const { call, omitLhs } = op;
5372
- const index2 = exp.children.indexOf($2);
5373
- if (index2 < 0)
5539
+ const index = exp.children.indexOf($2);
5540
+ if (index < 0)
5374
5541
  throw new Error("Assertion error: exp not in AssignmentExpression");
5375
5542
  exp.children.splice(
5376
- index2,
5543
+ index,
5377
5544
  1,
5378
5545
  exp.expression = $2 = [call, "(", lhs, ", ", $2, ")"]
5379
5546
  );
@@ -5382,12 +5549,15 @@ function processAssignments(statements) {
5382
5549
  }
5383
5550
  }
5384
5551
  let wrapped = false;
5552
+ let i = 0;
5385
5553
  while (i < len3) {
5386
5554
  const lastAssignment = $1[i++];
5387
5555
  const [, lhs, , op] = lastAssignment;
5388
- if (op.token !== "=")
5556
+ if (!(op.token === "=")) {
5389
5557
  continue;
5390
- if (lhs.type === "ObjectExpression" || lhs.type === "ObjectBindingPattern") {
5558
+ }
5559
+ let m1;
5560
+ if (m1 = lhs.type, m1 === "ObjectExpression" || m1 === "ObjectBindingPattern") {
5391
5561
  if (!wrapped) {
5392
5562
  wrapped = true;
5393
5563
  lhs.children.splice(0, 0, "(");
@@ -5400,6 +5570,7 @@ function processAssignments(statements) {
5400
5570
  const lastAssignment = $1[i];
5401
5571
  if (lastAssignment[3].token === "=") {
5402
5572
  const lhs = lastAssignment[1];
5573
+ let m2;
5403
5574
  if (lhs.type === "MemberExpression") {
5404
5575
  const members = lhs.children;
5405
5576
  const lastMember = members[members.length - 1];
@@ -5423,9 +5594,9 @@ function processAssignments(statements) {
5423
5594
  }
5424
5595
  exp.children = [$1];
5425
5596
  exp.names = [];
5426
- return exp;
5597
+ break;
5427
5598
  }
5428
- } else if (lhs.type === "ObjectBindingPattern" || lhs.type === "ArrayBindingPattern") {
5599
+ } else if (m2 = lhs.type, m2 === "ObjectBindingPattern" || m2 === "ArrayBindingPattern") {
5429
5600
  processBindingPatternLHS(lhs, tail);
5430
5601
  }
5431
5602
  }
@@ -5458,10 +5629,12 @@ function processAssignments(statements) {
5458
5629
  i--;
5459
5630
  }
5460
5631
  exp.names = $1.flatMap(([, l]) => l.names || []);
5461
- const index = exp.children.indexOf($2);
5462
- if (index < 0)
5463
- throw new Error("Assertion error: exp not in AssignmentExpression");
5464
- exp.children.splice(index + 1, 0, ...tail);
5632
+ if (tail.length) {
5633
+ const index = exp.children.indexOf($2);
5634
+ if (index < 0)
5635
+ throw new Error("Assertion error: exp not in AssignmentExpression");
5636
+ exp.children.splice(index + 1, 0, ...tail);
5637
+ }
5465
5638
  if (block) {
5466
5639
  block.parent = exp.parent;
5467
5640
  block.expressions.push(["", exp]);
@@ -5520,9 +5693,9 @@ function unchainOptionalMemberExpression(exp, ref, innerExp) {
5520
5693
  }
5521
5694
  j++;
5522
5695
  }
5523
- let ref6;
5524
- if (ref6 = conditions.length) {
5525
- const l = ref6;
5696
+ let ref9;
5697
+ if (ref9 = conditions.length) {
5698
+ const l = ref9;
5526
5699
  const cs = flatJoin(conditions, " && ");
5527
5700
  return {
5528
5701
  ...exp,
@@ -5559,8 +5732,8 @@ function processTypes(node) {
5559
5732
  return gatherRecursiveAll(node, (n) => n.type === "UnaryType").forEach((unary) => {
5560
5733
  let last;
5561
5734
  let count = 0;
5562
- let ref7;
5563
- while (unary.suffix.length && (ref7 = unary.suffix)[ref7.length - 1]?.token === "?") {
5735
+ let ref10;
5736
+ while (unary.suffix.length && (ref10 = unary.suffix)[ref10.length - 1]?.token === "?") {
5564
5737
  last = unary.suffix.pop();
5565
5738
  count++;
5566
5739
  }
@@ -5591,14 +5764,14 @@ function processTypes(node) {
5591
5764
  });
5592
5765
  }
5593
5766
  function processStatementExpressions(statements) {
5594
- gatherRecursiveAll(statements, ($) => $.type === "StatementExpression").forEach((_exp) => {
5767
+ gatherRecursiveAll(statements, ($5) => $5.type === "StatementExpression").forEach((_exp) => {
5595
5768
  const exp = _exp;
5596
5769
  const { statement } = exp;
5597
- let ref8;
5770
+ let ref11;
5598
5771
  switch (statement.type) {
5599
5772
  case "IfStatement": {
5600
- if (ref8 = expressionizeIfStatement(statement)) {
5601
- const expression = ref8;
5773
+ if (ref11 = expressionizeIfStatement(statement)) {
5774
+ const expression = ref11;
5602
5775
  return replaceNode(statement, expression, exp);
5603
5776
  } else {
5604
5777
  return replaceNode(statement, wrapIIFE([["", statement]]), exp);
@@ -5640,7 +5813,7 @@ function processNegativeIndexAccess(statements) {
5640
5813
  }
5641
5814
  } else if (index > start + 1) {
5642
5815
  ref = makeRef();
5643
- subexp = children.splice(start, index);
5816
+ subexp = children.splice(start, index - start);
5644
5817
  } else {
5645
5818
  throw new Error("Invalid parse tree for negative index access");
5646
5819
  }
@@ -5649,7 +5822,7 @@ function processNegativeIndexAccess(statements) {
5649
5822
  exp.hoistDec = hoistDec;
5650
5823
  children.splice(start, 0, makeLeftHandSideExpression(refAssignment));
5651
5824
  }
5652
- return exp.len.children = [
5825
+ exp.len.children = [
5653
5826
  ref,
5654
5827
  ".length"
5655
5828
  ];
@@ -5721,11 +5894,11 @@ function populateRefs(statements) {
5721
5894
  function processPlaceholders(statements) {
5722
5895
  const placeholderMap = /* @__PURE__ */ new Map();
5723
5896
  const liftedIfs = /* @__PURE__ */ new Set();
5724
- gatherRecursiveAll(statements, ($3) => $3.type === "Placeholder").forEach((_exp) => {
5897
+ gatherRecursiveAll(statements, ($6) => $6.type === "Placeholder").forEach((_exp) => {
5725
5898
  const exp = _exp;
5726
5899
  let ancestor;
5727
5900
  if (exp.subtype === ".") {
5728
- ({ ancestor } = findAncestor(exp, ($4) => $4.type === "Call"));
5901
+ ({ ancestor } = findAncestor(exp, ($7) => $7.type === "Call"));
5729
5902
  ancestor = ancestor?.parent;
5730
5903
  while (ancestor?.parent?.type === "UnaryExpression" || ancestor?.parent?.type === "NewExpression") {
5731
5904
  ancestor = ancestor.parent;
@@ -5744,10 +5917,10 @@ function processPlaceholders(statements) {
5744
5917
  if (type === "IfStatement") {
5745
5918
  liftedIfs.add(ancestor2);
5746
5919
  }
5747
- let m;
5748
- let m1;
5920
+ let m3;
5921
+ let m4;
5749
5922
  return type === "Call" || // Block, except for if/else blocks when condition already lifted
5750
- 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
5923
+ 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
5751
5924
  type === "Initializer" || // Right-hand side of assignment
5752
5925
  type === "AssignmentExpression" && findChildIndex(ancestor2, child2) === ancestor2.children.indexOf(ancestor2.expression) || type === "ReturnStatement" || type === "YieldExpression";
5753
5926
  }));
@@ -5826,8 +5999,8 @@ function processPlaceholders(statements) {
5826
5999
  for (let i4 = 0, len3 = placeholders.length; i4 < len3; i4++) {
5827
6000
  const placeholder = placeholders[i4];
5828
6001
  typeSuffix ??= placeholder.typeSuffix;
5829
- let ref9;
5830
- replaceNode((ref9 = placeholder.children)[ref9.length - 1], ref);
6002
+ let ref12;
6003
+ replaceNode((ref12 = placeholder.children)[ref12.length - 1], ref);
5831
6004
  }
5832
6005
  const { parent } = ancestor;
5833
6006
  const body = maybeUnwrap(ancestor);
@@ -5858,9 +6031,9 @@ function processPlaceholders(statements) {
5858
6031
  fnExp = makeLeftHandSideExpression(fnExp);
5859
6032
  }
5860
6033
  replaceNode(ancestor, fnExp, parent);
5861
- let ref10;
5862
- if (ref10 = getTrimmingSpace(body)) {
5863
- const ws = ref10;
6034
+ let ref13;
6035
+ if (ref13 = getTrimmingSpace(body)) {
6036
+ const ws = ref13;
5864
6037
  inplaceInsertTrimmingSpace(body, "");
5865
6038
  inplacePrepend(ws, fnExp);
5866
6039
  }
@@ -5885,43 +6058,39 @@ function reorderBindingRestProperty(props) {
5885
6058
  children: props,
5886
6059
  names
5887
6060
  };
5888
- } else if (restCount === 1) {
5889
- let after = props.slice(restIndex + 1);
5890
- let rest = props[restIndex];
5891
- props = props.slice(0, restIndex);
5892
- if (after.length) {
5893
- const { delim: restDelim } = rest, lastAfterProp = after[after.length - 1], { delim: lastDelim, children: lastAfterChildren } = lastAfterProp;
5894
- rest = {
5895
- ...rest,
5896
- delim: lastDelim,
5897
- children: [...rest.children.slice(0, -1), lastDelim]
5898
- };
5899
- after = [
5900
- ...after.slice(0, -1),
5901
- {
5902
- ...lastAfterProp,
5903
- delim: restDelim,
5904
- children: [...lastAfterChildren.slice(0, -1), restDelim]
5905
- }
5906
- ];
5907
- }
5908
- let ref11;
5909
- if (Array.isArray(rest.delim) && (ref11 = rest.delim)[ref11.length - 1]?.token === ",") {
5910
- rest.delim = rest.delim.slice(0, -1);
5911
- rest.children = [...rest.children.slice(0, -1), rest.delim];
5912
- }
5913
- const children = [...props, ...after, rest];
5914
- return {
5915
- children,
5916
- names
6061
+ }
6062
+ let after = props.slice(restIndex + 1);
6063
+ let rest = props[restIndex];
6064
+ props = props.slice(0, restIndex);
6065
+ if (after.length) {
6066
+ const { delim: restDelim } = rest, lastAfterProp = after[after.length - 1], { delim: lastDelim, children: lastAfterChildren } = lastAfterProp;
6067
+ rest = {
6068
+ ...rest,
6069
+ delim: lastDelim,
6070
+ children: [...rest.children.slice(0, -1), lastDelim]
5917
6071
  };
6072
+ after = [
6073
+ ...after.slice(0, -1),
6074
+ {
6075
+ ...lastAfterProp,
6076
+ delim: restDelim,
6077
+ children: [...lastAfterChildren.slice(0, -1), restDelim]
6078
+ }
6079
+ ];
5918
6080
  }
5919
- return {
5920
- children: [{
6081
+ let ref14;
6082
+ if (Array.isArray(rest.delim) && (ref14 = rest.delim)[ref14.length - 1]?.token === ",") {
6083
+ rest.delim = rest.delim.slice(0, -1);
6084
+ rest.children = [...rest.children.slice(0, -1), rest.delim];
6085
+ }
6086
+ const children = [...props, ...after, rest];
6087
+ if (restCount > 1) {
6088
+ children.push({
5921
6089
  type: "Error",
5922
6090
  message: "Multiple rest properties in object pattern"
5923
- }, props]
5924
- };
6091
+ });
6092
+ }
6093
+ return { children, names };
5925
6094
  }
5926
6095
  function replaceNodes(root, predicate, replacer) {
5927
6096
  if (!(root != null)) {
@@ -6104,6 +6273,7 @@ var grammar = {
6104
6273
  YieldExpression,
6105
6274
  ArrowFunction,
6106
6275
  FatArrow,
6276
+ FatArrowToken,
6107
6277
  TrailingDeclaration,
6108
6278
  TrailingPipe,
6109
6279
  FatArrowBody,
@@ -6224,9 +6394,11 @@ var grammar = {
6224
6394
  NoCommaBracedOrEmptyBlock,
6225
6395
  NoPostfixBracedOrEmptyBlock,
6226
6396
  EmptyBlock,
6397
+ BlockOrEmptyStatement,
6227
6398
  BlockOrEmpty,
6228
- EmptyBareBlock,
6229
6399
  EmptyStatementBareBlock,
6400
+ EmptyBareBlock,
6401
+ NoBlock,
6230
6402
  BracedBlock,
6231
6403
  NoPostfixBracedBlock,
6232
6404
  NoCommaBracedBlock,
@@ -7245,13 +7417,14 @@ function ExpressionizedStatement(ctx, state2) {
7245
7417
  }
7246
7418
  var StatementExpression$0 = DebuggerStatement;
7247
7419
  var StatementExpression$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(IfStatement), function($skip, $loc, $0, $1) {
7248
- if (!$1.else && isEmptyBareBlock($1.then))
7420
+ if (!$1.else && $1.then.implicit)
7249
7421
  return $skip;
7250
7422
  return $1;
7251
7423
  });
7252
7424
  var StatementExpression$2 = (0, import_lib3.$TS)((0, import_lib3.$S)(IterationExpression), function($skip, $loc, $0, $1) {
7253
- if (isEmptyBareBlock($1.block))
7425
+ if ($1.block.implicit && $1.subtype !== "DoStatement" && $1.subtype !== "ComptimeStatement") {
7254
7426
  return $skip;
7427
+ }
7255
7428
  return $1;
7256
7429
  });
7257
7430
  var StatementExpression$3 = SwitchStatement;
@@ -7342,7 +7515,7 @@ var ForbiddenImplicitCalls$6 = (0, import_lib3.$TS)((0, import_lib3.$S)(OmittedN
7342
7515
  return $0;
7343
7516
  return $skip;
7344
7517
  });
7345
- var ForbiddenImplicitCalls$7 = (0, import_lib3.$S)(PostfixStatement, EmptyStatementBareBlock);
7518
+ var ForbiddenImplicitCalls$7 = (0, import_lib3.$S)(PostfixStatement, NoBlock);
7346
7519
  var ForbiddenImplicitCalls$8 = (0, import_lib3.$EXPECT)($L5, 'ForbiddenImplicitCalls "... "');
7347
7520
  var ForbiddenImplicitCalls$$ = [ForbiddenImplicitCalls$0, ForbiddenImplicitCalls$1, ForbiddenImplicitCalls$2, ForbiddenImplicitCalls$3, ForbiddenImplicitCalls$4, ForbiddenImplicitCalls$5, ForbiddenImplicitCalls$6, ForbiddenImplicitCalls$7, ForbiddenImplicitCalls$8];
7348
7521
  function ForbiddenImplicitCalls(ctx, state2) {
@@ -7567,11 +7740,10 @@ var UnaryExpression$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3
7567
7740
  var post = $3;
7568
7741
  return processUnaryExpression(pre, exp, post);
7569
7742
  });
7570
- 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) {
7743
+ 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) {
7571
7744
  var ws = $3;
7572
7745
  var exp = $4;
7573
- ws = insertTrimmingSpace(ws, "");
7574
- return ["(", ...ws, exp, ")()"];
7746
+ return processCoffeeDo(ws, exp);
7575
7747
  });
7576
7748
  var UnaryExpression$$ = [UnaryExpression$0, UnaryExpression$1];
7577
7749
  function UnaryExpression(ctx, state2) {
@@ -7793,17 +7965,10 @@ var ArrowFunction$1 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$
7793
7965
  var async = $1;
7794
7966
  var parameters = $2;
7795
7967
  var suffix = $3;
7968
+ var arrow = $4;
7796
7969
  var expOrBlock = $5;
7797
- if (hasAwait(expOrBlock) && !async) {
7798
- async = "async ";
7799
- }
7800
- let error;
7801
- if (hasYield(expOrBlock)) {
7802
- error = {
7803
- type: "Error",
7804
- message: "Can't use yield inside of => arrow function"
7805
- };
7806
- }
7970
+ if (!async)
7971
+ async = [];
7807
7972
  return {
7808
7973
  type: "ArrowFunction",
7809
7974
  signature: {
@@ -7814,25 +7979,31 @@ var ArrowFunction$1 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$
7814
7979
  },
7815
7980
  parameters,
7816
7981
  returnType: suffix,
7817
- ts: false,
7818
7982
  async,
7819
7983
  block: expOrBlock,
7820
- children: [async, $0.slice(1), error]
7984
+ children: [async, parameters, suffix, arrow, expOrBlock]
7821
7985
  };
7822
7986
  });
7823
7987
  var ArrowFunction$$ = [ArrowFunction$0, ArrowFunction$1];
7824
7988
  function ArrowFunction(ctx, state2) {
7825
7989
  return (0, import_lib3.$EVENT_C)(ctx, state2, "ArrowFunction", ArrowFunction$$);
7826
7990
  }
7827
- 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) {
7991
+ var FatArrow$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$E)(_), FatArrowToken), function($skip, $loc, $0, $1, $2) {
7828
7992
  var ws = $1;
7993
+ var arrow = $2;
7829
7994
  if (!ws)
7830
- return " =>";
7831
- return [$1, "=>"];
7995
+ ws = " ";
7996
+ return [ws, arrow];
7832
7997
  });
7833
7998
  function FatArrow(ctx, state2) {
7834
7999
  return (0, import_lib3.$EVENT)(ctx, state2, "FatArrow", FatArrow$0);
7835
8000
  }
8001
+ 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) {
8002
+ return { $loc, token: "=>" };
8003
+ });
8004
+ function FatArrowToken(ctx, state2) {
8005
+ return (0, import_lib3.$EVENT)(ctx, state2, "FatArrowToken", FatArrowToken$0);
8006
+ }
7836
8007
  var TrailingDeclaration$0 = (0, import_lib3.$S)((0, import_lib3.$E)(_), (0, import_lib3.$C)(ConstAssignment, LetAssignment));
7837
8008
  function TrailingDeclaration(ctx, state2) {
7838
8009
  return (0, import_lib3.$EVENT)(ctx, state2, "TrailingDeclaration", TrailingDeclaration$0);
@@ -8344,7 +8515,13 @@ var ThisLiteral$2 = (0, import_lib3.$TS)((0, import_lib3.$S)(AtThis, (0, import_
8344
8515
  children: [at, {
8345
8516
  type: "PropertyAccess",
8346
8517
  name: id,
8347
- children: [".", id]
8518
+ children: [".", {
8519
+ $loc: {
8520
+ pos: $loc.pos + 1,
8521
+ length: $loc.length - 1
8522
+ },
8523
+ token: id
8524
+ }]
8348
8525
  }],
8349
8526
  thisShorthand: true
8350
8527
  };
@@ -9016,11 +9193,17 @@ function FunctionRestParameter(ctx, state2) {
9016
9193
  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) {
9017
9194
  var accessModifier = $2;
9018
9195
  var binding = $4;
9196
+ var typeSuffix = $5;
9197
+ var initializer = $6;
9198
+ var delim = $7;
9019
9199
  return {
9020
9200
  type: "Parameter",
9021
9201
  children: $0,
9022
9202
  names: binding.names,
9023
- accessModifier
9203
+ typeSuffix,
9204
+ accessModifier,
9205
+ initializer,
9206
+ delim
9024
9207
  };
9025
9208
  });
9026
9209
  function ParameterElement(ctx, state2) {
@@ -9435,7 +9618,6 @@ var FunctionSignature$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_li
9435
9618
  name: id?.name,
9436
9619
  parameters,
9437
9620
  returnType: suffix,
9438
- ts: false,
9439
9621
  async,
9440
9622
  generator,
9441
9623
  modifier: {
@@ -9461,14 +9643,6 @@ var FunctionExpression$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(FunctionSign
9461
9643
  ts: true
9462
9644
  };
9463
9645
  }
9464
- if (hasAwait(block) && !signature.async.length) {
9465
- signature.async.push("async ");
9466
- signature.modifier.async = true;
9467
- }
9468
- if (hasYield(block) && !signature.generator.length) {
9469
- signature.generator.push("*");
9470
- signature.modifier.generator = true;
9471
- }
9472
9646
  return {
9473
9647
  ...signature,
9474
9648
  type: "FunctionExpression",
@@ -9640,15 +9814,21 @@ var OperatorDeclaration$$ = [OperatorDeclaration$0, OperatorDeclaration$1, Opera
9640
9814
  function OperatorDeclaration(ctx, state2) {
9641
9815
  return (0, import_lib3.$EVENT_C)(ctx, state2, "OperatorDeclaration", OperatorDeclaration$$);
9642
9816
  }
9643
- var OperatorSignature$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Operator, (0, import_lib3.$E)((0, import_lib3.$S)(_, Function2)), _, Identifier, (0, import_lib3.$E)(OperatorBehavior), (0, import_lib3.$E)(_), NonEmptyParameters, (0, import_lib3.$E)(ReturnTypeSuffix)), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8) {
9644
- var op = $1;
9645
- var func = $2;
9646
- var w1 = $3;
9647
- var id = $4;
9648
- var behavior = $5;
9649
- var w2 = $6;
9650
- var parameters = $7;
9651
- var suffix = $8;
9817
+ var OperatorSignature$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$E)((0, import_lib3.$S)(Async, _)), Operator, (0, import_lib3.$E)((0, import_lib3.$S)(_, Function2)), (0, import_lib3.$E)((0, import_lib3.$S)((0, import_lib3.$E)(_), Star)), _, Identifier, (0, import_lib3.$E)(OperatorBehavior), (0, import_lib3.$E)(_), NonEmptyParameters, (0, import_lib3.$E)(ReturnTypeSuffix)), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10) {
9818
+ var async = $1;
9819
+ var op = $2;
9820
+ var func = $3;
9821
+ var generator = $4;
9822
+ var w1 = $5;
9823
+ var id = $6;
9824
+ var behavior = $7;
9825
+ var w2 = $8;
9826
+ var parameters = $9;
9827
+ var suffix = $10;
9828
+ if (!async)
9829
+ async = [];
9830
+ if (!generator)
9831
+ generator = [];
9652
9832
  if (!func) {
9653
9833
  func = { $loc: op.$loc, token: "function" };
9654
9834
  } else {
@@ -9657,12 +9837,17 @@ var OperatorSignature$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Operator, (0,
9657
9837
  return {
9658
9838
  type: "FunctionSignature",
9659
9839
  id,
9660
- modifier: {},
9840
+ name: id.name,
9661
9841
  parameters,
9662
9842
  returnType: suffix,
9663
- ts: false,
9843
+ async,
9844
+ generator,
9845
+ modifier: {
9846
+ async: !!async.length,
9847
+ generator: !!generator.length
9848
+ },
9664
9849
  block: null,
9665
- children: [func, w1, id, w2, parameters, suffix],
9850
+ children: [async, func, generator, w1, id, w2, parameters, suffix],
9666
9851
  behavior
9667
9852
  };
9668
9853
  });
@@ -9712,27 +9897,24 @@ var ThinArrowFunction$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_li
9712
9897
  var suffix = $3;
9713
9898
  var arrow = $5;
9714
9899
  var block = $6;
9715
- if (hasAwait(block) && !async) {
9716
- async = "async ";
9717
- }
9718
- let generator;
9719
- if (hasYield(block)) {
9720
- generator = "*";
9721
- }
9900
+ if (!async)
9901
+ async = [];
9902
+ const generator = [];
9722
9903
  return {
9723
9904
  type: "FunctionExpression",
9724
9905
  id: void 0,
9725
9906
  parameters,
9726
9907
  returnType: suffix,
9727
- ts: false,
9728
9908
  async,
9729
9909
  generator,
9730
9910
  block,
9731
9911
  signature: {
9732
9912
  name: void 0,
9913
+ async,
9914
+ generator,
9733
9915
  modifier: {
9734
- async: !!async,
9735
- generator: !!generator
9916
+ async: !!async.length,
9917
+ generator: !!generator.length
9736
9918
  },
9737
9919
  returnType: suffix
9738
9920
  },
@@ -9882,43 +10064,62 @@ var EmptyBlock$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(InsertOpenBrace, Ins
9882
10064
  expressions,
9883
10065
  children: [$1, expressions, $2],
9884
10066
  bare: false,
9885
- empty: true
10067
+ empty: true,
10068
+ implicit: true
9886
10069
  };
9887
10070
  });
9888
10071
  function EmptyBlock(ctx, state2) {
9889
10072
  return (0, import_lib3.$EVENT)(ctx, state2, "EmptyBlock", EmptyBlock$0);
9890
10073
  }
10074
+ var BlockOrEmptyStatement$0 = Block;
10075
+ var BlockOrEmptyStatement$1 = (0, import_lib3.$T)((0, import_lib3.$S)(NoBlock, EmptyStatementBareBlock), function(value) {
10076
+ return value[1];
10077
+ });
10078
+ var BlockOrEmptyStatement$$ = [BlockOrEmptyStatement$0, BlockOrEmptyStatement$1];
10079
+ function BlockOrEmptyStatement(ctx, state2) {
10080
+ return (0, import_lib3.$EVENT_C)(ctx, state2, "BlockOrEmptyStatement", BlockOrEmptyStatement$$);
10081
+ }
9891
10082
  var BlockOrEmpty$0 = Block;
9892
- var BlockOrEmpty$1 = EmptyStatementBareBlock;
10083
+ var BlockOrEmpty$1 = (0, import_lib3.$T)((0, import_lib3.$S)(NoBlock, EmptyBlock), function(value) {
10084
+ return value[1];
10085
+ });
9893
10086
  var BlockOrEmpty$$ = [BlockOrEmpty$0, BlockOrEmpty$1];
9894
10087
  function BlockOrEmpty(ctx, state2) {
9895
10088
  return (0, import_lib3.$EVENT_C)(ctx, state2, "BlockOrEmpty", BlockOrEmpty$$);
9896
10089
  }
9897
- var EmptyBareBlock$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L0, 'EmptyBareBlock ""'), function($skip, $loc, $0, $1) {
9898
- const expressions = [];
10090
+ var EmptyStatementBareBlock$0 = (0, import_lib3.$TV)(InsertEmptyStatement, function($skip, $loc, $0, $1) {
10091
+ var s = $0;
10092
+ const expressions = [["", s]];
9899
10093
  return {
9900
10094
  type: "BlockStatement",
9901
10095
  expressions,
9902
10096
  children: [expressions],
9903
- bare: true
10097
+ bare: true,
10098
+ empty: true,
10099
+ implicit: true,
10100
+ semicolon: s.children[0]
9904
10101
  };
9905
10102
  });
9906
- function EmptyBareBlock(ctx, state2) {
9907
- return (0, import_lib3.$EVENT)(ctx, state2, "EmptyBareBlock", EmptyBareBlock$0);
10103
+ function EmptyStatementBareBlock(ctx, state2) {
10104
+ return (0, import_lib3.$EVENT)(ctx, state2, "EmptyStatementBareBlock", EmptyStatementBareBlock$0);
9908
10105
  }
9909
- 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) {
9910
- var s = $3;
9911
- const expressions = [["", s]];
10106
+ var EmptyBareBlock$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L0, 'EmptyBareBlock ""'), function($skip, $loc, $0, $1) {
10107
+ const expressions = [];
9912
10108
  return {
9913
10109
  type: "BlockStatement",
9914
10110
  expressions,
9915
10111
  children: [expressions],
9916
10112
  bare: true,
9917
- semicolon: s.children[0]
10113
+ empty: true,
10114
+ implicit: true
9918
10115
  };
9919
10116
  });
9920
- function EmptyStatementBareBlock(ctx, state2) {
9921
- return (0, import_lib3.$EVENT)(ctx, state2, "EmptyStatementBareBlock", EmptyStatementBareBlock$0);
10117
+ function EmptyBareBlock(ctx, state2) {
10118
+ return (0, import_lib3.$EVENT)(ctx, state2, "EmptyBareBlock", EmptyBareBlock$0);
10119
+ }
10120
+ var NoBlock$0 = (0, import_lib3.$S)((0, import_lib3.$Y)(EOS), (0, import_lib3.$N)(IndentedFurther));
10121
+ function NoBlock(ctx, state2) {
10122
+ return (0, import_lib3.$EVENT)(ctx, state2, "NoBlock", NoBlock$0);
9922
10123
  }
9923
10124
  var BracedBlock$0 = NonSingleBracedBlock;
9924
10125
  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) {
@@ -11770,7 +11971,7 @@ var IterationExpression$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_
11770
11971
  function IterationExpression(ctx, state2) {
11771
11972
  return (0, import_lib3.$EVENT)(ctx, state2, "IterationExpression", IterationExpression$0);
11772
11973
  }
11773
- var LoopStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(LoopClause, BlockOrEmpty), function($skip, $loc, $0, $1, $2) {
11974
+ var LoopStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(LoopClause, BlockOrEmptyStatement), function($skip, $loc, $0, $1, $2) {
11774
11975
  var clause = $1;
11775
11976
  var block = $2;
11776
11977
  return {
@@ -11848,7 +12049,7 @@ var ComptimeStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Comptime, NoP
11848
12049
  function ComptimeStatement(ctx, state2) {
11849
12050
  return (0, import_lib3.$EVENT)(ctx, state2, "ComptimeStatement", ComptimeStatement$0);
11850
12051
  }
11851
- var WhileStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(WhileClause, BlockOrEmpty), function($skip, $loc, $0, $1, $2) {
12052
+ var WhileStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(WhileClause, BlockOrEmptyStatement), function($skip, $loc, $0, $1, $2) {
11852
12053
  var clause = $1;
11853
12054
  var block = $2;
11854
12055
  return {
@@ -11879,7 +12080,7 @@ var WhileClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$C)
11879
12080
  function WhileClause(ctx, state2) {
11880
12081
  return (0, import_lib3.$EVENT)(ctx, state2, "WhileClause", WhileClause$0);
11881
12082
  }
11882
- var ForStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(ForClause, BlockOrEmpty), function($skip, $loc, $0, $1, $2) {
12083
+ var ForStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(ForClause, BlockOrEmptyStatement), function($skip, $loc, $0, $1, $2) {
11883
12084
  var clause = $1;
11884
12085
  var block = $2;
11885
12086
  block = blockWithPrefix(clause.blockPrefix, block);
@@ -16457,34 +16658,22 @@ function parseProgram(input, options) {
16457
16658
  }
16458
16659
  }
16459
16660
 
16460
- // source/util.civet
16461
- var util_exports = {};
16462
- __export(util_exports, {
16661
+ // source/sourcemap.civet
16662
+ var sourcemap_exports = {};
16663
+ __export(sourcemap_exports, {
16463
16664
  SourceMap: () => SourceMap,
16464
16665
  base64Encode: () => base64Encode,
16465
16666
  locationTable: () => locationTable,
16466
16667
  lookupLineColumn: () => lookupLineColumn
16467
16668
  });
16468
- var smRegexp;
16469
- var prettySourceExcerpt;
16470
- var VLQ_SHIFT;
16471
- var VLQ_CONTINUATION_BIT;
16472
- var VLQ_VALUE_MASK;
16473
- var encodeVlq;
16474
- var BASE64_CHARS;
16475
- var encodeBase64;
16476
- var vlqTable;
16477
- var vlqChars;
16478
- var decodeError;
16479
- var decodeVLQ;
16480
- var remapPosition;
16481
16669
  var locationTable = function(input) {
16482
- var linesRe, lines, line, pos, result;
16483
- linesRe = /([^\r\n]*)(\r\n|\r|\n|$)/y;
16484
- lines = [];
16485
- line = 0;
16486
- pos = 0;
16487
- while (result = linesRe.exec(input)) {
16670
+ const linesRe = /([^\r\n]*)(\r\n|\r|\n|$)/y;
16671
+ const lines = [];
16672
+ let line = 0;
16673
+ let pos = 0;
16674
+ let ref;
16675
+ while (ref = linesRe.exec(input)) {
16676
+ const result = ref;
16488
16677
  pos += result[0].length;
16489
16678
  lines[line++] = pos;
16490
16679
  if (pos === input.length) {
@@ -16494,39 +16683,39 @@ var locationTable = function(input) {
16494
16683
  return lines;
16495
16684
  };
16496
16685
  var lookupLineColumn = function(table, pos) {
16497
- var l, prevEnd;
16498
- l = 0;
16499
- prevEnd = 0;
16686
+ let l = 0;
16687
+ let prevEnd = 0;
16500
16688
  while (table[l] <= pos) {
16501
16689
  prevEnd = table[l++];
16502
16690
  }
16503
16691
  return [l, pos - prevEnd];
16504
16692
  };
16505
16693
  var SourceMap = function(sourceString) {
16506
- var srcTable, sm, EOL2;
16507
- srcTable = locationTable(sourceString);
16508
- sm = {
16694
+ const srcTable = locationTable(sourceString);
16695
+ const sm = {
16509
16696
  lines: [[]],
16510
- lineNum: 0,
16697
+ line: 0,
16511
16698
  colOffset: 0,
16699
+ // relative to previous entry
16700
+ srcLine: 0,
16701
+ srcColumn: 0,
16702
+ srcOffset: 0,
16512
16703
  srcTable
16513
16704
  };
16514
- EOL2 = /\r?\n|\r/;
16705
+ const EOL2 = /\r?\n|\r/;
16515
16706
  return {
16516
16707
  data: sm,
16517
16708
  source: function() {
16518
16709
  return sourceString;
16519
16710
  },
16520
16711
  renderMappings: function() {
16521
- var lastSourceLine, lastSourceColumn;
16522
- lastSourceLine = 0;
16523
- lastSourceColumn = 0;
16524
- return sm.lines.map(function(line) {
16525
- return line.map(function(entry) {
16526
- var colDelta, sourceFileIndex, srcLine, srcCol, lineDelta;
16712
+ let lastSourceLine = 0;
16713
+ let lastSourceColumn = 0;
16714
+ return sm.lines.map((line) => {
16715
+ return line.map((entry) => {
16527
16716
  if (entry.length === 4) {
16528
- [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16529
- lineDelta = srcLine - lastSourceLine;
16717
+ let [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16718
+ const lineDelta = srcLine - lastSourceLine;
16530
16719
  colDelta = srcCol - lastSourceColumn;
16531
16720
  lastSourceLine = srcLine;
16532
16721
  lastSourceColumn = srcCol;
@@ -16550,102 +16739,69 @@ var SourceMap = function(sourceString) {
16550
16739
  }
16551
16740
  };
16552
16741
  },
16553
- updateSourceMap: function(outputStr, inputPos) {
16554
- var outLines, srcLine, srcCol;
16555
- outLines = outputStr.split(EOL2);
16742
+ updateSourceMap: function(outputStr, inputPos, colOffset = 0) {
16743
+ const outLines = outputStr.split(EOL2);
16744
+ let srcLine, srcCol;
16556
16745
  if (inputPos != null) {
16557
16746
  [srcLine, srcCol] = lookupLineColumn(srcTable, inputPos);
16747
+ srcCol += colOffset;
16748
+ sm.srcLine = srcLine;
16749
+ sm.srcColumn = srcCol;
16750
+ sm.srcOffset = inputPos + outputStr.length;
16558
16751
  }
16559
- outLines.forEach(function(line, i) {
16560
- var l;
16752
+ for (let i1 = 0, len3 = outLines.length; i1 < len3; i1++) {
16753
+ const i = i1;
16754
+ const line = outLines[i1];
16561
16755
  if (i > 0) {
16562
- sm.lineNum++;
16756
+ sm.line++;
16757
+ sm.srcLine++;
16563
16758
  sm.colOffset = 0;
16564
- sm.lines[sm.lineNum] = [];
16565
- srcCol = 0;
16759
+ sm.lines[sm.line] = [];
16760
+ sm.srcColumn = srcCol = colOffset;
16566
16761
  }
16567
- l = sm.colOffset;
16762
+ const l = sm.colOffset;
16568
16763
  sm.colOffset = line.length;
16764
+ sm.srcColumn += line.length;
16569
16765
  if (inputPos != null) {
16570
- return sm.lines[sm.lineNum].push([l, 0, srcLine + i, srcCol]);
16571
- } else if (l !== 0) {
16572
- return sm.lines[sm.lineNum].push([l]);
16766
+ sm.lines[sm.line].push([l, 0, srcLine + i, srcCol]);
16767
+ } else if (l != 0) {
16768
+ sm.lines[sm.line].push([l]);
16573
16769
  }
16574
- ;
16575
- return;
16576
- });
16770
+ }
16577
16771
  return;
16578
16772
  }
16579
16773
  };
16580
16774
  };
16581
- SourceMap.parseWithLines = function(base64encodedJSONstr) {
16582
- var json, sourceLine, sourceColumn, lines;
16583
- json = JSON.parse(Buffer.from(base64encodedJSONstr, "base64").toString("utf8"));
16584
- sourceLine = 0;
16585
- sourceColumn = 0;
16586
- lines = json.mappings.split(";").map(function(line) {
16587
- if (line.length === 0) {
16588
- return [];
16589
- }
16590
- return line.split(",").map(function(entry) {
16591
- var result;
16592
- result = decodeVLQ(entry);
16593
- switch (result.length) {
16594
- case 1: {
16595
- return [result[0]];
16596
- }
16597
- case 4: {
16598
- return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3]];
16599
- }
16600
- case 5: {
16601
- return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3], result[4]];
16602
- }
16603
- default: {
16604
- throw new Error("Unknown source map entry", result);
16605
- }
16606
- }
16607
- });
16775
+ var smRegexp = /\n\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,([+a-zA-Z0-9\/]*=?=?)$/;
16776
+ var remap = function(codeWithSourceMap, upstreamMap, sourcePath, targetPath) {
16777
+ let sourceMapText;
16778
+ const codeWithoutSourceMap = codeWithSourceMap.replace(smRegexp, (match, sm) => {
16779
+ sourceMapText = sm;
16780
+ return "";
16608
16781
  });
16609
- json.lines = lines;
16610
- return json;
16611
- };
16612
- smRegexp = /\n\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,([+a-zA-Z0-9\/]*=?=?)$/;
16613
- SourceMap.remap = function(codeWithSourceMap, upstreamMap, sourcePath, targetPath) {
16614
- var sourceMapText, codeWithoutSourceMap, remappedSourceMapJSON, newSourceMap, remappedCodeWithSourceMap, parsed, composedLines;
16615
- sourceMapText = null;
16616
- codeWithoutSourceMap = codeWithSourceMap.replace(
16617
- smRegexp,
16618
- (match, sm) => {
16619
- sourceMapText = sm;
16620
- return "";
16621
- }
16622
- );
16623
16782
  if (sourceMapText) {
16624
- parsed = SourceMap.parseWithLines(sourceMapText);
16625
- composedLines = SourceMap.composeLines(upstreamMap.data.lines, parsed.lines);
16783
+ const parsed = parseWithLines(sourceMapText);
16784
+ const composedLines = composeLines(upstreamMap.data.lines, parsed.lines);
16626
16785
  upstreamMap.data.lines = composedLines;
16627
16786
  }
16628
- remappedSourceMapJSON = upstreamMap.json(sourcePath, targetPath);
16629
- newSourceMap = `${"sourceMapping"}URL=data:application/json;charset=utf-8;base64,${base64Encode(JSON.stringify(remappedSourceMapJSON))}`;
16630
- remappedCodeWithSourceMap = `${codeWithoutSourceMap}
16787
+ const remappedSourceMapJSON = upstreamMap.json(sourcePath, targetPath);
16788
+ const newSourceMap = `${"sourceMapping"}URL=data:application/json;charset=utf-8;base64,${base64Encode(JSON.stringify(remappedSourceMapJSON))}`;
16789
+ const remappedCodeWithSourceMap = `${codeWithoutSourceMap}
16631
16790
  //# ${newSourceMap}`;
16632
16791
  return remappedCodeWithSourceMap;
16633
16792
  };
16634
- SourceMap.composeLines = function(upstreamMapping, lines) {
16635
- return lines.map(function(line, l) {
16636
- return line.map(function(entry) {
16637
- var colDelta, sourceFileIndex, srcLine, srcCol, srcPos, upstreamLine, upstreamCol;
16793
+ var composeLines = function(upstreamMapping, lines) {
16794
+ return lines.map((line) => {
16795
+ return line.map((entry) => {
16638
16796
  if (entry.length === 1) {
16639
16797
  return entry;
16640
16798
  }
16641
- ;
16642
- [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16643
- srcPos = remapPosition([srcLine, srcCol], upstreamMapping);
16799
+ const [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16800
+ const srcPos = remapPosition([srcLine, srcCol], upstreamMapping);
16644
16801
  if (!srcPos) {
16645
16802
  return [entry[0]];
16646
16803
  }
16647
- ;
16648
- [upstreamLine, upstreamCol] = srcPos;
16804
+ const [upstreamLine, upstreamCol] = srcPos;
16649
16805
  if (entry.length === 4) {
16650
16806
  return [colDelta, sourceFileIndex, upstreamLine, upstreamCol];
16651
16807
  }
@@ -16653,44 +16809,50 @@ SourceMap.composeLines = function(upstreamMapping, lines) {
16653
16809
  });
16654
16810
  });
16655
16811
  };
16656
- prettySourceExcerpt = function(source, location, length) {
16657
- var lines, lineNum, colNum, i, line, lineNumStr;
16658
- lines = source.split(/\r?\n|\r/);
16659
- lineNum = location.line;
16660
- colNum = location.column;
16661
- for (let start = lineNum - 2, end = lineNum + 2, i1 = i = start, asc = start <= end; asc ? i1 <= end : i1 >= end; i = asc ? ++i1 : --i1) {
16662
- if (i < 0 || i >= lines.length) {
16663
- continue;
16664
- }
16665
- line = lines[i];
16666
- lineNumStr = (i + 1).toString();
16667
- while (lineNumStr.length < 4) {
16668
- lineNumStr = " " + lineNumStr;
16669
- }
16670
- if (i === lineNum) {
16671
- console.log(`${lineNumStr}: ${line}`);
16672
- console.log(" ".repeat(lineNumStr.length + 2 + colNum) + "^".repeat(length));
16673
- } else {
16674
- console.log(`${lineNumStr}: ${line}`);
16812
+ var parseWithLines = function(base64encodedJSONstr) {
16813
+ const json = JSON.parse(Buffer.from(base64encodedJSONstr, "base64").toString("utf8"));
16814
+ let sourceLine = 0;
16815
+ let sourceColumn = 0;
16816
+ const lines = json.mappings.split(";").map((line) => {
16817
+ if (line.length === 0) {
16818
+ return [];
16675
16819
  }
16676
- }
16677
- return;
16820
+ return line.split(",").map((entry) => {
16821
+ const result = decodeVLQ(entry);
16822
+ switch (result.length) {
16823
+ case 1: {
16824
+ return [result[0]];
16825
+ }
16826
+ case 4: {
16827
+ return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3]];
16828
+ }
16829
+ case 5: {
16830
+ return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3], result[4]];
16831
+ }
16832
+ default: {
16833
+ throw new Error("Unknown source map entry", result);
16834
+ }
16835
+ }
16836
+ });
16837
+ });
16838
+ json.lines = lines;
16839
+ return json;
16678
16840
  };
16679
- VLQ_SHIFT = 5;
16680
- VLQ_CONTINUATION_BIT = 1 << VLQ_SHIFT;
16681
- VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - 1;
16682
- encodeVlq = function(value) {
16683
- var answer, valueToEncode, signBit, nextChunk;
16684
- answer = "";
16685
- let ref;
16841
+ Object.assign(SourceMap, { remap, parseWithLines, composeLines });
16842
+ var VLQ_SHIFT = 5;
16843
+ var VLQ_CONTINUATION_BIT = 1 << VLQ_SHIFT;
16844
+ var VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - 1;
16845
+ var encodeVlq = function(value) {
16846
+ let answer = "";
16847
+ let ref1;
16686
16848
  if (value < 0)
16687
- ref = 1;
16849
+ ref1 = 1;
16688
16850
  else
16689
- ref = 0;
16690
- signBit = ref;
16691
- valueToEncode = (Math.abs(value) << 1) + signBit;
16851
+ ref1 = 0;
16852
+ const signBit = ref1;
16853
+ let valueToEncode = (Math.abs(value) << 1) + signBit;
16692
16854
  while (valueToEncode || !answer) {
16693
- nextChunk = valueToEncode & VLQ_VALUE_MASK;
16855
+ let nextChunk = valueToEncode & VLQ_VALUE_MASK;
16694
16856
  valueToEncode = valueToEncode >> VLQ_SHIFT;
16695
16857
  if (valueToEncode) {
16696
16858
  nextChunk |= VLQ_CONTINUATION_BIT;
@@ -16699,57 +16861,53 @@ encodeVlq = function(value) {
16699
16861
  }
16700
16862
  return answer;
16701
16863
  };
16702
- BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16703
- encodeBase64 = function(value) {
16864
+ var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16865
+ var encodeBase64 = function(value) {
16704
16866
  return BASE64_CHARS[value] || (() => {
16705
- throw new Error(`Cannot Base64 encode value: ${value}`);
16867
+ throw new Error("Cannot Base64 encode value: ${value}");
16706
16868
  })();
16707
16869
  };
16708
16870
  var base64Encode = function(src) {
16709
16871
  return Buffer.from(src).toString("base64");
16710
16872
  };
16711
- vlqTable = new Uint8Array(128);
16712
- vlqChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16713
- (function() {
16714
- var i, l;
16715
- i = 0;
16716
- l = vlqTable.length;
16873
+ var vlqTable = new Uint8Array(128);
16874
+ var vlqChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16875
+ {
16876
+ let i = 0;
16877
+ let l = vlqTable.length;
16717
16878
  while (i < l) {
16718
16879
  vlqTable[i] = 255;
16719
16880
  i++;
16720
16881
  }
16721
16882
  i = 0;
16722
16883
  l = vlqChars.length;
16723
- const results = [];
16724
16884
  while (i < l) {
16725
16885
  vlqTable[vlqChars.charCodeAt(i)] = i;
16726
- results.push(i++);
16886
+ i++;
16727
16887
  }
16728
- ;
16729
- return results;
16730
- })();
16731
- decodeError = function(message) {
16888
+ }
16889
+ var decodeError = function(message) {
16732
16890
  throw new Error(message);
16733
16891
  };
16734
- decodeVLQ = function(mapping) {
16735
- var i, l, result, shift, vlq, c, index, v;
16736
- i = 0;
16737
- l = mapping.length;
16738
- result = [];
16892
+ var decodeVLQ = function(mapping) {
16893
+ let i = 0;
16894
+ let l = mapping.length;
16895
+ let result = [];
16739
16896
  while (i < l) {
16740
- shift = 0;
16741
- vlq = 0;
16897
+ let shift = 0;
16898
+ let vlq = 0;
16899
+ let v = 0;
16742
16900
  while (true) {
16743
16901
  if (i >= l) {
16744
16902
  decodeError("Unexpected early end of mapping data");
16745
16903
  }
16746
- c = mapping.charCodeAt(i);
16747
- if ((c & 127) !== c) {
16748
- decodeError(`Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}`);
16904
+ const c = mapping.charCodeAt(i);
16905
+ if ((c & 127) != c) {
16906
+ decodeError("Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}");
16749
16907
  }
16750
- index = vlqTable[c & 127];
16908
+ const index = vlqTable[c & 127];
16751
16909
  if (index === 255) {
16752
- decodeError(`Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}`);
16910
+ decodeError("Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}");
16753
16911
  }
16754
16912
  i++;
16755
16913
  vlq |= (index & 31) << shift;
@@ -16767,20 +16925,19 @@ decodeVLQ = function(mapping) {
16767
16925
  }
16768
16926
  return result;
16769
16927
  };
16770
- remapPosition = function(position, sourcemapLines) {
16771
- var line, character, textLine, i, p, l, lastMapping, lastMappingPosition, mapping;
16772
- [line, character] = position;
16773
- textLine = sourcemapLines[line];
16928
+ var remapPosition = function(position, sourcemapLines) {
16929
+ const [line, character] = position;
16930
+ const textLine = sourcemapLines[line];
16774
16931
  if (!textLine?.length) {
16775
16932
  return void 0;
16776
16933
  }
16777
- i = 0;
16778
- p = 0;
16779
- l = textLine.length;
16780
- lastMapping = void 0;
16781
- lastMappingPosition = 0;
16934
+ let i = 0;
16935
+ let p = 0;
16936
+ const l = textLine.length;
16937
+ let lastMapping = void 0;
16938
+ let lastMappingPosition = 0;
16782
16939
  while (i < l) {
16783
- mapping = textLine[i];
16940
+ const mapping = textLine[i];
16784
16941
  p += mapping[0];
16785
16942
  if (mapping.length === 4) {
16786
16943
  lastMapping = mapping;
@@ -16791,7 +16948,7 @@ remapPosition = function(position, sourcemapLines) {
16791
16948
  }
16792
16949
  i++;
16793
16950
  }
16794
- if (character - lastMappingPosition !== 0) {
16951
+ if (character - lastMappingPosition != 0) {
16795
16952
  return void 0;
16796
16953
  }
16797
16954
  if (lastMapping) {
@@ -16842,20 +16999,15 @@ var StateCache = class {
16842
16999
  };
16843
17000
 
16844
17001
  // source/main.civet
16845
- var { SourceMap: SourceMap2 } = util_exports;
17002
+ var { SourceMap: SourceMap2 } = sourcemap_exports;
16846
17003
  var ParseErrors = class extends Error {
16847
17004
  name = "ParseErrors";
16848
- filename;
16849
- line;
16850
- column;
16851
- offset;
16852
- constructor(message, filename1, line1, column1, offset1) {
16853
- super(message);
16854
- this.filename = filename1;
16855
- this.line = line1;
16856
- this.column = column1;
16857
- this.offset = offset1;
17005
+ errors;
17006
+ constructor(errors) {
17007
+ const message = errors.map(($) => $.message).join("\n");
17008
+ super(errors.map(($1) => $1.message).join("\n"));
16858
17009
  this.message = message;
17010
+ this.errors = errors;
16859
17011
  }
16860
17012
  };
16861
17013
  var uncacheable = /* @__PURE__ */ new Set([
@@ -16957,6 +17109,7 @@ ${counts}`;
16957
17109
  });
16958
17110
  }
16959
17111
  }
17112
+ const throwOnErrors = options.errors == null;
16960
17113
  function rest(ast2) {
16961
17114
  options = options;
16962
17115
  if (!(options.ast === "raw")) {
@@ -16966,28 +17119,36 @@ ${counts}`;
16966
17119
  return ast2;
16967
17120
  }
16968
17121
  function checkErrors() {
17122
+ if (!throwOnErrors) {
17123
+ return;
17124
+ }
17125
+ options = options;
16969
17126
  if (options.errors?.length) {
16970
- throw new ParseErrors(options.errors.map(($) => $.message).join("\n"));
17127
+ throw new ParseErrors(options.errors);
16971
17128
  }
16972
17129
  ;
16973
17130
  return;
16974
17131
  }
16975
17132
  if (options.sourceMap || options.inlineMap) {
16976
- const sm = SourceMap2(src);
16977
- options.updateSourceMap = sm.updateSourceMap;
17133
+ options.sourceMap = SourceMap2(src);
16978
17134
  const code = generate_default(ast2, options);
16979
17135
  checkErrors();
16980
17136
  if (options.inlineMap) {
16981
- return SourceMap2.remap(code, sm, filename2, filename2 + ".tsx");
17137
+ return SourceMap2.remap(code, options.sourceMap, filename2, filename2 + ".tsx");
16982
17138
  } else {
16983
17139
  return {
16984
17140
  code,
16985
- sourceMap: sm
17141
+ sourceMap: options.sourceMap
16986
17142
  };
16987
17143
  }
16988
17144
  }
16989
17145
  const result = generate_default(ast2, options);
16990
- checkErrors();
17146
+ if (options.errors?.length) {
17147
+ delete options.errors;
17148
+ options.sourceMap = SourceMap2(src);
17149
+ generate_default(ast2, options);
17150
+ checkErrors();
17151
+ }
16991
17152
  return result;
16992
17153
  }
16993
17154
  if (ast.then != null) {
@@ -17059,13 +17220,14 @@ var makeCache = function({ hits, trace } = {}) {
17059
17220
  return events;
17060
17221
  };
17061
17222
  var isCompileError = function(err) {
17062
- return err instanceof Error && //@ts-ignore
17063
- [err.message, err.name, err.filename, err.line, err.column, err.offset].every(($1) => $1 !== void 0);
17223
+ return err instanceof import_lib3.ParseError || err instanceof ParseErrors;
17064
17224
  };
17065
- var main_default = { parse, parseProgram, generate: generate_default, util: util_exports, compile, isCompileError };
17225
+ var main_default = { parse, parseProgram, ParseError: import_lib3.ParseError, ParseErrors, generate: generate_default, sourcemap: sourcemap_exports, SourceMap: SourceMap2, compile, isCompileError };
17066
17226
  // Annotate the CommonJS export names for ESM import in node:
17067
17227
  0 && (module.exports = {
17228
+ ParseError,
17068
17229
  ParseErrors,
17230
+ SourceMap,
17069
17231
  compile,
17070
17232
  generate,
17071
17233
  isCompileError,
@@ -17073,5 +17235,5 @@ var main_default = { parse, parseProgram, generate: generate_default, util: util
17073
17235
  parse,
17074
17236
  parseProgram,
17075
17237
  prune,
17076
- util
17238
+ sourcemap
17077
17239
  });