@barefootjs/jsx 0.37.1 → 0.38.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/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/analyzer.d.ts +31 -0
- package/dist/analyzer.d.ts.map +1 -1
- 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/errors.d.ts +3 -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 +37 -0
- package/dist/format-date-refusal.d.ts.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2421 -1787
- package/dist/ir-to-client-js/collect-elements.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/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/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/html-template.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/utils.d.ts +26 -0
- 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/to-locale-date-lowering.d.ts +7 -4
- package/dist/to-locale-date-lowering.d.ts.map +1 -1
- package/dist/types.d.ts +53 -17
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +724 -4564
- 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__/doc-examples.test.ts +12 -22
- 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__/ref-attr-absent-at-ssr.test.ts +472 -0
- package/src/__tests__/ssr-portal-ref-callback.test.ts +217 -0
- package/src/adapters/env-signal.ts +2 -21
- package/src/adapters/interface.ts +13 -0
- package/src/analyzer.ts +31 -27
- package/src/builtin-lowering-plugins.ts +0 -2
- package/src/compiler.ts +24 -0
- package/src/component-root-scope-comment.ts +59 -0
- package/src/errors.ts +44 -1
- package/src/event-handler-name.ts +14 -0
- package/src/expression-parser.ts +41 -17
- package/src/format-date-refusal.ts +266 -0
- package/src/index.ts +12 -2
- package/src/ir-to-client-js/child-components.ts +8 -3
- package/src/ir-to-client-js/collect-elements.ts +27 -13
- 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-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/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/emit-reactive.ts +140 -10
- package/src/ir-to-client-js/emit-registration.ts +2 -2
- 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 +4 -3
- package/src/ir-to-client-js/reactivity.ts +20 -16
- package/src/ir-to-client-js/source-map.ts +2 -1
- package/src/ir-to-client-js/utils.ts +34 -0
- package/src/jsx-to-ir.ts +737 -49
- package/src/opaque-local-accessor.ts +44 -0
- package/src/rich-type-refusal.ts +1 -1
- package/src/to-locale-date-lowering.ts +7 -4
- package/src/types.ts +51 -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
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import type { ComponentIR } from '../types.ts'
|
|
12
12
|
import type { ClientJsContext } from './types.ts'
|
|
13
|
-
import { PROPS_PARAM, isCommentScopedRoot } from './utils.ts'
|
|
13
|
+
import { PROPS_PARAM, isCommentScopedRoot, initFunctionName } from './utils.ts'
|
|
14
14
|
import { buildReferencesGraph } from './build-references.ts'
|
|
15
15
|
import { computePropUsage } from './compute-prop-usage.ts'
|
|
16
16
|
import { IMPORT_PLACEHOLDER, MODULE_CONSTANTS_PLACEHOLDER } from './imports.ts'
|
|
@@ -40,7 +40,7 @@ export function generateInitFunction(
|
|
|
40
40
|
emitChildComponentImports(lines, ctx, new Set(siblingComponents || []))
|
|
41
41
|
lines.push('')
|
|
42
42
|
lines.push(MODULE_CONSTANTS_PLACEHOLDER)
|
|
43
|
-
lines.push(`export function
|
|
43
|
+
lines.push(`export function ${initFunctionName(name)}(__scope, ${PROPS_PARAM} = {}) {`)
|
|
44
44
|
lines.push(` if (!__scope) return`)
|
|
45
45
|
// Host scope id for (bf-h, bf-m) child lookups inside this init body
|
|
46
46
|
// (#1249). Compile-time selectors emit
|
|
@@ -11,12 +11,13 @@ import { assertNever } from './walker.ts'
|
|
|
11
11
|
import { buildSignalMemoEnv, csrSubstitute, type CsrEnv } from './csr-substitute.ts'
|
|
12
12
|
import { rewritePropsObjectRef } from './rewrite-props-object.ts'
|
|
13
13
|
import type { ClientJsContext } from './types.ts'
|
|
14
|
-
import { BF_PARENT_SCOPE_PLACEHOLDER, BF_SCOPE, classifyDOMProp, escapeHtml } from '@barefootjs/shared'
|
|
14
|
+
import { BF_KEY, BF_PARENT_SCOPE_PLACEHOLDER, BF_SCOPE, classifyDOMProp, escapeHtml } from '@barefootjs/shared'
|
|
15
15
|
import { buildLoopChainExpr } from '../loop-chain.ts'
|
|
16
16
|
import { renderChildScopeArgs } from '../adapters/child-scope.ts'
|
|
17
17
|
import { BindingScope } from '../scope/binding-scope.ts'
|
|
18
18
|
import { interp, spliceChildValue, conditionalMarkup, renderChildCall, mappedRowsMarkup, dangerousInnerHtml, EMPTY_MARKUP } from './safe-html.ts'
|
|
19
19
|
import { markupSlotIdsOf } from './markup-slots.ts'
|
|
20
|
+
import { isEventHandlerName } from '../event-handler-name.ts'
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Protect string literals from regex-based replacements.
|
|
@@ -644,10 +645,30 @@ export function flatMapLeafKeyExpr(ir: IRNode): string | null {
|
|
|
644
645
|
}
|
|
645
646
|
}
|
|
646
647
|
|
|
647
|
-
/**
|
|
648
|
-
|
|
648
|
+
/**
|
|
649
|
+
* Copy of `ir` with the loop `key` attribute replaced by the reconciliation
|
|
650
|
+
* attribute the runtime keys on: `data-key={String(<key>)}` (element leaves
|
|
651
|
+
* only; a keyless leaf just loses nothing). This is the one client-side
|
|
652
|
+
* rendering of a flatMap leaf's key — the hydrate template, the CSR
|
|
653
|
+
* descriptor and the module-scope template all go through it — and it
|
|
654
|
+
* mirrors what SSR emits from the rawBody (`flatMapRawBodyWithLeafKeys`,
|
|
655
|
+
* jsx-to-ir.ts) and what `mapArray` stamps on adoption/creation (`BF_KEY`;
|
|
656
|
+
* the descriptor path never passes a depth-suffixed name), so every
|
|
657
|
+
* construction path agrees on the attribute. Rendered as an ordinary
|
|
658
|
+
* expression attribute, so it is escaped like one.
|
|
659
|
+
*/
|
|
660
|
+
function leafKeyAsDataKeyAttr(ir: IRNode): IRNode {
|
|
649
661
|
if (ir.type !== 'element') return ir
|
|
650
|
-
|
|
662
|
+
const keyExpr = flatMapLeafKeyExpr(ir)
|
|
663
|
+
if (keyExpr === null) return { ...ir, attrs: ir.attrs.filter((a) => a.name !== 'key') }
|
|
664
|
+
// In place, not appended: SSR splices `data-key` at the `key` attribute's
|
|
665
|
+
// position, so the attribute order matches byte-for-byte.
|
|
666
|
+
return {
|
|
667
|
+
...ir,
|
|
668
|
+
attrs: ir.attrs.map((a) =>
|
|
669
|
+
a.name === 'key' ? { ...a, name: BF_KEY, value: { kind: 'expression' as const, expr: `String(${keyExpr})` } } : a,
|
|
670
|
+
),
|
|
671
|
+
}
|
|
651
672
|
}
|
|
652
673
|
|
|
653
674
|
/**
|
|
@@ -675,7 +696,7 @@ export function renderFlatMapClientBody(
|
|
|
675
696
|
rawLeaf: true,
|
|
676
697
|
renderLeaf: (ir) => {
|
|
677
698
|
const key = flatMapLeafKeyExpr(ir)
|
|
678
|
-
const html = irToHtmlTemplate(
|
|
699
|
+
const html = irToHtmlTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, 1, undefined, undefined)
|
|
679
700
|
return `({ k: ${key ?? 'undefined'}, h: \`${html}\` })`
|
|
680
701
|
},
|
|
681
702
|
})
|
|
@@ -871,7 +892,7 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
|
|
|
871
892
|
// during module-scope string rendering, and a ref closing over an
|
|
872
893
|
// init-scope setter would leak it into the template (#2468). The
|
|
873
894
|
// init path re-applies refs once real DOM exists.
|
|
874
|
-
.filter(p => p.name !== 'ref' && !(
|
|
895
|
+
.filter(p => p.name !== 'ref' && !(isEventHandlerName(p.name)))
|
|
875
896
|
.map(p => {
|
|
876
897
|
// `/* @client */` defers the prop to hydrate via initChild.
|
|
877
898
|
if (p.clientOnly) return null
|
|
@@ -974,12 +995,13 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
|
|
|
974
995
|
if (node.flatMapCallback) {
|
|
975
996
|
// Complex flatMap: the body is structured segments, rendered through
|
|
976
997
|
// the same single door as map preambles.
|
|
977
|
-
//
|
|
978
|
-
//
|
|
979
|
-
//
|
|
980
|
-
//
|
|
998
|
+
// The leaf `key` renders as `data-key={String(<key>)}` here, in the
|
|
999
|
+
// CSR descriptor (`renderFlatMapClientBody`) and in the SSR rawBody
|
|
1000
|
+
// (`flatMapRawBodyWithLeafKeys`, jsx-to-ir.ts) alike — the attribute
|
|
1001
|
+
// `mapArray` stamps on adoption/creation, so SSR, hydrate template and
|
|
1002
|
+
// csr-mount agree on it (see `leafKeyAsDataKeyAttr`).
|
|
981
1003
|
const body = renderPreamble(node.flatMapCallback, {
|
|
982
|
-
renderLeaf: (ir) => irToHtmlTemplate(
|
|
1004
|
+
renderLeaf: (ir) => irToHtmlTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, loopDepth + 1, loopParams, branchSlotsVar),
|
|
983
1005
|
})
|
|
984
1006
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, 'flatMap', node.flatMapCallback.params, body))
|
|
985
1007
|
} else if (node.preamble) {
|
|
@@ -1445,8 +1467,8 @@ export function irToPlaceholderTemplate(node: IRNode, restSpreadNames?: Readonly
|
|
|
1445
1467
|
let mapExpr: string
|
|
1446
1468
|
if (node.flatMapCallback) {
|
|
1447
1469
|
const body = renderPreamble(node.flatMapCallback, {
|
|
1448
|
-
// Leaf `key`
|
|
1449
|
-
renderLeaf: (ir) => irToPlaceholderTemplate(
|
|
1470
|
+
// Leaf `key` → `data-key` — see the irToHtmlTemplate site above.
|
|
1471
|
+
renderLeaf: (ir) => irToPlaceholderTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, loopDepth + 1, loopParams),
|
|
1450
1472
|
})
|
|
1451
1473
|
mapExpr = interp(mappedRowsMarkup(wrappedArray, 'flatMap', node.flatMapCallback.params, body))
|
|
1452
1474
|
} else if (node.preamble) {
|
|
@@ -1537,7 +1559,7 @@ function irNodeToJsExprs(node: IRNode, brandMarkup = false): string[] {
|
|
|
1537
1559
|
const propsEntries: string[] = node.props
|
|
1538
1560
|
.filter(p => p.name !== 'key' && p.name !== '...' && !p.name.startsWith('...'))
|
|
1539
1561
|
.map(p => {
|
|
1540
|
-
if (
|
|
1562
|
+
if (isEventHandlerName(p.name)) {
|
|
1541
1563
|
return `${quotePropName(p.name)}: ${attrValueToString(p.value) ?? 'undefined'}`
|
|
1542
1564
|
}
|
|
1543
1565
|
switch (p.value.kind) {
|
|
@@ -2020,7 +2042,7 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
|
|
|
2020
2042
|
// during module-scope string rendering, and a ref closing over an
|
|
2021
2043
|
// init-scope setter would leak it into the template (#2468). The
|
|
2022
2044
|
// init path re-applies refs once real DOM exists.
|
|
2023
|
-
.filter(p => p.name !== 'ref' && !(
|
|
2045
|
+
.filter(p => p.name !== 'ref' && !(isEventHandlerName(p.name)))
|
|
2024
2046
|
.map(p => {
|
|
2025
2047
|
// `/* @client */` defers the prop to hydrate via initChild.
|
|
2026
2048
|
if (p.clientOnly) return null
|
|
@@ -2401,7 +2423,7 @@ export function computeDeferredChildSlots(
|
|
|
2401
2423
|
// `component` emit below so the deferral decision matches output.
|
|
2402
2424
|
if (p.name === '...' || p.name.startsWith('...') || p.name === 'key') return false
|
|
2403
2425
|
if (p.name === 'ref') return false
|
|
2404
|
-
if (
|
|
2426
|
+
if (isEventHandlerName(p.name)) return false
|
|
2405
2427
|
if (p.clientOnly) return false
|
|
2406
2428
|
return propResolvesUnsafe(p, env, unsafeLocalNames)
|
|
2407
2429
|
})
|
|
@@ -2671,7 +2693,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2671
2693
|
// during module-scope string rendering, and a ref closing over an
|
|
2672
2694
|
// init-scope setter would leak it into the template (#2468). The
|
|
2673
2695
|
// init path re-applies refs once real DOM exists.
|
|
2674
|
-
.filter(p => p.name !== 'ref' && !(
|
|
2696
|
+
.filter(p => p.name !== 'ref' && !(isEventHandlerName(p.name)))
|
|
2675
2697
|
.map(p => {
|
|
2676
2698
|
// `/* @client */` defers the prop to hydrate. Drop from the
|
|
2677
2699
|
// SSR `renderChild` props — `initChild`'s `propsExpr` getter
|
|
@@ -2791,8 +2813,8 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
|
|
|
2791
2813
|
const body = renderPreamble(node.flatMapCallback, {
|
|
2792
2814
|
textVariant: 'template',
|
|
2793
2815
|
transformJs: (t) => rewritePropsObjectRef(t, propsObjectName ?? null, restPropsName ?? null, { enclosingScope: childScope }),
|
|
2794
|
-
// Leaf `key`
|
|
2795
|
-
renderLeaf: (ir) => recurseInLoopBody(
|
|
2816
|
+
// Leaf `key` → `data-key` — see the irToHtmlTemplate site above.
|
|
2817
|
+
renderLeaf: (ir) => recurseInLoopBody(leafKeyAsDataKeyAttr(ir)),
|
|
2796
2818
|
})
|
|
2797
2819
|
mapExpr = interp(mappedRowsMarkup(iterArrayExpr, 'flatMap', node.flatMapCallback.params, body))
|
|
2798
2820
|
} else if (node.preamble) {
|
|
@@ -16,7 +16,7 @@ import { buildReferencesGraph, graphUsedIdentifiers } from './build-references.t
|
|
|
16
16
|
import { addConstantPropRefsToSet } from './init-declarations.ts'
|
|
17
17
|
import { canGenerateStaticTemplate, irToComponentTemplate, generateCsrTemplate } from './html-template.ts'
|
|
18
18
|
import { markupSlotIdsOf } from './markup-slots.ts'
|
|
19
|
-
import { PROPS_PARAM } from './utils.ts'
|
|
19
|
+
import { PROPS_PARAM, initFunctionName } from './utils.ts'
|
|
20
20
|
import { buildInlinableConstants, csrInlinableConstantsFromCtx } from './emit-registration.ts'
|
|
21
21
|
import { buildEnvFromCtx } from './compute-inlinability.ts'
|
|
22
22
|
import { nameForRegistryRef, buildImportAliasMap, setActiveImportAliases } from './component-scope.ts'
|
|
@@ -356,13 +356,14 @@ function generateTemplateOnlyMount(ir: ComponentIR, ctx: ClientJsContext): strin
|
|
|
356
356
|
|
|
357
357
|
lines.push(IMPORT_PLACEHOLDER)
|
|
358
358
|
lines.push('')
|
|
359
|
-
|
|
359
|
+
const initName = initFunctionName(name)
|
|
360
|
+
lines.push(`function ${initName}() {}`)
|
|
360
361
|
lines.push('')
|
|
361
362
|
// `name: '...'` only when the key was file-scoped — same reason as in
|
|
362
363
|
// `emitRegistrationAndHydration`: the hashed key must not reach `bf-s`
|
|
363
364
|
// (#2518).
|
|
364
365
|
const nameField = registryKey !== name ? `, name: '${name}'` : ''
|
|
365
|
-
lines.push(`hydrate('${registryKey}', { init:
|
|
366
|
+
lines.push(`hydrate('${registryKey}', { init: ${initName}, template: (${PROPS_PARAM}) => \`${templateHtml}\`${nameField} })`)
|
|
366
367
|
// See `emitRegistrationAndHydration` (./emit-registration.ts) for the
|
|
367
368
|
// rationale on why the component is also emitted as a callable
|
|
368
369
|
// shim. The same applies for template-only components since they
|
|
@@ -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
|
}
|
|
@@ -654,16 +655,23 @@ export function collectConditionalBranchChildComponents(
|
|
|
654
655
|
node: IRNode,
|
|
655
656
|
skipConditionals = false,
|
|
656
657
|
): Array<{ name: string; slotId: string | null; props: IRProp[]; children: IRNode[] }> {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
658
|
+
return collectConditionalBranchComponentNodes(node, skipConditionals).map(c => ({
|
|
659
|
+
name: c.name,
|
|
660
|
+
slotId: c.slotId,
|
|
661
|
+
props: c.props,
|
|
662
|
+
children: c.children,
|
|
663
|
+
}))
|
|
660
664
|
}
|
|
661
665
|
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
666
|
+
/**
|
|
667
|
+
* The component nodes a conditional branch's `bindEvents` initializes —
|
|
668
|
+
* THE definition of which children a branch owns. `collectConditionalBranchChildComponents`
|
|
669
|
+
* (what the branch emits `initChild` for) and the main collector's static
|
|
670
|
+
* child-init pass (which must skip exactly these, or the child is
|
|
671
|
+
* initialized twice) both read it.
|
|
672
|
+
*/
|
|
673
|
+
export function collectConditionalBranchComponentNodes(node: IRNode, skipConditionals = false): IRComponent[] {
|
|
674
|
+
const components: IRComponent[] = []
|
|
667
675
|
// Loops never contain collected components via this walker; halting there
|
|
668
676
|
// matches the pre-walker behaviour (no 'loop' case in the switch).
|
|
669
677
|
// skipConditionals also halts at nested conditionals / if-statements.
|
|
@@ -673,16 +681,12 @@ function traverseForComponents(
|
|
|
673
681
|
walkIR(node, null, {
|
|
674
682
|
...stops,
|
|
675
683
|
component: ({ node, descend }) => {
|
|
676
|
-
components.push(
|
|
677
|
-
name: node.name,
|
|
678
|
-
slotId: node.slotId,
|
|
679
|
-
props: node.props,
|
|
680
|
-
children: node.children,
|
|
681
|
-
})
|
|
684
|
+
components.push(node)
|
|
682
685
|
// Recurse into children passed to this component.
|
|
683
686
|
descend()
|
|
684
687
|
},
|
|
685
688
|
})
|
|
689
|
+
return components
|
|
686
690
|
}
|
|
687
691
|
|
|
688
692
|
/**
|
|
@@ -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
|
}
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
toHTMLAttrName as toHtmlAttrName,
|
|
28
28
|
keyAttrName as sharedKeyAttrName,
|
|
29
29
|
} from '@barefootjs/shared'
|
|
30
|
+
import { RUNTIME_IMPORT_CANDIDATES } from './imports.ts'
|
|
30
31
|
|
|
31
32
|
export { DATA_KEY, DATA_KEY_PREFIX, DATA_BF_PH, BF_LOOP_START, BF_LOOP_END, loopStartMarker, loopEndMarker, loopItemMarker, toHtmlAttrName }
|
|
32
33
|
|
|
@@ -36,6 +37,39 @@ export { DATA_KEY, DATA_KEY_PREFIX, DATA_BF_PH, BF_LOOP_START, BF_LOOP_END, loop
|
|
|
36
37
|
*/
|
|
37
38
|
export const PROPS_PARAM = '_p'
|
|
38
39
|
|
|
40
|
+
/** Every runtime helper name a generated module may import bare (#3113). */
|
|
41
|
+
const RESERVED_RUNTIME_NAMES = new Set<string>(RUNTIME_IMPORT_CANDIDATES)
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Name of the per-component init function (`init<Name>`), consistently
|
|
45
|
+
* computed wherever it's declared, registered, called, or located for
|
|
46
|
+
* source-mapping (#3113).
|
|
47
|
+
*
|
|
48
|
+
* The naive `` `init${name}` `` collides with the runtime's own imported
|
|
49
|
+
* `initChild` whenever a component is literally named `Child` — the
|
|
50
|
+
* generated module then both `import`s `initChild` from
|
|
51
|
+
* `@barefootjs/client/runtime` (to dispatch INTO this or another child)
|
|
52
|
+
* AND `export function initChild(...)` (THIS component's own compiled
|
|
53
|
+
* init) as two top-level declarations of the same identifier, which is a
|
|
54
|
+
* hard `SyntaxError` under real ES module semantics (verified against a
|
|
55
|
+
* raw `<script type="module">` load — the same unbundled-ESM shape
|
|
56
|
+
* `bf build` ships and `fixture-host.ts`'s `'hydrate'`/`'csr-mount'` modes
|
|
57
|
+
* serve, #2481). No bundler downstream can rescue a same-module identifier
|
|
58
|
+
* collision — a bundler renames colliding identifiers ACROSS merged
|
|
59
|
+
* modules, but `import { initChild } from '...'` and
|
|
60
|
+
* `function initChild() {}` live in the SAME module and are simply invalid
|
|
61
|
+
* syntax before any bundler sees them.
|
|
62
|
+
*
|
|
63
|
+
* Trailing `$` (rather than a numeric/underscore suffix) guarantees the
|
|
64
|
+
* disambiguated name can never itself collide with a *future*
|
|
65
|
+
* `RUNTIME_IMPORT_CANDIDATES` entry — none of those are, or plausibly will
|
|
66
|
+
* be, `$`-suffixed.
|
|
67
|
+
*/
|
|
68
|
+
export function initFunctionName(componentName: string): string {
|
|
69
|
+
const name = `init${componentName}`
|
|
70
|
+
return RESERVED_RUNTIME_NAMES.has(name) ? `${name}$` : name
|
|
71
|
+
}
|
|
72
|
+
|
|
39
73
|
/**
|
|
40
74
|
* True when the component's rendered root is a comment-scoped proxy rather
|
|
41
75
|
* than an element carrying its own `bf-s`/`bf-h` scope id directly — the
|