@barefootjs/jsx 0.38.0 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/action-accessor.d.ts +159 -0
  2. package/dist/action-accessor.d.ts.map +1 -0
  3. package/dist/adapters/jsx-adapter.d.ts.map +1 -1
  4. package/dist/analyzer.d.ts +30 -1
  5. package/dist/analyzer.d.ts.map +1 -1
  6. package/dist/async-action-refusal.d.ts +45 -0
  7. package/dist/async-action-refusal.d.ts.map +1 -0
  8. package/dist/compiler.d.ts.map +1 -1
  9. package/dist/debug.d.ts +61 -5
  10. package/dist/debug.d.ts.map +1 -1
  11. package/dist/errors.d.ts +4 -0
  12. package/dist/errors.d.ts.map +1 -1
  13. package/dist/format-date-refusal.d.ts +2 -6
  14. package/dist/format-date-refusal.d.ts.map +1 -1
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1056 -344
  18. package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
  19. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  20. package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
  21. package/dist/ir-to-client-js/compute-scope.d.ts.map +1 -1
  22. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -0
  23. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
  24. package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
  25. package/dist/ir-to-client-js/declaration-sort.d.ts +2 -1
  26. package/dist/ir-to-client-js/declaration-sort.d.ts.map +1 -1
  27. package/dist/ir-to-client-js/emit-module-level.d.ts.map +1 -1
  28. package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
  29. package/dist/ir-to-client-js/plan/declaration-emit.d.ts +7 -5
  30. package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
  31. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  33. package/dist/ir-to-client-js/types.d.ts +4 -0
  34. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  35. package/dist/ir-to-client-js/utils.d.ts +41 -2
  36. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  37. package/dist/jsx-to-ir.d.ts.map +1 -1
  38. package/dist/signal-initializer.d.ts +24 -0
  39. package/dist/signal-initializer.d.ts.map +1 -0
  40. package/dist/template-position-walk.d.ts +68 -0
  41. package/dist/template-position-walk.d.ts.map +1 -0
  42. package/dist/types.d.ts +51 -0
  43. package/dist/types.d.ts.map +1 -1
  44. package/package.json +2 -2
  45. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +191 -1
  46. package/src/__tests__/action-accessor.test.ts +166 -0
  47. package/src/__tests__/create-mutation.test.ts +220 -0
  48. package/src/__tests__/create-query.test.ts +644 -0
  49. package/src/__tests__/csr-fragment-root-scope-shape.test.ts +156 -0
  50. package/src/__tests__/debug.test.ts +222 -0
  51. package/src/__tests__/doc-examples.test.ts +66 -3
  52. package/src/__tests__/props-destructuring.test.ts +79 -4
  53. package/src/__tests__/reactive-factory-arity.test.ts +311 -0
  54. package/src/__tests__/ssr-portal-ref-callback.test.ts +5 -3
  55. package/src/action-accessor.ts +289 -0
  56. package/src/adapters/jsx-adapter.ts +17 -0
  57. package/src/analyzer.ts +558 -33
  58. package/src/async-action-refusal.ts +254 -0
  59. package/src/compiler.ts +3 -0
  60. package/src/debug.ts +318 -103
  61. package/src/errors.ts +39 -0
  62. package/src/format-date-refusal.ts +6 -125
  63. package/src/index.ts +2 -1
  64. package/src/ir-to-client-js/build-references.ts +6 -2
  65. package/src/ir-to-client-js/collect-elements.ts +1 -0
  66. package/src/ir-to-client-js/compute-inlinability.ts +2 -1
  67. package/src/ir-to-client-js/compute-scope.ts +3 -1
  68. package/src/ir-to-client-js/control-flow/plan/build-insert.ts +1 -0
  69. package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -0
  70. package/src/ir-to-client-js/control-flow/stringify/insert.ts +1 -1
  71. package/src/ir-to-client-js/csr-substitute.ts +11 -3
  72. package/src/ir-to-client-js/declaration-sort.ts +7 -3
  73. package/src/ir-to-client-js/emit-module-level.ts +7 -4
  74. package/src/ir-to-client-js/emit-registration.ts +5 -10
  75. package/src/ir-to-client-js/index.ts +7 -2
  76. package/src/ir-to-client-js/phases/ref-callbacks.ts +1 -1
  77. package/src/ir-to-client-js/plan/build-declaration-emit.ts +16 -15
  78. package/src/ir-to-client-js/plan/declaration-emit.ts +7 -5
  79. package/src/ir-to-client-js/prop-handling.ts +4 -0
  80. package/src/ir-to-client-js/reactivity.ts +1 -0
  81. package/src/ir-to-client-js/stringify/declaration-emit.ts +14 -7
  82. package/src/ir-to-client-js/types.ts +4 -0
  83. package/src/ir-to-client-js/utils.ts +55 -7
  84. package/src/jsx-to-ir.ts +36 -2
  85. package/src/signal-initializer.ts +36 -0
  86. package/src/template-position-walk.ts +203 -0
  87. package/src/types.ts +52 -0
@@ -26,6 +26,7 @@ import {
26
26
  loopItemMarker,
27
27
  toHTMLAttrName as toHtmlAttrName,
28
28
  keyAttrName as sharedKeyAttrName,
29
+ BF_PORTAL_OWNER,
29
30
  } from '@barefootjs/shared'
30
31
  import { RUNTIME_IMPORT_CANDIDATES } from './imports.ts'
31
32
 
@@ -81,7 +82,42 @@ export function initFunctionName(componentName: string): string {
81
82
  * — the wrapping comment marks a scope with no DOM presence of its own.
82
83
  */
83
84
  export function isCommentScopedRoot(root: ComponentIR['root']): boolean {
84
- return (root.type === 'fragment' && !!(root as IRFragment).needsScopeComment) || root.type === 'component'
85
+ return isScopeCommentFragmentRoot(root) || root.type === 'component'
86
+ }
87
+
88
+ /**
89
+ * True for a genuine `needsScopeComment` fragment root — the `fragmentRoot:
90
+ * true` def flag's condition (#2722). SSR renders it wrapped in
91
+ * `<!--bf-scope:-->` comments with no scope attribute on any element, so the
92
+ * CSR runtime must be told to mirror that (`materializeComponent` /
93
+ * `renderChild` in component.ts) instead of stamping `bf-s` onto the first
94
+ * rendered element.
95
+ */
96
+ export function isScopeCommentFragmentRoot(root: ComponentIR['root']): boolean {
97
+ return root.type === 'fragment' && !!(root as IRFragment).needsScopeComment
98
+ }
99
+
100
+ /**
101
+ * The scope-shape flags (`comment: true` / `fragmentRoot: true`) a
102
+ * component's `hydrate()` def declares — the ONE answer both registration
103
+ * emitters read: `emitRegistrationAndHydration` (emit-registration.ts, a
104
+ * component with an init body) and `generateTemplateOnlyMount` (index.ts, a
105
+ * stateless component registered for `renderChild()` only). The template-
106
+ * only emitter used to re-derive the def by hand and declared neither flag,
107
+ * so a fragment-rooted stateless child rendered by CSR got `bf-s` stamped on
108
+ * its first element while SSR (and so hydration) scoped it with a comment
109
+ * pair — a hydrated-vs-csr-mount divergence.
110
+ *
111
+ * A component-call root (#2649) never reaches the template-only emitter:
112
+ * its root child call always pushes a `childInits` entry
113
+ * (collect-elements.ts), so `needsClientJs` routes it to the init-bearing
114
+ * path. Both paths therefore share one answer here.
115
+ */
116
+ export function componentDefScopeFlags(root: ComponentIR['root']): string[] {
117
+ const flags: string[] = []
118
+ if (isCommentScopedRoot(root)) flags.push('comment: true')
119
+ if (isScopeCommentFragmentRoot(root)) flags.push('fragmentRoot: true')
120
+ return flags
85
121
  }
86
122
 
87
123
  /**
@@ -397,18 +433,30 @@ export function wrapHandlerForTurn(handler: string, handlerId: string, loc?: str
397
433
  * Heuristic: a single bare identifier (e.g. `attachPane`) is a local binding;
398
434
  * anything else (member access, call, arrow, …) is treated as a possibly-
399
435
  * undefined source and emitted with optional-call (`?.()`).
400
- */
401
- export function emitRefCall(callback: string, elementVar: string): string {
436
+ *
437
+ * `ssrPortalOwner` (the element's `IRElement.ssrPortalOwnerScope`, #3059):
438
+ * every SSR adapter renders that element at its portal outlet with
439
+ * `bf-po="<this component's scope id>"` — the owner marker hydration's
440
+ * portal-aware slot lookup finds it by, and which hydration keeps as-is.
441
+ * The CSR mirror stamps the same owner right AFTER the ref callback ran (not
442
+ * in the template: a `bf-po` present before the callback makes its
443
+ * `!isSSRPortal(el)` guard skip the move). Without it the owner came only
444
+ * from the callback's own `createPortal(el, …, { ownerScope })`, which
445
+ * derives it from `el.closest('[bf-s]')` — this component's root for an
446
+ * element root, but nothing (or an unrelated outer scope) for a
447
+ * `needsScopeComment` fragment root, whose scope id lives on a comment, so
448
+ * a CSR mount diverged from SSR/hydration on the attribute.
449
+ */
450
+ export function emitRefCall(callback: string, elementVar: string, ssrPortalOwner = false): string {
402
451
  const trimmed = callback.trim()
403
452
  const isBareIdent = /^[a-zA-Z_$][\w$]*$/.test(trimmed)
404
- if (isBareIdent) {
405
- return `(${callback})(${elementVar})`
406
- }
407
453
  // Wrap non-identifier expressions in parens so `?.()` binds to the whole
408
454
  // expression (e.g. `(_p.onMount)?.(_s0)` not `_p.onMount?.(_s0)` — both
409
455
  // parse the same here, but the parens preserve the legacy emit shape's
410
456
  // intent and stay safe for arbitrary callback expressions).
411
- return `(${callback})?.(${elementVar})`
457
+ const call = isBareIdent ? `(${callback})(${elementVar})` : `(${callback})?.(${elementVar})`
458
+ if (!ssrPortalOwner) return call
459
+ return `{ ${call}; if (__scopeId) ${elementVar}.setAttribute('${BF_PORTAL_OWNER}', __scopeId) }`
412
460
  }
413
461
 
414
462
  /** Infer a sensible JS default value literal from a type descriptor. */
package/src/jsx-to-ir.ts CHANGED
@@ -70,6 +70,7 @@ import { toHTMLAttrName, decodeEntities, BF_KEY, keyAttrName } from '@barefootjs
70
70
  import { BindingScope } from './scope/binding-scope.ts'
71
71
  import { identifierPattern, identifierCallPattern } from './identifier-pattern.ts'
72
72
  import { isEventHandlerName } from './event-handler-name.ts'
73
+ import { seedActionAccessorReads } from './action-accessor.ts'
73
74
 
74
75
  // =============================================================================
75
76
  // Transform Context
@@ -1188,6 +1189,11 @@ export function jsxToIR(analyzer: AnalyzerContext): IRNode | null {
1188
1189
  if (root) {
1189
1190
  reportRefAttrsAbsentAtSsr(root, ctx)
1190
1191
  attachParsedExpressions(root, analyzer)
1192
+ // #3166: seed a query/mutation action's `isPending()` / `error()` read
1193
+ // where the seed renders like the reference — `action-accessor.ts`'s gate
1194
+ // decides which positions, the same gate BF117's refusal-lift reads.
1195
+ // Runs on the attached `parsed` trees, so it must follow the attach walk.
1196
+ seedActionAccessorReads(root, analyzer.signals)
1191
1197
  resolveRootKeyAttr(root)
1192
1198
  }
1193
1199
  return root
@@ -2276,7 +2282,8 @@ function markDataKeyCarrier(children: IRNode[]): IRNode[] {
2276
2282
  * The marked copy of `node` if this subtree can render an element in first
2277
2283
  * position, or null if it cannot.
2278
2284
  *
2279
- * Descends through `conditional` because a fragment whose only top-level
2285
+ * Descends through a nested `fragment` (no DOM of its own) and through
2286
+ * `conditional`, because a fragment whose only top-level
2280
2287
  * child is a ternary or `&&` is still a single-visual-root row —
2281
2288
  * `{done ? <li class="done"/> : <li/>}` renders exactly one `<li>`. A flat
2282
2289
  * `children.findIndex(c => c.type === 'element')` returns -1 there and
@@ -2304,6 +2311,15 @@ function markCarrierIn(node: IRNode): IRNode | null {
2304
2311
  if (!whenTrue && !whenFalse) return null
2305
2312
  return { ...cond, whenTrue: whenTrue ?? cond.whenTrue, whenFalse: whenFalse ?? cond.whenFalse }
2306
2313
  }
2314
+ if (node.type === 'fragment') {
2315
+ // A fragment nested directly inside the root fragment (`<><><li/></></>`)
2316
+ // renders no DOM of its own, so its first element is the row's first
2317
+ // element too — the one the CSR runtime stamps the key on
2318
+ // (`component.ts`'s `roots.find(isElement)`, #2735).
2319
+ const frag = node as IRFragment
2320
+ const children = markDataKeyCarrier(frag.children)
2321
+ return children === frag.children ? null : { ...frag, children }
2322
+ }
2307
2323
  return null
2308
2324
  }
2309
2325
 
@@ -7161,7 +7177,8 @@ function bindingDeclares(binding: ts.BindingName, name: string): boolean {
7161
7177
  * lookup, so sharing the resolution does not widen what is recognized. It
7162
7178
  * is not a `.map()`-row guard: a portal element inside a row is broken
7163
7179
  * either way (a row-declared callback is still recognized, and still
7164
- * breaks), a pre-existing defect tracked separately.
7180
+ * breaks) — the known limitation `loop-row-ref-portal`
7181
+ * (`packages/adapter-tests/limitations/loop-row-ref-portal.ts`).
7165
7182
  *
7166
7183
  * A match makes `element.ssrPortalOwnerScope` true, which every adapter
7167
7184
  * (#3119) uses to place the element's SSR markup at its own portal
@@ -8971,9 +8988,26 @@ function shouldAutoDeferReactiveBrand(expr: ts.Expression, ctx: TransformContext
8971
8988
  // Preserves the original "any native ref anywhere defers to non-deferred"
8972
8989
  // semantics by checking every reactive-brand leaf, not just the first.
8973
8990
  if (leaves.some((leaf) => isSignalOrMemoReference(ctx.getJS(leaf), ctx))) return false
8991
+ // A query action's accessors (`fetchPosts.isPending()`, #3165) are not a
8992
+ // client-only brand package: they stay in the template, where BF117
8993
+ // (`async-action-refusal.ts`) refuses them until they are seeded.
8994
+ if (leaves.some((leaf) => isAsyncActionLeaf(leaf, ctx))) return false
8974
8995
  return true
8975
8996
  }
8976
8997
 
8998
+ /**
8999
+ * Whether a reactive-brand leaf (`fetchPosts.isPending`,
9000
+ * `fetchPosts.isPending()`) is rooted at the action binding of an async
9001
+ * factory (`const [, fetchPosts] = createQuery(…)`, #3165).
9002
+ */
9003
+ function isAsyncActionLeaf(leaf: ts.Node, ctx: TransformContext): boolean {
9004
+ let node: ts.Node = leaf
9005
+ while (ts.isCallExpression(node) || ts.isPropertyAccessExpression(node)) node = node.expression
9006
+ if (!ts.isIdentifier(node)) return false
9007
+ const name = node.text
9008
+ return ctx.analyzer.signals.some((s) => s.factory?.action === name)
9009
+ }
9010
+
8977
9011
  /**
8978
9012
  * Regex-based signal/memo detection.
8979
9013
  * Complements TypeChecker for cases where imported types can't be resolved.
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Client-JS initializers for signals that `createSignal` does not produce.
3
+ *
4
+ * Two factory families are collected as signals: env signals
5
+ * (`createSearchParams()`, #2057) and async reactive factories
6
+ * (`createQuery(fn, options)`, #3165). Every backend that re-emits a signal
7
+ * declaration into client JS asks this module for the initializer instead of
8
+ * hard-coding `createSignal`, so a new factory kind is one entry here rather
9
+ * than a special case per emit site.
10
+ */
11
+
12
+ import type { SignalInfo } from './types.ts'
13
+ import { ENV_SIGNAL_CLIENT_FACTORY } from './adapters/env-signal.ts'
14
+
15
+ /**
16
+ * The initializer expression that produces this signal's tuple in client JS
17
+ * when it isn't `createSignal(<initialValue>)`, or `null` for an ordinary
18
+ * signal. An async factory re-emits its own call with the authored arguments;
19
+ * an env signal calls its factory with none.
20
+ */
21
+ export function signalFactoryInitializer(signal: SignalInfo): string | null {
22
+ if (signal.factory) return `${signal.factory.callee}(${signal.factory.argsText})`
23
+ if (signal.envReader) {
24
+ const factory = signal.envFactory ?? ENV_SIGNAL_CLIENT_FACTORY[signal.envReader]
25
+ return factory ? `${factory}()` : null
26
+ }
27
+ return null
28
+ }
29
+
30
+ /**
31
+ * The second binding of the signal's tuple as written in the source: the
32
+ * setter for `createSignal` and env signals, the action for an async factory.
33
+ */
34
+ export function signalSecondBinding(signal: SignalInfo): string | null {
35
+ return signal.setter ?? signal.factory?.action ?? null
36
+ }
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Every template-lowered position in a component's IR, as parsed expressions.
3
+ *
4
+ * Shared by the policy refusals that fire in the IR-build phase ahead of every
5
+ * adapter's `generate()` — `checkAuthoredFormatDateCalls` (BF056) and
6
+ * `checkAsyncActionReads` (BF117) — so "every position a template could
7
+ * render" is decided once. Covered: text expressions, conditional and
8
+ * if-statement conditions, element / component / provider attribute values
9
+ * (expression, spread, and structured template parts), loop arrays, and the
10
+ * children of elements, components, fragments, providers, async boundaries,
11
+ * loops (including child components, nested components, and `flatMap` /
12
+ * preamble JSX segments) and conditional branches.
13
+ *
14
+ * A `/* @client *\/`-marked position (`clientOnly`) is skipped: the whole read
15
+ * is deferred to the client, where real JS evaluates it.
16
+ *
17
+ * Each position also reports its `role` — how the template USES the value
18
+ * there (rendered as text, tested for truthiness, written as an attribute…)
19
+ * — and, for the two roles a pass may rewrite in place, the IR `host` that
20
+ * holds it. The action-accessor seed (`action-accessor.ts`, #3166) reads
21
+ * both: a seed is only sound where it renders like the reference adapter,
22
+ * which depends on the role, and BF117's refusal-lift and the seed itself
23
+ * must see the SAME position set, which is why both ride this one walk.
24
+ * BF056 reads neither.
25
+ */
26
+
27
+ import type {
28
+ AttrValue,
29
+ ExpressionAttr,
30
+ IRConditional,
31
+ IRIfStatement,
32
+ IRNode,
33
+ IRTemplatePart,
34
+ SourceLocation,
35
+ } from './types.ts'
36
+ import type { ParsedExpr } from './expression-parser.ts'
37
+ import { parseExpression } from './expression-parser.ts'
38
+
39
+ /**
40
+ * How the template uses the value at a position:
41
+ *
42
+ * - `text` — an `IRExpression` child, rendered as text.
43
+ * - `condition` — an `IRConditional` / `IRIfStatement` condition, only ever
44
+ * tested for truthiness.
45
+ * - `element-attr` — an intrinsic element's attribute value (an `expression`
46
+ * attr's whole parse), rendered as the attribute.
47
+ * - `prop` — a component prop or a provider's `value`, handed on as a value.
48
+ * - `spread` — a spread bag (`{...x}`), on an element or a component.
49
+ * - `template-part` — a piece of a structured template attribute
50
+ * (`IRTemplatePart` ternary condition / branch, lookup key). These are raw
51
+ * text parsed on demand here; every adapter lowers them from that raw text,
52
+ * so nothing attached to the IR can stand in for them.
53
+ * - `loop-array` — a loop's array expression.
54
+ */
55
+ export type TemplatePositionRole =
56
+ | 'text'
57
+ | 'condition'
58
+ | 'element-attr'
59
+ | 'prop'
60
+ | 'spread'
61
+ | 'template-part'
62
+ | 'loop-array'
63
+
64
+ /**
65
+ * The IR slot a position's `expr` lives in, for a pass that rewrites the
66
+ * position in place (the action-accessor seed). Only the two roles such a
67
+ * pass may rewrite carry one: a `condition` (its `parsedCondition` /
68
+ * `templateCondition`) and an `element-attr` (the `ExpressionAttr`'s
69
+ * `parsed` / `templateExpr`).
70
+ */
71
+ export type TemplatePositionHost =
72
+ | { kind: 'condition'; node: IRConditional | IRIfStatement }
73
+ | { kind: 'element-attr'; value: ExpressionAttr }
74
+
75
+ export interface TemplatePosition {
76
+ expr: ParsedExpr
77
+ loc: SourceLocation
78
+ role: TemplatePositionRole
79
+ /** The attribute or prop name, when the position is an attribute / prop value. */
80
+ attrName?: string
81
+ host?: TemplatePositionHost
82
+ }
83
+
84
+ export function walkTemplatePositions(root: IRNode, visit: (position: TemplatePosition) => void): void {
85
+ walkNode(root, visit)
86
+ }
87
+
88
+ /**
89
+ * `IRTemplatePart.ternary.condition` / `.lookup.key` carry no attached parse
90
+ * (unlike every other position here), so parse on demand. `ternary.whenTrue`
91
+ * / `.whenFalse` are ALSO raw, unparsed text (the per-branch rendered
92
+ * snippet), so they get the same on-demand treatment — this is the
93
+ * `format-date-ternary` shape (#2843): a call in a ternary CONSEQUENT inside a
94
+ * structured template-literal attribute.
95
+ */
96
+ function walkTemplateParts(
97
+ parts: readonly IRTemplatePart[],
98
+ loc: SourceLocation,
99
+ attrName: string | undefined,
100
+ visit: (position: TemplatePosition) => void,
101
+ ): void {
102
+ const visitText = (text: string) => {
103
+ const trimmed = text.trim()
104
+ if (!trimmed) return
105
+ visit({ expr: parseExpression(trimmed), loc, role: 'template-part', attrName })
106
+ }
107
+ for (const part of parts) {
108
+ if (part.type === 'ternary') {
109
+ visitText(part.condition)
110
+ visitText(part.whenTrue)
111
+ visitText(part.whenFalse)
112
+ } else if (part.type === 'lookup') {
113
+ visitText(part.key)
114
+ }
115
+ }
116
+ }
117
+
118
+ function walkAttrValue(
119
+ value: AttrValue,
120
+ clientOnly: boolean | undefined,
121
+ loc: SourceLocation,
122
+ attrName: string,
123
+ onElement: boolean,
124
+ visit: (position: TemplatePosition) => void,
125
+ ): void {
126
+ if (clientOnly) return
127
+ if (value.kind === 'expression') {
128
+ if (value.parsed) {
129
+ visit(
130
+ onElement
131
+ ? { expr: value.parsed, loc, role: 'element-attr', attrName, host: { kind: 'element-attr', value } }
132
+ : { expr: value.parsed, loc, role: 'prop', attrName },
133
+ )
134
+ }
135
+ if (value.parts) walkTemplateParts(value.parts, loc, attrName, visit)
136
+ } else if (value.kind === 'spread') {
137
+ if (value.parsed) visit({ expr: value.parsed, loc, role: 'spread', attrName })
138
+ } else if (value.kind === 'template') {
139
+ walkTemplateParts(value.parts, loc, attrName, visit)
140
+ }
141
+ }
142
+
143
+ function walkNode(node: IRNode, visit: (position: TemplatePosition) => void): void {
144
+ if (node.type === 'expression') {
145
+ if (!node.clientOnly && node.parsed) visit({ expr: node.parsed, loc: node.loc, role: 'text' })
146
+ } else if (node.type === 'conditional') {
147
+ if (!node.clientOnly && node.parsedCondition) {
148
+ visit({ expr: node.parsedCondition, loc: node.loc, role: 'condition', host: { kind: 'condition', node } })
149
+ }
150
+ } else if (node.type === 'if-statement') {
151
+ if (node.parsedCondition) {
152
+ visit({ expr: node.parsedCondition, loc: node.loc, role: 'condition', host: { kind: 'condition', node } })
153
+ }
154
+ }
155
+
156
+ if (node.type === 'element') {
157
+ for (const attr of node.attrs) walkAttrValue(attr.value, attr.clientOnly, attr.loc, attr.name, true, visit)
158
+ } else if (node.type === 'component') {
159
+ for (const prop of node.props) walkAttrValue(prop.value, prop.clientOnly, prop.loc, prop.name, false, visit)
160
+ } else if (node.type === 'provider') {
161
+ walkAttrValue(node.valueProp.value, node.valueProp.clientOnly, node.valueProp.loc, 'value', false, visit)
162
+ }
163
+
164
+ switch (node.type) {
165
+ case 'element':
166
+ case 'component':
167
+ case 'fragment':
168
+ case 'provider':
169
+ for (const child of node.children) walkNode(child, visit)
170
+ break
171
+ case 'async':
172
+ walkNode(node.fallback, visit)
173
+ for (const child of node.children) walkNode(child, visit)
174
+ break
175
+ case 'loop': {
176
+ if (node.clientOnly) break
177
+ if (node.arrayParsed) visit({ expr: node.arrayParsed, loc: node.loc, role: 'loop-array' })
178
+ for (const child of node.children) walkNode(child, visit)
179
+ if (node.childComponent) {
180
+ for (const child of node.childComponent.children) walkNode(child, visit)
181
+ }
182
+ for (const nested of node.nestedComponents ?? []) {
183
+ for (const child of nested.children) walkNode(child, visit)
184
+ }
185
+ for (const seg of node.flatMapCallback?.segments ?? []) {
186
+ if (seg.kind === 'jsx') walkNode(seg.ir, visit)
187
+ }
188
+ for (const seg of node.preamble?.segments ?? []) {
189
+ if (seg.kind === 'jsx') walkNode(seg.ir, visit)
190
+ }
191
+ break
192
+ }
193
+ case 'conditional':
194
+ if (node.clientOnly) break
195
+ walkNode(node.whenTrue, visit)
196
+ walkNode(node.whenFalse, visit)
197
+ break
198
+ case 'if-statement':
199
+ walkNode(node.consequent, visit)
200
+ if (node.alternate) walkNode(node.alternate, visit)
201
+ break
202
+ }
203
+ }
package/src/types.ts CHANGED
@@ -1637,6 +1637,47 @@ export interface SignalInfo {
1637
1637
  * actually in scope, not a hardcoded canonical name (#2057).
1638
1638
  */
1639
1639
  envFactory?: string
1640
+ /**
1641
+ * Set when this signal is the value half of an async reactive factory
1642
+ * (`const [posts, action] = createQuery(fn, options)`, #3165) rather than
1643
+ * `createSignal`. The getter is a normal reactive getter (so it seeds,
1644
+ * substitutes and folds like any signal), and `initialValue` is the
1645
+ * `options.initial` expression — the literal `undefined` when the call has
1646
+ * no `initial`. `setter` is always `null`: the second tuple binding is
1647
+ * the factory's action, recorded here, never a setter.
1648
+ */
1649
+ factory?: SignalFactoryCall
1650
+ }
1651
+
1652
+ /**
1653
+ * The async reactive factory call a signal's value comes from (#3165). Every
1654
+ * backend that re-emits the declaration reads this instead of assuming
1655
+ * `createSignal`: client JS re-emits `<callee>(<argsText>)` (the request
1656
+ * function is never evaluated on the server), and SSR seeds the value from
1657
+ * `initialValue` like any other signal.
1658
+ */
1659
+ export interface SignalFactoryCall {
1660
+ /** Which factory: `createQuery` (#3165) or `createMutation` (#3210). */
1661
+ kind: 'query' | 'mutation'
1662
+ /** The callee as written: `createQuery` / `createMutation`, an alias, or `bf.createQuery`. */
1663
+ callee: string
1664
+ /**
1665
+ * The call's argument list as JS (type annotations stripped), emitted
1666
+ * verbatim into the client `init` body, where the props-rewrite passes turn
1667
+ * prop reads into live `_p` reads like any effect body.
1668
+ */
1669
+ argsText: string
1670
+ /**
1671
+ * The request function alone (the first argument, type annotations
1672
+ * stripped) and its free identifiers — `''` / empty when the call has no
1673
+ * argument. Kept apart from `argsText` because only the request function is
1674
+ * tracked: `options` (`initial`, `ttl`, `invalidates`) is read once, at
1675
+ * creation, so a signal read there re-sends nothing (`bf debug graph`, #3167).
1676
+ */
1677
+ requestText: string
1678
+ requestFreeIdentifiers: ReadonlySet<string>
1679
+ /** The action binding (the second tuple element), or `null` when it isn't destructured. */
1680
+ action: string | null
1640
1681
  }
1641
1682
 
1642
1683
  export interface MemoInfo {
@@ -1966,6 +2007,11 @@ export interface FunctionInfo {
1966
2007
  * migration; legacy emit paths default to inferring from `body`.
1967
2008
  */
1968
2009
  declarationKind?: 'function' | 'arrow' | 'function-expression'
2010
+ /**
2011
+ * Free identifiers of the function (parameters excluded), computed from the
2012
+ * AST: what its body reads when it is called.
2013
+ */
2014
+ freeIdentifiers?: ReadonlySet<string>
1969
2015
  /** When true, declared at module level (outside the component function). */
1970
2016
  isModule?: boolean
1971
2017
  /** When true, this function returns JSX and is inlined at call sites (#569). */
@@ -2019,6 +2065,12 @@ export interface ConstantInfo {
2019
2065
  isJsxFunction?: boolean
2020
2066
  /** When true, the initializer contains an arrow function or function expression (computed from AST). */
2021
2067
  containsArrow?: boolean
2068
+ /**
2069
+ * When true, the initializer IS an arrow function or function expression
2070
+ * (`const status = () => …`), so reading the constant yields a function and
2071
+ * only calling it evaluates the body. Computed from the AST.
2072
+ */
2073
+ isFunctionValue?: boolean
2022
2074
  /**
2023
2075
  * When true, a same-scope statement (a `for`/`while` body, or any other
2024
2076
  * imperative statement) mutates this binding's value AFTER its