@danielx/civet 0.7.3 → 0.7.5

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;
@@ -416,14 +416,14 @@ var require_machine = __commonJS({
416
416
  }, [1, 1]);
417
417
  return [line, column];
418
418
  }
419
- function validate(input, result, { filename }) {
419
+ function validate(input, result, { filename: filename2 }) {
420
420
  if (result && result.pos === input.length)
421
421
  return result.value;
422
422
  const expectations = Array.from(new Set(failExpected.slice(0, failIndex)));
423
423
  let l = location(input, maxFailPos), [line, column] = l;
424
424
  if (result && result.pos > maxFailPos) {
425
425
  l = location(input, result.pos);
426
- throw new Error(`${filename}:${line}:${column} Unconsumed input at #{l}
426
+ throw new Error(`${filename2}:${line}:${column} Unconsumed input at #{l}
427
427
 
428
428
  ${input.slice(result.pos)}
429
429
  `);
@@ -435,11 +435,11 @@ ${input.slice(result.pos)}
435
435
  hint = JSON.stringify(hint);
436
436
  else
437
437
  hint = "EOF";
438
- const error = new ParseError(`${filename}:${line}:${column} Failed to parse
438
+ const error = new ParseError(`${filename2}:${line}:${column} Failed to parse
439
439
  Expected:
440
440
  ${expectations.join("\n ")}
441
441
  Found: ${hint}
442
- `, "ParseError", filename, line, column, maxFailPos);
442
+ `, "ParseError", filename2, line, column, maxFailPos);
443
443
  throw error;
444
444
  }
445
445
  if (result) {
@@ -463,11 +463,11 @@ ${input.slice(result.pos)}
463
463
  };
464
464
  }
465
465
  var ParseError = class extends Error {
466
- constructor(message, name, filename, line, column, offset) {
466
+ constructor(message, name, filename2, line, column, offset) {
467
467
  super(message);
468
468
  this.message = message;
469
469
  this.name = name;
470
- this.filename = filename;
470
+ this.filename = filename2;
471
471
  this.line = line;
472
472
  this.column = column;
473
473
  this.offset = offset;
@@ -531,6 +531,7 @@ __export(lib_exports, {
531
531
  processCoffeeInterpolation: () => processCoffeeInterpolation,
532
532
  processForInOf: () => processForInOf,
533
533
  processProgram: () => processProgram,
534
+ processProgramAsync: () => processProgramAsync,
534
535
  processUnaryExpression: () => processUnaryExpression,
535
536
  quoteString: () => quoteString,
536
537
  reorderBindingRestProperty: () => reorderBindingRestProperty,
@@ -1153,14 +1154,12 @@ function processParams(f) {
1153
1154
  if (!prefix.length)
1154
1155
  return;
1155
1156
  if (isConstructor) {
1156
- const superCalls = gatherNodes(expressions, (exp) => {
1157
- return exp.type === "CallExpression" && exp.children[0]?.token === "super";
1158
- });
1157
+ const superCalls = gatherNodes(
1158
+ expressions,
1159
+ (a) => typeof a === "object" && a != null && "type" in a && a.type === "CallExpression" && "children" in a && Array.isArray(a.children) && a.children.length >= 1 && typeof a.children[0] === "object" && a.children[0] != null && "token" in a.children[0] && a.children[0].token === "super"
1160
+ );
1159
1161
  if (superCalls.length) {
1160
- const { child } = findAncestor(
1161
- superCalls[0],
1162
- (ancestor) => ancestor === block
1163
- );
1162
+ const { child } = findAncestor(superCalls[0], (a1) => a1 === block);
1164
1163
  const index = findChildIndex(expressions, child);
1165
1164
  if (index < 0) {
1166
1165
  throw new Error("Could not find super call within top-level expressions");
@@ -1245,7 +1244,7 @@ function blockWithPrefix(prefixStatements, block) {
1245
1244
  return block;
1246
1245
  }
1247
1246
  function braceBlock(block) {
1248
- if (block.bare) {
1247
+ if (block.bare && !block.root) {
1249
1248
  if (block.children === block.expressions) {
1250
1249
  block.children = [block.expressions];
1251
1250
  }
@@ -1297,8 +1296,8 @@ function makeBlockFragment() {
1297
1296
  function replaceBlockExpression(node, child, replacement) {
1298
1297
  let found = false;
1299
1298
  const { expressions } = node;
1300
- for (let i = 0, l = expressions.length; i < l; i++) {
1301
- const statement = expressions[i];
1299
+ for (let i1 = 0, len3 = expressions.length; i1 < len3; i1++) {
1300
+ const statement = expressions[i1];
1302
1301
  const [, s] = statement;
1303
1302
  if (s === child) {
1304
1303
  statement[1] = replacement;
@@ -1359,9 +1358,9 @@ function processBlocks(statements) {
1359
1358
  }
1360
1359
  function insertSemicolon(statements) {
1361
1360
  const l = statements.length;
1362
- for (let i1 = 0, len2 = statements.length; i1 < len2; i1++) {
1363
- const i = i1;
1364
- const s = statements[i1];
1361
+ for (let i2 = 0, len1 = statements.length; i2 < len1; i2++) {
1362
+ const i = i2;
1363
+ const s = statements[i2];
1365
1364
  if (i < l - 1) {
1366
1365
  if (needsPrecedingSemicolon(statements[i + 1][1])) {
1367
1366
  const delim = s[2];
@@ -1379,8 +1378,8 @@ function needsPrecedingSemicolon(exp) {
1379
1378
  return false;
1380
1379
  }
1381
1380
  if (Array.isArray(exp)) {
1382
- for (let i2 = 0, len1 = exp.length; i2 < len1; i2++) {
1383
- const child = exp[i2];
1381
+ for (let i3 = 0, len22 = exp.length; i3 < len22; i3++) {
1382
+ const child = exp[i3];
1384
1383
  if (!(child != null)) {
1385
1384
  continue;
1386
1385
  }
@@ -1422,6 +1421,9 @@ function needsPrecedingSemicolon(exp) {
1422
1421
  }
1423
1422
 
1424
1423
  // source/parser/util.civet
1424
+ function len(arr, length) {
1425
+ return arr.length === length;
1426
+ }
1425
1427
  var assert = {
1426
1428
  equal(a, b, msg) {
1427
1429
  if (a !== b) {
@@ -1441,9 +1443,12 @@ function addParentPointers(node, parent) {
1441
1443
  return;
1442
1444
  }
1443
1445
  node = node;
1444
- node.parent = parent;
1446
+ if (parent != null) {
1447
+ node.parent = parent;
1448
+ }
1445
1449
  if (node.children) {
1446
- for (const child of node.children) {
1450
+ for (let ref1 = node.children, i1 = 0, len1 = ref1.length; i1 < len1; i1++) {
1451
+ const child = ref1[i1];
1447
1452
  addParentPointers(child, node);
1448
1453
  }
1449
1454
  }
@@ -1453,10 +1458,9 @@ function clone(node) {
1453
1458
  return deepCopy(node);
1454
1459
  }
1455
1460
  function removeParentPointers(node) {
1456
- if (node == null)
1457
- return;
1458
- if (typeof node !== "object")
1461
+ if (!(node != null && typeof node === "object")) {
1459
1462
  return;
1463
+ }
1460
1464
  if (Array.isArray(node)) {
1461
1465
  for (const child of node) {
1462
1466
  removeParentPointers(child);
@@ -1500,7 +1504,7 @@ function isEmptyBareBlock(node) {
1500
1504
  if (node?.type !== "BlockStatement")
1501
1505
  return false;
1502
1506
  const { bare, expressions } = node;
1503
- return bare && (expressions.length === 0 || expressions.length === 1 && expressions[0][1]?.type === "EmptyStatement");
1507
+ return bare && (Array.isArray(expressions) && len(expressions, 0) || Array.isArray(expressions) && len(expressions, 1) && Array.isArray(expressions[0]) && expressions[0].length >= 2 && typeof expressions[0][1] === "object" && expressions[0][1] != null && "type" in expressions[0][1] && expressions[0][1].type === "EmptyStatement");
1504
1508
  }
1505
1509
  function isFunction(node) {
1506
1510
  const { type } = node;
@@ -1548,8 +1552,8 @@ function isExit(node) {
1548
1552
  if (!(node != null)) {
1549
1553
  return false;
1550
1554
  }
1551
- let ref1;
1552
1555
  let ref2;
1556
+ let ref3;
1553
1557
  switch (node.type) {
1554
1558
  case "ReturnStatement":
1555
1559
  case "ThrowStatement":
@@ -1558,10 +1562,10 @@ function isExit(node) {
1558
1562
  return true;
1559
1563
  }
1560
1564
  case "IfStatement": {
1561
- return isExit(node.then) && isExit((ref1 = node.else)?.[ref1.length - 1]);
1565
+ return isExit(node.then) && isExit((ref2 = node.else)?.[ref2.length - 1]);
1562
1566
  }
1563
1567
  case "BlockStatement": {
1564
- return isExit((ref2 = node.expressions)[ref2.length - 1]?.[1]);
1568
+ return isExit((ref3 = node.expressions)[ref3.length - 1]?.[1]);
1565
1569
  }
1566
1570
  case "IterationStatement": {
1567
1571
  return node.condition?.type === "ParenthesizedExpression" && node.condition.expression?.type === "Literal" && node.condition.expression?.raw === "true" && gatherRecursiveWithinFunction(
@@ -1857,8 +1861,8 @@ function updateParentPointers(node, parent, depth = 1) {
1857
1861
  return;
1858
1862
  }
1859
1863
  if (Array.isArray(node)) {
1860
- for (let i1 = 0, len2 = node.length; i1 < len2; i1++) {
1861
- const child = node[i1];
1864
+ for (let i2 = 0, len22 = node.length; i2 < len22; i2++) {
1865
+ const child = node[i2];
1862
1866
  updateParentPointers(child, parent, depth);
1863
1867
  }
1864
1868
  return;
@@ -1868,8 +1872,8 @@ function updateParentPointers(node, parent, depth = 1) {
1868
1872
  node.parent = parent;
1869
1873
  }
1870
1874
  if (depth && isParent(node)) {
1871
- for (let ref3 = node.children, i2 = 0, len1 = ref3.length; i2 < len1; i2++) {
1872
- const child = ref3[i2];
1875
+ for (let ref4 = node.children, i3 = 0, len3 = ref4.length; i3 < len3; i3++) {
1876
+ const child = ref4[i3];
1873
1877
  updateParentPointers(child, node, depth - 1);
1874
1878
  }
1875
1879
  }
@@ -1999,9 +2003,9 @@ function wrapWithReturn(expression) {
1999
2003
  }
2000
2004
  function flatJoin(array, separator) {
2001
2005
  const result = [];
2002
- for (let i3 = 0, len2 = array.length; i3 < len2; i3++) {
2003
- const i = i3;
2004
- const items = array[i3];
2006
+ for (let i4 = 0, len4 = array.length; i4 < len4; i4++) {
2007
+ const i = i4;
2008
+ const items = array[i4];
2005
2009
  if (i) {
2006
2010
  result.push(separator);
2007
2011
  }
@@ -2022,7 +2026,7 @@ function findChildIndex(parent, child) {
2022
2026
  if (!(children != null)) {
2023
2027
  return -1;
2024
2028
  }
2025
- for (let i1 = 0, len2 = children.length; i1 < len2; i1++) {
2029
+ for (let i1 = 0, len3 = children.length; i1 < len3; i1++) {
2026
2030
  const i = i1;
2027
2031
  const c = children[i1];
2028
2032
  if (c === child || Array.isArray(c) && arrayRecurse(c)) {
@@ -2052,8 +2056,9 @@ function findAncestor(node, predicate, stopPredicate) {
2052
2056
  return { ancestor: void 0, child: node };
2053
2057
  }
2054
2058
  function gatherNodes(node, predicate) {
2055
- if (node == null)
2059
+ if (node == null || typeof node === "string") {
2056
2060
  return [];
2061
+ }
2057
2062
  if (Array.isArray(node)) {
2058
2063
  return node.flatMap((n) => gatherNodes(n, predicate));
2059
2064
  }
@@ -2061,24 +2066,30 @@ function gatherNodes(node, predicate) {
2061
2066
  return [node];
2062
2067
  }
2063
2068
  switch (node.type) {
2064
- case "BlockStatement":
2069
+ case "BlockStatement": {
2065
2070
  return [];
2066
- case "ForStatement":
2071
+ }
2072
+ case "ForStatement": {
2067
2073
  const isDec = node.declaration?.type === "Declaration";
2068
2074
  return node.children.flatMap((n) => {
2069
- if (isDec && n === node.declaration)
2075
+ if (isDec && n === node.declaration) {
2070
2076
  return [];
2071
- return gatherNodes(n, predicate);
2077
+ } else {
2078
+ return gatherNodes(n, predicate);
2079
+ }
2072
2080
  });
2073
- default:
2081
+ }
2082
+ default: {
2074
2083
  return gatherNodes(node.children, predicate);
2084
+ }
2075
2085
  }
2076
2086
  }
2077
2087
  function gatherRecursive(node, predicate, skipPredicate) {
2078
- if (node == null)
2088
+ if (node == null || typeof node === "string") {
2079
2089
  return [];
2090
+ }
2080
2091
  if (Array.isArray(node)) {
2081
- return node.flatMap((n) => gatherRecursive(n, predicate, skipPredicate));
2092
+ return node.flatMap(($) => gatherRecursive($, predicate, skipPredicate));
2082
2093
  }
2083
2094
  if (skipPredicate?.(node))
2084
2095
  return [];
@@ -2088,8 +2099,9 @@ function gatherRecursive(node, predicate, skipPredicate) {
2088
2099
  return gatherRecursive(node.children, predicate, skipPredicate);
2089
2100
  }
2090
2101
  function gatherRecursiveAll(node, predicate) {
2091
- if (node == null)
2102
+ if (node == null || typeof node === "string") {
2092
2103
  return [];
2104
+ }
2093
2105
  if (Array.isArray(node)) {
2094
2106
  return node.flatMap((n) => gatherRecursiveAll(n, predicate));
2095
2107
  }
@@ -2129,7 +2141,7 @@ var precedenceOrder = [
2129
2141
  ["**"]
2130
2142
  ];
2131
2143
  var precedenceMap = /* @__PURE__ */ new Map();
2132
- for (let i1 = 0, len2 = precedenceOrder.length; i1 < len2; i1++) {
2144
+ for (let i1 = 0, len3 = precedenceOrder.length; i1 < len3; i1++) {
2133
2145
  const prec = i1;
2134
2146
  const ops = precedenceOrder[i1];
2135
2147
  for (let i2 = 0, len1 = ops.length; i2 < len1; i2++) {
@@ -2240,7 +2252,7 @@ function processBinaryOpExpression($0) {
2240
2252
  } else {
2241
2253
  b = recurse(b);
2242
2254
  }
2243
- if (op.token === "instanceof" && b.type === "Literal" && b.children?.[0]?.type === "StringLiteral") {
2255
+ if (op.token === "instanceof" && (typeof b === "object" && b != null && "type" in b && b.type === "Literal" && "children" in b && Array.isArray(b.children) && b.children.length >= 1 && typeof b.children[0] === "object" && b.children[0] != null && "type" in b.children[0] && b.children[0].type === "StringLiteral")) {
2244
2256
  a = ["typeof ", makeLeftHandSideExpression(a)];
2245
2257
  if (op.negated) {
2246
2258
  op = { ...op, token: "!==", negated: false };
@@ -2345,7 +2357,7 @@ function expandChainedComparisons([first, binops]) {
2345
2357
  let start = 0;
2346
2358
  const chains = [];
2347
2359
  var i = 0;
2348
- for (let i3 = 0, len2 = binops.length; i3 < len2; i3++) {
2360
+ for (let i3 = 0, len22 = binops.length; i3 < len22; i3++) {
2349
2361
  var i = i3;
2350
2362
  var [, op] = binops[i3];
2351
2363
  if (isRelationalOp(op)) {
@@ -2955,7 +2967,7 @@ function aliasBinding(p, ref) {
2955
2967
  }
2956
2968
 
2957
2969
  // source/parser/declaration.civet
2958
- function len(arr, length) {
2970
+ function len2(arr, length) {
2959
2971
  return arr.length === length;
2960
2972
  }
2961
2973
  function processAssignmentDeclaration(decl, pattern, suffix, ws, assign, e) {
@@ -3138,9 +3150,12 @@ function processDeclarationCondition(condition, rootCondition, parent) {
3138
3150
  rootCondition.blockPrefix = getPatternBlockPrefix(pattern, ref, decl, suffix);
3139
3151
  }
3140
3152
  function processDeclarationConditions(node) {
3141
- gatherRecursiveAll(node, (n) => {
3142
- return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
3143
- }).forEach((s) => {
3153
+ gatherRecursiveAll(
3154
+ node,
3155
+ (n) => {
3156
+ return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
3157
+ }
3158
+ ).forEach((s) => {
3144
3159
  return processDeclarationConditionStatement(s);
3145
3160
  });
3146
3161
  }
@@ -3150,7 +3165,7 @@ function processDeclarationConditionStatement(s) {
3150
3165
  return;
3151
3166
  }
3152
3167
  let { expression } = condition;
3153
- if (typeof expression === "object" && expression != null && "type" in expression && expression.type === "UnaryExpression" && "children" in expression && Array.isArray(expression.children) && len(expression.children, 2) && expression.children[0] === "!" && typeof expression.children[1] === "object" && expression.children[1] != null && "type" in expression.children[1] && expression.children[1].type === "ParenthesizedExpression" && "expression" in expression.children[1]) {
3168
+ if (typeof expression === "object" && expression != null && "type" in expression && expression.type === "UnaryExpression" && "children" in expression && Array.isArray(expression.children) && len2(expression.children, 2) && expression.children[0] === "!" && typeof expression.children[1] === "object" && expression.children[1] != null && "type" in expression.children[1] && expression.children[1].type === "ParenthesizedExpression" && "expression" in expression.children[1]) {
3154
3169
  const { type: type1, children: [, { type: type2, expression: expression2 }] } = expression;
3155
3170
  const type = [type1, type2];
3156
3171
  expression = expression2;
@@ -3159,7 +3174,7 @@ function processDeclarationConditionStatement(s) {
3159
3174
  const { ref, pattern } = expression;
3160
3175
  if (pattern) {
3161
3176
  const conditions = getPatternConditions(pattern, ref).filter((c) => {
3162
- if (Array.isArray(c) && len(c, 2) && c[0] === ref && c[1] === " != null") {
3177
+ if (Array.isArray(c) && len2(c, 2) && c[0] === ref && c[1] === " != null") {
3163
3178
  const [,] = c;
3164
3179
  return false;
3165
3180
  } else {
@@ -4076,36 +4091,79 @@ function processComptime(statements) {
4076
4091
  if (!getInitialConfig()?.comptime) {
4077
4092
  return;
4078
4093
  }
4079
- gatherRecursive(
4094
+ let prepareEval = () => {
4095
+ };
4096
+ if (getSync()) {
4097
+ runComptime(statements, prepareEval);
4098
+ return;
4099
+ } else {
4100
+ return (async () => {
4101
+ {
4102
+ try {
4103
+ const path = (await import("node:path")).default;
4104
+ const { createRequire } = await import("node:module");
4105
+ return prepareEval = () => {
4106
+ global.__filename = path.resolve(getFilename() ?? "");
4107
+ global.__dirname = path.dirname(global.__filename);
4108
+ return global.require = createRequire(global.__filename);
4109
+ };
4110
+ } catch (e) {
4111
+ return;
4112
+ }
4113
+ }
4114
+ })().then(async () => {
4115
+ await Promise.all(runComptime(statements, prepareEval));
4116
+ });
4117
+ }
4118
+ }
4119
+ function runComptime(statements, prepareEval) {
4120
+ const sync2 = getSync();
4121
+ return gatherRecursive(
4080
4122
  statements,
4081
4123
  (node) => {
4082
4124
  return node.type === "ComptimeStatement" || node.type === "ComptimeExpression";
4083
4125
  }
4084
- ).forEach((exp) => {
4126
+ ).map((exp) => {
4085
4127
  const content = exp.type === "ComptimeStatement" ? exp.block : exp.expression;
4086
4128
  const options = { js: true };
4087
4129
  const js = generate_default(prune(content), options);
4088
4130
  if (options.errors != null) {
4089
4131
  return;
4090
4132
  }
4091
- const output = eval?.(`"use strict";${js}`);
4133
+ prepareEval();
4134
+ let output = eval?.(`"use strict";${js}`);
4135
+ let promise;
4092
4136
  if (exp.type === "ComptimeExpression") {
4093
- let string;
4094
- try {
4095
- string = serialize(output);
4096
- } catch (e) {
4097
- exp.children = [
4137
+ const finish = () => {
4138
+ let string;
4139
+ try {
4140
+ string = serialize(output);
4141
+ } catch (e) {
4142
+ exp.children = [
4143
+ {
4144
+ type: "Error",
4145
+ message: `comptime result ${output} not serializable: ${e}`
4146
+ }
4147
+ ];
4148
+ return;
4149
+ }
4150
+ return exp.children = [string];
4151
+ };
4152
+ if (sync2) {
4153
+ finish();
4154
+ } else {
4155
+ promise = (async () => {
4098
4156
  {
4099
- type: "Error",
4100
- message: `comptime result ${output} not JSON serializable: ${e}`
4157
+ output = await output;
4158
+ return finish();
4101
4159
  }
4102
- ];
4103
- return;
4160
+ })();
4104
4161
  }
4105
- return exp.children = [string];
4106
4162
  } else {
4107
- return exp.children = [];
4163
+ promise = output;
4164
+ exp.children = [];
4108
4165
  }
4166
+ return promise;
4109
4167
  });
4110
4168
  }
4111
4169
  function serialize(value) {
@@ -4213,7 +4271,7 @@ function serialize(value) {
4213
4271
  case Object.prototype: {
4214
4272
  let objStr = "{";
4215
4273
  let descStr = "";
4216
- for (let ref2 = Object.getOwnPropertyNames(val).concat(Object.getOwnPropertySymbols(val)), i = 0, len2 = ref2.length; i < len2; i++) {
4274
+ for (let ref2 = Object.getOwnPropertyNames(val).concat(Object.getOwnPropertySymbols(val)), i = 0, len3 = ref2.length; i < len3; i++) {
4217
4275
  const prop = ref2[i];
4218
4276
  const desc = Object.getOwnPropertyDescriptor(val, prop);
4219
4277
  if (desc.enumerable && desc.configurable && desc.writable) {
@@ -4302,7 +4360,7 @@ function getIndentLevel(str, tab) {
4302
4360
  }
4303
4361
  function reduceIndentLevel(str, dedent, tab) {
4304
4362
  if (tab != null && tab != 1) {
4305
- for (let i1 = 0, len2 = str.length; i1 < len2; i1++) {
4363
+ for (let i1 = 0, len3 = str.length; i1 < len3; i1++) {
4306
4364
  const i = i1;
4307
4365
  const char = str[i1];
4308
4366
  if (!dedent) {
@@ -4384,7 +4442,7 @@ function dedentBlockSubstitutions($0, tab) {
4384
4442
  ;
4385
4443
  const dedent = ref1;
4386
4444
  let results = [s];
4387
- for (let i3 = 0, len2 = strWithSubstitutions.length; i3 < len2; i3++) {
4445
+ for (let i3 = 0, len22 = strWithSubstitutions.length; i3 < len22; i3++) {
4388
4446
  const i = i3;
4389
4447
  let part = strWithSubstitutions[i3];
4390
4448
  if (part.token != null) {
@@ -4514,9 +4572,8 @@ function isExpression(node) {
4514
4572
  return true;
4515
4573
  }
4516
4574
  function expressionizeBlock(blockOrExpression) {
4517
- let ref1;
4518
- if ((ref1 = blockOrExpression) && "expressions" in ref1) {
4519
- const { expressions } = ref1;
4575
+ if (blockOrExpression && typeof blockOrExpression === "object" && "expressions" in blockOrExpression) {
4576
+ const { expressions } = blockOrExpression;
4520
4577
  const l = expressions.length;
4521
4578
  const results = [];
4522
4579
  let i1 = 0;
@@ -4615,7 +4672,7 @@ function handleThisPrivateShorthands(value) {
4615
4672
  }
4616
4673
  function processCallMemberExpression(node) {
4617
4674
  const { children } = node;
4618
- if (children[0]?.parenthesizedOp?.token && children[1]?.type === "Call") {
4675
+ if (Array.isArray(children) && children.length >= 2 && typeof children[0] === "object" && children[0] != null && "parenthesizedOp" in children[0] && typeof children[0].parenthesizedOp === "object" && children[0].parenthesizedOp != null && "token" in children[0].parenthesizedOp && typeof children[1] === "object" && children[1] != null && "type" in children[1] && children[1].type === "Call") {
4619
4676
  const op = children[0].parenthesizedOp;
4620
4677
  let call = children[1];
4621
4678
  const args = [...call.args];
@@ -4709,14 +4766,14 @@ function processCallMemberExpression(node) {
4709
4766
  });
4710
4767
  }
4711
4768
  }
4712
- let ref2;
4769
+ let ref1;
4713
4770
  let object = {
4714
4771
  type: "ObjectExpression",
4715
4772
  children: [
4716
4773
  glob.object.children[0],
4717
4774
  // {
4718
4775
  ...parts,
4719
- (ref2 = glob.object.children)[ref2.length - 1]
4776
+ (ref1 = glob.object.children)[ref1.length - 1]
4720
4777
  // whitespace and }
4721
4778
  ],
4722
4779
  properties: parts,
@@ -4768,7 +4825,7 @@ function replaceNode(node, newNode, parent) {
4768
4825
  throw new Error("replaceNode failed: node has no parent");
4769
4826
  }
4770
4827
  function recurse(children) {
4771
- for (let i3 = 0, len2 = children.length; i3 < len2; i3++) {
4828
+ for (let i3 = 0, len22 = children.length; i3 < len22; i3++) {
4772
4829
  const i = i3;
4773
4830
  const child = children[i3];
4774
4831
  if (child === node) {
@@ -4858,8 +4915,8 @@ function convertNamedImportsToObject(node, pattern) {
4858
4915
  return { type: "Error", message: "cannot use `type` in dynamic import" };
4859
4916
  } else {
4860
4917
  const { source, binding } = specifier;
4861
- let ref3;
4862
- const delim = (ref3 = specifier.children)[ref3.length - 1];
4918
+ let ref2;
4919
+ const delim = (ref2 = specifier.children)[ref2.length - 1];
4863
4920
  return {
4864
4921
  type: pattern ? "BindingProperty" : "Property",
4865
4922
  name: source,
@@ -4869,7 +4926,7 @@ function convertNamedImportsToObject(node, pattern) {
4869
4926
  };
4870
4927
  }
4871
4928
  });
4872
- let ref4;
4929
+ let ref3;
4873
4930
  return {
4874
4931
  type: pattern ? "ObjectBindingPattern" : "ObjectExpression",
4875
4932
  names: node.names,
@@ -4878,7 +4935,7 @@ function convertNamedImportsToObject(node, pattern) {
4878
4935
  node.children[0],
4879
4936
  // {
4880
4937
  properties,
4881
- (ref4 = node.children)[ref4.length - 1]
4938
+ (ref3 = node.children)[ref3.length - 1]
4882
4939
  // }
4883
4940
  ]
4884
4941
  };
@@ -5055,17 +5112,17 @@ function processAssignments(statements) {
5055
5112
  statements,
5056
5113
  (n) => n.type === "AssignmentExpression" && n.names === null,
5057
5114
  (exp) => {
5058
- let { lhs: $1, expression: $2 } = exp, tail = [], i = 0, len2 = $1.length;
5115
+ let { lhs: $1, expression: $2 } = exp, tail = [], i = 0, len3 = $1.length;
5059
5116
  let block;
5060
- let ref5;
5061
- if (exp.parent?.type === "BlockStatement" && !(ref5 = $1[$1.length - 1])?.[ref5.length - 1]?.special) {
5117
+ let ref4;
5118
+ if (exp.parent?.type === "BlockStatement" && !(ref4 = $1[$1.length - 1])?.[ref4.length - 1]?.special) {
5062
5119
  block = makeBlockFragment();
5063
- let ref6;
5064
- if (ref6 = prependStatementExpressionBlock(
5120
+ let ref5;
5121
+ if (ref5 = prependStatementExpressionBlock(
5065
5122
  { type: "Initializer", expression: $2, children: [void 0, void 0, $2] },
5066
5123
  block
5067
5124
  )) {
5068
- const ref = ref6;
5125
+ const ref = ref5;
5069
5126
  exp.children = exp.children.map(function(c) {
5070
5127
  if (c === $2)
5071
5128
  return ref;
@@ -5095,7 +5152,7 @@ function processAssignments(statements) {
5095
5152
  }
5096
5153
  }
5097
5154
  let wrapped = false;
5098
- while (i < len2) {
5155
+ while (i < len3) {
5099
5156
  const lastAssignment = $1[i++];
5100
5157
  const [, lhs, , op] = lastAssignment;
5101
5158
  if (op.token !== "=")
@@ -5108,7 +5165,7 @@ function processAssignments(statements) {
5108
5165
  }
5109
5166
  }
5110
5167
  }
5111
- i = len2 - 1;
5168
+ i = len3 - 1;
5112
5169
  while (i >= 0) {
5113
5170
  const lastAssignment = $1[i];
5114
5171
  if (lastAssignment[3].token === "=") {
@@ -5144,14 +5201,14 @@ function processAssignments(statements) {
5144
5201
  }
5145
5202
  i--;
5146
5203
  }
5147
- i = len2 - 1;
5204
+ i = len3 - 1;
5148
5205
  const optionalChainRef = makeRef();
5149
5206
  while (i >= 0) {
5150
5207
  const assignment = $1[i];
5151
5208
  const [ws1, lhs, ws2, op] = assignment;
5152
5209
  if (lhs.type === "MemberExpression" || lhs.type === "CallExpression") {
5153
5210
  const newMemberExp = unchainOptionalMemberExpression(lhs, optionalChainRef, (children) => {
5154
- const assigns = $1.splice(i + 1, len2 - 1 - i);
5211
+ const assigns = $1.splice(i + 1, len3 - 1 - i);
5155
5212
  $1.pop();
5156
5213
  return [ws1, ...children, ws2, op, ...assigns, $2];
5157
5214
  });
@@ -5233,9 +5290,9 @@ function unchainOptionalMemberExpression(exp, ref, innerExp) {
5233
5290
  }
5234
5291
  j++;
5235
5292
  }
5236
- let ref7;
5237
- if (ref7 = conditions.length) {
5238
- const l = ref7;
5293
+ let ref6;
5294
+ if (ref6 = conditions.length) {
5295
+ const l = ref6;
5239
5296
  const cs = flatJoin(conditions, " && ");
5240
5297
  return {
5241
5298
  ...exp,
@@ -5272,8 +5329,8 @@ function processTypes(node) {
5272
5329
  return gatherRecursiveAll(node, (n) => n.type === "UnaryType").forEach((unary) => {
5273
5330
  let last;
5274
5331
  let count = 0;
5275
- let ref8;
5276
- while (unary.suffix.length && (ref8 = unary.suffix)[ref8.length - 1]?.token === "?") {
5332
+ let ref7;
5333
+ while (unary.suffix.length && (ref7 = unary.suffix)[ref7.length - 1]?.token === "?") {
5277
5334
  last = unary.suffix.pop();
5278
5335
  count++;
5279
5336
  }
@@ -5307,11 +5364,11 @@ function processStatementExpressions(statements) {
5307
5364
  gatherRecursiveAll(statements, ($) => $.type === "StatementExpression").forEach((_exp) => {
5308
5365
  const exp = _exp;
5309
5366
  const { statement } = exp;
5310
- let ref9;
5367
+ let ref8;
5311
5368
  switch (statement.type) {
5312
5369
  case "IfStatement": {
5313
- if (ref9 = expressionizeIfStatement(statement)) {
5314
- const expression = ref9;
5370
+ if (ref8 = expressionizeIfStatement(statement)) {
5371
+ const expression = ref8;
5315
5372
  return replaceNode(statement, expression, exp);
5316
5373
  } else {
5317
5374
  return replaceNode(statement, wrapIIFE([["", statement]]), exp);
@@ -5319,7 +5376,8 @@ function processStatementExpressions(statements) {
5319
5376
  }
5320
5377
  case "IterationExpression": {
5321
5378
  if (statement.subtype === "ComptimeStatement") {
5322
- const expression = wrapIIFE(statement.statement.block.expressions);
5379
+ const { expressions } = statement.statement.block;
5380
+ const expression = wrapIIFE(expressions, hasAwait(expressions));
5323
5381
  return replaceNode(statement, makeNode({
5324
5382
  type: "ComptimeExpression",
5325
5383
  expression,
@@ -5397,7 +5455,13 @@ function processProgram(root) {
5397
5455
  processBlocks(statements);
5398
5456
  populateRefs(statements);
5399
5457
  adjustAtBindings(statements);
5400
- processComptime(statements);
5458
+ if (getSync()) {
5459
+ processComptime(statements);
5460
+ }
5461
+ }
5462
+ async function processProgramAsync(root) {
5463
+ const { expressions: statements } = root;
5464
+ await processComptime(statements);
5401
5465
  }
5402
5466
  function populateRefs(statements) {
5403
5467
  const refNodes = gatherRecursive(statements, ({ type }) => type === "Ref");
@@ -5521,8 +5585,8 @@ function processPlaceholders(statements) {
5521
5585
  for (let i4 = 0, len3 = placeholders.length; i4 < len3; i4++) {
5522
5586
  const placeholder = placeholders[i4];
5523
5587
  typeSuffix ??= placeholder.typeSuffix;
5524
- let ref10;
5525
- replaceNode((ref10 = placeholder.children)[ref10.length - 1], ref);
5588
+ let ref9;
5589
+ replaceNode((ref9 = placeholder.children)[ref9.length - 1], ref);
5526
5590
  }
5527
5591
  const { parent } = ancestor;
5528
5592
  const body = maybeUnwrap(ancestor);
@@ -5553,9 +5617,9 @@ function processPlaceholders(statements) {
5553
5617
  fnExp = makeLeftHandSideExpression(fnExp);
5554
5618
  }
5555
5619
  replaceNode(ancestor, fnExp, parent);
5556
- let ref11;
5557
- if (ref11 = getTrimmingSpace(body)) {
5558
- const ws = ref11;
5620
+ let ref10;
5621
+ if (ref10 = getTrimmingSpace(body)) {
5622
+ const ws = ref10;
5559
5623
  inplaceInsertTrimmingSpace(body, "");
5560
5624
  inplacePrepend(ws, fnExp);
5561
5625
  }
@@ -5600,8 +5664,8 @@ function reorderBindingRestProperty(props) {
5600
5664
  }
5601
5665
  ];
5602
5666
  }
5603
- let ref12;
5604
- if (Array.isArray(rest.delim) && (ref12 = rest.delim)[ref12.length - 1]?.token === ",") {
5667
+ let ref11;
5668
+ if (Array.isArray(rest.delim) && (ref11 = rest.delim)[ref11.length - 1]?.token === ",") {
5605
5669
  rest.delim = rest.delim.slice(0, -1);
5606
5670
  rest.children = [...rest.children.slice(0, -1), rest.delim];
5607
5671
  }
@@ -6799,15 +6863,20 @@ var $R92 = (0, import_lib2.$R)(new RegExp("(?=[ \\t\\r\\n\\/#]|$)", "suy"));
6799
6863
  var $R93 = (0, import_lib2.$R)(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
6800
6864
  var $R94 = (0, import_lib2.$R)(new RegExp("[^]*", "suy"));
6801
6865
  var Program$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(Reset, Init, (0, import_lib2.$E)(EOS), TopLevelStatements, __), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
6866
+ var reset = $1;
6867
+ var init = $2;
6868
+ var ws1 = $3;
6802
6869
  var statements = $4;
6803
- processProgram({
6870
+ var ws2 = $5;
6871
+ const program = {
6804
6872
  type: "BlockStatement",
6805
6873
  expressions: statements,
6806
- children: [statements],
6874
+ children: [reset, init, ws1, statements, ws2],
6807
6875
  bare: true,
6808
6876
  root: true
6809
- }, ReservedWord);
6810
- return $0;
6877
+ };
6878
+ processProgram(program);
6879
+ return program;
6811
6880
  });
6812
6881
  function Program(ctx, state2) {
6813
6882
  return (0, import_lib2.$EVENT)(ctx, state2, "Program", Program$0);
@@ -7246,8 +7315,8 @@ var SingleLineBinaryOpRHS$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, impor
7246
7315
  function SingleLineBinaryOpRHS(ctx, state2) {
7247
7316
  return (0, import_lib2.$EVENT)(ctx, state2, "SingleLineBinaryOpRHS", SingleLineBinaryOpRHS$0);
7248
7317
  }
7249
- var RHS$0 = UnaryExpression;
7250
- var RHS$1 = ExpressionizedStatementWithTrailingCallExpressions;
7318
+ var RHS$0 = ExpressionizedStatementWithTrailingCallExpressions;
7319
+ var RHS$1 = UnaryExpression;
7251
7320
  var RHS$$ = [RHS$0, RHS$1];
7252
7321
  function RHS(ctx, state2) {
7253
7322
  return (0, import_lib2.$EVENT_C)(ctx, state2, "RHS", RHS$$);
@@ -8405,11 +8474,11 @@ var PropertyAccess$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(AccessStart, (0,
8405
8474
  var dot = $1;
8406
8475
  var neg = $2;
8407
8476
  var num = $3;
8408
- const len2 = {
8477
+ const len3 = {
8409
8478
  children: []
8410
8479
  }, children = [
8411
8480
  adjustIndexAccess(dot),
8412
- len2,
8481
+ len3,
8413
8482
  neg,
8414
8483
  num,
8415
8484
  "]"
@@ -8417,7 +8486,7 @@ var PropertyAccess$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(AccessStart, (0,
8417
8486
  return {
8418
8487
  type: "NegativeIndex",
8419
8488
  children,
8420
- len: len2
8489
+ len: len3
8421
8490
  };
8422
8491
  });
8423
8492
  var PropertyAccess$2 = (0, import_lib2.$TS)((0, import_lib2.$S)(AccessStart, (0, import_lib2.$Q)(InlineComment), (0, import_lib2.$C)(IdentifierName, PrivateIdentifier, LengthShorthand)), function($skip, $loc, $0, $1, $2, $3) {
@@ -13503,7 +13572,7 @@ var Comma$0 = (0, import_lib2.$TV)((0, import_lib2.$EXPECT)($L25, 'Comma ","'),
13503
13572
  function Comma(ctx, state2) {
13504
13573
  return (0, import_lib2.$EVENT)(ctx, state2, "Comma", Comma$0);
13505
13574
  }
13506
- var Comptime$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L138, 'Comptime "comptime"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
13575
+ var Comptime$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L138, 'Comptime "comptime"'), NonIdContinue, (0, import_lib2.$N)((0, import_lib2.$EXPECT)($L15, 'Comptime ":"'))), function($skip, $loc, $0, $1, $2, $3) {
13507
13576
  return { $loc, token: $1 };
13508
13577
  });
13509
13578
  function Comptime(ctx, state2) {
@@ -16089,26 +16158,29 @@ var parser = function() {
16089
16158
  const parser2 = options.startRule != null ? grammar[options.startRule] : Object.values(grammar)[0];
16090
16159
  if (!parser2)
16091
16160
  throw new Error(`Could not find rule with name '${options.startRule}'`);
16092
- const filename = options.filename || "<anonymous>";
16161
+ const filename2 = options.filename || "<anonymous>";
16093
16162
  reset();
16094
16163
  Object.assign(ctx, { ...options.events, tokenize: options.tokenize });
16095
16164
  return validate(input, parser2(ctx, {
16096
16165
  input,
16097
16166
  pos: 0
16098
16167
  }), {
16099
- filename
16168
+ filename: filename2
16100
16169
  });
16101
16170
  }
16102
16171
  };
16103
16172
  }();
16104
16173
  var { parse } = parser;
16174
+ var filename;
16105
16175
  var initialConfig;
16106
16176
  var config;
16177
+ var sync;
16107
16178
  var state = {};
16108
16179
  var getState = () => state;
16109
16180
  var getConfig = () => config;
16110
16181
  var getInitialConfig = () => initialConfig;
16111
- var setInitialConfig = (c) => initialConfig = c;
16182
+ var getFilename = () => filename;
16183
+ var getSync = () => sync;
16112
16184
  Object.defineProperties(state, {
16113
16185
  currentIndent: {
16114
16186
  get() {
@@ -16153,6 +16225,21 @@ Object.defineProperties(state, {
16153
16225
  }
16154
16226
  }
16155
16227
  });
16228
+ function parseProgram(input, options) {
16229
+ filename = options?.filename;
16230
+ initialConfig = options?.parseOptions;
16231
+ sync = options?.sync;
16232
+ const root = parse(input, options);
16233
+ if (sync) {
16234
+ filename = initialConfig = sync = null;
16235
+ return root;
16236
+ } else {
16237
+ return processProgramAsync(root).then(() => {
16238
+ filename = initialConfig = sync = null;
16239
+ return root;
16240
+ });
16241
+ }
16242
+ }
16156
16243
 
16157
16244
  // source/util.civet
16158
16245
  var util_exports = {};
@@ -16579,15 +16666,15 @@ var uncacheable = /* @__PURE__ */ new Set([
16579
16666
  "RestoreTrailingMemberProperty",
16580
16667
  "RestoreNewlineBinaryOp"
16581
16668
  ]);
16582
- var compile = function(src, options) {
16669
+ function compile(src, options) {
16583
16670
  if (!options) {
16584
16671
  options = {};
16585
16672
  } else {
16586
16673
  options = { ...options };
16587
16674
  }
16588
16675
  options.parseOptions = { ...options.parseOptions };
16589
- const filename = options.filename || "unknown";
16590
- if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
16676
+ const filename2 = options.filename || "unknown";
16677
+ if (filename2.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
16591
16678
  options.parseOptions.coffeeCompat = true;
16592
16679
  }
16593
16680
  const { hits, trace, noCache } = options;
@@ -16599,21 +16686,18 @@ var compile = function(src, options) {
16599
16686
  });
16600
16687
  }
16601
16688
  let ast;
16602
- setInitialConfig(options.parseOptions);
16603
16689
  try {
16604
- ast = parse(src, {
16605
- filename,
16690
+ ast = parseProgram(src, {
16691
+ parseOptions: options.parseOptions,
16692
+ sync: options.sync,
16693
+ filename: filename2,
16606
16694
  events
16607
16695
  });
16608
- if (!(options.ast === "raw")) {
16609
- ast = prune(ast);
16610
- }
16611
16696
  } finally {
16612
- setInitialConfig(void 0);
16613
16697
  if (hits || trace) {
16614
- import("fs").then(function({ writeFileSync }) {
16698
+ import("node:fs").then(function({ writeFileSync }) {
16615
16699
  let ref;
16616
- if ((ref = events?.meta) && "logs" in ref) {
16700
+ if ((ref = events?.meta) && typeof ref === "object" && "logs" in ref) {
16617
16701
  const { logs } = ref;
16618
16702
  if (trace) {
16619
16703
  writeFileSync(trace, logs.join("\n"));
@@ -16642,28 +16726,45 @@ ${counts}`;
16642
16726
  });
16643
16727
  }
16644
16728
  }
16645
- if (options.ast) {
16646
- return ast;
16647
- }
16648
- if (options.sourceMap || options.inlineMap) {
16649
- const sm = SourceMap2(src);
16650
- options.updateSourceMap = sm.updateSourceMap;
16651
- const code = generate_default(ast, options);
16652
- if (options.inlineMap) {
16653
- return SourceMap2.remap(code, sm, filename, filename + ".tsx");
16654
- } else {
16655
- return {
16656
- code,
16657
- sourceMap: sm
16658
- };
16729
+ function rest(ast2) {
16730
+ options = options;
16731
+ if (!(options.ast === "raw")) {
16732
+ ast2 = prune(ast2);
16733
+ }
16734
+ if (options.ast) {
16735
+ return ast2;
16736
+ }
16737
+ function checkErrors() {
16738
+ if (options.errors?.length) {
16739
+ throw new Error(`Parse errors: ${options.errors.map(($) => $.message).join("\n")} `);
16740
+ }
16741
+ ;
16742
+ return;
16743
+ }
16744
+ if (options.sourceMap || options.inlineMap) {
16745
+ const sm = SourceMap2(src);
16746
+ options.updateSourceMap = sm.updateSourceMap;
16747
+ const code = generate_default(ast2, options);
16748
+ checkErrors();
16749
+ if (options.inlineMap) {
16750
+ return SourceMap2.remap(code, sm, filename2, filename2 + ".tsx");
16751
+ } else {
16752
+ return {
16753
+ code,
16754
+ sourceMap: sm
16755
+ };
16756
+ }
16659
16757
  }
16758
+ const result = generate_default(ast2, options);
16759
+ checkErrors();
16760
+ return result;
16660
16761
  }
16661
- const result = generate_default(ast, options);
16662
- if (options.errors?.length) {
16663
- throw new Error(`Parse errors: ${options.errors.map(($) => $.message).join("\n")} `);
16762
+ if (ast.then != null) {
16763
+ return ast.then(rest);
16764
+ } else {
16765
+ return rest(ast);
16664
16766
  }
16665
- return result;
16666
- };
16767
+ }
16667
16768
  var makeCache = function({ hits, trace } = {}) {
16668
16769
  const meta = {};
16669
16770
  let hitCount;
@@ -16730,7 +16831,7 @@ var isCompileError = function(err) {
16730
16831
  return err instanceof Error && //@ts-ignore
16731
16832
  [err.message, err.name, err.filename, err.line, err.column, err.offset].every(($1) => $1 !== void 0);
16732
16833
  };
16733
- var main_default = { parse, generate: generate_default, util: util_exports, compile, isCompileError };
16834
+ var main_default = { parse, parseProgram, generate: generate_default, util: util_exports, compile, isCompileError };
16734
16835
  export {
16735
16836
  compile,
16736
16837
  main_default as default,
@@ -16738,6 +16839,7 @@ export {
16738
16839
  isCompileError,
16739
16840
  lib_exports as lib,
16740
16841
  parse,
16842
+ parseProgram,
16741
16843
  prune,
16742
16844
  util_exports as util
16743
16845
  };