@barefootjs/jsx 0.39.7 → 0.39.9

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 (192) hide show
  1. package/dist/adapters/callback-method.d.ts +36 -7
  2. package/dist/adapters/callback-method.d.ts.map +1 -1
  3. package/dist/adapters/component-props.d.ts +80 -13
  4. package/dist/adapters/component-props.d.ts.map +1 -1
  5. package/dist/adapters/dsl-template-adapter.d.ts +153 -0
  6. package/dist/adapters/dsl-template-adapter.d.ts.map +1 -0
  7. package/dist/adapters/jsx-adapter.d.ts +4 -0
  8. package/dist/adapters/jsx-adapter.d.ts.map +1 -1
  9. package/dist/adapters/literal-value.d.ts +2 -2
  10. package/dist/adapters/literal-value.d.ts.map +1 -1
  11. package/dist/adapters/loop-plan.d.ts +133 -9
  12. package/dist/adapters/loop-plan.d.ts.map +1 -1
  13. package/dist/adapters/parsed-expr-emitter.d.ts +44 -0
  14. package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
  15. package/dist/adapters/style-object.d.ts +33 -0
  16. package/dist/adapters/style-object.d.ts.map +1 -0
  17. package/dist/analyzer.d.ts.map +1 -1
  18. package/dist/assignment-target.d.ts +26 -0
  19. package/dist/assignment-target.d.ts.map +1 -0
  20. package/dist/children-nullish.d.ts +22 -0
  21. package/dist/children-nullish.d.ts.map +1 -0
  22. package/dist/errors.d.ts +2 -0
  23. package/dist/errors.d.ts.map +1 -1
  24. package/dist/expression-parser.d.ts +9 -19
  25. package/dist/expression-parser.d.ts.map +1 -1
  26. package/dist/free-refs.d.ts +6 -0
  27. package/dist/free-refs.d.ts.map +1 -1
  28. package/dist/index.d.ts +17 -14
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +15040 -13899
  31. package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
  33. package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts +2 -1
  34. package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts.map +1 -1
  35. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -2
  36. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
  37. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +24 -1
  38. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
  39. package/dist/ir-to-client-js/control-flow/shared.d.ts +16 -1
  40. package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
  41. package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts +6 -1
  42. package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
  43. package/dist/ir-to-client-js/control-flow/stringify/event-delegation.d.ts.map +1 -1
  44. package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts +10 -9
  45. package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
  46. package/dist/ir-to-client-js/csr-substitute.d.ts +13 -2
  47. package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
  48. package/dist/ir-to-client-js/emit-reactive.d.ts +1 -1
  49. package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
  50. package/dist/ir-to-client-js/emit-registration.d.ts +10 -8
  51. package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
  52. package/dist/ir-to-client-js/generate-init.d.ts.map +1 -1
  53. package/dist/ir-to-client-js/html-template.d.ts +0 -9
  54. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  55. package/dist/ir-to-client-js/identifiers.d.ts +6 -8
  56. package/dist/ir-to-client-js/identifiers.d.ts.map +1 -1
  57. package/dist/ir-to-client-js/imports.d.ts +23 -2
  58. package/dist/ir-to-client-js/imports.d.ts.map +1 -1
  59. package/dist/ir-to-client-js/phases/props-extraction.d.ts +6 -3
  60. package/dist/ir-to-client-js/phases/props-extraction.d.ts.map +1 -1
  61. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +8 -0
  62. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
  63. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +1 -1
  64. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
  65. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  66. package/dist/ir-to-client-js/rewrite-destructured-props.d.ts +1 -1
  67. package/dist/ir-to-client-js/rewrite-destructured-props.d.ts.map +1 -1
  68. package/dist/ir-to-client-js/rewrite-props-object.d.ts.map +1 -1
  69. package/dist/ir-to-client-js/safe-html.d.ts +20 -2
  70. package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
  71. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts +1 -0
  72. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
  73. package/dist/ir-to-client-js/types.d.ts +3 -3
  74. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  75. package/dist/ir-to-client-js/utils.d.ts +2 -11
  76. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  77. package/dist/jsx-to-ir.d.ts.map +1 -1
  78. package/dist/nullable-signal-attr.d.ts +40 -10
  79. package/dist/nullable-signal-attr.d.ts.map +1 -1
  80. package/dist/prop-rewrite.d.ts +35 -8
  81. package/dist/prop-rewrite.d.ts.map +1 -1
  82. package/dist/props-binding.d.ts +66 -1
  83. package/dist/props-binding.d.ts.map +1 -1
  84. package/dist/scanner/js-scanner.d.ts.map +1 -1
  85. package/dist/scanner/js-scanner.js +30 -2
  86. package/dist/scope/binding-scope.d.ts +30 -2
  87. package/dist/scope/binding-scope.d.ts.map +1 -1
  88. package/dist/scope/lexical-scope-walk.d.ts +26 -0
  89. package/dist/scope/lexical-scope-walk.d.ts.map +1 -0
  90. package/dist/signal-prop-name-collision.d.ts +6 -5
  91. package/dist/signal-prop-name-collision.d.ts.map +1 -1
  92. package/dist/ssr-defaults.d.ts +28 -0
  93. package/dist/ssr-defaults.d.ts.map +1 -1
  94. package/dist/ssr-seed-plan.d.ts +39 -14
  95. package/dist/ssr-seed-plan.d.ts.map +1 -1
  96. package/dist/types.d.ts +133 -19
  97. package/dist/types.d.ts.map +1 -1
  98. package/dist/value-references.d.ts +21 -0
  99. package/dist/value-references.d.ts.map +1 -1
  100. package/package.json +2 -2
  101. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +18 -18
  102. package/src/__tests__/adapter-output.test.ts +5 -3
  103. package/src/__tests__/analyzer.test.ts +33 -0
  104. package/src/__tests__/arithmetic-lowering.test.ts +48 -0
  105. package/src/__tests__/binding-scope.test.ts +29 -0
  106. package/src/__tests__/children-read.test.ts +226 -0
  107. package/src/__tests__/client-template-escape-soundness.test.ts +31 -1
  108. package/src/__tests__/component-props.test.ts +68 -1
  109. package/src/__tests__/constant-inlining-tree.test.ts +136 -0
  110. package/src/__tests__/create-query.test.ts +1 -1
  111. package/src/__tests__/destructure-default-reads-earlier-param.test.ts +138 -0
  112. package/src/__tests__/dsl-template-adapter.test.ts +173 -0
  113. package/src/__tests__/emit-to-string-call.test.ts +58 -0
  114. package/src/__tests__/event-handler-verbatim.test.ts +73 -0
  115. package/src/__tests__/expression-parser.test.ts +1 -44
  116. package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +90 -31
  117. package/src/__tests__/loop-plan.test.ts +131 -1
  118. package/src/__tests__/loop-row-child-children-handler.test.ts +129 -0
  119. package/src/__tests__/loop-row-child-children-inner-loop-shadow.test.ts +74 -0
  120. package/src/__tests__/loop-row-child-children-ref.test.ts +117 -0
  121. package/src/__tests__/nullable-signal-attr.test.ts +67 -3
  122. package/src/__tests__/props-alias-const.test.ts +60 -1
  123. package/src/__tests__/props-named-callback-param.test.ts +256 -0
  124. package/src/__tests__/reference-graph-identifiers.test.ts +161 -0
  125. package/src/__tests__/renamed-body-destructure-template.test.ts +86 -0
  126. package/src/__tests__/rewrite-props-object.test.ts +90 -0
  127. package/src/__tests__/runtime-import-detection.test.ts +134 -0
  128. package/src/__tests__/signal-prop-name-collision.test.ts +30 -0
  129. package/src/__tests__/ssr-defaults.test.ts +19 -1
  130. package/src/__tests__/ssr-seed-plan.test.ts +119 -0
  131. package/src/__tests__/style-object-plan.test.ts +54 -0
  132. package/src/__tests__/written-binding-substitution.test.ts +430 -0
  133. package/src/__tests__/zero-param-helper-inline.test.ts +57 -0
  134. package/src/adapters/callback-method.ts +48 -10
  135. package/src/adapters/component-props.ts +130 -12
  136. package/src/adapters/dsl-template-adapter.ts +259 -0
  137. package/src/adapters/jsx-adapter.ts +12 -6
  138. package/src/adapters/literal-value.ts +2 -2
  139. package/src/adapters/loop-plan.ts +201 -13
  140. package/src/adapters/parsed-expr-emitter.ts +67 -0
  141. package/src/adapters/style-object.ts +61 -0
  142. package/src/analyzer.ts +396 -16
  143. package/src/assignment-target.ts +79 -0
  144. package/src/children-nullish.ts +33 -0
  145. package/src/debug.ts +2 -2
  146. package/src/errors.ts +23 -0
  147. package/src/expression-parser.ts +56 -53
  148. package/src/free-refs.ts +28 -17
  149. package/src/index.ts +31 -10
  150. package/src/ir-to-client-js/compute-inlinability.ts +35 -5
  151. package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +21 -5
  152. package/src/ir-to-client-js/control-flow/plan/event-collision.ts +2 -1
  153. package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -2
  154. package/src/ir-to-client-js/control-flow/plan/loop.ts +25 -1
  155. package/src/ir-to-client-js/control-flow/shared.ts +41 -3
  156. package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +23 -3
  157. package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +3 -2
  158. package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +13 -12
  159. package/src/ir-to-client-js/csr-substitute.ts +82 -24
  160. package/src/ir-to-client-js/emit-reactive.ts +3 -3
  161. package/src/ir-to-client-js/emit-registration.ts +34 -58
  162. package/src/ir-to-client-js/generate-init.ts +17 -1
  163. package/src/ir-to-client-js/html-template.ts +48 -57
  164. package/src/ir-to-client-js/identifiers.ts +75 -24
  165. package/src/ir-to-client-js/imports.ts +56 -19
  166. package/src/ir-to-client-js/index.ts +2 -1
  167. package/src/ir-to-client-js/phases/event-handlers.ts +2 -2
  168. package/src/ir-to-client-js/phases/props-extraction.ts +39 -17
  169. package/src/ir-to-client-js/plan/build-declaration-emit.ts +2 -2
  170. package/src/ir-to-client-js/plan/build-static-array-child-init.ts +7 -0
  171. package/src/ir-to-client-js/plan/static-array-child-init.ts +8 -0
  172. package/src/ir-to-client-js/prune-unused-prop-extractions.ts +7 -4
  173. package/src/ir-to-client-js/reactivity.ts +2 -2
  174. package/src/ir-to-client-js/rewrite-destructured-props.ts +22 -5
  175. package/src/ir-to-client-js/rewrite-props-object.ts +14 -8
  176. package/src/ir-to-client-js/safe-html.ts +29 -35
  177. package/src/ir-to-client-js/stringify/static-array-child-init.ts +4 -1
  178. package/src/ir-to-client-js/types.ts +3 -2
  179. package/src/ir-to-client-js/utils.ts +42 -122
  180. package/src/jsx-to-ir.ts +310 -90
  181. package/src/nullable-signal-attr.ts +149 -33
  182. package/src/prop-rewrite.ts +72 -72
  183. package/src/props-binding.ts +90 -3
  184. package/src/scanner/__tests__/js-scanner.test.ts +37 -0
  185. package/src/scanner/js-scanner.ts +64 -4
  186. package/src/scope/binding-scope.ts +34 -3
  187. package/src/scope/lexical-scope-walk.ts +167 -0
  188. package/src/signal-prop-name-collision.ts +50 -24
  189. package/src/ssr-defaults.ts +47 -20
  190. package/src/ssr-seed-plan.ts +103 -23
  191. package/src/types.ts +140 -20
  192. package/src/value-references.ts +132 -0
@@ -8,9 +8,11 @@
8
8
  * template adapters' seed paths; this module computes it once, on the IR, so
9
9
  * every adapter consumes the same plan and only supplies its own syntax.
10
10
  *
11
- * Ordering / acyclicity guarantee: `steps` lists the component's signals
12
- * first, then its memos, each group in declaration order (matching
13
- * `IRMetadata.signals` / `IRMetadata.memos`), then canonical getter aliases.
11
+ * Ordering / acyclicity guarantee: `steps` lists the props whose destructure
12
+ * default reads an earlier prop first, in parameter order, then the
13
+ * component's signals, then its memos, each group in declaration order
14
+ * (matching `IRMetadata.signals` / `IRMetadata.memos`), then canonical getter
15
+ * aliases.
14
16
  * A binding's name only enters
15
17
  * the scope set AFTER its own step is decided, so a `derived` step's `frees`
16
18
  * can only name `baseScope` entries or EARLIER steps — self- and
@@ -22,11 +24,11 @@
22
24
  * literal value — `collectModuleStringConsts` is the shared source of that
23
25
  * set — so a reference to one is never a template-variable read.
24
26
  *
25
- * A `derived` step with EMPTY `frees` is a constant expression (e.g.
26
- * `createSignal('b')`): the plan still classifies it as derived because the
27
- * expression is fully analyzable; emit-side constant-skipping (adapters keep
28
- * their existing ssr-defaults seeding for such inits) is an adapter concern,
29
- * not a plan concern. Likewise the plan makes no backend-specific choices —
27
+ * A `derived` step whose `frees` name only module pure-string consts (or
28
+ * nothing, e.g. `createSignal('b')`) is a constant expression, marked
29
+ * `constant`: the plan still classifies it as derived because the expression
30
+ * is fully analyzable, and adapters keep their static ssr-defaults seed for
31
+ * it instead of computing it in-template. Likewise the plan makes no backend-specific choices —
30
32
  * no target-variable checks, no self-shadowing rules, no per-backend shape
31
33
  * catalogs — those stay in the adapters.
32
34
  */
@@ -42,12 +44,13 @@ import {
42
44
  stringifyParsedExpr,
43
45
  type ParsedExpr,
44
46
  } from './expression-parser.ts'
45
- import type { IRMetadata } from './types.ts'
47
+ import type { IRMetadata, ParamInfo } from './types.ts'
46
48
  import { isElidedFactoryGetter } from './types.ts'
47
49
 
48
50
  /**
49
- * One binding in dependency order (signals, memos, then getter aliases —
50
- * matching `IRMetadata` order and the adapters' iteration).
51
+ * One binding in dependency order (dependent prop defaults, signals, memos,
52
+ * then getter aliases — matching `IRMetadata` order and the adapters'
53
+ * iteration).
51
54
  *
52
55
  * - `env-reader`: an env signal whose `envReader` key resolves in the shared
53
56
  * registry (`envSignalReaderFor`). The runtime provides the per-request
@@ -56,7 +59,12 @@ import { isElidedFactoryGetter } from './types.ts'
56
59
  * registry falls through to the normal derived/opaque rules instead.
57
60
  * - `derived`: the binding's value expression is a supported shape whose free
58
61
  * identifiers are all in scope at this point (baseScope + earlier steps) —
59
- * an adapter may seed it in-template by lowering `parsed`/`expr`.
62
+ * an adapter may seed it in-template by lowering `parsed`/`expr`. An
63
+ * `origin: 'prop'` step re-binds a prop whose destructure default reads an
64
+ * earlier prop (`{ off = false, on = off }` → `on ?? off`, #3531): the
65
+ * static ssr-defaults seed cannot hold a value that depends on what the
66
+ * caller passed, so the template applies the default itself, reading the
67
+ * earlier prop's template variable.
60
68
  * - `opaque`: not seedable this way (empty init, unsupported shape,
61
69
  * unanalyzable free set, out-of-scope reference, or a block-bodied memo).
62
70
  * The name still enters scope for later steps; adapters keep their static
@@ -64,8 +72,21 @@ import { isElidedFactoryGetter } from './types.ts'
64
72
  */
65
73
  export type SsrSeedStep =
66
74
  | { kind: 'env-reader'; name: string; reader: EnvSignalReader }
67
- | { kind: 'derived'; name: string; origin: 'signal' | 'memo'; expr: string; parsed: ParsedExpr; frees: string[] }
68
- | { kind: 'opaque'; name: string; origin: 'signal' | 'memo' }
75
+ | {
76
+ kind: 'derived'
77
+ name: string
78
+ origin: 'signal' | 'memo' | 'prop'
79
+ expr: string
80
+ parsed: ParsedExpr
81
+ frees: string[]
82
+ /**
83
+ * Every free identifier is a module pure-string const, which every
84
+ * adapter inlines, so the lowered expression reads no template
85
+ * variable (#3542).
86
+ */
87
+ constant: boolean
88
+ }
89
+ | { kind: 'opaque'; name: string; origin: 'signal' | 'memo' | 'prop' }
69
90
 
70
91
  export interface SsrSeedPlan {
71
92
  /**
@@ -92,18 +113,21 @@ export interface SsrSeedPlan {
92
113
  */
93
114
  function classify(
94
115
  name: string,
95
- origin: 'signal' | 'memo',
116
+ origin: 'signal' | 'memo' | 'prop',
96
117
  expr: string,
97
118
  parsed: ParsedExpr,
98
119
  available: ReadonlySet<string>,
120
+ inlined: ReadonlySet<string>,
99
121
  ): SsrSeedStep {
100
- if (!isSupportedValue(parsed).supported) return { kind: 'opaque', name, origin }
122
+ const opaque: SsrSeedStep = { kind: 'opaque', name, origin }
123
+ if (!isSupportedValue(parsed).supported) return opaque
101
124
  const frees = freeIdentifiers(parsed)
102
- if (frees === null) return { kind: 'opaque', name, origin }
125
+ if (frees === null) return opaque
103
126
  for (const free of frees) {
104
- if (!available.has(free)) return { kind: 'opaque', name, origin }
127
+ if (!available.has(free)) return opaque
105
128
  }
106
- return { kind: 'derived', name, origin, expr, parsed, frees: [...frees] }
129
+ const constant = [...frees].every(free => inlined.has(free))
130
+ return { kind: 'derived', name, origin, expr, parsed, frees: [...frees], constant }
107
131
  }
108
132
 
109
133
  /**
@@ -191,17 +215,71 @@ function memoSeedExpr(memo: IRMetadata['memos'][number]): string {
191
215
  return memo.parsed ? stringifyParsedExpr(memo.parsed) : ''
192
216
  }
193
217
 
218
+ /**
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.
228
+ */
229
+ function dependentPropDefaultSteps(
230
+ metadata: IRMetadata,
231
+ available: ReadonlySet<string>,
232
+ inlined: ReadonlySet<string>,
233
+ ): SsrSeedStep[] {
234
+ const steps: SsrSeedStep[] = []
235
+ for (const p of inDefaultReadOrder(metadata.propsParams)) {
236
+ if (p.isRest || !p.defaultParts || !p.parsed || p.parsed.kind === 'arrow') continue
237
+ 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)
239
+ if (step.kind === 'derived') steps.push(step)
240
+ }
241
+ return steps
242
+ }
243
+
244
+ /**
245
+ * `params` with every prop placed after the props its destructure default
246
+ * reads (`ParamInfo.defaultParts`). `propsParams` follows the props TYPE's
247
+ * member order for a body destructure (`const { a = 'x', b = a } = props`
248
+ * over `{ b?: string; a?: string }`), which need not be the pattern's order,
249
+ * so the order comes from the reads themselves. The reads only ever name an
250
+ * EARLIER binding of the same pattern, so they form no cycle; otherwise the
251
+ * input order is kept. Every backend applying these defaults one prop at a
252
+ * time (the in-template re-binds here, Go's constructor) uses this order.
253
+ */
254
+ export function inDefaultReadOrder(params: readonly ParamInfo[]): ParamInfo[] {
255
+ const byName = new Map(params.filter(p => !p.isRest).map(p => [p.name, p]))
256
+ const ordered: ParamInfo[] = []
257
+ const placed = new Set<ParamInfo>()
258
+ const place = (p: ParamInfo): void => {
259
+ if (placed.has(p)) return
260
+ placed.add(p)
261
+ for (const part of p.defaultParts ?? []) {
262
+ const read = part.kind === 'param' ? byName.get(part.param.name) : undefined
263
+ if (read) place(read)
264
+ }
265
+ ordered.push(p)
266
+ }
267
+ for (const p of params) place(p)
268
+ return ordered
269
+ }
270
+
194
271
  export function computeSsrSeedPlan(metadata: IRMetadata): SsrSeedPlan {
195
272
  const baseScope: string[] = metadata.propsParams.map(p => p.name)
196
273
  if (metadata.propsObjectName) baseScope.push(metadata.propsObjectName)
197
- for (const name of collectModuleStringConsts(metadata.localConstants).keys()) {
198
- baseScope.push(name)
199
- }
274
+ const inlined = new Set(collectModuleStringConsts(metadata.localConstants).keys())
275
+ baseScope.push(...inlined)
200
276
 
201
277
  const available = new Set<string>(baseScope)
202
278
  const localConsts = localConstExprsByName(metadata)
203
279
  const steps: SsrSeedStep[] = []
204
280
 
281
+ steps.push(...dependentPropDefaultSteps(metadata, available, inlined))
282
+
205
283
  for (const signal of metadata.signals) {
206
284
  if (signal.envReader) {
207
285
  const reader = envSignalReaderFor(signal.envReader)
@@ -243,6 +321,7 @@ export function computeSsrSeedPlan(metadata: IRMetadata): SsrSeedPlan {
243
321
  // undefined) equally safe.
244
322
  resolveThroughLocalConsts(signal.parsed ?? parseExpression(`(${expr})`), localConsts),
245
323
  available,
324
+ inlined,
246
325
  ),
247
326
  )
248
327
  available.add(signal.getter)
@@ -259,6 +338,7 @@ export function computeSsrSeedPlan(metadata: IRMetadata): SsrSeedPlan {
259
338
  expr,
260
339
  resolveThroughLocalConsts(memo.parsed ?? parseExpression(expr), localConsts),
261
340
  available,
341
+ inlined,
262
342
  ),
263
343
  )
264
344
  available.add(memo.name)
@@ -271,7 +351,7 @@ export function computeSsrSeedPlan(metadata: IRMetadata): SsrSeedPlan {
271
351
  for (const [alias, origin] of resolveGetterAliases(metadata.localConstants ?? [], name => getters.has(name))) {
272
352
  if (metadata.propsParams.some(p => p.name === alias)) continue
273
353
  const parsed: ParsedExpr = { kind: 'call', callee: { kind: 'identifier', name: origin }, args: [] }
274
- steps.push(classify(alias, 'memo', `${origin}()`, parsed, available))
354
+ steps.push(classify(alias, 'memo', `${origin}()`, parsed, available, inlined))
275
355
  available.add(alias)
276
356
  }
277
357
  return { baseScope, steps }
package/src/types.ts CHANGED
@@ -7,6 +7,17 @@
7
7
  import type { ParsedExpr, ParsedStatement } from './expression-parser.ts'
8
8
  import type { SsrSeedPlan } from './ssr-seed-plan.ts'
9
9
 
10
+ /**
11
+ * JS/TS source text the IR carries verbatim (an expression, a handler, a
12
+ * statement body), as written in the component. Phase 2 passes it through to
13
+ * output or reads the parsed tree beside it; it does not re-derive meaning
14
+ * from the text with regex or string search (spec/adapter-architecture.md,
15
+ * rule 1). A flavor, not a strict brand: a plain `string` is assignable, so
16
+ * producers need no cast, while a read keeps the type and the emit-parse
17
+ * ratchet counts a string operation on it (#3543).
18
+ */
19
+ export type JsSourceText = string & { readonly __jsSourceText?: 'JsSourceText' }
20
+
10
21
  /**
11
22
  * Loop-hoisted sort comparator for the `.sort().map()` / `.toSorted().map()`
12
23
  * pattern (#2018 P5). Carries the generic comparator `arrow` (params + body)
@@ -92,7 +103,7 @@ export interface ParamInfo {
92
103
  name: string
93
104
  type: TypeInfo
94
105
  optional: boolean
95
- defaultValue?: string
106
+ defaultValue?: JsSourceText
96
107
  /**
97
108
  * `defaultValue` parsed into a structured tree, mirroring `SignalInfo.parsed`
98
109
  * (Roadmap A). Attached best-effort by the analyzer (`tsNodeToParsedExpr` on
@@ -105,8 +116,30 @@ export interface ParamInfo {
105
116
  parsed?: ParsedExpr
106
117
  /** When true, the default value contains an arrow function or function expression (computed from AST). */
107
118
  defaultContainsArrow?: boolean
119
+ /**
120
+ * `defaultValue` split at each read of an EARLIER binding of the same props
121
+ * destructure (`{ off = false, on = off }` → `on`'s parts are one `param`
122
+ * part naming `off`). The analyzer resolves the references against the
123
+ * pattern's own bindings (#3531): an earlier binding is in scope for a later
124
+ * default, so its name there is that prop, never an outer name. Set only
125
+ * when the default reads at least one; `parsed` keeps the identifiers, which
126
+ * a template backend reads as the earlier props' own template variables.
127
+ */
128
+ defaultParts?: PropDefaultPart[]
108
129
  /** When true, the parameter is a rest spread (`...args`) — emit must prepend `...`. */
109
130
  isRest?: boolean
131
+ /**
132
+ * Set when the component writes the destructured binding anywhere in its
133
+ * body (`++start`, `start = clamp(start)`, `[a, b] = [b, a]`,
134
+ * `for (start of …)`), event handlers and other callbacks included. The
135
+ * binding is then a local the component owns, as in JS, not the prop: the
136
+ * client init body declares it once (`let start = _p.start ?? 0`) and reads
137
+ * and writes that local instead of the live prop read `_p.start ?? 0`,
138
+ * which no write can take (`++(_p.start ?? 0)` is a SyntaxError). Set by
139
+ * `markWrittenBindings` (analyzer.ts); read through `keepsDeclaredValue`
140
+ * (props-binding.ts).
141
+ */
142
+ reassigned?: boolean
110
143
  /**
111
144
  * Source property name for an aliased destructured prop (`{ createdAt: c }`
112
145
  * → name: 'c', sourceName: 'createdAt'). Set ONLY when the binding renames —
@@ -118,6 +151,22 @@ export interface ParamInfo {
118
151
  sourceName?: string
119
152
  }
120
153
 
154
+ /**
155
+ * One piece of a destructure default that reads an earlier binding of its own
156
+ * pattern (`ParamInfo.defaultParts`): the default's text between the reads,
157
+ * and each read as the earlier prop it names. A client-JS emitter renders a
158
+ * `param` part as that prop's own live read (`_p.off ?? false`), so the
159
+ * default never names a binding the emitted scope lacks. A `param` part
160
+ * carries what that read needs, its own `defaultParts` included, so a chain
161
+ * (`{ a = 1, b = a, c = b }`) renders without a lookup.
162
+ */
163
+ export type PropDefaultPart =
164
+ | { kind: 'text'; text: JsSourceText }
165
+ | { kind: 'param'; param: PropDefaultRead }
166
+
167
+ /** The earlier binding a `param` part reads: the fields a live prop read needs. */
168
+ export type PropDefaultRead = Pick<ParamInfo, 'name' | 'sourceName' | 'defaultValue' | 'defaultContainsArrow' | 'defaultParts'>
169
+
121
170
  // =============================================================================
122
171
  // Staged-IR primitives: Phase / Scope / Effect (#1138)
123
172
  // =============================================================================
@@ -412,7 +461,7 @@ export interface IRText {
412
461
 
413
462
  export interface IRExpression {
414
463
  type: 'expression'
415
- expr: string
464
+ expr: JsSourceText
416
465
  /**
417
466
  * Pre-transformed expr with destructured prop refs rewritten to _p.xxx
418
467
  * (for client JS templates). Carries ONLY that rewrite — never an
@@ -459,6 +508,20 @@ export interface IRExpression {
459
508
  * unification A3) is its only wiring.
460
509
  */
461
510
  preambleRegion?: boolean
511
+ /**
512
+ * How the expression reads the component's own `children` prop (#3539):
513
+ * a bare read (`children` bound by the props destructure, renamed or not,
514
+ * `<propsObject>.children`, or a body alias such as `const { children: kids }
515
+ * = props`), that read on the left of `?? ''`, on the
516
+ * left of `?? <other fallback>`, or on the left of `|| <fallback>` (#3554).
517
+ * Decided once in Phase 1 from the binding,
518
+ * so a local `const children`, a loop row named `children`, or another
519
+ * object's `.children` is never mistaken for the prop. The children value
520
+ * is pre-rendered markup: adapters that cannot tell markup from a string
521
+ * by value (ERB) and the client template's child splice read this to skip
522
+ * escaping it, while a non-empty fallback stays escaped text.
523
+ */
524
+ childrenRead?: 'bare' | 'nullish-empty' | 'nullish-fallback' | 'or-fallback'
462
525
  /** When true, expression calls signal getters or memos (has reactive `foo()` pattern). */
463
526
  callsReactiveGetters?: boolean
464
527
  /** When true, expression contains function call(s) — any `identifier()` pattern (computed from AST). */
@@ -496,7 +559,7 @@ export interface IRExpression {
496
559
 
497
560
  export interface IRConditional {
498
561
  type: 'conditional'
499
- condition: string
562
+ condition: JsSourceText
500
563
  /** Pre-transformed condition with destructured prop refs rewritten to _p.xxx. */
501
564
  templateCondition?: string
502
565
  /**
@@ -562,7 +625,7 @@ export interface IRLoop {
562
625
  * inline via placeholder substitution — see `FlatMapCallback`.
563
626
  */
564
627
  method?: 'flatMap'
565
- array: string
628
+ array: JsSourceText
566
629
  /**
567
630
  * Structured parse of `array` (`parseExpression(array.trim())`), attached
568
631
  * during IR construction so adapters lower the loop's array from the tree
@@ -577,7 +640,7 @@ export interface IRLoop {
577
640
  itemType: TypeInfo | null
578
641
  param: string
579
642
  index: string | null
580
- key: string | null
643
+ key: JsSourceText | null
581
644
  children: IRNode[]
582
645
  slotId: string | null
583
646
  /**
@@ -1024,7 +1087,7 @@ export interface PreambleValueDeclaration {
1024
1087
  */
1025
1088
  export interface PreambleRegionSource {
1026
1089
  slotId: string
1027
- expr: string
1090
+ expr: JsSourceText
1028
1091
  joinArrayChild?: boolean
1029
1092
  }
1030
1093
 
@@ -1238,7 +1301,7 @@ export interface IRAsync {
1238
1301
  export interface IRIfStatement {
1239
1302
  type: 'if-statement'
1240
1303
  /** The condition expression (e.g., "name === 'github'") */
1241
- condition: string
1304
+ condition: JsSourceText
1242
1305
  /** Pre-transformed condition with destructured prop refs rewritten to _p.xxx. */
1243
1306
  templateCondition?: string
1244
1307
  /**
@@ -1337,10 +1400,10 @@ export interface LiteralAttr {
1337
1400
  export interface ExpressionAttr {
1338
1401
  kind: 'expression'
1339
1402
  /** Source-level JS expression text (e.g. `count()`, `props.checked`). */
1340
- expr: string
1403
+ expr: JsSourceText
1341
1404
  /** `expr` with destructured prop refs rewritten to `_p.xxx`, for SSR
1342
1405
  * template inlining. Absent when no rewrite was needed. */
1343
- templateExpr?: string
1406
+ templateExpr?: JsSourceText
1344
1407
  /**
1345
1408
  * Structured parse of `expr` (`parseExpression(expr.trim())`), attached
1346
1409
  * during IR construction so adapters lower the attribute value from the tree
@@ -1364,6 +1427,21 @@ export interface ExpressionAttr {
1364
1427
  * props.
1365
1428
  */
1366
1429
  parts?: IRTemplatePart[]
1430
+ /**
1431
+ * The author's source for `expr` with its TypeScript syntax intact
1432
+ * (`store as never`, `value!`, `(v: string) => …`), for adapters that emit
1433
+ * type-checked TSX (`preserveTypes`). Set only when `expr` came from a
1434
+ * type-stripped read of the source and the two texts differ. `forExpr` is
1435
+ * the `expr` it was captured beside: a later rewrite of `expr` makes them
1436
+ * differ, and the adapter then falls back to `expr`.
1437
+ */
1438
+ typed?: TypedExprSource
1439
+ }
1440
+
1441
+ /** See {@link ExpressionAttr.typed}. */
1442
+ export interface TypedExprSource {
1443
+ tsx: TsxSourceText
1444
+ forExpr: JsSourceText
1367
1445
  }
1368
1446
 
1369
1447
  export interface BooleanAttr {
@@ -1381,7 +1459,7 @@ export interface TemplateAttr {
1381
1459
 
1382
1460
  export interface SpreadAttr {
1383
1461
  kind: 'spread'
1384
- expr: string
1462
+ expr: JsSourceText
1385
1463
  templateExpr?: string
1386
1464
  /**
1387
1465
  * Structured parse of `expr` (`parseExpression(expr.trim())`), attached
@@ -1421,7 +1499,12 @@ export const AttrValueOf = {
1421
1499
  },
1422
1500
  expression(
1423
1501
  expr: string,
1424
- opts?: { templateExpr?: string; presenceOrUndefined?: boolean; parts?: IRTemplatePart[] },
1502
+ opts?: {
1503
+ templateExpr?: string
1504
+ presenceOrUndefined?: boolean
1505
+ parts?: IRTemplatePart[]
1506
+ typed?: TypedExprSource
1507
+ },
1425
1508
  ): ExpressionAttr {
1426
1509
  return {
1427
1510
  kind: 'expression',
@@ -1429,6 +1512,7 @@ export const AttrValueOf = {
1429
1512
  ...(opts?.templateExpr !== undefined && { templateExpr: opts.templateExpr }),
1430
1513
  ...(opts?.presenceOrUndefined !== undefined && { presenceOrUndefined: opts.presenceOrUndefined }),
1431
1514
  ...(opts?.parts !== undefined && { parts: opts.parts }),
1515
+ ...(opts?.typed !== undefined && { typed: opts.typed }),
1432
1516
  }
1433
1517
  },
1434
1518
  booleanAttr(): BooleanAttr {
@@ -1550,7 +1634,12 @@ export interface IRAttribute extends AttrMeta {
1550
1634
  export interface IREvent {
1551
1635
  name: string // 'click', 'input', 'keydown'
1552
1636
  originalAttr?: string // Original JSX attribute name: 'onClick', 'onKeyDown'
1553
- handler: string // JS expression: '() => setCount(n => n + 1)'
1637
+ /**
1638
+ * JS expression: '() => setCount(n => n + 1)'. Always a single expression
1639
+ * (a comma sequence arrives parenthesized), passed verbatim as the
1640
+ * listener argument.
1641
+ */
1642
+ handler: JsSourceText
1554
1643
  loc: SourceLocation
1555
1644
  }
1556
1645
 
@@ -1593,7 +1682,7 @@ export interface SignalPropSeed {
1593
1682
  export interface SignalInfo {
1594
1683
  getter: string
1595
1684
  setter: string | null
1596
- initialValue: string
1685
+ initialValue: JsSourceText
1597
1686
  /**
1598
1687
  * `initialValue` parsed into a structured tree (Roadmap A). Attached
1599
1688
  * best-effort by the analyzer so adapters can lower a literal initial value
@@ -1725,6 +1814,18 @@ export function isElidedFactoryGetter(signal: Pick<SignalInfo, 'factory' | 'gett
1725
1814
  return Boolean(signal.factory && signal.getterElided)
1726
1815
  }
1727
1816
 
1817
+ /**
1818
+ * Whether a props param binds the component's own `children` prop. Keyed by
1819
+ * the caller-facing key (`sourceName ?? name`), so a binding renamed in the
1820
+ * destructure (`{ children: kids }`) is the children prop exactly as
1821
+ * `{ children }` is (#3572). The one answer for every site that sets the
1822
+ * children prop apart from the data props: it is content the parent
1823
+ * renders, not a reactive value, a client-side prop read or hydration data.
1824
+ */
1825
+ export function isChildrenPropParam(p: Pick<ParamInfo, 'name' | 'sourceName'>): boolean {
1826
+ return (p.sourceName ?? p.name) === 'children'
1827
+ }
1828
+
1728
1829
  /**
1729
1830
  * The async reactive factory call a signal's value comes from (#3165). Every
1730
1831
  * backend that re-emits the declaration reads this instead of assuming
@@ -1758,7 +1859,7 @@ export interface SignalFactoryCall {
1758
1859
 
1759
1860
  export interface MemoInfo {
1760
1861
  name: string
1761
- computation: string
1862
+ computation: JsSourceText
1762
1863
  /**
1763
1864
  * The expression the memo evaluates to, read from the callback node at
1764
1865
  * analysis time (#3510): the body of a zero-parameter arrow or `function`
@@ -1848,7 +1949,7 @@ export interface MemoInfo {
1848
1949
  }
1849
1950
 
1850
1951
  export interface EffectInfo {
1851
- body: string
1952
+ body: JsSourceText
1852
1953
  deps: string[]
1853
1954
  /**
1854
1955
  * When set, the effect was captured as `const <captureName> = createEffect(...)`
@@ -1861,7 +1962,7 @@ export interface EffectInfo {
1861
1962
  }
1862
1963
 
1863
1964
  export interface OnMountInfo {
1864
- body: string
1965
+ body: JsSourceText
1865
1966
  loc: SourceLocation
1866
1967
  }
1867
1968
 
@@ -1878,7 +1979,7 @@ export interface OnMountInfo {
1878
1979
  */
1879
1980
  export interface InitStatementInfo {
1880
1981
  /** Raw JS source of the statement (TypeScript types already stripped). */
1881
- body: string
1982
+ body: JsSourceText
1882
1983
  loc: SourceLocation
1883
1984
  /**
1884
1985
  * Free identifier references used by this statement. Used by the emitter
@@ -2061,7 +2162,7 @@ export interface ImportSpecifier {
2061
2162
  export interface FunctionInfo {
2062
2163
  name: string
2063
2164
  params: ParamInfo[]
2064
- body: string
2165
+ body: JsSourceText
2065
2166
  /** Body with TypeScript type annotations preserved, for .tsx output */
2066
2167
  typedBody?: string
2067
2168
  /**
@@ -2120,7 +2221,7 @@ export interface FunctionInfo {
2120
2221
 
2121
2222
  export interface ConstantInfo {
2122
2223
  name: string
2123
- value?: string
2224
+ value?: JsSourceText
2124
2225
  /**
2125
2226
  * `value` parsed into a structured tree (Roadmap A). Attached best-effort by
2126
2227
  * the analyzer (parsed from the parenthesised value so a bare object literal
@@ -2181,7 +2282,10 @@ export interface ConstantInfo {
2181
2282
  * (the declaration's initializer text) no longer reflects what the
2182
2283
  * binding actually holds by the time the rest of the component runs
2183
2284
  * (#2910). Set by `markMutatedConstants` (analyzer.ts) from
2184
- * `InitStatementInfo.mutatedIdentifiers`/`assignedIdentifiers`.
2285
+ * `InitStatementInfo.mutatedIdentifiers`/`assignedIdentifiers`, and for
2286
+ * a binding a markup expression writes during render (`{++nextId}`, a
2287
+ * `.map()` callback that increments a counter) — not an event handler,
2288
+ * which runs after render.
2185
2289
  *
2186
2290
  * Every consumer that would otherwise re-inline `value` verbatim in
2187
2291
  * place of a bare reference to `name` — `expandDynamicPropValue`,
@@ -2193,6 +2297,15 @@ export interface ConstantInfo {
2193
2297
  * was supposed to do.
2194
2298
  */
2195
2299
  mutatedAfterDeclaration?: boolean
2300
+ /**
2301
+ * Set when the component writes the binding anywhere in its body, event
2302
+ * handlers and other callbacks included — the same fact
2303
+ * `ParamInfo.reassigned` records for a destructured prop, from the same
2304
+ * pass (`markWrittenBindings`, analyzer.ts). A written binding fails
2305
+ * `keepsDeclaredValue` (props-binding.ts), the one rule for whether a
2306
+ * binding may be read as the prop it was destructured from.
2307
+ */
2308
+ reassigned?: boolean
2196
2309
  /** The kind of system construct, if the initializer is createContext() or new WeakMap(). */
2197
2310
  systemConstructKind?: 'createContext' | 'weakMap'
2198
2311
  /** Value with destructured prop refs rewritten to _p.propName, for template inlining. */
@@ -2216,6 +2329,13 @@ export interface TypeDefinition {
2216
2329
  * type aliases that aren't object types (e.g. string-literal unions).
2217
2330
  */
2218
2331
  properties?: PropertyInfo[]
2332
+ /**
2333
+ * The members of a type alias whose type is a string literal or a union of
2334
+ * string literals only (`type Mode = 'light' | 'dark'`, in any quoting or
2335
+ * layout). Absent for every other definition, a union mixing in a
2336
+ * non-string member included, so adapters need not re-read `definition`.
2337
+ */
2338
+ stringLiteralUnion?: string[]
2219
2339
  loc: SourceLocation
2220
2340
  }
2221
2341