@barefootjs/jsx 0.35.4 → 0.35.6
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/analyzer-context.d.ts +5 -4
- package/dist/analyzer-context.d.ts.map +1 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.js +5306 -4949
- package/dist/ir-to-client-js/compute-inlinability.d.ts +8 -0
- package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
- package/dist/ir-to-client-js/compute-prop-usage.d.ts +6 -0
- package/dist/ir-to-client-js/compute-prop-usage.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-event-delegation.d.ts +3 -2
- package/dist/ir-to-client-js/control-flow/plan/build-event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop.d.ts +12 -2
- 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/event-collision.d.ts +40 -0
- package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts.map +1 -0
- package/dist/ir-to-client-js/control-flow/plan/event-delegation.d.ts +13 -0
- package/dist/ir-to-client-js/control-flow/plan/event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop-delegation-index.d.ts +45 -0
- package/dist/ir-to-client-js/control-flow/plan/loop-delegation-index.d.ts.map +1 -0
- package/dist/ir-to-client-js/control-flow/plan/types.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-delegation.d.ts +12 -0
- package/dist/ir-to-client-js/control-flow/stringify/event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow.d.ts +2 -1
- package/dist/ir-to-client-js/control-flow.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts +7 -3
- package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
- package/dist/ir-to-client-js/generate-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +2 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/index.d.ts +1 -0
- package/dist/ir-to-client-js/index.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/event-handlers.d.ts +9 -1
- package/dist/ir-to-client-js/phases/event-handlers.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/props-event-handlers.d.ts +5 -0
- package/dist/ir-to-client-js/phases/props-event-handlers.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/props-extraction.d.ts +15 -13
- package/dist/ir-to-client-js/phases/props-extraction.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases.d.ts +12 -1
- package/dist/ir-to-client-js/phases.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/build-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/prune-unused-prop-extractions.d.ts +50 -0
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
- package/dist/ir-to-client-js/rewrite-destructured-props.d.ts +29 -0
- package/dist/ir-to-client-js/rewrite-destructured-props.d.ts.map +1 -0
- package/dist/ir-to-client-js/utils.d.ts +21 -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/prop-rewrite.d.ts.map +1 -1
- package/dist/props-binding.d.ts +112 -1
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/static-literal.d.ts +20 -8
- package/dist/static-literal.d.ts.map +1 -1
- package/dist/types.d.ts +38 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +31 -35
- package/src/__tests__/aliased-destructured-prop-csr.test.ts +19 -7
- package/src/__tests__/body-destructured-prop-default-propsparams.test.ts +153 -0
- package/src/__tests__/body-destructured-props-live.test.ts +245 -0
- package/src/__tests__/client-js-generation.test.ts +11 -4
- package/src/__tests__/client-only-date-lowering.test.ts +5 -2
- package/src/__tests__/destructured-from-props-localconst-value.test.ts +17 -6
- package/src/__tests__/destructured-props-live.test.ts +167 -0
- package/src/__tests__/doc-examples.test.ts +2 -4
- package/src/__tests__/event-delegation-container-collision-2930.test.ts +197 -0
- package/src/__tests__/format-error.test.ts +5 -3
- package/src/__tests__/issue-2910-mutated-const-not-inlined.test.ts +118 -0
- package/src/__tests__/issue-2910-own-scope-id-emission.test.ts +64 -0
- package/src/__tests__/live-only-props.test.ts +160 -0
- package/src/__tests__/prop-references.test.ts +26 -17
- package/src/__tests__/props-destructuring.test.ts +6 -275
- package/src/__tests__/prune-unused-prop-extractions.test.ts +11 -5
- package/src/__tests__/signal-getter-not-called.test.ts +5 -0
- package/src/__tests__/ssr-defaults.test.ts +83 -0
- package/src/__tests__/staged-ir/02-shadow-guards.test.ts +12 -5
- package/src/__tests__/static-literal.test.ts +39 -4
- package/src/analyzer-context.ts +8 -7
- package/src/analyzer.ts +233 -106
- package/src/errors.ts +7 -8
- package/src/ir-to-client-js/compute-inlinability.ts +8 -1
- package/src/ir-to-client-js/compute-prop-usage.ts +19 -0
- package/src/ir-to-client-js/control-flow/plan/build-event-delegation.ts +5 -0
- package/src/ir-to-client-js/control-flow/plan/build-loop.ts +27 -11
- package/src/ir-to-client-js/control-flow/plan/event-collision.ts +55 -0
- package/src/ir-to-client-js/control-flow/plan/event-delegation.ts +13 -0
- package/src/ir-to-client-js/control-flow/plan/loop-delegation-index.ts +79 -0
- package/src/ir-to-client-js/control-flow/plan/types.ts +2 -0
- package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +50 -10
- package/src/ir-to-client-js/control-flow.ts +68 -31
- package/src/ir-to-client-js/emit-reactive.ts +12 -8
- package/src/ir-to-client-js/emit-registration.ts +2 -2
- package/src/ir-to-client-js/generate-init.ts +22 -2
- package/src/ir-to-client-js/imports.ts +6 -0
- package/src/ir-to-client-js/index.ts +51 -3
- package/src/ir-to-client-js/phases/event-handlers.ts +10 -0
- package/src/ir-to-client-js/phases/props-event-handlers.ts +6 -0
- package/src/ir-to-client-js/phases/props-extraction.ts +29 -48
- package/src/ir-to-client-js/phases.ts +17 -3
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +6 -5
- package/src/ir-to-client-js/prop-handling.ts +9 -0
- package/src/ir-to-client-js/prune-unused-prop-extractions.ts +31 -10
- package/src/ir-to-client-js/rewrite-destructured-props.ts +210 -0
- package/src/ir-to-client-js/utils.ts +29 -1
- package/src/jsx-to-ir.ts +110 -48
- package/src/prop-rewrite.ts +11 -0
- package/src/props-binding.ts +171 -6
- package/src/ssr-defaults.ts +10 -5
- package/src/static-literal.ts +21 -9
- package/src/types.ts +38 -0
|
@@ -1211,8 +1211,6 @@ export function initReactionBarByProp(__scope, _p = {}) {
|
|
|
1211
1211
|
if (!__scope) return
|
|
1212
1212
|
const __scopeId = __scope.getAttribute('bf-s')
|
|
1213
1213
|
|
|
1214
|
-
const entries = _p.entries ?? []
|
|
1215
|
-
|
|
1216
1214
|
const [_s2] = $(__scope, 's2')
|
|
1217
1215
|
|
|
1218
1216
|
const __tpl_l0 = document.createElement('template')
|
|
@@ -1220,7 +1218,7 @@ export function initReactionBarByProp(__scope, _p = {}) {
|
|
|
1220
1218
|
const __lzp_l0 = [[0], [3]]
|
|
1221
1219
|
const __lzs_l0 = [{ id: 's0', kind: 'text', path: [] }, { id: 's1', kind: 'text', path: [] }]
|
|
1222
1220
|
const __lzsc_l0 = [{ id: 's0', kind: 'text', path: __lzp_l0[0] }, { id: 's1', kind: 'text', path: __lzp_l0[1] }]
|
|
1223
|
-
mapArrayLazy(() => entries, _s2, ([emoji, users]) => String(emoji), {
|
|
1221
|
+
mapArrayLazy(() => (_p.entries ?? []), _s2, ([emoji, users]) => String(emoji), {
|
|
1224
1222
|
createRow: (__e, __idx) => {
|
|
1225
1223
|
const __bfItem = () => __e.item
|
|
1226
1224
|
const __el = __tpl_l0.content.firstElementChild.cloneNode(true)
|
|
@@ -1449,13 +1447,11 @@ export function initSortedList(__scope, _p = {}) {
|
|
|
1449
1447
|
if (!__scope) return
|
|
1450
1448
|
const __scopeId = __scope.getAttribute('bf-s')
|
|
1451
1449
|
|
|
1452
|
-
const items = _p.items
|
|
1453
|
-
|
|
1454
1450
|
const [_s1] = $(__scope, 's1')
|
|
1455
1451
|
|
|
1456
1452
|
const __tpl_l0 = document.createElement('template')
|
|
1457
1453
|
__tpl_l0.innerHTML = \`<li data-key=""><!--bf:s0--><!--/--></li>\`
|
|
1458
|
-
mapArray(() => items.sort(byPrice), _s1, (item) => String(item.id), (item, __idx, __existing) => {
|
|
1454
|
+
mapArray(() => _p.items.sort(byPrice), _s1, (item) => String(item.id), (item, __idx, __existing) => {
|
|
1459
1455
|
const __el = __existing ?? __tpl_l0.content.firstElementChild.cloneNode(true)
|
|
1460
1456
|
const __bfw_s0 = lazySlots(__el, [{ id: 's0', kind: 'text', path: __existing ? [] : [0] }])
|
|
1461
1457
|
createEffect(() => { __bfw_s0('s0', String(item().name)) })
|
|
@@ -2643,7 +2639,7 @@ hydrate('Gallery', { init: initGallery, template: (_p) => \`<div><button bf="s0"
|
|
|
2643
2639
|
export function Gallery(_p, __bfKey) { return createComponent('Gallery', _p, __bfKey) }"
|
|
2644
2640
|
`;
|
|
2645
2641
|
|
|
2646
|
-
exports[`docs/core/reactivity/props-reactivity.md doc-examples
|
|
2642
|
+
exports[`docs/core/reactivity/props-reactivity.md doc-examples L19 — (no label) 1`] = `
|
|
2647
2643
|
"import { createComponent, hydrate } from '@barefootjs/client/runtime'
|
|
2648
2644
|
|
|
2649
2645
|
function initStatementExample() {}
|
|
@@ -2652,7 +2648,7 @@ hydrate('StatementExample', { init: initStatementExample, template: (_p) => \`<d
|
|
|
2652
2648
|
export function StatementExample(_p, __bfKey) { return createComponent('StatementExample', _p, __bfKey) }"
|
|
2653
2649
|
`;
|
|
2654
2650
|
|
|
2655
|
-
exports[`docs/core/reactivity/props-reactivity.md doc-examples
|
|
2651
|
+
exports[`docs/core/reactivity/props-reactivity.md doc-examples L36 — (no label) 1`] = `
|
|
2656
2652
|
"import { createComponent, hydrate } from '@barefootjs/client/runtime'
|
|
2657
2653
|
|
|
2658
2654
|
function initStatementExample() {}
|
|
@@ -2661,7 +2657,7 @@ hydrate('StatementExample', { init: initStatementExample, template: (_p) => \`<d
|
|
|
2661
2657
|
export function StatementExample(_p, __bfKey) { return createComponent('StatementExample', _p, __bfKey) }"
|
|
2662
2658
|
`;
|
|
2663
2659
|
|
|
2664
|
-
exports[`docs/core/reactivity/props-reactivity.md doc-examples
|
|
2660
|
+
exports[`docs/core/reactivity/props-reactivity.md doc-examples L56 — (no label) 1`] = `
|
|
2665
2661
|
"import { createComponent, hydrate } from '@barefootjs/client/runtime'
|
|
2666
2662
|
|
|
2667
2663
|
function initStatementExample() {}
|
|
@@ -2670,7 +2666,16 @@ hydrate('StatementExample', { init: initStatementExample, template: (_p) => \`<d
|
|
|
2670
2666
|
export function StatementExample(_p, __bfKey) { return createComponent('StatementExample', _p, __bfKey) }"
|
|
2671
2667
|
`;
|
|
2672
2668
|
|
|
2673
|
-
exports[`docs/core/reactivity/props-reactivity.md doc-examples
|
|
2669
|
+
exports[`docs/core/reactivity/props-reactivity.md doc-examples L74 — (no label) 1`] = `
|
|
2670
|
+
"import { createComponent, hydrate } from '@barefootjs/client/runtime'
|
|
2671
|
+
|
|
2672
|
+
function initStatementExample() {}
|
|
2673
|
+
|
|
2674
|
+
hydrate('StatementExample', { init: initStatementExample, template: (_p) => \`<div></div>\` })
|
|
2675
|
+
export function StatementExample(_p, __bfKey) { return createComponent('StatementExample', _p, __bfKey) }"
|
|
2676
|
+
`;
|
|
2677
|
+
|
|
2678
|
+
exports[`docs/core/reactivity/props-reactivity.md doc-examples L117 — Parent 1`] = `
|
|
2674
2679
|
"import { createComponent, createEffect, createSignal, escapeTextOrMarkup, escapeTextOrNode, hydrate, lazySlots, $c, initChild, renderChild } from '@barefootjs/client/runtime'
|
|
2675
2680
|
import '/* @bf-child:Child */'
|
|
2676
2681
|
|
|
@@ -2744,7 +2749,7 @@ hydrate('Example', { init: initExample, template: (_p) => \`<div>\${renderChild(
|
|
|
2744
2749
|
export function Example(_p, __bfKey) { return createComponent('Example', _p, __bfKey) }"
|
|
2745
2750
|
`;
|
|
2746
2751
|
|
|
2747
|
-
exports[`docs/core/reactivity/props-reactivity.md doc-examples
|
|
2752
|
+
exports[`docs/core/reactivity/props-reactivity.md doc-examples L120 — Compiled props object 1`] = `
|
|
2748
2753
|
"import { createComponent, createEffect, createSignal, escapeTextOrMarkup, escapeTextOrNode, hydrate, lazySlots, escapeText } from '@barefootjs/client/runtime'
|
|
2749
2754
|
|
|
2750
2755
|
export function initTodoItem(__scope, _p = {}) {
|
|
@@ -2804,11 +2809,9 @@ export function initGreeting(__scope, _p = {}) {
|
|
|
2804
2809
|
if (!__scope) return
|
|
2805
2810
|
const __scopeId = __scope.getAttribute('bf-s')
|
|
2806
2811
|
|
|
2807
|
-
const name = _p.name
|
|
2808
|
-
|
|
2809
2812
|
const __bfw_s0 = lazySlots(__scope, [{ id: 's0', kind: 'markup', path: [] }])
|
|
2810
2813
|
createEffect(() => {
|
|
2811
|
-
const __val = name
|
|
2814
|
+
const __val = _p.name
|
|
2812
2815
|
__bfw_s0('s0', escapeTextOrNode(__val))
|
|
2813
2816
|
})
|
|
2814
2817
|
|
|
@@ -4012,7 +4015,7 @@ hydrate('StatementExample', { init: initStatementExample, template: (_p) => \`<d
|
|
|
4012
4015
|
export function StatementExample(_p, __bfKey) { return createComponent('StatementExample', _p, __bfKey) }"
|
|
4013
4016
|
`;
|
|
4014
4017
|
|
|
4015
|
-
exports[`docs/core/components/props-type-safety.md doc-examples
|
|
4018
|
+
exports[`docs/core/components/props-type-safety.md doc-examples L43 — (no label) 1`] = `
|
|
4016
4019
|
"import { createComponent, hydrate } from '@barefootjs/client/runtime'
|
|
4017
4020
|
|
|
4018
4021
|
function initStatementExample() {}
|
|
@@ -4021,17 +4024,14 @@ hydrate('StatementExample', { init: initStatementExample, template: (_p) => \`<d
|
|
|
4021
4024
|
export function StatementExample(_p, __bfKey) { return createComponent('StatementExample', _p, __bfKey) }"
|
|
4022
4025
|
`;
|
|
4023
4026
|
|
|
4024
|
-
exports[`docs/core/components/props-type-safety.md doc-examples
|
|
4027
|
+
exports[`docs/core/components/props-type-safety.md doc-examples L55 — (no label) 1`] = `
|
|
4025
4028
|
"import { $, applyRestAttrs, createComponent, createEffect, escapeAttr, hydrate, markupOrEmpty } from '@barefootjs/client/runtime'
|
|
4026
4029
|
|
|
4027
4030
|
|
|
4028
4031
|
export function initButton(__scope, _p = {}) {
|
|
4029
4032
|
if (!__scope) return
|
|
4030
4033
|
const __scopeId = __scope.getAttribute('bf-s')
|
|
4031
|
-
|
|
4032
|
-
const variant = _p.variant ?? 'default'
|
|
4033
|
-
const size = _p.size ?? 'md'
|
|
4034
|
-
const classes = \`btn btn-\${variant} btn-\${size} \${_p.className ?? ''}\`
|
|
4034
|
+
const classes = \`btn btn-\${(_p.variant ?? 'default')} btn-\${(_p.size ?? 'md')} \${_p.className ?? ''}\`
|
|
4035
4035
|
|
|
4036
4036
|
const [_s0] = $(__scope, 's0')
|
|
4037
4037
|
|
|
@@ -4054,7 +4054,7 @@ hydrate('Button__b3c36eee', { init: initButton, template: (_p) => \`<button \${(
|
|
|
4054
4054
|
export function Button(_p, __bfKey) { return createComponent('Button__b3c36eee', _p, __bfKey) }"
|
|
4055
4055
|
`;
|
|
4056
4056
|
|
|
4057
|
-
exports[`docs/core/components/props-type-safety.md doc-examples
|
|
4057
|
+
exports[`docs/core/components/props-type-safety.md doc-examples L79 — (no label) 1`] = `
|
|
4058
4058
|
"import { createComponent, hydrate } from '@barefootjs/client/runtime'
|
|
4059
4059
|
|
|
4060
4060
|
function initStatementExample() {}
|
|
@@ -4063,7 +4063,7 @@ hydrate('StatementExample', { init: initStatementExample, template: (_p) => \`<d
|
|
|
4063
4063
|
export function StatementExample(_p, __bfKey) { return createComponent('StatementExample', _p, __bfKey) }"
|
|
4064
4064
|
`;
|
|
4065
4065
|
|
|
4066
|
-
exports[`docs/core/components/props-type-safety.md doc-examples
|
|
4066
|
+
exports[`docs/core/components/props-type-safety.md doc-examples L90 — (no label) 1`] = `
|
|
4067
4067
|
"import { createComponent, createEffect, createSignal, escapeTextOrMarkup, escapeTextOrNode, hydrate, lazySlots, $c, initChild, renderChild } from '@barefootjs/client/runtime'
|
|
4068
4068
|
import '/* @bf-child:Card */'
|
|
4069
4069
|
|
|
@@ -4196,20 +4196,18 @@ export function initProductPage(__scope, _p = {}) {
|
|
|
4196
4196
|
if (!__scope) return
|
|
4197
4197
|
const __scopeId = __scope.getAttribute('bf-s')
|
|
4198
4198
|
|
|
4199
|
-
const product = _p.product ?? {}
|
|
4200
|
-
|
|
4201
4199
|
const [_s4] = $(__scope, 's4')
|
|
4202
4200
|
const [_s5, _s6] = $c(__scope, 's5', 's6')
|
|
4203
4201
|
|
|
4204
4202
|
const __bfw_s0 = lazySlots(__scope, [{ id: 's0', kind: 'markup', path: [] }])
|
|
4205
4203
|
createEffect(() => {
|
|
4206
|
-
const __val = product.name
|
|
4204
|
+
const __val = (_p.product ?? {}).name
|
|
4207
4205
|
__bfw_s0('s0', escapeTextOrNode(__val))
|
|
4208
4206
|
})
|
|
4209
4207
|
|
|
4210
4208
|
const __bfw_s2 = lazySlots(__scope, [{ id: 's2', kind: 'markup', path: [] }])
|
|
4211
4209
|
createEffect(() => {
|
|
4212
|
-
const __val = product.description
|
|
4210
|
+
const __val = (_p.product ?? {}).description
|
|
4213
4211
|
__bfw_s2('s2', escapeTextOrNode(__val))
|
|
4214
4212
|
})
|
|
4215
4213
|
|
|
@@ -4230,7 +4228,7 @@ export function initProductPage(__scope, _p = {}) {
|
|
|
4230
4228
|
createEffect(() => {
|
|
4231
4229
|
const [__ReviewStars_s5El] = $c(__scope, 's5')
|
|
4232
4230
|
if (__ReviewStars_s5El) {
|
|
4233
|
-
{ const __x = product.rating
|
|
4231
|
+
{ const __x = (_p.product ?? {}).rating
|
|
4234
4232
|
if (!(0 in __l) || !Object.is(__l[0], __x)) {
|
|
4235
4233
|
{ const __v = __x; if (__v != null) __ReviewStars_s5El.setAttribute('rating', String(__v)); else __ReviewStars_s5El.removeAttribute('rating') }
|
|
4236
4234
|
}
|
|
@@ -4238,7 +4236,7 @@ export function initProductPage(__scope, _p = {}) {
|
|
|
4238
4236
|
}
|
|
4239
4237
|
const [__AddToCart_s6El] = $c(__scope, 's6')
|
|
4240
4238
|
if (__AddToCart_s6El) {
|
|
4241
|
-
{ const __x = product.id
|
|
4239
|
+
{ const __x = (_p.product ?? {}).id
|
|
4242
4240
|
if (!(1 in __l) || !Object.is(__l[1], __x)) {
|
|
4243
4241
|
{ const __v = __x; if (__v != null) __AddToCart_s6El.setAttribute('productId', String(__v)); else __AddToCart_s6El.removeAttribute('productId') }
|
|
4244
4242
|
}
|
|
@@ -4247,8 +4245,8 @@ export function initProductPage(__scope, _p = {}) {
|
|
|
4247
4245
|
}) }
|
|
4248
4246
|
|
|
4249
4247
|
// Initialize child components with props
|
|
4250
|
-
initChild('ReviewStars', _s5, { get rating() { return product.rating } })
|
|
4251
|
-
initChild('AddToCart', _s6, { get productId() { return product.id } })
|
|
4248
|
+
initChild('ReviewStars', _s5, { get rating() { return (_p.product ?? {}).rating } })
|
|
4249
|
+
initChild('AddToCart', _s6, { get productId() { return (_p.product ?? {}).id } })
|
|
4252
4250
|
}
|
|
4253
4251
|
|
|
4254
4252
|
hydrate('ProductPage', { init: initProductPage, template: (_p) => \`<div><h1 bf="s1"><!--bf:s0-->\${escapeTextOrMarkup(_p.product.name)}<!--/--></h1><p bf="s3"><!--bf:s2-->\${escapeTextOrMarkup(_p.product.description)}<!--/--></p><img \${(_p.product.image) != null ? 'src="' + escapeAttr(_p.product.image) + '"' : ''} bf="s4" />\${renderChild('ReviewStars', {rating: _p.product.rating}, undefined, 's5')}\${renderChild('AddToCart', {productId: _p.product.id}, undefined, 's6')}</div>\` })
|
|
@@ -4898,11 +4896,9 @@ export function initTodoList(__scope, _p = {}) {
|
|
|
4898
4896
|
if (!__scope) return
|
|
4899
4897
|
const __scopeId = __scope.getAttribute('bf-s')
|
|
4900
4898
|
|
|
4901
|
-
const items = _p.items ?? []
|
|
4902
|
-
|
|
4903
4899
|
const [_s1] = $(__scope, 's1')
|
|
4904
4900
|
|
|
4905
|
-
mapArray(() => items, _s1, (item) => String(item.id), (item, __idx, __existing) => {
|
|
4901
|
+
mapArray(() => (_p.items ?? []), _s1, (item) => String(item.id), (item, __idx, __existing) => {
|
|
4906
4902
|
if (__existing) { initChild('TodoItem', __existing, { get "..."() { return item() } }); return __existing }
|
|
4907
4903
|
return createComponent('TodoItem', { get "..."() { return item() } }, item().id)
|
|
4908
4904
|
}, 'l0')
|
|
@@ -5243,7 +5239,7 @@ hydrate('Example', { init: initExample, template: (_p) => \`<div bf="s1"><!--bf-
|
|
|
5243
5239
|
export function Example(_p, __bfKey) { return createComponent('Example', _p, __bfKey) }"
|
|
5244
5240
|
`;
|
|
5245
5241
|
|
|
5246
|
-
exports[`docs/core/advanced/compiler-internals.md doc-examples
|
|
5242
|
+
exports[`docs/core/advanced/compiler-internals.md doc-examples L141 — (no label) 1`] = `
|
|
5247
5243
|
"import { createComponent, createEffect, createSignal, escapeTextOrMarkup, escapeTextOrNode, hydrate, lazySlots, $, escapeAttr, escapeText, mapArrayLazy, textOrNode } from '@barefootjs/client/runtime'
|
|
5248
5244
|
|
|
5249
5245
|
export function initTodoItem(__scope, _p = {}) {
|
|
@@ -5324,7 +5320,7 @@ hydrate('Example', { init: initExample, template: (_p) => \`<div bf="s1"><!--bf-
|
|
|
5324
5320
|
export function Example(_p, __bfKey) { return createComponent('Example', _p, __bfKey) }"
|
|
5325
5321
|
`;
|
|
5326
5322
|
|
|
5327
|
-
exports[`docs/core/advanced/compiler-internals.md doc-examples
|
|
5323
|
+
exports[`docs/core/advanced/compiler-internals.md doc-examples L195 — (no label) 1`] = `
|
|
5328
5324
|
"import { createComponent, hydrate } from '@barefootjs/client/runtime'
|
|
5329
5325
|
|
|
5330
5326
|
function initStatementExample() {}
|
|
@@ -9,8 +9,12 @@
|
|
|
9
9
|
* (the caller passes `n`) and the local binding hydrated to `undefined`.
|
|
10
10
|
*
|
|
11
11
|
* Mirrors `ssr-defaults.test.ts`'s aliased-prop describes (#2460) for the
|
|
12
|
-
* SSR-defaults half; this covers the generated `initXxx`
|
|
13
|
-
*
|
|
12
|
+
* SSR-defaults half; this covers the generated `initXxx` body and the CSR
|
|
13
|
+
* `template:` lambda.
|
|
14
|
+
*
|
|
15
|
+
* The rule pinned here is the caller-facing key: `_p` is keyed by
|
|
16
|
+
* `sourceName ?? name`, read at every reference site (there is no
|
|
17
|
+
* captured-once `const <local> = _p.<callerKey>` extraction).
|
|
14
18
|
*/
|
|
15
19
|
|
|
16
20
|
import { describe, test, expect } from 'bun:test'
|
|
@@ -37,10 +41,11 @@ describe('aliased destructured props reach client JS under the caller-facing key
|
|
|
37
41
|
|
|
38
42
|
const clientJs = result.files.find((f) => f.type === 'clientJs')
|
|
39
43
|
expect(clientJs).toBeDefined()
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
expect(clientJs!.content).toContain('const count =
|
|
44
|
+
// Every reference reads the CALLER-facing key `n`, never the local
|
|
45
|
+
// key `count`, and no local binding is introduced for it.
|
|
46
|
+
expect(clientJs!.content).not.toContain('const count = ')
|
|
43
47
|
expect(clientJs!.content).not.toContain('_p.count')
|
|
48
|
+
expect(clientJs!.content).toContain('console.log(_p.n)')
|
|
44
49
|
// The CSR `template:` lambda (module-scope SSR fallback) reads the
|
|
45
50
|
// same caller-facing key.
|
|
46
51
|
// `escapeTextOrMarkup`, not bare `escapeText` — this slot is
|
|
@@ -68,7 +73,11 @@ describe('aliased destructured props reach client JS under the caller-facing key
|
|
|
68
73
|
|
|
69
74
|
const clientJs = result.files.find((f) => f.type === 'clientJs')
|
|
70
75
|
expect(clientJs).toBeDefined()
|
|
71
|
-
|
|
76
|
+
// `sourceName ?? name` is an identity for an un-aliased prop, so this
|
|
77
|
+
// is indistinguishable from the aliased case above once the
|
|
78
|
+
// caller-facing key is substituted.
|
|
79
|
+
expect(clientJs!.content).not.toContain('const n = ')
|
|
80
|
+
expect(clientJs!.content).toContain('console.log(_p.n)')
|
|
72
81
|
// `escapeTextOrMarkup`, not bare `escapeText` — this slot is
|
|
73
82
|
// claim-plan `kind: 'markup'` (#2651), unrelated to the #2524 aliasing
|
|
74
83
|
// concern this test pins; only the escape call's name changed.
|
|
@@ -112,7 +121,10 @@ describe('aliased destructured props reach client JS under the caller-facing key
|
|
|
112
121
|
|
|
113
122
|
const clientJs = result.files.find((f) => f.type === 'clientJs')
|
|
114
123
|
expect(clientJs).toBeDefined()
|
|
115
|
-
|
|
124
|
+
// The handler reference reads the CALLER-facing key `onPress`, never
|
|
125
|
+
// the local key `handlePress`.
|
|
126
|
+
expect(clientJs!.content).not.toContain('const handlePress = ')
|
|
127
|
+
expect(clientJs!.content).toContain('_p.onPress')
|
|
116
128
|
expect(clientJs!.content).not.toContain('_p.handlePress')
|
|
117
129
|
})
|
|
118
130
|
})
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pins #2943's fix: a BODY-destructured prop's default (`const { label =
|
|
3
|
+
* 'none' } = props`) is now visible on `ir.metadata.propsParams` itself —
|
|
4
|
+
* the SAME shared `ParamInfo` a parameter-destructured default
|
|
5
|
+
* (`function Foo({ label = 'none' })`) already populated via
|
|
6
|
+
* `extractPropsFromTypeMembers`'s sibling path. Before this fix,
|
|
7
|
+
* `extractPropsFromTypeMembers` built `propsParams` purely from the TYPE
|
|
8
|
+
* annotation, with no notion of a body destructure's own default — every
|
|
9
|
+
* downstream SSR consumer of `ParamInfo.defaultValue`/`.optional` (each
|
|
10
|
+
* template adapter's presence-guard classification, `extractSsrDefaults`'s
|
|
11
|
+
* stash seed) then treated the prop as defaultless, guarding the attribute
|
|
12
|
+
* and omitting it entirely instead of falling back to the default the way
|
|
13
|
+
* Hono's real JS destructuring naturally does.
|
|
14
|
+
*
|
|
15
|
+
* See `analyzer.ts`'s `collectConstant` (the body-destructure branch) and
|
|
16
|
+
* `bindingElementDefaultFields` (the helper it now shares with the
|
|
17
|
+
* parameter-destructured path in `extractProps`).
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { describe, test, expect } from 'bun:test'
|
|
21
|
+
import { analyzeComponent } from '../analyzer'
|
|
22
|
+
import { buildMetadata } from '../compiler'
|
|
23
|
+
|
|
24
|
+
function propsParamsFor(source: string) {
|
|
25
|
+
const ctx = analyzeComponent(source, 'test.tsx')
|
|
26
|
+
return buildMetadata(ctx).propsParams
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe('body-destructured prop defaults overlay onto propsParams (#2943)', () => {
|
|
30
|
+
test('unrenamed default: the type-member entry gets defaultValue/parsed/optional', () => {
|
|
31
|
+
const propsParams = propsParamsFor(`
|
|
32
|
+
function Foo(props: { label?: string }) {
|
|
33
|
+
const { label = 'none' } = props
|
|
34
|
+
return <div data-label={label} />
|
|
35
|
+
}
|
|
36
|
+
`)
|
|
37
|
+
expect(propsParams).toEqual([
|
|
38
|
+
{
|
|
39
|
+
name: 'label',
|
|
40
|
+
type: { kind: 'primitive', raw: 'string', primitive: 'string' },
|
|
41
|
+
optional: true,
|
|
42
|
+
defaultValue: "'none'",
|
|
43
|
+
parsed: { kind: 'literal', value: 'none', literalType: 'string' },
|
|
44
|
+
},
|
|
45
|
+
])
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('renamed default: ADDS a second entry (sourceName-bearing) rather than replacing the original', () => {
|
|
49
|
+
// `label` itself stays a real, separately-classified binding (no
|
|
50
|
+
// default of its own — a bare `props.label` read elsewhere is still
|
|
51
|
+
// correctly guarded/stash-seeded), and `text` carries `sourceName:
|
|
52
|
+
// 'label'` so every `sourceName ?? name` consumer resolves the
|
|
53
|
+
// caller-facing key.
|
|
54
|
+
const propsParams = propsParamsFor(`
|
|
55
|
+
function Foo(props: { label?: string }) {
|
|
56
|
+
const { label: text = 'none' } = props
|
|
57
|
+
return <div data-label={text} />
|
|
58
|
+
}
|
|
59
|
+
`)
|
|
60
|
+
expect(propsParams).toHaveLength(2)
|
|
61
|
+
expect(propsParams.find(p => p.name === 'label')).toEqual({
|
|
62
|
+
name: 'label',
|
|
63
|
+
type: { kind: 'primitive', raw: 'string', primitive: 'string' },
|
|
64
|
+
optional: true,
|
|
65
|
+
})
|
|
66
|
+
expect(propsParams.find(p => p.name === 'text')).toEqual({
|
|
67
|
+
name: 'text',
|
|
68
|
+
type: { kind: 'primitive', raw: 'string', primitive: 'string' },
|
|
69
|
+
optional: true,
|
|
70
|
+
sourceName: 'label',
|
|
71
|
+
defaultValue: "'none'",
|
|
72
|
+
parsed: { kind: 'literal', value: 'none', literalType: 'string' },
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('untyped `props` param: synthesizes a propsParams entry with `type: unknown` (matching the parameter form\'s own fallback)', () => {
|
|
77
|
+
const propsParams = propsParamsFor(`
|
|
78
|
+
function Foo(props) {
|
|
79
|
+
const { label = 'none' } = props
|
|
80
|
+
return <div data-label={label} />
|
|
81
|
+
}
|
|
82
|
+
`)
|
|
83
|
+
expect(propsParams).toEqual([
|
|
84
|
+
{
|
|
85
|
+
name: 'label',
|
|
86
|
+
type: { kind: 'unknown', raw: 'unknown' },
|
|
87
|
+
optional: true,
|
|
88
|
+
defaultValue: "'none'",
|
|
89
|
+
parsed: { kind: 'literal', value: 'none', literalType: 'string' },
|
|
90
|
+
},
|
|
91
|
+
])
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('arrow-function default (#2940): defaultContainsArrow is set and `parsed` is a real structured arrow, not a truncated re-parse', () => {
|
|
95
|
+
const propsParams = propsParamsFor(`
|
|
96
|
+
function Foo(props: { fmt?: (v: number) => string }) {
|
|
97
|
+
const { fmt = (v) => 'v' + v } = props
|
|
98
|
+
return <div>{fmt(1)}</div>
|
|
99
|
+
}
|
|
100
|
+
`)
|
|
101
|
+
expect(propsParams).toHaveLength(1)
|
|
102
|
+
const fmt = propsParams[0]!
|
|
103
|
+
expect(fmt.name).toBe('fmt')
|
|
104
|
+
expect(fmt.optional).toBe(true)
|
|
105
|
+
expect(fmt.defaultValue).toBe("(v) => 'v' + v")
|
|
106
|
+
expect(fmt.defaultContainsArrow).toBe(true)
|
|
107
|
+
expect(fmt.parsed?.kind).toBe('arrow')
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test('renamed, NO default (#2788 shape, unaffected): still just one propsParams entry — no `kids` synthesized', () => {
|
|
111
|
+
// Defaultless renames stay on the pre-existing #2788 path
|
|
112
|
+
// (`resolveBodyDestructuredPropAliases`'s SSR-stash local-name-seeding
|
|
113
|
+
// safety net) — this fix's overlay only fires when `el.initializer`
|
|
114
|
+
// is present, so it must never duplicate that mechanism's work.
|
|
115
|
+
const propsParams = propsParamsFor(`
|
|
116
|
+
function Foo(props: { children?: string }) {
|
|
117
|
+
const { children: kids } = props
|
|
118
|
+
return <span>{kids}</span>
|
|
119
|
+
}
|
|
120
|
+
`)
|
|
121
|
+
expect(propsParams).toEqual([
|
|
122
|
+
{
|
|
123
|
+
name: 'children',
|
|
124
|
+
type: { kind: 'primitive', raw: 'string', primitive: 'string' },
|
|
125
|
+
optional: true,
|
|
126
|
+
},
|
|
127
|
+
])
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('a `let` binding still gets the default overlaid — the default is a declaration-time fact, independent of live-rewrite safety', () => {
|
|
131
|
+
// Unlike `resolveBodyPropAliases`'s `requireLiveRewriteSafe` gate
|
|
132
|
+
// (which excludes `let`/mutated locals because turning them into a
|
|
133
|
+
// LIVE `_p.X` read could silently write through to the caller's
|
|
134
|
+
// prop), a static SSR default has no such hazard — it describes what
|
|
135
|
+
// the source looked like at its own declaration line, nothing more.
|
|
136
|
+
const propsParams = propsParamsFor(`
|
|
137
|
+
function Foo(props: { label?: string }) {
|
|
138
|
+
let { label = 'none' } = props
|
|
139
|
+
label = label.toUpperCase()
|
|
140
|
+
return <div data-label={label} />
|
|
141
|
+
}
|
|
142
|
+
`)
|
|
143
|
+
expect(propsParams).toEqual([
|
|
144
|
+
{
|
|
145
|
+
name: 'label',
|
|
146
|
+
type: { kind: 'primitive', raw: 'string', primitive: 'string' },
|
|
147
|
+
optional: true,
|
|
148
|
+
defaultValue: "'none'",
|
|
149
|
+
parsed: { kind: 'literal', value: 'none', literalType: 'string' },
|
|
150
|
+
},
|
|
151
|
+
])
|
|
152
|
+
})
|
|
153
|
+
})
|