@danielx/civet 0.6.83 → 0.6.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -1186,7 +1186,7 @@ var Civet = (() => {
1186
1186
  });
1187
1187
 
1188
1188
  // source/parser/pattern-matching.civet
1189
- function processPatternMatching(statements, ReservedWord) {
1189
+ function processPatternMatching(statements, ReservedWord, getRef) {
1190
1190
  gatherRecursiveAll(statements, ($) => $.type === "SwitchStatement").forEach((s) => {
1191
1191
  const { caseBlock } = s;
1192
1192
  const { clauses } = caseBlock;
@@ -1246,7 +1246,7 @@ var Civet = (() => {
1246
1246
  const indent = block.expressions?.[0]?.[0] || "";
1247
1247
  const alternativeConditions = patterns.map((pattern2, i2) => {
1248
1248
  const conditions = [];
1249
- getPatternConditions(pattern2, ref, conditions);
1249
+ getPatternConditions(pattern2, ref, conditions, getRef);
1250
1250
  return conditions;
1251
1251
  });
1252
1252
  const conditionExpression = alternativeConditions.map((conditions, i2) => {
@@ -1304,26 +1304,26 @@ var Civet = (() => {
1304
1304
  return addParentPointers(s, s.parent);
1305
1305
  });
1306
1306
  }
1307
- function getPatternConditions(pattern, ref, conditions) {
1307
+ function getPatternConditions(pattern, ref, conditions, getRef) {
1308
1308
  if (pattern.rest)
1309
1309
  return;
1310
1310
  switch (pattern.type) {
1311
1311
  case "ArrayBindingPattern": {
1312
- const { elements, length } = pattern, hasRest = elements.some((e) => e.rest), comparator = hasRest ? " >= " : " === ", l = [comparator, (length - hasRest).toString()];
1312
+ const { elements, length } = pattern, hasRest = elements.some((e) => e.rest), l = (length - hasRest).toString(), lengthCheck = hasRest ? [ref, ".length >= ", l] : [getRef("len"), "(", ref, ", ", l, ")"];
1313
1313
  conditions.push(
1314
1314
  ["Array.isArray(", ref, ")"],
1315
- [ref, ".length", l]
1315
+ lengthCheck
1316
1316
  );
1317
1317
  elements.forEach(({ children: [, e] }, i) => {
1318
1318
  const subRef = [ref, "[", i.toString(), "]"];
1319
- return getPatternConditions(e, subRef, conditions);
1319
+ return getPatternConditions(e, subRef, conditions, getRef);
1320
1320
  });
1321
1321
  const { blockPrefix } = pattern;
1322
1322
  if (blockPrefix) {
1323
1323
  const postElements = blockPrefix.children[1], { length: postLength } = postElements;
1324
1324
  postElements.forEach(({ children: [, e] }, i) => {
1325
1325
  const subRef = [ref, "[", ref, ".length - ", (postLength + i).toString(), "]"];
1326
- return getPatternConditions(e, subRef, conditions);
1326
+ return getPatternConditions(e, subRef, conditions, getRef);
1327
1327
  });
1328
1328
  }
1329
1329
  break;
@@ -1355,7 +1355,7 @@ var Civet = (() => {
1355
1355
  subRef = [ref, ".", name];
1356
1356
  }
1357
1357
  if (value) {
1358
- getPatternConditions(value, subRef, conditions);
1358
+ getPatternConditions(value, subRef, conditions, getRef);
1359
1359
  }
1360
1360
  break;
1361
1361
  }
@@ -2121,7 +2121,7 @@ var Civet = (() => {
2121
2121
  ws = exp[0];
2122
2122
  exp = exp[1];
2123
2123
  }
2124
- if (!(exp.type === "StatementExpression")) {
2124
+ if (!(exp?.type === "StatementExpression")) {
2125
2125
  return;
2126
2126
  }
2127
2127
  const pre = [];
@@ -2139,7 +2139,8 @@ var Civet = (() => {
2139
2139
  assignResults(blockStatement, (resultNode) => {
2140
2140
  return makeNode({
2141
2141
  type: "AssignmentExpression",
2142
- children: [ref, " = ", resultNode]
2142
+ children: [ref, " = ", resultNode],
2143
+ parent: statement2
2143
2144
  });
2144
2145
  });
2145
2146
  const refDec = {
@@ -2157,7 +2158,8 @@ var Civet = (() => {
2157
2158
  assignResults(blockStatement, (resultNode) => {
2158
2159
  return makeNode({
2159
2160
  type: "AssignmentExpression",
2160
- children: [ref, " = ", resultNode]
2161
+ children: [ref, " = ", resultNode],
2162
+ parent: statement
2161
2163
  });
2162
2164
  });
2163
2165
  const refDec = {
@@ -2218,12 +2220,14 @@ var Civet = (() => {
2218
2220
  ]
2219
2221
  });
2220
2222
  }
2221
- function processDeclarationConditions(node) {
2223
+ function processDeclarationConditions(node, getRef) {
2222
2224
  gatherRecursiveAll(node, (n) => {
2223
2225
  return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
2224
- }).forEach(processDeclarationConditionStatement);
2226
+ }).forEach((s) => {
2227
+ return processDeclarationConditionStatement(s, getRef);
2228
+ });
2225
2229
  }
2226
- function processDeclarationConditionStatement(s) {
2230
+ function processDeclarationConditionStatement(s, getRef) {
2227
2231
  const { condition } = s;
2228
2232
  if (!condition?.expression) {
2229
2233
  return;
@@ -2238,7 +2242,7 @@ var Civet = (() => {
2238
2242
  const { ref, pattern } = expression;
2239
2243
  if (pattern) {
2240
2244
  let conditions = [];
2241
- getPatternConditions(pattern, ref, conditions);
2245
+ getPatternConditions(pattern, ref, conditions, getRef);
2242
2246
  conditions = conditions.filter((c) => {
2243
2247
  return !(c.length === 3 && c[0] === "typeof " && c[1] === ref && c[2] === " === 'object'") && !(c.length === 2 && c[0] === ref && c[1] === " != null");
2244
2248
  });
@@ -2634,17 +2638,21 @@ var Civet = (() => {
2634
2638
  stepExp = insertTrimmingSpace(stepExp, "");
2635
2639
  stepRef = maybeRef(stepExp, "step");
2636
2640
  }
2637
- const startRef = maybeRef(start, "start");
2638
- const endRef = maybeRef(end, "end");
2641
+ let startRef = maybeRef(start, "start");
2642
+ let endRef = maybeRef(end, "end");
2639
2643
  const startRefDec = startRef !== start ? [startRef, " = ", start, ", "] : [];
2640
2644
  const endRefDec = endRef !== end ? [endRef, " = ", end, ", "] : [];
2641
2645
  let ascDec = [], ascRef, asc;
2642
2646
  if (stepRef) {
2643
- if (stepRef !== stepExp) {
2647
+ if (!(stepRef === stepExp)) {
2644
2648
  ascDec = [", ", stepRef, " = ", stepExp];
2645
2649
  }
2646
- } else if (start.type === "Literal" && end.type === "Literal") {
2650
+ } else if ("Literal" === start.type && start.type === end.type) {
2647
2651
  asc = literalValue(start) <= literalValue(end);
2652
+ if ("StringLiteral" === start.subtype && start.subtype === end.subtype) {
2653
+ startRef = literalValue(start).charCodeAt(0).toString();
2654
+ endRef = literalValue(end).charCodeAt(0).toString();
2655
+ }
2648
2656
  } else {
2649
2657
  ascRef = makeRef("asc");
2650
2658
  ascDec = [", ", ascRef, " = ", startRef, " <= ", endRef];
@@ -2656,8 +2664,9 @@ var Civet = (() => {
2656
2664
  varAssign = [...insertTrimmingSpace(varName, ""), " = "];
2657
2665
  varLet = [",", ...varName, " = ", counterRef];
2658
2666
  } else {
2667
+ const value = "StringLiteral" === start.subtype ? ["String.fromCharCode(", counterRef, ")"] : counterRef;
2659
2668
  blockPrefix = [
2660
- ["", forDeclaration, " = ", counterRef, ";"]
2669
+ ["", forDeclaration, " = ", value, ";"]
2661
2670
  ];
2662
2671
  }
2663
2672
  } else if (forDeclaration) {
@@ -3223,6 +3232,7 @@ var Civet = (() => {
3223
3232
  case "BlockStatement":
3224
3233
  case "DebuggerStatement":
3225
3234
  case "Declaration":
3235
+ case "ForStatement":
3226
3236
  case "IfStatement":
3227
3237
  case "IterationStatement":
3228
3238
  case "ReturnStatement":
@@ -3911,12 +3921,12 @@ var Civet = (() => {
3911
3921
  addParentPointers(root);
3912
3922
  const { expressions: statements } = root;
3913
3923
  processTypes(statements);
3914
- processDeclarationConditions(statements);
3924
+ processDeclarationConditions(statements, m.getRef);
3915
3925
  processPipelineExpressions(statements);
3916
3926
  processDeclarations(statements);
3917
3927
  processAssignments(statements);
3918
3928
  processStatementExpressions(statements);
3919
- processPatternMatching(statements, ReservedWord);
3929
+ processPatternMatching(statements, ReservedWord, m.getRef);
3920
3930
  gatherRecursiveAll(statements, (n) => n.type === "IterationExpression").forEach((e) => expressionizeIteration(e));
3921
3931
  hoistRefDecs(statements);
3922
3932
  processFunctions(statements, config);
@@ -6130,9 +6140,7 @@ ${input.slice(result.pos)}
6130
6140
  return $EVENT_C(ctx, state, "UnaryWithoutParenthesizedAssignmentBody", UnaryWithoutParenthesizedAssignmentBody$$);
6131
6141
  }
6132
6142
  var UnaryPostfix$0 = QuestionMark;
6133
- var UnaryPostfix$1 = $T($P(TypePostfix), function(value) {
6134
- return { "ts": true, "children": value };
6135
- });
6143
+ var UnaryPostfix$1 = $P(TypePostfix);
6136
6144
  var UnaryPostfix$$ = [UnaryPostfix$0, UnaryPostfix$1];
6137
6145
  function UnaryPostfix(ctx, state) {
6138
6146
  return $EVENT_C(ctx, state, "UnaryPostfix", UnaryPostfix$$);
@@ -6140,7 +6148,7 @@ ${input.slice(result.pos)}
6140
6148
  var TypePostfix$0 = $TS($S(_, NWTypePostfix), function($skip, $loc, $0, $1, $2) {
6141
6149
  var ws = $1;
6142
6150
  var postfix = $2;
6143
- return [ws, ...postfix];
6151
+ return [ws, postfix];
6144
6152
  });
6145
6153
  function TypePostfix(ctx, state) {
6146
6154
  return $EVENT(ctx, state, "TypePostfix", TypePostfix$0);
@@ -6155,18 +6163,26 @@ ${input.slice(result.pos)}
6155
6163
  return $EVENT(ctx, state, "Tuple", Tuple$0);
6156
6164
  }
6157
6165
  var NWTypePostfix$0 = $TS($S(As, _, Tuple), function($skip, $loc, $0, $1, $2, $3) {
6158
- return [{ $loc: $1.$loc, token: "satisfies" }, $2, $3];
6166
+ return {
6167
+ ts: true,
6168
+ children: [{ $loc: $1.$loc, token: "satisfies" }, $2, $3]
6169
+ };
6159
6170
  });
6160
6171
  var NWTypePostfix$1 = $TS($S(As, $E(ExclamationPoint), Type), function($skip, $loc, $0, $1, $2, $3) {
6161
6172
  var as = $1;
6162
6173
  var ex = $2;
6163
6174
  var type = $3;
6175
+ let children;
6164
6176
  if (ex) {
6165
- return [{ $loc: ex.$loc, token: "as unknown " }, as, type];
6177
+ children = [{ $loc: ex.$loc, token: "as unknown " }, as, type];
6178
+ } else {
6179
+ children = [as, type];
6166
6180
  }
6167
- return [as, type];
6181
+ return { ts: true, children };
6182
+ });
6183
+ var NWTypePostfix$2 = $TS($S(Satisfies, Type), function($skip, $loc, $0, $1, $2) {
6184
+ return { ts: true, children: $0 };
6168
6185
  });
6169
- var NWTypePostfix$2 = $S(Satisfies, Type);
6170
6186
  var NWTypePostfix$$ = [NWTypePostfix$0, NWTypePostfix$1, NWTypePostfix$2];
6171
6187
  function NWTypePostfix(ctx, state) {
6172
6188
  return $EVENT_C(ctx, state, "NWTypePostfix", NWTypePostfix$$);
@@ -9493,8 +9509,9 @@ ${input.slice(result.pos)}
9493
9509
  return $EVENT_C(ctx, state, "MethodSignature", MethodSignature$$);
9494
9510
  }
9495
9511
  var ClassElementName$0 = PropertyName;
9496
- var ClassElementName$1 = PrivateIdentifier;
9497
- var ClassElementName$$ = [ClassElementName$0, ClassElementName$1];
9512
+ var ClassElementName$1 = LengthShorthand;
9513
+ var ClassElementName$2 = PrivateIdentifier;
9514
+ var ClassElementName$$ = [ClassElementName$0, ClassElementName$1, ClassElementName$2];
9498
9515
  function ClassElementName(ctx, state) {
9499
9516
  return $EVENT_C(ctx, state, "ClassElementName", ClassElementName$$);
9500
9517
  }
@@ -11120,27 +11137,26 @@ ${input.slice(result.pos)}
11120
11137
  children: [imp, $0.slice(1)]
11121
11138
  };
11122
11139
  });
11123
- var ImportDeclaration$1 = $T($S(Import, __, TypeKeyword, __, ImportClause, __, FromClause, $E(ImportAssertion)), function(value) {
11140
+ var ImportDeclaration$1 = $T($S(Import, __, TypeKeyword, __, ImportClause, __, FromClause), function(value) {
11124
11141
  return { "type": "ImportDeclaration", "ts": true, "children": value };
11125
11142
  });
11126
- var ImportDeclaration$2 = $T($S(Import, __, ImportClause, __, FromClause, $E(ImportAssertion)), function(value) {
11143
+ var ImportDeclaration$2 = $T($S(Import, __, ImportClause, __, FromClause), function(value) {
11127
11144
  return { "type": "ImportDeclaration", "children": value };
11128
11145
  });
11129
- var ImportDeclaration$3 = $T($S(Import, __, ModuleSpecifier, $E(ImportAssertion)), function(value) {
11146
+ var ImportDeclaration$3 = $T($S(Import, __, ModuleSpecifier), function(value) {
11130
11147
  return { "type": "ImportDeclaration", "children": value };
11131
11148
  });
11132
- var ImportDeclaration$4 = $TS($S(ImpliedImport, $E($S(TypeKeyword, __)), ImportClause, __, FromClause, $E(ImportAssertion)), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
11149
+ var ImportDeclaration$4 = $TS($S(ImpliedImport, $E($S(TypeKeyword, __)), ImportClause, __, FromClause), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
11133
11150
  var i = $1;
11134
11151
  var t = $2;
11135
11152
  var c = $3;
11136
11153
  var w = $4;
11137
11154
  var f = $5;
11138
- var a = $6;
11139
11155
  i.$loc = {
11140
11156
  pos: f[0].$loc.pos - 1,
11141
11157
  length: f[0].$loc.length + 1
11142
11158
  };
11143
- const children = [i, t, c, w, f, a];
11159
+ const children = [i, t, c, w, f];
11144
11160
  if (!t)
11145
11161
  return children;
11146
11162
  return { type: "ImportDeclaration", ts: true, children };
@@ -11299,7 +11315,8 @@ ${input.slice(result.pos)}
11299
11315
  function ModuleExportName(ctx, state) {
11300
11316
  return $EVENT_C(ctx, state, "ModuleExportName", ModuleExportName$$);
11301
11317
  }
11302
- var ModuleSpecifier$0 = $TS($S(UnprocessedModuleSpecifier), function($skip, $loc, $0, $1) {
11318
+ var ModuleSpecifier$0 = $TS($S(UnprocessedModuleSpecifier, $E(ImportAssertion)), function($skip, $loc, $0, $1, $2) {
11319
+ var a = $2;
11303
11320
  let { token } = $1;
11304
11321
  if (module.config.rewriteTsImports) {
11305
11322
  token = token.replace(/\.([mc])?ts(['"])$/, ".$1js$2");
@@ -11310,6 +11327,8 @@ ${input.slice(result.pos)}
11310
11327
  `${module.config.rewriteCivetImports.replace(/\$/g, "$$")}$1`
11311
11328
  );
11312
11329
  }
11330
+ if (a)
11331
+ return [{ ...$1, token }, a];
11313
11332
  return { ...$1, token };
11314
11333
  });
11315
11334
  function ModuleSpecifier(ctx, state) {
@@ -11674,7 +11693,11 @@ ${input.slice(result.pos)}
11674
11693
  function TripleSingleStringCharacters(ctx, state) {
11675
11694
  return $EVENT(ctx, state, "TripleSingleStringCharacters", TripleSingleStringCharacters$0);
11676
11695
  }
11677
- var CoffeeStringSubstitution$0 = $S(CoffeeSubstitutionStart, PostfixedExpression, __, CloseBrace);
11696
+ var CoffeeStringSubstitution$0 = $TS($S(CoffeeSubstitutionStart, AllowAll, $E($S(PostfixedExpression, __, CloseBrace)), RestoreAll), function($skip, $loc, $0, $1, $2, $3, $4) {
11697
+ if (!$3)
11698
+ return $skip;
11699
+ return [$1, ...$3];
11700
+ });
11678
11701
  function CoffeeStringSubstitution(ctx, state) {
11679
11702
  return $EVENT(ctx, state, "CoffeeStringSubstitution", CoffeeStringSubstitution$0);
11680
11703
  }
@@ -11851,7 +11874,11 @@ ${input.slice(result.pos)}
11851
11874
  function _TemplateLiteral(ctx, state) {
11852
11875
  return $EVENT_C(ctx, state, "_TemplateLiteral", _TemplateLiteral$$);
11853
11876
  }
11854
- var TemplateSubstitution$0 = $S(SubstitutionStart, PostfixedExpression, __, CloseBrace);
11877
+ var TemplateSubstitution$0 = $TS($S(SubstitutionStart, AllowAll, $E($S(PostfixedExpression, __, CloseBrace)), RestoreAll), function($skip, $loc, $0, $1, $2, $3, $4) {
11878
+ if (!$3)
11879
+ return $skip;
11880
+ return [$1, ...$3];
11881
+ });
11855
11882
  function TemplateSubstitution(ctx, state) {
11856
11883
  return $EVENT(ctx, state, "TemplateSubstitution", TemplateSubstitution$0);
11857
11884
  }
@@ -14602,6 +14629,19 @@ ${input.slice(result.pos)}
14602
14629
  };
14603
14630
  module.prelude.push(["", [preludeVar, isRef, typeSuffix, " = Object.is", asAny, ";\n"]]);
14604
14631
  },
14632
+ /**
14633
+ * Array length check with type guard.
14634
+ * From tlgreg https://discord.com/channels/933472021310996512/1012166187196629113/1157386582546976873
14635
+ */
14636
+ len(lenRef) {
14637
+ module.prelude.push(["", [{
14638
+ ts: true,
14639
+ children: ["function ", lenRef, "<T extends readonly unknown[], N extends number>(arr: T, length: N): arr is T & { length: N } { return arr.length === length }"]
14640
+ }, {
14641
+ js: true,
14642
+ children: ["function ", lenRef, "(arr, length) { return arr.length === length }"]
14643
+ }], "\n"]);
14644
+ },
14605
14645
  modulo(moduloRef) {
14606
14646
  const typeSuffix = {
14607
14647
  ts: true,
package/dist/main.js CHANGED
@@ -1178,7 +1178,7 @@ var init_op = __esm({
1178
1178
  });
1179
1179
 
1180
1180
  // source/parser/pattern-matching.civet
1181
- function processPatternMatching(statements, ReservedWord) {
1181
+ function processPatternMatching(statements, ReservedWord, getRef) {
1182
1182
  gatherRecursiveAll(statements, ($) => $.type === "SwitchStatement").forEach((s) => {
1183
1183
  const { caseBlock } = s;
1184
1184
  const { clauses } = caseBlock;
@@ -1238,7 +1238,7 @@ function processPatternMatching(statements, ReservedWord) {
1238
1238
  const indent = block.expressions?.[0]?.[0] || "";
1239
1239
  const alternativeConditions = patterns.map((pattern2, i2) => {
1240
1240
  const conditions = [];
1241
- getPatternConditions(pattern2, ref, conditions);
1241
+ getPatternConditions(pattern2, ref, conditions, getRef);
1242
1242
  return conditions;
1243
1243
  });
1244
1244
  const conditionExpression = alternativeConditions.map((conditions, i2) => {
@@ -1296,26 +1296,26 @@ function processPatternMatching(statements, ReservedWord) {
1296
1296
  return addParentPointers(s, s.parent);
1297
1297
  });
1298
1298
  }
1299
- function getPatternConditions(pattern, ref, conditions) {
1299
+ function getPatternConditions(pattern, ref, conditions, getRef) {
1300
1300
  if (pattern.rest)
1301
1301
  return;
1302
1302
  switch (pattern.type) {
1303
1303
  case "ArrayBindingPattern": {
1304
- const { elements, length } = pattern, hasRest = elements.some((e) => e.rest), comparator = hasRest ? " >= " : " === ", l = [comparator, (length - hasRest).toString()];
1304
+ const { elements, length } = pattern, hasRest = elements.some((e) => e.rest), l = (length - hasRest).toString(), lengthCheck = hasRest ? [ref, ".length >= ", l] : [getRef("len"), "(", ref, ", ", l, ")"];
1305
1305
  conditions.push(
1306
1306
  ["Array.isArray(", ref, ")"],
1307
- [ref, ".length", l]
1307
+ lengthCheck
1308
1308
  );
1309
1309
  elements.forEach(({ children: [, e] }, i) => {
1310
1310
  const subRef = [ref, "[", i.toString(), "]"];
1311
- return getPatternConditions(e, subRef, conditions);
1311
+ return getPatternConditions(e, subRef, conditions, getRef);
1312
1312
  });
1313
1313
  const { blockPrefix } = pattern;
1314
1314
  if (blockPrefix) {
1315
1315
  const postElements = blockPrefix.children[1], { length: postLength } = postElements;
1316
1316
  postElements.forEach(({ children: [, e] }, i) => {
1317
1317
  const subRef = [ref, "[", ref, ".length - ", (postLength + i).toString(), "]"];
1318
- return getPatternConditions(e, subRef, conditions);
1318
+ return getPatternConditions(e, subRef, conditions, getRef);
1319
1319
  });
1320
1320
  }
1321
1321
  break;
@@ -1347,7 +1347,7 @@ function getPatternConditions(pattern, ref, conditions) {
1347
1347
  subRef = [ref, ".", name];
1348
1348
  }
1349
1349
  if (value) {
1350
- getPatternConditions(value, subRef, conditions);
1350
+ getPatternConditions(value, subRef, conditions, getRef);
1351
1351
  }
1352
1352
  break;
1353
1353
  }
@@ -2113,7 +2113,7 @@ function prependStatementExpressionBlock(initializer, statement) {
2113
2113
  ws = exp[0];
2114
2114
  exp = exp[1];
2115
2115
  }
2116
- if (!(exp.type === "StatementExpression")) {
2116
+ if (!(exp?.type === "StatementExpression")) {
2117
2117
  return;
2118
2118
  }
2119
2119
  const pre = [];
@@ -2131,7 +2131,8 @@ function prependStatementExpressionBlock(initializer, statement) {
2131
2131
  assignResults(blockStatement, (resultNode) => {
2132
2132
  return makeNode({
2133
2133
  type: "AssignmentExpression",
2134
- children: [ref, " = ", resultNode]
2134
+ children: [ref, " = ", resultNode],
2135
+ parent: statement2
2135
2136
  });
2136
2137
  });
2137
2138
  const refDec = {
@@ -2149,7 +2150,8 @@ function prependStatementExpressionBlock(initializer, statement) {
2149
2150
  assignResults(blockStatement, (resultNode) => {
2150
2151
  return makeNode({
2151
2152
  type: "AssignmentExpression",
2152
- children: [ref, " = ", resultNode]
2153
+ children: [ref, " = ", resultNode],
2154
+ parent: statement
2153
2155
  });
2154
2156
  });
2155
2157
  const refDec = {
@@ -2210,12 +2212,14 @@ function processDeclarationCondition(condition, rootCondition, parent) {
2210
2212
  ]
2211
2213
  });
2212
2214
  }
2213
- function processDeclarationConditions(node) {
2215
+ function processDeclarationConditions(node, getRef) {
2214
2216
  gatherRecursiveAll(node, (n) => {
2215
2217
  return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
2216
- }).forEach(processDeclarationConditionStatement);
2218
+ }).forEach((s) => {
2219
+ return processDeclarationConditionStatement(s, getRef);
2220
+ });
2217
2221
  }
2218
- function processDeclarationConditionStatement(s) {
2222
+ function processDeclarationConditionStatement(s, getRef) {
2219
2223
  const { condition } = s;
2220
2224
  if (!condition?.expression) {
2221
2225
  return;
@@ -2230,7 +2234,7 @@ function processDeclarationConditionStatement(s) {
2230
2234
  const { ref, pattern } = expression;
2231
2235
  if (pattern) {
2232
2236
  let conditions = [];
2233
- getPatternConditions(pattern, ref, conditions);
2237
+ getPatternConditions(pattern, ref, conditions, getRef);
2234
2238
  conditions = conditions.filter((c) => {
2235
2239
  return !(c.length === 3 && c[0] === "typeof " && c[1] === ref && c[2] === " === 'object'") && !(c.length === 2 && c[0] === ref && c[1] === " != null");
2236
2240
  });
@@ -2626,17 +2630,21 @@ function forRange(open, forDeclaration, range, stepExp, close) {
2626
2630
  stepExp = insertTrimmingSpace(stepExp, "");
2627
2631
  stepRef = maybeRef(stepExp, "step");
2628
2632
  }
2629
- const startRef = maybeRef(start, "start");
2630
- const endRef = maybeRef(end, "end");
2633
+ let startRef = maybeRef(start, "start");
2634
+ let endRef = maybeRef(end, "end");
2631
2635
  const startRefDec = startRef !== start ? [startRef, " = ", start, ", "] : [];
2632
2636
  const endRefDec = endRef !== end ? [endRef, " = ", end, ", "] : [];
2633
2637
  let ascDec = [], ascRef, asc;
2634
2638
  if (stepRef) {
2635
- if (stepRef !== stepExp) {
2639
+ if (!(stepRef === stepExp)) {
2636
2640
  ascDec = [", ", stepRef, " = ", stepExp];
2637
2641
  }
2638
- } else if (start.type === "Literal" && end.type === "Literal") {
2642
+ } else if ("Literal" === start.type && start.type === end.type) {
2639
2643
  asc = literalValue(start) <= literalValue(end);
2644
+ if ("StringLiteral" === start.subtype && start.subtype === end.subtype) {
2645
+ startRef = literalValue(start).charCodeAt(0).toString();
2646
+ endRef = literalValue(end).charCodeAt(0).toString();
2647
+ }
2640
2648
  } else {
2641
2649
  ascRef = makeRef("asc");
2642
2650
  ascDec = [", ", ascRef, " = ", startRef, " <= ", endRef];
@@ -2648,8 +2656,9 @@ function forRange(open, forDeclaration, range, stepExp, close) {
2648
2656
  varAssign = [...insertTrimmingSpace(varName, ""), " = "];
2649
2657
  varLet = [",", ...varName, " = ", counterRef];
2650
2658
  } else {
2659
+ const value = "StringLiteral" === start.subtype ? ["String.fromCharCode(", counterRef, ")"] : counterRef;
2651
2660
  blockPrefix = [
2652
- ["", forDeclaration, " = ", counterRef, ";"]
2661
+ ["", forDeclaration, " = ", value, ";"]
2653
2662
  ];
2654
2663
  }
2655
2664
  } else if (forDeclaration) {
@@ -3215,6 +3224,7 @@ function isExpression(node) {
3215
3224
  case "BlockStatement":
3216
3225
  case "DebuggerStatement":
3217
3226
  case "Declaration":
3227
+ case "ForStatement":
3218
3228
  case "IfStatement":
3219
3229
  case "IterationStatement":
3220
3230
  case "ReturnStatement":
@@ -3903,12 +3913,12 @@ function processProgram(root, config, m, ReservedWord) {
3903
3913
  addParentPointers(root);
3904
3914
  const { expressions: statements } = root;
3905
3915
  processTypes(statements);
3906
- processDeclarationConditions(statements);
3916
+ processDeclarationConditions(statements, m.getRef);
3907
3917
  processPipelineExpressions(statements);
3908
3918
  processDeclarations(statements);
3909
3919
  processAssignments(statements);
3910
3920
  processStatementExpressions(statements);
3911
- processPatternMatching(statements, ReservedWord);
3921
+ processPatternMatching(statements, ReservedWord, m.getRef);
3912
3922
  gatherRecursiveAll(statements, (n) => n.type === "IterationExpression").forEach((e) => expressionizeIteration(e));
3913
3923
  hoistRefDecs(statements);
3914
3924
  processFunctions(statements, config);
@@ -6122,9 +6132,7 @@ var require_parser = __commonJS({
6122
6132
  return $EVENT_C(ctx, state, "UnaryWithoutParenthesizedAssignmentBody", UnaryWithoutParenthesizedAssignmentBody$$);
6123
6133
  }
6124
6134
  var UnaryPostfix$0 = QuestionMark;
6125
- var UnaryPostfix$1 = $T($P(TypePostfix), function(value) {
6126
- return { "ts": true, "children": value };
6127
- });
6135
+ var UnaryPostfix$1 = $P(TypePostfix);
6128
6136
  var UnaryPostfix$$ = [UnaryPostfix$0, UnaryPostfix$1];
6129
6137
  function UnaryPostfix(ctx, state) {
6130
6138
  return $EVENT_C(ctx, state, "UnaryPostfix", UnaryPostfix$$);
@@ -6132,7 +6140,7 @@ var require_parser = __commonJS({
6132
6140
  var TypePostfix$0 = $TS($S(_, NWTypePostfix), function($skip, $loc, $0, $1, $2) {
6133
6141
  var ws = $1;
6134
6142
  var postfix = $2;
6135
- return [ws, ...postfix];
6143
+ return [ws, postfix];
6136
6144
  });
6137
6145
  function TypePostfix(ctx, state) {
6138
6146
  return $EVENT(ctx, state, "TypePostfix", TypePostfix$0);
@@ -6147,18 +6155,26 @@ var require_parser = __commonJS({
6147
6155
  return $EVENT(ctx, state, "Tuple", Tuple$0);
6148
6156
  }
6149
6157
  var NWTypePostfix$0 = $TS($S(As, _, Tuple), function($skip, $loc, $0, $1, $2, $3) {
6150
- return [{ $loc: $1.$loc, token: "satisfies" }, $2, $3];
6158
+ return {
6159
+ ts: true,
6160
+ children: [{ $loc: $1.$loc, token: "satisfies" }, $2, $3]
6161
+ };
6151
6162
  });
6152
6163
  var NWTypePostfix$1 = $TS($S(As, $E(ExclamationPoint), Type), function($skip, $loc, $0, $1, $2, $3) {
6153
6164
  var as = $1;
6154
6165
  var ex = $2;
6155
6166
  var type = $3;
6167
+ let children;
6156
6168
  if (ex) {
6157
- return [{ $loc: ex.$loc, token: "as unknown " }, as, type];
6169
+ children = [{ $loc: ex.$loc, token: "as unknown " }, as, type];
6170
+ } else {
6171
+ children = [as, type];
6158
6172
  }
6159
- return [as, type];
6173
+ return { ts: true, children };
6174
+ });
6175
+ var NWTypePostfix$2 = $TS($S(Satisfies, Type), function($skip, $loc, $0, $1, $2) {
6176
+ return { ts: true, children: $0 };
6160
6177
  });
6161
- var NWTypePostfix$2 = $S(Satisfies, Type);
6162
6178
  var NWTypePostfix$$ = [NWTypePostfix$0, NWTypePostfix$1, NWTypePostfix$2];
6163
6179
  function NWTypePostfix(ctx, state) {
6164
6180
  return $EVENT_C(ctx, state, "NWTypePostfix", NWTypePostfix$$);
@@ -9485,8 +9501,9 @@ var require_parser = __commonJS({
9485
9501
  return $EVENT_C(ctx, state, "MethodSignature", MethodSignature$$);
9486
9502
  }
9487
9503
  var ClassElementName$0 = PropertyName;
9488
- var ClassElementName$1 = PrivateIdentifier;
9489
- var ClassElementName$$ = [ClassElementName$0, ClassElementName$1];
9504
+ var ClassElementName$1 = LengthShorthand;
9505
+ var ClassElementName$2 = PrivateIdentifier;
9506
+ var ClassElementName$$ = [ClassElementName$0, ClassElementName$1, ClassElementName$2];
9490
9507
  function ClassElementName(ctx, state) {
9491
9508
  return $EVENT_C(ctx, state, "ClassElementName", ClassElementName$$);
9492
9509
  }
@@ -11112,27 +11129,26 @@ var require_parser = __commonJS({
11112
11129
  children: [imp, $0.slice(1)]
11113
11130
  };
11114
11131
  });
11115
- var ImportDeclaration$1 = $T($S(Import, __, TypeKeyword, __, ImportClause, __, FromClause, $E(ImportAssertion)), function(value) {
11132
+ var ImportDeclaration$1 = $T($S(Import, __, TypeKeyword, __, ImportClause, __, FromClause), function(value) {
11116
11133
  return { "type": "ImportDeclaration", "ts": true, "children": value };
11117
11134
  });
11118
- var ImportDeclaration$2 = $T($S(Import, __, ImportClause, __, FromClause, $E(ImportAssertion)), function(value) {
11135
+ var ImportDeclaration$2 = $T($S(Import, __, ImportClause, __, FromClause), function(value) {
11119
11136
  return { "type": "ImportDeclaration", "children": value };
11120
11137
  });
11121
- var ImportDeclaration$3 = $T($S(Import, __, ModuleSpecifier, $E(ImportAssertion)), function(value) {
11138
+ var ImportDeclaration$3 = $T($S(Import, __, ModuleSpecifier), function(value) {
11122
11139
  return { "type": "ImportDeclaration", "children": value };
11123
11140
  });
11124
- var ImportDeclaration$4 = $TS($S(ImpliedImport, $E($S(TypeKeyword, __)), ImportClause, __, FromClause, $E(ImportAssertion)), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
11141
+ var ImportDeclaration$4 = $TS($S(ImpliedImport, $E($S(TypeKeyword, __)), ImportClause, __, FromClause), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
11125
11142
  var i = $1;
11126
11143
  var t = $2;
11127
11144
  var c = $3;
11128
11145
  var w = $4;
11129
11146
  var f = $5;
11130
- var a = $6;
11131
11147
  i.$loc = {
11132
11148
  pos: f[0].$loc.pos - 1,
11133
11149
  length: f[0].$loc.length + 1
11134
11150
  };
11135
- const children = [i, t, c, w, f, a];
11151
+ const children = [i, t, c, w, f];
11136
11152
  if (!t)
11137
11153
  return children;
11138
11154
  return { type: "ImportDeclaration", ts: true, children };
@@ -11291,7 +11307,8 @@ var require_parser = __commonJS({
11291
11307
  function ModuleExportName(ctx, state) {
11292
11308
  return $EVENT_C(ctx, state, "ModuleExportName", ModuleExportName$$);
11293
11309
  }
11294
- var ModuleSpecifier$0 = $TS($S(UnprocessedModuleSpecifier), function($skip, $loc, $0, $1) {
11310
+ var ModuleSpecifier$0 = $TS($S(UnprocessedModuleSpecifier, $E(ImportAssertion)), function($skip, $loc, $0, $1, $2) {
11311
+ var a = $2;
11295
11312
  let { token } = $1;
11296
11313
  if (module2.config.rewriteTsImports) {
11297
11314
  token = token.replace(/\.([mc])?ts(['"])$/, ".$1js$2");
@@ -11302,6 +11319,8 @@ var require_parser = __commonJS({
11302
11319
  `${module2.config.rewriteCivetImports.replace(/\$/g, "$$")}$1`
11303
11320
  );
11304
11321
  }
11322
+ if (a)
11323
+ return [{ ...$1, token }, a];
11305
11324
  return { ...$1, token };
11306
11325
  });
11307
11326
  function ModuleSpecifier(ctx, state) {
@@ -11666,7 +11685,11 @@ var require_parser = __commonJS({
11666
11685
  function TripleSingleStringCharacters(ctx, state) {
11667
11686
  return $EVENT(ctx, state, "TripleSingleStringCharacters", TripleSingleStringCharacters$0);
11668
11687
  }
11669
- var CoffeeStringSubstitution$0 = $S(CoffeeSubstitutionStart, PostfixedExpression, __, CloseBrace);
11688
+ var CoffeeStringSubstitution$0 = $TS($S(CoffeeSubstitutionStart, AllowAll, $E($S(PostfixedExpression, __, CloseBrace)), RestoreAll), function($skip, $loc, $0, $1, $2, $3, $4) {
11689
+ if (!$3)
11690
+ return $skip;
11691
+ return [$1, ...$3];
11692
+ });
11670
11693
  function CoffeeStringSubstitution(ctx, state) {
11671
11694
  return $EVENT(ctx, state, "CoffeeStringSubstitution", CoffeeStringSubstitution$0);
11672
11695
  }
@@ -11843,7 +11866,11 @@ var require_parser = __commonJS({
11843
11866
  function _TemplateLiteral(ctx, state) {
11844
11867
  return $EVENT_C(ctx, state, "_TemplateLiteral", _TemplateLiteral$$);
11845
11868
  }
11846
- var TemplateSubstitution$0 = $S(SubstitutionStart, PostfixedExpression, __, CloseBrace);
11869
+ var TemplateSubstitution$0 = $TS($S(SubstitutionStart, AllowAll, $E($S(PostfixedExpression, __, CloseBrace)), RestoreAll), function($skip, $loc, $0, $1, $2, $3, $4) {
11870
+ if (!$3)
11871
+ return $skip;
11872
+ return [$1, ...$3];
11873
+ });
11847
11874
  function TemplateSubstitution(ctx, state) {
11848
11875
  return $EVENT(ctx, state, "TemplateSubstitution", TemplateSubstitution$0);
11849
11876
  }
@@ -14594,6 +14621,19 @@ var require_parser = __commonJS({
14594
14621
  };
14595
14622
  module2.prelude.push(["", [preludeVar, isRef, typeSuffix, " = Object.is", asAny, ";\n"]]);
14596
14623
  },
14624
+ /**
14625
+ * Array length check with type guard.
14626
+ * From tlgreg https://discord.com/channels/933472021310996512/1012166187196629113/1157386582546976873
14627
+ */
14628
+ len(lenRef) {
14629
+ module2.prelude.push(["", [{
14630
+ ts: true,
14631
+ children: ["function ", lenRef, "<T extends readonly unknown[], N extends number>(arr: T, length: N): arr is T & { length: N } { return arr.length === length }"]
14632
+ }, {
14633
+ js: true,
14634
+ children: ["function ", lenRef, "(arr, length) { return arr.length === length }"]
14635
+ }], "\n"]);
14636
+ },
14597
14637
  modulo(moduloRef) {
14598
14638
  const typeSuffix = {
14599
14639
  ts: true,
package/dist/main.mjs CHANGED
@@ -1176,7 +1176,7 @@ var init_op = __esm({
1176
1176
  });
1177
1177
 
1178
1178
  // source/parser/pattern-matching.civet
1179
- function processPatternMatching(statements, ReservedWord) {
1179
+ function processPatternMatching(statements, ReservedWord, getRef) {
1180
1180
  gatherRecursiveAll(statements, ($) => $.type === "SwitchStatement").forEach((s) => {
1181
1181
  const { caseBlock } = s;
1182
1182
  const { clauses } = caseBlock;
@@ -1236,7 +1236,7 @@ function processPatternMatching(statements, ReservedWord) {
1236
1236
  const indent = block.expressions?.[0]?.[0] || "";
1237
1237
  const alternativeConditions = patterns.map((pattern2, i2) => {
1238
1238
  const conditions = [];
1239
- getPatternConditions(pattern2, ref, conditions);
1239
+ getPatternConditions(pattern2, ref, conditions, getRef);
1240
1240
  return conditions;
1241
1241
  });
1242
1242
  const conditionExpression = alternativeConditions.map((conditions, i2) => {
@@ -1294,26 +1294,26 @@ function processPatternMatching(statements, ReservedWord) {
1294
1294
  return addParentPointers(s, s.parent);
1295
1295
  });
1296
1296
  }
1297
- function getPatternConditions(pattern, ref, conditions) {
1297
+ function getPatternConditions(pattern, ref, conditions, getRef) {
1298
1298
  if (pattern.rest)
1299
1299
  return;
1300
1300
  switch (pattern.type) {
1301
1301
  case "ArrayBindingPattern": {
1302
- const { elements, length } = pattern, hasRest = elements.some((e) => e.rest), comparator = hasRest ? " >= " : " === ", l = [comparator, (length - hasRest).toString()];
1302
+ const { elements, length } = pattern, hasRest = elements.some((e) => e.rest), l = (length - hasRest).toString(), lengthCheck = hasRest ? [ref, ".length >= ", l] : [getRef("len"), "(", ref, ", ", l, ")"];
1303
1303
  conditions.push(
1304
1304
  ["Array.isArray(", ref, ")"],
1305
- [ref, ".length", l]
1305
+ lengthCheck
1306
1306
  );
1307
1307
  elements.forEach(({ children: [, e] }, i) => {
1308
1308
  const subRef = [ref, "[", i.toString(), "]"];
1309
- return getPatternConditions(e, subRef, conditions);
1309
+ return getPatternConditions(e, subRef, conditions, getRef);
1310
1310
  });
1311
1311
  const { blockPrefix } = pattern;
1312
1312
  if (blockPrefix) {
1313
1313
  const postElements = blockPrefix.children[1], { length: postLength } = postElements;
1314
1314
  postElements.forEach(({ children: [, e] }, i) => {
1315
1315
  const subRef = [ref, "[", ref, ".length - ", (postLength + i).toString(), "]"];
1316
- return getPatternConditions(e, subRef, conditions);
1316
+ return getPatternConditions(e, subRef, conditions, getRef);
1317
1317
  });
1318
1318
  }
1319
1319
  break;
@@ -1345,7 +1345,7 @@ function getPatternConditions(pattern, ref, conditions) {
1345
1345
  subRef = [ref, ".", name];
1346
1346
  }
1347
1347
  if (value) {
1348
- getPatternConditions(value, subRef, conditions);
1348
+ getPatternConditions(value, subRef, conditions, getRef);
1349
1349
  }
1350
1350
  break;
1351
1351
  }
@@ -2111,7 +2111,7 @@ function prependStatementExpressionBlock(initializer, statement) {
2111
2111
  ws = exp[0];
2112
2112
  exp = exp[1];
2113
2113
  }
2114
- if (!(exp.type === "StatementExpression")) {
2114
+ if (!(exp?.type === "StatementExpression")) {
2115
2115
  return;
2116
2116
  }
2117
2117
  const pre = [];
@@ -2129,7 +2129,8 @@ function prependStatementExpressionBlock(initializer, statement) {
2129
2129
  assignResults(blockStatement, (resultNode) => {
2130
2130
  return makeNode({
2131
2131
  type: "AssignmentExpression",
2132
- children: [ref, " = ", resultNode]
2132
+ children: [ref, " = ", resultNode],
2133
+ parent: statement2
2133
2134
  });
2134
2135
  });
2135
2136
  const refDec = {
@@ -2147,7 +2148,8 @@ function prependStatementExpressionBlock(initializer, statement) {
2147
2148
  assignResults(blockStatement, (resultNode) => {
2148
2149
  return makeNode({
2149
2150
  type: "AssignmentExpression",
2150
- children: [ref, " = ", resultNode]
2151
+ children: [ref, " = ", resultNode],
2152
+ parent: statement
2151
2153
  });
2152
2154
  });
2153
2155
  const refDec = {
@@ -2208,12 +2210,14 @@ function processDeclarationCondition(condition, rootCondition, parent) {
2208
2210
  ]
2209
2211
  });
2210
2212
  }
2211
- function processDeclarationConditions(node) {
2213
+ function processDeclarationConditions(node, getRef) {
2212
2214
  gatherRecursiveAll(node, (n) => {
2213
2215
  return n.type === "IfStatement" || n.type === "IterationStatement" || n.type === "SwitchStatement";
2214
- }).forEach(processDeclarationConditionStatement);
2216
+ }).forEach((s) => {
2217
+ return processDeclarationConditionStatement(s, getRef);
2218
+ });
2215
2219
  }
2216
- function processDeclarationConditionStatement(s) {
2220
+ function processDeclarationConditionStatement(s, getRef) {
2217
2221
  const { condition } = s;
2218
2222
  if (!condition?.expression) {
2219
2223
  return;
@@ -2228,7 +2232,7 @@ function processDeclarationConditionStatement(s) {
2228
2232
  const { ref, pattern } = expression;
2229
2233
  if (pattern) {
2230
2234
  let conditions = [];
2231
- getPatternConditions(pattern, ref, conditions);
2235
+ getPatternConditions(pattern, ref, conditions, getRef);
2232
2236
  conditions = conditions.filter((c) => {
2233
2237
  return !(c.length === 3 && c[0] === "typeof " && c[1] === ref && c[2] === " === 'object'") && !(c.length === 2 && c[0] === ref && c[1] === " != null");
2234
2238
  });
@@ -2624,17 +2628,21 @@ function forRange(open, forDeclaration, range, stepExp, close) {
2624
2628
  stepExp = insertTrimmingSpace(stepExp, "");
2625
2629
  stepRef = maybeRef(stepExp, "step");
2626
2630
  }
2627
- const startRef = maybeRef(start, "start");
2628
- const endRef = maybeRef(end, "end");
2631
+ let startRef = maybeRef(start, "start");
2632
+ let endRef = maybeRef(end, "end");
2629
2633
  const startRefDec = startRef !== start ? [startRef, " = ", start, ", "] : [];
2630
2634
  const endRefDec = endRef !== end ? [endRef, " = ", end, ", "] : [];
2631
2635
  let ascDec = [], ascRef, asc;
2632
2636
  if (stepRef) {
2633
- if (stepRef !== stepExp) {
2637
+ if (!(stepRef === stepExp)) {
2634
2638
  ascDec = [", ", stepRef, " = ", stepExp];
2635
2639
  }
2636
- } else if (start.type === "Literal" && end.type === "Literal") {
2640
+ } else if ("Literal" === start.type && start.type === end.type) {
2637
2641
  asc = literalValue(start) <= literalValue(end);
2642
+ if ("StringLiteral" === start.subtype && start.subtype === end.subtype) {
2643
+ startRef = literalValue(start).charCodeAt(0).toString();
2644
+ endRef = literalValue(end).charCodeAt(0).toString();
2645
+ }
2638
2646
  } else {
2639
2647
  ascRef = makeRef("asc");
2640
2648
  ascDec = [", ", ascRef, " = ", startRef, " <= ", endRef];
@@ -2646,8 +2654,9 @@ function forRange(open, forDeclaration, range, stepExp, close) {
2646
2654
  varAssign = [...insertTrimmingSpace(varName, ""), " = "];
2647
2655
  varLet = [",", ...varName, " = ", counterRef];
2648
2656
  } else {
2657
+ const value = "StringLiteral" === start.subtype ? ["String.fromCharCode(", counterRef, ")"] : counterRef;
2649
2658
  blockPrefix = [
2650
- ["", forDeclaration, " = ", counterRef, ";"]
2659
+ ["", forDeclaration, " = ", value, ";"]
2651
2660
  ];
2652
2661
  }
2653
2662
  } else if (forDeclaration) {
@@ -3213,6 +3222,7 @@ function isExpression(node) {
3213
3222
  case "BlockStatement":
3214
3223
  case "DebuggerStatement":
3215
3224
  case "Declaration":
3225
+ case "ForStatement":
3216
3226
  case "IfStatement":
3217
3227
  case "IterationStatement":
3218
3228
  case "ReturnStatement":
@@ -3901,12 +3911,12 @@ function processProgram(root, config, m, ReservedWord) {
3901
3911
  addParentPointers(root);
3902
3912
  const { expressions: statements } = root;
3903
3913
  processTypes(statements);
3904
- processDeclarationConditions(statements);
3914
+ processDeclarationConditions(statements, m.getRef);
3905
3915
  processPipelineExpressions(statements);
3906
3916
  processDeclarations(statements);
3907
3917
  processAssignments(statements);
3908
3918
  processStatementExpressions(statements);
3909
- processPatternMatching(statements, ReservedWord);
3919
+ processPatternMatching(statements, ReservedWord, m.getRef);
3910
3920
  gatherRecursiveAll(statements, (n) => n.type === "IterationExpression").forEach((e) => expressionizeIteration(e));
3911
3921
  hoistRefDecs(statements);
3912
3922
  processFunctions(statements, config);
@@ -6120,9 +6130,7 @@ var require_parser = __commonJS({
6120
6130
  return $EVENT_C(ctx, state, "UnaryWithoutParenthesizedAssignmentBody", UnaryWithoutParenthesizedAssignmentBody$$);
6121
6131
  }
6122
6132
  var UnaryPostfix$0 = QuestionMark;
6123
- var UnaryPostfix$1 = $T($P(TypePostfix), function(value) {
6124
- return { "ts": true, "children": value };
6125
- });
6133
+ var UnaryPostfix$1 = $P(TypePostfix);
6126
6134
  var UnaryPostfix$$ = [UnaryPostfix$0, UnaryPostfix$1];
6127
6135
  function UnaryPostfix(ctx, state) {
6128
6136
  return $EVENT_C(ctx, state, "UnaryPostfix", UnaryPostfix$$);
@@ -6130,7 +6138,7 @@ var require_parser = __commonJS({
6130
6138
  var TypePostfix$0 = $TS($S(_, NWTypePostfix), function($skip, $loc, $0, $1, $2) {
6131
6139
  var ws = $1;
6132
6140
  var postfix = $2;
6133
- return [ws, ...postfix];
6141
+ return [ws, postfix];
6134
6142
  });
6135
6143
  function TypePostfix(ctx, state) {
6136
6144
  return $EVENT(ctx, state, "TypePostfix", TypePostfix$0);
@@ -6145,18 +6153,26 @@ var require_parser = __commonJS({
6145
6153
  return $EVENT(ctx, state, "Tuple", Tuple$0);
6146
6154
  }
6147
6155
  var NWTypePostfix$0 = $TS($S(As, _, Tuple), function($skip, $loc, $0, $1, $2, $3) {
6148
- return [{ $loc: $1.$loc, token: "satisfies" }, $2, $3];
6156
+ return {
6157
+ ts: true,
6158
+ children: [{ $loc: $1.$loc, token: "satisfies" }, $2, $3]
6159
+ };
6149
6160
  });
6150
6161
  var NWTypePostfix$1 = $TS($S(As, $E(ExclamationPoint), Type), function($skip, $loc, $0, $1, $2, $3) {
6151
6162
  var as = $1;
6152
6163
  var ex = $2;
6153
6164
  var type = $3;
6165
+ let children;
6154
6166
  if (ex) {
6155
- return [{ $loc: ex.$loc, token: "as unknown " }, as, type];
6167
+ children = [{ $loc: ex.$loc, token: "as unknown " }, as, type];
6168
+ } else {
6169
+ children = [as, type];
6156
6170
  }
6157
- return [as, type];
6171
+ return { ts: true, children };
6172
+ });
6173
+ var NWTypePostfix$2 = $TS($S(Satisfies, Type), function($skip, $loc, $0, $1, $2) {
6174
+ return { ts: true, children: $0 };
6158
6175
  });
6159
- var NWTypePostfix$2 = $S(Satisfies, Type);
6160
6176
  var NWTypePostfix$$ = [NWTypePostfix$0, NWTypePostfix$1, NWTypePostfix$2];
6161
6177
  function NWTypePostfix(ctx, state) {
6162
6178
  return $EVENT_C(ctx, state, "NWTypePostfix", NWTypePostfix$$);
@@ -9483,8 +9499,9 @@ var require_parser = __commonJS({
9483
9499
  return $EVENT_C(ctx, state, "MethodSignature", MethodSignature$$);
9484
9500
  }
9485
9501
  var ClassElementName$0 = PropertyName;
9486
- var ClassElementName$1 = PrivateIdentifier;
9487
- var ClassElementName$$ = [ClassElementName$0, ClassElementName$1];
9502
+ var ClassElementName$1 = LengthShorthand;
9503
+ var ClassElementName$2 = PrivateIdentifier;
9504
+ var ClassElementName$$ = [ClassElementName$0, ClassElementName$1, ClassElementName$2];
9488
9505
  function ClassElementName(ctx, state) {
9489
9506
  return $EVENT_C(ctx, state, "ClassElementName", ClassElementName$$);
9490
9507
  }
@@ -11110,27 +11127,26 @@ var require_parser = __commonJS({
11110
11127
  children: [imp, $0.slice(1)]
11111
11128
  };
11112
11129
  });
11113
- var ImportDeclaration$1 = $T($S(Import, __, TypeKeyword, __, ImportClause, __, FromClause, $E(ImportAssertion)), function(value) {
11130
+ var ImportDeclaration$1 = $T($S(Import, __, TypeKeyword, __, ImportClause, __, FromClause), function(value) {
11114
11131
  return { "type": "ImportDeclaration", "ts": true, "children": value };
11115
11132
  });
11116
- var ImportDeclaration$2 = $T($S(Import, __, ImportClause, __, FromClause, $E(ImportAssertion)), function(value) {
11133
+ var ImportDeclaration$2 = $T($S(Import, __, ImportClause, __, FromClause), function(value) {
11117
11134
  return { "type": "ImportDeclaration", "children": value };
11118
11135
  });
11119
- var ImportDeclaration$3 = $T($S(Import, __, ModuleSpecifier, $E(ImportAssertion)), function(value) {
11136
+ var ImportDeclaration$3 = $T($S(Import, __, ModuleSpecifier), function(value) {
11120
11137
  return { "type": "ImportDeclaration", "children": value };
11121
11138
  });
11122
- var ImportDeclaration$4 = $TS($S(ImpliedImport, $E($S(TypeKeyword, __)), ImportClause, __, FromClause, $E(ImportAssertion)), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
11139
+ var ImportDeclaration$4 = $TS($S(ImpliedImport, $E($S(TypeKeyword, __)), ImportClause, __, FromClause), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
11123
11140
  var i = $1;
11124
11141
  var t = $2;
11125
11142
  var c = $3;
11126
11143
  var w = $4;
11127
11144
  var f = $5;
11128
- var a = $6;
11129
11145
  i.$loc = {
11130
11146
  pos: f[0].$loc.pos - 1,
11131
11147
  length: f[0].$loc.length + 1
11132
11148
  };
11133
- const children = [i, t, c, w, f, a];
11149
+ const children = [i, t, c, w, f];
11134
11150
  if (!t)
11135
11151
  return children;
11136
11152
  return { type: "ImportDeclaration", ts: true, children };
@@ -11289,7 +11305,8 @@ var require_parser = __commonJS({
11289
11305
  function ModuleExportName(ctx, state) {
11290
11306
  return $EVENT_C(ctx, state, "ModuleExportName", ModuleExportName$$);
11291
11307
  }
11292
- var ModuleSpecifier$0 = $TS($S(UnprocessedModuleSpecifier), function($skip, $loc, $0, $1) {
11308
+ var ModuleSpecifier$0 = $TS($S(UnprocessedModuleSpecifier, $E(ImportAssertion)), function($skip, $loc, $0, $1, $2) {
11309
+ var a = $2;
11293
11310
  let { token } = $1;
11294
11311
  if (module.config.rewriteTsImports) {
11295
11312
  token = token.replace(/\.([mc])?ts(['"])$/, ".$1js$2");
@@ -11300,6 +11317,8 @@ var require_parser = __commonJS({
11300
11317
  `${module.config.rewriteCivetImports.replace(/\$/g, "$$")}$1`
11301
11318
  );
11302
11319
  }
11320
+ if (a)
11321
+ return [{ ...$1, token }, a];
11303
11322
  return { ...$1, token };
11304
11323
  });
11305
11324
  function ModuleSpecifier(ctx, state) {
@@ -11664,7 +11683,11 @@ var require_parser = __commonJS({
11664
11683
  function TripleSingleStringCharacters(ctx, state) {
11665
11684
  return $EVENT(ctx, state, "TripleSingleStringCharacters", TripleSingleStringCharacters$0);
11666
11685
  }
11667
- var CoffeeStringSubstitution$0 = $S(CoffeeSubstitutionStart, PostfixedExpression, __, CloseBrace);
11686
+ var CoffeeStringSubstitution$0 = $TS($S(CoffeeSubstitutionStart, AllowAll, $E($S(PostfixedExpression, __, CloseBrace)), RestoreAll), function($skip, $loc, $0, $1, $2, $3, $4) {
11687
+ if (!$3)
11688
+ return $skip;
11689
+ return [$1, ...$3];
11690
+ });
11668
11691
  function CoffeeStringSubstitution(ctx, state) {
11669
11692
  return $EVENT(ctx, state, "CoffeeStringSubstitution", CoffeeStringSubstitution$0);
11670
11693
  }
@@ -11841,7 +11864,11 @@ var require_parser = __commonJS({
11841
11864
  function _TemplateLiteral(ctx, state) {
11842
11865
  return $EVENT_C(ctx, state, "_TemplateLiteral", _TemplateLiteral$$);
11843
11866
  }
11844
- var TemplateSubstitution$0 = $S(SubstitutionStart, PostfixedExpression, __, CloseBrace);
11867
+ var TemplateSubstitution$0 = $TS($S(SubstitutionStart, AllowAll, $E($S(PostfixedExpression, __, CloseBrace)), RestoreAll), function($skip, $loc, $0, $1, $2, $3, $4) {
11868
+ if (!$3)
11869
+ return $skip;
11870
+ return [$1, ...$3];
11871
+ });
11845
11872
  function TemplateSubstitution(ctx, state) {
11846
11873
  return $EVENT(ctx, state, "TemplateSubstitution", TemplateSubstitution$0);
11847
11874
  }
@@ -14592,6 +14619,19 @@ var require_parser = __commonJS({
14592
14619
  };
14593
14620
  module.prelude.push(["", [preludeVar, isRef, typeSuffix, " = Object.is", asAny, ";\n"]]);
14594
14621
  },
14622
+ /**
14623
+ * Array length check with type guard.
14624
+ * From tlgreg https://discord.com/channels/933472021310996512/1012166187196629113/1157386582546976873
14625
+ */
14626
+ len(lenRef) {
14627
+ module.prelude.push(["", [{
14628
+ ts: true,
14629
+ children: ["function ", lenRef, "<T extends readonly unknown[], N extends number>(arr: T, length: N): arr is T & { length: N } { return arr.length === length }"]
14630
+ }, {
14631
+ js: true,
14632
+ children: ["function ", lenRef, "(arr, length) { return arr.length === length }"]
14633
+ }], "\n"]);
14634
+ },
14595
14635
  modulo(moduloRef) {
14596
14636
  const typeSuffix = {
14597
14637
  ts: true,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.6.83",
4
+ "version": "0.6.85",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",