@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.mjs CHANGED
@@ -28,9 +28,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  mod
29
29
  ));
30
30
 
31
- // ../Hera/dist/machine.js
31
+ // node_modules/@danielx/hera/dist/machine.js
32
32
  var require_machine = __commonJS({
33
- "../Hera/dist/machine.js"(exports, module) {
33
+ "node_modules/@danielx/hera/dist/machine.js"(exports, module) {
34
34
  "use strict";
35
35
  var __defProp2 = Object.defineProperty;
36
36
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
@@ -69,6 +69,7 @@ var require_machine = __commonJS({
69
69
  $TS: () => $TS2,
70
70
  $TV: () => $TV2,
71
71
  $Y: () => $Y2,
72
+ ParseError: () => ParseError2,
72
73
  Validator: () => Validator2
73
74
  });
74
75
  module.exports = __toCommonJS(machine_exports);
@@ -435,11 +436,10 @@ ${input.slice(result.pos)}
435
436
  hint = JSON.stringify(hint);
436
437
  else
437
438
  hint = "EOF";
438
- const error = new ParseError(`${filename2}:${line}:${column} Failed to parse
439
- Expected:
439
+ const error = new ParseError2("Failed to parse", `Expected:
440
440
  ${expectations.join("\n ")}
441
441
  Found: ${hint}
442
- `, "ParseError", filename2, line, column, maxFailPos);
442
+ `, filename2, line, column, maxFailPos);
443
443
  throw error;
444
444
  }
445
445
  if (result) {
@@ -462,15 +462,21 @@ ${input.slice(result.pos)}
462
462
  reset
463
463
  };
464
464
  }
465
- var ParseError = class extends Error {
466
- constructor(message, name, filename2, line, column, offset) {
465
+ var ParseError2 = class extends Error {
466
+ constructor(header, body, filename2, line, column, offset) {
467
+ let message = `${filename2}:${line}:${column} ${header}`;
468
+ if (body)
469
+ message += `
470
+ ${body}`;
467
471
  super(message);
468
- this.message = message;
469
- this.name = name;
472
+ this.header = header;
473
+ this.body = body;
470
474
  this.filename = filename2;
471
475
  this.line = line;
472
476
  this.column = column;
473
477
  this.offset = offset;
478
+ this.name = "ParseError";
479
+ this.message = message;
474
480
  }
475
481
  };
476
482
  }
@@ -528,6 +534,7 @@ __export(lib_exports, {
528
534
  processAssignmentDeclaration: () => processAssignmentDeclaration,
529
535
  processBinaryOpExpression: () => processBinaryOpExpression,
530
536
  processCallMemberExpression: () => processCallMemberExpression,
537
+ processCoffeeDo: () => processCoffeeDo,
531
538
  processCoffeeInterpolation: () => processCoffeeInterpolation,
532
539
  processForInOf: () => processForInOf,
533
540
  processProgram: () => processProgram,
@@ -933,27 +940,49 @@ function assignResults(node, collect) {
933
940
  case "DebuggerStatement":
934
941
  case "EmptyStatement":
935
942
  case "ReturnStatement":
936
- case "ThrowStatement":
943
+ case "ThrowStatement": {
937
944
  return;
938
- case "Declaration":
945
+ }
946
+ case "Declaration": {
947
+ let ref5;
948
+ if (exp.bindings?.length) {
949
+ ref5 = patternAsValue((ref4 = exp.bindings)[ref4.length - 1].pattern);
950
+ } else {
951
+ ref5 = "void 0";
952
+ }
953
+ ;
954
+ const value = ref5;
939
955
  exp.children.push([
940
956
  "",
941
- [";", collect(patternAsValue((ref4 = exp.bindings)[ref4.length - 1].pattern))]
957
+ [";", collect(value)]
942
958
  ]);
943
959
  return;
960
+ }
961
+ case "FunctionExpression": {
962
+ if (exp.id) {
963
+ exp.children.push([
964
+ "",
965
+ [";", collect(exp.id)]
966
+ ]);
967
+ return;
968
+ }
969
+ break;
970
+ }
944
971
  case "ForStatement":
945
972
  case "IterationStatement":
946
973
  case "DoStatement":
947
- case "ComptimeStatement":
974
+ case "ComptimeStatement": {
948
975
  wrapIterationReturningResults(exp, outer, collect);
949
976
  return;
950
- case "BlockStatement":
977
+ }
978
+ case "BlockStatement": {
951
979
  if (node.expressions.some(isExit)) {
952
980
  return;
953
981
  }
954
982
  assignResults(exp.expressions[exp.expressions.length - 1], collect);
955
983
  return;
956
- case "IfStatement":
984
+ }
985
+ case "IfStatement": {
957
986
  assignResults(exp.then, collect);
958
987
  if (exp.then.bare && !exp.then.semicolon) {
959
988
  exp.then.children.push(exp.then.semicolon = ";");
@@ -961,18 +990,22 @@ function assignResults(node, collect) {
961
990
  if (exp.else) {
962
991
  assignResults(exp.else.block, collect);
963
992
  } else {
964
- exp.children.push([" else {", collect("undefined"), "}"]);
993
+ exp.children.push([" else {", collect("void 0"), "}"]);
965
994
  }
966
995
  return;
967
- case "PatternMatchingStatement":
996
+ }
997
+ case "PatternMatchingStatement": {
968
998
  assignResults(exp.children[0], collect);
969
999
  return;
970
- case "SwitchStatement":
1000
+ }
1001
+ case "SwitchStatement": {
971
1002
  assignResults(exp.children[2], collect);
972
1003
  return;
973
- case "TryStatement":
1004
+ }
1005
+ case "TryStatement": {
974
1006
  exp.blocks.forEach((block) => assignResults(block, collect));
975
1007
  return;
1008
+ }
976
1009
  }
977
1010
  if (node[node.length - 1]?.type === "SemicolonDelimiter") {
978
1011
  return;
@@ -983,7 +1016,7 @@ function insertReturn(node, outerNode = node) {
983
1016
  if (!node)
984
1017
  return;
985
1018
  switch (node.type) {
986
- case "BlockStatement":
1019
+ case "BlockStatement": {
987
1020
  if (node.expressions.length) {
988
1021
  if (node.expressions.some(([, exp2]) => isExit(exp2))) {
989
1022
  return;
@@ -996,7 +1029,8 @@ function insertReturn(node, outerNode = node) {
996
1029
  }
997
1030
  }
998
1031
  return;
999
- case "WhenClause":
1032
+ }
1033
+ case "WhenClause": {
1000
1034
  if (node.break) {
1001
1035
  node.children.splice(node.children.indexOf(node.break), 1);
1002
1036
  }
@@ -1006,9 +1040,11 @@ function insertReturn(node, outerNode = node) {
1006
1040
  node.block.expressions.push(wrapWithReturn());
1007
1041
  }
1008
1042
  return;
1009
- case "DefaultClause":
1043
+ }
1044
+ case "DefaultClause": {
1010
1045
  insertReturn(node.block);
1011
1046
  return;
1047
+ }
1012
1048
  }
1013
1049
  if (!Array.isArray(node))
1014
1050
  return;
@@ -1028,23 +1064,36 @@ function insertReturn(node, outerNode = node) {
1028
1064
  exp = exp.statement;
1029
1065
  ({ type } = exp);
1030
1066
  }
1031
- let ref5;
1067
+ let ref6;
1032
1068
  switch (type) {
1033
1069
  case "BreakStatement":
1034
1070
  case "ContinueStatement":
1035
1071
  case "DebuggerStatement":
1036
1072
  case "EmptyStatement":
1037
1073
  case "ReturnStatement":
1038
- case "ThrowStatement":
1074
+ case "ThrowStatement": {
1039
1075
  return;
1040
- case "Declaration":
1076
+ }
1077
+ case "Declaration": {
1078
+ let ref7;
1079
+ if (exp.bindings?.length) {
1080
+ ref7 = [" ", patternAsValue((ref6 = exp.bindings)[ref6.length - 1].pattern)];
1081
+ } else {
1082
+ ref7 = [];
1083
+ }
1084
+ ;
1085
+ const value = ref7;
1041
1086
  exp.children.push(["", {
1042
1087
  type: "ReturnStatement",
1043
- children: [";return ", patternAsValue((ref5 = exp.bindings)[ref5.length - 1].pattern)],
1088
+ children: [
1089
+ ";return",
1090
+ ...value
1091
+ ],
1044
1092
  parent: exp
1045
1093
  }]);
1046
1094
  return;
1047
- case "FunctionExpression":
1095
+ }
1096
+ case "FunctionExpression": {
1048
1097
  if (exp.id) {
1049
1098
  exp.children.push([
1050
1099
  "",
@@ -1057,16 +1106,19 @@ function insertReturn(node, outerNode = node) {
1057
1106
  return;
1058
1107
  }
1059
1108
  break;
1109
+ }
1060
1110
  case "ForStatement":
1061
1111
  case "IterationStatement":
1062
1112
  case "DoStatement":
1063
- case "ComptimeStatement":
1113
+ case "ComptimeStatement": {
1064
1114
  wrapIterationReturningResults(exp, outer);
1065
1115
  return;
1066
- case "BlockStatement":
1116
+ }
1117
+ case "BlockStatement": {
1067
1118
  insertReturn(exp.expressions[exp.expressions.length - 1]);
1068
1119
  return;
1069
- case "IfStatement":
1120
+ }
1121
+ case "IfStatement": {
1070
1122
  insertReturn(exp.then);
1071
1123
  if (exp.else)
1072
1124
  insertReturn(exp.else.block);
@@ -1078,18 +1130,23 @@ function insertReturn(node, outerNode = node) {
1078
1130
  parent: exp
1079
1131
  }]);
1080
1132
  return;
1081
- case "PatternMatchingStatement":
1133
+ }
1134
+ case "PatternMatchingStatement": {
1082
1135
  insertReturn(exp.children[0]);
1083
1136
  return;
1084
- case "SwitchStatement":
1137
+ }
1138
+ case "SwitchStatement": {
1085
1139
  insertSwitchReturns(exp);
1086
1140
  return;
1087
- case "TryStatement":
1141
+ }
1142
+ case "TryStatement": {
1088
1143
  exp.blocks.forEach((block) => insertReturn(block));
1089
1144
  return;
1145
+ }
1090
1146
  }
1091
- if (node[node.length - 1]?.type === "SemicolonDelimiter")
1147
+ if (node[node.length - 1]?.type === "SemicolonDelimiter") {
1092
1148
  return;
1149
+ }
1093
1150
  const returnStatement = wrapWithReturn(node[1]);
1094
1151
  node.splice(1, 1, returnStatement);
1095
1152
  }
@@ -1178,10 +1235,33 @@ function processParams(f) {
1178
1235
  }
1179
1236
  expressions.unshift(...prefix);
1180
1237
  }
1238
+ function processSignature(f) {
1239
+ const { block, signature } = f;
1240
+ if (hasAwait(block) && !f.async?.length) {
1241
+ f.async.push("async ");
1242
+ signature.modifier.async = true;
1243
+ }
1244
+ if (hasYield(block) && !f.generator?.length) {
1245
+ if (f.type === "ArrowFunction") {
1246
+ gatherRecursiveWithinFunction(block, ($) => $.type === "YieldExpression").forEach((y) => {
1247
+ const i = y.children.findIndex(($1) => $1.type === "Yield");
1248
+ return y.children.splice(i + 1, 0, {
1249
+ type: "Error",
1250
+ message: "Can't use yield inside of => arrow function"
1251
+ });
1252
+ });
1253
+ } else {
1254
+ f.generator.push("*");
1255
+ signature.modifier.generator = true;
1256
+ }
1257
+ }
1258
+ }
1181
1259
  function processFunctions(statements, config2) {
1182
1260
  gatherRecursiveAll(statements, ({ type }) => type === "FunctionExpression" || type === "ArrowFunction").forEach((f) => {
1183
- if (f.type === "FunctionExpression")
1261
+ if (f.type === "FunctionExpression") {
1184
1262
  implicitFunctionBlock(f);
1263
+ }
1264
+ processSignature(f);
1185
1265
  processParams(f);
1186
1266
  return processReturn(f, config2.implicitReturns);
1187
1267
  });
@@ -1229,6 +1309,102 @@ function skipImplicitArguments(args) {
1229
1309
  }
1230
1310
  return false;
1231
1311
  }
1312
+ function processCoffeeDo(ws, expression) {
1313
+ ws = insertTrimmingSpace(ws, "");
1314
+ const args = [];
1315
+ if (typeof expression === "object" && expression != null && "type" in expression && expression.type === "ArrowFunction" || typeof expression === "object" && expression != null && "type" in expression && expression.type === "FunctionExpression") {
1316
+ const { parameters } = expression;
1317
+ const newParameters = {
1318
+ ...parameters,
1319
+ children: (() => {
1320
+ const results = [];
1321
+ for (let ref8 = parameters.children, i1 = 0, len3 = ref8.length; i1 < len3; i1++) {
1322
+ let parameter = ref8[i1];
1323
+ if (typeof parameter === "object" && parameter != null && "type" in parameter && parameter.type === "Parameter") {
1324
+ let ref9;
1325
+ if (ref9 = parameter.initializer) {
1326
+ const initializer = ref9;
1327
+ args.push(initializer.expression, parameter.delim);
1328
+ parameter = {
1329
+ ...parameter,
1330
+ initializer: void 0,
1331
+ children: parameter.children.filter((a2) => a2 !== initializer)
1332
+ };
1333
+ } else {
1334
+ args.push(parameter.children.filter(
1335
+ (a3) => a3 !== parameter.typeSuffix
1336
+ ));
1337
+ }
1338
+ }
1339
+ results.push(parameter);
1340
+ }
1341
+ return results;
1342
+ })()
1343
+ };
1344
+ expression = {
1345
+ ...expression,
1346
+ parameters: newParameters,
1347
+ children: expression.children.map(($2) => $2 === parameters ? newParameters : $2)
1348
+ };
1349
+ }
1350
+ return {
1351
+ type: "CallExpression",
1352
+ children: [
1353
+ makeLeftHandSideExpression(expression),
1354
+ {
1355
+ type: "Call",
1356
+ args,
1357
+ children: ["(", args, ")"]
1358
+ }
1359
+ ]
1360
+ };
1361
+ }
1362
+ function makeAmpersandFunction(rhs) {
1363
+ let { ref, typeSuffix, body } = rhs;
1364
+ if (!(ref != null)) {
1365
+ ref = makeRef("$");
1366
+ inplacePrepend(ref, body);
1367
+ }
1368
+ if (body?.type === "ObjectExpression") {
1369
+ body = makeLeftHandSideExpression(body);
1370
+ }
1371
+ const parameters = makeNode({
1372
+ type: "Parameters",
1373
+ children: typeSuffix ? ["(", ref, typeSuffix, ")"] : [ref],
1374
+ names: []
1375
+ });
1376
+ const expressions = [[" ", body]];
1377
+ const block = makeNode({
1378
+ type: "BlockStatement",
1379
+ bare: true,
1380
+ expressions,
1381
+ children: [expressions],
1382
+ implicitlyReturned: true
1383
+ });
1384
+ const async = [];
1385
+ const children = [async, parameters, " =>", block];
1386
+ const fn = makeNode({
1387
+ type: "ArrowFunction",
1388
+ async,
1389
+ signature: {
1390
+ modifier: {
1391
+ async: !!async
1392
+ }
1393
+ },
1394
+ children,
1395
+ ref,
1396
+ block,
1397
+ parameters,
1398
+ ampersandBlock: true,
1399
+ body
1400
+ });
1401
+ if (isStatement(body)) {
1402
+ braceBlock(block);
1403
+ fn.ampersandBlock = false;
1404
+ delete fn.body;
1405
+ }
1406
+ return fn;
1407
+ }
1232
1408
 
1233
1409
  // source/parser/block.civet
1234
1410
  function blockWithPrefix(prefixStatements, block) {
@@ -1389,6 +1565,9 @@ function needsPrecedingSemicolon(exp) {
1389
1565
  }
1390
1566
  return false;
1391
1567
  }
1568
+ if (isToken(exp)) {
1569
+ exp = exp.token;
1570
+ }
1392
1571
  if (typeof exp === "string") {
1393
1572
  return /^\s*[\(\[\`\+\-\/]/.test(exp);
1394
1573
  }
@@ -1449,8 +1628,8 @@ function addParentPointers(node, parent) {
1449
1628
  node.parent = parent;
1450
1629
  }
1451
1630
  if (node.children) {
1452
- for (let ref1 = node.children, i1 = 0, len1 = ref1.length; i1 < len1; i1++) {
1453
- const child = ref1[i1];
1631
+ for (let ref = node.children, i1 = 0, len1 = ref.length; i1 < len1; i1++) {
1632
+ const child = ref[i1];
1454
1633
  addParentPointers(child, node);
1455
1634
  }
1456
1635
  }
@@ -1732,13 +1911,13 @@ function startsWith(target, value) {
1732
1911
  return;
1733
1912
  }
1734
1913
  function hasAwait(exp) {
1735
- return gatherRecursiveWithinFunction(exp, ({ type }) => type === "Await").length > 0;
1914
+ return gatherRecursiveWithinFunction(exp, ($1) => $1.type === "Await").length > 0;
1736
1915
  }
1737
1916
  function hasYield(exp) {
1738
- return gatherRecursiveWithinFunction(exp, ({ type }) => type === "Yield").length > 0;
1917
+ return gatherRecursiveWithinFunction(exp, ($2) => $2.type === "Yield").length > 0;
1739
1918
  }
1740
1919
  function hasImportDeclaration(exp) {
1741
- return gatherRecursiveWithinFunction(exp, ({ type }) => type === "ImportDeclaration").length > 0;
1920
+ return gatherRecursiveWithinFunction(exp, ($3) => $3.type === "ImportDeclaration").length > 0;
1742
1921
  }
1743
1922
  function deepCopy(node) {
1744
1923
  if (node == null)
@@ -1776,72 +1955,29 @@ function removeHoistDecs(node) {
1776
1955
  }
1777
1956
  }
1778
1957
  }
1779
- function makeAmpersandFunction(rhs) {
1780
- let { ref, typeSuffix, body } = rhs;
1781
- if (!(ref != null)) {
1782
- ref = makeRef("$");
1783
- inplacePrepend(ref, body);
1784
- }
1785
- if (body?.type === "ObjectExpression") {
1786
- body = makeLeftHandSideExpression(body);
1787
- }
1788
- const parameters = makeNode({
1789
- type: "Parameters",
1790
- children: typeSuffix ? ["(", ref, typeSuffix, ")"] : [ref],
1791
- names: []
1792
- });
1793
- const expressions = [[" ", body]];
1794
- const block = makeNode({
1795
- type: "BlockStatement",
1796
- bare: true,
1797
- expressions,
1798
- children: [expressions],
1799
- implicitlyReturned: true
1800
- });
1801
- const children = [parameters, " =>", block];
1802
- const async = hasAwait(body);
1803
- if (async) {
1804
- children.unshift("async ");
1805
- }
1806
- const fn = makeNode({
1807
- type: "ArrowFunction",
1808
- signature: {
1809
- modifier: {
1810
- async
1811
- }
1812
- },
1813
- children,
1814
- ref,
1815
- block,
1816
- parameters,
1817
- ampersandBlock: true,
1818
- body
1819
- });
1820
- if (isStatement(body)) {
1821
- braceBlock(block);
1822
- fn.ampersandBlock = false;
1823
- delete fn.body;
1824
- }
1825
- return fn;
1826
- }
1958
+ var skipParens = /* @__PURE__ */ new Set([
1959
+ "AmpersandRef",
1960
+ "CallExpression",
1961
+ "Identifier",
1962
+ "JSXElement",
1963
+ "JSXFragment",
1964
+ "Literal",
1965
+ "MemberExpression",
1966
+ "NewExpression",
1967
+ "ParenthesizedExpression",
1968
+ "Ref",
1969
+ "Placeholder",
1970
+ "StatementExpression"
1971
+ // wrapIIFE
1972
+ ]);
1827
1973
  function makeLeftHandSideExpression(expression) {
1828
- if (expression.parenthesized) {
1829
- return expression;
1830
- }
1831
- switch (expression.type) {
1832
- case "AmpersandRef":
1833
- case "CallExpression":
1834
- case "Identifier":
1835
- case "JSXElement":
1836
- case "JSXFragment":
1837
- case "Literal":
1838
- case "MemberExpression":
1839
- case "NewExpression":
1840
- case "ParenthesizedExpression":
1841
- case "Ref":
1842
- case "Placeholder":
1843
- case "StatementExpression":
1974
+ if (isASTNodeObject(expression)) {
1975
+ if (expression.parenthesized) {
1976
+ return expression;
1977
+ }
1978
+ if (skipParens.has(expression.type)) {
1844
1979
  return expression;
1980
+ }
1845
1981
  }
1846
1982
  return makeNode({
1847
1983
  type: "ParenthesizedExpression",
@@ -1869,8 +2005,8 @@ function updateParentPointers(node, parent, depth = 1) {
1869
2005
  node.parent = parent;
1870
2006
  }
1871
2007
  if (depth && isParent(node)) {
1872
- for (let ref2 = node.children, i3 = 0, len3 = ref2.length; i3 < len3; i3++) {
1873
- const child = ref2[i3];
2008
+ for (let ref1 = node.children, i3 = 0, len3 = ref1.length; i3 < len3; i3++) {
2009
+ const child = ref1[i3];
1874
2010
  updateParentPointers(child, node, depth - 1);
1875
2011
  }
1876
2012
  }
@@ -1941,11 +2077,11 @@ function parenthesizeType(type) {
1941
2077
  }
1942
2078
  function wrapIIFE(expressions, asyncFlag) {
1943
2079
  let prefix;
1944
- let async;
2080
+ const async = [];
1945
2081
  if (asyncFlag) {
1946
- async = "async ";
2082
+ async.push("async ");
1947
2083
  } else if (hasAwait(expressions)) {
1948
- async = "async ";
2084
+ async.push("async ");
1949
2085
  prefix = {
1950
2086
  type: "Await",
1951
2087
  children: ["await "]
@@ -1956,8 +2092,7 @@ function wrapIIFE(expressions, asyncFlag) {
1956
2092
  expressions,
1957
2093
  children: ["{", expressions, "}"],
1958
2094
  bare: false,
1959
- root: false,
1960
- parent: void 0
2095
+ root: false
1961
2096
  });
1962
2097
  const parameters = {
1963
2098
  type: "Parameters",
@@ -1966,7 +2101,7 @@ function wrapIIFE(expressions, asyncFlag) {
1966
2101
  };
1967
2102
  const signature = {
1968
2103
  modifier: {
1969
- async: !!async
2104
+ async: !!async.length
1970
2105
  },
1971
2106
  returnType: void 0
1972
2107
  };
@@ -2309,8 +2444,6 @@ function processBinaryOpExpression($0) {
2309
2444
  }
2310
2445
  return expandedOps;
2311
2446
  }
2312
- ;
2313
- return recurse;
2314
2447
  }
2315
2448
  function dotNumericLiteral(literal) {
2316
2449
  if (literal?.type === "Literal" && /^[+-]?(?:0|[1-9](?:_[0-9]|[0-9])*)$/.test(literal.raw)) {
@@ -2827,7 +2960,13 @@ function getPatternBlockPrefix(pattern, ref, decl = "const ", suffix) {
2827
2960
  thisAssignments = thisAssignments.map(($6) => ["", $6, ";"]);
2828
2961
  const duplicateDeclarations = aggregateDuplicateBindings([patternBindings, splices]);
2829
2962
  return [
2830
- ["", [decl, patternBindings, suffix, " = ", ref, ...splices], ";"],
2963
+ ["", {
2964
+ type: "Declaration",
2965
+ children: [decl, patternBindings, suffix, " = ", ref, ...splices],
2966
+ names: [],
2967
+ bindings: []
2968
+ // avoid implicit return of any bindings
2969
+ }, ";"],
2831
2970
  ...thisAssignments,
2832
2971
  ...duplicateDeclarations.map(($7) => ["", $7, ";"])
2833
2972
  ];
@@ -2975,9 +3114,18 @@ function aggregateDuplicateBindings(bindings) {
2975
3114
  aliasBinding(p, ref);
2976
3115
  return ref;
2977
3116
  });
2978
- return declarations.push(["const ", key, " = [", ...refs.map((r, i) => {
2979
- return i === 0 ? r : [", ", r];
2980
- }), "]"]);
3117
+ return declarations.push({
3118
+ type: "Declaration",
3119
+ children: [
3120
+ "const ",
3121
+ key,
3122
+ " = [",
3123
+ ...refs.map((r, i) => i === 0 ? r : [", ", r]),
3124
+ "]"
3125
+ ],
3126
+ names: [],
3127
+ bindings: []
3128
+ });
2981
3129
  });
2982
3130
  return declarations;
2983
3131
  }
@@ -3214,7 +3362,6 @@ function processDeclarationConditionStatement(s) {
3214
3362
  if (s.negated) {
3215
3363
  let m;
3216
3364
  if (!(m = condition.expression, typeof m === "object" && m != null && "type" in m && m.type === "UnaryExpression" && "children" in m && Array.isArray(m.children) && len2(m.children, 2) && m.children[0] === "!" && typeof m.children[1] === "object" && m.children[1] != null && "type" in m.children[1] && m.children[1].type === "ParenthesizedExpression")) {
3217
- console.log(condition.expression);
3218
3365
  throw new Error("Unsupported negated condition");
3219
3366
  }
3220
3367
  const { children } = condition.expression.children[1];
@@ -3469,8 +3616,7 @@ function processUnaryExpression(pre, exp, post) {
3469
3616
  token: " != null"
3470
3617
  };
3471
3618
  if (pre.length) {
3472
- let ref;
3473
- const lastPre = (ref = pre)[ref.length - 1];
3619
+ const lastPre = pre[pre.length - 1];
3474
3620
  if (lastPre.token === "!") {
3475
3621
  post.token = " == null";
3476
3622
  pre = pre.slice(0, -1);
@@ -3514,9 +3660,9 @@ function processUnaryExpression(pre, exp, post) {
3514
3660
  }
3515
3661
  }
3516
3662
  }
3517
- let ref1;
3518
- while (ref1 = pre.length) {
3519
- const l = ref1;
3663
+ let ref;
3664
+ while (ref = pre.length) {
3665
+ const l = ref;
3520
3666
  const last = pre[l - 1];
3521
3667
  if (last.type === "Await") {
3522
3668
  if (last.op) {
@@ -4107,49 +4253,69 @@ function stringify(node) {
4107
4253
  return `${node}`;
4108
4254
  }
4109
4255
  }
4110
- function gen(node, options) {
4111
- if (node === null || node === void 0) {
4112
- return "";
4113
- }
4114
- if (typeof node === "string") {
4115
- options?.updateSourceMap?.(node);
4116
- return node;
4117
- }
4118
- if (Array.isArray(node)) {
4119
- return node.map(function(child) {
4120
- return gen(child, options);
4121
- }).join("");
4122
- }
4123
- if (typeof node === "object") {
4124
- if (options.js && node.ts) {
4125
- return "";
4126
- }
4127
- if (!options.js && node.js) {
4256
+ function gen(root, options) {
4257
+ const updateSourceMap = options?.sourceMap?.updateSourceMap;
4258
+ return recurse(root);
4259
+ function recurse(node) {
4260
+ if (!(node != null)) {
4128
4261
  return "";
4129
4262
  }
4130
- if (node.type === "Error") {
4131
- options.errors ??= [];
4132
- options.errors.push(node);
4133
- return "";
4263
+ if (typeof node === "string") {
4264
+ updateSourceMap?.(node);
4265
+ return node;
4134
4266
  }
4135
- if (node.$loc != null) {
4136
- const { token, $loc } = node;
4137
- options?.updateSourceMap?.(token, $loc.pos);
4138
- return token;
4267
+ if (Array.isArray(node)) {
4268
+ return node.map(recurse).join("");
4139
4269
  }
4140
- if (!node.children) {
4141
- switch (node.type) {
4142
- case "Ref": {
4143
- throw new Error(`Unpopulated ref ${stringify(node)}`);
4270
+ if (typeof node === "object") {
4271
+ if (options.js && node.ts) {
4272
+ return "";
4273
+ }
4274
+ if (!options.js && node.js) {
4275
+ return "";
4276
+ }
4277
+ if (node.type === "Error") {
4278
+ const filename2 = options?.filename ?? "unknown";
4279
+ let line = "?";
4280
+ let column = "?";
4281
+ let offset;
4282
+ if (options && typeof options === "object" && "sourceMap" in options) {
4283
+ const { sourceMap } = options;
4284
+ line = sourceMap.data.srcLine + 1;
4285
+ column = sourceMap.data.srcColumn + 1;
4286
+ offset = sourceMap.data.srcOffset;
4144
4287
  }
4288
+ options.errors ??= [];
4289
+ options.errors.push(new import_lib3.ParseError(
4290
+ node.message,
4291
+ void 0,
4292
+ // body
4293
+ filename2,
4294
+ line,
4295
+ column,
4296
+ offset
4297
+ ));
4298
+ return "";
4299
+ }
4300
+ if (node.$loc != null) {
4301
+ const { token, $loc } = node;
4302
+ updateSourceMap?.(token, $loc.pos);
4303
+ return token;
4145
4304
  }
4146
- debugger;
4147
- throw new Error(`Unknown node ${stringify(node)}`);
4305
+ if (!node.children) {
4306
+ switch (node.type) {
4307
+ case "Ref": {
4308
+ throw new Error(`Unpopulated ref ${stringify(node)}`);
4309
+ }
4310
+ }
4311
+ debugger;
4312
+ throw new Error(`Unknown node ${stringify(node)}`);
4313
+ }
4314
+ return recurse(node.children);
4148
4315
  }
4149
- return gen(node.children, options);
4316
+ debugger;
4317
+ throw new Error(`Unknown node ${stringify(node)}`);
4150
4318
  }
4151
- debugger;
4152
- throw new Error(`Unknown node ${stringify(node)}`);
4153
4319
  }
4154
4320
  var generate_default = gen;
4155
4321
  function prune(node) {
@@ -4725,8 +4891,11 @@ function expressionizeBlock(blockOrExpression) {
4725
4891
  }
4726
4892
  if (results.length > 1) {
4727
4893
  return makeLeftHandSideExpression(results);
4894
+ } else if (results.length) {
4895
+ return results;
4896
+ } else {
4897
+ return ["void 0"];
4728
4898
  }
4729
- return results;
4730
4899
  } else {
4731
4900
  return blockOrExpression;
4732
4901
  }
@@ -4753,10 +4922,10 @@ function expressionizeIfStatement(statement) {
4753
4922
  children.push(":void 0");
4754
4923
  }
4755
4924
  children.push(closeParen);
4756
- return {
4925
+ return makeNode({
4757
4926
  type: "IfExpression",
4758
4927
  children
4759
- };
4928
+ });
4760
4929
  }
4761
4930
  function expressionizeTypeIf([ws, ifOp, condition, t, e]) {
4762
4931
  const children = [
@@ -5253,7 +5422,8 @@ function processAssignments(statements) {
5253
5422
  while (expr.type === "ParenthesizedExpression") {
5254
5423
  expr = expr.expression;
5255
5424
  }
5256
- if (expr.type === "AssignmentExpression" || expr.type === "UpdateExpression") {
5425
+ let m;
5426
+ if (m = expr.type, m === "AssignmentExpression" || m === "UpdateExpression") {
5257
5427
  if (expr.type === "UpdateExpression" && expr.children[0] === expr.assigned) {
5258
5428
  pre.push("(");
5259
5429
  post.push([", ", lhs, ")"]);
@@ -5267,26 +5437,31 @@ function processAssignments(statements) {
5267
5437
  return;
5268
5438
  }
5269
5439
  const pre = [], post = [];
5440
+ let ref4;
5270
5441
  switch (exp.type) {
5271
- case "AssignmentExpression":
5442
+ case "AssignmentExpression": {
5272
5443
  if (!exp.lhs)
5273
5444
  return;
5274
5445
  exp.lhs.forEach((lhsPart, i) => {
5275
- let newLhs2 = extractAssignment(lhsPart[1]);
5276
- if (newLhs2) {
5277
- return lhsPart[1] = newLhs2;
5446
+ let ref5;
5447
+ if (ref5 = extractAssignment(lhsPart[1])) {
5448
+ const newLhs = ref5;
5449
+ return lhsPart[1] = newLhs;
5278
5450
  }
5279
5451
  ;
5280
5452
  return;
5281
5453
  });
5282
5454
  break;
5283
- case "UpdateExpression":
5284
- let newLhs = extractAssignment(exp.assigned);
5285
- if (newLhs) {
5455
+ }
5456
+ case "UpdateExpression": {
5457
+ if (ref4 = extractAssignment(exp.assigned)) {
5458
+ const newLhs = ref4;
5286
5459
  const i = exp.children.indexOf(exp.assigned);
5287
5460
  exp.assigned = exp.children[i] = newLhs;
5288
5461
  }
5462
+ ;
5289
5463
  break;
5464
+ }
5290
5465
  }
5291
5466
  if (pre.length)
5292
5467
  exp.children.unshift(...pre);
@@ -5296,13 +5471,7 @@ function processAssignments(statements) {
5296
5471
  const { assigned } = exp;
5297
5472
  const ref = makeRef();
5298
5473
  const newMemberExp = unchainOptionalMemberExpression(assigned, ref, (children) => {
5299
- return exp.children.map((c) => {
5300
- if (c === assigned) {
5301
- return children;
5302
- } else {
5303
- return c;
5304
- }
5305
- });
5474
+ return exp.children.map(($) => $ === assigned ? children : $);
5306
5475
  });
5307
5476
  if (newMemberExp !== assigned) {
5308
5477
  if (newMemberExp.usesRef) {
@@ -5324,38 +5493,34 @@ function processAssignments(statements) {
5324
5493
  statements,
5325
5494
  (n) => n.type === "AssignmentExpression" && n.names === null,
5326
5495
  (exp) => {
5327
- let { lhs: $1, expression: $2 } = exp, tail = [], i = 0, len3 = $1.length;
5496
+ let { lhs: $1, expression: $2 } = exp, tail = [], len3 = $1.length;
5328
5497
  let block;
5329
- let ref4;
5330
- if (exp.parent?.type === "BlockStatement" && !(ref4 = $1[$1.length - 1])?.[ref4.length - 1]?.special) {
5498
+ let ref6;
5499
+ if (exp.parent?.type === "BlockStatement" && !(ref6 = $1[$1.length - 1])?.[ref6.length - 1]?.special) {
5331
5500
  block = makeBlockFragment();
5332
- let ref5;
5333
- if (ref5 = prependStatementExpressionBlock(
5501
+ let ref7;
5502
+ if (ref7 = prependStatementExpressionBlock(
5334
5503
  { type: "Initializer", expression: $2, children: [void 0, void 0, $2] },
5335
5504
  block
5336
5505
  )) {
5337
- const ref = ref5;
5338
- exp.children = exp.children.map(function(c) {
5339
- if (c === $2)
5340
- return ref;
5341
- else
5342
- return c;
5343
- });
5506
+ const ref = ref7;
5507
+ exp.children = exp.children.map(($3) => $3 === $2 ? ref : $3);
5344
5508
  $2 = ref;
5345
5509
  } else {
5346
5510
  block = void 0;
5347
5511
  }
5348
5512
  }
5349
- if ($1.some((left) => left[left.length - 1].special)) {
5513
+ let ref8;
5514
+ if ($1.some(($4) => (ref8 = $4)[ref8.length - 1].special)) {
5350
5515
  if ($1.length !== 1)
5351
5516
  throw new Error("Only one assignment with id= is allowed");
5352
5517
  const [, lhs, , op] = $1[0];
5353
5518
  const { call, omitLhs } = op;
5354
- const index2 = exp.children.indexOf($2);
5355
- if (index2 < 0)
5519
+ const index = exp.children.indexOf($2);
5520
+ if (index < 0)
5356
5521
  throw new Error("Assertion error: exp not in AssignmentExpression");
5357
5522
  exp.children.splice(
5358
- index2,
5523
+ index,
5359
5524
  1,
5360
5525
  exp.expression = $2 = [call, "(", lhs, ", ", $2, ")"]
5361
5526
  );
@@ -5364,12 +5529,15 @@ function processAssignments(statements) {
5364
5529
  }
5365
5530
  }
5366
5531
  let wrapped = false;
5532
+ let i = 0;
5367
5533
  while (i < len3) {
5368
5534
  const lastAssignment = $1[i++];
5369
5535
  const [, lhs, , op] = lastAssignment;
5370
- if (op.token !== "=")
5536
+ if (!(op.token === "=")) {
5371
5537
  continue;
5372
- if (lhs.type === "ObjectExpression" || lhs.type === "ObjectBindingPattern") {
5538
+ }
5539
+ let m1;
5540
+ if (m1 = lhs.type, m1 === "ObjectExpression" || m1 === "ObjectBindingPattern") {
5373
5541
  if (!wrapped) {
5374
5542
  wrapped = true;
5375
5543
  lhs.children.splice(0, 0, "(");
@@ -5382,6 +5550,7 @@ function processAssignments(statements) {
5382
5550
  const lastAssignment = $1[i];
5383
5551
  if (lastAssignment[3].token === "=") {
5384
5552
  const lhs = lastAssignment[1];
5553
+ let m2;
5385
5554
  if (lhs.type === "MemberExpression") {
5386
5555
  const members = lhs.children;
5387
5556
  const lastMember = members[members.length - 1];
@@ -5405,9 +5574,9 @@ function processAssignments(statements) {
5405
5574
  }
5406
5575
  exp.children = [$1];
5407
5576
  exp.names = [];
5408
- return exp;
5577
+ break;
5409
5578
  }
5410
- } else if (lhs.type === "ObjectBindingPattern" || lhs.type === "ArrayBindingPattern") {
5579
+ } else if (m2 = lhs.type, m2 === "ObjectBindingPattern" || m2 === "ArrayBindingPattern") {
5411
5580
  processBindingPatternLHS(lhs, tail);
5412
5581
  }
5413
5582
  }
@@ -5440,10 +5609,12 @@ function processAssignments(statements) {
5440
5609
  i--;
5441
5610
  }
5442
5611
  exp.names = $1.flatMap(([, l]) => l.names || []);
5443
- const index = exp.children.indexOf($2);
5444
- if (index < 0)
5445
- throw new Error("Assertion error: exp not in AssignmentExpression");
5446
- exp.children.splice(index + 1, 0, ...tail);
5612
+ if (tail.length) {
5613
+ const index = exp.children.indexOf($2);
5614
+ if (index < 0)
5615
+ throw new Error("Assertion error: exp not in AssignmentExpression");
5616
+ exp.children.splice(index + 1, 0, ...tail);
5617
+ }
5447
5618
  if (block) {
5448
5619
  block.parent = exp.parent;
5449
5620
  block.expressions.push(["", exp]);
@@ -5502,9 +5673,9 @@ function unchainOptionalMemberExpression(exp, ref, innerExp) {
5502
5673
  }
5503
5674
  j++;
5504
5675
  }
5505
- let ref6;
5506
- if (ref6 = conditions.length) {
5507
- const l = ref6;
5676
+ let ref9;
5677
+ if (ref9 = conditions.length) {
5678
+ const l = ref9;
5508
5679
  const cs = flatJoin(conditions, " && ");
5509
5680
  return {
5510
5681
  ...exp,
@@ -5541,8 +5712,8 @@ function processTypes(node) {
5541
5712
  return gatherRecursiveAll(node, (n) => n.type === "UnaryType").forEach((unary) => {
5542
5713
  let last;
5543
5714
  let count = 0;
5544
- let ref7;
5545
- while (unary.suffix.length && (ref7 = unary.suffix)[ref7.length - 1]?.token === "?") {
5715
+ let ref10;
5716
+ while (unary.suffix.length && (ref10 = unary.suffix)[ref10.length - 1]?.token === "?") {
5546
5717
  last = unary.suffix.pop();
5547
5718
  count++;
5548
5719
  }
@@ -5573,14 +5744,14 @@ function processTypes(node) {
5573
5744
  });
5574
5745
  }
5575
5746
  function processStatementExpressions(statements) {
5576
- gatherRecursiveAll(statements, ($) => $.type === "StatementExpression").forEach((_exp) => {
5747
+ gatherRecursiveAll(statements, ($5) => $5.type === "StatementExpression").forEach((_exp) => {
5577
5748
  const exp = _exp;
5578
5749
  const { statement } = exp;
5579
- let ref8;
5750
+ let ref11;
5580
5751
  switch (statement.type) {
5581
5752
  case "IfStatement": {
5582
- if (ref8 = expressionizeIfStatement(statement)) {
5583
- const expression = ref8;
5753
+ if (ref11 = expressionizeIfStatement(statement)) {
5754
+ const expression = ref11;
5584
5755
  return replaceNode(statement, expression, exp);
5585
5756
  } else {
5586
5757
  return replaceNode(statement, wrapIIFE([["", statement]]), exp);
@@ -5622,7 +5793,7 @@ function processNegativeIndexAccess(statements) {
5622
5793
  }
5623
5794
  } else if (index > start + 1) {
5624
5795
  ref = makeRef();
5625
- subexp = children.splice(start, index);
5796
+ subexp = children.splice(start, index - start);
5626
5797
  } else {
5627
5798
  throw new Error("Invalid parse tree for negative index access");
5628
5799
  }
@@ -5631,7 +5802,7 @@ function processNegativeIndexAccess(statements) {
5631
5802
  exp.hoistDec = hoistDec;
5632
5803
  children.splice(start, 0, makeLeftHandSideExpression(refAssignment));
5633
5804
  }
5634
- return exp.len.children = [
5805
+ exp.len.children = [
5635
5806
  ref,
5636
5807
  ".length"
5637
5808
  ];
@@ -5703,11 +5874,11 @@ function populateRefs(statements) {
5703
5874
  function processPlaceholders(statements) {
5704
5875
  const placeholderMap = /* @__PURE__ */ new Map();
5705
5876
  const liftedIfs = /* @__PURE__ */ new Set();
5706
- gatherRecursiveAll(statements, ($3) => $3.type === "Placeholder").forEach((_exp) => {
5877
+ gatherRecursiveAll(statements, ($6) => $6.type === "Placeholder").forEach((_exp) => {
5707
5878
  const exp = _exp;
5708
5879
  let ancestor;
5709
5880
  if (exp.subtype === ".") {
5710
- ({ ancestor } = findAncestor(exp, ($4) => $4.type === "Call"));
5881
+ ({ ancestor } = findAncestor(exp, ($7) => $7.type === "Call"));
5711
5882
  ancestor = ancestor?.parent;
5712
5883
  while (ancestor?.parent?.type === "UnaryExpression" || ancestor?.parent?.type === "NewExpression") {
5713
5884
  ancestor = ancestor.parent;
@@ -5726,10 +5897,10 @@ function processPlaceholders(statements) {
5726
5897
  if (type === "IfStatement") {
5727
5898
  liftedIfs.add(ancestor2);
5728
5899
  }
5729
- let m;
5730
- let m1;
5900
+ let m3;
5901
+ let m4;
5731
5902
  return type === "Call" || // Block, except for if/else blocks when condition already lifted
5732
- type === "BlockStatement" && !((m = ancestor2.parent, typeof m === "object" && m != null && "type" in m && m.type === "IfStatement") && liftedIfs.has(ancestor2.parent)) && !((m1 = ancestor2.parent, typeof m1 === "object" && m1 != null && "type" in m1 && m1.type === "ElseClause" && "parent" in m1 && typeof m1.parent === "object" && m1.parent != null && "type" in m1.parent && m1.parent.type === "IfStatement") && liftedIfs.has(ancestor2.parent.parent)) || type === "PipelineExpression" || // Declaration
5903
+ type === "BlockStatement" && !((m3 = ancestor2.parent, typeof m3 === "object" && m3 != null && "type" in m3 && m3.type === "IfStatement") && liftedIfs.has(ancestor2.parent)) && !((m4 = ancestor2.parent, typeof m4 === "object" && m4 != null && "type" in m4 && m4.type === "ElseClause" && "parent" in m4 && typeof m4.parent === "object" && m4.parent != null && "type" in m4.parent && m4.parent.type === "IfStatement") && liftedIfs.has(ancestor2.parent.parent)) || type === "PipelineExpression" || // Declaration
5733
5904
  type === "Initializer" || // Right-hand side of assignment
5734
5905
  type === "AssignmentExpression" && findChildIndex(ancestor2, child2) === ancestor2.children.indexOf(ancestor2.expression) || type === "ReturnStatement" || type === "YieldExpression";
5735
5906
  }));
@@ -5808,8 +5979,8 @@ function processPlaceholders(statements) {
5808
5979
  for (let i4 = 0, len3 = placeholders.length; i4 < len3; i4++) {
5809
5980
  const placeholder = placeholders[i4];
5810
5981
  typeSuffix ??= placeholder.typeSuffix;
5811
- let ref9;
5812
- replaceNode((ref9 = placeholder.children)[ref9.length - 1], ref);
5982
+ let ref12;
5983
+ replaceNode((ref12 = placeholder.children)[ref12.length - 1], ref);
5813
5984
  }
5814
5985
  const { parent } = ancestor;
5815
5986
  const body = maybeUnwrap(ancestor);
@@ -5840,9 +6011,9 @@ function processPlaceholders(statements) {
5840
6011
  fnExp = makeLeftHandSideExpression(fnExp);
5841
6012
  }
5842
6013
  replaceNode(ancestor, fnExp, parent);
5843
- let ref10;
5844
- if (ref10 = getTrimmingSpace(body)) {
5845
- const ws = ref10;
6014
+ let ref13;
6015
+ if (ref13 = getTrimmingSpace(body)) {
6016
+ const ws = ref13;
5846
6017
  inplaceInsertTrimmingSpace(body, "");
5847
6018
  inplacePrepend(ws, fnExp);
5848
6019
  }
@@ -5867,43 +6038,39 @@ function reorderBindingRestProperty(props) {
5867
6038
  children: props,
5868
6039
  names
5869
6040
  };
5870
- } else if (restCount === 1) {
5871
- let after = props.slice(restIndex + 1);
5872
- let rest = props[restIndex];
5873
- props = props.slice(0, restIndex);
5874
- if (after.length) {
5875
- const { delim: restDelim } = rest, lastAfterProp = after[after.length - 1], { delim: lastDelim, children: lastAfterChildren } = lastAfterProp;
5876
- rest = {
5877
- ...rest,
5878
- delim: lastDelim,
5879
- children: [...rest.children.slice(0, -1), lastDelim]
5880
- };
5881
- after = [
5882
- ...after.slice(0, -1),
5883
- {
5884
- ...lastAfterProp,
5885
- delim: restDelim,
5886
- children: [...lastAfterChildren.slice(0, -1), restDelim]
5887
- }
5888
- ];
5889
- }
5890
- let ref11;
5891
- if (Array.isArray(rest.delim) && (ref11 = rest.delim)[ref11.length - 1]?.token === ",") {
5892
- rest.delim = rest.delim.slice(0, -1);
5893
- rest.children = [...rest.children.slice(0, -1), rest.delim];
5894
- }
5895
- const children = [...props, ...after, rest];
5896
- return {
5897
- children,
5898
- names
6041
+ }
6042
+ let after = props.slice(restIndex + 1);
6043
+ let rest = props[restIndex];
6044
+ props = props.slice(0, restIndex);
6045
+ if (after.length) {
6046
+ const { delim: restDelim } = rest, lastAfterProp = after[after.length - 1], { delim: lastDelim, children: lastAfterChildren } = lastAfterProp;
6047
+ rest = {
6048
+ ...rest,
6049
+ delim: lastDelim,
6050
+ children: [...rest.children.slice(0, -1), lastDelim]
5899
6051
  };
6052
+ after = [
6053
+ ...after.slice(0, -1),
6054
+ {
6055
+ ...lastAfterProp,
6056
+ delim: restDelim,
6057
+ children: [...lastAfterChildren.slice(0, -1), restDelim]
6058
+ }
6059
+ ];
5900
6060
  }
5901
- return {
5902
- children: [{
6061
+ let ref14;
6062
+ if (Array.isArray(rest.delim) && (ref14 = rest.delim)[ref14.length - 1]?.token === ",") {
6063
+ rest.delim = rest.delim.slice(0, -1);
6064
+ rest.children = [...rest.children.slice(0, -1), rest.delim];
6065
+ }
6066
+ const children = [...props, ...after, rest];
6067
+ if (restCount > 1) {
6068
+ children.push({
5903
6069
  type: "Error",
5904
6070
  message: "Multiple rest properties in object pattern"
5905
- }, props]
5906
- };
6071
+ });
6072
+ }
6073
+ return { children, names };
5907
6074
  }
5908
6075
  function replaceNodes(root, predicate, replacer) {
5909
6076
  if (!(root != null)) {
@@ -6086,6 +6253,7 @@ var grammar = {
6086
6253
  YieldExpression,
6087
6254
  ArrowFunction,
6088
6255
  FatArrow,
6256
+ FatArrowToken,
6089
6257
  TrailingDeclaration,
6090
6258
  TrailingPipe,
6091
6259
  FatArrowBody,
@@ -6206,9 +6374,11 @@ var grammar = {
6206
6374
  NoCommaBracedOrEmptyBlock,
6207
6375
  NoPostfixBracedOrEmptyBlock,
6208
6376
  EmptyBlock,
6377
+ BlockOrEmptyStatement,
6209
6378
  BlockOrEmpty,
6210
- EmptyBareBlock,
6211
6379
  EmptyStatementBareBlock,
6380
+ EmptyBareBlock,
6381
+ NoBlock,
6212
6382
  BracedBlock,
6213
6383
  NoPostfixBracedBlock,
6214
6384
  NoCommaBracedBlock,
@@ -7227,13 +7397,14 @@ function ExpressionizedStatement(ctx, state2) {
7227
7397
  }
7228
7398
  var StatementExpression$0 = DebuggerStatement;
7229
7399
  var StatementExpression$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(IfStatement), function($skip, $loc, $0, $1) {
7230
- if (!$1.else && isEmptyBareBlock($1.then))
7400
+ if (!$1.else && $1.then.implicit)
7231
7401
  return $skip;
7232
7402
  return $1;
7233
7403
  });
7234
7404
  var StatementExpression$2 = (0, import_lib3.$TS)((0, import_lib3.$S)(IterationExpression), function($skip, $loc, $0, $1) {
7235
- if (isEmptyBareBlock($1.block))
7405
+ if ($1.block.implicit && $1.subtype !== "DoStatement" && $1.subtype !== "ComptimeStatement") {
7236
7406
  return $skip;
7407
+ }
7237
7408
  return $1;
7238
7409
  });
7239
7410
  var StatementExpression$3 = SwitchStatement;
@@ -7324,7 +7495,7 @@ var ForbiddenImplicitCalls$6 = (0, import_lib3.$TS)((0, import_lib3.$S)(OmittedN
7324
7495
  return $0;
7325
7496
  return $skip;
7326
7497
  });
7327
- var ForbiddenImplicitCalls$7 = (0, import_lib3.$S)(PostfixStatement, EmptyStatementBareBlock);
7498
+ var ForbiddenImplicitCalls$7 = (0, import_lib3.$S)(PostfixStatement, NoBlock);
7328
7499
  var ForbiddenImplicitCalls$8 = (0, import_lib3.$EXPECT)($L5, 'ForbiddenImplicitCalls "... "');
7329
7500
  var ForbiddenImplicitCalls$$ = [ForbiddenImplicitCalls$0, ForbiddenImplicitCalls$1, ForbiddenImplicitCalls$2, ForbiddenImplicitCalls$3, ForbiddenImplicitCalls$4, ForbiddenImplicitCalls$5, ForbiddenImplicitCalls$6, ForbiddenImplicitCalls$7, ForbiddenImplicitCalls$8];
7330
7501
  function ForbiddenImplicitCalls(ctx, state2) {
@@ -7549,11 +7720,10 @@ var UnaryExpression$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3
7549
7720
  var post = $3;
7550
7721
  return processUnaryExpression(pre, exp, post);
7551
7722
  });
7552
- var UnaryExpression$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(CoffeeDoEnabled, Do, __, (0, import_lib3.$C)((0, import_lib3.$S)(LeftHandSideExpression, (0, import_lib3.$N)((0, import_lib3.$S)(__, AssignmentOpSymbol))), ArrowFunction, ExtendedExpression)), function($skip, $loc, $0, $1, $2, $3, $4) {
7723
+ var UnaryExpression$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(CoffeeDoEnabled, Do, __, (0, import_lib3.$C)(ArrowFunction, (0, import_lib3.$S)(LeftHandSideExpression, (0, import_lib3.$N)((0, import_lib3.$S)(__, AssignmentOpSymbol))), ExtendedExpression)), function($skip, $loc, $0, $1, $2, $3, $4) {
7553
7724
  var ws = $3;
7554
7725
  var exp = $4;
7555
- ws = insertTrimmingSpace(ws, "");
7556
- return ["(", ...ws, exp, ")()"];
7726
+ return processCoffeeDo(ws, exp);
7557
7727
  });
7558
7728
  var UnaryExpression$$ = [UnaryExpression$0, UnaryExpression$1];
7559
7729
  function UnaryExpression(ctx, state2) {
@@ -7775,17 +7945,10 @@ var ArrowFunction$1 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$
7775
7945
  var async = $1;
7776
7946
  var parameters = $2;
7777
7947
  var suffix = $3;
7948
+ var arrow = $4;
7778
7949
  var expOrBlock = $5;
7779
- if (hasAwait(expOrBlock) && !async) {
7780
- async = "async ";
7781
- }
7782
- let error;
7783
- if (hasYield(expOrBlock)) {
7784
- error = {
7785
- type: "Error",
7786
- message: "Can't use yield inside of => arrow function"
7787
- };
7788
- }
7950
+ if (!async)
7951
+ async = [];
7789
7952
  return {
7790
7953
  type: "ArrowFunction",
7791
7954
  signature: {
@@ -7796,25 +7959,31 @@ var ArrowFunction$1 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$
7796
7959
  },
7797
7960
  parameters,
7798
7961
  returnType: suffix,
7799
- ts: false,
7800
7962
  async,
7801
7963
  block: expOrBlock,
7802
- children: [async, $0.slice(1), error]
7964
+ children: [async, parameters, suffix, arrow, expOrBlock]
7803
7965
  };
7804
7966
  });
7805
7967
  var ArrowFunction$$ = [ArrowFunction$0, ArrowFunction$1];
7806
7968
  function ArrowFunction(ctx, state2) {
7807
7969
  return (0, import_lib3.$EVENT_C)(ctx, state2, "ArrowFunction", ArrowFunction$$);
7808
7970
  }
7809
- var FatArrow$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$E)(_), (0, import_lib3.$C)((0, import_lib3.$EXPECT)($L13, 'FatArrow "=>"'), (0, import_lib3.$EXPECT)($L14, 'FatArrow "\u21D2"'))), function($skip, $loc, $0, $1, $2) {
7971
+ var FatArrow$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$E)(_), FatArrowToken), function($skip, $loc, $0, $1, $2) {
7810
7972
  var ws = $1;
7973
+ var arrow = $2;
7811
7974
  if (!ws)
7812
- return " =>";
7813
- return [$1, "=>"];
7975
+ ws = " ";
7976
+ return [ws, arrow];
7814
7977
  });
7815
7978
  function FatArrow(ctx, state2) {
7816
7979
  return (0, import_lib3.$EVENT)(ctx, state2, "FatArrow", FatArrow$0);
7817
7980
  }
7981
+ 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) {
7982
+ return { $loc, token: "=>" };
7983
+ });
7984
+ function FatArrowToken(ctx, state2) {
7985
+ return (0, import_lib3.$EVENT)(ctx, state2, "FatArrowToken", FatArrowToken$0);
7986
+ }
7818
7987
  var TrailingDeclaration$0 = (0, import_lib3.$S)((0, import_lib3.$E)(_), (0, import_lib3.$C)(ConstAssignment, LetAssignment));
7819
7988
  function TrailingDeclaration(ctx, state2) {
7820
7989
  return (0, import_lib3.$EVENT)(ctx, state2, "TrailingDeclaration", TrailingDeclaration$0);
@@ -8326,7 +8495,13 @@ var ThisLiteral$2 = (0, import_lib3.$TS)((0, import_lib3.$S)(AtThis, (0, import_
8326
8495
  children: [at, {
8327
8496
  type: "PropertyAccess",
8328
8497
  name: id,
8329
- children: [".", id]
8498
+ children: [".", {
8499
+ $loc: {
8500
+ pos: $loc.pos + 1,
8501
+ length: $loc.length - 1
8502
+ },
8503
+ token: id
8504
+ }]
8330
8505
  }],
8331
8506
  thisShorthand: true
8332
8507
  };
@@ -8998,11 +9173,17 @@ function FunctionRestParameter(ctx, state2) {
8998
9173
  var ParameterElement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$E)(_), (0, import_lib3.$E)(AccessModifier), (0, import_lib3.$E)(_), (0, import_lib3.$C)(NWBindingIdentifier, BindingPattern), (0, import_lib3.$E)(TypeSuffix), (0, import_lib3.$E)(Initializer), ParameterElementDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
8999
9174
  var accessModifier = $2;
9000
9175
  var binding = $4;
9176
+ var typeSuffix = $5;
9177
+ var initializer = $6;
9178
+ var delim = $7;
9001
9179
  return {
9002
9180
  type: "Parameter",
9003
9181
  children: $0,
9004
9182
  names: binding.names,
9005
- accessModifier
9183
+ typeSuffix,
9184
+ accessModifier,
9185
+ initializer,
9186
+ delim
9006
9187
  };
9007
9188
  });
9008
9189
  function ParameterElement(ctx, state2) {
@@ -9417,7 +9598,6 @@ var FunctionSignature$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_li
9417
9598
  name: id?.name,
9418
9599
  parameters,
9419
9600
  returnType: suffix,
9420
- ts: false,
9421
9601
  async,
9422
9602
  generator,
9423
9603
  modifier: {
@@ -9443,14 +9623,6 @@ var FunctionExpression$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(FunctionSign
9443
9623
  ts: true
9444
9624
  };
9445
9625
  }
9446
- if (hasAwait(block) && !signature.async.length) {
9447
- signature.async.push("async ");
9448
- signature.modifier.async = true;
9449
- }
9450
- if (hasYield(block) && !signature.generator.length) {
9451
- signature.generator.push("*");
9452
- signature.modifier.generator = true;
9453
- }
9454
9626
  return {
9455
9627
  ...signature,
9456
9628
  type: "FunctionExpression",
@@ -9622,15 +9794,21 @@ var OperatorDeclaration$$ = [OperatorDeclaration$0, OperatorDeclaration$1, Opera
9622
9794
  function OperatorDeclaration(ctx, state2) {
9623
9795
  return (0, import_lib3.$EVENT_C)(ctx, state2, "OperatorDeclaration", OperatorDeclaration$$);
9624
9796
  }
9625
- 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) {
9626
- var op = $1;
9627
- var func = $2;
9628
- var w1 = $3;
9629
- var id = $4;
9630
- var behavior = $5;
9631
- var w2 = $6;
9632
- var parameters = $7;
9633
- var suffix = $8;
9797
+ 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) {
9798
+ var async = $1;
9799
+ var op = $2;
9800
+ var func = $3;
9801
+ var generator = $4;
9802
+ var w1 = $5;
9803
+ var id = $6;
9804
+ var behavior = $7;
9805
+ var w2 = $8;
9806
+ var parameters = $9;
9807
+ var suffix = $10;
9808
+ if (!async)
9809
+ async = [];
9810
+ if (!generator)
9811
+ generator = [];
9634
9812
  if (!func) {
9635
9813
  func = { $loc: op.$loc, token: "function" };
9636
9814
  } else {
@@ -9639,12 +9817,17 @@ var OperatorSignature$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Operator, (0,
9639
9817
  return {
9640
9818
  type: "FunctionSignature",
9641
9819
  id,
9642
- modifier: {},
9820
+ name: id.name,
9643
9821
  parameters,
9644
9822
  returnType: suffix,
9645
- ts: false,
9823
+ async,
9824
+ generator,
9825
+ modifier: {
9826
+ async: !!async.length,
9827
+ generator: !!generator.length
9828
+ },
9646
9829
  block: null,
9647
- children: [func, w1, id, w2, parameters, suffix],
9830
+ children: [async, func, generator, w1, id, w2, parameters, suffix],
9648
9831
  behavior
9649
9832
  };
9650
9833
  });
@@ -9694,27 +9877,24 @@ var ThinArrowFunction$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_li
9694
9877
  var suffix = $3;
9695
9878
  var arrow = $5;
9696
9879
  var block = $6;
9697
- if (hasAwait(block) && !async) {
9698
- async = "async ";
9699
- }
9700
- let generator;
9701
- if (hasYield(block)) {
9702
- generator = "*";
9703
- }
9880
+ if (!async)
9881
+ async = [];
9882
+ const generator = [];
9704
9883
  return {
9705
9884
  type: "FunctionExpression",
9706
9885
  id: void 0,
9707
9886
  parameters,
9708
9887
  returnType: suffix,
9709
- ts: false,
9710
9888
  async,
9711
9889
  generator,
9712
9890
  block,
9713
9891
  signature: {
9714
9892
  name: void 0,
9893
+ async,
9894
+ generator,
9715
9895
  modifier: {
9716
- async: !!async,
9717
- generator: !!generator
9896
+ async: !!async.length,
9897
+ generator: !!generator.length
9718
9898
  },
9719
9899
  returnType: suffix
9720
9900
  },
@@ -9864,43 +10044,62 @@ var EmptyBlock$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(InsertOpenBrace, Ins
9864
10044
  expressions,
9865
10045
  children: [$1, expressions, $2],
9866
10046
  bare: false,
9867
- empty: true
10047
+ empty: true,
10048
+ implicit: true
9868
10049
  };
9869
10050
  });
9870
10051
  function EmptyBlock(ctx, state2) {
9871
10052
  return (0, import_lib3.$EVENT)(ctx, state2, "EmptyBlock", EmptyBlock$0);
9872
10053
  }
10054
+ var BlockOrEmptyStatement$0 = Block;
10055
+ var BlockOrEmptyStatement$1 = (0, import_lib3.$T)((0, import_lib3.$S)(NoBlock, EmptyStatementBareBlock), function(value) {
10056
+ return value[1];
10057
+ });
10058
+ var BlockOrEmptyStatement$$ = [BlockOrEmptyStatement$0, BlockOrEmptyStatement$1];
10059
+ function BlockOrEmptyStatement(ctx, state2) {
10060
+ return (0, import_lib3.$EVENT_C)(ctx, state2, "BlockOrEmptyStatement", BlockOrEmptyStatement$$);
10061
+ }
9873
10062
  var BlockOrEmpty$0 = Block;
9874
- var BlockOrEmpty$1 = EmptyStatementBareBlock;
10063
+ var BlockOrEmpty$1 = (0, import_lib3.$T)((0, import_lib3.$S)(NoBlock, EmptyBlock), function(value) {
10064
+ return value[1];
10065
+ });
9875
10066
  var BlockOrEmpty$$ = [BlockOrEmpty$0, BlockOrEmpty$1];
9876
10067
  function BlockOrEmpty(ctx, state2) {
9877
10068
  return (0, import_lib3.$EVENT_C)(ctx, state2, "BlockOrEmpty", BlockOrEmpty$$);
9878
10069
  }
9879
- var EmptyBareBlock$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L0, 'EmptyBareBlock ""'), function($skip, $loc, $0, $1) {
9880
- const expressions = [];
10070
+ var EmptyStatementBareBlock$0 = (0, import_lib3.$TV)(InsertEmptyStatement, function($skip, $loc, $0, $1) {
10071
+ var s = $0;
10072
+ const expressions = [["", s]];
9881
10073
  return {
9882
10074
  type: "BlockStatement",
9883
10075
  expressions,
9884
10076
  children: [expressions],
9885
- bare: true
10077
+ bare: true,
10078
+ empty: true,
10079
+ implicit: true,
10080
+ semicolon: s.children[0]
9886
10081
  };
9887
10082
  });
9888
- function EmptyBareBlock(ctx, state2) {
9889
- return (0, import_lib3.$EVENT)(ctx, state2, "EmptyBareBlock", EmptyBareBlock$0);
10083
+ function EmptyStatementBareBlock(ctx, state2) {
10084
+ return (0, import_lib3.$EVENT)(ctx, state2, "EmptyStatementBareBlock", EmptyStatementBareBlock$0);
9890
10085
  }
9891
- var EmptyStatementBareBlock$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$Y)(EOS), (0, import_lib3.$N)(IndentedFurther), InsertEmptyStatement), function($skip, $loc, $0, $1, $2, $3) {
9892
- var s = $3;
9893
- const expressions = [["", s]];
10086
+ var EmptyBareBlock$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L0, 'EmptyBareBlock ""'), function($skip, $loc, $0, $1) {
10087
+ const expressions = [];
9894
10088
  return {
9895
10089
  type: "BlockStatement",
9896
10090
  expressions,
9897
10091
  children: [expressions],
9898
10092
  bare: true,
9899
- semicolon: s.children[0]
10093
+ empty: true,
10094
+ implicit: true
9900
10095
  };
9901
10096
  });
9902
- function EmptyStatementBareBlock(ctx, state2) {
9903
- return (0, import_lib3.$EVENT)(ctx, state2, "EmptyStatementBareBlock", EmptyStatementBareBlock$0);
10097
+ function EmptyBareBlock(ctx, state2) {
10098
+ return (0, import_lib3.$EVENT)(ctx, state2, "EmptyBareBlock", EmptyBareBlock$0);
10099
+ }
10100
+ var NoBlock$0 = (0, import_lib3.$S)((0, import_lib3.$Y)(EOS), (0, import_lib3.$N)(IndentedFurther));
10101
+ function NoBlock(ctx, state2) {
10102
+ return (0, import_lib3.$EVENT)(ctx, state2, "NoBlock", NoBlock$0);
9904
10103
  }
9905
10104
  var BracedBlock$0 = NonSingleBracedBlock;
9906
10105
  var BracedBlock$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(InsertOpenBrace, (0, import_lib3.$N)(EOS), PostfixedSingleLineStatements, InsertSpace, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
@@ -11752,7 +11951,7 @@ var IterationExpression$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_
11752
11951
  function IterationExpression(ctx, state2) {
11753
11952
  return (0, import_lib3.$EVENT)(ctx, state2, "IterationExpression", IterationExpression$0);
11754
11953
  }
11755
- var LoopStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(LoopClause, BlockOrEmpty), function($skip, $loc, $0, $1, $2) {
11954
+ var LoopStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(LoopClause, BlockOrEmptyStatement), function($skip, $loc, $0, $1, $2) {
11756
11955
  var clause = $1;
11757
11956
  var block = $2;
11758
11957
  return {
@@ -11830,7 +12029,7 @@ var ComptimeStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Comptime, NoP
11830
12029
  function ComptimeStatement(ctx, state2) {
11831
12030
  return (0, import_lib3.$EVENT)(ctx, state2, "ComptimeStatement", ComptimeStatement$0);
11832
12031
  }
11833
- var WhileStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(WhileClause, BlockOrEmpty), function($skip, $loc, $0, $1, $2) {
12032
+ var WhileStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(WhileClause, BlockOrEmptyStatement), function($skip, $loc, $0, $1, $2) {
11834
12033
  var clause = $1;
11835
12034
  var block = $2;
11836
12035
  return {
@@ -11861,7 +12060,7 @@ var WhileClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$C)
11861
12060
  function WhileClause(ctx, state2) {
11862
12061
  return (0, import_lib3.$EVENT)(ctx, state2, "WhileClause", WhileClause$0);
11863
12062
  }
11864
- var ForStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(ForClause, BlockOrEmpty), function($skip, $loc, $0, $1, $2) {
12063
+ var ForStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(ForClause, BlockOrEmptyStatement), function($skip, $loc, $0, $1, $2) {
11865
12064
  var clause = $1;
11866
12065
  var block = $2;
11867
12066
  block = blockWithPrefix(clause.blockPrefix, block);
@@ -16439,34 +16638,22 @@ function parseProgram(input, options) {
16439
16638
  }
16440
16639
  }
16441
16640
 
16442
- // source/util.civet
16443
- var util_exports = {};
16444
- __export(util_exports, {
16641
+ // source/sourcemap.civet
16642
+ var sourcemap_exports = {};
16643
+ __export(sourcemap_exports, {
16445
16644
  SourceMap: () => SourceMap,
16446
16645
  base64Encode: () => base64Encode,
16447
16646
  locationTable: () => locationTable,
16448
16647
  lookupLineColumn: () => lookupLineColumn
16449
16648
  });
16450
- var smRegexp;
16451
- var prettySourceExcerpt;
16452
- var VLQ_SHIFT;
16453
- var VLQ_CONTINUATION_BIT;
16454
- var VLQ_VALUE_MASK;
16455
- var encodeVlq;
16456
- var BASE64_CHARS;
16457
- var encodeBase64;
16458
- var vlqTable;
16459
- var vlqChars;
16460
- var decodeError;
16461
- var decodeVLQ;
16462
- var remapPosition;
16463
16649
  var locationTable = function(input) {
16464
- var linesRe, lines, line, pos, result;
16465
- linesRe = /([^\r\n]*)(\r\n|\r|\n|$)/y;
16466
- lines = [];
16467
- line = 0;
16468
- pos = 0;
16469
- while (result = linesRe.exec(input)) {
16650
+ const linesRe = /([^\r\n]*)(\r\n|\r|\n|$)/y;
16651
+ const lines = [];
16652
+ let line = 0;
16653
+ let pos = 0;
16654
+ let ref;
16655
+ while (ref = linesRe.exec(input)) {
16656
+ const result = ref;
16470
16657
  pos += result[0].length;
16471
16658
  lines[line++] = pos;
16472
16659
  if (pos === input.length) {
@@ -16476,39 +16663,39 @@ var locationTable = function(input) {
16476
16663
  return lines;
16477
16664
  };
16478
16665
  var lookupLineColumn = function(table, pos) {
16479
- var l, prevEnd;
16480
- l = 0;
16481
- prevEnd = 0;
16666
+ let l = 0;
16667
+ let prevEnd = 0;
16482
16668
  while (table[l] <= pos) {
16483
16669
  prevEnd = table[l++];
16484
16670
  }
16485
16671
  return [l, pos - prevEnd];
16486
16672
  };
16487
16673
  var SourceMap = function(sourceString) {
16488
- var srcTable, sm, EOL2;
16489
- srcTable = locationTable(sourceString);
16490
- sm = {
16674
+ const srcTable = locationTable(sourceString);
16675
+ const sm = {
16491
16676
  lines: [[]],
16492
- lineNum: 0,
16677
+ line: 0,
16493
16678
  colOffset: 0,
16679
+ // relative to previous entry
16680
+ srcLine: 0,
16681
+ srcColumn: 0,
16682
+ srcOffset: 0,
16494
16683
  srcTable
16495
16684
  };
16496
- EOL2 = /\r?\n|\r/;
16685
+ const EOL2 = /\r?\n|\r/;
16497
16686
  return {
16498
16687
  data: sm,
16499
16688
  source: function() {
16500
16689
  return sourceString;
16501
16690
  },
16502
16691
  renderMappings: function() {
16503
- var lastSourceLine, lastSourceColumn;
16504
- lastSourceLine = 0;
16505
- lastSourceColumn = 0;
16506
- return sm.lines.map(function(line) {
16507
- return line.map(function(entry) {
16508
- var colDelta, sourceFileIndex, srcLine, srcCol, lineDelta;
16692
+ let lastSourceLine = 0;
16693
+ let lastSourceColumn = 0;
16694
+ return sm.lines.map((line) => {
16695
+ return line.map((entry) => {
16509
16696
  if (entry.length === 4) {
16510
- [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16511
- lineDelta = srcLine - lastSourceLine;
16697
+ let [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16698
+ const lineDelta = srcLine - lastSourceLine;
16512
16699
  colDelta = srcCol - lastSourceColumn;
16513
16700
  lastSourceLine = srcLine;
16514
16701
  lastSourceColumn = srcCol;
@@ -16532,102 +16719,69 @@ var SourceMap = function(sourceString) {
16532
16719
  }
16533
16720
  };
16534
16721
  },
16535
- updateSourceMap: function(outputStr, inputPos) {
16536
- var outLines, srcLine, srcCol;
16537
- outLines = outputStr.split(EOL2);
16722
+ updateSourceMap: function(outputStr, inputPos, colOffset = 0) {
16723
+ const outLines = outputStr.split(EOL2);
16724
+ let srcLine, srcCol;
16538
16725
  if (inputPos != null) {
16539
16726
  [srcLine, srcCol] = lookupLineColumn(srcTable, inputPos);
16727
+ srcCol += colOffset;
16728
+ sm.srcLine = srcLine;
16729
+ sm.srcColumn = srcCol;
16730
+ sm.srcOffset = inputPos + outputStr.length;
16540
16731
  }
16541
- outLines.forEach(function(line, i) {
16542
- var l;
16732
+ for (let i1 = 0, len3 = outLines.length; i1 < len3; i1++) {
16733
+ const i = i1;
16734
+ const line = outLines[i1];
16543
16735
  if (i > 0) {
16544
- sm.lineNum++;
16736
+ sm.line++;
16737
+ sm.srcLine++;
16545
16738
  sm.colOffset = 0;
16546
- sm.lines[sm.lineNum] = [];
16547
- srcCol = 0;
16739
+ sm.lines[sm.line] = [];
16740
+ sm.srcColumn = srcCol = colOffset;
16548
16741
  }
16549
- l = sm.colOffset;
16742
+ const l = sm.colOffset;
16550
16743
  sm.colOffset = line.length;
16744
+ sm.srcColumn += line.length;
16551
16745
  if (inputPos != null) {
16552
- return sm.lines[sm.lineNum].push([l, 0, srcLine + i, srcCol]);
16553
- } else if (l !== 0) {
16554
- return sm.lines[sm.lineNum].push([l]);
16746
+ sm.lines[sm.line].push([l, 0, srcLine + i, srcCol]);
16747
+ } else if (l != 0) {
16748
+ sm.lines[sm.line].push([l]);
16555
16749
  }
16556
- ;
16557
- return;
16558
- });
16750
+ }
16559
16751
  return;
16560
16752
  }
16561
16753
  };
16562
16754
  };
16563
- SourceMap.parseWithLines = function(base64encodedJSONstr) {
16564
- var json, sourceLine, sourceColumn, lines;
16565
- json = JSON.parse(Buffer.from(base64encodedJSONstr, "base64").toString("utf8"));
16566
- sourceLine = 0;
16567
- sourceColumn = 0;
16568
- lines = json.mappings.split(";").map(function(line) {
16569
- if (line.length === 0) {
16570
- return [];
16571
- }
16572
- return line.split(",").map(function(entry) {
16573
- var result;
16574
- result = decodeVLQ(entry);
16575
- switch (result.length) {
16576
- case 1: {
16577
- return [result[0]];
16578
- }
16579
- case 4: {
16580
- return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3]];
16581
- }
16582
- case 5: {
16583
- return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3], result[4]];
16584
- }
16585
- default: {
16586
- throw new Error("Unknown source map entry", result);
16587
- }
16588
- }
16589
- });
16755
+ var smRegexp = /\n\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,([+a-zA-Z0-9\/]*=?=?)$/;
16756
+ var remap = function(codeWithSourceMap, upstreamMap, sourcePath, targetPath) {
16757
+ let sourceMapText;
16758
+ const codeWithoutSourceMap = codeWithSourceMap.replace(smRegexp, (match, sm) => {
16759
+ sourceMapText = sm;
16760
+ return "";
16590
16761
  });
16591
- json.lines = lines;
16592
- return json;
16593
- };
16594
- smRegexp = /\n\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,([+a-zA-Z0-9\/]*=?=?)$/;
16595
- SourceMap.remap = function(codeWithSourceMap, upstreamMap, sourcePath, targetPath) {
16596
- var sourceMapText, codeWithoutSourceMap, remappedSourceMapJSON, newSourceMap, remappedCodeWithSourceMap, parsed, composedLines;
16597
- sourceMapText = null;
16598
- codeWithoutSourceMap = codeWithSourceMap.replace(
16599
- smRegexp,
16600
- (match, sm) => {
16601
- sourceMapText = sm;
16602
- return "";
16603
- }
16604
- );
16605
16762
  if (sourceMapText) {
16606
- parsed = SourceMap.parseWithLines(sourceMapText);
16607
- composedLines = SourceMap.composeLines(upstreamMap.data.lines, parsed.lines);
16763
+ const parsed = parseWithLines(sourceMapText);
16764
+ const composedLines = composeLines(upstreamMap.data.lines, parsed.lines);
16608
16765
  upstreamMap.data.lines = composedLines;
16609
16766
  }
16610
- remappedSourceMapJSON = upstreamMap.json(sourcePath, targetPath);
16611
- newSourceMap = `${"sourceMapping"}URL=data:application/json;charset=utf-8;base64,${base64Encode(JSON.stringify(remappedSourceMapJSON))}`;
16612
- remappedCodeWithSourceMap = `${codeWithoutSourceMap}
16767
+ const remappedSourceMapJSON = upstreamMap.json(sourcePath, targetPath);
16768
+ const newSourceMap = `${"sourceMapping"}URL=data:application/json;charset=utf-8;base64,${base64Encode(JSON.stringify(remappedSourceMapJSON))}`;
16769
+ const remappedCodeWithSourceMap = `${codeWithoutSourceMap}
16613
16770
  //# ${newSourceMap}`;
16614
16771
  return remappedCodeWithSourceMap;
16615
16772
  };
16616
- SourceMap.composeLines = function(upstreamMapping, lines) {
16617
- return lines.map(function(line, l) {
16618
- return line.map(function(entry) {
16619
- var colDelta, sourceFileIndex, srcLine, srcCol, srcPos, upstreamLine, upstreamCol;
16773
+ var composeLines = function(upstreamMapping, lines) {
16774
+ return lines.map((line) => {
16775
+ return line.map((entry) => {
16620
16776
  if (entry.length === 1) {
16621
16777
  return entry;
16622
16778
  }
16623
- ;
16624
- [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16625
- srcPos = remapPosition([srcLine, srcCol], upstreamMapping);
16779
+ const [colDelta, sourceFileIndex, srcLine, srcCol] = entry;
16780
+ const srcPos = remapPosition([srcLine, srcCol], upstreamMapping);
16626
16781
  if (!srcPos) {
16627
16782
  return [entry[0]];
16628
16783
  }
16629
- ;
16630
- [upstreamLine, upstreamCol] = srcPos;
16784
+ const [upstreamLine, upstreamCol] = srcPos;
16631
16785
  if (entry.length === 4) {
16632
16786
  return [colDelta, sourceFileIndex, upstreamLine, upstreamCol];
16633
16787
  }
@@ -16635,44 +16789,50 @@ SourceMap.composeLines = function(upstreamMapping, lines) {
16635
16789
  });
16636
16790
  });
16637
16791
  };
16638
- prettySourceExcerpt = function(source, location, length) {
16639
- var lines, lineNum, colNum, i, line, lineNumStr;
16640
- lines = source.split(/\r?\n|\r/);
16641
- lineNum = location.line;
16642
- colNum = location.column;
16643
- for (let start = lineNum - 2, end = lineNum + 2, i1 = i = start, asc = start <= end; asc ? i1 <= end : i1 >= end; i = asc ? ++i1 : --i1) {
16644
- if (i < 0 || i >= lines.length) {
16645
- continue;
16646
- }
16647
- line = lines[i];
16648
- lineNumStr = (i + 1).toString();
16649
- while (lineNumStr.length < 4) {
16650
- lineNumStr = " " + lineNumStr;
16651
- }
16652
- if (i === lineNum) {
16653
- console.log(`${lineNumStr}: ${line}`);
16654
- console.log(" ".repeat(lineNumStr.length + 2 + colNum) + "^".repeat(length));
16655
- } else {
16656
- console.log(`${lineNumStr}: ${line}`);
16792
+ var parseWithLines = function(base64encodedJSONstr) {
16793
+ const json = JSON.parse(Buffer.from(base64encodedJSONstr, "base64").toString("utf8"));
16794
+ let sourceLine = 0;
16795
+ let sourceColumn = 0;
16796
+ const lines = json.mappings.split(";").map((line) => {
16797
+ if (line.length === 0) {
16798
+ return [];
16657
16799
  }
16658
- }
16659
- return;
16800
+ return line.split(",").map((entry) => {
16801
+ const result = decodeVLQ(entry);
16802
+ switch (result.length) {
16803
+ case 1: {
16804
+ return [result[0]];
16805
+ }
16806
+ case 4: {
16807
+ return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3]];
16808
+ }
16809
+ case 5: {
16810
+ return [result[0], result[1], sourceLine += result[2], sourceColumn += result[3], result[4]];
16811
+ }
16812
+ default: {
16813
+ throw new Error("Unknown source map entry", result);
16814
+ }
16815
+ }
16816
+ });
16817
+ });
16818
+ json.lines = lines;
16819
+ return json;
16660
16820
  };
16661
- VLQ_SHIFT = 5;
16662
- VLQ_CONTINUATION_BIT = 1 << VLQ_SHIFT;
16663
- VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - 1;
16664
- encodeVlq = function(value) {
16665
- var answer, valueToEncode, signBit, nextChunk;
16666
- answer = "";
16667
- let ref;
16821
+ Object.assign(SourceMap, { remap, parseWithLines, composeLines });
16822
+ var VLQ_SHIFT = 5;
16823
+ var VLQ_CONTINUATION_BIT = 1 << VLQ_SHIFT;
16824
+ var VLQ_VALUE_MASK = VLQ_CONTINUATION_BIT - 1;
16825
+ var encodeVlq = function(value) {
16826
+ let answer = "";
16827
+ let ref1;
16668
16828
  if (value < 0)
16669
- ref = 1;
16829
+ ref1 = 1;
16670
16830
  else
16671
- ref = 0;
16672
- signBit = ref;
16673
- valueToEncode = (Math.abs(value) << 1) + signBit;
16831
+ ref1 = 0;
16832
+ const signBit = ref1;
16833
+ let valueToEncode = (Math.abs(value) << 1) + signBit;
16674
16834
  while (valueToEncode || !answer) {
16675
- nextChunk = valueToEncode & VLQ_VALUE_MASK;
16835
+ let nextChunk = valueToEncode & VLQ_VALUE_MASK;
16676
16836
  valueToEncode = valueToEncode >> VLQ_SHIFT;
16677
16837
  if (valueToEncode) {
16678
16838
  nextChunk |= VLQ_CONTINUATION_BIT;
@@ -16681,57 +16841,53 @@ encodeVlq = function(value) {
16681
16841
  }
16682
16842
  return answer;
16683
16843
  };
16684
- BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16685
- encodeBase64 = function(value) {
16844
+ var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16845
+ var encodeBase64 = function(value) {
16686
16846
  return BASE64_CHARS[value] || (() => {
16687
- throw new Error(`Cannot Base64 encode value: ${value}`);
16847
+ throw new Error("Cannot Base64 encode value: ${value}");
16688
16848
  })();
16689
16849
  };
16690
16850
  var base64Encode = function(src) {
16691
16851
  return Buffer.from(src).toString("base64");
16692
16852
  };
16693
- vlqTable = new Uint8Array(128);
16694
- vlqChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16695
- (function() {
16696
- var i, l;
16697
- i = 0;
16698
- l = vlqTable.length;
16853
+ var vlqTable = new Uint8Array(128);
16854
+ var vlqChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16855
+ {
16856
+ let i = 0;
16857
+ let l = vlqTable.length;
16699
16858
  while (i < l) {
16700
16859
  vlqTable[i] = 255;
16701
16860
  i++;
16702
16861
  }
16703
16862
  i = 0;
16704
16863
  l = vlqChars.length;
16705
- const results = [];
16706
16864
  while (i < l) {
16707
16865
  vlqTable[vlqChars.charCodeAt(i)] = i;
16708
- results.push(i++);
16866
+ i++;
16709
16867
  }
16710
- ;
16711
- return results;
16712
- })();
16713
- decodeError = function(message) {
16868
+ }
16869
+ var decodeError = function(message) {
16714
16870
  throw new Error(message);
16715
16871
  };
16716
- decodeVLQ = function(mapping) {
16717
- var i, l, result, shift, vlq, c, index, v;
16718
- i = 0;
16719
- l = mapping.length;
16720
- result = [];
16872
+ var decodeVLQ = function(mapping) {
16873
+ let i = 0;
16874
+ let l = mapping.length;
16875
+ let result = [];
16721
16876
  while (i < l) {
16722
- shift = 0;
16723
- vlq = 0;
16877
+ let shift = 0;
16878
+ let vlq = 0;
16879
+ let v = 0;
16724
16880
  while (true) {
16725
16881
  if (i >= l) {
16726
16882
  decodeError("Unexpected early end of mapping data");
16727
16883
  }
16728
- c = mapping.charCodeAt(i);
16729
- if ((c & 127) !== c) {
16730
- decodeError(`Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}`);
16884
+ const c = mapping.charCodeAt(i);
16885
+ if ((c & 127) != c) {
16886
+ decodeError("Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}");
16731
16887
  }
16732
- index = vlqTable[c & 127];
16888
+ const index = vlqTable[c & 127];
16733
16889
  if (index === 255) {
16734
- decodeError(`Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}`);
16890
+ decodeError("Invalid mapping character: ${JSON.stringify(String.fromCharCode(c))}");
16735
16891
  }
16736
16892
  i++;
16737
16893
  vlq |= (index & 31) << shift;
@@ -16749,20 +16905,19 @@ decodeVLQ = function(mapping) {
16749
16905
  }
16750
16906
  return result;
16751
16907
  };
16752
- remapPosition = function(position, sourcemapLines) {
16753
- var line, character, textLine, i, p, l, lastMapping, lastMappingPosition, mapping;
16754
- [line, character] = position;
16755
- textLine = sourcemapLines[line];
16908
+ var remapPosition = function(position, sourcemapLines) {
16909
+ const [line, character] = position;
16910
+ const textLine = sourcemapLines[line];
16756
16911
  if (!textLine?.length) {
16757
16912
  return void 0;
16758
16913
  }
16759
- i = 0;
16760
- p = 0;
16761
- l = textLine.length;
16762
- lastMapping = void 0;
16763
- lastMappingPosition = 0;
16914
+ let i = 0;
16915
+ let p = 0;
16916
+ const l = textLine.length;
16917
+ let lastMapping = void 0;
16918
+ let lastMappingPosition = 0;
16764
16919
  while (i < l) {
16765
- mapping = textLine[i];
16920
+ const mapping = textLine[i];
16766
16921
  p += mapping[0];
16767
16922
  if (mapping.length === 4) {
16768
16923
  lastMapping = mapping;
@@ -16773,7 +16928,7 @@ remapPosition = function(position, sourcemapLines) {
16773
16928
  }
16774
16929
  i++;
16775
16930
  }
16776
- if (character - lastMappingPosition !== 0) {
16931
+ if (character - lastMappingPosition != 0) {
16777
16932
  return void 0;
16778
16933
  }
16779
16934
  if (lastMapping) {
@@ -16824,20 +16979,15 @@ var StateCache = class {
16824
16979
  };
16825
16980
 
16826
16981
  // source/main.civet
16827
- var { SourceMap: SourceMap2 } = util_exports;
16982
+ var { SourceMap: SourceMap2 } = sourcemap_exports;
16828
16983
  var ParseErrors = class extends Error {
16829
16984
  name = "ParseErrors";
16830
- filename;
16831
- line;
16832
- column;
16833
- offset;
16834
- constructor(message, filename1, line1, column1, offset1) {
16835
- super(message);
16836
- this.filename = filename1;
16837
- this.line = line1;
16838
- this.column = column1;
16839
- this.offset = offset1;
16985
+ errors;
16986
+ constructor(errors) {
16987
+ const message = errors.map(($) => $.message).join("\n");
16988
+ super(errors.map(($1) => $1.message).join("\n"));
16840
16989
  this.message = message;
16990
+ this.errors = errors;
16841
16991
  }
16842
16992
  };
16843
16993
  var uncacheable = /* @__PURE__ */ new Set([
@@ -16939,6 +17089,7 @@ ${counts}`;
16939
17089
  });
16940
17090
  }
16941
17091
  }
17092
+ const throwOnErrors = options.errors == null;
16942
17093
  function rest(ast2) {
16943
17094
  options = options;
16944
17095
  if (!(options.ast === "raw")) {
@@ -16948,28 +17099,36 @@ ${counts}`;
16948
17099
  return ast2;
16949
17100
  }
16950
17101
  function checkErrors() {
17102
+ if (!throwOnErrors) {
17103
+ return;
17104
+ }
17105
+ options = options;
16951
17106
  if (options.errors?.length) {
16952
- throw new ParseErrors(options.errors.map(($) => $.message).join("\n"));
17107
+ throw new ParseErrors(options.errors);
16953
17108
  }
16954
17109
  ;
16955
17110
  return;
16956
17111
  }
16957
17112
  if (options.sourceMap || options.inlineMap) {
16958
- const sm = SourceMap2(src);
16959
- options.updateSourceMap = sm.updateSourceMap;
17113
+ options.sourceMap = SourceMap2(src);
16960
17114
  const code = generate_default(ast2, options);
16961
17115
  checkErrors();
16962
17116
  if (options.inlineMap) {
16963
- return SourceMap2.remap(code, sm, filename2, filename2 + ".tsx");
17117
+ return SourceMap2.remap(code, options.sourceMap, filename2, filename2 + ".tsx");
16964
17118
  } else {
16965
17119
  return {
16966
17120
  code,
16967
- sourceMap: sm
17121
+ sourceMap: options.sourceMap
16968
17122
  };
16969
17123
  }
16970
17124
  }
16971
17125
  const result = generate_default(ast2, options);
16972
- checkErrors();
17126
+ if (options.errors?.length) {
17127
+ delete options.errors;
17128
+ options.sourceMap = SourceMap2(src);
17129
+ generate_default(ast2, options);
17130
+ checkErrors();
17131
+ }
16973
17132
  return result;
16974
17133
  }
16975
17134
  if (ast.then != null) {
@@ -17041,12 +17200,14 @@ var makeCache = function({ hits, trace } = {}) {
17041
17200
  return events;
17042
17201
  };
17043
17202
  var isCompileError = function(err) {
17044
- return err instanceof Error && //@ts-ignore
17045
- [err.message, err.name, err.filename, err.line, err.column, err.offset].every(($1) => $1 !== void 0);
17203
+ return err instanceof import_lib3.ParseError || err instanceof ParseErrors;
17046
17204
  };
17047
- var main_default = { parse, parseProgram, generate: generate_default, util: util_exports, compile, isCompileError };
17205
+ var main_default = { parse, parseProgram, ParseError: import_lib3.ParseError, ParseErrors, generate: generate_default, sourcemap: sourcemap_exports, SourceMap: SourceMap2, compile, isCompileError };
17206
+ var export_ParseError = import_lib3.ParseError;
17048
17207
  export {
17208
+ export_ParseError as ParseError,
17049
17209
  ParseErrors,
17210
+ SourceMap2 as SourceMap,
17050
17211
  compile,
17051
17212
  main_default as default,
17052
17213
  generate_default as generate,
@@ -17055,5 +17216,5 @@ export {
17055
17216
  parse,
17056
17217
  parseProgram,
17057
17218
  prune,
17058
- util_exports as util
17219
+ sourcemap_exports as sourcemap
17059
17220
  };