@barefootjs/jsx 0.37.0 → 0.38.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/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/analyzer.d.ts +40 -0
- package/dist/analyzer.d.ts.map +1 -1
- 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/errors.d.ts +3 -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 +37 -0
- package/dist/format-date-refusal.d.ts.map +1 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2973 -2310
- package/dist/ir-to-client-js/collect-elements.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 +13 -2
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop.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/lazy-conditional.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-child-arm.d.ts +9 -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 +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/control-flow/stringify/loop-child-arm.d.ts +9 -1
- package/dist/ir-to-client-js/control-flow/stringify/loop-child-arm.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/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts +16 -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 +2 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +26 -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/opaque-local-accessor.d.ts +27 -0
- package/dist/opaque-local-accessor.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 +53 -17
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +724 -4564
- 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__/doc-examples.test.ts +12 -22
- 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 +80 -0
- 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__/ref-attr-absent-at-ssr.test.ts +472 -0
- package/src/__tests__/ssr-portal-ref-callback.test.ts +217 -0
- package/src/adapters/env-signal.ts +2 -21
- package/src/adapters/interface.ts +13 -0
- package/src/analyzer.ts +40 -28
- package/src/builtin-lowering-plugins.ts +0 -2
- package/src/compiler.ts +24 -0
- package/src/component-root-scope-comment.ts +59 -0
- package/src/errors.ts +44 -1
- package/src/event-handler-name.ts +14 -0
- package/src/expression-parser.ts +41 -17
- package/src/format-date-refusal.ts +266 -0
- package/src/index.ts +13 -3
- package/src/ir-to-client-js/child-components.ts +8 -3
- package/src/ir-to-client-js/collect-elements.ts +29 -13
- 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-loop-child-arm.ts +31 -1
- package/src/ir-to-client-js/control-flow/plan/build-loop.ts +23 -11
- package/src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts +5 -0
- package/src/ir-to-client-js/control-flow/plan/lazy-conditional.ts +1 -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-child-arm.ts +11 -0
- 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/loop-child-arm.ts +22 -1
- package/src/ir-to-client-js/emit-reactive.ts +140 -10
- package/src/ir-to-client-js/emit-registration.ts +2 -2
- 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 +4 -3
- package/src/ir-to-client-js/reactivity.ts +28 -17
- package/src/ir-to-client-js/source-map.ts +2 -1
- package/src/ir-to-client-js/types.ts +2 -0
- package/src/ir-to-client-js/utils.ts +34 -0
- package/src/jsx-to-ir.ts +737 -49
- package/src/opaque-local-accessor.ts +44 -0
- package/src/rich-type-refusal.ts +1 -1
- package/src/to-locale-date-lowering.ts +7 -4
- package/src/types.ts +51 -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
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `checkAuthoredFormatDateCalls` (#3089, BF056): a direct call to
|
|
3
|
+
* `formatDate` imported from `@barefootjs/client` (or its `/runtime`
|
|
4
|
+
* subpath) in a template-lowered position is refused at compile time,
|
|
5
|
+
* uniformly across every adapter including Hono.
|
|
6
|
+
*
|
|
7
|
+
* This is a POLICY decision, not a template-language capability gap:
|
|
8
|
+
* `formatDate` is compiler ABI — the lowering TARGET the `.toLocaleDateString()`
|
|
9
|
+
* sugar rewrites to (`to-locale-date-lowering.ts`), emitted by the compiler
|
|
10
|
+
* itself into generated client JS and every adapter's native `format_date`
|
|
11
|
+
* helper (`spec/template-helpers.md`) — never an authored API. So this check
|
|
12
|
+
* fires ahead of `adapter.generate()` in the shared IR-build phase and is
|
|
13
|
+
* pinned identically on all nine adapters, the same "every backend, no
|
|
14
|
+
* exceptions" shape `checkRichTypePropSerialization` (BF049,
|
|
15
|
+
* `rich-type-refusal.ts`) uses for a hydration-transport gap that is equally
|
|
16
|
+
* universal on Hono's JS-runtime leg as on the 8 template-language adapters'
|
|
17
|
+
* leg.
|
|
18
|
+
*
|
|
19
|
+
* A `/* @client *\/`-escaped position is skipped — deferring the whole read
|
|
20
|
+
* to the client means real JS evaluates it there, and the still-exported
|
|
21
|
+
* (now `@internal`) runtime function works fine as ordinary client code.
|
|
22
|
+
*
|
|
23
|
+
* Deliberately a SEPARATE walk from `checkRichTypeMethodCalls`
|
|
24
|
+
* (`rich-type-refusal.ts`), which answers a different question (does a
|
|
25
|
+
* METHOD CALL on a host-rich-typed receiver have a catalogued lowering) and
|
|
26
|
+
* short-circuits when the component has no `propsType` — a `formatDate`
|
|
27
|
+
* call needs no receiver type at all and can appear in a props-free
|
|
28
|
+
* component, so it cannot share that early return. The tree coverage below
|
|
29
|
+
* intentionally mirrors that module's `walkNode` / `walkAttrValue` /
|
|
30
|
+
* `walkTemplateParts` (element/component/provider attrs, loop array +
|
|
31
|
+
* children, conditional/if-statement branches, async fallback + children)
|
|
32
|
+
* for the same reason both checks need it: "every position a template
|
|
33
|
+
* could render" — for two unrelated predicates.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import type {
|
|
37
|
+
IRNode,
|
|
38
|
+
IRMetadata,
|
|
39
|
+
CompilerError,
|
|
40
|
+
SourceLocation,
|
|
41
|
+
AttrValue,
|
|
42
|
+
IRTemplatePart,
|
|
43
|
+
} from './types.ts'
|
|
44
|
+
import type { ParsedExpr } from './expression-parser.ts'
|
|
45
|
+
import { parseExpression } from './expression-parser.ts'
|
|
46
|
+
import { ErrorCodes } from './errors.ts'
|
|
47
|
+
|
|
48
|
+
/** Entries that re-export the pure client `formatDate` helper (#2324). */
|
|
49
|
+
const FORMAT_DATE_SOURCES: ReadonlySet<string> = new Set([
|
|
50
|
+
'@barefootjs/client',
|
|
51
|
+
'@barefootjs/client/runtime',
|
|
52
|
+
])
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The local binding name(s) `formatDate` is imported under in this
|
|
56
|
+
* component — matched by exported name, gated on the LOCAL alias, accepted
|
|
57
|
+
* from both the main entry and the runtime re-export. Mirrors the shape of
|
|
58
|
+
* the removed `formatDateLocalNames` (`adapters/env-signal.ts`), rebuilt
|
|
59
|
+
* here since this is now the only consumer of that resolution.
|
|
60
|
+
*/
|
|
61
|
+
function collectFormatDateBoundNames(metadata: IRMetadata): Set<string> {
|
|
62
|
+
const names = new Set<string>()
|
|
63
|
+
for (const imp of metadata.imports) {
|
|
64
|
+
if (!FORMAT_DATE_SOURCES.has(imp.source) || imp.isTypeOnly) continue
|
|
65
|
+
for (const s of imp.specifiers) {
|
|
66
|
+
if (s.isTypeOnly || s.isNamespace || s.isDefault) continue
|
|
67
|
+
if (s.name === 'formatDate') names.add(s.alias ?? s.name)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return names
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function checkAuthoredFormatDateCalls(root: IRNode, metadata: IRMetadata, errors: CompilerError[]): void {
|
|
74
|
+
const names = collectFormatDateBoundNames(metadata)
|
|
75
|
+
if (names.size === 0) return
|
|
76
|
+
const seen = new Set<string>()
|
|
77
|
+
walkNode(root, names, errors, seen)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function pushDiagnostic(errors: CompilerError[], seen: Set<string>, loc: SourceLocation, name: string): void {
|
|
81
|
+
const key = `${loc.start.line}:${loc.start.column}`
|
|
82
|
+
if (seen.has(key)) return
|
|
83
|
+
seen.add(key)
|
|
84
|
+
errors.push({
|
|
85
|
+
code: ErrorCodes.FORMAT_DATE_AUTHORED_CALL,
|
|
86
|
+
severity: 'error',
|
|
87
|
+
message:
|
|
88
|
+
`'${name}(...)' cannot be called directly — formatDate is compiler ABI (the lowering target of the ` +
|
|
89
|
+
`.toLocaleDateString() sugar), not an authored API.`,
|
|
90
|
+
loc,
|
|
91
|
+
suggestion: {
|
|
92
|
+
message:
|
|
93
|
+
"Use date.toLocaleDateString(locale, { timeZone, ... }) with a literal locale and an explicit literal " +
|
|
94
|
+
"timeZone (a canonical IANA zone ID, a fixed '±HH:MM' offset, or 'UTC') so it compiles to the format_date " +
|
|
95
|
+
'helper, or defer the whole read to the client with /* @client */ — it runs as real JS in the browser, so ' +
|
|
96
|
+
'it can call any date-formatting API you like, including this one.',
|
|
97
|
+
escape: [{ kind: 'client-directive' }],
|
|
98
|
+
},
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Does `expr`'s tree contain a call whose callee is one of `names`? Mirrors `checkExpr`'s tree coverage (rich-type-refusal.ts). */
|
|
103
|
+
function exprCallsName(expr: ParsedExpr, names: ReadonlySet<string>): boolean {
|
|
104
|
+
switch (expr.kind) {
|
|
105
|
+
case 'call':
|
|
106
|
+
if (expr.callee.kind === 'identifier' && names.has(expr.callee.name)) return true
|
|
107
|
+
if (exprCallsName(expr.callee, names)) return true
|
|
108
|
+
return expr.args.some((a) => exprCallsName(a, names))
|
|
109
|
+
case 'member':
|
|
110
|
+
return exprCallsName(expr.object, names)
|
|
111
|
+
case 'index-access':
|
|
112
|
+
return exprCallsName(expr.object, names) || exprCallsName(expr.index, names)
|
|
113
|
+
case 'binary':
|
|
114
|
+
return exprCallsName(expr.left, names) || exprCallsName(expr.right, names)
|
|
115
|
+
case 'unary':
|
|
116
|
+
return exprCallsName(expr.argument, names)
|
|
117
|
+
case 'conditional':
|
|
118
|
+
return (
|
|
119
|
+
exprCallsName(expr.test, names) ||
|
|
120
|
+
exprCallsName(expr.consequent, names) ||
|
|
121
|
+
exprCallsName(expr.alternate, names)
|
|
122
|
+
)
|
|
123
|
+
case 'logical':
|
|
124
|
+
return exprCallsName(expr.left, names) || exprCallsName(expr.right, names)
|
|
125
|
+
case 'template-literal':
|
|
126
|
+
return expr.parts.some((p) => p.type === 'expression' && exprCallsName(p.expr, names))
|
|
127
|
+
case 'arrow':
|
|
128
|
+
return exprCallsName(expr.body, names)
|
|
129
|
+
case 'array-literal':
|
|
130
|
+
return expr.elements.some((e) => exprCallsName(e, names))
|
|
131
|
+
case 'object-literal':
|
|
132
|
+
return expr.properties.some((p) => exprCallsName(p.kind === 'spread' ? p.expr : p.value, names))
|
|
133
|
+
case 'array-method': {
|
|
134
|
+
if (exprCallsName(expr.object, names)) return true
|
|
135
|
+
if (expr.args.some((a) => exprCallsName(a, names))) return true
|
|
136
|
+
if (expr.method === 'flat' && expr.depthExpr) return exprCallsName(expr.depthExpr, names)
|
|
137
|
+
return false
|
|
138
|
+
}
|
|
139
|
+
case 'identifier':
|
|
140
|
+
case 'literal':
|
|
141
|
+
case 'regex':
|
|
142
|
+
case 'unsupported':
|
|
143
|
+
return false
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** First bound name, for the diagnostic message — the exact alias matters far less than firing at all. */
|
|
148
|
+
function anyName(names: ReadonlySet<string>): string {
|
|
149
|
+
for (const n of names) return n
|
|
150
|
+
return 'formatDate'
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* `IRTemplatePart.ternary.condition` / `.lookup.key` carry no attached
|
|
155
|
+
* parse (unlike every other position here), so parse on demand — same as
|
|
156
|
+
* `rich-type-refusal.ts`'s `walkTemplateParts`. `ternary.whenTrue` /
|
|
157
|
+
* `.whenFalse` are ALSO raw, unparsed text (the per-branch rendered
|
|
158
|
+
* snippet), so they get the same on-demand treatment: this is exactly the
|
|
159
|
+
* `format-date-ternary` shape (#2843) — a call in a ternary CONSEQUENT
|
|
160
|
+
* inside a structured template-literal attribute.
|
|
161
|
+
*/
|
|
162
|
+
function walkTemplateParts(
|
|
163
|
+
parts: readonly IRTemplatePart[],
|
|
164
|
+
loc: SourceLocation,
|
|
165
|
+
names: ReadonlySet<string>,
|
|
166
|
+
errors: CompilerError[],
|
|
167
|
+
seen: Set<string>,
|
|
168
|
+
): void {
|
|
169
|
+
const checkText = (text: string) => {
|
|
170
|
+
const trimmed = text.trim()
|
|
171
|
+
if (!trimmed) return
|
|
172
|
+
if (exprCallsName(parseExpression(trimmed), names)) pushDiagnostic(errors, seen, loc, anyName(names))
|
|
173
|
+
}
|
|
174
|
+
for (const part of parts) {
|
|
175
|
+
if (part.type === 'ternary') {
|
|
176
|
+
checkText(part.condition)
|
|
177
|
+
checkText(part.whenTrue)
|
|
178
|
+
checkText(part.whenFalse)
|
|
179
|
+
} else if (part.type === 'lookup') {
|
|
180
|
+
checkText(part.key)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function walkAttrValue(
|
|
186
|
+
value: AttrValue,
|
|
187
|
+
clientOnly: boolean | undefined,
|
|
188
|
+
loc: SourceLocation,
|
|
189
|
+
names: ReadonlySet<string>,
|
|
190
|
+
errors: CompilerError[],
|
|
191
|
+
seen: Set<string>,
|
|
192
|
+
): void {
|
|
193
|
+
if (clientOnly) return
|
|
194
|
+
if (value.kind === 'expression') {
|
|
195
|
+
if (value.parsed && exprCallsName(value.parsed, names)) pushDiagnostic(errors, seen, loc, anyName(names))
|
|
196
|
+
if (value.parts) walkTemplateParts(value.parts, loc, names, errors, seen)
|
|
197
|
+
} else if (value.kind === 'spread') {
|
|
198
|
+
if (value.parsed && exprCallsName(value.parsed, names)) pushDiagnostic(errors, seen, loc, anyName(names))
|
|
199
|
+
} else if (value.kind === 'template') {
|
|
200
|
+
walkTemplateParts(value.parts, loc, names, errors, seen)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function walkNode(node: IRNode, names: ReadonlySet<string>, errors: CompilerError[], seen: Set<string>): void {
|
|
205
|
+
if (node.type === 'expression') {
|
|
206
|
+
if (!node.clientOnly && node.parsed && exprCallsName(node.parsed, names)) {
|
|
207
|
+
pushDiagnostic(errors, seen, node.loc, anyName(names))
|
|
208
|
+
}
|
|
209
|
+
} else if (node.type === 'conditional') {
|
|
210
|
+
if (!node.clientOnly && node.parsedCondition && exprCallsName(node.parsedCondition, names)) {
|
|
211
|
+
pushDiagnostic(errors, seen, node.loc, anyName(names))
|
|
212
|
+
}
|
|
213
|
+
} else if (node.type === 'if-statement') {
|
|
214
|
+
if (node.parsedCondition && exprCallsName(node.parsedCondition, names)) {
|
|
215
|
+
pushDiagnostic(errors, seen, node.loc, anyName(names))
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (node.type === 'element') {
|
|
220
|
+
for (const attr of node.attrs) walkAttrValue(attr.value, attr.clientOnly, attr.loc, names, errors, seen)
|
|
221
|
+
} else if (node.type === 'component') {
|
|
222
|
+
for (const prop of node.props) walkAttrValue(prop.value, prop.clientOnly, prop.loc, names, errors, seen)
|
|
223
|
+
} else if (node.type === 'provider') {
|
|
224
|
+
walkAttrValue(node.valueProp.value, node.valueProp.clientOnly, node.valueProp.loc, names, errors, seen)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
switch (node.type) {
|
|
228
|
+
case 'element':
|
|
229
|
+
case 'component':
|
|
230
|
+
case 'fragment':
|
|
231
|
+
case 'provider':
|
|
232
|
+
for (const child of node.children) walkNode(child, names, errors, seen)
|
|
233
|
+
break
|
|
234
|
+
case 'async':
|
|
235
|
+
walkNode(node.fallback, names, errors, seen)
|
|
236
|
+
for (const child of node.children) walkNode(child, names, errors, seen)
|
|
237
|
+
break
|
|
238
|
+
case 'loop': {
|
|
239
|
+
if (node.clientOnly) break
|
|
240
|
+
if (node.arrayParsed && exprCallsName(node.arrayParsed, names)) pushDiagnostic(errors, seen, node.loc, anyName(names))
|
|
241
|
+
for (const child of node.children) walkNode(child, names, errors, seen)
|
|
242
|
+
if (node.childComponent) {
|
|
243
|
+
for (const child of node.childComponent.children) walkNode(child, names, errors, seen)
|
|
244
|
+
}
|
|
245
|
+
for (const nested of node.nestedComponents ?? []) {
|
|
246
|
+
for (const child of nested.children) walkNode(child, names, errors, seen)
|
|
247
|
+
}
|
|
248
|
+
for (const seg of node.flatMapCallback?.segments ?? []) {
|
|
249
|
+
if (seg.kind === 'jsx') walkNode(seg.ir, names, errors, seen)
|
|
250
|
+
}
|
|
251
|
+
for (const seg of node.preamble?.segments ?? []) {
|
|
252
|
+
if (seg.kind === 'jsx') walkNode(seg.ir, names, errors, seen)
|
|
253
|
+
}
|
|
254
|
+
break
|
|
255
|
+
}
|
|
256
|
+
case 'conditional':
|
|
257
|
+
if (node.clientOnly) break
|
|
258
|
+
walkNode(node.whenTrue, names, errors, seen)
|
|
259
|
+
walkNode(node.whenFalse, names, errors, seen)
|
|
260
|
+
break
|
|
261
|
+
case 'if-statement':
|
|
262
|
+
walkNode(node.consequent, names, errors, seen)
|
|
263
|
+
if (node.alternate) walkNode(node.alternate, names, errors, seen)
|
|
264
|
+
break
|
|
265
|
+
}
|
|
266
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,16 @@ export type { CompileResult, CompileOptions, CompileOptionsWithAdapter, FileOutp
|
|
|
11
11
|
// SSR template-variable defaults (manifest seeds for stash-based adapters)
|
|
12
12
|
export { extractSsrDefaults, deriveStashFromDefaults } from './ssr-defaults.ts'
|
|
13
13
|
|
|
14
|
+
// #3144: shared "is this a component-body local bound to an opaque call"
|
|
15
|
+
// check, consulted by every non-JS-runtime adapter's `call()` fallback
|
|
16
|
+
// before it treats a zero-arg identifier call as a signal getter.
|
|
17
|
+
export { isOpaqueLocalAccessorName } from './opaque-local-accessor.ts'
|
|
18
|
+
|
|
19
|
+
// The one event-handler-name classification (`on[A-Z]`) — `only`/`once` are
|
|
20
|
+
// data props, not handlers. Shared by the IR builder, client-JS prop wiring
|
|
21
|
+
// and the SSR adapters' "a handler has no SSR value" skips.
|
|
22
|
+
export { isEventHandlerName } from './event-handler-name.ts'
|
|
23
|
+
|
|
14
24
|
// Shared props-destructure binding + alias-map helpers (#2524, #2788)
|
|
15
25
|
export { propsDestructureBinding, buildPropAliasMap, isIdentifierName, resolveBodyDestructuredPropAliases } from './props-binding.ts'
|
|
16
26
|
export type { SsrDefault } from './ssr-defaults.ts'
|
|
@@ -79,7 +89,7 @@ export type {
|
|
|
79
89
|
} from './types.ts'
|
|
80
90
|
|
|
81
91
|
// Analyzer
|
|
82
|
-
export { analyzeComponent, listComponentFunctions, listComponentFunctions as listExportedComponents, scanComponentFile, createProgramForFile, needsTypeBasedDetection, REACTIVE_PRIMITIVES, BROWSER_ONLY_CLIENT_APIS, type AnalyzerContext, type ComponentFileScan } from './analyzer.ts'
|
|
92
|
+
export { analyzeComponent, listComponentFunctions, listComponentFunctions as listExportedComponents, scanComponentFile, createProgramForFile, needsTypeBasedDetection, resolveRelativeImportToFile, REACTIVE_PRIMITIVES, BROWSER_ONLY_CLIENT_APIS, type AnalyzerContext, type ComponentFileScan } from './analyzer.ts'
|
|
83
93
|
export { createProgramForCorpus, type SharedProgramOptions } from './shared-program.ts'
|
|
84
94
|
|
|
85
95
|
// JSX to IR transformer
|
|
@@ -111,7 +121,7 @@ export type { ParsedExprEmitter, LoweringEmitter, HigherOrderMethod, ArrayMethod
|
|
|
111
121
|
export { collectLoopBoundNames } from './adapters/loop-bound-names.ts'
|
|
112
122
|
export { derivesScopeFromSlot } from './adapters/child-scope.ts'
|
|
113
123
|
export { evaluateStaticLiteral, isFullyStaticLiteral, resolveStaticLoopSource } from './static-literal.ts'
|
|
114
|
-
export { importsSearchParams, searchParamsLocalNames, envSignalLocalNames, envSignalReaderFor, ENV_SIGNAL_READERS, queryHrefLocalNames,
|
|
124
|
+
export { importsSearchParams, searchParamsLocalNames, envSignalLocalNames, envSignalReaderFor, ENV_SIGNAL_READERS, queryHrefLocalNames, matchSearchParamsMethodCall } from './adapters/env-signal.ts'
|
|
115
125
|
export type { EnvSignalReader } from './adapters/env-signal.ts'
|
|
116
126
|
export { matchQueryHrefCall, queryHrefArgs, type QueryHrefCall, type QueryHrefTriple } from './query-href-lowering.ts'
|
|
117
127
|
export {
|
|
@@ -225,7 +235,7 @@ export { ErrorCodes, createError, formatError, generateCodeFrame } from './error
|
|
|
225
235
|
export { isValueReferenceIdentifier, collectValueReferencedNames } from './value-references.ts'
|
|
226
236
|
|
|
227
237
|
// Expression Parser
|
|
228
|
-
export { parseExpression, tsNodeToParsedExpr, asCallbackMethodCall, CALLBACK_METHODS, sortComparatorFromArrow, serializeParsedExpr, freeVarsInBody, freeIdentifiers, materializeGetterCalls, isSupported, isSupportedValue, exprToString, stringifyParsedExpr, identifierPath, parseBlockBody, parseBlockBodyTolerant, foldBlockToExpr, predicateTernaryToLogical, containsHigherOrder, extractArrowBodyExpression, parseStyleObjectEntries, hasUnsafeStyleValue, parseProviderObjectLiteral, type ProviderObjectMember, type FoldBlockOptions } from './expression-parser.ts'
|
|
238
|
+
export { parseExpression, tsNodeToParsedExpr, asCallbackMethodCall, CALLBACK_METHODS, sortComparatorFromArrow, serializeParsedExpr, freeVarsInBody, freeIdentifiers, materializeGetterCalls, isSupported, isSupportedValue, exprToString, stringifyParsedExpr, identifierPath, parseBlockBody, parseBlockBodyTolerant, foldBlockToExpr, predicateTernaryToLogical, containsHigherOrder, extractArrowBodyExpression, parseStyleObjectEntries, hasUnsafeStyleValue, parseProviderObjectLiteral, isFunctionShapedExpression, type ProviderObjectMember, type FoldBlockOptions } from './expression-parser.ts'
|
|
229
239
|
export type { StyleObjectEntry } from './expression-parser.ts'
|
|
230
240
|
export { PARSED_EXPR_KINDS, ARRAY_METHOD_NAMES, SORT_KEY_TYPES, SORT_KEY_TARGETS, SORT_KEY_DIRECTIONS } from './expression-parser.ts'
|
|
231
241
|
export type { ParsedExpr, ObjectLiteralProperty, ParsedStatement, SortComparator, SortKey, FlatDepth, SupportLevel, SupportResult, TemplatePart } from './expression-parser.ts'
|
|
@@ -89,14 +89,19 @@ export function collectComponentNamesFromIR(nodes: IRNode[], names: Set<string>)
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
|
-
* Collect child component names from conditional
|
|
93
|
-
*
|
|
94
|
-
*
|
|
92
|
+
* Collect child component names from conditional branches: the branch's
|
|
93
|
+
* own child components, components inside composite loops within the
|
|
94
|
+
* branch (e.g., Badge inside a branch loop), and nested conditionals.
|
|
95
|
+
* A branch-owned child is initialized by the branch's `insert()`
|
|
96
|
+
* bindEvents, not through `ctx.childInits`, so it is named here.
|
|
95
97
|
*/
|
|
96
98
|
function collectChildNamesFromBranches(
|
|
97
99
|
cond: Pick<ConditionalElement, 'whenTrue' | 'whenFalse'>,
|
|
98
100
|
names: Set<string>,
|
|
99
101
|
): void {
|
|
102
|
+
for (const child of [...cond.whenTrue.childComponents, ...cond.whenFalse.childComponents]) {
|
|
103
|
+
names.add(child.name)
|
|
104
|
+
}
|
|
100
105
|
for (const loop of [...cond.whenTrue.loops, ...cond.whenFalse.loops]) {
|
|
101
106
|
if (loop.nestedComponents) {
|
|
102
107
|
for (const comp of loop.nestedComponents) names.add(comp.name)
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* IR tree traversal → collect elements into ClientJsContext.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { type IRNode, type IRElement, type IRComponent, type IRLoop, type IRProp, pickAttrMetaFromIR } from '../types.ts'
|
|
5
|
+
import { type IRNode, type IRElement, type IRComponent, type IRConditional, type IRLoop, type IRProp, pickAttrMetaFromIR } from '../types.ts'
|
|
6
6
|
import type { ClientJsContext, ConditionalBranchChildComponent, ConditionalBranchReactiveAttr, BranchLoop, ConditionalBranchTextEffect, ConditionalElement, LoopChildBindings, LoopChildBranchSummary, LoopChildConditional, LoopOffset, NestedLoop } from './types.ts'
|
|
7
7
|
import { attrValueToString, freeIdsFromRefs, quotePropName, PROPS_PARAM, type LoopParamSpec } from './utils.ts'
|
|
8
|
-
import { classifyReactivity, needsEffectWrapper, decideWrapForAttr, decideWrapForChildProp, decideWrapFromAstFlags, collectEventHandlersFromIR, collectConditionalBranchEvents, collectConditionalBranchRefs, collectConditionalBranchChildComponents, collectLoopChildEventsWithNesting, collectLoopChildReactiveAttrs, collectLoopChildReactiveTexts, collectLoopChildRefs, emptyLoopChildBindings, buildLoopRowScope, anyNameIn } from './reactivity.ts'
|
|
8
|
+
import { classifyReactivity, needsEffectWrapper, decideWrapForAttr, decideWrapForChildProp, decideWrapFromAstFlags, collectEventHandlersFromIR, collectConditionalBranchEvents, collectConditionalBranchRefs, collectConditionalBranchChildComponents, collectConditionalBranchComponentNodes, collectLoopChildEventsWithNesting, collectLoopChildReactiveAttrs, collectLoopChildReactiveTexts, collectLoopChildRefs, emptyLoopChildBindings, buildLoopRowScope, anyNameIn } from './reactivity.ts'
|
|
9
9
|
import { irToHtmlTemplate, irToPlaceholderTemplate, irChildrenToJsExpr, jsxChildrenPropGetterExpr, buildLoopSkeletonTemplate, computeSkeletonSlotPaths, renderFlatMapClientBody, renderFlatMapProjectionClientBody, flatMapCallbackHasKeyedLeaf, type SkeletonSlotPaths } from './html-template.ts'
|
|
10
10
|
import { detectRootNamespaceWrapTag } from './control-flow/stringify/template-parse.ts'
|
|
11
11
|
import { expandDynamicPropValue, expandConstantForReactivity, resolveRestSpreadOrigin, resolveRestSpreadNames } from './prop-handling.ts'
|
|
@@ -14,6 +14,7 @@ import { walkIR, stopAt } from './walker.ts'
|
|
|
14
14
|
import { buildLoopChainExpr } from '../loop-chain.ts'
|
|
15
15
|
import { classifyDOMProp } from '@barefootjs/shared'
|
|
16
16
|
import type { BindingScope } from '../scope/binding-scope.ts'
|
|
17
|
+
import { isEventHandlerName } from '../event-handler-name.ts'
|
|
17
18
|
|
|
18
19
|
/** Expressions that render nothing (0 DOM nodes) — `&&` / `?:` empty branches. */
|
|
19
20
|
const EMPTY_RENDER_EXPRS = new Set(['null', 'undefined', 'false', "''", '""', '``'])
|
|
@@ -402,7 +403,7 @@ export function collectInnerLoops(
|
|
|
402
403
|
props: c.props.map(p => ({
|
|
403
404
|
name: p.name,
|
|
404
405
|
value: p.value,
|
|
405
|
-
isEventHandler:
|
|
406
|
+
isEventHandler: isEventHandlerName(p.name),
|
|
406
407
|
})),
|
|
407
408
|
children: c.children,
|
|
408
409
|
loopDepth: emitDepth,
|
|
@@ -522,10 +523,7 @@ function buildComponentPropsExpr(props: IRProp[], ctx: ClientJsContext): string
|
|
|
522
523
|
for (const prop of props) {
|
|
523
524
|
if (prop.name === '...' || prop.name.startsWith('...')) continue
|
|
524
525
|
explicitPropNames.push(prop.name)
|
|
525
|
-
const isEventHandler =
|
|
526
|
-
prop.name.startsWith('on') &&
|
|
527
|
-
prop.name.length > 2 &&
|
|
528
|
-
prop.name[2] === prop.name[2].toUpperCase()
|
|
526
|
+
const isEventHandler = isEventHandlerName(prop.name)
|
|
529
527
|
if (isEventHandler) {
|
|
530
528
|
// Event handlers reach here only as `expression` variants.
|
|
531
529
|
propsForInit.push(`${quotePropName(prop.name)}: ${attrValueToString(prop.value) ?? prop.name}`)
|
|
@@ -652,6 +650,18 @@ export function collectElements(
|
|
|
652
650
|
siblingOffsets: Map<IRLoop, IRNode[]>,
|
|
653
651
|
insideConditional = false,
|
|
654
652
|
): void {
|
|
653
|
+
// Child components an emitted conditional's branch initializes itself
|
|
654
|
+
// (its `bindEvents` → `initChild`). The static child-init pass below
|
|
655
|
+
// must skip exactly these: a second, parent-owned init of the same child
|
|
656
|
+
// doubles every effect / listener and survives the branch's removal —
|
|
657
|
+
// and once `insert()` re-renders the branch it even targets a detached
|
|
658
|
+
// node, so `initChild`'s re-entry guard can't catch it.
|
|
659
|
+
const branchOwnedComponents = new Set<IRComponent>()
|
|
660
|
+
const claimBranchComponents = (c: IRConditional): void => {
|
|
661
|
+
for (const branch of [c.whenTrue, c.whenFalse]) {
|
|
662
|
+
for (const comp of collectConditionalBranchComponentNodes(branch)) branchOwnedComponents.add(comp)
|
|
663
|
+
}
|
|
664
|
+
}
|
|
655
665
|
walkIR<boolean>(node, insideConditional, {
|
|
656
666
|
element: ({ node: el, scope: inCond, descend }) => {
|
|
657
667
|
collectFromElement(el, ctx, inCond)
|
|
@@ -692,6 +702,7 @@ export function collectElements(
|
|
|
692
702
|
conditional: ({ node: c, scope: inCond, descend }) => {
|
|
693
703
|
if (c.clientOnly && c.slotId) {
|
|
694
704
|
ctx.clientOnlyConditionals.push(buildConditionalMetadata(c, ctx, siblingOffsets))
|
|
705
|
+
claimBranchComponents(c)
|
|
695
706
|
} else if (c.slotId) {
|
|
696
707
|
// Solid-style wrap-by-default fallback (#941, follow-up to #937/#939).
|
|
697
708
|
// Wrap not only statically-proven-reactive conditions, but also any
|
|
@@ -702,6 +713,7 @@ export function collectElements(
|
|
|
702
713
|
// are collected by the enclosing conditional via `collectBranchConditionals`
|
|
703
714
|
// and emitted inside that conditional's bindEvents.
|
|
704
715
|
ctx.conditionalElements.push(buildConditionalMetadata(c, ctx, siblingOffsets))
|
|
716
|
+
claimBranchComponents(c)
|
|
705
717
|
}
|
|
706
718
|
}
|
|
707
719
|
// Recurse into both branches with insideConditional = true so
|
|
@@ -983,7 +995,7 @@ export function collectElements(
|
|
|
983
995
|
// Reactive props need effects to update the element when values change.
|
|
984
996
|
for (const prop of c.props) {
|
|
985
997
|
if (prop.value.kind === 'jsx-children') continue
|
|
986
|
-
if (
|
|
998
|
+
if (isEventHandlerName(prop.name)) continue
|
|
987
999
|
// Only `expression` variants reach the signal/memo getter heuristic
|
|
988
1000
|
// — literal / template / spread / boolean forms don't have a single
|
|
989
1001
|
// bare-identifier shape to lookup.
|
|
@@ -1007,11 +1019,13 @@ export function collectElements(
|
|
|
1007
1019
|
|
|
1008
1020
|
collectReactiveChildProps(c, ctx)
|
|
1009
1021
|
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1022
|
+
if (!branchOwnedComponents.has(c)) {
|
|
1023
|
+
ctx.childInits.push({
|
|
1024
|
+
name: c.name,
|
|
1025
|
+
slotId: c.slotId,
|
|
1026
|
+
propsExpr: buildComponentPropsExpr(c.props, ctx),
|
|
1027
|
+
})
|
|
1028
|
+
}
|
|
1015
1029
|
|
|
1016
1030
|
descend()
|
|
1017
1031
|
// Traverse JSX prop children so events, reactive expressions, and nested
|
|
@@ -1700,6 +1714,8 @@ function summarizeLoopChildBranch(
|
|
|
1700
1714
|
innerLoops: inner.length > 0 ? inner : undefined,
|
|
1701
1715
|
conditionals: collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex),
|
|
1702
1716
|
events: collectConditionalBranchEvents(node),
|
|
1717
|
+
// Mirrors the top-level `summarizeBranch`'s `refs` field (#3009).
|
|
1718
|
+
refs: collectConditionalBranchRefs(node),
|
|
1703
1719
|
// Loop-param-aware — reuses the flat loop-item collectors scoped to just
|
|
1704
1720
|
// this branch's subtree. Both already stop descending into any further
|
|
1705
1721
|
// nested reactive conditional (own insert()/arm), so calling them here
|
|
@@ -17,7 +17,7 @@ import { buildBranchLoopDelegationPlan } from './build-event-delegation.ts'
|
|
|
17
17
|
import { buildReactiveEffectsPlan } from './build-reactive-effects.ts'
|
|
18
18
|
import { buildPlainRowCore } from './build-plain-row.ts'
|
|
19
19
|
import type { LazyRowScopeInfo } from './lazy-row-eligibility.ts'
|
|
20
|
-
import { loopKeyFn, buildChildRefBindings } from '../shared.ts'
|
|
20
|
+
import { loopKeyFn, buildChildRefBindings, hasReactiveLoopBindings } from '../shared.ts'
|
|
21
21
|
import type {
|
|
22
22
|
BranchCompositeLoopPlan,
|
|
23
23
|
BranchLoopPlan,
|
|
@@ -43,9 +43,7 @@ export function buildBranchLoopPlan(
|
|
|
43
43
|
return composite
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const hasReactiveEffects = loop.bindings
|
|
47
|
-
|| loop.bindings.reactiveTexts.length > 0
|
|
48
|
-
|| loop.bindings.conditionals.length > 0
|
|
46
|
+
const hasReactiveEffects = hasReactiveLoopBindings(loop.bindings)
|
|
49
47
|
|
|
50
48
|
// flatMap descriptor mode — see buildPlainLoopPlan (build-loop.ts).
|
|
51
49
|
const fm = loop.flatMapClient
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import type { TopLevelLoop } from '../../types.ts'
|
|
15
|
+
import type { IRNode } from '../../../types.ts'
|
|
15
16
|
import {
|
|
16
17
|
buildChainedArrayExpr,
|
|
17
18
|
varSlotId,
|
|
@@ -25,12 +26,39 @@ import {
|
|
|
25
26
|
buildCompSelector,
|
|
26
27
|
isTextOnlyConditional,
|
|
27
28
|
buildChildRefBindings,
|
|
29
|
+
hasReactiveLoopBindings,
|
|
30
|
+
buildChildrenTextEffect,
|
|
28
31
|
} from '../shared.ts'
|
|
29
32
|
import { irChildrenToJsExpr, renderPreamble } from '../../html-template.ts'
|
|
30
33
|
import { buildReactiveEffectsPlan } from './build-reactive-effects.ts'
|
|
31
34
|
import type { ComponentLoopPlan, NestedComponentInit } from './types.ts'
|
|
32
35
|
import { internalInvariant } from '../../../errors.ts'
|
|
33
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Collect the `slotId` of every `expression` leaf reachable through
|
|
39
|
+
* `nodes` — recursing only through `text`/`expression`/text-only
|
|
40
|
+
* `conditional` nodes, mirroring exactly the shape `isTextOnlyConditional`
|
|
41
|
+
* validates. Used to find which of a component-root loop's own
|
|
42
|
+
* `elem.bindings.reactiveTexts` entries (collected via the generic,
|
|
43
|
+
* depth-unaware `collectLoopChildBindings` walk — see the comment below)
|
|
44
|
+
* are already patched by a NESTED child component's `childrenTextEffect`,
|
|
45
|
+
* so the row-level wiring doesn't ALSO patch them (#3143 follow-up: two
|
|
46
|
+
* independent effects racing to write — and, before #3064's marker-aware
|
|
47
|
+
* patch, one destroying the other's `<!--bf:^sN-->` markers outright —
|
|
48
|
+
* caught by `update-expected-html` fixture drift on `data-table`, whose
|
|
49
|
+
* `TableRow` loop forwards `<TableCell>{payment.id}</TableCell>` nested
|
|
50
|
+
* components).
|
|
51
|
+
*/
|
|
52
|
+
function collectTextOnlySlotIds(nodes: readonly IRNode[], into: Set<string>): void {
|
|
53
|
+
for (const node of nodes) {
|
|
54
|
+
if (node.type === 'expression') {
|
|
55
|
+
if (node.slotId) into.add(node.slotId)
|
|
56
|
+
} else if (node.type === 'conditional' && isTextOnlyConditional(node)) {
|
|
57
|
+
collectTextOnlySlotIds([node.whenTrue, node.whenFalse], into)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
34
62
|
/** @internal — prefer `buildLoopPlan`. */
|
|
35
63
|
export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?: string): ComponentLoopPlan {
|
|
36
64
|
const { name } = elem.childComponent!
|
|
@@ -56,6 +84,11 @@ export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?
|
|
|
56
84
|
|
|
57
85
|
// Only init components at loopDepth 0 — inner-loop components are handled by their own loop
|
|
58
86
|
const outerNestedComps = (elem.nestedComponents ?? []).filter(c => !c.loopDepth)
|
|
87
|
+
const wrap = (expr: string) => wrapLoopParamAsAccessor(expr, elem.param, elem.paramBindings, elem.index)
|
|
88
|
+
// Slot ids already patched by a nested component's OWN `childrenTextEffect`
|
|
89
|
+
// below — collected up front so the row-level reactive-texts wiring further
|
|
90
|
+
// down can exclude them (see the comment on that filter for why).
|
|
91
|
+
const nestedChildrenTextEffectSlotIds = new Set<string>()
|
|
59
92
|
const nestedComps: NestedComponentInit[] = outerNestedComps.map(comp => {
|
|
60
93
|
const isTextOnly = comp.children?.length
|
|
61
94
|
? comp.children.every(c => c.type === 'expression' || c.type === 'text' || isTextOnlyConditional(c))
|
|
@@ -64,17 +97,46 @@ export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?
|
|
|
64
97
|
const childrenFreeIds = isTextOnly && comp.children ? irChildrenFreeIds(comp.children) : undefined
|
|
65
98
|
const childrenRefsLoop = rawChildrenExpr != null && childrenFreeIds != null
|
|
66
99
|
&& (childrenFreeIds.has(elem.param) || (!!elem.index && childrenFreeIds.has(elem.index)))
|
|
100
|
+
if (childrenRefsLoop && comp.children) {
|
|
101
|
+
collectTextOnlySlotIds(comp.children, nestedChildrenTextEffectSlotIds)
|
|
102
|
+
}
|
|
67
103
|
return {
|
|
68
104
|
componentName: comp.name,
|
|
69
105
|
selector: buildCompSelector(comp),
|
|
70
106
|
propsExpr: buildComponentPropsExpr(comp, elem.param, undefined, elem.index),
|
|
107
|
+
// #3064: marker-scoped where possible — see `buildChildrenTextEffect`.
|
|
71
108
|
childrenTextEffect: childrenRefsLoop
|
|
72
|
-
?
|
|
109
|
+
? buildChildrenTextEffect(comp.children!, rawChildrenExpr!, wrap)
|
|
73
110
|
: null,
|
|
74
111
|
}
|
|
75
112
|
})
|
|
76
113
|
|
|
77
|
-
|
|
114
|
+
// #3143: a component-root loop's own reactive attrs/texts — collected via
|
|
115
|
+
// `collectLoopChildBindings` into `elem.bindings` the same way as every
|
|
116
|
+
// other loop shape (`collect-elements.ts`'s `loop:` visitor calls it
|
|
117
|
+
// unconditionally) — used to be silently dropped here: this builder only
|
|
118
|
+
// ever read `elem.bindings.conditionals`, never `.reactiveAttrs` /
|
|
119
|
+
// `.reactiveTexts`. Those two collectors DO reach a forwarded element
|
|
120
|
+
// inside the root component's own `<Chip>...</Chip>` JSX-children body
|
|
121
|
+
// (`traverseElements`'s default `walkIR` descent into an `IRComponent`
|
|
122
|
+
// node's `.children` — no `component:` visitor override needed, unlike
|
|
123
|
+
// the JSX-children PROP form), so the bindings were computed and then
|
|
124
|
+
// thrown away. Routing them through the same `ReactiveEffectsPlan` the
|
|
125
|
+
// conditionals already used fixes it — see `stringifyComponentLoop`'s
|
|
126
|
+
// gate, widened alongside this to actually emit the effects on the
|
|
127
|
+
// no-nested-components ("simple") path too.
|
|
128
|
+
//
|
|
129
|
+
// The SAME depth-unaware collector also reaches text expressions that
|
|
130
|
+
// are a NESTED component's own children (`<TableRow><TableCell>
|
|
131
|
+
// {payment.id}</TableCell></TableRow>`) — those already get their own
|
|
132
|
+
// patch via `nestedComps[].childrenTextEffect` above, so wiring them
|
|
133
|
+
// AGAIN here would emit two independent effects for the same slot (see
|
|
134
|
+
// `collectTextOnlySlotIds`'s doc comment). Filtered out before either
|
|
135
|
+
// the presence check or the plan itself sees them.
|
|
136
|
+
const rowReactiveTexts = nestedChildrenTextEffectSlotIds.size > 0
|
|
137
|
+
? elem.bindings.reactiveTexts.filter(t => !nestedChildrenTextEffectSlotIds.has(t.slotId))
|
|
138
|
+
: elem.bindings.reactiveTexts
|
|
139
|
+
const hasReactiveEffects = hasReactiveLoopBindings({ ...elem.bindings, reactiveTexts: rowReactiveTexts })
|
|
78
140
|
|
|
79
141
|
return {
|
|
80
142
|
kind: 'component',
|
|
@@ -101,10 +163,10 @@ export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?
|
|
|
101
163
|
// `childRefs`) is preserved; populated as empty.
|
|
102
164
|
childRefs: buildChildRefBindings(elem.bindings.refs, elem.param, elem.paramBindings, elem.index),
|
|
103
165
|
profileLoopId: profileComponentName ? `${profileComponentName}#binding:${elem.slotId}` : undefined,
|
|
104
|
-
|
|
166
|
+
reactiveEffects: hasReactiveEffects
|
|
105
167
|
? buildReactiveEffectsPlan({
|
|
106
|
-
attrs:
|
|
107
|
-
texts:
|
|
168
|
+
attrs: elem.bindings.reactiveAttrs,
|
|
169
|
+
texts: rowReactiveTexts,
|
|
108
170
|
conditionals: elem.bindings.conditionals,
|
|
109
171
|
loopParam: elem.param,
|
|
110
172
|
loopParamBindings: elem.paramBindings,
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
destructureLoopParam,
|
|
21
21
|
buildDepthLevels,
|
|
22
22
|
buildChildRefBindings,
|
|
23
|
+
hasReactiveLoopBindings,
|
|
23
24
|
} from '../shared.ts'
|
|
24
25
|
import { buildReactiveEffectsPlan } from './build-reactive-effects.ts'
|
|
25
26
|
import { buildInnerLoopsPlan } from './build-inner-loop.ts'
|
|
@@ -170,13 +171,9 @@ function filterCondCompsOut(
|
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
function hasReactive(elem: TopLevelLoop): boolean {
|
|
173
|
-
return elem.bindings
|
|
174
|
-
|| elem.bindings.reactiveTexts.length > 0
|
|
175
|
-
|| elem.bindings.conditionals.length > 0
|
|
174
|
+
return hasReactiveLoopBindings(elem.bindings)
|
|
176
175
|
}
|
|
177
176
|
|
|
178
177
|
function hasReactiveBranch(loop: BranchLoop): boolean {
|
|
179
|
-
return loop.bindings
|
|
180
|
-
|| loop.bindings.reactiveTexts.length > 0
|
|
181
|
-
|| loop.bindings.conditionals.length > 0
|
|
178
|
+
return hasReactiveLoopBindings(loop.bindings)
|
|
182
179
|
}
|