@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,15 +2,16 @@
|
|
|
2
2
|
* IR tree traversal → collect elements into ClientJsContext.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { type IRNode, type IRElement, type IRComponent, type IRConditional, type IRLoop, type IRProp, pickAttrMetaFromIR } from '../types.ts'
|
|
5
|
+
import { type AttrValue, type IRNode, type IRElement, type IRComponent, type IRConditional, type IRLoop, type IRProp, pickAttrMetaFromIR } from '../types.ts'
|
|
6
6
|
import type { ClientJsContext, ConditionalBranchChildComponent, ConditionalBranchReactiveAttr, BranchLoop, ConditionalBranchTextEffect, ConditionalElement, LoopChildBindings, LoopChildBranchSummary, LoopChildConditional, LoopOffset, NestedLoop } from './types.ts'
|
|
7
|
-
import { attrValueToString, freeIdsFromRefs,
|
|
7
|
+
import { attrValueToString, freeIdsFromRefs, PROPS_PARAM, toHtmlAttrName, rowBoundNames, withRowAccessor, type LoopParamSpec } from './utils.ts'
|
|
8
8
|
import { classifyReactivity, needsEffectWrapper, decideWrapForAttr, decideWrapForChildProp, decideWrapFromAstFlags, collectEventHandlersFromIR, collectConditionalBranchEvents, collectConditionalBranchRefs, collectConditionalBranchChildComponents, collectConditionalBranchComponentNodes, collectLoopChildEventsWithNesting, collectLoopChildReactiveAttrs, collectLoopChildReactiveTexts, collectLoopChildRefs, emptyLoopChildBindings, buildLoopRowScope, anyNameIn } from './reactivity.ts'
|
|
9
9
|
import { irToHtmlTemplate, irToPlaceholderTemplate, irChildrenToJsExpr, jsxChildrenPropGetterExpr, buildLoopSkeletonTemplate, computeSkeletonSlotPaths, renderFlatMapClientBody, renderFlatMapProjectionClientBody, flatMapCallbackHasKeyedLeaf, type SkeletonSlotPaths } from './html-template.ts'
|
|
10
10
|
import { detectRootNamespaceWrapTag } from './control-flow/stringify/template-parse.ts'
|
|
11
11
|
import { expandDynamicPropValue, expandConstantForReactivity, resolveRestSpreadOrigin, resolveRestSpreadNames } from './prop-handling.ts'
|
|
12
12
|
import { extractFreeIdentifiersFromText } from './csr-substitute.ts'
|
|
13
13
|
import { walkIR, stopAt } from './walker.ts'
|
|
14
|
+
import { callerFirstPropExpr, childPropsObjectExpr, isSpreadPropName, lastPropsObjectSpreadIndex } from './child-props-object.ts'
|
|
14
15
|
import { buildLoopChainExpr } from '../loop-chain.ts'
|
|
15
16
|
import { classifyDOMProp } from '@barefootjs/shared'
|
|
16
17
|
import type { BindingScope } from '../scope/binding-scope.ts'
|
|
@@ -445,6 +446,11 @@ export function collectInnerLoops(
|
|
|
445
446
|
childComponents,
|
|
446
447
|
insideConditional: !flat && scope.insideCond ? true : undefined,
|
|
447
448
|
offset: flat ? undefined : resolveLoopOffset(siblingOffsets.get(n)),
|
|
449
|
+
filterPredicate: n.filterPredicate ? { param: n.filterPredicate.param, raw: n.filterPredicate.raw } : undefined,
|
|
450
|
+
sortComparator: n.sortComparator
|
|
451
|
+
? { paramA: n.sortComparator.paramA, paramB: n.sortComparator.paramB, raw: n.sortComparator.raw }
|
|
452
|
+
: undefined,
|
|
453
|
+
chainOrder: n.chainOrder,
|
|
448
454
|
bindings,
|
|
449
455
|
})
|
|
450
456
|
// Branch-mode callers handle deeper nesting via their own collection paths.
|
|
@@ -504,6 +510,18 @@ function decideLoopRendering(
|
|
|
504
510
|
return { useElementReconciliation, innerLoops }
|
|
505
511
|
}
|
|
506
512
|
|
|
513
|
+
/**
|
|
514
|
+
* Whether a top-level loop carries its collected inner loops to the client
|
|
515
|
+
* JS plans: a reconciled (composite) row, a static array's row, and a
|
|
516
|
+
* component-root row (#3694), whose forwarded children's inner loops get
|
|
517
|
+
* their event handlers wired per row (`buildForwardedInnerLoopsPlan`).
|
|
518
|
+
*/
|
|
519
|
+
function keepsInnerLoops(loop: IRLoop, useElementReconciliation: boolean, innerLoops: NestedLoop[] | undefined): boolean {
|
|
520
|
+
if (useElementReconciliation) return true
|
|
521
|
+
if (!innerLoops || innerLoops.length === 0) return false
|
|
522
|
+
return loop.isStaticArray || !!loop.childComponent
|
|
523
|
+
}
|
|
524
|
+
|
|
507
525
|
/** Check whether an array of IR nodes contains any component nodes (recursively). */
|
|
508
526
|
function jsxChildrenContainComponent(nodes: IRNode[]): boolean {
|
|
509
527
|
for (const node of nodes) {
|
|
@@ -517,70 +535,86 @@ function jsxChildrenContainComponent(nodes: IRNode[]): boolean {
|
|
|
517
535
|
return false
|
|
518
536
|
}
|
|
519
537
|
|
|
538
|
+
/**
|
|
539
|
+
* One explicit prop's `initChild` props-object entry: its value expression,
|
|
540
|
+
* and whether it is read through a getter (deferred, so reactive) or is a
|
|
541
|
+
* plain data property.
|
|
542
|
+
*/
|
|
543
|
+
function componentInitPropValue(prop: IRProp, ctx: ClientJsContext): { expr: string; getter: boolean } {
|
|
544
|
+
if (isEventHandlerName(prop.name)) {
|
|
545
|
+
// Event handlers reach here only as `expression` variants.
|
|
546
|
+
return { expr: attrValueToString(prop.value) ?? prop.name, getter: false }
|
|
547
|
+
}
|
|
548
|
+
switch (prop.value.kind) {
|
|
549
|
+
case 'jsx-children':
|
|
550
|
+
if (jsxChildrenContainComponent(prop.value.children)) {
|
|
551
|
+
return { expr: `__slot(() => ${irChildrenToJsExpr(prop.value.children)})`, getter: true }
|
|
552
|
+
}
|
|
553
|
+
// Brand via the shared door (#2651/#2702) — see
|
|
554
|
+
// `jsxChildrenPropGetterExpr`'s docstring.
|
|
555
|
+
return { expr: jsxChildrenPropGetterExpr(prop.value.children, prop.name), getter: true }
|
|
556
|
+
case 'expression':
|
|
557
|
+
case 'template':
|
|
558
|
+
case 'spread':
|
|
559
|
+
return { expr: expandDynamicPropValue(attrValueToString(prop.value)!, ctx), getter: true }
|
|
560
|
+
case 'literal':
|
|
561
|
+
return { expr: JSON.stringify(prop.value.value), getter: false }
|
|
562
|
+
case 'boolean-shorthand':
|
|
563
|
+
case 'boolean-attr':
|
|
564
|
+
// `boolean-attr` should not reach here for component props
|
|
565
|
+
// (processComponentProps promotes it to boolean-shorthand), but handle
|
|
566
|
+
// it defensively.
|
|
567
|
+
return { expr: 'true', getter: false }
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* The merged value of the explicit prop at `index` for a reactive DOM
|
|
573
|
+
* mirror: caller-first when a later props-object spread (at `spreadAt`, see
|
|
574
|
+
* `lastPropsObjectSpreadIndex`) overrides it, `expr` as written otherwise.
|
|
575
|
+
*/
|
|
576
|
+
function mergedMirrorExpr(name: string, expr: string, index: number, spreadAt: number): string {
|
|
577
|
+
return index < spreadAt ? callerFirstPropExpr(name, expr) : expr
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Which caller bag an element's spread attribute forwards, for
|
|
582
|
+
* `applyRestAttrs`: its text resolved through any `const x__alias = x` hop
|
|
583
|
+
* onto the rest/props binding (#2723, `resolveRestSpreadOrigin`). Null
|
|
584
|
+
* when Phase 1 did not resolve the spread to the bag
|
|
585
|
+
* (`SpreadAttr.callerBag`): a loop row or callback parameter spelled like
|
|
586
|
+
* the rest binding is that binding (#3851).
|
|
587
|
+
*/
|
|
588
|
+
function callerBagSpreadOrigin(value: AttrValue, ctx: ClientJsContext): 'rest' | 'props' | null {
|
|
589
|
+
if (value.kind !== 'spread' || value.callerBag === undefined) return null
|
|
590
|
+
const spreadVal = attrValueToString(value) ?? ''
|
|
591
|
+
return spreadVal ? resolveRestSpreadOrigin(ctx, spreadVal) : null
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* The live `_p.<key>` read a closed-rest-expanded attribute binds to
|
|
596
|
+
* (`IRAttribute.restExpandedKey`, #3057), with the value an earlier
|
|
597
|
+
* attribute gave the key when the caller omits it, as SSR rendered it
|
|
598
|
+
* (`IRAttribute.restFallback`, #3851).
|
|
599
|
+
*/
|
|
600
|
+
function restKeyLiveRead(attr: IRElement['attrs'][number]): string {
|
|
601
|
+
const read = `${PROPS_PARAM}.${attr.name}`
|
|
602
|
+
return attr.restFallback === undefined ? read : `${read} ?? (${attr.restFallback})`
|
|
603
|
+
}
|
|
604
|
+
|
|
520
605
|
/** Build propsExpr for a child component from its IR props. */
|
|
521
606
|
function buildComponentPropsExpr(props: IRProp[], ctx: ClientJsContext): string {
|
|
522
607
|
const knownSpreadProp = props.find(p => {
|
|
523
|
-
if (
|
|
608
|
+
if (!isSpreadPropName(p.name)) return false
|
|
524
609
|
if (p.value.kind !== 'spread' && p.value.kind !== 'expression') return false
|
|
525
610
|
const expr = p.value.kind === 'spread' ? p.value.expr : p.value.expr
|
|
526
611
|
// #2723: resolve through any `const x__alias = x` hop onto the
|
|
527
612
|
// rest/props binding — see `resolveRestSpreadOrigin`'s docstring.
|
|
528
613
|
return resolveRestSpreadOrigin(ctx, expr) !== null
|
|
529
614
|
})
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
const explicitPropNames: string[] = []
|
|
534
|
-
for (const prop of props) {
|
|
535
|
-
if (prop.name === '...' || prop.name.startsWith('...')) continue
|
|
536
|
-
explicitPropNames.push(prop.name)
|
|
537
|
-
const isEventHandler = isEventHandlerName(prop.name)
|
|
538
|
-
if (isEventHandler) {
|
|
539
|
-
// Event handlers reach here only as `expression` variants.
|
|
540
|
-
propsForInit.push(`${quotePropName(prop.name)}: ${attrValueToString(prop.value) ?? prop.name}`)
|
|
541
|
-
continue
|
|
542
|
-
}
|
|
543
|
-
switch (prop.value.kind) {
|
|
544
|
-
case 'jsx-children': {
|
|
545
|
-
if (jsxChildrenContainComponent(prop.value.children)) {
|
|
546
|
-
const jsxExpr = irChildrenToJsExpr(prop.value.children)
|
|
547
|
-
propsForInit.push(`get ${quotePropName(prop.name)}() { return __slot(() => ${jsxExpr}) }`)
|
|
548
|
-
} else {
|
|
549
|
-
// Brand via the shared door (#2651/#2702) — see
|
|
550
|
-
// `jsxChildrenPropGetterExpr`'s docstring.
|
|
551
|
-
const jsxExpr = jsxChildrenPropGetterExpr(prop.value.children, prop.name)
|
|
552
|
-
propsForInit.push(`get ${quotePropName(prop.name)}() { return ${jsxExpr} }`)
|
|
553
|
-
}
|
|
554
|
-
break
|
|
555
|
-
}
|
|
556
|
-
case 'expression':
|
|
557
|
-
case 'template':
|
|
558
|
-
case 'spread': {
|
|
559
|
-
const valueExpr = attrValueToString(prop.value)!
|
|
560
|
-
const expandedValue = expandDynamicPropValue(valueExpr, ctx)
|
|
561
|
-
propsForInit.push(`get ${quotePropName(prop.name)}() { return ${expandedValue} }`)
|
|
562
|
-
break
|
|
563
|
-
}
|
|
564
|
-
case 'literal':
|
|
565
|
-
propsForInit.push(`${quotePropName(prop.name)}: ${JSON.stringify(prop.value.value)}`)
|
|
566
|
-
break
|
|
567
|
-
case 'boolean-shorthand':
|
|
568
|
-
propsForInit.push(`${quotePropName(prop.name)}: true`)
|
|
569
|
-
break
|
|
570
|
-
case 'boolean-attr':
|
|
571
|
-
// Should not reach here for component props (processComponentProps
|
|
572
|
-
// promotes to boolean-shorthand), but handle defensively.
|
|
573
|
-
propsForInit.push(`${quotePropName(prop.name)}: true`)
|
|
574
|
-
break
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
if (spreadSource) {
|
|
579
|
-
const overrides = propsForInit.length > 0 ? `{ ${propsForInit.join(', ')} }` : '{}'
|
|
580
|
-
const excludeKeys = JSON.stringify(explicitPropNames)
|
|
581
|
-
return `forwardProps(${spreadSource}, ${overrides}, ${excludeKeys})`
|
|
582
|
-
}
|
|
583
|
-
return propsForInit.length > 0 ? `{ ${propsForInit.join(', ')} }` : '{}'
|
|
615
|
+
return childPropsObjectExpr(props, prop => componentInitPropValue(prop, ctx), {
|
|
616
|
+
forwardCaller: knownSpreadProp !== undefined,
|
|
617
|
+
})
|
|
584
618
|
}
|
|
585
619
|
|
|
586
620
|
/**
|
|
@@ -589,7 +623,8 @@ function buildComponentPropsExpr(props: IRProp[], ctx: ClientJsContext): string
|
|
|
589
623
|
* side-effect helper so `buildComponentPropsExpr` stays a pure function.
|
|
590
624
|
*/
|
|
591
625
|
function collectReactiveChildProps(node: IRComponent, ctx: ClientJsContext): void {
|
|
592
|
-
|
|
626
|
+
const spreadAt = lastPropsObjectSpreadIndex(node.props)
|
|
627
|
+
for (const [index, prop] of node.props.entries()) {
|
|
593
628
|
if (prop.name === '...' || prop.name.startsWith('...')) continue
|
|
594
629
|
if (prop.value.kind === 'jsx-children') continue
|
|
595
630
|
// `classifyDOMProp` is the single source of truth for "how does this prop
|
|
@@ -629,7 +664,7 @@ function collectReactiveChildProps(node: IRComponent, ctx: ClientJsContext): voi
|
|
|
629
664
|
slotId: node.slotId,
|
|
630
665
|
propName: prop.name,
|
|
631
666
|
attrName,
|
|
632
|
-
expression: expandedValue,
|
|
667
|
+
expression: mergedMirrorExpr(prop.name, expandedValue, index, spreadAt),
|
|
633
668
|
...pickAttrMetaFromIR(prop),
|
|
634
669
|
})
|
|
635
670
|
}
|
|
@@ -971,7 +1006,7 @@ export function collectElements(
|
|
|
971
1006
|
nestedComponents: l.nestedComponents,
|
|
972
1007
|
isStaticArray: clientIsStaticArray,
|
|
973
1008
|
useElementReconciliation,
|
|
974
|
-
innerLoops: (
|
|
1009
|
+
innerLoops: keepsInnerLoops(l, useElementReconciliation, innerLoops) ? innerLoops : undefined,
|
|
975
1010
|
offset: resolveLoopOffset(siblingOffsets.get(l)),
|
|
976
1011
|
filterPredicate: l.filterPredicate ? {
|
|
977
1012
|
param: l.filterPredicate.param,
|
|
@@ -1004,7 +1039,8 @@ export function collectElements(
|
|
|
1004
1039
|
component: ({ node: c, descend, descendJsxChildren }) => {
|
|
1005
1040
|
if (c.slotId) {
|
|
1006
1041
|
// Reactive props need effects to update the element when values change.
|
|
1007
|
-
|
|
1042
|
+
const spreadAt = lastPropsObjectSpreadIndex(c.props)
|
|
1043
|
+
for (const [index, prop] of c.props.entries()) {
|
|
1008
1044
|
if (prop.value.kind === 'jsx-children') continue
|
|
1009
1045
|
if (isEventHandlerName(prop.name)) continue
|
|
1010
1046
|
// Only `expression` variants reach the signal/memo getter heuristic
|
|
@@ -1020,7 +1056,7 @@ export function collectElements(
|
|
|
1020
1056
|
ctx.reactiveProps.push({
|
|
1021
1057
|
slotId: c.slotId,
|
|
1022
1058
|
propName: prop.name,
|
|
1023
|
-
expression:
|
|
1059
|
+
expression: mergedMirrorExpr(prop.name, value, index, spreadAt),
|
|
1024
1060
|
componentName: c.name,
|
|
1025
1061
|
})
|
|
1026
1062
|
}
|
|
@@ -1099,10 +1135,7 @@ function collectFromElement(element: IRElement, ctx: ClientJsContext, insideCond
|
|
|
1099
1135
|
// Other identifiers or complex expressions may not exist in the compiled init scope.
|
|
1100
1136
|
// Always use PROPS_PARAM as the source since the init function parameter is PROPS_PARAM.
|
|
1101
1137
|
if (attr.name === '...' && attr.value) {
|
|
1102
|
-
const
|
|
1103
|
-
// #2723: resolve through any `const x__alias = x` hop onto the
|
|
1104
|
-
// rest/props binding — see `resolveRestSpreadOrigin`'s docstring.
|
|
1105
|
-
const spreadOrigin = spreadVal ? resolveRestSpreadOrigin(ctx, spreadVal) : null
|
|
1138
|
+
const spreadOrigin = callerBagSpreadOrigin(attr.value, ctx)
|
|
1106
1139
|
if (spreadOrigin !== null) {
|
|
1107
1140
|
// `applyRestAttrs(_el, _p, exclude)` is handed the FULL props
|
|
1108
1141
|
// object (`PROPS_PARAM`), not a computed JS rest binding, and the
|
|
@@ -1191,7 +1224,7 @@ function collectFromElement(element: IRElement, ctx: ClientJsContext, insideCond
|
|
|
1191
1224
|
ctx.reactiveAttrs.push({
|
|
1192
1225
|
slotId: element.slotId,
|
|
1193
1226
|
attrName: attr.name,
|
|
1194
|
-
expression:
|
|
1227
|
+
expression: restKeyLiveRead(attr),
|
|
1195
1228
|
...pickAttrMetaFromIR(attr),
|
|
1196
1229
|
})
|
|
1197
1230
|
continue
|
|
@@ -683,7 +683,7 @@ function collectTemplateRiskyNames(irRoot: IRNode): Set<string> {
|
|
|
683
683
|
},
|
|
684
684
|
component: ({ descend, descendJsxChildren }) => {
|
|
685
685
|
// Component props are stripped from `renderChild` when
|
|
686
|
-
// `
|
|
686
|
+
// `transformExprOrUnsafe` reports them unsafe (see
|
|
687
687
|
// html-template.ts). `initChild`'s getter binding then fills
|
|
688
688
|
// the prop once init runs. No diagnostic needed.
|
|
689
689
|
descend()
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
} from '../shared.ts'
|
|
33
33
|
import { irChildrenToJsExpr, renderPreamble } from '../../html-template.ts'
|
|
34
34
|
import { buildReactiveEffectsPlan } from './build-reactive-effects.ts'
|
|
35
|
+
import { buildForwardedInnerLoopsPlan } from './build-inner-loop.ts'
|
|
35
36
|
import type { ComponentLoopPlan, NestedComponentInit } from './types.ts'
|
|
36
37
|
import { internalInvariant } from '../../../errors.ts'
|
|
37
38
|
|
|
@@ -146,10 +147,21 @@ export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?
|
|
|
146
147
|
// loop has no delegation pass (`loopEventDelegationVariant` returns null
|
|
147
148
|
// for it), so each row attaches its handlers directly, exactly like the
|
|
148
149
|
// composite row's `outerEvents`. Events inside an inner loop of the
|
|
149
|
-
// forwarded children (`nestedLoops` non-empty)
|
|
150
|
+
// forwarded children (`nestedLoops` non-empty) go to `innerLoops` below.
|
|
150
151
|
const rowEvents = elem.bindings.events
|
|
151
152
|
.filter(ev => ev.nestedLoops.length === 0)
|
|
152
153
|
.map(ev => buildRowEventBinding(ev, elem.param, elem.paramBindings, elem.index))
|
|
154
|
+
// #3694: an event inside an inner loop of the forwarded children is wired
|
|
155
|
+
// by running that inner loop's composite-row emission over each row's
|
|
156
|
+
// element, hydrated and client-built alike.
|
|
157
|
+
const forwardedInnerLoops = (parentElVar: '__existing' | '__csrEl') => buildForwardedInnerLoopsPlan({
|
|
158
|
+
innerLoops: elem.innerLoops,
|
|
159
|
+
events: elem.bindings.events,
|
|
160
|
+
parentElVar,
|
|
161
|
+
outerLoopParam: elem.param,
|
|
162
|
+
outerLoopParamBindings: elem.paramBindings,
|
|
163
|
+
outerLoopIndex: elem.index,
|
|
164
|
+
})
|
|
153
165
|
|
|
154
166
|
return {
|
|
155
167
|
kind: 'component',
|
|
@@ -170,6 +182,7 @@ export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?
|
|
|
170
182
|
keyExpr,
|
|
171
183
|
nestedComps,
|
|
172
184
|
rowEvents,
|
|
185
|
+
innerLoops: { hydrated: forwardedInnerLoops('__existing'), created: forwardedInnerLoops('__csrEl') },
|
|
173
186
|
// #3612: refs on elements forwarded as the root component's own
|
|
174
187
|
// `children` (`<Chip><input ref={el => …} /></Chip>`), collected by the
|
|
175
188
|
// same `collectLoopChildBindings` walk as `rowEvents` above and resolved
|
|
@@ -179,6 +192,7 @@ export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?
|
|
|
179
192
|
// binding here: it goes to the component through `componentPropsExpr`.
|
|
180
193
|
childRefs: buildChildRefBindings(elem.bindings.refs, elem.param, elem.paramBindings, elem.index),
|
|
181
194
|
profileLoopId: profileComponentName ? `${profileComponentName}#binding:${elem.slotId}` : undefined,
|
|
195
|
+
profileComponentName,
|
|
182
196
|
reactiveEffects: hasReactiveEffects
|
|
183
197
|
? buildReactiveEffectsPlan({
|
|
184
198
|
attrs: elem.bindings.reactiveAttrs,
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import type {
|
|
27
|
+
LoopChildConditional,
|
|
27
28
|
LoopChildEvent,
|
|
28
29
|
NestedLoop,
|
|
29
30
|
} from '../../types.ts'
|
|
@@ -42,6 +43,7 @@ import {
|
|
|
42
43
|
attrValueToString,
|
|
43
44
|
} from '../../utils.ts'
|
|
44
45
|
import { buildChildRefBindings } from '../shared.ts'
|
|
46
|
+
import { buildLoopChainExpr } from '../../../loop-chain.ts'
|
|
45
47
|
import { renderPreamble, irToHtmlTemplate } from '../../html-template.ts'
|
|
46
48
|
import { buildLoopChildConditionalsPlan } from './build-loop-child-arm.ts'
|
|
47
49
|
import type { LoopChildConditionalPlan } from './loop-child-arm.ts'
|
|
@@ -67,11 +69,18 @@ function wrapAttrValueExpression(value: AttrValue, wrap: (s: string) => string):
|
|
|
67
69
|
return AttrValueOf.expression(wrap(flat ?? 'undefined'))
|
|
68
70
|
}
|
|
69
71
|
case 'spread':
|
|
70
|
-
|
|
72
|
+
// Keep the Phase-1 props-object marker: the props object merges this
|
|
73
|
+
// spread in source order (#3713).
|
|
74
|
+
return {
|
|
75
|
+
...AttrValueOf.spread(wrap(value.expr), value.templateExpr ? wrap(value.templateExpr) : undefined),
|
|
76
|
+
...(value.propsObject && { propsObject: true as const }),
|
|
77
|
+
}
|
|
71
78
|
}
|
|
72
79
|
}
|
|
73
80
|
import type { DepthLevel } from '../shared.ts'
|
|
81
|
+
import type { LoopRowEventBinding } from './loop.ts'
|
|
74
82
|
import {
|
|
83
|
+
buildDepthLevels,
|
|
75
84
|
destructureLoopParam,
|
|
76
85
|
loopKeyFn,
|
|
77
86
|
nestedLoopIndexAlias,
|
|
@@ -143,7 +152,14 @@ export function buildInnerLoopsPlan(args: BuildInnerLoopsArgs): InnerLoopsPlan {
|
|
|
143
152
|
// shortcut was unsound.
|
|
144
153
|
const emit: InnerLoopReactiveEmit = buildReactiveEmit(inner, level, wrapOuter, uidSuffix, outerLoopParam, outerLoopParamBindings, outerLoopIndex)
|
|
145
154
|
|
|
146
|
-
|
|
155
|
+
// The inner `.filter()` / `.toSorted()` chain (#3694), so the rows
|
|
156
|
+
// reconciled are the rows the template rendered.
|
|
157
|
+
const arrayExpr = wrapOuter(buildLoopChainExpr({
|
|
158
|
+
base: inner.array,
|
|
159
|
+
filterPredicate: inner.filterPredicate,
|
|
160
|
+
sortComparator: inner.sortComparator,
|
|
161
|
+
chainOrder: inner.chainOrder,
|
|
162
|
+
}))
|
|
147
163
|
|
|
148
164
|
const childLevelsPlan = childLevels.length > 0
|
|
149
165
|
? buildInnerLoopsPlan({
|
|
@@ -231,15 +247,20 @@ function buildReactiveEmit(
|
|
|
231
247
|
props: comp.props.map(p => ({ ...p, value: wrapAttrValueExpression(p.value, wrapInner) })),
|
|
232
248
|
children: comp.children?.map(wrapIRNode),
|
|
233
249
|
}))
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
250
|
+
// Resolved against every enclosing row, like the texts below (#3694): an
|
|
251
|
+
// inner-wrap-only handler left a grandparent row's item two loops up
|
|
252
|
+
// unwrapped (`o.id` on the accessor reads `undefined`).
|
|
253
|
+
const events: LoopRowEventBinding[] = level.events.map(ev => ({
|
|
254
|
+
childSlotId: ev.childSlotId,
|
|
255
|
+
eventName: ev.eventName,
|
|
256
|
+
handler: wrapBoth(ev.handler),
|
|
237
257
|
}))
|
|
238
258
|
|
|
239
259
|
const reactiveTexts: InnerLoopText[] = inner.bindings.reactiveTexts.map(text => ({
|
|
240
260
|
slotId: text.slotId,
|
|
241
261
|
wrappedExpression: wrapLoopParamAsAccessor(wrapOuterRow(text.expression), inner.param, inner.paramBindings, inner.index),
|
|
242
262
|
insideConditional: !!text.insideConditional,
|
|
263
|
+
...(text.markup && { markup: true as const }),
|
|
243
264
|
}))
|
|
244
265
|
|
|
245
266
|
const reactiveAttrs: InnerLoopReactiveAttr[] = inner.bindings.reactiveAttrs.map(attr => {
|
|
@@ -320,3 +341,62 @@ function buildReactiveEmit(
|
|
|
320
341
|
childRefs,
|
|
321
342
|
}
|
|
322
343
|
}
|
|
344
|
+
|
|
345
|
+
export interface BuildForwardedInnerLoopsArgs {
|
|
346
|
+
/** The row's inner loops, DFS-ordered (`TopLevelLoop.innerLoops`). */
|
|
347
|
+
innerLoops: readonly NestedLoop[] | undefined
|
|
348
|
+
/** The row's collected events (`TopLevelLoop.bindings.events`). */
|
|
349
|
+
events: readonly LoopChildEvent[]
|
|
350
|
+
/** The row element the inner loop containers are looked up in. */
|
|
351
|
+
parentElVar: string
|
|
352
|
+
/** The outer row's param, or `undefined` when the row binds it as a plain value (a static array). */
|
|
353
|
+
outerLoopParam?: string
|
|
354
|
+
outerLoopParamBindings?: readonly LoopParamBinding[]
|
|
355
|
+
outerLoopIndex?: string | null
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* The inner-loop plan for the inner loops of a component-root row's
|
|
360
|
+
* forwarded children (`<Chip key={o.id}><ul>{o.tags.map(tag => <li><button
|
|
361
|
+
* onClick={…}/></li>)}</ul></Chip>`, #3694). The child component renders its
|
|
362
|
+
* `children` once, so nothing else reaches an element inside such an inner
|
|
363
|
+
* loop: a handler there was dropped. Each row now runs the composite row's
|
|
364
|
+
* inner-loop emission (`buildInnerLoopsPlan`) over its own element, which
|
|
365
|
+
* claims the rendered inner rows and attaches the handlers with the inner
|
|
366
|
+
* and the outer bindings resolved the same way as on a composite row.
|
|
367
|
+
*
|
|
368
|
+
* Only inner loops that carry an event, and the enclosing loops they need,
|
|
369
|
+
* are planned; the others keep their output unchanged. Child components
|
|
370
|
+
* inside an inner loop are left to their existing pass (`comps` empty), so
|
|
371
|
+
* none is initialised twice.
|
|
372
|
+
*/
|
|
373
|
+
export function buildForwardedInnerLoopsPlan(args: BuildForwardedInnerLoopsArgs): InnerLoopsPlan {
|
|
374
|
+
const { innerLoops, events, parentElVar, outerLoopParam, outerLoopParamBindings, outerLoopIndex } = args
|
|
375
|
+
if (!innerLoops || innerLoops.length === 0) return []
|
|
376
|
+
const levels = buildDepthLevels([...innerLoops], [], [...events])
|
|
377
|
+
const kept = levels.filter((_, i) => levelCarriesEvent(levels, i))
|
|
378
|
+
if (kept.length === 0) return []
|
|
379
|
+
return buildInnerLoopsPlan({ levels: kept, parentElVar, outerLoopParam, outerLoopParamBindings, outerLoopIndex })
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Whether `levels[i]` or a loop nested inside it (the deeper levels right
|
|
384
|
+
* after it) carries an event, on its row or inside a conditional of its row.
|
|
385
|
+
*/
|
|
386
|
+
function levelCarriesEvent(levels: readonly DepthLevel[], i: number): boolean {
|
|
387
|
+
const depth = levels[i].loopInfo?.depth ?? 0
|
|
388
|
+
for (let j = i; j < levels.length; j++) {
|
|
389
|
+
if (j > i && (levels[j].loopInfo?.depth ?? 0) <= depth) break
|
|
390
|
+
if (levels[j].events.length > 0) return true
|
|
391
|
+
if (conditionalsCarryEvent(levels[j].loopInfo?.bindings.conditionals ?? [])) return true
|
|
392
|
+
}
|
|
393
|
+
return false
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function conditionalsCarryEvent(conditionals: readonly LoopChildConditional[]): boolean {
|
|
397
|
+
return conditionals.some(c => [c.whenTrue, c.whenFalse].some(branch =>
|
|
398
|
+
(branch.events?.length ?? 0) > 0
|
|
399
|
+
|| conditionalsCarryEvent(branch.conditionals ?? [])
|
|
400
|
+
|| (branch.innerLoops ?? []).some(l => l.bindings.events.length > 0 || conditionalsCarryEvent(l.bindings.conditionals)),
|
|
401
|
+
))
|
|
402
|
+
}
|
|
@@ -59,6 +59,8 @@ export interface LazyRowAttrBinding {
|
|
|
59
59
|
/** One reactive text (content slot) of a lazy row. */
|
|
60
60
|
export interface LazyRowTextBinding {
|
|
61
61
|
slotId: string
|
|
62
|
+
/** Claimed and written as markup (`RowTextSlot`). */
|
|
63
|
+
markup?: true
|
|
62
64
|
wrappedExpression: string
|
|
63
65
|
ordinal: number
|
|
64
66
|
readsItem: boolean
|
|
@@ -340,6 +342,7 @@ export function decideLazyRow(args: BuildLazyRowArgs): {
|
|
|
340
342
|
readsItem: c.readsItem || !c.readsOuter,
|
|
341
343
|
readsOuter: c.readsOuter,
|
|
342
344
|
readsPreamble: c.readsPreamble,
|
|
345
|
+
...(text.markup && { markup: true as const }),
|
|
343
346
|
}
|
|
344
347
|
})
|
|
345
348
|
|
|
@@ -24,7 +24,7 @@ import type {
|
|
|
24
24
|
LoopParamBinding,
|
|
25
25
|
} from '../../../types.ts'
|
|
26
26
|
import { AttrValueOf, pickAttrMeta } from '../../../types.ts'
|
|
27
|
-
import {
|
|
27
|
+
import { wrapLoopParamAsAccessor, attrValueToString, rowBoundNames, unionNames, type ShadowableWrap } from '../../utils.ts'
|
|
28
28
|
import { addCondAttrToTemplate, irChildrenToJsExpr } from '../../html-template.ts'
|
|
29
29
|
import type { ReactiveAttrSlot } from './reactive-effects.ts'
|
|
30
30
|
|
|
@@ -58,12 +58,18 @@ function wrapAttrValueExpression(value: AttrValue, wrap: (s: string) => string):
|
|
|
58
58
|
return AttrValueOf.expression(wrap(flat ?? 'undefined'))
|
|
59
59
|
}
|
|
60
60
|
case 'spread':
|
|
61
|
-
|
|
61
|
+
// Keep the Phase-1 props-object marker: the props object merges this
|
|
62
|
+
// spread in source order (#3713).
|
|
63
|
+
return {
|
|
64
|
+
...AttrValueOf.spread(wrap(value.expr), value.templateExpr ? wrap(value.templateExpr) : undefined),
|
|
65
|
+
...(value.propsObject && { propsObject: true as const }),
|
|
66
|
+
}
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
69
|
import { destructureLoopParam, loopKeyFn, buildCompSelector, nestedLoopIndexAlias } from '../shared.ts'
|
|
65
70
|
import { BF_HOST, BF_AT } from '@barefootjs/shared'
|
|
66
71
|
import { isEventHandlerName } from '../../../event-handler-name.ts'
|
|
72
|
+
import { childPropsObjectExpr, type ChildPropValue } from '../../child-props-object.ts'
|
|
67
73
|
import type {
|
|
68
74
|
BranchChildComponentInit,
|
|
69
75
|
BranchChildComponentInitsPlan,
|
|
@@ -172,35 +178,30 @@ export function buildBranchChildComponentInitsPlan(
|
|
|
172
178
|
for (const comp of components) {
|
|
173
179
|
const selector = buildCompSelector(comp)
|
|
174
180
|
|
|
175
|
-
const propsEntries = comp.props
|
|
176
|
-
.filter(p => p.name !== 'key')
|
|
177
|
-
.map(p => {
|
|
178
|
-
if (isEventHandlerName(p.name)) {
|
|
179
|
-
return `${quotePropName(p.name)}: ${wrap(attrValueToString(p.value) ?? 'undefined')}`
|
|
180
|
-
}
|
|
181
|
-
switch (p.value.kind) {
|
|
182
|
-
case 'literal':
|
|
183
|
-
return `get ${quotePropName(p.name)}() { return ${JSON.stringify(p.value.value)} }`
|
|
184
|
-
case 'boolean-shorthand':
|
|
185
|
-
case 'boolean-attr':
|
|
186
|
-
return `get ${quotePropName(p.name)}() { return true }`
|
|
187
|
-
case 'jsx-children':
|
|
188
|
-
case 'expression':
|
|
189
|
-
case 'template':
|
|
190
|
-
case 'spread': {
|
|
191
|
-
const expr = attrValueToString(p.value) ?? 'undefined'
|
|
192
|
-
return `get ${quotePropName(p.name)}() { return ${wrap(expr)} }`
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
|
|
197
181
|
// Children are needed for CSR createComponent; SSR initChild ignores them
|
|
198
182
|
// (text already lives in the rendered HTML).
|
|
199
183
|
const childrenExpr = comp.children?.length ? irChildrenToJsExpr(comp.children) : null
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const propsExpr =
|
|
184
|
+
const trailing = childrenExpr ? [`get children() { return ${wrap(childrenExpr)} }`] : []
|
|
185
|
+
// A props-object spread merges in source order through the shared door
|
|
186
|
+
// (#3713) instead of becoming a getter named `...`.
|
|
187
|
+
const propsExpr = childPropsObjectExpr(comp.props, (p): ChildPropValue | null => {
|
|
188
|
+
if (p.name === 'key') return null
|
|
189
|
+
if (isEventHandlerName(p.name)) {
|
|
190
|
+
return { expr: wrap(attrValueToString(p.value) ?? 'undefined'), getter: false }
|
|
191
|
+
}
|
|
192
|
+
switch (p.value.kind) {
|
|
193
|
+
case 'literal':
|
|
194
|
+
return { expr: JSON.stringify(p.value.value), getter: true }
|
|
195
|
+
case 'boolean-shorthand':
|
|
196
|
+
case 'boolean-attr':
|
|
197
|
+
return { expr: 'true', getter: true }
|
|
198
|
+
case 'jsx-children':
|
|
199
|
+
case 'expression':
|
|
200
|
+
case 'template':
|
|
201
|
+
case 'spread':
|
|
202
|
+
return { expr: wrap(attrValueToString(p.value) ?? 'undefined'), getter: true }
|
|
203
|
+
}
|
|
204
|
+
}, { trailing })
|
|
204
205
|
|
|
205
206
|
inits.push({
|
|
206
207
|
name: comp.name,
|
|
@@ -342,6 +343,7 @@ export function buildBranchInnerLoopsPlan(
|
|
|
342
343
|
slotId: text.slotId,
|
|
343
344
|
wrappedExpression: wrapBoth(text.expression),
|
|
344
345
|
insideConditional: !!text.insideConditional,
|
|
346
|
+
...(text.markup && { markup: true as const }),
|
|
345
347
|
}))
|
|
346
348
|
|
|
347
349
|
plan.push({
|
|
@@ -98,6 +98,7 @@ export function buildReactiveEffectsPlan(
|
|
|
98
98
|
const outerTexts: ReactiveTextEffect[] = texts.map(text => ({
|
|
99
99
|
slotId: text.slotId,
|
|
100
100
|
wrappedExpression: wrap(text.expression),
|
|
101
|
+
...(text.markup && { markup: true as const }),
|
|
101
102
|
}))
|
|
102
103
|
|
|
103
104
|
// 3. Per-conditional plans. Each arm's own reactive attrs / texts come
|
|
@@ -16,13 +16,12 @@
|
|
|
16
16
|
* reactivity in the row. See `build-inner-loop.ts`'s module docstring.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import type { LoopChildEvent } from '../../types.ts'
|
|
20
19
|
import type {
|
|
21
20
|
AttrMeta,
|
|
22
21
|
IRLoopChildComponent,
|
|
23
22
|
LoopParamBinding,
|
|
24
23
|
} from '../../../types.ts'
|
|
25
|
-
import type { LoopChildRefBinding } from './loop.ts'
|
|
24
|
+
import type { LoopChildRefBinding, LoopRowEventBinding } from './loop.ts'
|
|
26
25
|
import type { LoopChildConditionalPlan } from './loop-child-arm.ts'
|
|
27
26
|
|
|
28
27
|
/**
|
|
@@ -40,6 +39,8 @@ export type PreludeStatements = readonly string[]
|
|
|
40
39
|
/** A reactive text effect inside a reactive inner loop's renderItem body. */
|
|
41
40
|
export interface InnerLoopText {
|
|
42
41
|
slotId: string
|
|
42
|
+
/** Claimed and written as markup (`RowTextSlot`). */
|
|
43
|
+
markup?: true
|
|
43
44
|
/** Already wrapped via inner+outer loop param accessor (`wrapBoth`). */
|
|
44
45
|
wrappedExpression: string
|
|
45
46
|
/**
|
|
@@ -142,8 +143,8 @@ export interface InnerLoopReactiveEmit {
|
|
|
142
143
|
wrappedKey: string | null
|
|
143
144
|
/** Inner-wrapped components for emitComponentAndEventSetup. */
|
|
144
145
|
components: readonly IRLoopChildComponent[]
|
|
145
|
-
/**
|
|
146
|
-
events: readonly
|
|
146
|
+
/** Events resolved against the inner and every enclosing row, attached directly to each inner row. */
|
|
147
|
+
events: readonly LoopRowEventBinding[]
|
|
147
148
|
/** Pre-wrapped reactive text effects for the inner-item body. */
|
|
148
149
|
reactiveTexts: readonly InnerLoopText[]
|
|
149
150
|
/** Pre-wrapped reactive attribute effects for the inner-item body. */
|
|
@@ -76,6 +76,8 @@ export type BranchChildComponentInitsPlan = readonly BranchChildComponentInit[]
|
|
|
76
76
|
/** A reactive text effect inside a branch inner loop's renderItem body. */
|
|
77
77
|
export interface BranchInnerLoopText {
|
|
78
78
|
slotId: string
|
|
79
|
+
/** Claimed and written as markup (`RowTextSlot`). */
|
|
80
|
+
markup?: true
|
|
79
81
|
/** Already wrapped via inner+outer loop param accessor (`wrapBoth`). */
|
|
80
82
|
wrappedExpression: string
|
|
81
83
|
/**
|
|
@@ -130,6 +130,8 @@ export interface LoopRowEventBinding {
|
|
|
130
130
|
eventName: string
|
|
131
131
|
/** Handler expression, as the row's binding of the item reads it. */
|
|
132
132
|
handler: JsSourceText
|
|
133
|
+
/** See `LoopChildEvent.receiverSlotIds` (#3695). */
|
|
134
|
+
receiverSlotIds?: readonly string[]
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
/**
|
|
@@ -240,6 +242,14 @@ interface ComponentLoopVariant extends DynamicLoopCommon {
|
|
|
240
242
|
* the SSR/CSR split shape (the simple shape has no row handle).
|
|
241
243
|
*/
|
|
242
244
|
rowEvents: readonly LoopRowEventBinding[]
|
|
245
|
+
/**
|
|
246
|
+
* Inner loops of the ROOT component's forwarded `children` that carry an
|
|
247
|
+
* event handler (#3694), planned once per row element: `hydrated` over
|
|
248
|
+
* `__existing`, `created` over `__csrEl`. Each row runs them after its own
|
|
249
|
+
* `rowEvents`, so the handlers reach the inner rows. Empty when no inner
|
|
250
|
+
* loop carries an event; non-empty forces the SSR/CSR split shape.
|
|
251
|
+
*/
|
|
252
|
+
innerLoops: { hydrated: InnerLoopsPlan; created: InnerLoopsPlan }
|
|
243
253
|
/**
|
|
244
254
|
* Reactive-effects plan for the loop ROOT component's own reactive attrs /
|
|
245
255
|
* texts / conditionals — i.e. bindings on elements forwarded as the root
|
|
@@ -254,6 +264,8 @@ interface ComponentLoopVariant extends DynamicLoopCommon {
|
|
|
254
264
|
* `mapArray`. Undefined off → byte-identical (SR8).
|
|
255
265
|
*/
|
|
256
266
|
profileLoopId?: string
|
|
267
|
+
/** Owning component name in profile mode, threaded to `stringifyInnerLoops`. */
|
|
268
|
+
profileComponentName?: string
|
|
257
269
|
}
|
|
258
270
|
|
|
259
271
|
/**
|
|
@@ -37,6 +37,8 @@ export interface ReactiveAttrSlot {
|
|
|
37
37
|
/** A reactive text effect (one createEffect updating textContent). */
|
|
38
38
|
export interface ReactiveTextEffect {
|
|
39
39
|
slotId: string
|
|
40
|
+
/** Claimed and written as markup (`RowTextSlot`). */
|
|
41
|
+
markup?: true
|
|
40
42
|
/** Already wrapped via wrapLoopParamAsAccessor at build time. */
|
|
41
43
|
wrappedExpression: string
|
|
42
44
|
}
|