@barefootjs/jsx 0.35.7 → 0.35.8

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.
@@ -1 +1 @@
1
- {"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAInE,OAAO,EACL,KAAK,eAAe,EAUrB,MAAM,uBAAuB,CAAA;AAqB9B;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAU/D;AA8BD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf;IAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC;IAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAA;CAAE,GAAG,IAAI,CA8CpF;AAMD,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,mBAAmB,CAAC,EAAE,MAAM,EAC5B,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,EACpB,mBAAmB,CAAC,EAAE,oBAAoB,EAC1C,eAAe,CAAC,EAAE,OAAO,GACxB,eAAe,CAkKjB;AA8iBD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,GAAG,EAAE,CAAC,UAAU,CAavE;AA+3CD,MAAM,MAAM,aAAa,GAAG,EAAE,CAAC,UAAU,GAAG,EAAE,CAAC,qBAAqB,GAAG,EAAE,CAAC,WAAW,CAAA;AAErF;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,KAAK,CAAC;QACd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AM,mBAAmB,aAG9B,CAAA;AA25CF;;;;;;;;;;;GAWG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI,CA4EvE;AA8OD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAA"}
package/dist/index.js CHANGED
@@ -3475,6 +3475,7 @@ function csrSubstituteOnce(value, env, enclosingScope) {
3475
3475
  const recordSubstitution = (start, end, sub) => {
3476
3476
  splices.push({ start: start - OFFSET, end: end - OFFSET, text: `(${sub.replacement})` });
3477
3477
  };
3478
+ const bareReplacementText = (sub) => sub.kind === "call" ? `(() => (${sub.replacement}))` : `(${sub.replacement})`;
3478
3479
  const collectBindingNames = (name, out) => {
3479
3480
  if (ts8.isIdentifier(name))
3480
3481
  out.add(name.text);
@@ -3523,11 +3524,11 @@ function csrSubstituteOnce(value, env, enclosingScope) {
3523
3524
  if (ts8.isShorthandPropertyAssignment(node)) {
3524
3525
  if (ts8.isIdentifier(node.name) && !isBound(node.name.text)) {
3525
3526
  const sub = env.substitutions.get(node.name.text);
3526
- if (sub && sub.kind === "identifier") {
3527
+ if (sub) {
3527
3528
  splices.push({
3528
3529
  start: node.getStart(sourceFile) - OFFSET,
3529
3530
  end: node.getEnd() - OFFSET,
3530
- text: `${node.name.text}: (${sub.replacement})`
3531
+ text: `${node.name.text}: ${bareReplacementText(sub)}`
3531
3532
  });
3532
3533
  }
3533
3534
  }
@@ -3555,8 +3556,12 @@ function csrSubstituteOnce(value, env, enclosingScope) {
3555
3556
  if (isBound(node.text))
3556
3557
  return;
3557
3558
  const sub = env.substitutions.get(node.text);
3558
- if (sub && sub.kind === "identifier") {
3559
- recordSubstitution(node.getStart(sourceFile), node.getEnd(), sub);
3559
+ if (sub) {
3560
+ splices.push({
3561
+ start: node.getStart(sourceFile) - OFFSET,
3562
+ end: node.getEnd() - OFFSET,
3563
+ text: bareReplacementText(sub)
3564
+ });
3560
3565
  }
3561
3566
  return;
3562
3567
  }
@@ -3661,6 +3666,9 @@ function buildSignalMemoEnv(signals, memos, propsObjectName, localConstants = []
3661
3666
  replacement: normalizeSignalInitial(s, propsObjectName),
3662
3667
  freeIdentifiers: s.initialFreeIdentifiers ?? new Set
3663
3668
  });
3669
+ if (s.setter) {
3670
+ substitutions.set(s.setter, { kind: "identifier", replacement: "() => {}", freeIdentifiers: new Set });
3671
+ }
3664
3672
  }
3665
3673
  for (const m of memos) {
3666
3674
  substitutions.set(m.name, {
@@ -6894,6 +6902,9 @@ function collectNamedExports(sourceFile) {
6894
6902
  }
6895
6903
  return exported;
6896
6904
  }
6905
+ function isFunctionScope(node) {
6906
+ return ts14.isArrowFunction(node) || ts14.isFunctionExpression(node) || ts14.isFunctionDeclaration(node) || ts14.isMethodDeclaration(node) || ts14.isGetAccessorDeclaration(node) || ts14.isSetAccessorDeclaration(node) || ts14.isConstructorDeclaration(node);
6907
+ }
6897
6908
  function visit2(node, ctx, targetComponentName, namedExports) {
6898
6909
  if (ts14.isExpressionStatement(node) && ts14.isStringLiteral(node.expression)) {
6899
6910
  if (node.expression.text === "use client" || node.expression.text === "'use client'") {
@@ -7019,7 +7030,11 @@ function visit2(node, ctx, targetComponentName, namedExports) {
7019
7030
  }
7020
7031
  }
7021
7032
  }
7022
- ts14.forEachChild(node, (child) => visit2(child, ctx, targetComponentName, namedExports));
7033
+ ts14.forEachChild(node, (child) => {
7034
+ if (isFunctionScope(child) && !ts14.isFunctionDeclaration(child) && child !== ctx.componentNode)
7035
+ return;
7036
+ visit2(child, ctx, targetComponentName, namedExports);
7037
+ });
7023
7038
  }
7024
7039
  function analyzeComponentBody(node, ctx) {
7025
7040
  if (node.parameters.length > 0) {
@@ -7128,9 +7143,8 @@ function visitComponentBody(node, ctx) {
7128
7143
  ctx.jsxReturn = unwrapJsxTransparent(node.expression);
7129
7144
  }
7130
7145
  ts14.forEachChild(node, (child) => {
7131
- if (ts14.isArrowFunction(child) || ts14.isFunctionExpression(child) || ts14.isFunctionDeclaration(child)) {
7146
+ if (isFunctionScope(child))
7132
7147
  return;
7133
- }
7134
7148
  visitComponentBody(child, ctx);
7135
7149
  });
7136
7150
  }
@@ -17225,6 +17239,7 @@ var RUNTIME_IMPORT_CANDIDATES = [
17225
17239
  "createEffect",
17226
17240
  "onCleanup",
17227
17241
  "onMount",
17242
+ "batch",
17228
17243
  "hydrate",
17229
17244
  "insert",
17230
17245
  "getLoopChildren",
@@ -24657,6 +24672,9 @@ function extractSsrDefaults(metadata) {
24657
24672
  out[sig.getter] = { value: resultToJsonable(value) };
24658
24673
  }
24659
24674
  bindings[sig.getter] = value;
24675
+ if (sig.setter && !(sig.setter in out)) {
24676
+ out[sig.setter] = { value: null };
24677
+ }
24660
24678
  }
24661
24679
  for (const memo of metadata.memos) {
24662
24680
  if (memo.isModule)
@@ -24673,6 +24691,10 @@ function extractSsrDefaults(metadata) {
24673
24691
  }
24674
24692
  {
24675
24693
  const getterNames = collectAliasableGetterNames(metadata.signals, metadata.memos);
24694
+ for (const sig of metadata.signals) {
24695
+ if (sig.setter && !sig.isModule && !sig.envReader)
24696
+ getterNames.add(sig.setter);
24697
+ }
24676
24698
  for (const [alias, origin] of resolveGetterAliases(metadata.localConstants ?? [], (n) => getterNames.has(n))) {
24677
24699
  if (alias in out)
24678
24700
  continue;
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * - signal getter calls (`count()`) → `(initialValue)`
8
8
  * - memo getter calls (`bars()`) → `(computationBody)`
9
+ * - bare signal/memo getter refs (`count`) → `(() => (initialValue))`
9
10
  * - bare inlinable-const refs (`label`) → `(csrInlinable.rewrittenValue)`
10
11
  * - bare source-level props refs (`props.x`) → `_p.x`
11
12
  *
@@ -51,7 +52,25 @@ export type CsrInlinabilityMap = Map<string, CsrInlinableEntry | null>;
51
52
  /**
52
53
  * A single substitution: when the source expression mentions `name`
53
54
  * (either bare or as a zero-arg call, depending on `kind`), the AST
54
- * walker splices `replacement` in place.
55
+ * walker splices a replacement in place.
56
+ *
57
+ * `kind` says what `replacement` IS, not just where it matches:
58
+ *
59
+ * - `'call'`: `replacement` is the VALUE the zero-arg accessor `name()`
60
+ * produces (a signal's initial value, a memo's computation body). The
61
+ * call site `name()` substitutes to `(replacement)` directly. A BARE
62
+ * reference to `name` (uncalled — e.g. a getter passed as a component
63
+ * prop, `<Display value={count} />`, #2924) substitutes to
64
+ * `(() => (replacement))` instead: a thunk over the same value, which
65
+ * is the CSR-template mirror of the reference adapter's SSR shim
66
+ * (`const count = () => 5`, `packages/adapter-hono`) — the only
67
+ * reading that lets a bare accessor evaluate identically on SSR and on
68
+ * CSR-fresh-mount. Registered only by `buildSignalMemoEnv` below.
69
+ * - `'identifier'`: `replacement` is already the value a BARE reference
70
+ * to `name` should read as (e.g. an inlinable const's resolved value);
71
+ * there is no corresponding call form. Substitutes to `(replacement)`
72
+ * at both a bare reference and the (non-existent, for this kind) call
73
+ * position.
55
74
  */
56
75
  export interface CsrSubstitution {
57
76
  kind: 'call' | 'identifier';
@@ -62,10 +81,11 @@ export interface CsrSubstitution {
62
81
  }
63
82
  export interface CsrEnv {
64
83
  /**
65
- * Map of name → substitution. Call-kind entries match `name()`
66
- * (zero-arg call with bare-ident callee) and replace the entire
67
- * call expression; identifier-kind entries match bare uses of
68
- * `name` outside member-access tails.
84
+ * Map of name → substitution. Call-kind entries match both `name()`
85
+ * (zero-arg call with bare-ident callee — replaced with the accessor's
86
+ * value) and bare uses of `name` (replaced with a thunk over that same
87
+ * value, #2924); identifier-kind entries match bare uses of `name`
88
+ * outside member-access tails.
69
89
  */
70
90
  substitutions: Map<string, CsrSubstitution>;
71
91
  /** Source-level props object name (`props`); null for destructured-args. */
@@ -1 +1 @@
1
- {"version":3,"file":"csr-substitute.d.ts","sourceRoot":"","sources":["../../src/ir-to-client-js/csr-substitute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACr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AE,GACzB,GAAG,CAAC,MAAM,CAAC,CASb;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,SAAS,UAAU,EAAE,EAC9B,KAAK,EAAE,SAAS,QAAQ,EAAE,EAC1B,eAAe,EAAE,MAAM,GAAG,IAAI,EAC9B,cAAc,GAAE,SAAS,YAAY,EAAO,GAC3C,MAAM,CA6CR"}
@@ -2,9 +2,9 @@
2
2
  * Import detection and DOM import management.
3
3
  */
4
4
  import type { ComponentIR } from '../types.ts';
5
- export declare const RUNTIME_IMPORT_CANDIDATES: readonly ['createSignal', 'createMemo', 'createEffect', 'onCleanup', 'onMount', 'hydrate', 'insert', 'getLoopChildren', 'getLoopNodes', 'mapArray', 'mapArrayAnchored', 'mapArrayLazy', 'patchLeaf', 'createDisposableEffect', 'findCondContainer', 'createComponent', 'renderChild', 'registerComponent', 'registerTemplate', 'initChild', 'upsertChild', 'mountRowRoot', 'withParentScope', 'createPortal', 'provideContext', 'createContext', 'useContext', 'forwardProps', 'applyRestAttrs', 'splitProps', 'spreadAttrs', 'styleToCss', 'escapeAttr', 'escapeText', 'escapeTextOrNode', 'escapeCommentText', 'bfMarkup', 'escapeTextOrMarkup', 'markupOrEmpty', 'qsa', 'qsaItem', 'qsaChildScope', 'qsaChildScopes', 'upsertChildItem', '__slot', '__bfSlot', '__bfText', 'claimSlots', 'lazySlots', 'lazyClaimSlots', 'textOrNode', 'beginTurn', 'endTurn', 'date', 'formatDate', 'ownScopeId'];
5
+ export declare const RUNTIME_IMPORT_CANDIDATES: readonly ['createSignal', 'createMemo', 'createEffect', 'onCleanup', 'onMount', 'batch', 'hydrate', 'insert', 'getLoopChildren', 'getLoopNodes', 'mapArray', 'mapArrayAnchored', 'mapArrayLazy', 'patchLeaf', 'createDisposableEffect', 'findCondContainer', 'createComponent', 'renderChild', 'registerComponent', 'registerTemplate', 'initChild', 'upsertChild', 'mountRowRoot', 'withParentScope', 'createPortal', 'provideContext', 'createContext', 'useContext', 'forwardProps', 'applyRestAttrs', 'splitProps', 'spreadAttrs', 'styleToCss', 'escapeAttr', 'escapeText', 'escapeTextOrNode', 'escapeCommentText', 'bfMarkup', 'escapeTextOrMarkup', 'markupOrEmpty', 'qsa', 'qsaItem', 'qsaChildScope', 'qsaChildScopes', 'upsertChildItem', '__slot', '__bfSlot', '__bfText', 'claimSlots', 'lazySlots', 'lazyClaimSlots', 'textOrNode', 'beginTurn', 'endTurn', 'date', 'formatDate', 'ownScopeId'];
6
6
  /** @deprecated Use RUNTIME_IMPORT_CANDIDATES */
7
- export declare const DOM_IMPORT_CANDIDATES: readonly ["createSignal", "createMemo", "createEffect", "onCleanup", "onMount", "hydrate", "insert", "getLoopChildren", "getLoopNodes", "mapArray", "mapArrayAnchored", "mapArrayLazy", "patchLeaf", "createDisposableEffect", "findCondContainer", "createComponent", "renderChild", "registerComponent", "registerTemplate", "initChild", "upsertChild", "mountRowRoot", "withParentScope", "createPortal", "provideContext", "createContext", "useContext", "forwardProps", "applyRestAttrs", "splitProps", "spreadAttrs", "styleToCss", "escapeAttr", "escapeText", "escapeTextOrNode", "escapeCommentText", "bfMarkup", "escapeTextOrMarkup", "markupOrEmpty", "qsa", "qsaItem", "qsaChildScope", "qsaChildScopes", "upsertChildItem", "__slot", "__bfSlot", "__bfText", "claimSlots", "lazySlots", "lazyClaimSlots", "textOrNode", "beginTurn", "endTurn", "date", "formatDate", "ownScopeId"];
7
+ export declare const DOM_IMPORT_CANDIDATES: readonly ["createSignal", "createMemo", "createEffect", "onCleanup", "onMount", "batch", "hydrate", "insert", "getLoopChildren", "getLoopNodes", "mapArray", "mapArrayAnchored", "mapArrayLazy", "patchLeaf", "createDisposableEffect", "findCondContainer", "createComponent", "renderChild", "registerComponent", "registerTemplate", "initChild", "upsertChild", "mountRowRoot", "withParentScope", "createPortal", "provideContext", "createContext", "useContext", "forwardProps", "applyRestAttrs", "splitProps", "spreadAttrs", "styleToCss", "escapeAttr", "escapeText", "escapeTextOrNode", "escapeCommentText", "bfMarkup", "escapeTextOrMarkup", "markupOrEmpty", "qsa", "qsaItem", "qsaChildScope", "qsaChildScopes", "upsertChildItem", "__slot", "__bfSlot", "__bfText", "claimSlots", "lazySlots", "lazyClaimSlots", "textOrNode", "beginTurn", "endTurn", "date", "formatDate", "ownScopeId"];
8
8
  export declare const RUNTIME_MODULE = "@barefootjs/client/runtime";
9
9
  export declare const IMPORT_PLACEHOLDER = "/* __BAREFOOTJS_DOM_IMPORTS__ */";
10
10
  export declare const MODULE_CONSTANTS_PLACEHOLDER = "/* __MODULE_LEVEL_CONSTANTS__ */";
@@ -1 +1 @@
1
- {"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../src/ir-to-client-js/imports.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAU,MAAM,aAAa,CAAA;AAMtD,eAAO,MAAM,yBAAyB,YACpC,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EACpE,SAAS,EAAE,QAAQ,EAAE,iBAAiB,EAAE,cAAc,EAAE,UAAU,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EAAE,wBAAwB,EAK7I,mBAAmB,EACnB,iBAAiB,EAAE,aAAa,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAKrG,cAAc,EAId,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAAE,eAAe,EAAE,YAAY,EAC/C,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAG3H,mBAAmB,EAInB,UAAU,EAAE,oBAAoB,EAGhC,eAAe,EACf,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAUxG,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EA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"ssr-defaults.d.ts","sourceRoot":"","sources":["../src/ssr-defaults.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,KAAK,EAAE,OAAO,CAAA;IACd;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAuBzB;AAkBD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,SAAS,CA8P/F"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/jsx",
3
- "version": "0.35.7",
3
+ "version": "0.35.8",
4
4
  "description": "JSX compiler for BarefootJS - transforms JSX to server HTML + client JS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -49,7 +49,7 @@
49
49
  "directory": "packages/jsx"
50
50
  },
51
51
  "dependencies": {
52
- "@barefootjs/shared": "0.35.7"
52
+ "@barefootjs/shared": "0.35.8"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@barefootjs/client": ">=0.2.0",
@@ -0,0 +1,117 @@
1
+ /**
2
+ * #2924 — a BARE (uncalled) reference to a `call`-kind `CsrSubstitution`
3
+ * entry (a signal/memo getter) must substitute as a thunk over the
4
+ * accessor's value, not the value itself.
5
+ *
6
+ * `buildSignalMemoEnv` registers signal getters and memos as `kind: 'call'`
7
+ * entries: the CALL SITE `count()` substitutes to the accessor's value
8
+ * directly (`(5)`), because calling the accessor IS reading the value. A
9
+ * BARE reference to the same name (`count`, uncalled — e.g. passed as a
10
+ * component prop, `<Display value={count} />`) is not a read: it's the
11
+ * accessor itself, which only exists as a real closure inside `initXxx`'s
12
+ * function scope. Before this fix, `csrSubstituteOnce`'s bare-identifier
13
+ * and shorthand-property branches only matched `kind === 'identifier'`, so
14
+ * a bare `count` fell through untouched and leaked into the module-scope
15
+ * `template` lambda as a genuine free identifier — a guaranteed
16
+ * `ReferenceError` on CSR-fresh-mount.
17
+ *
18
+ * The fix: a bare reference to a `call`-kind entry now substitutes to
19
+ * `(() => (value))` — a thunk over the same value the call form produces.
20
+ * This mirrors the reference adapter's (Hono's) SSR shim for the same
21
+ * shape (`const count = () => 5`), so the CSR template and SSR markup
22
+ * agree on what a bare accessor prop evaluates to.
23
+ *
24
+ * Direct unit coverage of `csrSubstitute` itself; `csr-template-scope-
25
+ * soundness.test.ts`'s case D exercises the same fix through the full
26
+ * compile pipeline.
27
+ */
28
+
29
+ import { describe, test, expect } from 'bun:test'
30
+ import { csrSubstitute, type CsrEnv } from '../ir-to-client-js/csr-substitute.ts'
31
+ import { BindingScope } from '../scope/binding-scope.ts'
32
+
33
+ function callEnv(name: string, replacement: string): CsrEnv {
34
+ return {
35
+ substitutions: new Map([[name, { kind: 'call', replacement, freeIdentifiers: new Set() }]]),
36
+ propsObjectName: null,
37
+ }
38
+ }
39
+
40
+ describe('csrSubstitute: bare reference to a call-kind entry (#2924)', () => {
41
+ test('a called reference still substitutes to the plain value', () => {
42
+ const { rewritten, freeIdentifiers } = csrSubstitute('count()', callEnv('count', '5'))
43
+ expect(rewritten).toBe('(5)')
44
+ expect(freeIdentifiers.size).toBe(0)
45
+ })
46
+
47
+ test('a bare reference substitutes to a thunk over the same value', () => {
48
+ const { rewritten, freeIdentifiers } = csrSubstitute('count', callEnv('count', '5'))
49
+ expect(rewritten).toBe('(() => (5))')
50
+ expect(freeIdentifiers.size).toBe(0)
51
+ })
52
+
53
+ test('a bare reference nested in an object literal value position substitutes to a thunk', () => {
54
+ const { rewritten } = csrSubstitute('{ v: count }', callEnv('count', '5'))
55
+ expect(rewritten).toBe('{ v: (() => (5)) }')
56
+ })
57
+
58
+ test('a bare reference in shorthand-property position substitutes to a thunk, keyed correctly', () => {
59
+ const { rewritten } = csrSubstitute('{ count }', callEnv('count', '5'))
60
+ expect(rewritten).toBe('{ count: (() => (5)) }')
61
+ })
62
+
63
+ test('member access on the bare name is untouched (structural protection, #1100)', () => {
64
+ const { rewritten, freeIdentifiers } = csrSubstitute('ctx.count', callEnv('count', '5'))
65
+ expect(rewritten).toBe('ctx.count')
66
+ expect(freeIdentifiers.has('ctx')).toBe(true)
67
+ expect(freeIdentifiers.has('count')).toBe(false)
68
+ })
69
+
70
+ test('a getter call INSIDE a memo body thunk still substitutes (fixed-point loop)', () => {
71
+ const env: CsrEnv = {
72
+ substitutions: new Map([
73
+ ['count', { kind: 'call', replacement: '5', freeIdentifiers: new Set() }],
74
+ ['doubled', { kind: 'call', replacement: 'count() * 2', freeIdentifiers: new Set(['count']) }],
75
+ ]),
76
+ propsObjectName: null,
77
+ }
78
+ const { rewritten, freeIdentifiers } = csrSubstitute('doubled', env)
79
+ expect(rewritten).toBe('(() => ((5) * 2))')
80
+ expect(freeIdentifiers.size).toBe(0)
81
+ })
82
+
83
+ test('a .map() row parameter shadowing the getter name is not substituted', () => {
84
+ const scope = BindingScope.EMPTY.enterLoopRow({ param: 'count' })
85
+ const { rewritten } = csrSubstitute('count', callEnv('count', '5'), scope)
86
+ expect(rewritten).toBe('count')
87
+ })
88
+
89
+ test('an identifier-kind entry (inlinable const) is unaffected by the thunk rule', () => {
90
+ const env: CsrEnv = {
91
+ substitutions: new Map([['label', { kind: 'identifier', replacement: "'hi'", freeIdentifiers: new Set() }]]),
92
+ propsObjectName: null,
93
+ }
94
+ const { rewritten } = csrSubstitute('label', env)
95
+ expect(rewritten).toBe("('hi')")
96
+ })
97
+ })
98
+
99
+ describe('csrSubstitute: bare reference to a signal setter (#2924, setter-symmetric case)', () => {
100
+ function setterEnv(name: string): CsrEnv {
101
+ return {
102
+ substitutions: new Map([[name, { kind: 'identifier', replacement: '() => {}', freeIdentifiers: new Set() }]]),
103
+ propsObjectName: null,
104
+ }
105
+ }
106
+
107
+ test('a bare setter reference substitutes to the noop shim (identifier-kind, no thunk-wrapping)', () => {
108
+ const { rewritten, freeIdentifiers } = csrSubstitute('setCount', setterEnv('setCount'))
109
+ expect(rewritten).toBe('(() => {})')
110
+ expect(freeIdentifiers.size).toBe(0)
111
+ })
112
+
113
+ test('a setter reference nested in an object literal value position also substitutes', () => {
114
+ const { rewritten } = csrSubstitute('{ onChange: setCount }', setterEnv('setCount'))
115
+ expect(rewritten).toBe('{ onChange: (() => {}) }')
116
+ })
117
+ })
@@ -15,6 +15,14 @@
15
15
  * C. a getter-elided signal (`const [, setActive] = createSignal(0)`)
16
16
  * was dropped from init entirely while its setter stayed referenced
17
17
  * by the emitted handler.
18
+ *
19
+ * D. a component prop whose value is (or contains) a BARE — uncalled —
20
+ * reference to a local signal/memo getter (`<Display value={count} />`,
21
+ * #2924) kept the bare source-level name in the `renderChild(...)`
22
+ * props literal instead of substituting a thunk over its value.
23
+ * E. the setter-symmetric case (`<Display update={setCount} />`, #2924):
24
+ * a bare reference to a signal SETTER hit the identical gap — no
25
+ * substitution entry existed for the setter's name at all.
18
26
  */
19
27
 
20
28
  import { describe, test, expect } from 'bun:test'
@@ -93,6 +101,123 @@ export function Fire() {
93
101
  // statement must exist in the emitted init.
94
102
  expect(clientJs).toMatch(/setFlag\s*\]\s*=\s*createSignal\(0\)/)
95
103
  })
104
+
105
+ test('D: a bare signal getter passed as a component prop substitutes a thunk in the template', () => {
106
+ const clientJs = clientJsOf(`
107
+ "use client"
108
+ import { createSignal } from '@barefootjs/client'
109
+
110
+ function Display(props: { value: () => number }) {
111
+ return <span class="value">{props.value()}</span>
112
+ }
113
+
114
+ export function Counter() {
115
+ const [count, setCount] = createSignal(5)
116
+ return (
117
+ <div class="root">
118
+ <Display value={count} />
119
+ </div>
120
+ )
121
+ }
122
+ `)
123
+ const template = templateLambdaOf(clientJs, 'Counter')
124
+ expect(template).toContain('value: (() => (5))')
125
+ expect(template).not.toMatch(/value:\s*count\b/)
126
+ })
127
+
128
+ test('D: a bare memo getter passed as a component prop substitutes a thunk over its computation', () => {
129
+ const clientJs = clientJsOf(`
130
+ "use client"
131
+ import { createSignal, createMemo } from '@barefootjs/client'
132
+
133
+ function Display(props: { value: () => number }) {
134
+ return <span class="value">{props.value()}</span>
135
+ }
136
+
137
+ export function Counter() {
138
+ const [count] = createSignal(5)
139
+ const doubled = createMemo(() => count() * 2)
140
+ return (
141
+ <div class="root">
142
+ <Display value={doubled} />
143
+ </div>
144
+ )
145
+ }
146
+ `)
147
+ const template = templateLambdaOf(clientJs, 'Counter')
148
+ expect(template).toContain('value: (() => ((5) * 2))')
149
+ expect(template).not.toMatch(/value:\s*doubled\b/)
150
+ })
151
+
152
+ test('D: a bare getter wrapped in an object literal prop also substitutes a thunk (Context-Provider idiom)', () => {
153
+ const clientJs = clientJsOf(`
154
+ "use client"
155
+ import { createSignal } from '@barefootjs/client'
156
+
157
+ function Display(props: { value: { v: () => number } }) {
158
+ return <span class="value">{props.value.v()}</span>
159
+ }
160
+
161
+ export function Counter() {
162
+ const [count, setCount] = createSignal(5)
163
+ return (
164
+ <div class="root">
165
+ <Display value={{ v: count }} />
166
+ </div>
167
+ )
168
+ }
169
+ `)
170
+ const template = templateLambdaOf(clientJs, 'Counter')
171
+ expect(template).toContain('{ v: (() => (5)) }')
172
+ expect(template).not.toMatch(/\{\s*v:\s*count\s*\}/)
173
+ })
174
+
175
+ test('D: a getter-only const alias (e.g. `const c2 = count`) inlines the same thunk, not a deferred placeholder', () => {
176
+ const clientJs = clientJsOf(`
177
+ "use client"
178
+ import { createSignal } from '@barefootjs/client'
179
+
180
+ function Display(props: { value: () => number }) {
181
+ return <span class="value">{props.value()}</span>
182
+ }
183
+
184
+ export function Counter() {
185
+ const [count, setCount] = createSignal(5)
186
+ const c2 = count
187
+ return (
188
+ <div class="root">
189
+ <Display value={c2} />
190
+ </div>
191
+ )
192
+ }
193
+ `)
194
+ const template = templateLambdaOf(clientJs, 'Counter')
195
+ expect(template).toContain('value: (() => (5))')
196
+ expect(template).not.toContain('data-bf-ph')
197
+ })
198
+
199
+ test('E: a bare signal setter passed as a component prop substitutes the SSR noop shim', () => {
200
+ const clientJs = clientJsOf(`
201
+ "use client"
202
+ import { createSignal } from '@barefootjs/client'
203
+
204
+ function Display(props: { update: () => void }) {
205
+ return <button onClick={() => props.update()}>go</button>
206
+ }
207
+
208
+ export function Counter() {
209
+ const [count, setCount] = createSignal(5)
210
+ return (
211
+ <div class="root">
212
+ <Display update={setCount} />
213
+ </div>
214
+ )
215
+ }
216
+ `)
217
+ const template = templateLambdaOf(clientJs, 'Counter')
218
+ expect(template).toContain('update: (() => {})')
219
+ expect(template).not.toMatch(/update:\s*setCount\b/)
220
+ })
96
221
  })
97
222
 
98
223
  /**
@@ -0,0 +1,286 @@
1
+ /**
2
+ * Module-level helper functions referenced from a component (#2986).
3
+ *
4
+ * `visit()`'s module-level walk used to descend into the body of a
5
+ * module-level `const f = (…) => { … }` and collect that body's inner
6
+ * `const`/`function` declarations as if they were declarations of the
7
+ * FILE itself — hoisted into both the component's init function and the
8
+ * marked template, where their references to the helper's own
9
+ * parameters are unbound. The `function f(…) { … }` declaration form was
10
+ * immune (the module-level branch `return`s right after collecting it,
11
+ * so it is never walked into) — that asymmetry is what the issue
12
+ * reported as "function vs const arrow" being inlined differently.
13
+ *
14
+ * Pre-fix, the leaked inner declaration appeared TWICE in the emitted
15
+ * client JS: once (broken — unbound param refs) hoisted to the top of
16
+ * init, and once more correctly inside the helper's own body. Every
17
+ * "does not leak" assertion below therefore checks the occurrence COUNT
18
+ * of the inner statement, not just its presence — a bare `.toContain`
19
+ * would pass on both the broken and the fixed output.
20
+ *
21
+ * Every parity case asserts that the `const` arrow form and the
22
+ * `function` declaration form agree — that agreement is the property
23
+ * whose absence produced the bug, and the guard this test protects
24
+ * (`isFunctionScope`, `analyzer.ts`) is now the single shared answer to
25
+ * "does this node open a new function scope?" for both the module-level
26
+ * walk (`visit`) and the component-body walk (`visitComponentBody`).
27
+ */
28
+
29
+ import { describe, test, expect } from 'bun:test'
30
+ import { compileJSX } from '../index'
31
+ import { HonoAdapter } from '../../../adapter-hono/src/adapter'
32
+
33
+ function compile(source: string) {
34
+ const result = compileJSX(source, 'ModuleHelper.tsx', { adapter: new HonoAdapter() })
35
+ const clientJs = result.files.find(f => f.type === 'clientJs')?.content ?? ''
36
+ const markedTemplate = result.files.find(f => f.type === 'markedTemplate')?.content ?? ''
37
+ return { result, clientJs, markedTemplate }
38
+ }
39
+
40
+ function countOccurrences(haystack: string, needle: string): number {
41
+ return haystack.split(needle).length - 1
42
+ }
43
+
44
+ describe('module-level helper functions (#2986)', () => {
45
+ test('sync block-bodied helper: inner declaration stays inside the helper, not hoisted into init', () => {
46
+ const { result, clientJs, markedTemplate } = compile(`
47
+ 'use client'
48
+ import { createSignal } from '@barefootjs/client'
49
+ const score = (title: string, term: string): number => {
50
+ const t = title.toLowerCase()
51
+ return t.includes(term) ? 1 : 0
52
+ }
53
+ export function Search() {
54
+ const [term, setTerm] = createSignal('')
55
+ return <div onClick={() => setTerm('x')}>{score('hello', term())}</div>
56
+ }
57
+ `)
58
+ expect(result.errors.filter(e => e.severity === 'error')).toEqual([])
59
+ // Pre-fix this line was duplicated: once (broken) at the top of init
60
+ // and once inside `score`'s own body. It must appear exactly once.
61
+ expect(countOccurrences(clientJs, 'const t = title.toLowerCase()')).toBe(1)
62
+ expect(clientJs).toContain('const score = (title, term) => {')
63
+ // The Hono reference adapter's marked template is TSX source rendered
64
+ // through the JSX runtime, so it legitimately contains the helper
65
+ // once, correctly scoped — pre-fix it was duplicated here too.
66
+ expect(countOccurrences(markedTemplate, 'const t = title.toLowerCase()')).toBe(1)
67
+ })
68
+
69
+ test('async helper: no top-level-of-init await, async wrapper intact, no bare await in the template', () => {
70
+ const { result, clientJs, markedTemplate } = compile(`
71
+ 'use client'
72
+ import { createSignal, onMount } from '@barefootjs/client'
73
+ const loadData = async (): Promise<string[]> => {
74
+ const res = await fetch('/data.json')
75
+ return res.json()
76
+ }
77
+ function Widget() {
78
+ const [items, setItems] = createSignal<string[]>([])
79
+ onMount(() => { void loadData().then(setItems) })
80
+ return <div>{items().length}</div>
81
+ }
82
+ export default Widget
83
+ `)
84
+ expect(result.errors.filter(e => e.severity === 'error')).toEqual([])
85
+ expect(countOccurrences(clientJs, "await fetch('/data.json')")).toBe(1)
86
+ expect(clientJs).toContain('const loadData = async () => {')
87
+ // Same reasoning as the sync case: the reference adapter's marked
88
+ // template is TSX source, so `loadData` legitimately appears once,
89
+ // correctly scoped — pre-fix its inner `await` was duplicated here.
90
+ expect(countOccurrences(markedTemplate, "await fetch('/data.json')")).toBe(1)
91
+ })
92
+
93
+ test('object-literal property arrow: an async method on a module-level object const does not leak', () => {
94
+ const { result, clientJs } = compile(`
95
+ 'use client'
96
+ import { createSignal } from '@barefootjs/client'
97
+ const api = {
98
+ load: async () => {
99
+ const res = await fetch('/data.json')
100
+ return res.json()
101
+ },
102
+ }
103
+ export function Widget() {
104
+ const [count, setCount] = createSignal(0)
105
+ return <button onClick={() => { void api.load(); setCount(count() + 1) }}>{count()}</button>
106
+ }
107
+ `)
108
+ expect(result.errors.filter(e => e.severity === 'error')).toEqual([])
109
+ expect(countOccurrences(clientJs, "await fetch('/data.json')")).toBe(1)
110
+ })
111
+
112
+ test('nested function inside a module arrow does not escape to module scope', () => {
113
+ const { result, clientJs } = compile(`
114
+ 'use client'
115
+ import { createSignal } from '@barefootjs/client'
116
+ const outer = (v: number) => {
117
+ function inner(q: number) { return q + v }
118
+ return inner(1)
119
+ }
120
+ export function Widget() {
121
+ const [count, setCount] = createSignal(0)
122
+ return <button onClick={() => setCount(outer(count()))}>{count()}</button>
123
+ }
124
+ `)
125
+ expect(result.errors.filter(e => e.severity === 'error')).toEqual([])
126
+ expect(clientJs).not.toMatch(/var inner = inner \?\?/)
127
+ })
128
+
129
+ test('factory arrow containing createSignal: no false BF011 (SIGNAL_OUTSIDE_COMPONENT)', () => {
130
+ const { result } = compile(`
131
+ 'use client'
132
+ import { createSignal } from '@barefootjs/client'
133
+ const mk = () => {
134
+ const [a, setA] = createSignal(0)
135
+ return a
136
+ }
137
+ export function Widget() {
138
+ const a = mk()
139
+ return <div>{a()}</div>
140
+ }
141
+ `)
142
+ expect(result.errors.filter(e => e.code === 'BF011')).toEqual([])
143
+ })
144
+
145
+ test('component-body object method: an inline method on a component-local const does not leak into init', () => {
146
+ const { result, clientJs } = compile(`
147
+ 'use client'
148
+ import { createSignal } from '@barefootjs/client'
149
+ export function Widget() {
150
+ const [count, setCount] = createSignal(0)
151
+ const api = {
152
+ load() {
153
+ const r = 1
154
+ return r
155
+ },
156
+ }
157
+ return <button onClick={() => setCount(count() + api.load())}>{count()}</button>
158
+ }
159
+ `)
160
+ expect(result.errors.filter(e => e.severity === 'error')).toEqual([])
161
+ expect(countOccurrences(clientJs, 'const r = 1')).toBe(1)
162
+ })
163
+
164
+ test('guard: a component-body async function declaration referencing component scope still lowers to an async arrow in init', () => {
165
+ const { result, clientJs } = compile(`
166
+ 'use client'
167
+ import { createSignal } from '@barefootjs/client'
168
+ export function Widget() {
169
+ const [items, setItems] = createSignal<string[]>([])
170
+ async function fetchItems() {
171
+ const res = await fetch('/data.json')
172
+ setItems(await res.json())
173
+ }
174
+ return <button onClick={() => fetchItems()}>{items().length}</button>
175
+ }
176
+ `)
177
+ expect(result.errors.filter(e => e.severity === 'error')).toEqual([])
178
+ // References `setItems` (component scope), so `compute-scope`'s
179
+ // fixpoint must demote it to init scope, same as the #1130 pin.
180
+ expect(clientJs).toMatch(/const\s+fetchItems\s*=\s*async\s*\(/)
181
+ })
182
+
183
+ test('guard: a module-level async helper with no component-scope references is safely promoted to module scope', () => {
184
+ const { result, clientJs } = compile(`
185
+ 'use client'
186
+ import { createSignal, onMount } from '@barefootjs/client'
187
+ export function Widget() {
188
+ const [items, setItems] = createSignal<string[]>([])
189
+ async function fetchItems() {
190
+ const res = await fetch('/data.json')
191
+ return res.json()
192
+ }
193
+ onMount(() => { void fetchItems().then(setItems) })
194
+ return <div>{items().length}</div>
195
+ }
196
+ `)
197
+ expect(result.errors.filter(e => e.severity === 'error')).toEqual([])
198
+ // `fetchItems` closes over nothing component-scoped, so it is free to
199
+ // live at true module scope; it must still be a valid, complete async
200
+ // function exactly once (not leaked/duplicated into init).
201
+ expect(countOccurrences(clientJs, "await fetch('/data.json')")).toBe(1)
202
+ })
203
+
204
+ test('guard: an arrow component still collects a function declared inside its own body', () => {
205
+ const { result, clientJs } = compile(`
206
+ 'use client'
207
+ import { createSignal } from '@barefootjs/client'
208
+ const Widget = () => {
209
+ function helper(n: number) { return n * 2 }
210
+ const [count, setCount] = createSignal(0)
211
+ return <button onClick={() => setCount(helper(count()))}>{count()}</button>
212
+ }
213
+ export default Widget
214
+ `)
215
+ expect(result.errors.filter(e => e.severity === 'error')).toEqual([])
216
+ expect(clientJs).toContain('helper')
217
+ })
218
+
219
+ describe('parity between the `const` arrow form and the `function` declaration form', () => {
220
+ test('sync block-bodied helper: neither form duplicates the inner statement', () => {
221
+ const arrowForm = compile(`
222
+ 'use client'
223
+ import { createSignal } from '@barefootjs/client'
224
+ const score = (title: string, term: string): number => {
225
+ const t = title.toLowerCase()
226
+ return t.includes(term) ? 1 : 0
227
+ }
228
+ export function Search() {
229
+ const [term, setTerm] = createSignal('')
230
+ return <div onClick={() => setTerm('x')}>{score('hello', term())}</div>
231
+ }
232
+ `)
233
+ const functionForm = compile(`
234
+ 'use client'
235
+ import { createSignal } from '@barefootjs/client'
236
+ function score(title: string, term: string): number {
237
+ const t = title.toLowerCase()
238
+ return t.includes(term) ? 1 : 0
239
+ }
240
+ export function Search() {
241
+ const [term, setTerm] = createSignal('')
242
+ return <div onClick={() => setTerm('x')}>{score('hello', term())}</div>
243
+ }
244
+ `)
245
+ expect(arrowForm.result.errors.filter(e => e.severity === 'error')).toEqual([])
246
+ expect(functionForm.result.errors.filter(e => e.severity === 'error')).toEqual([])
247
+ expect(countOccurrences(arrowForm.clientJs, 'const t = title.toLowerCase()')).toBe(1)
248
+ expect(countOccurrences(functionForm.clientJs, 'const t = title.toLowerCase()')).toBe(1)
249
+ })
250
+
251
+ test('async helper: neither form duplicates the inner await', () => {
252
+ const arrowForm = compile(`
253
+ 'use client'
254
+ import { createSignal, onMount } from '@barefootjs/client'
255
+ const loadData = async (): Promise<string[]> => {
256
+ const res = await fetch('/data.json')
257
+ return res.json()
258
+ }
259
+ function Widget() {
260
+ const [items, setItems] = createSignal<string[]>([])
261
+ onMount(() => { void loadData().then(setItems) })
262
+ return <div>{items().length}</div>
263
+ }
264
+ export default Widget
265
+ `)
266
+ const functionForm = compile(`
267
+ 'use client'
268
+ import { createSignal, onMount } from '@barefootjs/client'
269
+ async function loadData(): Promise<string[]> {
270
+ const res = await fetch('/data.json')
271
+ return res.json()
272
+ }
273
+ function Widget() {
274
+ const [items, setItems] = createSignal<string[]>([])
275
+ onMount(() => { void loadData().then(setItems) })
276
+ return <div>{items().length}</div>
277
+ }
278
+ export default Widget
279
+ `)
280
+ expect(arrowForm.result.errors.filter(e => e.severity === 'error')).toEqual([])
281
+ expect(functionForm.result.errors.filter(e => e.severity === 'error')).toEqual([])
282
+ expect(countOccurrences(arrowForm.clientJs, "await fetch('/data.json')")).toBe(1)
283
+ expect(countOccurrences(functionForm.clientJs, "await fetch('/data.json')")).toBe(1)
284
+ })
285
+ })
286
+ })
@@ -878,6 +878,43 @@ export function Ticker() {
878
878
  expect(clientJs!.content).toMatch(/import\s*\{[^}]*onMount[^}]*\}\s*from\s*'@barefootjs\/client\/runtime'/)
879
879
  })
880
880
 
881
+ // This is a COMPILE-TIME assertion only (the generated import list), not
882
+ // a runtime behavior test — `batch` around a single `setCount` call has
883
+ // no observable effect at runtime (batching only matters for coalescing
884
+ // MULTIPLE signal writes into one effect flush; see `batch`'s doc comment
885
+ // in `packages/client/src/reactive.ts`). It's used here purely as the
886
+ // smallest fixture that calls `batch` from a cross-file factory, to pin
887
+ // #2985: `batch` was missing from `RUNTIME_IMPORT_CANDIDATES`
888
+ // (`ir-to-client-js/imports.ts`), so it compiled clean but was silently
889
+ // dropped from the emitted `@barefootjs/client/runtime` import, throwing
890
+ // `ReferenceError: batch is not defined` at hydration.
891
+ test('M17b: batch is provisioned from usage for a cross-file factory (#2985)', () => {
892
+ writeFixture('matrix17b/useCounter.tsx', `'use client'
893
+ import { batch, createSignal } from '@barefootjs/client'
894
+
895
+ export function useCounter() {
896
+ const [count, setCount] = createSignal(0)
897
+ const increment = () => batch(() => setCount(count() + 1))
898
+ return { count, increment }
899
+ }
900
+ `)
901
+ const consumerSource = `'use client'
902
+ import { useCounter } from './useCounter'
903
+
904
+ export function Counter() {
905
+ const { count, increment } = useCounter()
906
+ return <button onClick={increment}>{count()}</button>
907
+ }
908
+ `
909
+ const consumerPath = writeFixture('matrix17b/Counter.tsx', consumerSource)
910
+
911
+ const result = compileJSX(consumerSource, consumerPath, { adapter })
912
+ expect(result.errors.filter(e => e.severity === 'error')).toHaveLength(0)
913
+ const clientJs = result.files.find(f => f.type === 'clientJs')
914
+ expect(clientJs).toBeDefined()
915
+ expect(clientJs!.content).toMatch(/import\s*\{[^}]*\bbatch\b[^}]*\}\s*from\s*'@barefootjs\/client\/runtime'/)
916
+ })
917
+
881
918
  test('M18: a type-only helper import does not trigger BF112 and is re-provisioned as `import type` (#2350)', () => {
882
919
  writeFixture('matrix18/todo-types.ts', `export interface Todo {
883
920
  id: number
@@ -641,6 +641,26 @@ describe('extractSsrDefaults', () => {
641
641
  expect(defaults?.label).toEqual({ propName: 'label', value: null })
642
642
  expect(defaults?.labelAlias).toBe(defaults?.label)
643
643
  })
644
+
645
+ // #2924 review follow-up (pullfrog nitpick on the PR fixing the setter
646
+ // case): the setter-symmetric shape of the #2813 getter-alias test above
647
+ // — a bare local-const alias of a signal SETTER must be seeded under its
648
+ // own name too, not just the setter's own name.
649
+ test('a bare local-const alias of a signal setter is seeded under the alias name too', () => {
650
+ const metadata = metadataFor(`
651
+ 'use client'
652
+ import { createSignal } from '@barefootjs/client'
653
+ function C() {
654
+ const [count, setCount] = createSignal(5)
655
+ const setCountAlias = setCount
656
+ return <button onClick={() => setCountAlias(6)}>{count()}</button>
657
+ }
658
+ `)
659
+
660
+ const defaults = extractSsrDefaults(metadata)
661
+ expect(defaults?.setCount).toEqual({ value: null })
662
+ expect(defaults?.setCountAlias).toEqual({ value: null })
663
+ })
644
664
  })
645
665
 
646
666
  // TS twin of the Ruby/Python/PHP/Perl/Rust `derive*FromDefaults` runtime
@@ -711,8 +731,10 @@ describe('deriveStashFromDefaults', () => {
711
731
  `)
712
732
  const defaults = extractSsrDefaults(metadata)!
713
733
 
714
- expect(deriveStashFromDefaults(defaults, { label: 'Hello' })).toEqual({ label: 'Hello' })
715
- expect(deriveStashFromDefaults(defaults, {})).toEqual({ label: null })
734
+ // `setLabel` also gets a stash entry (#2924's SSR-half fix) — every
735
+ // signal setter is seeded unconditionally, same as every getter.
736
+ expect(deriveStashFromDefaults(defaults, { label: 'Hello' })).toEqual({ label: 'Hello', setLabel: null })
737
+ expect(deriveStashFromDefaults(defaults, {})).toEqual({ label: null, setLabel: null })
716
738
  })
717
739
 
718
740
  test('propName-less entry (signal / memo local): always uses the static value', () => {
package/src/analyzer.ts CHANGED
@@ -386,6 +386,28 @@ function collectNamedExports(sourceFile: ts.SourceFile): Set<string> {
386
386
  // Single Pass Visitor
387
387
  // =============================================================================
388
388
 
389
+ /**
390
+ * Does this node open a new function scope?
391
+ *
392
+ * The single answer to the one question every declaration collector in
393
+ * this file asks: bindings declared inside a function belong to that
394
+ * function, never to the scope being collected. `visitComponentBody` has
395
+ * always stopped here; `visit` did not, so the inner `const`/`function`
396
+ * declarations of a module-level `const f = (…) => { … }` were collected
397
+ * as module-level declarations of the FILE — hoisted into the init body
398
+ * and into the marked template, where their references to the helper's
399
+ * own parameters are unbound (#2986).
400
+ */
401
+ function isFunctionScope(node: ts.Node): boolean {
402
+ return ts.isArrowFunction(node)
403
+ || ts.isFunctionExpression(node)
404
+ || ts.isFunctionDeclaration(node)
405
+ || ts.isMethodDeclaration(node)
406
+ || ts.isGetAccessorDeclaration(node)
407
+ || ts.isSetAccessorDeclaration(node)
408
+ || ts.isConstructorDeclaration(node)
409
+ }
410
+
389
411
  function visit(
390
412
  node: ts.Node,
391
413
  ctx: AnalyzerContext,
@@ -607,7 +629,23 @@ function visit(
607
629
  }
608
630
  }
609
631
 
610
- ts.forEachChild(node, (child) => visit(child, ctx, targetComponentName, namedExports))
632
+ ts.forEachChild(node, (child) => {
633
+ // Stop at a nested function scope (#2986). Two carve-outs at module level:
634
+ //
635
+ // • `function` declarations must still be VISITED, because the
636
+ // module-level branch above is what collects them — and it `return`s
637
+ // immediately afterwards, so the descent-stop is already encoded
638
+ // there. This walk is also the ONLY one that reaches a `function`
639
+ // declaration inside a component body (`visitComponentBody` skips
640
+ // them); `compute-scope`'s fixpoint then demotes it to init scope.
641
+ // Skipping them here silently produces zero-output components.
642
+ //
643
+ // • The target component's own arrow (`const App = () => { … }`):
644
+ // `analyzeComponentBody` handles its body, but `visit` must still
645
+ // descend to reach the `function` declarations inside it.
646
+ if (isFunctionScope(child) && !ts.isFunctionDeclaration(child) && child !== ctx.componentNode) return
647
+ visit(child, ctx, targetComponentName, namedExports)
648
+ })
611
649
  }
612
650
 
613
651
  // =============================================================================
@@ -846,17 +884,11 @@ function visitComponentBody(node: ts.Node, ctx: AnalyzerContext): void {
846
884
  ctx.jsxReturn = unwrapJsxTransparent(node.expression)
847
885
  }
848
886
 
849
- // Skip recursion into function bodies (arrow functions, function expressions, function declarations)
850
- // to avoid collecting inner local variables
887
+ // Skip recursion into a nested function scope — its bindings are
888
+ // function-scoped, not component init-scope declarations. Same predicate
889
+ // the module-level walk (`visit`) uses.
851
890
  ts.forEachChild(node, (child) => {
852
- // Don't recurse into function bodies - their variables are function-scoped
853
- if (
854
- ts.isArrowFunction(child) ||
855
- ts.isFunctionExpression(child) ||
856
- ts.isFunctionDeclaration(child)
857
- ) {
858
- return
859
- }
891
+ if (isFunctionScope(child)) return
860
892
  visitComponentBody(child, ctx)
861
893
  })
862
894
  }
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * - signal getter calls (`count()`) → `(initialValue)`
8
8
  * - memo getter calls (`bars()`) → `(computationBody)`
9
+ * - bare signal/memo getter refs (`count`) → `(() => (initialValue))`
9
10
  * - bare inlinable-const refs (`label`) → `(csrInlinable.rewrittenValue)`
10
11
  * - bare source-level props refs (`props.x`) → `_p.x`
11
12
  *
@@ -59,7 +60,25 @@ export type CsrInlinabilityMap = Map<string, CsrInlinableEntry | null>
59
60
  /**
60
61
  * A single substitution: when the source expression mentions `name`
61
62
  * (either bare or as a zero-arg call, depending on `kind`), the AST
62
- * walker splices `replacement` in place.
63
+ * walker splices a replacement in place.
64
+ *
65
+ * `kind` says what `replacement` IS, not just where it matches:
66
+ *
67
+ * - `'call'`: `replacement` is the VALUE the zero-arg accessor `name()`
68
+ * produces (a signal's initial value, a memo's computation body). The
69
+ * call site `name()` substitutes to `(replacement)` directly. A BARE
70
+ * reference to `name` (uncalled — e.g. a getter passed as a component
71
+ * prop, `<Display value={count} />`, #2924) substitutes to
72
+ * `(() => (replacement))` instead: a thunk over the same value, which
73
+ * is the CSR-template mirror of the reference adapter's SSR shim
74
+ * (`const count = () => 5`, `packages/adapter-hono`) — the only
75
+ * reading that lets a bare accessor evaluate identically on SSR and on
76
+ * CSR-fresh-mount. Registered only by `buildSignalMemoEnv` below.
77
+ * - `'identifier'`: `replacement` is already the value a BARE reference
78
+ * to `name` should read as (e.g. an inlinable const's resolved value);
79
+ * there is no corresponding call form. Substitutes to `(replacement)`
80
+ * at both a bare reference and the (non-existent, for this kind) call
81
+ * position.
63
82
  */
64
83
  export interface CsrSubstitution {
65
84
  kind: 'call' | 'identifier'
@@ -71,10 +90,11 @@ export interface CsrSubstitution {
71
90
 
72
91
  export interface CsrEnv {
73
92
  /**
74
- * Map of name → substitution. Call-kind entries match `name()`
75
- * (zero-arg call with bare-ident callee) and replace the entire
76
- * call expression; identifier-kind entries match bare uses of
77
- * `name` outside member-access tails.
93
+ * Map of name → substitution. Call-kind entries match both `name()`
94
+ * (zero-arg call with bare-ident callee — replaced with the accessor's
95
+ * value) and bare uses of `name` (replaced with a thunk over that same
96
+ * value, #2924); identifier-kind entries match bare uses of `name`
97
+ * outside member-access tails.
78
98
  */
79
99
  substitutions: Map<string, CsrSubstitution>
80
100
  /** Source-level props object name (`props`); null for destructured-args. */
@@ -181,6 +201,13 @@ function csrSubstituteOnce(
181
201
  splices.push({ start: start - OFFSET, end: end - OFFSET, text: `(${sub.replacement})` })
182
202
  }
183
203
 
204
+ // Text spliced in for a BARE (uncalled) reference to `sub`'s name — see
205
+ // `CsrSubstitution`'s docstring for why `call`-kind entries need a
206
+ // thunk here instead of the raw value substituted at the call site
207
+ // (#2924).
208
+ const bareReplacementText = (sub: CsrSubstitution): string =>
209
+ sub.kind === 'call' ? `(() => (${sub.replacement}))` : `(${sub.replacement})`
210
+
184
211
  const collectBindingNames = (name: ts.BindingName, out: Set<string>): void => {
185
212
  if (ts.isIdentifier(name)) out.add(name.text)
186
213
  else if (ts.isObjectBindingPattern(name)) {
@@ -243,18 +270,21 @@ function csrSubstituteOnce(
243
270
  }
244
271
 
245
272
  // Shorthand property: `{ X }` — `X` IS both a key and a value
246
- // reference. Treat the value side as a free ref.
273
+ // reference. Treat the value side as a free ref. `X` is necessarily a
274
+ // BARE reference here (there's no call-syntax shorthand), so a
275
+ // `call`-kind entry needs the thunk form too (#2924) — same as the
276
+ // bare-identifier branch below.
247
277
  if (ts.isShorthandPropertyAssignment(node)) {
248
278
  if (ts.isIdentifier(node.name) && !isBound(node.name.text)) {
249
279
  const sub = env.substitutions.get(node.name.text)
250
- if (sub && sub.kind === 'identifier') {
280
+ if (sub) {
251
281
  // The shorthand expands to a key-value pair when we substitute,
252
282
  // so emit `name: (replacement)` to keep the object literal
253
283
  // grammatical. Position spans the whole shorthand.
254
284
  splices.push({
255
285
  start: node.getStart(sourceFile) - OFFSET,
256
286
  end: node.getEnd() - OFFSET,
257
- text: `${node.name.text}: (${sub.replacement})`,
287
+ text: `${node.name.text}: ${bareReplacementText(sub)}`,
258
288
  })
259
289
  }
260
290
  }
@@ -295,12 +325,18 @@ function csrSubstituteOnce(
295
325
  return
296
326
  }
297
327
 
298
- // Bare identifier reference.
328
+ // Bare identifier reference. A `call`-kind entry (a signal/memo
329
+ // getter) substitutes to a thunk over its value here, not the value
330
+ // itself — the bare form is the accessor, not a read of it (#2924).
299
331
  if (ts.isIdentifier(node)) {
300
332
  if (isBound(node.text)) return
301
333
  const sub = env.substitutions.get(node.text)
302
- if (sub && sub.kind === 'identifier') {
303
- recordSubstitution(node.getStart(sourceFile), node.getEnd(), sub)
334
+ if (sub) {
335
+ splices.push({
336
+ start: node.getStart(sourceFile) - OFFSET,
337
+ end: node.getEnd() - OFFSET,
338
+ text: bareReplacementText(sub),
339
+ })
304
340
  }
305
341
  return
306
342
  }
@@ -553,6 +589,20 @@ export function buildSignalMemoEnv(
553
589
  replacement: normalizeSignalInitial(s, propsObjectName),
554
590
  freeIdentifiers: s.initialFreeIdentifiers ?? new Set(),
555
591
  })
592
+ // A bare reference to the SETTER (`<Display update={setCount} />`,
593
+ // any non-`on*`-prefixed prop name — #2924's setter-symmetric case)
594
+ // hits the identical template-scope gap as a bare getter reference:
595
+ // `setCount` only exists as a real closure inside `initCounter`. The
596
+ // reference (Hono) adapter's own SSR shim answers this the same way
597
+ // it answers a bare getter — a module-scope noop (`const setCount =
598
+ // () => {}`) — so an `identifier`-kind entry (not `call`: a setter is
599
+ // never itself CALLED as a zero-arg form the way a getter is) mirrors
600
+ // that shim directly, with no thunk-wrapping needed. `s.setter` is
601
+ // null for the setter-elided declaration form (`const [count] =
602
+ // createSignal(...)`), which has no name to register.
603
+ if (s.setter) {
604
+ substitutions.set(s.setter, { kind: 'identifier', replacement: '() => {}', freeIdentifiers: new Set() })
605
+ }
556
606
  }
557
607
  for (const m of memos) {
558
608
  substitutions.set(m.name, {
@@ -11,6 +11,11 @@ import { identifierCallPattern } from '../identifier-pattern.ts'
11
11
  // All exports from @barefootjs/client/runtime that may be used in generated code
12
12
  export const RUNTIME_IMPORT_CANDIDATES = [
13
13
  'createSignal', 'createMemo', 'createEffect', 'onCleanup', 'onMount',
14
+ // Coalesces multiple signal writes into one flush (#2985) — omitted here
15
+ // previously even though it's a real `@barefootjs/client` export, so a
16
+ // cross-file reactive factory that called it compiled clean but left
17
+ // `batch` unimported in the generated client bundle.
18
+ 'batch',
14
19
  'hydrate', 'insert', 'getLoopChildren', 'getLoopNodes', 'mapArray', 'mapArrayAnchored', 'mapArrayLazy', 'patchLeaf', 'createDisposableEffect',
15
20
  // Resolves the real DOM container for a loop nested inside a loop-row
16
21
  // conditional's branch when the conditional's wrapper element carries no
@@ -298,6 +298,23 @@ export function extractSsrDefaults(metadata: IRMetadata): Record<string, SsrDefa
298
298
  // through the chain exactly as before; only the manifest's own seed
299
299
  // choice changes, not the static-eval semantics.
300
300
  bindings[sig.getter] = value
301
+
302
+ // #2924 (SSR half): a bare reference to the SETTER (`<Display
303
+ // update={setCount} />`) can reach a template-stash adapter's own
304
+ // rendered template text the same way a bare getter reference does
305
+ // (`bf->render_child('display', update => $setCount, ...)`) — Mojo's
306
+ // `Mojo::Template->new(vars => 1)` only declares `my $x` for stash
307
+ // keys it's actually given, so an unseeded setter aborts the render
308
+ // with Perl's strict-mode "Global symbol requires explicit package
309
+ // name". Mirrors Hono's own unconditional SSR shim for every signal's
310
+ // setter (`const setCount: (...) => void = () => {}`, emitted next to
311
+ // the getter's `const count = () => 5` regardless of where either is
312
+ // referenced) — seeded here the same unconditional way, since the
313
+ // value is never read or invoked during SSR (only forwarded through
314
+ // `render_child`), just needs to EXIST in the stash.
315
+ if (sig.setter && !(sig.setter in out)) {
316
+ out[sig.setter] = { value: null }
317
+ }
301
318
  }
302
319
 
303
320
  for (const memo of metadata.memos) {
@@ -330,8 +347,23 @@ export function extractSsrDefaults(metadata: IRMetadata): Record<string, SsrDefa
330
347
  // pointing at one value. Env-signal getters are excluded from the
331
348
  // getter-name set (they're never given an `out` entry above — an
332
349
  // adapter's own env-signal binding seeds them instead).
350
+ //
351
+ // #2924 review follow-up: a local-const alias of a signal SETTER
352
+ // (`const alias = setCount`) needs the identical treatment — the setter
353
+ // loop above now seeds `out[sig.setter]` unconditionally, but
354
+ // `collectAliasableGetterNames` only ever returns GETTER/memo names
355
+ // (it's also the Go adapter's own `rootFieldRef` eligibility set, which
356
+ // has no notion of a setter alias, so widening it there would be the
357
+ // wrong fix). Union in the setter names locally instead, mirroring how
358
+ // the CSR side's own `substitutions.has(n)` predicate already covers
359
+ // both without any special-casing (`csr-substitute.ts`'s
360
+ // `buildSignalMemoEnv`, since this PR's setter entries land in the same
361
+ // `substitutions` map as getters).
333
362
  {
334
363
  const getterNames = collectAliasableGetterNames(metadata.signals, metadata.memos)
364
+ for (const sig of metadata.signals) {
365
+ if (sig.setter && !sig.isModule && !sig.envReader) getterNames.add(sig.setter)
366
+ }
335
367
  for (const [alias, origin] of resolveGetterAliases(metadata.localConstants ?? [], (n) => getterNames.has(n))) {
336
368
  if (alias in out) continue
337
369
  out[alias] = out[origin]