@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
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import ts from 'typescript'
|
|
28
|
-
import type
|
|
28
|
+
import { type PropUsage, isChildrenPropParam } from '../types.ts'
|
|
29
29
|
import { computePropsUsedAsConditions } from './compute-prop-usage.ts'
|
|
30
30
|
import { boundPropLocalNames, livePropReadExpr, resolveBodyPropAliases, type LivePropReadInfo } from '../props-binding.ts'
|
|
31
31
|
import { parsePropReadInitializer } from './prune-unused-prop-extractions.ts'
|
|
@@ -54,7 +54,8 @@ export function rewriteDestructuredPropReads(
|
|
|
54
54
|
* handler-local `const title = 'local'` keep their own binding even when
|
|
55
55
|
* `title` is also a prop name.
|
|
56
56
|
*
|
|
57
|
-
* Excluding
|
|
57
|
+
* Excluding the children prop (`isChildrenPropParam`, renamed or not):
|
|
58
|
+
* reading `_p.children` live re-invokes a getter that
|
|
58
59
|
* instantiates child components (see `emitPropsExtraction`) — `children`
|
|
59
60
|
* must stay a captured-once read, by design.
|
|
60
61
|
*
|
|
@@ -74,7 +75,7 @@ function rewriteParamDestructuredReads(
|
|
|
74
75
|
propUsage: ReadonlyMap<string, PropUsage>,
|
|
75
76
|
): string {
|
|
76
77
|
const names = new Set(boundPropLocalNames(ctx))
|
|
77
|
-
names.delete(
|
|
78
|
+
for (const p of ctx.propsParams) if (isChildrenPropParam(p)) names.delete(p.name)
|
|
78
79
|
if (names.size === 0) return code
|
|
79
80
|
|
|
80
81
|
const propsUsedAsConditions = computePropsUsedAsConditions(ctx, names)
|
|
@@ -102,16 +103,27 @@ function rewriteParamDestructuredReads(
|
|
|
102
103
|
return result
|
|
103
104
|
}
|
|
104
105
|
|
|
106
|
+
/**
|
|
107
|
+
* The `defaultParts` the analyzer recorded on a body-destructured local's
|
|
108
|
+
* props param (`ParamInfo.defaultParts`), when its default reads an earlier
|
|
109
|
+
* binding of the same pattern.
|
|
110
|
+
*/
|
|
111
|
+
function bodyAliasDefaultParts(ctx: ClientJsContext, local: string, key: string): Pick<LivePropReadInfo, 'defaultParts'> {
|
|
112
|
+
const param = ctx.propsParams.find(p => !p.isRest && p.name === local && (p.sourceName ?? p.name) === key)
|
|
113
|
+
return param?.defaultParts ? { defaultParts: param.defaultParts } : {}
|
|
114
|
+
}
|
|
115
|
+
|
|
105
116
|
/**
|
|
106
117
|
* Rewrite every bare value-position read of a BODY-destructured (or
|
|
107
118
|
* bare-member-alias) prop local in `code` to a live `_p.<key>` read, for a
|
|
108
119
|
* bare-props-form component (`function Foo(props: Props)`).
|
|
109
120
|
*
|
|
110
|
-
* `resolveBodyPropAliases`
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* the correct call, not a shortcut: BOTH are pure
|
|
114
|
-
* with no computation of their own, so both should
|
|
121
|
+
* `resolveBodyPropAliases` treats `const { value } = props` and `const value
|
|
122
|
+
* = props.value` alike (their `value` text is identical; only
|
|
123
|
+
* `ConstantInfo.propsDestructure` tells them apart, #3501), and so does this
|
|
124
|
+
* rewrite. That's the correct call, not a shortcut: BOTH are pure
|
|
125
|
+
* single-prop passthroughs with no computation of their own, so both should
|
|
126
|
+
* read live, matching
|
|
115
127
|
* `props.value` used directly (which already reads live via
|
|
116
128
|
* `rewritePropsObjectRef`).
|
|
117
129
|
*
|
|
@@ -149,7 +161,7 @@ function rewriteBodyAliasReads(code: string, ctx: ClientJsContext): string {
|
|
|
149
161
|
const sourceFile = ts.createSourceFile('init-body.ts', code, ts.ScriptTarget.Latest, /*setParentNodes*/ true, ts.ScriptKind.TS)
|
|
150
162
|
|
|
151
163
|
const spans: Array<readonly [number, number]> = []
|
|
152
|
-
const located = new Map<string, { key: string
|
|
164
|
+
const located = new Map<string, Pick<LivePropReadInfo, 'defaultValue' | 'defaultContainsArrow' | 'defaultParts'> & { key: string }>()
|
|
153
165
|
for (const stmt of sourceFile.statements) {
|
|
154
166
|
if (!ts.isFunctionDeclaration(stmt) || !stmt.name?.text.startsWith('init') || !stmt.body) continue
|
|
155
167
|
for (const inner of stmt.body.statements) {
|
|
@@ -180,6 +192,11 @@ function rewriteBodyAliasReads(code: string, ctx: ClientJsContext): string {
|
|
|
180
192
|
defaultContainsArrow: alias.defaultContainsArrow && !(
|
|
181
193
|
parsedInit.fallback && ts.isParenthesizedExpression(parsedInit.fallback)
|
|
182
194
|
),
|
|
195
|
+
// A default reading an earlier binding of the same destructure
|
|
196
|
+
// (`const { off = false, on = off } = props`, #3531): the analyzer
|
|
197
|
+
// split it on the binding's props param, and the earlier binding's
|
|
198
|
+
// declaration is gone from this body, so the read renders live.
|
|
199
|
+
...bodyAliasDefaultParts(ctx, decl.name.text, alias.key),
|
|
183
200
|
})
|
|
184
201
|
spans.push([inner.getFullStart(), inner.getEnd()])
|
|
185
202
|
}
|
|
@@ -204,6 +221,7 @@ function rewriteBodyAliasReads(code: string, ctx: ClientJsContext): string {
|
|
|
204
221
|
sourceName: info.key,
|
|
205
222
|
defaultValue: info.defaultValue,
|
|
206
223
|
defaultContainsArrow: info.defaultContainsArrow,
|
|
224
|
+
...(info.defaultParts && { defaultParts: info.defaultParts }),
|
|
207
225
|
}
|
|
208
226
|
return livePropReadExpr(prop, undefined, false)
|
|
209
227
|
}
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
39
|
import type { IRExpression } from '../types.ts'
|
|
40
|
-
import {
|
|
40
|
+
import { PROPS_PARAM } from './utils.ts'
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* A JS expression string that evaluates, in the client template, to HTML
|
|
@@ -110,6 +110,27 @@ export function childrenMarkup(expr: string): SafeHtml {
|
|
|
110
110
|
return safeHtml(`markupOrEmpty(${expr})`)
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
/**
|
|
114
|
+
* `_p.children == null ? escapeText(expr) : markupOrEmpty(_p.children)` — a
|
|
115
|
+
* read of the children prop with a text fallback: `children ?? 'x'`,
|
|
116
|
+
* `(children ?? '<b>x</b>') ?? ''` (`absentWhen: 'nullish'`), or
|
|
117
|
+
* `children || 'x'` (`absentWhen: 'falsy'`, tested as `!_p.children`); #3554.
|
|
118
|
+
* Phase 1 decided from the binding that the chain's head is the component's
|
|
119
|
+
* own `children` prop (`IRExpression.childrenRead`), so the head is read where
|
|
120
|
+
* every client template finds that prop, `_p.children` (the same place the
|
|
121
|
+
* Phase 1 `templateExpr` rewrite and the alias inlining resolve a destructured
|
|
122
|
+
* or aliased `children` to). Present children are the HTML string
|
|
123
|
+
* `materializeComponent` joined, spliced as `childrenMarkup` does; otherwise
|
|
124
|
+
* `expr` (the whole lowered chain) evaluates to its fallback, which is text
|
|
125
|
+
* and escaped. `expr` is not split: when the head is absent,
|
|
126
|
+
* `(c ?? x) ?? y` and `c ?? (x ?? y)` both evaluate to `x ?? y`.
|
|
127
|
+
*/
|
|
128
|
+
export function childrenMarkupOrEscapedFallback(expr: string, absentWhen: 'nullish' | 'falsy'): SafeHtml {
|
|
129
|
+
const children = `${PROPS_PARAM}.children`
|
|
130
|
+
const absent = absentWhen === 'nullish' ? `${children} == null` : `!${children}`
|
|
131
|
+
return safeHtml(`${absent} ? escapeText(${expr}) : markupOrEmpty(${children})`)
|
|
132
|
+
}
|
|
133
|
+
|
|
113
134
|
/**
|
|
114
135
|
* Stage 3 / D4 — an element-array child (`{out}`) built by an arbitrary
|
|
115
136
|
* `.map()` preamble is an array of compiled-leaf HTML strings; join it
|
|
@@ -179,37 +200,6 @@ export const EMPTY_MARKUP: SafeHtml = safeHtml("''")
|
|
|
179
200
|
// The door for a child-position expression node.
|
|
180
201
|
// ---------------------------------------------------------------------------
|
|
181
202
|
|
|
182
|
-
/**
|
|
183
|
-
* Recognizes a JSX child-position expression that is exactly a reference to
|
|
184
|
-
* the reserved `children` prop, optionally with `?? ''`: bare `children` (destructured) or
|
|
185
|
-
* `<receiver>.children` for any single-identifier receiver (`props.children`,
|
|
186
|
-
* a custom props-param name, a loop-scoped alias closing over props, ...).
|
|
187
|
-
*
|
|
188
|
-
* Deliberately LOOSER than `isTransparentFragment` (`jsx-to-ir.ts`), which
|
|
189
|
-
* runs on the TS AST with the analyzer-resolved props name in hand. This
|
|
190
|
-
* layer parses IR expressions without analyzer context, so any single-identifier receiver
|
|
191
|
-
* is the available approximation. The looseness costs nothing measurable: an
|
|
192
|
-
* unrelated `.children` member (a tree node's own `children` array, say) is a
|
|
193
|
-
* reactive member expression that gets a `slotId` and takes the slotted arm
|
|
194
|
-
* of `spliceChildValue` before this predicate is consulted.
|
|
195
|
-
*/
|
|
196
|
-
function isChildrenPassthroughExpr(expr: string): boolean {
|
|
197
|
-
return isChildrenPassthrough(parseExpression(expr))
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function isChildrenPassthrough(expr: ParsedExpr): boolean {
|
|
201
|
-
if (expr.kind === 'identifier') return expr.name === 'children'
|
|
202
|
-
if (expr.kind === 'member') {
|
|
203
|
-
return expr.object.kind === 'identifier' && expr.property === 'children'
|
|
204
|
-
&& !expr.computed && !expr.optional
|
|
205
|
-
}
|
|
206
|
-
// An empty fallback adds no untrusted text to the compiler-built markup.
|
|
207
|
-
// Other fallbacks still take the escape-by-default path.
|
|
208
|
-
return expr.kind === 'logical' && expr.op === '??'
|
|
209
|
-
&& expr.right.kind === 'literal' && expr.right.value === ''
|
|
210
|
-
&& isChildrenPassthrough(expr.left)
|
|
211
|
-
}
|
|
212
|
-
|
|
213
203
|
export interface ChildSpliceContext {
|
|
214
204
|
/**
|
|
215
205
|
* Set while emitting inside a conditional-branch `template()` arrow
|
|
@@ -241,7 +231,9 @@ export interface ChildSpliceContext {
|
|
|
241
231
|
* 3. `slotId` ∈ markupSlotIds → `escapedTextOrMarkup`
|
|
242
232
|
* 4. `slotId` → `escapedText`
|
|
243
233
|
* 5. `{children}` passthrough → `childrenMarkup` (bare splice only, #2775/#2786)
|
|
244
|
-
* 6.
|
|
234
|
+
* 6. `children ?? fallback`, → `childrenMarkupOrEscapedFallback` (#3554)
|
|
235
|
+
* `children || fallback`
|
|
236
|
+
* 7. otherwise → `escapedText`
|
|
245
237
|
*
|
|
246
238
|
* Arm 5 tests BOTH `node.expr` (the original source text, stable across
|
|
247
239
|
* builders) and the caller's resolved form (with parentheses handled structurally): a
|
|
@@ -250,7 +242,7 @@ export interface ChildSpliceContext {
|
|
|
250
242
|
* either alone misses one of the two shapes (#2786).
|
|
251
243
|
*/
|
|
252
244
|
export function spliceChildValue(
|
|
253
|
-
node: Pick<IRExpression, 'expr' | 'slotId' | 'joinArrayChild'>,
|
|
245
|
+
node: Pick<IRExpression, 'expr' | 'slotId' | 'joinArrayChild' | 'childrenRead'>,
|
|
254
246
|
valueExpr: string,
|
|
255
247
|
cx: ChildSpliceContext,
|
|
256
248
|
): SafeHtml {
|
|
@@ -259,8 +251,10 @@ export function spliceChildValue(
|
|
|
259
251
|
if (node.slotId) {
|
|
260
252
|
return cx.markupSlotIds?.has(node.slotId) ? escapedTextOrMarkup(valueExpr) : escapedText(valueExpr)
|
|
261
253
|
}
|
|
262
|
-
if (
|
|
254
|
+
if (node.childrenRead === 'bare' || node.childrenRead === 'nullish-empty') {
|
|
263
255
|
return childrenMarkup(valueExpr)
|
|
264
256
|
}
|
|
257
|
+
if (node.childrenRead === 'nullish-fallback') return childrenMarkupOrEscapedFallback(valueExpr, 'nullish')
|
|
258
|
+
if (node.childrenRead === 'or-fallback') return childrenMarkupOrEscapedFallback(valueExpr, 'falsy')
|
|
265
259
|
return escapedText(valueExpr)
|
|
266
260
|
}
|
|
@@ -125,7 +125,7 @@ function emitSignal(lines: string[], plan: SignalEmitPlan): void {
|
|
|
125
125
|
function emitControlledEffect(lines: string[], plan: ControlledSignalEffectPlan): void {
|
|
126
126
|
lines.push(` createEffect(() => {`)
|
|
127
127
|
lines.push(` const __val = ${plan.accessorExpr}`)
|
|
128
|
-
lines.push(` if (__val !== undefined) ${plan.setter}(__val)`)
|
|
128
|
+
lines.push(` if (__val !== undefined) ${plan.setter}(${plan.valueExpr ?? '__val'})`)
|
|
129
129
|
lines.push(` }${bfIdArg(plan.bfId)})`)
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -24,6 +24,7 @@ import type {
|
|
|
24
24
|
TypeDefinition,
|
|
25
25
|
MapCallbackPreamble,
|
|
26
26
|
PreambleRegionSource,
|
|
27
|
+
JsSourceText,
|
|
27
28
|
} from '../types.ts'
|
|
28
29
|
import type { CsrInlinabilityMap } from './csr-substitute.ts'
|
|
29
30
|
import type { SkeletonSlotPaths } from './html-template.ts'
|
|
@@ -197,7 +198,7 @@ export interface DynamicElement {
|
|
|
197
198
|
export interface ConditionalBranchEvent {
|
|
198
199
|
slotId: string
|
|
199
200
|
eventName: string
|
|
200
|
-
handler:
|
|
201
|
+
handler: JsSourceText
|
|
201
202
|
}
|
|
202
203
|
|
|
203
204
|
export interface ConditionalBranchRef {
|
|
@@ -528,7 +529,7 @@ export interface NestedLoop extends LoopCore {
|
|
|
528
529
|
export interface LoopChildEvent {
|
|
529
530
|
eventName: string // 'click', 'submit', etc.
|
|
530
531
|
childSlotId: string // bf slot ID of the element with the event
|
|
531
|
-
handler:
|
|
532
|
+
handler: JsSourceText // Handler expression (may reference loop param)
|
|
532
533
|
/** Nesting info for events inside nested inner loops. Empty = direct child. */
|
|
533
534
|
nestedLoops: NestedLoop[]
|
|
534
535
|
/** DOM nesting depth (0 = loop body root). Deepest-first sorting for event delegation (#774). */
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import ts from 'typescript'
|
|
7
|
-
import type { AttrValue, IRTemplatePart, LoopParamBinding, FreeReference, IRNode, IRFragment, ComponentIR } from '../types.ts'
|
|
7
|
+
import type { AttrValue, IRTemplatePart, LoopParamBinding, FreeReference, IRNode, IRFragment, ComponentIR, JsSourceText } from '../types.ts'
|
|
8
8
|
import type { TopLevelLoop, BranchLoop, LoopOffset } from './types.ts'
|
|
9
9
|
import { isNonReferenceIdentifierPosition } from '../analyzer.ts'
|
|
10
10
|
import { BindingScope, type LoopBindingSource } from '../scope/binding-scope.ts'
|
|
@@ -387,30 +387,6 @@ export function quotePropName(name: string): string {
|
|
|
387
387
|
// toHtmlAttrName is now re-exported from @barefootjs/shared (classifyDOMProp's
|
|
388
388
|
// toHTMLAttrName), keeping the same public name for downstream consumers.
|
|
389
389
|
|
|
390
|
-
/**
|
|
391
|
-
* Wrap arrow function handler in block to prevent accidental return false.
|
|
392
|
-
* Returning false from a DOM event handler prevents default behavior.
|
|
393
|
-
*
|
|
394
|
-
* Example:
|
|
395
|
-
* Input: (e) => e.key === 'Enter' && handleAdd()
|
|
396
|
-
* Output: (e) => { e.key === 'Enter' && handleAdd() }
|
|
397
|
-
*/
|
|
398
|
-
export function wrapHandlerInBlock(handler: string): string {
|
|
399
|
-
const trimmed = handler.trim()
|
|
400
|
-
|
|
401
|
-
if (trimmed.startsWith('(') && trimmed.includes('=>')) {
|
|
402
|
-
const arrowIndex = trimmed.indexOf('=>')
|
|
403
|
-
const params = trimmed.substring(0, arrowIndex + 2)
|
|
404
|
-
const body = trimmed.substring(arrowIndex + 2).trim()
|
|
405
|
-
|
|
406
|
-
if (!body.startsWith('{')) {
|
|
407
|
-
return `${params} { ${body} }`
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
return trimmed
|
|
412
|
-
}
|
|
413
|
-
|
|
414
390
|
/**
|
|
415
391
|
* Profile mode (#1690, SR3): wrap an event handler so a profiling run can
|
|
416
392
|
* attribute the reactive work it triggers to one turn. The original handler
|
|
@@ -424,7 +400,7 @@ export function wrapHandlerInBlock(handler: string): string {
|
|
|
424
400
|
* emitted while it runs. Used at every handler emit site in profile mode so
|
|
425
401
|
* no path is left unattributed.
|
|
426
402
|
*/
|
|
427
|
-
export function wrapHandlerForTurn(handler:
|
|
403
|
+
export function wrapHandlerForTurn(handler: JsSourceText, handlerId: string, loc?: string): string {
|
|
428
404
|
const idArg = loc ? `${JSON.stringify(handlerId)}, ${JSON.stringify(loc)}` : JSON.stringify(handlerId)
|
|
429
405
|
return `(...__bfa) => { beginTurn(${idArg}); try { return (${handler.trim()})(...__bfa) } finally { endTurn() } }`
|
|
430
406
|
}
|
|
@@ -469,6 +445,17 @@ export function emitRefCall(callback: string, elementVar: string, ssrPortalOwner
|
|
|
469
445
|
return `{ ${call}; if (__scopeId) ${elementVar}.setAttribute('${BF_PORTAL_OWNER}', __scopeId) }`
|
|
470
446
|
}
|
|
471
447
|
|
|
448
|
+
/**
|
|
449
|
+
* Whether a signal's initializer is a bare read of the props object
|
|
450
|
+
* (`props.X`, `props.row.count`) with no fallback of its own
|
|
451
|
+
* (`SignalInfo.propSeed`, #3508), the one shape both the init
|
|
452
|
+
* body and the CSR template give a type default (`?? <inferDefaultValue>`)
|
|
453
|
+
* so an omitted prop never seeds the signal with `undefined`.
|
|
454
|
+
*/
|
|
455
|
+
export function readsBareProp(signal: { propSeed?: { via: string; fallback: unknown } }): boolean {
|
|
456
|
+
return signal.propSeed?.via === 'member' && signal.propSeed.fallback === null
|
|
457
|
+
}
|
|
458
|
+
|
|
472
459
|
/** Infer a sensible JS default value literal from a type descriptor. */
|
|
473
460
|
export function inferDefaultValue(type: { kind: string; primitive?: string }): string {
|
|
474
461
|
if (type.kind === 'primitive') {
|