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.
package/dist/cli/index.js CHANGED
@@ -7125,6 +7125,9 @@ var Encoder = class {
7125
7125
  this.expected([adjacencyExpected(d)])
7126
7126
  );
7127
7127
  case "withCtx": {
7128
+ if (typeof d.extra === "function") {
7129
+ return this.emit(OP_WITHCTX, ~this.fn(d.extra, d.extraSrc ?? null), this.node(d.parser).ip);
7130
+ }
7128
7131
  if (!emittableConst(d.extra)) {
7129
7132
  this.runtimeOnly.add("withCtx(extra) \u2014 the state object is not serialisable");
7130
7133
  }
@@ -12470,8 +12473,21 @@ function assemble(t2, prog, cfg) {
12470
12473
  };
12471
12474
  }
12472
12475
  case OP_WITHCTX: {
12473
- const extra = k[code[ip + 1]];
12476
+ const ki = code[ip + 1];
12474
12477
  const child = link(code[ip + 2]);
12478
+ if (ki < 0) {
12479
+ const derive2 = fns[~ki];
12480
+ return (input, pos, ctx) => {
12481
+ const saved = ctx.state;
12482
+ ctx.state = derive2(saved);
12483
+ try {
12484
+ return child(input, pos, ctx);
12485
+ } finally {
12486
+ ctx.state = saved;
12487
+ }
12488
+ };
12489
+ }
12490
+ const extra = k[ki];
12475
12491
  return (input, pos, ctx) => {
12476
12492
  const saved = ctx.state;
12477
12493
  ctx.state = extra;