@barefootjs/jsx 0.39.8 → 0.39.9
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/callback-method.d.ts +19 -7
- package/dist/adapters/callback-method.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +2 -0
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
- package/dist/adapters/loop-plan.d.ts +133 -9
- package/dist/adapters/loop-plan.d.ts.map +1 -1
- package/dist/adapters/parsed-expr-emitter.d.ts +20 -3
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/assignment-target.d.ts +26 -0
- package/dist/assignment-target.d.ts.map +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1913 -1457
- package/dist/ir-to-client-js/compute-inlinability.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/loop.d.ts +24 -1
- 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 +16 -1
- 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 +6 -1
- 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 +13 -2
- package/dist/ir-to-client-js/csr-substitute.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/phases/props-extraction.d.ts +5 -3
- package/dist/ir-to-client-js/phases/props-extraction.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +8 -0
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/rewrite-props-object.d.ts.map +1 -1
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts +1 -0
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -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/prop-rewrite.d.ts +17 -8
- package/dist/prop-rewrite.d.ts.map +1 -1
- package/dist/props-binding.d.ts +57 -0
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/scope/binding-scope.d.ts +30 -2
- package/dist/scope/binding-scope.d.ts.map +1 -1
- package/dist/scope/lexical-scope-walk.d.ts +26 -0
- package/dist/scope/lexical-scope-walk.d.ts.map +1 -0
- package/dist/types.d.ts +25 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/arithmetic-lowering.test.ts +5 -1
- package/src/__tests__/binding-scope.test.ts +29 -0
- package/src/__tests__/create-query.test.ts +1 -1
- package/src/__tests__/emit-to-string-call.test.ts +58 -0
- package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +90 -31
- package/src/__tests__/loop-plan.test.ts +131 -1
- package/src/__tests__/loop-row-child-children-handler.test.ts +129 -0
- package/src/__tests__/loop-row-child-children-inner-loop-shadow.test.ts +74 -0
- package/src/__tests__/loop-row-child-children-ref.test.ts +117 -0
- package/src/__tests__/props-alias-const.test.ts +60 -1
- package/src/__tests__/props-named-callback-param.test.ts +256 -0
- package/src/__tests__/renamed-body-destructure-template.test.ts +86 -0
- package/src/__tests__/rewrite-props-object.test.ts +90 -0
- package/src/__tests__/written-binding-substitution.test.ts +430 -0
- package/src/adapters/callback-method.ts +25 -10
- package/src/adapters/dsl-template-adapter.ts +11 -0
- package/src/adapters/loop-plan.ts +201 -13
- package/src/adapters/parsed-expr-emitter.ts +37 -4
- package/src/analyzer.ts +283 -2
- package/src/assignment-target.ts +79 -0
- package/src/errors.ts +11 -0
- package/src/index.ts +13 -2
- package/src/ir-to-client-js/compute-inlinability.ts +6 -3
- package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +21 -5
- package/src/ir-to-client-js/control-flow/plan/loop.ts +25 -1
- package/src/ir-to-client-js/control-flow/shared.ts +41 -3
- package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +23 -3
- package/src/ir-to-client-js/csr-substitute.ts +70 -22
- package/src/ir-to-client-js/emit-reactive.ts +2 -2
- package/src/ir-to-client-js/emit-registration.ts +6 -1
- package/src/ir-to-client-js/html-template.ts +18 -7
- package/src/ir-to-client-js/phases/props-extraction.ts +26 -5
- package/src/ir-to-client-js/plan/build-static-array-child-init.ts +7 -0
- package/src/ir-to-client-js/plan/static-array-child-init.ts +8 -0
- package/src/ir-to-client-js/rewrite-destructured-props.ts +2 -2
- package/src/ir-to-client-js/rewrite-props-object.ts +14 -8
- package/src/ir-to-client-js/stringify/static-array-child-init.ts +4 -1
- package/src/ir-to-client-js/utils.ts +40 -96
- package/src/jsx-to-ir.ts +31 -12
- package/src/prop-rewrite.ts +31 -72
- package/src/props-binding.ts +73 -1
- package/src/scope/binding-scope.ts +34 -3
- package/src/scope/lexical-scope-walk.ts +167 -0
- package/src/types.ts +25 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether an identifier is WRITTEN by the expression that contains it.
|
|
3
|
+
*
|
|
4
|
+
* Every substitution the compiler performs over a parsed expression (a
|
|
5
|
+
* destructured prop's live read `_p.x ?? d`, a constant's inlined value, a
|
|
6
|
+
* signal's initial value in the client template) replaces a READ of a
|
|
7
|
+
* binding with an expression that produces its value. A write position
|
|
8
|
+
* cannot take that replacement: `++nextId` becomes `++(0)` and `start += 1`
|
|
9
|
+
* becomes `(_p.start ?? 0) += 1`, both a SyntaxError that breaks the whole
|
|
10
|
+
* client module. The substitution walks ask this predicate first and leave
|
|
11
|
+
* a written identifier alone; the caller then decides what a write to the
|
|
12
|
+
* binding means in its scope (a local in the init body, a template slot
|
|
13
|
+
* left to init).
|
|
14
|
+
*
|
|
15
|
+
* Needs a tree built with parent pointers (`setParentNodes`).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import ts from 'typescript'
|
|
19
|
+
|
|
20
|
+
/** `=`, and every compound assignment (`+=`, `??=`, `<<=`, …). */
|
|
21
|
+
function isAssignmentOperator(kind: ts.SyntaxKind): boolean {
|
|
22
|
+
return kind >= ts.SyntaxKind.FirstAssignment && kind <= ts.SyntaxKind.LastAssignment
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Wrappers that keep their operand an assignment target: `(x) = 1`, `x! = 1`, `(x as T) = 1`. */
|
|
26
|
+
function isTransparentWrapper(n: ts.Node): boolean {
|
|
27
|
+
return (
|
|
28
|
+
ts.isParenthesizedExpression(n) ||
|
|
29
|
+
ts.isNonNullExpression(n) ||
|
|
30
|
+
ts.isAsExpression(n) ||
|
|
31
|
+
ts.isTypeAssertionExpression(n) ||
|
|
32
|
+
ts.isSatisfiesExpression(n)
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The node one level up a destructuring-assignment pattern from `node`, or
|
|
38
|
+
* null when `parent` is not a pattern piece that keeps `node` a target: an
|
|
39
|
+
* array element or spread (`[x, ...rest] = …`), an object shorthand or
|
|
40
|
+
* property value (`({ x, k: y } = …)`), or an object spread.
|
|
41
|
+
*/
|
|
42
|
+
function patternContainer(node: ts.Node, parent: ts.Node): ts.Node | null {
|
|
43
|
+
if (ts.isArrayLiteralExpression(parent) || ts.isObjectLiteralExpression(parent)) return parent
|
|
44
|
+
if (ts.isSpreadElement(parent) || ts.isSpreadAssignment(parent)) return parent
|
|
45
|
+
if (ts.isShorthandPropertyAssignment(parent) && parent.name === node) return parent
|
|
46
|
+
if (ts.isPropertyAssignment(parent) && parent.initializer === node) return parent
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* True when `id` is the target of an assignment (`x = …`, `x += …`), an
|
|
52
|
+
* update (`++x`, `x--`), a destructuring assignment (`[x, y] = …`,
|
|
53
|
+
* `({ x } = …)`, `[x = 1] = …`) or a `for (x of …)` / `for (x in …)` head.
|
|
54
|
+
* A member write (`x.a = 1`, `x[i]++`) writes the object, not the binding,
|
|
55
|
+
* so `x` there is a read.
|
|
56
|
+
*/
|
|
57
|
+
export function isAssignmentTargetIdentifier(id: ts.Identifier): boolean {
|
|
58
|
+
let node: ts.Node = id
|
|
59
|
+
let parent: ts.Node | undefined = id.parent
|
|
60
|
+
while (parent) {
|
|
61
|
+
if (isTransparentWrapper(parent)) {
|
|
62
|
+
node = parent
|
|
63
|
+
parent = parent.parent
|
|
64
|
+
continue
|
|
65
|
+
}
|
|
66
|
+
if (ts.isPrefixUnaryExpression(parent) || ts.isPostfixUnaryExpression(parent)) {
|
|
67
|
+
return parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken
|
|
68
|
+
}
|
|
69
|
+
if (ts.isBinaryExpression(parent)) {
|
|
70
|
+
return parent.left === node && isAssignmentOperator(parent.operatorToken.kind)
|
|
71
|
+
}
|
|
72
|
+
if ((ts.isForOfStatement(parent) || ts.isForInStatement(parent)) && parent.initializer === node) return true
|
|
73
|
+
const container = patternContainer(node, parent)
|
|
74
|
+
if (!container) return false
|
|
75
|
+
node = container
|
|
76
|
+
parent = container.parent
|
|
77
|
+
}
|
|
78
|
+
return false
|
|
79
|
+
}
|
package/src/errors.ts
CHANGED
|
@@ -181,6 +181,15 @@ export const ErrorCodes = {
|
|
|
181
181
|
// back to its row, so its delegated event handlers would stop running
|
|
182
182
|
// after hydration (#3318). A keyed top-level row is supported.
|
|
183
183
|
ROW_PORTAL_UNPAIRABLE: 'BF064',
|
|
184
|
+
// A `'use client'` component's markup writes a component binding while it
|
|
185
|
+
// renders (`{++nextId}`, a `.map()` row incrementing a counter, a
|
|
186
|
+
// callback any call in the markup may run in place), outside a function
|
|
187
|
+
// the markup hands on (an attribute / prop value, or a wrapped event
|
|
188
|
+
// handler; `markupTiming`). The client template runs at module scope
|
|
189
|
+
// and cannot write the binding, and init re-evaluates only reactive
|
|
190
|
+
// positions, so a client-side mount would silently lose the written
|
|
191
|
+
// value. Refused instead (`markWrittenBindings`, analyzer.ts).
|
|
192
|
+
STAGE_WRITE_IN_MARKUP: 'BF065',
|
|
184
193
|
|
|
185
194
|
// Inline JSX-callback synthesis errors (BF080-BF089) — raised by the
|
|
186
195
|
// preprocess-inline-jsx-callbacks pass (#1211) when an inline JSX-
|
|
@@ -320,6 +329,8 @@ const errorMessages: Record<ErrorCode, string> = {
|
|
|
320
329
|
|
|
321
330
|
[ErrorCodes.ROW_PORTAL_UNPAIRABLE]:
|
|
322
331
|
'A ref callback portals an element out of a .map() row that hydration cannot pair with the element (the row root itself, a nested or unkeyed loop, an element inside a reactive conditional in the row, or an element inside a child component\'s children), so its event handlers would stop running after hydration.',
|
|
332
|
+
[ErrorCodes.STAGE_WRITE_IN_MARKUP]:
|
|
333
|
+
"A client component's markup writes a component binding while it renders (an assignment or ++/-- outside an event handler), which the client template cannot reproduce.",
|
|
323
334
|
|
|
324
335
|
[ErrorCodes.INLINE_JSX_CALLBACK_CAPTURE]:
|
|
325
336
|
"Inline JSX-returning arrow function captures a non-module identifier. Extract the callback into a top-level 'use client' component (e.g. `function MyNode(n) { return <div/> }` then `renderNode={MyNode}`) or pass captured values via component props.",
|
package/src/index.ts
CHANGED
|
@@ -152,6 +152,7 @@ export {
|
|
|
152
152
|
emitCallbackEval,
|
|
153
153
|
isPredicateMethod,
|
|
154
154
|
lowerCallbackMethod,
|
|
155
|
+
lowerSortComparator,
|
|
155
156
|
nestedCallbackRefusal,
|
|
156
157
|
filterPredicateShapeRefusal,
|
|
157
158
|
missingFilterPredicateRefusal,
|
|
@@ -168,6 +169,7 @@ export type {
|
|
|
168
169
|
CallbackLoweringOptions,
|
|
169
170
|
CallbackPlan,
|
|
170
171
|
PredicateMethod,
|
|
172
|
+
SortPlan,
|
|
171
173
|
} from './adapters/callback-method.ts'
|
|
172
174
|
export type {
|
|
173
175
|
ArrayMethodArg,
|
|
@@ -183,10 +185,19 @@ export { childTemplateName, componentPropKey, isEmptyComponentProps, planCompone
|
|
|
183
185
|
export type { ComponentPropEntry, ComponentPropSegment, ComponentPropSpelling, ComponentPropsOptions, ComponentPropsParam, EarlierComponentProps, ResolvedComponentProp, SpelledComponentPropSegment } from './adapters/component-props.ts'
|
|
184
186
|
export { parseUndefinedAlternateTernary, planAttrExpression, planSpreadAttr, unsupportedAttrExpression, unsupportedAttrExpressionError } from './adapters/attr-plan.ts'
|
|
185
187
|
export type { AttrExpressionPlan, AttrPlanContext, SpreadAttrPlan, SpreadPlanContext, UndefinedAlternateTernary } from './adapters/attr-plan.ts'
|
|
186
|
-
export { planLoop } from './adapters/loop-plan.ts'
|
|
188
|
+
export { planLoop, spellDestructureLocals, spellFilteredRow, spellSortedSource } from './adapters/loop-plan.ts'
|
|
187
189
|
export { computedConstContext, inlineComputedConstAttr, inlineComputedConsts } from './adapters/computed-const.ts'
|
|
188
190
|
export type { ComputedConstContext } from './adapters/computed-const.ts'
|
|
189
|
-
export type {
|
|
191
|
+
export type {
|
|
192
|
+
DestructureSpelling,
|
|
193
|
+
DestructureValue,
|
|
194
|
+
LoopFilterPlan,
|
|
195
|
+
LoopFilterPredicate,
|
|
196
|
+
LoopFilterSpelling,
|
|
197
|
+
LoopPlan,
|
|
198
|
+
LoopPlanContext,
|
|
199
|
+
LoopSortSpelling,
|
|
200
|
+
} from './adapters/loop-plan.ts'
|
|
190
201
|
export { evaluateStaticLiteral, isFullyStaticLiteral, resolveStaticLoopSource } from './static-literal.ts'
|
|
191
202
|
export {
|
|
192
203
|
arithmeticOperandIsNull,
|
|
@@ -480,7 +480,7 @@ function populateCsrInlinable(
|
|
|
480
480
|
// sees `props.X` and can detect bridged-arg calls. The final
|
|
481
481
|
// emit-time substitution applies the bare-prop rewrite.
|
|
482
482
|
const source = c.value!.trim()
|
|
483
|
-
const { rewritten, freeIdentifiers } = csrSubstitute(source, env)
|
|
483
|
+
const { rewritten, freeIdentifiers, writes } = csrSubstitute(source, env)
|
|
484
484
|
|
|
485
485
|
// If the rewrite still references any unresolved local constant
|
|
486
486
|
// by name, defer to a later iteration — its substitution may
|
|
@@ -505,7 +505,7 @@ function populateCsrInlinable(
|
|
|
505
505
|
// `rewritePropsObjectRef` doesn't need to redo the AST work. The
|
|
506
506
|
// free identifiers are re-extracted from the bridged form so
|
|
507
507
|
// the post-substitution unsafe-name check stays exact.
|
|
508
|
-
const bridgedRewritten = bridgedCsrForm(rewritten, source, env, relocateEnv, receivers)
|
|
508
|
+
const bridgedRewritten = bridgedCsrForm(rewritten, writes, source, env, relocateEnv, receivers)
|
|
509
509
|
if (bridgedRewritten === null) {
|
|
510
510
|
ctx.csrInlinable.set(c.name, null)
|
|
511
511
|
} else {
|
|
@@ -552,15 +552,18 @@ function hasNoCsrSubstitute(c: ConstantInfo): boolean {
|
|
|
552
552
|
|
|
553
553
|
/**
|
|
554
554
|
* The bridged CSR form of a const whose substituted text is `rewritten`, or
|
|
555
|
-
* null when it isn't safe in template scope.
|
|
555
|
+
* null when it isn't safe in template scope. A value that writes a binding
|
|
556
|
+
* (`writes`, see `csrSubstitute`) runs only where it is declared.
|
|
556
557
|
*/
|
|
557
558
|
function bridgedCsrForm(
|
|
558
559
|
rewritten: string,
|
|
560
|
+
writes: ReadonlySet<string>,
|
|
559
561
|
source: string,
|
|
560
562
|
env: CsrEnv,
|
|
561
563
|
relocateEnv: RelocateEnv,
|
|
562
564
|
receivers: ReturnType<typeof inlinedReceiverCheck>,
|
|
563
565
|
): string | null {
|
|
566
|
+
if (writes.size > 0) return null
|
|
564
567
|
const inlineResult = isInlinableInTemplate(rewritten, relocateEnv)
|
|
565
568
|
return inlineResult.ok ? inlineResult.rewrittenValue : receivers.check(source, env)
|
|
566
569
|
}
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
buildChildRefBindings,
|
|
29
29
|
hasReactiveLoopBindings,
|
|
30
30
|
buildChildrenTextEffect,
|
|
31
|
+
buildRowEventBinding,
|
|
31
32
|
} from '../shared.ts'
|
|
32
33
|
import { irChildrenToJsExpr, renderPreamble } from '../../html-template.ts'
|
|
33
34
|
import { buildReactiveEffectsPlan } from './build-reactive-effects.ts'
|
|
@@ -138,6 +139,18 @@ export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?
|
|
|
138
139
|
: elem.bindings.reactiveTexts
|
|
139
140
|
const hasReactiveEffects = hasReactiveLoopBindings({ ...elem.bindings, reactiveTexts: rowReactiveTexts })
|
|
140
141
|
|
|
142
|
+
// #3607: an event on an element forwarded as the root component's own
|
|
143
|
+
// `children` is collected into `elem.bindings.events` by the same
|
|
144
|
+
// `collectLoopChildBindings` walk as the reactive attrs/texts above, and
|
|
145
|
+
// was dropped here the same way they were before #3143. A component-root
|
|
146
|
+
// loop has no delegation pass (`loopEventDelegationVariant` returns null
|
|
147
|
+
// for it), so each row attaches its handlers directly, exactly like the
|
|
148
|
+
// composite row's `outerEvents`. Events inside an inner loop of the
|
|
149
|
+
// forwarded children (`nestedLoops` non-empty) are not reached here.
|
|
150
|
+
const rowEvents = elem.bindings.events
|
|
151
|
+
.filter(ev => ev.nestedLoops.length === 0)
|
|
152
|
+
.map(ev => buildRowEventBinding(ev, elem.param, elem.paramBindings, elem.index))
|
|
153
|
+
|
|
141
154
|
return {
|
|
142
155
|
kind: 'component',
|
|
143
156
|
// Rows are createComponent-driven: a lowered HTML-string leaf passed as a
|
|
@@ -156,11 +169,14 @@ export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?
|
|
|
156
169
|
componentPropsExpr: propsExpr,
|
|
157
170
|
keyExpr,
|
|
158
171
|
nestedComps,
|
|
159
|
-
|
|
160
|
-
//
|
|
161
|
-
//
|
|
162
|
-
//
|
|
163
|
-
//
|
|
172
|
+
rowEvents,
|
|
173
|
+
// #3612: refs on elements forwarded as the root component's own
|
|
174
|
+
// `children` (`<Chip><input ref={el => …} /></Chip>`), collected by the
|
|
175
|
+
// same `collectLoopChildBindings` walk as `rowEvents` above and resolved
|
|
176
|
+
// with the same loop-param accessor rewrite. Each row (hydrated and
|
|
177
|
+
// client-built) invokes them against its own element. A `ref` on the
|
|
178
|
+
// root component element itself (`<Chip ref={fn} />`) is a prop, not a
|
|
179
|
+
// binding here: it goes to the component through `componentPropsExpr`.
|
|
164
180
|
childRefs: buildChildRefBindings(elem.bindings.refs, elem.param, elem.paramBindings, elem.index),
|
|
165
181
|
profileLoopId: profileComponentName ? `${profileComponentName}#binding:${elem.slotId}` : undefined,
|
|
166
182
|
reactiveEffects: hasReactiveEffects
|
|
@@ -22,7 +22,7 @@ import type {
|
|
|
22
22
|
LoopChildReactiveText,
|
|
23
23
|
TopLevelLoop,
|
|
24
24
|
} from '../../types.ts'
|
|
25
|
-
import type { IRLoopChildComponent } from '../../../types.ts'
|
|
25
|
+
import type { IRLoopChildComponent, JsSourceText } from '../../../types.ts'
|
|
26
26
|
import type { SafeHtml } from '../../safe-html.ts'
|
|
27
27
|
import type { SkeletonSlotPaths } from '../../html-template.ts'
|
|
28
28
|
import type { ReactiveEffectsPlan } from './reactive-effects.ts'
|
|
@@ -116,6 +116,22 @@ export interface LoopChildRefBinding {
|
|
|
116
116
|
ssrPortalOwner?: boolean
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* A loop-row child event resolved for a direct per-row listener (#3607):
|
|
121
|
+
* `handler` is already in the form the row binds its item in (wrapped with
|
|
122
|
+
* the loop-param accessor for a `mapArray` row, plain for a static
|
|
123
|
+
* `forEach` row), so the stringifier only spells the `qsa` lookup +
|
|
124
|
+
* `addEventListener` line.
|
|
125
|
+
*/
|
|
126
|
+
export interface LoopRowEventBinding {
|
|
127
|
+
/** bf slot ID of the element bearing the handler. */
|
|
128
|
+
childSlotId: string
|
|
129
|
+
/** JSX event name (`click`, `input`, …); normalised to the DOM name at emit. */
|
|
130
|
+
eventName: string
|
|
131
|
+
/** Handler expression, as the row's binding of the item reads it. */
|
|
132
|
+
handler: JsSourceText
|
|
133
|
+
}
|
|
134
|
+
|
|
119
135
|
/**
|
|
120
136
|
* Plain element body, no child components, no inner loops. Covers the
|
|
121
137
|
* single-line and multi-line renderItem shapes — the stringifier picks
|
|
@@ -216,6 +232,14 @@ interface ComponentLoopVariant extends DynamicLoopCommon {
|
|
|
216
232
|
keyExpr: string
|
|
217
233
|
/** Nested child component initialisers; empty for the simple case. */
|
|
218
234
|
nestedComps: NestedComponentInit[]
|
|
235
|
+
/**
|
|
236
|
+
* Event handlers on elements forwarded as the ROOT component's own
|
|
237
|
+
* `children` (`<Chip><button onClick={...}/></Chip>`, #3607), outside any
|
|
238
|
+
* inner loop. Attached directly to each row (hydrated and client-built)
|
|
239
|
+
* the same way the composite row attaches `outerEvents`. Non-empty forces
|
|
240
|
+
* the SSR/CSR split shape (the simple shape has no row handle).
|
|
241
|
+
*/
|
|
242
|
+
rowEvents: readonly LoopRowEventBinding[]
|
|
219
243
|
/**
|
|
220
244
|
* Reactive-effects plan for the loop ROOT component's own reactive attrs /
|
|
221
245
|
* texts / conditionals — i.e. bindings on elements forwarded as the root
|
|
@@ -21,7 +21,7 @@ import { spliceChildValue } from '../safe-html.ts'
|
|
|
21
21
|
import { emitListenerBlock } from './stringify/event-listener.ts'
|
|
22
22
|
import { nameForRegistryRef } from '../component-scope.ts'
|
|
23
23
|
import { BF_SCOPE, BF_HOST, BF_AT } from '@barefootjs/shared'
|
|
24
|
-
import type { LoopChildRefBinding, PreambleRegionPlan, NestedChildrenTextEffect } from './plan/loop.ts'
|
|
24
|
+
import type { LoopChildRefBinding, LoopRowEventBinding, PreambleRegionPlan, NestedChildrenTextEffect } from './plan/loop.ts'
|
|
25
25
|
import type { PreambleRegionSource } from '../../types.ts'
|
|
26
26
|
import {
|
|
27
27
|
extractFreeIdentifiersFromText,
|
|
@@ -383,8 +383,46 @@ function emitEventSetup(
|
|
|
383
383
|
bodyIsMultiRoot: boolean = false,
|
|
384
384
|
loopIndex?: string | null,
|
|
385
385
|
): void {
|
|
386
|
-
const
|
|
387
|
-
|
|
386
|
+
const binding = loopParam
|
|
387
|
+
? buildRowEventBinding(ev, loopParam, loopParamBindings, loopIndex)
|
|
388
|
+
: { childSlotId: ev.childSlotId, eventName: ev.eventName, handler: ev.handler }
|
|
389
|
+
emitRowEventListener(ls, indent, elVar, binding, bodyIsMultiRoot)
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Resolve a loop-row child event into the binding a renderItem body attaches
|
|
394
|
+
* directly to the row's element (`emitRowEventListener`): the handler gets
|
|
395
|
+
* the same loop-param accessor rewrite as every other per-row read (#2859),
|
|
396
|
+
* so a row that survives a same-key reorder reads its current item / index.
|
|
397
|
+
*/
|
|
398
|
+
export function buildRowEventBinding(
|
|
399
|
+
ev: LoopChildEvent,
|
|
400
|
+
loopParam: string,
|
|
401
|
+
loopParamBindings: readonly LoopParamBinding[] | undefined,
|
|
402
|
+
loopIndex?: string | null,
|
|
403
|
+
): LoopRowEventBinding {
|
|
404
|
+
return {
|
|
405
|
+
childSlotId: ev.childSlotId,
|
|
406
|
+
eventName: ev.eventName,
|
|
407
|
+
handler: wrapLoopParamAsAccessor(ev.handler, loopParam, loopParamBindings, loopIndex),
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Emit the per-row `{ const __e = qsa(<elVar>, '[bf="<slot>"]'); if (__e)
|
|
413
|
+
* __e.addEventListener(...) }` block for one resolved row event binding.
|
|
414
|
+
* Shared by the composite row (`emitComponentAndEventSetup`) and the
|
|
415
|
+
* component-root row (`stringifyComponentLoop`, #3607), so both spell the
|
|
416
|
+
* direct per-row listener the same way.
|
|
417
|
+
*/
|
|
418
|
+
export function emitRowEventListener(
|
|
419
|
+
ls: string[],
|
|
420
|
+
indent: string,
|
|
421
|
+
elVar: string,
|
|
422
|
+
binding: LoopRowEventBinding,
|
|
423
|
+
bodyIsMultiRoot: boolean = false,
|
|
424
|
+
): void {
|
|
425
|
+
emitListenerBlock(ls, indent, elVar, binding.childSlotId, '__e', binding.eventName, binding.handler, 'dom', bodyIsMultiRoot)
|
|
388
426
|
}
|
|
389
427
|
|
|
390
428
|
/**
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* Two output shapes (preserved byte-identical from the legacy
|
|
5
5
|
* `emitComponentLoopReconciliation` for the case it covered):
|
|
6
6
|
*
|
|
7
|
-
* nestedComps
|
|
7
|
+
* nestedComps, rowEvents, childRefs empty AND reactiveEffects === null
|
|
8
|
+
* (simple) —
|
|
8
9
|
* two-line renderItem body:
|
|
9
10
|
* <i>mapArray(() => <arr>, <container>, <keyFn>, (<head>, <idx>, __existing) => {
|
|
10
11
|
* <i> <unwrap?>
|
|
@@ -19,12 +20,16 @@
|
|
|
19
20
|
* <i> if (__existing) {
|
|
20
21
|
* <i> initChild('<C>', __existing, <props>)
|
|
21
22
|
* <i> {<each nested initChild + optional createEffect>}
|
|
23
|
+
* <i> {<each row event: qsa + addEventListener>}
|
|
22
24
|
* <i> <stringifyReactiveEffects on __existing if reactiveEffects>
|
|
25
|
+
* <i> {<each row ref: qsa + callback invocation>}
|
|
23
26
|
* <i> return __existing
|
|
24
27
|
* <i> }
|
|
25
28
|
* <i> const __csrEl = createComponent('<C>', <props>, <key>)
|
|
26
29
|
* <i> {<each nested initChild + optional createEffect>}
|
|
30
|
+
* <i> {<each row event: qsa + addEventListener>}
|
|
27
31
|
* <i> <stringifyReactiveEffects on __csrEl if reactiveEffects>
|
|
32
|
+
* <i> {<each row ref: qsa + callback invocation>}
|
|
28
33
|
* <i> return __csrEl
|
|
29
34
|
* <i>})
|
|
30
35
|
*
|
|
@@ -35,7 +40,8 @@
|
|
|
35
40
|
import { stringifyReactiveEffects } from './reactive-effects.ts'
|
|
36
41
|
import type { ComponentLoopPlan, NestedComponentInit } from '../plan/types.ts'
|
|
37
42
|
import { nameForRegistryRef } from '../../component-scope.ts'
|
|
38
|
-
import { stringifyChildrenTextEffect } from '../shared.ts'
|
|
43
|
+
import { stringifyChildrenTextEffect, emitRowEventListener } from '../shared.ts'
|
|
44
|
+
import { emitLoopChildRefs } from './loop.ts'
|
|
39
45
|
|
|
40
46
|
export function stringifyComponentLoop(lines: string[], plan: ComponentLoopPlan): void {
|
|
41
47
|
const {
|
|
@@ -50,6 +56,8 @@ export function stringifyComponentLoop(lines: string[], plan: ComponentLoopPlan)
|
|
|
50
56
|
componentPropsExpr,
|
|
51
57
|
keyExpr,
|
|
52
58
|
nestedComps,
|
|
59
|
+
rowEvents,
|
|
60
|
+
childRefs,
|
|
53
61
|
reactiveEffects,
|
|
54
62
|
profileLoopId,
|
|
55
63
|
mapPreambleWrapped,
|
|
@@ -77,7 +85,11 @@ export function stringifyComponentLoop(lines: string[], plan: ComponentLoopPlan)
|
|
|
77
85
|
// exactly the `<Chip><a href={...}>...</a></Chip>` shape: `<a>` isn't a
|
|
78
86
|
// component, so `nestedComps` was always empty, and the "simple" path
|
|
79
87
|
// never even looked at `reactiveEffects`.
|
|
80
|
-
|
|
88
|
+
//
|
|
89
|
+
// #3607: the same holds for a handler on a forwarded element — it needs
|
|
90
|
+
// the row element to attach to, and (#3612) for a `ref` callback on one —
|
|
91
|
+
// it needs the row element to look the target up in.
|
|
92
|
+
if (nestedComps.length === 0 && !reactiveEffects && rowEvents.length === 0 && childRefs.length === 0) {
|
|
81
93
|
lines.push(` if (__existing) { initChild('${scopedComp}', __existing, ${componentPropsExpr}); return __existing }`)
|
|
82
94
|
lines.push(` return createComponent('${scopedComp}', ${componentPropsExpr}, ${keyExpr})`)
|
|
83
95
|
lines.push(` }, '${markerId}'${loopBfId})`)
|
|
@@ -88,18 +100,26 @@ export function stringifyComponentLoop(lines: string[], plan: ComponentLoopPlan)
|
|
|
88
100
|
lines.push(` if (__existing) {`)
|
|
89
101
|
lines.push(` initChild('${scopedComp}', __existing, ${componentPropsExpr})`)
|
|
90
102
|
for (const nc of nestedComps) emitNestedInit(lines, ' ', '__existing', nc)
|
|
103
|
+
for (const ev of rowEvents) emitRowEventListener(lines, ' ', '__existing', ev)
|
|
91
104
|
if (reactiveEffects) {
|
|
92
105
|
stringifyReactiveEffects(lines, reactiveEffects, { indent: ' ', elVar: '__existing' })
|
|
93
106
|
}
|
|
107
|
+
// #3612: refs run last, as on the composite row (`stringifyCompositeLoop`),
|
|
108
|
+
// so the callback sees the row with its handlers and effects in place.
|
|
109
|
+
// A ref that portals its element is refused (BF064) inside a child
|
|
110
|
+
// component's forwarded children, so no row portal claim is needed here.
|
|
111
|
+
emitLoopChildRefs(lines, childRefs, { indent: ' ', elVar: '__existing', bodyIsMultiRoot: false, containerVar })
|
|
94
112
|
lines.push(` return __existing`)
|
|
95
113
|
lines.push(` }`)
|
|
96
114
|
|
|
97
115
|
// CSR side
|
|
98
116
|
lines.push(` const __csrEl = createComponent('${scopedComp}', ${componentPropsExpr}, ${keyExpr})`)
|
|
99
117
|
for (const nc of nestedComps) emitNestedInit(lines, ' ', '__csrEl', nc)
|
|
118
|
+
for (const ev of rowEvents) emitRowEventListener(lines, ' ', '__csrEl', ev)
|
|
100
119
|
if (reactiveEffects) {
|
|
101
120
|
stringifyReactiveEffects(lines, reactiveEffects, { indent: ' ', elVar: '__csrEl' })
|
|
102
121
|
}
|
|
122
|
+
emitLoopChildRefs(lines, childRefs, { indent: ' ', elVar: '__csrEl', bodyIsMultiRoot: false, containerVar })
|
|
103
123
|
lines.push(` return __csrEl`)
|
|
104
124
|
lines.push(` }, '${markerId}'${loopBfId})`)
|
|
105
125
|
}
|
|
@@ -32,6 +32,7 @@ import type { ConstantInfo, MemoInfo, SignalInfo } from '../types.ts'
|
|
|
32
32
|
import type { BindingScope } from '../scope/binding-scope.ts'
|
|
33
33
|
import { resolveAliasOrigin } from '../props-binding.ts'
|
|
34
34
|
import { signalSecondBinding } from '../signal-initializer.ts'
|
|
35
|
+
import { isAssignmentTargetIdentifier } from '../assignment-target.ts'
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* CSR-substituted const value: the const's initializer with every
|
|
@@ -141,9 +142,9 @@ export function csrSubstitute(
|
|
|
141
142
|
value: string,
|
|
142
143
|
env: CsrEnv,
|
|
143
144
|
enclosingScope?: BindingScope,
|
|
144
|
-
):
|
|
145
|
+
): CsrSubstituteResult {
|
|
145
146
|
if (!value || value.trim().length === 0) {
|
|
146
|
-
return { rewritten: value, freeIdentifiers: new Set() }
|
|
147
|
+
return { rewritten: value, freeIdentifiers: new Set(), writes: new Set() }
|
|
147
148
|
}
|
|
148
149
|
|
|
149
150
|
// Fixed-point iteration handles substitutions whose replacements
|
|
@@ -153,22 +154,39 @@ export function csrSubstitute(
|
|
|
153
154
|
const maxIter = env.substitutions.size + 1
|
|
154
155
|
let current = value
|
|
155
156
|
let lastFreeIdentifiers: ReadonlySet<string> = new Set()
|
|
157
|
+
const writes = new Set<string>()
|
|
156
158
|
for (let i = 0; i < maxIter; i++) {
|
|
157
159
|
const step = csrSubstituteOnce(current, env, enclosingScope)
|
|
158
160
|
lastFreeIdentifiers = step.freeIdentifiers
|
|
161
|
+
for (const name of step.writes) writes.add(name)
|
|
159
162
|
if (step.rewritten === current) break
|
|
160
163
|
current = step.rewritten
|
|
161
164
|
}
|
|
162
|
-
return { rewritten: current, freeIdentifiers: lastFreeIdentifiers }
|
|
165
|
+
return { rewritten: current, freeIdentifiers: lastFreeIdentifiers, writes }
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* `csrSubstitute`'s result. `writes` names the free identifiers the
|
|
170
|
+
* expression assigns or updates (`++nextId`, `start += 1`, `[a, b] = …`),
|
|
171
|
+
* including those inside a spliced memo body or a nested arrow. Such a name
|
|
172
|
+
* is never substituted (`++(0)` is a SyntaxError) and the template lambda,
|
|
173
|
+
* which runs at module scope, has no binding to write, so a caller treats a
|
|
174
|
+
* non-empty set like an unsafe local: the template leaves the position to
|
|
175
|
+
* init.
|
|
176
|
+
*/
|
|
177
|
+
export interface CsrSubstituteResult {
|
|
178
|
+
rewritten: string
|
|
179
|
+
freeIdentifiers: ReadonlySet<string>
|
|
180
|
+
writes: ReadonlySet<string>
|
|
163
181
|
}
|
|
164
182
|
|
|
165
183
|
function csrSubstituteOnce(
|
|
166
184
|
value: string,
|
|
167
185
|
env: CsrEnv,
|
|
168
186
|
enclosingScope?: BindingScope,
|
|
169
|
-
):
|
|
187
|
+
): CsrSubstituteResult {
|
|
170
188
|
if (!value || value.trim().length === 0) {
|
|
171
|
-
return { rewritten: value, freeIdentifiers: new Set() }
|
|
189
|
+
return { rewritten: value, freeIdentifiers: new Set(), writes: new Set() }
|
|
172
190
|
}
|
|
173
191
|
const sourceFile = ts.createSourceFile(
|
|
174
192
|
'__csr_substitute__.ts',
|
|
@@ -179,7 +197,7 @@ function csrSubstituteOnce(
|
|
|
179
197
|
)
|
|
180
198
|
const stmt = sourceFile.statements[0]
|
|
181
199
|
if (!stmt || !ts.isExpressionStatement(stmt)) {
|
|
182
|
-
return { rewritten: value, freeIdentifiers: extractFreeIdentifiersFromText(value) }
|
|
200
|
+
return { rewritten: value, freeIdentifiers: extractFreeIdentifiersFromText(value), writes: new Set() }
|
|
183
201
|
}
|
|
184
202
|
const exprNode = ts.isParenthesizedExpression(stmt.expression)
|
|
185
203
|
? stmt.expression.expression
|
|
@@ -192,6 +210,7 @@ function csrSubstituteOnce(
|
|
|
192
210
|
|
|
193
211
|
type Splice = { start: number; end: number; text: string }
|
|
194
212
|
const splices: Splice[] = []
|
|
213
|
+
const writes = new Set<string>()
|
|
195
214
|
|
|
196
215
|
// Track the bound names in nested arrow/function scopes so we don't
|
|
197
216
|
// substitute identifiers shadowed by a parameter or local binding.
|
|
@@ -218,6 +237,34 @@ function csrSubstituteOnce(
|
|
|
218
237
|
const bareReplacementText = (sub: CsrSubstitution): string =>
|
|
219
238
|
sub.kind === 'call' ? `(() => (${sub.replacement}))` : `(${sub.replacement})`
|
|
220
239
|
|
|
240
|
+
// The substitution for a free reference `id`, or undefined. A written
|
|
241
|
+
// name (`++nextId`, `({ x } = obj)`) is recorded in `writes` and never
|
|
242
|
+
// substituted: a value is not an assignment target (`++(0)` is a
|
|
243
|
+
// SyntaxError).
|
|
244
|
+
const readSubstitution = (id: ts.Identifier): CsrSubstitution | undefined => {
|
|
245
|
+
if (isBound(id.text)) return undefined
|
|
246
|
+
if (isAssignmentTargetIdentifier(id)) {
|
|
247
|
+
if (!isFunctionLocal(id.text)) writes.add(id.text)
|
|
248
|
+
return undefined
|
|
249
|
+
}
|
|
250
|
+
return env.substitutions.get(id.text)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Every name a function inside `value` declares anywhere in its body
|
|
254
|
+
// (`for (let i …)`, a nested block's `let`, a catch variable), innermost
|
|
255
|
+
// last. `boundStack` binds only a body's top-level declarations, which
|
|
256
|
+
// is all substitution needs; a write to one of these is the function's
|
|
257
|
+
// own, never a write to a component binding.
|
|
258
|
+
const functionLocalStack: Array<Set<string>> = []
|
|
259
|
+
const isFunctionLocal = (name: string): boolean => functionLocalStack.some(frame => frame.has(name))
|
|
260
|
+
const collectFunctionLocals = (n: ts.Node, out: Set<string>): void => {
|
|
261
|
+
ts.forEachChild(n, child => {
|
|
262
|
+
if (ts.isVariableDeclaration(child)) collectBindingNames(child.name, out)
|
|
263
|
+
else if (ts.isFunctionDeclaration(child) && child.name) out.add(child.name.text)
|
|
264
|
+
if (!ts.isFunctionLike(child)) collectFunctionLocals(child, out)
|
|
265
|
+
})
|
|
266
|
+
}
|
|
267
|
+
|
|
221
268
|
const collectBindingNames = (name: ts.BindingName, out: Set<string>): void => {
|
|
222
269
|
if (ts.isIdentifier(name)) out.add(name.text)
|
|
223
270
|
else if (ts.isObjectBindingPattern(name)) {
|
|
@@ -286,18 +333,16 @@ function csrSubstituteOnce(
|
|
|
286
333
|
// `call`-kind entry needs the thunk form too (#2924) — same as the
|
|
287
334
|
// bare-identifier branch below.
|
|
288
335
|
if (ts.isShorthandPropertyAssignment(node)) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
})
|
|
300
|
-
}
|
|
336
|
+
const sub = readSubstitution(node.name)
|
|
337
|
+
if (sub) {
|
|
338
|
+
// The shorthand expands to a key-value pair when we substitute,
|
|
339
|
+
// so emit `name: (replacement)` to keep the object literal
|
|
340
|
+
// grammatical. Position spans the whole shorthand.
|
|
341
|
+
splices.push({
|
|
342
|
+
start: node.getStart(sourceFile) - OFFSET,
|
|
343
|
+
end: node.getEnd() - OFFSET,
|
|
344
|
+
text: `${node.name.text}: ${bareReplacementText(sub)}`,
|
|
345
|
+
})
|
|
301
346
|
}
|
|
302
347
|
return
|
|
303
348
|
}
|
|
@@ -321,8 +366,12 @@ function csrSubstituteOnce(
|
|
|
321
366
|
if (node.body && ts.isBlock(node.body)) {
|
|
322
367
|
collectBlockDeclarations(node.body, bound)
|
|
323
368
|
}
|
|
369
|
+
const locals = new Set(bound)
|
|
370
|
+
collectFunctionLocals(node.body, locals)
|
|
324
371
|
boundStack.push(bound)
|
|
325
|
-
|
|
372
|
+
functionLocalStack.push(locals)
|
|
373
|
+
visit(node.body)
|
|
374
|
+
functionLocalStack.pop()
|
|
326
375
|
boundStack.pop()
|
|
327
376
|
return
|
|
328
377
|
}
|
|
@@ -340,8 +389,7 @@ function csrSubstituteOnce(
|
|
|
340
389
|
// getter) substitutes to a thunk over its value here, not the value
|
|
341
390
|
// itself — the bare form is the accessor, not a read of it (#2924).
|
|
342
391
|
if (ts.isIdentifier(node)) {
|
|
343
|
-
|
|
344
|
-
const sub = env.substitutions.get(node.text)
|
|
392
|
+
const sub = readSubstitution(node)
|
|
345
393
|
if (sub) {
|
|
346
394
|
splices.push({
|
|
347
395
|
start: node.getStart(sourceFile) - OFFSET,
|
|
@@ -396,7 +444,7 @@ function csrSubstituteOnce(
|
|
|
396
444
|
if (enclosingScope.isBound(name)) freeIdentifiers.delete(name)
|
|
397
445
|
}
|
|
398
446
|
}
|
|
399
|
-
return { rewritten, freeIdentifiers }
|
|
447
|
+
return { rewritten, freeIdentifiers, writes }
|
|
400
448
|
}
|
|
401
449
|
|
|
402
450
|
export function extractFreeIdentifiersFromText(text: string): Set<string> {
|
|
@@ -17,7 +17,7 @@ import { toLocaleDatePlugin, foldedArgToClientJs } from '../to-locale-date-lower
|
|
|
17
17
|
import { tsNodeToParsedExpr } from '../expression-parser.ts'
|
|
18
18
|
import type { LoweringMatcher } from '../lowering-registry.ts'
|
|
19
19
|
import { rewriteBarePropRefs } from '../prop-rewrite.ts'
|
|
20
|
-
import { livePropReadExpr } from '../props-binding.ts'
|
|
20
|
+
import { livePropReadExpr, keepsDeclaredValue } from '../props-binding.ts'
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Profile mode (#1690, SR3/SR4): the id appended to a DOM-binding effect so the
|
|
@@ -327,7 +327,7 @@ export function rewriteDestructuredPropsInExpr(expr: string, ctx: ClientJsContex
|
|
|
327
327
|
const propAliases = new Map<string, string>()
|
|
328
328
|
const propsByName = new Map<string, ClientJsContext['propsParams'][number]>()
|
|
329
329
|
for (const prop of ctx.propsParams) {
|
|
330
|
-
if (isChildrenPropParam(prop)) continue
|
|
330
|
+
if (isChildrenPropParam(prop) || !keepsDeclaredValue(prop)) continue
|
|
331
331
|
propNames.add(prop.name)
|
|
332
332
|
propsByName.set(prop.name, prop)
|
|
333
333
|
// `_p` is always keyed by the caller-facing name (#2524 CSR half).
|
|
@@ -14,6 +14,7 @@ import { csrSubstitute, type CsrEnv } from './csr-substitute.ts'
|
|
|
14
14
|
import { markupSlotIdsOf } from './markup-slots.ts'
|
|
15
15
|
import { nameForRegistryRef } from './component-scope.ts'
|
|
16
16
|
import { resolveRestSpreadNames } from './prop-handling.ts'
|
|
17
|
+
import { writesAnyBinding } from '../props-binding.ts'
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Resolve chained references within a constants map.
|
|
@@ -191,7 +192,11 @@ export function emitRegistrationAndHydration(
|
|
|
191
192
|
|
|
192
193
|
// Build ComponentDef object for hydrate()
|
|
193
194
|
const defParts: string[] = [`init: ${initFunctionName(name)}`]
|
|
194
|
-
|
|
195
|
+
// A component that writes a binding (`writesAnyBinding`) always takes the
|
|
196
|
+
// CSR template below: only that emitter checks each expression for a
|
|
197
|
+
// write (`csrSubstitute`'s `writes`) and leaves it to init, so no template
|
|
198
|
+
// path can carry `++start` into module scope, where `start` does not exist.
|
|
199
|
+
if (!writesAnyBinding(ctx) && canGenerateStaticTemplate(_ir.root, reactiveGetterNames, inlinableConstants, unsafeLocalNames)) {
|
|
195
200
|
const markupSlotIds = markupSlotIdsOf(ctx)
|
|
196
201
|
const templateHtml = irToComponentTemplate(_ir.root, inlinableConstants, restSpreadNames, ctx.propsObjectName, markupSlotIds, ctx.restPropsName)
|
|
197
202
|
if (templateHtml) {
|