@barefootjs/erb 0.31.9 → 0.31.10

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/vite.js CHANGED
@@ -3916,6 +3916,38 @@ function classify(name, origin, expr, parsed, available) {
3916
3916
  }
3917
3917
  return { kind: "derived", name, origin, expr, parsed, frees: [...frees] };
3918
3918
  }
3919
+ function localConstExprsByName(metadata) {
3920
+ const out = new Map;
3921
+ for (const c of metadata.localConstants ?? []) {
3922
+ if (c.isModule || c.declarationKind !== "const" || c.value === undefined)
3923
+ continue;
3924
+ out.set(c.name, c.parsed ?? parseExpression(c.value.trim()));
3925
+ }
3926
+ return out;
3927
+ }
3928
+ function resolveThroughLocalConsts(parsed, localConsts) {
3929
+ let current = parsed;
3930
+ const maxIter = localConsts.size + 1;
3931
+ for (let i = 0;i < maxIter; i++) {
3932
+ const frees = freeIdentifiers(current);
3933
+ if (frees === null)
3934
+ break;
3935
+ let changed = false;
3936
+ for (const name of frees) {
3937
+ const value = localConsts.get(name);
3938
+ if (!value)
3939
+ continue;
3940
+ const inlined = inlineBinding(current, name, value);
3941
+ if (inlined === null)
3942
+ continue;
3943
+ current = inlined;
3944
+ changed = true;
3945
+ }
3946
+ if (!changed)
3947
+ break;
3948
+ }
3949
+ return current;
3950
+ }
3919
3951
  function computeSsrSeedPlan(metadata) {
3920
3952
  const baseScope = metadata.propsParams.map((p) => p.name);
3921
3953
  if (metadata.propsObjectName)
@@ -3924,6 +3956,7 @@ function computeSsrSeedPlan(metadata) {
3924
3956
  baseScope.push(name);
3925
3957
  }
3926
3958
  const available = new Set(baseScope);
3959
+ const localConsts = localConstExprsByName(metadata);
3927
3960
  const steps = [];
3928
3961
  for (const signal of metadata.signals) {
3929
3962
  if (signal.envReader) {
@@ -3935,13 +3968,13 @@ function computeSsrSeedPlan(metadata) {
3935
3968
  }
3936
3969
  }
3937
3970
  const expr = signal.initialValue.trim();
3938
- steps.push(expr === "" ? { kind: "opaque", name: signal.getter, origin: "signal" } : classify(signal.getter, "signal", expr, parseExpression(expr), available));
3971
+ steps.push(expr === "" ? { kind: "opaque", name: signal.getter, origin: "signal" } : classify(signal.getter, "signal", expr, resolveThroughLocalConsts(parseExpression(expr), localConsts), available));
3939
3972
  available.add(signal.getter);
3940
3973
  }
3941
3974
  for (const memo of metadata.memos) {
3942
3975
  const body = extractArrowBodyExpression(memo.computation);
3943
3976
  const expr = body?.trim() ?? "";
3944
- steps.push(expr === "" ? { kind: "opaque", name: memo.name, origin: "memo" } : classify(memo.name, "memo", expr, memo.parsed ?? parseExpression(expr), available));
3977
+ steps.push(expr === "" ? { kind: "opaque", name: memo.name, origin: "memo" } : classify(memo.name, "memo", expr, resolveThroughLocalConsts(memo.parsed ?? parseExpression(expr), localConsts), available));
3945
3978
  available.add(memo.name);
3946
3979
  }
3947
3980
  return { baseScope, steps };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/erb",
3
- "version": "0.31.9",
3
+ "version": "0.31.10",
4
4
  "description": "ERB (Embedded Ruby) adapter for BarefootJS — compiles IR to .erb templates and ships the Ruby rendering backend; runs under any Rack app (Sinatra, Rails)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -54,7 +54,7 @@
54
54
  "directory": "packages/adapter-erb"
55
55
  },
56
56
  "dependencies": {
57
- "@barefootjs/shared": "0.31.9"
57
+ "@barefootjs/shared": "0.31.10"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@barefootjs/jsx": ">=0.2.0",
@@ -71,9 +71,9 @@
71
71
  },
72
72
  "devDependencies": {
73
73
  "@barefootjs/adapter-tests": "0.1.0",
74
- "@barefootjs/jsx": "0.31.9",
75
- "@barefootjs/vite": "0.31.9",
76
- "@barefootjs/client": "0.31.9",
74
+ "@barefootjs/jsx": "0.31.10",
75
+ "@barefootjs/vite": "0.31.10",
76
+ "@barefootjs/client": "0.31.10",
77
77
  "typescript": "^5.0.0",
78
78
  "vite": "^6.0.0"
79
79
  }
@@ -605,6 +605,16 @@ function buildRubyProps(
605
605
  // Env signals (#2057 / #1922) are bound below via `search_params('')`,
606
606
  // not from a static initial value.
607
607
  if (signal.envReader) continue
608
+ // #2669: a self-derivation collision (the signal's own initializer
609
+ // derives from a same-named prop, e.g. `createSignal(props.label ??
610
+ // 'Default')`) already got the correct RAW-prop seed above via
611
+ // `derivedProps` / `obj[param.name]` — `extractSsrDefaults` marks that
612
+ // with a `propName`-carrying entry (see its docstring's invariant).
613
+ // Re-seeding here with this harness's OWN recompute
614
+ // (`evaluateSignalInit`) would clobber the correctly-derived caller
615
+ // value with the harness's evaluated-from-static-props number, papering
616
+ // over the exact production bug this fixture exists to catch.
617
+ if (rootSsrDefaults[signal.getter]?.propName !== undefined) continue
608
618
  const value = evaluateSignalInit(signal.initialValue.trim(), props)
609
619
  if (value !== null) {
610
620
  obj[signal.getter] = value
@@ -614,6 +624,12 @@ function buildRubyProps(
614
624
  // Memo values seeded from the statically-evaluated ssrDefaults, same
615
625
  // as the production plugin's before_render hook.
616
626
  for (const memo of ir.metadata.memos) {
627
+ // #2669: same self-derivation skip as the signal loop above — a
628
+ // `propName`-carrying memo entry already stands as the correctly
629
+ // prop-derived seed; don't clobber it with the memo's OWN evaluated
630
+ // value (which for a non-idempotent derivation is already the WRONG,
631
+ // double-applied number).
632
+ if (rootSsrDefaults[memo.name]?.propName !== undefined) continue
617
633
  obj[memo.name] = rootSsrDefaults[memo.name]?.value ?? 0
618
634
  }
619
635