@barefootjs/jsx 0.17.0 → 0.18.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 (88) hide show
  1. package/dist/adapters/env-signal.d.ts +42 -7
  2. package/dist/adapters/env-signal.d.ts.map +1 -1
  3. package/dist/adapters/interface.d.ts +20 -4
  4. package/dist/adapters/interface.d.ts.map +1 -1
  5. package/dist/adapters/parsed-expr-emitter.d.ts +3 -1
  6. package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
  7. package/dist/analyzer-context.d.ts.map +1 -1
  8. package/dist/analyzer.d.ts.map +1 -1
  9. package/dist/augment-inherited-props.d.ts +19 -0
  10. package/dist/augment-inherited-props.d.ts.map +1 -1
  11. package/dist/compiler.d.ts.map +1 -1
  12. package/dist/expression-parser.d.ts +48 -2
  13. package/dist/expression-parser.d.ts.map +1 -1
  14. package/dist/index.d.ts +24 -5
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +1728 -969
  17. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  18. package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
  19. package/dist/ir-to-client-js/control-flow/plan/build-loop.d.ts.map +1 -1
  20. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +9 -0
  21. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
  22. package/dist/ir-to-client-js/control-flow/stringify/loop.d.ts.map +1 -1
  23. package/dist/ir-to-client-js/control-flow/stringify/template-parse.d.ts +19 -0
  24. package/dist/ir-to-client-js/control-flow/stringify/template-parse.d.ts.map +1 -1
  25. package/dist/ir-to-client-js/emit-registration.d.ts +4 -2
  26. package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
  27. package/dist/ir-to-client-js/html-template.d.ts +41 -0
  28. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  29. package/dist/ir-to-client-js/types.d.ts +22 -1
  30. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  31. package/dist/jsx-to-ir.d.ts.map +1 -1
  32. package/dist/loop-destructure.d.ts +55 -18
  33. package/dist/loop-destructure.d.ts.map +1 -1
  34. package/dist/lowering-registry.d.ts +13 -0
  35. package/dist/lowering-registry.d.ts.map +1 -1
  36. package/dist/relocate.d.ts +28 -0
  37. package/dist/relocate.d.ts.map +1 -1
  38. package/dist/ssr-defaults.d.ts.map +1 -1
  39. package/dist/ssr-seed-plan.d.ts +84 -0
  40. package/dist/ssr-seed-plan.d.ts.map +1 -0
  41. package/dist/types.d.ts +79 -0
  42. package/dist/types.d.ts.map +1 -1
  43. package/package.json +2 -2
  44. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +284 -12
  45. package/src/__tests__/augment-inherited-props.test.ts +96 -0
  46. package/src/__tests__/compiler-runtime-contract.test.ts +11 -1
  47. package/src/__tests__/compiler-stress-1244.test.ts +13 -4
  48. package/src/__tests__/csr-substitution-safety-divergence.test.ts +137 -0
  49. package/src/__tests__/destructured-map-params.test.ts +11 -1
  50. package/src/__tests__/expression-parser.test.ts +74 -3
  51. package/src/__tests__/free-identifiers.test.ts +55 -0
  52. package/src/__tests__/ir-sort-comparator.test.ts +261 -0
  53. package/src/__tests__/loop-destructure.test.ts +313 -0
  54. package/src/__tests__/loop-hoisted-template.test.ts +235 -0
  55. package/src/__tests__/materialize-getter-calls.test.ts +58 -0
  56. package/src/__tests__/props-destructuring.test.ts +110 -0
  57. package/src/__tests__/serialize-parsed-expr.test.ts +88 -2
  58. package/src/__tests__/ssr-defaults.test.ts +20 -0
  59. package/src/__tests__/ssr-seed-plan.test.ts +212 -0
  60. package/src/__tests__/staged-ir/11-template-primitive-registry.test.ts +231 -1
  61. package/src/__tests__/tagged-template-interleave.test.ts +268 -0
  62. package/src/__tests__/unsupported-expression.test.ts +194 -7
  63. package/src/adapters/env-signal.ts +57 -9
  64. package/src/adapters/interface.ts +20 -4
  65. package/src/adapters/parsed-expr-emitter.ts +19 -2
  66. package/src/analyzer-context.ts +20 -0
  67. package/src/analyzer.ts +74 -1
  68. package/src/augment-inherited-props.ts +139 -9
  69. package/src/compiler.ts +10 -1
  70. package/src/expression-parser.ts +421 -50
  71. package/src/index.ts +30 -3
  72. package/src/ir-to-client-js/collect-elements.ts +15 -1
  73. package/src/ir-to-client-js/compute-inlinability.ts +6 -1
  74. package/src/ir-to-client-js/control-flow/plan/build-loop.ts +1 -0
  75. package/src/ir-to-client-js/control-flow/plan/loop.ts +9 -0
  76. package/src/ir-to-client-js/control-flow/stringify/loop.ts +30 -8
  77. package/src/ir-to-client-js/control-flow/stringify/template-parse.ts +30 -0
  78. package/src/ir-to-client-js/emit-registration.ts +4 -2
  79. package/src/ir-to-client-js/html-template.ts +198 -1
  80. package/src/ir-to-client-js/index.ts +1 -0
  81. package/src/ir-to-client-js/types.ts +22 -0
  82. package/src/jsx-to-ir.ts +409 -24
  83. package/src/loop-destructure.ts +89 -36
  84. package/src/lowering-registry.ts +16 -0
  85. package/src/relocate.ts +201 -14
  86. package/src/ssr-defaults.ts +34 -32
  87. package/src/ssr-seed-plan.ts +146 -0
  88. package/src/types.ts +76 -0
@@ -268,6 +268,26 @@ export function createAnalyzerContext(
268
268
  checker: null,
269
269
  componentBodyBlock: null,
270
270
  getJS(node: ts.Node): string {
271
+ // A node whose owning source file differs from this component's
272
+ // `sourceFile` comes from a synthetic re-parse — e.g. #2090's
273
+ // resolved sort-comparator functions, or #2092's desugared
274
+ // tagged-template-literal callee — rather than a live position in
275
+ // this file. `reconstructWithoutTypes` slices `sourceFile.text` by
276
+ // the node's start/end, so feeding it a foreign node's positions
277
+ // would silently slice the WRONG bytes (not throw). These synthetic
278
+ // subtrees are already built from plain re-parsed source text with
279
+ // no straggling TS type syntax to strip, so the node's own text is
280
+ // correct as-is — mirrors the `astText()` workaround already used
281
+ // for synthetic const/function re-parses elsewhere in the compiler.
282
+ let ownSourceFile: ts.SourceFile | undefined
283
+ try {
284
+ ownSourceFile = node.getSourceFile()
285
+ } catch {
286
+ ownSourceFile = undefined
287
+ }
288
+ if (ownSourceFile && ownSourceFile !== sourceFile) {
289
+ return node.getText(ownSourceFile)
290
+ }
271
291
  return reconstructWithoutTypes(node, sourceFile, this.typeExcludeRanges)
272
292
  },
273
293
  }
package/src/analyzer.ts CHANGED
@@ -3011,6 +3011,12 @@ function extractProps(param: ts.ParameterDeclaration, ctx: AnalyzerContext): voi
3011
3011
  hasIgnoreDirective: ignored,
3012
3012
  }
3013
3013
 
3014
+ // Resolve each destructured binding's declared type from the param's type
3015
+ // annotation, so `{ value }: Props` keeps the same per-prop TypeInfo as the
3016
+ // `props: Props` path instead of degrading to `unknown` (which typed
3017
+ // adapters emit as `interface{}` + an unchecked assertion). See issue #2150.
3018
+ const memberTypes = param.type ? collectMemberTypes(param.type, ctx) : null
3019
+
3014
3020
  for (const element of param.name.elements) {
3015
3021
  if (ts.isBindingElement(element) && ts.isIdentifier(element.name)) {
3016
3022
  const localName = element.name.text
@@ -3022,10 +3028,19 @@ function extractProps(param: ts.ParameterDeclaration, ctx: AnalyzerContext): voi
3022
3028
  continue
3023
3029
  }
3024
3030
 
3031
+ // Aliased bindings (`{ value: v }`) take their type from the source
3032
+ // property name, not the local alias.
3033
+ const sourcePropName =
3034
+ element.propertyName && ts.isIdentifier(element.propertyName)
3035
+ ? element.propertyName.text
3036
+ : localName
3037
+ const resolvedType: TypeInfo =
3038
+ memberTypes?.get(sourcePropName) ?? { kind: 'unknown', raw: 'unknown' }
3039
+
3025
3040
  const defaultContainsArrow = element.initializer ? nodeContainsArrow(element.initializer) : false
3026
3041
  ctx.propsParams.push({
3027
3042
  name: localName,
3028
- type: { kind: 'unknown', raw: 'unknown' },
3043
+ type: resolvedType,
3029
3044
  optional: !!element.initializer,
3030
3045
  defaultValue,
3031
3046
  defaultContainsArrow: defaultContainsArrow || undefined,
@@ -3108,6 +3123,64 @@ function collectKeysFromMembers(
3108
3123
  return keys
3109
3124
  }
3110
3125
 
3126
+ /**
3127
+ * Build a property-name -> resolved TypeInfo map from a props type annotation,
3128
+ * for destructured params (`{ value }: Props`) so they carry the same per-prop
3129
+ * types the props-object path (`props: Props`) already resolves. Returns null
3130
+ * for external/unresolvable types.
3131
+ *
3132
+ * Scope (deliberately narrow — targets the panic in issue #2150):
3133
+ * - Only REQUIRED members are resolved. Optional members (`value?: T`) are left
3134
+ * out so they keep degrading to `unknown` -> `interface{}`: typed adapters
3135
+ * rely on that nillable field to omit an unset optional attribute
3136
+ * (`{{if ne .X nil}}` in Go), which a concrete zero value could not express.
3137
+ * - Only PRIMITIVE members (string/number/boolean) are resolved. Those are the
3138
+ * types that otherwise produce an unchecked scalar assertion (`in.X.(int)`)
3139
+ * that panics. Arrays/objects/functions are left as `unknown` because typed
3140
+ * adapters lower them through interface{}-based helpers (`bf_flat`, spread,
3141
+ * `bf_json`); giving them concrete types would break that lowering and is a
3142
+ * larger, separate change.
3143
+ */
3144
+ function collectMemberTypes(
3145
+ typeNode: ts.TypeNode,
3146
+ ctx: AnalyzerContext
3147
+ ): Map<string, TypeInfo> | null {
3148
+ const isResolvablePrimitive = (info: TypeInfo): boolean =>
3149
+ info.kind === 'primitive' &&
3150
+ (info.primitive === 'string' || info.primitive === 'number' || info.primitive === 'boolean')
3151
+
3152
+ const fromMembers = (members: ts.NodeArray<ts.TypeElement>): Map<string, TypeInfo> => {
3153
+ const map = new Map<string, TypeInfo>()
3154
+ for (const member of members) {
3155
+ if (ts.isPropertySignature(member) && member.name && member.type && !member.questionToken) {
3156
+ const info = typeNodeToTypeInfo(member.type, ctx.sourceFile)
3157
+ if (info && isResolvablePrimitive(info)) {
3158
+ map.set(member.name.getText(ctx.sourceFile), info)
3159
+ }
3160
+ }
3161
+ }
3162
+ return map
3163
+ }
3164
+
3165
+ if (ts.isTypeLiteralNode(typeNode)) {
3166
+ return fromMembers(typeNode.members)
3167
+ }
3168
+
3169
+ if (ts.isTypeReferenceNode(typeNode)) {
3170
+ const typeName = typeNode.typeName.getText(ctx.sourceFile)
3171
+ const typeDecl = findTypeDeclaration(typeName, ctx.sourceFile)
3172
+ if (!typeDecl) return null
3173
+ if (ts.isInterfaceDeclaration(typeDecl)) {
3174
+ return fromMembers(typeDecl.members)
3175
+ }
3176
+ if (ts.isTypeAliasDeclaration(typeDecl) && ts.isTypeLiteralNode(typeDecl.type)) {
3177
+ return fromMembers(typeDecl.type.members)
3178
+ }
3179
+ }
3180
+
3181
+ return null
3182
+ }
3183
+
3111
3184
  /**
3112
3185
  * Extract props parameters from a type annotation.
3113
3186
  * Supports type literals and type references to local interfaces.
@@ -32,6 +32,25 @@ export interface ContextConsumer {
32
32
  * absent / not a literal (the consumer then defaults to the empty value).
33
33
  */
34
34
  defaultValue: string | number | boolean | null
35
+ /**
36
+ * Set to `'object'` when the `createContext(<default>)` argument is an
37
+ * OBJECT LITERAL (`createContext<{ config: X }>({ config: {} })`) — a shape
38
+ * `defaultValue` alone can't distinguish from "no default at all" (both
39
+ * collapse to `null`). Adapters with a live SSR context stack (twig, jinja,
40
+ * erb, minijinja, xslate, mojolicious) never read this: their consumer seed
41
+ * (`bf.use_context(name, default)`) only matters when NO enclosing Provider
42
+ * ran, and every existing fixture exercising an object-shaped default keeps
43
+ * its consumer nested inside a Provider that supplies a live value at
44
+ * render time — see each adapter's `memo/seed.ts` (or equivalent). Go has no
45
+ * such runtime stack: it bakes the Provider's value into the descendant's
46
+ * constructor call at COMPILE time (`extendProviderContext` /
47
+ * `emitStaticChildInstances`, go-template-adapter.ts), so an object-shaped
48
+ * default needs its own Go type (`map[string]interface{}`, not the scalar
49
+ * `string` fallback `contextConsumerGoType` used to pick for every
50
+ * non-literal default) — `defaultKind` is what lets it tell "object" apart
51
+ * from "no default" (#2087).
52
+ */
53
+ defaultKind?: 'object'
35
54
  }
36
55
 
37
56
  /**
@@ -44,9 +63,15 @@ export function collectContextConsumers(metadata: IRMetadata): ContextConsumer[]
44
63
  const constants = metadata.localConstants ?? []
45
64
  // Map each createContext const name → its default-arg literal value.
46
65
  const contextDefaults = new Map<string, string | number | boolean | null>()
66
+ // Map each createContext const name → 'object' when its default is an
67
+ // object-literal (a shape `contextDefaults` alone can't distinguish from
68
+ // "no default" — both parse to `null`). Only Go consults this (see
69
+ // `ContextConsumer.defaultKind`'s docstring).
70
+ const contextDefaultKinds = new Map<string, 'object'>()
47
71
  for (const c of constants) {
48
72
  if (c.systemConstructKind !== 'createContext' || c.value === undefined) continue
49
73
  contextDefaults.set(c.name, parseCreateContextDefault(c.value))
74
+ if (isObjectLiteralCreateContextDefault(c.value)) contextDefaultKinds.set(c.name, 'object')
50
75
  }
51
76
  if (contextDefaults.size === 0) return []
52
77
 
@@ -59,6 +84,7 @@ export function collectContextConsumers(metadata: IRMetadata): ContextConsumer[]
59
84
  localName: c.name,
60
85
  contextName: ctxName,
61
86
  defaultValue: contextDefaults.get(ctxName) ?? null,
87
+ defaultKind: contextDefaultKinds.get(ctxName),
62
88
  })
63
89
  }
64
90
  return consumers
@@ -87,6 +113,14 @@ function parseCreateContextDefault(source: string): string | number | boolean |
87
113
  return null
88
114
  }
89
115
 
116
+ /** True when `createContext(<arg>)`'s argument is an object-literal (`{ config: {} }`). */
117
+ function isObjectLiteralCreateContextDefault(source: string): boolean {
118
+ const expr = parseSingleExpression(source)
119
+ if (!expr || !ts.isCallExpression(expr)) return false
120
+ if (expr.arguments.length === 0) return false
121
+ return ts.isObjectLiteralExpression(expr.arguments[0])
122
+ }
123
+
90
124
  function parseSingleExpression(source: string): ts.Expression | null {
91
125
  const sf = ts.createSourceFile('__ctx.ts', `(${source})`, ts.ScriptTarget.Latest, false)
92
126
  const stmt = sf.statements[0]
@@ -139,14 +173,65 @@ export function augmentInheritedPropAccesses(ir: ComponentIR): void {
139
173
  const booleanAttrProps = new Set<string>()
140
174
  const accessed = new Set<string>()
141
175
  const accessRe = new RegExp(`(?:^|[^\\w$.])${propsObj}\\.([A-Za-z_$][\\w$]*)`, 'g')
142
- const scan = (s: string | undefined): void => {
176
+ const scan = (s: string | undefined, also?: Set<string>): void => {
143
177
  if (!s) return
144
- for (const m of s.matchAll(accessRe)) accessed.add(m[1])
178
+ for (const m of s.matchAll(accessRe)) {
179
+ accessed.add(m[1])
180
+ also?.add(m[1])
181
+ }
182
+ }
183
+
184
+ // Coalesce-literal type pins: a read of the form `props.X ?? <literal>`
185
+ // (or `|| <literal>`) fixes X's type to the literal's. The Go adapter
186
+ // seeds a prop-derived signal/memo constructor from the synthetic field
187
+ // (`Count: in.Initial` where `Count int` came from evaluating
188
+ // `props.initial ?? 0`), so classifying `initial` with the string
189
+ // default produces a Go type mismatch the compiler rejects.
190
+ const coalesceLiteralTypes = new Map<string, 'number' | 'boolean' | 'string'>()
191
+ const pinCoalesceLiterals = (s: string | undefined): void => {
192
+ if (!s || !s.includes(propsObj)) return
193
+ const sf = ts.createSourceFile('__aug.ts', `(${s})`, ts.ScriptTarget.Latest, false)
194
+ const visit = (n: ts.Node): void => {
195
+ if (
196
+ ts.isBinaryExpression(n) &&
197
+ (n.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken ||
198
+ n.operatorToken.kind === ts.SyntaxKind.BarBarToken)
199
+ ) {
200
+ let left: ts.Expression = n.left
201
+ while (ts.isParenthesizedExpression(left)) left = left.expression
202
+ if (
203
+ ts.isPropertyAccessExpression(left) &&
204
+ ts.isIdentifier(left.expression) &&
205
+ left.expression.text === propsObj
206
+ ) {
207
+ const name = left.name.text
208
+ let right: ts.Expression = n.right
209
+ while (ts.isParenthesizedExpression(right)) right = right.expression
210
+ if (ts.isPrefixUnaryExpression(right)) right = right.operand
211
+ const kind = ts.isNumericLiteral(right)
212
+ ? 'number'
213
+ : right.kind === ts.SyntaxKind.TrueKeyword || right.kind === ts.SyntaxKind.FalseKeyword
214
+ ? 'boolean'
215
+ : ts.isStringLiteralLike(right)
216
+ ? 'string'
217
+ : null
218
+ if (kind && !coalesceLiteralTypes.has(name)) coalesceLiteralTypes.set(name, kind)
219
+ }
220
+ }
221
+ ts.forEachChild(n, visit)
222
+ }
223
+ visit(sf)
145
224
  }
146
225
 
147
226
  // Memos, signals, init statements, effects: any `props.X` read.
148
- for (const memo of ir.metadata.memos) scan(memo.computation)
149
- for (const signal of ir.metadata.signals) scan(signal.initialValue)
227
+ for (const memo of ir.metadata.memos) {
228
+ scan(memo.computation)
229
+ pinCoalesceLiterals(memo.computation)
230
+ }
231
+ for (const signal of ir.metadata.signals) {
232
+ scan(signal.initialValue)
233
+ pinCoalesceLiterals(signal.initialValue)
234
+ }
150
235
  for (const stmt of ir.metadata.initStatements ?? []) scan(stmt.body)
151
236
  for (const eff of ir.metadata.effects ?? []) scan((eff as { body?: string }).body)
152
237
 
@@ -157,12 +242,58 @@ export function augmentInheritedPropAccesses(ir: ComponentIR): void {
157
242
  for (const c of ir.metadata.localConstants ?? []) {
158
243
  if (c.isModule) continue
159
244
  scan(c.value)
245
+ pinCoalesceLiterals(c.value)
160
246
  }
161
247
 
162
248
  // Template attribute exprs — also note bare-ref / boolean usage.
163
249
  const walk = (node: IRNode | undefined): void => {
164
250
  if (!node) return
251
+ // Non-attribute expression carriers (#2126 follow-up): a `props.X`
252
+ // read can reach the template as a bare scalar through a dynamic
253
+ // text child (`<p>{props.label}</p>`), a conditional / if-statement
254
+ // condition (`{props.show && …}`), or a loop's array expression
255
+ // (`(props.items ?? []).map(…)`). With a typed props object those
256
+ // names are already in `propsParams`; with an untyped `props`
257
+ // parameter these reads were invisible to this pass, so the emitted
258
+ // template referenced a var the props type / ssrDefaults never
259
+ // declared (a strict-mode 500 on Perl-family adapters, a missing
260
+ // struct field on Go). Text reads keep the default `string`
261
+ // classification; condition / loop-array reads land in the nillable
262
+ // bucket (`unknown` → omittable/interface-typed) since their values
263
+ // are only ever truth-tested or iterated.
264
+ const carrier = node as unknown as { type?: string; expr?: string; condition?: string; array?: string }
265
+ if (carrier.type === 'expression') {
266
+ scan(carrier.expr)
267
+ pinCoalesceLiterals(carrier.expr)
268
+ }
269
+ scan(carrier.condition, bareRefProps)
270
+ pinCoalesceLiterals(carrier.condition)
271
+ scan(carrier.array, bareRefProps)
165
272
  const el = node as unknown as IRElement
273
+ // Component nodes carry the same AttrValue shapes under `props`
274
+ // (`<Child value={props.foo} />` reads `$foo` at child-props
275
+ // construction time in the SSR template) — but they are NOT HTML
276
+ // attributes: boolean-attr inference by name doesn't apply, and the
277
+ // value's type belongs to the child's contract, not to how this
278
+ // component renders it. Classify these reads as nillable (`unknown`)
279
+ // unless a `?? <literal>` pins a concrete type.
280
+ for (const prop of (node as unknown as { props?: IRElement['attrs'] }).props ?? []) {
281
+ const v = prop.value as { kind?: string; expr?: string; parts?: Array<{ type: string } & Record<string, string>> }
282
+ if (v?.parts) {
283
+ for (const part of v.parts) {
284
+ if (part.type === 'string') scan(part.value)
285
+ else if (part.type === 'ternary') {
286
+ scan(part.condition)
287
+ scan(part.whenTrue)
288
+ scan(part.whenFalse)
289
+ } else if (part.type === 'lookup') scan(part.key)
290
+ }
291
+ }
292
+ if (v?.kind === 'expression' && typeof v.expr === 'string') {
293
+ scan(v.expr, bareRefProps)
294
+ pinCoalesceLiterals(v.expr)
295
+ }
296
+ }
166
297
  for (const attr of el.attrs ?? []) {
167
298
  const v = attr.value as {
168
299
  kind?: string
@@ -231,14 +362,13 @@ export function augmentInheritedPropAccesses(ir: ComponentIR): void {
231
362
  if (existing.has(name)) continue
232
363
  let raw: string
233
364
  if (booleanAttrProps.has(name)) raw = 'boolean'
365
+ else if (coalesceLiteralTypes.has(name)) raw = coalesceLiteralTypes.get(name)!
234
366
  else if (bareRefProps.has(name)) raw = 'unknown' // → interface{} (nillable, omittable)
235
367
  else raw = 'string' // read in a memo / string context (e.g. className)
236
368
  const type: TypeInfo =
237
- raw === 'boolean'
238
- ? { kind: 'primitive', raw: 'boolean', primitive: 'boolean' }
239
- : raw === 'string'
240
- ? { kind: 'primitive', raw: 'string', primitive: 'string' }
241
- : { kind: 'unknown', raw: 'unknown' }
369
+ raw === 'unknown'
370
+ ? { kind: 'unknown', raw: 'unknown' }
371
+ : { kind: 'primitive', raw, primitive: raw as 'string' | 'number' | 'boolean' }
242
372
  ir.metadata.propsParams.push({ name, type, optional: true })
243
373
  existing.add(name)
244
374
  }
package/src/compiler.ts CHANGED
@@ -23,6 +23,7 @@ import { generateModuleExports, collectInlineExportedNames } from './module-expo
23
23
  import { applyCssLayerPrefix } from './css-layer-prefixer.ts'
24
24
  import { preprocessInlineJsxCallbacks } from './preprocess-inline-jsx-callbacks.ts'
25
25
  import { extractSsrDefaults } from './ssr-defaults.ts'
26
+ import { computeSsrSeedPlan } from './ssr-seed-plan.ts'
26
27
 
27
28
  /**
28
29
  * Extended compile options with required adapter
@@ -275,6 +276,7 @@ function compileMultipleComponents(
275
276
  path: dir + output.componentName + adapter.extension,
276
277
  content: output.rawTemplate,
277
278
  type: 'markedTemplate',
279
+ componentName: output.componentName,
278
280
  })
279
281
  // SSR defaults, paired with the per-component template file via
280
282
  // the matching basename (the build pipeline pairs them in
@@ -286,6 +288,7 @@ function compileMultipleComponents(
286
288
  path: dir + output.componentName + '.ssr-defaults.json',
287
289
  content: JSON.stringify(ssrDefaults),
288
290
  type: 'ssrDefaults',
291
+ componentName: output.componentName,
289
292
  })
290
293
  }
291
294
  }
@@ -482,7 +485,7 @@ function compileMultipleComponents(
482
485
  export function buildMetadata(
483
486
  ctx: ReturnType<typeof analyzeComponent>,
484
487
  ): IRMetadata {
485
- return {
488
+ const metadata: IRMetadata = {
486
489
  componentName: ctx.componentName || 'Unknown',
487
490
  hasDefaultExport: ctx.hasDefaultExport,
488
491
  isExported: ctx.isExported,
@@ -512,6 +515,10 @@ export function buildMetadata(
512
515
  localFunctions: ctx.localFunctions,
513
516
  localConstants: ctx.localConstants,
514
517
  }
518
+ // Computed from the assembled metadata (not `ctx`): the plan reads the
519
+ // exact fields adapters see, so the two can never disagree.
520
+ metadata.ssrSeedPlan = computeSsrSeedPlan(metadata)
521
+ return metadata
515
522
  }
516
523
 
517
524
  // =============================================================================
@@ -667,6 +674,7 @@ export function compileJSX(
667
674
  path: filePath.replace(/\.tsx?$/, adapter.extension),
668
675
  content,
669
676
  type: 'markedTemplate',
677
+ componentName: componentIR.metadata.componentName,
670
678
  })
671
679
 
672
680
  // SSR defaults — JSON-encoded seed values for the template's
@@ -681,6 +689,7 @@ export function compileJSX(
681
689
  path: filePath.replace(/\.tsx?$/, '.ssr-defaults.json'),
682
690
  content: JSON.stringify(ssrDefaults),
683
691
  type: 'ssrDefaults',
692
+ componentName: componentIR.metadata.componentName,
684
693
  })
685
694
  }
686
695
  }