parseman 0.54.0 → 0.55.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.
@@ -7243,6 +7243,9 @@ var Encoder = class {
7243
7243
  this.expected([adjacencyExpected(d)])
7244
7244
  );
7245
7245
  case "withCtx": {
7246
+ if (typeof d.extra === "function") {
7247
+ return this.emit(OP_WITHCTX, ~this.fn(d.extra, d.extraSrc ?? null), this.node(d.parser).ip);
7248
+ }
7246
7249
  if (!emittableConst(d.extra)) {
7247
7250
  this.runtimeOnly.add("withCtx(extra) \u2014 the state object is not serialisable");
7248
7251
  }
@@ -12586,8 +12589,21 @@ function assemble(t2, prog, cfg) {
12586
12589
  };
12587
12590
  }
12588
12591
  case OP_WITHCTX: {
12589
- const extra = k[code[ip + 1]];
12592
+ const ki = code[ip + 1];
12590
12593
  const child = link(code[ip + 2]);
12594
+ if (ki < 0) {
12595
+ const derive2 = fns[~ki];
12596
+ return (input, pos, ctx) => {
12597
+ const saved = ctx.state;
12598
+ ctx.state = derive2(saved);
12599
+ try {
12600
+ return child(input, pos, ctx);
12601
+ } finally {
12602
+ ctx.state = saved;
12603
+ }
12604
+ };
12605
+ }
12606
+ const extra = k[ki];
12591
12607
  return (input, pos, ctx) => {
12592
12608
  const saved = ctx.state;
12593
12609
  ctx.state = extra;