@barefootjs/jsx 0.37.0 → 0.38.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.
- package/dist/adapters/env-signal.d.ts +0 -8
- package/dist/adapters/env-signal.d.ts.map +1 -1
- package/dist/adapters/interface.d.ts +12 -0
- package/dist/adapters/interface.d.ts.map +1 -1
- package/dist/analyzer.d.ts +40 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/builtin-lowering-plugins.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/component-root-scope-comment.d.ts +36 -0
- package/dist/component-root-scope-comment.d.ts.map +1 -0
- package/dist/errors.d.ts +3 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/event-handler-name.d.ts +13 -0
- package/dist/event-handler-name.d.ts.map +1 -0
- package/dist/expression-parser.d.ts +9 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/format-date-refusal.d.ts +37 -0
- package/dist/format-date-refusal.d.ts.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2973 -2310
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-branch-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-composite-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts +13 -2
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-reactive-effects.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/lazy-conditional.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/lazy-row-eligibility.d.ts +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts +9 -0
- package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +57 -12
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/shared.d.ts +44 -3
- package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts +7 -5
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/loop-child-arm.d.ts +9 -1
- package/dist/ir-to-client-js/control-flow/stringify/loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts +43 -2
- package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts +16 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/source-map.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +2 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +26 -0
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/opaque-local-accessor.d.ts +27 -0
- package/dist/opaque-local-accessor.d.ts.map +1 -0
- package/dist/to-locale-date-lowering.d.ts +7 -4
- package/dist/to-locale-date-lowering.d.ts.map +1 -1
- package/dist/types.d.ts +53 -17
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +724 -4564
- package/src/__tests__/binding-scope-ratchet.test.ts +21 -10
- package/src/__tests__/branch-local-in-raw-capture.test.ts +1 -1
- package/src/__tests__/branch-local-same-name-collision.test.ts +9 -9
- package/src/__tests__/client-js-generation.test.ts +175 -0
- package/src/__tests__/component-root-scope-comment.test.ts +106 -0
- package/src/__tests__/doc-examples.test.ts +12 -22
- package/src/__tests__/event-handler-name.test.ts +74 -0
- package/src/__tests__/flatmap-segments.test.ts +11 -9
- package/src/__tests__/format-date-refusal.test.ts +134 -0
- package/src/__tests__/fragment-wrapped-conditional-return-branch.test.ts +132 -0
- package/src/__tests__/hydrate-template.test.ts +9 -1
- package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +2 -2
- package/src/__tests__/issue-3009-loop-branch-ref.test.ts +80 -0
- package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +213 -0
- package/src/__tests__/issue-3113-init-fn-name-collision.test.ts +133 -0
- package/src/__tests__/jsx-return-type-assertion.test.ts +2 -2
- package/src/__tests__/lazy-row-eligibility.test.ts +5 -4
- package/src/__tests__/loop-row-child-children-reactive-attrs.test.ts +108 -0
- package/src/__tests__/loop-row-child-text-children-markers.test.ts +158 -0
- package/src/__tests__/opaque-local-accessor.test.ts +90 -0
- package/src/__tests__/profiler-e2e.test.ts +13 -8
- package/src/__tests__/ref-attr-absent-at-ssr.test.ts +472 -0
- package/src/__tests__/ssr-portal-ref-callback.test.ts +217 -0
- package/src/adapters/env-signal.ts +2 -21
- package/src/adapters/interface.ts +13 -0
- package/src/analyzer.ts +40 -28
- package/src/builtin-lowering-plugins.ts +0 -2
- package/src/compiler.ts +24 -0
- package/src/component-root-scope-comment.ts +59 -0
- package/src/errors.ts +44 -1
- package/src/event-handler-name.ts +14 -0
- package/src/expression-parser.ts +41 -17
- package/src/format-date-refusal.ts +266 -0
- package/src/index.ts +13 -3
- package/src/ir-to-client-js/child-components.ts +8 -3
- package/src/ir-to-client-js/collect-elements.ts +29 -13
- package/src/ir-to-client-js/control-flow/plan/build-branch-loop.ts +2 -4
- package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +67 -5
- package/src/ir-to-client-js/control-flow/plan/build-composite-loop.ts +3 -6
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +31 -1
- package/src/ir-to-client-js/control-flow/plan/build-loop.ts +23 -11
- package/src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts +5 -0
- package/src/ir-to-client-js/control-flow/plan/lazy-conditional.ts +1 -0
- package/src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts +3 -3
- package/src/ir-to-client-js/control-flow/plan/loop-child-arm.ts +11 -0
- package/src/ir-to-client-js/control-flow/plan/loop.ts +51 -10
- package/src/ir-to-client-js/control-flow/shared.ts +78 -5
- package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +25 -12
- package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +22 -1
- package/src/ir-to-client-js/emit-reactive.ts +140 -10
- package/src/ir-to-client-js/emit-registration.ts +2 -2
- package/src/ir-to-client-js/generate-init.ts +2 -2
- package/src/ir-to-client-js/html-template.ts +41 -19
- package/src/ir-to-client-js/index.ts +4 -3
- package/src/ir-to-client-js/reactivity.ts +28 -17
- package/src/ir-to-client-js/source-map.ts +2 -1
- package/src/ir-to-client-js/types.ts +2 -0
- package/src/ir-to-client-js/utils.ts +34 -0
- package/src/jsx-to-ir.ts +737 -49
- package/src/opaque-local-accessor.ts +44 -0
- package/src/rich-type-refusal.ts +1 -1
- package/src/to-locale-date-lowering.ts +7 -4
- package/src/types.ts +51 -15
- package/dist/format-date-lowering.d.ts +0 -30
- package/dist/format-date-lowering.d.ts.map +0 -1
- package/src/__tests__/create-selector.test.ts +0 -124
- package/src/__tests__/format-date-lowering.test.ts +0 -125
- package/src/format-date-lowering.ts +0 -55
|
@@ -47,6 +47,25 @@ function bindingIdArg(ctx: ClientJsContext, slotId: string | undefined): string
|
|
|
47
47
|
* hazard for anything that duck-types form controls via `'value' in el`
|
|
48
48
|
* (#2716).
|
|
49
49
|
*
|
|
50
|
+
* A single-selection `<select>` gets one more step (#3066,
|
|
51
|
+
* `select-out-of-range-selected-index`): if the assigned value matches no
|
|
52
|
+
* `<option>`, the browser resolves `select.value = __val` to no selection
|
|
53
|
+
* at all (`selectedIndex` -1) — but #2852 made SSR select a hidden
|
|
54
|
+
* placeholder `<option value="">` (`selectedIndex` 0) for exactly this
|
|
55
|
+
* case. Falling back to `selectedIndex = 0` here keeps the live post-
|
|
56
|
+
* hydration state equal to what SSR already rendered, instead of the two
|
|
57
|
+
* legs agreeing only visually (both blank) while their actual selection
|
|
58
|
+
* state diverges. `!target.multiple && target.size <= 1` excludes list
|
|
59
|
+
* boxes — mirroring `jsx-to-ir.ts`'s `isMultiSelection`, which skips the
|
|
60
|
+
* SSR placeholder for EITHER `multiple` OR a `size` > 1 (a `<select
|
|
61
|
+
* size={2}>` is a list box even without the `multiple` attribute): an
|
|
62
|
+
* unmatched value already leaves a `multiple`/`size>1` select with nothing
|
|
63
|
+
* selected on both legs (see `select-multiple-value-no-match-ssr`'s
|
|
64
|
+
* docstring), so there is no placeholder to reconcile against there and
|
|
65
|
+
* forcing a selection would be a behavior change of its own — checking
|
|
66
|
+
* `multiple` alone would wrongly force `selectedIndex = 0` on a bare
|
|
67
|
+
* `size={2}` select whose SSR leg (correctly) left nothing selected.
|
|
68
|
+
*
|
|
50
69
|
* NOT for the child-component-root `value` MIRROR (`emitReactivePropBindings`
|
|
51
70
|
* / `emitReactiveChildProps` reflecting a named prop onto a child's root
|
|
52
71
|
* element) — that mechanism has no SSR-rendered counterpart at all
|
|
@@ -56,7 +75,7 @@ function bindingIdArg(ctx: ClientJsContext, slotId: string | undefined): string
|
|
|
56
75
|
function emitValueUpdateStatements(target: string, expression: string): string[] {
|
|
57
76
|
return [
|
|
58
77
|
`const __val = String(${expression})`,
|
|
59
|
-
`if ('value' in ${target}) { if (${target}.value !== __val) ${target}.value = __val } else { ${target}.setAttribute('value', __val) }`,
|
|
78
|
+
`if ('value' in ${target}) { if (${target}.value !== __val) { ${target}.value = __val; if (${target}.tagName === 'SELECT' && !${target}.multiple && ${target}.size <= 1 && ${target}.value !== __val) ${target}.selectedIndex = 0 } } else { ${target}.setAttribute('value', __val) }`,
|
|
60
79
|
]
|
|
61
80
|
}
|
|
62
81
|
|
|
@@ -89,8 +108,41 @@ function emitChildValueMirrorStatements(target: string, expression: string): str
|
|
|
89
108
|
*
|
|
90
109
|
* Per-kind WRITE dispatch only — an effect body must never call this
|
|
91
110
|
* directly, only through `emitDedupedAttrUpdate` below (#2869).
|
|
111
|
+
*
|
|
112
|
+
* `mirrorSeed` (child-prop-mirror-attr-ssr): set only by the two
|
|
113
|
+
* CHILD-ROOT MIRROR callers (`emitReactivePropBindings` /
|
|
114
|
+
* `emitReactiveChildProps`) writing a parent-passed named prop onto a
|
|
115
|
+
* child component's root element, never for an element's OWN attribute
|
|
116
|
+
* binding. Unlike a developer-authored attribute on an element the
|
|
117
|
+
* compiler controls, this mirror has no way to know whether the CHILD
|
|
118
|
+
* actually renders `attrName` at all — the child may consume the prop as
|
|
119
|
+
* text, a class token, or not render it anywhere, in which case SSR never
|
|
120
|
+
* emits the attribute and an unconditional write here would plant one
|
|
121
|
+
* hydration alone created (the exact defect `child-prop-mirror-attr-ssr`
|
|
122
|
+
* tracked). So the generic/presence branches gate on whether the child's
|
|
123
|
+
* OWN render (SSR markup, or the child's own template on a client mount)
|
|
124
|
+
* put the attribute there — never CREATING an attribute SSR wouldn't have.
|
|
125
|
+
*
|
|
126
|
+
* The answer is read from the DOM ONCE, on the effect's first run, and
|
|
127
|
+
* remembered in the caller's `MIRROR_SEED_STORE_DECL` slot
|
|
128
|
+
* (`__m[i] ??= target.hasAttribute(name)`), never re-read: this branch's
|
|
129
|
+
* own `removeAttribute` (value went `null`) is what would flip a live
|
|
130
|
+
* `hasAttribute` read to `false`, and a live gate would then ratchet a
|
|
131
|
+
* one-time removal into a permanent stop — a forwarded prop that goes
|
|
132
|
+
* `null` and back would never be re-applied. Seeding once keeps the
|
|
133
|
+
* decision about the CHILD, not about the mirror's own last write.
|
|
134
|
+
* `class`/`value`/boolean stay ungated: `class` mirrors an established,
|
|
135
|
+
* separately-relied-on forwarding convention (icon components), and
|
|
136
|
+
* `value`/boolean already have their own no-SSR-fallback handling
|
|
137
|
+
* (`emitChildValueMirrorStatements`, #2716) this flag doesn't touch.
|
|
92
138
|
*/
|
|
93
|
-
export function emitAttrUpdate(
|
|
139
|
+
export function emitAttrUpdate(
|
|
140
|
+
target: string,
|
|
141
|
+
attrName: string,
|
|
142
|
+
expression: string,
|
|
143
|
+
meta: AttrMeta,
|
|
144
|
+
mirrorSeed: MirrorSeed | null = null,
|
|
145
|
+
): string[] {
|
|
94
146
|
const htmlName = toHtmlAttrName(attrName)
|
|
95
147
|
if (attrName === 'dangerouslySetInnerHTML' || htmlName === 'dangerouslySetInnerHTML') {
|
|
96
148
|
// `{ __html }` is not an attribute — it replaces the element's content.
|
|
@@ -115,16 +167,39 @@ export function emitAttrUpdate(target: string, attrName: string, expression: str
|
|
|
115
167
|
return emitValueUpdateStatements(target, expression)
|
|
116
168
|
}
|
|
117
169
|
if (isBooleanAttr(htmlName)) {
|
|
170
|
+
// CHILD-ROOT MIRROR case (`mirrorSeed` set): same reasoning as the
|
|
171
|
+
// `presenceOrUndefined`/generic branches below — a boolean-IDL name
|
|
172
|
+
// like `open`/`checked` is only a REAL property on the elements that
|
|
173
|
+
// natively expose it (`<details>`, `<dialog>`, form controls); the
|
|
174
|
+
// compiler can't know whether the CHILD's own root is one of those or
|
|
175
|
+
// an ordinary `<div>` that merely happens to receive a prop sharing
|
|
176
|
+
// that name. An unconditional `target.open = …` plants a live DOM
|
|
177
|
+
// property SSR never had (and never reflects to a visible attribute
|
|
178
|
+
// on a plain element), so gate it the same way: seed once from
|
|
179
|
+
// whether the child's OWN render already put the attribute there.
|
|
180
|
+
if (mirrorSeed) {
|
|
181
|
+
return [`if (${mirrorSeedGate(mirrorSeed, target, htmlName)}) ${target}.${htmlName} = !!(${expression})`]
|
|
182
|
+
}
|
|
118
183
|
return [`${target}.${htmlName} = !!(${expression})`]
|
|
119
184
|
}
|
|
120
185
|
if (meta.presenceOrUndefined) {
|
|
121
186
|
// aria-* requires explicit "true" value per WAI-ARIA spec
|
|
122
187
|
const attrVal = htmlName.startsWith('aria-') ? 'true' : ''
|
|
188
|
+
if (mirrorSeed) {
|
|
189
|
+
return [
|
|
190
|
+
`if (${mirrorSeedGate(mirrorSeed, target, htmlName)}) { if (${expression}) ${target}.setAttribute('${htmlName}', '${attrVal}'); else ${target}.removeAttribute('${htmlName}') }`,
|
|
191
|
+
]
|
|
192
|
+
}
|
|
123
193
|
return [
|
|
124
194
|
`if (${expression}) ${target}.setAttribute('${htmlName}', '${attrVal}')`,
|
|
125
195
|
`else ${target}.removeAttribute('${htmlName}')`,
|
|
126
196
|
]
|
|
127
197
|
}
|
|
198
|
+
if (mirrorSeed) {
|
|
199
|
+
return [
|
|
200
|
+
`if (${mirrorSeedGate(mirrorSeed, target, htmlName)}) { const __v = ${expression}; if (__v != null) ${target}.setAttribute('${htmlName}', String(__v)); else ${target}.removeAttribute('${htmlName}') }`,
|
|
201
|
+
]
|
|
202
|
+
}
|
|
128
203
|
return [
|
|
129
204
|
`{ const __v = ${expression}; if (__v != null) ${target}.setAttribute('${htmlName}', String(__v)); else ${target}.removeAttribute('${htmlName}') }`,
|
|
130
205
|
]
|
|
@@ -144,6 +219,27 @@ export function emitAttrUpdate(target: string, attrName: string, expression: str
|
|
|
144
219
|
*/
|
|
145
220
|
export const DEDUP_STORE_DECL = 'const __l = []'
|
|
146
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Per-effect store for the child-root mirror's seeded presence answers
|
|
224
|
+
* (`emitAttrUpdate`'s `mirrorSeed`) — `const __m = []`, declared once in
|
|
225
|
+
* the block that creates the mirror effect, indexed by the prop's ordinal
|
|
226
|
+
* within that effect.
|
|
227
|
+
*/
|
|
228
|
+
export const MIRROR_SEED_STORE_DECL = 'const __m = []'
|
|
229
|
+
|
|
230
|
+
/** Where one mirrored prop keeps its seeded "does the child render this attribute?" answer. */
|
|
231
|
+
export interface MirrorSeed {
|
|
232
|
+
/** The store variable declared by `MIRROR_SEED_STORE_DECL` in the enclosing block. */
|
|
233
|
+
store: string
|
|
234
|
+
/** This prop's slot in that store — unique within the effect. */
|
|
235
|
+
index: number
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** The seeded gate: read `hasAttribute` on the first run only, then reuse the answer. */
|
|
239
|
+
function mirrorSeedGate(seed: MirrorSeed, target: string, htmlName: string): string {
|
|
240
|
+
return `${seed.store}[${seed.index}] ??= ${target}.hasAttribute('${htmlName}')`
|
|
241
|
+
}
|
|
242
|
+
|
|
147
243
|
/**
|
|
148
244
|
* `__l`-backed dedup test. `in` (not a truthiness check) so a legitimately
|
|
149
245
|
* `undefined` value still records and still writes once; `!(N in __l)` on
|
|
@@ -191,8 +287,9 @@ export function emitDedupedAttrUpdate(
|
|
|
191
287
|
meta: AttrMeta,
|
|
192
288
|
ordinal: number,
|
|
193
289
|
guard: string | null = dedupGuard(ordinal),
|
|
290
|
+
mirrorSeed: MirrorSeed | null = null,
|
|
194
291
|
): string[] {
|
|
195
|
-
const write = emitAttrUpdate(target, attrName, '__x', meta)
|
|
292
|
+
const write = emitAttrUpdate(target, attrName, '__x', meta, mirrorSeed)
|
|
196
293
|
const lines = [`{ const __x = ${expression}`]
|
|
197
294
|
if (guard) {
|
|
198
295
|
lines.push(`if (${guard}) {`)
|
|
@@ -602,7 +699,22 @@ export function emitReactivePropBindings(lines: string[], ctx: ClientJsContext):
|
|
|
602
699
|
if (ctx.reactiveProps.length > 0) {
|
|
603
700
|
lines.push('')
|
|
604
701
|
lines.push(` // Reactive prop bindings`)
|
|
702
|
+
// The generic named-prop mirror AND the boolean-IDL mirror below both
|
|
703
|
+
// seed their presence answer once per prop (`emitAttrUpdate`'s
|
|
704
|
+
// `mirrorSeed`) — same CHILD-ROOT MIRROR reasoning `emitAttrUpdate`'s
|
|
705
|
+
// docstring gives for `emitReactiveChildProps`'s identical boolean
|
|
706
|
+
// branch: the compiler can't know whether this slot's root is one of
|
|
707
|
+
// the elements that natively expose e.g. `open`/`checked`, so an
|
|
708
|
+
// unconditional `target.open = …` here would plant a live DOM property
|
|
709
|
+
// SSR never rendered (`child-prop-mirror-attr-ssr`). The store is
|
|
710
|
+
// declared only when some prop takes one of those two paths, so
|
|
711
|
+
// effects made of `selected` / `value` mirrors alone keep their shape.
|
|
712
|
+
const usesMirrorSeed = (prop: ClientJsContext['reactiveProps'][number]): boolean =>
|
|
713
|
+
prop.propName !== 'selected' && prop.propName !== 'value'
|
|
714
|
+
const needsSeedStore = ctx.reactiveProps.some(usesMirrorSeed)
|
|
715
|
+
if (needsSeedStore) lines.push(` { ${MIRROR_SEED_STORE_DECL}`)
|
|
605
716
|
lines.push(` createEffect(() => {`)
|
|
717
|
+
let seedIndex = 0
|
|
606
718
|
|
|
607
719
|
const propsBySlot = new Map<string, typeof ctx.reactiveProps>()
|
|
608
720
|
for (const prop of ctx.reactiveProps) {
|
|
@@ -646,16 +758,27 @@ export function emitReactivePropBindings(lines: string[], ctx: ClientJsContext):
|
|
|
646
758
|
// truthy, so setAttribute('disabled', 'false') still disables the element.
|
|
647
759
|
} else if (prop.propName === 'value') {
|
|
648
760
|
for (const stmt of emitChildValueMirrorStatements(ref, value)) lines.push(` ${stmt}`)
|
|
649
|
-
} else if (isBooleanAttr(prop.propName)) {
|
|
650
|
-
lines.push(` ${ref}.${prop.propName} = !!(${value})`)
|
|
651
761
|
} else {
|
|
652
|
-
|
|
762
|
+
// Generic AND boolean-IDL named-prop mirror alike
|
|
763
|
+
// (child-prop-mirror-attr-ssr): `mirrorSeed` restricts the write
|
|
764
|
+
// to when the child's OWN render already put the
|
|
765
|
+
// `${prop.propName}` attribute on `ref` — see `emitAttrUpdate`'s
|
|
766
|
+
// docstring, which dispatches boolean-IDL names (`open`,
|
|
767
|
+
// `checked`, …) to its own gated branch internally. Routed
|
|
768
|
+
// through the shared dispatcher instead of a hand-rolled
|
|
769
|
+
// `target.x = !!(...)` / `setAttribute` so this and
|
|
770
|
+
// `emitReactiveChildProps`'s identical mirror share one
|
|
771
|
+
// implementation of the gate — a second hand-rolled boolean
|
|
772
|
+
// write here previously bypassed it entirely
|
|
773
|
+
// (child-prop-mirror-attr-ssr reopened via this parallel path).
|
|
774
|
+
const seed: MirrorSeed = { store: '__m', index: seedIndex++ }
|
|
775
|
+
for (const stmt of emitAttrUpdate(ref, prop.propName, value, {}, seed)) lines.push(` ${stmt}`)
|
|
653
776
|
}
|
|
654
777
|
}
|
|
655
778
|
lines.push(` }`)
|
|
656
779
|
}
|
|
657
780
|
|
|
658
|
-
lines.push(` }${bindingIdArg(ctx, ctx.reactiveProps[0]?.slotId)})`)
|
|
781
|
+
lines.push(` }${bindingIdArg(ctx, ctx.reactiveProps[0]?.slotId)})${needsSeedStore ? ' }' : ''}`)
|
|
659
782
|
}
|
|
660
783
|
}
|
|
661
784
|
|
|
@@ -664,7 +787,7 @@ export function emitReactiveChildProps(lines: string[], ctx: ClientJsContext): v
|
|
|
664
787
|
if (ctx.reactiveChildProps.length > 0) {
|
|
665
788
|
lines.push('')
|
|
666
789
|
lines.push(` // Reactive child component props`)
|
|
667
|
-
lines.push(` { ${DEDUP_STORE_DECL}`)
|
|
790
|
+
lines.push(` { ${DEDUP_STORE_DECL}; ${MIRROR_SEED_STORE_DECL}`)
|
|
668
791
|
lines.push(` createEffect(() => {`)
|
|
669
792
|
|
|
670
793
|
const propsByComponent = new Map<string, typeof ctx.reactiveChildProps>()
|
|
@@ -697,9 +820,16 @@ export function emitReactiveChildProps(lines: string[], ctx: ClientJsContext): v
|
|
|
697
820
|
// of `emitAttrUpdate`'s generic (attribute-fallback) dispatch;
|
|
698
821
|
// see `emitChildValueMirrorStatements`'s docstring (#2716). It has
|
|
699
822
|
// its own DOM-compare and consumes no dedup ordinal (#2869).
|
|
700
|
-
|
|
823
|
+
// `mirrorSeed` (child-prop-mirror-attr-ssr) — this is the
|
|
824
|
+
// CHILD-ROOT MIRROR, not an element's own attribute binding; see
|
|
825
|
+
// `emitAttrUpdate`'s docstring for why only the generic/presence
|
|
826
|
+
// branches gate on the child's rendered attribute, seeded once.
|
|
827
|
+
// The dedup ordinal doubles as the seed slot: unique per prop here.
|
|
828
|
+
const isValueMirror = toHtmlAttrName(prop.attrName) === 'value'
|
|
829
|
+
const stmts = isValueMirror
|
|
701
830
|
? emitChildValueMirrorStatements(varName, prop.expression)
|
|
702
|
-
: emitDedupedAttrUpdate(varName, prop.attrName, prop.expression, prop, ordinal
|
|
831
|
+
: emitDedupedAttrUpdate(varName, prop.attrName, prop.expression, prop, ordinal, dedupGuard(ordinal), { store: '__m', index: ordinal })
|
|
832
|
+
if (!isValueMirror) ordinal++
|
|
703
833
|
for (const stmt of stmts) {
|
|
704
834
|
lines.push(` ${stmt}`)
|
|
705
835
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import type { ComponentIR, IRFragment, IRNode, ReferencesGraph, SignalInfo } from '../types.ts'
|
|
8
8
|
import type { ClientJsContext } from './types.ts'
|
|
9
|
-
import { PROPS_PARAM, isCommentScopedRoot } from './utils.ts'
|
|
9
|
+
import { PROPS_PARAM, isCommentScopedRoot, initFunctionName } from './utils.ts'
|
|
10
10
|
import { computeInlinability, toLegacyInlinability } from './compute-inlinability.ts'
|
|
11
11
|
import { canGenerateStaticTemplate, irToComponentTemplate, generateCsrTemplate, createStringProtector } from './html-template.ts'
|
|
12
12
|
import { markupSlotIdsOf } from './markup-slots.ts'
|
|
@@ -218,7 +218,7 @@ export function emitRegistrationAndHydration(
|
|
|
218
218
|
const isCommentScope = isCommentScopedRoot(_ir.root)
|
|
219
219
|
|
|
220
220
|
// Build ComponentDef object for hydrate()
|
|
221
|
-
const defParts: string[] = [`init:
|
|
221
|
+
const defParts: string[] = [`init: ${initFunctionName(name)}`]
|
|
222
222
|
if (canGenerateStaticTemplate(_ir.root, propNamesForStaticCheck, inlinableConstants, unsafeLocalNames)) {
|
|
223
223
|
const markupSlotIds = markupSlotIdsOf(ctx)
|
|
224
224
|
const templateHtml = irToComponentTemplate(_ir.root, inlinableConstants, restSpreadNames, ctx.propsObjectName, markupSlotIds, ctx.restPropsName)
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import type { ComponentIR } from '../types.ts'
|
|
12
12
|
import type { ClientJsContext } from './types.ts'
|
|
13
|
-
import { PROPS_PARAM, isCommentScopedRoot } from './utils.ts'
|
|
13
|
+
import { PROPS_PARAM, isCommentScopedRoot, initFunctionName } from './utils.ts'
|
|
14
14
|
import { buildReferencesGraph } from './build-references.ts'
|
|
15
15
|
import { computePropUsage } from './compute-prop-usage.ts'
|
|
16
16
|
import { IMPORT_PLACEHOLDER, MODULE_CONSTANTS_PLACEHOLDER } from './imports.ts'
|
|
@@ -40,7 +40,7 @@ export function generateInitFunction(
|
|
|
40
40
|
emitChildComponentImports(lines, ctx, new Set(siblingComponents || []))
|
|
41
41
|
lines.push('')
|
|
42
42
|
lines.push(MODULE_CONSTANTS_PLACEHOLDER)
|
|
43
|
-
lines.push(`export function
|
|
43
|
+
lines.push(`export function ${initFunctionName(name)}(__scope, ${PROPS_PARAM} = {}) {`)
|
|
44
44
|
lines.push(` if (!__scope) return`)
|
|
45
45
|
// Host scope id for (bf-h, bf-m) child lookups inside this init body
|
|
46
46
|
// (#1249). Compile-time selectors emit
|
|
@@ -11,12 +11,13 @@ import { assertNever } from './walker.ts'
|
|
|
11
11
|
import { buildSignalMemoEnv, csrSubstitute, type CsrEnv } from './csr-substitute.ts'
|
|
12
12
|
import { rewritePropsObjectRef } from './rewrite-props-object.ts'
|
|
13
13
|
import type { ClientJsContext } from './types.ts'
|
|
14
|
-
import { BF_PARENT_SCOPE_PLACEHOLDER, BF_SCOPE, classifyDOMProp, escapeHtml } from '@barefootjs/shared'
|
|
14
|
+
import { BF_KEY, BF_PARENT_SCOPE_PLACEHOLDER, BF_SCOPE, classifyDOMProp, escapeHtml } from '@barefootjs/shared'
|
|
15
15
|
import { buildLoopChainExpr } from '../loop-chain.ts'
|
|
16
16
|
import { renderChildScopeArgs } from '../adapters/child-scope.ts'
|
|
17
17
|
import { BindingScope } from '../scope/binding-scope.ts'
|
|
18
18
|
import { interp, spliceChildValue, conditionalMarkup, renderChildCall, mappedRowsMarkup, dangerousInnerHtml, EMPTY_MARKUP } from './safe-html.ts'
|
|
19
19
|
import { markupSlotIdsOf } from './markup-slots.ts'
|
|
20
|
+
import { isEventHandlerName } from '../event-handler-name.ts'
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Protect string literals from regex-based replacements.
|
|
@@ -644,10 +645,30 @@ export function flatMapLeafKeyExpr(ir: IRNode): string | null {
|
|
|
644
645
|
}
|
|
645
646
|
}
|
|
646
647
|
|
|
647
|
-
/**
|
|
648
|
-
|
|
648
|
+
/**
|
|
649
|
+
* Copy of `ir` with the loop `key` attribute replaced by the reconciliation
|
|
650
|
+
* attribute the runtime keys on: `data-key={String(<key>)}` (element leaves
|
|
651
|
+
* only; a keyless leaf just loses nothing). This is the one client-side
|
|
652
|
+
* rendering of a flatMap leaf's key — the hydrate template, the CSR
|
|
653
|
+
* descriptor and the module-scope template all go through it — and it
|
|
654
|
+
* mirrors what SSR emits from the rawBody (`flatMapRawBodyWithLeafKeys`,
|
|
655
|
+
* jsx-to-ir.ts) and what `mapArray` stamps on adoption/creation (`BF_KEY`;
|
|
656
|
+
* the descriptor path never passes a depth-suffixed name), so every
|
|
657
|
+
* construction path agrees on the attribute. Rendered as an ordinary
|
|
658
|
+
* expression attribute, so it is escaped like one.
|
|
659
|
+
*/
|
|
660
|
+
function leafKeyAsDataKeyAttr(ir: IRNode): IRNode {
|
|
649
661
|
if (ir.type !== 'element') return ir
|
|
650
|
-
|
|
662
|
+
const keyExpr = flatMapLeafKeyExpr(ir)
|
|
663
|
+
if (keyExpr === null) return { ...ir, attrs: ir.attrs.filter((a) => a.name !== 'key') }
|
|
664
|
+
// In place, not appended: SSR splices `data-key` at the `key` attribute's
|
|
665
|
+
// position, so the attribute order matches byte-for-byte.
|
|
666
|
+
return {
|
|
667
|
+
...ir,
|
|
668
|
+
attrs: ir.attrs.map((a) =>
|
|
669
|
+
a.name === 'key' ? { ...a, name: BF_KEY, value: { kind: 'expression' as const, expr: `String(${keyExpr})` } } : a,
|
|
670
|
+
),
|
|
671
|
+
}
|
|
651
672
|
}
|
|
652
673
|
|
|
653
674
|
/**
|
|
@@ -675,7 +696,7 @@ export function renderFlatMapClientBody(
|
|
|
675
696
|
rawLeaf: true,
|
|
676
697
|
renderLeaf: (ir) => {
|
|
677
698
|
const key = flatMapLeafKeyExpr(ir)
|
|
678
|
-
const html = irToHtmlTemplate(
|
|
699
|
+
const html = irToHtmlTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, 1, undefined, undefined)
|
|
679
700
|
return `({ k: ${key ?? 'undefined'}, h: \`${html}\` })`
|
|
680
701
|
},
|
|
681
702
|
})
|
|
@@ -871,7 +892,7 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
|
|
|
871
892
|
// during module-scope string rendering, and a ref closing over an
|
|
872
893
|
// init-scope setter would leak it into the template (#2468). The
|
|
873
894
|
// init path re-applies refs once real DOM exists.
|
|
874
|
-
.filter(p => p.name !== 'ref' && !(
|
|
895
|
+
.filter(p => p.name !== 'ref' && !(isEventHandlerName(p.name)))
|
|
875
896
|
.map(p => {
|
|
876
897
|
// `/* @client */` defers the prop to hydrate via initChild.
|
|
877
898
|
if (p.clientOnly) return null
|
|
@@ -974,12 +995,13 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
|
|
|
974
995
|
if (node.flatMapCallback) {
|
|
975
996
|
// Complex flatMap: the body is structured segments, rendered through
|
|
976
997
|
// the same single door as map preambles.
|
|
977
|
-
//
|
|
978
|
-
//
|
|
979
|
-
//
|
|
980
|
-
//
|
|
998
|
+
// The leaf `key` renders as `data-key={String(<key>)}` here, in the
|
|
999
|
+
// CSR descriptor (`renderFlatMapClientBody`) and in the SSR rawBody
|
|
1000
|
+
// (`flatMapRawBodyWithLeafKeys`, jsx-to-ir.ts) alike — the attribute
|
|
1001
|
+
// `mapArray` stamps on adoption/creation, so SSR, hydrate template and
|
|
1002
|
+
// csr-mount agree on it (see `leafKeyAsDataKeyAttr`).
|
|
981
1003
|
const body = renderPreamble(node.flatMapCallback, {
|
|
982
|
-
renderLeaf: (ir) => irToHtmlTemplate(
|
|
1004
|
+
renderLeaf: (ir) => irToHtmlTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, loopDepth + 1, loopParams, branchSlotsVar),
|
|
983
1005
|
})
|
|
984
1006
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, 'flatMap', node.flatMapCallback.params, body))
|
|
985
1007
|
} else if (node.preamble) {
|
|
@@ -1445,8 +1467,8 @@ export function irToPlaceholderTemplate(node: IRNode, restSpreadNames?: Readonly
|
|
|
1445
1467
|
let mapExpr: string
|
|
1446
1468
|
if (node.flatMapCallback) {
|
|
1447
1469
|
const body = renderPreamble(node.flatMapCallback, {
|
|
1448
|
-
// Leaf `key`
|
|
1449
|
-
renderLeaf: (ir) => irToPlaceholderTemplate(
|
|
1470
|
+
// Leaf `key` → `data-key` — see the irToHtmlTemplate site above.
|
|
1471
|
+
renderLeaf: (ir) => irToPlaceholderTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, loopDepth + 1, loopParams),
|
|
1450
1472
|
})
|
|
1451
1473
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, 'flatMap', node.flatMapCallback.params, body))
|
|
1452
1474
|
} else if (node.preamble) {
|
|
@@ -1537,7 +1559,7 @@ function irNodeToJsExprs(node: IRNode, brandMarkup = false): string[] {
|
|
|
1537
1559
|
const propsEntries: string[] = node.props
|
|
1538
1560
|
.filter(p => p.name !== 'key' && p.name !== '...' && !p.name.startsWith('...'))
|
|
1539
1561
|
.map(p => {
|
|
1540
|
-
if (
|
|
1562
|
+
if (isEventHandlerName(p.name)) {
|
|
1541
1563
|
return `${quotePropName(p.name)}: ${attrValueToString(p.value) ?? 'undefined'}`
|
|
1542
1564
|
}
|
|
1543
1565
|
switch (p.value.kind) {
|
|
@@ -2020,7 +2042,7 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
|
|
|
2020
2042
|
// during module-scope string rendering, and a ref closing over an
|
|
2021
2043
|
// init-scope setter would leak it into the template (#2468). The
|
|
2022
2044
|
// init path re-applies refs once real DOM exists.
|
|
2023
|
-
.filter(p => p.name !== 'ref' && !(
|
|
2045
|
+
.filter(p => p.name !== 'ref' && !(isEventHandlerName(p.name)))
|
|
2024
2046
|
.map(p => {
|
|
2025
2047
|
// `/* @client */` defers the prop to hydrate via initChild.
|
|
2026
2048
|
if (p.clientOnly) return null
|
|
@@ -2401,7 +2423,7 @@ export function computeDeferredChildSlots(
|
|
|
2401
2423
|
// `component` emit below so the deferral decision matches output.
|
|
2402
2424
|
if (p.name === '...' || p.name.startsWith('...') || p.name === 'key') return false
|
|
2403
2425
|
if (p.name === 'ref') return false
|
|
2404
|
-
if (
|
|
2426
|
+
if (isEventHandlerName(p.name)) return false
|
|
2405
2427
|
if (p.clientOnly) return false
|
|
2406
2428
|
return propResolvesUnsafe(p, env, unsafeLocalNames)
|
|
2407
2429
|
})
|
|
@@ -2671,7 +2693,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2671
2693
|
// during module-scope string rendering, and a ref closing over an
|
|
2672
2694
|
// init-scope setter would leak it into the template (#2468). The
|
|
2673
2695
|
// init path re-applies refs once real DOM exists.
|
|
2674
|
-
.filter(p => p.name !== 'ref' && !(
|
|
2696
|
+
.filter(p => p.name !== 'ref' && !(isEventHandlerName(p.name)))
|
|
2675
2697
|
.map(p => {
|
|
2676
2698
|
// `/* @client */` defers the prop to hydrate. Drop from the
|
|
2677
2699
|
// SSR `renderChild` props — `initChild`'s `propsExpr` getter
|
|
@@ -2791,8 +2813,8 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2791
2813
|
const body = renderPreamble(node.flatMapCallback, {
|
|
2792
2814
|
textVariant: 'template',
|
|
2793
2815
|
transformJs: (t) => rewritePropsObjectRef(t, propsObjectName ?? null, restPropsName ?? null, { enclosingScope: childScope }),
|
|
2794
|
-
// Leaf `key`
|
|
2795
|
-
renderLeaf: (ir) => recurseInLoopBody(
|
|
2816
|
+
// Leaf `key` → `data-key` — see the irToHtmlTemplate site above.
|
|
2817
|
+
renderLeaf: (ir) => recurseInLoopBody(leafKeyAsDataKeyAttr(ir)),
|
|
2796
2818
|
})
|
|
2797
2819
|
mapExpr = interp(mappedRowsMarkup(iterArrayExpr, 'flatMap', node.flatMapCallback.params, body))
|
|
2798
2820
|
} else if (node.preamble) {
|
|
@@ -16,7 +16,7 @@ import { buildReferencesGraph, graphUsedIdentifiers } from './build-references.t
|
|
|
16
16
|
import { addConstantPropRefsToSet } from './init-declarations.ts'
|
|
17
17
|
import { canGenerateStaticTemplate, irToComponentTemplate, generateCsrTemplate } from './html-template.ts'
|
|
18
18
|
import { markupSlotIdsOf } from './markup-slots.ts'
|
|
19
|
-
import { PROPS_PARAM } from './utils.ts'
|
|
19
|
+
import { PROPS_PARAM, initFunctionName } from './utils.ts'
|
|
20
20
|
import { buildInlinableConstants, csrInlinableConstantsFromCtx } from './emit-registration.ts'
|
|
21
21
|
import { buildEnvFromCtx } from './compute-inlinability.ts'
|
|
22
22
|
import { nameForRegistryRef, buildImportAliasMap, setActiveImportAliases } from './component-scope.ts'
|
|
@@ -356,13 +356,14 @@ function generateTemplateOnlyMount(ir: ComponentIR, ctx: ClientJsContext): strin
|
|
|
356
356
|
|
|
357
357
|
lines.push(IMPORT_PLACEHOLDER)
|
|
358
358
|
lines.push('')
|
|
359
|
-
|
|
359
|
+
const initName = initFunctionName(name)
|
|
360
|
+
lines.push(`function ${initName}() {}`)
|
|
360
361
|
lines.push('')
|
|
361
362
|
// `name: '...'` only when the key was file-scoped — same reason as in
|
|
362
363
|
// `emitRegistrationAndHydration`: the hashed key must not reach `bf-s`
|
|
363
364
|
// (#2518).
|
|
364
365
|
const nameField = registryKey !== name ? `, name: '${name}'` : ''
|
|
365
|
-
lines.push(`hydrate('${registryKey}', { init:
|
|
366
|
+
lines.push(`hydrate('${registryKey}', { init: ${initName}, template: (${PROPS_PARAM}) => \`${templateHtml}\`${nameField} })`)
|
|
366
367
|
// See `emitRegistrationAndHydration` (./emit-registration.ts) for the
|
|
367
368
|
// rationale on why the component is also emitted as a callable
|
|
368
369
|
// shim. The same applies for template-only components since they
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Reactivity detection: reactive expression checking, event/ref collection.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { type IRNode, type IRElement, type IRProp, type LoopParamBinding, type OriginInfo, pickAttrMetaFromIR, isReactiveOrigin } from '../types.ts'
|
|
5
|
+
import { type IRNode, type IRElement, type IRComponent, type IRProp, type LoopParamBinding, type OriginInfo, pickAttrMetaFromIR, isReactiveOrigin } from '../types.ts'
|
|
6
6
|
import type {
|
|
7
7
|
ClientJsContext,
|
|
8
8
|
ConditionalBranchEvent,
|
|
@@ -20,6 +20,7 @@ import { extractFreeIdentifiersFromText } from './csr-substitute.ts'
|
|
|
20
20
|
import { walkIR, stopAt } from './walker.ts'
|
|
21
21
|
import { BindingScope } from '../scope/binding-scope.ts'
|
|
22
22
|
import { identifierCallPattern } from '../identifier-pattern.ts'
|
|
23
|
+
import { isEventHandlerName } from '../event-handler-name.ts'
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* Build the `BindingScope` for one loop row's own bindings — item /
|
|
@@ -384,7 +385,7 @@ export function collectEventHandlersFromIR(node: IRNode): string[] {
|
|
|
384
385
|
},
|
|
385
386
|
component: ({ node, descend }) => {
|
|
386
387
|
for (const prop of node.props) {
|
|
387
|
-
if (
|
|
388
|
+
if (isEventHandlerName(prop.name)) {
|
|
388
389
|
const handler = attrValueToString(prop.value)
|
|
389
390
|
if (handler) handlers.push(handler)
|
|
390
391
|
}
|
|
@@ -502,6 +503,13 @@ export function collectConditionalBranchRefs(node: IRNode): ConditionalBranchRef
|
|
|
502
503
|
* `traverseElements` already stops at nested loops, so refs on elements
|
|
503
504
|
* inside a `.map().map()` are picked up by that nested loop's own collector
|
|
504
505
|
* pass, not by the outer one.
|
|
506
|
+
*
|
|
507
|
+
* Also stops at a nested reactive conditional (#3009, matching
|
|
508
|
+
* `collectConditionalBranchEvents`'s `true`): its caller collects that
|
|
509
|
+
* conditional separately and gives its branches their own ref collection
|
|
510
|
+
* (`LoopChildBranchSummary.refs`). Descending here too would hoist a
|
|
511
|
+
* branch's ref to row level, where it fires only once at row creation
|
|
512
|
+
* instead of on every branch activation — the bug #3009 fixed.
|
|
505
513
|
*/
|
|
506
514
|
export function collectLoopChildRefs(node: IRNode): LoopChildRef[] {
|
|
507
515
|
const refs: LoopChildRef[] = []
|
|
@@ -512,7 +520,7 @@ export function collectLoopChildRefs(node: IRNode): LoopChildRef[] {
|
|
|
512
520
|
callback: el.ref,
|
|
513
521
|
})
|
|
514
522
|
}
|
|
515
|
-
})
|
|
523
|
+
}, true)
|
|
516
524
|
return refs
|
|
517
525
|
}
|
|
518
526
|
|
|
@@ -647,16 +655,23 @@ export function collectConditionalBranchChildComponents(
|
|
|
647
655
|
node: IRNode,
|
|
648
656
|
skipConditionals = false,
|
|
649
657
|
): Array<{ name: string; slotId: string | null; props: IRProp[]; children: IRNode[] }> {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
658
|
+
return collectConditionalBranchComponentNodes(node, skipConditionals).map(c => ({
|
|
659
|
+
name: c.name,
|
|
660
|
+
slotId: c.slotId,
|
|
661
|
+
props: c.props,
|
|
662
|
+
children: c.children,
|
|
663
|
+
}))
|
|
653
664
|
}
|
|
654
665
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
666
|
+
/**
|
|
667
|
+
* The component nodes a conditional branch's `bindEvents` initializes —
|
|
668
|
+
* THE definition of which children a branch owns. `collectConditionalBranchChildComponents`
|
|
669
|
+
* (what the branch emits `initChild` for) and the main collector's static
|
|
670
|
+
* child-init pass (which must skip exactly these, or the child is
|
|
671
|
+
* initialized twice) both read it.
|
|
672
|
+
*/
|
|
673
|
+
export function collectConditionalBranchComponentNodes(node: IRNode, skipConditionals = false): IRComponent[] {
|
|
674
|
+
const components: IRComponent[] = []
|
|
660
675
|
// Loops never contain collected components via this walker; halting there
|
|
661
676
|
// matches the pre-walker behaviour (no 'loop' case in the switch).
|
|
662
677
|
// skipConditionals also halts at nested conditionals / if-statements.
|
|
@@ -666,16 +681,12 @@ function traverseForComponents(
|
|
|
666
681
|
walkIR(node, null, {
|
|
667
682
|
...stops,
|
|
668
683
|
component: ({ node, descend }) => {
|
|
669
|
-
components.push(
|
|
670
|
-
name: node.name,
|
|
671
|
-
slotId: node.slotId,
|
|
672
|
-
props: node.props,
|
|
673
|
-
children: node.children,
|
|
674
|
-
})
|
|
684
|
+
components.push(node)
|
|
675
685
|
// Recurse into children passed to this component.
|
|
676
686
|
descend()
|
|
677
687
|
},
|
|
678
688
|
})
|
|
689
|
+
return components
|
|
679
690
|
}
|
|
680
691
|
|
|
681
692
|
/**
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { SourceLocation } from '../types.ts'
|
|
10
|
+
import { initFunctionName } from './utils.ts'
|
|
10
11
|
|
|
11
12
|
// =============================================================================
|
|
12
13
|
// VLQ Base64 Encoding
|
|
@@ -271,7 +272,7 @@ export function buildSourceMapFromIR(
|
|
|
271
272
|
mapEventHandlers(lines, ir.root, gen)
|
|
272
273
|
|
|
273
274
|
// Map the init function declaration to the component function
|
|
274
|
-
const initLine = findLineIndex(lines, `export function
|
|
275
|
+
const initLine = findLineIndex(lines, `export function ${initFunctionName(meta.componentName)}(`)
|
|
275
276
|
if (initLine >= 0 && ir.root.loc) {
|
|
276
277
|
gen.addMappingFromLoc(initLine, 0, ir.root.loc)
|
|
277
278
|
}
|
|
@@ -580,6 +580,8 @@ export interface LoopChildBranchSummary {
|
|
|
580
580
|
conditionals?: LoopChildConditional[]
|
|
581
581
|
/** Events on elements inside the branch — attached via insert() bindEvents (#839). */
|
|
582
582
|
events?: ConditionalBranchEvent[]
|
|
583
|
+
/** Refs on elements directly inside the branch — attached via insert() bindEvents, same as `events` above (#3009). Mirrors the top-level `BranchSummary.refs`. */
|
|
584
|
+
refs?: ConditionalBranchRef[]
|
|
583
585
|
/**
|
|
584
586
|
* Reactive attrs on elements directly inside the branch — attached via
|
|
585
587
|
* insert() bindEvents (#2347). Collected loop-param-aware so `u().active`
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
toHTMLAttrName as toHtmlAttrName,
|
|
28
28
|
keyAttrName as sharedKeyAttrName,
|
|
29
29
|
} from '@barefootjs/shared'
|
|
30
|
+
import { RUNTIME_IMPORT_CANDIDATES } from './imports.ts'
|
|
30
31
|
|
|
31
32
|
export { DATA_KEY, DATA_KEY_PREFIX, DATA_BF_PH, BF_LOOP_START, BF_LOOP_END, loopStartMarker, loopEndMarker, loopItemMarker, toHtmlAttrName }
|
|
32
33
|
|
|
@@ -36,6 +37,39 @@ export { DATA_KEY, DATA_KEY_PREFIX, DATA_BF_PH, BF_LOOP_START, BF_LOOP_END, loop
|
|
|
36
37
|
*/
|
|
37
38
|
export const PROPS_PARAM = '_p'
|
|
38
39
|
|
|
40
|
+
/** Every runtime helper name a generated module may import bare (#3113). */
|
|
41
|
+
const RESERVED_RUNTIME_NAMES = new Set<string>(RUNTIME_IMPORT_CANDIDATES)
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Name of the per-component init function (`init<Name>`), consistently
|
|
45
|
+
* computed wherever it's declared, registered, called, or located for
|
|
46
|
+
* source-mapping (#3113).
|
|
47
|
+
*
|
|
48
|
+
* The naive `` `init${name}` `` collides with the runtime's own imported
|
|
49
|
+
* `initChild` whenever a component is literally named `Child` — the
|
|
50
|
+
* generated module then both `import`s `initChild` from
|
|
51
|
+
* `@barefootjs/client/runtime` (to dispatch INTO this or another child)
|
|
52
|
+
* AND `export function initChild(...)` (THIS component's own compiled
|
|
53
|
+
* init) as two top-level declarations of the same identifier, which is a
|
|
54
|
+
* hard `SyntaxError` under real ES module semantics (verified against a
|
|
55
|
+
* raw `<script type="module">` load — the same unbundled-ESM shape
|
|
56
|
+
* `bf build` ships and `fixture-host.ts`'s `'hydrate'`/`'csr-mount'` modes
|
|
57
|
+
* serve, #2481). No bundler downstream can rescue a same-module identifier
|
|
58
|
+
* collision — a bundler renames colliding identifiers ACROSS merged
|
|
59
|
+
* modules, but `import { initChild } from '...'` and
|
|
60
|
+
* `function initChild() {}` live in the SAME module and are simply invalid
|
|
61
|
+
* syntax before any bundler sees them.
|
|
62
|
+
*
|
|
63
|
+
* Trailing `$` (rather than a numeric/underscore suffix) guarantees the
|
|
64
|
+
* disambiguated name can never itself collide with a *future*
|
|
65
|
+
* `RUNTIME_IMPORT_CANDIDATES` entry — none of those are, or plausibly will
|
|
66
|
+
* be, `$`-suffixed.
|
|
67
|
+
*/
|
|
68
|
+
export function initFunctionName(componentName: string): string {
|
|
69
|
+
const name = `init${componentName}`
|
|
70
|
+
return RESERVED_RUNTIME_NAMES.has(name) ? `${name}$` : name
|
|
71
|
+
}
|
|
72
|
+
|
|
39
73
|
/**
|
|
40
74
|
* True when the component's rendered root is a comment-scoped proxy rather
|
|
41
75
|
* than an element carrying its own `bf-s`/`bf-h` scope id directly — the
|