parseman 0.60.6 → 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 (40) hide show
  1. package/dist/analysis/diagnostics.js +47 -36
  2. package/dist/analysis/diagnostics.js.map +3 -3
  3. package/dist/cli/index.js +47 -36
  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/compiler/token-capability.js +1 -0
  12. package/dist/compiler/token-capability.js.map +1 -1
  13. package/dist/compiler/value-usage.d.ts.map +1 -1
  14. package/dist/functional/run.d.ts.map +1 -1
  15. package/dist/index.js +91 -66
  16. package/dist/index.js.map +3 -3
  17. package/dist/language-service/index.js +1 -1
  18. package/dist/language-service/index.js.map +1 -1
  19. package/dist/plugin/index.js +254 -229
  20. package/dist/plugin/index.js.map +3 -3
  21. package/dist/run/index.js +1 -1
  22. package/dist/run/index.js.map +1 -1
  23. package/dist/spec/index.js.map +1 -1
  24. package/dist/table/emit.d.ts.map +1 -1
  25. package/dist/table/index.js +11 -6
  26. package/dist/table/index.js.map +3 -3
  27. package/dist/table/program.d.ts +3 -1
  28. package/dist/table/program.d.ts.map +1 -1
  29. package/dist/version.d.ts +1 -1
  30. package/package.json +1 -1
  31. package/src/combinators/choice.ts +3 -1
  32. package/src/combinators/expect.ts +1 -0
  33. package/src/combinators/link-scope.ts +19 -0
  34. package/src/combinators/node.ts +11 -2
  35. package/src/combinators/parser.ts +37 -31
  36. package/src/compiler/value-usage.ts +16 -29
  37. package/src/functional/run.ts +3 -1
  38. package/src/table/emit.ts +5 -1
  39. package/src/table/program.ts +8 -2
  40. package/src/version.ts +1 -1
@@ -500,15 +500,20 @@ function markUnusedValues(root) {
500
500
  case "many":
501
501
  case "oneOrMore":
502
502
  mark(def, consumed);
503
- visit(def.parser, consumed);
504
- return;
505
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":
506
513
  visit(def.parser, consumed);
507
514
  return;
508
515
  case "sequence":
509
516
  mark(def, consumed);
510
- for (const p of def.parsers) visit(p, consumed);
511
- return;
512
517
  case "choice":
513
518
  for (const p of def.parsers) visit(p, consumed);
514
519
  return;
@@ -519,22 +524,24 @@ function markUnusedValues(root) {
519
524
  if (def.otherwise) visit(def.otherwise, consumed);
520
525
  return;
521
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":
522
532
  visit(def.parser, false);
523
533
  return;
524
534
  case "transform":
525
- visit(def.parser, true);
526
- return;
535
+ // the map fn reads the value → always consumed.
527
536
  case "field":
537
+ // the field capture records the parsed value → always consumed.
538
+ case "leaf":
528
539
  visit(def.parser, true);
529
540
  return;
530
541
  case "sepBy":
531
542
  visit(def.parser, true);
532
543
  visit(def.separator, false);
533
544
  return;
534
- case "not":
535
- case "peek":
536
- visit(def.parser, false);
537
- return;
538
545
  case "grammar":
539
546
  visit(def.parser, consumed);
540
547
  if (def.triviaParser) visit(def.triviaParser, false);
@@ -543,19 +550,6 @@ function markUnusedValues(root) {
543
550
  visit(def.parser, consumed);
544
551
  visit(def.sentinel, false);
545
552
  return;
546
- case "token":
547
- visit(def.parser, false);
548
- return;
549
- case "label":
550
- case "trivia":
551
- case "attempt":
552
- case "withCtx":
553
- case "expect":
554
- visit(def.parser, consumed);
555
- return;
556
- case "leaf":
557
- visit(def.parser, true);
558
- return;
559
553
  case "lazy":
560
554
  return;
561
555
  default:
@@ -585,6 +579,21 @@ function markUnusedValues(root) {
585
579
  visit(resolveRoot(root), true);
586
580
  }
587
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
+
588
597
  // src/line-index.ts
589
598
  import { PlainLineSpan, PlainSpan } from "../cst/plain.js";
590
599
  function createLineIndex() {
@@ -1992,6 +2001,7 @@ function linkRules(recipes, link) {
1992
2001
  }
1993
2002
  });
1994
2003
  const winners = /* @__PURE__ */ new Map();
2004
+ const afterLink2 = [];
1995
2005
  const priorHoles = /* @__PURE__ */ new Map();
1996
2006
  const prior = new Proxy({}, {
1997
2007
  get(_target, key) {
@@ -2004,38 +2014,42 @@ function linkRules(recipes, link) {
2004
2014
  return hole;
2005
2015
  }
2006
2016
  });
2007
- for (const recipe of recipes) {
2008
- const definitions = recipe.factory(proxy, prior);
2009
- for (const key of Object.keys(definitions)) {
2010
- winners.set(key, { parser: definitions[key], options: recipe.options });
2011
- }
2012
- }
2013
- const keys = [...winners.keys()];
2014
2017
  const copies = /* @__PURE__ */ new Map();
2015
- for (const [key, { parser: defined }] of winners) {
2016
- const placeholder = cache[key];
2017
- const parser2 = ownRule(defined, copies);
2018
- if (placeholder === parser2) {
2019
- throw new Error(`rules(): rule "${key}" cannot be a direct alias to itself`);
2020
- }
2021
- if (isDefinableRef(placeholder)) {
2022
- if (!isNamedRuleRefForAnotherRule(parser2, key)) tagRule(parser2, key);
2023
- placeholder.define(parser2);
2024
- placeholder._meta.firstSet = parser2._meta.firstSet;
2025
- placeholder._meta.canMatchNewline = parser2._meta.canMatchNewline;
2026
- } else if (isNamedRuleRefForAnotherRule(parser2, key) || link !== void 0) {
2027
- if (!isNamedRuleRefForAnotherRule(parser2, key)) tagRule(parser2, key);
2028
- const alias = ref();
2029
- tagRule(alias, key);
2030
- alias.define(parser2);
2031
- alias._meta.firstSet = parser2._meta.firstSet;
2032
- alias._meta.canMatchNewline = parser2._meta.canMatchNewline;
2033
- cache[key] = alias;
2034
- } else {
2035
- tagRule(parser2, key);
2036
- 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
+ }
2037
2048
  }
2049
+ } finally {
2050
+ for (const settle of afterLink2) settle();
2038
2051
  }
2052
+ const keys = [...winners.keys()];
2039
2053
  for (const key of keys) {
2040
2054
  const options = winners.get(key).options;
2041
2055
  let rule = cache[key];
@@ -3742,6 +3756,7 @@ function derive(c, seen) {
3742
3756
  case "optional":
3743
3757
  case "many":
3744
3758
  case "oneOrMore":
3759
+ case "sepBy":
3745
3760
  case "transform":
3746
3761
  case "not":
3747
3762
  case "peek":
@@ -3889,7 +3904,7 @@ function choice(...args) {
3889
3904
  const result = parsers[idx].parse(input, pos, ctx);
3890
3905
  if (result.ok) return result;
3891
3906
  expected.push(...result.expected);
3892
- 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 };
3893
3908
  return { ok: false, expected, span: { start: pos, end: pos } };
3894
3909
  }
3895
3910
  if (ctx._probe !== void 0 || ctx._tolerant) for (const p of parsers) p.parse(input, pos, ctx);
@@ -5283,8 +5298,14 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
5283
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;
5284
5299
  const capturesTrivia = captureTrivia || (build ? buildReadsTrivia(def) : project === void 0);
5285
5300
  const readsState = build ? buildReadsState(def) : project === void 0;
5286
- const hasOwnFields = parserHasOwnFields(combinator);
5287
- 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
+ }
5288
5309
  const guardable = combinator._meta.firstSet.kind !== "any" && !matchesEmpty(combinator);
5289
5310
  let failExpected;
5290
5311
  return {
@@ -5597,6 +5618,9 @@ function sourceLeaf(root, fn) {
5597
5618
  return makeLeaf(root, fn, true);
5598
5619
  }
5599
5620
 
5621
+ // src/version.ts
5622
+ var PARSEMAN_VERSION = "0.61.0";
5623
+
5600
5624
  // src/table/lex-body.ts
5601
5625
  function buildLexBodyRecognizer(spec, constants) {
5602
5626
  const raw = constants[spec[0]];
@@ -6212,11 +6236,12 @@ function assemblyExtraIps(prog) {
6212
6236
  }
6213
6237
  function expandCompact(p) {
6214
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}`);
6215
6240
  return ownTableProgram({
6216
6241
  code: p.c,
6217
6242
  k: p.k,
6218
6243
  cc: p.x,
6219
- fx: p.e,
6244
+ fx: p.e.map((set) => set.map((i) => p.es[i])),
6220
6245
  disp: p.d,
6221
6246
  rules: p.r,
6222
6247
  fns: p.f,
@@ -7279,7 +7304,7 @@ function selectOptionalSuffixLexBody(ir) {
7279
7304
  function reinstallsRuleTrivia(reference, target) {
7280
7305
  return (reference._meta.grammarTrivia ?? target._meta.grammarTrivia) !== void 0 && hasOwnTriviaBoundary(target);
7281
7306
  }
7282
- function directTokenBodyParser(parser2, resolve3, scope) {
7307
+ function directTokenBodyParser(parser2, resolve3, scope2) {
7283
7308
  const outer = parser2._def;
7284
7309
  if (outer.tag !== "token") return void 0;
7285
7310
  let body = outer.parser;
@@ -7289,7 +7314,7 @@ function directTokenBodyParser(parser2, resolve3, scope) {
7289
7314
  const wrapper = body._def;
7290
7315
  if (wrapper.tag === "grammar") {
7291
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;
7292
- if (scope !== void 0) scope.cleared = true;
7317
+ if (scope2 !== void 0) scope2.cleared = true;
7293
7318
  body = wrapper.parser;
7294
7319
  continue;
7295
7320
  }
@@ -7546,10 +7571,10 @@ function directFixedLexNode(parser2, resolve3, active, pureOnly = false, cleared
7546
7571
  }
7547
7572
  }
7548
7573
  function directFixedTokenBody(parser2, resolve3) {
7549
- const scope = { cleared: false };
7550
- const body = directTokenBodyParser(parser2, resolve3, scope);
7574
+ const scope2 = { cleared: false };
7575
+ const body = directTokenBodyParser(parser2, resolve3, scope2);
7551
7576
  if (body === void 0) return void 0;
7552
- const root = directFixedLexNode(body, resolve3, /* @__PURE__ */ new Set(), false, scope.cleared);
7577
+ const root = directFixedLexNode(body, resolve3, /* @__PURE__ */ new Set(), false, scope2.cleared);
7553
7578
  return root === void 0 ? void 0 : { kind: "fixed-tree", root };
7554
7579
  }
7555
7580
  function directBalancedTokenBody(parser2, resolve3) {
@@ -13545,9 +13570,6 @@ function clearOf(ranges, input, from, to) {
13545
13570
  return true;
13546
13571
  }
13547
13572
 
13548
- // src/version.ts
13549
- var PARSEMAN_VERSION = "0.60.6";
13550
-
13551
13573
  // src/table/assemble.ts
13552
13574
  import { PlainBuf as PlainBuf2, PlainField, PlainLeaf as PlainLeaf9, PlainNode as PlainNode2, PlainSpan as PlainSpan10 } from "../cst/plain.js";
13553
13575
 
@@ -17566,12 +17588,15 @@ function assertPrintable(prog, who) {
17566
17588
  }
17567
17589
  }
17568
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]));
17569
17593
  return [
17570
17594
  ...emitAssemblies(prog, opts.assemblies ?? []),
17571
17595
  `c:[${prog.code.join(",")}],`,
17572
17596
  `k:[${prog.k.map(emitConst).join(",")}],`,
17573
17597
  `x:${emitClassPool(prog.cc)},`,
17574
- `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(",")}],`,
17575
17600
  `d:[${prog.disp.map((a) => `[${a.join(",")}]`).join(",")}],`,
17576
17601
  `r:${JSON.stringify(prog.rules)},`,
17577
17602
  ...prog.lines === 1 ? ["l:1,"] : [],
@@ -20344,7 +20369,7 @@ function runOnce(entry, input, options) {
20344
20369
  const r = invoke(entry, input, 0, ctx);
20345
20370
  const value = r.ok ? r.value : void 0;
20346
20371
  let span = r.span ?? { start: 0, end: 0 };
20347
- const expected = r.ok ? [] : r.expected ?? [];
20372
+ const expected = r.ok ? [] : [...new Set(r.expected ?? [])];
20348
20373
  let unconsumedFrom = null;
20349
20374
  if (r.ok) {
20350
20375
  let pos = span.end;
@@ -20757,12 +20782,12 @@ function isWhenFactory(v) {
20757
20782
  function isStaticValueEntry(v) {
20758
20783
  return !!v && typeof v === "object" && "value" in v && "mfSrcs" in v;
20759
20784
  }
20760
- function wordFactoryFromArgs(args, scope, code, mfs) {
20785
+ function wordFactoryFromArgs(args, scope2, code, mfs) {
20761
20786
  const [boundaryOrOptsArg, optsArg] = args;
20762
20787
  if (boundaryOrOptsArg?.type === "SpreadElement" || optsArg?.type === "SpreadElement") return null;
20763
- 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);
20764
20789
  const boundaryOrOpts = rawBoundaryOrOpts === void 0 ? "_0-9A-Za-z" : rawBoundaryOrOpts;
20765
- 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);
20766
20791
  if (typeof boundaryOrOpts === "string") {
20767
20792
  if (opts !== void 0 && (typeof opts !== "object" || opts === null || Array.isArray(opts))) return null;
20768
20793
  const caseInsensitive2 = typeof opts === "object" && opts !== null && "caseInsensitive" in opts ? opts.caseInsensitive : false;
@@ -20786,10 +20811,10 @@ function dispatchWhenOptions(v) {
20786
20811
  if (typeof caseInsensitive !== "boolean") return null;
20787
20812
  return { caseInsensitive };
20788
20813
  }
20789
- function whenFactoryFromArgs(args, scope, code, mfs) {
20814
+ function whenFactoryFromArgs(args, scope2, code, mfs) {
20790
20815
  const [optsArg, extra] = args;
20791
20816
  if (optsArg?.type === "SpreadElement" || extra !== void 0) return null;
20792
- 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);
20793
20818
  const opts = dispatchWhenOptions(rawOpts);
20794
20819
  return opts === null ? null : { tag: "whenFactory", caseInsensitive: opts.caseInsensitive ?? false };
20795
20820
  }
@@ -20861,20 +20886,20 @@ function gatedArmParts(e) {
20861
20886
  }
20862
20887
  return gate2 && combinator ? { gate: gate2, combinator } : null;
20863
20888
  }
20864
- function dispatchArmValue(node2, scope, code, mfs) {
20889
+ function dispatchArmValue(node2, scope2, code, mfs) {
20865
20890
  if (node2.type === "Identifier") {
20866
- const value = anyValue(node2, scope, code, mfs);
20891
+ const value = anyValue(node2, scope2, code, mfs);
20867
20892
  return isDispatchArm(value) ? value : null;
20868
20893
  }
20869
20894
  if (node2.type !== "CallExpression") return null;
20870
20895
  const callee = node2.callee;
20871
20896
  if (callee.type !== "Identifier") return null;
20872
- const factory = scope.get(callee.name);
20897
+ const factory = scope2.get(callee.name);
20873
20898
  if (isWhenFactory(factory)) {
20874
20899
  const [keyArg, parserArg, extraArg] = node2.arguments;
20875
20900
  if (!keyArg || !parserArg || extraArg !== void 0 || keyArg.type === "SpreadElement" || parserArg.type === "SpreadElement") return null;
20876
- const key = anyValue(keyArg, scope, code, mfs);
20877
- const parserValue = anyValue(parserArg, scope, code, mfs);
20901
+ const key = anyValue(keyArg, scope2, code, mfs);
20902
+ const parserValue = anyValue(parserArg, scope2, code, mfs);
20878
20903
  if (!isCombinator3(parserValue)) return null;
20879
20904
  const opts = { caseInsensitive: factory.caseInsensitive };
20880
20905
  if (typeof key === "string") return when(key, parserValue, opts);
@@ -20885,10 +20910,10 @@ function dispatchArmValue(node2, scope, code, mfs) {
20885
20910
  if (callee.name === "otherwise") {
20886
20911
  const [parserArg, optsArg] = node2.arguments;
20887
20912
  if (!parserArg || parserArg.type === "SpreadElement" || optsArg?.type === "SpreadElement") return null;
20888
- const parserValue = anyValue(parserArg, scope, code, mfs);
20913
+ const parserValue = anyValue(parserArg, scope2, code, mfs);
20889
20914
  if (!isCombinator3(parserValue)) return null;
20890
20915
  if (optsArg === void 0) return otherwise(parserValue);
20891
- const opts = anyValue(optsArg, scope, code, mfs);
20916
+ const opts = anyValue(optsArg, scope2, code, mfs);
20892
20917
  if (typeof opts !== "object" || opts === null) return null;
20893
20918
  const commit = opts.commit;
20894
20919
  if (commit !== void 0 && typeof commit !== "boolean") return null;
@@ -20897,9 +20922,9 @@ function dispatchArmValue(node2, scope, code, mfs) {
20897
20922
  if (callee.name === "when") {
20898
20923
  const [keyArg, parserArg, optsArg] = node2.arguments;
20899
20924
  if (!keyArg || !parserArg || keyArg.type === "SpreadElement" || parserArg.type === "SpreadElement" || optsArg?.type === "SpreadElement") return null;
20900
- const key = anyValue(keyArg, scope, code, mfs);
20901
- const parserValue = anyValue(parserArg, scope, code, mfs);
20902
- 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));
20903
20928
  if (opts === null) return null;
20904
20929
  if (!isCombinator3(parserValue)) return null;
20905
20930
  if (typeof key === "string") return when(key, parserValue, opts);
@@ -20926,8 +20951,8 @@ function isDispatchMatcher(v) {
20926
20951
  if ((rec.kind === "startsWith" || rec.kind === "endsWith") && typeof rec.value === "string") return true;
20927
20952
  return rec.kind === "matches" && typeof rec.value === "string" && typeof rec.flags === "string";
20928
20953
  }
20929
- function scopeGet(scope, name, mfs) {
20930
- const entry = scope.get(name);
20954
+ function scopeGet(scope2, name, mfs) {
20955
+ const entry = scope2.get(name);
20931
20956
  if (!entry) return null;
20932
20957
  if (isScopeEntry(entry)) {
20933
20958
  if (mfs && entry.mfSrcs.length > 0) mfs.push(...entry.mfSrcs);
@@ -20948,10 +20973,10 @@ function staticLiteralValue(expr) {
20948
20973
  const val = unwrapStaticExpr(expr);
20949
20974
  return val.type === "Literal" || val.type === "BooleanLiteral" || val.type === "NumericLiteral" ? val.value : void 0;
20950
20975
  }
20951
- function staticStringArray(expr, scope) {
20976
+ function staticStringArray(expr, scope2) {
20952
20977
  const id = unwrapStaticExpr(expr);
20953
- if (id.type === "Identifier" && scope !== void 0 && id.name !== void 0) {
20954
- 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);
20955
20980
  const value = isStaticValueEntry(scoped) ? scoped.value : scoped;
20956
20981
  return Array.isArray(value) && value.every((v) => typeof v === "string") ? value : void 0;
20957
20982
  }
@@ -20976,11 +21001,11 @@ function staticNodeProject(expr) {
20976
21001
  if (typeof literalValue === "number" || literalValue !== void 0) return { ok: false };
20977
21002
  return { ok: false };
20978
21003
  }
20979
- function scopedStaticValue(expr, scope) {
21004
+ function scopedStaticValue(expr, scope2) {
20980
21005
  const unwrapped = unwrapStaticExpr(expr);
20981
21006
  if (unwrapped.type !== "Identifier" || unwrapped.name === "undefined") return { found: false };
20982
- if (!scope.has(unwrapped.name)) return { found: false };
20983
- const scoped = scope.get(unwrapped.name);
21007
+ if (!scope2.has(unwrapped.name)) return { found: false };
21008
+ const scoped = scope2.get(unwrapped.name);
20984
21009
  const value = isStaticValueEntry(scoped) ? scoped.value : scoped;
20985
21010
  return { found: true, value };
20986
21011
  }
@@ -21006,9 +21031,9 @@ function staticNodeOptionsFromValue(value) {
21006
21031
  }
21007
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;
21008
21033
  }
21009
- function staticNodeOptions(expr, scope) {
21034
+ function staticNodeOptions(expr, scope2) {
21010
21035
  const unwrapped = unwrapStaticExpr(expr);
21011
- const scoped = scopedStaticValue(unwrapped, scope);
21036
+ const scoped = scopedStaticValue(unwrapped, scope2);
21012
21037
  if (scoped.found) return staticNodeOptionsFromValue(scoped.value);
21013
21038
  if (unwrapped.type !== "ObjectExpression") return STATIC_NODE_OPTIONS_NOT_OPTIONS;
21014
21039
  const opts = {};
@@ -21026,7 +21051,7 @@ function staticNodeOptions(expr, scope) {
21026
21051
  if (project?.ok === false) return STATIC_NODE_OPTIONS_FAILED;
21027
21052
  if (project !== void 0) opts.project = project.value;
21028
21053
  } else if (name === "tags") {
21029
- const tags = staticStringArray(p.value, scope);
21054
+ const tags = staticStringArray(p.value, scope2);
21030
21055
  if (tags === void 0) return STATIC_NODE_OPTIONS_FAILED;
21031
21056
  opts.tags = tags;
21032
21057
  } else if (name === "buildArity") {
@@ -21038,21 +21063,21 @@ function staticNodeOptions(expr, scope) {
21038
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;
21039
21064
  }
21040
21065
  var UNKNOWN_OPTIONS = /* @__PURE__ */ Symbol("parseman.unknownOptions");
21041
- function scanOptions(optsArg, scope, code) {
21066
+ function scanOptions(optsArg, scope2, code) {
21042
21067
  if (optsArg === void 0) return void 0;
21043
21068
  if (optsArg.type === "SpreadElement") return UNKNOWN_OPTIONS;
21044
- const opts = anyValue(optsArg, scope, code, []);
21045
- return isHole(optsArg, opts, scope) ? UNKNOWN_OPTIONS : opts;
21069
+ const opts = anyValue(optsArg, scope2, code, []);
21070
+ return isHole(optsArg, opts, scope2) ? UNKNOWN_OPTIONS : opts;
21046
21071
  }
21047
- function exprToCombi(node2, scope, code, mfs) {
21048
- 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);
21049
21074
  if (node2.type !== "CallExpression") return null;
21050
21075
  const callee = node2.callee;
21051
21076
  if (callee.type === "CallExpression" && callee.callee.type === "Identifier" && callee.callee.name === "makeWord") {
21052
21077
  const strArg = node2.arguments[0];
21053
21078
  if (!strArg || strArg.type === "SpreadElement") return null;
21054
- const factory2 = wordFactoryFromArgs(callee.arguments, scope, code, mfs);
21055
- const str = anyValue(strArg, scope, code, mfs);
21079
+ const factory2 = wordFactoryFromArgs(callee.arguments, scope2, code, mfs);
21080
+ const str = anyValue(strArg, scope2, code, mfs);
21056
21081
  if (factory2 === null || typeof str !== "string") return null;
21057
21082
  try {
21058
21083
  return word(str, factory2.boundary, { caseInsensitive: factory2.caseInsensitive });
@@ -21061,11 +21086,11 @@ function exprToCombi(node2, scope, code, mfs) {
21061
21086
  }
21062
21087
  }
21063
21088
  if (callee.type === "Identifier") {
21064
- const factory2 = scope.get(callee.name);
21089
+ const factory2 = scope2.get(callee.name);
21065
21090
  if (isWordFactory(factory2)) {
21066
21091
  const [strArg] = node2.arguments;
21067
21092
  if (!strArg || strArg.type === "SpreadElement") return null;
21068
- const str = anyValue(strArg, scope, code, mfs);
21093
+ const str = anyValue(strArg, scope2, code, mfs);
21069
21094
  if (typeof str !== "string") return null;
21070
21095
  try {
21071
21096
  return word(str, factory2.boundary, { caseInsensitive: factory2.caseInsensitive });
@@ -21078,7 +21103,7 @@ function exprToCombi(node2, scope, code, mfs) {
21078
21103
  if (callee.name === "transform" && code !== void 0 && mfs !== void 0) {
21079
21104
  const [parserArg, fnArg] = node2.arguments;
21080
21105
  if (!parserArg || !fnArg || parserArg.type === "SpreadElement" || fnArg.type === "SpreadElement") return null;
21081
- const inner = anyValue(parserArg, scope, code, mfs);
21106
+ const inner = anyValue(parserArg, scope2, code, mfs);
21082
21107
  if (!isCombinator3(inner)) return null;
21083
21108
  const fnSrc = stripTsFromSource(fnArg, code);
21084
21109
  mfs.push(fnSrc);
@@ -21093,7 +21118,7 @@ function exprToCombi(node2, scope, code, mfs) {
21093
21118
  if ((callee.name === "leaf" || callee.name === "sourceLeaf") && code !== void 0 && mfs !== void 0) {
21094
21119
  const [parserArg, fnArg] = node2.arguments;
21095
21120
  if (!parserArg || !fnArg || parserArg.type === "SpreadElement" || fnArg.type === "SpreadElement") return null;
21096
- const inner = anyValue(parserArg, scope, code, mfs);
21121
+ const inner = anyValue(parserArg, scope2, code, mfs);
21097
21122
  if (!isCombinator3(inner)) return null;
21098
21123
  const fnSrc = stripTsFromSource(fnArg, code);
21099
21124
  mfs.push(fnSrc);
@@ -21108,20 +21133,20 @@ function exprToCombi(node2, scope, code, mfs) {
21108
21133
  if (callee.name === "node" && code !== void 0) {
21109
21134
  const [firstArg, secondArg, thirdArg, fourthArg] = node2.arguments;
21110
21135
  if (!firstArg || firstArg.type === "SpreadElement") return null;
21111
- const firstVal = anyValue(firstArg, scope, code, mfs);
21136
+ const firstVal = anyValue(firstArg, scope2, code, mfs);
21112
21137
  const explicitType = typeof firstVal === "string" ? firstVal : void 0;
21113
21138
  const parserArg = explicitType !== void 0 ? secondArg : firstArg;
21114
21139
  const buildArg = explicitType !== void 0 ? thirdArg : secondArg;
21115
21140
  const optsArg = explicitType !== void 0 ? fourthArg : thirdArg;
21116
21141
  if (!parserArg || parserArg.type === "SpreadElement") return null;
21117
- const inner = anyValue(parserArg, scope, code, mfs);
21142
+ const inner = anyValue(parserArg, scope2, code, mfs);
21118
21143
  if (!isCombinator3(inner)) return null;
21119
21144
  const be = buildArg;
21120
21145
  const buildExpr = be === void 0 || be.type === "SpreadElement" ? void 0 : unwrapStaticExpr(be);
21121
- 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;
21122
21147
  if (buildArgOptions === STATIC_NODE_OPTIONS_FAILED) return null;
21123
21148
  const buildArgIsOptions = buildArgOptions !== STATIC_NODE_OPTIONS_NOT_OPTIONS;
21124
- const scopedBuild = buildExpr === void 0 ? { found: false } : scopedStaticValue(buildExpr, scope);
21149
+ const scopedBuild = buildExpr === void 0 ? { found: false } : scopedStaticValue(buildExpr, scope2);
21125
21150
  const absentBuild = buildExpr?.type === "Identifier" && buildExpr.name === "undefined" || buildExpr !== void 0 && staticLiteralValue(buildExpr) === null || scopedBuild.found && (scopedBuild.value === void 0 || scopedBuild.value === null);
21126
21151
  const hasBuild = be !== void 0 && be.type !== "SpreadElement" && !buildArgIsOptions && !absentBuild;
21127
21152
  const buildSrc = hasBuild ? stripTsFromSource(be, code) : void 0;
@@ -21130,7 +21155,7 @@ function exprToCombi(node2, scope, code, mfs) {
21130
21155
  opts = buildArgOptions;
21131
21156
  } else if (optsArg !== void 0) {
21132
21157
  if (optsArg.type === "SpreadElement") return null;
21133
- const optsResult = staticNodeOptions(optsArg, scope);
21158
+ const optsResult = staticNodeOptions(optsArg, scope2);
21134
21159
  if (optsResult === STATIC_NODE_OPTIONS_FAILED || optsResult === STATIC_NODE_OPTIONS_NOT_OPTIONS) return null;
21135
21160
  opts = optsResult;
21136
21161
  }
@@ -21186,9 +21211,9 @@ function exprToCombi(node2, scope, code, mfs) {
21186
21211
  if (callee.name === "parser") {
21187
21212
  const [optsArg, rootArg] = node2.arguments;
21188
21213
  if (!optsArg || !rootArg || optsArg.type === "SpreadElement" || rootArg.type === "SpreadElement") return null;
21189
- const opts = anyValue(optsArg, scope, code, []);
21214
+ const opts = anyValue(optsArg, scope2, code, []);
21190
21215
  if (!opts || typeof opts !== "object") return null;
21191
- const root = anyValue(rootArg, scope, code, mfs);
21216
+ const root = anyValue(rootArg, scope2, code, mfs);
21192
21217
  if (!isCombinator3(root)) return null;
21193
21218
  try {
21194
21219
  return parser(opts, root);
@@ -21200,15 +21225,15 @@ function exprToCombi(node2, scope, code, mfs) {
21200
21225
  const [itemArg, sepArg, optsArg] = node2.arguments;
21201
21226
  if (!itemArg || !sepArg || itemArg.type === "SpreadElement" || sepArg.type === "SpreadElement") return null;
21202
21227
  const itemMfs = [];
21203
- const itemCombi = anyValue(itemArg, scope, code, itemMfs);
21228
+ const itemCombi = anyValue(itemArg, scope2, code, itemMfs);
21204
21229
  if (!isCombinator3(itemCombi)) return null;
21205
21230
  const sepMfs = [];
21206
- const sepCombi = anyValue(sepArg, scope, code, sepMfs);
21231
+ const sepCombi = anyValue(sepArg, scope2, code, sepMfs);
21207
21232
  if (!isCombinator3(sepCombi)) return null;
21208
21233
  let opts;
21209
21234
  if (optsArg) {
21210
21235
  if (optsArg.type === "SpreadElement") return null;
21211
- const v = anyValue(optsArg, scope, code, []);
21236
+ const v = anyValue(optsArg, scope2, code, []);
21212
21237
  if (!v || typeof v !== "object") return null;
21213
21238
  opts = v;
21214
21239
  }
@@ -21223,12 +21248,12 @@ function exprToCombi(node2, scope, code, mfs) {
21223
21248
  const [itemArg, optsArg] = node2.arguments;
21224
21249
  if (!itemArg || itemArg.type === "SpreadElement") return null;
21225
21250
  const itemMfs = [];
21226
- const itemCombi = anyValue(itemArg, scope, code, itemMfs);
21251
+ const itemCombi = anyValue(itemArg, scope2, code, itemMfs);
21227
21252
  if (!isCombinator3(itemCombi)) return null;
21228
21253
  let opts;
21229
21254
  if (optsArg) {
21230
21255
  if (optsArg.type === "SpreadElement") return null;
21231
- const v = anyValue(optsArg, scope, code, []);
21256
+ const v = anyValue(optsArg, scope2, code, []);
21232
21257
  if (!v || typeof v !== "object") return null;
21233
21258
  opts = v;
21234
21259
  }
@@ -21245,7 +21270,7 @@ function exprToCombi(node2, scope, code, mfs) {
21245
21270
  if (callee.name === "not") {
21246
21271
  const [innerArg] = node2.arguments;
21247
21272
  if (!innerArg || innerArg.type === "SpreadElement") return null;
21248
- const inner = anyValue(innerArg, scope, code, mfs);
21273
+ const inner = anyValue(innerArg, scope2, code, mfs);
21249
21274
  if (!isCombinator3(inner)) return null;
21250
21275
  try {
21251
21276
  return not(inner);
@@ -21256,7 +21281,7 @@ function exprToCombi(node2, scope, code, mfs) {
21256
21281
  if (callee.name === "peek") {
21257
21282
  const [innerArg] = node2.arguments;
21258
21283
  if (!innerArg || innerArg.type === "SpreadElement") return null;
21259
- const inner = anyValue(innerArg, scope, code, mfs);
21284
+ const inner = anyValue(innerArg, scope2, code, mfs);
21260
21285
  if (!isCombinator3(inner)) return null;
21261
21286
  try {
21262
21287
  return peek(inner);
@@ -21267,10 +21292,10 @@ function exprToCombi(node2, scope, code, mfs) {
21267
21292
  if (callee.name === "balanced") {
21268
21293
  const [openArg, closeArg, optsArg] = node2.arguments;
21269
21294
  if (!openArg || !closeArg || openArg.type === "SpreadElement" || closeArg.type === "SpreadElement") return null;
21270
- const open = anyValue(openArg, scope, code, []);
21271
- const close = anyValue(closeArg, scope, code, []);
21295
+ const open = anyValue(openArg, scope2, code, []);
21296
+ const close = anyValue(closeArg, scope2, code, []);
21272
21297
  if (typeof open !== "string" || typeof close !== "string") return null;
21273
- const opts = scanOptions(optsArg, scope, code);
21298
+ const opts = scanOptions(optsArg, scope2, code);
21274
21299
  if (opts === UNKNOWN_OPTIONS) return null;
21275
21300
  try {
21276
21301
  return balanced(open, close, opts);
@@ -21281,9 +21306,9 @@ function exprToCombi(node2, scope, code, mfs) {
21281
21306
  if (callee.name === "scanTo") {
21282
21307
  const [sentinelArg, optsArg] = node2.arguments;
21283
21308
  if (!sentinelArg || sentinelArg.type === "SpreadElement") return null;
21284
- const sentinel = anyValue(sentinelArg, scope, code, []);
21309
+ const sentinel = anyValue(sentinelArg, scope2, code, []);
21285
21310
  if (!isCombinator3(sentinel)) return null;
21286
- const opts = scanOptions(optsArg, scope, code);
21311
+ const opts = scanOptions(optsArg, scope2, code);
21287
21312
  if (opts === UNKNOWN_OPTIONS) return null;
21288
21313
  try {
21289
21314
  return scanTo(sentinel, opts);
@@ -21312,12 +21337,12 @@ function exprToCombi(node2, scope, code, mfs) {
21312
21337
  if (!extraArg || !innerArg || extraArg.type === "SpreadElement" || innerArg.type === "SpreadElement") return null;
21313
21338
  const extraSrc = stripTsFromSource(extraArg, code);
21314
21339
  mfs.push(extraSrc);
21315
- const inner = anyValue(innerArg, scope, code, mfs);
21340
+ const inner = anyValue(innerArg, scope2, code, mfs);
21316
21341
  if (!isCombinator3(inner)) return null;
21317
21342
  try {
21318
21343
  const extraType = unwrapStaticExpr(extraArg).type;
21319
21344
  const derives = extraType === "ArrowFunctionExpression" || extraType === "FunctionExpression";
21320
- const evaluated = derives ? null : anyValue(extraArg, scope, code, []);
21345
+ const evaluated = derives ? null : anyValue(extraArg, scope2, code, []);
21321
21346
  const usable = typeof evaluated === "object" && evaluated !== null && !Array.isArray(evaluated) && Object.getPrototypeOf(evaluated) === Object.prototype;
21322
21347
  const combi = withCtx(derives ? DERIVE_STAND_IN : usable ? evaluated : UNEVALUATED_EXTRA, inner);
21323
21348
  if (combi._def.tag !== "withCtx") return null;
@@ -21330,12 +21355,12 @@ function exprToCombi(node2, scope, code, mfs) {
21330
21355
  if (callee.name === "dispatch") {
21331
21356
  const [selectorArg, ...armArgs] = node2.arguments;
21332
21357
  if (!selectorArg || selectorArg.type === "SpreadElement") return null;
21333
- const selector = anyValue(selectorArg, scope, code, mfs);
21358
+ const selector = anyValue(selectorArg, scope2, code, mfs);
21334
21359
  if (!isCombinator3(selector)) return null;
21335
21360
  const arms = [];
21336
21361
  for (const arg of armArgs) {
21337
21362
  if (arg.type === "SpreadElement") return null;
21338
- const arm = dispatchArmValue(arg, scope, code, mfs);
21363
+ const arm = dispatchArmValue(arg, scope2, code, mfs);
21339
21364
  if (!isDispatchArm(arm)) return null;
21340
21365
  arms.push(arm);
21341
21366
  }
@@ -21357,12 +21382,12 @@ function exprToCombi(node2, scope, code, mfs) {
21357
21382
  if (!parts) return null;
21358
21383
  const gateSrc = stripTsFromSource(parts.gate, code);
21359
21384
  mfs.push(gateSrc);
21360
- const combi = anyValue(parts.combinator, scope, code, mfs);
21385
+ const combi = anyValue(parts.combinator, scope2, code, mfs);
21361
21386
  if (!isCombinator3(combi)) return null;
21362
21387
  arms.push({ gate: () => true, combinator: combi });
21363
21388
  gateSrcs.push(gateSrc);
21364
21389
  } else {
21365
- const combi = anyValue(argNode, scope, code, mfs);
21390
+ const combi = anyValue(argNode, scope2, code, mfs);
21366
21391
  if (!isCombinator3(combi)) return null;
21367
21392
  arms.push(combi);
21368
21393
  gateSrcs.push(null);
@@ -21384,7 +21409,7 @@ function exprToCombi(node2, scope, code, mfs) {
21384
21409
  if (!factory) return null;
21385
21410
  const args = node2.arguments.map((arg) => {
21386
21411
  if (arg.type === "SpreadElement") return null;
21387
- return anyValue(arg, scope, code, mfs);
21412
+ return anyValue(arg, scope2, code, mfs);
21388
21413
  });
21389
21414
  if (args.some((a) => a === null)) return null;
21390
21415
  try {
@@ -21393,16 +21418,16 @@ function exprToCombi(node2, scope, code, mfs) {
21393
21418
  return null;
21394
21419
  }
21395
21420
  }
21396
- function isHole(node2, value, scope) {
21421
+ function isHole(node2, value, scope2) {
21397
21422
  if (value !== null) return false;
21398
21423
  const n = unwrapStaticExpr(node2);
21399
- if (n.type === "Identifier") return !scope.has(n.name);
21424
+ if (n.type === "Identifier") return !scope2.has(n.name);
21400
21425
  return !(n.type === "Literal" && n.value === null) && n.type !== "ArrowFunctionExpression" && n.type !== "FunctionExpression";
21401
21426
  }
21402
- function anyValue(node2, scope, code, mfs) {
21427
+ function anyValue(node2, scope2, code, mfs) {
21403
21428
  if (node2.type === "TSAsExpression" || node2.type === "TSSatisfiesExpression" || node2.type === "TSNonNullExpression" || node2.type === "TSTypeAssertion" || node2.type === "TSInstantiationExpression" || node2.type === "ParenthesizedExpression") {
21404
21429
  const inner = node2.expression;
21405
- return inner ? anyValue(inner, scope, code, mfs) : null;
21430
+ return inner ? anyValue(inner, scope2, code, mfs) : null;
21406
21431
  }
21407
21432
  if (node2.type === "Literal") {
21408
21433
  if ("regex" in node2 && node2.regex !== null && node2.regex !== void 0) {
@@ -21419,8 +21444,8 @@ function anyValue(node2, scope, code, mfs) {
21419
21444
  continue;
21420
21445
  }
21421
21446
  if (el.type === "SpreadElement") return null;
21422
- const v = anyValue(el, scope, code, mfs);
21423
- if (isHole(el, v, scope)) return null;
21447
+ const v = anyValue(el, scope2, code, mfs);
21448
+ if (isHole(el, v, scope2)) return null;
21424
21449
  out.push(v);
21425
21450
  }
21426
21451
  return out;
@@ -21431,15 +21456,15 @@ function anyValue(node2, scope, code, mfs) {
21431
21456
  const key = propName(prop);
21432
21457
  if (key === null) return null;
21433
21458
  const valueNode = prop.value;
21434
- const v = anyValue(valueNode, scope, code, mfs);
21435
- if (isHole(valueNode, v, scope)) return null;
21459
+ const v = anyValue(valueNode, scope2, code, mfs);
21460
+ if (isHole(valueNode, v, scope2)) return null;
21436
21461
  obj[key] = v;
21437
21462
  }
21438
21463
  return obj;
21439
21464
  }
21440
21465
  if (node2.type === "Identifier") {
21441
21466
  if (node2.name === "undefined") return void 0;
21442
- const entry = scope.get(node2.name) ?? null;
21467
+ const entry = scope2.get(node2.name) ?? null;
21443
21468
  if (isScopeEntry(entry)) {
21444
21469
  if (mfs && entry.mfSrcs.length > 0) mfs.push(...entry.mfSrcs);
21445
21470
  return entry.combi;
@@ -21452,10 +21477,10 @@ function anyValue(node2, scope, code, mfs) {
21452
21477
  }
21453
21478
  if (node2.type === "MemberExpression") {
21454
21479
  const mem = node2;
21455
- const obj = anyValue(mem.object, scope, code, mfs);
21480
+ const obj = anyValue(mem.object, scope2, code, mfs);
21456
21481
  if (!obj || typeof obj !== "object") return null;
21457
21482
  if (node2.computed) {
21458
- const key = anyValue(node2.property, scope, code, mfs);
21483
+ const key = anyValue(node2.property, scope2, code, mfs);
21459
21484
  if (typeof key !== "string" && typeof key !== "number") return null;
21460
21485
  return obj[key] ?? null;
21461
21486
  }
@@ -21466,50 +21491,50 @@ function anyValue(node2, scope, code, mfs) {
21466
21491
  if (node2.type === "CallExpression") {
21467
21492
  const callee = node2.callee;
21468
21493
  if (callee.type === "Identifier" && callee.name === "makeWord") {
21469
- return wordFactoryFromArgs(node2.arguments, scope, code, mfs);
21494
+ return wordFactoryFromArgs(node2.arguments, scope2, code, mfs);
21470
21495
  }
21471
21496
  if (callee.type === "Identifier" && callee.name === "makeWhen") {
21472
- return whenFactoryFromArgs(node2.arguments, scope, code, mfs);
21497
+ return whenFactoryFromArgs(node2.arguments, scope2, code, mfs);
21473
21498
  }
21474
21499
  if (callee.type === "Identifier" && (callee.name === "startsWith" || callee.name === "endsWith")) {
21475
21500
  if (node2.arguments.length !== 1 || node2.arguments[0]?.type === "SpreadElement") return null;
21476
- const value = anyValue(node2.arguments[0], scope, code, mfs);
21501
+ const value = anyValue(node2.arguments[0], scope2, code, mfs);
21477
21502
  if (typeof value !== "string") return null;
21478
21503
  return callee.name === "startsWith" ? startsWith(value) : endsWith(value);
21479
21504
  }
21480
21505
  if (callee.type === "Identifier" && callee.name === "matches") {
21481
21506
  if (node2.arguments.length !== 1 || node2.arguments[0]?.type === "SpreadElement") return null;
21482
- const value = anyValue(node2.arguments[0], scope, code, mfs);
21507
+ const value = anyValue(node2.arguments[0], scope2, code, mfs);
21483
21508
  if (!(value instanceof RegExp)) return null;
21484
21509
  return matches(value);
21485
21510
  }
21486
21511
  if (callee.type === "Identifier" && (callee.name === "when" || callee.name === "otherwise")) {
21487
- return dispatchArmValue(node2, scope, code, mfs);
21512
+ return dispatchArmValue(node2, scope2, code, mfs);
21488
21513
  }
21489
- if (callee.type === "Identifier" && isWhenFactory(scope.get(callee.name))) {
21490
- return dispatchArmValue(node2, scope, code, mfs);
21514
+ if (callee.type === "Identifier" && isWhenFactory(scope2.get(callee.name))) {
21515
+ return dispatchArmValue(node2, scope2, code, mfs);
21491
21516
  }
21492
- return exprToCombi(node2, scope, code, mfs);
21517
+ return exprToCombi(node2, scope2, code, mfs);
21493
21518
  }
21494
21519
  return null;
21495
21520
  }
21496
- function evaluateWordFactory(node2, scope, code) {
21521
+ function evaluateWordFactory(node2, scope2, code) {
21497
21522
  if (node2.type !== "CallExpression") return null;
21498
21523
  const callee = node2.callee;
21499
21524
  if (callee.type !== "Identifier" || callee.name !== "makeWord") return null;
21500
- return wordFactoryFromArgs(node2.arguments, scope, code);
21525
+ return wordFactoryFromArgs(node2.arguments, scope2, code);
21501
21526
  }
21502
- function evaluateWhenFactory(node2, scope, code) {
21527
+ function evaluateWhenFactory(node2, scope2, code) {
21503
21528
  if (node2.type !== "CallExpression") return null;
21504
21529
  const callee = node2.callee;
21505
21530
  if (callee.type !== "Identifier" || callee.name !== "makeWhen") return null;
21506
- return whenFactoryFromArgs(node2.arguments, scope, code);
21531
+ return whenFactoryFromArgs(node2.arguments, scope2, code);
21507
21532
  }
21508
- function evaluateExpr(node2, scope, code, mapFnSources) {
21509
- return exprToCombi(node2, scope, code, mapFnSources);
21533
+ function evaluateExpr(node2, scope2, code, mapFnSources) {
21534
+ return exprToCombi(node2, scope2, code, mapFnSources);
21510
21535
  }
21511
- function evaluateCombinatorArray(node2, scope, code) {
21512
- const val = anyValue(node2, scope, code, []);
21536
+ function evaluateCombinatorArray(node2, scope2, code) {
21537
+ const val = anyValue(node2, scope2, code, []);
21513
21538
  if (!Array.isArray(val) || val.length === 0) return null;
21514
21539
  if (!val.every(isCombinator3)) return null;
21515
21540
  return val;
@@ -21523,15 +21548,15 @@ function collectRuleKeys(retObj) {
21523
21548
  }
21524
21549
  return out;
21525
21550
  }
21526
- function evaluateStaticValue(node2, scope, code) {
21527
- return anyValue(node2, scope, code, []);
21551
+ function evaluateStaticValue(node2, scope2, code) {
21552
+ return anyValue(node2, scope2, code, []);
21528
21553
  }
21529
- function flattenRuleEntries(retObj, scope, code) {
21554
+ function flattenRuleEntries(retObj, scope2, code) {
21530
21555
  const out = [];
21531
21556
  for (const prop of retObj.properties) {
21532
21557
  const key = propName(prop);
21533
21558
  if (!key) return null;
21534
- out.push({ key, value: prop.value, scope, code });
21559
+ out.push({ key, value: prop.value, scope: scope2, code });
21535
21560
  }
21536
21561
  return out;
21537
21562
  }
@@ -21549,7 +21574,7 @@ function identifierNamesIn(node2, out = /* @__PURE__ */ new Set()) {
21549
21574
  }
21550
21575
  return out;
21551
21576
  }
21552
- function evalBodyStatements(statements, scope, code, out) {
21577
+ function evalBodyStatements(statements, scope2, code, out) {
21553
21578
  const bodyMfs = [];
21554
21579
  const laterNames = [];
21555
21580
  {
@@ -21579,7 +21604,7 @@ function evalBodyStatements(statements, scope, code, out) {
21579
21604
  return false;
21580
21605
  }
21581
21606
  const before = bodyMfs.length;
21582
- const val = anyValue(decl.init, scope, code, bodyMfs);
21607
+ const val = anyValue(decl.init, scope2, code, bodyMfs);
21583
21608
  if (val === null) {
21584
21609
  if (out) {
21585
21610
  const used = identifierNamesIn(decl.init);
@@ -21589,14 +21614,14 @@ function evalBodyStatements(statements, scope, code, out) {
21589
21614
  return false;
21590
21615
  }
21591
21616
  const thisDeclMfSrcs = bodyMfs.slice(before);
21592
- if (isCombinator3(val)) scope.set(name, { combi: val, mfSrcs: thisDeclMfSrcs });
21593
- else if (isDispatchArm(val)) scope.set(name, { value: val, mfSrcs: thisDeclMfSrcs });
21594
- 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);
21595
21620
  }
21596
21621
  }
21597
21622
  return true;
21598
21623
  }
21599
- function evaluateParserFactory(factoryNode, scope, code, mapFnSources, out, options) {
21624
+ function evaluateParserFactory(factoryNode, scope2, code, mapFnSources, out, options) {
21600
21625
  if (factoryNode.type !== "ArrowFunctionExpression" && factoryNode.type !== "FunctionDeclaration" && factoryNode.type !== "FunctionExpression") return null;
21601
21626
  const factory = factoryNode;
21602
21627
  const params = factory.params;
@@ -21639,7 +21664,7 @@ function evaluateParserFactory(factoryNode, scope, code, mapFnSources, out, opti
21639
21664
  let built;
21640
21665
  try {
21641
21666
  built = rules(options ?? {}, (g, prior) => {
21642
- const localScope = scope instanceof ModuleScope ? scope.fork() : new Map(scope);
21667
+ const localScope = scope2 instanceof ModuleScope ? scope2.fork() : new Map(scope2);
21643
21668
  localScope.set(proxyName, g);
21644
21669
  if (priorName !== void 0) localScope.set(priorName, prior);
21645
21670
  if (!evalBodyStatements(statements, localScope, code, out)) throw ABORT;
@@ -21672,16 +21697,16 @@ var externalAccesses = /* @__PURE__ */ new WeakMap();
21672
21697
  function isDefinableRef2(v) {
21673
21698
  return isCombinator3(v) && typeof v.define === "function" && v._def.tag === "lazy";
21674
21699
  }
21675
- function evaluateRefDeclaration(init, name, scope) {
21700
+ function evaluateRefDeclaration(init, name, scope2) {
21676
21701
  if (init.type !== "CallExpression") return null;
21677
21702
  const callee = init.callee;
21678
21703
  if (callee.type !== "Identifier" || callee.name !== "ref") return null;
21679
21704
  if (init.arguments.length !== 0) return null;
21680
21705
  const slot = ref();
21681
- scope.set(name, { combi: slot, mfSrcs: [] });
21706
+ scope2.set(name, { combi: slot, mfSrcs: [] });
21682
21707
  return slot;
21683
21708
  }
21684
- function applyDefineStatement(callExpr, scope, code) {
21709
+ function applyDefineStatement(callExpr, scope2, code) {
21685
21710
  if (callExpr.type !== "CallExpression") return false;
21686
21711
  const callee = callExpr.callee;
21687
21712
  if (callee.type !== "MemberExpression") return false;
@@ -21689,12 +21714,12 @@ function applyDefineStatement(callExpr, scope, code) {
21689
21714
  if (mem.computed) return false;
21690
21715
  if (mem.property.type !== "Identifier" || mem.property.name !== "define") return false;
21691
21716
  if (mem.object.type !== "Identifier" || !mem.object.name) return false;
21692
- const target = scope.get(mem.object.name);
21717
+ const target = scope2.get(mem.object.name);
21693
21718
  const refCombi = isScopeEntry(target) ? target.combi : isCombinator3(target) ? target : null;
21694
21719
  if (!refCombi || !isDefinableRef2(refCombi)) return false;
21695
21720
  const args = callExpr.arguments;
21696
21721
  if (args.length !== 1 || args[0].type === "SpreadElement") return false;
21697
- const inner = anyValue(args[0], scope, code, []);
21722
+ const inner = anyValue(args[0], scope2, code, []);
21698
21723
  if (!isCombinator3(inner)) return false;
21699
21724
  try {
21700
21725
  refCombi.define(inner);
@@ -21703,17 +21728,17 @@ function applyDefineStatement(callExpr, scope, code) {
21703
21728
  }
21704
21729
  return true;
21705
21730
  }
21706
- function referencesAny(node2, names, scope) {
21731
+ function referencesAny(node2, names, scope2) {
21707
21732
  if (node2.type === "Identifier") {
21708
- 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);
21709
21734
  }
21710
21735
  for (const key of Object.keys(node2)) {
21711
21736
  const child = node2[key];
21712
21737
  if (!child || typeof child !== "object") continue;
21713
21738
  if (Array.isArray(child)) {
21714
- 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;
21715
21740
  } else if ("type" in child) {
21716
- if (referencesAny(child, names, scope)) return true;
21741
+ if (referencesAny(child, names, scope2)) return true;
21717
21742
  }
21718
21743
  }
21719
21744
  return false;
@@ -21765,30 +21790,30 @@ function patternNames(pat, out) {
21765
21790
  return;
21766
21791
  }
21767
21792
  }
21768
- function declare(scope, name, b) {
21769
- const prev = scope.bindings.get(name);
21793
+ function declare(scope2, name, b) {
21794
+ const prev = scope2.bindings.get(name);
21770
21795
  if (prev) prev.reassigned = true;
21771
- else scope.bindings.set(name, b);
21796
+ else scope2.bindings.set(name, b);
21772
21797
  }
21773
- function functionScope(scope) {
21774
- let s = scope;
21798
+ function functionScope(scope2) {
21799
+ let s = scope2;
21775
21800
  while (!s.isFunction && s.parent) s = s.parent;
21776
21801
  return s;
21777
21802
  }
21778
21803
  function buildScopeTree(body, moduleEnd) {
21779
21804
  const root = newScope(0, moduleEnd, null, true);
21780
- const declarePattern = (scope, pat, kind, init) => {
21805
+ const declarePattern = (scope2, pat, kind, init) => {
21781
21806
  const names = [];
21782
21807
  patternNames(pat, names);
21783
- const target = kind === "var" ? functionScope(scope) : scope;
21808
+ const target = kind === "var" ? functionScope(scope2) : scope2;
21784
21809
  for (const name of names) {
21785
21810
  declare(target, name, init !== void 0 && names.length === 1 ? { kind, init } : { kind });
21786
21811
  }
21787
21812
  };
21788
- const walk = (n, scope) => {
21813
+ const walk = (n, scope2) => {
21789
21814
  if (!n || typeof n !== "object") return;
21790
21815
  if (Array.isArray(n)) {
21791
- for (const item of n) walk(item, scope);
21816
+ for (const item of n) walk(item, scope2);
21792
21817
  return;
21793
21818
  }
21794
21819
  const node2 = n;
@@ -21797,15 +21822,15 @@ function buildScopeTree(body, moduleEnd) {
21797
21822
  case "VariableDeclaration": {
21798
21823
  const kind = node2.kind ?? "var";
21799
21824
  for (const d of node2.declarations ?? []) {
21800
- declarePattern(scope, d.id, kind, d.init ?? void 0);
21825
+ declarePattern(scope2, d.id, kind, d.init ?? void 0);
21801
21826
  }
21802
21827
  break;
21803
21828
  }
21804
21829
  case "FunctionDeclaration":
21805
- 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 });
21806
21831
  break;
21807
21832
  case "ClassDeclaration":
21808
- if (node2.id) declare(scope, node2.id.name, { kind: "class" });
21833
+ if (node2.id) declare(scope2, node2.id.name, { kind: "class" });
21809
21834
  break;
21810
21835
  case "ImportDeclaration": {
21811
21836
  const specifier = node2.source?.value ?? "";
@@ -21813,7 +21838,7 @@ function buildScopeTree(body, moduleEnd) {
21813
21838
  const local = sp.local?.name;
21814
21839
  if (!local) continue;
21815
21840
  const imported = sp.type === "ImportDefaultSpecifier" ? "default" : sp.type === "ImportNamespaceSpecifier" ? "*" : sp.imported?.name ?? local;
21816
- declare(scope, local, { kind: "import", importRef: { specifier, imported } });
21841
+ declare(scope2, local, { kind: "import", importRef: { specifier, imported } });
21817
21842
  }
21818
21843
  break;
21819
21844
  }
@@ -21822,7 +21847,7 @@ function buildScopeTree(body, moduleEnd) {
21822
21847
  }
21823
21848
  if (SCOPE_TYPES.has(node2.type)) {
21824
21849
  const isFn = FUNCTION_TYPES.has(node2.type);
21825
- const inner = newScope(node2.start, node2.end, scope, isFn);
21850
+ const inner = newScope(node2.start, node2.end, scope2, isFn);
21826
21851
  if (isFn) {
21827
21852
  for (const p of node2.params ?? []) declarePattern(inner, p, "param");
21828
21853
  if (node2.type === "FunctionExpression" && node2.id) {
@@ -21838,7 +21863,7 @@ function buildScopeTree(body, moduleEnd) {
21838
21863
  }
21839
21864
  for (const key of Object.keys(node2)) {
21840
21865
  if (key === "type" || key === "start" || key === "end") continue;
21841
- walk(node2[key], scope);
21866
+ walk(node2[key], scope2);
21842
21867
  }
21843
21868
  };
21844
21869
  for (const stmt of body) walk(stmt, root);
@@ -21852,8 +21877,8 @@ function scopeAt(root, offset) {
21852
21877
  cur = next;
21853
21878
  }
21854
21879
  }
21855
- function lookup(scope, name) {
21856
- for (let s = scope; s; s = s.parent) {
21880
+ function lookup(scope2, name) {
21881
+ for (let s = scope2; s; s = s.parent) {
21857
21882
  const b = s.bindings.get(name);
21858
21883
  if (b) return { binding: b, scope: s };
21859
21884
  }
@@ -23579,7 +23604,7 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
23579
23604
  const stuck = rebaseCarriedBuilderImports(combi2, m.file);
23580
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: [] } };
23581
23606
  }
23582
- const scope2 = moduleValueScope(m);
23607
+ const scope3 = moduleValueScope(m);
23583
23608
  reducerResolver.register(m.file);
23584
23609
  builderImports = (name2) => {
23585
23610
  const b = m.imports.get(name2);
@@ -23587,11 +23612,11 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
23587
23612
  return b && source !== null ? { source, imported: b.imported } : null;
23588
23613
  };
23589
23614
  const mfs = [];
23590
- const combi = evaluateExpr(init, scope2, m.src, mfs);
23615
+ const combi = evaluateExpr(init, scope3, m.src, mfs);
23591
23616
  if (combi) return { value: { combi, mfSrcs: mfs } };
23592
- 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);
23593
23618
  if (factory) return { value: factory };
23594
- const value = evaluateStaticValue(init, scope2, m.src);
23619
+ const value = evaluateStaticValue(init, scope3, m.src);
23595
23620
  if (value !== null && value !== void 0 || isStaticNullishExpression(init)) return { value };
23596
23621
  return {
23597
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})`
@@ -23632,12 +23657,12 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
23632
23657
  }
23633
23658
  return { unresolved: `is not exported by ${m.file}` };
23634
23659
  }
23635
- const scope2 = moduleValueScope(m);
23636
- if (!scope2.has(local)) {
23637
- scope2.get(local);
23660
+ const scope3 = moduleValueScope(m);
23661
+ if (!scope3.has(local)) {
23662
+ scope3.get(local);
23638
23663
  return { unresolved: `could not be resolved in ${m.file}` };
23639
23664
  }
23640
- return { value: scope2.get(local) };
23665
+ return { value: scope3.get(local) };
23641
23666
  };
23642
23667
  const importedValue = (from, binding) => {
23643
23668
  const file = resolveValueFile(from, binding.source);
@@ -23656,7 +23681,7 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
23656
23681
  deferredLocals.delete(name);
23657
23682
  const outer = [...unresolvedImports];
23658
23683
  unresolvedImports.clear();
23659
- const value = evaluateStaticValue(deferred, scope, code);
23684
+ const value = evaluateStaticValue(deferred, scope2, code);
23660
23685
  const why = [...unresolvedImports];
23661
23686
  unresolvedImports.clear();
23662
23687
  for (const n of outer) unresolvedImports.add(n);
@@ -23770,7 +23795,7 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
23770
23795
  });
23771
23796
  reducerResolver.register(file);
23772
23797
  }
23773
- const scope = new ModuleScope(resolveMainFree, unresolvedImports);
23798
+ const scope2 = new ModuleScope(resolveMainFree, unresolvedImports);
23774
23799
  const replacements = [];
23775
23800
  const warnings = [];
23776
23801
  beginDegradationCapture();
@@ -23852,7 +23877,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
23852
23877
  const out = evaluate(value);
23853
23878
  if (out === null) {
23854
23879
  const id2 = value.type === "Identifier" ? value.name : null;
23855
- 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;
23856
23881
  return unevaluable(value.start, `${label2}: rules({ ${name} })`);
23857
23882
  }
23858
23883
  unresolvedImports.clear();
@@ -23862,7 +23887,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
23862
23887
  const assertPlainOptions = (optExpr, label2) => {
23863
23888
  for (const p of optExpr?.type === "ObjectExpression" ? optExpr.properties : []) {
23864
23889
  if (propName(p) !== null) continue;
23865
- const key = p.type === "Property" ? evaluateStaticValue(p.key, scope, code) : null;
23890
+ const key = p.type === "Property" ? evaluateStaticValue(p.key, scope2, code) : null;
23866
23891
  if (typeof key !== "string" || RULES_OPTIONS.has(key)) {
23867
23892
  unevaluable(p.start, `${label2}: an options ${p.type === "Property" ? "computed key" : "spread"}`);
23868
23893
  }
@@ -23870,7 +23895,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
23870
23895
  };
23871
23896
  const triviaOption = (optExpr, label2) => {
23872
23897
  assertPlainOptions(optExpr, label2);
23873
- 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, []));
23874
23899
  };
23875
23900
  const evaluateRulesFactory = (init, label2) => {
23876
23901
  const args = init.arguments;
@@ -23884,7 +23909,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
23884
23909
  }
23885
23910
  const namedFactory = factoryArgRaw.type === "Identifier" ? factoryDecls.get(factoryArgRaw.name) : void 0;
23886
23911
  const factoryArg = namedFactory !== void 0 && namedFactory.declaredAt <= init.start ? namedFactory.fn : factoryArgRaw;
23887
- const factoryScope = namedFactory?.scope ?? scope;
23912
+ const factoryScope = namedFactory?.scope ?? scope2;
23888
23913
  const factoryCode = namedFactory?.code ?? code;
23889
23914
  const importedFactory = namedFactory?.imported === true && factoryArg === namedFactory.fn ? factoryArgRaw.name : void 0;
23890
23915
  const failedFactory = factoryArgRaw.type === "Identifier" ? factoryFailures.get(factoryArgRaw.name) : void 0;
@@ -23911,9 +23936,9 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
23911
23936
  }
23912
23937
  const gTrivia = triviaOption(optionsArg, label2);
23913
23938
  const scanSkipArray = requiredOption(label2, "scanSkip", optionValue("scanSkip"), (v) => {
23914
- const units = evaluateCombinatorArray(v, scope, code);
23939
+ const units = evaluateCombinatorArray(v, scope2, code);
23915
23940
  if (units) return units;
23916
- const value = evaluateStaticValue(v, scope, code);
23941
+ const value = evaluateStaticValue(v, scope2, code);
23917
23942
  return Array.isArray(value) && value.length === 0 ? [] : null;
23918
23943
  });
23919
23944
  const gScanSkip = scanSkipArray?.length ? scanSkipArray : void 0;
@@ -24432,7 +24457,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
24432
24457
  for (const stmt of body) {
24433
24458
  if (stmt.type === "ExpressionStatement") {
24434
24459
  const expr = stmt.expression;
24435
- if (applyDefineStatement(expr, scope, code)) {
24460
+ if (applyDefineStatement(expr, scope2, code)) {
24436
24461
  defineRemovals.push({ start: stmt.start, end: stmt.end });
24437
24462
  }
24438
24463
  continue;
@@ -24444,11 +24469,11 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
24444
24469
  if (!d.init || d.id.type !== "Identifier") continue;
24445
24470
  const name = d.id.name;
24446
24471
  const init = d.init;
24447
- if (evaluateRefDeclaration(init, name, scope)) continue;
24448
- if (scope.has(name)) continue;
24449
- if (!referencesAny(init, allNames, scope)) continue;
24450
- const combi = evaluateExpr(init, scope, code, []);
24451
- 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: [] });
24452
24477
  }
24453
24478
  }
24454
24479
  }
@@ -24474,12 +24499,12 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
24474
24499
  const kind = vd.kind ?? "const";
24475
24500
  if (d.id.type === "Identifier") {
24476
24501
  const varName = d.id.name;
24477
- if (!referencesAny(init, allNames, scope)) {
24502
+ if (!referencesAny(init, allNames, scope2)) {
24478
24503
  deferredLocals.set(varName, init);
24479
24504
  continue;
24480
24505
  }
24481
24506
  if (refNames.has(varName)) {
24482
- const refEntry = scope.get(varName);
24507
+ const refEntry = scope2.get(varName);
24483
24508
  const refCombi = refEntry?.combi ?? null;
24484
24509
  if (refCombi) {
24485
24510
  const compiled2 = compile(refCombi, refEntry?.mfSrcs, { recovery, coverage: grammarCoverage });
@@ -24564,32 +24589,32 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
24564
24589
  }
24565
24590
  const mapFnSources = [];
24566
24591
  unresolvedImports.clear();
24567
- const parser2 = evaluateExpr(init, scope, code, mapFnSources);
24592
+ const parser2 = evaluateExpr(init, scope2, code, mapFnSources);
24568
24593
  if (parser2 === null) {
24569
- const wordFactory = evaluateWordFactory(init, scope, code);
24594
+ const wordFactory = evaluateWordFactory(init, scope2, code);
24570
24595
  if (wordFactory) {
24571
24596
  ;
24572
- scope.set(varName, wordFactory);
24597
+ scope2.set(varName, wordFactory);
24573
24598
  replacements.push({ start: init.start, end: init.end, replacement: "undefined" });
24574
24599
  continue;
24575
24600
  }
24576
- const whenFactory = evaluateWhenFactory(init, scope, code);
24601
+ const whenFactory = evaluateWhenFactory(init, scope2, code);
24577
24602
  if (whenFactory) {
24578
24603
  ;
24579
- scope.set(varName, whenFactory);
24604
+ scope2.set(varName, whenFactory);
24580
24605
  replacements.push({ start: init.start, end: init.end, replacement: "undefined" });
24581
24606
  continue;
24582
24607
  }
24583
- const combiArray = evaluateCombinatorArray(init, scope, code);
24608
+ const combiArray = evaluateCombinatorArray(init, scope2, code);
24584
24609
  if (combiArray) {
24585
24610
  ;
24586
- scope.set(varName, combiArray);
24611
+ scope2.set(varName, combiArray);
24587
24612
  continue;
24588
24613
  }
24589
- const staticValue = evaluateStaticValue(init, scope, code);
24614
+ const staticValue = evaluateStaticValue(init, scope2, code);
24590
24615
  if (staticValue !== null && staticValue !== void 0 || isStaticNullishExpression(init)) {
24591
24616
  ;
24592
- scope.set(varName, staticValue);
24617
+ scope2.set(varName, staticValue);
24593
24618
  continue;
24594
24619
  }
24595
24620
  if (factoryDecls.has(varName)) {
@@ -24612,9 +24637,9 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
24612
24637
  replacement: compiled.inlineExpression,
24613
24638
  carry: { name: varName, combi: parser2, exported: exportPrefix !== "" }
24614
24639
  });
24615
- scope.set(varName, { combi: parser2, mfSrcs: mapFnSources });
24640
+ scope2.set(varName, { combi: parser2, mfSrcs: mapFnSources });
24616
24641
  } else if (d.id.type === "ObjectPattern") {
24617
- if (!referencesAny(init, allNames, scope)) continue;
24642
+ if (!referencesAny(init, allNames, scope2)) continue;
24618
24643
  if (!isRulesCall(init)) {
24619
24644
  warn(init.start, `destructured macro binding must come from rules(...)`);
24620
24645
  continue;
@@ -24648,7 +24673,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
24648
24673
  }
24649
24674
  bindings.push({ ruleKey, localName });
24650
24675
  const rule = compiledRules.ruleMap.get(ruleKey);
24651
- if (rule) scope.set(localName, { combi: rule, mfSrcs: [] });
24676
+ if (rule) scope2.set(localName, { combi: rule, mfSrcs: [] });
24652
24677
  }
24653
24678
  if (!allOk) continue;
24654
24679
  const holderVar = `__rules${ruleMapHolderCounter++}`;