@barefootjs/jsx 0.39.7 → 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 +36 -7
- package/dist/adapters/callback-method.d.ts.map +1 -1
- package/dist/adapters/component-props.d.ts +80 -13
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +153 -0
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -0
- package/dist/adapters/jsx-adapter.d.ts +4 -0
- package/dist/adapters/jsx-adapter.d.ts.map +1 -1
- package/dist/adapters/literal-value.d.ts +2 -2
- package/dist/adapters/literal-value.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 +44 -0
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/style-object.d.ts +33 -0
- package/dist/adapters/style-object.d.ts.map +1 -0
- 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/children-nullish.d.ts +22 -0
- package/dist/children-nullish.d.ts.map +1 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +9 -19
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/free-refs.d.ts +6 -0
- package/dist/free-refs.d.ts.map +1 -1
- package/dist/index.d.ts +17 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15040 -13899
- 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/event-collision.d.ts +2 -1
- package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -2
- package/dist/ir-to-client-js/control-flow/plan/insert.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/control-flow/stringify/event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts +10 -9
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.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-reactive.d.ts +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-registration.d.ts +10 -8
- package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
- package/dist/ir-to-client-js/generate-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts +0 -9
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/identifiers.d.ts +6 -8
- package/dist/ir-to-client-js/identifiers.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +23 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/props-extraction.d.ts +6 -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/prune-unused-prop-extractions.d.ts +1 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/rewrite-destructured-props.d.ts +1 -1
- package/dist/ir-to-client-js/rewrite-destructured-props.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/safe-html.d.ts +20 -2
- package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts +1 -0
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +3 -3
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +2 -11
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +40 -10
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/prop-rewrite.d.ts +35 -8
- package/dist/prop-rewrite.d.ts.map +1 -1
- package/dist/props-binding.d.ts +66 -1
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/scanner/js-scanner.d.ts.map +1 -1
- package/dist/scanner/js-scanner.js +30 -2
- 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/signal-prop-name-collision.d.ts +6 -5
- package/dist/signal-prop-name-collision.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +28 -0
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/ssr-seed-plan.d.ts +39 -14
- package/dist/ssr-seed-plan.d.ts.map +1 -1
- package/dist/types.d.ts +133 -19
- package/dist/types.d.ts.map +1 -1
- package/dist/value-references.d.ts +21 -0
- package/dist/value-references.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +18 -18
- package/src/__tests__/adapter-output.test.ts +5 -3
- package/src/__tests__/analyzer.test.ts +33 -0
- package/src/__tests__/arithmetic-lowering.test.ts +48 -0
- package/src/__tests__/binding-scope.test.ts +29 -0
- package/src/__tests__/children-read.test.ts +226 -0
- package/src/__tests__/client-template-escape-soundness.test.ts +31 -1
- package/src/__tests__/component-props.test.ts +68 -1
- package/src/__tests__/constant-inlining-tree.test.ts +136 -0
- package/src/__tests__/create-query.test.ts +1 -1
- package/src/__tests__/destructure-default-reads-earlier-param.test.ts +138 -0
- package/src/__tests__/dsl-template-adapter.test.ts +173 -0
- package/src/__tests__/emit-to-string-call.test.ts +58 -0
- package/src/__tests__/event-handler-verbatim.test.ts +73 -0
- package/src/__tests__/expression-parser.test.ts +1 -44
- 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__/nullable-signal-attr.test.ts +67 -3
- package/src/__tests__/props-alias-const.test.ts +60 -1
- package/src/__tests__/props-named-callback-param.test.ts +256 -0
- package/src/__tests__/reference-graph-identifiers.test.ts +161 -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__/runtime-import-detection.test.ts +134 -0
- package/src/__tests__/signal-prop-name-collision.test.ts +30 -0
- package/src/__tests__/ssr-defaults.test.ts +19 -1
- package/src/__tests__/ssr-seed-plan.test.ts +119 -0
- package/src/__tests__/style-object-plan.test.ts +54 -0
- package/src/__tests__/written-binding-substitution.test.ts +430 -0
- package/src/__tests__/zero-param-helper-inline.test.ts +57 -0
- package/src/adapters/callback-method.ts +48 -10
- package/src/adapters/component-props.ts +130 -12
- package/src/adapters/dsl-template-adapter.ts +259 -0
- package/src/adapters/jsx-adapter.ts +12 -6
- package/src/adapters/literal-value.ts +2 -2
- package/src/adapters/loop-plan.ts +201 -13
- package/src/adapters/parsed-expr-emitter.ts +67 -0
- package/src/adapters/style-object.ts +61 -0
- package/src/analyzer.ts +396 -16
- package/src/assignment-target.ts +79 -0
- package/src/children-nullish.ts +33 -0
- package/src/debug.ts +2 -2
- package/src/errors.ts +23 -0
- package/src/expression-parser.ts +56 -53
- package/src/free-refs.ts +28 -17
- package/src/index.ts +31 -10
- package/src/ir-to-client-js/compute-inlinability.ts +35 -5
- package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +21 -5
- package/src/ir-to-client-js/control-flow/plan/event-collision.ts +2 -1
- package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -2
- 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/control-flow/stringify/event-delegation.ts +3 -2
- package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +13 -12
- package/src/ir-to-client-js/csr-substitute.ts +82 -24
- package/src/ir-to-client-js/emit-reactive.ts +3 -3
- package/src/ir-to-client-js/emit-registration.ts +34 -58
- package/src/ir-to-client-js/generate-init.ts +17 -1
- package/src/ir-to-client-js/html-template.ts +48 -57
- package/src/ir-to-client-js/identifiers.ts +75 -24
- package/src/ir-to-client-js/imports.ts +56 -19
- package/src/ir-to-client-js/index.ts +2 -1
- package/src/ir-to-client-js/phases/event-handlers.ts +2 -2
- package/src/ir-to-client-js/phases/props-extraction.ts +39 -17
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +2 -2
- 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/prune-unused-prop-extractions.ts +7 -4
- package/src/ir-to-client-js/reactivity.ts +2 -2
- package/src/ir-to-client-js/rewrite-destructured-props.ts +22 -5
- package/src/ir-to-client-js/rewrite-props-object.ts +14 -8
- package/src/ir-to-client-js/safe-html.ts +29 -35
- package/src/ir-to-client-js/stringify/static-array-child-init.ts +4 -1
- package/src/ir-to-client-js/types.ts +3 -2
- package/src/ir-to-client-js/utils.ts +42 -122
- package/src/jsx-to-ir.ts +310 -90
- package/src/nullable-signal-attr.ts +149 -33
- package/src/prop-rewrite.ts +72 -72
- package/src/props-binding.ts +90 -3
- package/src/scanner/__tests__/js-scanner.test.ts +37 -0
- package/src/scanner/js-scanner.ts +64 -4
- package/src/scope/binding-scope.ts +34 -3
- package/src/scope/lexical-scope-walk.ts +167 -0
- package/src/signal-prop-name-collision.ts +50 -24
- package/src/ssr-defaults.ts +47 -20
- package/src/ssr-seed-plan.ts +103 -23
- package/src/types.ts +140 -20
- package/src/value-references.ts +132 -0
|
@@ -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
|
}
|
|
@@ -54,6 +54,7 @@ import type {
|
|
|
54
54
|
StaticIndexItemLookup,
|
|
55
55
|
LoopChildEvent,
|
|
56
56
|
} from '../plan/types.ts'
|
|
57
|
+
import type { JsSourceText } from '../../../types.ts'
|
|
57
58
|
|
|
58
59
|
/**
|
|
59
60
|
* Profile mode (#1690, SR3): bracket a delegated handler call with turn
|
|
@@ -74,7 +75,7 @@ function withTurn(call: string, componentName: string | undefined, childSlotId:
|
|
|
74
75
|
* or the name already equals the in-scope index var (a self-alias). Uses AST
|
|
75
76
|
* free identifiers, not a token match, so `item.id` (property) doesn't count.
|
|
76
77
|
*/
|
|
77
|
-
function indexBindingLine(handler:
|
|
78
|
+
function indexBindingLine(handler: JsSourceText, indexParam: string | null, indexExpr: string): string | null {
|
|
78
79
|
if (!indexParam || indexParam === indexExpr) return null
|
|
79
80
|
if (!extractFreeIdentifiersFromText(handler).has(indexParam)) return null
|
|
80
81
|
return `const ${indexParam} = ${indexExpr}`
|
|
@@ -93,7 +94,7 @@ function indexBindingLine(handler: string, indexParam: string | null, indexExpr:
|
|
|
93
94
|
function preambleLineForHandler(
|
|
94
95
|
mapPreamble: string | null,
|
|
95
96
|
declaredNames: readonly string[],
|
|
96
|
-
handler:
|
|
97
|
+
handler: JsSourceText,
|
|
97
98
|
): string | null {
|
|
98
99
|
if (!mapPreamble || declaredNames.length === 0) return null
|
|
99
100
|
const free = extractFreeIdentifiersFromText(handler)
|
|
@@ -6,36 +6,37 @@
|
|
|
6
6
|
* 2. inline event setup (`emit-control-flow.ts::emitEventSetup`)
|
|
7
7
|
* 3. loop-cond branch bindings (`stringify/loop-child-arm.ts::stringifyBranchEventBindings`)
|
|
8
8
|
*
|
|
9
|
-
* Each repeated
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* Each repeated the DOM-event-name normalisation + `if (elem)
|
|
10
|
+
* elem.addEventListener(...)` line. Centralising the shape here keeps the
|
|
11
|
+
* event-name decision in one place — useful when
|
|
12
12
|
* we eventually drop the legacy "raw event name" mode (currently only used
|
|
13
13
|
* by `@client` conditionals).
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import { toDomEventName,
|
|
16
|
+
import { toDomEventName, wrapHandlerForTurn } from '../../utils.ts'
|
|
17
|
+
import type { JsSourceText } from '../../../types.ts'
|
|
17
18
|
|
|
18
19
|
export type EventNameMode = 'dom' | 'raw'
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Emit `if (<elementVar>) <elementVar>.addEventListener('<eventName>',
|
|
22
|
-
* <
|
|
23
|
-
*
|
|
24
|
-
* `
|
|
25
|
-
*
|
|
23
|
+
* <handler>)` on a single line. The handler is already source-level and
|
|
24
|
+
* an expression (Phase 1 parenthesizes a comma sequence), so it is passed
|
|
25
|
+
* verbatim: `addEventListener` ignores a listener's return value, so an
|
|
26
|
+
* expression-bodied arrow needs no block wrap (#3538).
|
|
26
27
|
*/
|
|
27
28
|
export function emitListenerLine(
|
|
28
29
|
lines: string[],
|
|
29
30
|
indent: string,
|
|
30
31
|
elementVar: string,
|
|
31
32
|
eventName: string,
|
|
32
|
-
handler:
|
|
33
|
+
handler: JsSourceText,
|
|
33
34
|
mode: EventNameMode = 'dom',
|
|
34
35
|
turnId?: string,
|
|
35
36
|
): void {
|
|
36
37
|
// Profile mode (#1690, SR3): when a turn id is supplied the handler is
|
|
37
38
|
// bracketed with beginTurn/endTurn instead of the plain block wrap.
|
|
38
|
-
const wrapped = turnId ? wrapHandlerForTurn(handler, turnId) :
|
|
39
|
+
const wrapped = turnId ? wrapHandlerForTurn(handler, turnId) : handler.trim()
|
|
39
40
|
const name = mode === 'dom' ? toDomEventName(eventName) : eventName
|
|
40
41
|
lines.push(`${indent}if (${elementVar}) ${elementVar}.addEventListener('${name}', ${wrapped})`)
|
|
41
42
|
}
|
|
@@ -57,11 +58,11 @@ export function emitListenerBlock(
|
|
|
57
58
|
slotId: string,
|
|
58
59
|
elementLocal: string,
|
|
59
60
|
eventName: string,
|
|
60
|
-
handler:
|
|
61
|
+
handler: JsSourceText,
|
|
61
62
|
mode: EventNameMode = 'dom',
|
|
62
63
|
bodyIsMultiRoot: boolean = false,
|
|
63
64
|
): void {
|
|
64
|
-
const wrapped =
|
|
65
|
+
const wrapped = handler.trim()
|
|
65
66
|
const name = mode === 'dom' ? toDomEventName(eventName) : eventName
|
|
66
67
|
const lookup = bodyIsMultiRoot ? 'qsaItem' : 'qsa'
|
|
67
68
|
lines.push(`${indent}{ const ${elementLocal} = ${lookup}(${scopeVar}, '[bf="${slotId}"]'); if (${elementLocal}) ${elementLocal}.addEventListener('${name}', ${wrapped}) }`)
|
|
@@ -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
|
|
@@ -102,6 +103,15 @@ export interface CsrEnv {
|
|
|
102
103
|
propsObjectName: string | null
|
|
103
104
|
}
|
|
104
105
|
|
|
106
|
+
/**
|
|
107
|
+
* The value positions of an object-literal `key: value` entry: the value,
|
|
108
|
+
* and a computed key's expression (`{ [size]: value }`, #3535). A plain key
|
|
109
|
+
* is a name, never a reference.
|
|
110
|
+
*/
|
|
111
|
+
function propertyValueExpressions(node: ts.PropertyAssignment): ts.Expression[] {
|
|
112
|
+
return ts.isComputedPropertyName(node.name) ? [node.name.expression, node.initializer] : [node.initializer]
|
|
113
|
+
}
|
|
114
|
+
|
|
105
115
|
/**
|
|
106
116
|
* Substitute an expression for CSR template scope. Returns the rewritten
|
|
107
117
|
* text plus the free identifiers of the rewritten form.
|
|
@@ -132,9 +142,9 @@ export function csrSubstitute(
|
|
|
132
142
|
value: string,
|
|
133
143
|
env: CsrEnv,
|
|
134
144
|
enclosingScope?: BindingScope,
|
|
135
|
-
):
|
|
145
|
+
): CsrSubstituteResult {
|
|
136
146
|
if (!value || value.trim().length === 0) {
|
|
137
|
-
return { rewritten: value, freeIdentifiers: new Set() }
|
|
147
|
+
return { rewritten: value, freeIdentifiers: new Set(), writes: new Set() }
|
|
138
148
|
}
|
|
139
149
|
|
|
140
150
|
// Fixed-point iteration handles substitutions whose replacements
|
|
@@ -144,22 +154,39 @@ export function csrSubstitute(
|
|
|
144
154
|
const maxIter = env.substitutions.size + 1
|
|
145
155
|
let current = value
|
|
146
156
|
let lastFreeIdentifiers: ReadonlySet<string> = new Set()
|
|
157
|
+
const writes = new Set<string>()
|
|
147
158
|
for (let i = 0; i < maxIter; i++) {
|
|
148
159
|
const step = csrSubstituteOnce(current, env, enclosingScope)
|
|
149
160
|
lastFreeIdentifiers = step.freeIdentifiers
|
|
161
|
+
for (const name of step.writes) writes.add(name)
|
|
150
162
|
if (step.rewritten === current) break
|
|
151
163
|
current = step.rewritten
|
|
152
164
|
}
|
|
153
|
-
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>
|
|
154
181
|
}
|
|
155
182
|
|
|
156
183
|
function csrSubstituteOnce(
|
|
157
184
|
value: string,
|
|
158
185
|
env: CsrEnv,
|
|
159
186
|
enclosingScope?: BindingScope,
|
|
160
|
-
):
|
|
187
|
+
): CsrSubstituteResult {
|
|
161
188
|
if (!value || value.trim().length === 0) {
|
|
162
|
-
return { rewritten: value, freeIdentifiers: new Set() }
|
|
189
|
+
return { rewritten: value, freeIdentifiers: new Set(), writes: new Set() }
|
|
163
190
|
}
|
|
164
191
|
const sourceFile = ts.createSourceFile(
|
|
165
192
|
'__csr_substitute__.ts',
|
|
@@ -170,7 +197,7 @@ function csrSubstituteOnce(
|
|
|
170
197
|
)
|
|
171
198
|
const stmt = sourceFile.statements[0]
|
|
172
199
|
if (!stmt || !ts.isExpressionStatement(stmt)) {
|
|
173
|
-
return { rewritten: value, freeIdentifiers: extractFreeIdentifiersFromText(value) }
|
|
200
|
+
return { rewritten: value, freeIdentifiers: extractFreeIdentifiersFromText(value), writes: new Set() }
|
|
174
201
|
}
|
|
175
202
|
const exprNode = ts.isParenthesizedExpression(stmt.expression)
|
|
176
203
|
? stmt.expression.expression
|
|
@@ -183,6 +210,7 @@ function csrSubstituteOnce(
|
|
|
183
210
|
|
|
184
211
|
type Splice = { start: number; end: number; text: string }
|
|
185
212
|
const splices: Splice[] = []
|
|
213
|
+
const writes = new Set<string>()
|
|
186
214
|
|
|
187
215
|
// Track the bound names in nested arrow/function scopes so we don't
|
|
188
216
|
// substitute identifiers shadowed by a parameter or local binding.
|
|
@@ -209,6 +237,34 @@ function csrSubstituteOnce(
|
|
|
209
237
|
const bareReplacementText = (sub: CsrSubstitution): string =>
|
|
210
238
|
sub.kind === 'call' ? `(() => (${sub.replacement}))` : `(${sub.replacement})`
|
|
211
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
|
+
|
|
212
268
|
const collectBindingNames = (name: ts.BindingName, out: Set<string>): void => {
|
|
213
269
|
if (ts.isIdentifier(name)) out.add(name.text)
|
|
214
270
|
else if (ts.isObjectBindingPattern(name)) {
|
|
@@ -264,9 +320,10 @@ function csrSubstituteOnce(
|
|
|
264
320
|
}
|
|
265
321
|
|
|
266
322
|
// Property assignment in object literal: `{ X: value }` — `X` is a
|
|
267
|
-
// key, not a free ref. `value` is
|
|
323
|
+
// key, not a free ref. `value` is, and so is a computed key's
|
|
324
|
+
// expression (`{ [size]: value }`, #3535).
|
|
268
325
|
if (ts.isPropertyAssignment(node)) {
|
|
269
|
-
|
|
326
|
+
propertyValueExpressions(node).forEach(visit)
|
|
270
327
|
return
|
|
271
328
|
}
|
|
272
329
|
|
|
@@ -276,18 +333,16 @@ function csrSubstituteOnce(
|
|
|
276
333
|
// `call`-kind entry needs the thunk form too (#2924) — same as the
|
|
277
334
|
// bare-identifier branch below.
|
|
278
335
|
if (ts.isShorthandPropertyAssignment(node)) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
})
|
|
290
|
-
}
|
|
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
|
+
})
|
|
291
346
|
}
|
|
292
347
|
return
|
|
293
348
|
}
|
|
@@ -311,8 +366,12 @@ function csrSubstituteOnce(
|
|
|
311
366
|
if (node.body && ts.isBlock(node.body)) {
|
|
312
367
|
collectBlockDeclarations(node.body, bound)
|
|
313
368
|
}
|
|
369
|
+
const locals = new Set(bound)
|
|
370
|
+
collectFunctionLocals(node.body, locals)
|
|
314
371
|
boundStack.push(bound)
|
|
315
|
-
|
|
372
|
+
functionLocalStack.push(locals)
|
|
373
|
+
visit(node.body)
|
|
374
|
+
functionLocalStack.pop()
|
|
316
375
|
boundStack.pop()
|
|
317
376
|
return
|
|
318
377
|
}
|
|
@@ -330,8 +389,7 @@ function csrSubstituteOnce(
|
|
|
330
389
|
// getter) substitutes to a thunk over its value here, not the value
|
|
331
390
|
// itself — the bare form is the accessor, not a read of it (#2924).
|
|
332
391
|
if (ts.isIdentifier(node)) {
|
|
333
|
-
|
|
334
|
-
const sub = env.substitutions.get(node.text)
|
|
392
|
+
const sub = readSubstitution(node)
|
|
335
393
|
if (sub) {
|
|
336
394
|
splices.push({
|
|
337
395
|
start: node.getStart(sourceFile) - OFFSET,
|
|
@@ -386,7 +444,7 @@ function csrSubstituteOnce(
|
|
|
386
444
|
if (enclosingScope.isBound(name)) freeIdentifiers.delete(name)
|
|
387
445
|
}
|
|
388
446
|
}
|
|
389
|
-
return { rewritten, freeIdentifiers }
|
|
447
|
+
return { rewritten, freeIdentifiers, writes }
|
|
390
448
|
}
|
|
391
449
|
|
|
392
450
|
export function extractFreeIdentifiersFromText(text: string): Set<string> {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import ts from 'typescript'
|
|
8
|
-
import type
|
|
8
|
+
import { type AttrMeta, type IRMetadata, isChildrenPropParam } from '../types.ts'
|
|
9
9
|
import { isBooleanAttr } from '../html-constants.ts'
|
|
10
10
|
import type { ClientJsContext } from './types.ts'
|
|
11
11
|
import { toHtmlAttrName, varSlotId, PROPS_PARAM } from './utils.ts'
|
|
@@ -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 (prop
|
|
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).
|
|
@@ -9,72 +9,44 @@ import type { ClientJsContext } from './types.ts'
|
|
|
9
9
|
import { PROPS_PARAM, componentDefScopeFlags, initFunctionName } from './utils.ts'
|
|
10
10
|
import { collectReactiveGetterNames } from '../analyzer-context.ts'
|
|
11
11
|
import { computeInlinability, toLegacyInlinability } from './compute-inlinability.ts'
|
|
12
|
-
import { canGenerateStaticTemplate, irToComponentTemplate, generateCsrTemplate
|
|
12
|
+
import { canGenerateStaticTemplate, irToComponentTemplate, generateCsrTemplate } from './html-template.ts'
|
|
13
|
+
import { csrSubstitute, type CsrEnv } from './csr-substitute.ts'
|
|
13
14
|
import { markupSlotIdsOf } from './markup-slots.ts'
|
|
14
15
|
import { nameForRegistryRef } from './component-scope.ts'
|
|
15
16
|
import { resolveRestSpreadNames } from './prop-handling.ts'
|
|
17
|
+
import { writesAnyBinding } from '../props-binding.ts'
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* Resolve chained references within a constants map.
|
|
19
|
-
* If constant A references constant B, replace B's name in A's value with
|
|
20
|
-
*
|
|
21
|
+
* If constant A references constant B, replace B's name in A's value with
|
|
22
|
+
* B's resolved value. The substitution runs on the expression tree
|
|
23
|
+
* (`csrSubstitute`), so a constant's name inside a string or template
|
|
24
|
+
* literal, a member name, or a binding that shadows it is never replaced,
|
|
25
|
+
* and an object-literal shorthand expands to `name: (value)` (#3535).
|
|
21
26
|
*
|
|
22
|
-
* When `freeIdsMap` is supplied, it is updated in place
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* transitively-closed free-id map
|
|
26
|
-
*
|
|
27
|
-
* re-scanning the resolved string.
|
|
27
|
+
* When `freeIdsMap` is supplied, it is updated in place to the free
|
|
28
|
+
* identifiers of each resolved value, so downstream callers
|
|
29
|
+
* (`toLegacyInlinability` unsafe-ref check, #1267) can read a
|
|
30
|
+
* transitively-closed free-id map without re-scanning the resolved string.
|
|
31
|
+
* A constant whose recorded free ids name no other constant is skipped.
|
|
28
32
|
*/
|
|
29
33
|
export function resolveChainedRefs(constants: Map<string, string>, freeIdsMap?: Map<string, Set<string>>): void {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
for (const [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// Protect string literals within compound values (e.g., Record objects
|
|
47
|
-
// containing 'size-4') from regex-based identifier replacement
|
|
48
|
-
const { protect, restore } = createStringProtector()
|
|
49
|
-
let newValue = protect(constValue)
|
|
50
|
-
const freeIds = freeIdsMap?.get(constName)
|
|
51
|
-
for (const [otherName, otherValue] of constants) {
|
|
52
|
-
if (otherName === constName) continue
|
|
53
|
-
// Use freeIdentifiers to skip constants that are definitely not referenced.
|
|
54
|
-
// On subsequent iterations the value may have been expanded beyond what
|
|
55
|
-
// freeIdentifiers tracks, so fall through to regex when freeIds is unavailable
|
|
56
|
-
// or when the iteration is > 1 (values have been mutated).
|
|
57
|
-
if (freeIds && iteration === 1 && !freeIds.has(otherName)) continue
|
|
58
|
-
const replaced = newValue.replace(new RegExp(`(?<![-.])\\b${otherName}\\b`, 'g'), `(${protect(otherValue)})`)
|
|
59
|
-
if (replaced !== newValue) {
|
|
60
|
-
newValue = replaced
|
|
61
|
-
changed = true
|
|
62
|
-
// Maintain a transitively-closed free-id set on the resolving
|
|
63
|
-
// constant: drop the substituted name, union in the substituted
|
|
64
|
-
// constant's own free ids.
|
|
65
|
-
if (freeIds) {
|
|
66
|
-
freeIds.delete(otherName)
|
|
67
|
-
const otherFreeIds = freeIdsMap?.get(otherName)
|
|
68
|
-
if (otherFreeIds) {
|
|
69
|
-
for (const id of otherFreeIds) freeIds.add(id)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
newValue = restore(newValue)
|
|
75
|
-
if (newValue !== constValue) {
|
|
76
|
-
constants.set(constName, newValue)
|
|
77
|
-
}
|
|
34
|
+
for (const [constName, constValue] of constants) {
|
|
35
|
+
const freeIds = freeIdsMap?.get(constName)
|
|
36
|
+
if (freeIds && ![...freeIds].some(id => id !== constName && constants.has(id))) continue
|
|
37
|
+
// Every other constant, not only the recorded free ids: a substituted
|
|
38
|
+
// value can bring in a name the original value did not mention.
|
|
39
|
+
const env: CsrEnv = { substitutions: new Map(), propsObjectName: null }
|
|
40
|
+
for (const [otherName, otherValue] of constants) {
|
|
41
|
+
if (otherName === constName) continue
|
|
42
|
+
env.substitutions.set(otherName, { kind: 'identifier', replacement: otherValue, freeIdentifiers: new Set() })
|
|
43
|
+
}
|
|
44
|
+
const { rewritten, freeIdentifiers } = csrSubstitute(constValue, env)
|
|
45
|
+
if (rewritten === constValue) continue
|
|
46
|
+
constants.set(constName, rewritten)
|
|
47
|
+
if (freeIds) {
|
|
48
|
+
freeIds.clear()
|
|
49
|
+
for (const id of freeIdentifiers) freeIds.add(id)
|
|
78
50
|
}
|
|
79
51
|
}
|
|
80
52
|
}
|
|
@@ -220,7 +192,11 @@ export function emitRegistrationAndHydration(
|
|
|
220
192
|
|
|
221
193
|
// Build ComponentDef object for hydrate()
|
|
222
194
|
const defParts: string[] = [`init: ${initFunctionName(name)}`]
|
|
223
|
-
|
|
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)) {
|
|
224
200
|
const markupSlotIds = markupSlotIdsOf(ctx)
|
|
225
201
|
const templateHtml = irToComponentTemplate(_ir.root, inlinableConstants, restSpreadNames, ctx.propsObjectName, markupSlotIds, ctx.restPropsName)
|
|
226
202
|
if (templateHtml) {
|