@barefootjs/jsx 0.40.0 → 0.40.2
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/ambiguous-nil-arithmetic.d.ts +42 -0
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +1 -0
- package/dist/adapters/attr-plan.d.ts.map +1 -1
- package/dist/adapters/boolean-carrier.d.ts +31 -0
- package/dist/adapters/boolean-carrier.d.ts.map +1 -0
- 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 +38 -5
- package/dist/adapters/callback-method.d.ts.map +1 -1
- package/dist/adapters/component-props.d.ts +22 -7
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/computed-const.d.ts +28 -1
- package/dist/adapters/computed-const.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +39 -1
- 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 +52 -0
- package/dist/adapters/loop-row-type.d.ts.map +1 -0
- package/dist/adapters/nil-reading.d.ts +68 -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 +45 -0
- package/dist/adapters/number-value.d.ts.map +1 -0
- 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 +70 -12
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/primitive-plan.d.ts +291 -0
- package/dist/adapters/primitive-plan.d.ts.map +1 -0
- package/dist/analyzer-context.d.ts +11 -0
- package/dist/analyzer-context.d.ts.map +1 -1
- package/dist/analyzer.d.ts +34 -0
- 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 +24 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5671 -2586
- package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
- package/dist/ir-to-client-js/child-props-object.d.ts +64 -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-component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts +29 -0
- 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-lazy-row.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.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/plan/build-reactive-effects.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts +5 -4
- package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts +2 -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 +15 -0
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/reactive-effects.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 +22 -0
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
- 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/event-listener.d.ts +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/lazy-row.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts +3 -2
- 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/plan/build-static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +37 -19
- 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/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/safe-html.d.ts +9 -3
- package/dist/ir-to-client-js/safe-html.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/ir-to-client-js/types.d.ts +30 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +8 -0
- package/dist/ir-to-client-js/utils.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 +95 -10
- 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 +27 -3
- 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 +100 -4
- 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 +16 -0
- package/dist/scope/root-prop-alias.d.ts.map +1 -1
- package/dist/signal-prop-name-collision.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +4 -2
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/ssr-seed-plan.d.ts +14 -0
- package/dist/ssr-seed-plan.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-parts.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 +120 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +3 -3
- package/src/__tests__/binding-scope-ratchet.test.ts +12 -2
- package/src/__tests__/binding-scope.test.ts +89 -1
- package/src/__tests__/body-destructure-props-object-alias.test.ts +123 -0
- package/src/__tests__/boolean-carrier.test.ts +74 -0
- 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__/component-props.test.ts +14 -0
- package/src/__tests__/computed-const.test.ts +188 -0
- package/src/__tests__/emit-to-string-call.test.ts +2 -1
- package/src/__tests__/expression-parser.test.ts +24 -0
- 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 +143 -0
- package/src/__tests__/issue-3713-props-spread-loop-row.test.ts +65 -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-prop-read.test.ts +111 -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 +137 -0
- 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 +77 -0
- package/src/__tests__/nullable-signal-attr.test.ts +231 -2
- package/src/__tests__/primitive-plan.test.ts +416 -0
- package/src/__tests__/profile-binding-ids.test.ts +14 -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__/props-object-whole-read.test.ts +40 -0
- package/src/__tests__/reactive-attrs-in-map.test.ts +1 -1
- package/src/__tests__/reactive-factory-inlining.test.ts +4 -1
- package/src/__tests__/rest-binding-gaps.test.ts +192 -0
- package/src/__tests__/root-prop-alias.test.ts +79 -1
- package/src/__tests__/signal-prop-name-collision.test.ts +102 -2
- package/src/__tests__/source-file-cache.test.ts +105 -0
- package/src/__tests__/ssr-seed-plan.test.ts +43 -0
- 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__/template-parts-literal-boundary.test.ts +19 -0
- package/src/adapters/ambiguous-nil-arithmetic.ts +103 -0
- package/src/adapters/attr-plan.ts +6 -2
- package/src/adapters/boolean-carrier.ts +76 -0
- package/src/adapters/boolean-result.ts +72 -66
- package/src/adapters/brace-delimiter-text.ts +25 -0
- package/src/adapters/callback-method.ts +151 -27
- package/src/adapters/component-props.ts +28 -8
- package/src/adapters/computed-const.ts +443 -10
- package/src/adapters/dsl-template-adapter.ts +79 -2
- package/src/adapters/loop-bound-names.ts +9 -1
- package/src/adapters/loop-plan.ts +1 -1
- package/src/adapters/loop-row-type.ts +139 -0
- package/src/adapters/nil-reading.ts +297 -0
- package/src/adapters/non-primitive-equality.ts +92 -0
- package/src/adapters/number-value.ts +108 -0
- package/src/adapters/operand-typing.ts +522 -0
- package/src/adapters/parsed-expr-emitter.ts +154 -19
- package/src/adapters/primitive-plan.ts +696 -0
- package/src/analyzer-context.ts +14 -0
- package/src/analyzer.ts +692 -85
- 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 +74 -2
- package/src/index.ts +45 -9
- package/src/ir-to-client-js/build-references.ts +69 -0
- package/src/ir-to-client-js/child-props-object.ts +106 -0
- package/src/ir-to-client-js/collect-elements.ts +100 -67
- package/src/ir-to-client-js/compute-inlinability.ts +1 -1
- package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +15 -1
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +85 -5
- package/src/ir-to-client-js/control-flow/plan/build-lazy-row.ts +3 -0
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +30 -28
- package/src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts +1 -0
- package/src/ir-to-client-js/control-flow/plan/inner-loop.ts +5 -4
- package/src/ir-to-client-js/control-flow/plan/loop-child-arm.ts +2 -0
- package/src/ir-to-client-js/control-flow/plan/loop.ts +12 -0
- package/src/ir-to-client-js/control-flow/plan/reactive-effects.ts +2 -0
- package/src/ir-to-client-js/control-flow/shared.ts +23 -24
- package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +29 -0
- package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +8 -2
- package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +8 -1
- package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +8 -7
- package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +8 -7
- package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +4 -4
- package/src/ir-to-client-js/control-flow/stringify/loop.ts +3 -3
- package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +6 -6
- package/src/ir-to-client-js/emit-reactive.ts +1 -1
- package/src/ir-to-client-js/html-template.ts +95 -38
- package/src/ir-to-client-js/imports.ts +1 -1
- package/src/ir-to-client-js/index.ts +53 -11
- package/src/ir-to-client-js/plan/build-static-array-child-init.ts +42 -15
- package/src/ir-to-client-js/plan/static-array-child-init.ts +34 -19
- package/src/ir-to-client-js/prop-handling.ts +22 -3
- package/src/ir-to-client-js/reactivity.ts +14 -0
- package/src/ir-to-client-js/safe-html.ts +11 -4
- package/src/ir-to-client-js/stringify/static-array-child-init.ts +30 -12
- package/src/ir-to-client-js/types.ts +23 -0
- package/src/ir-to-client-js/utils.ts +15 -1
- package/src/jsx-to-ir.ts +510 -58
- package/src/nullable-signal-attr.ts +366 -28
- package/src/prop-rewrite.ts +30 -6
- package/src/props-binding.ts +54 -3
- package/src/props-object-whole-read.ts +87 -0
- package/src/rich-type-refusal.ts +2 -1
- package/src/scope/binding-scope.ts +203 -11
- package/src/scope/lexical-scope-walk.ts +4 -3
- package/src/scope/root-prop-alias.ts +23 -0
- package/src/signal-prop-name-collision.ts +113 -22
- package/src/ssr-defaults.ts +10 -4
- package/src/ssr-seed-plan.ts +82 -17
- package/src/strip-types.ts +31 -3
- package/src/template-parts.ts +21 -1
- package/src/template-position-walk.ts +57 -28
- package/src/types.ts +117 -0
|
@@ -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'
|
|
@@ -144,11 +144,16 @@ export const VOID_ELEMENTS = new Set([
|
|
|
144
144
|
* The `base` override lets the CSR-template path pre-substitute
|
|
145
145
|
* props (`_p.items.toSorted(...)`) before the chain rides on top.
|
|
146
146
|
*/
|
|
147
|
-
function applyLoopChain(loop: import('../types.ts').IRLoop, base: string = loop.array): string {
|
|
147
|
+
function applyLoopChain(loop: import('../types.ts').IRLoop, base: string = loop.array, moduleScope = false): string {
|
|
148
|
+
const filter = loop.filterPredicate
|
|
148
149
|
return buildLoopChainExpr({
|
|
149
150
|
base,
|
|
150
151
|
sortComparator: loop.sortComparator,
|
|
151
|
-
|
|
152
|
+
// The module-scope template reads the predicate's `_p.`-rewritten twin
|
|
153
|
+
// (Phase 1's `templateRaw`, #3845), as it reads `templateArray`.
|
|
154
|
+
filterPredicate: filter && moduleScope && filter.templateRaw !== undefined
|
|
155
|
+
? { param: filter.param, raw: filter.templateRaw }
|
|
156
|
+
: filter,
|
|
152
157
|
chainOrder: loop.chainOrder,
|
|
153
158
|
})
|
|
154
159
|
}
|
|
@@ -238,11 +243,13 @@ function maybeHoistedScopeAttr(
|
|
|
238
243
|
}
|
|
239
244
|
|
|
240
245
|
/**
|
|
241
|
-
*
|
|
242
|
-
* references an init-body-only name (#1128)
|
|
243
|
-
*
|
|
244
|
-
* array for an empty array literal, or short-circuit a text expression
|
|
245
|
-
* an empty string
|
|
246
|
+
* Spelling the CSR template's `transformExpr` emits when the expression
|
|
247
|
+
* references an init-body-only name (#1128), so a position that just
|
|
248
|
+
* evaluates it reads `undefined`. Sites that drop a renderChild prop, swap a
|
|
249
|
+
* loop array for an empty array literal, or short-circuit a text expression
|
|
250
|
+
* to an empty string decide that from `transformExprOrUnsafe`'s `null`, not
|
|
251
|
+
* from equality with this string: a source written as the literal
|
|
252
|
+
* `undefined` spells the same (#3752). Module-internal.
|
|
246
253
|
*/
|
|
247
254
|
const UNSAFE_TEMPLATE_EXPR = 'undefined'
|
|
248
255
|
|
|
@@ -344,6 +351,18 @@ function transformKeyValue(value: AttrValue, transformExpr: (expr: JsSourceText,
|
|
|
344
351
|
}
|
|
345
352
|
}
|
|
346
353
|
|
|
354
|
+
/**
|
|
355
|
+
* Whether the spread `v` forwards the component's own caller bag (the rest
|
|
356
|
+
* props or the props object, through any alias), which the init's
|
|
357
|
+
* `applyRestAttrs` applies instead of the template. `name` must be one of
|
|
358
|
+
* `restSpreadNames`, and Phase 1 must have resolved the spread to the bag
|
|
359
|
+
* (`SpreadAttr.callerBag`): a loop row or callback parameter spelled like
|
|
360
|
+
* the rest binding is that binding, spread like any other object (#3851).
|
|
361
|
+
*/
|
|
362
|
+
function isCallerBagSpread(v: SpreadAttr, restSpreadNames: ReadonlySet<string> | undefined, name: string = v.expr): boolean {
|
|
363
|
+
return !!restSpreadNames?.has(name) && v.callerBag !== undefined
|
|
364
|
+
}
|
|
365
|
+
|
|
347
366
|
/**
|
|
348
367
|
* Render one element attribute into its template-literal substring for the
|
|
349
368
|
* SSR template path. Switches on `AttrValue.kind` exhaustively so a new
|
|
@@ -377,7 +396,7 @@ function renderTemplateAttrPart(
|
|
|
377
396
|
return templateAttrExpr(attrName, wrap(tmplStr))
|
|
378
397
|
}
|
|
379
398
|
case 'spread': {
|
|
380
|
-
if (
|
|
399
|
+
if (isCallerBagSpread(v, restSpreadNames)) return ''
|
|
381
400
|
// `wrap` lowers loop-param references — including destructured rest
|
|
382
401
|
// bindings (`...rest` lifted via `paramBindings`) — into their item
|
|
383
402
|
// accessor. Skipping it here meant `{...rest}` inside a `.map()`
|
|
@@ -393,6 +412,26 @@ function renderTemplateAttrPart(
|
|
|
393
412
|
}
|
|
394
413
|
}
|
|
395
414
|
|
|
415
|
+
/**
|
|
416
|
+
* Whether a child-component call's prop reaches the CSR `renderChild(...)`
|
|
417
|
+
* props object. Explicit props do (`key` is the call's own identity, not a
|
|
418
|
+
* prop). A spread does when it is the component's own props object
|
|
419
|
+
* (`SpreadAttr.propsObject`, decided in Phase 1): kept in source order next
|
|
420
|
+
* to the explicit props, the object literal merges like the JSX call does
|
|
421
|
+
* (#3688) — a later key overrides an earlier one, and the spread overrides
|
|
422
|
+
* only the keys the caller passed. Any other spread stays out.
|
|
423
|
+
*/
|
|
424
|
+
function keepsTemplateComponentProp(p: IRProp): boolean {
|
|
425
|
+
if (p.name === 'key') return false
|
|
426
|
+
if (p.name === '...' || p.name.startsWith('...')) return p.value.kind === 'spread' && p.value.propsObject === true
|
|
427
|
+
return true
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** One `renderChild(...)` props-object entry: `name: value`, or `...value` for a spread. */
|
|
431
|
+
function templatePropEntry(p: IRProp, valueExpr: string): string {
|
|
432
|
+
return p.name === '...' || p.name.startsWith('...') ? `...${valueExpr}` : `${quotePropName(p.name)}: ${valueExpr}`
|
|
433
|
+
}
|
|
434
|
+
|
|
396
435
|
/**
|
|
397
436
|
* Source-of-truth predicates for the collision-safe spread-attrs merge
|
|
398
437
|
* shared by all three CSR-side emit paths (`irToHtmlTemplate`,
|
|
@@ -743,7 +782,7 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
|
|
|
743
782
|
// SSR-reused row never has — visible the moment a row-count change
|
|
744
783
|
// makes reused and rebuilt rows coexist in one list (#2756).
|
|
745
784
|
const mergeCtx: MergeContext = {
|
|
746
|
-
isFilteredSpread: (v) =>
|
|
785
|
+
isFilteredSpread: (v) => isCallerBagSpread(v, restSpreadNames),
|
|
747
786
|
honorClientOnly: true,
|
|
748
787
|
}
|
|
749
788
|
const useMerge = shouldUseSpreadAttrsMerge(node.attrs, mergeCtx)
|
|
@@ -873,7 +912,7 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
|
|
|
873
912
|
// This allows stateless components in conditional branches to render their content
|
|
874
913
|
// instead of emitting empty placeholders (#435).
|
|
875
914
|
const propsEntries = node.props
|
|
876
|
-
.filter(
|
|
915
|
+
.filter(keepsTemplateComponentProp)
|
|
877
916
|
// `ref` joins the `on*` handlers here: a function prop cannot run
|
|
878
917
|
// during module-scope string rendering, and a ref closing over an
|
|
879
918
|
// init-scope setter would leak it into the template (#2468). The
|
|
@@ -927,7 +966,7 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
|
|
|
927
966
|
// previously masked by the post-hoc `wrapLoopParamAsAccessor`
|
|
928
967
|
// pass over the whole branch string, which #2868 removed.
|
|
929
968
|
const expr = wrapExpr(attrValueToString(p.value, { useTemplate: true }) ?? 'undefined')
|
|
930
|
-
return
|
|
969
|
+
return templatePropEntry(p, expr)
|
|
931
970
|
}
|
|
932
971
|
}
|
|
933
972
|
})
|
|
@@ -1581,7 +1620,15 @@ function irNodeToJsExprs(node: IRNode, brandMarkup = false): string[] {
|
|
|
1581
1620
|
}
|
|
1582
1621
|
|
|
1583
1622
|
const propsExpr = propsEntries.length > 0 ? `{ ${propsEntries.join(', ')} }` : '{}'
|
|
1584
|
-
|
|
1623
|
+
// A slotted child gets the same slot identity SSR stamps on it
|
|
1624
|
+
// (`bf-h` = the authoring component, `bf-m` = its slot), so a
|
|
1625
|
+
// client-built tree matches the server's and a lookup of content
|
|
1626
|
+
// forwarded through it can tell it is a receiver (#3695). A loop row
|
|
1627
|
+
// root never takes a slot (`createComponent`'s own contract).
|
|
1628
|
+
const slotArg = node.slotId && !node.loopItemRoot
|
|
1629
|
+
? `, undefined, { parent: __scopeId, mount: '${node.slotId}' }`
|
|
1630
|
+
: ''
|
|
1631
|
+
return [`createComponent('${nameForRegistryRef(node.name)}', ${propsExpr}${slotArg})`]
|
|
1585
1632
|
}
|
|
1586
1633
|
|
|
1587
1634
|
case 'expression':
|
|
@@ -1736,8 +1783,9 @@ export interface TemplateOptions {
|
|
|
1736
1783
|
* (the literal token `'undefined'`) whenever the resulting expression
|
|
1737
1784
|
* still references one of these names. The init function's
|
|
1738
1785
|
* `createEffect` / `initChild` bindings populate the real value once
|
|
1739
|
-
* init runs. Per-context guards (loop array, text expression
|
|
1740
|
-
*
|
|
1786
|
+
* init runs. Per-context guards (loop array, text expression, child
|
|
1787
|
+
* prop) test `transformExprOrUnsafe`'s `null` instead and translate it
|
|
1788
|
+
* into something safe for that AST position.
|
|
1741
1789
|
*/
|
|
1742
1790
|
unsafeLocalNames?: Set<string>
|
|
1743
1791
|
/**
|
|
@@ -1897,7 +1945,7 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
|
|
|
1897
1945
|
// loops emit `data-key-N` unconditionally per the reconciliation
|
|
1898
1946
|
// contract).
|
|
1899
1947
|
const mergeCtx: MergeContext = {
|
|
1900
|
-
isFilteredSpread: (v) =>
|
|
1948
|
+
isFilteredSpread: (v) => isCallerBagSpread(v, restSpreadNames, v.templateExpr ?? v.expr),
|
|
1901
1949
|
honorClientOnly: true,
|
|
1902
1950
|
}
|
|
1903
1951
|
const useMerge = shouldUseSpreadAttrsMerge(node.attrs, mergeCtx)
|
|
@@ -2031,7 +2079,7 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
|
|
|
2031
2079
|
|
|
2032
2080
|
// Use renderChild() to render child component's template at runtime (#435)
|
|
2033
2081
|
const propsEntries = node.props
|
|
2034
|
-
.filter(
|
|
2082
|
+
.filter(keepsTemplateComponentProp)
|
|
2035
2083
|
// `ref` joins the `on*` handlers here: a function prop cannot run
|
|
2036
2084
|
// during module-scope string rendering, and a ref closing over an
|
|
2037
2085
|
// init-scope setter would leak it into the template (#2468). The
|
|
@@ -2059,7 +2107,7 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
|
|
|
2059
2107
|
case 'expression':
|
|
2060
2108
|
return `${quotePropName(p.name)}: ${transformExpr(p.value.expr, p.value.templateExpr)}`
|
|
2061
2109
|
case 'spread':
|
|
2062
|
-
return
|
|
2110
|
+
return templatePropEntry(p, transformExpr(p.value.expr, p.value.templateExpr))
|
|
2063
2111
|
case 'template': {
|
|
2064
2112
|
const valueStr = attrValueToString(p.value, { useTemplate: true })!
|
|
2065
2113
|
return `${quotePropName(p.name)}: ${transformExpr(valueStr)}`
|
|
@@ -2471,7 +2519,14 @@ export function computeDeferredChildSlots(
|
|
|
2471
2519
|
function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): string {
|
|
2472
2520
|
const { restSpreadNames, propsObjectName, restPropsName, csrEnv, unsafeLocalNames, loopDepth = 0 } = opts
|
|
2473
2521
|
const env: CsrEnv = csrEnv ?? { substitutions: new Map(), propsObjectName: propsObjectName ?? null }
|
|
2474
|
-
|
|
2522
|
+
// `null` when the expression cannot run in the module-scope template
|
|
2523
|
+
// (it writes a binding or reads an init-only name). Call sites that drop
|
|
2524
|
+
// or replace such an expression test this, not `transformExpr`'s
|
|
2525
|
+
// `UNSAFE_TEMPLATE_EXPR` spelling: that sentinel is also what a source
|
|
2526
|
+
// written as the literal `undefined` transforms to, and a child prop
|
|
2527
|
+
// `label={undefined}` must keep its key (it overrides an earlier
|
|
2528
|
+
// spread value, #3752).
|
|
2529
|
+
const transformExprOrUnsafe = (expr: JsSourceText, templateExpr?: JsSourceText): string | null => {
|
|
2475
2530
|
// Single AST substitution pass: replaces signal getter calls
|
|
2476
2531
|
// (`count()` → `(initialValue)`), memo calls (`bars()` → `(body)`),
|
|
2477
2532
|
// and inlinable-const refs (`label` → `(rewrittenValue)`) in one
|
|
@@ -2486,7 +2541,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2486
2541
|
// An expression that writes a binding (`{++nextId}`, a child prop
|
|
2487
2542
|
// `() => ++start`) cannot run here: the template has no binding to
|
|
2488
2543
|
// write, and the write belongs to init's run of the component.
|
|
2489
|
-
if (writes.size > 0) return
|
|
2544
|
+
if (writes.size > 0) return null
|
|
2490
2545
|
|
|
2491
2546
|
// The CSR template runs at module scope, so any post-substitution
|
|
2492
2547
|
// free identifier that lands in `unsafeLocalNames` (init-body-only
|
|
@@ -2501,7 +2556,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2501
2556
|
// (and its `'foo-className'` / `a.className` false-match risk)
|
|
2502
2557
|
// is gone (#1267 / #1277).
|
|
2503
2558
|
if (unsafeLocalNames && unsafeLocalNames.size > 0 && setIntersects(freeIdentifiers, unsafeLocalNames)) {
|
|
2504
|
-
return
|
|
2559
|
+
return null
|
|
2505
2560
|
}
|
|
2506
2561
|
// Final emit-form: rewrite `propsName.X → _p.X` (and a direct
|
|
2507
2562
|
// rest-bag read, `restName.X → _p.X` — the rest binding IS `_p` at
|
|
@@ -2514,6 +2569,8 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2514
2569
|
// gate — #1138).
|
|
2515
2570
|
return rewritePropsObjectRef(rewritten, propsObjectName ?? null, restPropsName ?? null, { enclosingScope: opts.scope })
|
|
2516
2571
|
}
|
|
2572
|
+
const transformExpr = (expr: JsSourceText, templateExpr?: JsSourceText): string =>
|
|
2573
|
+
transformExprOrUnsafe(expr, templateExpr) ?? UNSAFE_TEMPLATE_EXPR
|
|
2517
2574
|
|
|
2518
2575
|
// `recurse` preserves `inHoistedChildren` for structural pass-through
|
|
2519
2576
|
// (fragment / conditional); `childrenRecurse` clears it — a new element
|
|
@@ -2532,7 +2589,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2532
2589
|
// `buildSpreadAttrsMergeCall`) keep the contract aligned with
|
|
2533
2590
|
// the other two CSR-side emit paths.
|
|
2534
2591
|
const mergeCtx: MergeContext = {
|
|
2535
|
-
isFilteredSpread: (v) =>
|
|
2592
|
+
isFilteredSpread: (v) => isCallerBagSpread(v, restSpreadNames, v.templateExpr ?? v.expr),
|
|
2536
2593
|
honorClientOnly: true,
|
|
2537
2594
|
}
|
|
2538
2595
|
const useMerge = shouldUseSpreadAttrsMerge(node.attrs, mergeCtx)
|
|
@@ -2656,12 +2713,12 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2656
2713
|
return `<!--bf:${node.slotId}--><!--/-->`
|
|
2657
2714
|
}
|
|
2658
2715
|
{
|
|
2659
|
-
const transformed =
|
|
2716
|
+
const transformed = transformExprOrUnsafe(node.expr, node.templateExpr)
|
|
2660
2717
|
// Init-body-only refs would render the literal text "undefined"
|
|
2661
2718
|
// before init's createEffect overwrites the slot (#1128). Emit
|
|
2662
2719
|
// an empty placeholder instead — a literal, so it bypasses the door.
|
|
2663
2720
|
const hole = interp(
|
|
2664
|
-
transformed ===
|
|
2721
|
+
transformed === null
|
|
2665
2722
|
? EMPTY_MARKUP
|
|
2666
2723
|
: spliceChildValue(node, transformed, { markupSlotIds: opts.markupSlotIds }),
|
|
2667
2724
|
)
|
|
@@ -2706,7 +2763,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2706
2763
|
}
|
|
2707
2764
|
|
|
2708
2765
|
const propsEntries = node.props
|
|
2709
|
-
.filter(
|
|
2766
|
+
.filter(keepsTemplateComponentProp)
|
|
2710
2767
|
// `ref` joins the `on*` handlers here: a function prop cannot run
|
|
2711
2768
|
// during module-scope string rendering, and a ref closing over an
|
|
2712
2769
|
// init-scope setter would leak it into the template (#2468). The
|
|
@@ -2737,18 +2794,19 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2737
2794
|
return `${quotePropName(p.name)}: true`
|
|
2738
2795
|
case 'expression':
|
|
2739
2796
|
case 'spread': {
|
|
2740
|
-
const transformed =
|
|
2741
|
-
//
|
|
2742
|
-
//
|
|
2743
|
-
//
|
|
2744
|
-
|
|
2745
|
-
|
|
2797
|
+
const transformed = transformExprOrUnsafe(p.value.expr, p.value.templateExpr)
|
|
2798
|
+
// An init-scope-only reference (#1128) drops the prop from
|
|
2799
|
+
// renderChild — initChild's getter binding will populate it once
|
|
2800
|
+
// init runs. A prop written as the literal `undefined` is not
|
|
2801
|
+
// unsafe and keeps its key (#3752).
|
|
2802
|
+
if (transformed === null) return null
|
|
2803
|
+
return templatePropEntry(p, transformed)
|
|
2746
2804
|
}
|
|
2747
2805
|
case 'template': {
|
|
2748
2806
|
const valueStr = attrValueToString(p.value, { useTemplate: true })
|
|
2749
2807
|
if (!valueStr) return null
|
|
2750
|
-
const transformed =
|
|
2751
|
-
if (transformed ===
|
|
2808
|
+
const transformed = transformExprOrUnsafe(valueStr)
|
|
2809
|
+
if (transformed === null) return null
|
|
2752
2810
|
return `${quotePropName(p.name)}: ${transformed}`
|
|
2753
2811
|
}
|
|
2754
2812
|
}
|
|
@@ -2789,12 +2847,12 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2789
2847
|
const hoistValues: string[] = []
|
|
2790
2848
|
for (const name of hoisted) {
|
|
2791
2849
|
const sub = env.substitutions.get(name)!
|
|
2792
|
-
const value =
|
|
2850
|
+
const value = transformExprOrUnsafe(sub.kind === 'call' ? `${name}()` : name)
|
|
2793
2851
|
// An init-only value stays on the resolved substitution, whose free
|
|
2794
2852
|
// identifiers still name the init-only local, so a row expression
|
|
2795
2853
|
// reading it is deferred like any other unsafe read rather than
|
|
2796
2854
|
// handed a bound `undefined` to dereference.
|
|
2797
|
-
if (value ===
|
|
2855
|
+
if (value === null) continue
|
|
2798
2856
|
const param = `__bf_outer_${name}`
|
|
2799
2857
|
hoistParams.push(param)
|
|
2800
2858
|
hoistValues.push(value)
|
|
@@ -2832,10 +2890,9 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2832
2890
|
// (already prop-substituted) so the chain inherits the same
|
|
2833
2891
|
// `_p.X` rewrites the pre-Tier-B path used.
|
|
2834
2892
|
const chainedTemplateArray = node.sortComparator || node.filterPredicate
|
|
2835
|
-
? applyLoopChain(node, node.templateArray)
|
|
2893
|
+
? applyLoopChain(node, node.templateArray, true)
|
|
2836
2894
|
: node.templateArray
|
|
2837
|
-
const
|
|
2838
|
-
const safeRawArrayExpr = rawArrayExpr === UNSAFE_TEMPLATE_EXPR ? '[]' : rawArrayExpr
|
|
2895
|
+
const safeRawArrayExpr = transformExprOrUnsafe(node.array, chainedTemplateArray) ?? '[]'
|
|
2839
2896
|
const { array: iterArrayExpr, callbackParam } = applyIterationShape(node, safeRawArrayExpr, indexParam)
|
|
2840
2897
|
const iterMethod = node.method ?? 'map'
|
|
2841
2898
|
let mapExpr: string
|
|
@@ -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. */
|
|
@@ -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
|
/**
|
|
@@ -35,10 +36,12 @@ function staticPreludeStatements(preamble: MapCallbackPreamble | undefined): str
|
|
|
35
36
|
: []
|
|
36
37
|
}
|
|
37
38
|
import { buildCompSelector, buildStaticChildRefBindings } from '../control-flow/shared.ts'
|
|
39
|
+
import { buildForwardedInnerLoopsPlan } from '../control-flow/plan/build-inner-loop.ts'
|
|
38
40
|
|
|
39
41
|
/** The inline prop shape carried on `IRLoopChildComponent.props`. */
|
|
40
42
|
type LoopChildCompProp = IRLoopChildComponent['props'][number]
|
|
41
43
|
import type {
|
|
44
|
+
ChildScopesLookup,
|
|
42
45
|
ComponentRootedInnerLoopInitPlan,
|
|
43
46
|
InnerLoopComp,
|
|
44
47
|
InnerLoopNestedInitPlan,
|
|
@@ -113,18 +116,32 @@ export function buildStaticArrayChildInitsPlan(
|
|
|
113
116
|
return plans
|
|
114
117
|
}
|
|
115
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
|
+
|
|
116
134
|
function buildSingleCompPlan(
|
|
117
135
|
elem: TopLevelLoop,
|
|
118
136
|
childComponent: IRLoopChildComponent,
|
|
119
137
|
): SingleCompInitPlan {
|
|
120
|
-
const { name, props
|
|
121
|
-
const childSelector = buildCompSelector({ name, slotId })
|
|
138
|
+
const { name, props } = childComponent
|
|
122
139
|
|
|
123
140
|
return {
|
|
124
141
|
kind: 'single-comp',
|
|
125
142
|
containerVar: `_${varSlotId(elem.slotId)}`,
|
|
126
143
|
componentName: name,
|
|
127
|
-
|
|
144
|
+
lookup: buildChildScopesLookup(childComponent),
|
|
128
145
|
arrayExpr: elem.array,
|
|
129
146
|
param: elem.param,
|
|
130
147
|
indexParam: elem.index || '__idx',
|
|
@@ -136,7 +153,16 @@ function buildSingleCompPlan(
|
|
|
136
153
|
// handlers on its forwarded children directly.
|
|
137
154
|
rowEvents: elem.bindings.events
|
|
138
155
|
.filter(ev => ev.nestedLoops.length === 0)
|
|
139
|
-
.map(ev => ({ childSlotId: ev.childSlotId, eventName: ev.eventName, handler: ev.handler })),
|
|
156
|
+
.map(ev => ({ childSlotId: ev.childSlotId, eventName: ev.eventName, handler: ev.handler, receiverSlotIds: ev.receiverSlotIds })),
|
|
157
|
+
// #3694: the static twin of the component-root loop's `innerLoops` —
|
|
158
|
+
// events inside an inner loop of the forwarded children, wired through
|
|
159
|
+
// the composite row's inner-loop emission over each hydrated row. No
|
|
160
|
+
// outer accessor: the forEach binds `param` to the plain item.
|
|
161
|
+
innerLoops: buildForwardedInnerLoopsPlan({
|
|
162
|
+
innerLoops: elem.innerLoops,
|
|
163
|
+
events: elem.bindings.events,
|
|
164
|
+
parentElVar: 'childScope',
|
|
165
|
+
}),
|
|
140
166
|
}
|
|
141
167
|
}
|
|
142
168
|
|
|
@@ -149,7 +175,7 @@ function buildOuterNestedPlan(
|
|
|
149
175
|
kind: 'outer-nested',
|
|
150
176
|
containerVar: `_${varSlotId(elem.slotId)}`,
|
|
151
177
|
componentName: comp.name,
|
|
152
|
-
|
|
178
|
+
lookup: buildChildScopesLookup(comp),
|
|
153
179
|
arrayExpr: elem.array,
|
|
154
180
|
param: elem.param,
|
|
155
181
|
indexParam,
|
|
@@ -172,7 +198,7 @@ function buildInnerLoopNestedPlan(
|
|
|
172
198
|
const innerIndexParam = innerLoop.index || '__innerIdx'
|
|
173
199
|
const comps: InnerLoopComp[] = innerComps.map(comp => ({
|
|
174
200
|
componentName: comp.name,
|
|
175
|
-
|
|
201
|
+
lookup: buildChildScopesLookup(comp),
|
|
176
202
|
propsExpr: buildStaticPropsExpr(comp.props),
|
|
177
203
|
}))
|
|
178
204
|
|
|
@@ -235,7 +261,7 @@ function buildComponentRootedInnerLoopPlan(
|
|
|
235
261
|
): ComponentRootedInnerLoopInitPlan {
|
|
236
262
|
const comps: InnerLoopComp[] = innerComps.map(comp => ({
|
|
237
263
|
componentName: comp.name,
|
|
238
|
-
|
|
264
|
+
lookup: buildChildScopesLookup(comp),
|
|
239
265
|
propsExpr: buildStaticPropsExpr(comp.props),
|
|
240
266
|
}))
|
|
241
267
|
|
|
@@ -268,29 +294,30 @@ function buildComponentRootedInnerLoopPlan(
|
|
|
268
294
|
* property, NOT a getter), matching the legacy emitter byte-for-byte.
|
|
269
295
|
*/
|
|
270
296
|
function buildStaticPropsExpr(props: readonly LoopChildCompProp[]): PropsExpr {
|
|
271
|
-
|
|
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 => {
|
|
272
300
|
if (p.isEventHandler) {
|
|
273
|
-
return
|
|
301
|
+
return { expr: attrValueToString(p.value) ?? 'undefined', getter: false }
|
|
274
302
|
}
|
|
275
303
|
switch (p.value.kind) {
|
|
276
304
|
case 'literal':
|
|
277
|
-
return
|
|
305
|
+
return { expr: JSON.stringify(p.value.value), getter: false }
|
|
278
306
|
case 'boolean-shorthand':
|
|
279
307
|
case 'boolean-attr':
|
|
280
|
-
return
|
|
308
|
+
return { expr: 'true', getter: false }
|
|
281
309
|
case 'jsx-children':
|
|
282
310
|
// Brand via the shared door (#2651/#2702) — see
|
|
283
311
|
// `jsxChildrenPropGetterExpr`'s docstring. A named jsx-children
|
|
284
312
|
// prop on a component instantiated inside a static-array `.map()`
|
|
285
313
|
// loop used to reach its getter unbranded (pullfrog review, PR
|
|
286
314
|
// #2820).
|
|
287
|
-
return
|
|
315
|
+
return { expr: jsxChildrenPropGetterExpr(p.value.children, p.name), getter: true }
|
|
288
316
|
case 'expression':
|
|
289
317
|
case 'template':
|
|
290
318
|
case 'spread':
|
|
291
|
-
return
|
|
319
|
+
return { expr: attrValueToString(p.value) ?? 'undefined', getter: true }
|
|
292
320
|
}
|
|
293
321
|
})
|
|
294
|
-
return entries.length > 0 ? `{ ${entries.join(', ')} }` : '{}'
|
|
295
322
|
}
|
|
296
323
|
|