@barefootjs/jsx 0.39.0 → 0.39.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.
Files changed (47) hide show
  1. package/dist/adapters/interface.d.ts +19 -0
  2. package/dist/adapters/interface.d.ts.map +1 -1
  3. package/dist/adapters/jsx-adapter.d.ts.map +1 -1
  4. package/dist/analyzer.d.ts +19 -0
  5. package/dist/analyzer.d.ts.map +1 -1
  6. package/dist/compiler.d.ts.map +1 -1
  7. package/dist/debug.d.ts.map +1 -1
  8. package/dist/html-types.d.ts +5 -0
  9. package/dist/html-types.d.ts.map +1 -1
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +195 -68
  13. package/dist/ir-to-client-js/collect-elements.d.ts +17 -1
  14. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  15. package/dist/ir-to-client-js/reactivity.d.ts +10 -2
  16. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  17. package/dist/ir-to-client-js/utils.d.ts +11 -7
  18. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  19. package/dist/ssr-defaults.d.ts.map +1 -1
  20. package/dist/ssr-seed-plan.d.ts.map +1 -1
  21. package/dist/types.d.ts +44 -0
  22. package/dist/types.d.ts.map +1 -1
  23. package/package.json +2 -2
  24. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +4 -4
  25. package/src/__tests__/adapter-output.test.ts +142 -0
  26. package/src/__tests__/create-mutation.test.ts +30 -0
  27. package/src/__tests__/create-query.test.ts +52 -0
  28. package/src/__tests__/debug.test.ts +83 -0
  29. package/src/__tests__/ir-fragment-transparency.test.ts +23 -0
  30. package/src/__tests__/issue-3240-nested-static-map-event-delegation.test.ts +245 -0
  31. package/src/__tests__/jsx-text-linebreak-whitespace.test.ts +80 -0
  32. package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +445 -0
  33. package/src/adapters/interface.ts +19 -0
  34. package/src/adapters/jsx-adapter.ts +30 -20
  35. package/src/analyzer.ts +35 -11
  36. package/src/compiler.ts +78 -46
  37. package/src/debug.ts +34 -2
  38. package/src/html-types.ts +14 -0
  39. package/src/index.ts +1 -0
  40. package/src/ir-to-client-js/collect-elements.ts +64 -4
  41. package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +112 -3
  42. package/src/ir-to-client-js/reactivity.ts +31 -1
  43. package/src/ir-to-client-js/utils.ts +130 -15
  44. package/src/jsx-to-ir.ts +75 -12
  45. package/src/ssr-defaults.ts +10 -0
  46. package/src/ssr-seed-plan.ts +12 -1
  47. package/src/types.ts +47 -0
@@ -6,6 +6,7 @@
6
6
  import ts from 'typescript'
7
7
  import type { AttrValue, IRTemplatePart, LoopParamBinding, FreeReference, IRNode, IRFragment, ComponentIR } from '../types.ts'
8
8
  import type { TopLevelLoop, BranchLoop, LoopOffset } from './types.ts'
9
+ import { isNonReferenceIdentifierPosition } from '../analyzer.ts'
9
10
  import { buildLoopChainExpr } from '../loop-chain.ts'
10
11
  import { templatePartsToJsExpr } from '../template-parts.ts'
11
12
  import { escapeIdentifierForRegex, ID_BOUNDARY_BEFORE, ID_BOUNDARY_AFTER } from '../identifier-pattern.ts'
@@ -683,9 +684,12 @@ function renderLoopBindingAccess(b: LoopParamBinding, base: string): string {
683
684
  * e.g., "item.text" → "item().text", "item" → "item()"
684
685
  * Does not double-wrap: "item().text" stays "item().text"
685
686
  *
686
- * String-context aware: skips replacements inside string literals and template
687
- * literal string parts (e.g., CSS class name "preview-field" stays unchanged
688
- * when paramName is "field"). Handles arbitrarily nested template literals.
687
+ * The plain-param branch (`rewriteIdentifierAsAccessor`) walks the real AST,
688
+ * so it is inherently string/template-literal-context aware (a CSS class
689
+ * name like "preview-field" never surfaces as an `Identifier` node when
690
+ * `paramName` is "field") AND skips object-literal keys, shorthand
691
+ * properties, and member/property names — tokens that spell `paramName`
692
+ * without referencing it (#3239).
689
693
  *
690
694
  * When `bindings` is supplied (destructured `.map()` callback, #951), each
691
695
  * binding name is rewritten to `__bfItem()${path}` instead of wrapping the
@@ -717,12 +721,7 @@ export function wrapLoopParamAsAccessor(
717
721
  if (bindings && bindings.length > 0) {
718
722
  result = rewriteLoopBindingRefs(expr, bindings, '__bfItem()')
719
723
  } else {
720
- // `paramName` is a legal JS identifier and may itself start with `$`
721
- // (`$1`, `$&`, …) — a plain string replacement would risk `String.replace`
722
- // reading those as backreference/whole-match sequences, so use a replacer
723
- // function to insert the accessor text literally (#2592).
724
- const re = new RegExp(`${ID_BOUNDARY_BEFORE}${escapeIdentifierForRegex(paramName)}(?!\\s*\\()(?!-)${ID_BOUNDARY_AFTER}`, 'gu')
725
- result = replaceInExprContexts(expr, re, () => `${paramName}()`)
724
+ result = rewriteIdentifierAsAccessor(expr, paramName)
726
725
  }
727
726
  if (indexParam && indexParam !== paramName) {
728
727
  result = wrapIndexParamAsAccessor(result, indexParam)
@@ -731,10 +730,11 @@ export function wrapLoopParamAsAccessor(
731
730
  }
732
731
 
733
732
  /**
734
- * The index-only half of `wrapLoopParamAsAccessor` — same regex shape, own
735
- * identifier. Factored out so `wrapLoopParamAsAccessor` can run it as a
736
- * second pass regardless of which item-rewrite branch (bindings vs. plain
737
- * param) ran first (#2859).
733
+ * The index-only half of `wrapLoopParamAsAccessor` — same AST-aware
734
+ * identifier rewrite (`rewriteIdentifierAsAccessor`), own identifier.
735
+ * Factored out so `wrapLoopParamAsAccessor` can run it as a second pass
736
+ * regardless of which item-rewrite branch (bindings vs. plain param) ran
737
+ * first (#2859).
738
738
  *
739
739
  * Also exported standalone for `build-loop.ts`/`build-branch-loop.ts`: a
740
740
  * plain loop's `template`/`mapPreambleWrapped` are built ONCE, before lazy
@@ -746,8 +746,123 @@ export function wrapLoopParamAsAccessor(
746
746
  * is NOT going lazy.
747
747
  */
748
748
  export function wrapIndexParamAsAccessor(expr: string, indexParam: string): string {
749
- const re = new RegExp(`${ID_BOUNDARY_BEFORE}${escapeIdentifierForRegex(indexParam)}(?!\\s*\\()(?!-)${ID_BOUNDARY_AFTER}`, 'gu')
750
- return replaceInExprContexts(expr, re, () => `${indexParam}()`)
749
+ return rewriteIdentifierAsAccessor(expr, indexParam)
750
+ }
751
+
752
+ /**
753
+ * AST-aware engine behind `wrapLoopParamAsAccessor`'s plain-param branch and
754
+ * `wrapIndexParamAsAccessor`: rewrite every genuine value reference to
755
+ * `name` in `expr` into `${name}()`, while leaving alone every token that
756
+ * merely SPELLS `name` without referencing it — an object-literal key
757
+ * (`{ name: 1 }`), a shorthand property (`{ name }`, expanded to
758
+ * `{ name: name() }` in one edit — the same transformation #1244 gave the
759
+ * destructured-binding path via `expandShorthandBindings`), and a
760
+ * member/property name (`obj.name`, `obj?.name`).
761
+ *
762
+ * The previous implementation was a `\bname\b`-style regex
763
+ * (`ID_BOUNDARY_BEFORE`/`AFTER` only know about identifier-character
764
+ * boundaries, not JS grammar), so it matched those non-reference tokens too:
765
+ * a key or shorthand rewrite produces invalid JS (`{ name(): 1 }`,
766
+ * `{ name() }`) that fails at parse time; a member-name rewrite produces
767
+ * valid-but-wrong JS (`obj.name()`) that throws `TypeError: obj.name is not
768
+ * a function` at row-creation time (#3239). Parsing the real AST — the same
769
+ * technique `expandShorthandBindings` already uses below — makes each of
770
+ * those positions a type of AST node this function can name and skip,
771
+ * instead of a regex guessing from surrounding characters.
772
+ *
773
+ * A nested declaration that re-binds `name` (a parameter, a `const`/`let`,
774
+ * or a destructured local) is deliberately NOT skipped, unlike
775
+ * `analyzer.ts`'s rename `classify()`: this rewrite has no scope tracking,
776
+ * so it cannot tell a reference to the shadowing local from a reference to
777
+ * the outer loop param past that point, and silently wrapping only the
778
+ * OUTER-scope references while leaving the shadowed ones alone (or vice
779
+ * versa) would just move the #3239 bug rather than fix it. Wrapping the
780
+ * shadowing declaration's own name is always a syntax break at the
781
+ * declaration site itself (`const name = 1` → `const name() = 1`, `(name)
782
+ * => …` → `(name()) => …` — a call can't legally appear where a binding
783
+ * name is expected), so the module fails to parse instead of silently
784
+ * running with the wrong value — the same loud, build-time failure the old
785
+ * regex produced for this shape (it had no shadow-awareness either).
786
+ *
787
+ * A NAMED function expression is the one shadowing shape this function
788
+ * skips wholesale rather than leaving loud: `(function name() { ... })`'s
789
+ * own name is scoped to exactly that expression's body and nowhere else, so
790
+ * `visit` never descends into it at all once it sees the self-shadowing
791
+ * name — no reference inside can possibly mean the outer `name`. A
792
+ * `function`/`class` DECLARATION's name is different: its binding reaches
793
+ * into the surrounding scope too (a function declaration's name is hoisted
794
+ * above it; a class declaration's own static/instance members can
795
+ * self-reference it), so the same whole-subtree skip isn't sound here —
796
+ * a self-reference to a `function`/`class` declaration whose name happens
797
+ * to match `name` is still silently misrewritten, an accepted
798
+ * pre-existing-shaped gap the old regex had too (the "followed by `(`"
799
+ * exclusion below only protects the declaration's OWN name token, not
800
+ * references reachable from within or after it).
801
+ */
802
+ function rewriteIdentifierAsAccessor(expr: string, name: string): string {
803
+ // Fast path: `name` doesn't occur in the text at all → nothing to rewrite.
804
+ // A cheap substring check only ever causes an unnecessary parse below
805
+ // (e.g. `name` occurs only as part of a longer identifier), never a wrong
806
+ // answer, since the AST walk re-checks the exact identifier text.
807
+ if (!expr.includes(name)) return expr
808
+
809
+ const wrapped = `(${expr})`
810
+ const sf = ts.createSourceFile('__bf_expr.ts', wrapped, ts.ScriptTarget.Latest, /* setParentNodes */ true)
811
+ const edits: Array<{ start: number; end: number; replacement: string }> = []
812
+
813
+ const visit = (node: ts.Node): void => {
814
+ // A named function expression's own name is scoped to exactly its own
815
+ // body, so nothing reachable inside it can refer to the outer `name` —
816
+ // skip the whole subtree instead of only its declaration-name
817
+ // identifier (see this function's docstring for why a `function`/
818
+ // `class` DECLARATION can't get the same treatment this cheaply).
819
+ if (ts.isFunctionExpression(node) && node.name?.text === name) return
820
+
821
+ if (ts.isIdentifier(node) && node.text === name) {
822
+ const p = node.parent
823
+ // Pure-key / non-reference positions — never rewrite. Shared with
824
+ // `analyzer.ts`'s factory-rename `classify()`, which answers the same
825
+ // "is this identifier actually a value reference" question.
826
+ if (isNonReferenceIdentifierPosition(node)) return
827
+ // A function declaration's own name is always followed by `(` in
828
+ // valid source, which is exactly the shape the old
829
+ // `\bname\b(?!\s*\()`-style regex used to recognize and skip. Leaving
830
+ // it unwrapped (rather than declining loudly, as the shadowing
831
+ // declarations below do) matches the old behavior instead of
832
+ // regressing code that used to compile. A `class name {}`
833
+ // declaration's name is followed by `{`/`extends`, not `(`, so the
834
+ // old regex did NOT protect it either — wrapping it is a pre-existing
835
+ // syntax break, not a regression, so it's left to the shadowing-decl
836
+ // path below like any other declaration name.
837
+ if (ts.isFunctionDeclaration(p) && p.name === node) return
838
+ if (ts.isCallExpression(p) && p.expression === node) return // already `name()` — no double-wrap (#2592)
839
+ if (ts.isNewExpression(p) && p.expression === node) return // `new name()` — same "followed by (" shape as a call
840
+
841
+ // Shorthand property (`{ name }`) expands key + wraps value in one
842
+ // edit — the plain-param analogue of `expandShorthandBindings` below.
843
+ // Every other reachable position here is a genuine value reference —
844
+ // OR a shadowing declaration name (nested parameter/`const`/`let`/
845
+ // destructured local): both get wrapped, per this function's
846
+ // docstring on why a shadow is left to fail loudly rather than
847
+ // silently misrewritten.
848
+ const isShorthand = ts.isShorthandPropertyAssignment(p) && p.name === node
849
+ const start = node.getStart(sf) - 1
850
+ const end = node.getEnd() - 1
851
+ edits.push({ start, end, replacement: isShorthand ? `${name}: ${name}()` : `${name}()` })
852
+ return
853
+ }
854
+ ts.forEachChild(node, visit)
855
+ }
856
+ visit(sf)
857
+
858
+ if (edits.length === 0) return expr
859
+ // Apply right-to-left so earlier offsets stay valid as later ones grow.
860
+ edits.sort((a, b) => b.start - a.start)
861
+ let out = expr
862
+ for (const e of edits) {
863
+ out = out.slice(0, e.start) + e.replacement + out.slice(e.end)
864
+ }
865
+ return out
751
866
  }
752
867
 
753
868
  /**
package/src/jsx-to-ir.ts CHANGED
@@ -2207,7 +2207,7 @@ function isTransparentFragment(
2207
2207
  // Filter out whitespace-only text nodes
2208
2208
  const children = node.children.filter(child => {
2209
2209
  if (ts.isJsxText(child)) {
2210
- return child.text.trim() !== ''
2210
+ return cleanJsxWhitespace(child.text) !== ''
2211
2211
  }
2212
2212
  return true
2213
2213
  })
@@ -2375,11 +2375,15 @@ function transformChildren(
2375
2375
 
2376
2376
  const transformed = transformNode(child, ctx)
2377
2377
  if (transformed) {
2378
- // Skip empty text nodes
2379
- if (transformed.type === 'text' && transformed.value.trim() === '') {
2380
- continue
2381
- }
2382
-
2378
+ // `transformText` (the only producer of `type: 'text'` reached from
2379
+ // here — a `JsxText` child) already returns `null` for a node the
2380
+ // JSX whitespace rule says renders nothing, and keeps a node whose
2381
+ // cleaned value is a meaningful single space (`<b>a</b> <i>b</i>`,
2382
+ // #3237). Re-checking `.value.trim() === ''` here duplicated that
2383
+ // decision with a looser rule that silently discarded exactly that
2384
+ // meaningful space — the "one decision, two implementations"
2385
+ // pattern CLAUDE.md's Reference Adapter section calls out. Trust
2386
+ // the single source of truth instead of re-deciding here.
2383
2387
  result.push(transformed)
2384
2388
  }
2385
2389
  }
@@ -2427,10 +2431,25 @@ function isRenderNothingLiteral(expr: ts.Expression, ctx: TransformContext): boo
2427
2431
  }
2428
2432
 
2429
2433
  function transformText(node: ts.JsxText, ctx: TransformContext): IRText | null {
2430
- // Normalize whitespace (React-like behavior)
2431
- const text = node.text.replace(/\s+/g, ' ')
2432
-
2433
- if (text.trim() === '') {
2434
+ // Normalize whitespace the way JSX itself does (TypeScript/Babel/React
2435
+ // agree): a text node is split on line breaks, and only whitespace that
2436
+ // sits at a line break — the leading run of a non-first line, the
2437
+ // trailing run of a non-last line — is trimmed away; empty lines are
2438
+ // dropped and the rest are rejoined with a single space. Whitespace
2439
+ // that does NOT straddle a line break (interior runs on one line, or
2440
+ // the entirety of a single-line text node) is left exactly as written.
2441
+ // A naive `\s+` collapse over the whole node (the previous behavior)
2442
+ // over-trims: `<div>\n Light\n</div>` compiled to `" Light "` instead
2443
+ // of `"Light"` (#3237).
2444
+ const text = cleanJsxWhitespace(node.text)
2445
+
2446
+ // Empty STRING, not empty-after-trim: a single-line text node made
2447
+ // entirely of whitespace (no line break) is a meaningful single space
2448
+ // in JSX — `<b>a</b> <i>b</i>` — and `cleanJsxWhitespace` already
2449
+ // reduces a multi-line, indentation-only node (no line break survives
2450
+ // the per-line trim) to `''`. Checking `.trim() === ''` here would
2451
+ // discard that meaningful single space too.
2452
+ if (text === '') {
2434
2453
  return null
2435
2454
  }
2436
2455
 
@@ -2446,6 +2465,38 @@ function transformText(node: ts.JsxText, ctx: TransformContext): IRText | null {
2446
2465
  }
2447
2466
  }
2448
2467
 
2468
+ /**
2469
+ * JSX's whitespace-cleanup rule for a text child, as TypeScript, Babel and
2470
+ * React all implement it (see e.g. Babel's `cleanJSXElementLiteralChild`):
2471
+ *
2472
+ * - Split the raw text on line breaks.
2473
+ * - A tab is treated as a space.
2474
+ * - On every line except the first, strip the leading run of spaces
2475
+ * (it is indentation introduced by the line break, not authored text).
2476
+ * - On every line except the last, strip the trailing run of spaces
2477
+ * (same reasoning, from the other side).
2478
+ * - Drop lines that are empty after that trim.
2479
+ * - Join what's left with a single space.
2480
+ *
2481
+ * A single-line text node (no line break at all) is both "first" and
2482
+ * "last", so neither trim applies and the text passes through untouched —
2483
+ * `<b>a</b> <i>b</i>`'s single-space text node, or `const x = 1; ` inside
2484
+ * a `<pre>`, keep their interior whitespace exactly as written.
2485
+ */
2486
+ function cleanJsxWhitespace(raw: string): string {
2487
+ const lines = raw.split(/\r\n|\n|\r/)
2488
+ const kept: string[] = []
2489
+ for (let i = 0; i < lines.length; i++) {
2490
+ const isFirstLine = i === 0
2491
+ const isLastLine = i === lines.length - 1
2492
+ let line = lines[i].replace(/\t/g, ' ')
2493
+ if (!isFirstLine) line = line.replace(/^ +/, '')
2494
+ if (!isLastLine) line = line.replace(/ +$/, '')
2495
+ if (line !== '') kept.push(line)
2496
+ }
2497
+ return kept.join(' ')
2498
+ }
2499
+
2449
2500
  // =============================================================================
2450
2501
  // Expression Transformation
2451
2502
  // =============================================================================
@@ -6525,6 +6576,7 @@ function expandSpreadAttribute(
6525
6576
  value: AttrValue
6526
6577
  loc: SourceLocation
6527
6578
  freeIdentifiers?: ReadonlySet<string>
6579
+ restExpandedKey?: boolean
6528
6580
  }> {
6529
6581
  const spreadExpr = ctx.getJS(attr.expression)
6530
6582
  const expandedKeys = ctx.analyzer.restPropsExpandedKeys
@@ -6535,13 +6587,17 @@ function expandSpreadAttribute(
6535
6587
  if (expandedKeys.length > 0 && restName && spreadExpr === restName) {
6536
6588
  // Expanded per-key attrs reference `${restName}.${key}` — `restName` is
6537
6589
  // the only free identifier (the `.${key}` tail is a member-access name,
6538
- // not an identifier reference).
6590
+ // not an identifier reference). `restExpandedKey` (#3057) marks these so
6591
+ // Phase 2 (`collectElements`) can bind them reactively off a live
6592
+ // `_p.<key>` read instead of the one-time `${restName}.${key}` snapshot
6593
+ // — see `IRAttribute.restExpandedKey`'s docstring.
6539
6594
  const perKeyFreeIds: ReadonlySet<string> = new Set([restName])
6540
6595
  return expandedKeys.map(key => ({
6541
6596
  name: key,
6542
6597
  value: AttrValueOf.expression(`${restName}.${key}`),
6543
6598
  loc,
6544
6599
  freeIdentifiers: perKeyFreeIds,
6600
+ restExpandedKey: true,
6545
6601
  }))
6546
6602
  }
6547
6603
 
@@ -8281,7 +8337,14 @@ function processComponentProps(
8281
8337
 
8282
8338
  for (const attr of attributes.properties) {
8283
8339
  if (ts.isJsxSpreadAttribute(attr)) {
8284
- props.push(...expandSpreadAttribute(attr, ctx))
8340
+ // `restExpandedKey` (#3057) is consumed only by the element-attribute
8341
+ // path (`collect-elements.ts`'s `attr.restExpandedKey` branch) — a
8342
+ // component-prop forwarded via `{...rest}` already gets a live
8343
+ // `_p.<key>` read through `buildComponentPropsExpr`'s own rest
8344
+ // rewrite, so `IRProp` declares no such field. Strip it here rather
8345
+ // than letting the shared helper's per-key marking leak into IRProp
8346
+ // as an inert flag nothing reads.
8347
+ props.push(...expandSpreadAttribute(attr, ctx).map(({ restExpandedKey: _restExpandedKey, ...prop }) => prop))
8285
8348
  continue
8286
8349
  }
8287
8350
 
@@ -34,6 +34,7 @@ import { extractFreeIdentifiersFromNode } from './analyzer.ts'
34
34
  import { resolveGetterAliases, collectAliasableGetterNames } from './ir-to-client-js/csr-substitute.ts'
35
35
  import { resolveBodyDestructuredPropAliases } from './props-binding.ts'
36
36
  import type { IRMetadata } from './types.ts'
37
+ import { isElidedFactoryGetter } from './types.ts'
37
38
 
38
39
  /**
39
40
  * A single template-variable default. Keyed in the manifest by the
@@ -247,6 +248,15 @@ export function extractSsrDefaults(metadata: IRMetadata): Record<string, SsrDefa
247
248
  // request-scoped reader, seeded by the adapter's env-signal binding, not a
248
249
  // baked initial value.
249
250
  if (sig.envReader) continue
251
+ // An elided async-factory value (#3245): `getter` holds a synthesized
252
+ // internal name that no expression in the source ever references.
253
+ // Seeding it here would leak that compiler-internal name into every
254
+ // template-stash backend's manifest (and, transitively, the Perl/etc.
255
+ // stash) for a binding nothing reads. See `isElidedFactoryGetter`'s
256
+ // docstring for the full rationale — a plain `createSignal`
257
+ // getter-elided form is unaffected, a pre-existing, separate question
258
+ // this issue doesn't cover.
259
+ if (isElidedFactoryGetter(sig)) continue
250
260
  const value = tryStaticEval(sig.initialValue, { bindings, propsLike })
251
261
  // Self-derivation collision (#2669): a signal whose getter shares its
252
262
  // name with the prop its OWN initializer derives from
@@ -41,6 +41,7 @@ import {
41
41
  type ParsedExpr,
42
42
  } from './expression-parser.ts'
43
43
  import type { IRMetadata } from './types.ts'
44
+ import { isElidedFactoryGetter } from './types.ts'
44
45
 
45
46
  /**
46
47
  * One binding in component declaration order (signals first, then memos —
@@ -197,7 +198,17 @@ export function computeSsrSeedPlan(metadata: IRMetadata): SsrSeedPlan {
197
198
  }
198
199
  const expr = signal.initialValue.trim()
199
200
  steps.push(
200
- expr === ''
201
+ // An elided async-factory value (#3245): `signal.getter` is a
202
+ // synthesized internal name nothing in the source ever references
203
+ // (see `isElidedFactoryGetter`'s docstring). Forced `opaque` (never
204
+ // `derived`) so an adapter that seeds `derived` steps in-template
205
+ // (Jinja/Erb/Pebble's `generateDerivedMemoSeed`) can't emit a
206
+ // `{% set __bfGet_x = ... %}` for it — the invariant "one step per
207
+ // signal" still holds (the name stays out of every backend's
208
+ // rendered output; only ITS OWN classify outcome is overridden, not
209
+ // the name's presence in `steps`/`available` for other signals'
210
+ // scope checks).
211
+ expr === '' || isElidedFactoryGetter(signal)
201
212
  ? { kind: 'opaque', name: signal.getter, origin: 'signal' }
202
213
  : classify(
203
214
  signal.getter,
package/src/types.ts CHANGED
@@ -1515,6 +1515,29 @@ export interface IRAttribute extends AttrMeta {
1515
1515
  * same opt-out, applied to element-attribute position.
1516
1516
  */
1517
1517
  clientOnly?: boolean
1518
+ /**
1519
+ * Set when this attribute entry was produced by statically expanding a
1520
+ * closed-type `{...rest}` spread onto one of its known keys
1521
+ * (`expandSpreadAttribute`'s per-key branch, jsx-to-ir.ts) — #3057. The
1522
+ * expanded value (`<restName>.<key>`) reads the destructured rest
1523
+ * OBJECT, a one-time snapshot built at component-init time, so Phase 2's
1524
+ * string-level reactivity heuristics (`needsEffectWrapper`) never
1525
+ * recognize it as reading a live prop the way a bare destructured
1526
+ * parameter does — `rest` isn't itself a tracked prop name, and neither
1527
+ * is the expanded key. Without this flag the attribute is silently
1528
+ * treated as static: it renders once from SSR/the initial client
1529
+ * construction and never updates again, even though the value the child
1530
+ * forwards is exactly as live as any other prop.
1531
+ *
1532
+ * `collectElements` reads this to unconditionally push the attribute
1533
+ * into `ctx.reactiveAttrs`, rewriting its expression onto a live
1534
+ * `_p.<key>` read instead of the snapshot `<restName>.<key>` — the same
1535
+ * write shape `emitAttrUpdate` already produces for a developer-authored
1536
+ * reactive attribute, so a forwarded rest key updates reactively end to
1537
+ * end (undefined → present, present → absent → present again) exactly
1538
+ * like SSR / hydrated / csr-mount agree it should.
1539
+ */
1540
+ restExpandedKey?: boolean
1518
1541
  }
1519
1542
 
1520
1543
  export interface IREvent {
@@ -1649,6 +1672,30 @@ export interface SignalInfo {
1649
1672
  factory?: SignalFactoryCall
1650
1673
  }
1651
1674
 
1675
+ /**
1676
+ * True for the value-elided form of an async reactive factory declaration
1677
+ * (`const [, save] = createMutation(...)`, #3245): `signal.getter` then
1678
+ * holds the synthesized internal name (`__bfGet_<action>`, see
1679
+ * `SignalInfo.getterElided`'s docstring) that nothing in the source ever
1680
+ * references. Every consumer that would otherwise re-emit or seed that name
1681
+ * into caller-facing output (an SSR getter stub, a props struct/constructor
1682
+ * field, an SSR-defaults manifest entry, an SSR seed-plan step) checks this
1683
+ * first and skips it — see `bf debug graph`'s `debug.ts` precedent (#3227)
1684
+ * this generalizes.
1685
+ *
1686
+ * A plain `createSignal` getter-elided form (`const [, setX] =
1687
+ * createSignal(0)`) is NOT covered by this predicate, even though
1688
+ * `analyzer.ts`'s synthesis and `SignalInfo.getterElided`'s own docstring
1689
+ * make clear its getter is *equally* synthesized and unreferenced — it
1690
+ * leaks `__bfGet_<setter>` through the exact same sites today. #3245 scoped
1691
+ * this fix to the `factory` case only; widening this predicate to plain
1692
+ * `getterElided` (dropping the `factory` restriction) would close that gap
1693
+ * too, but is left for a separate follow-up rather than folded in here.
1694
+ */
1695
+ export function isElidedFactoryGetter(signal: Pick<SignalInfo, 'factory' | 'getterElided'>): boolean {
1696
+ return Boolean(signal.factory && signal.getterElided)
1697
+ }
1698
+
1652
1699
  /**
1653
1700
  * The async reactive factory call a signal's value comes from (#3165). Every
1654
1701
  * backend that re-emits the declaration reads this instead of assuming