@barefootjs/jsx 0.39.9 → 0.40.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 (164) hide show
  1. package/dist/adapters/ambiguous-nil-arithmetic.d.ts +41 -0
  2. package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +1 -0
  3. package/dist/adapters/attr-plan.d.ts +1 -20
  4. package/dist/adapters/attr-plan.d.ts.map +1 -1
  5. package/dist/adapters/boolean-carrier.d.ts +31 -0
  6. package/dist/adapters/boolean-carrier.d.ts.map +1 -0
  7. package/dist/adapters/component-props.d.ts +22 -7
  8. package/dist/adapters/component-props.d.ts.map +1 -1
  9. package/dist/adapters/computed-const.d.ts +17 -0
  10. package/dist/adapters/computed-const.d.ts.map +1 -1
  11. package/dist/adapters/dsl-template-adapter.d.ts +95 -2
  12. package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
  13. package/dist/adapters/loop-plan.d.ts +41 -1
  14. package/dist/adapters/loop-plan.d.ts.map +1 -1
  15. package/dist/adapters/number-value.d.ts +43 -0
  16. package/dist/adapters/number-value.d.ts.map +1 -0
  17. package/dist/analyzer-context.d.ts +7 -0
  18. package/dist/analyzer-context.d.ts.map +1 -1
  19. package/dist/analyzer.d.ts +34 -0
  20. package/dist/analyzer.d.ts.map +1 -1
  21. package/dist/augment-inherited-props.d.ts.map +1 -1
  22. package/dist/css-layer-prefixer.d.ts.map +1 -1
  23. package/dist/debug.d.ts.map +1 -1
  24. package/dist/expression-parser.d.ts.map +1 -1
  25. package/dist/index.d.ts +10 -7
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +2102 -1344
  28. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  29. package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
  30. package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts +29 -0
  31. package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.d.ts +2 -0
  33. package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.d.ts.map +1 -1
  34. package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
  35. package/dist/ir-to-client-js/control-flow/plan/build-reactive-effects.d.ts.map +1 -1
  36. package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts +5 -4
  37. package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts.map +1 -1
  38. package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts +2 -0
  39. package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts.map +1 -1
  40. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +15 -0
  41. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
  42. package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts +2 -0
  43. package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts.map +1 -1
  44. package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
  45. package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts +20 -0
  46. package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
  47. package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
  48. package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts +1 -1
  49. package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
  50. package/dist/ir-to-client-js/control-flow/stringify/lazy-row.d.ts.map +1 -1
  51. package/dist/ir-to-client-js/html-template.d.ts +3 -2
  52. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  53. package/dist/ir-to-client-js/plan/build-static-array-child-init.d.ts.map +1 -1
  54. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +7 -1
  55. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
  56. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  57. package/dist/ir-to-client-js/safe-html.d.ts +9 -3
  58. package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
  59. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
  60. package/dist/ir-to-client-js/types.d.ts +30 -0
  61. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  62. package/dist/ir-to-client-js/utils.d.ts +9 -1
  63. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  64. package/dist/jsx-to-ir.d.ts.map +1 -1
  65. package/dist/module-exports.d.ts.map +1 -1
  66. package/dist/nullable-signal-attr.d.ts +29 -3
  67. package/dist/nullable-signal-attr.d.ts.map +1 -1
  68. package/dist/props-binding.d.ts +27 -3
  69. package/dist/props-binding.d.ts.map +1 -1
  70. package/dist/scope/binding-scope.d.ts +24 -1
  71. package/dist/scope/binding-scope.d.ts.map +1 -1
  72. package/dist/scope/root-prop-alias.d.ts +14 -1
  73. package/dist/scope/root-prop-alias.d.ts.map +1 -1
  74. package/dist/signal-prop-name-collision.d.ts.map +1 -1
  75. package/dist/ssr-defaults.d.ts +4 -2
  76. package/dist/ssr-defaults.d.ts.map +1 -1
  77. package/dist/ssr-seed-plan.d.ts +14 -0
  78. package/dist/ssr-seed-plan.d.ts.map +1 -1
  79. package/dist/template-parts.d.ts +1 -1
  80. package/dist/template-parts.d.ts.map +1 -1
  81. package/dist/types.d.ts +35 -1
  82. package/dist/types.d.ts.map +1 -1
  83. package/package.json +2 -2
  84. package/src/__tests__/attr-plan.test.ts +1 -14
  85. package/src/__tests__/binding-scope-ratchet.test.ts +12 -2
  86. package/src/__tests__/boolean-carrier.test.ts +74 -0
  87. package/src/__tests__/client-template-escape-soundness.test.ts +17 -4
  88. package/src/__tests__/client-template-static-delimiters.test.ts +57 -0
  89. package/src/__tests__/component-props.test.ts +14 -0
  90. package/src/__tests__/computed-const.test.ts +85 -0
  91. package/src/__tests__/dsl-template-adapter.test.ts +70 -0
  92. package/src/__tests__/expression-parser.test.ts +24 -0
  93. package/src/__tests__/extract-function-params.test.ts +37 -0
  94. package/src/__tests__/issue-2960-multi-root-cond-same-tag.test.ts +18 -0
  95. package/src/__tests__/issue-3688-props-spread-child-csr.test.ts +142 -0
  96. package/src/__tests__/jsx-text-linebreak-whitespace.test.ts +11 -0
  97. package/src/__tests__/loop-plan.test.ts +66 -1
  98. package/src/__tests__/loop-row-prop-read.test.ts +111 -0
  99. package/src/__tests__/memo-body-expr.test.ts +137 -0
  100. package/src/__tests__/nullable-signal-attr.test.ts +97 -2
  101. package/src/__tests__/profile-binding-ids.test.ts +14 -0
  102. package/src/__tests__/root-prop-alias.test.ts +34 -1
  103. package/src/__tests__/signal-prop-name-collision.test.ts +102 -2
  104. package/src/__tests__/source-file-cache.test.ts +105 -0
  105. package/src/__tests__/ssr-seed-plan.test.ts +43 -0
  106. package/src/__tests__/template-parts-literal-boundary.test.ts +41 -0
  107. package/src/adapters/ambiguous-nil-arithmetic.ts +94 -0
  108. package/src/adapters/attr-plan.ts +8 -56
  109. package/src/adapters/boolean-carrier.ts +76 -0
  110. package/src/adapters/component-props.ts +28 -8
  111. package/src/adapters/computed-const.ts +206 -7
  112. package/src/adapters/dsl-template-adapter.ts +183 -2
  113. package/src/adapters/loop-plan.ts +67 -2
  114. package/src/adapters/number-value.ts +95 -0
  115. package/src/analyzer-context.ts +8 -0
  116. package/src/analyzer.ts +187 -66
  117. package/src/augment-inherited-props.ts +5 -9
  118. package/src/css-layer-prefixer.ts +4 -5
  119. package/src/debug.ts +1 -0
  120. package/src/expression-parser.ts +4 -1
  121. package/src/index.ts +23 -5
  122. package/src/ir-to-client-js/collect-elements.ts +104 -46
  123. package/src/ir-to-client-js/compute-inlinability.ts +2 -2
  124. package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +15 -1
  125. package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +79 -4
  126. package/src/ir-to-client-js/control-flow/plan/build-lazy-row.ts +3 -0
  127. package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +1 -0
  128. package/src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts +1 -0
  129. package/src/ir-to-client-js/control-flow/plan/inner-loop.ts +5 -4
  130. package/src/ir-to-client-js/control-flow/plan/loop-child-arm.ts +2 -0
  131. package/src/ir-to-client-js/control-flow/plan/loop.ts +12 -0
  132. package/src/ir-to-client-js/control-flow/plan/reactive-effects.ts +2 -0
  133. package/src/ir-to-client-js/control-flow/shared.ts +3 -2
  134. package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +27 -0
  135. package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +8 -2
  136. package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +8 -1
  137. package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +8 -7
  138. package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +8 -7
  139. package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +4 -4
  140. package/src/ir-to-client-js/control-flow/stringify/loop.ts +3 -3
  141. package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +6 -6
  142. package/src/ir-to-client-js/emit-reactive.ts +1 -1
  143. package/src/ir-to-client-js/html-template.ts +122 -75
  144. package/src/ir-to-client-js/plan/build-static-array-child-init.ts +11 -1
  145. package/src/ir-to-client-js/plan/static-array-child-init.ts +7 -1
  146. package/src/ir-to-client-js/reactivity.ts +14 -0
  147. package/src/ir-to-client-js/safe-html.ts +11 -4
  148. package/src/ir-to-client-js/stringify/static-array-child-init.ts +6 -4
  149. package/src/ir-to-client-js/types.ts +23 -0
  150. package/src/ir-to-client-js/utils.ts +16 -2
  151. package/src/jsx-to-ir.ts +112 -55
  152. package/src/loop-destructure.ts +4 -1
  153. package/src/module-exports.ts +13 -21
  154. package/src/nullable-signal-attr.ts +134 -13
  155. package/src/props-binding.ts +54 -3
  156. package/src/rich-type-refusal.ts +3 -1
  157. package/src/scope/binding-scope.ts +35 -2
  158. package/src/scope/root-prop-alias.ts +17 -1
  159. package/src/signal-prop-name-collision.ts +113 -22
  160. package/src/ssr-defaults.ts +10 -4
  161. package/src/ssr-seed-plan.ts +82 -17
  162. package/src/template-parts.ts +25 -3
  163. package/src/template-position-walk.ts +3 -1
  164. package/src/types.ts +32 -1
@@ -1,5 +1,5 @@
1
1
  import ts from 'typescript'
2
- import type { ConstantInfo, ParamInfo, PropUsage, SignalPropSeed } from './types.ts'
2
+ import type { ConstantInfo, FunctionInfo, MemoInfo, ParamInfo, PropUsage, SignalInfo, SignalPropSeed } from './types.ts'
3
3
  import type { ParsedExpr } from './expression-parser.ts'
4
4
  import { propHasPropertyAccess } from './ir-to-client-js/compute-prop-usage.ts'
5
5
  import { parsePropReadInitializer } from './ir-to-client-js/prune-unused-prop-extractions.ts'
@@ -115,8 +115,8 @@ export function isPropsAliasConst(
115
115
  * binding into a live prop read: the init body's alias rewrite
116
116
  * (`resolveBodyPropAliases`) and parameter rewrite
117
117
  * (`rewriteDestructuredPropReads`), the reactive attribute rewrite
118
- * (`rewriteDestructuredPropsInExpr`), and the template's prop shadow guard
119
- * (`propShadowingNames`, `jsx-to-ir.ts`, #3579).
118
+ * (`rewriteDestructuredPropsInExpr`), and the template's prop read set
119
+ * (`templatePropReadParams`, #3579).
120
120
  */
121
121
  export function keepsDeclaredValue(
122
122
  b: { declarationKind?: ConstantInfo['declarationKind']; mutatedAfterDeclaration?: boolean; reassigned?: boolean },
@@ -167,6 +167,57 @@ export function isRenamedBodyPropParam(
167
167
  return propsParams.some(p => !p.isRest && p.name === c.name && p.sourceName === key)
168
168
  }
169
169
 
170
+ /** The component bindings {@link templatePropReadParams} reads. */
171
+ export interface TemplatePropReadBindings {
172
+ propsObjectName: string | null
173
+ propsParams: readonly ParamInfo[]
174
+ signals: readonly Pick<SignalInfo, 'getter' | 'setter'>[]
175
+ memos: readonly Pick<MemoInfo, 'name'>[]
176
+ localFunctions: readonly Pick<FunctionInfo, 'name'>[]
177
+ localConstants: readonly ConstantInfo[]
178
+ }
179
+
180
+ /**
181
+ * The props bindings a client `template:` reads as their live prop
182
+ * (`livePropReadExpr`, default included). The one set the Phase-1 markup
183
+ * rewrite and a signal seed's or memo body's template text share, so a
184
+ * binding read through a memo takes the same default as one read in markup.
185
+ *
186
+ * In a destructured-parameter component that is every parameter. In a
187
+ * `(props)`-arg component a bare name is a prop only where the body binds it
188
+ * as one, so the set is exactly the body bindings that hold their prop
189
+ * ({@link holdsProp}) and that no other component binding (a signal, memo,
190
+ * local function or other local) shares a name with. A typed prop the body
191
+ * does not bind is not in scope as a bare name: a bare `value` there is a
192
+ * local function, a module binding or a global, never `_p.value`.
193
+ */
194
+ export function templatePropReadParams(b: TemplatePropReadBindings): ParamInfo[] {
195
+ if (!b.propsObjectName) return [...b.propsParams]
196
+ const held = new Set<string>()
197
+ const other = new Set<string>()
198
+ for (const s of b.signals) {
199
+ other.add(s.getter)
200
+ if (s.setter) other.add(s.setter)
201
+ }
202
+ for (const m of b.memos) other.add(m.name)
203
+ for (const f of b.localFunctions) other.add(f.name)
204
+ for (const c of b.localConstants) (holdsProp(c, b.propsObjectName, b.propsParams) ? held : other).add(c.name)
205
+ return b.propsParams.filter(p => held.has(p.name) && !other.has(p.name))
206
+ }
207
+
208
+ /**
209
+ * Whether a `(props)`-arg component's body binding is the prop itself: an
210
+ * alias (`const { b } = props`, `const b = props.b`) or a renamed body
211
+ * binding with a default, which reads as its own prop entry like the
212
+ * parameter form (#3579). A body destructure binding that is reassigned or
213
+ * mutated no longer holds its prop, renamed or not, so the template keeps it
214
+ * a local.
215
+ */
216
+ function holdsProp(c: ConstantInfo, propsObjectName: string, propsParams: readonly ParamInfo[]): boolean {
217
+ if (c.propsDestructure && !keepsDeclaredValue(c)) return false
218
+ return isPropsAliasConst(c, propsObjectName) || isRenamedBodyPropParam(c, propsParams)
219
+ }
220
+
170
221
  /**
171
222
  * How a parsed signal initializer reads a prop: a member chain rooted at the
172
223
  * props object (`props.<name>`, `props.row.count`, `props.items[0]`) or a
@@ -373,7 +373,9 @@ function walkTemplateParts(
373
373
  seen: Set<string>,
374
374
  ): void {
375
375
  for (const part of parts) {
376
- if (part.type === 'ternary') {
376
+ if (part.type === 'expression') {
377
+ checkExpr(part.parsed, loc, meta, bindings, matchers, errors, seen)
378
+ } else if (part.type === 'ternary') {
377
379
  const trimmed = part.condition.trim()
378
380
  if (trimmed) checkExpr(parseExpression(trimmed), loc, meta, bindings, matchers, errors, seen)
379
381
  } else if (part.type === 'lookup') {
@@ -29,6 +29,13 @@
29
29
  * "just names you can't resolve against component-level state."
30
30
  */
31
31
 
32
+ /**
33
+ * The identifier a template reads as the component's props object:
34
+ * `props.X` is the component's prop `X` while no binding shadows `props`
35
+ * (#3693).
36
+ */
37
+ export const PROPS_OBJECT_IDENTIFIER = 'props'
38
+
32
39
  /**
33
40
  * How a name inside a `ScopeFrame` came to be bound — the row shapes
34
41
  * (`'item'`/`'index'`/`'destructure'`/`'preamble'`) for `'loop-row'` frames,
@@ -206,13 +213,39 @@ export class BindingScope {
206
213
  return false
207
214
  }
208
215
 
209
- /** Resolve string typing at this position, respecting the nearest binding. */
216
+ /**
217
+ * Whether a binding here shadows the component's props object
218
+ * ({@link PROPS_OBJECT_IDENTIFIER}): a `.map((props) => …)` row, a
219
+ * destructured `({ props })` field, a preamble local or a callback param.
220
+ * `props.X` then reads that binding's member, not the component's prop
221
+ * `X` (#3693).
222
+ */
223
+ shadowsPropsObject(): boolean {
224
+ return this.isBound(PROPS_OBJECT_IDENTIFIER)
225
+ }
226
+
227
+ /**
228
+ * Resolve string typing at this position, respecting the nearest binding.
229
+ * `componentProperty`: `name` is read as `props.<name>`, which is the
230
+ * component's prop only while no binding shadows `props`; a shadowing
231
+ * binding's member has no typing here.
232
+ */
210
233
  isStringValueName(name: string, outer: (name: string) => boolean, componentProperty = false): boolean {
211
- if (componentProperty) return outer(name)
234
+ if (componentProperty) return !this.shadowsPropsObject() && outer(name)
212
235
  const hit = this.lookup(name)
213
236
  return hit ? hit.binding.stringValue === true : outer(name)
214
237
  }
215
238
 
239
+ /** Whether any frame is a loop row: the position sits inside a `.map()` row body. */
240
+ insideLoopRow(): boolean {
241
+ return this.frames.some(frame => frame.kind === 'loop-row')
242
+ }
243
+
244
+ /** The names the innermost frame binds, in binding order. */
245
+ innermostNames(): readonly string[] {
246
+ return this.frames[0] ? [...this.frames[0].bindings.keys()] : []
247
+ }
248
+
216
249
  /** Names this frame shadows in an enclosing callback/row frame. */
217
250
  shadowedNames(): readonly string[] {
218
251
  if (!this.frames[0]) return []
@@ -1,6 +1,7 @@
1
1
  import { collectLoopBoundNames } from '../adapters/loop-bound-names.ts'
2
+ import type { ParsedExpr } from '../expression-parser.ts'
2
3
  import type { ComponentIR } from '../types.ts'
3
- import type { BindingScope } from './binding-scope.ts'
4
+ import { PROPS_OBJECT_IDENTIFIER, type BindingScope } from './binding-scope.ts'
4
5
 
5
6
  /**
6
7
  * Root-prop aliases for template engines that flatten `props.X` to the bare
@@ -79,3 +80,18 @@ export function rootPropReadName(
79
80
  if (!scope.isBound(name)) return name
80
81
  return aliases.get(name) ?? name
81
82
  }
83
+
84
+ /**
85
+ * Whether `expr` reads the component's props object at a position where
86
+ * `isBound` answers which names a binding shadows: the bare identifier
87
+ * `props` that no binding shadows (#3693). A `.map((props) => …)` row, a
88
+ * destructured `({ props })` field, a preamble local or a callback param
89
+ * named `props` is that binding instead, so `props.X` reads its member
90
+ * rather than flattening to the component's prop `X`. Template emitters
91
+ * flatten a `props.X` read only when this holds; `isBound` is the
92
+ * adapter's current `BindingScope` (`scope.isBound`), or, in a filter
93
+ * predicate, the predicate's own params plus the enclosing scope.
94
+ */
95
+ export function isRootPropsObject(expr: ParsedExpr, isBound: (name: string) => boolean): boolean {
96
+ return expr.kind === 'identifier' && expr.name === PROPS_OBJECT_IDENTIFIER && !isBound(expr.name)
97
+ }
@@ -71,36 +71,113 @@ interface SeparatedBinding {
71
71
  name: string
72
72
  loc: SourceLocation
73
73
  prefix: 'bfSignal' | 'bfMemo'
74
+ /** Its own initializer derives from the same-named prop. */
75
+ selfDerived: boolean
74
76
  }
75
77
 
76
78
  /**
77
79
  * Signal getters and memos that share a name with a prop of a bare-props
78
80
  * component (`props.label` beside `const [label] = createSignal(...)` or
79
- * `const label = createMemo(...)`). The comparison ignores case because a
80
- * backend may fold it (Go exports both `label` and `Label` as the field
81
- * `Label`).
81
+ * `const label = createMemo(...)`). `propNames` holds lower-cased names:
82
+ * the comparison ignores case because a backend may fold it (Go exports
83
+ * both `label` and `Label` as the field `Label`).
82
84
  *
83
85
  * A binding whose own initializer derives from that same prop
84
- * (`createSignal(props.label ?? 'x')`) is left alone: the template-stash
85
- * backends keep it on the prop's variable, seeded from the raw prop, and
86
- * `extractSsrDefaults` decides that case with the same `referencesOwnProp`
87
- * test. A raw `props.label` read beside such a binding then sees the
88
- * derived value (limitation `signal-from-same-named-prop-raw-read`).
86
+ * (`createSignal(props.label ?? 'x')`) is marked `selfDerived`: the
87
+ * template-stash backends keep it on the prop's variable, seeded from the
88
+ * raw prop (`extractSsrDefaults` decides that case with the same
89
+ * `referencesOwnProp` test), unless the component also reads the raw prop
90
+ * (`separateSignalPropBindings`).
89
91
  */
90
- function collidingBindings(ctx: AnalyzerContext, propsObjectName: string): SeparatedBinding[] {
91
- const propNames = new Set(ctx.propsParams.map(p => p.name.toLowerCase()))
92
+ function collidingBindings(ctx: AnalyzerContext, propsObjectName: string, propNames: ReadonlySet<string>): SeparatedBinding[] {
92
93
  const localConsts = localConstValuesByName(ctx)
93
- const collides = (name: string, derivation: string): boolean =>
94
- propNames.has(name.toLowerCase()) && !referencesOwnProp(derivation, propsObjectName, name, localConsts)
94
+ const collides = (name: string): boolean => propNames.has(name.toLowerCase())
95
+ const selfDerived = (name: string, derivation: string): boolean =>
96
+ referencesOwnProp(derivation, propsObjectName, name, localConsts)
95
97
  const signals: SeparatedBinding[] = ctx.signals
96
- .filter(s => !s.isModule && !s.getterElided && !s.envReader && collides(s.getter, s.initialValue))
97
- .map(s => ({ name: s.getter, loc: s.loc, prefix: 'bfSignal' }))
98
+ .filter(s => !s.isModule && !s.getterElided && !s.envReader && collides(s.getter))
99
+ .map(s => ({ name: s.getter, loc: s.loc, prefix: 'bfSignal', selfDerived: selfDerived(s.getter, s.initialValue) }))
98
100
  const memos: SeparatedBinding[] = ctx.memos
99
- .filter(m => !m.isModule && collides(m.name, m.computation))
100
- .map(m => ({ name: m.name, loc: m.loc, prefix: 'bfMemo' }))
101
+ .filter(m => !m.isModule && collides(m.name))
102
+ .map(m => ({ name: m.name, loc: m.loc, prefix: 'bfMemo', selfDerived: selfDerived(m.name, m.computation) }))
101
103
  return [...signals, ...memos]
102
104
  }
103
105
 
106
+ /**
107
+ * A property read off the props object (`props.label`): its lower-cased
108
+ * name and position. `name` is null for a computed key (`props[k]`), which
109
+ * may read any prop.
110
+ */
111
+ interface PropsRead {
112
+ name: string | null
113
+ pos: number
114
+ }
115
+
116
+ /**
117
+ * The key a props read names: an identifier member (`props.label`), or an
118
+ * element access with a literal key (`props['label']`, `` props[`label`] ``,
119
+ * `props[0]`), each also optional (`props?.['label']`). The key is the
120
+ * literal's own text, so a numeric key names its number and never matches
121
+ * an identifier. Null for a computed key. Undefined when `node` is no
122
+ * member access off `propsObjectName`.
123
+ */
124
+ function propsReadKey(node: ts.Node, propsObjectName: string): { receiver: ts.Identifier; key: string | null } | undefined {
125
+ if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {
126
+ return isNamedReceiver(node.expression, propsObjectName) ? { receiver: node.expression, key: node.name.text } : undefined
127
+ }
128
+ if (!ts.isElementAccessExpression(node) || !isNamedReceiver(node.expression, propsObjectName)) return undefined
129
+ const arg = node.argumentExpression
130
+ const literal = ts.isStringLiteral(arg) || ts.isNoSubstitutionTemplateLiteral(arg) || ts.isNumericLiteral(arg)
131
+ return { receiver: node.expression, key: literal ? arg.text : null }
132
+ }
133
+
134
+ function isNamedReceiver(expr: ts.Expression, propsObjectName: string): expr is ts.Identifier {
135
+ return ts.isIdentifier(expr) && expr.text === propsObjectName
136
+ }
137
+
138
+ /**
139
+ * Every property read off the props object (`props.label`,
140
+ * `props['label']`) inside the component. An untyped `props` parameter
141
+ * declares no `propsParams`, so these reads are its only prop names.
142
+ * `isPropsObject` decides whether an access's receiver is the props
143
+ * binding itself.
144
+ */
145
+ function propsReads(
146
+ component: ts.Node,
147
+ propsObjectName: string,
148
+ isPropsObject: (receiver: ts.Identifier) => boolean,
149
+ ): PropsRead[] {
150
+ const reads: PropsRead[] = []
151
+ function visit(node: ts.Node): void {
152
+ const read = propsReadKey(node, propsObjectName)
153
+ if (read && isPropsObject(read.receiver)) {
154
+ reads.push({ name: read.key === null ? null : read.key.toLowerCase(), pos: node.getStart() })
155
+ }
156
+ ts.forEachChild(node, visit)
157
+ }
158
+ visit(component)
159
+ return reads
160
+ }
161
+
162
+ /** The prop names the reads spell; a computed-key read names none. */
163
+ function readNames(reads: readonly PropsRead[]): string[] {
164
+ return reads.flatMap(r => (r.name === null ? [] : [r.name]))
165
+ }
166
+
167
+ /**
168
+ * Whether `binding`, declared by `declaration`, must leave the prop's
169
+ * name. A self-derived binding shares the prop's template variable only
170
+ * while nothing else reads the raw prop: a `props.<name>` read outside its
171
+ * own initializer would otherwise see the derived value. A computed-key
172
+ * read (`props[k]`) may read that prop, so it counts too.
173
+ */
174
+ function needsSeparation(binding: SeparatedBinding, declaration: ts.VariableDeclaration, reads: readonly PropsRead[]): boolean {
175
+ if (!binding.selfDerived) return true
176
+ const init = declaration.initializer
177
+ const name = binding.name.toLowerCase()
178
+ return reads.some(r => (r.name === null || r.name === name) && (!init || r.pos < init.getStart() || r.pos >= init.getEnd()))
179
+ }
180
+
104
181
  /**
105
182
  * A prop and a signal getter or memo of the same name are different JS
106
183
  * bindings (`props.label` and `label()`), but scalar template backends
@@ -119,15 +196,29 @@ export function separateSignalPropBindings(
119
196
  ctx: AnalyzerContext,
120
197
  isNonReference: (id: ts.Identifier) => boolean,
121
198
  ): string | null {
122
- if (!ctx.propsObjectName || !ctx.componentNode) return null
123
- const candidates = collidingBindings(ctx, ctx.propsObjectName)
124
- if (candidates.length === 0) return null
199
+ const propsObjectName = ctx.propsObjectName
200
+ const component = ctx.componentNode
201
+ if (!propsObjectName || !component) return null
202
+ const declared = ctx.propsParams.map(p => p.name.toLowerCase())
203
+ // Every same-spelled read is a candidate before binding resolution, so
204
+ // the checker is built only when some binding can collide.
205
+ const spelled = readNames(propsReads(component, propsObjectName, () => true))
206
+ if (collidingBindings(ctx, propsObjectName, new Set([...declared, ...spelled])).length === 0) return null
125
207
 
126
208
  const sf = ctx.sourceFile
127
209
  const checker = ctx.checker ?? ts.createProgram([sf.fileName], { noLib: true, noResolve: true }, {
128
210
  ...ts.createCompilerHost({ noLib: true, noResolve: true }),
129
211
  getSourceFile: () => sf,
130
212
  }).getTypeChecker()
213
+ // A read counts only when its receiver is the props parameter, not a
214
+ // callback parameter or local that shadows the name.
215
+ const param = component.parameters.find(p => ts.isIdentifier(p.name) && p.name.text === propsObjectName)
216
+ const paramSymbol = param && checker.getSymbolAtLocation(param.name)
217
+ const reads = paramSymbol
218
+ ? propsReads(component, propsObjectName, id => checker.getSymbolAtLocation(id) === paramSymbol)
219
+ : []
220
+ const candidates = collidingBindings(ctx, propsObjectName, new Set([...declared, ...readNames(reads)]))
221
+ if (candidates.length === 0) return null
131
222
  const occupied = new Set<string>()
132
223
  function collectNames(node: ts.Node): void {
133
224
  // Also avoid case-fold collisions introduced by backend field naming.
@@ -145,7 +236,7 @@ export function separateSignalPropBindings(
145
236
  function collectBindings(node: ts.Node): void {
146
237
  if (ts.isVariableDeclaration(node)) {
147
238
  const binding = declarations.get(node.getStart(sf))
148
- if (binding) {
239
+ if (binding && needsSeparation(binding, node, reads)) {
149
240
  const names = ts.isIdentifier(node.name) ? [node.name]
150
241
  : ts.isArrayBindingPattern(node.name)
151
242
  ? node.name.elements.flatMap(e => ts.isBindingElement(e) && ts.isIdentifier(e.name) ? [e.name] : [])
@@ -164,7 +255,7 @@ export function separateSignalPropBindings(
164
255
  }
165
256
  ts.forEachChild(node, collectBindings)
166
257
  }
167
- collectBindings(ctx.componentNode)
258
+ collectBindings(component)
168
259
 
169
260
  const edits: { start: number; end: number; text: string }[] = []
170
261
  function collectEdits(node: ts.Node): void {
@@ -180,7 +271,7 @@ export function separateSignalPropBindings(
180
271
  }
181
272
  ts.forEachChild(node, collectEdits)
182
273
  }
183
- collectEdits(ctx.componentNode)
274
+ collectEdits(component)
184
275
  if (edits.length === 0) return null
185
276
  let source = sf.text
186
277
  for (const edit of edits.sort((a, b) => b.start - a.start)) {
@@ -176,10 +176,14 @@ function addPropSsrDefaults(
176
176
  // A prop whose default reads an earlier prop (`{ off = false, on = !off }`,
177
177
  // #3531) and that the seed plan re-binds in-template: its value depends on
178
178
  // what the caller passed, so no static value is right, and a non-null seed
179
- // would read as caller-supplied to the template's own `on ?? !off`.
179
+ // would read as caller-supplied to the template's own `on ?? !off`. A
180
+ // computed default that reads no earlier prop (`{ b = 'abc'.length }`)
181
+ // keeps its static value when it has one: that value is the default
182
+ // itself, so the template's `b ?? <default>` yields the same.
180
183
  const plan = metadata.ssrSeedPlan ?? computeSsrSeedPlan(metadata)
184
+ const readsEarlier = new Set(metadata.propsParams.filter(p => p.defaultParts).map(p => p.name))
181
185
  const templateDefaulted = new Set(
182
- plan.steps.filter(s => s.kind === 'derived' && s.origin === 'prop').map(s => s.name),
186
+ plan.steps.filter(s => s.kind === 'derived' && s.origin === 'prop' && readsEarlier.has(s.name)).map(s => s.name),
183
187
  )
184
188
  for (const p of metadata.propsParams) {
185
189
  if (p.isRest) continue
@@ -487,8 +491,10 @@ export function localConstValuesByName(metadata: Pick<IRMetadata, 'localConstant
487
491
  *
488
492
  * Also the analyzer's test for which same-named signal/memo keeps sharing
489
493
  * the prop's template variable (`separateSignalPropBindings`): a binding
490
- * this answers `false` for is renamed before IR is built, so the two
491
- * callers cannot disagree about which collisions stay collapsed.
494
+ * this answers `false` for is renamed before IR is built, and so is one it
495
+ * answers `true` for when the component also reads the raw prop elsewhere.
496
+ * A renamed binding no longer matches here, so the two callers cannot
497
+ * disagree about which collisions stay collapsed.
492
498
  */
493
499
  export function referencesOwnProp(
494
500
  expr: string | undefined,
@@ -44,6 +44,7 @@ import {
44
44
  stringifyParsedExpr,
45
45
  type ParsedExpr,
46
46
  } from './expression-parser.ts'
47
+ import { templatePropReadParams } from './props-binding.ts'
47
48
  import type { IRMetadata, ParamInfo } from './types.ts'
48
49
  import { isElidedFactoryGetter } from './types.ts'
49
50
 
@@ -216,31 +217,95 @@ function memoSeedExpr(memo: IRMetadata['memos'][number]): string {
216
217
  }
217
218
 
218
219
  /**
219
- * A `derived` step per prop whose destructure default reads an earlier prop of
220
- * the same pattern (`ParamInfo.defaultParts`, #3531): `on ?? <default>`, where
221
- * the default's identifiers are the earlier props' template variables. Every
222
- * prop is already in `available` (baseScope), and the steps run in dependency
223
- * order ({@link inDefaultReadOrder}), so a chain (`{ a = 1, b = a, c = b }`)
224
- * reads `b` after its own step re-bound it. A default the plan cannot lower
225
- * (or a function default) adds no step and keeps the static ssr-defaults
226
- * seed. A callback inside the default (`a.filter((x) => …)`) does not make
227
- * it a function default.
220
+ * Whether `p`'s destructure default is computed when the prop is absent: a
221
+ * default that is neither a function nor literal data
222
+ * ({@link isLiteralData}). A default reading an earlier prop
223
+ * (`ParamInfo.defaultParts`, `{ a, b = a }`) is one, and so is one that
224
+ * calls or reads anything else (`{ b = ['y', ''].filter((x) => x !== '') }`,
225
+ * `{ n = 'abc'.length }`, `{ m = DEFAULT }`). A callback inside the default
226
+ * does not make it a function default.
227
+ *
228
+ * Every backend applies such a default when it renders (the SSR seed plan's
229
+ * prop steps, Go's props constructor) instead of a value fixed at compile
230
+ * time, which only literal data has.
228
231
  */
229
- function dependentPropDefaultSteps(
230
- metadata: IRMetadata,
231
- available: ReadonlySet<string>,
232
- inlined: ReadonlySet<string>,
233
- ): SsrSeedStep[] {
232
+ export function hasComputedDefault(p: ParamInfo): boolean {
233
+ if (p.isRest || p.defaultValue === undefined || !p.parsed || p.parsed.kind === 'arrow') return false
234
+ return p.defaultParts !== undefined || !isLiteralData(p.parsed)
235
+ }
236
+
237
+ /**
238
+ * A literal (`'x'`, `-1`, `null`, `undefined`), a template literal with no
239
+ * substitution, or an array / object literal of literal data: a value that
240
+ * reads and calls nothing.
241
+ */
242
+ function isLiteralData(e: ParsedExpr): boolean {
243
+ switch (e.kind) {
244
+ case 'literal':
245
+ return true
246
+ case 'identifier':
247
+ return e.name === 'undefined'
248
+ case 'unary':
249
+ return (e.op === '-' || e.op === '+') && e.argument.kind === 'literal' && e.argument.literalType === 'number'
250
+ case 'template-literal':
251
+ return e.parts.every(part => part.type === 'string')
252
+ case 'array-literal':
253
+ return e.elements.every(isLiteralData)
254
+ case 'object-literal':
255
+ return e.properties.every(prop => prop.kind !== 'spread' && isLiteralData(prop.value))
256
+ default:
257
+ return false
258
+ }
259
+ }
260
+
261
+ /**
262
+ * A `derived` step per prop with a computed destructure default
263
+ * ({@link hasComputedDefault}): `on ?? <default>`. A default reading an
264
+ * earlier prop of the same pattern (`ParamInfo.defaultParts`, #3531) reads
265
+ * the earlier props' template variables. Every prop is already in
266
+ * `available` (baseScope), and the steps run in dependency order
267
+ * ({@link inDefaultReadOrder}), so a chain (`{ a = 1, b = a, c = b }`) reads
268
+ * `b` after its own step re-bound it. A default the plan cannot lower adds
269
+ * no step and keeps the static ssr-defaults seed.
270
+ */
271
+ function dependentPropDefaultSteps(metadata: IRMetadata, inlined: ReadonlySet<string>): SsrSeedStep[] {
272
+ const { readable, available, unshadowed } = propDefaultScope(metadata, inlined)
234
273
  const steps: SsrSeedStep[] = []
235
274
  for (const p of inDefaultReadOrder(metadata.propsParams)) {
236
- if (p.isRest || !p.defaultParts || !p.parsed || p.parsed.kind === 'arrow') continue
275
+ if (!hasComputedDefault(p) || !p.parsed || !readable.has(p.name)) continue
237
276
  const parsed: ParsedExpr = { kind: 'logical', op: '??', left: { kind: 'identifier', name: p.name }, right: p.parsed }
238
- const step = classify(p.name, 'prop', stringifyParsedExpr(parsed), parsed, available, inlined)
277
+ const step = classify(p.name, 'prop', stringifyParsedExpr(parsed), parsed, available, unshadowed)
239
278
  if (step.kind === 'derived') steps.push(step)
240
279
  }
241
280
  return steps
242
281
  }
243
282
 
283
+ /**
284
+ * The names a prop default step may read: the props a template reads as
285
+ * their live prop (`templatePropReadParams`, so a binding that a local of
286
+ * the same name shadows gets no step), the props object, and the module
287
+ * string consts no component-scope binding shadows (`const DEF = 'z'` in
288
+ * the body hides a module `DEF`, whatever the declaration order).
289
+ */
290
+ function propDefaultScope(
291
+ metadata: IRMetadata,
292
+ inlined: ReadonlySet<string>,
293
+ ): { readable: ReadonlySet<string>; available: ReadonlySet<string>; unshadowed: ReadonlySet<string> } {
294
+ const readable = new Set(templatePropReadParams(metadata).map(p => p.name))
295
+ const locals = new Set<string>()
296
+ for (const c of metadata.localConstants ?? []) if (!c.isModule) locals.add(c.name)
297
+ for (const f of metadata.localFunctions ?? []) if (!f.isModule) locals.add(f.name)
298
+ for (const s of metadata.signals) {
299
+ locals.add(s.getter)
300
+ if (s.setter) locals.add(s.setter)
301
+ }
302
+ for (const m of metadata.memos) locals.add(m.name)
303
+ const unshadowed = new Set([...inlined].filter(name => !locals.has(name)))
304
+ const available = new Set([...readable, ...unshadowed])
305
+ if (metadata.propsObjectName) available.add(metadata.propsObjectName)
306
+ return { readable, available, unshadowed }
307
+ }
308
+
244
309
  /**
245
310
  * `params` with every prop placed after the props its destructure default
246
311
  * reads (`ParamInfo.defaultParts`). `propsParams` follows the props TYPE's
@@ -278,7 +343,7 @@ export function computeSsrSeedPlan(metadata: IRMetadata): SsrSeedPlan {
278
343
  const localConsts = localConstExprsByName(metadata)
279
344
  const steps: SsrSeedStep[] = []
280
345
 
281
- steps.push(...dependentPropDefaultSteps(metadata, available, inlined))
346
+ steps.push(...dependentPropDefaultSteps(metadata, inlined))
282
347
 
283
348
  for (const signal of metadata.signals) {
284
349
  if (signal.envReader) {
@@ -14,7 +14,7 @@ import type { IRTemplatePart } from './types.ts'
14
14
 
15
15
  export interface TemplatePartsToJsOptions {
16
16
  /**
17
- * Prefer each part's prop-rewritten projection (`templateValue` /
17
+ * Prefer each part's prop-rewritten projection (`templateExpr` /
18
18
  * `templateCondition` / `templateKey`, i.e. destructured props rewritten
19
19
  * to `_p.X`) when present. Used by the client-JS / module-registration
20
20
  * template emitters, which run outside the component's destructured scope.
@@ -60,6 +60,26 @@ export function lookupPartToJsExpr(
60
60
  return `(${obj}${typed})[${key}]`
61
61
  }
62
62
 
63
+ /**
64
+ * Spell a `ternary` part's branch — the literal's COOKED value, as the IR
65
+ * carries it — as a single-quoted JS string literal. The cooked value of
66
+ * `'a\nb'` holds a real newline and that of `"it's"` a bare quote, so
67
+ * wrapping it in quotes unescaped yields an unterminated or unbalanced
68
+ * literal. Escapes only what a single-quoted literal cannot hold raw (the
69
+ * backslash, the quote and the line terminators), so a branch without
70
+ * them prints exactly as before.
71
+ */
72
+ function singleQuotedJsString(value: string): string {
73
+ const body = value
74
+ .replace(/\\/g, '\\\\')
75
+ .replace(/'/g, "\\'")
76
+ .replace(/\n/g, '\\n')
77
+ .replace(/\r/g, '\\r')
78
+ .replace(/\u2028/g, '\\u2028')
79
+ .replace(/\u2029/g, '\\u2029')
80
+ return `'${body}'`
81
+ }
82
+
63
83
  /** Convert a `template` variant's parts into a JS template-literal string. */
64
84
  export function templatePartsToJsExpr(
65
85
  parts: readonly IRTemplatePart[],
@@ -68,10 +88,12 @@ export function templatePartsToJsExpr(
68
88
  let result = '`'
69
89
  for (const part of parts) {
70
90
  if (part.type === 'string') {
71
- result += (opts?.useTemplate && part.templateValue) ? part.templateValue : part.value
91
+ result += part.value.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$\{/g, '\\${').replace(/\r/g, '\\r')
92
+ } else if (part.type === 'expression') {
93
+ result += `\${${opts?.useTemplate ? part.templateExpr ?? part.expr : part.expr}}`
72
94
  } else if (part.type === 'ternary') {
73
95
  const cond = (opts?.useTemplate && part.templateCondition) ? part.templateCondition : part.condition
74
- result += `\${${cond} ? '${part.whenTrue}' : '${part.whenFalse}'}`
96
+ result += `\${${cond} ? ${singleQuotedJsString(part.whenTrue)} : ${singleQuotedJsString(part.whenFalse)}}`
75
97
  } else if (part.type === 'lookup') {
76
98
  result += `\${${lookupPartToJsExpr(part, opts)}}`
77
99
  }
@@ -105,7 +105,9 @@ function walkTemplateParts(
105
105
  visit({ expr: parseExpression(trimmed), loc, role: 'template-part', attrName })
106
106
  }
107
107
  for (const part of parts) {
108
- if (part.type === 'ternary') {
108
+ if (part.type === 'expression') {
109
+ visit({ expr: part.parsed, loc, role: 'template-part', attrName })
110
+ } else if (part.type === 'ternary') {
109
111
  visitText(part.condition)
110
112
  visitText(part.whenTrue)
111
113
  visitText(part.whenFalse)
package/src/types.ts CHANGED
@@ -102,6 +102,16 @@ export interface PropertyInfo {
102
102
  export interface ParamInfo {
103
103
  name: string
104
104
  type: TypeInfo
105
+ /**
106
+ * The binding's declared type when `type` is `unknown` only because a
107
+ * destructured binding's declared type does not resolve to a concrete
108
+ * representation (`isResolvableMemberType` declines a union such as
109
+ * `n?: number | null`). `type` stays `unknown` so typed backends keep
110
+ * their untyped field; a reader that classifies the value's nil from the
111
+ * declaration (`collectNullishAttrContext`) reads this, as it reads
112
+ * `type` for the `props.n` form.
113
+ */
114
+ declaredType?: TypeInfo
105
115
  optional: boolean
106
116
  defaultValue?: JsSourceText
107
117
  /**
@@ -522,6 +532,17 @@ export interface IRExpression {
522
532
  * escaping it, while a non-empty fallback stays escaped text.
523
533
  */
524
534
  childrenRead?: 'bare' | 'nullish-empty' | 'nullish-fallback' | 'or-fallback'
535
+ /**
536
+ * A child-position read, inside a loop row, of one of the component's own
537
+ * props other than `children` (`{props.footer}`, a destructured `{footer}`,
538
+ * or a const alias of either), not shadowed by a row binding. Decided once
539
+ * in Phase 1 from the binding. The caller may pass a JSX element at that
540
+ * prop, which reaches the client as a `bfMarkup()` value or a `__slot()`
541
+ * marker, so the client writes the row slot as markup, exactly like the
542
+ * same read outside a loop. A row's own data (the item, a preamble local)
543
+ * is never flagged and stays escaped text.
544
+ */
545
+ loopRowPropRead?: true
525
546
  /** When true, expression calls signal getters or memos (has reactive `foo()` pattern). */
526
547
  callsReactiveGetters?: boolean
527
548
  /** When true, expression contains function call(s) — any `identifier()` pattern (computed from AST). */
@@ -1338,7 +1359,8 @@ export interface IRIfStatement {
1338
1359
  // =============================================================================
1339
1360
 
1340
1361
  export type IRTemplatePart =
1341
- | { type: 'string'; value: string; templateValue?: string }
1362
+ | { type: 'string'; value: string }
1363
+ | { type: 'expression'; expr: JsSourceText; templateExpr?: JsSourceText; parsed: ParsedExpr }
1342
1364
  | { type: 'ternary'; condition: string; templateCondition?: string; whenTrue: string; whenFalse: string }
1343
1365
  /**
1344
1366
  * `${MAP[KEY]}` indexed lookup against a `Record<T, string>` literal
@@ -1480,6 +1502,15 @@ export interface SpreadAttr {
1480
1502
  * per-key expansion earlier and leave this unset (#1407).
1481
1503
  */
1482
1504
  slotId?: string
1505
+ /**
1506
+ * Set on a child-component call's spread (`<Child {...props} />`) whose
1507
+ * source is the component's own props object, through any alias hop
1508
+ * (`resolveRestSpreadOriginCore` → `'props'`). Such a spread carries
1509
+ * exactly the keys the caller passed, so the client JS merges it with the
1510
+ * call's explicit props in source order, as JS does (#3688). Unset for
1511
+ * any other spread, including a `{...rest}` bag.
1512
+ */
1513
+ propsObject?: true
1483
1514
  }
1484
1515
 
1485
1516
  export interface JsxChildrenAttr {