@barefootjs/jsx 0.39.6 → 0.39.8
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/attr-plan.d.ts +8 -1
- package/dist/adapters/attr-plan.d.ts.map +1 -1
- package/dist/adapters/callback-method.d.ts +44 -0
- 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/computed-const.d.ts +52 -0
- package/dist/adapters/computed-const.d.ts.map +1 -0
- package/dist/adapters/dangerous-inner-html.d.ts +10 -0
- package/dist/adapters/dangerous-inner-html.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +151 -0
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -0
- package/dist/adapters/element-shell.d.ts +44 -0
- package/dist/adapters/element-shell.d.ts.map +1 -0
- package/dist/adapters/interface.d.ts +2 -0
- package/dist/adapters/interface.d.ts.map +1 -1
- 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/parsed-expr-emitter.d.ts +27 -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/augment-inherited-props.d.ts +7 -0
- package/dist/augment-inherited-props.d.ts.map +1 -1
- package/dist/children-nullish.d.ts +22 -0
- package/dist/children-nullish.d.ts.map +1 -0
- package/dist/errors.d.ts +1 -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/fold-render-reassignments.d.ts +43 -0
- package/dist/fold-render-reassignments.d.ts.map +1 -0
- package/dist/free-refs.d.ts +15 -0
- package/dist/free-refs.d.ts.map +1 -1
- package/dist/index.d.ts +21 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24620 -23233
- package/dist/ir-to-client-js/compute-inlinability.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/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 +0 -13
- 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 +9 -19
- 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/index.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -2
- package/dist/ir-to-client-js/phases/props-extraction.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts +5 -0
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
- package/dist/ir-to-client-js/prop-handling.d.ts +11 -12
- package/dist/ir-to-client-js/prop-handling.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/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/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 +15 -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 +43 -12
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/prop-rewrite.d.ts +18 -0
- package/dist/prop-rewrite.d.ts.map +1 -1
- package/dist/props-binding.d.ts +43 -6
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/relocate.d.ts +16 -0
- package/dist/relocate.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/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 +37 -18
- package/dist/ssr-seed-plan.d.ts.map +1 -1
- package/dist/types.d.ts +162 -20
- 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 +44 -0
- package/src/__tests__/block-memo-type.test.ts +51 -0
- package/src/__tests__/callback-method.test.ts +75 -0
- package/src/__tests__/children-read.test.ts +226 -0
- package/src/__tests__/client-only-date-lowering.test.ts +2 -2
- package/src/__tests__/client-template-escape-soundness.test.ts +31 -1
- package/src/__tests__/component-props.test.ts +68 -1
- package/src/__tests__/computed-const.test.ts +101 -0
- package/src/__tests__/constant-inlining-tree.test.ts +136 -0
- 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__/element-shell.test.ts +78 -0
- package/src/__tests__/event-handler-verbatim.test.ts +73 -0
- package/src/__tests__/expression-parser.test.ts +1 -44
- package/src/__tests__/fold-render-reassignments.test.ts +96 -0
- package/src/__tests__/inlinable-local-method-call.test.ts +81 -0
- package/src/__tests__/memo-body-expr.test.ts +120 -0
- package/src/__tests__/nullable-signal-attr.test.ts +67 -3
- package/src/__tests__/prop-handling.test.ts +35 -16
- package/src/__tests__/props-alias-const.test.ts +65 -0
- package/src/__tests__/reference-graph-identifiers.test.ts +161 -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__/signal-prop-seed.test.ts +90 -0
- package/src/__tests__/ssr-defaults.test.ts +19 -1
- package/src/__tests__/ssr-seed-plan.test.ts +173 -1
- package/src/__tests__/static-template-reachability.test.ts +137 -0
- package/src/__tests__/style-object-plan.test.ts +54 -0
- package/src/__tests__/zero-param-helper-inline.test.ts +57 -0
- package/src/adapters/attr-plan.ts +29 -1
- package/src/adapters/callback-method.ts +85 -0
- package/src/adapters/component-props.ts +130 -12
- package/src/adapters/computed-const.ts +185 -0
- package/src/adapters/dangerous-inner-html.ts +33 -0
- package/src/adapters/dsl-template-adapter.ts +248 -0
- package/src/adapters/element-shell.ts +160 -0
- package/src/adapters/interface.ts +8 -0
- package/src/adapters/jsx-adapter.ts +12 -6
- package/src/adapters/literal-value.ts +2 -2
- package/src/adapters/parsed-expr-emitter.ts +34 -0
- package/src/adapters/style-object.ts +61 -0
- package/src/analyzer.ts +382 -94
- package/src/augment-inherited-props.ts +12 -0
- package/src/children-nullish.ts +33 -0
- package/src/debug.ts +2 -2
- package/src/errors.ts +12 -0
- package/src/expression-parser.ts +56 -53
- package/src/fold-render-reassignments.ts +314 -0
- package/src/free-refs.ts +77 -17
- package/src/index.ts +27 -10
- package/src/ir-to-client-js/compute-inlinability.ts +122 -19
- 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/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 +25 -37
- package/src/ir-to-client-js/emit-reactive.ts +2 -2
- package/src/ir-to-client-js/emit-registration.ts +31 -59
- package/src/ir-to-client-js/generate-init.ts +17 -1
- package/src/ir-to-client-js/html-template.ts +56 -120
- 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 +5 -3
- package/src/ir-to-client-js/init-declarations.ts +1 -1
- package/src/ir-to-client-js/phases/event-handlers.ts +2 -2
- package/src/ir-to-client-js/phases/props-extraction.ts +16 -15
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +26 -52
- package/src/ir-to-client-js/plan/declaration-emit.ts +5 -0
- package/src/ir-to-client-js/prop-handling.ts +13 -54
- 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 +27 -9
- package/src/ir-to-client-js/safe-html.ts +29 -35
- package/src/ir-to-client-js/stringify/declaration-emit.ts +1 -1
- package/src/ir-to-client-js/types.ts +3 -2
- package/src/ir-to-client-js/utils.ts +13 -26
- package/src/jsx-to-ir.ts +318 -130
- package/src/nullable-signal-attr.ts +156 -37
- package/src/prop-rewrite.ts +41 -0
- package/src/props-binding.ts +117 -7
- package/src/relocate.ts +40 -8
- package/src/scanner/__tests__/js-scanner.test.ts +37 -0
- package/src/scanner/js-scanner.ts +64 -4
- package/src/signal-prop-name-collision.ts +50 -24
- package/src/ssr-defaults.ts +47 -20
- package/src/ssr-seed-plan.ts +121 -29
- package/src/types.ts +165 -21
- package/src/value-references.ts +132 -0
package/src/free-refs.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type {
|
|
|
23
23
|
ConstantInfo,
|
|
24
24
|
FunctionInfo,
|
|
25
25
|
} from './types.ts'
|
|
26
|
+
import { isChildrenPropParam } from './types.ts'
|
|
26
27
|
import { isReactiveType } from './reactivity-checker.ts'
|
|
27
28
|
import { incrementCounter } from './instrumentation.ts'
|
|
28
29
|
|
|
@@ -36,6 +37,12 @@ export interface BindingEnvironment {
|
|
|
36
37
|
memos: readonly MemoInfo[]
|
|
37
38
|
propsParams: readonly ParamInfo[]
|
|
38
39
|
propsObjectName: string | null
|
|
40
|
+
/**
|
|
41
|
+
* Component-scope consts that alias the props object (`const p = props`,
|
|
42
|
+
* through any number of hops). A `.children` read through one of them is
|
|
43
|
+
* the children prop, the same as `props.children` (#3572).
|
|
44
|
+
*/
|
|
45
|
+
propsObjectAliases?: ReadonlySet<string>
|
|
39
46
|
restPropsName: string | null
|
|
40
47
|
localConstants: readonly ConstantInfo[]
|
|
41
48
|
localFunctions: readonly FunctionInfo[]
|
|
@@ -106,7 +113,7 @@ function buildBindingMap(env: BindingEnvironment): Map<string, BindingKind> {
|
|
|
106
113
|
// the OR-combined `reactive` flag promotes it to a text slot,
|
|
107
114
|
// breaking SSR hydration on every UI component that forwards
|
|
108
115
|
// children.
|
|
109
|
-
if (p
|
|
116
|
+
if (isChildrenPropParam(p)) continue
|
|
110
117
|
map.set(p.name, 'prop')
|
|
111
118
|
}
|
|
112
119
|
if (env.propsObjectName !== null) {
|
|
@@ -298,6 +305,25 @@ function resolveConstantInitializerRefs(
|
|
|
298
305
|
* the transitive-taint expansion path. `visited` tracks identifier names
|
|
299
306
|
* already expanded to break cycles like `const a = b; const b = a`.
|
|
300
307
|
*/
|
|
308
|
+
/**
|
|
309
|
+
* `props.children` is rendered into the server-side HTML (it is the child
|
|
310
|
+
* slot, not a reactive value). The `props` identifier is a non-reactive
|
|
311
|
+
* reference *only* in this position, so consumers don't wrap the
|
|
312
|
+
* surrounding expression in createEffect just because it touches `props`.
|
|
313
|
+
* Matches the legacy `isPropsReference` semantics. A const alias of the
|
|
314
|
+
* props object (`const p = props; p.children`) reads the same prop (#3572).
|
|
315
|
+
*/
|
|
316
|
+
function isPropsChildrenRead(ident: ts.Identifier, env: BindingEnvironment): boolean {
|
|
317
|
+
if (env.propsObjectName !== ident.text && !env.propsObjectAliases?.has(ident.text)) return false
|
|
318
|
+
const parent = ident.parent
|
|
319
|
+
return (
|
|
320
|
+
!!parent &&
|
|
321
|
+
ts.isPropertyAccessExpression(parent) &&
|
|
322
|
+
parent.expression === ident &&
|
|
323
|
+
parent.name.text === 'children'
|
|
324
|
+
)
|
|
325
|
+
}
|
|
326
|
+
|
|
301
327
|
function resolveFreeRefsInternal(
|
|
302
328
|
node: ts.Node,
|
|
303
329
|
env: BindingEnvironment,
|
|
@@ -312,22 +338,7 @@ function resolveFreeRefsInternal(
|
|
|
312
338
|
for (const ident of idents) {
|
|
313
339
|
const name = ident.text
|
|
314
340
|
|
|
315
|
-
|
|
316
|
-
// child slot, not a reactive value). Treat the `props` identifier as
|
|
317
|
-
// a non-reactive reference *only* in this position so consumers don't
|
|
318
|
-
// wrap the surrounding expression in createEffect just because it
|
|
319
|
-
// touches `props`. Matches the legacy `isPropsReference` semantics.
|
|
320
|
-
if (env.propsObjectName === name) {
|
|
321
|
-
const parent = ident.parent
|
|
322
|
-
if (
|
|
323
|
-
parent &&
|
|
324
|
-
ts.isPropertyAccessExpression(parent) &&
|
|
325
|
-
parent.expression === ident &&
|
|
326
|
-
parent.name.text === 'children'
|
|
327
|
-
) {
|
|
328
|
-
continue
|
|
329
|
-
}
|
|
330
|
-
}
|
|
341
|
+
if (isPropsChildrenRead(ident, env)) continue
|
|
331
342
|
|
|
332
343
|
let kind: BindingKind | undefined = bindingMap.get(name)
|
|
333
344
|
|
|
@@ -425,3 +436,52 @@ export function resolveFreeRefs(
|
|
|
425
436
|
): FreeReference[] {
|
|
426
437
|
return resolveFreeRefsInternal(node, env, new Set<string>())
|
|
427
438
|
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Replace the free references to a helper's parameters, inside the IR built
|
|
442
|
+
* from its inlined body, with the references of the call's arguments
|
|
443
|
+
* (#3509). `argRefs` maps each parameter name to its argument's resolved
|
|
444
|
+
* references. Rewrites `origin.freeRefs` (expressions, conditions, and any
|
|
445
|
+
* other node carrying an origin) and attribute `freeIdentifiers` in place,
|
|
446
|
+
* anywhere in the subtree.
|
|
447
|
+
*/
|
|
448
|
+
export function rebindHelperParamRefs(root: unknown, argRefs: ReadonlyMap<string, readonly FreeReference[]>): void {
|
|
449
|
+
if (argRefs.size === 0) return
|
|
450
|
+
const seen = new WeakSet<object>()
|
|
451
|
+
const visit = (value: unknown): void => {
|
|
452
|
+
if (typeof value !== 'object' || value === null || seen.has(value)) return
|
|
453
|
+
seen.add(value)
|
|
454
|
+
if (Array.isArray(value)) {
|
|
455
|
+
for (const item of value) visit(item)
|
|
456
|
+
return
|
|
457
|
+
}
|
|
458
|
+
if (value instanceof Set || value instanceof Map) return
|
|
459
|
+
const node = value as { origin?: { freeRefs?: FreeReference[] }; freeIdentifiers?: ReadonlySet<string> }
|
|
460
|
+
if (node.origin?.freeRefs) node.origin.freeRefs = rebindRefs(node.origin.freeRefs, argRefs)
|
|
461
|
+
if (node.freeIdentifiers instanceof Set) node.freeIdentifiers = rebindIds(node.freeIdentifiers, argRefs)
|
|
462
|
+
for (const child of Object.values(value)) visit(child)
|
|
463
|
+
}
|
|
464
|
+
visit(root)
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function rebindRefs(refs: FreeReference[], argRefs: ReadonlyMap<string, readonly FreeReference[]>): FreeReference[] {
|
|
468
|
+
if (!refs.some(r => argRefs.has(r.name))) return refs
|
|
469
|
+
const out: FreeReference[] = []
|
|
470
|
+
for (const ref of refs) {
|
|
471
|
+
const replacement = argRefs.get(ref.name)
|
|
472
|
+
if (!replacement) out.push(ref)
|
|
473
|
+
else for (const r of replacement) if (!out.some(o => o.name === r.name && o.kind === r.kind)) out.push(r)
|
|
474
|
+
}
|
|
475
|
+
return out
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function rebindIds(ids: ReadonlySet<string>, argRefs: ReadonlyMap<string, readonly FreeReference[]>): ReadonlySet<string> {
|
|
479
|
+
if (![...ids].some(id => argRefs.has(id))) return ids
|
|
480
|
+
const out = new Set<string>()
|
|
481
|
+
for (const id of ids) {
|
|
482
|
+
const replacement = argRefs.get(id)
|
|
483
|
+
if (!replacement) out.add(id)
|
|
484
|
+
else for (const r of replacement) if (r.kind !== 'reactive-brand') out.add(r.name)
|
|
485
|
+
}
|
|
486
|
+
return out
|
|
487
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ export { isOpaqueLocalAccessorName } from './opaque-local-accessor.ts'
|
|
|
20
20
|
// data props, not handlers. Shared by the IR builder, client-JS prop wiring
|
|
21
21
|
// and the SSR adapters' "a handler has no SSR value" skips.
|
|
22
22
|
export { isEventHandlerName } from './event-handler-name.ts'
|
|
23
|
+
export { fallbackChainParts, nullishChainParts } from './children-nullish.ts'
|
|
23
24
|
|
|
24
25
|
// Shared props-destructure binding + alias-map helpers (#2524, #2788)
|
|
25
26
|
export { propsDestructureBinding, buildPropAliasMap, isIdentifierName, resolveBodyDestructuredPropAliases } from './props-binding.ts'
|
|
@@ -38,11 +39,12 @@ export { resolveGetterAliases, collectAliasableGetterNames } from './ir-to-clien
|
|
|
38
39
|
export { buildImportAliasMap } from './ir-to-client-js/component-scope.ts'
|
|
39
40
|
|
|
40
41
|
// Backend-neutral SSR seed plan (in-template derived signal/memo seeding)
|
|
41
|
-
export { computeSsrSeedPlan } from './ssr-seed-plan.ts'
|
|
42
|
+
export { computeSsrSeedPlan, inDefaultReadOrder } from './ssr-seed-plan.ts'
|
|
42
43
|
export type { SsrSeedPlan, SsrSeedStep } from './ssr-seed-plan.ts'
|
|
43
44
|
|
|
44
45
|
// Pure IR types
|
|
45
46
|
export type {
|
|
47
|
+
JsSourceText,
|
|
46
48
|
ComponentIR,
|
|
47
49
|
IRNode,
|
|
48
50
|
IRElement,
|
|
@@ -64,6 +66,7 @@ export type {
|
|
|
64
66
|
AttrValue,
|
|
65
67
|
LiteralAttr,
|
|
66
68
|
ExpressionAttr,
|
|
69
|
+
TypedExprSource,
|
|
67
70
|
BooleanAttr,
|
|
68
71
|
BooleanShorthandAttr,
|
|
69
72
|
TemplateAttr,
|
|
@@ -72,6 +75,8 @@ export type {
|
|
|
72
75
|
IRTemplatePart,
|
|
73
76
|
IRProp,
|
|
74
77
|
ParamInfo,
|
|
78
|
+
PropDefaultPart,
|
|
79
|
+
PropDefaultRead,
|
|
75
80
|
PropertyInfo,
|
|
76
81
|
MemoInfo,
|
|
77
82
|
ConstantInfo,
|
|
@@ -87,7 +92,7 @@ export type {
|
|
|
87
92
|
RenderDivergences,
|
|
88
93
|
ImportInfo,
|
|
89
94
|
} from './types.ts'
|
|
90
|
-
export { isElidedFactoryGetter } from './types.ts'
|
|
95
|
+
export { isElidedFactoryGetter, isChildrenPropParam } from './types.ts'
|
|
91
96
|
|
|
92
97
|
// Analyzer
|
|
93
98
|
export { analyzeComponent, listComponentFunctions, listComponentFunctions as listExportedComponents, scanComponentFile, createProgramForFile, createAnchoredProgram, needsTypeBasedDetection, resolveRelativeImportToFile, REACTIVE_PRIMITIVES, CLIENT_EXPORTS, BROWSER_ONLY_CLIENT_APIS, type AnalyzerContext, type ComponentFileScan } from './analyzer.ts'
|
|
@@ -102,6 +107,8 @@ export { generateModuleExports, extractFunctionParams, formatParamWithType, find
|
|
|
102
107
|
|
|
103
108
|
// Adapters
|
|
104
109
|
export { BaseAdapter } from './adapters/interface.ts'
|
|
110
|
+
export { DslTemplateAdapter } from './adapters/dsl-template-adapter.ts'
|
|
111
|
+
export type { TemplateIdentifierSpelling } from './adapters/dsl-template-adapter.ts'
|
|
105
112
|
// Dependency-free adapter for tooling that only needs client JS (e.g. the
|
|
106
113
|
// profiler scenario driver) — the client output is adapter-independent.
|
|
107
114
|
export { TestAdapter, testAdapter } from './adapters/test-adapter.ts'
|
|
@@ -117,9 +124,10 @@ export type {
|
|
|
117
124
|
export { JsxAdapter } from './adapters/jsx-adapter.ts'
|
|
118
125
|
export type { JsxAdapterConfig } from './adapters/jsx-adapter.ts'
|
|
119
126
|
export { rewriteImportsForTemplate, rewriteDynamicImportsInSource } from './adapters/template-imports.ts'
|
|
120
|
-
export { emitParsedExpr, groupBinaryOperand, groupObjectLiteralSegments, isStringTypedOperand, isStringConcatBinary, isNumericArithmeticResult } from './adapters/parsed-expr-emitter.ts'
|
|
121
|
-
export type { ParsedExprEmitter, LoweringEmitter, HigherOrderMethod, ArrayMethod, SortMethod, LiteralType } from './adapters/parsed-expr-emitter.ts'
|
|
127
|
+
export { emitParsedExpr, arithmeticHelper, groupBinaryOperand, groupUnaryOperand, groupObjectLiteralSegments, isStringTypedOperand, isStringConcatBinary, isNumericArithmeticResult } from './adapters/parsed-expr-emitter.ts'
|
|
128
|
+
export type { ArithmeticHelper, ParsedExprEmitter, LoweringEmitter, HigherOrderMethod, ArrayMethod, SortMethod, LiteralType } from './adapters/parsed-expr-emitter.ts'
|
|
122
129
|
export { collectLoopBoundNames } from './adapters/loop-bound-names.ts'
|
|
130
|
+
export { planStyleObject, type StyleObjectPlanEntry } from './adapters/style-object.ts'
|
|
123
131
|
export { filterCaptureCollisions } from './adapters/filter-capture-collisions.ts'
|
|
124
132
|
export { templateNameCollisionErrors } from './adapters/template-name-collisions.ts'
|
|
125
133
|
export {
|
|
@@ -145,6 +153,10 @@ export {
|
|
|
145
153
|
isPredicateMethod,
|
|
146
154
|
lowerCallbackMethod,
|
|
147
155
|
nestedCallbackRefusal,
|
|
156
|
+
filterPredicateShapeRefusal,
|
|
157
|
+
missingFilterPredicateRefusal,
|
|
158
|
+
isUnloweredCall,
|
|
159
|
+
unloweredCallRefusal,
|
|
148
160
|
sortEvalPlan,
|
|
149
161
|
sortRefusal,
|
|
150
162
|
} from './adapters/callback-method.ts'
|
|
@@ -167,11 +179,13 @@ export type {
|
|
|
167
179
|
ArrayMethodSpelling,
|
|
168
180
|
} from './adapters/array-method.ts'
|
|
169
181
|
export { derivesScopeFromSlot } from './adapters/child-scope.ts'
|
|
170
|
-
export { childTemplateName, componentPropKey, isEmptyComponentProps, planComponentProps, spellComponentProps } from './adapters/component-props.ts'
|
|
171
|
-
export type { ComponentPropEntry, ComponentPropSegment, ComponentPropSpelling, ComponentPropsOptions, SpelledComponentPropSegment } from './adapters/component-props.ts'
|
|
172
|
-
export { parseUndefinedAlternateTernary, planAttrExpression, planSpreadAttr, unsupportedAttrExpression } from './adapters/attr-plan.ts'
|
|
182
|
+
export { childTemplateName, componentPropKey, isEmptyComponentProps, planComponentProps, propsSpreadParam, resolveComponentPropKeys, spellComponentProps } from './adapters/component-props.ts'
|
|
183
|
+
export type { ComponentPropEntry, ComponentPropSegment, ComponentPropSpelling, ComponentPropsOptions, ComponentPropsParam, EarlierComponentProps, ResolvedComponentProp, SpelledComponentPropSegment } from './adapters/component-props.ts'
|
|
184
|
+
export { parseUndefinedAlternateTernary, planAttrExpression, planSpreadAttr, unsupportedAttrExpression, unsupportedAttrExpressionError } from './adapters/attr-plan.ts'
|
|
173
185
|
export type { AttrExpressionPlan, AttrPlanContext, SpreadAttrPlan, SpreadPlanContext, UndefinedAlternateTernary } from './adapters/attr-plan.ts'
|
|
174
186
|
export { planLoop } from './adapters/loop-plan.ts'
|
|
187
|
+
export { computedConstContext, inlineComputedConstAttr, inlineComputedConsts } from './adapters/computed-const.ts'
|
|
188
|
+
export type { ComputedConstContext } from './adapters/computed-const.ts'
|
|
175
189
|
export type { LoopPlan, LoopPlanContext } from './adapters/loop-plan.ts'
|
|
176
190
|
export { evaluateStaticLiteral, isFullyStaticLiteral, resolveStaticLoopSource } from './static-literal.ts'
|
|
177
191
|
export {
|
|
@@ -180,6 +194,7 @@ export {
|
|
|
180
194
|
arithmeticOperandCoercion,
|
|
181
195
|
bareGetterCallName,
|
|
182
196
|
attrValueMayBeNullish,
|
|
197
|
+
collectAbsentPropSeedReads,
|
|
183
198
|
collectNullableSignalGetters,
|
|
184
199
|
collectNullishAttrContext,
|
|
185
200
|
isNullableSignal,
|
|
@@ -225,7 +240,10 @@ export {
|
|
|
225
240
|
resolveDangerousInnerHtml,
|
|
226
241
|
dangerousInnerHtmlMetacharViolation,
|
|
227
242
|
dangerousInnerHtmlDiagnostic,
|
|
243
|
+
renderDangerousInnerHtml,
|
|
228
244
|
} from './adapters/dangerous-inner-html.ts'
|
|
245
|
+
export { renderElementAttributes, renderElementShell, renderFragmentScope } from './adapters/element-shell.ts'
|
|
246
|
+
export type { ElementShellSpelling } from './adapters/element-shell.ts'
|
|
229
247
|
export type { DangerousInnerHtmlResolution } from './adapters/dangerous-inner-html.ts'
|
|
230
248
|
|
|
231
249
|
// Client JS Generator
|
|
@@ -304,8 +322,7 @@ export { ErrorCodes, createError, formatError, generateCodeFrame } from './error
|
|
|
304
322
|
export { isValueReferenceIdentifier, collectValueReferencedNames } from './value-references.ts'
|
|
305
323
|
|
|
306
324
|
// Expression Parser
|
|
307
|
-
export { parseExpression, tsNodeToParsedExpr, asCallbackMethodCall, hasOpaqueCall, unboundCallbackParamRead, unboundCallbackParamReason, CALLBACK_METHODS, sortComparatorFromArrow, serializeParsedExpr, freeVarsInBody, freeIdentifiers, renameFreeIdentifiers, materializeGetterCalls, isSupported, isSupportedValue, exprToString, stringifyParsedExpr, identifierPath, parseBlockBody, parseBlockBodyTolerant, foldBlockToExpr, predicateTernaryToLogical, containsHigherOrder, extractArrowBodyExpression,
|
|
308
|
-
export type { StyleObjectEntry } from './expression-parser.ts'
|
|
325
|
+
export { parseExpression, tsNodeToParsedExpr, asCallbackMethodCall, hasOpaqueCall, unboundCallbackParamRead, unboundCallbackParamReason, CALLBACK_METHODS, sortComparatorFromArrow, serializeParsedExpr, freeVarsInBody, freeIdentifiers, renameFreeIdentifiers, materializeGetterCalls, isSupported, isSupportedValue, exprToString, stringifyParsedExpr, identifierPath, parseBlockBody, parseBlockBodyTolerant, foldBlockToExpr, predicateTernaryToLogical, containsHigherOrder, extractArrowBodyExpression, hasUnsafeStyleValue, parseProviderObjectLiteral, isFunctionShapedExpression, type ProviderObjectMember, type FoldBlockOptions } from './expression-parser.ts'
|
|
309
326
|
export { literalMemberIndex } from './literal-member-index.ts'
|
|
310
327
|
export { PARSED_EXPR_KINDS, ARRAY_METHOD_NAMES, SORT_KEY_TYPES, SORT_KEY_TARGETS, SORT_KEY_DIRECTIONS } from './expression-parser.ts'
|
|
311
328
|
export type { ParsedExpr, ObjectLiteralProperty, ParsedStatement, SortComparator, SortKey, FlatDepth, SupportLevel, SupportResult, TemplatePart } from './expression-parser.ts'
|
|
@@ -431,7 +448,7 @@ export { BOOLEAN_ATTRS, isBooleanAttr } from './html-constants.ts'
|
|
|
431
448
|
export { USE_CLIENT_DIRECTIVE, CLIENT_EXPRESSION_DIRECTIVE } from './directives.ts'
|
|
432
449
|
|
|
433
450
|
// Shared props-object-pattern helpers for the Go / Mojo template adapters
|
|
434
|
-
export { augmentInheritedPropAccesses, parseRecordIndexAccess, evalStringArrayJoin, collectModuleStringConsts, lookupStaticRecordLiteral, lookupLiteralConst, collectContextConsumers } from './augment-inherited-props.ts'
|
|
451
|
+
export { augmentInheritedPropAccesses, parseRecordIndexAccess, evalStringArrayJoin, collectModuleStringConsts, lookupStaticRecordLiteral, lookupLiteralConst, collectContextConsumers, contextConsumerSeed } from './augment-inherited-props.ts'
|
|
435
452
|
export type { RecordIndexAccess, RecordIndexEntry, ContextConsumer } from './augment-inherited-props.ts'
|
|
436
453
|
|
|
437
454
|
// HTML element attribute types
|
|
@@ -30,6 +30,7 @@ import { extractIdentifiers, extractTemplateIdentifiers } from './identifiers.ts
|
|
|
30
30
|
import { isInlinableInTemplate, buildRelocateEnvFromIR } from '../relocate.ts'
|
|
31
31
|
import type { RelocateEnv, RelocateDecision } from '../relocate.ts'
|
|
32
32
|
import { createError, ErrorCodes } from '../errors.ts'
|
|
33
|
+
import { zeroArgCallBody } from '../expression-parser.ts'
|
|
33
34
|
import { attrValueToString } from './utils.ts'
|
|
34
35
|
import { walkIR, type IRVisitor } from './walker.ts'
|
|
35
36
|
import { buildSignalMemoEnv, csrSubstitute, resolveGetterAliases, type CsrEnv, type CsrSubstitution } from './csr-substitute.ts'
|
|
@@ -296,19 +297,27 @@ export function computeInlinability(
|
|
|
296
297
|
// here rather than calling `computeDeclarationScopes` a second time.
|
|
297
298
|
|
|
298
299
|
const decisionsByName = new Map<string, RelocateDecision[]>()
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
300
|
+
// Constants are classified in declaration order, so a later const can see
|
|
301
|
+
// which earlier ones inline (#3513) and accept a method call on them.
|
|
302
|
+
const inlinableLocals = new Set<string>()
|
|
303
|
+
env.inlinableLocals = inlinableLocals
|
|
304
|
+
const classifyAll = (refused: ReadonlySet<string>) => {
|
|
305
|
+
inlinableLocals.clear()
|
|
306
|
+
for (const c of ctx.localConstants) {
|
|
307
|
+
const { status, decisions } = classifyConstantInitial(
|
|
308
|
+
c,
|
|
309
|
+
graph.declaredNames,
|
|
310
|
+
signalGetters,
|
|
311
|
+
signalSetters,
|
|
312
|
+
memoNames,
|
|
313
|
+
env,
|
|
314
|
+
getterAliases,
|
|
315
|
+
constantScope,
|
|
316
|
+
)
|
|
317
|
+
constants.set(c.name, status)
|
|
318
|
+
decisionsByName.set(c.name, decisions)
|
|
319
|
+
if (status.kind === 'inlinable' && !refused.has(c.name)) inlinableLocals.add(c.name)
|
|
320
|
+
}
|
|
312
321
|
}
|
|
313
322
|
|
|
314
323
|
const templateRiskyNames = collectTemplateRiskyNames(irRoot)
|
|
@@ -320,7 +329,21 @@ export function computeInlinability(
|
|
|
320
329
|
// transformation. The map lives on `ClientJsContext` — not on the
|
|
321
330
|
// cross-adapter `ConstantInfo` IR — so SSR adapters don't see CSR
|
|
322
331
|
// substitution semantics they have no use for.
|
|
323
|
-
|
|
332
|
+
//
|
|
333
|
+
// A const classified inlinable can still end with no CSR form here
|
|
334
|
+
// (`(choices).includes(name)` fails the post-substitution check). A
|
|
335
|
+
// method call on it was accepted on the provisional verdict, so it would
|
|
336
|
+
// read as `undefined.m()`: withdraw the receiver and classify again
|
|
337
|
+
// until no accepted receiver is refused. Each round removes at least one
|
|
338
|
+
// name, so this stops within `localConstants.length` rounds.
|
|
339
|
+
const refused = new Set<string>()
|
|
340
|
+
for (;;) {
|
|
341
|
+
classifyAll(refused)
|
|
342
|
+
populateCsrInlinable(ctx, env, getterAliases, constantScope)
|
|
343
|
+
const withdrawn = [...inlinableLocals].filter(name => ctx.csrInlinable.get(name) === null)
|
|
344
|
+
if (withdrawn.length === 0) break
|
|
345
|
+
for (const name of withdrawn) refused.add(name)
|
|
346
|
+
}
|
|
324
347
|
|
|
325
348
|
return { constants, functions, decisionsByName, templateRiskyNames }
|
|
326
349
|
}
|
|
@@ -346,7 +369,10 @@ export function computeInlinability(
|
|
|
346
369
|
* in which case it gets an identity entry (`rewrittenValue: name`)
|
|
347
370
|
* instead of `null` — the compiled bundle declares the const at
|
|
348
371
|
* module scope too, so referencing it by its own bare name from the
|
|
349
|
-
* CSR template is exactly as safe as a `module-scope-safe` function
|
|
372
|
+
* CSR template is exactly as safe as a `module-scope-safe` function.
|
|
373
|
+
* A zero-param arrow helper (`() => props.mode === 'wide'`) is not
|
|
374
|
+
* marked here either: it is substituted like any other value, so a
|
|
375
|
+
* template call `isWide()` reads its body (#3562)
|
|
350
376
|
* - it's a system construct (`createContext`, `new WeakMap`)
|
|
351
377
|
* - it's a JSX literal (handled by jsx-inline routing)
|
|
352
378
|
* - it's a bare alias-hop chain naming a signal/memo getter (`getterAliases`)
|
|
@@ -381,6 +407,7 @@ function populateCsrInlinable(
|
|
|
381
407
|
substitutions: new Map([...baseEnv.substitutions, ...constSubs]),
|
|
382
408
|
propsObjectName: baseEnv.propsObjectName,
|
|
383
409
|
})
|
|
410
|
+
const receivers = inlinedReceiverCheck(relocateEnv)
|
|
384
411
|
|
|
385
412
|
// Pre-mark consts that are structurally ineligible — they record
|
|
386
413
|
// `null` in `ctx.csrInlinable`. Mirrors `classifyConstantInitial`
|
|
@@ -414,7 +441,12 @@ function populateCsrInlinable(
|
|
|
414
441
|
finalised.add(c.name)
|
|
415
442
|
continue
|
|
416
443
|
}
|
|
417
|
-
|
|
444
|
+
// A zero-param helper (`const isWide = () => props.mode === 'wide'`) goes
|
|
445
|
+
// through the substitution below like any other const: `isWide()` then
|
|
446
|
+
// reads `(() => props.mode === 'wide')()` in template scope, so a seed
|
|
447
|
+
// or attribute that calls it renders its value instead of the empty
|
|
448
|
+
// fallback (#3562).
|
|
449
|
+
if (hasNoCsrSubstitute(c) || getterAliases.has(c.name)) {
|
|
418
450
|
ctx.csrInlinable.set(c.name, null)
|
|
419
451
|
finalised.add(c.name)
|
|
420
452
|
}
|
|
@@ -473,11 +505,10 @@ function populateCsrInlinable(
|
|
|
473
505
|
// `rewritePropsObjectRef` doesn't need to redo the AST work. The
|
|
474
506
|
// free identifiers are re-extracted from the bridged form so
|
|
475
507
|
// the post-substitution unsafe-name check stays exact.
|
|
476
|
-
const
|
|
477
|
-
if (
|
|
508
|
+
const bridgedRewritten = bridgedCsrForm(rewritten, source, env, relocateEnv, receivers)
|
|
509
|
+
if (bridgedRewritten === null) {
|
|
478
510
|
ctx.csrInlinable.set(c.name, null)
|
|
479
511
|
} else {
|
|
480
|
-
const bridgedRewritten = inlineResult.rewrittenValue
|
|
481
512
|
const bridgedFreeIdentifiers = recomputeFreeIdentifiers(bridgedRewritten, freeIdentifiers)
|
|
482
513
|
ctx.csrInlinable.set(c.name, { rewrittenValue: bridgedRewritten, freeIdentifiers: bridgedFreeIdentifiers })
|
|
483
514
|
constSubs.set(c.name, {
|
|
@@ -485,6 +516,7 @@ function populateCsrInlinable(
|
|
|
485
516
|
replacement: bridgedRewritten,
|
|
486
517
|
freeIdentifiers: bridgedFreeIdentifiers,
|
|
487
518
|
})
|
|
519
|
+
receivers.add(c.name, bridgedRewritten)
|
|
488
520
|
}
|
|
489
521
|
finalised.add(c.name)
|
|
490
522
|
progressed = true
|
|
@@ -500,6 +532,77 @@ function populateCsrInlinable(
|
|
|
500
532
|
}
|
|
501
533
|
}
|
|
502
534
|
|
|
535
|
+
/**
|
|
536
|
+
* A const whose value is a zero-param, synchronous arrow with a pure value
|
|
537
|
+
* body (`() => props.mode === 'wide'`, see `zeroArgCallBody`): calling it
|
|
538
|
+
* only reads the names its body reads, so splicing the arrow into template
|
|
539
|
+
* scope is as safe as splicing that body, which the substitution's own
|
|
540
|
+
* template-safety check decides. A body that mutates state
|
|
541
|
+
* (`() => ({ id: ++nextId })`) must run where it is declared.
|
|
542
|
+
*/
|
|
543
|
+
function isZeroParamArrowHelper(c: ConstantInfo): boolean {
|
|
544
|
+
return c.parsed !== undefined && zeroArgCallBody(c.parsed) !== null
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** A const with no value this pass can substitute (see `populateCsrInlinable`). */
|
|
548
|
+
function hasNoCsrSubstitute(c: ConstantInfo): boolean {
|
|
549
|
+
const containsUnsplicedArrow = c.containsArrow && !isZeroParamArrowHelper(c)
|
|
550
|
+
return Boolean(c.isJsx || !c.value || containsUnsplicedArrow || c.systemConstructKind || c.mutatedAfterDeclaration)
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* The bridged CSR form of a const whose substituted text is `rewritten`, or
|
|
555
|
+
* null when it isn't safe in template scope.
|
|
556
|
+
*/
|
|
557
|
+
function bridgedCsrForm(
|
|
558
|
+
rewritten: string,
|
|
559
|
+
source: string,
|
|
560
|
+
env: CsrEnv,
|
|
561
|
+
relocateEnv: RelocateEnv,
|
|
562
|
+
receivers: ReturnType<typeof inlinedReceiverCheck>,
|
|
563
|
+
): string | null {
|
|
564
|
+
const inlineResult = isInlinableInTemplate(rewritten, relocateEnv)
|
|
565
|
+
return inlineResult.ok ? inlineResult.rewrittenValue : receivers.check(source, env)
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* The post-substitution check refuses a method call on an inlinable local
|
|
570
|
+
* (`text.toUpperCase()`, #3513): once `text` is substituted, the receiver
|
|
571
|
+
* is a parenthesized expression the adapter can't vouch for. `check`
|
|
572
|
+
* re-runs it with the receivers that already have a CSR form left as
|
|
573
|
+
* identifiers, so relocate's receiver rule decides the call and inlines
|
|
574
|
+
* each one as its `inline` form (an `inline` read inside a call argument
|
|
575
|
+
* still counts as bridged, #1138). A receiver whose own CSR form was
|
|
576
|
+
* refused is never added, so a call on it stays refused.
|
|
577
|
+
*/
|
|
578
|
+
function inlinedReceiverCheck(relocateEnv: RelocateEnv): {
|
|
579
|
+
add: (name: string, bridged: string) => void
|
|
580
|
+
check: (source: string, env: CsrEnv) => string | null
|
|
581
|
+
} {
|
|
582
|
+
const inlined = new Map<string, string>()
|
|
583
|
+
const vetted = new Set<string>()
|
|
584
|
+
const receiverEnv: RelocateEnv = { ...relocateEnv, inlinable: inlined, inlinableLocals: vetted }
|
|
585
|
+
return {
|
|
586
|
+
add(name, bridged) {
|
|
587
|
+
// Only an init-local reaches relocate's receiver rule; a module
|
|
588
|
+
// const keeps the post-substitution verdict (#2106).
|
|
589
|
+
const kind = relocateEnv.bindings.get(name)
|
|
590
|
+
if (kind !== 'init-local' && kind !== 'sub-init-local') return
|
|
591
|
+
if (relocateEnv.inlinableLocals?.has(name) !== true) return
|
|
592
|
+
vetted.add(name)
|
|
593
|
+
inlined.set(name, `(${bridged})`)
|
|
594
|
+
},
|
|
595
|
+
check(source, env) {
|
|
596
|
+
if (vetted.size === 0) return null
|
|
597
|
+
const substitutions = new Map(env.substitutions)
|
|
598
|
+
for (const name of vetted) substitutions.delete(name)
|
|
599
|
+
const partial = csrSubstitute(source, { substitutions, propsObjectName: env.propsObjectName }).rewritten
|
|
600
|
+
const result = isInlinableInTemplate(partial, receiverEnv)
|
|
601
|
+
return result.ok ? result.rewrittenValue : null
|
|
602
|
+
},
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
503
606
|
/**
|
|
504
607
|
* Recompute free identifiers after `relocate` has rewritten bare prop
|
|
505
608
|
* refs to `_p.X`. The pre-rewrite free-id set may still mention the
|
|
@@ -20,13 +20,14 @@
|
|
|
20
20
|
|
|
21
21
|
import type { InteractiveElement } from '../../types.ts'
|
|
22
22
|
import { toDomEventName, NON_BUBBLING_EVENTS } from '../../utils.ts'
|
|
23
|
+
import type { JsSourceText } from '../../../types.ts'
|
|
23
24
|
|
|
24
25
|
export interface ContainerOwnHandler {
|
|
25
26
|
/** The container element's own slot id (used for profile-mode turn ids). */
|
|
26
27
|
slotId: string
|
|
27
28
|
/** Original (pre-DOM-mapped) event name, e.g. 'contextmenu'. */
|
|
28
29
|
eventName: string
|
|
29
|
-
handler:
|
|
30
|
+
handler: JsSourceText
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
/**
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* `ArmBody.conditionals`, so one stringifier handles arbitrary depth.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type { AttrMeta } from '../../../types.ts'
|
|
9
|
+
import type { AttrMeta, JsSourceText } from '../../../types.ts'
|
|
10
10
|
import type { ScopeRef } from './common.ts'
|
|
11
11
|
import type { BranchLoopPlan } from './branch-loop.ts'
|
|
12
12
|
|
|
@@ -84,7 +84,7 @@ export interface ArmEventBind {
|
|
|
84
84
|
slotId: string
|
|
85
85
|
eventName: string
|
|
86
86
|
/** Handler source expression (already trimmed). The stringifier wraps it. */
|
|
87
|
-
handler:
|
|
87
|
+
handler: JsSourceText
|
|
88
88
|
/** Profile-mode turn id (#1690, SR3); when set the listener is turn-wrapped. */
|
|
89
89
|
turnId?: string
|
|
90
90
|
}
|
|
@@ -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}) }`)
|