@barefootjs/jsx 0.37.1 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/action-accessor.d.ts +159 -0
- package/dist/action-accessor.d.ts.map +1 -0
- package/dist/adapters/env-signal.d.ts +0 -8
- package/dist/adapters/env-signal.d.ts.map +1 -1
- package/dist/adapters/interface.d.ts +12 -0
- package/dist/adapters/interface.d.ts.map +1 -1
- package/dist/adapters/jsx-adapter.d.ts.map +1 -1
- package/dist/analyzer.d.ts +61 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/async-action-refusal.d.ts +45 -0
- package/dist/async-action-refusal.d.ts.map +1 -0
- package/dist/builtin-lowering-plugins.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/component-root-scope-comment.d.ts +36 -0
- package/dist/component-root-scope-comment.d.ts.map +1 -0
- package/dist/debug.d.ts +61 -5
- package/dist/debug.d.ts.map +1 -1
- package/dist/errors.d.ts +7 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/event-handler-name.d.ts +13 -0
- package/dist/event-handler-name.d.ts.map +1 -0
- package/dist/expression-parser.d.ts +9 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/format-date-refusal.d.ts +33 -0
- package/dist/format-date-refusal.d.ts.map +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3260 -1914
- package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
- package/dist/ir-to-client-js/compute-scope.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-branch-loop.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-composite-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop.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/lazy-row-eligibility.d.ts +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +57 -12
- 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 +44 -3
- package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts +7 -5
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
- package/dist/ir-to-client-js/declaration-sort.d.ts +2 -1
- package/dist/ir-to-client-js/declaration-sort.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-module-level.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts +43 -2
- package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts +7 -5
- package/dist/ir-to-client-js/plan/declaration-emit.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 +9 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/source-map.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +4 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +66 -1
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/opaque-local-accessor.d.ts +27 -0
- package/dist/opaque-local-accessor.d.ts.map +1 -0
- package/dist/signal-initializer.d.ts +24 -0
- package/dist/signal-initializer.d.ts.map +1 -0
- package/dist/template-position-walk.d.ts +68 -0
- package/dist/template-position-walk.d.ts.map +1 -0
- package/dist/to-locale-date-lowering.d.ts +7 -4
- package/dist/to-locale-date-lowering.d.ts.map +1 -1
- package/dist/types.d.ts +104 -17
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +878 -4528
- package/src/__tests__/action-accessor.test.ts +166 -0
- package/src/__tests__/binding-scope-ratchet.test.ts +21 -10
- package/src/__tests__/branch-local-in-raw-capture.test.ts +1 -1
- package/src/__tests__/branch-local-same-name-collision.test.ts +9 -9
- package/src/__tests__/client-js-generation.test.ts +175 -0
- package/src/__tests__/component-root-scope-comment.test.ts +106 -0
- package/src/__tests__/create-mutation.test.ts +220 -0
- package/src/__tests__/create-query.test.ts +644 -0
- package/src/__tests__/csr-fragment-root-scope-shape.test.ts +156 -0
- package/src/__tests__/debug.test.ts +222 -0
- package/src/__tests__/doc-examples.test.ts +78 -25
- package/src/__tests__/event-handler-name.test.ts +74 -0
- package/src/__tests__/flatmap-segments.test.ts +11 -9
- package/src/__tests__/format-date-refusal.test.ts +134 -0
- package/src/__tests__/fragment-wrapped-conditional-return-branch.test.ts +132 -0
- package/src/__tests__/hydrate-template.test.ts +9 -1
- package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +2 -2
- package/src/__tests__/issue-3009-loop-branch-ref.test.ts +2 -2
- package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +213 -0
- package/src/__tests__/issue-3113-init-fn-name-collision.test.ts +133 -0
- package/src/__tests__/jsx-return-type-assertion.test.ts +2 -2
- package/src/__tests__/lazy-row-eligibility.test.ts +5 -4
- package/src/__tests__/loop-row-child-children-reactive-attrs.test.ts +108 -0
- package/src/__tests__/loop-row-child-text-children-markers.test.ts +158 -0
- package/src/__tests__/opaque-local-accessor.test.ts +90 -0
- package/src/__tests__/profiler-e2e.test.ts +13 -8
- package/src/__tests__/props-destructuring.test.ts +79 -4
- package/src/__tests__/reactive-factory-arity.test.ts +311 -0
- package/src/__tests__/ref-attr-absent-at-ssr.test.ts +472 -0
- package/src/__tests__/ssr-portal-ref-callback.test.ts +219 -0
- package/src/action-accessor.ts +289 -0
- package/src/adapters/env-signal.ts +2 -21
- package/src/adapters/interface.ts +13 -0
- package/src/adapters/jsx-adapter.ts +17 -0
- package/src/analyzer.ts +589 -60
- package/src/async-action-refusal.ts +254 -0
- package/src/builtin-lowering-plugins.ts +0 -2
- package/src/compiler.ts +27 -0
- package/src/component-root-scope-comment.ts +59 -0
- package/src/debug.ts +318 -103
- package/src/errors.ts +83 -1
- package/src/event-handler-name.ts +14 -0
- package/src/expression-parser.ts +41 -17
- package/src/format-date-refusal.ts +147 -0
- package/src/index.ts +14 -3
- package/src/ir-to-client-js/build-references.ts +6 -2
- package/src/ir-to-client-js/child-components.ts +8 -3
- package/src/ir-to-client-js/collect-elements.ts +28 -13
- package/src/ir-to-client-js/compute-inlinability.ts +2 -1
- package/src/ir-to-client-js/compute-scope.ts +3 -1
- package/src/ir-to-client-js/control-flow/plan/build-branch-loop.ts +2 -4
- package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +67 -5
- package/src/ir-to-client-js/control-flow/plan/build-composite-loop.ts +3 -6
- package/src/ir-to-client-js/control-flow/plan/build-insert.ts +1 -0
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +2 -1
- package/src/ir-to-client-js/control-flow/plan/build-loop.ts +23 -11
- package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -0
- package/src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts +3 -3
- package/src/ir-to-client-js/control-flow/plan/loop.ts +51 -10
- package/src/ir-to-client-js/control-flow/shared.ts +78 -5
- package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +25 -12
- package/src/ir-to-client-js/control-flow/stringify/insert.ts +1 -1
- package/src/ir-to-client-js/csr-substitute.ts +11 -3
- package/src/ir-to-client-js/declaration-sort.ts +7 -3
- package/src/ir-to-client-js/emit-module-level.ts +7 -4
- package/src/ir-to-client-js/emit-reactive.ts +140 -10
- package/src/ir-to-client-js/emit-registration.ts +6 -11
- package/src/ir-to-client-js/generate-init.ts +2 -2
- package/src/ir-to-client-js/html-template.ts +41 -19
- package/src/ir-to-client-js/index.ts +9 -3
- package/src/ir-to-client-js/phases/ref-callbacks.ts +1 -1
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +16 -15
- package/src/ir-to-client-js/plan/declaration-emit.ts +7 -5
- package/src/ir-to-client-js/prop-handling.ts +4 -0
- package/src/ir-to-client-js/reactivity.ts +21 -16
- package/src/ir-to-client-js/source-map.ts +2 -1
- package/src/ir-to-client-js/stringify/declaration-emit.ts +14 -7
- package/src/ir-to-client-js/types.ts +4 -0
- package/src/ir-to-client-js/utils.ts +89 -7
- package/src/jsx-to-ir.ts +772 -50
- package/src/opaque-local-accessor.ts +44 -0
- package/src/rich-type-refusal.ts +1 -1
- package/src/signal-initializer.ts +36 -0
- package/src/template-position-walk.ts +203 -0
- package/src/to-locale-date-lowering.ts +7 -4
- package/src/types.ts +103 -15
- package/dist/format-date-lowering.d.ts +0 -30
- package/dist/format-date-lowering.d.ts.map +0 -1
- package/src/__tests__/create-selector.test.ts +0 -124
- package/src/__tests__/format-date-lowering.test.ts +0 -125
- package/src/format-date-lowering.ts +0 -55
package/src/debug.ts
CHANGED
|
@@ -32,6 +32,8 @@ import { decideWrapFromAstFlags } from './ir-to-client-js/reactivity.ts'
|
|
|
32
32
|
import { tokenContainsIdent } from './ir-to-client-js/utils.ts'
|
|
33
33
|
import { identifierCallPattern } from './identifier-pattern.ts'
|
|
34
34
|
import { BindingScope } from './scope/binding-scope.ts'
|
|
35
|
+
import { ACTION_ACCESSOR_NAMES, collectActionAccessorReads, collectActionNames, parsedExprChildren, type ActionAccessorName } from './action-accessor.ts'
|
|
36
|
+
import { parseExpression, tsNodeToParsedExpr, type ParsedExpr } from './expression-parser.ts'
|
|
35
37
|
|
|
36
38
|
// =============================================================================
|
|
37
39
|
// Types
|
|
@@ -44,6 +46,55 @@ export interface SignalNode {
|
|
|
44
46
|
initialValue: string
|
|
45
47
|
consumers: string[] // names of memos/effects/DOM nodes that read this signal
|
|
46
48
|
loc: { file: string; line: number }
|
|
49
|
+
/**
|
|
50
|
+
* Set when this signal is the value half of an async reactive factory
|
|
51
|
+
* (`createQuery` / `createMutation`, spec/async.md §7.8): the value is
|
|
52
|
+
* written by the factory's request, not by a setter. The same object as the
|
|
53
|
+
* factory's entry in `ComponentGraph.factories`.
|
|
54
|
+
*/
|
|
55
|
+
factory?: AsyncFactoryInfo
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The async factory behind a signal node (#3167). A query is a signal
|
|
60
|
+
* source with inputs: `requestDeps` are the signals, memos and props its
|
|
61
|
+
* request function reads, each of which re-sends the request when it changes
|
|
62
|
+
* (so each lists `query:<value>` among its consumers). Only the request
|
|
63
|
+
* function counts: `options` is read once, at creation. A mutation's request
|
|
64
|
+
* function is read untracked, only when the action is called, so its
|
|
65
|
+
* `requestDeps` is always empty.
|
|
66
|
+
*/
|
|
67
|
+
export interface AsyncFactoryInfo {
|
|
68
|
+
/**
|
|
69
|
+
* How `query:<key>` edges and `AccessorNode.factory` name the factory: its
|
|
70
|
+
* value signal, or its action when the value isn't destructured
|
|
71
|
+
* (`const [, save] = createMutation(…)` — the graph never shows the
|
|
72
|
+
* synthesized getter such a declaration gets).
|
|
73
|
+
*/
|
|
74
|
+
key: string
|
|
75
|
+
kind: 'query' | 'mutation'
|
|
76
|
+
/** The callee as written: `createQuery`, `createMutation`, an alias, or `bf.createQuery`. */
|
|
77
|
+
callee: string
|
|
78
|
+
/** The action binding, or `null` when it isn't destructured. */
|
|
79
|
+
action: string | null
|
|
80
|
+
/** The value signal, or `null` when the value isn't destructured. */
|
|
81
|
+
value: string | null
|
|
82
|
+
requestDeps: string[]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* An async action's reactive accessor, `<action>.isPending()` or
|
|
87
|
+
* `<action>.error()` (#3167). Named `<action>.<accessor>` — the same
|
|
88
|
+
* spelling a binding's `deps` uses for a read of it.
|
|
89
|
+
*/
|
|
90
|
+
export interface AccessorNode {
|
|
91
|
+
kind: 'accessor'
|
|
92
|
+
name: string
|
|
93
|
+
action: string
|
|
94
|
+
accessor: ActionAccessorName
|
|
95
|
+
/** The owning factory's `AsyncFactoryInfo.key`. */
|
|
96
|
+
factory: string
|
|
97
|
+
consumers: string[] // names of memos/effects/DOM nodes that read this accessor
|
|
47
98
|
}
|
|
48
99
|
|
|
49
100
|
export interface MemoNode {
|
|
@@ -74,8 +125,10 @@ export interface DomBinding {
|
|
|
74
125
|
* member as `<propsObject>.<member>` (`props.value`) — and a prop read
|
|
75
126
|
* through a prop-derived local const (`class={classes}`) is reported as the
|
|
76
127
|
* underlying prop(s), never the const. Every entry resolves to a node in
|
|
77
|
-
* `ComponentGraph.signals` / `.memos` / `.props
|
|
78
|
-
*
|
|
128
|
+
* `ComponentGraph.signals` / `.memos` / `.props`, or — for an async action's
|
|
129
|
+
* accessor read (`save.isPending()`, #3167) — `<action>.<accessor>`, a node
|
|
130
|
+
* in `ComponentGraph.accessors`. Event handlers instead list the setters /
|
|
131
|
+
* getters the handler body references.
|
|
79
132
|
*/
|
|
80
133
|
deps: string[]
|
|
81
134
|
type: 'text' | 'event' | 'conditional' | 'loop' | 'attribute'
|
|
@@ -142,18 +195,22 @@ export interface ComponentGraph {
|
|
|
142
195
|
memos: MemoNode[]
|
|
143
196
|
effects: EffectNode[]
|
|
144
197
|
props: PropNode[]
|
|
198
|
+
/** Async factories (`createQuery` / `createMutation`, #3167), in declaration order. */
|
|
199
|
+
factories: AsyncFactoryInfo[]
|
|
200
|
+
/** Their actions' accessors. */
|
|
201
|
+
accessors: AccessorNode[]
|
|
145
202
|
domBindings: DomBinding[]
|
|
146
203
|
}
|
|
147
204
|
|
|
148
205
|
export interface UpdatePath {
|
|
149
206
|
target: string
|
|
150
|
-
kind: 'signal' | 'memo' | 'prop'
|
|
207
|
+
kind: 'signal' | 'memo' | 'prop' | 'accessor'
|
|
151
208
|
dependents: UpdatePathEntry[]
|
|
152
209
|
}
|
|
153
210
|
|
|
154
211
|
export interface UpdatePathEntry {
|
|
155
212
|
name: string
|
|
156
|
-
kind: 'memo' | 'effect' | 'dom'
|
|
213
|
+
kind: 'memo' | 'effect' | 'dom' | 'query'
|
|
157
214
|
label: string
|
|
158
215
|
/** Transitive dependents — memos/effects that depend on this entry */
|
|
159
216
|
children: UpdatePathEntry[]
|
|
@@ -230,7 +287,7 @@ export interface WhyUpdateResult {
|
|
|
230
287
|
|
|
231
288
|
export interface WhyUpdateDep {
|
|
232
289
|
name: string
|
|
233
|
-
kind: 'signal' | 'memo' | 'prop'
|
|
290
|
+
kind: 'signal' | 'memo' | 'prop' | 'accessor'
|
|
234
291
|
dependsOn: string[]
|
|
235
292
|
changedBy: WhyUpdateSource[]
|
|
236
293
|
}
|
|
@@ -286,6 +343,8 @@ export function buildComponentGraph(source: string, filePath: string, componentN
|
|
|
286
343
|
memos: [],
|
|
287
344
|
effects: [],
|
|
288
345
|
props: [],
|
|
346
|
+
factories: [],
|
|
347
|
+
accessors: [],
|
|
289
348
|
domBindings: [],
|
|
290
349
|
}
|
|
291
350
|
}
|
|
@@ -299,6 +358,8 @@ export function buildComponentGraph(source: string, filePath: string, componentN
|
|
|
299
358
|
memos: [],
|
|
300
359
|
effects: [],
|
|
301
360
|
props: [],
|
|
361
|
+
factories: [],
|
|
362
|
+
accessors: [],
|
|
302
363
|
domBindings: [],
|
|
303
364
|
}
|
|
304
365
|
}
|
|
@@ -415,91 +476,58 @@ export function buildGraphFromIR(ir: ComponentIR): ComponentGraph {
|
|
|
415
476
|
return [...out]
|
|
416
477
|
}
|
|
417
478
|
|
|
479
|
+
// Async factories (#3167, spec/async.md §7.8). An action's accessor read
|
|
480
|
+
// (`save.isPending()`) is a reactive source like a signal read, so it lands
|
|
481
|
+
// in a binding's deps as `<action>.<accessor>`. Reads are found by the same
|
|
482
|
+
// `ParsedExpr` traversal BF117 uses, over the ORIGINAL expression text: the
|
|
483
|
+
// IR's own `.parsed` / `.parsedCondition` at an admitted position has
|
|
484
|
+
// already been replaced by the SSR seed (`seedActionAccessorReads`), so the
|
|
485
|
+
// read is no longer there. Parsed only when an action name appears in the
|
|
486
|
+
// text as a token.
|
|
487
|
+
const actions = collectActionNames(meta.signals)
|
|
488
|
+
const accessorNames = new Set<string>()
|
|
489
|
+
for (const action of actions) for (const accessor of ACTION_ACCESSOR_NAMES) accessorNames.add(`${action}.${accessor}`)
|
|
490
|
+
const accessorDepsOf = (expr: string, isShadowed?: (name: string) => boolean): string[] =>
|
|
491
|
+
[...actions].some(action => tokenContainsIdent(expr, action))
|
|
492
|
+
? collectActionAccessorReads(parseExpression(expr), actions, isShadowed).map(r => `${r.action}.${r.accessor}`)
|
|
493
|
+
: []
|
|
494
|
+
|
|
418
495
|
// Collect DOM bindings from IR tree
|
|
419
496
|
const domBindings: DomBinding[] = []
|
|
420
|
-
collectDomBindings(ir.root, domBindings, signalGetters, memoNames, undefined, BindingScope.EMPTY, propDepsOf)
|
|
421
|
-
|
|
422
|
-
//
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
// Build consumer lists for memos
|
|
449
|
-
const memoConsumers = new Map<string, string[]>()
|
|
450
|
-
for (const m of meta.memos) memoConsumers.set(m.name, [])
|
|
451
|
-
|
|
452
|
-
for (let i = 0; i < meta.effects.length; i++) {
|
|
453
|
-
const effect = meta.effects[i]
|
|
454
|
-
for (const dep of effect.deps) {
|
|
455
|
-
memoConsumers.get(dep)?.push(`effect:e${i}`)
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
for (const dom of domBindings) {
|
|
460
|
-
for (const dep of dom.deps) {
|
|
461
|
-
memoConsumers.get(dep)?.push(`dom:${dom.label}`)
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
// Also track memo→memo dependencies
|
|
466
|
-
for (const memo of meta.memos) {
|
|
467
|
-
for (const dep of memo.deps) {
|
|
468
|
-
memoConsumers.get(dep)?.push(`memo:${memo.name}`)
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// Props are nodes too (#2903): every binding dep that is neither a signal
|
|
473
|
-
// nor a memo is a prop read (that is the only other thing `propDepsOf`
|
|
474
|
-
// contributes), keyed in first-seen order so the graph is stable.
|
|
475
|
-
const propConsumers = new Map<string, string[]>()
|
|
476
|
-
for (const dom of domBindings) {
|
|
477
|
-
if (dom.type === 'event') continue
|
|
478
|
-
for (const dep of dom.deps) {
|
|
479
|
-
if (signalGetters.has(dep) || memoNames.has(dep)) continue
|
|
480
|
-
let consumers = propConsumers.get(dep)
|
|
481
|
-
if (!consumers) {
|
|
482
|
-
consumers = []
|
|
483
|
-
propConsumers.set(dep, consumers)
|
|
484
|
-
}
|
|
485
|
-
consumers.push(`dom:${dom.label}`)
|
|
486
|
-
}
|
|
497
|
+
collectDomBindings(ir.root, domBindings, signalGetters, memoNames, undefined, BindingScope.EMPTY, propDepsOf, accessorDepsOf)
|
|
498
|
+
|
|
499
|
+
// A query's request function re-sends when a signal, memo or prop it reads
|
|
500
|
+
// changes, so each of those is an input of the query. `options` is read once
|
|
501
|
+
// at creation, and a mutation's request function is read untracked (at call
|
|
502
|
+
// time only): neither has inputs.
|
|
503
|
+
const factories: AsyncFactoryInfo[] = []
|
|
504
|
+
const factoryOf = new Map<SignalInfo, AsyncFactoryInfo>()
|
|
505
|
+
for (const s of meta.signals) {
|
|
506
|
+
if (!s.factory) continue
|
|
507
|
+
const value = s.getterElided ? null : s.getter
|
|
508
|
+
const ids = s.factory.requestFreeIdentifiers
|
|
509
|
+
const info: AsyncFactoryInfo = {
|
|
510
|
+
key: value ?? s.factory.action ?? s.getter,
|
|
511
|
+
kind: s.factory.kind,
|
|
512
|
+
callee: s.factory.callee,
|
|
513
|
+
action: s.factory.action,
|
|
514
|
+
value,
|
|
515
|
+
requestDeps: s.factory.kind === 'query'
|
|
516
|
+
? [
|
|
517
|
+
...[...ids].filter(id => id !== s.getter && (signalGetters.has(id) || memoNames.has(id))),
|
|
518
|
+
...propDepsOf(s.factory.requestText, ids),
|
|
519
|
+
]
|
|
520
|
+
: [],
|
|
521
|
+
}
|
|
522
|
+
factories.push(info)
|
|
523
|
+
factoryOf.set(s, info)
|
|
487
524
|
}
|
|
488
525
|
|
|
489
|
-
const signals: SignalNode[] = meta.signals.map(s => ({
|
|
490
|
-
kind: 'signal',
|
|
491
|
-
name: s.getter,
|
|
492
|
-
setter: s.setter,
|
|
493
|
-
initialValue: s.initialValue,
|
|
494
|
-
consumers: signalConsumers.get(s.getter) ?? [],
|
|
495
|
-
loc: { file: s.loc.file, line: s.loc.start.line },
|
|
496
|
-
}))
|
|
497
|
-
|
|
498
526
|
const memos: MemoNode[] = meta.memos.map(m => ({
|
|
499
527
|
kind: 'memo',
|
|
500
528
|
name: m.name,
|
|
501
|
-
deps: m.deps,
|
|
502
|
-
consumers:
|
|
529
|
+
deps: [...m.deps, ...bodyAccessorDeps(m.computation, actions)],
|
|
530
|
+
consumers: [],
|
|
503
531
|
computation: m.computation,
|
|
504
532
|
loc: { file: m.loc.file, line: m.loc.start.line },
|
|
505
533
|
}))
|
|
@@ -507,17 +535,75 @@ export function buildGraphFromIR(ir: ComponentIR): ComponentGraph {
|
|
|
507
535
|
const effects: EffectNode[] = meta.effects.map((e, i) => ({
|
|
508
536
|
kind: 'effect',
|
|
509
537
|
label: `e${i}`,
|
|
510
|
-
deps: e.deps,
|
|
538
|
+
deps: [...e.deps, ...bodyAccessorDeps(e.body, actions)],
|
|
511
539
|
body: e.body,
|
|
512
540
|
loc: { file: e.loc.file, line: e.loc.start.line },
|
|
513
541
|
}))
|
|
514
542
|
|
|
543
|
+
// Consumer lists: signals, memos and accessors are keyed up front; a prop
|
|
544
|
+
// is keyed the first time something reads it (#2903), in first-seen order
|
|
545
|
+
// so the graph is stable. A binding dep that is neither a signal, a memo
|
|
546
|
+
// nor an accessor is a prop read.
|
|
547
|
+
const signalConsumers = new Map<string, string[]>(meta.signals.map(s => [s.getter, []]))
|
|
548
|
+
const memoConsumers = new Map<string, string[]>(meta.memos.map(m => [m.name, []]))
|
|
549
|
+
const accessorConsumers = new Map<string, string[]>([...accessorNames].map(name => [name, []]))
|
|
550
|
+
const propConsumers = new Map<string, string[]>()
|
|
551
|
+
const addConsumer = (dep: string, consumer: string, props: boolean): void => {
|
|
552
|
+
const consumers = signalConsumers.get(dep) ?? memoConsumers.get(dep) ?? accessorConsumers.get(dep)
|
|
553
|
+
if (consumers) {
|
|
554
|
+
consumers.push(consumer)
|
|
555
|
+
} else if (props) {
|
|
556
|
+
const list = propConsumers.get(dep) ?? []
|
|
557
|
+
propConsumers.set(dep, list)
|
|
558
|
+
list.push(consumer)
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
for (const m of memos) for (const dep of m.deps) addConsumer(dep, `memo:${m.name}`, false)
|
|
562
|
+
for (const e of effects) for (const dep of e.deps) addConsumer(dep, `effect:${e.label}`, false)
|
|
563
|
+
for (const dom of domBindings) {
|
|
564
|
+
for (const dep of dom.deps) addConsumer(dep, `dom:${dom.label}`, dom.type !== 'event')
|
|
565
|
+
}
|
|
566
|
+
// A query's request inputs, props included (#3167).
|
|
567
|
+
for (const f of factories) for (const dep of f.requestDeps) addConsumer(dep, `query:${f.key}`, true)
|
|
568
|
+
for (const m of memos) m.consumers = memoConsumers.get(m.name) ?? []
|
|
569
|
+
|
|
570
|
+
const signals: SignalNode[] = meta.signals.filter(s => !(s.factory && s.getterElided)).map(s => {
|
|
571
|
+
const factory = factoryOf.get(s)
|
|
572
|
+
return {
|
|
573
|
+
kind: 'signal',
|
|
574
|
+
name: s.getter,
|
|
575
|
+
setter: s.setter,
|
|
576
|
+
initialValue: s.initialValue,
|
|
577
|
+
consumers: signalConsumers.get(s.getter) ?? [],
|
|
578
|
+
loc: { file: s.loc.file, line: s.loc.start.line },
|
|
579
|
+
...(factory && { factory }),
|
|
580
|
+
}
|
|
581
|
+
})
|
|
582
|
+
|
|
515
583
|
const props: PropNode[] = [...propConsumers].map(([name, consumers]) => ({
|
|
516
584
|
kind: 'prop',
|
|
517
585
|
name,
|
|
518
586
|
consumers,
|
|
519
587
|
}))
|
|
520
588
|
|
|
589
|
+
// Every accessor of every destructured action is a node, read or not, in
|
|
590
|
+
// declaration order — the same way every signal is listed.
|
|
591
|
+
const accessors: AccessorNode[] = factories.flatMap(f =>
|
|
592
|
+
f.action === null
|
|
593
|
+
? []
|
|
594
|
+
: [...ACTION_ACCESSOR_NAMES].map(accessor => {
|
|
595
|
+
const name = `${f.action}.${accessor}`
|
|
596
|
+
return {
|
|
597
|
+
kind: 'accessor' as const,
|
|
598
|
+
name,
|
|
599
|
+
action: f.action!,
|
|
600
|
+
accessor: accessor as ActionAccessorName,
|
|
601
|
+
factory: f.key,
|
|
602
|
+
consumers: accessorConsumers.get(name) ?? [],
|
|
603
|
+
}
|
|
604
|
+
}),
|
|
605
|
+
)
|
|
606
|
+
|
|
521
607
|
return {
|
|
522
608
|
componentName: meta.componentName,
|
|
523
609
|
sourceFile: findSourceFile(meta) ?? '',
|
|
@@ -525,10 +611,44 @@ export function buildGraphFromIR(ir: ComponentIR): ComponentGraph {
|
|
|
525
611
|
memos,
|
|
526
612
|
effects,
|
|
527
613
|
props,
|
|
614
|
+
factories,
|
|
615
|
+
accessors,
|
|
528
616
|
domBindings,
|
|
529
617
|
}
|
|
530
618
|
}
|
|
531
619
|
|
|
620
|
+
/**
|
|
621
|
+
* Accessor reads in a memo or effect body (#3167). Neither has a `ParsedExpr`
|
|
622
|
+
* that always covers its body — a block body only folds to a value expression
|
|
623
|
+
* in simple cases — so each expression the body holds is converted with
|
|
624
|
+
* `tsNodeToParsedExpr` and read by the same collector as a binding. A
|
|
625
|
+
* conversion that is not complete (it contains an `unsupported` node, such as
|
|
626
|
+
* a block-bodied callback passed to `forEach`) is searched inside instead of
|
|
627
|
+
* accepted, so a read under it is never lost; arrow-parameter shadowing holds
|
|
628
|
+
* wherever a conversion is complete. The body is parsed only when an action
|
|
629
|
+
* name appears in it as a token.
|
|
630
|
+
*/
|
|
631
|
+
function bodyAccessorDeps(body: string, actions: ReadonlySet<string>): string[] {
|
|
632
|
+
if (![...actions].some(action => tokenContainsIdent(body, action))) return []
|
|
633
|
+
const found = new Set<string>()
|
|
634
|
+
const visit = (node: ts.Node): void => {
|
|
635
|
+
if (ts.isExpression(node)) {
|
|
636
|
+
const parsed = tsNodeToParsedExpr(node)
|
|
637
|
+
if (!containsUnsupported(parsed)) {
|
|
638
|
+
for (const r of collectActionAccessorReads(parsed, actions)) found.add(`${r.action}.${r.accessor}`)
|
|
639
|
+
return
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
ts.forEachChild(node, visit)
|
|
643
|
+
}
|
|
644
|
+
visit(ts.createSourceFile('__body.tsx', `(${body})`, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX))
|
|
645
|
+
return [...found]
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function containsUnsupported(expr: ParsedExpr): boolean {
|
|
649
|
+
return expr.kind === 'unsupported' || parsedExprChildren(expr).some(child => containsUnsupported(child.expr))
|
|
650
|
+
}
|
|
651
|
+
|
|
532
652
|
/**
|
|
533
653
|
* Build both the ComponentIR and the reactive dependency graph in one pass.
|
|
534
654
|
* Callers that need the raw IR tree (events, loops, why-update) use this
|
|
@@ -1120,9 +1240,21 @@ export function traceUpdatePath(graph: ComponentGraph, targetName: string): Upda
|
|
|
1120
1240
|
if (memo) return { target: targetName, kind: 'memo', dependents: traceConsumers(memo.consumers, graph) }
|
|
1121
1241
|
const prop = graph.props.find(p => p.name === targetName)
|
|
1122
1242
|
if (prop) return { target: targetName, kind: 'prop', dependents: traceConsumers(prop.consumers, graph) }
|
|
1243
|
+
const accessor = graph.accessors.find(a => a.name === targetName)
|
|
1244
|
+
if (accessor) return { target: targetName, kind: 'accessor', dependents: traceConsumers(accessor.consumers, graph) }
|
|
1123
1245
|
return null
|
|
1124
1246
|
}
|
|
1125
1247
|
|
|
1248
|
+
/** Every name `traceUpdatePath` accepts: signals, memos, props and action accessors (#3167). */
|
|
1249
|
+
export function traceableNames(graph: ComponentGraph): string[] {
|
|
1250
|
+
return [
|
|
1251
|
+
...graph.signals.map(s => s.name),
|
|
1252
|
+
...graph.memos.map(m => m.name),
|
|
1253
|
+
...graph.props.map(p => p.name),
|
|
1254
|
+
...graph.accessors.map(a => a.name),
|
|
1255
|
+
]
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1126
1258
|
function traceConsumers(consumers: string[], graph: ComponentGraph): UpdatePathEntry[] {
|
|
1127
1259
|
return consumers.map(consumer => buildUpdateEntry(consumer, graph, new Set()))
|
|
1128
1260
|
}
|
|
@@ -1158,6 +1290,19 @@ function buildUpdateEntry(consumer: string, graph: ComponentGraph, visited: Set<
|
|
|
1158
1290
|
return { name: name, kind: 'dom', label: name, children: [] }
|
|
1159
1291
|
}
|
|
1160
1292
|
|
|
1293
|
+
// A query re-sends its request (#3167): its value and its accessors update,
|
|
1294
|
+
// so their readers are its dependents. `name` is the factory key: the value
|
|
1295
|
+
// signal, or the action when the value isn't destructured.
|
|
1296
|
+
if (type === 'query') {
|
|
1297
|
+
const value = graph.signals.find(s => s.name === name)
|
|
1298
|
+
const readers = [
|
|
1299
|
+
...(value?.consumers ?? []),
|
|
1300
|
+
...graph.accessors.filter(a => a.factory === name).flatMap(a => a.consumers),
|
|
1301
|
+
]
|
|
1302
|
+
const children = [...new Set(readers)].map(c => buildUpdateEntry(c, graph, new Set(visited)))
|
|
1303
|
+
return { name, kind: 'query', label: `${name} (query)`, children }
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1161
1306
|
return { name: consumer, kind: 'effect', label: consumer, children: [] }
|
|
1162
1307
|
}
|
|
1163
1308
|
|
|
@@ -1188,12 +1333,26 @@ export function buildWhyUpdate(
|
|
|
1188
1333
|
}
|
|
1189
1334
|
const binding = matches[0]
|
|
1190
1335
|
|
|
1336
|
+
// An async action is its factory's setter for this purpose (#3167): a
|
|
1337
|
+
// handler that calls it (`onClick={() => save()}`, directly or through a
|
|
1338
|
+
// local function) changes the factory's value and accessors, so it maps to
|
|
1339
|
+
// the factory's key and rides the same setter-call resolution.
|
|
1191
1340
|
const setterToSignal = new Map<string, string>()
|
|
1192
1341
|
for (const s of ir.metadata.signals) {
|
|
1193
1342
|
if (s.setter) setterToSignal.set(s.setter, s.getter)
|
|
1194
1343
|
}
|
|
1344
|
+
for (const f of graph.factories) {
|
|
1345
|
+
if (f.action) setterToSignal.set(f.action, f.key)
|
|
1346
|
+
}
|
|
1195
1347
|
const fnSetters = buildLocalFunctionSetterMap(ir.metadata, setterToSignal)
|
|
1196
1348
|
const events = collectEventBindings(ir.root, setterToSignal, fnSetters)
|
|
1349
|
+
const changedByOf = (key: string): WhyUpdateSource[] =>
|
|
1350
|
+
events.flatMap(ev =>
|
|
1351
|
+
ev.setterCalls
|
|
1352
|
+
.filter(sc => sc.signal === key)
|
|
1353
|
+
.map(sc => ({ handler: ev.eventName, setter: sc.setter, elementContext: ev.elementContext, via: sc.via })),
|
|
1354
|
+
)
|
|
1355
|
+
const factoryByKey = new Map(graph.factories.map(f => [f.key, f]))
|
|
1197
1356
|
|
|
1198
1357
|
const deps: WhyUpdateDep[] = []
|
|
1199
1358
|
const visited = new Set<string>()
|
|
@@ -1202,7 +1361,17 @@ export function buildWhyUpdate(
|
|
|
1202
1361
|
if (visited.has(name)) return
|
|
1203
1362
|
visited.add(name)
|
|
1204
1363
|
|
|
1205
|
-
|
|
1364
|
+
// A factory's value, or one of its action's accessors (#3167): changed by
|
|
1365
|
+
// a call of the action, and — for a query — by any of its request inputs.
|
|
1366
|
+
const accessor = graph.accessors.find(a => a.name === name)
|
|
1367
|
+
const signal = accessor ? undefined : graph.signals.find(s => s.name === name)
|
|
1368
|
+
const factory = factoryByKey.get(accessor?.factory ?? signal?.factory?.key ?? '')
|
|
1369
|
+
if (factory) {
|
|
1370
|
+
deps.push({ name, kind: accessor ? 'accessor' : 'signal', dependsOn: factory.requestDeps, changedBy: changedByOf(factory.key) })
|
|
1371
|
+
for (const dep of factory.requestDeps) traceDep(dep)
|
|
1372
|
+
return
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1206
1375
|
if (signal) {
|
|
1207
1376
|
const changedBy: WhyUpdateSource[] = []
|
|
1208
1377
|
for (const ev of events) {
|
|
@@ -1272,7 +1441,9 @@ export function formatWhyUpdate(result: WhyUpdateResult): string {
|
|
|
1272
1441
|
lines.push(' (prop — the parent component passes a new value)')
|
|
1273
1442
|
} else {
|
|
1274
1443
|
lines.push(`${dep.name} changes from:`)
|
|
1275
|
-
|
|
1444
|
+
// A query's value and accessors also change when a request input does (#3167).
|
|
1445
|
+
for (const d of dep.dependsOn) lines.push(` ${d} (re-sends the request)`)
|
|
1446
|
+
if (dep.changedBy.length === 0 && dep.dependsOn.length === 0) {
|
|
1276
1447
|
lines.push(' (no event handlers found)')
|
|
1277
1448
|
}
|
|
1278
1449
|
for (const src of dep.changedBy) {
|
|
@@ -1301,7 +1472,25 @@ export function formatComponentGraph(graph: ComponentGraph): string {
|
|
|
1301
1472
|
if (graph.signals.length > 0) {
|
|
1302
1473
|
lines.push(` signals:`)
|
|
1303
1474
|
for (const s of graph.signals) {
|
|
1304
|
-
|
|
1475
|
+
// An async factory's value (#3167): which factory writes it, its
|
|
1476
|
+
// action, and — for a query — the inputs its request function reads.
|
|
1477
|
+
const factory = s.factory
|
|
1478
|
+
? ` [${s.factory.callee}${s.factory.action ? `, action ${s.factory.action}` : ''}]` +
|
|
1479
|
+
(s.factory.requestDeps.length > 0 ? ` <- ${s.factory.requestDeps.join(', ')}` : '')
|
|
1480
|
+
: ''
|
|
1481
|
+
lines.push(` ${s.name} (initial: ${s.initialValue})${factory}`)
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
// Async actions' accessors (#3167), listed so the `<action>.<accessor> ->`
|
|
1486
|
+
// edges below have a node to point at.
|
|
1487
|
+
if (graph.accessors.length > 0) {
|
|
1488
|
+
const factoryByKey = new Map(graph.factories.map(f => [f.key, f]))
|
|
1489
|
+
lines.push(` accessors:`)
|
|
1490
|
+
for (const a of graph.accessors) {
|
|
1491
|
+
const f = factoryByKey.get(a.factory)
|
|
1492
|
+
const owner = f?.value ? `of ${f.value}` : `${f?.callee}, value not destructured`
|
|
1493
|
+
lines.push(` ${a.name}() (${owner})`)
|
|
1305
1494
|
}
|
|
1306
1495
|
}
|
|
1307
1496
|
|
|
@@ -1373,7 +1562,7 @@ export function formatComponentGraph(graph: ComponentGraph): string {
|
|
|
1373
1562
|
}
|
|
1374
1563
|
|
|
1375
1564
|
// Dependency graph
|
|
1376
|
-
if (graph.signals.length > 0 || graph.memos.length > 0 || graph.props.length > 0) {
|
|
1565
|
+
if (graph.signals.length > 0 || graph.memos.length > 0 || graph.props.length > 0 || graph.accessors.length > 0) {
|
|
1377
1566
|
lines.push(` dependency graph:`)
|
|
1378
1567
|
for (const s of graph.signals) {
|
|
1379
1568
|
for (const consumer of s.consumers) {
|
|
@@ -1390,6 +1579,11 @@ export function formatComponentGraph(graph: ComponentGraph): string {
|
|
|
1390
1579
|
lines.push(` ${p.name} -> ${consumer}`)
|
|
1391
1580
|
}
|
|
1392
1581
|
}
|
|
1582
|
+
for (const a of graph.accessors) {
|
|
1583
|
+
for (const consumer of a.consumers) {
|
|
1584
|
+
lines.push(` ${a.name} -> ${consumer}`)
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1393
1587
|
}
|
|
1394
1588
|
|
|
1395
1589
|
return lines.join('\n')
|
|
@@ -1433,6 +1627,7 @@ export function graphToJSON(graph: ComponentGraph): object {
|
|
|
1433
1627
|
initialValue: s.initialValue,
|
|
1434
1628
|
consumers: s.consumers,
|
|
1435
1629
|
loc: s.loc,
|
|
1630
|
+
...(s.factory && { factory: s.factory }),
|
|
1436
1631
|
})),
|
|
1437
1632
|
memos: graph.memos.map(m => ({
|
|
1438
1633
|
name: m.name,
|
|
@@ -1451,6 +1646,14 @@ export function graphToJSON(graph: ComponentGraph): object {
|
|
|
1451
1646
|
name: p.name,
|
|
1452
1647
|
consumers: p.consumers,
|
|
1453
1648
|
})),
|
|
1649
|
+
factories: graph.factories,
|
|
1650
|
+
accessors: graph.accessors.map(a => ({
|
|
1651
|
+
name: a.name,
|
|
1652
|
+
action: a.action,
|
|
1653
|
+
accessor: a.accessor,
|
|
1654
|
+
factory: a.factory,
|
|
1655
|
+
consumers: a.consumers,
|
|
1656
|
+
})),
|
|
1454
1657
|
domBindings: graph.domBindings.map(d => ({
|
|
1455
1658
|
label: d.label,
|
|
1456
1659
|
slotId: d.slotId,
|
|
@@ -1806,6 +2009,11 @@ function collectDomBindings(
|
|
|
1806
2009
|
// the graph prints `(no tracked deps)` for it (#2903). Returns the prop
|
|
1807
2010
|
// names, which join `deps` alongside signal / memo reads.
|
|
1808
2011
|
propDepsOf: (expr: string, freeIds?: ReadonlySet<string>, isShadowed?: (name: string) => boolean) => string[] = () => [],
|
|
2012
|
+
// Which async action accessors (`save.isPending()`, #3167) does a binding's
|
|
2013
|
+
// expression read, as `<action>.<accessor>`? A statically known reactive
|
|
2014
|
+
// source like a signal read, under the same loop-scope shadow guard as
|
|
2015
|
+
// `propDepsOf`.
|
|
2016
|
+
accessorDepsOf: (expr: string, isShadowed?: (name: string) => boolean) => string[] = () => [],
|
|
1809
2017
|
): void {
|
|
1810
2018
|
const boundNames = scope.valueBoundNames()
|
|
1811
2019
|
// Shadow guard for prop deps (see `propDepsOf`'s `isShadowed` in
|
|
@@ -1850,7 +2058,10 @@ function collectDomBindings(
|
|
|
1850
2058
|
if (attr.name === 'key' && boundNames.size > 0) continue
|
|
1851
2059
|
const expr = attrValueToString(attr.value)
|
|
1852
2060
|
if (!expr) continue
|
|
1853
|
-
const signalDeps =
|
|
2061
|
+
const signalDeps = [
|
|
2062
|
+
...extractReactiveDeps(expr, signalGetters, memoNames),
|
|
2063
|
+
...accessorDepsOf(expr, isShadowed),
|
|
2064
|
+
]
|
|
1854
2065
|
const isReactive = signalDeps.length > 0 || attrReadsLoopParam(attr.freeIdentifiers)
|
|
1855
2066
|
// A prop-driven attribute (`id={props.id}`, `class={`…${props.x}`}`) is
|
|
1856
2067
|
// wrapped in a `createEffect` by the emitter even with no signal/memo
|
|
@@ -1892,7 +2103,7 @@ function collectDomBindings(
|
|
|
1892
2103
|
}
|
|
1893
2104
|
// Recurse — pass element tag as parent context for text bindings
|
|
1894
2105
|
for (const child of node.children) {
|
|
1895
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, node.tag, scope, propDepsOf)
|
|
2106
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, node.tag, scope, propDepsOf, accessorDepsOf)
|
|
1896
2107
|
}
|
|
1897
2108
|
break
|
|
1898
2109
|
}
|
|
@@ -1901,9 +2112,11 @@ function collectDomBindings(
|
|
|
1901
2112
|
// `node.reactive || node.callsReactiveGetters || node.hasFunctionCalls`.
|
|
1902
2113
|
const decision = decideWrapFromAstFlags(node)
|
|
1903
2114
|
const loopReactive = exprReadsLoopParam(node)
|
|
1904
|
-
|
|
2115
|
+
const accessorDeps = accessorDepsOf(node.expr, isShadowed)
|
|
2116
|
+
if ((decision.wrap || loopReactive || accessorDeps.length > 0) && node.slotId) {
|
|
1905
2117
|
const deps = [
|
|
1906
2118
|
...extractReactiveDeps(node.expr, signalGetters, memoNames),
|
|
2119
|
+
...accessorDeps,
|
|
1907
2120
|
...propDepsOf(node.expr, freeIdsOf(node.origin), isShadowed),
|
|
1908
2121
|
]
|
|
1909
2122
|
const preview = parentTag
|
|
@@ -1916,11 +2129,11 @@ function collectDomBindings(
|
|
|
1916
2129
|
deps,
|
|
1917
2130
|
type: 'text',
|
|
1918
2131
|
classification:
|
|
1919
|
-
(decision.wrap && decision.reason === 'proven-reactive') || loopReactive
|
|
2132
|
+
(decision.wrap && decision.reason === 'proven-reactive') || loopReactive || accessorDeps.length > 0
|
|
1920
2133
|
? 'reactive'
|
|
1921
2134
|
: 'fallback',
|
|
1922
2135
|
expression: node.expr,
|
|
1923
|
-
wrapReason: decision.wrap ? decision.reason : 'string-reactive',
|
|
2136
|
+
wrapReason: decision.wrap && accessorDeps.length === 0 ? decision.reason : 'string-reactive',
|
|
1924
2137
|
loc: node.loc,
|
|
1925
2138
|
jsxPreview: preview,
|
|
1926
2139
|
})
|
|
@@ -1934,9 +2147,11 @@ function collectDomBindings(
|
|
|
1934
2147
|
// param is neither signal nor memo. Use the resolved `origin.freeRefs`.
|
|
1935
2148
|
const loopReactive =
|
|
1936
2149
|
boundNames.size > 0 && (node.origin?.freeRefs?.some(r => boundNames.has(r.name)) ?? false)
|
|
1937
|
-
|
|
2150
|
+
const accessorDeps = accessorDepsOf(node.condition, isShadowed)
|
|
2151
|
+
if ((decision.wrap || loopReactive || accessorDeps.length > 0) && node.slotId) {
|
|
1938
2152
|
const deps = [
|
|
1939
2153
|
...extractReactiveDeps(node.condition, signalGetters, memoNames),
|
|
2154
|
+
...accessorDeps,
|
|
1940
2155
|
...propDepsOf(node.condition, freeIdsOf(node.origin), isShadowed),
|
|
1941
2156
|
]
|
|
1942
2157
|
bindings.push({
|
|
@@ -1946,17 +2161,17 @@ function collectDomBindings(
|
|
|
1946
2161
|
deps,
|
|
1947
2162
|
type: 'conditional',
|
|
1948
2163
|
classification:
|
|
1949
|
-
(decision.wrap && decision.reason === 'proven-reactive') || loopReactive
|
|
2164
|
+
(decision.wrap && decision.reason === 'proven-reactive') || loopReactive || accessorDeps.length > 0
|
|
1950
2165
|
? 'reactive'
|
|
1951
2166
|
: 'fallback',
|
|
1952
2167
|
expression: node.condition,
|
|
1953
|
-
wrapReason: decision.wrap ? decision.reason : 'string-reactive',
|
|
2168
|
+
wrapReason: decision.wrap && accessorDeps.length === 0 ? decision.reason : 'string-reactive',
|
|
1954
2169
|
loc: node.loc,
|
|
1955
2170
|
jsxPreview: `{${truncateExpr(node.condition)} ? ... : ...}`,
|
|
1956
2171
|
})
|
|
1957
2172
|
}
|
|
1958
|
-
collectDomBindings(node.whenTrue, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf)
|
|
1959
|
-
collectDomBindings(node.whenFalse, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf)
|
|
2173
|
+
collectDomBindings(node.whenTrue, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf)
|
|
2174
|
+
collectDomBindings(node.whenFalse, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf)
|
|
1960
2175
|
break
|
|
1961
2176
|
}
|
|
1962
2177
|
case 'loop': {
|
|
@@ -2007,7 +2222,7 @@ function collectDomBindings(
|
|
|
2007
2222
|
// `paramBindings`/`preamble`), so no bespoke Set bookkeeping is needed.
|
|
2008
2223
|
const childScope = scope.enterLoopRow(node)
|
|
2009
2224
|
for (const child of node.children) {
|
|
2010
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, childScope, propDepsOf)
|
|
2225
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, childScope, propDepsOf, accessorDepsOf)
|
|
2011
2226
|
}
|
|
2012
2227
|
break
|
|
2013
2228
|
}
|
|
@@ -2047,21 +2262,21 @@ function collectDomBindings(
|
|
|
2047
2262
|
}
|
|
2048
2263
|
}
|
|
2049
2264
|
for (const child of node.children) {
|
|
2050
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf)
|
|
2265
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf)
|
|
2051
2266
|
}
|
|
2052
2267
|
break
|
|
2053
2268
|
}
|
|
2054
2269
|
case 'fragment':
|
|
2055
2270
|
case 'provider': {
|
|
2056
2271
|
for (const child of node.children) {
|
|
2057
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf)
|
|
2272
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf)
|
|
2058
2273
|
}
|
|
2059
2274
|
break
|
|
2060
2275
|
}
|
|
2061
2276
|
case 'if-statement': {
|
|
2062
|
-
collectDomBindings(node.consequent, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf)
|
|
2277
|
+
collectDomBindings(node.consequent, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf)
|
|
2063
2278
|
if (node.alternate) {
|
|
2064
|
-
collectDomBindings(node.alternate, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf)
|
|
2279
|
+
collectDomBindings(node.alternate, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf)
|
|
2065
2280
|
}
|
|
2066
2281
|
break
|
|
2067
2282
|
}
|