@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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Reactivity detection: reactive expression checking, event/ref collection.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { type IRNode, type IRElement, type IRProp, type LoopParamBinding, type OriginInfo, pickAttrMetaFromIR, isReactiveOrigin } from '../types.ts'
|
|
5
|
+
import { type IRNode, type IRElement, type IRComponent, type IRProp, type LoopParamBinding, type OriginInfo, pickAttrMetaFromIR, isReactiveOrigin } from '../types.ts'
|
|
6
6
|
import type {
|
|
7
7
|
ClientJsContext,
|
|
8
8
|
ConditionalBranchEvent,
|
|
@@ -20,6 +20,7 @@ import { extractFreeIdentifiersFromText } from './csr-substitute.ts'
|
|
|
20
20
|
import { walkIR, stopAt } from './walker.ts'
|
|
21
21
|
import { BindingScope } from '../scope/binding-scope.ts'
|
|
22
22
|
import { identifierCallPattern } from '../identifier-pattern.ts'
|
|
23
|
+
import { isEventHandlerName } from '../event-handler-name.ts'
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* Build the `BindingScope` for one loop row's own bindings — item /
|
|
@@ -384,7 +385,7 @@ export function collectEventHandlersFromIR(node: IRNode): string[] {
|
|
|
384
385
|
},
|
|
385
386
|
component: ({ node, descend }) => {
|
|
386
387
|
for (const prop of node.props) {
|
|
387
|
-
if (
|
|
388
|
+
if (isEventHandlerName(prop.name)) {
|
|
388
389
|
const handler = attrValueToString(prop.value)
|
|
389
390
|
if (handler) handlers.push(handler)
|
|
390
391
|
}
|
|
@@ -487,6 +488,7 @@ export function collectConditionalBranchRefs(node: IRNode): ConditionalBranchRef
|
|
|
487
488
|
refs.push({
|
|
488
489
|
slotId: el.slotId,
|
|
489
490
|
callback: el.ref,
|
|
491
|
+
...(el.ssrPortalOwnerScope && { ssrPortalOwner: true }),
|
|
490
492
|
})
|
|
491
493
|
}
|
|
492
494
|
}, true)
|
|
@@ -654,16 +656,23 @@ export function collectConditionalBranchChildComponents(
|
|
|
654
656
|
node: IRNode,
|
|
655
657
|
skipConditionals = false,
|
|
656
658
|
): Array<{ name: string; slotId: string | null; props: IRProp[]; children: IRNode[] }> {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
659
|
+
return collectConditionalBranchComponentNodes(node, skipConditionals).map(c => ({
|
|
660
|
+
name: c.name,
|
|
661
|
+
slotId: c.slotId,
|
|
662
|
+
props: c.props,
|
|
663
|
+
children: c.children,
|
|
664
|
+
}))
|
|
660
665
|
}
|
|
661
666
|
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
+
/**
|
|
668
|
+
* The component nodes a conditional branch's `bindEvents` initializes —
|
|
669
|
+
* THE definition of which children a branch owns. `collectConditionalBranchChildComponents`
|
|
670
|
+
* (what the branch emits `initChild` for) and the main collector's static
|
|
671
|
+
* child-init pass (which must skip exactly these, or the child is
|
|
672
|
+
* initialized twice) both read it.
|
|
673
|
+
*/
|
|
674
|
+
export function collectConditionalBranchComponentNodes(node: IRNode, skipConditionals = false): IRComponent[] {
|
|
675
|
+
const components: IRComponent[] = []
|
|
667
676
|
// Loops never contain collected components via this walker; halting there
|
|
668
677
|
// matches the pre-walker behaviour (no 'loop' case in the switch).
|
|
669
678
|
// skipConditionals also halts at nested conditionals / if-statements.
|
|
@@ -673,16 +682,12 @@ function traverseForComponents(
|
|
|
673
682
|
walkIR(node, null, {
|
|
674
683
|
...stops,
|
|
675
684
|
component: ({ node, descend }) => {
|
|
676
|
-
components.push(
|
|
677
|
-
name: node.name,
|
|
678
|
-
slotId: node.slotId,
|
|
679
|
-
props: node.props,
|
|
680
|
-
children: node.children,
|
|
681
|
-
})
|
|
685
|
+
components.push(node)
|
|
682
686
|
// Recurse into children passed to this component.
|
|
683
687
|
descend()
|
|
684
688
|
},
|
|
685
689
|
})
|
|
690
|
+
return components
|
|
686
691
|
}
|
|
687
692
|
|
|
688
693
|
/**
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { SourceLocation } from '../types.ts'
|
|
10
|
+
import { initFunctionName } from './utils.ts'
|
|
10
11
|
|
|
11
12
|
// =============================================================================
|
|
12
13
|
// VLQ Base64 Encoding
|
|
@@ -271,7 +272,7 @@ export function buildSourceMapFromIR(
|
|
|
271
272
|
mapEventHandlers(lines, ir.root, gen)
|
|
272
273
|
|
|
273
274
|
// Map the init function declaration to the component function
|
|
274
|
-
const initLine = findLineIndex(lines, `export function
|
|
275
|
+
const initLine = findLineIndex(lines, `export function ${initFunctionName(meta.componentName)}(`)
|
|
275
276
|
if (initLine >= 0 && ir.root.loc) {
|
|
276
277
|
gen.addMappingFromLoc(initLine, 0, ir.root.loc)
|
|
277
278
|
}
|
|
@@ -70,15 +70,22 @@ function emitSignal(lines: string[], plan: SignalEmitPlan): void {
|
|
|
70
70
|
// getter name into output (#2468 sweep — dropping the declaration
|
|
71
71
|
// entirely left the setter as a guaranteed ReferenceError).
|
|
72
72
|
const getterSlot = plan.getterElided ? '' : plan.getter
|
|
73
|
-
// Env signal (#2057): emit its own factory call
|
|
74
|
-
//
|
|
75
|
-
//
|
|
73
|
+
// Env signal (#2057) or async factory (#3165): emit its own factory call
|
|
74
|
+
// verbatim (`createSearchParams()`, `createQuery(fn, options)`) — no baked
|
|
75
|
+
// initial value, profile id, or controlled effect applies. Only an async
|
|
76
|
+
// factory carries a branch condition (see `SignalEmitPlan.branchCondition`).
|
|
76
77
|
if (plan.initializerOverride) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
const bindings = plan.setter ? `${getterSlot}, ${plan.setter}` : plan.getter
|
|
79
|
+
if (plan.branchCondition) {
|
|
80
|
+
lines.push(plan.setter
|
|
81
|
+
? (plan.getterElided ? ` let ${plan.setter}` : ` let ${plan.getter}, ${plan.setter}`)
|
|
82
|
+
: ` let ${plan.getter}`)
|
|
83
|
+
lines.push(` if (${plan.branchCondition}) {`)
|
|
84
|
+
lines.push(` ;[${bindings}] = ${plan.initializerOverride}`)
|
|
85
|
+
lines.push(` }`)
|
|
86
|
+
return
|
|
81
87
|
}
|
|
88
|
+
lines.push(` const [${bindings}] = ${plan.initializerOverride}`)
|
|
82
89
|
return
|
|
83
90
|
}
|
|
84
91
|
const id = bfIdArg(plan.bfId)
|
|
@@ -203,6 +203,8 @@ export interface ConditionalBranchEvent {
|
|
|
203
203
|
export interface ConditionalBranchRef {
|
|
204
204
|
slotId: string
|
|
205
205
|
callback: string
|
|
206
|
+
/** Mirrors `IRElement.ssrPortalOwnerScope` — see `emitRefCall`. */
|
|
207
|
+
ssrPortalOwner?: boolean
|
|
206
208
|
}
|
|
207
209
|
|
|
208
210
|
export interface ConditionalBranchChildComponent {
|
|
@@ -740,6 +742,8 @@ export type CollectedLoop = TopLevelLoop | BranchLoop | NestedLoop
|
|
|
740
742
|
export interface RefElement {
|
|
741
743
|
slotId: string
|
|
742
744
|
callback: string
|
|
745
|
+
/** Mirrors `IRElement.ssrPortalOwnerScope` — see `emitRefCall`. */
|
|
746
|
+
ssrPortalOwner?: boolean
|
|
743
747
|
}
|
|
744
748
|
|
|
745
749
|
export interface ChildInit {
|
|
@@ -26,7 +26,9 @@ import {
|
|
|
26
26
|
loopItemMarker,
|
|
27
27
|
toHTMLAttrName as toHtmlAttrName,
|
|
28
28
|
keyAttrName as sharedKeyAttrName,
|
|
29
|
+
BF_PORTAL_OWNER,
|
|
29
30
|
} from '@barefootjs/shared'
|
|
31
|
+
import { RUNTIME_IMPORT_CANDIDATES } from './imports.ts'
|
|
30
32
|
|
|
31
33
|
export { DATA_KEY, DATA_KEY_PREFIX, DATA_BF_PH, BF_LOOP_START, BF_LOOP_END, loopStartMarker, loopEndMarker, loopItemMarker, toHtmlAttrName }
|
|
32
34
|
|
|
@@ -36,6 +38,39 @@ export { DATA_KEY, DATA_KEY_PREFIX, DATA_BF_PH, BF_LOOP_START, BF_LOOP_END, loop
|
|
|
36
38
|
*/
|
|
37
39
|
export const PROPS_PARAM = '_p'
|
|
38
40
|
|
|
41
|
+
/** Every runtime helper name a generated module may import bare (#3113). */
|
|
42
|
+
const RESERVED_RUNTIME_NAMES = new Set<string>(RUNTIME_IMPORT_CANDIDATES)
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Name of the per-component init function (`init<Name>`), consistently
|
|
46
|
+
* computed wherever it's declared, registered, called, or located for
|
|
47
|
+
* source-mapping (#3113).
|
|
48
|
+
*
|
|
49
|
+
* The naive `` `init${name}` `` collides with the runtime's own imported
|
|
50
|
+
* `initChild` whenever a component is literally named `Child` — the
|
|
51
|
+
* generated module then both `import`s `initChild` from
|
|
52
|
+
* `@barefootjs/client/runtime` (to dispatch INTO this or another child)
|
|
53
|
+
* AND `export function initChild(...)` (THIS component's own compiled
|
|
54
|
+
* init) as two top-level declarations of the same identifier, which is a
|
|
55
|
+
* hard `SyntaxError` under real ES module semantics (verified against a
|
|
56
|
+
* raw `<script type="module">` load — the same unbundled-ESM shape
|
|
57
|
+
* `bf build` ships and `fixture-host.ts`'s `'hydrate'`/`'csr-mount'` modes
|
|
58
|
+
* serve, #2481). No bundler downstream can rescue a same-module identifier
|
|
59
|
+
* collision — a bundler renames colliding identifiers ACROSS merged
|
|
60
|
+
* modules, but `import { initChild } from '...'` and
|
|
61
|
+
* `function initChild() {}` live in the SAME module and are simply invalid
|
|
62
|
+
* syntax before any bundler sees them.
|
|
63
|
+
*
|
|
64
|
+
* Trailing `$` (rather than a numeric/underscore suffix) guarantees the
|
|
65
|
+
* disambiguated name can never itself collide with a *future*
|
|
66
|
+
* `RUNTIME_IMPORT_CANDIDATES` entry — none of those are, or plausibly will
|
|
67
|
+
* be, `$`-suffixed.
|
|
68
|
+
*/
|
|
69
|
+
export function initFunctionName(componentName: string): string {
|
|
70
|
+
const name = `init${componentName}`
|
|
71
|
+
return RESERVED_RUNTIME_NAMES.has(name) ? `${name}$` : name
|
|
72
|
+
}
|
|
73
|
+
|
|
39
74
|
/**
|
|
40
75
|
* True when the component's rendered root is a comment-scoped proxy rather
|
|
41
76
|
* than an element carrying its own `bf-s`/`bf-h` scope id directly — the
|
|
@@ -47,7 +82,42 @@ export const PROPS_PARAM = '_p'
|
|
|
47
82
|
* — the wrapping comment marks a scope with no DOM presence of its own.
|
|
48
83
|
*/
|
|
49
84
|
export function isCommentScopedRoot(root: ComponentIR['root']): boolean {
|
|
50
|
-
return (root
|
|
85
|
+
return isScopeCommentFragmentRoot(root) || root.type === 'component'
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* True for a genuine `needsScopeComment` fragment root — the `fragmentRoot:
|
|
90
|
+
* true` def flag's condition (#2722). SSR renders it wrapped in
|
|
91
|
+
* `<!--bf-scope:-->` comments with no scope attribute on any element, so the
|
|
92
|
+
* CSR runtime must be told to mirror that (`materializeComponent` /
|
|
93
|
+
* `renderChild` in component.ts) instead of stamping `bf-s` onto the first
|
|
94
|
+
* rendered element.
|
|
95
|
+
*/
|
|
96
|
+
export function isScopeCommentFragmentRoot(root: ComponentIR['root']): boolean {
|
|
97
|
+
return root.type === 'fragment' && !!(root as IRFragment).needsScopeComment
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The scope-shape flags (`comment: true` / `fragmentRoot: true`) a
|
|
102
|
+
* component's `hydrate()` def declares — the ONE answer both registration
|
|
103
|
+
* emitters read: `emitRegistrationAndHydration` (emit-registration.ts, a
|
|
104
|
+
* component with an init body) and `generateTemplateOnlyMount` (index.ts, a
|
|
105
|
+
* stateless component registered for `renderChild()` only). The template-
|
|
106
|
+
* only emitter used to re-derive the def by hand and declared neither flag,
|
|
107
|
+
* so a fragment-rooted stateless child rendered by CSR got `bf-s` stamped on
|
|
108
|
+
* its first element while SSR (and so hydration) scoped it with a comment
|
|
109
|
+
* pair — a hydrated-vs-csr-mount divergence.
|
|
110
|
+
*
|
|
111
|
+
* A component-call root (#2649) never reaches the template-only emitter:
|
|
112
|
+
* its root child call always pushes a `childInits` entry
|
|
113
|
+
* (collect-elements.ts), so `needsClientJs` routes it to the init-bearing
|
|
114
|
+
* path. Both paths therefore share one answer here.
|
|
115
|
+
*/
|
|
116
|
+
export function componentDefScopeFlags(root: ComponentIR['root']): string[] {
|
|
117
|
+
const flags: string[] = []
|
|
118
|
+
if (isCommentScopedRoot(root)) flags.push('comment: true')
|
|
119
|
+
if (isScopeCommentFragmentRoot(root)) flags.push('fragmentRoot: true')
|
|
120
|
+
return flags
|
|
51
121
|
}
|
|
52
122
|
|
|
53
123
|
/**
|
|
@@ -363,18 +433,30 @@ export function wrapHandlerForTurn(handler: string, handlerId: string, loc?: str
|
|
|
363
433
|
* Heuristic: a single bare identifier (e.g. `attachPane`) is a local binding;
|
|
364
434
|
* anything else (member access, call, arrow, …) is treated as a possibly-
|
|
365
435
|
* undefined source and emitted with optional-call (`?.()`).
|
|
366
|
-
|
|
367
|
-
|
|
436
|
+
*
|
|
437
|
+
* `ssrPortalOwner` (the element's `IRElement.ssrPortalOwnerScope`, #3059):
|
|
438
|
+
* every SSR adapter renders that element at its portal outlet with
|
|
439
|
+
* `bf-po="<this component's scope id>"` — the owner marker hydration's
|
|
440
|
+
* portal-aware slot lookup finds it by, and which hydration keeps as-is.
|
|
441
|
+
* The CSR mirror stamps the same owner right AFTER the ref callback ran (not
|
|
442
|
+
* in the template: a `bf-po` present before the callback makes its
|
|
443
|
+
* `!isSSRPortal(el)` guard skip the move). Without it the owner came only
|
|
444
|
+
* from the callback's own `createPortal(el, …, { ownerScope })`, which
|
|
445
|
+
* derives it from `el.closest('[bf-s]')` — this component's root for an
|
|
446
|
+
* element root, but nothing (or an unrelated outer scope) for a
|
|
447
|
+
* `needsScopeComment` fragment root, whose scope id lives on a comment, so
|
|
448
|
+
* a CSR mount diverged from SSR/hydration on the attribute.
|
|
449
|
+
*/
|
|
450
|
+
export function emitRefCall(callback: string, elementVar: string, ssrPortalOwner = false): string {
|
|
368
451
|
const trimmed = callback.trim()
|
|
369
452
|
const isBareIdent = /^[a-zA-Z_$][\w$]*$/.test(trimmed)
|
|
370
|
-
if (isBareIdent) {
|
|
371
|
-
return `(${callback})(${elementVar})`
|
|
372
|
-
}
|
|
373
453
|
// Wrap non-identifier expressions in parens so `?.()` binds to the whole
|
|
374
454
|
// expression (e.g. `(_p.onMount)?.(_s0)` not `_p.onMount?.(_s0)` — both
|
|
375
455
|
// parse the same here, but the parens preserve the legacy emit shape's
|
|
376
456
|
// intent and stay safe for arbitrary callback expressions).
|
|
377
|
-
|
|
457
|
+
const call = isBareIdent ? `(${callback})(${elementVar})` : `(${callback})?.(${elementVar})`
|
|
458
|
+
if (!ssrPortalOwner) return call
|
|
459
|
+
return `{ ${call}; if (__scopeId) ${elementVar}.setAttribute('${BF_PORTAL_OWNER}', __scopeId) }`
|
|
378
460
|
}
|
|
379
461
|
|
|
380
462
|
/** Infer a sensible JS default value literal from a type descriptor. */
|