@barefootjs/jsx 0.40.0 → 0.40.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts +42 -0
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +1 -0
- package/dist/adapters/attr-plan.d.ts.map +1 -1
- package/dist/adapters/boolean-carrier.d.ts +31 -0
- package/dist/adapters/boolean-carrier.d.ts.map +1 -0
- package/dist/adapters/boolean-result.d.ts +32 -10
- package/dist/adapters/boolean-result.d.ts.map +1 -1
- package/dist/adapters/brace-delimiter-text.d.ts +18 -0
- package/dist/adapters/brace-delimiter-text.d.ts.map +1 -0
- package/dist/adapters/callback-method.d.ts +38 -5
- package/dist/adapters/callback-method.d.ts.map +1 -1
- package/dist/adapters/component-props.d.ts +22 -7
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/computed-const.d.ts +28 -1
- package/dist/adapters/computed-const.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +39 -1
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
- package/dist/adapters/loop-bound-names.d.ts +9 -1
- package/dist/adapters/loop-bound-names.d.ts.map +1 -1
- package/dist/adapters/loop-row-type.d.ts +52 -0
- package/dist/adapters/loop-row-type.d.ts.map +1 -0
- package/dist/adapters/nil-reading.d.ts +68 -0
- package/dist/adapters/nil-reading.d.ts.map +1 -0
- package/dist/adapters/non-primitive-equality.d.ts +33 -0
- package/dist/adapters/non-primitive-equality.d.ts.map +1 -0
- package/dist/adapters/number-value.d.ts +45 -0
- package/dist/adapters/number-value.d.ts.map +1 -0
- package/dist/adapters/operand-typing.d.ts +126 -0
- package/dist/adapters/operand-typing.d.ts.map +1 -0
- package/dist/adapters/parsed-expr-emitter.d.ts +70 -12
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/primitive-plan.d.ts +291 -0
- package/dist/adapters/primitive-plan.d.ts.map +1 -0
- package/dist/analyzer-context.d.ts +11 -0
- package/dist/analyzer-context.d.ts.map +1 -1
- package/dist/analyzer.d.ts +34 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/augment-inherited-props.d.ts +63 -8
- package/dist/augment-inherited-props.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/event-handler-name.d.ts +12 -0
- package/dist/event-handler-name.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +8 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/index.d.ts +24 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5671 -2586
- package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
- package/dist/ir-to-client-js/child-props-object.d.ts +64 -0
- package/dist/ir-to-client-js/child-props-object.d.ts.map +1 -0
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts +29 -0
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-reactive-effects.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts +5 -4
- package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +15 -0
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts +22 -0
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/lazy-row.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts +3 -2
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +2 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/index.d.ts +2 -6
- package/dist/ir-to-client-js/index.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/build-static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +37 -19
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/safe-html.d.ts +9 -3
- package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts +3 -2
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +30 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +8 -0
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts +1 -0
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +95 -10
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/prop-rewrite.d.ts +7 -0
- package/dist/prop-rewrite.d.ts.map +1 -1
- package/dist/props-binding.d.ts +27 -3
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/props-object-whole-read.d.ts +15 -0
- package/dist/props-object-whole-read.d.ts.map +1 -0
- package/dist/rich-type-refusal.d.ts.map +1 -1
- package/dist/scope/binding-scope.d.ts +100 -4
- package/dist/scope/binding-scope.d.ts.map +1 -1
- package/dist/scope/lexical-scope-walk.d.ts +3 -2
- package/dist/scope/lexical-scope-walk.d.ts.map +1 -1
- package/dist/scope/root-prop-alias.d.ts +16 -0
- package/dist/scope/root-prop-alias.d.ts.map +1 -1
- package/dist/signal-prop-name-collision.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +4 -2
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/ssr-seed-plan.d.ts +14 -0
- package/dist/ssr-seed-plan.d.ts.map +1 -1
- package/dist/strip-types.d.ts +13 -0
- package/dist/strip-types.d.ts.map +1 -1
- package/dist/template-parts.d.ts.map +1 -1
- package/dist/template-position-walk.d.ts +21 -3
- package/dist/template-position-walk.d.ts.map +1 -1
- package/dist/types.d.ts +120 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +3 -3
- package/src/__tests__/binding-scope-ratchet.test.ts +12 -2
- package/src/__tests__/binding-scope.test.ts +89 -1
- package/src/__tests__/body-destructure-props-object-alias.test.ts +123 -0
- package/src/__tests__/boolean-carrier.test.ts +74 -0
- package/src/__tests__/boolean-result.test.ts +22 -5
- package/src/__tests__/brace-delimiter-text.test.ts +26 -0
- package/src/__tests__/callback-method.test.ts +62 -2
- package/src/__tests__/child-components-in-map.test.ts +1 -1
- package/src/__tests__/component-props.test.ts +14 -0
- package/src/__tests__/computed-const.test.ts +188 -0
- package/src/__tests__/emit-to-string-call.test.ts +2 -1
- package/src/__tests__/expression-parser.test.ts +24 -0
- package/src/__tests__/hydration-payload-analysis.test.ts +166 -0
- package/src/__tests__/issue-2724-prop-alias-loop-not-static.test.ts +7 -7
- package/src/__tests__/issue-2754-rest-spread-needs-slot.test.ts +5 -2
- package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +1 -1
- package/src/__tests__/issue-2835-props-type-member-name-collision.test.ts +4 -4
- package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +1 -1
- package/src/__tests__/issue-3688-props-spread-child-csr.test.ts +143 -0
- package/src/__tests__/issue-3713-props-spread-loop-row.test.ts +65 -0
- package/src/__tests__/lookup-literal-const.test.ts +9 -3
- package/src/__tests__/loop-index-reactivity.test.ts +2 -2
- package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +1 -1
- package/src/__tests__/loop-plan.test.ts +1 -1
- package/src/__tests__/loop-row-const-initializer-shadow.test.ts +146 -0
- package/src/__tests__/loop-row-prop-read.test.ts +111 -0
- package/src/__tests__/loop-row-type.test.ts +64 -0
- package/src/__tests__/lowering-value-position.test.ts +4 -0
- package/src/__tests__/memo-body-expr.test.ts +137 -0
- package/src/__tests__/module-const-destructure-default.test.ts +156 -0
- package/src/__tests__/nested-loop-index-param.test.ts +1 -1
- package/src/__tests__/nested-loop-reactive-attrs.test.ts +2 -2
- package/src/__tests__/nested-row-shadowing.test.ts +2 -2
- package/src/__tests__/nil-reading.test.ts +77 -0
- package/src/__tests__/nullable-signal-attr.test.ts +231 -2
- package/src/__tests__/primitive-plan.test.ts +416 -0
- package/src/__tests__/profile-binding-ids.test.ts +14 -0
- package/src/__tests__/profile-loop-binding-ids.test.ts +2 -2
- package/src/__tests__/profile-nested-binding-ids.test.ts +2 -2
- package/src/__tests__/props-object-whole-read.test.ts +40 -0
- package/src/__tests__/reactive-attrs-in-map.test.ts +1 -1
- package/src/__tests__/reactive-factory-inlining.test.ts +4 -1
- package/src/__tests__/rest-binding-gaps.test.ts +192 -0
- package/src/__tests__/root-prop-alias.test.ts +79 -1
- package/src/__tests__/signal-prop-name-collision.test.ts +102 -2
- package/src/__tests__/source-file-cache.test.ts +105 -0
- package/src/__tests__/ssr-seed-plan.test.ts +43 -0
- package/src/__tests__/static-loop-csr-materialize.test.ts +2 -2
- package/src/__tests__/static-record-literal-array.test.ts +171 -0
- package/src/__tests__/string-concat-identifier.test.ts +40 -1
- package/src/__tests__/template-parts-literal-boundary.test.ts +19 -0
- package/src/adapters/ambiguous-nil-arithmetic.ts +103 -0
- package/src/adapters/attr-plan.ts +6 -2
- package/src/adapters/boolean-carrier.ts +76 -0
- package/src/adapters/boolean-result.ts +72 -66
- package/src/adapters/brace-delimiter-text.ts +25 -0
- package/src/adapters/callback-method.ts +151 -27
- package/src/adapters/component-props.ts +28 -8
- package/src/adapters/computed-const.ts +443 -10
- package/src/adapters/dsl-template-adapter.ts +79 -2
- package/src/adapters/loop-bound-names.ts +9 -1
- package/src/adapters/loop-plan.ts +1 -1
- package/src/adapters/loop-row-type.ts +139 -0
- package/src/adapters/nil-reading.ts +297 -0
- package/src/adapters/non-primitive-equality.ts +92 -0
- package/src/adapters/number-value.ts +108 -0
- package/src/adapters/operand-typing.ts +522 -0
- package/src/adapters/parsed-expr-emitter.ts +154 -19
- package/src/adapters/primitive-plan.ts +696 -0
- package/src/analyzer-context.ts +14 -0
- package/src/analyzer.ts +692 -85
- package/src/augment-inherited-props.ts +108 -10
- package/src/compiler.ts +17 -0
- package/src/event-handler-name.ts +15 -0
- package/src/expression-parser.ts +74 -2
- package/src/index.ts +45 -9
- package/src/ir-to-client-js/build-references.ts +69 -0
- package/src/ir-to-client-js/child-props-object.ts +106 -0
- package/src/ir-to-client-js/collect-elements.ts +100 -67
- package/src/ir-to-client-js/compute-inlinability.ts +1 -1
- package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +15 -1
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +85 -5
- package/src/ir-to-client-js/control-flow/plan/build-lazy-row.ts +3 -0
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +30 -28
- package/src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts +1 -0
- package/src/ir-to-client-js/control-flow/plan/inner-loop.ts +5 -4
- package/src/ir-to-client-js/control-flow/plan/loop-child-arm.ts +2 -0
- package/src/ir-to-client-js/control-flow/plan/loop.ts +12 -0
- package/src/ir-to-client-js/control-flow/plan/reactive-effects.ts +2 -0
- package/src/ir-to-client-js/control-flow/shared.ts +23 -24
- package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +29 -0
- package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +8 -2
- package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +8 -1
- package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +8 -7
- package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +8 -7
- package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +4 -4
- package/src/ir-to-client-js/control-flow/stringify/loop.ts +3 -3
- package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +6 -6
- package/src/ir-to-client-js/emit-reactive.ts +1 -1
- package/src/ir-to-client-js/html-template.ts +95 -38
- package/src/ir-to-client-js/imports.ts +1 -1
- package/src/ir-to-client-js/index.ts +53 -11
- package/src/ir-to-client-js/plan/build-static-array-child-init.ts +42 -15
- package/src/ir-to-client-js/plan/static-array-child-init.ts +34 -19
- package/src/ir-to-client-js/prop-handling.ts +22 -3
- package/src/ir-to-client-js/reactivity.ts +14 -0
- package/src/ir-to-client-js/safe-html.ts +11 -4
- package/src/ir-to-client-js/stringify/static-array-child-init.ts +30 -12
- package/src/ir-to-client-js/types.ts +23 -0
- package/src/ir-to-client-js/utils.ts +15 -1
- package/src/jsx-to-ir.ts +510 -58
- package/src/nullable-signal-attr.ts +366 -28
- package/src/prop-rewrite.ts +30 -6
- package/src/props-binding.ts +54 -3
- package/src/props-object-whole-read.ts +87 -0
- package/src/rich-type-refusal.ts +2 -1
- package/src/scope/binding-scope.ts +203 -11
- package/src/scope/lexical-scope-walk.ts +4 -3
- package/src/scope/root-prop-alias.ts +23 -0
- package/src/signal-prop-name-collision.ts +113 -22
- package/src/ssr-defaults.ts +10 -4
- package/src/ssr-seed-plan.ts +82 -17
- package/src/strip-types.ts +31 -3
- package/src/template-parts.ts +21 -1
- package/src/template-position-walk.ts +57 -28
- package/src/types.ts +117 -0
|
@@ -26,21 +26,37 @@
|
|
|
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
|
|
|
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. */
|
|
@@ -79,6 +91,12 @@ export interface SingleCompInitPlan {
|
|
|
79
91
|
* plain item, as for `propsExpr`.
|
|
80
92
|
*/
|
|
81
93
|
rowEvents: readonly LoopRowEventBinding[]
|
|
94
|
+
/**
|
|
95
|
+
* Inner loops of the row component's forwarded `children` that carry an
|
|
96
|
+
* event handler (#3694), run over each hydrated row (`childScope`) after
|
|
97
|
+
* `rowEvents`. Empty when no inner loop carries an event.
|
|
98
|
+
*/
|
|
99
|
+
innerLoops: InnerLoopsPlan
|
|
82
100
|
}
|
|
83
101
|
|
|
84
102
|
/** Plan for one depth-0 component inside `loop.nestedComponents`. */
|
|
@@ -86,11 +104,8 @@ export interface OuterNestedInitPlan {
|
|
|
86
104
|
kind: 'outer-nested'
|
|
87
105
|
containerVar: string
|
|
88
106
|
componentName: string
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
* `__iterEl.querySelector(<here>)`. See `buildCompSelector`.
|
|
92
|
-
*/
|
|
93
|
-
selector: string
|
|
107
|
+
/** How the component's scope is found in `__iterEl` (#3821). */
|
|
108
|
+
lookup: ChildScopesLookup
|
|
94
109
|
arrayExpr: string
|
|
95
110
|
param: string
|
|
96
111
|
indexParam: string
|
|
@@ -184,7 +199,7 @@ export interface InnerLoopNestedInitPlan {
|
|
|
184
199
|
* the parent container with no per-group element to index.
|
|
185
200
|
*
|
|
186
201
|
* Instead this shape zips the inner component scopes — found in document order
|
|
187
|
-
*
|
|
202
|
+
* by the comp's `ChildScopesLookup` — against the flattened
|
|
188
203
|
* `outer.forEach(o => inner.forEach(i => ...))` iteration. Document order is
|
|
189
204
|
* the SSR render order, so position `__ci++` pairs each scope with its data
|
|
190
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 }
|
|
@@ -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)
|
|
@@ -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,
|
|
@@ -61,9 +63,10 @@ import type {
|
|
|
61
63
|
import { nameForRegistryRef } from '../component-scope.ts'
|
|
62
64
|
import { varSlotId } from '../utils.ts'
|
|
63
65
|
import { emitDedupedAttrUpdate, DEDUP_STORE_DECL } from '../emit-reactive.ts'
|
|
64
|
-
import { claimPlanLiteral, claimWriterVarName, type ClaimSlotSpec } from '../control-flow/stringify/claim-plan.ts'
|
|
66
|
+
import { claimPlanLiteral, claimWriterVarName, rowTextSlotKind, rowTextSlotValue, type ClaimSlotSpec } from '../control-flow/stringify/claim-plan.ts'
|
|
65
67
|
import { emitLoopChildRefs } from '../control-flow/stringify/loop.ts'
|
|
66
68
|
import { emitRowEventListener } from '../control-flow/shared.ts'
|
|
69
|
+
import { stringifyInnerLoops } from '../control-flow/stringify/inner-loop.ts'
|
|
67
70
|
|
|
68
71
|
export function stringifyStaticArrayChildInits(
|
|
69
72
|
lines: string[],
|
|
@@ -91,11 +94,25 @@ function stringifyOne(lines: string[], plan: StaticArrayChildInitPlan): void {
|
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
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
|
+
|
|
94
111
|
function emitSingleComp(lines: string[], plan: SingleCompInitPlan): void {
|
|
95
|
-
const { containerVar, componentName,
|
|
112
|
+
const { containerVar, componentName, lookup, arrayExpr, param, indexParam, outerPreludeStatements, propsExpr, rowEvents, innerLoops } = plan
|
|
96
113
|
lines.push(` // Initialize static array children (hydrate skips nested instances)`)
|
|
97
114
|
lines.push(` if (${containerVar}) {`)
|
|
98
|
-
lines.push(` const __childScopes =
|
|
115
|
+
lines.push(` const __childScopes = ${childScopesCall(containerVar, lookup)}`)
|
|
99
116
|
lines.push(` __childScopes.forEach((childScope, ${indexParam}) => {`)
|
|
100
117
|
lines.push(` const ${param} = ${arrayExpr}[${indexParam}]`)
|
|
101
118
|
// Outer `.map()` callback preamble locals — emitted unwrapped after
|
|
@@ -106,13 +123,14 @@ function emitSingleComp(lines: string[], plan: SingleCompInitPlan): void {
|
|
|
106
123
|
}
|
|
107
124
|
lines.push(` initChild('${nameForRegistryRef(componentName)}', childScope, ${propsExpr})`)
|
|
108
125
|
for (const ev of rowEvents) emitRowEventListener(lines, ' ', 'childScope', ev)
|
|
126
|
+
stringifyInnerLoops(lines, innerLoops, ' ')
|
|
109
127
|
lines.push(` })`)
|
|
110
128
|
lines.push(` }`)
|
|
111
129
|
lines.push('')
|
|
112
130
|
}
|
|
113
131
|
|
|
114
132
|
function emitOuterNested(lines: string[], plan: OuterNestedInitPlan): void {
|
|
115
|
-
const { containerVar, componentName,
|
|
133
|
+
const { containerVar, componentName, lookup, arrayExpr, param, indexParam, offsetExpr, outerPreludeStatements, propsExpr } = plan
|
|
116
134
|
lines.push(` // Initialize nested ${componentName} in static array`)
|
|
117
135
|
lines.push(` if (${containerVar}) {`)
|
|
118
136
|
lines.push(` ${arrayExpr}.forEach((${param}, ${indexParam}) => {`)
|
|
@@ -125,7 +143,7 @@ function emitOuterNested(lines: string[], plan: OuterNestedInitPlan): void {
|
|
|
125
143
|
for (const stmt of outerPreludeStatements) {
|
|
126
144
|
lines.push(` ${stmt}`)
|
|
127
145
|
}
|
|
128
|
-
lines.push(` const __compEl =
|
|
146
|
+
lines.push(` const __compEl = ${childScopeCall('__iterEl', lookup)}`)
|
|
129
147
|
lines.push(` if (__compEl) initChild('${nameForRegistryRef(componentName)}', __compEl, ${propsExpr})`)
|
|
130
148
|
lines.push(` }`)
|
|
131
149
|
lines.push(` })`)
|
|
@@ -181,7 +199,7 @@ function emitInnerLoopNested(lines: string[], plan: InnerLoopNestedInitPlan): vo
|
|
|
181
199
|
// re-declare `const __compEl` in the same scope (#1664).
|
|
182
200
|
comps.forEach((comp, i) => {
|
|
183
201
|
const compElVar = comps.length > 1 ? `__compEl${i}` : '__compEl'
|
|
184
|
-
lines.push(` const ${compElVar} =
|
|
202
|
+
lines.push(` const ${compElVar} = ${childScopeCall('__innerEl', comp.lookup)}`)
|
|
185
203
|
lines.push(` if (${compElVar}) initChild('${nameForRegistryRef(comp.componentName)}', ${compElVar}, ${comp.propsExpr})`)
|
|
186
204
|
})
|
|
187
205
|
// Plain-element reactive attrs / texts / refs inside this inner loop's
|
|
@@ -205,11 +223,11 @@ function emitInnerLoopNested(lines: string[], plan: InnerLoopNestedInitPlan): vo
|
|
|
205
223
|
lines.push(` }`)
|
|
206
224
|
}
|
|
207
225
|
if (texts.length > 0) {
|
|
208
|
-
const slots: ClaimSlotSpec[] = texts.map(t => ({ id: t.slotId, kind:
|
|
226
|
+
const slots: ClaimSlotSpec[] = texts.map(t => ({ id: t.slotId, kind: rowTextSlotKind(t), path: [] }))
|
|
209
227
|
const writer = claimWriterVarName(slots, varSlotId)
|
|
210
228
|
lines.push(` const ${writer} = lazySlots(__innerEl, ${claimPlanLiteral(slots)})`)
|
|
211
229
|
for (const text of texts) {
|
|
212
|
-
lines.push(` createEffect(() => { ${writer}('${text.slotId}',
|
|
230
|
+
lines.push(` createEffect(() => { ${writer}('${text.slotId}', ${rowTextSlotValue(text, text.expression)}) })`)
|
|
213
231
|
}
|
|
214
232
|
}
|
|
215
233
|
// Ref callbacks fire on every forEach iteration — initial mount and any
|
|
@@ -227,7 +245,7 @@ function emitInnerLoopNested(lines: string[], plan: InnerLoopNestedInitPlan): vo
|
|
|
227
245
|
*
|
|
228
246
|
* <i>// Initialize component-rooted inner-loop components (depth N)
|
|
229
247
|
* <i>if (<container>) {
|
|
230
|
-
* <i> const <scopes_c> =
|
|
248
|
+
* <i> const <scopes_c> = childScopesBySlot(<container>, __scopeId, '<slot_c>') // per comp
|
|
231
249
|
* <i> let <cursor_c> = 0
|
|
232
250
|
* <i> <outerArr>.forEach((<outerParam>[, <outerIdx>]) => {
|
|
233
251
|
* <i> <outerPreludeStatements*>
|
|
@@ -268,7 +286,7 @@ function emitComponentRootedInnerLoop(lines: string[], plan: ComponentRootedInne
|
|
|
268
286
|
lines.push(` // Initialize component-rooted inner-loop components (depth ${depth})`)
|
|
269
287
|
lines.push(` if (${containerVar}) {`)
|
|
270
288
|
comps.forEach((comp, i) => {
|
|
271
|
-
lines.push(` const ${scopesVar(i)} =
|
|
289
|
+
lines.push(` const ${scopesVar(i)} = ${childScopesCall(containerVar, comp.lookup)}`)
|
|
272
290
|
lines.push(` let ${cursorVar(i)} = 0`)
|
|
273
291
|
})
|
|
274
292
|
// Declared index names are appended to the forEach heads (#2231);
|
|
@@ -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
|
/**
|