@barefootjs/jsx 0.40.1 → 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 +4 -3
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +1 -1
- 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/computed-const.d.ts +11 -1
- package/dist/adapters/computed-const.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +21 -0
- 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 +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 +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 +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 +19 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4628 -2198
- 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-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/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/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 +68 -9
- 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-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/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 +3 -3
- 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-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__/computed-const.test.ts +103 -0
- 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__/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__/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 +134 -0
- package/src/__tests__/primitive-plan.test.ts +416 -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 +53 -8
- 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/adapters/ambiguous-nil-arithmetic.ts +22 -13
- 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/computed-const.ts +238 -4
- package/src/adapters/dsl-template-adapter.ts +40 -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 +17 -4
- 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 +6 -0
- package/src/analyzer.ts +505 -19
- 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 +33 -7
- 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 +30 -55
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +6 -1
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +29 -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 +25 -8
- 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 +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/stringify/static-array-child-init.ts +26 -10
- package/src/jsx-to-ir.ts +446 -37
- package/src/nullable-signal-attr.ts +246 -29
- package/src/prop-rewrite.ts +30 -6
- 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/strip-types.ts +31 -3
- package/src/template-position-walk.ts +57 -28
- package/src/types.ts +87 -0
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
|
|
20
20
|
import type { IRLoopChildComponent, MapCallbackPreamble } from '../../types.ts'
|
|
21
21
|
import type { ClientJsContext, LoopChildReactiveAttr, NestedLoop, TopLevelLoop } from '../types.ts'
|
|
22
|
-
import {
|
|
22
|
+
import { varSlotId, attrValueToString, buildLoopChildIndexExpr } from '../utils.ts'
|
|
23
|
+
import { childPropsObjectExpr, type ChildPropValue } from '../child-props-object.ts'
|
|
23
24
|
import { jsxChildrenPropGetterExpr, renderPreamble, irToHtmlTemplate } from '../html-template.ts'
|
|
24
25
|
|
|
25
26
|
/**
|
|
@@ -40,6 +41,7 @@ import { buildForwardedInnerLoopsPlan } from '../control-flow/plan/build-inner-l
|
|
|
40
41
|
/** The inline prop shape carried on `IRLoopChildComponent.props`. */
|
|
41
42
|
type LoopChildCompProp = IRLoopChildComponent['props'][number]
|
|
42
43
|
import type {
|
|
44
|
+
ChildScopesLookup,
|
|
43
45
|
ComponentRootedInnerLoopInitPlan,
|
|
44
46
|
InnerLoopComp,
|
|
45
47
|
InnerLoopNestedInitPlan,
|
|
@@ -114,18 +116,32 @@ export function buildStaticArrayChildInitsPlan(
|
|
|
114
116
|
return plans
|
|
115
117
|
}
|
|
116
118
|
|
|
119
|
+
/**
|
|
120
|
+
* The one decision for how a static array's child init finds a component's
|
|
121
|
+
* scope (#3821), for every shape: the document-order zip and the per-row
|
|
122
|
+
* lookup alike. A slotted component is looked up by its slot, which the
|
|
123
|
+
* runtime matches on an element's `bf-h`/`bf-m`/`bf-s` and on a fragment
|
|
124
|
+
* root's `<!--bf-scope:…|h=…|m=…-->` comment alike; an element selector
|
|
125
|
+
* (`buildCompSelector`) cannot reach the comment, so a fragment-rooted row
|
|
126
|
+
* was never initialised. Without a slot id the name-prefix selector stays.
|
|
127
|
+
*/
|
|
128
|
+
function buildChildScopesLookup(comp: { slotId?: string | null; name: string }): ChildScopesLookup {
|
|
129
|
+
return comp.slotId
|
|
130
|
+
? { by: 'slot', slotId: comp.slotId }
|
|
131
|
+
: { by: 'name', selector: buildCompSelector(comp) }
|
|
132
|
+
}
|
|
133
|
+
|
|
117
134
|
function buildSingleCompPlan(
|
|
118
135
|
elem: TopLevelLoop,
|
|
119
136
|
childComponent: IRLoopChildComponent,
|
|
120
137
|
): SingleCompInitPlan {
|
|
121
|
-
const { name, props
|
|
122
|
-
const childSelector = buildCompSelector({ name, slotId })
|
|
138
|
+
const { name, props } = childComponent
|
|
123
139
|
|
|
124
140
|
return {
|
|
125
141
|
kind: 'single-comp',
|
|
126
142
|
containerVar: `_${varSlotId(elem.slotId)}`,
|
|
127
143
|
componentName: name,
|
|
128
|
-
|
|
144
|
+
lookup: buildChildScopesLookup(childComponent),
|
|
129
145
|
arrayExpr: elem.array,
|
|
130
146
|
param: elem.param,
|
|
131
147
|
indexParam: elem.index || '__idx',
|
|
@@ -159,7 +175,7 @@ function buildOuterNestedPlan(
|
|
|
159
175
|
kind: 'outer-nested',
|
|
160
176
|
containerVar: `_${varSlotId(elem.slotId)}`,
|
|
161
177
|
componentName: comp.name,
|
|
162
|
-
|
|
178
|
+
lookup: buildChildScopesLookup(comp),
|
|
163
179
|
arrayExpr: elem.array,
|
|
164
180
|
param: elem.param,
|
|
165
181
|
indexParam,
|
|
@@ -182,7 +198,7 @@ function buildInnerLoopNestedPlan(
|
|
|
182
198
|
const innerIndexParam = innerLoop.index || '__innerIdx'
|
|
183
199
|
const comps: InnerLoopComp[] = innerComps.map(comp => ({
|
|
184
200
|
componentName: comp.name,
|
|
185
|
-
|
|
201
|
+
lookup: buildChildScopesLookup(comp),
|
|
186
202
|
propsExpr: buildStaticPropsExpr(comp.props),
|
|
187
203
|
}))
|
|
188
204
|
|
|
@@ -245,7 +261,7 @@ function buildComponentRootedInnerLoopPlan(
|
|
|
245
261
|
): ComponentRootedInnerLoopInitPlan {
|
|
246
262
|
const comps: InnerLoopComp[] = innerComps.map(comp => ({
|
|
247
263
|
componentName: comp.name,
|
|
248
|
-
|
|
264
|
+
lookup: buildChildScopesLookup(comp),
|
|
249
265
|
propsExpr: buildStaticPropsExpr(comp.props),
|
|
250
266
|
}))
|
|
251
267
|
|
|
@@ -278,29 +294,30 @@ function buildComponentRootedInnerLoopPlan(
|
|
|
278
294
|
* property, NOT a getter), matching the legacy emitter byte-for-byte.
|
|
279
295
|
*/
|
|
280
296
|
function buildStaticPropsExpr(props: readonly LoopChildCompProp[]): PropsExpr {
|
|
281
|
-
|
|
297
|
+
// A props-object spread merges in source order through the shared door
|
|
298
|
+
// (#3713) instead of becoming a getter named `...`.
|
|
299
|
+
return childPropsObjectExpr(props, (p): ChildPropValue => {
|
|
282
300
|
if (p.isEventHandler) {
|
|
283
|
-
return
|
|
301
|
+
return { expr: attrValueToString(p.value) ?? 'undefined', getter: false }
|
|
284
302
|
}
|
|
285
303
|
switch (p.value.kind) {
|
|
286
304
|
case 'literal':
|
|
287
|
-
return
|
|
305
|
+
return { expr: JSON.stringify(p.value.value), getter: false }
|
|
288
306
|
case 'boolean-shorthand':
|
|
289
307
|
case 'boolean-attr':
|
|
290
|
-
return
|
|
308
|
+
return { expr: 'true', getter: false }
|
|
291
309
|
case 'jsx-children':
|
|
292
310
|
// Brand via the shared door (#2651/#2702) — see
|
|
293
311
|
// `jsxChildrenPropGetterExpr`'s docstring. A named jsx-children
|
|
294
312
|
// prop on a component instantiated inside a static-array `.map()`
|
|
295
313
|
// loop used to reach its getter unbranded (pullfrog review, PR
|
|
296
314
|
// #2820).
|
|
297
|
-
return
|
|
315
|
+
return { expr: jsxChildrenPropGetterExpr(p.value.children, p.name), getter: true }
|
|
298
316
|
case 'expression':
|
|
299
317
|
case 'template':
|
|
300
318
|
case 'spread':
|
|
301
|
-
return
|
|
319
|
+
return { expr: attrValueToString(p.value) ?? 'undefined', getter: true }
|
|
302
320
|
}
|
|
303
321
|
})
|
|
304
|
-
return entries.length > 0 ? `{ ${entries.join(', ')} }` : '{}'
|
|
305
322
|
}
|
|
306
323
|
|
|
@@ -33,14 +33,30 @@ import type { LoopChildReactiveAttr, LoopChildReactiveText } from '../types.ts'
|
|
|
33
33
|
/** Pre-built `{ name: value, ... }` props object expression. */
|
|
34
34
|
export type PropsExpr = string
|
|
35
35
|
|
|
36
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* How a static array's row init finds every child scope of one component in
|
|
38
|
+
* a container, in document order (#3821). Decided once by
|
|
39
|
+
* `buildChildScopesLookup`:
|
|
40
|
+
*
|
|
41
|
+
* - `slot` — the component sits at a known slot: the runtime's
|
|
42
|
+
* `childScopesBySlot` / `childScopeBySlot(el, __scopeId, slotId)` find
|
|
43
|
+
* both an element-rooted scope and a fragment-rooted one (declared by a
|
|
44
|
+
* `<!--bf-scope:-->` comment, which no element selector can match).
|
|
45
|
+
* - `name` — no slot id: `qsaChildScopes` / `qsaChildScope` with the
|
|
46
|
+
* `[bf-s^="Name_"]` selector.
|
|
47
|
+
*/
|
|
48
|
+
export type ChildScopesLookup =
|
|
49
|
+
| { by: 'slot'; slotId: string }
|
|
50
|
+
| { by: 'name'; selector: string }
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A child-component initialiser inside an inner-loop body, or zipped by
|
|
54
|
+
* document order against loop items.
|
|
55
|
+
*/
|
|
37
56
|
export interface InnerLoopComp {
|
|
38
57
|
componentName: string
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
* `__innerEl.querySelector(<here>)`. See `buildCompSelector`.
|
|
42
|
-
*/
|
|
43
|
-
selector: string
|
|
58
|
+
/** How the component's scope is found (#3821). See `ChildScopesLookup`. */
|
|
59
|
+
lookup: ChildScopesLookup
|
|
44
60
|
/** Pre-built props object expression. */
|
|
45
61
|
propsExpr: PropsExpr
|
|
46
62
|
}
|
|
@@ -51,12 +67,8 @@ export interface SingleCompInitPlan {
|
|
|
51
67
|
/** Container variable name — e.g. `_s4` (already prefixed). */
|
|
52
68
|
containerVar: string
|
|
53
69
|
componentName: string
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
* `containerVar.querySelectorAll(<here>)`. Combines slotId-suffix match
|
|
57
|
-
* with name-prefix match.
|
|
58
|
-
*/
|
|
59
|
-
childSelector: string
|
|
70
|
+
/** How every row's child scope is found under `containerVar` (#3821). */
|
|
71
|
+
lookup: ChildScopesLookup
|
|
60
72
|
/** Array expression as written in user code. */
|
|
61
73
|
arrayExpr: string
|
|
62
74
|
/** Loop parameter identifier. */
|
|
@@ -92,11 +104,8 @@ export interface OuterNestedInitPlan {
|
|
|
92
104
|
kind: 'outer-nested'
|
|
93
105
|
containerVar: string
|
|
94
106
|
componentName: string
|
|
95
|
-
/**
|
|
96
|
-
|
|
97
|
-
* `__iterEl.querySelector(<here>)`. See `buildCompSelector`.
|
|
98
|
-
*/
|
|
99
|
-
selector: string
|
|
107
|
+
/** How the component's scope is found in `__iterEl` (#3821). */
|
|
108
|
+
lookup: ChildScopesLookup
|
|
100
109
|
arrayExpr: string
|
|
101
110
|
param: string
|
|
102
111
|
indexParam: string
|
|
@@ -190,7 +199,7 @@ export interface InnerLoopNestedInitPlan {
|
|
|
190
199
|
* the parent container with no per-group element to index.
|
|
191
200
|
*
|
|
192
201
|
* Instead this shape zips the inner component scopes — found in document order
|
|
193
|
-
*
|
|
202
|
+
* by the comp's `ChildScopesLookup` — against the flattened
|
|
194
203
|
* `outer.forEach(o => inner.forEach(i => ...))` iteration. Document order is
|
|
195
204
|
* the SSR render order, so position `__ci++` pairs each scope with its data
|
|
196
205
|
* item regardless of whether the outer component root is an element or a
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Props expansion, dependency analysis, and controlled component detection.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { ParamInfo, SignalInfo } from '../types.ts'
|
|
5
|
+
import type { ConstantInfo, ParamInfo, SignalInfo } from '../types.ts'
|
|
6
6
|
import type { ClientJsContext } from './types.ts'
|
|
7
7
|
import type { BindingScope } from '../scope/binding-scope.ts'
|
|
8
8
|
import { resolveRestSpreadOriginCore } from '../props-binding.ts'
|
|
@@ -118,13 +118,32 @@ export function expandDynamicPropValue(value: string, ctx: ClientJsContext, scop
|
|
|
118
118
|
// Re-embedding it here would silently drop the mutation; keep the bare
|
|
119
119
|
// reference instead so the emitted getter reads the LIVE binding.
|
|
120
120
|
if (constant?.mutatedAfterDeclaration) return value
|
|
121
|
-
if (constant && constant.value) {
|
|
121
|
+
if (constant && constant.value && !initializerCapturedBy(constant, scope)) {
|
|
122
122
|
return constant.value
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
return value
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Would `constant`'s initializer text, spliced in place of a reference to it
|
|
130
|
+
* at a site inside `scope`, read a different binding than the declaration
|
|
131
|
+
* does (#3736)? The initializer resolves in the scope the const is declared
|
|
132
|
+
* in, so a name it reads that a loop row or callback here binds
|
|
133
|
+
* (`const b = a` read in `rows.map(a => …)`) would re-resolve to the row's
|
|
134
|
+
* binding. The reference then stays the const itself, which init declares.
|
|
135
|
+
*
|
|
136
|
+
* A SHADOW GUARD, so `isBound` (every binding source hides the outer name),
|
|
137
|
+
* not `valueBoundNames`.
|
|
138
|
+
*/
|
|
139
|
+
function initializerCapturedBy(constant: ConstantInfo, scope: BindingScope | undefined): boolean {
|
|
140
|
+
if (!scope || !constant.freeIdentifiers) return false
|
|
141
|
+
for (const name of constant.freeIdentifiers) {
|
|
142
|
+
if (scope.isBound(name)) return true
|
|
143
|
+
}
|
|
144
|
+
return false
|
|
145
|
+
}
|
|
146
|
+
|
|
128
147
|
/**
|
|
129
148
|
* Expand a local constant for reactivity detection in stateless components.
|
|
130
149
|
* Stateful components use props.xxx directly, so expansion is unnecessary.
|
|
@@ -165,7 +184,7 @@ export function expandConstantForReactivity(
|
|
|
165
184
|
// binding's `value` is a stale pre-mutation snapshot, so it must not be
|
|
166
185
|
// substituted in place of a live reference.
|
|
167
186
|
if (constant?.mutatedAfterDeclaration) return { expr, freeIds: originalFreeIds }
|
|
168
|
-
if (constant && constant.value) {
|
|
187
|
+
if (constant && constant.value && !initializerCapturedBy(constant, scope)) {
|
|
169
188
|
return { expr: constant.value, freeIds: constant.freeIdentifiers }
|
|
170
189
|
}
|
|
171
190
|
return { expr, freeIds: originalFreeIds }
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* single-comp:
|
|
8
8
|
* <i>// Initialize static array children (hydrate skips nested instances)
|
|
9
9
|
* <i>if (<container>) {
|
|
10
|
-
* <i> const __childScopes =
|
|
10
|
+
* <i> const __childScopes = childScopesBySlot(<container>, __scopeId, '<slot>')
|
|
11
|
+
* <i> // or qsaChildScopes(<container>, <selector>) without a slot
|
|
11
12
|
* <i> __childScopes.forEach((childScope, <idx>) => {
|
|
12
13
|
* <i> const <param> = <array>[<idx>]
|
|
13
14
|
* <i> <outerPreludeStatements*> // raw outer preamble (#1064)
|
|
@@ -23,7 +24,7 @@
|
|
|
23
24
|
* <i> const __iterEl = <container>.children[<offset>]
|
|
24
25
|
* <i> if (__iterEl) {
|
|
25
26
|
* <i> <outerPreludeStatements*> // raw outer preamble (#1064)
|
|
26
|
-
* <i> const __compEl =
|
|
27
|
+
* <i> const __compEl = childScopeBySlot(__iterEl, __scopeId, '<slot>')
|
|
27
28
|
* <i> if (__compEl) initChild('<name>', __compEl, <props>)
|
|
28
29
|
* <i> }
|
|
29
30
|
* <i> })
|
|
@@ -51,6 +52,7 @@
|
|
|
51
52
|
*/
|
|
52
53
|
|
|
53
54
|
import type {
|
|
55
|
+
ChildScopesLookup,
|
|
54
56
|
ComponentRootedInnerLoopInitPlan,
|
|
55
57
|
InnerLoopNestedInitPlan,
|
|
56
58
|
OuterNestedInitPlan,
|
|
@@ -92,11 +94,25 @@ function stringifyOne(lines: string[], plan: StaticArrayChildInitPlan): void {
|
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
96
|
|
|
97
|
+
/** Spell a `ChildScopesLookup` as the runtime call that finds every scope. */
|
|
98
|
+
function childScopesCall(containerVar: string, lookup: ChildScopesLookup): string {
|
|
99
|
+
return lookup.by === 'slot'
|
|
100
|
+
? `childScopesBySlot(${containerVar}, __scopeId, '${lookup.slotId}')`
|
|
101
|
+
: `qsaChildScopes(${containerVar}, ${lookup.selector})`
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Spell a `ChildScopesLookup` as the runtime call that finds one scope. */
|
|
105
|
+
function childScopeCall(elVar: string, lookup: ChildScopesLookup): string {
|
|
106
|
+
return lookup.by === 'slot'
|
|
107
|
+
? `childScopeBySlot(${elVar}, __scopeId, '${lookup.slotId}')`
|
|
108
|
+
: `qsaChildScope(${elVar}, ${lookup.selector})`
|
|
109
|
+
}
|
|
110
|
+
|
|
95
111
|
function emitSingleComp(lines: string[], plan: SingleCompInitPlan): void {
|
|
96
|
-
const { containerVar, componentName,
|
|
112
|
+
const { containerVar, componentName, lookup, arrayExpr, param, indexParam, outerPreludeStatements, propsExpr, rowEvents, innerLoops } = plan
|
|
97
113
|
lines.push(` // Initialize static array children (hydrate skips nested instances)`)
|
|
98
114
|
lines.push(` if (${containerVar}) {`)
|
|
99
|
-
lines.push(` const __childScopes =
|
|
115
|
+
lines.push(` const __childScopes = ${childScopesCall(containerVar, lookup)}`)
|
|
100
116
|
lines.push(` __childScopes.forEach((childScope, ${indexParam}) => {`)
|
|
101
117
|
lines.push(` const ${param} = ${arrayExpr}[${indexParam}]`)
|
|
102
118
|
// Outer `.map()` callback preamble locals — emitted unwrapped after
|
|
@@ -114,7 +130,7 @@ function emitSingleComp(lines: string[], plan: SingleCompInitPlan): void {
|
|
|
114
130
|
}
|
|
115
131
|
|
|
116
132
|
function emitOuterNested(lines: string[], plan: OuterNestedInitPlan): void {
|
|
117
|
-
const { containerVar, componentName,
|
|
133
|
+
const { containerVar, componentName, lookup, arrayExpr, param, indexParam, offsetExpr, outerPreludeStatements, propsExpr } = plan
|
|
118
134
|
lines.push(` // Initialize nested ${componentName} in static array`)
|
|
119
135
|
lines.push(` if (${containerVar}) {`)
|
|
120
136
|
lines.push(` ${arrayExpr}.forEach((${param}, ${indexParam}) => {`)
|
|
@@ -127,7 +143,7 @@ function emitOuterNested(lines: string[], plan: OuterNestedInitPlan): void {
|
|
|
127
143
|
for (const stmt of outerPreludeStatements) {
|
|
128
144
|
lines.push(` ${stmt}`)
|
|
129
145
|
}
|
|
130
|
-
lines.push(` const __compEl =
|
|
146
|
+
lines.push(` const __compEl = ${childScopeCall('__iterEl', lookup)}`)
|
|
131
147
|
lines.push(` if (__compEl) initChild('${nameForRegistryRef(componentName)}', __compEl, ${propsExpr})`)
|
|
132
148
|
lines.push(` }`)
|
|
133
149
|
lines.push(` })`)
|
|
@@ -183,7 +199,7 @@ function emitInnerLoopNested(lines: string[], plan: InnerLoopNestedInitPlan): vo
|
|
|
183
199
|
// re-declare `const __compEl` in the same scope (#1664).
|
|
184
200
|
comps.forEach((comp, i) => {
|
|
185
201
|
const compElVar = comps.length > 1 ? `__compEl${i}` : '__compEl'
|
|
186
|
-
lines.push(` const ${compElVar} =
|
|
202
|
+
lines.push(` const ${compElVar} = ${childScopeCall('__innerEl', comp.lookup)}`)
|
|
187
203
|
lines.push(` if (${compElVar}) initChild('${nameForRegistryRef(comp.componentName)}', ${compElVar}, ${comp.propsExpr})`)
|
|
188
204
|
})
|
|
189
205
|
// Plain-element reactive attrs / texts / refs inside this inner loop's
|
|
@@ -211,7 +227,7 @@ function emitInnerLoopNested(lines: string[], plan: InnerLoopNestedInitPlan): vo
|
|
|
211
227
|
const writer = claimWriterVarName(slots, varSlotId)
|
|
212
228
|
lines.push(` const ${writer} = lazySlots(__innerEl, ${claimPlanLiteral(slots)})`)
|
|
213
229
|
for (const text of texts) {
|
|
214
|
-
lines.push(` createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.expression
|
|
230
|
+
lines.push(` createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.expression)}) })`)
|
|
215
231
|
}
|
|
216
232
|
}
|
|
217
233
|
// Ref callbacks fire on every forEach iteration — initial mount and any
|
|
@@ -229,7 +245,7 @@ function emitInnerLoopNested(lines: string[], plan: InnerLoopNestedInitPlan): vo
|
|
|
229
245
|
*
|
|
230
246
|
* <i>// Initialize component-rooted inner-loop components (depth N)
|
|
231
247
|
* <i>if (<container>) {
|
|
232
|
-
* <i> const <scopes_c> =
|
|
248
|
+
* <i> const <scopes_c> = childScopesBySlot(<container>, __scopeId, '<slot_c>') // per comp
|
|
233
249
|
* <i> let <cursor_c> = 0
|
|
234
250
|
* <i> <outerArr>.forEach((<outerParam>[, <outerIdx>]) => {
|
|
235
251
|
* <i> <outerPreludeStatements*>
|
|
@@ -270,7 +286,7 @@ function emitComponentRootedInnerLoop(lines: string[], plan: ComponentRootedInne
|
|
|
270
286
|
lines.push(` // Initialize component-rooted inner-loop components (depth ${depth})`)
|
|
271
287
|
lines.push(` if (${containerVar}) {`)
|
|
272
288
|
comps.forEach((comp, i) => {
|
|
273
|
-
lines.push(` const ${scopesVar(i)} =
|
|
289
|
+
lines.push(` const ${scopesVar(i)} = ${childScopesCall(containerVar, comp.lookup)}`)
|
|
274
290
|
lines.push(` let ${cursorVar(i)} = 0`)
|
|
275
291
|
})
|
|
276
292
|
// Declared index names are appended to the forEach heads (#2231);
|