@barefootjs/jsx 0.40.0 → 0.40.1
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 +41 -0
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +1 -0
- package/dist/adapters/attr-plan.d.ts.map +1 -1
- package/dist/adapters/boolean-carrier.d.ts +31 -0
- package/dist/adapters/boolean-carrier.d.ts.map +1 -0
- package/dist/adapters/component-props.d.ts +22 -7
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/computed-const.d.ts +17 -0
- package/dist/adapters/computed-const.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +18 -1
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
- package/dist/adapters/number-value.d.ts +43 -0
- package/dist/adapters/number-value.d.ts.map +1 -0
- package/dist/analyzer-context.d.ts +7 -0
- package/dist/analyzer-context.d.ts.map +1 -1
- package/dist/analyzer.d.ts +34 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/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 +1006 -351
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts +29 -0
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-reactive-effects.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts +5 -4
- package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +15 -0
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts +20 -0
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/lazy-row.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts +3 -2
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/build-static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +7 -1
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/safe-html.d.ts +9 -3
- package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +30 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +8 -0
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +29 -3
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/props-binding.d.ts +27 -3
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/scope/binding-scope.d.ts +22 -1
- package/dist/scope/binding-scope.d.ts.map +1 -1
- package/dist/scope/root-prop-alias.d.ts +14 -1
- package/dist/scope/root-prop-alias.d.ts.map +1 -1
- package/dist/signal-prop-name-collision.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +4 -2
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/ssr-seed-plan.d.ts +14 -0
- package/dist/ssr-seed-plan.d.ts.map +1 -1
- package/dist/template-parts.d.ts.map +1 -1
- package/dist/types.d.ts +30 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/binding-scope-ratchet.test.ts +12 -2
- package/src/__tests__/boolean-carrier.test.ts +74 -0
- package/src/__tests__/component-props.test.ts +14 -0
- package/src/__tests__/computed-const.test.ts +85 -0
- package/src/__tests__/expression-parser.test.ts +24 -0
- package/src/__tests__/issue-3688-props-spread-child-csr.test.ts +142 -0
- package/src/__tests__/loop-row-prop-read.test.ts +111 -0
- package/src/__tests__/memo-body-expr.test.ts +137 -0
- package/src/__tests__/nullable-signal-attr.test.ts +97 -2
- package/src/__tests__/profile-binding-ids.test.ts +14 -0
- package/src/__tests__/root-prop-alias.test.ts +34 -1
- package/src/__tests__/signal-prop-name-collision.test.ts +102 -2
- package/src/__tests__/source-file-cache.test.ts +105 -0
- package/src/__tests__/ssr-seed-plan.test.ts +43 -0
- package/src/__tests__/template-parts-literal-boundary.test.ts +19 -0
- package/src/adapters/ambiguous-nil-arithmetic.ts +94 -0
- package/src/adapters/attr-plan.ts +6 -2
- package/src/adapters/boolean-carrier.ts +76 -0
- package/src/adapters/component-props.ts +28 -8
- package/src/adapters/computed-const.ts +206 -7
- package/src/adapters/dsl-template-adapter.ts +39 -0
- package/src/adapters/number-value.ts +95 -0
- package/src/analyzer-context.ts +8 -0
- package/src/analyzer.ts +187 -66
- package/src/expression-parser.ts +4 -1
- package/src/index.ts +12 -2
- package/src/ir-to-client-js/collect-elements.ts +104 -46
- package/src/ir-to-client-js/compute-inlinability.ts +1 -1
- package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +15 -1
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +79 -4
- package/src/ir-to-client-js/control-flow/plan/build-lazy-row.ts +3 -0
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +1 -0
- package/src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts +1 -0
- package/src/ir-to-client-js/control-flow/plan/inner-loop.ts +5 -4
- package/src/ir-to-client-js/control-flow/plan/loop-child-arm.ts +2 -0
- package/src/ir-to-client-js/control-flow/plan/loop.ts +12 -0
- package/src/ir-to-client-js/control-flow/plan/reactive-effects.ts +2 -0
- package/src/ir-to-client-js/control-flow/shared.ts +3 -2
- package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +27 -0
- package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +8 -2
- package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +8 -1
- package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +8 -7
- package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +8 -7
- package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +4 -4
- package/src/ir-to-client-js/control-flow/stringify/loop.ts +3 -3
- package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +6 -6
- package/src/ir-to-client-js/emit-reactive.ts +1 -1
- package/src/ir-to-client-js/html-template.ts +70 -30
- package/src/ir-to-client-js/plan/build-static-array-child-init.ts +11 -1
- package/src/ir-to-client-js/plan/static-array-child-init.ts +7 -1
- package/src/ir-to-client-js/reactivity.ts +14 -0
- package/src/ir-to-client-js/safe-html.ts +11 -4
- package/src/ir-to-client-js/stringify/static-array-child-init.ts +6 -4
- package/src/ir-to-client-js/types.ts +23 -0
- package/src/ir-to-client-js/utils.ts +15 -1
- package/src/jsx-to-ir.ts +78 -35
- package/src/nullable-signal-attr.ts +134 -13
- package/src/props-binding.ts +54 -3
- package/src/scope/binding-scope.ts +30 -2
- package/src/scope/root-prop-alias.ts +17 -1
- package/src/signal-prop-name-collision.ts +113 -22
- package/src/ssr-defaults.ts +10 -4
- package/src/ssr-seed-plan.ts +82 -17
- package/src/template-parts.ts +21 -1
- package/src/types.ts +30 -0
|
@@ -732,7 +732,7 @@ export function emitReactivePropBindings(lines: string[], ctx: ClientJsContext):
|
|
|
732
732
|
const ref = slotId === ctx.commentScopeRootSlotId ? '__scope' : `_${varSlotId(slotId)}`
|
|
733
733
|
lines.push(` if (${ref}) {`)
|
|
734
734
|
for (const prop of props) {
|
|
735
|
-
const value =
|
|
735
|
+
const value = prop.expression
|
|
736
736
|
if (prop.propName === 'selected') {
|
|
737
737
|
if (prop.componentName === 'TabsContent') {
|
|
738
738
|
lines.push(` ${ref}.setAttribute('data-state', ${value} ? 'active' : 'inactive')`)
|
|
@@ -238,11 +238,13 @@ function maybeHoistedScopeAttr(
|
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
/**
|
|
241
|
-
*
|
|
242
|
-
* references an init-body-only name (#1128)
|
|
243
|
-
*
|
|
244
|
-
* array for an empty array literal, or short-circuit a text expression
|
|
245
|
-
* an empty string
|
|
241
|
+
* Spelling the CSR template's `transformExpr` emits when the expression
|
|
242
|
+
* references an init-body-only name (#1128), so a position that just
|
|
243
|
+
* evaluates it reads `undefined`. Sites that drop a renderChild prop, swap a
|
|
244
|
+
* loop array for an empty array literal, or short-circuit a text expression
|
|
245
|
+
* to an empty string decide that from `transformExprOrUnsafe`'s `null`, not
|
|
246
|
+
* from equality with this string: a source written as the literal
|
|
247
|
+
* `undefined` spells the same (#3752). Module-internal.
|
|
246
248
|
*/
|
|
247
249
|
const UNSAFE_TEMPLATE_EXPR = 'undefined'
|
|
248
250
|
|
|
@@ -393,6 +395,26 @@ function renderTemplateAttrPart(
|
|
|
393
395
|
}
|
|
394
396
|
}
|
|
395
397
|
|
|
398
|
+
/**
|
|
399
|
+
* Whether a child-component call's prop reaches the CSR `renderChild(...)`
|
|
400
|
+
* props object. Explicit props do (`key` is the call's own identity, not a
|
|
401
|
+
* prop). A spread does when it is the component's own props object
|
|
402
|
+
* (`SpreadAttr.propsObject`, decided in Phase 1): kept in source order next
|
|
403
|
+
* to the explicit props, the object literal merges like the JSX call does
|
|
404
|
+
* (#3688) — a later key overrides an earlier one, and the spread overrides
|
|
405
|
+
* only the keys the caller passed. Any other spread stays out.
|
|
406
|
+
*/
|
|
407
|
+
function keepsTemplateComponentProp(p: IRProp): boolean {
|
|
408
|
+
if (p.name === 'key') return false
|
|
409
|
+
if (p.name === '...' || p.name.startsWith('...')) return p.value.kind === 'spread' && p.value.propsObject === true
|
|
410
|
+
return true
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/** One `renderChild(...)` props-object entry: `name: value`, or `...value` for a spread. */
|
|
414
|
+
function templatePropEntry(p: IRProp, valueExpr: string): string {
|
|
415
|
+
return p.name === '...' || p.name.startsWith('...') ? `...${valueExpr}` : `${quotePropName(p.name)}: ${valueExpr}`
|
|
416
|
+
}
|
|
417
|
+
|
|
396
418
|
/**
|
|
397
419
|
* Source-of-truth predicates for the collision-safe spread-attrs merge
|
|
398
420
|
* shared by all three CSR-side emit paths (`irToHtmlTemplate`,
|
|
@@ -873,7 +895,7 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
|
|
|
873
895
|
// This allows stateless components in conditional branches to render their content
|
|
874
896
|
// instead of emitting empty placeholders (#435).
|
|
875
897
|
const propsEntries = node.props
|
|
876
|
-
.filter(
|
|
898
|
+
.filter(keepsTemplateComponentProp)
|
|
877
899
|
// `ref` joins the `on*` handlers here: a function prop cannot run
|
|
878
900
|
// during module-scope string rendering, and a ref closing over an
|
|
879
901
|
// init-scope setter would leak it into the template (#2468). The
|
|
@@ -927,7 +949,7 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
|
|
|
927
949
|
// previously masked by the post-hoc `wrapLoopParamAsAccessor`
|
|
928
950
|
// pass over the whole branch string, which #2868 removed.
|
|
929
951
|
const expr = wrapExpr(attrValueToString(p.value, { useTemplate: true }) ?? 'undefined')
|
|
930
|
-
return
|
|
952
|
+
return templatePropEntry(p, expr)
|
|
931
953
|
}
|
|
932
954
|
}
|
|
933
955
|
})
|
|
@@ -1581,7 +1603,15 @@ function irNodeToJsExprs(node: IRNode, brandMarkup = false): string[] {
|
|
|
1581
1603
|
}
|
|
1582
1604
|
|
|
1583
1605
|
const propsExpr = propsEntries.length > 0 ? `{ ${propsEntries.join(', ')} }` : '{}'
|
|
1584
|
-
|
|
1606
|
+
// A slotted child gets the same slot identity SSR stamps on it
|
|
1607
|
+
// (`bf-h` = the authoring component, `bf-m` = its slot), so a
|
|
1608
|
+
// client-built tree matches the server's and a lookup of content
|
|
1609
|
+
// forwarded through it can tell it is a receiver (#3695). A loop row
|
|
1610
|
+
// root never takes a slot (`createComponent`'s own contract).
|
|
1611
|
+
const slotArg = node.slotId && !node.loopItemRoot
|
|
1612
|
+
? `, undefined, { parent: __scopeId, mount: '${node.slotId}' }`
|
|
1613
|
+
: ''
|
|
1614
|
+
return [`createComponent('${nameForRegistryRef(node.name)}', ${propsExpr}${slotArg})`]
|
|
1585
1615
|
}
|
|
1586
1616
|
|
|
1587
1617
|
case 'expression':
|
|
@@ -1736,8 +1766,9 @@ export interface TemplateOptions {
|
|
|
1736
1766
|
* (the literal token `'undefined'`) whenever the resulting expression
|
|
1737
1767
|
* still references one of these names. The init function's
|
|
1738
1768
|
* `createEffect` / `initChild` bindings populate the real value once
|
|
1739
|
-
* init runs. Per-context guards (loop array, text expression
|
|
1740
|
-
*
|
|
1769
|
+
* init runs. Per-context guards (loop array, text expression, child
|
|
1770
|
+
* prop) test `transformExprOrUnsafe`'s `null` instead and translate it
|
|
1771
|
+
* into something safe for that AST position.
|
|
1741
1772
|
*/
|
|
1742
1773
|
unsafeLocalNames?: Set<string>
|
|
1743
1774
|
/**
|
|
@@ -2031,7 +2062,7 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
|
|
|
2031
2062
|
|
|
2032
2063
|
// Use renderChild() to render child component's template at runtime (#435)
|
|
2033
2064
|
const propsEntries = node.props
|
|
2034
|
-
.filter(
|
|
2065
|
+
.filter(keepsTemplateComponentProp)
|
|
2035
2066
|
// `ref` joins the `on*` handlers here: a function prop cannot run
|
|
2036
2067
|
// during module-scope string rendering, and a ref closing over an
|
|
2037
2068
|
// init-scope setter would leak it into the template (#2468). The
|
|
@@ -2059,7 +2090,7 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
|
|
|
2059
2090
|
case 'expression':
|
|
2060
2091
|
return `${quotePropName(p.name)}: ${transformExpr(p.value.expr, p.value.templateExpr)}`
|
|
2061
2092
|
case 'spread':
|
|
2062
|
-
return
|
|
2093
|
+
return templatePropEntry(p, transformExpr(p.value.expr, p.value.templateExpr))
|
|
2063
2094
|
case 'template': {
|
|
2064
2095
|
const valueStr = attrValueToString(p.value, { useTemplate: true })!
|
|
2065
2096
|
return `${quotePropName(p.name)}: ${transformExpr(valueStr)}`
|
|
@@ -2471,7 +2502,14 @@ export function computeDeferredChildSlots(
|
|
|
2471
2502
|
function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): string {
|
|
2472
2503
|
const { restSpreadNames, propsObjectName, restPropsName, csrEnv, unsafeLocalNames, loopDepth = 0 } = opts
|
|
2473
2504
|
const env: CsrEnv = csrEnv ?? { substitutions: new Map(), propsObjectName: propsObjectName ?? null }
|
|
2474
|
-
|
|
2505
|
+
// `null` when the expression cannot run in the module-scope template
|
|
2506
|
+
// (it writes a binding or reads an init-only name). Call sites that drop
|
|
2507
|
+
// or replace such an expression test this, not `transformExpr`'s
|
|
2508
|
+
// `UNSAFE_TEMPLATE_EXPR` spelling: that sentinel is also what a source
|
|
2509
|
+
// written as the literal `undefined` transforms to, and a child prop
|
|
2510
|
+
// `label={undefined}` must keep its key (it overrides an earlier
|
|
2511
|
+
// spread value, #3752).
|
|
2512
|
+
const transformExprOrUnsafe = (expr: JsSourceText, templateExpr?: JsSourceText): string | null => {
|
|
2475
2513
|
// Single AST substitution pass: replaces signal getter calls
|
|
2476
2514
|
// (`count()` → `(initialValue)`), memo calls (`bars()` → `(body)`),
|
|
2477
2515
|
// and inlinable-const refs (`label` → `(rewrittenValue)`) in one
|
|
@@ -2486,7 +2524,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2486
2524
|
// An expression that writes a binding (`{++nextId}`, a child prop
|
|
2487
2525
|
// `() => ++start`) cannot run here: the template has no binding to
|
|
2488
2526
|
// write, and the write belongs to init's run of the component.
|
|
2489
|
-
if (writes.size > 0) return
|
|
2527
|
+
if (writes.size > 0) return null
|
|
2490
2528
|
|
|
2491
2529
|
// The CSR template runs at module scope, so any post-substitution
|
|
2492
2530
|
// free identifier that lands in `unsafeLocalNames` (init-body-only
|
|
@@ -2501,7 +2539,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2501
2539
|
// (and its `'foo-className'` / `a.className` false-match risk)
|
|
2502
2540
|
// is gone (#1267 / #1277).
|
|
2503
2541
|
if (unsafeLocalNames && unsafeLocalNames.size > 0 && setIntersects(freeIdentifiers, unsafeLocalNames)) {
|
|
2504
|
-
return
|
|
2542
|
+
return null
|
|
2505
2543
|
}
|
|
2506
2544
|
// Final emit-form: rewrite `propsName.X → _p.X` (and a direct
|
|
2507
2545
|
// rest-bag read, `restName.X → _p.X` — the rest binding IS `_p` at
|
|
@@ -2514,6 +2552,8 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2514
2552
|
// gate — #1138).
|
|
2515
2553
|
return rewritePropsObjectRef(rewritten, propsObjectName ?? null, restPropsName ?? null, { enclosingScope: opts.scope })
|
|
2516
2554
|
}
|
|
2555
|
+
const transformExpr = (expr: JsSourceText, templateExpr?: JsSourceText): string =>
|
|
2556
|
+
transformExprOrUnsafe(expr, templateExpr) ?? UNSAFE_TEMPLATE_EXPR
|
|
2517
2557
|
|
|
2518
2558
|
// `recurse` preserves `inHoistedChildren` for structural pass-through
|
|
2519
2559
|
// (fragment / conditional); `childrenRecurse` clears it — a new element
|
|
@@ -2656,12 +2696,12 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2656
2696
|
return `<!--bf:${node.slotId}--><!--/-->`
|
|
2657
2697
|
}
|
|
2658
2698
|
{
|
|
2659
|
-
const transformed =
|
|
2699
|
+
const transformed = transformExprOrUnsafe(node.expr, node.templateExpr)
|
|
2660
2700
|
// Init-body-only refs would render the literal text "undefined"
|
|
2661
2701
|
// before init's createEffect overwrites the slot (#1128). Emit
|
|
2662
2702
|
// an empty placeholder instead — a literal, so it bypasses the door.
|
|
2663
2703
|
const hole = interp(
|
|
2664
|
-
transformed ===
|
|
2704
|
+
transformed === null
|
|
2665
2705
|
? EMPTY_MARKUP
|
|
2666
2706
|
: spliceChildValue(node, transformed, { markupSlotIds: opts.markupSlotIds }),
|
|
2667
2707
|
)
|
|
@@ -2706,7 +2746,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2706
2746
|
}
|
|
2707
2747
|
|
|
2708
2748
|
const propsEntries = node.props
|
|
2709
|
-
.filter(
|
|
2749
|
+
.filter(keepsTemplateComponentProp)
|
|
2710
2750
|
// `ref` joins the `on*` handlers here: a function prop cannot run
|
|
2711
2751
|
// during module-scope string rendering, and a ref closing over an
|
|
2712
2752
|
// init-scope setter would leak it into the template (#2468). The
|
|
@@ -2737,18 +2777,19 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2737
2777
|
return `${quotePropName(p.name)}: true`
|
|
2738
2778
|
case 'expression':
|
|
2739
2779
|
case 'spread': {
|
|
2740
|
-
const transformed =
|
|
2741
|
-
//
|
|
2742
|
-
//
|
|
2743
|
-
//
|
|
2744
|
-
|
|
2745
|
-
|
|
2780
|
+
const transformed = transformExprOrUnsafe(p.value.expr, p.value.templateExpr)
|
|
2781
|
+
// An init-scope-only reference (#1128) drops the prop from
|
|
2782
|
+
// renderChild — initChild's getter binding will populate it once
|
|
2783
|
+
// init runs. A prop written as the literal `undefined` is not
|
|
2784
|
+
// unsafe and keeps its key (#3752).
|
|
2785
|
+
if (transformed === null) return null
|
|
2786
|
+
return templatePropEntry(p, transformed)
|
|
2746
2787
|
}
|
|
2747
2788
|
case 'template': {
|
|
2748
2789
|
const valueStr = attrValueToString(p.value, { useTemplate: true })
|
|
2749
2790
|
if (!valueStr) return null
|
|
2750
|
-
const transformed =
|
|
2751
|
-
if (transformed ===
|
|
2791
|
+
const transformed = transformExprOrUnsafe(valueStr)
|
|
2792
|
+
if (transformed === null) return null
|
|
2752
2793
|
return `${quotePropName(p.name)}: ${transformed}`
|
|
2753
2794
|
}
|
|
2754
2795
|
}
|
|
@@ -2789,12 +2830,12 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2789
2830
|
const hoistValues: string[] = []
|
|
2790
2831
|
for (const name of hoisted) {
|
|
2791
2832
|
const sub = env.substitutions.get(name)!
|
|
2792
|
-
const value =
|
|
2833
|
+
const value = transformExprOrUnsafe(sub.kind === 'call' ? `${name}()` : name)
|
|
2793
2834
|
// An init-only value stays on the resolved substitution, whose free
|
|
2794
2835
|
// identifiers still name the init-only local, so a row expression
|
|
2795
2836
|
// reading it is deferred like any other unsafe read rather than
|
|
2796
2837
|
// handed a bound `undefined` to dereference.
|
|
2797
|
-
if (value ===
|
|
2838
|
+
if (value === null) continue
|
|
2798
2839
|
const param = `__bf_outer_${name}`
|
|
2799
2840
|
hoistParams.push(param)
|
|
2800
2841
|
hoistValues.push(value)
|
|
@@ -2834,8 +2875,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2834
2875
|
const chainedTemplateArray = node.sortComparator || node.filterPredicate
|
|
2835
2876
|
? applyLoopChain(node, node.templateArray)
|
|
2836
2877
|
: node.templateArray
|
|
2837
|
-
const
|
|
2838
|
-
const safeRawArrayExpr = rawArrayExpr === UNSAFE_TEMPLATE_EXPR ? '[]' : rawArrayExpr
|
|
2878
|
+
const safeRawArrayExpr = transformExprOrUnsafe(node.array, chainedTemplateArray) ?? '[]'
|
|
2839
2879
|
const { array: iterArrayExpr, callbackParam } = applyIterationShape(node, safeRawArrayExpr, indexParam)
|
|
2840
2880
|
const iterMethod = node.method ?? 'map'
|
|
2841
2881
|
let mapExpr: string
|
|
@@ -35,6 +35,7 @@ function staticPreludeStatements(preamble: MapCallbackPreamble | undefined): str
|
|
|
35
35
|
: []
|
|
36
36
|
}
|
|
37
37
|
import { buildCompSelector, buildStaticChildRefBindings } from '../control-flow/shared.ts'
|
|
38
|
+
import { buildForwardedInnerLoopsPlan } from '../control-flow/plan/build-inner-loop.ts'
|
|
38
39
|
|
|
39
40
|
/** The inline prop shape carried on `IRLoopChildComponent.props`. */
|
|
40
41
|
type LoopChildCompProp = IRLoopChildComponent['props'][number]
|
|
@@ -136,7 +137,16 @@ function buildSingleCompPlan(
|
|
|
136
137
|
// handlers on its forwarded children directly.
|
|
137
138
|
rowEvents: elem.bindings.events
|
|
138
139
|
.filter(ev => ev.nestedLoops.length === 0)
|
|
139
|
-
.map(ev => ({ childSlotId: ev.childSlotId, eventName: ev.eventName, handler: ev.handler })),
|
|
140
|
+
.map(ev => ({ childSlotId: ev.childSlotId, eventName: ev.eventName, handler: ev.handler, receiverSlotIds: ev.receiverSlotIds })),
|
|
141
|
+
// #3694: the static twin of the component-root loop's `innerLoops` —
|
|
142
|
+
// events inside an inner loop of the forwarded children, wired through
|
|
143
|
+
// the composite row's inner-loop emission over each hydrated row. No
|
|
144
|
+
// outer accessor: the forEach binds `param` to the plain item.
|
|
145
|
+
innerLoops: buildForwardedInnerLoopsPlan({
|
|
146
|
+
innerLoops: elem.innerLoops,
|
|
147
|
+
events: elem.bindings.events,
|
|
148
|
+
parentElVar: 'childScope',
|
|
149
|
+
}),
|
|
140
150
|
}
|
|
141
151
|
}
|
|
142
152
|
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
import type { LoopRowEventBinding } from '../control-flow/plan/loop.ts'
|
|
29
|
-
import type { PreludeStatements } from '../control-flow/plan/inner-loop.ts'
|
|
29
|
+
import type { InnerLoopsPlan, PreludeStatements } from '../control-flow/plan/inner-loop.ts'
|
|
30
30
|
import type { LoopChildRefBinding } from '../control-flow/plan/loop.ts'
|
|
31
31
|
import type { LoopChildReactiveAttr, LoopChildReactiveText } from '../types.ts'
|
|
32
32
|
|
|
@@ -79,6 +79,12 @@ export interface SingleCompInitPlan {
|
|
|
79
79
|
* plain item, as for `propsExpr`.
|
|
80
80
|
*/
|
|
81
81
|
rowEvents: readonly LoopRowEventBinding[]
|
|
82
|
+
/**
|
|
83
|
+
* Inner loops of the row component's forwarded `children` that carry an
|
|
84
|
+
* event handler (#3694), run over each hydrated row (`childScope`) after
|
|
85
|
+
* `rowEvents`. Empty when no inner loop carries an event.
|
|
86
|
+
*/
|
|
87
|
+
innerLoops: InnerLoopsPlan
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
/** Plan for one depth-0 component inside `loop.nestedComponents`. */
|
|
@@ -594,12 +594,16 @@ export function collectLoopChildEventsWithNesting(
|
|
|
594
594
|
nestingStack: NestedLoop[]
|
|
595
595
|
lastElementSlotId: string | null
|
|
596
596
|
domDepth: number
|
|
597
|
+
/** Slot ids of the components below the row root whose `children`
|
|
598
|
+
* enclose the current node (#3695) — see `LoopChildEvent.receiverSlotIds`. */
|
|
599
|
+
receivers: readonly string[]
|
|
597
600
|
}
|
|
598
601
|
const events: LoopChildEvent[] = []
|
|
599
602
|
const initialScope: Scope = {
|
|
600
603
|
nestingStack: initialNestingStack,
|
|
601
604
|
lastElementSlotId: null,
|
|
602
605
|
domDepth: 0,
|
|
606
|
+
receivers: [],
|
|
603
607
|
}
|
|
604
608
|
walkIR(node, initialScope, {
|
|
605
609
|
element: ({ node: el, scope, descend }) => {
|
|
@@ -611,6 +615,7 @@ export function collectLoopChildEventsWithNesting(
|
|
|
611
615
|
handler: event.handler,
|
|
612
616
|
nestedLoops: [...scope.nestingStack],
|
|
613
617
|
domDepth: scope.domDepth,
|
|
618
|
+
...(el.slotId.startsWith('^') && scope.receivers.length > 0 && { receiverSlotIds: scope.receivers }),
|
|
614
619
|
})
|
|
615
620
|
}
|
|
616
621
|
}
|
|
@@ -620,13 +625,21 @@ export function collectLoopChildEventsWithNesting(
|
|
|
620
625
|
domDepth: scope.domDepth + 1,
|
|
621
626
|
})
|
|
622
627
|
},
|
|
628
|
+
component: ({ node: c, scope, descend }) => {
|
|
629
|
+
// The row's own root component is the lookup root, never a scope
|
|
630
|
+
// between the element and it; a component nested below it renders the
|
|
631
|
+
// forwarded element inside its own scope (#3695).
|
|
632
|
+
descend(c !== node && c.slotId ? { ...scope, receivers: [...scope.receivers, c.slotId] } : scope)
|
|
633
|
+
},
|
|
623
634
|
loop: ({ node: l, scope, descend }) => {
|
|
624
635
|
// Enter nested loop — push nesting info with container element's slotId.
|
|
625
636
|
// `bindings` is required on every loop variant; populate as empty here
|
|
626
637
|
// because this NestedLoop sub-record is only used as event-delegation
|
|
627
638
|
// metadata (nestedLoops chain), not as a structurally-complete loop.
|
|
639
|
+
// An inner row is its own lookup root, so the receivers restart.
|
|
628
640
|
descend({
|
|
629
641
|
...scope,
|
|
642
|
+
receivers: [],
|
|
630
643
|
nestingStack: [
|
|
631
644
|
...scope.nestingStack,
|
|
632
645
|
{
|
|
@@ -791,6 +804,7 @@ export function collectLoopChildReactiveTexts(
|
|
|
791
804
|
expression: expanded.expr,
|
|
792
805
|
insideConditional: insideConditional || undefined,
|
|
793
806
|
...(expanded.freeIds !== undefined && { freeIdentifiers: expanded.freeIds }),
|
|
807
|
+
...(n.loopRowPropRead && { markup: true as const }),
|
|
794
808
|
})
|
|
795
809
|
},
|
|
796
810
|
conditional: ({ node: c, descend }) => {
|
|
@@ -213,7 +213,10 @@ export interface ChildSpliceContext {
|
|
|
213
213
|
* branch-row builders, whose reactive twin is a `kind: 'text'` writer
|
|
214
214
|
* (`String(...)` into `nodeValue`) — plain `escapeText` is the consistent
|
|
215
215
|
* choice there, and it is also the choice that never unwraps a
|
|
216
|
-
* `bfMarkup()`-shaped object arriving in JSON-sourced loop data.
|
|
216
|
+
* `bfMarkup()`-shaped object arriving in JSON-sourced loop data. The one
|
|
217
|
+
* exception is a row's read of the component's own prop
|
|
218
|
+
* (`IRExpression.loopRowPropRead`): its row writer is `kind: 'markup'`,
|
|
219
|
+
* so the door unwraps it as it does the same read outside a loop.
|
|
217
220
|
*/
|
|
218
221
|
readonly markupSlotIds?: ReadonlySet<string>
|
|
219
222
|
}
|
|
@@ -228,7 +231,10 @@ export interface ChildSpliceContext {
|
|
|
228
231
|
* Arms, first match wins:
|
|
229
232
|
* 1. `joinArrayChild` → `joinedMarkup` (array of compiled leaves)
|
|
230
233
|
* 2. `branchSlotsVar` → `branchSlotValue` (runtime coercion, may be a Node)
|
|
231
|
-
* 3. `slotId` ∈ markupSlotIds
|
|
234
|
+
* 3. `slotId` ∈ markupSlotIds,→ `escapedTextOrMarkup`
|
|
235
|
+
* or a loop-row prop read
|
|
236
|
+
* (`loopRowPropRead`, whose
|
|
237
|
+
* row writer is 'markup' too)
|
|
232
238
|
* 4. `slotId` → `escapedText`
|
|
233
239
|
* 5. `{children}` passthrough → `childrenMarkup` (bare splice only, #2775/#2786)
|
|
234
240
|
* 6. `children ?? fallback`, → `childrenMarkupOrEscapedFallback` (#3554)
|
|
@@ -242,14 +248,15 @@ export interface ChildSpliceContext {
|
|
|
242
248
|
* either alone misses one of the two shapes (#2786).
|
|
243
249
|
*/
|
|
244
250
|
export function spliceChildValue(
|
|
245
|
-
node: Pick<IRExpression, 'expr' | 'slotId' | 'joinArrayChild' | 'childrenRead'>,
|
|
251
|
+
node: Pick<IRExpression, 'expr' | 'slotId' | 'joinArrayChild' | 'childrenRead' | 'loopRowPropRead'>,
|
|
246
252
|
valueExpr: string,
|
|
247
253
|
cx: ChildSpliceContext,
|
|
248
254
|
): SafeHtml {
|
|
249
255
|
if (node.joinArrayChild) return joinedMarkup(valueExpr)
|
|
250
256
|
if (cx.branchSlotsVar) return branchSlotValue(valueExpr, cx.branchSlotsVar)
|
|
251
257
|
if (node.slotId) {
|
|
252
|
-
|
|
258
|
+
const markup = cx.markupSlotIds?.has(node.slotId) || node.loopRowPropRead
|
|
259
|
+
return markup ? escapedTextOrMarkup(valueExpr) : escapedText(valueExpr)
|
|
253
260
|
}
|
|
254
261
|
if (node.childrenRead === 'bare' || node.childrenRead === 'nullish-empty') {
|
|
255
262
|
return childrenMarkup(valueExpr)
|
|
@@ -61,9 +61,10 @@ import type {
|
|
|
61
61
|
import { nameForRegistryRef } from '../component-scope.ts'
|
|
62
62
|
import { varSlotId } from '../utils.ts'
|
|
63
63
|
import { emitDedupedAttrUpdate, DEDUP_STORE_DECL } from '../emit-reactive.ts'
|
|
64
|
-
import { claimPlanLiteral, claimWriterVarName, type ClaimSlotSpec } from '../control-flow/stringify/claim-plan.ts'
|
|
64
|
+
import { claimPlanLiteral, claimWriterVarName, rowTextSlotKind, rowTextSlotValue, type ClaimSlotSpec } from '../control-flow/stringify/claim-plan.ts'
|
|
65
65
|
import { emitLoopChildRefs } from '../control-flow/stringify/loop.ts'
|
|
66
66
|
import { emitRowEventListener } from '../control-flow/shared.ts'
|
|
67
|
+
import { stringifyInnerLoops } from '../control-flow/stringify/inner-loop.ts'
|
|
67
68
|
|
|
68
69
|
export function stringifyStaticArrayChildInits(
|
|
69
70
|
lines: string[],
|
|
@@ -92,7 +93,7 @@ function stringifyOne(lines: string[], plan: StaticArrayChildInitPlan): void {
|
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
function emitSingleComp(lines: string[], plan: SingleCompInitPlan): void {
|
|
95
|
-
const { containerVar, componentName, childSelector, arrayExpr, param, indexParam, outerPreludeStatements, propsExpr, rowEvents } = plan
|
|
96
|
+
const { containerVar, componentName, childSelector, arrayExpr, param, indexParam, outerPreludeStatements, propsExpr, rowEvents, innerLoops } = plan
|
|
96
97
|
lines.push(` // Initialize static array children (hydrate skips nested instances)`)
|
|
97
98
|
lines.push(` if (${containerVar}) {`)
|
|
98
99
|
lines.push(` const __childScopes = qsaChildScopes(${containerVar}, ${childSelector})`)
|
|
@@ -106,6 +107,7 @@ function emitSingleComp(lines: string[], plan: SingleCompInitPlan): void {
|
|
|
106
107
|
}
|
|
107
108
|
lines.push(` initChild('${nameForRegistryRef(componentName)}', childScope, ${propsExpr})`)
|
|
108
109
|
for (const ev of rowEvents) emitRowEventListener(lines, ' ', 'childScope', ev)
|
|
110
|
+
stringifyInnerLoops(lines, innerLoops, ' ')
|
|
109
111
|
lines.push(` })`)
|
|
110
112
|
lines.push(` }`)
|
|
111
113
|
lines.push('')
|
|
@@ -205,11 +207,11 @@ function emitInnerLoopNested(lines: string[], plan: InnerLoopNestedInitPlan): vo
|
|
|
205
207
|
lines.push(` }`)
|
|
206
208
|
}
|
|
207
209
|
if (texts.length > 0) {
|
|
208
|
-
const slots: ClaimSlotSpec[] = texts.map(t => ({ id: t.slotId, kind:
|
|
210
|
+
const slots: ClaimSlotSpec[] = texts.map(t => ({ id: t.slotId, kind: rowTextSlotKind(t), path: [] }))
|
|
209
211
|
const writer = claimWriterVarName(slots, varSlotId)
|
|
210
212
|
lines.push(` const ${writer} = lazySlots(__innerEl, ${claimPlanLiteral(slots)})`)
|
|
211
213
|
for (const text of texts) {
|
|
212
|
-
lines.push(` createEffect(() => { ${writer}('${text.slotId}',
|
|
214
|
+
lines.push(` createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.expression, 'String')}) })`)
|
|
213
215
|
}
|
|
214
216
|
}
|
|
215
217
|
// Ref callbacks fire on every forEach iteration — initial mount and any
|
|
@@ -172,6 +172,11 @@ export interface InteractiveElement {
|
|
|
172
172
|
export interface ReactiveComponentProp {
|
|
173
173
|
slotId: string
|
|
174
174
|
propName: string
|
|
175
|
+
/**
|
|
176
|
+
* The JS expression whose value the mirror writes: the signal/memo call
|
|
177
|
+
* (`count()`), read caller-first when a later `{...props}` spread
|
|
178
|
+
* overrides the prop (#3688).
|
|
179
|
+
*/
|
|
175
180
|
expression: string
|
|
176
181
|
componentName: string
|
|
177
182
|
}
|
|
@@ -522,6 +527,14 @@ export interface NestedLoop extends LoopCore {
|
|
|
522
527
|
insideConditional?: boolean
|
|
523
528
|
/** Offset of this loop's items past its preceding container siblings (#1693). */
|
|
524
529
|
offset?: LoopOffset
|
|
530
|
+
/**
|
|
531
|
+
* The inner `.map()`'s `.filter()` / `.toSorted()` chain (#3694), so a
|
|
532
|
+
* reactive inner `mapArray` reconciles the rows the template rendered
|
|
533
|
+
* rather than the base array's.
|
|
534
|
+
*/
|
|
535
|
+
filterPredicate?: { param: string; raw: string }
|
|
536
|
+
sortComparator?: { paramA: string; paramB: string; raw: string }
|
|
537
|
+
chainOrder?: 'filter-sort' | 'sort-filter'
|
|
525
538
|
// Per-item bindings (events / reactiveAttrs / reactiveTexts / refs / conditionals)
|
|
526
539
|
// now live on `LoopCore.bindings` — see issue #1244 §B.
|
|
527
540
|
}
|
|
@@ -534,6 +547,14 @@ export interface LoopChildEvent {
|
|
|
534
547
|
nestedLoops: NestedLoop[]
|
|
535
548
|
/** DOM nesting depth (0 = loop body root). Deepest-first sorting for event delegation (#774). */
|
|
536
549
|
domDepth: number
|
|
550
|
+
/**
|
|
551
|
+
* For a parent-owned (`^sN`) element forwarded as the `children` of a
|
|
552
|
+
* component nested BELOW the row root (#3695): those components' slot
|
|
553
|
+
* ids, outermost first. The per-row lookup crosses into their scopes only
|
|
554
|
+
* (see `ConditionalBranchReactiveAttr.receiverSlotIds`, #3324). Absent
|
|
555
|
+
* when no such component encloses the element.
|
|
556
|
+
*/
|
|
557
|
+
receiverSlotIds?: readonly string[]
|
|
537
558
|
}
|
|
538
559
|
|
|
539
560
|
export interface LoopChildReactiveAttr extends AttrMeta {
|
|
@@ -565,6 +586,8 @@ export interface LoopChildReactiveText {
|
|
|
565
586
|
* constants' own `freeIdentifiers`.
|
|
566
587
|
*/
|
|
567
588
|
freeIdentifiers?: ReadonlySet<string>
|
|
589
|
+
/** A read of the component's own prop (`IRExpression.loopRowPropRead`): claimed and written as markup (`RowTextSlot`). */
|
|
590
|
+
markup?: true
|
|
568
591
|
}
|
|
569
592
|
|
|
570
593
|
/**
|
|
@@ -191,7 +191,21 @@ export function varSlotId(slotId: string): string {
|
|
|
191
191
|
*/
|
|
192
192
|
export function profileBindingId(componentName: string | undefined, slotId: string): string {
|
|
193
193
|
if (!componentName || slotId === '?') return ''
|
|
194
|
-
return `, ${
|
|
194
|
+
return `, ${codeSafeStringLiteral(`${componentName}#binding:${slotId}`)}`
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* A double-quoted JS string literal that is safe to splice into emitted code
|
|
199
|
+
* wherever it lands. `JSON.stringify` alone leaves `<`, `>` and `/` raw (a
|
|
200
|
+
* `</script>` closes an inline script) and, before ES2019, U+2028 / U+2029
|
|
201
|
+
* ended a string literal. Those are escaped as `\uXXXX`, which evaluates to the
|
|
202
|
+
* same string, so a value without them prints exactly as `JSON.stringify` did.
|
|
203
|
+
*/
|
|
204
|
+
export function codeSafeStringLiteral(value: string): string {
|
|
205
|
+
return JSON.stringify(value).replace(
|
|
206
|
+
/[<>/\u2028\u2029]/g,
|
|
207
|
+
ch => `\\u${ch.charCodeAt(0).toString(16).padStart(4, '0')}`,
|
|
208
|
+
)
|
|
195
209
|
}
|
|
196
210
|
|
|
197
211
|
/**
|