@barefootjs/jsx 0.37.1 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/action-accessor.d.ts +159 -0
- package/dist/action-accessor.d.ts.map +1 -0
- package/dist/adapters/env-signal.d.ts +0 -8
- package/dist/adapters/env-signal.d.ts.map +1 -1
- package/dist/adapters/interface.d.ts +12 -0
- package/dist/adapters/interface.d.ts.map +1 -1
- package/dist/adapters/jsx-adapter.d.ts.map +1 -1
- package/dist/analyzer.d.ts +61 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/async-action-refusal.d.ts +45 -0
- package/dist/async-action-refusal.d.ts.map +1 -0
- package/dist/builtin-lowering-plugins.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/component-root-scope-comment.d.ts +36 -0
- package/dist/component-root-scope-comment.d.ts.map +1 -0
- package/dist/debug.d.ts +61 -5
- package/dist/debug.d.ts.map +1 -1
- package/dist/errors.d.ts +7 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/event-handler-name.d.ts +13 -0
- package/dist/event-handler-name.d.ts.map +1 -0
- package/dist/expression-parser.d.ts +9 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/format-date-refusal.d.ts +33 -0
- package/dist/format-date-refusal.d.ts.map +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3260 -1914
- package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
- package/dist/ir-to-client-js/compute-scope.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-branch-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-composite-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/lazy-row-eligibility.d.ts +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +57 -12
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/shared.d.ts +44 -3
- package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts +7 -5
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
- package/dist/ir-to-client-js/declaration-sort.d.ts +2 -1
- package/dist/ir-to-client-js/declaration-sort.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-module-level.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts +43 -2
- package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts +7 -5
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
- package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts +9 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/source-map.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +4 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +66 -1
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/opaque-local-accessor.d.ts +27 -0
- package/dist/opaque-local-accessor.d.ts.map +1 -0
- package/dist/signal-initializer.d.ts +24 -0
- package/dist/signal-initializer.d.ts.map +1 -0
- package/dist/template-position-walk.d.ts +68 -0
- package/dist/template-position-walk.d.ts.map +1 -0
- package/dist/to-locale-date-lowering.d.ts +7 -4
- package/dist/to-locale-date-lowering.d.ts.map +1 -1
- package/dist/types.d.ts +104 -17
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +878 -4528
- package/src/__tests__/action-accessor.test.ts +166 -0
- package/src/__tests__/binding-scope-ratchet.test.ts +21 -10
- package/src/__tests__/branch-local-in-raw-capture.test.ts +1 -1
- package/src/__tests__/branch-local-same-name-collision.test.ts +9 -9
- package/src/__tests__/client-js-generation.test.ts +175 -0
- package/src/__tests__/component-root-scope-comment.test.ts +106 -0
- package/src/__tests__/create-mutation.test.ts +220 -0
- package/src/__tests__/create-query.test.ts +644 -0
- package/src/__tests__/csr-fragment-root-scope-shape.test.ts +156 -0
- package/src/__tests__/debug.test.ts +222 -0
- package/src/__tests__/doc-examples.test.ts +78 -25
- package/src/__tests__/event-handler-name.test.ts +74 -0
- package/src/__tests__/flatmap-segments.test.ts +11 -9
- package/src/__tests__/format-date-refusal.test.ts +134 -0
- package/src/__tests__/fragment-wrapped-conditional-return-branch.test.ts +132 -0
- package/src/__tests__/hydrate-template.test.ts +9 -1
- package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +2 -2
- package/src/__tests__/issue-3009-loop-branch-ref.test.ts +2 -2
- package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +213 -0
- package/src/__tests__/issue-3113-init-fn-name-collision.test.ts +133 -0
- package/src/__tests__/jsx-return-type-assertion.test.ts +2 -2
- package/src/__tests__/lazy-row-eligibility.test.ts +5 -4
- package/src/__tests__/loop-row-child-children-reactive-attrs.test.ts +108 -0
- package/src/__tests__/loop-row-child-text-children-markers.test.ts +158 -0
- package/src/__tests__/opaque-local-accessor.test.ts +90 -0
- package/src/__tests__/profiler-e2e.test.ts +13 -8
- package/src/__tests__/props-destructuring.test.ts +79 -4
- package/src/__tests__/reactive-factory-arity.test.ts +311 -0
- package/src/__tests__/ref-attr-absent-at-ssr.test.ts +472 -0
- package/src/__tests__/ssr-portal-ref-callback.test.ts +219 -0
- package/src/action-accessor.ts +289 -0
- package/src/adapters/env-signal.ts +2 -21
- package/src/adapters/interface.ts +13 -0
- package/src/adapters/jsx-adapter.ts +17 -0
- package/src/analyzer.ts +589 -60
- package/src/async-action-refusal.ts +254 -0
- package/src/builtin-lowering-plugins.ts +0 -2
- package/src/compiler.ts +27 -0
- package/src/component-root-scope-comment.ts +59 -0
- package/src/debug.ts +318 -103
- package/src/errors.ts +83 -1
- package/src/event-handler-name.ts +14 -0
- package/src/expression-parser.ts +41 -17
- package/src/format-date-refusal.ts +147 -0
- package/src/index.ts +14 -3
- package/src/ir-to-client-js/build-references.ts +6 -2
- package/src/ir-to-client-js/child-components.ts +8 -3
- package/src/ir-to-client-js/collect-elements.ts +28 -13
- package/src/ir-to-client-js/compute-inlinability.ts +2 -1
- package/src/ir-to-client-js/compute-scope.ts +3 -1
- package/src/ir-to-client-js/control-flow/plan/build-branch-loop.ts +2 -4
- package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +67 -5
- package/src/ir-to-client-js/control-flow/plan/build-composite-loop.ts +3 -6
- package/src/ir-to-client-js/control-flow/plan/build-insert.ts +1 -0
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +2 -1
- package/src/ir-to-client-js/control-flow/plan/build-loop.ts +23 -11
- package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -0
- package/src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts +3 -3
- package/src/ir-to-client-js/control-flow/plan/loop.ts +51 -10
- package/src/ir-to-client-js/control-flow/shared.ts +78 -5
- package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +25 -12
- package/src/ir-to-client-js/control-flow/stringify/insert.ts +1 -1
- package/src/ir-to-client-js/csr-substitute.ts +11 -3
- package/src/ir-to-client-js/declaration-sort.ts +7 -3
- package/src/ir-to-client-js/emit-module-level.ts +7 -4
- package/src/ir-to-client-js/emit-reactive.ts +140 -10
- package/src/ir-to-client-js/emit-registration.ts +6 -11
- package/src/ir-to-client-js/generate-init.ts +2 -2
- package/src/ir-to-client-js/html-template.ts +41 -19
- package/src/ir-to-client-js/index.ts +9 -3
- package/src/ir-to-client-js/phases/ref-callbacks.ts +1 -1
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +16 -15
- package/src/ir-to-client-js/plan/declaration-emit.ts +7 -5
- package/src/ir-to-client-js/prop-handling.ts +4 -0
- package/src/ir-to-client-js/reactivity.ts +21 -16
- package/src/ir-to-client-js/source-map.ts +2 -1
- package/src/ir-to-client-js/stringify/declaration-emit.ts +14 -7
- package/src/ir-to-client-js/types.ts +4 -0
- package/src/ir-to-client-js/utils.ts +89 -7
- package/src/jsx-to-ir.ts +772 -50
- package/src/opaque-local-accessor.ts +44 -0
- package/src/rich-type-refusal.ts +1 -1
- package/src/signal-initializer.ts +36 -0
- package/src/template-position-walk.ts +203 -0
- package/src/to-locale-date-lowering.ts +7 -4
- package/src/types.ts +103 -15
- package/dist/format-date-lowering.d.ts +0 -30
- package/dist/format-date-lowering.d.ts.map +0 -1
- package/src/__tests__/create-selector.test.ts +0 -124
- package/src/__tests__/format-date-lowering.test.ts +0 -125
- package/src/format-date-lowering.ts +0 -55
package/src/errors.ts
CHANGED
|
@@ -35,7 +35,7 @@ export const ErrorCodes = {
|
|
|
35
35
|
// JSX errors (BF021-BF029). BF022 was retired (see
|
|
36
36
|
// `invalid-jsx-attribute.audit.test.ts`) and BF026 is reserved by
|
|
37
37
|
// `spec/callback-fidelity.md` for a future `.map()`-callback-shape
|
|
38
|
-
// diagnostic —
|
|
38
|
+
// diagnostic — BF029 is the next free slot.
|
|
39
39
|
UNSUPPORTED_JSX_PATTERN: 'BF021',
|
|
40
40
|
MISSING_KEY_IN_LIST: 'BF023',
|
|
41
41
|
MISSING_KEY_IN_NESTED_LIST: 'BF024',
|
|
@@ -50,6 +50,20 @@ export const ErrorCodes = {
|
|
|
50
50
|
// no IR and no diagnostic (#2720). Loud stopgap until the analyzer learns
|
|
51
51
|
// to resolve the identifier at return position too.
|
|
52
52
|
RETURN_VALUE_NOT_JSX: 'BF027',
|
|
53
|
+
// #3063: a `'use client'` (or otherwise client-interactive) component
|
|
54
|
+
// whose multi-return `if`/`else` chain has at least one branch wrapped in
|
|
55
|
+
// a bare JSX fragment (`return <>…</>`, no wrapping element). The
|
|
56
|
+
// `ComponentDef`'s `comment: true` / `fragmentRoot: true` client-JS flags
|
|
57
|
+
// (`emit-registration.ts`) are decided ONCE per component from
|
|
58
|
+
// `ir.root.type`, which is always `'if-statement'` here regardless of any
|
|
59
|
+
// individual branch's shape — so the client hydration claim
|
|
60
|
+
// (`materializeComponent`, `packages/client/src/runtime/component.ts`)
|
|
61
|
+
// never learns to look for that branch's comment-scope boundary. SSR and
|
|
62
|
+
// a fresh CSR mount both render the branch correctly; only claiming
|
|
63
|
+
// existing SSR markup during hydration misses it (no `bf-s`, so the
|
|
64
|
+
// branch's own events never bind). See
|
|
65
|
+
// `packages/adapter-tests/limitations/fragment-wrapped-conditional-return-branch-scope.ts`.
|
|
66
|
+
FRAGMENT_WRAPPED_CONDITIONAL_RETURN_BRANCH: 'BF029',
|
|
53
67
|
|
|
54
68
|
// Component errors (BF043-BF049). BF043 is retired (it warned that props
|
|
55
69
|
// destructuring broke reactivity, which it no longer does) and is the next
|
|
@@ -105,6 +119,14 @@ export const ErrorCodes = {
|
|
|
105
119
|
// dangling reference (#2432).
|
|
106
120
|
INLINED_IMPORT_MISSING_EXPORT: 'BF055',
|
|
107
121
|
|
|
122
|
+
// `@barefootjs/client`'s `formatDate` called directly by name in a
|
|
123
|
+
// template-lowered position (#3089). `formatDate` is compiler ABI — the
|
|
124
|
+
// lowering TARGET of the `.toLocaleDateString()` sugar, emitted by the
|
|
125
|
+
// compiler itself — never an authored API, so this is a POLICY refusal
|
|
126
|
+
// (not a per-adapter capability gap) and fires identically on every
|
|
127
|
+
// adapter including Hono. See `format-date-refusal.ts`.
|
|
128
|
+
FORMAT_DATE_AUTHORED_CALL: 'BF056',
|
|
129
|
+
|
|
108
130
|
// Init statement errors (BF052)
|
|
109
131
|
UNDECLARED_INIT_STATEMENT_REFERENCE: 'BF052',
|
|
110
132
|
|
|
@@ -130,6 +152,19 @@ export const ErrorCodes = {
|
|
|
130
152
|
STAGE_REACTIVE_IN_TEMPLATE: 'BF060',
|
|
131
153
|
STAGE_INIT_LOCAL_IN_TEMPLATE: 'BF061',
|
|
132
154
|
STAGE_AWAIT_IN_TEMPLATE: 'BF062',
|
|
155
|
+
// An element's `ref` callback unconditionally writes an attribute
|
|
156
|
+
// (`el.setAttribute('<name>', …)` / `el.dataset.<x> = …`) at mount —
|
|
157
|
+
// directly, or at the top level of a directly nested `createEffect` /
|
|
158
|
+
// `onMount` — that the element's own JSX never renders. A `ref` callback
|
|
159
|
+
// never runs at SSR, so the server HTML always lacks the attribute and
|
|
160
|
+
// the first client pass adds it: pre- and post-hydration DOM differ (a
|
|
161
|
+
// visible snap). Narrowed to that decidable, always-divergent shape: an
|
|
162
|
+
// attribute the JSX DOES render (e.g. a `data-state="closed"` literal an
|
|
163
|
+
// effect later overwrites) is out of scope, since the literal is often
|
|
164
|
+
// exactly the value the effect computes on its first run. Escapable with
|
|
165
|
+
// `/* @client */` before the ref expression. See
|
|
166
|
+
// `packages/adapter-tests/limitations/ref-effect-attr-state-ssr.ts`.
|
|
167
|
+
REF_ATTR_ABSENT_AT_SSR: 'BF063',
|
|
133
168
|
|
|
134
169
|
// Inline JSX-callback synthesis errors (BF080-BF089) — raised by the
|
|
135
170
|
// preprocess-inline-jsx-callbacks pass (#1211) when an inline JSX-
|
|
@@ -143,6 +178,27 @@ export const ErrorCodes = {
|
|
|
143
178
|
REACTIVE_FACTORY_MODULE_CAPTURE: 'BF112',
|
|
144
179
|
REACTIVE_FACTORY_IMPORT_COLLISION: 'BF113',
|
|
145
180
|
REACTIVE_FACTORY_PARAM_SHADOWED: 'BF114',
|
|
181
|
+
// A tuple destructure of `createSignal`/`createMemo` whose element count
|
|
182
|
+
// the factory doesn't return (#3159). Before this code existed, an
|
|
183
|
+
// over-arity destructure (`const [a, b, c] = createSignal(...)`) silently
|
|
184
|
+
// dropped the WHOLE declaration from the compiled output — every
|
|
185
|
+
// reference then fell through to an unrelated same-name prop accessor if
|
|
186
|
+
// one happened to exist, or threw ReferenceError at hydrate if not.
|
|
187
|
+
REACTIVE_FACTORY_ARITY_MISMATCH: 'BF115',
|
|
188
|
+
// An authored `createSignal`/`createMemo` call with more arguments than
|
|
189
|
+
// the primitive accepts (#3159). Before this code existed, the extra
|
|
190
|
+
// argument(s) were silently dropped from the emitted client JS.
|
|
191
|
+
REACTIVE_FACTORY_EXTRA_ARGUMENTS: 'BF116',
|
|
192
|
+
// An async action's accessors (`action.isPending()` / `action.error()`, from
|
|
193
|
+
// `createQuery` or `createMutation`), or the action itself, read in a
|
|
194
|
+
// template-lowered position where their seed would not render like Hono
|
|
195
|
+
// (#3165; #3166 seeds the positions where it does). Refused on every
|
|
196
|
+
// adapter including Hono. See `async-action-refusal.ts`.
|
|
197
|
+
ASYNC_ACTION_READ_IN_TEMPLATE: 'BF117',
|
|
198
|
+
// An `initial` option passed to `createMutation` (#3210). A mutation has no
|
|
199
|
+
// initial request to seed from (spec/async.md §7.4): its value is
|
|
200
|
+
// `undefined` until the action is called, and the runtime ignores the key.
|
|
201
|
+
MUTATION_INITIAL_OPTION: 'BF118',
|
|
146
202
|
} as const
|
|
147
203
|
|
|
148
204
|
export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes]
|
|
@@ -182,6 +238,9 @@ const errorMessages: Record<ErrorCode, string> = {
|
|
|
182
238
|
[ErrorCodes.RETURN_VALUE_NOT_JSX]:
|
|
183
239
|
"Component's return value is not recognized as JSX — return the JSX expression directly instead of binding it to a local variable first.",
|
|
184
240
|
|
|
241
|
+
[ErrorCodes.FRAGMENT_WRAPPED_CONDITIONAL_RETURN_BRANCH]:
|
|
242
|
+
'A fragment-wrapped branch of a multi-return client component is never hydrated: the client only decides once per component whether its root scope is comment-based, so this branch renders correctly at SSR and on a fresh client mount, but its events never bind after hydrating existing server HTML. Wrap this branch\'s JSX in a real element instead of a bare fragment (`<>…</>` → `<div>…</div>`), or add /* @client */ immediately before the fragment to compile it anyway and accept the known hydration gap.',
|
|
243
|
+
|
|
185
244
|
[ErrorCodes.SIGNAL_GETTER_NOT_CALLED]:
|
|
186
245
|
'Signal/memo getter passed without calling it. Use getter() to read the value.',
|
|
187
246
|
[ErrorCodes.JSX_IN_LOCAL_FUNCTION]:
|
|
@@ -211,6 +270,9 @@ const errorMessages: Record<ErrorCode, string> = {
|
|
|
211
270
|
[ErrorCodes.WRONG_PACKAGE_IMPORT]:
|
|
212
271
|
'Import from wrong package.',
|
|
213
272
|
|
|
273
|
+
[ErrorCodes.FORMAT_DATE_AUTHORED_CALL]:
|
|
274
|
+
'formatDate cannot be called directly — it is compiler ABI, not an authored API.',
|
|
275
|
+
|
|
214
276
|
[ErrorCodes.BUILTIN_REQUIRES_IMPORT]:
|
|
215
277
|
"Built-in <Async> / <Region> must be imported from '@barefootjs/client'. " +
|
|
216
278
|
'The compiler recognises these tags by their import (not by tag name), ' +
|
|
@@ -233,6 +295,8 @@ const errorMessages: Record<ErrorCode, string> = {
|
|
|
233
295
|
|
|
234
296
|
[ErrorCodes.STAGE_AWAIT_IN_TEMPLATE]:
|
|
235
297
|
'AwaitExpression in template scope. The generated template and init functions are synchronous — a bare `await` produces a SyntaxError at parse time. Move the await into the component body (before the return) or into an onMount/effect callback, and pass the resolved value to JSX.',
|
|
298
|
+
[ErrorCodes.REF_ATTR_ABSENT_AT_SSR]:
|
|
299
|
+
'A ref callback writes an attribute on mount that the element\'s JSX never renders. A ref callback never runs at SSR, so the server HTML lacks the attribute and hydration adds it — the DOM visibly changes at the hydrate boundary.',
|
|
236
300
|
|
|
237
301
|
[ErrorCodes.INLINE_JSX_CALLBACK_CAPTURE]:
|
|
238
302
|
"Inline JSX-returning arrow function captures a non-module identifier. Extract the callback into a top-level 'use client' component (e.g. `function MyNode(n) { return <div/> }` then `renderNode={MyNode}`) or pass captured values via component props.",
|
|
@@ -258,6 +322,24 @@ const errorMessages: Record<ErrorCode, string> = {
|
|
|
258
322
|
|
|
259
323
|
[ErrorCodes.REACTIVE_FACTORY_PARAM_SHADOWED]:
|
|
260
324
|
'Reactive factory parameter is shadowed by a nested declaration inside the factory body, so argument substitution at the inline site would be ambiguous. Rename the inner binding so it does not collide with the parameter.',
|
|
325
|
+
|
|
326
|
+
[ErrorCodes.REACTIVE_FACTORY_ARITY_MISMATCH]:
|
|
327
|
+
"Tuple destructure of 'createSignal'/'createMemo' does not match the number of " +
|
|
328
|
+
'elements the factory returns. `createSignal` returns `[getter, setter]` (destructure ' +
|
|
329
|
+
'1 or 2 elements); `createMemo` returns a single getter (do not destructure it as an ' +
|
|
330
|
+
'array at all).',
|
|
331
|
+
|
|
332
|
+
[ErrorCodes.REACTIVE_FACTORY_EXTRA_ARGUMENTS]:
|
|
333
|
+
"'createSignal'/'createMemo' call passes more arguments than the primitive accepts " +
|
|
334
|
+
'(`createSignal(initialValue?)`, `createMemo(computeFn)`, `createSearchParams()`). The extra argument(s) are ' +
|
|
335
|
+
'silently dropped from the compiled client JS.',
|
|
336
|
+
|
|
337
|
+
[ErrorCodes.ASYNC_ACTION_READ_IN_TEMPLATE]:
|
|
338
|
+
"An async action's accessors (`isPending()` / `error()`) cannot be read in this template position — " +
|
|
339
|
+
'the request function never runs on the server, so there is no value to render.',
|
|
340
|
+
[ErrorCodes.MUTATION_INITIAL_OPTION]:
|
|
341
|
+
'`createMutation` takes no `initial` option — a mutation has no initial request to seed its value from. ' +
|
|
342
|
+
'Use `createQuery` for a value that needs an initial state.',
|
|
261
343
|
}
|
|
262
344
|
|
|
263
345
|
// =============================================================================
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a JSX attribute / component-prop name is an event handler
|
|
3
|
+
* (`onClick`, `onValueChange`, ...) rather than a plain attribute or data
|
|
4
|
+
* prop: `on` followed by an uppercase letter. `on`, `only`, `once`, `online`
|
|
5
|
+
* are ordinary names.
|
|
6
|
+
*
|
|
7
|
+
* The one decision every site shares: native-element attribute extraction
|
|
8
|
+
* (routes into `IREvent`, never rendered HTML), the `isEventHandler` flag on
|
|
9
|
+
* loop child-component props, client-JS prop wiring, and the SSR adapters'
|
|
10
|
+
* "handler has no SSR value" skips.
|
|
11
|
+
*/
|
|
12
|
+
export function isEventHandlerName(name: string): boolean {
|
|
13
|
+
return /^on[A-Z]/.test(name)
|
|
14
|
+
}
|
package/src/expression-parser.ts
CHANGED
|
@@ -600,6 +600,46 @@ export type ProviderObjectMember =
|
|
|
600
600
|
| { name: string; kind: 'function' }
|
|
601
601
|
| { name: string; kind: 'expression'; expr: string }
|
|
602
602
|
|
|
603
|
+
/**
|
|
604
|
+
* Whether an expression node is function-shaped: an arrow / function
|
|
605
|
+
* expression, or a `??` / `||` fallback chain with one as an operand
|
|
606
|
+
* (`props.onX ?? (() => {})` is function-typed whichever side wins).
|
|
607
|
+
*/
|
|
608
|
+
function isFunctionShapedNode(e: ts.Expression): boolean {
|
|
609
|
+
let v: ts.Expression = e
|
|
610
|
+
while (ts.isParenthesizedExpression(v)) v = v.expression
|
|
611
|
+
if (ts.isArrowFunction(v) || ts.isFunctionExpression(v)) return true
|
|
612
|
+
if (
|
|
613
|
+
ts.isBinaryExpression(v) &&
|
|
614
|
+
(v.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken ||
|
|
615
|
+
v.operatorToken.kind === ts.SyntaxKind.BarBarToken)
|
|
616
|
+
) {
|
|
617
|
+
return isFunctionShapedNode(v.left) || isFunctionShapedNode(v.right)
|
|
618
|
+
}
|
|
619
|
+
return false
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Whether `source` is a function-shaped expression — behavior, not data, so
|
|
624
|
+
* SSR never has a value for it (the same classification
|
|
625
|
+
* `parseProviderObjectLiteral` gives a provider member's `function` kind).
|
|
626
|
+
* Covers the block-bodied arrows `parseExpression` leaves `unsupported`
|
|
627
|
+
* (`(el) => { el.focus() }`). Parses `source`, so callers reach for it off
|
|
628
|
+
* the hot path only (e.g. before refusing a value they could not lower).
|
|
629
|
+
*/
|
|
630
|
+
export function isFunctionShapedExpression(source: string): boolean {
|
|
631
|
+
const sf = ts.createSourceFile(
|
|
632
|
+
'__fn__.tsx',
|
|
633
|
+
`(${source})`,
|
|
634
|
+
ts.ScriptTarget.Latest,
|
|
635
|
+
/* setParentNodes */ true,
|
|
636
|
+
ts.ScriptKind.TSX,
|
|
637
|
+
)
|
|
638
|
+
const stmt = sf.statements[0]
|
|
639
|
+
if (sf.statements.length !== 1 || !stmt || !ts.isExpressionStatement(stmt)) return false
|
|
640
|
+
return isFunctionShapedNode(stmt.expression)
|
|
641
|
+
}
|
|
642
|
+
|
|
603
643
|
/**
|
|
604
644
|
* Structurally parse a `<Ctx.Provider value={{ … }}>` object literal into
|
|
605
645
|
* per-member SSR lowering classifications (see `ProviderObjectMember`).
|
|
@@ -625,22 +665,6 @@ export function parseProviderObjectLiteral(source: string): ProviderObjectMember
|
|
|
625
665
|
while (init && ts.isParenthesizedExpression(init)) init = init.expression
|
|
626
666
|
if (!init || !ts.isObjectLiteralExpression(init)) return null
|
|
627
667
|
|
|
628
|
-
const isFunctionShaped = (e: ts.Expression): boolean => {
|
|
629
|
-
let v: ts.Expression = e
|
|
630
|
-
while (ts.isParenthesizedExpression(v)) v = v.expression
|
|
631
|
-
if (ts.isArrowFunction(v) || ts.isFunctionExpression(v)) return true
|
|
632
|
-
// `props.onX ?? (() => {})` — a fallback chain with a function operand
|
|
633
|
-
// is function-typed regardless of which side wins at runtime.
|
|
634
|
-
if (
|
|
635
|
-
ts.isBinaryExpression(v) &&
|
|
636
|
-
(v.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken ||
|
|
637
|
-
v.operatorToken.kind === ts.SyntaxKind.BarBarToken)
|
|
638
|
-
) {
|
|
639
|
-
return isFunctionShaped(v.left) || isFunctionShaped(v.right)
|
|
640
|
-
}
|
|
641
|
-
return false
|
|
642
|
-
}
|
|
643
|
-
|
|
644
668
|
const members: ProviderObjectMember[] = []
|
|
645
669
|
for (const prop of init.properties) {
|
|
646
670
|
if (ts.isShorthandPropertyAssignment(prop)) {
|
|
@@ -668,7 +692,7 @@ export function parseProviderObjectLiteral(source: string): ProviderObjectMember
|
|
|
668
692
|
members.push({ name, kind: 'getter', body: v.body.getText(sf).trim() })
|
|
669
693
|
continue
|
|
670
694
|
}
|
|
671
|
-
if (
|
|
695
|
+
if (isFunctionShapedNode(v)) {
|
|
672
696
|
members.push({ name, kind: 'function' })
|
|
673
697
|
continue
|
|
674
698
|
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `checkAuthoredFormatDateCalls` (#3089, BF056): a direct call to
|
|
3
|
+
* `formatDate` imported from `@barefootjs/client` (or its `/runtime`
|
|
4
|
+
* subpath) in a template-lowered position is refused at compile time,
|
|
5
|
+
* uniformly across every adapter including Hono.
|
|
6
|
+
*
|
|
7
|
+
* This is a POLICY decision, not a template-language capability gap:
|
|
8
|
+
* `formatDate` is compiler ABI — the lowering TARGET the `.toLocaleDateString()`
|
|
9
|
+
* sugar rewrites to (`to-locale-date-lowering.ts`), emitted by the compiler
|
|
10
|
+
* itself into generated client JS and every adapter's native `format_date`
|
|
11
|
+
* helper (`spec/template-helpers.md`) — never an authored API. So this check
|
|
12
|
+
* fires ahead of `adapter.generate()` in the shared IR-build phase and is
|
|
13
|
+
* pinned identically on all nine adapters, the same "every backend, no
|
|
14
|
+
* exceptions" shape `checkRichTypePropSerialization` (BF049,
|
|
15
|
+
* `rich-type-refusal.ts`) uses for a hydration-transport gap that is equally
|
|
16
|
+
* universal on Hono's JS-runtime leg as on the 8 template-language adapters'
|
|
17
|
+
* leg.
|
|
18
|
+
*
|
|
19
|
+
* A `/* @client *\/`-escaped position is skipped — deferring the whole read
|
|
20
|
+
* to the client means real JS evaluates it there, and the still-exported
|
|
21
|
+
* (now `@internal`) runtime function works fine as ordinary client code.
|
|
22
|
+
*
|
|
23
|
+
* Deliberately a SEPARATE walk from `checkRichTypeMethodCalls`
|
|
24
|
+
* (`rich-type-refusal.ts`), which answers a different question (does a
|
|
25
|
+
* METHOD CALL on a host-rich-typed receiver have a catalogued lowering) and
|
|
26
|
+
* short-circuits when the component has no `propsType` — a `formatDate`
|
|
27
|
+
* call needs no receiver type at all and can appear in a props-free
|
|
28
|
+
* component, so it cannot share that early return. The positions come from
|
|
29
|
+
* `walkTemplatePositions` (`template-position-walk.ts`), which BF117 shares.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import type {
|
|
33
|
+
IRNode,
|
|
34
|
+
IRMetadata,
|
|
35
|
+
CompilerError,
|
|
36
|
+
SourceLocation,
|
|
37
|
+
} from './types.ts'
|
|
38
|
+
import type { ParsedExpr } from './expression-parser.ts'
|
|
39
|
+
import { ErrorCodes } from './errors.ts'
|
|
40
|
+
import { walkTemplatePositions } from './template-position-walk.ts'
|
|
41
|
+
|
|
42
|
+
/** Entries that re-export the pure client `formatDate` helper (#2324). */
|
|
43
|
+
const FORMAT_DATE_SOURCES: ReadonlySet<string> = new Set([
|
|
44
|
+
'@barefootjs/client',
|
|
45
|
+
'@barefootjs/client/runtime',
|
|
46
|
+
])
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The local binding name(s) `formatDate` is imported under in this
|
|
50
|
+
* component — matched by exported name, gated on the LOCAL alias, accepted
|
|
51
|
+
* from both the main entry and the runtime re-export. Mirrors the shape of
|
|
52
|
+
* the removed `formatDateLocalNames` (`adapters/env-signal.ts`), rebuilt
|
|
53
|
+
* here since this is now the only consumer of that resolution.
|
|
54
|
+
*/
|
|
55
|
+
function collectFormatDateBoundNames(metadata: IRMetadata): Set<string> {
|
|
56
|
+
const names = new Set<string>()
|
|
57
|
+
for (const imp of metadata.imports) {
|
|
58
|
+
if (!FORMAT_DATE_SOURCES.has(imp.source) || imp.isTypeOnly) continue
|
|
59
|
+
for (const s of imp.specifiers) {
|
|
60
|
+
if (s.isTypeOnly || s.isNamespace || s.isDefault) continue
|
|
61
|
+
if (s.name === 'formatDate') names.add(s.alias ?? s.name)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return names
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function checkAuthoredFormatDateCalls(root: IRNode, metadata: IRMetadata, errors: CompilerError[]): void {
|
|
68
|
+
const names = collectFormatDateBoundNames(metadata)
|
|
69
|
+
if (names.size === 0) return
|
|
70
|
+
const seen = new Set<string>()
|
|
71
|
+
walkTemplatePositions(root, ({ expr, loc }) => {
|
|
72
|
+
if (exprCallsName(expr, names)) pushDiagnostic(errors, seen, loc, anyName(names))
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function pushDiagnostic(errors: CompilerError[], seen: Set<string>, loc: SourceLocation, name: string): void {
|
|
77
|
+
const key = `${loc.start.line}:${loc.start.column}`
|
|
78
|
+
if (seen.has(key)) return
|
|
79
|
+
seen.add(key)
|
|
80
|
+
errors.push({
|
|
81
|
+
code: ErrorCodes.FORMAT_DATE_AUTHORED_CALL,
|
|
82
|
+
severity: 'error',
|
|
83
|
+
message:
|
|
84
|
+
`'${name}(...)' cannot be called directly — formatDate is compiler ABI (the lowering target of the ` +
|
|
85
|
+
`.toLocaleDateString() sugar), not an authored API.`,
|
|
86
|
+
loc,
|
|
87
|
+
suggestion: {
|
|
88
|
+
message:
|
|
89
|
+
"Use date.toLocaleDateString(locale, { timeZone, ... }) with a literal locale and an explicit literal " +
|
|
90
|
+
"timeZone (a canonical IANA zone ID, a fixed '±HH:MM' offset, or 'UTC') so it compiles to the format_date " +
|
|
91
|
+
'helper, or defer the whole read to the client with /* @client */ — it runs as real JS in the browser, so ' +
|
|
92
|
+
'it can call any date-formatting API you like, including this one.',
|
|
93
|
+
escape: [{ kind: 'client-directive' }],
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Does `expr`'s tree contain a call whose callee is one of `names`? Mirrors `checkExpr`'s tree coverage (rich-type-refusal.ts). */
|
|
99
|
+
function exprCallsName(expr: ParsedExpr, names: ReadonlySet<string>): boolean {
|
|
100
|
+
switch (expr.kind) {
|
|
101
|
+
case 'call':
|
|
102
|
+
if (expr.callee.kind === 'identifier' && names.has(expr.callee.name)) return true
|
|
103
|
+
if (exprCallsName(expr.callee, names)) return true
|
|
104
|
+
return expr.args.some((a) => exprCallsName(a, names))
|
|
105
|
+
case 'member':
|
|
106
|
+
return exprCallsName(expr.object, names)
|
|
107
|
+
case 'index-access':
|
|
108
|
+
return exprCallsName(expr.object, names) || exprCallsName(expr.index, names)
|
|
109
|
+
case 'binary':
|
|
110
|
+
return exprCallsName(expr.left, names) || exprCallsName(expr.right, names)
|
|
111
|
+
case 'unary':
|
|
112
|
+
return exprCallsName(expr.argument, names)
|
|
113
|
+
case 'conditional':
|
|
114
|
+
return (
|
|
115
|
+
exprCallsName(expr.test, names) ||
|
|
116
|
+
exprCallsName(expr.consequent, names) ||
|
|
117
|
+
exprCallsName(expr.alternate, names)
|
|
118
|
+
)
|
|
119
|
+
case 'logical':
|
|
120
|
+
return exprCallsName(expr.left, names) || exprCallsName(expr.right, names)
|
|
121
|
+
case 'template-literal':
|
|
122
|
+
return expr.parts.some((p) => p.type === 'expression' && exprCallsName(p.expr, names))
|
|
123
|
+
case 'arrow':
|
|
124
|
+
return exprCallsName(expr.body, names)
|
|
125
|
+
case 'array-literal':
|
|
126
|
+
return expr.elements.some((e) => exprCallsName(e, names))
|
|
127
|
+
case 'object-literal':
|
|
128
|
+
return expr.properties.some((p) => exprCallsName(p.kind === 'spread' ? p.expr : p.value, names))
|
|
129
|
+
case 'array-method': {
|
|
130
|
+
if (exprCallsName(expr.object, names)) return true
|
|
131
|
+
if (expr.args.some((a) => exprCallsName(a, names))) return true
|
|
132
|
+
if (expr.method === 'flat' && expr.depthExpr) return exprCallsName(expr.depthExpr, names)
|
|
133
|
+
return false
|
|
134
|
+
}
|
|
135
|
+
case 'identifier':
|
|
136
|
+
case 'literal':
|
|
137
|
+
case 'regex':
|
|
138
|
+
case 'unsupported':
|
|
139
|
+
return false
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** First bound name, for the diagnostic message — the exact alias matters far less than firing at all. */
|
|
144
|
+
function anyName(names: ReadonlySet<string>): string {
|
|
145
|
+
for (const n of names) return n
|
|
146
|
+
return 'formatDate'
|
|
147
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,16 @@ export type { CompileResult, CompileOptions, CompileOptionsWithAdapter, FileOutp
|
|
|
11
11
|
// SSR template-variable defaults (manifest seeds for stash-based adapters)
|
|
12
12
|
export { extractSsrDefaults, deriveStashFromDefaults } from './ssr-defaults.ts'
|
|
13
13
|
|
|
14
|
+
// #3144: shared "is this a component-body local bound to an opaque call"
|
|
15
|
+
// check, consulted by every non-JS-runtime adapter's `call()` fallback
|
|
16
|
+
// before it treats a zero-arg identifier call as a signal getter.
|
|
17
|
+
export { isOpaqueLocalAccessorName } from './opaque-local-accessor.ts'
|
|
18
|
+
|
|
19
|
+
// The one event-handler-name classification (`on[A-Z]`) — `only`/`once` are
|
|
20
|
+
// data props, not handlers. Shared by the IR builder, client-JS prop wiring
|
|
21
|
+
// and the SSR adapters' "a handler has no SSR value" skips.
|
|
22
|
+
export { isEventHandlerName } from './event-handler-name.ts'
|
|
23
|
+
|
|
14
24
|
// Shared props-destructure binding + alias-map helpers (#2524, #2788)
|
|
15
25
|
export { propsDestructureBinding, buildPropAliasMap, isIdentifierName, resolveBodyDestructuredPropAliases } from './props-binding.ts'
|
|
16
26
|
export type { SsrDefault } from './ssr-defaults.ts'
|
|
@@ -79,7 +89,7 @@ export type {
|
|
|
79
89
|
} from './types.ts'
|
|
80
90
|
|
|
81
91
|
// Analyzer
|
|
82
|
-
export { analyzeComponent, listComponentFunctions, listComponentFunctions as listExportedComponents, scanComponentFile, createProgramForFile, needsTypeBasedDetection, resolveRelativeImportToFile, REACTIVE_PRIMITIVES, BROWSER_ONLY_CLIENT_APIS, type AnalyzerContext, type ComponentFileScan } from './analyzer.ts'
|
|
92
|
+
export { analyzeComponent, listComponentFunctions, listComponentFunctions as listExportedComponents, scanComponentFile, createProgramForFile, createAnchoredProgram, needsTypeBasedDetection, resolveRelativeImportToFile, REACTIVE_PRIMITIVES, BROWSER_ONLY_CLIENT_APIS, type AnalyzerContext, type ComponentFileScan } from './analyzer.ts'
|
|
83
93
|
export { createProgramForCorpus, type SharedProgramOptions } from './shared-program.ts'
|
|
84
94
|
|
|
85
95
|
// JSX to IR transformer
|
|
@@ -111,7 +121,7 @@ export type { ParsedExprEmitter, LoweringEmitter, HigherOrderMethod, ArrayMethod
|
|
|
111
121
|
export { collectLoopBoundNames } from './adapters/loop-bound-names.ts'
|
|
112
122
|
export { derivesScopeFromSlot } from './adapters/child-scope.ts'
|
|
113
123
|
export { evaluateStaticLiteral, isFullyStaticLiteral, resolveStaticLoopSource } from './static-literal.ts'
|
|
114
|
-
export { importsSearchParams, searchParamsLocalNames, envSignalLocalNames, envSignalReaderFor, ENV_SIGNAL_READERS, queryHrefLocalNames,
|
|
124
|
+
export { importsSearchParams, searchParamsLocalNames, envSignalLocalNames, envSignalReaderFor, ENV_SIGNAL_READERS, queryHrefLocalNames, matchSearchParamsMethodCall } from './adapters/env-signal.ts'
|
|
115
125
|
export type { EnvSignalReader } from './adapters/env-signal.ts'
|
|
116
126
|
export { matchQueryHrefCall, queryHrefArgs, type QueryHrefCall, type QueryHrefTriple } from './query-href-lowering.ts'
|
|
117
127
|
export {
|
|
@@ -225,7 +235,7 @@ export { ErrorCodes, createError, formatError, generateCodeFrame } from './error
|
|
|
225
235
|
export { isValueReferenceIdentifier, collectValueReferencedNames } from './value-references.ts'
|
|
226
236
|
|
|
227
237
|
// Expression Parser
|
|
228
|
-
export { parseExpression, tsNodeToParsedExpr, asCallbackMethodCall, CALLBACK_METHODS, sortComparatorFromArrow, serializeParsedExpr, freeVarsInBody, freeIdentifiers, materializeGetterCalls, isSupported, isSupportedValue, exprToString, stringifyParsedExpr, identifierPath, parseBlockBody, parseBlockBodyTolerant, foldBlockToExpr, predicateTernaryToLogical, containsHigherOrder, extractArrowBodyExpression, parseStyleObjectEntries, hasUnsafeStyleValue, parseProviderObjectLiteral, type ProviderObjectMember, type FoldBlockOptions } from './expression-parser.ts'
|
|
238
|
+
export { parseExpression, tsNodeToParsedExpr, asCallbackMethodCall, CALLBACK_METHODS, sortComparatorFromArrow, serializeParsedExpr, freeVarsInBody, freeIdentifiers, materializeGetterCalls, isSupported, isSupportedValue, exprToString, stringifyParsedExpr, identifierPath, parseBlockBody, parseBlockBodyTolerant, foldBlockToExpr, predicateTernaryToLogical, containsHigherOrder, extractArrowBodyExpression, parseStyleObjectEntries, hasUnsafeStyleValue, parseProviderObjectLiteral, isFunctionShapedExpression, type ProviderObjectMember, type FoldBlockOptions } from './expression-parser.ts'
|
|
229
239
|
export type { StyleObjectEntry } from './expression-parser.ts'
|
|
230
240
|
export { PARSED_EXPR_KINDS, ARRAY_METHOD_NAMES, SORT_KEY_TYPES, SORT_KEY_TARGETS, SORT_KEY_DIRECTIONS } from './expression-parser.ts'
|
|
231
241
|
export type { ParsedExpr, ObjectLiteralProperty, ParsedStatement, SortComparator, SortKey, FlatDepth, SupportLevel, SupportResult, TemplatePart } from './expression-parser.ts'
|
|
@@ -246,6 +256,7 @@ export {
|
|
|
246
256
|
buildLoopSummary,
|
|
247
257
|
buildWhyUpdate,
|
|
248
258
|
traceUpdatePath,
|
|
259
|
+
traceableNames,
|
|
249
260
|
formatComponentGraph,
|
|
250
261
|
formatUpdatePath,
|
|
251
262
|
formatEventSummary,
|
|
@@ -41,6 +41,7 @@ import { attrValueToString } from './utils.ts'
|
|
|
41
41
|
import type { ClientJsContext } from './types.ts'
|
|
42
42
|
import { extractIdentifiers, extractTemplateIdentifiers } from './identifiers.ts'
|
|
43
43
|
import { walkIR } from './walker.ts'
|
|
44
|
+
import { signalSecondBinding } from '../signal-initializer.ts'
|
|
44
45
|
|
|
45
46
|
// All non-declaration edge origins share a single null source — no
|
|
46
47
|
// query on the graph distinguishes them on read today. Stage E
|
|
@@ -59,7 +60,8 @@ export function buildReferencesGraph(ctx: ClientJsContext, irRoot: IRNode): Refe
|
|
|
59
60
|
for (const f of ctx.localFunctions) declaredNames.add(f.name)
|
|
60
61
|
for (const s of ctx.signals) {
|
|
61
62
|
declaredNames.add(s.getter)
|
|
62
|
-
|
|
63
|
+
const second = signalSecondBinding(s)
|
|
64
|
+
if (second) declaredNames.add(second)
|
|
63
65
|
}
|
|
64
66
|
for (const m of ctx.memos) declaredNames.add(m.name)
|
|
65
67
|
for (const p of ctx.propsParams) {
|
|
@@ -189,7 +191,9 @@ export function buildReferencesGraph(ctx: ClientJsContext, irRoot: IRNode): Refe
|
|
|
189
191
|
|
|
190
192
|
// identifiers.ts L137-139
|
|
191
193
|
for (const signal of ctx.signals) {
|
|
192
|
-
|
|
194
|
+
// An async factory's declaration is its whole call (`createQuery(fn,
|
|
195
|
+
// options)`, #3165): the request function's reads are dependencies too.
|
|
196
|
+
addExprEdges({ kind: 'signal', name: signal.getter }, signal.factory?.argsText ?? signal.initialValue, 'init-body')
|
|
193
197
|
}
|
|
194
198
|
|
|
195
199
|
// identifiers.ts L141-143
|
|
@@ -89,14 +89,19 @@ export function collectComponentNamesFromIR(nodes: IRNode[], names: Set<string>)
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
|
-
* Collect child component names from conditional
|
|
93
|
-
*
|
|
94
|
-
*
|
|
92
|
+
* Collect child component names from conditional branches: the branch's
|
|
93
|
+
* own child components, components inside composite loops within the
|
|
94
|
+
* branch (e.g., Badge inside a branch loop), and nested conditionals.
|
|
95
|
+
* A branch-owned child is initialized by the branch's `insert()`
|
|
96
|
+
* bindEvents, not through `ctx.childInits`, so it is named here.
|
|
95
97
|
*/
|
|
96
98
|
function collectChildNamesFromBranches(
|
|
97
99
|
cond: Pick<ConditionalElement, 'whenTrue' | 'whenFalse'>,
|
|
98
100
|
names: Set<string>,
|
|
99
101
|
): void {
|
|
102
|
+
for (const child of [...cond.whenTrue.childComponents, ...cond.whenFalse.childComponents]) {
|
|
103
|
+
names.add(child.name)
|
|
104
|
+
}
|
|
100
105
|
for (const loop of [...cond.whenTrue.loops, ...cond.whenFalse.loops]) {
|
|
101
106
|
if (loop.nestedComponents) {
|
|
102
107
|
for (const comp of loop.nestedComponents) names.add(comp.name)
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* IR tree traversal → collect elements into ClientJsContext.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { type IRNode, type IRElement, type IRComponent, type IRLoop, type IRProp, pickAttrMetaFromIR } from '../types.ts'
|
|
5
|
+
import { type IRNode, type IRElement, type IRComponent, type IRConditional, type IRLoop, type IRProp, pickAttrMetaFromIR } from '../types.ts'
|
|
6
6
|
import type { ClientJsContext, ConditionalBranchChildComponent, ConditionalBranchReactiveAttr, BranchLoop, ConditionalBranchTextEffect, ConditionalElement, LoopChildBindings, LoopChildBranchSummary, LoopChildConditional, LoopOffset, NestedLoop } from './types.ts'
|
|
7
7
|
import { attrValueToString, freeIdsFromRefs, quotePropName, PROPS_PARAM, type LoopParamSpec } from './utils.ts'
|
|
8
|
-
import { classifyReactivity, needsEffectWrapper, decideWrapForAttr, decideWrapForChildProp, decideWrapFromAstFlags, collectEventHandlersFromIR, collectConditionalBranchEvents, collectConditionalBranchRefs, collectConditionalBranchChildComponents, collectLoopChildEventsWithNesting, collectLoopChildReactiveAttrs, collectLoopChildReactiveTexts, collectLoopChildRefs, emptyLoopChildBindings, buildLoopRowScope, anyNameIn } from './reactivity.ts'
|
|
8
|
+
import { classifyReactivity, needsEffectWrapper, decideWrapForAttr, decideWrapForChildProp, decideWrapFromAstFlags, collectEventHandlersFromIR, collectConditionalBranchEvents, collectConditionalBranchRefs, collectConditionalBranchChildComponents, collectConditionalBranchComponentNodes, collectLoopChildEventsWithNesting, collectLoopChildReactiveAttrs, collectLoopChildReactiveTexts, collectLoopChildRefs, emptyLoopChildBindings, buildLoopRowScope, anyNameIn } from './reactivity.ts'
|
|
9
9
|
import { irToHtmlTemplate, irToPlaceholderTemplate, irChildrenToJsExpr, jsxChildrenPropGetterExpr, buildLoopSkeletonTemplate, computeSkeletonSlotPaths, renderFlatMapClientBody, renderFlatMapProjectionClientBody, flatMapCallbackHasKeyedLeaf, type SkeletonSlotPaths } from './html-template.ts'
|
|
10
10
|
import { detectRootNamespaceWrapTag } from './control-flow/stringify/template-parse.ts'
|
|
11
11
|
import { expandDynamicPropValue, expandConstantForReactivity, resolveRestSpreadOrigin, resolveRestSpreadNames } from './prop-handling.ts'
|
|
@@ -14,6 +14,7 @@ import { walkIR, stopAt } from './walker.ts'
|
|
|
14
14
|
import { buildLoopChainExpr } from '../loop-chain.ts'
|
|
15
15
|
import { classifyDOMProp } from '@barefootjs/shared'
|
|
16
16
|
import type { BindingScope } from '../scope/binding-scope.ts'
|
|
17
|
+
import { isEventHandlerName } from '../event-handler-name.ts'
|
|
17
18
|
|
|
18
19
|
/** Expressions that render nothing (0 DOM nodes) — `&&` / `?:` empty branches. */
|
|
19
20
|
const EMPTY_RENDER_EXPRS = new Set(['null', 'undefined', 'false', "''", '""', '``'])
|
|
@@ -402,7 +403,7 @@ export function collectInnerLoops(
|
|
|
402
403
|
props: c.props.map(p => ({
|
|
403
404
|
name: p.name,
|
|
404
405
|
value: p.value,
|
|
405
|
-
isEventHandler:
|
|
406
|
+
isEventHandler: isEventHandlerName(p.name),
|
|
406
407
|
})),
|
|
407
408
|
children: c.children,
|
|
408
409
|
loopDepth: emitDepth,
|
|
@@ -522,10 +523,7 @@ function buildComponentPropsExpr(props: IRProp[], ctx: ClientJsContext): string
|
|
|
522
523
|
for (const prop of props) {
|
|
523
524
|
if (prop.name === '...' || prop.name.startsWith('...')) continue
|
|
524
525
|
explicitPropNames.push(prop.name)
|
|
525
|
-
const isEventHandler =
|
|
526
|
-
prop.name.startsWith('on') &&
|
|
527
|
-
prop.name.length > 2 &&
|
|
528
|
-
prop.name[2] === prop.name[2].toUpperCase()
|
|
526
|
+
const isEventHandler = isEventHandlerName(prop.name)
|
|
529
527
|
if (isEventHandler) {
|
|
530
528
|
// Event handlers reach here only as `expression` variants.
|
|
531
529
|
propsForInit.push(`${quotePropName(prop.name)}: ${attrValueToString(prop.value) ?? prop.name}`)
|
|
@@ -652,6 +650,18 @@ export function collectElements(
|
|
|
652
650
|
siblingOffsets: Map<IRLoop, IRNode[]>,
|
|
653
651
|
insideConditional = false,
|
|
654
652
|
): void {
|
|
653
|
+
// Child components an emitted conditional's branch initializes itself
|
|
654
|
+
// (its `bindEvents` → `initChild`). The static child-init pass below
|
|
655
|
+
// must skip exactly these: a second, parent-owned init of the same child
|
|
656
|
+
// doubles every effect / listener and survives the branch's removal —
|
|
657
|
+
// and once `insert()` re-renders the branch it even targets a detached
|
|
658
|
+
// node, so `initChild`'s re-entry guard can't catch it.
|
|
659
|
+
const branchOwnedComponents = new Set<IRComponent>()
|
|
660
|
+
const claimBranchComponents = (c: IRConditional): void => {
|
|
661
|
+
for (const branch of [c.whenTrue, c.whenFalse]) {
|
|
662
|
+
for (const comp of collectConditionalBranchComponentNodes(branch)) branchOwnedComponents.add(comp)
|
|
663
|
+
}
|
|
664
|
+
}
|
|
655
665
|
walkIR<boolean>(node, insideConditional, {
|
|
656
666
|
element: ({ node: el, scope: inCond, descend }) => {
|
|
657
667
|
collectFromElement(el, ctx, inCond)
|
|
@@ -692,6 +702,7 @@ export function collectElements(
|
|
|
692
702
|
conditional: ({ node: c, scope: inCond, descend }) => {
|
|
693
703
|
if (c.clientOnly && c.slotId) {
|
|
694
704
|
ctx.clientOnlyConditionals.push(buildConditionalMetadata(c, ctx, siblingOffsets))
|
|
705
|
+
claimBranchComponents(c)
|
|
695
706
|
} else if (c.slotId) {
|
|
696
707
|
// Solid-style wrap-by-default fallback (#941, follow-up to #937/#939).
|
|
697
708
|
// Wrap not only statically-proven-reactive conditions, but also any
|
|
@@ -702,6 +713,7 @@ export function collectElements(
|
|
|
702
713
|
// are collected by the enclosing conditional via `collectBranchConditionals`
|
|
703
714
|
// and emitted inside that conditional's bindEvents.
|
|
704
715
|
ctx.conditionalElements.push(buildConditionalMetadata(c, ctx, siblingOffsets))
|
|
716
|
+
claimBranchComponents(c)
|
|
705
717
|
}
|
|
706
718
|
}
|
|
707
719
|
// Recurse into both branches with insideConditional = true so
|
|
@@ -983,7 +995,7 @@ export function collectElements(
|
|
|
983
995
|
// Reactive props need effects to update the element when values change.
|
|
984
996
|
for (const prop of c.props) {
|
|
985
997
|
if (prop.value.kind === 'jsx-children') continue
|
|
986
|
-
if (
|
|
998
|
+
if (isEventHandlerName(prop.name)) continue
|
|
987
999
|
// Only `expression` variants reach the signal/memo getter heuristic
|
|
988
1000
|
// — literal / template / spread / boolean forms don't have a single
|
|
989
1001
|
// bare-identifier shape to lookup.
|
|
@@ -1007,11 +1019,13 @@ export function collectElements(
|
|
|
1007
1019
|
|
|
1008
1020
|
collectReactiveChildProps(c, ctx)
|
|
1009
1021
|
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1022
|
+
if (!branchOwnedComponents.has(c)) {
|
|
1023
|
+
ctx.childInits.push({
|
|
1024
|
+
name: c.name,
|
|
1025
|
+
slotId: c.slotId,
|
|
1026
|
+
propsExpr: buildComponentPropsExpr(c.props, ctx),
|
|
1027
|
+
})
|
|
1028
|
+
}
|
|
1015
1029
|
|
|
1016
1030
|
descend()
|
|
1017
1031
|
// Traverse JSX prop children so events, reactive expressions, and nested
|
|
@@ -1063,6 +1077,7 @@ function collectFromElement(element: IRElement, ctx: ClientJsContext, insideCond
|
|
|
1063
1077
|
ctx.refElements.push({
|
|
1064
1078
|
slotId: element.slotId,
|
|
1065
1079
|
callback: element.ref,
|
|
1080
|
+
...(element.ssrPortalOwnerScope && { ssrPortalOwner: true }),
|
|
1066
1081
|
})
|
|
1067
1082
|
}
|
|
1068
1083
|
|
|
@@ -33,6 +33,7 @@ import { createError, ErrorCodes } from '../errors.ts'
|
|
|
33
33
|
import { attrValueToString } from './utils.ts'
|
|
34
34
|
import { walkIR, type IRVisitor } from './walker.ts'
|
|
35
35
|
import { buildSignalMemoEnv, csrSubstitute, resolveGetterAliases, type CsrEnv, type CsrSubstitution } from './csr-substitute.ts'
|
|
36
|
+
import { signalSecondBinding } from '../signal-initializer.ts'
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
39
|
* Build a `RelocateEnv` from a live `ClientJsContext`. The IR-keyed env
|
|
@@ -266,7 +267,7 @@ export function computeInlinability(
|
|
|
266
267
|
|
|
267
268
|
// --- Constants (initial classification) ---
|
|
268
269
|
const signalGetters = new Set(ctx.signals.map(s => s.getter))
|
|
269
|
-
const signalSetters = new Set(ctx.signals.
|
|
270
|
+
const signalSetters = new Set(ctx.signals.flatMap(s => signalSecondBinding(s) ?? []))
|
|
270
271
|
const memoNames = new Set(ctx.memos.map(m => m.name))
|
|
271
272
|
// A bare alias-hop chain that ultimately names a signal/memo getter
|
|
272
273
|
// (`const items__alias = items`, #2778) is `reactive-read` the same as
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
graphFunctionReferences,
|
|
22
22
|
graphUsedIdentifiers,
|
|
23
23
|
} from './build-references.ts'
|
|
24
|
+
import { signalSecondBinding } from '../signal-initializer.ts'
|
|
24
25
|
|
|
25
26
|
export interface DeclarationScopes {
|
|
26
27
|
constantScope: Map<string, DeclarationScope>
|
|
@@ -104,7 +105,8 @@ export function computeDeclarationScopes(
|
|
|
104
105
|
const initRequired = new Set<string>()
|
|
105
106
|
for (const s of ctx.signals) {
|
|
106
107
|
initRequired.add(s.getter)
|
|
107
|
-
|
|
108
|
+
const second = signalSecondBinding(s)
|
|
109
|
+
if (second) initRequired.add(second)
|
|
108
110
|
}
|
|
109
111
|
for (const m of ctx.memos) initRequired.add(m.name)
|
|
110
112
|
for (const p of ctx.propsParams) initRequired.add(p.name)
|