@barefootjs/jsx 0.41.1 → 0.41.3

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 (105) hide show
  1. package/dist/adapters/attr-plan.d.ts +8 -0
  2. package/dist/adapters/attr-plan.d.ts.map +1 -1
  3. package/dist/adapters/component-props.d.ts.map +1 -1
  4. package/dist/adapters/computed-const.d.ts +19 -0
  5. package/dist/adapters/computed-const.d.ts.map +1 -1
  6. package/dist/adapters/dsl-template-adapter.d.ts +2 -1
  7. package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
  8. package/dist/adapters/inherited-const-server-read.d.ts +37 -0
  9. package/dist/adapters/inherited-const-server-read.d.ts.map +1 -0
  10. package/dist/adapters/loop-row-type.d.ts +18 -0
  11. package/dist/adapters/loop-row-type.d.ts.map +1 -1
  12. package/dist/adapters/non-primitive-equality.d.ts +8 -2
  13. package/dist/adapters/non-primitive-equality.d.ts.map +1 -1
  14. package/dist/adapters/unapplied-prop-default.d.ts +34 -0
  15. package/dist/adapters/unapplied-prop-default.d.ts.map +1 -0
  16. package/dist/adapters/uninlinable-seed-call.d.ts +29 -0
  17. package/dist/adapters/uninlinable-seed-call.d.ts.map +1 -0
  18. package/dist/analyzer.d.ts.map +1 -1
  19. package/dist/augment-inherited-props.d.ts +4 -22
  20. package/dist/augment-inherited-props.d.ts.map +1 -1
  21. package/dist/caller-value-reach.d.ts +57 -0
  22. package/dist/caller-value-reach.d.ts.map +1 -0
  23. package/dist/const-identity.d.ts +38 -0
  24. package/dist/const-identity.d.ts.map +1 -0
  25. package/dist/index.d.ts +10 -5
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +2685 -1381
  28. package/dist/ir-to-client-js/child-props-object.d.ts +39 -41
  29. package/dist/ir-to-client-js/child-props-object.d.ts.map +1 -1
  30. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  31. package/dist/ir-to-client-js/component-scope.d.ts +13 -2
  32. package/dist/ir-to-client-js/component-scope.d.ts.map +1 -1
  33. package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.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/html-template.d.ts.map +1 -1
  36. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  37. package/dist/jsx-to-ir.d.ts.map +1 -1
  38. package/dist/local-call-body.d.ts +112 -0
  39. package/dist/local-call-body.d.ts.map +1 -0
  40. package/dist/nullable-signal-attr.d.ts +10 -0
  41. package/dist/nullable-signal-attr.d.ts.map +1 -1
  42. package/dist/prop-default-resolution.d.ts +52 -0
  43. package/dist/prop-default-resolution.d.ts.map +1 -0
  44. package/dist/props-binding.d.ts +15 -0
  45. package/dist/props-binding.d.ts.map +1 -1
  46. package/dist/server-read-walk.d.ts +66 -0
  47. package/dist/server-read-walk.d.ts.map +1 -0
  48. package/dist/ssr-defaults.d.ts.map +1 -1
  49. package/dist/ssr-seed-plan.d.ts +24 -1
  50. package/dist/ssr-seed-plan.d.ts.map +1 -1
  51. package/dist/static-const-member.d.ts +92 -0
  52. package/dist/static-const-member.d.ts.map +1 -0
  53. package/dist/static-literal.d.ts +21 -1
  54. package/dist/static-literal.d.ts.map +1 -1
  55. package/dist/types.d.ts +63 -0
  56. package/dist/types.d.ts.map +1 -1
  57. package/package.json +2 -2
  58. package/src/__tests__/computed-const.test.ts +7 -1
  59. package/src/__tests__/const-identity-child-prop.test.ts +127 -0
  60. package/src/__tests__/inherited-const-server-read.test.ts +116 -0
  61. package/src/__tests__/issue-3688-props-spread-child-csr.test.ts +8 -3
  62. package/src/__tests__/issue-3714-open-rest-spread-child.test.ts +188 -0
  63. package/src/__tests__/local-call-body.test.ts +101 -0
  64. package/src/__tests__/loop-branch-bare-expression-reactive-text.test.ts +212 -56
  65. package/src/__tests__/nested-loop-conditional.test.ts +16 -16
  66. package/src/__tests__/prop-default-resolution.test.ts +185 -0
  67. package/src/__tests__/props-spread-shadowed.test.ts +113 -0
  68. package/src/__tests__/server-read-walk.test.ts +125 -0
  69. package/src/__tests__/ssr-defaults.test.ts +67 -7
  70. package/src/__tests__/static-literal.test.ts +47 -2
  71. package/src/__tests__/static-record-literal-array.test.ts +82 -11
  72. package/src/adapters/attr-plan.ts +12 -1
  73. package/src/adapters/component-props.ts +2 -1
  74. package/src/adapters/computed-const.ts +108 -12
  75. package/src/adapters/dsl-template-adapter.ts +17 -4
  76. package/src/adapters/inherited-const-server-read.ts +174 -0
  77. package/src/adapters/loop-row-type.ts +69 -2
  78. package/src/adapters/non-primitive-equality.ts +17 -2
  79. package/src/adapters/unapplied-prop-default.ts +83 -0
  80. package/src/adapters/uninlinable-seed-call.ts +62 -0
  81. package/src/analyzer.ts +43 -3
  82. package/src/augment-inherited-props.ts +4 -49
  83. package/src/caller-value-reach.ts +436 -0
  84. package/src/compiler.ts +4 -4
  85. package/src/const-identity.ts +189 -0
  86. package/src/index.ts +10 -5
  87. package/src/ir-to-client-js/child-props-object.ts +94 -62
  88. package/src/ir-to-client-js/collect-elements.ts +53 -68
  89. package/src/ir-to-client-js/component-scope.ts +16 -2
  90. package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +1 -0
  91. package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +1 -0
  92. package/src/ir-to-client-js/html-template.ts +24 -4
  93. package/src/ir-to-client-js/index.ts +2 -2
  94. package/src/ir-to-client-js/prop-handling.ts +4 -0
  95. package/src/jsx-to-ir.ts +40 -2
  96. package/src/local-call-body.ts +191 -0
  97. package/src/nullable-signal-attr.ts +39 -17
  98. package/src/prop-default-resolution.ts +195 -0
  99. package/src/props-binding.ts +16 -0
  100. package/src/server-read-walk.ts +174 -0
  101. package/src/ssr-defaults.ts +93 -10
  102. package/src/ssr-seed-plan.ts +104 -18
  103. package/src/static-const-member.ts +243 -0
  104. package/src/static-literal.ts +55 -1
  105. package/src/types.ts +63 -1
package/src/index.ts CHANGED
@@ -39,7 +39,8 @@ export { resolveGetterAliases, collectAliasableGetterNames } from './ir-to-clien
39
39
  export { buildImportAliasMap } from './ir-to-client-js/component-scope.ts'
40
40
 
41
41
  // Backend-neutral SSR seed plan (in-template derived signal/memo seeding)
42
- export { computeSsrSeedPlan, hasComputedDefault, inDefaultReadOrder } from './ssr-seed-plan.ts'
42
+ export { appliedPropDefaults, computeSsrSeedPlan, hasComputedDefault, inDefaultReadOrder, type PropDefaultApplication } from './ssr-seed-plan.ts'
43
+ export type { ResolvedPropDefault } from './prop-default-resolution.ts'
43
44
  export type { SsrSeedPlan, SsrSeedStep } from './ssr-seed-plan.ts'
44
45
 
45
46
  // Pure IR types
@@ -132,10 +133,13 @@ export type { JsxAdapterConfig } from './adapters/jsx-adapter.ts'
132
133
  export { rewriteImportsForTemplate, rewriteDynamicImportsInSource } from './adapters/template-imports.ts'
133
134
  export { emitParsedExpr, emitParsedValue, primitivePlanFor, arithmeticHelper, groupBinaryOperand, groupUnaryOperand, groupObjectLiteralSegments, isStringTypedOperand, isStringConcatBinary, isNumericArithmeticResult } from './adapters/parsed-expr-emitter.ts'
134
135
  export type { StringNameTest } from './adapters/parsed-expr-emitter.ts'
135
- export { concatType, declaredValueTypes, loopRowType, type DeclaredValueTypes } from './adapters/loop-row-type.ts'
136
+ export { concatType, declaredValueMayBeNil, declaredValueTypes, loopRowType, type DeclaredValueTypes } from './adapters/loop-row-type.ts'
136
137
  export { collectNumberValueNames, isNumberValuedExpr, numberValuedSeedNames } from './adapters/number-value.ts'
137
138
  export { operandFacts, planPrimitive, planTest, spellTest, primitivesAt, isNativePlan, relationalHelper, isNativeToNumber, booleanValueSites, planTextDisplay, foldNegatedNumberLiteral, numberLiteralSpelling, isRuntimeNumberLiteral, plusSpelling, planToString, needsToString, strictEqSpelling, mayHoldObject, isNullishTest, isNilLiteralOperand, nilTestOperand, refuseUnspelledNilTest, NON_PRIMITIVE_EQUALITY_REASON } from './adapters/primitive-plan.ts'
138
139
  export { refuseNonPrimitiveStrictEquality, type NonPrimitiveEqualitySink } from './adapters/non-primitive-equality.ts'
140
+ export { refuseInheritedConstServerReads } from './adapters/inherited-const-server-read.ts'
141
+ export { refuseUninlinableSeedCalls, type UninlinableSeedCallSink } from './adapters/uninlinable-seed-call.ts'
142
+ export { refuseUnappliedPropDefaults, type UnappliedPropDefaultSink } from './adapters/unapplied-prop-default.ts'
139
143
  export { rewriteNilReadings, rewriteNilReadingsDeep, isNilReadingFallback, NAN_LITERAL } from './adapters/nil-reading.ts'
140
144
  export type { PrimitiveOp, Proof, NativeSafeClaims, NativeSafeTable, PrimitiveHelper, NilTestHelper, PrimitivePlan, PrimitiveInputs, TextDisplay, NumberLiteralSpelling, PlusSpelling, StrictEqSpelling } from './adapters/primitive-plan.ts'
141
145
  export {
@@ -214,7 +218,7 @@ export type {
214
218
  export { derivesScopeFromSlot } from './adapters/child-scope.ts'
215
219
  export { childTemplateName, componentPropKey, isEmptyComponentProps, planComponentProps, propsSpreadParam, resolveComponentPropKeys, spellComponentProps, templatePropValue } from './adapters/component-props.ts'
216
220
  export type { ComponentPropEntry, ComponentPropSegment, ComponentPropSpelling, ComponentPropsOptions, ComponentPropsParam, EarlierComponentProps, ResolvedComponentProp, SpelledComponentPropSegment } from './adapters/component-props.ts'
217
- export { parseUndefinedAlternateTernary, planAttrExpression, planSpreadAttr, } from './adapters/attr-plan.ts'
221
+ export { parseUndefinedAlternateTernary, planAttrExpression, planSpreadAttr, spreadsPropsObject, } from './adapters/attr-plan.ts'
218
222
  export type { AttrExpressionPlan, AttrPlanContext, SpreadAttrPlan, SpreadPlanContext, UndefinedAlternateTernary } from './adapters/attr-plan.ts'
219
223
  export { loopHeaderTargets, planLoop, savedLoopBindings, spellDestructureLocals, spellFilteredRow, spellSortedSource } from './adapters/loop-plan.ts'
220
224
  export { computedConstContext, inlineComputedConstAttr, inlineComputedConsts } from './adapters/computed-const.ts'
@@ -231,7 +235,7 @@ export type {
231
235
  LoopSortSpelling,
232
236
  SavedLoopBinding,
233
237
  } from './adapters/loop-plan.ts'
234
- export { evaluateStaticLiteral, isFullyStaticLiteral, resolveStaticLoopSource } from './static-literal.ts'
238
+ export { evaluateStaticLiteral, foldStaticBindings, isFullyStaticLiteral, resolveStaticLoopSource } from './static-literal.ts'
235
239
  export {
236
240
  arithmeticOperandIsNull,
237
241
  arithmeticOperandIsUndefined,
@@ -496,8 +500,9 @@ export { BOOLEAN_ATTRS, isBooleanAttr } from './html-constants.ts'
496
500
  export { USE_CLIENT_DIRECTIVE, CLIENT_EXPRESSION_DIRECTIVE } from './directives.ts'
497
501
 
498
502
  // Shared props-object-pattern helpers for the Go / Mojo template adapters
499
- export { augmentInheritedPropAccesses, parseRecordIndexAccess, evalStringArrayJoin, collectModuleStringConsts, lookupStaticRecordLiteral, lookupStaticArrayElement, resolveStaticConstBinding, lookupLiteralConst, collectContextConsumers, contextConsumerSeed, type LiteralConst } from './augment-inherited-props.ts'
503
+ export { augmentInheritedPropAccesses, parseRecordIndexAccess, evalStringArrayJoin, collectModuleStringConsts, lookupStaticRecordLiteral, resolveStaticConstBinding, lookupLiteralConst, collectContextConsumers, contextConsumerSeed, type LiteralConst } from './augment-inherited-props.ts'
500
504
  export type { RecordIndexAccess, RecordIndexEntry, ContextConsumer } from './augment-inherited-props.ts'
505
+ export { lookupStaticConstMember, readStaticConstMember, spellStaticConstMember, staticIndexKey, type StaticConstMemberRead, type StaticConstMemberSink } from './static-const-member.ts'
501
506
 
502
507
  // HTML element attribute types
503
508
  export type {
@@ -5,16 +5,20 @@
5
5
  * Every call-site builder (top-level child, loop row, composite loop row,
6
6
  * conditional branch, static-array row) decides each explicit prop's own
7
7
  * value spelling, then hands the list here. This module is the one place
8
- * that decides how a spread of the component's own props object
9
- * (`SpreadAttr.propsObject`, set in Phase 1) merges with the explicit props
10
- * in source order (#3688, #3713):
8
+ * that decides how a spread of one of the component's own prop bags (the
9
+ * props object, `SpreadAttr.propsObject`, or its `...rest` binding,
10
+ * `SpreadAttr.callerBag === 'rest'`; both set in Phase 1) merges with the
11
+ * explicit props in source order (#3688, #3713, #3714):
11
12
  *
12
13
  * - a spread prop never becomes an entry of its own;
13
- * - an explicit prop written before the last props-object spread is only a
14
- * default: the caller's own value wins when the caller passed that key;
14
+ * - an explicit prop written before a bag spread that carries its key is
15
+ * only a default: the caller's own value wins when the caller passed
16
+ * that key;
15
17
  * - an explicit prop written after it wins as written;
16
- * - every key the caller passed and the call did not name is forwarded
17
- * through `forwardProps`, as getters, so it stays reactive.
18
+ * - every key the caller passed, the call did not name and a bag spread
19
+ * carries is forwarded through `forwardProps`, as getters, so it stays
20
+ * reactive. A rest bag does not carry the keys the component
21
+ * destructured (`SpreadAttr.restOmittedKeys`).
18
22
  */
19
23
 
20
24
  import type { AttrValue } from '../types.ts'
@@ -38,25 +42,64 @@ export function isSpreadPropName(name: string): boolean {
38
42
  }
39
43
 
40
44
  /**
41
- * Index of the last spread of the component's own props object in a child
42
- * component call (`<Tag tone="first" {...props} />`), or -1. An explicit
43
- * prop written before it is only a default: the spread overrides it when
44
- * the caller passed that key, as in JS (#3688). Both the props object built
45
- * here and the top-level reactive DOM mirrors read this one decision, so an
46
- * overridden explicit expression can't overwrite the spread-selected value
47
- * on update.
45
+ * The caller keys a spread of one of the component's own prop bags leaves
46
+ * out, or null when `value` is not such a spread: none for the props object
47
+ * (`SpreadAttr.propsObject`), the destructured keys for a `{...rest}` bag
48
+ * (`SpreadAttr.restOmittedKeys`, #3714). The client holds either bag as the
49
+ * caller's whole props object (`_p`).
48
50
  */
49
- export function lastPropsObjectSpreadIndex(props: readonly ChildPropLike[]): number {
50
- let at = -1
51
- props.forEach((p, index) => {
52
- if (p.value.kind === 'spread' && p.value.propsObject === true) at = index
53
- })
54
- return at
51
+ export function callerBagSpreadOmit(value: AttrValue): readonly string[] | null {
52
+ if (value.kind !== 'spread') return null
53
+ if (value.propsObject === true) return []
54
+ return value.callerBag === 'rest' ? (value.restOmittedKeys ?? []) : null
55
55
  }
56
56
 
57
57
  /**
58
- * The value of an explicit prop a later props-object spread overrides (see
59
- * `lastPropsObjectSpreadIndex`): the caller's own value when it passed the
58
+ * Whether a caller-bag spread written after `index` in a child component
59
+ * call carries the key `name` (`<Tag tone="first" {...props} />`,
60
+ * `<Tag tone="first" {...rest} />`). The explicit prop at `index` is then
61
+ * only a default: the spread overrides it when the caller passed that key,
62
+ * as in JS (#3688). A rest bag never carries a key the component
63
+ * destructured, so `<Tag title="x" {...rest} />` keeps `title` as written
64
+ * (#3714). Both the props object built here and the top-level reactive DOM
65
+ * mirrors read this one decision, so an overridden explicit expression
66
+ * can't overwrite the spread-selected value on update.
67
+ */
68
+ function laterCallerBagCarries(props: readonly ChildPropLike[], index: number, name: string): boolean {
69
+ for (let at = index + 1; at < props.length; at++) {
70
+ const omit = callerBagSpreadOmit(props[at]!.value)
71
+ if (omit !== null && !omit.includes(name)) return true
72
+ }
73
+ return false
74
+ }
75
+
76
+ /**
77
+ * The caller keys no caller-bag spread of the call carries, or null when
78
+ * the call spreads no caller bag: the keys every one of them leaves out.
79
+ */
80
+ function callerBagsOmit(props: readonly ChildPropLike[]): string[] | null {
81
+ let omitted: string[] | null = null
82
+ for (const prop of props) {
83
+ const omit = callerBagSpreadOmit(prop.value)
84
+ if (omit === null) continue
85
+ omitted = omitted === null ? [...omit] : omitted.filter(key => omit.includes(key))
86
+ }
87
+ return omitted
88
+ }
89
+
90
+ /**
91
+ * A `{...rest}` bag as a props object: the caller's props without the keys
92
+ * the component destructured (`omit`), each read through a getter, so it
93
+ * stays live. The one spelling the child props object and the registration
94
+ * template share.
95
+ */
96
+ export function restBagExpr(omit: readonly string[]): string {
97
+ return `forwardProps(${PROPS_PARAM}, {}, ${codeSafeStringArray(omit)})`
98
+ }
99
+
100
+ /**
101
+ * The value of an explicit prop a later caller-bag spread overrides (see
102
+ * `laterCallerBagCarries`): the caller's own value when it passed the
60
103
  * key, `expr` otherwise. `forwardProps` lets every override win, so the
61
104
  * merge is spelled into the value itself.
62
105
  */
@@ -70,8 +113,8 @@ export function callerFirstPropExpr(name: string, expr: string): string {
70
113
  * (`<Chip {...row} />`, a loop row `{...r}`): not one of the caller's own
71
114
  * prop bags (`SpreadAttr.callerBag`, decided in Phase 1). Its keys are
72
115
  * merged in source order through `spreadChildProps` (#3861). A caller-bag
73
- * spread is the props object (`propsObject`, merged by `forwardProps`) or a
74
- * `{...rest}` bag, which the top-level path forwards whole.
116
+ * spread is the props object or a `{...rest}` bag
117
+ * (`callerBagSpreadOmit`), merged by `forwardProps`.
75
118
  */
76
119
  export function isObjectSpreadProp(prop: ChildPropLike): boolean {
77
120
  return isSpreadPropName(prop.name) && prop.value.kind === 'spread' && prop.value.callerBag === undefined
@@ -80,18 +123,11 @@ export function isObjectSpreadProp(prop: ChildPropLike): boolean {
80
123
  export interface ChildPropsObjectOptions {
81
124
  /** Entries appended after the explicit props (e.g. a row's `children` getter). */
82
125
  trailing?: readonly string[]
83
- /**
84
- * Forward the caller's props even without a props-object spread — the
85
- * top-level path's `{...rest}` forwarding, which predates the marker.
86
- */
87
- forwardCaller?: boolean
88
- /**
89
- * The caller's `{...rest}` bag as a props object (the caller's props
90
- * without the keys the component destructured), so a call that also
91
- * spreads an object merges the bag in source order as one more part.
92
- * Without it a rest bag spread is left to `forwardCaller`.
93
- */
94
- restBag?: string
126
+ }
127
+
128
+ /** Whether a child component call spreads one of the component's own prop bags (`callerBagSpreadOmit`). */
129
+ export function spreadsCallerBag(props: readonly ChildPropLike[]): boolean {
130
+ return props.some(prop => callerBagSpreadOmit(prop.value) !== null)
95
131
  }
96
132
 
97
133
  /**
@@ -120,9 +156,9 @@ export function lastObjectSpreadIndex(props: readonly ChildPropLike[]): number {
120
156
  * The value of the explicit prop at `index` for a reactive DOM mirror,
121
157
  * merged with every spread written after it, as the props object merges
122
158
  * them: a later object spread (`spreadOf` spells its value) wins when its
123
- * object has the key, and a later props-object spread wins when the caller
124
- * passed it (`callerFirstPropExpr`). `expr` as written when no spread
125
- * follows.
159
+ * object has the key, and a later caller-bag spread that carries the key
160
+ * (`callerBagSpreadOmit`) wins when the caller passed it
161
+ * (`callerFirstPropExpr`). `expr` as written when no spread follows.
126
162
  */
127
163
  export function mergedExplicitPropExpr<P extends ChildPropLike>(
128
164
  props: readonly P[],
@@ -133,11 +169,13 @@ export function mergedExplicitPropExpr<P extends ChildPropLike>(
133
169
  const name = props[index]!.name
134
170
  const key = codeSafeStringLiteral(name)
135
171
  let merged = expr
136
- // The last spread kind applied: two props-object spreads in a row merge once.
172
+ // The last spread kind applied: two caller-bag spreads in a row merge once.
137
173
  let last: 'props' | 'object' | null = null
138
174
  for (let at = index + 1; at < props.length; at++) {
139
175
  const prop = props[at]!
140
- if (prop.value.kind === 'spread' && prop.value.propsObject === true) {
176
+ const omit = callerBagSpreadOmit(prop.value)
177
+ if (omit !== null) {
178
+ if (omit.includes(name)) continue
141
179
  if (last !== 'props') merged = callerFirstPropExpr(name, merged)
142
180
  last = 'props'
143
181
  } else if (isObjectSpreadProp(prop)) {
@@ -154,13 +192,12 @@ export function mergedExplicitPropExpr<P extends ChildPropLike>(
154
192
  * also spells an object spread's value (`isObjectSpreadProp`).
155
193
  *
156
194
  * Without an object spread, the explicit props form one object literal,
157
- * wrapped in `forwardProps` for a props-object spread (or the caller
158
- * forwarding). With one, every part merges in source order through
159
- * `spreadChildProps` (#3861): each run of explicit props is an object
160
- * literal, an object spread a thunk of its value, and a props-object spread
161
- * the thunk `() => _p`, so a later part wins as in JS. A `{...rest}` bag is
162
- * a part too when the caller spells it (`restBag`); otherwise it is
163
- * forwarded off `_p` after the merge.
195
+ * wrapped in `forwardProps` for a caller-bag spread. With one, every part
196
+ * merges in source order through `spreadChildProps` (#3861): each run of
197
+ * explicit props is an object literal, an object spread a thunk of its
198
+ * value, a props-object spread the thunk `() => _p`, and a `{...rest}` bag
199
+ * the caller's props without the destructured keys (`restBagExpr`), so a
200
+ * later part wins as in JS.
164
201
  */
165
202
  export function childPropsObjectExpr<P extends ChildPropLike>(
166
203
  props: readonly P[],
@@ -168,7 +205,7 @@ export function childPropsObjectExpr<P extends ChildPropLike>(
168
205
  options: ChildPropsObjectOptions = {},
169
206
  ): string {
170
207
  if (lastObjectSpreadIndex(props) >= 0) return spreadPartsExpr(props, valueOf, options)
171
- const spreadAt = lastPropsObjectSpreadIndex(props)
208
+ const bagsOmit = callerBagsOmit(props)
172
209
  const entries: string[] = []
173
210
  const explicitNames: string[] = []
174
211
  props.forEach((prop, index) => {
@@ -177,7 +214,7 @@ export function childPropsObjectExpr<P extends ChildPropLike>(
177
214
  if (!value) return
178
215
  explicitNames.push(prop.name)
179
216
  const key = quotePropName(prop.name)
180
- if (index < spreadAt) {
217
+ if (laterCallerBagCarries(props, index, prop.name)) {
181
218
  entries.push(`get ${key}() { return ${callerFirstPropExpr(prop.name, value.expr)} }`)
182
219
  } else {
183
220
  entries.push(explicitEntry(key, value))
@@ -185,8 +222,9 @@ export function childPropsObjectExpr<P extends ChildPropLike>(
185
222
  })
186
223
  entries.push(...(options.trailing ?? []))
187
224
  const object = objectLiteral(entries)
188
- if (spreadAt < 0 && !options.forwardCaller) return object
189
- return `forwardProps(${PROPS_PARAM}, ${object}, ${codeSafeStringArray(explicitNames)})`
225
+ if (bagsOmit === null) return object
226
+ const excluded = [...explicitNames, ...bagsOmit.filter(key => !explicitNames.includes(key))]
227
+ return `forwardProps(${PROPS_PARAM}, ${object}, ${codeSafeStringArray(excluded)})`
190
228
  }
191
229
 
192
230
  /** One explicit prop's object-literal entry: a getter or a data property. */
@@ -202,8 +240,6 @@ function spreadPartsExpr<P extends ChildPropLike>(
202
240
  ): string {
203
241
  const parts: string[] = []
204
242
  let entries: string[] = []
205
- const explicitNames: string[] = []
206
- let mergesCaller = false
207
243
  const flush = (): void => {
208
244
  if (entries.length > 0) parts.push(objectLiteral(entries))
209
245
  entries = []
@@ -212,13 +248,12 @@ function spreadPartsExpr<P extends ChildPropLike>(
212
248
  if (prop.value.kind === 'spread' && prop.value.propsObject === true) {
213
249
  flush()
214
250
  parts.push(`() => ${PROPS_PARAM}`)
215
- mergesCaller = true
216
251
  continue
217
252
  }
218
- if (prop.value.kind === 'spread' && prop.value.callerBag === 'rest' && options.restBag !== undefined) {
253
+ const restOmit = callerBagSpreadOmit(prop.value)
254
+ if (restOmit !== null) {
219
255
  flush()
220
- parts.push(options.restBag)
221
- mergesCaller = true
256
+ parts.push(restBagExpr(restOmit))
222
257
  continue
223
258
  }
224
259
  if (isSpreadPropName(prop.name) && !isObjectSpreadProp(prop)) continue
@@ -229,12 +264,9 @@ function spreadPartsExpr<P extends ChildPropLike>(
229
264
  parts.push(`() => (${value.expr})`)
230
265
  continue
231
266
  }
232
- explicitNames.push(prop.name)
233
267
  entries.push(explicitEntry(quotePropName(prop.name), value))
234
268
  }
235
269
  entries.push(...(options.trailing ?? []))
236
270
  flush()
237
- const merged = `spreadChildProps(${parts.join(', ')})`
238
- if (!options.forwardCaller || mergesCaller) return merged
239
- return `forwardProps(${PROPS_PARAM}, ${merged}, ${codeSafeStringArray(explicitNames)})`
271
+ return `spreadChildProps(${parts.join(', ')})`
240
272
  }
@@ -11,7 +11,7 @@ import { detectRootNamespaceWrapTag } from './control-flow/stringify/template-pa
11
11
  import { expandDynamicPropValue, expandConstantForReactivity, resolveRestSpreadOrigin, resolveRestSpreadNames } from './prop-handling.ts'
12
12
  import { extractFreeIdentifiersFromText } from './csr-substitute.ts'
13
13
  import { walkIR, stopAt } from './walker.ts'
14
- import { childPropsObjectExpr, codeSafeStringArray, isSpreadPropName, mergedExplicitPropExpr } from './child-props-object.ts'
14
+ import { childPropsObjectExpr, codeSafeStringArray, isSpreadPropName, mergedExplicitPropExpr, spreadsCallerBag } from './child-props-object.ts'
15
15
  import { buildLoopChainExpr } from '../loop-chain.ts'
16
16
  import { classifyDOMProp } from '@barefootjs/shared'
17
17
  import type { BindingScope } from '../scope/binding-scope.ts'
@@ -540,7 +540,7 @@ function jsxChildrenContainComponent(nodes: IRNode[]): boolean {
540
540
  * and whether it is read through a getter (deferred, so reactive) or is a
541
541
  * plain data property.
542
542
  */
543
- function componentInitPropValue(prop: IRProp, ctx: ClientJsContext): { expr: string; getter: boolean } {
543
+ function componentInitPropValue(prop: Pick<IRProp, 'name' | 'value'>, ctx: ClientJsContext): { expr: string; getter: boolean } {
544
544
  if (isEventHandlerName(prop.name)) {
545
545
  // Event handlers reach here only as `expression` variants.
546
546
  return { expr: attrValueToString(prop.value) ?? prop.name, getter: false }
@@ -594,24 +594,30 @@ function restKeyLiveRead(attr: IRElement['attrs'][number]): string {
594
594
  }
595
595
 
596
596
  /** Build propsExpr for a child component from its IR props. */
597
- function buildComponentPropsExpr(props: IRProp[], ctx: ClientJsContext): string {
598
- const knownSpreadProp = props.find(p => {
599
- if (!isSpreadPropName(p.name)) return false
600
- if (p.value.kind !== 'spread' && p.value.kind !== 'expression') return false
601
- const expr = p.value.kind === 'spread' ? p.value.expr : p.value.expr
602
- // #2723: resolve through any `const x__alias = x` hop onto the
603
- // rest/props binding — see `resolveRestSpreadOrigin`'s docstring.
604
- return resolveRestSpreadOrigin(ctx, expr) !== null
605
- })
606
- // The rest bag without the keys the component destructured, keyed the
607
- // way they arrive on `_p` (the `applyRestAttrs` exclusion set).
608
- const consumedKeys = ctx.propsParams.map(p => p.sourceName ?? p.name)
609
- return childPropsObjectExpr(props, prop => componentInitPropValue(prop, ctx), {
610
- forwardCaller: knownSpreadProp !== undefined,
611
- restBag: `forwardProps(${PROPS_PARAM}, {}, ${codeSafeStringArray(consumedKeys)})`,
597
+ function buildComponentPropsExpr(comp: Pick<IRComponent, 'props' | 'children'>, ctx: ClientJsContext): string {
598
+ return childPropsObjectExpr(comp.props, prop => componentInitPropValue(prop, ctx), {
599
+ trailing: callerBagCallChildrenEntry(comp, ctx),
612
600
  })
613
601
  }
614
602
 
603
+ /**
604
+ * The `children` entry of a call that spreads one of the component's own
605
+ * prop bags (`<Child {...rest}>…</Child>`, `<Child {...props}>…</Child>`)
606
+ * and has JSX children: the children, spelled as a `children={…}` prop is
607
+ * (`componentInitPropValue`), written last. JSX children are the call's
608
+ * last `children`, so they win over a `children` key the bag carries, and a
609
+ * bag that leaves `children` out (the component destructured it) still
610
+ * hands the child what the call wrote: `{children}`, `{children ?? 'x'}`,
611
+ * text or an element (#3714). Empty for a call without such a spread,
612
+ * which has no caller `children` to tell apart from its own.
613
+ */
614
+ function callerBagCallChildrenEntry(comp: Pick<IRComponent, 'props' | 'children'>, ctx: ClientJsContext): string[] {
615
+ if (comp.children.length === 0 || !spreadsCallerBag(comp.props)) return []
616
+ if (comp.props.some(prop => prop.name === 'children')) return []
617
+ const value = componentInitPropValue({ name: 'children', value: { kind: 'jsx-children', children: comp.children } }, ctx)
618
+ return value.expr === "''" ? [] : [`get children() { return ${value.expr} }`]
619
+ }
620
+
615
621
  /**
616
622
  * Push reactive child-prop entries for a component node into `ctx.reactiveChildProps`.
617
623
  * Mirrors the wrap-decision pass done during propsExpr construction; kept as a dedicated
@@ -666,13 +672,13 @@ function collectReactiveChildProps(node: IRComponent, ctx: ClientJsContext): voi
666
672
 
667
673
  /** Convert raw component info from IR traversal to ConditionalBranchChildComponent with built propsExpr. */
668
674
  function buildBranchChildComponents(
669
- rawComponents: Array<{ name: string; slotId: string | null; props: IRProp[] }>,
675
+ rawComponents: Array<{ name: string; slotId: string | null; props: IRProp[]; children: IRNode[] }>,
670
676
  ctx: ClientJsContext,
671
677
  ): ConditionalBranchChildComponent[] {
672
678
  return rawComponents.map(comp => ({
673
679
  name: comp.name,
674
680
  slotId: comp.slotId,
675
- propsExpr: buildComponentPropsExpr(comp.props, ctx),
681
+ propsExpr: buildComponentPropsExpr(comp, ctx),
676
682
  }))
677
683
  }
678
684
 
@@ -1063,7 +1069,7 @@ export function collectElements(
1063
1069
  ctx.childInits.push({
1064
1070
  name: c.name,
1065
1071
  slotId: c.slotId,
1066
- propsExpr: buildComponentPropsExpr(c.props, ctx),
1072
+ propsExpr: buildComponentPropsExpr(c, ctx),
1067
1073
  })
1068
1074
  }
1069
1075
 
@@ -1147,8 +1153,8 @@ function collectFromElement(element: IRElement, ctx: ClientJsContext, insideCond
1147
1153
  // `applyRestAttrs` filters `Object.keys(_p)` — which is always
1148
1154
  // caller-keyed (#2524 CSR half) — so the exclude list must use
1149
1155
  // the caller-facing key too, not the local binding name.
1150
- const consumedKeys =
1151
- spreadOrigin === 'rest' ? ctx.propsParams.map(p => p.sourceName ?? p.name) : []
1156
+ // Phase 1 lists them on the spread (`SpreadAttr.restOmittedKeys`).
1157
+ const consumedKeys = (attr.value.kind === 'spread' && attr.value.restOmittedKeys) || []
1152
1158
  const staticAttrKeys = element.attrs
1153
1159
  .filter(a => a.name !== '...')
1154
1160
  .map(a => a.name)
@@ -1826,54 +1832,33 @@ function summarizeLoopChildBranch(
1826
1832
  // on the branch root yields exactly this branch's direct bindings
1827
1833
  // without re-collecting what a nested arm already owns (#2347).
1828
1834
  reactiveAttrs: collectLoopChildReactiveAttrs(node, ctx, loopParam, loopParamBindings, true, preambleNames, loopIndex),
1829
- // Skip ONLY when the branch's entire content is a single bare
1830
- // `expression` (no wrapping element) that MAY yield a live DOM node —
1831
- // i.e. it contains a call anywhere (`node.hasFunctionCalls`, computed
1832
- // by the AST walk in `exprHasFunctionCalls`/jsx-to-ir.ts, recursively —
1833
- // catches a call nested in a template literal or a nested ternary, not
1834
- // just a top-level call). A call can return an Element (a hoisted
1835
- // `renderNode={(n) => <Pill/>}` callback lowered to a component call,
1836
- // #1211/#1213) and the compiler cannot tell from syntax whether it does
1837
- // — both `renderChild(...)` and `_p.renderCell(...)` are a
1838
- // `CallExpression` — so this stays conservative for ANY call, not just
1839
- // ones known to return JSX. Re-evaluating a non-idempotent call inside
1840
- // an *additional* nested createEffect (on top of the eval already done
1841
- // for the `__bfSlot`-wrapped splice whenever `insert()` (re-)mounts this
1842
- // branch) would call it again on every unrelated tick and discard the
1843
- // previous element's listeners/state.
1835
+ // The branch's own text slots, decided by the collector every other row
1836
+ // text goes through (`collectLoopChildReactiveTexts`): a slot whose
1837
+ // expression reads the row or a reactive source, or contains a call
1838
+ // (`decideWrapFromAstFlags`), gets an update effect inside this arm.
1839
+ // `insert()` (runtime/insert.ts) leaves a branch alone while its
1840
+ // condition is unchanged, so this effect is the only thing that
1841
+ // rewrites the branch when a keyed row is reused with a new item.
1842
+ //
1843
+ // That includes a branch that is one bare expression with a call in it
1844
+ // (`cond ? fmt(row.wait) : '0s'`, #3894). Such a branch used to get no
1845
+ // effect whatever it called, so the slot kept the value the row was
1846
+ // built with, while the same call directly in the row, or in a
1847
+ // conditional outside a loop, was re-evaluated.
1844
1848
  //
1845
- // Everything else — a property access (`row.label`), an identifier, a
1846
- // literal, a template literal, string concatenation, or a nested
1847
- // ternary of those — cannot itself construct a DOM node (only a JSX
1848
- // literal or a call can, and a JSX literal branch is never `type:
1849
- // 'expression'` in the first place — see `transformJsxExpression`), so
1850
- // it is safe to collect. This is the fix for the loop-branch-stale-text
1851
- // defect: a keyed loop row whose branch is e.g. `row.done ? row.label :
1852
- // 'pending'` previously had NO update path at all when `row.label`
1853
- // changed without `row.done` flipping — `insert()` (runtime/insert.ts)
1854
- // correctly no-ops when its condition is unchanged (branch-internal
1855
- // updates are deliberately the effect system's job, not DOM
1856
- // replacement's), but with reactiveTexts always `[]` for this shape,
1857
- // no effect existed either, so the branch was frozen at its mount-time
1858
- // value. The stale rationale in a prior version of this comment blamed
1859
- // "the loop-child arm's `$t()`-based anchor lookup", but `$t()` no
1860
- // longer exists — it was one of four content mechanisms deleted by the
1861
- // slot-unification work. The current claim door
1862
- // (`stringifyLoopChildArm` → `lazySlots(..., kind: 'markup')` →
1863
- // `writeMarkup`, runtime/claim-slots.ts) clears the claimed range and
1864
- // splices the Node by identity, so "lands beside the first" cannot
1865
- // happen through it; only the call's non-idempotence still applies, and
1866
- // that alone is why the skip narrows rather than disappears.
1849
+ // The one branch left without an effect is the one Phase 1 marks
1850
+ // `readsCallerValue`: it has a call and reads something the caller
1851
+ // supplied that may be or build a live element, such as a callback prop
1852
+ // (`props.renderNode ? props.renderNode(n) : <span/>`, #1211/#1213).
1853
+ // That element owns its state, and evaluating the branch again on every
1854
+ // change of the row's item would replace it each time, so the row keeps
1855
+ // the element `insert()` mounted with the branch.
1867
1856
  //
1868
- // Collecting here is necessary but not sufficient: `n.slotId` must also
1869
- // be set for `collectLoopChildReactiveTexts` (ir-to-client-js/
1870
- // reactivity.ts) to do anything — see `transformConditionalBranch`'s
1871
- // `refsLoopParam` check (jsx-to-ir.ts) for the matching half of this fix
1872
- // that gives a bare loop-item-reading branch a slotId at all, which also
1873
- // makes `irToHtmlTemplate` emit its `<!--bf:sN-->…<!--/-->` marker (the
1874
- // same call builds both the SSR and the CSR/hydration template, so the
1875
- // two can't disagree on shape).
1876
- reactiveTexts: node.type === 'expression' && node.hasFunctionCalls
1857
+ // `n.slotId` must be set for the collector to take a slot. See
1858
+ // `transformConditionalBranch`'s `refsLoopParam` check (jsx-to-ir.ts),
1859
+ // which gives a bare branch reading the loop item its slot and so the
1860
+ // `<!--bf:sN-->` marker in both the SSR and the client template.
1861
+ reactiveTexts: node.type === 'expression' && node.readsCallerValue
1877
1862
  ? []
1878
1863
  : collectLoopChildReactiveTexts(node, ctx, loopParam, loopParamBindings, true, preambleNames, loopIndex),
1879
1864
  }
@@ -61,8 +61,19 @@ export function computeFileScope(entryPath: string): string {
61
61
  */
62
62
  let _activeScope: { fileScope: string; nonExportedSiblings: Set<string> } | null = null
63
63
 
64
- export function setActiveComponentScope(scope: { fileScope: string; nonExportedSiblings: Set<string> } | null): void {
64
+ /**
65
+ * Install `scope` and return the scope it replaces. A compile restores the
66
+ * returned scope when it finishes instead of clearing to `null`: an adapter
67
+ * may compile another file from inside `generate()` (go-template reads a
68
+ * cross-file child's shape that way, #3753), and the outer compile's client
69
+ * JS is emitted after that nested compile returns.
70
+ */
71
+ export function setActiveComponentScope(
72
+ scope: { fileScope: string; nonExportedSiblings: Set<string> } | null,
73
+ ): { fileScope: string; nonExportedSiblings: Set<string> } | null {
74
+ const previous = _activeScope
65
75
  _activeScope = scope
76
+ return previous
66
77
  }
67
78
 
68
79
  /**
@@ -101,8 +112,11 @@ export function buildImportAliasMap(imports: readonly ImportInfo[]): Map<string,
101
112
  return aliases
102
113
  }
103
114
 
104
- export function setActiveImportAliases(aliases: ReadonlyMap<string, string> | null): void {
115
+ /** Install `aliases` and return the map it replaces (restored the same way as the component scope). */
116
+ export function setActiveImportAliases(aliases: ReadonlyMap<string, string> | null): ReadonlyMap<string, string> | null {
117
+ const previous = _activeImportAliases
105
118
  _activeImportAliases = aliases
119
+ return previous
106
120
  }
107
121
 
108
122
  /**
@@ -76,6 +76,7 @@ function wrapAttrValueExpression(value: AttrValue, wrap: (s: string) => string):
76
76
  ...AttrValueOf.spread(wrap(value.expr), value.templateExpr ? wrap(value.templateExpr) : undefined),
77
77
  ...(value.propsObject && { propsObject: true as const }),
78
78
  ...(value.callerBag !== undefined && { callerBag: value.callerBag }),
79
+ ...(value.restOmittedKeys !== undefined && { restOmittedKeys: value.restOmittedKeys }),
79
80
  }
80
81
  }
81
82
  }
@@ -65,6 +65,7 @@ function wrapAttrValueExpression(value: AttrValue, wrap: (s: string) => string):
65
65
  ...AttrValueOf.spread(wrap(value.expr), value.templateExpr ? wrap(value.templateExpr) : undefined),
66
66
  ...(value.propsObject && { propsObject: true as const }),
67
67
  ...(value.callerBag !== undefined && { callerBag: value.callerBag }),
68
+ ...(value.restOmittedKeys !== undefined && { restOmittedKeys: value.restOmittedKeys }),
68
69
  }
69
70
  }
70
71
  }
@@ -19,7 +19,7 @@ import { interp, spliceChildValue, conditionalMarkup, renderChildCall, mappedRow
19
19
  import { markupSlotIdsOf } from './markup-slots.ts'
20
20
  import { isEventHandlerName } from '../event-handler-name.ts'
21
21
  import { writesAnyBinding } from '../props-binding.ts'
22
- import { isObjectSpreadProp } from './child-props-object.ts'
22
+ import { callerBagSpreadOmit, isObjectSpreadProp, restBagExpr } from './child-props-object.ts'
23
23
 
24
24
  /** Static HTML is embedded in a JS template literal; dynamic expressions use interp(). */
25
25
  function escapeStaticTemplateHtml(text: string): string {
@@ -422,13 +422,14 @@ function renderTemplateAttrPart(
422
422
  * (#3688) — a later key overrides an earlier one, and the spread overrides
423
423
  * only the keys the caller passed. A spread of any other object
424
424
  * (`isObjectSpreadProp`: a loop row, an object prop, a local) is kept the
425
- * same way, so its keys reach the child in source order (#3861). A
426
- * `{...rest}` bag stays out: the init forwards it.
425
+ * same way, so its keys reach the child in source order (#3861). So is a
426
+ * `{...rest}` bag, spelled without the keys the component destructured
427
+ * (`restBagTemplateEntry`, #3714).
427
428
  */
428
429
  function keepsTemplateComponentProp(p: IRProp): boolean {
429
430
  if (p.name === 'key') return false
430
431
  if (p.name === '...' || p.name.startsWith('...')) {
431
- return p.value.kind === 'spread' && (p.value.propsObject === true || isObjectSpreadProp(p))
432
+ return p.value.kind === 'spread' && (callerBagSpreadOmit(p.value) !== null || isObjectSpreadProp(p))
432
433
  }
433
434
  return true
434
435
  }
@@ -438,6 +439,19 @@ function templatePropEntry(p: IRProp, valueExpr: string): string {
438
439
  return p.name === '...' || p.name.startsWith('...') ? `...${valueExpr}` : `${quotePropName(p.name)}: ${valueExpr}`
439
440
  }
440
441
 
442
+ /**
443
+ * The `renderChild(...)` props-object entry of a `{...rest}` bag spread
444
+ * (`SpreadAttr.callerBag === 'rest'`), or null when `p` is not one. The
445
+ * template holds the bag as the caller's whole props object (`_p`), so the
446
+ * entry spreads it without the keys the component destructured
447
+ * (`restBagExpr`, the spelling the init's props object uses), in the
448
+ * spread's source position (#3714).
449
+ */
450
+ function restBagTemplateEntry(p: IRProp): string | null {
451
+ if (p.value.kind !== 'spread' || p.value.callerBag !== 'rest') return null
452
+ return `...${restBagExpr(p.value.restOmittedKeys ?? [])}`
453
+ }
454
+
441
455
  /**
442
456
  * Source-of-truth predicates for the collision-safe spread-attrs merge
443
457
  * shared by all three CSR-side emit paths (`irToHtmlTemplate`,
@@ -927,6 +941,8 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
927
941
  .map(p => {
928
942
  // `/* @client */` defers the prop to hydrate via initChild.
929
943
  if (p.clientOnly) return null
944
+ const restBagEntry = restBagTemplateEntry(p)
945
+ if (restBagEntry !== null) return restBagEntry
930
946
  switch (p.value.kind) {
931
947
  case 'jsx-children': {
932
948
  const hoistedRecurse = (n: IRNode): string => irToHtmlTemplate(n, restSpreadNames, loopDepth, loopParams, branchSlotsVar, true)
@@ -2094,6 +2110,8 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
2094
2110
  .map(p => {
2095
2111
  // `/* @client */` defers the prop to hydrate via initChild.
2096
2112
  if (p.clientOnly) return null
2113
+ const restBagEntry = restBagTemplateEntry(p)
2114
+ if (restBagEntry !== null) return restBagEntry
2097
2115
  switch (p.value.kind) {
2098
2116
  case 'jsx-children': {
2099
2117
  const hoistedRecurse = (n: IRNode): string => irToComponentTemplateWithOpts(n, { ...opts, inHoistedChildren: true })
@@ -2784,6 +2802,8 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2784
2802
  // (built in collect-elements) reads the value once init
2785
2803
  // runs, mirroring the existing UNSAFE strip path below.
2786
2804
  if (p.clientOnly) return null
2805
+ const restBagEntry = restBagTemplateEntry(p)
2806
+ if (restBagEntry !== null) return restBagEntry
2787
2807
  switch (p.value.kind) {
2788
2808
  case 'jsx-children': {
2789
2809
  const hoistedRecurse = (n: IRNode): string => generateCsrTemplateWithOpts(n, { ...opts, inHoistedChildren: true })