parseman 0.50.0 → 0.50.1

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.
@@ -6540,6 +6540,22 @@ var Encoder = class {
6540
6540
  choiceRollbackMasks = /* @__PURE__ */ new Map();
6541
6541
  nonCommittingChoiceSites = /* @__PURE__ */ new Set();
6542
6542
  failureRollbackCleanSites = /* @__PURE__ */ new Set();
6543
+ /**
6544
+ * `hasSideWriter` memo for `failureNeedsRollback`, shared across every call
6545
+ * for the lifetime of this `Encoder`. A cached entry is written only when
6546
+ * `complete` is true, which means the answer is a path-independent fact
6547
+ * about that combinator node — it does not depend on which root's traversal
6548
+ * asked, only on the node's own reachable subgraph. Scoping the memo per call
6549
+ * (as a local inside `failureNeedsRollback`) was correct but discarded that
6550
+ * fact after every arm, so a grammar with many ordered-choice arms / optional
6551
+ * / attempt sites re-walked the SAME shared rule graph from scratch for each
6552
+ * site — O(sites × graph size) instead of O(graph size). Measured on the
6553
+ * scss-parser grammar (composed CSS-base superset, the deepest/largest of the
6554
+ * four grammars): 47-50s for one `compileRuleMap` with the per-call memo,
6555
+ * versus the whole macro transform completing in under a second once this
6556
+ * memo is hoisted here.
6557
+ */
6558
+ sideWriterMemo = /* @__PURE__ */ new Map();
6543
6559
  labels = void 0;
6544
6560
  /** Trivia table in scope at the row being encoded — codegen's `ctx.activeTrivia`. */
6545
6561
  activeTrivia = void 0;
@@ -6965,13 +6981,13 @@ var Encoder = class {
6965
6981
  const refName = p._ruleName;
6966
6982
  const winner = refName === void 0 ? void 0 : this.winners?.[refName];
6967
6983
  const root = winner !== void 0 && !winnerWrapsReference2(winner, p) ? winner : p;
6968
- const sideWriterMemo = /* @__PURE__ */ new Map();
6969
- const hasSideWriter = (current, seen = /* @__PURE__ */ new Set()) => {
6984
+ const sideWriterMemo = this.sideWriterMemo;
6985
+ const seen = /* @__PURE__ */ new Set();
6986
+ const hasSideWriter = (current) => {
6970
6987
  const cached = sideWriterMemo.get(current);
6971
6988
  if (cached !== void 0) return { found: cached, complete: true };
6972
6989
  if (seen.has(current)) return { found: false, complete: false };
6973
- const next = new Set(seen);
6974
- next.add(current);
6990
+ seen.add(current);
6975
6991
  const def = current._def;
6976
6992
  let result;
6977
6993
  switch (def.tag) {
@@ -6986,11 +7002,11 @@ var Encoder = class {
6986
7002
  const name = current._ruleName;
6987
7003
  const resolvedWinner = name === void 0 ? void 0 : this.winners?.[name];
6988
7004
  if (resolvedWinner !== void 0 && !winnerWrapsReference2(resolvedWinner, current)) {
6989
- result = hasSideWriter(resolvedWinner, next);
7005
+ result = hasSideWriter(resolvedWinner);
6990
7006
  break;
6991
7007
  }
6992
7008
  try {
6993
- result = hasSideWriter(def.thunk(), next);
7009
+ result = hasSideWriter(def.thunk());
6994
7010
  } catch {
6995
7011
  result = { found: true, complete: true };
6996
7012
  }
@@ -7000,7 +7016,7 @@ var Encoder = class {
7000
7016
  let complete = true;
7001
7017
  result = { found: false, complete: true };
7002
7018
  for (const child of childrenOf2(def)) {
7003
- const childResult = hasSideWriter(child, next);
7019
+ const childResult = hasSideWriter(child);
7004
7020
  if (childResult.found) {
7005
7021
  result = { found: true, complete: true };
7006
7022
  break;
@@ -7010,6 +7026,7 @@ var Encoder = class {
7010
7026
  if (!result.found) result = { found: false, complete };
7011
7027
  }
7012
7028
  }
7029
+ seen.delete(current);
7013
7030
  if (result.found || result.complete) sideWriterMemo.set(current, result.found);
7014
7031
  return result;
7015
7032
  };
@@ -16675,7 +16692,7 @@ function compileRuleMap(ruleMap, opts = {}) {
16675
16692
  }
16676
16693
 
16677
16694
  // src/version.ts
16678
- var PARSEMAN_VERSION = "0.50.0";
16695
+ var PARSEMAN_VERSION = "0.50.1";
16679
16696
 
16680
16697
  // src/compiler/compile-linkable-table.ts
16681
16698
  function isLocal(rule) {