@barefootjs/jsx 0.40.1 → 0.41.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/boolean-result.d.ts +32 -10
- package/dist/adapters/boolean-result.d.ts.map +1 -1
- package/dist/adapters/brace-delimiter-text.d.ts +18 -0
- package/dist/adapters/brace-delimiter-text.d.ts.map +1 -0
- package/dist/adapters/callback-method.d.ts +45 -5
- package/dist/adapters/callback-method.d.ts.map +1 -1
- package/dist/adapters/component-props.d.ts +3 -4
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/computed-const.d.ts +11 -1
- package/dist/adapters/computed-const.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +24 -12
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
- package/dist/adapters/loop-bound-names.d.ts +9 -1
- package/dist/adapters/loop-bound-names.d.ts.map +1 -1
- package/dist/adapters/loop-row-type.d.ts +59 -0
- package/dist/adapters/loop-row-type.d.ts.map +1 -0
- package/dist/adapters/nil-reading.d.ts +63 -0
- package/dist/adapters/nil-reading.d.ts.map +1 -0
- package/dist/adapters/non-primitive-equality.d.ts +33 -0
- package/dist/adapters/non-primitive-equality.d.ts.map +1 -0
- package/dist/adapters/number-value.d.ts +5 -3
- package/dist/adapters/number-value.d.ts.map +1 -1
- package/dist/adapters/operand-typing.d.ts +126 -0
- package/dist/adapters/operand-typing.d.ts.map +1 -0
- package/dist/adapters/parsed-expr-emitter.d.ts +80 -12
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/primitive-plan.d.ts +320 -0
- package/dist/adapters/primitive-plan.d.ts.map +1 -0
- package/dist/adapters/prop-classes.d.ts +5 -0
- package/dist/adapters/prop-classes.d.ts.map +1 -1
- package/dist/analyzer-context.d.ts +4 -0
- package/dist/analyzer-context.d.ts.map +1 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/augment-inherited-props.d.ts +63 -8
- package/dist/augment-inherited-props.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/event-handler-name.d.ts +12 -0
- package/dist/event-handler-name.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +8 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/index.d.ts +20 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4903 -2311
- package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
- package/dist/ir-to-client-js/child-props-object.d.ts +106 -0
- package/dist/ir-to-client-js/child-props-object.d.ts.map +1 -0
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
- 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/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts +4 -2
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +2 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/index.d.ts +2 -6
- package/dist/ir-to-client-js/index.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -3
- package/dist/ir-to-client-js/plan/build-declaration-emit.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/build-static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +30 -18
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +3 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts +3 -2
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts +1 -0
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +51 -34
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/prop-rewrite.d.ts +7 -0
- package/dist/prop-rewrite.d.ts.map +1 -1
- package/dist/props-binding.d.ts +58 -13
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/props-object-whole-read.d.ts +15 -0
- package/dist/props-object-whole-read.d.ts.map +1 -0
- package/dist/rich-type-refusal.d.ts.map +1 -1
- package/dist/scope/binding-scope.d.ts +85 -10
- package/dist/scope/binding-scope.d.ts.map +1 -1
- package/dist/scope/lexical-scope-walk.d.ts +3 -2
- package/dist/scope/lexical-scope-walk.d.ts.map +1 -1
- package/dist/scope/root-prop-alias.d.ts +10 -7
- package/dist/scope/root-prop-alias.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +39 -3
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/strip-types.d.ts +13 -0
- package/dist/strip-types.d.ts.map +1 -1
- package/dist/template-position-walk.d.ts +21 -3
- package/dist/template-position-walk.d.ts.map +1 -1
- package/dist/types.d.ts +90 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +9 -9
- package/src/__tests__/binding-scope.test.ts +89 -1
- package/src/__tests__/body-destructure-props-object-alias.test.ts +123 -0
- package/src/__tests__/body-destructured-prop-default-arrow.test.ts +2 -2
- package/src/__tests__/body-destructured-props-live.test.ts +5 -5
- package/src/__tests__/boolean-result.test.ts +22 -5
- package/src/__tests__/brace-delimiter-text.test.ts +26 -0
- package/src/__tests__/callback-method.test.ts +62 -2
- package/src/__tests__/child-components-in-map.test.ts +1 -1
- package/src/__tests__/client-js-generation.test.ts +3 -3
- package/src/__tests__/computed-const.test.ts +103 -0
- package/src/__tests__/destructure-default-reads-earlier-param.test.ts +7 -7
- package/src/__tests__/destructured-props-live.test.ts +1 -1
- package/src/__tests__/emit-to-string-call.test.ts +2 -1
- package/src/__tests__/hydration-payload-analysis.test.ts +166 -0
- package/src/__tests__/issue-2724-prop-alias-loop-not-static.test.ts +7 -7
- package/src/__tests__/issue-2754-rest-spread-needs-slot.test.ts +5 -2
- package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +1 -1
- package/src/__tests__/issue-2835-props-type-member-name-collision.test.ts +4 -4
- package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +1 -1
- package/src/__tests__/issue-3688-props-spread-child-csr.test.ts +2 -1
- package/src/__tests__/issue-3713-props-spread-loop-row.test.ts +65 -0
- package/src/__tests__/issue-3861-object-spread-child.test.ts +102 -0
- package/src/__tests__/lookup-literal-const.test.ts +9 -3
- package/src/__tests__/loop-index-reactivity.test.ts +2 -2
- package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +1 -1
- package/src/__tests__/loop-plan.test.ts +1 -1
- package/src/__tests__/loop-row-const-initializer-shadow.test.ts +146 -0
- package/src/__tests__/loop-row-type.test.ts +64 -0
- package/src/__tests__/lowering-value-position.test.ts +4 -0
- package/src/__tests__/memo-body-expr.test.ts +2 -2
- package/src/__tests__/module-const-destructure-default.test.ts +156 -0
- package/src/__tests__/nested-loop-index-param.test.ts +1 -1
- package/src/__tests__/nested-loop-reactive-attrs.test.ts +2 -2
- package/src/__tests__/nested-row-shadowing.test.ts +2 -2
- package/src/__tests__/nil-reading.test.ts +78 -0
- package/src/__tests__/nullable-signal-attr.test.ts +109 -48
- package/src/__tests__/primitive-plan.test.ts +494 -0
- package/src/__tests__/profile-loop-binding-ids.test.ts +2 -2
- package/src/__tests__/profile-nested-binding-ids.test.ts +2 -2
- package/src/__tests__/prop-default-undefined-only.test.ts +115 -0
- package/src/__tests__/prop-references.test.ts +2 -2
- package/src/__tests__/props-destructuring.test.ts +17 -0
- package/src/__tests__/props-object-whole-read.test.ts +40 -0
- package/src/__tests__/prune-unused-prop-extractions.test.ts +3 -3
- package/src/__tests__/reactive-attrs-in-map.test.ts +1 -1
- package/src/__tests__/reactive-factory-inlining.test.ts +4 -1
- package/src/__tests__/renamed-body-destructure-template.test.ts +7 -7
- package/src/__tests__/rest-binding-gaps.test.ts +192 -0
- package/src/__tests__/rewrite-destructured-props.test.ts +1 -1
- package/src/__tests__/root-prop-alias.test.ts +53 -8
- package/src/__tests__/ssr-defaults.test.ts +113 -25
- package/src/__tests__/static-loop-csr-materialize.test.ts +2 -2
- package/src/__tests__/static-record-literal-array.test.ts +171 -0
- package/src/__tests__/string-concat-identifier.test.ts +40 -1
- package/src/__tests__/written-binding-substitution.test.ts +8 -8
- package/src/adapters/boolean-result.ts +72 -66
- package/src/adapters/brace-delimiter-text.ts +25 -0
- package/src/adapters/callback-method.ts +159 -27
- package/src/adapters/component-props.ts +3 -4
- package/src/adapters/computed-const.ts +238 -4
- package/src/adapters/dsl-template-adapter.ts +62 -26
- package/src/adapters/loop-bound-names.ts +9 -1
- package/src/adapters/loop-plan.ts +1 -1
- package/src/adapters/loop-row-type.ts +149 -0
- package/src/adapters/nil-reading.ts +295 -0
- package/src/adapters/non-primitive-equality.ts +92 -0
- package/src/adapters/number-value.ts +17 -4
- package/src/adapters/operand-typing.ts +522 -0
- package/src/adapters/parsed-expr-emitter.ts +183 -19
- package/src/adapters/primitive-plan.ts +765 -0
- package/src/adapters/prop-classes.ts +16 -3
- package/src/analyzer-context.ts +6 -0
- package/src/analyzer.ts +532 -26
- package/src/augment-inherited-props.ts +108 -10
- package/src/compiler.ts +17 -0
- package/src/event-handler-name.ts +15 -0
- package/src/expression-parser.ts +70 -1
- package/src/index.ts +35 -16
- package/src/ir-to-client-js/build-references.ts +69 -0
- package/src/ir-to-client-js/child-props-object.ts +240 -0
- package/src/ir-to-client-js/collect-elements.ts +31 -63
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +8 -1
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +31 -28
- package/src/ir-to-client-js/control-flow/shared.ts +20 -22
- package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +5 -3
- package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +2 -2
- package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +1 -1
- package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +2 -2
- package/src/ir-to-client-js/control-flow/stringify/loop.ts +1 -1
- package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +3 -3
- package/src/ir-to-client-js/html-template.ts +43 -17
- package/src/ir-to-client-js/imports.ts +2 -2
- package/src/ir-to-client-js/index.ts +53 -11
- package/src/ir-to-client-js/phases/props-extraction.ts +11 -7
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +40 -7
- package/src/ir-to-client-js/plan/build-static-array-child-init.ts +31 -14
- package/src/ir-to-client-js/plan/static-array-child-init.ts +27 -18
- package/src/ir-to-client-js/prop-handling.ts +22 -3
- package/src/ir-to-client-js/prune-unused-prop-extractions.ts +58 -5
- package/src/ir-to-client-js/rewrite-destructured-props.ts +31 -1
- package/src/ir-to-client-js/stringify/static-array-child-init.ts +26 -10
- package/src/jsx-to-ir.ts +459 -37
- package/src/nullable-signal-attr.ts +200 -110
- package/src/prop-rewrite.ts +30 -6
- package/src/props-binding.ts +84 -19
- package/src/props-object-whole-read.ts +87 -0
- package/src/rich-type-refusal.ts +2 -1
- package/src/scope/binding-scope.ts +182 -18
- package/src/scope/lexical-scope-walk.ts +4 -3
- package/src/scope/root-prop-alias.ts +15 -8
- package/src/ssr-defaults.ts +100 -11
- package/src/strip-types.ts +31 -3
- package/src/template-position-walk.ts +57 -28
- package/src/types.ts +87 -0
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts +0 -41
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +0 -1
- package/src/adapters/ambiguous-nil-arithmetic.ts +0 -94
|
@@ -198,14 +198,14 @@ export function stringifyBranchInnerLoops(
|
|
|
198
198
|
// insert() may swap the branch's DOM between runs, and a 'text' write
|
|
199
199
|
// is a plain, idempotent `nodeValue` assignment with no dedup state to
|
|
200
200
|
// go stale — replaces the old re-query-$t-on-every-run discipline.
|
|
201
|
-
lines.push(`${indent} createEffect(() => { claimSlots(__bel${uid}, [{ id: '${text.slotId}', kind: '${rowTextSlotKind(text)}', path: [] }]).write('${text.slotId}', ${rowTextSlotValue(text, text.wrappedExpression
|
|
201
|
+
lines.push(`${indent} createEffect(() => { claimSlots(__bel${uid}, [{ id: '${text.slotId}', kind: '${rowTextSlotKind(text)}', path: [] }]).write('${text.slotId}', ${rowTextSlotValue(text, text.wrappedExpression)}) }${bf})`)
|
|
202
202
|
}
|
|
203
203
|
if (plainTexts.length > 0) {
|
|
204
204
|
const slots: ClaimSlotSpec[] = plainTexts.map(t => ({ id: t.slotId, kind: rowTextSlotKind(t), path: [] }))
|
|
205
205
|
const writer = claimWriterVarName(slots, varSlotId)
|
|
206
206
|
lines.push(`${indent} const ${writer} = lazySlots(__bel${uid}, ${claimPlanLiteral(slots)})`)
|
|
207
207
|
for (const text of plainTexts) {
|
|
208
|
-
lines.push(`${indent} createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.wrappedExpression
|
|
208
|
+
lines.push(`${indent} createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.wrappedExpression)}) }${profileBindingId(pc, text.slotId)})`)
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
if (inner.nestedConditionals.length > 0) {
|
|
@@ -519,7 +519,7 @@ export function stringifyStaticLoop(lines: string[], plan: StaticLoopPlan): void
|
|
|
519
519
|
const writer = claimWriterVarName(slots, varSlotId)
|
|
520
520
|
lines.push(` const ${writer} = lazySlots(__iterEl, ${claimPlanLiteral(slots)})`)
|
|
521
521
|
for (const text of texts) {
|
|
522
|
-
lines.push(` createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.expression
|
|
522
|
+
lines.push(` createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.expression)}) }${profileBindingId(pc, text.slotId)})`)
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
// Ref callbacks fire on every forEach iteration — initial mount and any
|
|
@@ -294,7 +294,7 @@ function emitConsolidatedRowEffect(
|
|
|
294
294
|
// preamble region) uses the multi-line block.
|
|
295
295
|
if (attrSlots.length === 0 && preambleRegions.length === 0 && outerTexts.length === 1) {
|
|
296
296
|
const text = outerTexts[0]
|
|
297
|
-
lines.push(`${indent}createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.wrappedExpression
|
|
297
|
+
lines.push(`${indent}createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.wrappedExpression)}) })`)
|
|
298
298
|
return
|
|
299
299
|
}
|
|
300
300
|
lines.push(`${indent}createEffect(() => {`)
|
|
@@ -319,7 +319,7 @@ function emitConsolidatedRowEffect(
|
|
|
319
319
|
lines.push(`${indent} }`)
|
|
320
320
|
}
|
|
321
321
|
for (const text of outerTexts) {
|
|
322
|
-
lines.push(`${indent} ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.wrappedExpression
|
|
322
|
+
lines.push(`${indent} ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.wrappedExpression)})`)
|
|
323
323
|
}
|
|
324
324
|
for (const region of preambleRegions) {
|
|
325
325
|
lines.push(`${indent} ${writer}('${region.slotId}', ${region.valueExpr})`)
|
|
@@ -345,7 +345,7 @@ function emitOuterTexts(
|
|
|
345
345
|
const writer = claimWriterVarName(slots, varSlotId)
|
|
346
346
|
lines.push(`${indent}const ${writer} = lazySlots(${elVar}, ${claimPlanLiteral(slots)})`)
|
|
347
347
|
for (const text of texts) {
|
|
348
|
-
lines.push(`${indent}createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.wrappedExpression
|
|
348
|
+
lines.push(`${indent}createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.wrappedExpression)}) }${bindingBfId(text.slotId)})`)
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
351
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* IR → HTML template string generation and validation.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { AttrValue, FlatMapCallback, IRAttribute, IRElement, IRExpression, IRNode, IRProp, MapCallbackPreamble, JsSourceText } from '../types.ts'
|
|
5
|
+
import type { AttrValue, FlatMapCallback, IRAttribute, IRElement, IRExpression, IRNode, IRProp, MapCallbackPreamble, JsSourceText, SpreadAttr } from '../types.ts'
|
|
6
6
|
import { isBooleanAttr } from '../html-constants.ts'
|
|
7
7
|
import { toHtmlAttrName, attrValueToString, quotePropName, PROPS_PARAM, DATA_BF_PH, keyAttrName, loopStartMarker, loopEndMarker, loopItemMarker, freeIdsFromRefs, setIntersects, wrapExprWithLoopParams, specsInsideRow } from './utils.ts'
|
|
8
8
|
import type { LoopParamSpec } from './utils.ts'
|
|
@@ -19,6 +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
23
|
|
|
23
24
|
/** Static HTML is embedded in a JS template literal; dynamic expressions use interp(). */
|
|
24
25
|
function escapeStaticTemplateHtml(text: string): string {
|
|
@@ -144,11 +145,16 @@ export const VOID_ELEMENTS = new Set([
|
|
|
144
145
|
* The `base` override lets the CSR-template path pre-substitute
|
|
145
146
|
* props (`_p.items.toSorted(...)`) before the chain rides on top.
|
|
146
147
|
*/
|
|
147
|
-
function applyLoopChain(loop: import('../types.ts').IRLoop, base: string = loop.array): string {
|
|
148
|
+
function applyLoopChain(loop: import('../types.ts').IRLoop, base: string = loop.array, moduleScope = false): string {
|
|
149
|
+
const filter = loop.filterPredicate
|
|
148
150
|
return buildLoopChainExpr({
|
|
149
151
|
base,
|
|
150
152
|
sortComparator: loop.sortComparator,
|
|
151
|
-
|
|
153
|
+
// The module-scope template reads the predicate's `_p.`-rewritten twin
|
|
154
|
+
// (Phase 1's `templateRaw`, #3845), as it reads `templateArray`.
|
|
155
|
+
filterPredicate: filter && moduleScope && filter.templateRaw !== undefined
|
|
156
|
+
? { param: filter.param, raw: filter.templateRaw }
|
|
157
|
+
: filter,
|
|
152
158
|
chainOrder: loop.chainOrder,
|
|
153
159
|
})
|
|
154
160
|
}
|
|
@@ -346,6 +352,18 @@ function transformKeyValue(value: AttrValue, transformExpr: (expr: JsSourceText,
|
|
|
346
352
|
}
|
|
347
353
|
}
|
|
348
354
|
|
|
355
|
+
/**
|
|
356
|
+
* Whether the spread `v` forwards the component's own caller bag (the rest
|
|
357
|
+
* props or the props object, through any alias), which the init's
|
|
358
|
+
* `applyRestAttrs` applies instead of the template. `name` must be one of
|
|
359
|
+
* `restSpreadNames`, and Phase 1 must have resolved the spread to the bag
|
|
360
|
+
* (`SpreadAttr.callerBag`): a loop row or callback parameter spelled like
|
|
361
|
+
* the rest binding is that binding, spread like any other object (#3851).
|
|
362
|
+
*/
|
|
363
|
+
function isCallerBagSpread(v: SpreadAttr, restSpreadNames: ReadonlySet<string> | undefined, name: string = v.expr): boolean {
|
|
364
|
+
return !!restSpreadNames?.has(name) && v.callerBag !== undefined
|
|
365
|
+
}
|
|
366
|
+
|
|
349
367
|
/**
|
|
350
368
|
* Render one element attribute into its template-literal substring for the
|
|
351
369
|
* SSR template path. Switches on `AttrValue.kind` exhaustively so a new
|
|
@@ -379,7 +397,7 @@ function renderTemplateAttrPart(
|
|
|
379
397
|
return templateAttrExpr(attrName, wrap(tmplStr))
|
|
380
398
|
}
|
|
381
399
|
case 'spread': {
|
|
382
|
-
if (
|
|
400
|
+
if (isCallerBagSpread(v, restSpreadNames)) return ''
|
|
383
401
|
// `wrap` lowers loop-param references — including destructured rest
|
|
384
402
|
// bindings (`...rest` lifted via `paramBindings`) — into their item
|
|
385
403
|
// accessor. Skipping it here meant `{...rest}` inside a `.map()`
|
|
@@ -402,11 +420,16 @@ function renderTemplateAttrPart(
|
|
|
402
420
|
* (`SpreadAttr.propsObject`, decided in Phase 1): kept in source order next
|
|
403
421
|
* to the explicit props, the object literal merges like the JSX call does
|
|
404
422
|
* (#3688) — a later key overrides an earlier one, and the spread overrides
|
|
405
|
-
* only the keys the caller passed.
|
|
423
|
+
* only the keys the caller passed. A spread of any other object
|
|
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.
|
|
406
427
|
*/
|
|
407
428
|
function keepsTemplateComponentProp(p: IRProp): boolean {
|
|
408
429
|
if (p.name === 'key') return false
|
|
409
|
-
if (p.name === '...' || p.name.startsWith('...'))
|
|
430
|
+
if (p.name === '...' || p.name.startsWith('...')) {
|
|
431
|
+
return p.value.kind === 'spread' && (p.value.propsObject === true || isObjectSpreadProp(p))
|
|
432
|
+
}
|
|
410
433
|
return true
|
|
411
434
|
}
|
|
412
435
|
|
|
@@ -765,7 +788,7 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
|
|
|
765
788
|
// SSR-reused row never has — visible the moment a row-count change
|
|
766
789
|
// makes reused and rebuilt rows coexist in one list (#2756).
|
|
767
790
|
const mergeCtx: MergeContext = {
|
|
768
|
-
isFilteredSpread: (v) =>
|
|
791
|
+
isFilteredSpread: (v) => isCallerBagSpread(v, restSpreadNames),
|
|
769
792
|
honorClientOnly: true,
|
|
770
793
|
}
|
|
771
794
|
const useMerge = shouldUseSpreadAttrsMerge(node.attrs, mergeCtx)
|
|
@@ -1928,7 +1951,7 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
|
|
|
1928
1951
|
// loops emit `data-key-N` unconditionally per the reconciliation
|
|
1929
1952
|
// contract).
|
|
1930
1953
|
const mergeCtx: MergeContext = {
|
|
1931
|
-
isFilteredSpread: (v) =>
|
|
1954
|
+
isFilteredSpread: (v) => isCallerBagSpread(v, restSpreadNames, v.templateExpr ?? v.expr),
|
|
1932
1955
|
honorClientOnly: true,
|
|
1933
1956
|
}
|
|
1934
1957
|
const useMerge = shouldUseSpreadAttrsMerge(node.attrs, mergeCtx)
|
|
@@ -2459,13 +2482,16 @@ export function computeDeferredChildSlots(
|
|
|
2459
2482
|
}
|
|
2460
2483
|
if (n.slotId) {
|
|
2461
2484
|
const dropped = n.props.some(p => {
|
|
2462
|
-
//
|
|
2463
|
-
//
|
|
2464
|
-
//
|
|
2465
|
-
//
|
|
2466
|
-
//
|
|
2467
|
-
//
|
|
2468
|
-
|
|
2485
|
+
// A caller-bag spread (`...props`, `...rest`) is forwarded off
|
|
2486
|
+
// `_p`, not the per-prop inline form, so it is out of scope for
|
|
2487
|
+
// this drop check; a spread of any other object is inlined like
|
|
2488
|
+
// an explicit prop and checked the same way (#3861). `key` and
|
|
2489
|
+
// event handlers (`onX`) never carry init-scope render values.
|
|
2490
|
+
// This filter set MUST mirror the `propsEntries` filter in the
|
|
2491
|
+
// CSR `component` emit below so the deferral decision matches
|
|
2492
|
+
// output.
|
|
2493
|
+
if (p.name === 'key') return false
|
|
2494
|
+
if ((p.name === '...' || p.name.startsWith('...')) && !isObjectSpreadProp(p)) return false
|
|
2469
2495
|
if (p.name === 'ref') return false
|
|
2470
2496
|
if (isEventHandlerName(p.name)) return false
|
|
2471
2497
|
if (p.clientOnly) return false
|
|
@@ -2572,7 +2598,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2572
2598
|
// `buildSpreadAttrsMergeCall`) keep the contract aligned with
|
|
2573
2599
|
// the other two CSR-side emit paths.
|
|
2574
2600
|
const mergeCtx: MergeContext = {
|
|
2575
|
-
isFilteredSpread: (v) =>
|
|
2601
|
+
isFilteredSpread: (v) => isCallerBagSpread(v, restSpreadNames, v.templateExpr ?? v.expr),
|
|
2576
2602
|
honorClientOnly: true,
|
|
2577
2603
|
}
|
|
2578
2604
|
const useMerge = shouldUseSpreadAttrsMerge(node.attrs, mergeCtx)
|
|
@@ -2873,7 +2899,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2873
2899
|
// (already prop-substituted) so the chain inherits the same
|
|
2874
2900
|
// `_p.X` rewrites the pre-Tier-B path used.
|
|
2875
2901
|
const chainedTemplateArray = node.sortComparator || node.filterPredicate
|
|
2876
|
-
? applyLoopChain(node, node.templateArray)
|
|
2902
|
+
? applyLoopChain(node, node.templateArray, true)
|
|
2877
2903
|
: node.templateArray
|
|
2878
2904
|
const safeRawArrayExpr = transformExprOrUnsafe(node.array, chainedTemplateArray) ?? '[]'
|
|
2879
2905
|
const { array: iterArrayExpr, callbackParam } = applyIterationShape(node, safeRawArrayExpr, indexParam)
|
|
@@ -35,7 +35,7 @@ export const RUNTIME_IMPORT_CANDIDATES = [
|
|
|
35
35
|
'withParentScope',
|
|
36
36
|
'createPortal',
|
|
37
37
|
'provideContext', 'createContext', 'useContext',
|
|
38
|
-
'forwardProps', 'applyRestAttrs', 'splitProps', 'spreadAttrs', 'styleToCss', 'escapeAttr', 'escapeText', 'escapeTextOrNode',
|
|
38
|
+
'forwardProps', 'spreadChildProps', 'applyRestAttrs', 'splitProps', 'spreadAttrs', 'styleToCss', 'escapeAttr', 'escapeText', 'escapeTextOrNode',
|
|
39
39
|
// Whole-item loop conditional's `bf-loop-i:<key>` anchor comment (#1665,
|
|
40
40
|
// #2795 follow-up) — neutralizes `-` so a key can't close the comment early.
|
|
41
41
|
'escapeCommentText',
|
|
@@ -48,7 +48,7 @@ export const RUNTIME_IMPORT_CANDIDATES = [
|
|
|
48
48
|
'markupOrEmpty',
|
|
49
49
|
'qsa', 'qsaItem',
|
|
50
50
|
// Loop-row elements a `ref` callback portals out of their row (#3318).
|
|
51
|
-
'adoptRowPortal', 'claimRowPortals', 'relayRowPortalEvents', 'isRowPortalOf', 'qsaChildScope', 'qsaChildScopes', 'upsertChildItem', '__slot', '__bfSlot', '__bfText',
|
|
51
|
+
'adoptRowPortal', 'claimRowPortals', 'relayRowPortalEvents', 'isRowPortalOf', 'qsaChildScope', 'qsaChildScopes', 'childScopesBySlot', 'childScopeBySlot', 'upsertChildItem', '__slot', '__bfSlot', '__bfText',
|
|
52
52
|
// Claim-plan interpreter (slot unification A2/A3, spec/slot-unification.md)
|
|
53
53
|
// — the "one claim mechanism" that replaced `patchSlotRange` and
|
|
54
54
|
// `updateClientMarker` (both deleted) as the content-slot update door.
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* Generates client-side JavaScript from Pure IR for hydration.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { ComponentIR } from '../types.ts'
|
|
7
|
+
import type { AttrValue, ClientAnalysis, ComponentIR, IRNode } from '../types.ts'
|
|
8
|
+
import { walkIR } from './walker.ts'
|
|
8
9
|
import type { ClientJsContext } from './types.ts'
|
|
9
10
|
import type {
|
|
10
11
|
TemplatePrimitiveRegistry,
|
|
@@ -26,6 +27,7 @@ import { IMPORT_PLACEHOLDER, RUNTIME_MODULE, detectUsedImports, collectExternalI
|
|
|
26
27
|
import { isInlinableInTemplate } from '../relocate.ts'
|
|
27
28
|
import { buildSourceMapFromIR, type SourceMapV3 } from './source-map.ts'
|
|
28
29
|
import { resolvePropDeclaredType, baseTypeName } from '../rich-type-evidence.ts'
|
|
30
|
+
import { isHydrationPayloadPropName } from '../event-handler-name.ts'
|
|
29
31
|
|
|
30
32
|
export interface ClientJsResult {
|
|
31
33
|
code: string
|
|
@@ -149,11 +151,11 @@ export function generateClientJsWithSourceMap(
|
|
|
149
151
|
function computeLiveOnlyProps(ir: ComponentIR, neededProps: ReadonlySet<string>): Record<string, string> {
|
|
150
152
|
const liveOnlyProps: Record<string, string> = {}
|
|
151
153
|
for (const param of ir.metadata.propsParams) {
|
|
152
|
-
// Same exclusions `propsToSerialize` (hono-adapter.ts) applies
|
|
153
|
-
//
|
|
154
|
-
// than prop serialization, and `__*` is
|
|
155
|
-
// round-trips through `bf-p`.
|
|
156
|
-
if (param.isRest ||
|
|
154
|
+
// Same exclusions `propsToSerialize` (hono-adapter.ts) applies
|
|
155
|
+
// (`isHydrationPayloadPropName`): an `on[A-Z]` handler is wired through
|
|
156
|
+
// the listener path rather than prop serialization, and `__*` is
|
|
157
|
+
// hydration plumbing that never round-trips through `bf-p`.
|
|
158
|
+
if (param.isRest || !isHydrationPayloadPropName(param.name)) continue
|
|
157
159
|
if (!neededProps.has(param.name)) continue
|
|
158
160
|
const declared = resolvePropDeclaredType(param.sourceName ?? param.name, ir.metadata)
|
|
159
161
|
const isFunctionTyped =
|
|
@@ -171,15 +173,13 @@ function computeLiveOnlyProps(ir: ComponentIR, neededProps: ReadonlySet<string>)
|
|
|
171
173
|
* and which props the init function actually reads. This runs BEFORE the adapter
|
|
172
174
|
* so the adapter can use the results to optimize bf-p serialization.
|
|
173
175
|
*/
|
|
174
|
-
export function analyzeClientNeeds(
|
|
175
|
-
ir: ComponentIR,
|
|
176
|
-
): { needsInit: boolean; usedProps: string[]; liveOnlyProps: Record<string, string> } {
|
|
176
|
+
export function analyzeClientNeeds(ir: ComponentIR): ClientAnalysis {
|
|
177
177
|
const ctx = createContext(ir, undefined)
|
|
178
178
|
const siblingOffsets = computeLoopSiblingOffsets(ir.root)
|
|
179
179
|
collectElements(ir.root, ctx, siblingOffsets)
|
|
180
180
|
|
|
181
181
|
if (!needsClientJs(ctx)) {
|
|
182
|
-
return { needsInit: false, usedProps: [], liveOnlyProps: {} }
|
|
182
|
+
return { needsInit: false, usedProps: [], usedRestKeys: [], readsCallerBag: false, liveOnlyProps: {} }
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
// Use the shared reference graph instead of replicating the extraction
|
|
@@ -205,7 +205,49 @@ export function analyzeClientNeeds(
|
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
return {
|
|
208
|
+
return {
|
|
209
|
+
needsInit: true,
|
|
210
|
+
usedProps: [...neededProps],
|
|
211
|
+
usedRestKeys: usedRestKeys(ir, usedIdentifiers),
|
|
212
|
+
readsCallerBag: spreadsCallerBag(ir.root),
|
|
213
|
+
liveOnlyProps: computeLiveOnlyProps(ir, neededProps),
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The closed-type rest keys (`restPropsExpandedKeys`) the client reads (#3845).
|
|
219
|
+
* A `{...rest}` spread of a closed rest type unrolls into one `rest.<key>`
|
|
220
|
+
* read per key, which the client reads live as `_p.<key>`. Matched the way
|
|
221
|
+
* `usedProps` matches a prop: by name among the identifiers the client code
|
|
222
|
+
* references (member names included), alongside the rest binding itself.
|
|
223
|
+
*/
|
|
224
|
+
function usedRestKeys(ir: ComponentIR, usedIdentifiers: ReadonlySet<string>): string[] {
|
|
225
|
+
const restName = ir.metadata.restPropsName
|
|
226
|
+
if (!restName || !usedIdentifiers.has(restName)) return []
|
|
227
|
+
return ir.metadata.restPropsExpandedKeys.filter(key => usedIdentifiers.has(key) && isHydrationPayloadPropName(key))
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Whether the component spreads one of the caller's prop bags whole
|
|
232
|
+
* (`SpreadAttr.callerBag`, decided in Phase 1) onto an element or a child
|
|
233
|
+
* component. The client reads every key of that bag off `_p`
|
|
234
|
+
* (`applyRestAttrs` / `forwardProps`), keys the component never names.
|
|
235
|
+
*/
|
|
236
|
+
function spreadsCallerBag(root: IRNode): boolean {
|
|
237
|
+
let found = false
|
|
238
|
+
const isBagSpread = (value: AttrValue): boolean => value.kind === 'spread' && value.callerBag !== undefined
|
|
239
|
+
walkIR<null>(root, null, {
|
|
240
|
+
element: ({ node, descend }) => {
|
|
241
|
+
if (node.attrs.some(attr => isBagSpread(attr.value))) found = true
|
|
242
|
+
descend()
|
|
243
|
+
},
|
|
244
|
+
component: ({ node, descend, descendJsxChildren }) => {
|
|
245
|
+
if (node.props.some(prop => isBagSpread(prop.value))) found = true
|
|
246
|
+
descend()
|
|
247
|
+
descendJsxChildren()
|
|
248
|
+
},
|
|
249
|
+
})
|
|
250
|
+
return found
|
|
209
251
|
}
|
|
210
252
|
|
|
211
253
|
/** Initialize an empty ClientJsContext from component IR metadata. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `props-extraction` phase — emit the one-time prop extractions:
|
|
3
|
-
* `const children = _p.children [
|
|
3
|
+
* `const children = _p.children [<fallback>]` (or `const kids =
|
|
4
4
|
* _p.children` for a renamed `{ children: kids }`), and `let start =
|
|
5
5
|
* _p.start [?? <default>]` for each prop the component writes
|
|
6
6
|
* (`ParamInfo.reassigned`, see `keepsDeclaredValue`).
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
* other destructured prop is rewritten to a live read instead, by
|
|
13
13
|
* `rewriteDestructuredPropReads` (`generate-init.ts`).
|
|
14
14
|
*
|
|
15
|
-
* The line is composed
|
|
15
|
+
* The line is composed with `composePropRead` rather than
|
|
16
16
|
* `livePropReadExpr` so it stays unparenthesized — that exact
|
|
17
|
-
* `const X =
|
|
17
|
+
* `const X = <prop read>` shape is what `pruneUnusedPropExtractions`'s AST
|
|
18
18
|
* matcher recognizes when the init body never reads `children`.
|
|
19
19
|
*
|
|
20
20
|
* Skipped entirely for an opaque props object (`propsObjectName != null`):
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
import { type PropUsage, isChildrenPropParam } from '../../types.ts'
|
|
25
25
|
import { computePropsUsedAsConditions } from '../compute-prop-usage.ts'
|
|
26
|
-
import { propReadBase, propReadFallback, keepsDeclaredValue } from '../../props-binding.ts'
|
|
26
|
+
import { composePropRead, propReadBase, propReadFallback, keepsDeclaredValue, retainedPropLocals } from '../../props-binding.ts'
|
|
27
27
|
import type { ClientJsContext } from '../types.ts'
|
|
28
28
|
|
|
29
29
|
export function emitPropsExtraction(
|
|
@@ -47,7 +47,7 @@ export function emitPropsExtraction(
|
|
|
47
47
|
|
|
48
48
|
const usedAsCondition = computePropsUsedAsConditions(ctx, neededProps).has(local)
|
|
49
49
|
const fallback = propReadFallback(prop, propUsage.get(local), usedAsCondition)
|
|
50
|
-
const read = propReadBase(prop)
|
|
50
|
+
const read = composePropRead(propReadBase(prop), fallback)
|
|
51
51
|
// A children binding the component writes needs a `let` to take the write.
|
|
52
52
|
lines.push(` ${keepsDeclaredValue(prop) ? 'const' : 'let'} ${local} = ${read}`, '')
|
|
53
53
|
}
|
|
@@ -62,9 +62,13 @@ function emitWrittenPropLocals(lines: string[], ctx: ClientJsContext, propUsage:
|
|
|
62
62
|
const written = ctx.propsParams.filter(p => !p.isRest && !isChildrenPropParam(p) && !keepsDeclaredValue(p))
|
|
63
63
|
if (written.length === 0) return
|
|
64
64
|
const usedAsCondition = computePropsUsedAsConditions(ctx, new Set(written.map(p => p.name)))
|
|
65
|
+
// The locals are declared in parameter order, so a default reading an
|
|
66
|
+
// earlier written prop reads its local, as in JS (`{ a = [], b = a }`
|
|
67
|
+
// shares `a`'s array); an earlier prop that is not written reads live.
|
|
68
|
+
const retained = retainedPropLocals(ctx)
|
|
65
69
|
for (const prop of written) {
|
|
66
|
-
const fallback = propReadFallback(prop, propUsage.get(prop.name), usedAsCondition.has(prop.name))
|
|
67
|
-
lines.push(` let ${prop.name} = ${propReadBase(prop)
|
|
70
|
+
const fallback = propReadFallback(prop, propUsage.get(prop.name), usedAsCondition.has(prop.name), retained)
|
|
71
|
+
lines.push(` let ${prop.name} = ${composePropRead(propReadBase(prop), fallback)}`)
|
|
68
72
|
}
|
|
69
73
|
lines.push('')
|
|
70
74
|
}
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
import type { ControlledSignal } from '../init-declarations.ts'
|
|
12
12
|
import type { Declaration } from '../declaration-sort.ts'
|
|
13
13
|
import type { ClientJsContext } from '../types.ts'
|
|
14
|
-
import type { ParamInfo, SignalInfo } from '../../types.ts'
|
|
14
|
+
import type { ConstantInfo, ParamInfo, SignalInfo } from '../../types.ts'
|
|
15
15
|
import { inferDefaultValue, PROPS_PARAM, readsBareProp } from '../utils.ts'
|
|
16
|
-
import { livePropReadExpr, propDefaultText } from '../../props-binding.ts'
|
|
16
|
+
import { coalesceDefaultText, composePropRead, livePropReadExpr, propDefaultText } from '../../props-binding.ts'
|
|
17
17
|
import { signalFactoryInitializer, signalSecondBinding } from '../../signal-initializer.ts'
|
|
18
18
|
import type {
|
|
19
19
|
ControlledSignalEffectPlan,
|
|
@@ -54,7 +54,7 @@ export function buildDeclarationEmitPlan(
|
|
|
54
54
|
kind: 'constant',
|
|
55
55
|
keyword: c.declarationKind ?? 'const',
|
|
56
56
|
name: c.name,
|
|
57
|
-
valueExpr: c.value !== undefined ? c.value : null,
|
|
57
|
+
valueExpr: bodyDestructureValue(c, ctx) ?? (c.value !== undefined ? c.value : null),
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
case 'signal':
|
|
@@ -126,7 +126,7 @@ function buildSignalPlan(
|
|
|
126
126
|
* `<it> ?? <inferred default>`, so the signal never starts as
|
|
127
127
|
* `undefined`.
|
|
128
128
|
* 2. A controlled signal seeded by a bare destructured binding →
|
|
129
|
-
* `_p.<caller key
|
|
129
|
+
* `_p.<caller key>` with the prop's default (`composePropRead`).
|
|
130
130
|
* 3. Anything else (a `??` / `||` fallback the user wrote, any other
|
|
131
131
|
* expression) → the initializer as written; `generateInit`'s
|
|
132
132
|
* `rewritePropsObjectRef` maps its `props.X` reads to `_p.X`.
|
|
@@ -138,14 +138,47 @@ function resolveSignalInitialValue(signal: SignalInfo, lookups: DeclarationEmitL
|
|
|
138
138
|
const controlled = lookups.controlledBySignal.get(signal)
|
|
139
139
|
if (controlled) {
|
|
140
140
|
const prop = lookups.propByName.get(controlled.propName)
|
|
141
|
-
const
|
|
142
|
-
// `_p` is always keyed by the caller-facing name (#2524 CSR half).
|
|
143
|
-
|
|
141
|
+
const defaultText = prop && propDefaultText(prop)
|
|
142
|
+
// `_p` is always keyed by the caller-facing name (#2524 CSR half). The
|
|
143
|
+
// prop's own default applies to an absent or `undefined` prop only;
|
|
144
|
+
// the inferred one keeps the signal from starting as either nil.
|
|
145
|
+
const base = `${PROPS_PARAM}.${prop?.sourceName ?? controlled.propName}`
|
|
146
|
+
return composePropRead(
|
|
147
|
+
base,
|
|
148
|
+
defaultText
|
|
149
|
+
? { kind: 'default', text: coalesceDefaultText(defaultText, prop.defaultContainsArrow) }
|
|
150
|
+
: { kind: 'guard', text: inferDefaultValue(signal.type) },
|
|
151
|
+
)
|
|
144
152
|
}
|
|
145
153
|
}
|
|
146
154
|
return signal.initialValue
|
|
147
155
|
}
|
|
148
156
|
|
|
157
|
+
/**
|
|
158
|
+
* The client-JS initializer of a body destructure of the props object with
|
|
159
|
+
* a default (`const { label = 'x' } = props`): its prop read with the
|
|
160
|
+
* default applied to an absent or `undefined` prop only
|
|
161
|
+
* (`composePropRead`). The IR encodes the destructure as `props.label ??
|
|
162
|
+
* 'x'` (`ConstantInfo.value`), which the SSR seed plans read; built here
|
|
163
|
+
* from the props param the analyzer overlays the default onto (#2943), not
|
|
164
|
+
* from that text. The default is the authored expression: a read of an
|
|
165
|
+
* earlier binding (`{ a = [], b = a }`) stays a read of that local, which
|
|
166
|
+
* `rewriteBodyAliasReads` turns into a live prop read only where it drops
|
|
167
|
+
* the local's declaration. Null for any other constant, which keeps its own
|
|
168
|
+
* value.
|
|
169
|
+
*/
|
|
170
|
+
function bodyDestructureValue(c: ConstantInfo, ctx: ClientJsContext): string | null {
|
|
171
|
+
const sourceKey = c.propsDestructure?.sourceKey
|
|
172
|
+
if (sourceKey === undefined || ctx.propsObjectName === null) return null
|
|
173
|
+
const param = ctx.propsParams.find(p => p.name === c.name && (p.sourceName ?? p.name) === sourceKey)
|
|
174
|
+
const defaultText = param?.defaultValue
|
|
175
|
+
if (!param || !defaultText) return null
|
|
176
|
+
return composePropRead(`${ctx.propsObjectName}.${sourceKey}`, {
|
|
177
|
+
kind: 'default',
|
|
178
|
+
text: coalesceDefaultText(defaultText, param.defaultContainsArrow),
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
|
|
149
182
|
function buildControlledSignalEffect(
|
|
150
183
|
signal: SignalInfo,
|
|
151
184
|
lookups: DeclarationEmitLookups,
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
|
|
20
20
|
import type { IRLoopChildComponent, MapCallbackPreamble } from '../../types.ts'
|
|
21
21
|
import type { ClientJsContext, LoopChildReactiveAttr, NestedLoop, TopLevelLoop } from '../types.ts'
|
|
22
|
-
import {
|
|
22
|
+
import { varSlotId, attrValueToString, buildLoopChildIndexExpr } from '../utils.ts'
|
|
23
|
+
import { childPropsObjectExpr, type ChildPropValue } from '../child-props-object.ts'
|
|
23
24
|
import { jsxChildrenPropGetterExpr, renderPreamble, irToHtmlTemplate } from '../html-template.ts'
|
|
24
25
|
|
|
25
26
|
/**
|
|
@@ -40,6 +41,7 @@ import { buildForwardedInnerLoopsPlan } from '../control-flow/plan/build-inner-l
|
|
|
40
41
|
/** The inline prop shape carried on `IRLoopChildComponent.props`. */
|
|
41
42
|
type LoopChildCompProp = IRLoopChildComponent['props'][number]
|
|
42
43
|
import type {
|
|
44
|
+
ChildScopesLookup,
|
|
43
45
|
ComponentRootedInnerLoopInitPlan,
|
|
44
46
|
InnerLoopComp,
|
|
45
47
|
InnerLoopNestedInitPlan,
|
|
@@ -114,18 +116,32 @@ export function buildStaticArrayChildInitsPlan(
|
|
|
114
116
|
return plans
|
|
115
117
|
}
|
|
116
118
|
|
|
119
|
+
/**
|
|
120
|
+
* The one decision for how a static array's child init finds a component's
|
|
121
|
+
* scope (#3821), for every shape: the document-order zip and the per-row
|
|
122
|
+
* lookup alike. A slotted component is looked up by its slot, which the
|
|
123
|
+
* runtime matches on an element's `bf-h`/`bf-m`/`bf-s` and on a fragment
|
|
124
|
+
* root's `<!--bf-scope:…|h=…|m=…-->` comment alike; an element selector
|
|
125
|
+
* (`buildCompSelector`) cannot reach the comment, so a fragment-rooted row
|
|
126
|
+
* was never initialised. Without a slot id the name-prefix selector stays.
|
|
127
|
+
*/
|
|
128
|
+
function buildChildScopesLookup(comp: { slotId?: string | null; name: string }): ChildScopesLookup {
|
|
129
|
+
return comp.slotId
|
|
130
|
+
? { by: 'slot', slotId: comp.slotId }
|
|
131
|
+
: { by: 'name', selector: buildCompSelector(comp) }
|
|
132
|
+
}
|
|
133
|
+
|
|
117
134
|
function buildSingleCompPlan(
|
|
118
135
|
elem: TopLevelLoop,
|
|
119
136
|
childComponent: IRLoopChildComponent,
|
|
120
137
|
): SingleCompInitPlan {
|
|
121
|
-
const { name, props
|
|
122
|
-
const childSelector = buildCompSelector({ name, slotId })
|
|
138
|
+
const { name, props } = childComponent
|
|
123
139
|
|
|
124
140
|
return {
|
|
125
141
|
kind: 'single-comp',
|
|
126
142
|
containerVar: `_${varSlotId(elem.slotId)}`,
|
|
127
143
|
componentName: name,
|
|
128
|
-
|
|
144
|
+
lookup: buildChildScopesLookup(childComponent),
|
|
129
145
|
arrayExpr: elem.array,
|
|
130
146
|
param: elem.param,
|
|
131
147
|
indexParam: elem.index || '__idx',
|
|
@@ -159,7 +175,7 @@ function buildOuterNestedPlan(
|
|
|
159
175
|
kind: 'outer-nested',
|
|
160
176
|
containerVar: `_${varSlotId(elem.slotId)}`,
|
|
161
177
|
componentName: comp.name,
|
|
162
|
-
|
|
178
|
+
lookup: buildChildScopesLookup(comp),
|
|
163
179
|
arrayExpr: elem.array,
|
|
164
180
|
param: elem.param,
|
|
165
181
|
indexParam,
|
|
@@ -182,7 +198,7 @@ function buildInnerLoopNestedPlan(
|
|
|
182
198
|
const innerIndexParam = innerLoop.index || '__innerIdx'
|
|
183
199
|
const comps: InnerLoopComp[] = innerComps.map(comp => ({
|
|
184
200
|
componentName: comp.name,
|
|
185
|
-
|
|
201
|
+
lookup: buildChildScopesLookup(comp),
|
|
186
202
|
propsExpr: buildStaticPropsExpr(comp.props),
|
|
187
203
|
}))
|
|
188
204
|
|
|
@@ -245,7 +261,7 @@ function buildComponentRootedInnerLoopPlan(
|
|
|
245
261
|
): ComponentRootedInnerLoopInitPlan {
|
|
246
262
|
const comps: InnerLoopComp[] = innerComps.map(comp => ({
|
|
247
263
|
componentName: comp.name,
|
|
248
|
-
|
|
264
|
+
lookup: buildChildScopesLookup(comp),
|
|
249
265
|
propsExpr: buildStaticPropsExpr(comp.props),
|
|
250
266
|
}))
|
|
251
267
|
|
|
@@ -278,29 +294,30 @@ function buildComponentRootedInnerLoopPlan(
|
|
|
278
294
|
* property, NOT a getter), matching the legacy emitter byte-for-byte.
|
|
279
295
|
*/
|
|
280
296
|
function buildStaticPropsExpr(props: readonly LoopChildCompProp[]): PropsExpr {
|
|
281
|
-
|
|
297
|
+
// A props-object spread merges in source order through the shared door
|
|
298
|
+
// (#3713) instead of becoming a getter named `...`.
|
|
299
|
+
return childPropsObjectExpr(props, (p): ChildPropValue => {
|
|
282
300
|
if (p.isEventHandler) {
|
|
283
|
-
return
|
|
301
|
+
return { expr: attrValueToString(p.value) ?? 'undefined', getter: false }
|
|
284
302
|
}
|
|
285
303
|
switch (p.value.kind) {
|
|
286
304
|
case 'literal':
|
|
287
|
-
return
|
|
305
|
+
return { expr: JSON.stringify(p.value.value), getter: false }
|
|
288
306
|
case 'boolean-shorthand':
|
|
289
307
|
case 'boolean-attr':
|
|
290
|
-
return
|
|
308
|
+
return { expr: 'true', getter: false }
|
|
291
309
|
case 'jsx-children':
|
|
292
310
|
// Brand via the shared door (#2651/#2702) — see
|
|
293
311
|
// `jsxChildrenPropGetterExpr`'s docstring. A named jsx-children
|
|
294
312
|
// prop on a component instantiated inside a static-array `.map()`
|
|
295
313
|
// loop used to reach its getter unbranded (pullfrog review, PR
|
|
296
314
|
// #2820).
|
|
297
|
-
return
|
|
315
|
+
return { expr: jsxChildrenPropGetterExpr(p.value.children, p.name), getter: true }
|
|
298
316
|
case 'expression':
|
|
299
317
|
case 'template':
|
|
300
318
|
case 'spread':
|
|
301
|
-
return
|
|
319
|
+
return { expr: attrValueToString(p.value) ?? 'undefined', getter: true }
|
|
302
320
|
}
|
|
303
321
|
})
|
|
304
|
-
return entries.length > 0 ? `{ ${entries.join(', ')} }` : '{}'
|
|
305
322
|
}
|
|
306
323
|
|
|
@@ -33,14 +33,30 @@ import type { LoopChildReactiveAttr, LoopChildReactiveText } from '../types.ts'
|
|
|
33
33
|
/** Pre-built `{ name: value, ... }` props object expression. */
|
|
34
34
|
export type PropsExpr = string
|
|
35
35
|
|
|
36
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* How a static array's row init finds every child scope of one component in
|
|
38
|
+
* a container, in document order (#3821). Decided once by
|
|
39
|
+
* `buildChildScopesLookup`:
|
|
40
|
+
*
|
|
41
|
+
* - `slot` — the component sits at a known slot: the runtime's
|
|
42
|
+
* `childScopesBySlot` / `childScopeBySlot(el, __scopeId, slotId)` find
|
|
43
|
+
* both an element-rooted scope and a fragment-rooted one (declared by a
|
|
44
|
+
* `<!--bf-scope:-->` comment, which no element selector can match).
|
|
45
|
+
* - `name` — no slot id: `qsaChildScopes` / `qsaChildScope` with the
|
|
46
|
+
* `[bf-s^="Name_"]` selector.
|
|
47
|
+
*/
|
|
48
|
+
export type ChildScopesLookup =
|
|
49
|
+
| { by: 'slot'; slotId: string }
|
|
50
|
+
| { by: 'name'; selector: string }
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A child-component initialiser inside an inner-loop body, or zipped by
|
|
54
|
+
* document order against loop items.
|
|
55
|
+
*/
|
|
37
56
|
export interface InnerLoopComp {
|
|
38
57
|
componentName: string
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
* `__innerEl.querySelector(<here>)`. See `buildCompSelector`.
|
|
42
|
-
*/
|
|
43
|
-
selector: string
|
|
58
|
+
/** How the component's scope is found (#3821). See `ChildScopesLookup`. */
|
|
59
|
+
lookup: ChildScopesLookup
|
|
44
60
|
/** Pre-built props object expression. */
|
|
45
61
|
propsExpr: PropsExpr
|
|
46
62
|
}
|
|
@@ -51,12 +67,8 @@ export interface SingleCompInitPlan {
|
|
|
51
67
|
/** Container variable name — e.g. `_s4` (already prefixed). */
|
|
52
68
|
containerVar: string
|
|
53
69
|
componentName: string
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
* `containerVar.querySelectorAll(<here>)`. Combines slotId-suffix match
|
|
57
|
-
* with name-prefix match.
|
|
58
|
-
*/
|
|
59
|
-
childSelector: string
|
|
70
|
+
/** How every row's child scope is found under `containerVar` (#3821). */
|
|
71
|
+
lookup: ChildScopesLookup
|
|
60
72
|
/** Array expression as written in user code. */
|
|
61
73
|
arrayExpr: string
|
|
62
74
|
/** Loop parameter identifier. */
|
|
@@ -92,11 +104,8 @@ export interface OuterNestedInitPlan {
|
|
|
92
104
|
kind: 'outer-nested'
|
|
93
105
|
containerVar: string
|
|
94
106
|
componentName: string
|
|
95
|
-
/**
|
|
96
|
-
|
|
97
|
-
* `__iterEl.querySelector(<here>)`. See `buildCompSelector`.
|
|
98
|
-
*/
|
|
99
|
-
selector: string
|
|
107
|
+
/** How the component's scope is found in `__iterEl` (#3821). */
|
|
108
|
+
lookup: ChildScopesLookup
|
|
100
109
|
arrayExpr: string
|
|
101
110
|
param: string
|
|
102
111
|
indexParam: string
|
|
@@ -190,7 +199,7 @@ export interface InnerLoopNestedInitPlan {
|
|
|
190
199
|
* the parent container with no per-group element to index.
|
|
191
200
|
*
|
|
192
201
|
* Instead this shape zips the inner component scopes — found in document order
|
|
193
|
-
*
|
|
202
|
+
* by the comp's `ChildScopesLookup` — against the flattened
|
|
194
203
|
* `outer.forEach(o => inner.forEach(i => ...))` iteration. Document order is
|
|
195
204
|
* the SSR render order, so position `__ci++` pairs each scope with its data
|
|
196
205
|
* item regardless of whether the outer component root is an element or a
|