parseman 0.60.5 → 0.61.0

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.
Files changed (59) hide show
  1. package/dist/analysis/diagnostics.js +77 -40
  2. package/dist/analysis/diagnostics.js.map +3 -3
  3. package/dist/cli/index.js +77 -40
  4. package/dist/cli/index.js.map +3 -3
  5. package/dist/combinators/choice.d.ts.map +1 -1
  6. package/dist/combinators/expect.d.ts.map +1 -1
  7. package/dist/combinators/link-scope.d.ts +7 -0
  8. package/dist/combinators/link-scope.d.ts.map +1 -0
  9. package/dist/combinators/node.d.ts.map +1 -1
  10. package/dist/combinators/parser.d.ts.map +1 -1
  11. package/dist/combinators/trivia-boundary.d.ts +5 -3
  12. package/dist/combinators/trivia-boundary.d.ts.map +1 -1
  13. package/dist/compiler/token-capability.js +7 -0
  14. package/dist/compiler/token-capability.js.map +1 -1
  15. package/dist/compiler/value-usage.d.ts.map +1 -1
  16. package/dist/functional/run.d.ts.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +121 -70
  20. package/dist/index.js.map +3 -3
  21. package/dist/language-service/index.js +1 -1
  22. package/dist/language-service/index.js.map +1 -1
  23. package/dist/plugin/index.js +284 -233
  24. package/dist/plugin/index.js.map +3 -3
  25. package/dist/run/index.js +1 -1
  26. package/dist/run/index.js.map +1 -1
  27. package/dist/spec/index.js.map +1 -1
  28. package/dist/table/assemble.d.ts.map +1 -1
  29. package/dist/table/emit-assembly.d.ts.map +1 -1
  30. package/dist/table/emit.d.ts.map +1 -1
  31. package/dist/table/encode.d.ts.map +1 -1
  32. package/dist/table/exec.d.ts.map +1 -1
  33. package/dist/table/index.js +41 -10
  34. package/dist/table/index.js.map +3 -3
  35. package/dist/table/ops.d.ts +6 -0
  36. package/dist/table/ops.d.ts.map +1 -1
  37. package/dist/table/program.d.ts +3 -1
  38. package/dist/table/program.d.ts.map +1 -1
  39. package/dist/version.d.ts +1 -1
  40. package/package.json +1 -1
  41. package/src/combinators/choice.ts +3 -1
  42. package/src/combinators/expect.ts +1 -0
  43. package/src/combinators/grammar.ts +1 -1
  44. package/src/combinators/link-scope.ts +19 -0
  45. package/src/combinators/node.ts +11 -2
  46. package/src/combinators/parser.ts +37 -31
  47. package/src/combinators/trivia-boundary.ts +11 -3
  48. package/src/compiler/value-usage.ts +16 -29
  49. package/src/functional/run.ts +3 -1
  50. package/src/index.ts +1 -1
  51. package/src/table/assemble.ts +11 -1
  52. package/src/table/emit-assembly.ts +10 -1
  53. package/src/table/emit.ts +5 -1
  54. package/src/table/encode.ts +16 -9
  55. package/src/table/exec.ts +11 -9
  56. package/src/table/ops.ts +6 -0
  57. package/src/table/program.ts +8 -2
  58. package/src/table/site-labels.ts +3 -3
  59. package/src/version.ts +1 -1
@@ -48,6 +48,12 @@ function hasOwnTriviaBoundary(p, depth = MAX_DEPTH) {
48
48
  case "oneOrMore":
49
49
  case "sepBy":
50
50
  return true;
51
+ // A scope that names or clears trivia keeps an outer install out of its body.
52
+ // Any other inherits, so it falls through at no cost in depth: line tracking
53
+ // wraps every rule in one, and must not change what this walk sees.
54
+ case "grammar":
55
+ if (d.triviaParser || d.clearTrivia) return false;
56
+ depth++;
51
57
  // Transparent wrappers — they add no position, so ask what they wrap.
52
58
  case "node":
53
59
  case "transform":
@@ -494,15 +500,20 @@ function markUnusedValues(root) {
494
500
  case "many":
495
501
  case "oneOrMore":
496
502
  mark(def, consumed);
497
- visit(def.parser, consumed);
498
- return;
499
503
  case "optional":
504
+ // `optional` returns `inner | null` — no aggregate array/tuple to elide, so
505
+ // it carries no valueUnused flag. Still descend so an inner many/sequence
506
+ // under a node() is analyzed (it benefits even when its optional wrapper
507
+ // doesn't).
508
+ case "label":
509
+ case "trivia":
510
+ case "attempt":
511
+ case "withCtx":
512
+ case "expect":
500
513
  visit(def.parser, consumed);
501
514
  return;
502
515
  case "sequence":
503
516
  mark(def, consumed);
504
- for (const p of def.parsers) visit(p, consumed);
505
- return;
506
517
  case "choice":
507
518
  for (const p of def.parsers) visit(p, consumed);
508
519
  return;
@@ -513,22 +524,24 @@ function markUnusedValues(root) {
513
524
  if (def.otherwise) visit(def.otherwise, consumed);
514
525
  return;
515
526
  case "node":
527
+ // builds from captured children, NOT the inner parser value.
528
+ case "not":
529
+ case "peek":
530
+ // lookahead — value never observed
531
+ case "token":
516
532
  visit(def.parser, false);
517
533
  return;
518
534
  case "transform":
519
- visit(def.parser, true);
520
- return;
535
+ // the map fn reads the value → always consumed.
521
536
  case "field":
537
+ // the field capture records the parsed value → always consumed.
538
+ case "leaf":
522
539
  visit(def.parser, true);
523
540
  return;
524
541
  case "sepBy":
525
542
  visit(def.parser, true);
526
543
  visit(def.separator, false);
527
544
  return;
528
- case "not":
529
- case "peek":
530
- visit(def.parser, false);
531
- return;
532
545
  case "grammar":
533
546
  visit(def.parser, consumed);
534
547
  if (def.triviaParser) visit(def.triviaParser, false);
@@ -537,19 +550,6 @@ function markUnusedValues(root) {
537
550
  visit(def.parser, consumed);
538
551
  visit(def.sentinel, false);
539
552
  return;
540
- case "token":
541
- visit(def.parser, false);
542
- return;
543
- case "label":
544
- case "trivia":
545
- case "attempt":
546
- case "withCtx":
547
- case "expect":
548
- visit(def.parser, consumed);
549
- return;
550
- case "leaf":
551
- visit(def.parser, true);
552
- return;
553
553
  case "lazy":
554
554
  return;
555
555
  default:
@@ -579,6 +579,21 @@ function markUnusedValues(root) {
579
579
  visit(resolveRoot(root), true);
580
580
  }
581
581
 
582
+ // src/combinators/link-scope.ts
583
+ var scope;
584
+ function afterLink(settle) {
585
+ scope?.push(settle);
586
+ }
587
+ function collectAfterLink(pending, build) {
588
+ const outer = scope;
589
+ scope = outer ?? pending;
590
+ try {
591
+ return build();
592
+ } finally {
593
+ scope = outer;
594
+ }
595
+ }
596
+
582
597
  // src/line-index.ts
583
598
  import { PlainLineSpan, PlainSpan } from "../cst/plain.js";
584
599
  function createLineIndex() {
@@ -1782,7 +1797,7 @@ function parser(opts, root) {
1782
1797
  ctx.triviaKindLabels = void 0;
1783
1798
  } else if (scopeTrivia !== void 0) {
1784
1799
  ctx.trivia = scopeTrivia;
1785
- if (scopeLabels) ctx.triviaKindLabels = scopeLabels;
1800
+ ctx.triviaKindLabels = scopeLabels;
1786
1801
  }
1787
1802
  if (forceCaptureTrivia || _ctx?.captureTrivia) ctx.captureTrivia = true;
1788
1803
  if (ownCaptureMask !== void 0) ctx._triviaCaptureMask = ownCaptureMask;
@@ -1986,6 +2001,7 @@ function linkRules(recipes, link) {
1986
2001
  }
1987
2002
  });
1988
2003
  const winners = /* @__PURE__ */ new Map();
2004
+ const afterLink2 = [];
1989
2005
  const priorHoles = /* @__PURE__ */ new Map();
1990
2006
  const prior = new Proxy({}, {
1991
2007
  get(_target, key) {
@@ -1998,38 +2014,42 @@ function linkRules(recipes, link) {
1998
2014
  return hole;
1999
2015
  }
2000
2016
  });
2001
- for (const recipe of recipes) {
2002
- const definitions = recipe.factory(proxy, prior);
2003
- for (const key of Object.keys(definitions)) {
2004
- winners.set(key, { parser: definitions[key], options: recipe.options });
2005
- }
2006
- }
2007
- const keys = [...winners.keys()];
2008
2017
  const copies = /* @__PURE__ */ new Map();
2009
- for (const [key, { parser: defined }] of winners) {
2010
- const placeholder = cache[key];
2011
- const parser2 = ownRule(defined, copies);
2012
- if (placeholder === parser2) {
2013
- throw new Error(`rules(): rule "${key}" cannot be a direct alias to itself`);
2014
- }
2015
- if (isDefinableRef(placeholder)) {
2016
- if (!isNamedRuleRefForAnotherRule(parser2, key)) tagRule(parser2, key);
2017
- placeholder.define(parser2);
2018
- placeholder._meta.firstSet = parser2._meta.firstSet;
2019
- placeholder._meta.canMatchNewline = parser2._meta.canMatchNewline;
2020
- } else if (isNamedRuleRefForAnotherRule(parser2, key) || link !== void 0) {
2021
- if (!isNamedRuleRefForAnotherRule(parser2, key)) tagRule(parser2, key);
2022
- const alias = ref();
2023
- tagRule(alias, key);
2024
- alias.define(parser2);
2025
- alias._meta.firstSet = parser2._meta.firstSet;
2026
- alias._meta.canMatchNewline = parser2._meta.canMatchNewline;
2027
- cache[key] = alias;
2028
- } else {
2029
- tagRule(parser2, key);
2030
- cache[key] = parser2;
2018
+ try {
2019
+ for (const recipe of recipes) {
2020
+ const definitions = collectAfterLink(afterLink2, () => recipe.factory(proxy, prior));
2021
+ for (const key of Object.keys(definitions)) {
2022
+ winners.set(key, { parser: definitions[key], options: recipe.options });
2023
+ }
2024
+ }
2025
+ for (const [key, { parser: defined }] of winners) {
2026
+ const placeholder = cache[key];
2027
+ const parser2 = ownRule(defined, copies);
2028
+ if (placeholder === parser2) {
2029
+ throw new Error(`rules(): rule "${key}" cannot be a direct alias to itself`);
2030
+ }
2031
+ if (isDefinableRef(placeholder)) {
2032
+ if (!isNamedRuleRefForAnotherRule(parser2, key)) tagRule(parser2, key);
2033
+ placeholder.define(parser2);
2034
+ placeholder._meta.firstSet = parser2._meta.firstSet;
2035
+ placeholder._meta.canMatchNewline = parser2._meta.canMatchNewline;
2036
+ } else if (isNamedRuleRefForAnotherRule(parser2, key) || link !== void 0) {
2037
+ if (!isNamedRuleRefForAnotherRule(parser2, key)) tagRule(parser2, key);
2038
+ const alias = ref();
2039
+ tagRule(alias, key);
2040
+ alias.define(parser2);
2041
+ alias._meta.firstSet = parser2._meta.firstSet;
2042
+ alias._meta.canMatchNewline = parser2._meta.canMatchNewline;
2043
+ cache[key] = alias;
2044
+ } else {
2045
+ tagRule(parser2, key);
2046
+ cache[key] = parser2;
2047
+ }
2031
2048
  }
2049
+ } finally {
2050
+ for (const settle of afterLink2) settle();
2032
2051
  }
2052
+ const keys = [...winners.keys()];
2033
2053
  for (const key of keys) {
2034
2054
  const options = winners.get(key).options;
2035
2055
  let rule = cache[key];
@@ -3736,6 +3756,7 @@ function derive(c, seen) {
3736
3756
  case "optional":
3737
3757
  case "many":
3738
3758
  case "oneOrMore":
3759
+ case "sepBy":
3739
3760
  case "transform":
3740
3761
  case "not":
3741
3762
  case "peek":
@@ -3883,7 +3904,7 @@ function choice(...args) {
3883
3904
  const result = parsers[idx].parse(input, pos, ctx);
3884
3905
  if (result.ok) return result;
3885
3906
  expected.push(...result.expected);
3886
- if (result.committed) return { ok: false, expected, span: { start: pos, end: pos }, committed: true };
3907
+ if (result.committed) return { ok: false, expected, span: result.span, committed: true };
3887
3908
  return { ok: false, expected, span: { start: pos, end: pos } };
3888
3909
  }
3889
3910
  if (ctx._probe !== void 0 || ctx._tolerant) for (const p of parsers) p.parse(input, pos, ctx);
@@ -5277,8 +5298,14 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
5277
5298
  const def = unwrap || collapse || project !== void 0 || captureTrivia || trailingTrivia || buildArity !== void 0 || tags !== void 0 && tags.length > 0 ? { ...baseDef, ...unwrap ? { unwrap: true } : {}, ...collapse ? { collapse: true } : {}, ...project !== void 0 ? { project } : {}, ...captureTrivia ? { captureTrivia: true } : {}, ...trailingTrivia ? { trailingTrivia: true } : {}, ...buildArity !== void 0 ? { buildArity } : {}, ...tags !== void 0 && tags.length > 0 ? { tags } : {} } : baseDef;
5278
5299
  const capturesTrivia = captureTrivia || (build ? buildReadsTrivia(def) : project === void 0);
5279
5300
  const readsState = build ? buildReadsState(def) : project === void 0;
5280
- const hasOwnFields = parserHasOwnFields(combinator);
5281
- const capturesFields = hasOwnFields && (build ? buildReadsFields(def) : project === void 0);
5301
+ let hasOwnFields = parserHasOwnFields(combinator);
5302
+ let capturesFields = hasOwnFields && (build ? buildReadsFields(def) : project === void 0);
5303
+ if (!hasOwnFields) {
5304
+ afterLink(() => {
5305
+ hasOwnFields = parserHasOwnFields(combinator);
5306
+ capturesFields = hasOwnFields && (build ? buildReadsFields(def) : project === void 0);
5307
+ });
5308
+ }
5282
5309
  const guardable = combinator._meta.firstSet.kind !== "any" && !matchesEmpty(combinator);
5283
5310
  let failExpected;
5284
5311
  return {
@@ -5591,6 +5618,9 @@ function sourceLeaf(root, fn) {
5591
5618
  return makeLeaf(root, fn, true);
5592
5619
  }
5593
5620
 
5621
+ // src/version.ts
5622
+ var PARSEMAN_VERSION = "0.61.0";
5623
+
5594
5624
  // src/table/lex-body.ts
5595
5625
  function buildLexBodyRecognizer(spec, constants) {
5596
5626
  const raw = constants[spec[0]];
@@ -6206,11 +6236,12 @@ function assemblyExtraIps(prog) {
6206
6236
  }
6207
6237
  function expandCompact(p) {
6208
6238
  if ("code" in p) return p;
6239
+ if (p.es === void 0) throw new Error(`parseman: this parser was printed by an earlier parseman; reprint it with parseman ${PARSEMAN_VERSION}`);
6209
6240
  return ownTableProgram({
6210
6241
  code: p.c,
6211
6242
  k: p.k,
6212
6243
  cc: p.x,
6213
- fx: p.e,
6244
+ fx: p.e.map((set) => set.map((i) => p.es[i])),
6214
6245
  disp: p.d,
6215
6246
  rules: p.r,
6216
6247
  fns: p.f,
@@ -7148,6 +7179,7 @@ var OP_LIT_CI = 27;
7148
7179
  var OP_LIT_CI_TRACK = 28;
7149
7180
  var OP_TOKEN = 29;
7150
7181
  var OP_SCOPE_CAP = 30;
7182
+ var SCOPE_INHERIT = -2;
7151
7183
  var OP_WITHCTX = 31;
7152
7184
  var OP_GUARD = 32;
7153
7185
  var OP_ADJ = 33;
@@ -7272,7 +7304,7 @@ function selectOptionalSuffixLexBody(ir) {
7272
7304
  function reinstallsRuleTrivia(reference, target) {
7273
7305
  return (reference._meta.grammarTrivia ?? target._meta.grammarTrivia) !== void 0 && hasOwnTriviaBoundary(target);
7274
7306
  }
7275
- function directTokenBodyParser(parser2, resolve3, scope) {
7307
+ function directTokenBodyParser(parser2, resolve3, scope2) {
7276
7308
  const outer = parser2._def;
7277
7309
  if (outer.tag !== "token") return void 0;
7278
7310
  let body = outer.parser;
@@ -7282,7 +7314,7 @@ function directTokenBodyParser(parser2, resolve3, scope) {
7282
7314
  const wrapper = body._def;
7283
7315
  if (wrapper.tag === "grammar") {
7284
7316
  if (wrapper.clearTrivia !== true || wrapper.triviaParser !== void 0 || wrapper.captureTrivia === true || wrapper.rootCapture === "opaque" || wrapper.constructionTrackLines !== "inherit" || wrapper.constructionCaptureTriviaKinds !== void 0) return void 0;
7285
- if (scope !== void 0) scope.cleared = true;
7317
+ if (scope2 !== void 0) scope2.cleared = true;
7286
7318
  body = wrapper.parser;
7287
7319
  continue;
7288
7320
  }
@@ -7539,10 +7571,10 @@ function directFixedLexNode(parser2, resolve3, active, pureOnly = false, cleared
7539
7571
  }
7540
7572
  }
7541
7573
  function directFixedTokenBody(parser2, resolve3) {
7542
- const scope = { cleared: false };
7543
- const body = directTokenBodyParser(parser2, resolve3, scope);
7574
+ const scope2 = { cleared: false };
7575
+ const body = directTokenBodyParser(parser2, resolve3, scope2);
7544
7576
  if (body === void 0) return void 0;
7545
- const root = directFixedLexNode(body, resolve3, /* @__PURE__ */ new Set(), false, scope.cleared);
7577
+ const root = directFixedLexNode(body, resolve3, /* @__PURE__ */ new Set(), false, scope2.cleared);
7546
7578
  return root === void 0 ? void 0 : { kind: "fixed-tree", root };
7547
7579
  }
7548
7580
  function directBalancedTokenBody(parser2, resolve3) {
@@ -9180,7 +9212,7 @@ var Encoder = class {
9180
9212
  this.triviaKnown = savedKnown;
9181
9213
  if (d.clearTrivia === true) return this.emit(op, -1, bodyIp, flags);
9182
9214
  if (d.triviaParser === void 0) {
9183
- return cap || flags !== 0 ? this.emit(op, -1, bodyIp, flags) : bodyIp;
9215
+ return cap ? this.emit(op, SCOPE_INHERIT, bodyIp, flags) : bodyIp;
9184
9216
  }
9185
9217
  return this.emit(op, this.triviaSlot(d.triviaParser), bodyIp, flags);
9186
9218
  }
@@ -10572,7 +10604,7 @@ function transfer(code, ip, at, hostCst) {
10572
10604
  const op = code[ip];
10573
10605
  if (op === OP_SCOPE || op === OP_SCOPE_CAP || op === OP_SCOPE_PLAIN) {
10574
10606
  const ki = code[ip + 1];
10575
- const tri = ki < 0 ? TRI_NONE : ki;
10607
+ const tri = ki === SCOPE_INHERIT ? at.tri : ki < 0 ? TRI_NONE : ki;
10576
10608
  const cap = op === OP_SCOPE_CAP ? CAP_ON : at.cap;
10577
10609
  if (tri === at.tri && cap === at.cap) return at;
10578
10610
  return { tri, buf: at.buf, raw: at.raw, cap };
@@ -10646,7 +10678,7 @@ function scanHandoffNeeded(code, ip, labels) {
10646
10678
  if (l.tri === TRI_UNKNOWN) return true;
10647
10679
  const op = code[at];
10648
10680
  if (op === OP_SCAN) return true;
10649
- if (op === OP_TOKEN || op === OP_SCOPE_CAP) continue;
10681
+ if (op === OP_TOKEN || op === OP_SCOPE_CAP && code[at + 1] !== SCOPE_INHERIT) continue;
10650
10682
  if ((op === OP_SCOPE_PLAIN || op === OP_SCOPE) && !(code[at + 1] >= 0 && l.tri === code[at + 1] && (op === OP_SCOPE_PLAIN || code[at + 3] === 0))) continue;
10651
10683
  kids.length = 0;
10652
10684
  if (!childSlots(code, at, kids)) return true;
@@ -11941,6 +11973,15 @@ return r.value
11941
11973
  const cap = op === OP_SCOPE_CAP;
11942
11974
  const flags = op === OP_SCOPE_PLAIN ? 0 : code[ip + 3];
11943
11975
  const child = link(code[ip + 2]);
11976
+ if (ki === SCOPE_INHERIT) {
11977
+ return `${head}
11978
+ const sC=ctx.captureTrivia
11979
+ ctx.captureTrivia=true
11980
+ const v=${child}(input,pos,ctx)
11981
+ ctx.captureTrivia=sC
11982
+ return v
11983
+ }`;
11984
+ }
11944
11985
  const scanFor = swapLegal && ki >= 0 && !triviaLabelled[ki] ? hoist("ts", `TRIVIASCAN[${ki}]`) : "null";
11945
11986
  const tri = ki < 0 ? "undefined" : hoist("tv", `TRIVIA[${ki}]`);
11946
11987
  const lab = ki < 0 ? "undefined" : hoist("tl", `TRIVIA[${ki}]._meta.triviaKindLabels`);
@@ -13529,9 +13570,6 @@ function clearOf(ranges, input, from, to) {
13529
13570
  return true;
13530
13571
  }
13531
13572
 
13532
- // src/version.ts
13533
- var PARSEMAN_VERSION = "0.60.5";
13534
-
13535
13573
  // src/table/assemble.ts
13536
13574
  import { PlainBuf as PlainBuf2, PlainField, PlainLeaf as PlainLeaf9, PlainNode as PlainNode2, PlainSpan as PlainSpan10 } from "../cst/plain.js";
13537
13575
 
@@ -15060,6 +15098,16 @@ function assemble(t, prog, cfg) {
15060
15098
  case OP_SCOPE_CAP:
15061
15099
  case OP_SCOPE_PLAIN: {
15062
15100
  const ki = code[ip + 1];
15101
+ if (ki === SCOPE_INHERIT) {
15102
+ const body = link(code[ip + 2]);
15103
+ return (input, pos, ctx) => {
15104
+ const savedCap = ctx.captureTrivia;
15105
+ ctx.captureTrivia = true;
15106
+ const v = body(input, pos, ctx);
15107
+ ctx.captureTrivia = savedCap;
15108
+ return v;
15109
+ };
15110
+ }
15063
15111
  const scopeTrivia = ki < 0 ? void 0 : trivia2[ki];
15064
15112
  const scopeLabels = scopeTrivia?._meta.triviaKindLabels;
15065
15113
  const scanFor = swapLegal && ki >= 0 && !triviaLabelled[ki] ? triviaScan[ki] : null;
@@ -17540,12 +17588,15 @@ function assertPrintable(prog, who) {
17540
17588
  }
17541
17589
  }
17542
17590
  function programFields(prog, fns, opts = {}) {
17591
+ const tokens = [...new Set(prog.fx.flat())];
17592
+ const tokenAt = new Map(tokens.map((token2, i) => [token2, i]));
17543
17593
  return [
17544
17594
  ...emitAssemblies(prog, opts.assemblies ?? []),
17545
17595
  `c:[${prog.code.join(",")}],`,
17546
17596
  `k:[${prog.k.map(emitConst).join(",")}],`,
17547
17597
  `x:${emitClassPool(prog.cc)},`,
17548
- `e:[${prog.fx.map((f) => `[${f.map(jsString).join(",")}]`).join(",")}],`,
17598
+ `e:[${prog.fx.map((f) => `[${f.map((token2) => tokenAt.get(token2)).join(",")}]`).join(",")}],`,
17599
+ `es:[${tokens.map(jsString).join(",")}],`,
17549
17600
  `d:[${prog.disp.map((a) => `[${a.join(",")}]`).join(",")}],`,
17550
17601
  `r:${JSON.stringify(prog.rules)},`,
17551
17602
  ...prog.lines === 1 ? ["l:1,"] : [],
@@ -20318,7 +20369,7 @@ function runOnce(entry, input, options) {
20318
20369
  const r = invoke(entry, input, 0, ctx);
20319
20370
  const value = r.ok ? r.value : void 0;
20320
20371
  let span = r.span ?? { start: 0, end: 0 };
20321
- const expected = r.ok ? [] : r.expected ?? [];
20372
+ const expected = r.ok ? [] : [...new Set(r.expected ?? [])];
20322
20373
  let unconsumedFrom = null;
20323
20374
  if (r.ok) {
20324
20375
  let pos = span.end;
@@ -20731,12 +20782,12 @@ function isWhenFactory(v) {
20731
20782
  function isStaticValueEntry(v) {
20732
20783
  return !!v && typeof v === "object" && "value" in v && "mfSrcs" in v;
20733
20784
  }
20734
- function wordFactoryFromArgs(args, scope, code, mfs) {
20785
+ function wordFactoryFromArgs(args, scope2, code, mfs) {
20735
20786
  const [boundaryOrOptsArg, optsArg] = args;
20736
20787
  if (boundaryOrOptsArg?.type === "SpreadElement" || optsArg?.type === "SpreadElement") return null;
20737
- const rawBoundaryOrOpts = boundaryOrOptsArg === void 0 ? void 0 : anyValue(boundaryOrOptsArg, scope, code, mfs);
20788
+ const rawBoundaryOrOpts = boundaryOrOptsArg === void 0 ? void 0 : anyValue(boundaryOrOptsArg, scope2, code, mfs);
20738
20789
  const boundaryOrOpts = rawBoundaryOrOpts === void 0 ? "_0-9A-Za-z" : rawBoundaryOrOpts;
20739
- const opts = optsArg === void 0 ? void 0 : anyValue(optsArg, scope, code, mfs);
20790
+ const opts = optsArg === void 0 ? void 0 : anyValue(optsArg, scope2, code, mfs);
20740
20791
  if (typeof boundaryOrOpts === "string") {
20741
20792
  if (opts !== void 0 && (typeof opts !== "object" || opts === null || Array.isArray(opts))) return null;
20742
20793
  const caseInsensitive2 = typeof opts === "object" && opts !== null && "caseInsensitive" in opts ? opts.caseInsensitive : false;
@@ -20760,10 +20811,10 @@ function dispatchWhenOptions(v) {
20760
20811
  if (typeof caseInsensitive !== "boolean") return null;
20761
20812
  return { caseInsensitive };
20762
20813
  }
20763
- function whenFactoryFromArgs(args, scope, code, mfs) {
20814
+ function whenFactoryFromArgs(args, scope2, code, mfs) {
20764
20815
  const [optsArg, extra] = args;
20765
20816
  if (optsArg?.type === "SpreadElement" || extra !== void 0) return null;
20766
- const rawOpts = optsArg === void 0 ? void 0 : anyValue(optsArg, scope, code, mfs);
20817
+ const rawOpts = optsArg === void 0 ? void 0 : anyValue(optsArg, scope2, code, mfs);
20767
20818
  const opts = dispatchWhenOptions(rawOpts);
20768
20819
  return opts === null ? null : { tag: "whenFactory", caseInsensitive: opts.caseInsensitive ?? false };
20769
20820
  }
@@ -20835,20 +20886,20 @@ function gatedArmParts(e) {
20835
20886
  }
20836
20887
  return gate2 && combinator ? { gate: gate2, combinator } : null;
20837
20888
  }
20838
- function dispatchArmValue(node2, scope, code, mfs) {
20889
+ function dispatchArmValue(node2, scope2, code, mfs) {
20839
20890
  if (node2.type === "Identifier") {
20840
- const value = anyValue(node2, scope, code, mfs);
20891
+ const value = anyValue(node2, scope2, code, mfs);
20841
20892
  return isDispatchArm(value) ? value : null;
20842
20893
  }
20843
20894
  if (node2.type !== "CallExpression") return null;
20844
20895
  const callee = node2.callee;
20845
20896
  if (callee.type !== "Identifier") return null;
20846
- const factory = scope.get(callee.name);
20897
+ const factory = scope2.get(callee.name);
20847
20898
  if (isWhenFactory(factory)) {
20848
20899
  const [keyArg, parserArg, extraArg] = node2.arguments;
20849
20900
  if (!keyArg || !parserArg || extraArg !== void 0 || keyArg.type === "SpreadElement" || parserArg.type === "SpreadElement") return null;
20850
- const key = anyValue(keyArg, scope, code, mfs);
20851
- const parserValue = anyValue(parserArg, scope, code, mfs);
20901
+ const key = anyValue(keyArg, scope2, code, mfs);
20902
+ const parserValue = anyValue(parserArg, scope2, code, mfs);
20852
20903
  if (!isCombinator3(parserValue)) return null;
20853
20904
  const opts = { caseInsensitive: factory.caseInsensitive };
20854
20905
  if (typeof key === "string") return when(key, parserValue, opts);
@@ -20859,10 +20910,10 @@ function dispatchArmValue(node2, scope, code, mfs) {
20859
20910
  if (callee.name === "otherwise") {
20860
20911
  const [parserArg, optsArg] = node2.arguments;
20861
20912
  if (!parserArg || parserArg.type === "SpreadElement" || optsArg?.type === "SpreadElement") return null;
20862
- const parserValue = anyValue(parserArg, scope, code, mfs);
20913
+ const parserValue = anyValue(parserArg, scope2, code, mfs);
20863
20914
  if (!isCombinator3(parserValue)) return null;
20864
20915
  if (optsArg === void 0) return otherwise(parserValue);
20865
- const opts = anyValue(optsArg, scope, code, mfs);
20916
+ const opts = anyValue(optsArg, scope2, code, mfs);
20866
20917
  if (typeof opts !== "object" || opts === null) return null;
20867
20918
  const commit = opts.commit;
20868
20919
  if (commit !== void 0 && typeof commit !== "boolean") return null;
@@ -20871,9 +20922,9 @@ function dispatchArmValue(node2, scope, code, mfs) {
20871
20922
  if (callee.name === "when") {
20872
20923
  const [keyArg, parserArg, optsArg] = node2.arguments;
20873
20924
  if (!keyArg || !parserArg || keyArg.type === "SpreadElement" || parserArg.type === "SpreadElement" || optsArg?.type === "SpreadElement") return null;
20874
- const key = anyValue(keyArg, scope, code, mfs);
20875
- const parserValue = anyValue(parserArg, scope, code, mfs);
20876
- const opts = dispatchWhenOptions(optsArg === void 0 ? void 0 : anyValue(optsArg, scope, code, mfs));
20925
+ const key = anyValue(keyArg, scope2, code, mfs);
20926
+ const parserValue = anyValue(parserArg, scope2, code, mfs);
20927
+ const opts = dispatchWhenOptions(optsArg === void 0 ? void 0 : anyValue(optsArg, scope2, code, mfs));
20877
20928
  if (opts === null) return null;
20878
20929
  if (!isCombinator3(parserValue)) return null;
20879
20930
  if (typeof key === "string") return when(key, parserValue, opts);
@@ -20900,8 +20951,8 @@ function isDispatchMatcher(v) {
20900
20951
  if ((rec.kind === "startsWith" || rec.kind === "endsWith") && typeof rec.value === "string") return true;
20901
20952
  return rec.kind === "matches" && typeof rec.value === "string" && typeof rec.flags === "string";
20902
20953
  }
20903
- function scopeGet(scope, name, mfs) {
20904
- const entry = scope.get(name);
20954
+ function scopeGet(scope2, name, mfs) {
20955
+ const entry = scope2.get(name);
20905
20956
  if (!entry) return null;
20906
20957
  if (isScopeEntry(entry)) {
20907
20958
  if (mfs && entry.mfSrcs.length > 0) mfs.push(...entry.mfSrcs);
@@ -20922,10 +20973,10 @@ function staticLiteralValue(expr) {
20922
20973
  const val = unwrapStaticExpr(expr);
20923
20974
  return val.type === "Literal" || val.type === "BooleanLiteral" || val.type === "NumericLiteral" ? val.value : void 0;
20924
20975
  }
20925
- function staticStringArray(expr, scope) {
20976
+ function staticStringArray(expr, scope2) {
20926
20977
  const id = unwrapStaticExpr(expr);
20927
- if (id.type === "Identifier" && scope !== void 0 && id.name !== void 0) {
20928
- const scoped = scope.get(id.name);
20978
+ if (id.type === "Identifier" && scope2 !== void 0 && id.name !== void 0) {
20979
+ const scoped = scope2.get(id.name);
20929
20980
  const value = isStaticValueEntry(scoped) ? scoped.value : scoped;
20930
20981
  return Array.isArray(value) && value.every((v) => typeof v === "string") ? value : void 0;
20931
20982
  }
@@ -20950,11 +21001,11 @@ function staticNodeProject(expr) {
20950
21001
  if (typeof literalValue === "number" || literalValue !== void 0) return { ok: false };
20951
21002
  return { ok: false };
20952
21003
  }
20953
- function scopedStaticValue(expr, scope) {
21004
+ function scopedStaticValue(expr, scope2) {
20954
21005
  const unwrapped = unwrapStaticExpr(expr);
20955
21006
  if (unwrapped.type !== "Identifier" || unwrapped.name === "undefined") return { found: false };
20956
- if (!scope.has(unwrapped.name)) return { found: false };
20957
- const scoped = scope.get(unwrapped.name);
21007
+ if (!scope2.has(unwrapped.name)) return { found: false };
21008
+ const scoped = scope2.get(unwrapped.name);
20958
21009
  const value = isStaticValueEntry(scoped) ? scoped.value : scoped;
20959
21010
  return { found: true, value };
20960
21011
  }
@@ -20980,9 +21031,9 @@ function staticNodeOptionsFromValue(value) {
20980
21031
  }
20981
21032
  return opts.unwrap || opts.collapse || opts.project !== void 0 || opts.captureTrivia || opts.trailingTrivia || opts.tags !== void 0 || opts.buildArity !== void 0 ? opts : void 0;
20982
21033
  }
20983
- function staticNodeOptions(expr, scope) {
21034
+ function staticNodeOptions(expr, scope2) {
20984
21035
  const unwrapped = unwrapStaticExpr(expr);
20985
- const scoped = scopedStaticValue(unwrapped, scope);
21036
+ const scoped = scopedStaticValue(unwrapped, scope2);
20986
21037
  if (scoped.found) return staticNodeOptionsFromValue(scoped.value);
20987
21038
  if (unwrapped.type !== "ObjectExpression") return STATIC_NODE_OPTIONS_NOT_OPTIONS;
20988
21039
  const opts = {};
@@ -21000,7 +21051,7 @@ function staticNodeOptions(expr, scope) {
21000
21051
  if (project?.ok === false) return STATIC_NODE_OPTIONS_FAILED;
21001
21052
  if (project !== void 0) opts.project = project.value;
21002
21053
  } else if (name === "tags") {
21003
- const tags = staticStringArray(p.value, scope);
21054
+ const tags = staticStringArray(p.value, scope2);
21004
21055
  if (tags === void 0) return STATIC_NODE_OPTIONS_FAILED;
21005
21056
  opts.tags = tags;
21006
21057
  } else if (name === "buildArity") {
@@ -21012,21 +21063,21 @@ function staticNodeOptions(expr, scope) {
21012
21063
  return opts.unwrap || opts.collapse || opts.project !== void 0 || opts.captureTrivia || opts.trailingTrivia || opts.tags !== void 0 || opts.buildArity !== void 0 ? opts : void 0;
21013
21064
  }
21014
21065
  var UNKNOWN_OPTIONS = /* @__PURE__ */ Symbol("parseman.unknownOptions");
21015
- function scanOptions(optsArg, scope, code) {
21066
+ function scanOptions(optsArg, scope2, code) {
21016
21067
  if (optsArg === void 0) return void 0;
21017
21068
  if (optsArg.type === "SpreadElement") return UNKNOWN_OPTIONS;
21018
- const opts = anyValue(optsArg, scope, code, []);
21019
- return isHole(optsArg, opts, scope) ? UNKNOWN_OPTIONS : opts;
21069
+ const opts = anyValue(optsArg, scope2, code, []);
21070
+ return isHole(optsArg, opts, scope2) ? UNKNOWN_OPTIONS : opts;
21020
21071
  }
21021
- function exprToCombi(node2, scope, code, mfs) {
21022
- if (node2.type === "Identifier") return scopeGet(scope, node2.name, mfs);
21072
+ function exprToCombi(node2, scope2, code, mfs) {
21073
+ if (node2.type === "Identifier") return scopeGet(scope2, node2.name, mfs);
21023
21074
  if (node2.type !== "CallExpression") return null;
21024
21075
  const callee = node2.callee;
21025
21076
  if (callee.type === "CallExpression" && callee.callee.type === "Identifier" && callee.callee.name === "makeWord") {
21026
21077
  const strArg = node2.arguments[0];
21027
21078
  if (!strArg || strArg.type === "SpreadElement") return null;
21028
- const factory2 = wordFactoryFromArgs(callee.arguments, scope, code, mfs);
21029
- const str = anyValue(strArg, scope, code, mfs);
21079
+ const factory2 = wordFactoryFromArgs(callee.arguments, scope2, code, mfs);
21080
+ const str = anyValue(strArg, scope2, code, mfs);
21030
21081
  if (factory2 === null || typeof str !== "string") return null;
21031
21082
  try {
21032
21083
  return word(str, factory2.boundary, { caseInsensitive: factory2.caseInsensitive });
@@ -21035,11 +21086,11 @@ function exprToCombi(node2, scope, code, mfs) {
21035
21086
  }
21036
21087
  }
21037
21088
  if (callee.type === "Identifier") {
21038
- const factory2 = scope.get(callee.name);
21089
+ const factory2 = scope2.get(callee.name);
21039
21090
  if (isWordFactory(factory2)) {
21040
21091
  const [strArg] = node2.arguments;
21041
21092
  if (!strArg || strArg.type === "SpreadElement") return null;
21042
- const str = anyValue(strArg, scope, code, mfs);
21093
+ const str = anyValue(strArg, scope2, code, mfs);
21043
21094
  if (typeof str !== "string") return null;
21044
21095
  try {
21045
21096
  return word(str, factory2.boundary, { caseInsensitive: factory2.caseInsensitive });
@@ -21052,7 +21103,7 @@ function exprToCombi(node2, scope, code, mfs) {
21052
21103
  if (callee.name === "transform" && code !== void 0 && mfs !== void 0) {
21053
21104
  const [parserArg, fnArg] = node2.arguments;
21054
21105
  if (!parserArg || !fnArg || parserArg.type === "SpreadElement" || fnArg.type === "SpreadElement") return null;
21055
- const inner = anyValue(parserArg, scope, code, mfs);
21106
+ const inner = anyValue(parserArg, scope2, code, mfs);
21056
21107
  if (!isCombinator3(inner)) return null;
21057
21108
  const fnSrc = stripTsFromSource(fnArg, code);
21058
21109
  mfs.push(fnSrc);
@@ -21067,7 +21118,7 @@ function exprToCombi(node2, scope, code, mfs) {
21067
21118
  if ((callee.name === "leaf" || callee.name === "sourceLeaf") && code !== void 0 && mfs !== void 0) {
21068
21119
  const [parserArg, fnArg] = node2.arguments;
21069
21120
  if (!parserArg || !fnArg || parserArg.type === "SpreadElement" || fnArg.type === "SpreadElement") return null;
21070
- const inner = anyValue(parserArg, scope, code, mfs);
21121
+ const inner = anyValue(parserArg, scope2, code, mfs);
21071
21122
  if (!isCombinator3(inner)) return null;
21072
21123
  const fnSrc = stripTsFromSource(fnArg, code);
21073
21124
  mfs.push(fnSrc);
@@ -21082,20 +21133,20 @@ function exprToCombi(node2, scope, code, mfs) {
21082
21133
  if (callee.name === "node" && code !== void 0) {
21083
21134
  const [firstArg, secondArg, thirdArg, fourthArg] = node2.arguments;
21084
21135
  if (!firstArg || firstArg.type === "SpreadElement") return null;
21085
- const firstVal = anyValue(firstArg, scope, code, mfs);
21136
+ const firstVal = anyValue(firstArg, scope2, code, mfs);
21086
21137
  const explicitType = typeof firstVal === "string" ? firstVal : void 0;
21087
21138
  const parserArg = explicitType !== void 0 ? secondArg : firstArg;
21088
21139
  const buildArg = explicitType !== void 0 ? thirdArg : secondArg;
21089
21140
  const optsArg = explicitType !== void 0 ? fourthArg : thirdArg;
21090
21141
  if (!parserArg || parserArg.type === "SpreadElement") return null;
21091
- const inner = anyValue(parserArg, scope, code, mfs);
21142
+ const inner = anyValue(parserArg, scope2, code, mfs);
21092
21143
  if (!isCombinator3(inner)) return null;
21093
21144
  const be = buildArg;
21094
21145
  const buildExpr = be === void 0 || be.type === "SpreadElement" ? void 0 : unwrapStaticExpr(be);
21095
- const buildArgOptions = be !== void 0 && be.type !== "SpreadElement" ? staticNodeOptions(buildArg, scope) : STATIC_NODE_OPTIONS_NOT_OPTIONS;
21146
+ const buildArgOptions = be !== void 0 && be.type !== "SpreadElement" ? staticNodeOptions(buildArg, scope2) : STATIC_NODE_OPTIONS_NOT_OPTIONS;
21096
21147
  if (buildArgOptions === STATIC_NODE_OPTIONS_FAILED) return null;
21097
21148
  const buildArgIsOptions = buildArgOptions !== STATIC_NODE_OPTIONS_NOT_OPTIONS;
21098
- const scopedBuild = buildExpr === void 0 ? { found: false } : scopedStaticValue(buildExpr, scope);
21149
+ const scopedBuild = buildExpr === void 0 ? { found: false } : scopedStaticValue(buildExpr, scope2);
21099
21150
  const absentBuild = buildExpr?.type === "Identifier" && buildExpr.name === "undefined" || buildExpr !== void 0 && staticLiteralValue(buildExpr) === null || scopedBuild.found && (scopedBuild.value === void 0 || scopedBuild.value === null);
21100
21151
  const hasBuild = be !== void 0 && be.type !== "SpreadElement" && !buildArgIsOptions && !absentBuild;
21101
21152
  const buildSrc = hasBuild ? stripTsFromSource(be, code) : void 0;
@@ -21104,7 +21155,7 @@ function exprToCombi(node2, scope, code, mfs) {
21104
21155
  opts = buildArgOptions;
21105
21156
  } else if (optsArg !== void 0) {
21106
21157
  if (optsArg.type === "SpreadElement") return null;
21107
- const optsResult = staticNodeOptions(optsArg, scope);
21158
+ const optsResult = staticNodeOptions(optsArg, scope2);
21108
21159
  if (optsResult === STATIC_NODE_OPTIONS_FAILED || optsResult === STATIC_NODE_OPTIONS_NOT_OPTIONS) return null;
21109
21160
  opts = optsResult;
21110
21161
  }
@@ -21160,9 +21211,9 @@ function exprToCombi(node2, scope, code, mfs) {
21160
21211
  if (callee.name === "parser") {
21161
21212
  const [optsArg, rootArg] = node2.arguments;
21162
21213
  if (!optsArg || !rootArg || optsArg.type === "SpreadElement" || rootArg.type === "SpreadElement") return null;
21163
- const opts = anyValue(optsArg, scope, code, []);
21214
+ const opts = anyValue(optsArg, scope2, code, []);
21164
21215
  if (!opts || typeof opts !== "object") return null;
21165
- const root = anyValue(rootArg, scope, code, mfs);
21216
+ const root = anyValue(rootArg, scope2, code, mfs);
21166
21217
  if (!isCombinator3(root)) return null;
21167
21218
  try {
21168
21219
  return parser(opts, root);
@@ -21174,15 +21225,15 @@ function exprToCombi(node2, scope, code, mfs) {
21174
21225
  const [itemArg, sepArg, optsArg] = node2.arguments;
21175
21226
  if (!itemArg || !sepArg || itemArg.type === "SpreadElement" || sepArg.type === "SpreadElement") return null;
21176
21227
  const itemMfs = [];
21177
- const itemCombi = anyValue(itemArg, scope, code, itemMfs);
21228
+ const itemCombi = anyValue(itemArg, scope2, code, itemMfs);
21178
21229
  if (!isCombinator3(itemCombi)) return null;
21179
21230
  const sepMfs = [];
21180
- const sepCombi = anyValue(sepArg, scope, code, sepMfs);
21231
+ const sepCombi = anyValue(sepArg, scope2, code, sepMfs);
21181
21232
  if (!isCombinator3(sepCombi)) return null;
21182
21233
  let opts;
21183
21234
  if (optsArg) {
21184
21235
  if (optsArg.type === "SpreadElement") return null;
21185
- const v = anyValue(optsArg, scope, code, []);
21236
+ const v = anyValue(optsArg, scope2, code, []);
21186
21237
  if (!v || typeof v !== "object") return null;
21187
21238
  opts = v;
21188
21239
  }
@@ -21197,12 +21248,12 @@ function exprToCombi(node2, scope, code, mfs) {
21197
21248
  const [itemArg, optsArg] = node2.arguments;
21198
21249
  if (!itemArg || itemArg.type === "SpreadElement") return null;
21199
21250
  const itemMfs = [];
21200
- const itemCombi = anyValue(itemArg, scope, code, itemMfs);
21251
+ const itemCombi = anyValue(itemArg, scope2, code, itemMfs);
21201
21252
  if (!isCombinator3(itemCombi)) return null;
21202
21253
  let opts;
21203
21254
  if (optsArg) {
21204
21255
  if (optsArg.type === "SpreadElement") return null;
21205
- const v = anyValue(optsArg, scope, code, []);
21256
+ const v = anyValue(optsArg, scope2, code, []);
21206
21257
  if (!v || typeof v !== "object") return null;
21207
21258
  opts = v;
21208
21259
  }
@@ -21219,7 +21270,7 @@ function exprToCombi(node2, scope, code, mfs) {
21219
21270
  if (callee.name === "not") {
21220
21271
  const [innerArg] = node2.arguments;
21221
21272
  if (!innerArg || innerArg.type === "SpreadElement") return null;
21222
- const inner = anyValue(innerArg, scope, code, mfs);
21273
+ const inner = anyValue(innerArg, scope2, code, mfs);
21223
21274
  if (!isCombinator3(inner)) return null;
21224
21275
  try {
21225
21276
  return not(inner);
@@ -21230,7 +21281,7 @@ function exprToCombi(node2, scope, code, mfs) {
21230
21281
  if (callee.name === "peek") {
21231
21282
  const [innerArg] = node2.arguments;
21232
21283
  if (!innerArg || innerArg.type === "SpreadElement") return null;
21233
- const inner = anyValue(innerArg, scope, code, mfs);
21284
+ const inner = anyValue(innerArg, scope2, code, mfs);
21234
21285
  if (!isCombinator3(inner)) return null;
21235
21286
  try {
21236
21287
  return peek(inner);
@@ -21241,10 +21292,10 @@ function exprToCombi(node2, scope, code, mfs) {
21241
21292
  if (callee.name === "balanced") {
21242
21293
  const [openArg, closeArg, optsArg] = node2.arguments;
21243
21294
  if (!openArg || !closeArg || openArg.type === "SpreadElement" || closeArg.type === "SpreadElement") return null;
21244
- const open = anyValue(openArg, scope, code, []);
21245
- const close = anyValue(closeArg, scope, code, []);
21295
+ const open = anyValue(openArg, scope2, code, []);
21296
+ const close = anyValue(closeArg, scope2, code, []);
21246
21297
  if (typeof open !== "string" || typeof close !== "string") return null;
21247
- const opts = scanOptions(optsArg, scope, code);
21298
+ const opts = scanOptions(optsArg, scope2, code);
21248
21299
  if (opts === UNKNOWN_OPTIONS) return null;
21249
21300
  try {
21250
21301
  return balanced(open, close, opts);
@@ -21255,9 +21306,9 @@ function exprToCombi(node2, scope, code, mfs) {
21255
21306
  if (callee.name === "scanTo") {
21256
21307
  const [sentinelArg, optsArg] = node2.arguments;
21257
21308
  if (!sentinelArg || sentinelArg.type === "SpreadElement") return null;
21258
- const sentinel = anyValue(sentinelArg, scope, code, []);
21309
+ const sentinel = anyValue(sentinelArg, scope2, code, []);
21259
21310
  if (!isCombinator3(sentinel)) return null;
21260
- const opts = scanOptions(optsArg, scope, code);
21311
+ const opts = scanOptions(optsArg, scope2, code);
21261
21312
  if (opts === UNKNOWN_OPTIONS) return null;
21262
21313
  try {
21263
21314
  return scanTo(sentinel, opts);
@@ -21286,12 +21337,12 @@ function exprToCombi(node2, scope, code, mfs) {
21286
21337
  if (!extraArg || !innerArg || extraArg.type === "SpreadElement" || innerArg.type === "SpreadElement") return null;
21287
21338
  const extraSrc = stripTsFromSource(extraArg, code);
21288
21339
  mfs.push(extraSrc);
21289
- const inner = anyValue(innerArg, scope, code, mfs);
21340
+ const inner = anyValue(innerArg, scope2, code, mfs);
21290
21341
  if (!isCombinator3(inner)) return null;
21291
21342
  try {
21292
21343
  const extraType = unwrapStaticExpr(extraArg).type;
21293
21344
  const derives = extraType === "ArrowFunctionExpression" || extraType === "FunctionExpression";
21294
- const evaluated = derives ? null : anyValue(extraArg, scope, code, []);
21345
+ const evaluated = derives ? null : anyValue(extraArg, scope2, code, []);
21295
21346
  const usable = typeof evaluated === "object" && evaluated !== null && !Array.isArray(evaluated) && Object.getPrototypeOf(evaluated) === Object.prototype;
21296
21347
  const combi = withCtx(derives ? DERIVE_STAND_IN : usable ? evaluated : UNEVALUATED_EXTRA, inner);
21297
21348
  if (combi._def.tag !== "withCtx") return null;
@@ -21304,12 +21355,12 @@ function exprToCombi(node2, scope, code, mfs) {
21304
21355
  if (callee.name === "dispatch") {
21305
21356
  const [selectorArg, ...armArgs] = node2.arguments;
21306
21357
  if (!selectorArg || selectorArg.type === "SpreadElement") return null;
21307
- const selector = anyValue(selectorArg, scope, code, mfs);
21358
+ const selector = anyValue(selectorArg, scope2, code, mfs);
21308
21359
  if (!isCombinator3(selector)) return null;
21309
21360
  const arms = [];
21310
21361
  for (const arg of armArgs) {
21311
21362
  if (arg.type === "SpreadElement") return null;
21312
- const arm = dispatchArmValue(arg, scope, code, mfs);
21363
+ const arm = dispatchArmValue(arg, scope2, code, mfs);
21313
21364
  if (!isDispatchArm(arm)) return null;
21314
21365
  arms.push(arm);
21315
21366
  }
@@ -21331,12 +21382,12 @@ function exprToCombi(node2, scope, code, mfs) {
21331
21382
  if (!parts) return null;
21332
21383
  const gateSrc = stripTsFromSource(parts.gate, code);
21333
21384
  mfs.push(gateSrc);
21334
- const combi = anyValue(parts.combinator, scope, code, mfs);
21385
+ const combi = anyValue(parts.combinator, scope2, code, mfs);
21335
21386
  if (!isCombinator3(combi)) return null;
21336
21387
  arms.push({ gate: () => true, combinator: combi });
21337
21388
  gateSrcs.push(gateSrc);
21338
21389
  } else {
21339
- const combi = anyValue(argNode, scope, code, mfs);
21390
+ const combi = anyValue(argNode, scope2, code, mfs);
21340
21391
  if (!isCombinator3(combi)) return null;
21341
21392
  arms.push(combi);
21342
21393
  gateSrcs.push(null);
@@ -21358,7 +21409,7 @@ function exprToCombi(node2, scope, code, mfs) {
21358
21409
  if (!factory) return null;
21359
21410
  const args = node2.arguments.map((arg) => {
21360
21411
  if (arg.type === "SpreadElement") return null;
21361
- return anyValue(arg, scope, code, mfs);
21412
+ return anyValue(arg, scope2, code, mfs);
21362
21413
  });
21363
21414
  if (args.some((a) => a === null)) return null;
21364
21415
  try {
@@ -21367,16 +21418,16 @@ function exprToCombi(node2, scope, code, mfs) {
21367
21418
  return null;
21368
21419
  }
21369
21420
  }
21370
- function isHole(node2, value, scope) {
21421
+ function isHole(node2, value, scope2) {
21371
21422
  if (value !== null) return false;
21372
21423
  const n = unwrapStaticExpr(node2);
21373
- if (n.type === "Identifier") return !scope.has(n.name);
21424
+ if (n.type === "Identifier") return !scope2.has(n.name);
21374
21425
  return !(n.type === "Literal" && n.value === null) && n.type !== "ArrowFunctionExpression" && n.type !== "FunctionExpression";
21375
21426
  }
21376
- function anyValue(node2, scope, code, mfs) {
21427
+ function anyValue(node2, scope2, code, mfs) {
21377
21428
  if (node2.type === "TSAsExpression" || node2.type === "TSSatisfiesExpression" || node2.type === "TSNonNullExpression" || node2.type === "TSTypeAssertion" || node2.type === "TSInstantiationExpression" || node2.type === "ParenthesizedExpression") {
21378
21429
  const inner = node2.expression;
21379
- return inner ? anyValue(inner, scope, code, mfs) : null;
21430
+ return inner ? anyValue(inner, scope2, code, mfs) : null;
21380
21431
  }
21381
21432
  if (node2.type === "Literal") {
21382
21433
  if ("regex" in node2 && node2.regex !== null && node2.regex !== void 0) {
@@ -21393,8 +21444,8 @@ function anyValue(node2, scope, code, mfs) {
21393
21444
  continue;
21394
21445
  }
21395
21446
  if (el.type === "SpreadElement") return null;
21396
- const v = anyValue(el, scope, code, mfs);
21397
- if (isHole(el, v, scope)) return null;
21447
+ const v = anyValue(el, scope2, code, mfs);
21448
+ if (isHole(el, v, scope2)) return null;
21398
21449
  out.push(v);
21399
21450
  }
21400
21451
  return out;
@@ -21405,15 +21456,15 @@ function anyValue(node2, scope, code, mfs) {
21405
21456
  const key = propName(prop);
21406
21457
  if (key === null) return null;
21407
21458
  const valueNode = prop.value;
21408
- const v = anyValue(valueNode, scope, code, mfs);
21409
- if (isHole(valueNode, v, scope)) return null;
21459
+ const v = anyValue(valueNode, scope2, code, mfs);
21460
+ if (isHole(valueNode, v, scope2)) return null;
21410
21461
  obj[key] = v;
21411
21462
  }
21412
21463
  return obj;
21413
21464
  }
21414
21465
  if (node2.type === "Identifier") {
21415
21466
  if (node2.name === "undefined") return void 0;
21416
- const entry = scope.get(node2.name) ?? null;
21467
+ const entry = scope2.get(node2.name) ?? null;
21417
21468
  if (isScopeEntry(entry)) {
21418
21469
  if (mfs && entry.mfSrcs.length > 0) mfs.push(...entry.mfSrcs);
21419
21470
  return entry.combi;
@@ -21426,10 +21477,10 @@ function anyValue(node2, scope, code, mfs) {
21426
21477
  }
21427
21478
  if (node2.type === "MemberExpression") {
21428
21479
  const mem = node2;
21429
- const obj = anyValue(mem.object, scope, code, mfs);
21480
+ const obj = anyValue(mem.object, scope2, code, mfs);
21430
21481
  if (!obj || typeof obj !== "object") return null;
21431
21482
  if (node2.computed) {
21432
- const key = anyValue(node2.property, scope, code, mfs);
21483
+ const key = anyValue(node2.property, scope2, code, mfs);
21433
21484
  if (typeof key !== "string" && typeof key !== "number") return null;
21434
21485
  return obj[key] ?? null;
21435
21486
  }
@@ -21440,50 +21491,50 @@ function anyValue(node2, scope, code, mfs) {
21440
21491
  if (node2.type === "CallExpression") {
21441
21492
  const callee = node2.callee;
21442
21493
  if (callee.type === "Identifier" && callee.name === "makeWord") {
21443
- return wordFactoryFromArgs(node2.arguments, scope, code, mfs);
21494
+ return wordFactoryFromArgs(node2.arguments, scope2, code, mfs);
21444
21495
  }
21445
21496
  if (callee.type === "Identifier" && callee.name === "makeWhen") {
21446
- return whenFactoryFromArgs(node2.arguments, scope, code, mfs);
21497
+ return whenFactoryFromArgs(node2.arguments, scope2, code, mfs);
21447
21498
  }
21448
21499
  if (callee.type === "Identifier" && (callee.name === "startsWith" || callee.name === "endsWith")) {
21449
21500
  if (node2.arguments.length !== 1 || node2.arguments[0]?.type === "SpreadElement") return null;
21450
- const value = anyValue(node2.arguments[0], scope, code, mfs);
21501
+ const value = anyValue(node2.arguments[0], scope2, code, mfs);
21451
21502
  if (typeof value !== "string") return null;
21452
21503
  return callee.name === "startsWith" ? startsWith(value) : endsWith(value);
21453
21504
  }
21454
21505
  if (callee.type === "Identifier" && callee.name === "matches") {
21455
21506
  if (node2.arguments.length !== 1 || node2.arguments[0]?.type === "SpreadElement") return null;
21456
- const value = anyValue(node2.arguments[0], scope, code, mfs);
21507
+ const value = anyValue(node2.arguments[0], scope2, code, mfs);
21457
21508
  if (!(value instanceof RegExp)) return null;
21458
21509
  return matches(value);
21459
21510
  }
21460
21511
  if (callee.type === "Identifier" && (callee.name === "when" || callee.name === "otherwise")) {
21461
- return dispatchArmValue(node2, scope, code, mfs);
21512
+ return dispatchArmValue(node2, scope2, code, mfs);
21462
21513
  }
21463
- if (callee.type === "Identifier" && isWhenFactory(scope.get(callee.name))) {
21464
- return dispatchArmValue(node2, scope, code, mfs);
21514
+ if (callee.type === "Identifier" && isWhenFactory(scope2.get(callee.name))) {
21515
+ return dispatchArmValue(node2, scope2, code, mfs);
21465
21516
  }
21466
- return exprToCombi(node2, scope, code, mfs);
21517
+ return exprToCombi(node2, scope2, code, mfs);
21467
21518
  }
21468
21519
  return null;
21469
21520
  }
21470
- function evaluateWordFactory(node2, scope, code) {
21521
+ function evaluateWordFactory(node2, scope2, code) {
21471
21522
  if (node2.type !== "CallExpression") return null;
21472
21523
  const callee = node2.callee;
21473
21524
  if (callee.type !== "Identifier" || callee.name !== "makeWord") return null;
21474
- return wordFactoryFromArgs(node2.arguments, scope, code);
21525
+ return wordFactoryFromArgs(node2.arguments, scope2, code);
21475
21526
  }
21476
- function evaluateWhenFactory(node2, scope, code) {
21527
+ function evaluateWhenFactory(node2, scope2, code) {
21477
21528
  if (node2.type !== "CallExpression") return null;
21478
21529
  const callee = node2.callee;
21479
21530
  if (callee.type !== "Identifier" || callee.name !== "makeWhen") return null;
21480
- return whenFactoryFromArgs(node2.arguments, scope, code);
21531
+ return whenFactoryFromArgs(node2.arguments, scope2, code);
21481
21532
  }
21482
- function evaluateExpr(node2, scope, code, mapFnSources) {
21483
- return exprToCombi(node2, scope, code, mapFnSources);
21533
+ function evaluateExpr(node2, scope2, code, mapFnSources) {
21534
+ return exprToCombi(node2, scope2, code, mapFnSources);
21484
21535
  }
21485
- function evaluateCombinatorArray(node2, scope, code) {
21486
- const val = anyValue(node2, scope, code, []);
21536
+ function evaluateCombinatorArray(node2, scope2, code) {
21537
+ const val = anyValue(node2, scope2, code, []);
21487
21538
  if (!Array.isArray(val) || val.length === 0) return null;
21488
21539
  if (!val.every(isCombinator3)) return null;
21489
21540
  return val;
@@ -21497,15 +21548,15 @@ function collectRuleKeys(retObj) {
21497
21548
  }
21498
21549
  return out;
21499
21550
  }
21500
- function evaluateStaticValue(node2, scope, code) {
21501
- return anyValue(node2, scope, code, []);
21551
+ function evaluateStaticValue(node2, scope2, code) {
21552
+ return anyValue(node2, scope2, code, []);
21502
21553
  }
21503
- function flattenRuleEntries(retObj, scope, code) {
21554
+ function flattenRuleEntries(retObj, scope2, code) {
21504
21555
  const out = [];
21505
21556
  for (const prop of retObj.properties) {
21506
21557
  const key = propName(prop);
21507
21558
  if (!key) return null;
21508
- out.push({ key, value: prop.value, scope, code });
21559
+ out.push({ key, value: prop.value, scope: scope2, code });
21509
21560
  }
21510
21561
  return out;
21511
21562
  }
@@ -21523,7 +21574,7 @@ function identifierNamesIn(node2, out = /* @__PURE__ */ new Set()) {
21523
21574
  }
21524
21575
  return out;
21525
21576
  }
21526
- function evalBodyStatements(statements, scope, code, out) {
21577
+ function evalBodyStatements(statements, scope2, code, out) {
21527
21578
  const bodyMfs = [];
21528
21579
  const laterNames = [];
21529
21580
  {
@@ -21553,7 +21604,7 @@ function evalBodyStatements(statements, scope, code, out) {
21553
21604
  return false;
21554
21605
  }
21555
21606
  const before = bodyMfs.length;
21556
- const val = anyValue(decl.init, scope, code, bodyMfs);
21607
+ const val = anyValue(decl.init, scope2, code, bodyMfs);
21557
21608
  if (val === null) {
21558
21609
  if (out) {
21559
21610
  const used = identifierNamesIn(decl.init);
@@ -21563,14 +21614,14 @@ function evalBodyStatements(statements, scope, code, out) {
21563
21614
  return false;
21564
21615
  }
21565
21616
  const thisDeclMfSrcs = bodyMfs.slice(before);
21566
- if (isCombinator3(val)) scope.set(name, { combi: val, mfSrcs: thisDeclMfSrcs });
21567
- else if (isDispatchArm(val)) scope.set(name, { value: val, mfSrcs: thisDeclMfSrcs });
21568
- else scope.set(name, val);
21617
+ if (isCombinator3(val)) scope2.set(name, { combi: val, mfSrcs: thisDeclMfSrcs });
21618
+ else if (isDispatchArm(val)) scope2.set(name, { value: val, mfSrcs: thisDeclMfSrcs });
21619
+ else scope2.set(name, val);
21569
21620
  }
21570
21621
  }
21571
21622
  return true;
21572
21623
  }
21573
- function evaluateParserFactory(factoryNode, scope, code, mapFnSources, out, options) {
21624
+ function evaluateParserFactory(factoryNode, scope2, code, mapFnSources, out, options) {
21574
21625
  if (factoryNode.type !== "ArrowFunctionExpression" && factoryNode.type !== "FunctionDeclaration" && factoryNode.type !== "FunctionExpression") return null;
21575
21626
  const factory = factoryNode;
21576
21627
  const params = factory.params;
@@ -21613,7 +21664,7 @@ function evaluateParserFactory(factoryNode, scope, code, mapFnSources, out, opti
21613
21664
  let built;
21614
21665
  try {
21615
21666
  built = rules(options ?? {}, (g, prior) => {
21616
- const localScope = scope instanceof ModuleScope ? scope.fork() : new Map(scope);
21667
+ const localScope = scope2 instanceof ModuleScope ? scope2.fork() : new Map(scope2);
21617
21668
  localScope.set(proxyName, g);
21618
21669
  if (priorName !== void 0) localScope.set(priorName, prior);
21619
21670
  if (!evalBodyStatements(statements, localScope, code, out)) throw ABORT;
@@ -21646,16 +21697,16 @@ var externalAccesses = /* @__PURE__ */ new WeakMap();
21646
21697
  function isDefinableRef2(v) {
21647
21698
  return isCombinator3(v) && typeof v.define === "function" && v._def.tag === "lazy";
21648
21699
  }
21649
- function evaluateRefDeclaration(init, name, scope) {
21700
+ function evaluateRefDeclaration(init, name, scope2) {
21650
21701
  if (init.type !== "CallExpression") return null;
21651
21702
  const callee = init.callee;
21652
21703
  if (callee.type !== "Identifier" || callee.name !== "ref") return null;
21653
21704
  if (init.arguments.length !== 0) return null;
21654
21705
  const slot = ref();
21655
- scope.set(name, { combi: slot, mfSrcs: [] });
21706
+ scope2.set(name, { combi: slot, mfSrcs: [] });
21656
21707
  return slot;
21657
21708
  }
21658
- function applyDefineStatement(callExpr, scope, code) {
21709
+ function applyDefineStatement(callExpr, scope2, code) {
21659
21710
  if (callExpr.type !== "CallExpression") return false;
21660
21711
  const callee = callExpr.callee;
21661
21712
  if (callee.type !== "MemberExpression") return false;
@@ -21663,12 +21714,12 @@ function applyDefineStatement(callExpr, scope, code) {
21663
21714
  if (mem.computed) return false;
21664
21715
  if (mem.property.type !== "Identifier" || mem.property.name !== "define") return false;
21665
21716
  if (mem.object.type !== "Identifier" || !mem.object.name) return false;
21666
- const target = scope.get(mem.object.name);
21717
+ const target = scope2.get(mem.object.name);
21667
21718
  const refCombi = isScopeEntry(target) ? target.combi : isCombinator3(target) ? target : null;
21668
21719
  if (!refCombi || !isDefinableRef2(refCombi)) return false;
21669
21720
  const args = callExpr.arguments;
21670
21721
  if (args.length !== 1 || args[0].type === "SpreadElement") return false;
21671
- const inner = anyValue(args[0], scope, code, []);
21722
+ const inner = anyValue(args[0], scope2, code, []);
21672
21723
  if (!isCombinator3(inner)) return false;
21673
21724
  try {
21674
21725
  refCombi.define(inner);
@@ -21677,17 +21728,17 @@ function applyDefineStatement(callExpr, scope, code) {
21677
21728
  }
21678
21729
  return true;
21679
21730
  }
21680
- function referencesAny(node2, names, scope) {
21731
+ function referencesAny(node2, names, scope2) {
21681
21732
  if (node2.type === "Identifier") {
21682
- return names.has(node2.name) || Map.prototype.has.call(scope, node2.name);
21733
+ return names.has(node2.name) || Map.prototype.has.call(scope2, node2.name);
21683
21734
  }
21684
21735
  for (const key of Object.keys(node2)) {
21685
21736
  const child = node2[key];
21686
21737
  if (!child || typeof child !== "object") continue;
21687
21738
  if (Array.isArray(child)) {
21688
- if (child.some((c) => c && typeof c === "object" && "type" in c && referencesAny(c, names, scope))) return true;
21739
+ if (child.some((c) => c && typeof c === "object" && "type" in c && referencesAny(c, names, scope2))) return true;
21689
21740
  } else if ("type" in child) {
21690
- if (referencesAny(child, names, scope)) return true;
21741
+ if (referencesAny(child, names, scope2)) return true;
21691
21742
  }
21692
21743
  }
21693
21744
  return false;
@@ -21739,30 +21790,30 @@ function patternNames(pat, out) {
21739
21790
  return;
21740
21791
  }
21741
21792
  }
21742
- function declare(scope, name, b) {
21743
- const prev = scope.bindings.get(name);
21793
+ function declare(scope2, name, b) {
21794
+ const prev = scope2.bindings.get(name);
21744
21795
  if (prev) prev.reassigned = true;
21745
- else scope.bindings.set(name, b);
21796
+ else scope2.bindings.set(name, b);
21746
21797
  }
21747
- function functionScope(scope) {
21748
- let s = scope;
21798
+ function functionScope(scope2) {
21799
+ let s = scope2;
21749
21800
  while (!s.isFunction && s.parent) s = s.parent;
21750
21801
  return s;
21751
21802
  }
21752
21803
  function buildScopeTree(body, moduleEnd) {
21753
21804
  const root = newScope(0, moduleEnd, null, true);
21754
- const declarePattern = (scope, pat, kind, init) => {
21805
+ const declarePattern = (scope2, pat, kind, init) => {
21755
21806
  const names = [];
21756
21807
  patternNames(pat, names);
21757
- const target = kind === "var" ? functionScope(scope) : scope;
21808
+ const target = kind === "var" ? functionScope(scope2) : scope2;
21758
21809
  for (const name of names) {
21759
21810
  declare(target, name, init !== void 0 && names.length === 1 ? { kind, init } : { kind });
21760
21811
  }
21761
21812
  };
21762
- const walk = (n, scope) => {
21813
+ const walk = (n, scope2) => {
21763
21814
  if (!n || typeof n !== "object") return;
21764
21815
  if (Array.isArray(n)) {
21765
- for (const item of n) walk(item, scope);
21816
+ for (const item of n) walk(item, scope2);
21766
21817
  return;
21767
21818
  }
21768
21819
  const node2 = n;
@@ -21771,15 +21822,15 @@ function buildScopeTree(body, moduleEnd) {
21771
21822
  case "VariableDeclaration": {
21772
21823
  const kind = node2.kind ?? "var";
21773
21824
  for (const d of node2.declarations ?? []) {
21774
- declarePattern(scope, d.id, kind, d.init ?? void 0);
21825
+ declarePattern(scope2, d.id, kind, d.init ?? void 0);
21775
21826
  }
21776
21827
  break;
21777
21828
  }
21778
21829
  case "FunctionDeclaration":
21779
- if (node2.id) declare(functionScope(scope), node2.id.name, { kind: "function", init: node2 });
21830
+ if (node2.id) declare(functionScope(scope2), node2.id.name, { kind: "function", init: node2 });
21780
21831
  break;
21781
21832
  case "ClassDeclaration":
21782
- if (node2.id) declare(scope, node2.id.name, { kind: "class" });
21833
+ if (node2.id) declare(scope2, node2.id.name, { kind: "class" });
21783
21834
  break;
21784
21835
  case "ImportDeclaration": {
21785
21836
  const specifier = node2.source?.value ?? "";
@@ -21787,7 +21838,7 @@ function buildScopeTree(body, moduleEnd) {
21787
21838
  const local = sp.local?.name;
21788
21839
  if (!local) continue;
21789
21840
  const imported = sp.type === "ImportDefaultSpecifier" ? "default" : sp.type === "ImportNamespaceSpecifier" ? "*" : sp.imported?.name ?? local;
21790
- declare(scope, local, { kind: "import", importRef: { specifier, imported } });
21841
+ declare(scope2, local, { kind: "import", importRef: { specifier, imported } });
21791
21842
  }
21792
21843
  break;
21793
21844
  }
@@ -21796,7 +21847,7 @@ function buildScopeTree(body, moduleEnd) {
21796
21847
  }
21797
21848
  if (SCOPE_TYPES.has(node2.type)) {
21798
21849
  const isFn = FUNCTION_TYPES.has(node2.type);
21799
- const inner = newScope(node2.start, node2.end, scope, isFn);
21850
+ const inner = newScope(node2.start, node2.end, scope2, isFn);
21800
21851
  if (isFn) {
21801
21852
  for (const p of node2.params ?? []) declarePattern(inner, p, "param");
21802
21853
  if (node2.type === "FunctionExpression" && node2.id) {
@@ -21812,7 +21863,7 @@ function buildScopeTree(body, moduleEnd) {
21812
21863
  }
21813
21864
  for (const key of Object.keys(node2)) {
21814
21865
  if (key === "type" || key === "start" || key === "end") continue;
21815
- walk(node2[key], scope);
21866
+ walk(node2[key], scope2);
21816
21867
  }
21817
21868
  };
21818
21869
  for (const stmt of body) walk(stmt, root);
@@ -21826,8 +21877,8 @@ function scopeAt(root, offset) {
21826
21877
  cur = next;
21827
21878
  }
21828
21879
  }
21829
- function lookup(scope, name) {
21830
- for (let s = scope; s; s = s.parent) {
21880
+ function lookup(scope2, name) {
21881
+ for (let s = scope2; s; s = s.parent) {
21831
21882
  const b = s.bindings.get(name);
21832
21883
  if (b) return { binding: b, scope: s };
21833
21884
  }
@@ -23553,7 +23604,7 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
23553
23604
  const stuck = rebaseCarriedBuilderImports(combi2, m.file);
23554
23605
  return stuck ? { unresolved: `has a node() builder reading \`${stuck.local}\` from '${stuck.source}' inside ${m.file}, which this module cannot import \u2014 import it there by package name` } : { value: { combi: combi2, mfSrcs: [] } };
23555
23606
  }
23556
- const scope2 = moduleValueScope(m);
23607
+ const scope3 = moduleValueScope(m);
23557
23608
  reducerResolver.register(m.file);
23558
23609
  builderImports = (name2) => {
23559
23610
  const b = m.imports.get(name2);
@@ -23561,11 +23612,11 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
23561
23612
  return b && source !== null ? { source, imported: b.imported } : null;
23562
23613
  };
23563
23614
  const mfs = [];
23564
- const combi = evaluateExpr(init, scope2, m.src, mfs);
23615
+ const combi = evaluateExpr(init, scope3, m.src, mfs);
23565
23616
  if (combi) return { value: { combi, mfSrcs: mfs } };
23566
- const factory = evaluateWordFactory(init, scope2, m.src) ?? evaluateWhenFactory(init, scope2, m.src);
23617
+ const factory = evaluateWordFactory(init, scope3, m.src) ?? evaluateWhenFactory(init, scope3, m.src);
23567
23618
  if (factory) return { value: factory };
23568
- const value = evaluateStaticValue(init, scope2, m.src);
23619
+ const value = evaluateStaticValue(init, scope3, m.src);
23569
23620
  if (value !== null && value !== void 0 || isStaticNullishExpression(init)) return { value };
23570
23621
  return {
23571
23622
  unresolved: /\btableRules\b/.test(m.src.slice(init.start, init.end)) ? `is a compiled parser in ${m.file} that carries no combinator IR \u2014 rebuild that module with parseman v${PARSEMAN_VERSION}` : `is not a statically-known combinator or value (${m.file})`
@@ -23606,12 +23657,12 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
23606
23657
  }
23607
23658
  return { unresolved: `is not exported by ${m.file}` };
23608
23659
  }
23609
- const scope2 = moduleValueScope(m);
23610
- if (!scope2.has(local)) {
23611
- scope2.get(local);
23660
+ const scope3 = moduleValueScope(m);
23661
+ if (!scope3.has(local)) {
23662
+ scope3.get(local);
23612
23663
  return { unresolved: `could not be resolved in ${m.file}` };
23613
23664
  }
23614
- return { value: scope2.get(local) };
23665
+ return { value: scope3.get(local) };
23615
23666
  };
23616
23667
  const importedValue = (from, binding) => {
23617
23668
  const file = resolveValueFile(from, binding.source);
@@ -23630,7 +23681,7 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
23630
23681
  deferredLocals.delete(name);
23631
23682
  const outer = [...unresolvedImports];
23632
23683
  unresolvedImports.clear();
23633
- const value = evaluateStaticValue(deferred, scope, code);
23684
+ const value = evaluateStaticValue(deferred, scope2, code);
23634
23685
  const why = [...unresolvedImports];
23635
23686
  unresolvedImports.clear();
23636
23687
  for (const n of outer) unresolvedImports.add(n);
@@ -23744,7 +23795,7 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
23744
23795
  });
23745
23796
  reducerResolver.register(file);
23746
23797
  }
23747
- const scope = new ModuleScope(resolveMainFree, unresolvedImports);
23798
+ const scope2 = new ModuleScope(resolveMainFree, unresolvedImports);
23748
23799
  const replacements = [];
23749
23800
  const warnings = [];
23750
23801
  beginDegradationCapture();
@@ -23826,7 +23877,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
23826
23877
  const out = evaluate(value);
23827
23878
  if (out === null) {
23828
23879
  const id2 = value.type === "Identifier" ? value.name : null;
23829
- if (id2 !== null && scope.has(id2) && scope.get(id2) == null) return void 0;
23880
+ if (id2 !== null && scope2.has(id2) && scope2.get(id2) == null) return void 0;
23830
23881
  return unevaluable(value.start, `${label2}: rules({ ${name} })`);
23831
23882
  }
23832
23883
  unresolvedImports.clear();
@@ -23836,7 +23887,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
23836
23887
  const assertPlainOptions = (optExpr, label2) => {
23837
23888
  for (const p of optExpr?.type === "ObjectExpression" ? optExpr.properties : []) {
23838
23889
  if (propName(p) !== null) continue;
23839
- const key = p.type === "Property" ? evaluateStaticValue(p.key, scope, code) : null;
23890
+ const key = p.type === "Property" ? evaluateStaticValue(p.key, scope2, code) : null;
23840
23891
  if (typeof key !== "string" || RULES_OPTIONS.has(key)) {
23841
23892
  unevaluable(p.start, `${label2}: an options ${p.type === "Property" ? "computed key" : "spread"}`);
23842
23893
  }
@@ -23844,7 +23895,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
23844
23895
  };
23845
23896
  const triviaOption = (optExpr, label2) => {
23846
23897
  assertPlainOptions(optExpr, label2);
23847
- return requiredOption(label2, "trivia", optionProp(optExpr, "trivia"), (v) => evaluateExpr(v, scope, code, []));
23898
+ return requiredOption(label2, "trivia", optionProp(optExpr, "trivia"), (v) => evaluateExpr(v, scope2, code, []));
23848
23899
  };
23849
23900
  const evaluateRulesFactory = (init, label2) => {
23850
23901
  const args = init.arguments;
@@ -23858,7 +23909,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
23858
23909
  }
23859
23910
  const namedFactory = factoryArgRaw.type === "Identifier" ? factoryDecls.get(factoryArgRaw.name) : void 0;
23860
23911
  const factoryArg = namedFactory !== void 0 && namedFactory.declaredAt <= init.start ? namedFactory.fn : factoryArgRaw;
23861
- const factoryScope = namedFactory?.scope ?? scope;
23912
+ const factoryScope = namedFactory?.scope ?? scope2;
23862
23913
  const factoryCode = namedFactory?.code ?? code;
23863
23914
  const importedFactory = namedFactory?.imported === true && factoryArg === namedFactory.fn ? factoryArgRaw.name : void 0;
23864
23915
  const failedFactory = factoryArgRaw.type === "Identifier" ? factoryFailures.get(factoryArgRaw.name) : void 0;
@@ -23885,9 +23936,9 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
23885
23936
  }
23886
23937
  const gTrivia = triviaOption(optionsArg, label2);
23887
23938
  const scanSkipArray = requiredOption(label2, "scanSkip", optionValue("scanSkip"), (v) => {
23888
- const units = evaluateCombinatorArray(v, scope, code);
23939
+ const units = evaluateCombinatorArray(v, scope2, code);
23889
23940
  if (units) return units;
23890
- const value = evaluateStaticValue(v, scope, code);
23941
+ const value = evaluateStaticValue(v, scope2, code);
23891
23942
  return Array.isArray(value) && value.length === 0 ? [] : null;
23892
23943
  });
23893
23944
  const gScanSkip = scanSkipArray?.length ? scanSkipArray : void 0;
@@ -24406,7 +24457,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
24406
24457
  for (const stmt of body) {
24407
24458
  if (stmt.type === "ExpressionStatement") {
24408
24459
  const expr = stmt.expression;
24409
- if (applyDefineStatement(expr, scope, code)) {
24460
+ if (applyDefineStatement(expr, scope2, code)) {
24410
24461
  defineRemovals.push({ start: stmt.start, end: stmt.end });
24411
24462
  }
24412
24463
  continue;
@@ -24418,11 +24469,11 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
24418
24469
  if (!d.init || d.id.type !== "Identifier") continue;
24419
24470
  const name = d.id.name;
24420
24471
  const init = d.init;
24421
- if (evaluateRefDeclaration(init, name, scope)) continue;
24422
- if (scope.has(name)) continue;
24423
- if (!referencesAny(init, allNames, scope)) continue;
24424
- const combi = evaluateExpr(init, scope, code, []);
24425
- if (combi) scope.set(name, { combi, mfSrcs: [] });
24472
+ if (evaluateRefDeclaration(init, name, scope2)) continue;
24473
+ if (scope2.has(name)) continue;
24474
+ if (!referencesAny(init, allNames, scope2)) continue;
24475
+ const combi = evaluateExpr(init, scope2, code, []);
24476
+ if (combi) scope2.set(name, { combi, mfSrcs: [] });
24426
24477
  }
24427
24478
  }
24428
24479
  }
@@ -24448,12 +24499,12 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
24448
24499
  const kind = vd.kind ?? "const";
24449
24500
  if (d.id.type === "Identifier") {
24450
24501
  const varName = d.id.name;
24451
- if (!referencesAny(init, allNames, scope)) {
24502
+ if (!referencesAny(init, allNames, scope2)) {
24452
24503
  deferredLocals.set(varName, init);
24453
24504
  continue;
24454
24505
  }
24455
24506
  if (refNames.has(varName)) {
24456
- const refEntry = scope.get(varName);
24507
+ const refEntry = scope2.get(varName);
24457
24508
  const refCombi = refEntry?.combi ?? null;
24458
24509
  if (refCombi) {
24459
24510
  const compiled2 = compile(refCombi, refEntry?.mfSrcs, { recovery, coverage: grammarCoverage });
@@ -24538,32 +24589,32 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
24538
24589
  }
24539
24590
  const mapFnSources = [];
24540
24591
  unresolvedImports.clear();
24541
- const parser2 = evaluateExpr(init, scope, code, mapFnSources);
24592
+ const parser2 = evaluateExpr(init, scope2, code, mapFnSources);
24542
24593
  if (parser2 === null) {
24543
- const wordFactory = evaluateWordFactory(init, scope, code);
24594
+ const wordFactory = evaluateWordFactory(init, scope2, code);
24544
24595
  if (wordFactory) {
24545
24596
  ;
24546
- scope.set(varName, wordFactory);
24597
+ scope2.set(varName, wordFactory);
24547
24598
  replacements.push({ start: init.start, end: init.end, replacement: "undefined" });
24548
24599
  continue;
24549
24600
  }
24550
- const whenFactory = evaluateWhenFactory(init, scope, code);
24601
+ const whenFactory = evaluateWhenFactory(init, scope2, code);
24551
24602
  if (whenFactory) {
24552
24603
  ;
24553
- scope.set(varName, whenFactory);
24604
+ scope2.set(varName, whenFactory);
24554
24605
  replacements.push({ start: init.start, end: init.end, replacement: "undefined" });
24555
24606
  continue;
24556
24607
  }
24557
- const combiArray = evaluateCombinatorArray(init, scope, code);
24608
+ const combiArray = evaluateCombinatorArray(init, scope2, code);
24558
24609
  if (combiArray) {
24559
24610
  ;
24560
- scope.set(varName, combiArray);
24611
+ scope2.set(varName, combiArray);
24561
24612
  continue;
24562
24613
  }
24563
- const staticValue = evaluateStaticValue(init, scope, code);
24614
+ const staticValue = evaluateStaticValue(init, scope2, code);
24564
24615
  if (staticValue !== null && staticValue !== void 0 || isStaticNullishExpression(init)) {
24565
24616
  ;
24566
- scope.set(varName, staticValue);
24617
+ scope2.set(varName, staticValue);
24567
24618
  continue;
24568
24619
  }
24569
24620
  if (factoryDecls.has(varName)) {
@@ -24586,9 +24637,9 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
24586
24637
  replacement: compiled.inlineExpression,
24587
24638
  carry: { name: varName, combi: parser2, exported: exportPrefix !== "" }
24588
24639
  });
24589
- scope.set(varName, { combi: parser2, mfSrcs: mapFnSources });
24640
+ scope2.set(varName, { combi: parser2, mfSrcs: mapFnSources });
24590
24641
  } else if (d.id.type === "ObjectPattern") {
24591
- if (!referencesAny(init, allNames, scope)) continue;
24642
+ if (!referencesAny(init, allNames, scope2)) continue;
24592
24643
  if (!isRulesCall(init)) {
24593
24644
  warn(init.start, `destructured macro binding must come from rules(...)`);
24594
24645
  continue;
@@ -24622,7 +24673,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
24622
24673
  }
24623
24674
  bindings.push({ ruleKey, localName });
24624
24675
  const rule = compiledRules.ruleMap.get(ruleKey);
24625
- if (rule) scope.set(localName, { combi: rule, mfSrcs: [] });
24676
+ if (rule) scope2.set(localName, { combi: rule, mfSrcs: [] });
24626
24677
  }
24627
24678
  if (!allOk) continue;
24628
24679
  const holderVar = `__rules${ruleMapHolderCounter++}`;