@barefootjs/jsx 0.40.1 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/boolean-result.d.ts +32 -10
- package/dist/adapters/boolean-result.d.ts.map +1 -1
- package/dist/adapters/brace-delimiter-text.d.ts +18 -0
- package/dist/adapters/brace-delimiter-text.d.ts.map +1 -0
- package/dist/adapters/callback-method.d.ts +45 -5
- package/dist/adapters/callback-method.d.ts.map +1 -1
- package/dist/adapters/component-props.d.ts +3 -4
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/computed-const.d.ts +11 -1
- package/dist/adapters/computed-const.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +24 -12
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
- package/dist/adapters/loop-bound-names.d.ts +9 -1
- package/dist/adapters/loop-bound-names.d.ts.map +1 -1
- package/dist/adapters/loop-row-type.d.ts +59 -0
- package/dist/adapters/loop-row-type.d.ts.map +1 -0
- package/dist/adapters/nil-reading.d.ts +63 -0
- package/dist/adapters/nil-reading.d.ts.map +1 -0
- package/dist/adapters/non-primitive-equality.d.ts +33 -0
- package/dist/adapters/non-primitive-equality.d.ts.map +1 -0
- package/dist/adapters/number-value.d.ts +5 -3
- package/dist/adapters/number-value.d.ts.map +1 -1
- package/dist/adapters/operand-typing.d.ts +126 -0
- package/dist/adapters/operand-typing.d.ts.map +1 -0
- package/dist/adapters/parsed-expr-emitter.d.ts +80 -12
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/primitive-plan.d.ts +320 -0
- package/dist/adapters/primitive-plan.d.ts.map +1 -0
- package/dist/adapters/prop-classes.d.ts +5 -0
- package/dist/adapters/prop-classes.d.ts.map +1 -1
- package/dist/analyzer-context.d.ts +4 -0
- package/dist/analyzer-context.d.ts.map +1 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/augment-inherited-props.d.ts +63 -8
- package/dist/augment-inherited-props.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/event-handler-name.d.ts +12 -0
- package/dist/event-handler-name.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +8 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/index.d.ts +20 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4903 -2311
- package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
- package/dist/ir-to-client-js/child-props-object.d.ts +106 -0
- package/dist/ir-to-client-js/child-props-object.d.ts.map +1 -0
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts +4 -2
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +2 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/index.d.ts +2 -6
- package/dist/ir-to-client-js/index.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -3
- package/dist/ir-to-client-js/plan/build-declaration-emit.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/build-static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +30 -18
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +3 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts +3 -2
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts +1 -0
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +51 -34
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/prop-rewrite.d.ts +7 -0
- package/dist/prop-rewrite.d.ts.map +1 -1
- package/dist/props-binding.d.ts +58 -13
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/props-object-whole-read.d.ts +15 -0
- package/dist/props-object-whole-read.d.ts.map +1 -0
- package/dist/rich-type-refusal.d.ts.map +1 -1
- package/dist/scope/binding-scope.d.ts +85 -10
- package/dist/scope/binding-scope.d.ts.map +1 -1
- package/dist/scope/lexical-scope-walk.d.ts +3 -2
- package/dist/scope/lexical-scope-walk.d.ts.map +1 -1
- package/dist/scope/root-prop-alias.d.ts +10 -7
- package/dist/scope/root-prop-alias.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +39 -3
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/strip-types.d.ts +13 -0
- package/dist/strip-types.d.ts.map +1 -1
- package/dist/template-position-walk.d.ts +21 -3
- package/dist/template-position-walk.d.ts.map +1 -1
- package/dist/types.d.ts +90 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +9 -9
- package/src/__tests__/binding-scope.test.ts +89 -1
- package/src/__tests__/body-destructure-props-object-alias.test.ts +123 -0
- package/src/__tests__/body-destructured-prop-default-arrow.test.ts +2 -2
- package/src/__tests__/body-destructured-props-live.test.ts +5 -5
- package/src/__tests__/boolean-result.test.ts +22 -5
- package/src/__tests__/brace-delimiter-text.test.ts +26 -0
- package/src/__tests__/callback-method.test.ts +62 -2
- package/src/__tests__/child-components-in-map.test.ts +1 -1
- package/src/__tests__/client-js-generation.test.ts +3 -3
- package/src/__tests__/computed-const.test.ts +103 -0
- package/src/__tests__/destructure-default-reads-earlier-param.test.ts +7 -7
- package/src/__tests__/destructured-props-live.test.ts +1 -1
- package/src/__tests__/emit-to-string-call.test.ts +2 -1
- package/src/__tests__/hydration-payload-analysis.test.ts +166 -0
- package/src/__tests__/issue-2724-prop-alias-loop-not-static.test.ts +7 -7
- package/src/__tests__/issue-2754-rest-spread-needs-slot.test.ts +5 -2
- package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +1 -1
- package/src/__tests__/issue-2835-props-type-member-name-collision.test.ts +4 -4
- package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +1 -1
- package/src/__tests__/issue-3688-props-spread-child-csr.test.ts +2 -1
- package/src/__tests__/issue-3713-props-spread-loop-row.test.ts +65 -0
- package/src/__tests__/issue-3861-object-spread-child.test.ts +102 -0
- package/src/__tests__/lookup-literal-const.test.ts +9 -3
- package/src/__tests__/loop-index-reactivity.test.ts +2 -2
- package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +1 -1
- package/src/__tests__/loop-plan.test.ts +1 -1
- package/src/__tests__/loop-row-const-initializer-shadow.test.ts +146 -0
- package/src/__tests__/loop-row-type.test.ts +64 -0
- package/src/__tests__/lowering-value-position.test.ts +4 -0
- package/src/__tests__/memo-body-expr.test.ts +2 -2
- package/src/__tests__/module-const-destructure-default.test.ts +156 -0
- package/src/__tests__/nested-loop-index-param.test.ts +1 -1
- package/src/__tests__/nested-loop-reactive-attrs.test.ts +2 -2
- package/src/__tests__/nested-row-shadowing.test.ts +2 -2
- package/src/__tests__/nil-reading.test.ts +78 -0
- package/src/__tests__/nullable-signal-attr.test.ts +109 -48
- package/src/__tests__/primitive-plan.test.ts +494 -0
- package/src/__tests__/profile-loop-binding-ids.test.ts +2 -2
- package/src/__tests__/profile-nested-binding-ids.test.ts +2 -2
- package/src/__tests__/prop-default-undefined-only.test.ts +115 -0
- package/src/__tests__/prop-references.test.ts +2 -2
- package/src/__tests__/props-destructuring.test.ts +17 -0
- package/src/__tests__/props-object-whole-read.test.ts +40 -0
- package/src/__tests__/prune-unused-prop-extractions.test.ts +3 -3
- package/src/__tests__/reactive-attrs-in-map.test.ts +1 -1
- package/src/__tests__/reactive-factory-inlining.test.ts +4 -1
- package/src/__tests__/renamed-body-destructure-template.test.ts +7 -7
- package/src/__tests__/rest-binding-gaps.test.ts +192 -0
- package/src/__tests__/rewrite-destructured-props.test.ts +1 -1
- package/src/__tests__/root-prop-alias.test.ts +53 -8
- package/src/__tests__/ssr-defaults.test.ts +113 -25
- package/src/__tests__/static-loop-csr-materialize.test.ts +2 -2
- package/src/__tests__/static-record-literal-array.test.ts +171 -0
- package/src/__tests__/string-concat-identifier.test.ts +40 -1
- package/src/__tests__/written-binding-substitution.test.ts +8 -8
- package/src/adapters/boolean-result.ts +72 -66
- package/src/adapters/brace-delimiter-text.ts +25 -0
- package/src/adapters/callback-method.ts +159 -27
- package/src/adapters/component-props.ts +3 -4
- package/src/adapters/computed-const.ts +238 -4
- package/src/adapters/dsl-template-adapter.ts +62 -26
- package/src/adapters/loop-bound-names.ts +9 -1
- package/src/adapters/loop-plan.ts +1 -1
- package/src/adapters/loop-row-type.ts +149 -0
- package/src/adapters/nil-reading.ts +295 -0
- package/src/adapters/non-primitive-equality.ts +92 -0
- package/src/adapters/number-value.ts +17 -4
- package/src/adapters/operand-typing.ts +522 -0
- package/src/adapters/parsed-expr-emitter.ts +183 -19
- package/src/adapters/primitive-plan.ts +765 -0
- package/src/adapters/prop-classes.ts +16 -3
- package/src/analyzer-context.ts +6 -0
- package/src/analyzer.ts +532 -26
- package/src/augment-inherited-props.ts +108 -10
- package/src/compiler.ts +17 -0
- package/src/event-handler-name.ts +15 -0
- package/src/expression-parser.ts +70 -1
- package/src/index.ts +35 -16
- package/src/ir-to-client-js/build-references.ts +69 -0
- package/src/ir-to-client-js/child-props-object.ts +240 -0
- package/src/ir-to-client-js/collect-elements.ts +31 -63
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +8 -1
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +31 -28
- package/src/ir-to-client-js/control-flow/shared.ts +20 -22
- package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +5 -3
- package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +2 -2
- package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +1 -1
- package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +2 -2
- package/src/ir-to-client-js/control-flow/stringify/loop.ts +1 -1
- package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +3 -3
- package/src/ir-to-client-js/html-template.ts +43 -17
- package/src/ir-to-client-js/imports.ts +2 -2
- package/src/ir-to-client-js/index.ts +53 -11
- package/src/ir-to-client-js/phases/props-extraction.ts +11 -7
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +40 -7
- package/src/ir-to-client-js/plan/build-static-array-child-init.ts +31 -14
- package/src/ir-to-client-js/plan/static-array-child-init.ts +27 -18
- package/src/ir-to-client-js/prop-handling.ts +22 -3
- package/src/ir-to-client-js/prune-unused-prop-extractions.ts +58 -5
- package/src/ir-to-client-js/rewrite-destructured-props.ts +31 -1
- package/src/ir-to-client-js/stringify/static-array-child-init.ts +26 -10
- package/src/jsx-to-ir.ts +459 -37
- package/src/nullable-signal-attr.ts +200 -110
- package/src/prop-rewrite.ts +30 -6
- package/src/props-binding.ts +84 -19
- package/src/props-object-whole-read.ts +87 -0
- package/src/rich-type-refusal.ts +2 -1
- package/src/scope/binding-scope.ts +182 -18
- package/src/scope/lexical-scope-walk.ts +4 -3
- package/src/scope/root-prop-alias.ts +15 -8
- package/src/ssr-defaults.ts +100 -11
- package/src/strip-types.ts +31 -3
- package/src/template-position-walk.ts +57 -28
- package/src/types.ts +87 -0
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts +0 -41
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +0 -1
- package/src/adapters/ambiguous-nil-arithmetic.ts +0 -94
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spelling of a child component's props object (`initChild` /
|
|
3
|
+
* `createComponent` / `upsertChild` argument).
|
|
4
|
+
*
|
|
5
|
+
* Every call-site builder (top-level child, loop row, composite loop row,
|
|
6
|
+
* conditional branch, static-array row) decides each explicit prop's own
|
|
7
|
+
* value spelling, then hands the list here. This module is the one place
|
|
8
|
+
* that decides how a spread of the component's own props object
|
|
9
|
+
* (`SpreadAttr.propsObject`, set in Phase 1) merges with the explicit props
|
|
10
|
+
* in source order (#3688, #3713):
|
|
11
|
+
*
|
|
12
|
+
* - a spread prop never becomes an entry of its own;
|
|
13
|
+
* - an explicit prop written before the last props-object spread is only a
|
|
14
|
+
* default: the caller's own value wins when the caller passed that key;
|
|
15
|
+
* - an explicit prop written after it wins as written;
|
|
16
|
+
* - every key the caller passed and the call did not name is forwarded
|
|
17
|
+
* through `forwardProps`, as getters, so it stays reactive.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { AttrValue } from '../types.ts'
|
|
21
|
+
import { codeSafeStringLiteral, PROPS_PARAM, quotePropName } from './utils.ts'
|
|
22
|
+
|
|
23
|
+
/** One explicit prop's value as a call-site builder spells it. */
|
|
24
|
+
export interface ChildPropValue {
|
|
25
|
+
expr: string
|
|
26
|
+
/** `get key() { return expr }` when true, `key: expr` otherwise. */
|
|
27
|
+
getter: boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface ChildPropLike {
|
|
31
|
+
name: string
|
|
32
|
+
value: AttrValue
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** True for the IR name of a spread prop (`...` / `...expr`). */
|
|
36
|
+
export function isSpreadPropName(name: string): boolean {
|
|
37
|
+
return name.startsWith('...')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Index of the last spread of the component's own props object in a child
|
|
42
|
+
* component call (`<Tag tone="first" {...props} />`), or -1. An explicit
|
|
43
|
+
* prop written before it is only a default: the spread overrides it when
|
|
44
|
+
* the caller passed that key, as in JS (#3688). Both the props object built
|
|
45
|
+
* here and the top-level reactive DOM mirrors read this one decision, so an
|
|
46
|
+
* overridden explicit expression can't overwrite the spread-selected value
|
|
47
|
+
* on update.
|
|
48
|
+
*/
|
|
49
|
+
export function lastPropsObjectSpreadIndex(props: readonly ChildPropLike[]): number {
|
|
50
|
+
let at = -1
|
|
51
|
+
props.forEach((p, index) => {
|
|
52
|
+
if (p.value.kind === 'spread' && p.value.propsObject === true) at = index
|
|
53
|
+
})
|
|
54
|
+
return at
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The value of an explicit prop a later props-object spread overrides (see
|
|
59
|
+
* `lastPropsObjectSpreadIndex`): the caller's own value when it passed the
|
|
60
|
+
* key, `expr` otherwise. `forwardProps` lets every override win, so the
|
|
61
|
+
* merge is spelled into the value itself.
|
|
62
|
+
*/
|
|
63
|
+
export function callerFirstPropExpr(name: string, expr: string): string {
|
|
64
|
+
const key = codeSafeStringLiteral(name)
|
|
65
|
+
return `(${key} in ${PROPS_PARAM} ? ${PROPS_PARAM}[${key}] : ${expr})`
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* True for a spread of an arbitrary object onto a child component
|
|
70
|
+
* (`<Chip {...row} />`, a loop row `{...r}`): not one of the caller's own
|
|
71
|
+
* prop bags (`SpreadAttr.callerBag`, decided in Phase 1). Its keys are
|
|
72
|
+
* merged in source order through `spreadChildProps` (#3861). A caller-bag
|
|
73
|
+
* spread is the props object (`propsObject`, merged by `forwardProps`) or a
|
|
74
|
+
* `{...rest}` bag, which the top-level path forwards whole.
|
|
75
|
+
*/
|
|
76
|
+
export function isObjectSpreadProp(prop: ChildPropLike): boolean {
|
|
77
|
+
return isSpreadPropName(prop.name) && prop.value.kind === 'spread' && prop.value.callerBag === undefined
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ChildPropsObjectOptions {
|
|
81
|
+
/** Entries appended after the explicit props (e.g. a row's `children` getter). */
|
|
82
|
+
trailing?: readonly string[]
|
|
83
|
+
/**
|
|
84
|
+
* Forward the caller's props even without a props-object spread — the
|
|
85
|
+
* top-level path's `{...rest}` forwarding, which predates the marker.
|
|
86
|
+
*/
|
|
87
|
+
forwardCaller?: boolean
|
|
88
|
+
/**
|
|
89
|
+
* The caller's `{...rest}` bag as a props object (the caller's props
|
|
90
|
+
* without the keys the component destructured), so a call that also
|
|
91
|
+
* spreads an object merges the bag in source order as one more part.
|
|
92
|
+
* Without it a rest bag spread is left to `forwardCaller`.
|
|
93
|
+
*/
|
|
94
|
+
restBag?: string
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A JS array literal of code-safe string literals (`codeSafeStringLiteral`),
|
|
99
|
+
* printed exactly as `JSON.stringify` prints an array of ordinary names.
|
|
100
|
+
*/
|
|
101
|
+
export function codeSafeStringArray(values: readonly string[]): string {
|
|
102
|
+
return `[${values.map(codeSafeStringLiteral).join(',')}]`
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** An object literal of `entries`, `{}` when there are none. */
|
|
106
|
+
function objectLiteral(entries: readonly string[]): string {
|
|
107
|
+
return entries.length > 0 ? `{ ${entries.join(', ')} }` : '{}'
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Index of the last object spread (`isObjectSpreadProp`) in a child component call, or -1. */
|
|
111
|
+
export function lastObjectSpreadIndex(props: readonly ChildPropLike[]): number {
|
|
112
|
+
let at = -1
|
|
113
|
+
props.forEach((p, index) => {
|
|
114
|
+
if (isObjectSpreadProp(p)) at = index
|
|
115
|
+
})
|
|
116
|
+
return at
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The value of the explicit prop at `index` for a reactive DOM mirror,
|
|
121
|
+
* merged with every spread written after it, as the props object merges
|
|
122
|
+
* them: a later object spread (`spreadOf` spells its value) wins when its
|
|
123
|
+
* object has the key, and a later props-object spread wins when the caller
|
|
124
|
+
* passed it (`callerFirstPropExpr`). `expr` as written when no spread
|
|
125
|
+
* follows.
|
|
126
|
+
*/
|
|
127
|
+
export function mergedExplicitPropExpr<P extends ChildPropLike>(
|
|
128
|
+
props: readonly P[],
|
|
129
|
+
index: number,
|
|
130
|
+
expr: string,
|
|
131
|
+
spreadOf: (prop: P) => string,
|
|
132
|
+
): string {
|
|
133
|
+
const name = props[index]!.name
|
|
134
|
+
const key = codeSafeStringLiteral(name)
|
|
135
|
+
let merged = expr
|
|
136
|
+
// The last spread kind applied: two props-object spreads in a row merge once.
|
|
137
|
+
let last: 'props' | 'object' | null = null
|
|
138
|
+
for (let at = index + 1; at < props.length; at++) {
|
|
139
|
+
const prop = props[at]!
|
|
140
|
+
if (prop.value.kind === 'spread' && prop.value.propsObject === true) {
|
|
141
|
+
if (last !== 'props') merged = callerFirstPropExpr(name, merged)
|
|
142
|
+
last = 'props'
|
|
143
|
+
} else if (isObjectSpreadProp(prop)) {
|
|
144
|
+
merged = `((__s) => __s != null && ${key} in Object(__s) ? Object(__s)[${key}] : ${merged})(${spreadOf(prop)})`
|
|
145
|
+
last = 'object'
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return merged
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Build a child component's props object expression. `valueOf` spells one
|
|
153
|
+
* explicit prop's value, or returns null to leave it out (e.g. `key`). It
|
|
154
|
+
* also spells an object spread's value (`isObjectSpreadProp`).
|
|
155
|
+
*
|
|
156
|
+
* Without an object spread, the explicit props form one object literal,
|
|
157
|
+
* wrapped in `forwardProps` for a props-object spread (or the caller
|
|
158
|
+
* forwarding). With one, every part merges in source order through
|
|
159
|
+
* `spreadChildProps` (#3861): each run of explicit props is an object
|
|
160
|
+
* literal, an object spread a thunk of its value, and a props-object spread
|
|
161
|
+
* the thunk `() => _p`, so a later part wins as in JS. A `{...rest}` bag is
|
|
162
|
+
* a part too when the caller spells it (`restBag`); otherwise it is
|
|
163
|
+
* forwarded off `_p` after the merge.
|
|
164
|
+
*/
|
|
165
|
+
export function childPropsObjectExpr<P extends ChildPropLike>(
|
|
166
|
+
props: readonly P[],
|
|
167
|
+
valueOf: (prop: P) => ChildPropValue | null,
|
|
168
|
+
options: ChildPropsObjectOptions = {},
|
|
169
|
+
): string {
|
|
170
|
+
if (lastObjectSpreadIndex(props) >= 0) return spreadPartsExpr(props, valueOf, options)
|
|
171
|
+
const spreadAt = lastPropsObjectSpreadIndex(props)
|
|
172
|
+
const entries: string[] = []
|
|
173
|
+
const explicitNames: string[] = []
|
|
174
|
+
props.forEach((prop, index) => {
|
|
175
|
+
if (isSpreadPropName(prop.name)) return
|
|
176
|
+
const value = valueOf(prop)
|
|
177
|
+
if (!value) return
|
|
178
|
+
explicitNames.push(prop.name)
|
|
179
|
+
const key = quotePropName(prop.name)
|
|
180
|
+
if (index < spreadAt) {
|
|
181
|
+
entries.push(`get ${key}() { return ${callerFirstPropExpr(prop.name, value.expr)} }`)
|
|
182
|
+
} else {
|
|
183
|
+
entries.push(explicitEntry(key, value))
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
entries.push(...(options.trailing ?? []))
|
|
187
|
+
const object = objectLiteral(entries)
|
|
188
|
+
if (spreadAt < 0 && !options.forwardCaller) return object
|
|
189
|
+
return `forwardProps(${PROPS_PARAM}, ${object}, ${codeSafeStringArray(explicitNames)})`
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** One explicit prop's object-literal entry: a getter or a data property. */
|
|
193
|
+
function explicitEntry(key: string, value: ChildPropValue): string {
|
|
194
|
+
return value.getter ? `get ${key}() { return ${value.expr} }` : `${key}: ${value.expr}`
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** {@link childPropsObjectExpr} for a call with an object spread: `spreadChildProps(...parts)`. */
|
|
198
|
+
function spreadPartsExpr<P extends ChildPropLike>(
|
|
199
|
+
props: readonly P[],
|
|
200
|
+
valueOf: (prop: P) => ChildPropValue | null,
|
|
201
|
+
options: ChildPropsObjectOptions,
|
|
202
|
+
): string {
|
|
203
|
+
const parts: string[] = []
|
|
204
|
+
let entries: string[] = []
|
|
205
|
+
const explicitNames: string[] = []
|
|
206
|
+
let mergesCaller = false
|
|
207
|
+
const flush = (): void => {
|
|
208
|
+
if (entries.length > 0) parts.push(objectLiteral(entries))
|
|
209
|
+
entries = []
|
|
210
|
+
}
|
|
211
|
+
for (const prop of props) {
|
|
212
|
+
if (prop.value.kind === 'spread' && prop.value.propsObject === true) {
|
|
213
|
+
flush()
|
|
214
|
+
parts.push(`() => ${PROPS_PARAM}`)
|
|
215
|
+
mergesCaller = true
|
|
216
|
+
continue
|
|
217
|
+
}
|
|
218
|
+
if (prop.value.kind === 'spread' && prop.value.callerBag === 'rest' && options.restBag !== undefined) {
|
|
219
|
+
flush()
|
|
220
|
+
parts.push(options.restBag)
|
|
221
|
+
mergesCaller = true
|
|
222
|
+
continue
|
|
223
|
+
}
|
|
224
|
+
if (isSpreadPropName(prop.name) && !isObjectSpreadProp(prop)) continue
|
|
225
|
+
const value = valueOf(prop)
|
|
226
|
+
if (!value) continue
|
|
227
|
+
if (isObjectSpreadProp(prop)) {
|
|
228
|
+
flush()
|
|
229
|
+
parts.push(`() => (${value.expr})`)
|
|
230
|
+
continue
|
|
231
|
+
}
|
|
232
|
+
explicitNames.push(prop.name)
|
|
233
|
+
entries.push(explicitEntry(quotePropName(prop.name), value))
|
|
234
|
+
}
|
|
235
|
+
entries.push(...(options.trailing ?? []))
|
|
236
|
+
flush()
|
|
237
|
+
const merged = `spreadChildProps(${parts.join(', ')})`
|
|
238
|
+
if (!options.forwardCaller || mergesCaller) return merged
|
|
239
|
+
return `forwardProps(${PROPS_PARAM}, ${merged}, ${codeSafeStringArray(explicitNames)})`
|
|
240
|
+
}
|
|
@@ -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 { childPropsObjectExpr, codeSafeStringArray, isSpreadPropName, mergedExplicitPropExpr } 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'
|
|
@@ -568,75 +569,47 @@ function componentInitPropValue(prop: IRProp, ctx: ClientJsContext): { expr: str
|
|
|
568
569
|
}
|
|
569
570
|
|
|
570
571
|
/**
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
* explicit expression can't overwrite the spread-selected value on update.
|
|
572
|
+
* Which caller bag an element's spread attribute forwards, for
|
|
573
|
+
* `applyRestAttrs`: its text resolved through any `const x__alias = x` hop
|
|
574
|
+
* onto the rest/props binding (#2723, `resolveRestSpreadOrigin`). Null
|
|
575
|
+
* when Phase 1 did not resolve the spread to the bag
|
|
576
|
+
* (`SpreadAttr.callerBag`): a loop row or callback parameter spelled like
|
|
577
|
+
* the rest binding is that binding (#3851).
|
|
578
578
|
*/
|
|
579
|
-
function
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
})
|
|
584
|
-
return at
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
/**
|
|
588
|
-
* The value of an explicit prop a later props-object spread overrides (see
|
|
589
|
-
* `lastPropsObjectSpreadIndex`): the caller's own value when it passed the
|
|
590
|
-
* key, `expr` otherwise. `forwardProps` lets every override win, so the
|
|
591
|
-
* merge is spelled into the value itself.
|
|
592
|
-
*/
|
|
593
|
-
function callerFirstPropExpr(name: string, expr: string): string {
|
|
594
|
-
const key = JSON.stringify(name)
|
|
595
|
-
return `(${key} in ${PROPS_PARAM} ? ${PROPS_PARAM}[${key}] : ${expr})`
|
|
579
|
+
function callerBagSpreadOrigin(value: AttrValue, ctx: ClientJsContext): 'rest' | 'props' | null {
|
|
580
|
+
if (value.kind !== 'spread' || value.callerBag === undefined) return null
|
|
581
|
+
const spreadVal = attrValueToString(value) ?? ''
|
|
582
|
+
return spreadVal ? resolveRestSpreadOrigin(ctx, spreadVal) : null
|
|
596
583
|
}
|
|
597
584
|
|
|
598
585
|
/**
|
|
599
|
-
* The
|
|
600
|
-
*
|
|
601
|
-
*
|
|
586
|
+
* The live `_p.<key>` read a closed-rest-expanded attribute binds to
|
|
587
|
+
* (`IRAttribute.restExpandedKey`, #3057), with the value an earlier
|
|
588
|
+
* attribute gave the key when the caller omits it, as SSR rendered it
|
|
589
|
+
* (`IRAttribute.restFallback`, #3851).
|
|
602
590
|
*/
|
|
603
|
-
function
|
|
604
|
-
|
|
591
|
+
function restKeyLiveRead(attr: IRElement['attrs'][number]): string {
|
|
592
|
+
const read = `${PROPS_PARAM}.${attr.name}`
|
|
593
|
+
return attr.restFallback === undefined ? read : `${read} ?? (${attr.restFallback})`
|
|
605
594
|
}
|
|
606
595
|
|
|
607
596
|
/** Build propsExpr for a child component from its IR props. */
|
|
608
597
|
function buildComponentPropsExpr(props: IRProp[], ctx: ClientJsContext): string {
|
|
609
598
|
const knownSpreadProp = props.find(p => {
|
|
610
|
-
if (
|
|
599
|
+
if (!isSpreadPropName(p.name)) return false
|
|
611
600
|
if (p.value.kind !== 'spread' && p.value.kind !== 'expression') return false
|
|
612
601
|
const expr = p.value.kind === 'spread' ? p.value.expr : p.value.expr
|
|
613
602
|
// #2723: resolve through any `const x__alias = x` hop onto the
|
|
614
603
|
// rest/props binding — see `resolveRestSpreadOrigin`'s docstring.
|
|
615
604
|
return resolveRestSpreadOrigin(ctx, expr) !== null
|
|
616
605
|
})
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
if (prop.name === '...' || prop.name.startsWith('...')) return
|
|
624
|
-
explicitPropNames.push(prop.name)
|
|
625
|
-
const key = quotePropName(prop.name)
|
|
626
|
-
const { expr, getter } = componentInitPropValue(prop, ctx)
|
|
627
|
-
if (index < spreadAt) {
|
|
628
|
-
propsForInit.push(`get ${key}() { return ${callerFirstPropExpr(prop.name, expr)} }`)
|
|
629
|
-
} else {
|
|
630
|
-
propsForInit.push(getter ? `get ${key}() { return ${expr} }` : `${key}: ${expr}`)
|
|
631
|
-
}
|
|
606
|
+
// The rest bag without the keys the component destructured, keyed the
|
|
607
|
+
// way they arrive on `_p` (the `applyRestAttrs` exclusion set).
|
|
608
|
+
const consumedKeys = ctx.propsParams.map(p => p.sourceName ?? p.name)
|
|
609
|
+
return childPropsObjectExpr(props, prop => componentInitPropValue(prop, ctx), {
|
|
610
|
+
forwardCaller: knownSpreadProp !== undefined,
|
|
611
|
+
restBag: `forwardProps(${PROPS_PARAM}, {}, ${codeSafeStringArray(consumedKeys)})`,
|
|
632
612
|
})
|
|
633
|
-
|
|
634
|
-
if (spreadSource) {
|
|
635
|
-
const overrides = propsForInit.length > 0 ? `{ ${propsForInit.join(', ')} }` : '{}'
|
|
636
|
-
const excludeKeys = JSON.stringify(explicitPropNames)
|
|
637
|
-
return `forwardProps(${spreadSource}, ${overrides}, ${excludeKeys})`
|
|
638
|
-
}
|
|
639
|
-
return propsForInit.length > 0 ? `{ ${propsForInit.join(', ')} }` : '{}'
|
|
640
613
|
}
|
|
641
614
|
|
|
642
615
|
/**
|
|
@@ -645,7 +618,6 @@ function buildComponentPropsExpr(props: IRProp[], ctx: ClientJsContext): string
|
|
|
645
618
|
* side-effect helper so `buildComponentPropsExpr` stays a pure function.
|
|
646
619
|
*/
|
|
647
620
|
function collectReactiveChildProps(node: IRComponent, ctx: ClientJsContext): void {
|
|
648
|
-
const spreadAt = lastPropsObjectSpreadIndex(node.props)
|
|
649
621
|
for (const [index, prop] of node.props.entries()) {
|
|
650
622
|
if (prop.name === '...' || prop.name.startsWith('...')) continue
|
|
651
623
|
if (prop.value.kind === 'jsx-children') continue
|
|
@@ -686,7 +658,7 @@ function collectReactiveChildProps(node: IRComponent, ctx: ClientJsContext): voi
|
|
|
686
658
|
slotId: node.slotId,
|
|
687
659
|
propName: prop.name,
|
|
688
660
|
attrName,
|
|
689
|
-
expression:
|
|
661
|
+
expression: mergedExplicitPropExpr(node.props, index, expandedValue, spread => expandDynamicPropValue(attrValueToString(spread.value)!, ctx)),
|
|
690
662
|
...pickAttrMetaFromIR(prop),
|
|
691
663
|
})
|
|
692
664
|
}
|
|
@@ -1061,7 +1033,6 @@ export function collectElements(
|
|
|
1061
1033
|
component: ({ node: c, descend, descendJsxChildren }) => {
|
|
1062
1034
|
if (c.slotId) {
|
|
1063
1035
|
// Reactive props need effects to update the element when values change.
|
|
1064
|
-
const spreadAt = lastPropsObjectSpreadIndex(c.props)
|
|
1065
1036
|
for (const [index, prop] of c.props.entries()) {
|
|
1066
1037
|
if (prop.value.kind === 'jsx-children') continue
|
|
1067
1038
|
if (isEventHandlerName(prop.name)) continue
|
|
@@ -1078,7 +1049,7 @@ export function collectElements(
|
|
|
1078
1049
|
ctx.reactiveProps.push({
|
|
1079
1050
|
slotId: c.slotId,
|
|
1080
1051
|
propName: prop.name,
|
|
1081
|
-
expression:
|
|
1052
|
+
expression: mergedExplicitPropExpr(c.props, index, value, spread => expandDynamicPropValue(attrValueToString(spread.value)!, ctx)),
|
|
1082
1053
|
componentName: c.name,
|
|
1083
1054
|
})
|
|
1084
1055
|
}
|
|
@@ -1157,10 +1128,7 @@ function collectFromElement(element: IRElement, ctx: ClientJsContext, insideCond
|
|
|
1157
1128
|
// Other identifiers or complex expressions may not exist in the compiled init scope.
|
|
1158
1129
|
// Always use PROPS_PARAM as the source since the init function parameter is PROPS_PARAM.
|
|
1159
1130
|
if (attr.name === '...' && attr.value) {
|
|
1160
|
-
const
|
|
1161
|
-
// #2723: resolve through any `const x__alias = x` hop onto the
|
|
1162
|
-
// rest/props binding — see `resolveRestSpreadOrigin`'s docstring.
|
|
1163
|
-
const spreadOrigin = spreadVal ? resolveRestSpreadOrigin(ctx, spreadVal) : null
|
|
1131
|
+
const spreadOrigin = callerBagSpreadOrigin(attr.value, ctx)
|
|
1164
1132
|
if (spreadOrigin !== null) {
|
|
1165
1133
|
// `applyRestAttrs(_el, _p, exclude)` is handed the FULL props
|
|
1166
1134
|
// object (`PROPS_PARAM`), not a computed JS rest binding, and the
|
|
@@ -1249,7 +1217,7 @@ function collectFromElement(element: IRElement, ctx: ClientJsContext, insideCond
|
|
|
1249
1217
|
ctx.reactiveAttrs.push({
|
|
1250
1218
|
slotId: element.slotId,
|
|
1251
1219
|
attrName: attr.name,
|
|
1252
|
-
expression:
|
|
1220
|
+
expression: restKeyLiveRead(attr),
|
|
1253
1221
|
...pickAttrMetaFromIR(attr),
|
|
1254
1222
|
})
|
|
1255
1223
|
continue
|
|
@@ -69,7 +69,14 @@ function wrapAttrValueExpression(value: AttrValue, wrap: (s: string) => string):
|
|
|
69
69
|
return AttrValueOf.expression(wrap(flat ?? 'undefined'))
|
|
70
70
|
}
|
|
71
71
|
case 'spread':
|
|
72
|
-
|
|
72
|
+
// Keep the Phase-1 caller-bag markers: the props object merges this
|
|
73
|
+
// spread in source order (#3713), and any other spread of an object
|
|
74
|
+
// merges its own keys (#3861).
|
|
75
|
+
return {
|
|
76
|
+
...AttrValueOf.spread(wrap(value.expr), value.templateExpr ? wrap(value.templateExpr) : undefined),
|
|
77
|
+
...(value.propsObject && { propsObject: true as const }),
|
|
78
|
+
...(value.callerBag !== undefined && { callerBag: value.callerBag }),
|
|
79
|
+
}
|
|
73
80
|
}
|
|
74
81
|
}
|
|
75
82
|
import type { DepthLevel } from '../shared.ts'
|
|
@@ -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,20 @@ 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 caller-bag markers: the props object merges this
|
|
62
|
+
// spread in source order (#3713), and any other spread of an object
|
|
63
|
+
// merges its own keys (#3861).
|
|
64
|
+
return {
|
|
65
|
+
...AttrValueOf.spread(wrap(value.expr), value.templateExpr ? wrap(value.templateExpr) : undefined),
|
|
66
|
+
...(value.propsObject && { propsObject: true as const }),
|
|
67
|
+
...(value.callerBag !== undefined && { callerBag: value.callerBag }),
|
|
68
|
+
}
|
|
62
69
|
}
|
|
63
70
|
}
|
|
64
71
|
import { destructureLoopParam, loopKeyFn, buildCompSelector, nestedLoopIndexAlias } from '../shared.ts'
|
|
65
72
|
import { BF_HOST, BF_AT } from '@barefootjs/shared'
|
|
66
73
|
import { isEventHandlerName } from '../../../event-handler-name.ts'
|
|
74
|
+
import { childPropsObjectExpr, type ChildPropValue } from '../../child-props-object.ts'
|
|
67
75
|
import type {
|
|
68
76
|
BranchChildComponentInit,
|
|
69
77
|
BranchChildComponentInitsPlan,
|
|
@@ -172,35 +180,30 @@ export function buildBranchChildComponentInitsPlan(
|
|
|
172
180
|
for (const comp of components) {
|
|
173
181
|
const selector = buildCompSelector(comp)
|
|
174
182
|
|
|
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
183
|
// Children are needed for CSR createComponent; SSR initChild ignores them
|
|
198
184
|
// (text already lives in the rendered HTML).
|
|
199
185
|
const childrenExpr = comp.children?.length ? irChildrenToJsExpr(comp.children) : null
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const propsExpr =
|
|
186
|
+
const trailing = childrenExpr ? [`get children() { return ${wrap(childrenExpr)} }`] : []
|
|
187
|
+
// A props-object spread merges in source order through the shared door
|
|
188
|
+
// (#3713) instead of becoming a getter named `...`.
|
|
189
|
+
const propsExpr = childPropsObjectExpr(comp.props, (p): ChildPropValue | null => {
|
|
190
|
+
if (p.name === 'key') return null
|
|
191
|
+
if (isEventHandlerName(p.name)) {
|
|
192
|
+
return { expr: wrap(attrValueToString(p.value) ?? 'undefined'), getter: false }
|
|
193
|
+
}
|
|
194
|
+
switch (p.value.kind) {
|
|
195
|
+
case 'literal':
|
|
196
|
+
return { expr: JSON.stringify(p.value.value), getter: true }
|
|
197
|
+
case 'boolean-shorthand':
|
|
198
|
+
case 'boolean-attr':
|
|
199
|
+
return { expr: 'true', getter: true }
|
|
200
|
+
case 'jsx-children':
|
|
201
|
+
case 'expression':
|
|
202
|
+
case 'template':
|
|
203
|
+
case 'spread':
|
|
204
|
+
return { expr: wrap(attrValueToString(p.value) ?? 'undefined'), getter: true }
|
|
205
|
+
}
|
|
206
|
+
}, { trailing })
|
|
204
207
|
|
|
205
208
|
inits.push({
|
|
206
209
|
name: comp.name,
|
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
import type { LoopChildBindings, LoopChildEvent, LoopChildRef, TopLevelLoop, NestedLoop, CollectedLoop } from '../types.ts'
|
|
16
16
|
import type { IRLoopChildComponent, IRExpression, IRNode, LoopParamBinding } from '../../types.ts'
|
|
17
17
|
import { preambleAnalysisText } from '../../types.ts'
|
|
18
|
-
import {
|
|
18
|
+
import { wrapLoopParamAsAccessor, irChildrenFreeIds, attrValueToString } from '../utils.ts'
|
|
19
19
|
import { irChildrenToJsExpr, jsxChildrenPropGetterExpr } from '../html-template.ts'
|
|
20
20
|
import { spliceChildValue } from '../safe-html.ts'
|
|
21
|
+
import { childPropsObjectExpr, type ChildPropValue } from '../child-props-object.ts'
|
|
21
22
|
import { emitListenerBlock } from './stringify/event-listener.ts'
|
|
22
23
|
import { nameForRegistryRef } from '../component-scope.ts'
|
|
23
24
|
import { BF_SCOPE, BF_HOST, BF_AT } from '@barefootjs/shared'
|
|
@@ -284,43 +285,40 @@ export function buildComponentPropsExpr(
|
|
|
284
285
|
loopIndex?: string | null,
|
|
285
286
|
): string {
|
|
286
287
|
const wrap = loopParam ? (expr: string) => wrapLoopParamAsAccessor(expr, loopParam, loopParamBindings, loopIndex) : (expr: string) => expr
|
|
287
|
-
|
|
288
|
+
// A props-object spread merges in source order through the shared door
|
|
289
|
+
// (#3713) instead of becoming a getter named `...`.
|
|
290
|
+
const trailing: string[] = []
|
|
291
|
+
if ('children' in comp && Array.isArray(comp.children) && comp.children.length > 0) {
|
|
292
|
+
const childrenExpr = irChildrenToJsExpr(comp.children)
|
|
293
|
+
if (childrenExpr && childrenExpr !== "''") {
|
|
294
|
+
trailing.push(`get children() { return ${wrap(childrenExpr)} }`)
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return childPropsObjectExpr(comp.props, (p): ChildPropValue => {
|
|
288
298
|
if (p.isEventHandler) {
|
|
289
|
-
|
|
290
|
-
return `${quotePropName(p.name)}: ${wrap(handlerExpr)}`
|
|
299
|
+
return { expr: wrap(attrValueToString(p.value) ?? 'undefined'), getter: false }
|
|
291
300
|
}
|
|
292
301
|
switch (p.value.kind) {
|
|
293
302
|
case 'literal':
|
|
294
303
|
// Literal string values must NOT be wrapped — they don't reference loop params
|
|
295
|
-
return
|
|
304
|
+
return { expr: JSON.stringify(p.value.value), getter: true }
|
|
296
305
|
case 'boolean-shorthand':
|
|
297
306
|
case 'boolean-attr':
|
|
298
|
-
return
|
|
299
|
-
case 'jsx-children':
|
|
307
|
+
return { expr: 'true', getter: true }
|
|
308
|
+
case 'jsx-children':
|
|
300
309
|
// Brand via the shared door (#2651/#2702) — see
|
|
301
310
|
// `jsxChildrenPropGetterExpr`'s docstring. This builder is shared
|
|
302
311
|
// by loop and conditional-branch component reconciliation, so a
|
|
303
312
|
// named jsx-children prop on a component instantiated in either
|
|
304
313
|
// context used to reach its getter unbranded (pullfrog review, PR
|
|
305
314
|
// #2820).
|
|
306
|
-
|
|
307
|
-
return `get ${quotePropName(p.name)}() { return ${wrap(childExpr)} }`
|
|
308
|
-
}
|
|
315
|
+
return { expr: wrap(jsxChildrenPropGetterExpr(p.value.children, p.name)), getter: true }
|
|
309
316
|
case 'expression':
|
|
310
317
|
case 'template':
|
|
311
|
-
case 'spread':
|
|
312
|
-
|
|
313
|
-
return `get ${quotePropName(p.name)}() { return ${wrap(valueExpr)} }`
|
|
314
|
-
}
|
|
318
|
+
case 'spread':
|
|
319
|
+
return { expr: wrap(attrValueToString(p.value)!), getter: true }
|
|
315
320
|
}
|
|
316
|
-
})
|
|
317
|
-
if ('children' in comp && Array.isArray(comp.children) && comp.children.length > 0) {
|
|
318
|
-
const childrenExpr = irChildrenToJsExpr(comp.children)
|
|
319
|
-
if (childrenExpr && childrenExpr !== "''") {
|
|
320
|
-
entries.push(`get children() { return ${wrap(childrenExpr)} }`)
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
return entries.length > 0 ? `{ ${entries.join(', ')} }` : '{}'
|
|
321
|
+
}, { trailing })
|
|
324
322
|
}
|
|
325
323
|
|
|
326
324
|
/** Per-inner-loop data for composite loop emission. */
|
|
@@ -65,10 +65,12 @@ export function rowTextSlotKind(text: RowTextSlot): 'text' | 'markup' {
|
|
|
65
65
|
* The value a loop-row content slot's writer receives: `escapeTextOrNode`
|
|
66
66
|
* for a markup slot (unwraps a `bfMarkup()` value, passes a Node or a
|
|
67
67
|
* `__slot()` marker through, escapes a string before the markup writer's
|
|
68
|
-
* `innerHTML`), `
|
|
68
|
+
* `innerHTML`), `textOrNode(expr)` for a 'text' slot (passes a Node through
|
|
69
|
+
* for the claim to promote, and renders a boolean as no text, as JSX does,
|
|
70
|
+
* #3824 step 5).
|
|
69
71
|
*/
|
|
70
|
-
export function rowTextSlotValue(text: RowTextSlot, expr: string
|
|
71
|
-
return text.markup ? `escapeTextOrNode(${expr})` :
|
|
72
|
+
export function rowTextSlotValue(text: RowTextSlot, expr: string): string {
|
|
73
|
+
return text.markup ? `escapeTextOrNode(${expr})` : `textOrNode(${expr})`
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
/** Render one `SlotSpec` as a source-text object literal. */
|
|
@@ -112,14 +112,14 @@ function emitReactive(lines: string[], inner: InnerLoopPlan, indent: string, pc:
|
|
|
112
112
|
// writes are a plain, idempotent `nodeValue` assignment with no
|
|
113
113
|
// dedup/trust-first-run state to go stale — so re-claiming here is exactly
|
|
114
114
|
// as safe as, and replaces, the old re-query-$t-on-every-run discipline.
|
|
115
|
-
lines.push(`${indent} createEffect(() => { claimSlots(__innerEl${uid}, [{ id: '${text.slotId}', kind: '${rowTextSlotKind(text)}', path: [] }]).write('${text.slotId}', ${rowTextSlotValue(text, text.wrappedExpression
|
|
115
|
+
lines.push(`${indent} createEffect(() => { claimSlots(__innerEl${uid}, [{ id: '${text.slotId}', kind: '${rowTextSlotKind(text)}', path: [] }]).write('${text.slotId}', ${rowTextSlotValue(text, text.wrappedExpression)}) }${bf})`)
|
|
116
116
|
}
|
|
117
117
|
if (plainTexts.length > 0) {
|
|
118
118
|
const slots: ClaimSlotSpec[] = plainTexts.map(t => ({ id: t.slotId, kind: rowTextSlotKind(t), path: [] }))
|
|
119
119
|
const writer = claimWriterVarName(slots, varSlotId)
|
|
120
120
|
lines.push(`${indent} const ${writer} = lazySlots(__innerEl${uid}, ${claimPlanLiteral(slots)})`)
|
|
121
121
|
for (const text of plainTexts) {
|
|
122
|
-
lines.push(`${indent} createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.wrappedExpression
|
|
122
|
+
lines.push(`${indent} createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.wrappedExpression)}) }${profileBindingId(pc, text.slotId)})`)
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
if (emit.reactiveAttrs.length > 0) lines.push(`${indent} ${DEDUP_STORE_DECL}`)
|
|
@@ -535,7 +535,7 @@ function emitTextBinding(
|
|
|
535
535
|
? `${doorExpr}.write('${t.slotId}', ${valueExpr})`
|
|
536
536
|
: `${doorExpr}('${t.slotId}', ${valueExpr})`
|
|
537
537
|
|
|
538
|
-
const value = rowTextSlotValue(t, '__x'
|
|
538
|
+
const value = rowTextSlotValue(t, '__x')
|
|
539
539
|
if (mode === 'outer') {
|
|
540
540
|
lines.push(`${ind}if (__seed) {`)
|
|
541
541
|
lines.push(`${ind} const __s = ${value}`)
|