@barefootjs/jsx 0.39.3 → 0.39.5
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 -0
- package/dist/adapters/boolean-result.d.ts.map +1 -0
- package/dist/adapters/filter-capture-collisions.d.ts +17 -0
- package/dist/adapters/filter-capture-collisions.d.ts.map +1 -0
- package/dist/adapters/parsed-expr-emitter.d.ts +8 -0
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/template-name-collisions.d.ts +21 -0
- package/dist/adapters/template-name-collisions.d.ts.map +1 -0
- package/dist/analyzer-context.d.ts.map +1 -1
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +10 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +688 -176
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-composite-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts +13 -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-loop-child-arm.d.ts +3 -2
- 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/event-delegation.d.ts +7 -0
- package/dist/ir-to-client-js/control-flow/plan/event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/loop.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/composite-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/loop.d.ts +14 -0
- package/dist/ir-to-client-js/control-flow/stringify/loop.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/phases/rest-attr-applications.d.ts +3 -1
- package/dist/ir-to-client-js/phases/rest-attr-applications.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 +6 -0
- package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +12 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +39 -1
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +33 -0
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/profiler.d.ts +9 -1
- package/dist/profiler.d.ts.map +1 -1
- package/dist/scope/binding-scope.d.ts +10 -0
- package/dist/scope/binding-scope.d.ts.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/binding-scope-ratchet.test.ts +1 -1
- package/src/__tests__/binding-scope.test.ts +11 -0
- package/src/__tests__/boolean-result.test.ts +27 -0
- package/src/__tests__/compile-without-node-process.test.ts +78 -0
- package/src/__tests__/csr-template-loop-shadow.test.ts +83 -0
- package/src/__tests__/doc-examples.test.ts +1 -0
- package/src/__tests__/nested-row-shadowing.test.ts +57 -0
- package/src/__tests__/profile-turn-markers.test.ts +22 -0
- package/src/__tests__/profiler.test.ts +10 -9
- package/src/__tests__/rename-free-identifiers.test.ts +26 -0
- package/src/__tests__/ssr-portal-ref-callback.test.ts +88 -13
- package/src/__tests__/template-name-collisions.test.ts +81 -0
- package/src/adapters/boolean-result.ts +89 -0
- package/src/adapters/filter-capture-collisions.ts +29 -0
- package/src/adapters/parsed-expr-emitter.ts +18 -0
- package/src/adapters/template-name-collisions.ts +120 -0
- package/src/analyzer-context.ts +15 -1
- package/src/errors.ts +11 -0
- package/src/expression-parser.ts +32 -0
- package/src/index.ts +9 -2
- package/src/ir-to-client-js/collect-elements.ts +22 -10
- package/src/ir-to-client-js/control-flow/plan/build-composite-loop.ts +2 -0
- package/src/ir-to-client-js/control-flow/plan/build-event-delegation.ts +13 -0
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +38 -12
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +12 -5
- package/src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts +2 -2
- package/src/ir-to-client-js/control-flow/plan/event-delegation.ts +7 -0
- package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -0
- package/src/ir-to-client-js/control-flow/plan/loop.ts +2 -0
- package/src/ir-to-client-js/control-flow/shared.ts +6 -1
- package/src/ir-to-client-js/control-flow/stringify/branch-loop.ts +6 -3
- package/src/ir-to-client-js/control-flow/stringify/composite-loop.ts +7 -4
- package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +21 -6
- package/src/ir-to-client-js/control-flow/stringify/insert.ts +6 -1
- package/src/ir-to-client-js/control-flow/stringify/loop.ts +55 -8
- package/src/ir-to-client-js/html-template.ts +72 -15
- package/src/ir-to-client-js/imports.ts +3 -1
- package/src/ir-to-client-js/index.ts +7 -2
- package/src/ir-to-client-js/phases/rest-attr-applications.ts +8 -2
- package/src/ir-to-client-js/reactivity.ts +1 -0
- package/src/ir-to-client-js/safe-html.ts +10 -0
- package/src/ir-to-client-js/types.ts +12 -0
- package/src/ir-to-client-js/utils.ts +81 -7
- package/src/jsx-to-ir.ts +138 -32
- package/src/nullable-signal-attr.ts +78 -0
- package/src/profiler.ts +79 -10
- package/src/scope/binding-scope.ts +19 -0
- package/src/types.ts +7 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { 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, quotePropName, PROPS_PARAM, toHtmlAttrName, type LoopParamSpec } from './utils.ts'
|
|
7
|
+
import { attrValueToString, freeIdsFromRefs, quotePropName, 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'
|
|
@@ -328,12 +328,16 @@ export function collectInnerLoops(
|
|
|
328
328
|
},
|
|
329
329
|
loop: ({ node: n, scope, descend }) => {
|
|
330
330
|
const emitDepth = fixedDepth ?? scope.depth + 1
|
|
331
|
+
// This nested row reads its destructure bindings through its own
|
|
332
|
+
// accessor, not the enclosing row's `__bfItem` (#3397).
|
|
333
|
+
const rowBindings = withRowAccessor(n.paramBindings, n.markerId)
|
|
331
334
|
// Generate item template for CSR rendering in mapArray.
|
|
332
335
|
// Pass loopParams so expressions are wrapped at generation time (not post-hoc regex).
|
|
333
336
|
// Forward destructured bindings (#951) so inner-loop template
|
|
334
337
|
// references to the destructured locals are rewritten.
|
|
338
|
+
// The outer spec skips the names this row rebinds (#3394).
|
|
335
339
|
const loopParamsForTemplate = outerSpec
|
|
336
|
-
? [outerSpec, { param: n.param, bindings:
|
|
340
|
+
? [{ ...outerSpec, shadowed: rowBoundNames(n) }, { param: n.param, bindings: rowBindings, index: n.index }]
|
|
337
341
|
: undefined
|
|
338
342
|
const template = n.children.map(c => irToPlaceholderTemplate(c, undefined, emitDepth, loopParamsForTemplate)).join('')
|
|
339
343
|
// Per-item bindings for inner loop body, collected uniformly when
|
|
@@ -369,8 +373,8 @@ export function collectInnerLoops(
|
|
|
369
373
|
// guarantees the branch's marker is mounted the moment this
|
|
370
374
|
// effect first runs (issue-2706-nested-loop-conditional-slot
|
|
371
375
|
// .test.ts's original repro).
|
|
372
|
-
bindings.reactiveTexts.push(...collectLoopChildReactiveTexts(child, ctx, n.param,
|
|
373
|
-
bindings.reactiveAttrs.push(...collectLoopChildReactiveAttrs(child, ctx, n.param,
|
|
376
|
+
bindings.reactiveTexts.push(...collectLoopChildReactiveTexts(child, ctx, n.param, rowBindings, true, innerPreambleNames, n.index, scope.bindingScope))
|
|
377
|
+
bindings.reactiveAttrs.push(...collectLoopChildReactiveAttrs(child, ctx, n.param, rowBindings, true, innerPreambleNames, n.index, scope.bindingScope))
|
|
374
378
|
bindings.refs.push(...collectLoopChildRefs(child))
|
|
375
379
|
}
|
|
376
380
|
bindings.conditionals.push(...collectLoopChildConditionals(
|
|
@@ -378,7 +382,7 @@ export function collectInnerLoops(
|
|
|
378
382
|
ctx,
|
|
379
383
|
siblingOffsets,
|
|
380
384
|
n.param,
|
|
381
|
-
|
|
385
|
+
rowBindings,
|
|
382
386
|
innerPreambleNames,
|
|
383
387
|
n.index,
|
|
384
388
|
// Render a branch's HTML against the FULL ancestor chain (outer
|
|
@@ -427,7 +431,7 @@ export function collectInnerLoops(
|
|
|
427
431
|
array: n.array,
|
|
428
432
|
arrayFreeIdentifiers: n.arrayFreeIdentifiers,
|
|
429
433
|
param: n.param,
|
|
430
|
-
paramBindings:
|
|
434
|
+
paramBindings: rowBindings,
|
|
431
435
|
index: n.index,
|
|
432
436
|
key: n.key,
|
|
433
437
|
markerId: n.markerId,
|
|
@@ -451,7 +455,7 @@ export function collectInnerLoops(
|
|
|
451
455
|
descend({
|
|
452
456
|
...scope,
|
|
453
457
|
depth: scope.depth + 1,
|
|
454
|
-
bindingScope: buildLoopRowScope(n.param,
|
|
458
|
+
bindingScope: buildLoopRowScope(n.param, rowBindings, innerPreambleNames, n.index, scope.bindingScope),
|
|
455
459
|
})
|
|
456
460
|
}
|
|
457
461
|
},
|
|
@@ -1253,9 +1257,16 @@ function collectFromElement(element: IRElement, ctx: ClientJsContext, insideCond
|
|
|
1253
1257
|
*/
|
|
1254
1258
|
function collectBranchReactiveAttrs(node: IRNode, ctx: ClientJsContext): ConditionalBranchReactiveAttr[] {
|
|
1255
1259
|
const attrs: ConditionalBranchReactiveAttr[] = []
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1260
|
+
// Scope: the slot ids of the components whose `children` enclose the
|
|
1261
|
+
// current node — a parent-owned (`^sN`) element renders inside one of
|
|
1262
|
+
// them, which is how the runtime tells it from another component's
|
|
1263
|
+
// same-numbered forwarded element (#3324).
|
|
1264
|
+
walkIR<readonly string[]>(node, [], {
|
|
1265
|
+
...stopAt<readonly string[]>('conditional', 'ifStatement', 'loop'),
|
|
1266
|
+
component: ({ node: c, scope, descend }) => {
|
|
1267
|
+
descend(c.slotId ? [...scope, c.slotId] : scope)
|
|
1268
|
+
},
|
|
1269
|
+
element: ({ node: el, scope, descend }) => {
|
|
1259
1270
|
if (!el.slotId) {
|
|
1260
1271
|
descend()
|
|
1261
1272
|
return
|
|
@@ -1276,6 +1287,7 @@ function collectBranchReactiveAttrs(node: IRNode, ctx: ClientJsContext): Conditi
|
|
|
1276
1287
|
if (!attr.clientOnly && !decideWrapForAttr(expanded.expr, ctx, attr).wrap) continue
|
|
1277
1288
|
attrs.push({
|
|
1278
1289
|
slotId: el.slotId,
|
|
1290
|
+
...(el.slotId.startsWith('^') && { receiverSlotIds: scope }),
|
|
1279
1291
|
attrName: attr.name,
|
|
1280
1292
|
expression: expanded.expr,
|
|
1281
1293
|
...pickAttrMetaFromIR(attr),
|
|
@@ -62,6 +62,7 @@ export function buildTopLevelCompositePlan(elem: TopLevelLoop, profileComponentN
|
|
|
62
62
|
outerLoopParam: elem.param,
|
|
63
63
|
outerLoopParamBindings: elem.paramBindings,
|
|
64
64
|
outerLoopIndex: elem.index,
|
|
65
|
+
rowHasPortal: elem.bindings.refs.some(r => r.ssrPortalOwner),
|
|
65
66
|
}),
|
|
66
67
|
loopParam: elem.param,
|
|
67
68
|
loopParamBindings: elem.paramBindings,
|
|
@@ -125,6 +126,7 @@ export function buildBranchCompositePlan(loop: BranchLoop, cv: string, profileCo
|
|
|
125
126
|
outerLoopParam: loop.param,
|
|
126
127
|
outerLoopParamBindings: loop.paramBindings,
|
|
127
128
|
outerLoopIndex: loop.index,
|
|
129
|
+
rowHasPortal: loop.bindings.refs.some(r => r.ssrPortalOwner),
|
|
128
130
|
}),
|
|
129
131
|
loopParam: loop.param,
|
|
130
132
|
loopParamBindings: loop.paramBindings,
|
|
@@ -30,6 +30,7 @@ export function buildDynamicLoopDelegationPlan(
|
|
|
30
30
|
events: elem.bindings.events,
|
|
31
31
|
profileComponentName,
|
|
32
32
|
ownHandlers,
|
|
33
|
+
...(hasRowPortalRef(elem) && { relayRowPortals: true }),
|
|
33
34
|
itemLookup: buildKeyedOrIndexLookup({
|
|
34
35
|
// Chain `.filter()` / `.toSorted()` so the index-based lookup walks
|
|
35
36
|
// the same array shape mapArray reconciled into the DOM (#1434).
|
|
@@ -69,6 +70,7 @@ export function buildBranchLoopDelegationPlan(
|
|
|
69
70
|
containerVar: `__loop_${cv}`,
|
|
70
71
|
events: loop.bindings.events,
|
|
71
72
|
profileComponentName,
|
|
73
|
+
...(hasRowPortalRef(loop) && { relayRowPortals: true }),
|
|
72
74
|
itemLookup: buildKeyedOrIndexLookup({
|
|
73
75
|
// See note on `buildDynamicLoopDelegationPlan` above (#1434).
|
|
74
76
|
array: buildChainedArrayExpr(loop),
|
|
@@ -98,6 +100,12 @@ export function buildStaticArrayDelegationPlan(
|
|
|
98
100
|
profileComponentName?: string,
|
|
99
101
|
ownHandlers?: Map<string, ContainerOwnHandler>,
|
|
100
102
|
): EventDelegationPlan {
|
|
103
|
+
// A row-portaled element is not under its row, so the positional lookup
|
|
104
|
+
// cannot reach the row from it; the row key it carries can (#3318).
|
|
105
|
+
// BF064 guarantees a portaling loop is keyed.
|
|
106
|
+
if (hasRowPortalRef(elem) && elem.key !== null) {
|
|
107
|
+
return buildDynamicLoopDelegationPlan(elem, profileComponentName, ownHandlers)
|
|
108
|
+
}
|
|
101
109
|
return {
|
|
102
110
|
kind: 'event-delegation',
|
|
103
111
|
containerVar: `_${varSlotId(elem.slotId)}`,
|
|
@@ -125,6 +133,11 @@ export function buildStaticArrayDelegationPlan(
|
|
|
125
133
|
}
|
|
126
134
|
}
|
|
127
135
|
|
|
136
|
+
/** A row `ref` callback of the loop portals its element out of the row (#3318). */
|
|
137
|
+
function hasRowPortalRef(loop: TopLevelLoop | BranchLoop): boolean {
|
|
138
|
+
return loop.bindings.refs.some(r => r.ssrPortalOwner)
|
|
139
|
+
}
|
|
140
|
+
|
|
128
141
|
/**
|
|
129
142
|
* Helper used by both the top-level and branch-scoped builders. Picks
|
|
130
143
|
* `keyed` vs `dynamic-index` based on whether the loop has an explicit key.
|
|
@@ -36,6 +36,9 @@ import type {
|
|
|
36
36
|
import { AttrValueOf, pickAttrMeta } from '../../../types.ts'
|
|
37
37
|
import {
|
|
38
38
|
wrapLoopParamAsAccessor,
|
|
39
|
+
rowBoundNames,
|
|
40
|
+
unionNames,
|
|
41
|
+
type ShadowableWrap,
|
|
39
42
|
attrValueToString,
|
|
40
43
|
} from '../../utils.ts'
|
|
41
44
|
import { buildChildRefBindings } from '../shared.ts'
|
|
@@ -88,6 +91,18 @@ export interface BuildInnerLoopsArgs {
|
|
|
88
91
|
outerLoopParamBindings?: readonly LoopParamBinding[]
|
|
89
92
|
/** Outer loop's index param name, when present (#2861). */
|
|
90
93
|
outerLoopIndex?: string | null
|
|
94
|
+
/**
|
|
95
|
+
* The outer row portals an element out of itself (#3318), so a container
|
|
96
|
+
* inside it is looked up through the row's registered roots (`qsaItem`).
|
|
97
|
+
*/
|
|
98
|
+
rowHasPortal?: boolean
|
|
99
|
+
/**
|
|
100
|
+
* Every enclosing loop's accessor rewrite, composed (#3397). A recursion
|
|
101
|
+
* for a deeper level passes it so a row two or more loops deep still
|
|
102
|
+
* rewrites its grandparent's bindings; the top call builds it from
|
|
103
|
+
* `outerLoopParam`.
|
|
104
|
+
*/
|
|
105
|
+
wrapOuter?: ShadowableWrap
|
|
91
106
|
}
|
|
92
107
|
|
|
93
108
|
/**
|
|
@@ -96,10 +111,10 @@ export interface BuildInnerLoopsArgs {
|
|
|
96
111
|
* conditional branch are skipped (they're emitted by `stringifyBranchInnerLoops`).
|
|
97
112
|
*/
|
|
98
113
|
export function buildInnerLoopsPlan(args: BuildInnerLoopsArgs): InnerLoopsPlan {
|
|
99
|
-
const { levels, parentElVar, outerLoopParam, outerLoopParamBindings, outerLoopIndex } = args
|
|
100
|
-
const wrapOuter = outerLoopParam
|
|
101
|
-
? (expr
|
|
102
|
-
:
|
|
114
|
+
const { levels, parentElVar, outerLoopParam, outerLoopParamBindings, outerLoopIndex, rowHasPortal } = args
|
|
115
|
+
const wrapOuter: ShadowableWrap = args.wrapOuter ?? (outerLoopParam
|
|
116
|
+
? (expr, shadowed) => wrapLoopParamAsAccessor(expr, outerLoopParam, outerLoopParamBindings, outerLoopIndex, shadowed)
|
|
117
|
+
: expr => expr)
|
|
103
118
|
|
|
104
119
|
const plan: InnerLoopPlan[] = []
|
|
105
120
|
let i = 0
|
|
@@ -119,7 +134,7 @@ export function buildInnerLoopsPlan(args: BuildInnerLoopsArgs): InnerLoopsPlan {
|
|
|
119
134
|
|
|
120
135
|
const uidSuffix = `${inner.depth}_${i}`
|
|
121
136
|
const containerExpr = inner.containerSlotId
|
|
122
|
-
?
|
|
137
|
+
? `${rowHasPortal ? 'qsaItem' : 'qsa'}(${parentElVar}, '[bf="${inner.containerSlotId}"]')`
|
|
123
138
|
: parentElVar
|
|
124
139
|
|
|
125
140
|
// #2865: every nested loop gets the full reactive `mapArray` emission,
|
|
@@ -137,6 +152,12 @@ export function buildInnerLoopsPlan(args: BuildInnerLoopsArgs): InnerLoopsPlan {
|
|
|
137
152
|
outerLoopParam: inner.param,
|
|
138
153
|
outerLoopParamBindings: inner.paramBindings,
|
|
139
154
|
outerLoopIndex: inner.index,
|
|
155
|
+
// This row's accessor over every enclosing one, so a deeper row
|
|
156
|
+
// still rewrites the outer rows' bindings (#3397).
|
|
157
|
+
wrapOuter: (expr, shadowed) => wrapLoopParamAsAccessor(
|
|
158
|
+
wrapOuter(expr, unionNames(rowBoundNames(inner), shadowed)),
|
|
159
|
+
inner.param, inner.paramBindings, inner.index, shadowed,
|
|
160
|
+
),
|
|
140
161
|
})
|
|
141
162
|
: []
|
|
142
163
|
|
|
@@ -165,14 +186,19 @@ export function buildInnerLoopsPlan(args: BuildInnerLoopsArgs): InnerLoopsPlan {
|
|
|
165
186
|
function buildReactiveEmit(
|
|
166
187
|
inner: NestedLoop,
|
|
167
188
|
level: DepthLevel,
|
|
168
|
-
wrapOuter:
|
|
189
|
+
wrapOuter: ShadowableWrap,
|
|
169
190
|
uidSuffix: string,
|
|
170
191
|
outerLoopParam?: string,
|
|
171
192
|
outerLoopParamBindings?: readonly LoopParamBinding[],
|
|
172
193
|
outerLoopIndex?: string | null,
|
|
173
194
|
): InnerLoopReactiveEmit {
|
|
174
195
|
const wrapInner = (expr: string) => wrapLoopParamAsAccessor(expr, inner.param, inner.paramBindings, inner.index)
|
|
175
|
-
|
|
196
|
+
// Inside the inner row, a name it rebinds (item, index, destructure
|
|
197
|
+
// binding, preamble local) is not the outer row's binding (#3394).
|
|
198
|
+
const innerShadowed = rowBoundNames(inner)
|
|
199
|
+
const wrapOuterRow: ShadowableWrap = (expr, shadowed) => wrapOuter(expr, unionNames(innerShadowed, shadowed))
|
|
200
|
+
const wrapBoth: ShadowableWrap = (expr, shadowed) =>
|
|
201
|
+
wrapLoopParamAsAccessor(wrapOuterRow(expr, shadowed), inner.param, inner.paramBindings, inner.index, shadowed)
|
|
176
202
|
const { head: paramHead, unwrap: paramUnwrap } = destructureLoopParam(inner.param, inner.paramBindings)
|
|
177
203
|
const wrappedKey = inner.key
|
|
178
204
|
? wrapLoopParamAsAccessor(inner.key, inner.param, inner.paramBindings, inner.index)
|
|
@@ -212,12 +238,12 @@ function buildReactiveEmit(
|
|
|
212
238
|
|
|
213
239
|
const reactiveTexts: InnerLoopText[] = inner.bindings.reactiveTexts.map(text => ({
|
|
214
240
|
slotId: text.slotId,
|
|
215
|
-
wrappedExpression: wrapLoopParamAsAccessor(
|
|
241
|
+
wrappedExpression: wrapLoopParamAsAccessor(wrapOuterRow(text.expression), inner.param, inner.paramBindings, inner.index),
|
|
216
242
|
insideConditional: !!text.insideConditional,
|
|
217
243
|
}))
|
|
218
244
|
|
|
219
245
|
const reactiveAttrs: InnerLoopReactiveAttr[] = inner.bindings.reactiveAttrs.map(attr => {
|
|
220
|
-
const wrapped = wrapLoopParamAsAccessor(
|
|
246
|
+
const wrapped = wrapLoopParamAsAccessor(wrapOuterRow(attr.expression), inner.param, inner.paramBindings, inner.index)
|
|
221
247
|
return {
|
|
222
248
|
slotId: attr.childSlotId,
|
|
223
249
|
attrName: attr.attrName,
|
|
@@ -247,15 +273,15 @@ function buildReactiveEmit(
|
|
|
247
273
|
if (paramUnwrap) preludeStatements.push(paramUnwrap)
|
|
248
274
|
if (inner.preamble) {
|
|
249
275
|
// Leaf JSX renders under both param contexts, mirroring the
|
|
250
|
-
// wrapInner(
|
|
276
|
+
// wrapInner(wrapOuterRow(...)) applied to the js text.
|
|
251
277
|
const leafLoopParams = outerLoopParam
|
|
252
278
|
? [
|
|
253
|
-
{ param: outerLoopParam, bindings: outerLoopParamBindings, index: outerLoopIndex },
|
|
279
|
+
{ param: outerLoopParam, bindings: outerLoopParamBindings, index: outerLoopIndex, shadowed: innerShadowed },
|
|
254
280
|
{ param: inner.param, bindings: inner.paramBindings, index: inner.index },
|
|
255
281
|
]
|
|
256
282
|
: [{ param: inner.param, bindings: inner.paramBindings, index: inner.index }]
|
|
257
283
|
preludeStatements.push(renderPreamble(inner.preamble, {
|
|
258
|
-
transformJs: (t) => wrapInner(
|
|
284
|
+
transformJs: (t) => wrapInner(wrapOuterRow(t)),
|
|
259
285
|
renderLeaf: (ir) => irToHtmlTemplate(ir, undefined, 1, leafLoopParams, undefined),
|
|
260
286
|
}))
|
|
261
287
|
}
|
|
@@ -24,7 +24,7 @@ import type {
|
|
|
24
24
|
LoopParamBinding,
|
|
25
25
|
} from '../../../types.ts'
|
|
26
26
|
import { AttrValueOf, pickAttrMeta } from '../../../types.ts'
|
|
27
|
-
import { quotePropName, wrapLoopParamAsAccessor, attrValueToString } from '../../utils.ts'
|
|
27
|
+
import { quotePropName, 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
|
|
|
@@ -234,7 +234,7 @@ export interface BuildBranchInnerLoopsArgs {
|
|
|
234
234
|
* Outer-wrap closure — defaults to wrapping with `outerLoopParam`. Overridden
|
|
235
235
|
* by `emitNestedLoopChildConditionals` recursion (which threads its own wrap).
|
|
236
236
|
*/
|
|
237
|
-
wrapOuter:
|
|
237
|
+
wrapOuter: ShadowableWrap
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
/**
|
|
@@ -269,7 +269,14 @@ export function buildBranchInnerLoopsPlan(
|
|
|
269
269
|
if (!inner.template) continue
|
|
270
270
|
|
|
271
271
|
const wrapInner = (expr: string) => wrapLoopParamAsAccessor(expr, inner.param, inner.paramBindings, inner.index)
|
|
272
|
-
|
|
272
|
+
// Inside the inner row, a name it rebinds is not the outer row's
|
|
273
|
+
// binding (#3394).
|
|
274
|
+
// `wrapOuter` already composes every enclosing loop's rewrite; pass the
|
|
275
|
+
// shadowed names through it so each of them skips them.
|
|
276
|
+
const innerShadowed = rowBoundNames(inner)
|
|
277
|
+
const wrapOuterRow: ShadowableWrap = (expr, shadowed) => wrapOuter(expr, unionNames(innerShadowed, shadowed))
|
|
278
|
+
const wrapBoth: ShadowableWrap = (expr, shadowed) =>
|
|
279
|
+
wrapLoopParamAsAccessor(wrapOuterRow(expr, shadowed), inner.param, inner.paramBindings, inner.index, shadowed)
|
|
273
280
|
|
|
274
281
|
const csl = inner.containerSlotId
|
|
275
282
|
// Inner loop's container: host-side `bf="<slot>"` slot marker first,
|
|
@@ -378,7 +385,7 @@ export interface BuildLoopChildConditionalsArgs {
|
|
|
378
385
|
/** Element variable used as `insert(scopeVar, ...)` first arg. */
|
|
379
386
|
scopeVar: string
|
|
380
387
|
/** Wrap closure for condition / HTML / handlers. */
|
|
381
|
-
wrap:
|
|
388
|
+
wrap: ShadowableWrap
|
|
382
389
|
/**
|
|
383
390
|
* Loop param identifier — the wrap that wires the recursion's nested
|
|
384
391
|
* inner loops uses this. Typically equals the inner loop's param when
|
|
@@ -501,7 +508,7 @@ export function buildArmTextsPlan(
|
|
|
501
508
|
|
|
502
509
|
interface BuildLoopChildArmArgs {
|
|
503
510
|
branch: LoopChildBranchSummary
|
|
504
|
-
wrap:
|
|
511
|
+
wrap: ShadowableWrap
|
|
505
512
|
loopParam: string
|
|
506
513
|
loopParamBindings?: readonly LoopParamBinding[]
|
|
507
514
|
/** Loop's index param name, when it declares one (#2861). */
|
|
@@ -29,7 +29,7 @@ import type {
|
|
|
29
29
|
} from '../../types.ts'
|
|
30
30
|
import type { LoopParamBinding } from '../../../types.ts'
|
|
31
31
|
import { pickAttrMeta } from '../../../types.ts'
|
|
32
|
-
import { wrapLoopParamAsAccessor } from '../../utils.ts'
|
|
32
|
+
import { wrapLoopParamAsAccessor, type ShadowableWrap } from '../../utils.ts'
|
|
33
33
|
import { addCondAttrToTemplate } from '../../html-template.ts'
|
|
34
34
|
import {
|
|
35
35
|
buildArmAttrsPlan,
|
|
@@ -65,7 +65,7 @@ export function buildReactiveEffectsPlan(
|
|
|
65
65
|
args: BuildReactiveEffectsArgs,
|
|
66
66
|
): ReactiveEffectsPlan {
|
|
67
67
|
const { attrs, texts, conditionals, loopParam, loopParamBindings, loopIndex, profileComponentName } = args
|
|
68
|
-
const wrap = (expr
|
|
68
|
+
const wrap: ShadowableWrap = (expr, shadowed) => wrapLoopParamAsAccessor(expr, loopParam, loopParamBindings, loopIndex, shadowed)
|
|
69
69
|
|
|
70
70
|
// 1. Group attrs by slot, preserving declaration order (Map insertion order
|
|
71
71
|
// matches the legacy iteration that produced byte-identical output).
|
|
@@ -46,6 +46,13 @@ export interface EventDelegationPlan {
|
|
|
46
46
|
* (the common case: no collision) keeps the emitted listener unchanged.
|
|
47
47
|
*/
|
|
48
48
|
ownHandlers?: Map<string, ContainerOwnHandler>
|
|
49
|
+
/**
|
|
50
|
+
* A row of this loop portals an element out of the container (#3318).
|
|
51
|
+
* The stringifier then also relays each listener to the adopted elements
|
|
52
|
+
* (`relayRowPortalEvents`) and accepts slot matches inside them
|
|
53
|
+
* (`isRowPortalOf`). `undefined` keeps the emitted listener unchanged.
|
|
54
|
+
*/
|
|
55
|
+
relayRowPortals?: boolean
|
|
49
56
|
}
|
|
50
57
|
|
|
51
58
|
/**
|
|
@@ -117,6 +117,8 @@ export interface ArmTextEffect {
|
|
|
117
117
|
*/
|
|
118
118
|
export interface ArmReactiveAttr extends AttrMeta {
|
|
119
119
|
slotId: string
|
|
120
|
+
/** See `ConditionalBranchReactiveAttr.receiverSlotIds` (#3324). */
|
|
121
|
+
receiverSlotIds?: readonly string[]
|
|
120
122
|
attrName: string
|
|
121
123
|
expression: string
|
|
122
124
|
}
|
|
@@ -112,6 +112,8 @@ export interface LoopChildRefBinding {
|
|
|
112
112
|
* `reactiveAttrs` are already handled on the static path.
|
|
113
113
|
*/
|
|
114
114
|
callback: string
|
|
115
|
+
/** The callback portals the element out of the row (#3318); see `LoopChildRef.ssrPortalOwner`. */
|
|
116
|
+
ssrPortalOwner?: boolean
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
/**
|
|
@@ -154,6 +154,7 @@ export function buildChildRefBindings(
|
|
|
154
154
|
return refs.map(r => ({
|
|
155
155
|
childSlotId: r.childSlotId,
|
|
156
156
|
callback: wrapLoopParamAsAccessor(r.callback, loopParam, loopParamBindings, loopIndex),
|
|
157
|
+
...(r.ssrPortalOwner && { ssrPortalOwner: true }),
|
|
157
158
|
}))
|
|
158
159
|
}
|
|
159
160
|
|
|
@@ -173,6 +174,7 @@ export function buildStaticChildRefBindings(
|
|
|
173
174
|
return refs.map(r => ({
|
|
174
175
|
childSlotId: r.childSlotId,
|
|
175
176
|
callback: r.callback,
|
|
177
|
+
...(r.ssrPortalOwner && { ssrPortalOwner: true }),
|
|
176
178
|
}))
|
|
177
179
|
}
|
|
178
180
|
|
|
@@ -230,7 +232,10 @@ export function destructureLoopParam(
|
|
|
230
232
|
): { head: string; unwrap: string } {
|
|
231
233
|
if (param.startsWith('[') || param.startsWith('{')) {
|
|
232
234
|
if (paramBindings && paramBindings.length > 0) {
|
|
233
|
-
|
|
235
|
+
// A nested row names its accessor after its loop (`withRowAccessor`,
|
|
236
|
+
// #3397), so it does not shadow an enclosing row's `__bfItem`.
|
|
237
|
+
const accessor = paramBindings[0].accessor
|
|
238
|
+
return { head: accessor ? accessor.replace(/\(\)$/, '') : '__bfItem', unwrap: '' }
|
|
234
239
|
}
|
|
235
240
|
return {
|
|
236
241
|
head: '__bfItem',
|
|
@@ -14,7 +14,7 @@ import { stringifyCompositeLoop } from './composite-loop.ts'
|
|
|
14
14
|
import { stringifyEventDelegation } from './event-delegation.ts'
|
|
15
15
|
import { stringifyReactiveEffects } from './reactive-effects.ts'
|
|
16
16
|
import { emitTemplateCloneInline, emitLoopItemElementSetup } from './template-parse.ts'
|
|
17
|
-
import { emitLoopChildRefs } from './loop.ts'
|
|
17
|
+
import { emitLoopChildRefs, emitRowPortalClaim, rowPortalSlotIds } from './loop.ts'
|
|
18
18
|
import { stringifyLazyRowLoop } from './lazy-row.ts'
|
|
19
19
|
import type {
|
|
20
20
|
BranchLoopPlan,
|
|
@@ -137,6 +137,9 @@ function emitPlain(lines: string[], plan: BranchPlainLoopPlan): void {
|
|
|
137
137
|
indent: ' ',
|
|
138
138
|
singleRootLayout: 'inline',
|
|
139
139
|
})
|
|
140
|
+
// See `stringifyPlainLoop` (#3318).
|
|
141
|
+
emitRowPortalClaim(lines, childRefs, { indent: ' ', containerVar })
|
|
142
|
+
const itemLookup = bodyIsMultiRoot || rowPortalSlotIds(childRefs).length > 0
|
|
140
143
|
if (reactiveEffects !== null || preambleRegions.length > 0) {
|
|
141
144
|
// Row-granularity effects (§3(c)): mirrors `stringifyPlainLoop`'s
|
|
142
145
|
// top-level call — attrs, outer texts, and preamble regions merge
|
|
@@ -144,12 +147,12 @@ function emitPlain(lines: string[], plan: BranchPlainLoopPlan): void {
|
|
|
144
147
|
stringifyReactiveEffects(lines, reactiveEffects, {
|
|
145
148
|
indent: ' ',
|
|
146
149
|
elVar: '__el',
|
|
147
|
-
bodyIsMultiRoot,
|
|
150
|
+
bodyIsMultiRoot: itemLookup,
|
|
148
151
|
preambleRegions,
|
|
149
152
|
mapPreambleWrapped,
|
|
150
153
|
})
|
|
151
154
|
}
|
|
152
|
-
emitLoopChildRefs(lines, childRefs, { indent: ' ', elVar: '__el', bodyIsMultiRoot })
|
|
155
|
+
emitLoopChildRefs(lines, childRefs, { indent: ' ', elVar: '__el', bodyIsMultiRoot: itemLookup, containerVar })
|
|
153
156
|
lines.push(` return __el`)
|
|
154
157
|
lines.push(` }, '${markerId}'${loopBfId})`)
|
|
155
158
|
}
|
|
@@ -34,7 +34,7 @@ import { emitComponentAndEventSetup } from '../shared.ts'
|
|
|
34
34
|
import { stringifyInnerLoops } from './inner-loop.ts'
|
|
35
35
|
import { stringifyReactiveEffects } from './reactive-effects.ts'
|
|
36
36
|
import { emitLoopItemElementSetup } from './template-parse.ts'
|
|
37
|
-
import { emitLoopChildRefs } from './loop.ts'
|
|
37
|
+
import { emitLoopChildRefs, emitRowPortalClaim, rowPortalSlotIds } from './loop.ts'
|
|
38
38
|
import type { CompositeLoopPlan } from '../plan/types.ts'
|
|
39
39
|
|
|
40
40
|
export function stringifyCompositeLoop(lines: string[], plan: CompositeLoopPlan): void {
|
|
@@ -125,16 +125,19 @@ export function stringifyCompositeLoop(lines: string[], plan: CompositeLoopPlan)
|
|
|
125
125
|
// variant whose tail needs the row already connected.
|
|
126
126
|
mountRow: true,
|
|
127
127
|
})
|
|
128
|
-
|
|
128
|
+
// See `stringifyPlainLoop` (#3318).
|
|
129
|
+
emitRowPortalClaim(lines, childRefs, { indent: bodyIndent, containerVar })
|
|
130
|
+
const itemLookup = bodyIsMultiRoot || rowPortalSlotIds(childRefs).length > 0
|
|
131
|
+
emitComponentAndEventSetup(lines, bodyIndent, '__el', compsArr, eventsArr, loopParam, loopParamBindings, itemLookup, loopIndex)
|
|
129
132
|
if (innerLoops.length > 0) {
|
|
130
133
|
stringifyInnerLoops(lines, innerLoops, bodyIndent, pc)
|
|
131
134
|
}
|
|
132
135
|
|
|
133
136
|
if (reactiveEffects) {
|
|
134
|
-
stringifyReactiveEffects(lines, reactiveEffects, { indent: bodyIndent, elVar: '__el', bodyIsMultiRoot })
|
|
137
|
+
stringifyReactiveEffects(lines, reactiveEffects, { indent: bodyIndent, elVar: '__el', bodyIsMultiRoot: itemLookup })
|
|
135
138
|
}
|
|
136
139
|
|
|
137
|
-
emitLoopChildRefs(lines, childRefs, { indent: bodyIndent, elVar: '__el', bodyIsMultiRoot })
|
|
140
|
+
emitLoopChildRefs(lines, childRefs, { indent: bodyIndent, elVar: '__el', bodyIsMultiRoot: itemLookup, containerVar })
|
|
138
141
|
|
|
139
142
|
lines.push(`${bodyIndent}return __el`)
|
|
140
143
|
const loopBfId = profileLoopId ? `, ${JSON.stringify(profileLoopId)}` : ''
|
|
@@ -101,7 +101,7 @@ function preambleLineForHandler(
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
export function stringifyEventDelegation(lines: string[], plan: EventDelegationPlan): void {
|
|
104
|
-
const { containerVar, events, itemLookup, profileComponentName, ownHandlers } = plan
|
|
104
|
+
const { containerVar, events, itemLookup, profileComponentName, ownHandlers, relayRowPortals } = plan
|
|
105
105
|
const eventsByName = new Map<string, LoopChildEvent[]>()
|
|
106
106
|
for (const ev of events) {
|
|
107
107
|
if (!eventsByName.has(ev.eventName)) eventsByName.set(ev.eventName, [])
|
|
@@ -121,10 +121,14 @@ export function stringifyEventDelegation(lines: string[], plan: EventDelegationP
|
|
|
121
121
|
const ownHandlerCall = ownHandler
|
|
122
122
|
? withTurn(`(${ownHandler.handler.trim()})(__bfEvt)`, profileComponentName, ownHandler.slotId, ownHandler.eventName)
|
|
123
123
|
: null
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
const listenedName = useCapture ? eventName : domEventName
|
|
125
|
+
if (relayRowPortals) {
|
|
126
|
+
// Named so the same listener can also be relayed to the elements rows
|
|
127
|
+
// portal out of the container (#3318).
|
|
128
|
+
lines.push(` if (${containerVar}) {`)
|
|
129
|
+
lines.push(` const __bfDl = (__bfEvt) => {`)
|
|
126
130
|
} else {
|
|
127
|
-
lines.push(` if (${containerVar}) ${containerVar}.addEventListener('${
|
|
131
|
+
lines.push(` if (${containerVar}) ${containerVar}.addEventListener('${listenedName}', (__bfEvt) => {`)
|
|
128
132
|
}
|
|
129
133
|
lines.push(` const target = __bfEvt.target`)
|
|
130
134
|
for (const ev of evs) {
|
|
@@ -137,7 +141,12 @@ export function stringifyEventDelegation(lines: string[], plan: EventDelegationP
|
|
|
137
141
|
// the `container.contains(...)` guard rejects the foreign match and the
|
|
138
142
|
// handler falls through to the correct branch.
|
|
139
143
|
lines.push(` const ${childVar}El = target.closest('[bf="${ev.childSlotId}"]')`)
|
|
140
|
-
|
|
144
|
+
// A row-portaled element sits outside the container; the registry
|
|
145
|
+
// vouches for it instead (#3318).
|
|
146
|
+
const inContainer = relayRowPortals
|
|
147
|
+
? `(${containerVar}.contains(${childVar}El) || isRowPortalOf(${childVar}El, ${containerVar}))`
|
|
148
|
+
: `${containerVar}.contains(${childVar}El)`
|
|
149
|
+
lines.push(` if (${childVar}El && ${inContainer}) {`)
|
|
141
150
|
const handlerCall = withTurn(`(${ev.handler.trim()})(__bfEvt)`, profileComponentName, ev.childSlotId, ev.eventName)
|
|
142
151
|
switch (itemLookup.kind) {
|
|
143
152
|
case 'keyed':
|
|
@@ -179,7 +188,13 @@ export function stringifyEventDelegation(lines: string[], plan: EventDelegationP
|
|
|
179
188
|
// own handler still fires — same as today's separate listener.
|
|
180
189
|
lines.push(` if (!__bfEvt.cancelBubble) { ${ownHandlerCall} }`)
|
|
181
190
|
}
|
|
182
|
-
if (
|
|
191
|
+
if (relayRowPortals) {
|
|
192
|
+
const captureArg = useCapture ? ', true' : ''
|
|
193
|
+
lines.push(` }`)
|
|
194
|
+
lines.push(` ${containerVar}.addEventListener('${listenedName}', __bfDl${captureArg})`)
|
|
195
|
+
lines.push(` relayRowPortalEvents(${containerVar}, '${listenedName}', __bfDl${captureArg})`)
|
|
196
|
+
lines.push(` }`)
|
|
197
|
+
} else if (useCapture) {
|
|
183
198
|
lines.push(` }, true)`)
|
|
184
199
|
} else {
|
|
185
200
|
lines.push(` })`)
|
|
@@ -162,7 +162,12 @@ function emitArmBody(
|
|
|
162
162
|
for (const [slotId, attrs] of attrsBySlot) {
|
|
163
163
|
const v = varSlotId(slotId)
|
|
164
164
|
const elVar = `__ra_${v}`
|
|
165
|
-
|
|
165
|
+
// A parent-owned slot passes the components it is forwarded into, so
|
|
166
|
+
// the lookup can cross into their scopes without resolving another
|
|
167
|
+
// component's same-numbered forwarded element (#3324).
|
|
168
|
+
const receivers = attrs[0].receiverSlotIds
|
|
169
|
+
const receiverArg = receivers && receivers.length > 0 ? `, ${JSON.stringify(receivers)}` : ''
|
|
170
|
+
lines.push(`${indent}{ const ${elVar} = qsa(__branchScope, '[bf="${slotId}"]'${receiverArg})`)
|
|
166
171
|
lines.push(`${indent}${DEDUP_STORE_DECL}`)
|
|
167
172
|
lines.push(`${indent}if (${elVar}) {`)
|
|
168
173
|
let ordinal = 0
|