@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
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authored `formatDate` call refusal (BF056, #3089).
|
|
3
|
+
*
|
|
4
|
+
* `formatDate` is compiler ABI — the lowering target of the
|
|
5
|
+
* `.toLocaleDateString(locale, { timeZone, ... })` sugar — never an
|
|
6
|
+
* authored API. `checkAuthoredFormatDateCalls` (format-date-refusal.ts) is
|
|
7
|
+
* wired into `compileJSX`, so these tests go through it directly, same as
|
|
8
|
+
* `rich-type-method-refusal.test.ts`.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, test, expect } from 'bun:test'
|
|
12
|
+
import { compileJSX } from '../compiler'
|
|
13
|
+
import { ErrorCodes } from '../errors'
|
|
14
|
+
import { TestAdapter } from '../adapters/test-adapter'
|
|
15
|
+
|
|
16
|
+
const adapter = new TestAdapter()
|
|
17
|
+
|
|
18
|
+
function bf056(source: string, filePath = 'Test.tsx') {
|
|
19
|
+
const result = compileJSX(source, filePath, { adapter })
|
|
20
|
+
return result.errors.filter((e) => e.code === ErrorCodes.FORMAT_DATE_AUTHORED_CALL)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('authored formatDate call refusal — fires (BF056)', () => {
|
|
24
|
+
test('text-position call', () => {
|
|
25
|
+
const errors = bf056(`
|
|
26
|
+
import { formatDate } from '@barefootjs/client'
|
|
27
|
+
export function Foo({ createdAt }: { createdAt: Date }) {
|
|
28
|
+
return <div>{formatDate(createdAt, 'YYYY-MM-DD')}</div>
|
|
29
|
+
}
|
|
30
|
+
`)
|
|
31
|
+
expect(errors.length).toBe(1)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('attribute-position call', () => {
|
|
35
|
+
const errors = bf056(`
|
|
36
|
+
import { formatDate } from '@barefootjs/client'
|
|
37
|
+
export function Foo({ createdAt }: { createdAt: Date }) {
|
|
38
|
+
return <div title={formatDate(createdAt, 'YYYY-MM-DD')} />
|
|
39
|
+
}
|
|
40
|
+
`)
|
|
41
|
+
expect(errors.length).toBe(1)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('ternary-consequent inside a structured template attribute', () => {
|
|
45
|
+
const errors = bf056(`
|
|
46
|
+
import { formatDate } from '@barefootjs/client'
|
|
47
|
+
export function Foo({ ok, createdAt }: { ok: boolean; createdAt: Date }) {
|
|
48
|
+
return <div title={ok ? formatDate(createdAt, 'YYYY-MM-DD') : 'n/a'} />
|
|
49
|
+
}
|
|
50
|
+
`)
|
|
51
|
+
expect(errors.length).toBe(1)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('imported via the /runtime subpath', () => {
|
|
55
|
+
const errors = bf056(`
|
|
56
|
+
import { formatDate } from '@barefootjs/client/runtime'
|
|
57
|
+
export function Foo({ createdAt }: { createdAt: Date }) {
|
|
58
|
+
return <div>{formatDate(createdAt, 'YYYY-MM-DD')}</div>
|
|
59
|
+
}
|
|
60
|
+
`)
|
|
61
|
+
expect(errors.length).toBe(1)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('aliased import', () => {
|
|
65
|
+
const errors = bf056(`
|
|
66
|
+
import { formatDate as fd } from '@barefootjs/client'
|
|
67
|
+
export function Foo({ createdAt }: { createdAt: Date }) {
|
|
68
|
+
return <div>{fd(createdAt, 'YYYY-MM-DD')}</div>
|
|
69
|
+
}
|
|
70
|
+
`)
|
|
71
|
+
expect(errors.length).toBe(1)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('nested inside a loop row', () => {
|
|
75
|
+
const errors = bf056(`
|
|
76
|
+
import { formatDate } from '@barefootjs/client'
|
|
77
|
+
export function Foo({ items }: { items: Date[] }) {
|
|
78
|
+
return <ul>{items.map((d, i) => <li key={i}>{formatDate(d, 'YYYY-MM-DD')}</li>)}</ul>
|
|
79
|
+
}
|
|
80
|
+
`)
|
|
81
|
+
expect(errors.length).toBe(1)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('two distinct call sites both fire (dedup is per-location, not per-file)', () => {
|
|
85
|
+
const errors = bf056(`
|
|
86
|
+
import { formatDate } from '@barefootjs/client'
|
|
87
|
+
export function Foo({ a, b }: { a: Date; b: Date }) {
|
|
88
|
+
return <div>{formatDate(a, 'YYYY-MM-DD')}{formatDate(b, 'YYYY-MM-DD')}</div>
|
|
89
|
+
}
|
|
90
|
+
`)
|
|
91
|
+
expect(errors.length).toBe(2)
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
describe('authored formatDate call refusal — silent (no BF056)', () => {
|
|
96
|
+
test('/* @client */ defers the read', () => {
|
|
97
|
+
const errors = bf056(`
|
|
98
|
+
'use client'
|
|
99
|
+
import { formatDate } from '@barefootjs/client'
|
|
100
|
+
export function Foo({ createdAt }: { createdAt: Date }) {
|
|
101
|
+
return <div>{/* @client */ formatDate(createdAt, 'YYYY-MM-DD')}</div>
|
|
102
|
+
}
|
|
103
|
+
`)
|
|
104
|
+
expect(errors.length).toBe(0)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('a same-named local helper NOT imported from @barefootjs/client is untouched', () => {
|
|
108
|
+
const errors = bf056(`
|
|
109
|
+
function formatDate(d: Date, p: string) { return d.toISOString() }
|
|
110
|
+
export function Foo({ createdAt }: { createdAt: Date }) {
|
|
111
|
+
return <div>{formatDate(createdAt, 'YYYY-MM-DD')}</div>
|
|
112
|
+
}
|
|
113
|
+
`)
|
|
114
|
+
expect(errors.length).toBe(0)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
test('the sanctioned toLocaleDateString sugar is untouched', () => {
|
|
118
|
+
const errors = bf056(`
|
|
119
|
+
export function Foo({ createdAt }: { createdAt: Date }) {
|
|
120
|
+
return <div>{createdAt.toLocaleDateString('en-US', { timeZone: 'UTC' })}</div>
|
|
121
|
+
}
|
|
122
|
+
`)
|
|
123
|
+
expect(errors.length).toBe(0)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
test('no formatDate import at all', () => {
|
|
127
|
+
const errors = bf056(`
|
|
128
|
+
export function Foo({ createdAt }: { createdAt: Date }) {
|
|
129
|
+
return <div>{createdAt.toISOString()}</div>
|
|
130
|
+
}
|
|
131
|
+
`)
|
|
132
|
+
expect(errors.length).toBe(0)
|
|
133
|
+
})
|
|
134
|
+
})
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostic tests for BF029 (#3063).
|
|
3
|
+
*
|
|
4
|
+
* A `'use client'` component with an early-return branch whose OTHER
|
|
5
|
+
* branch is wrapped in a bare fragment (`return <>…</>`) is never fully
|
|
6
|
+
* hydrated: `ComponentDef`'s `comment` / `fragmentRoot` flags
|
|
7
|
+
* (`emit-registration.ts`) are decided once per component from
|
|
8
|
+
* `ir.root.type === 'if-statement'`, which can't say "branch A needs the
|
|
9
|
+
* comment-scope boundary, branch B doesn't" — so hydration never claims
|
|
10
|
+
* the fragment-wrapped branch's root (SSR and a fresh CSR mount are both
|
|
11
|
+
* correct; only claiming existing SSR markup during hydrate misses it).
|
|
12
|
+
* Fail loud at compile time instead of shipping a branch whose events
|
|
13
|
+
* silently never bind, with a `/* @client *\/` escape for the case an author
|
|
14
|
+
* accepts the known gap.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { describe, test, expect } from 'bun:test'
|
|
18
|
+
import { compileJSX } from '../compiler'
|
|
19
|
+
import { TestAdapter } from '../adapters/test-adapter'
|
|
20
|
+
import { ErrorCodes } from '../errors'
|
|
21
|
+
|
|
22
|
+
const adapter = new TestAdapter()
|
|
23
|
+
|
|
24
|
+
function findBF029(errors: ReturnType<typeof compileJSX>['errors']) {
|
|
25
|
+
return errors.filter(e => e.code === ErrorCodes.FRAGMENT_WRAPPED_CONDITIONAL_RETURN_BRANCH)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('BF029 — fragment-wrapped branch of a conditional return', () => {
|
|
29
|
+
test('fires when the final (else) branch is a bare fragment', () => {
|
|
30
|
+
const source = `
|
|
31
|
+
'use client'
|
|
32
|
+
import { createSignal } from '@barefootjs/client'
|
|
33
|
+
|
|
34
|
+
export function ConditionalReturnFragmentBranch(props: { x: boolean }) {
|
|
35
|
+
const [count, setCount] = createSignal(0)
|
|
36
|
+
if (props.x) return <a>link</a>
|
|
37
|
+
return <><button onClick={() => setCount(count() + 1)}>button: {count()}</button></>
|
|
38
|
+
}
|
|
39
|
+
`
|
|
40
|
+
const result = compileJSX(source, 'ConditionalReturnFragmentBranch.tsx', { adapter })
|
|
41
|
+
const matches = findBF029(result.errors)
|
|
42
|
+
expect(matches).toHaveLength(1)
|
|
43
|
+
expect(matches[0].severity).toBe('error')
|
|
44
|
+
expect(matches[0].message).toContain('/* @client */')
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('fires when a non-final (if) branch is a bare fragment', () => {
|
|
48
|
+
const source = `
|
|
49
|
+
'use client'
|
|
50
|
+
import { createSignal } from '@barefootjs/client'
|
|
51
|
+
|
|
52
|
+
export function IfBranchFragment(props: { x: boolean }) {
|
|
53
|
+
const [count, setCount] = createSignal(0)
|
|
54
|
+
if (props.x) {
|
|
55
|
+
return <><button onClick={() => setCount(count() + 1)}>button: {count()}</button></>
|
|
56
|
+
}
|
|
57
|
+
return <a>link</a>
|
|
58
|
+
}
|
|
59
|
+
`
|
|
60
|
+
const result = compileJSX(source, 'IfBranchFragment.tsx', { adapter })
|
|
61
|
+
expect(findBF029(result.errors)).toHaveLength(1)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('does not fire when every branch is a bare element (no fragment)', () => {
|
|
65
|
+
const source = `
|
|
66
|
+
'use client'
|
|
67
|
+
import { createSignal } from '@barefootjs/client'
|
|
68
|
+
|
|
69
|
+
export function AllElements(props: { x: boolean }) {
|
|
70
|
+
const [count, setCount] = createSignal(0)
|
|
71
|
+
if (props.x) return <a>link</a>
|
|
72
|
+
return <button onClick={() => setCount(count() + 1)}>button: {count()}</button>
|
|
73
|
+
}
|
|
74
|
+
`
|
|
75
|
+
const result = compileJSX(source, 'AllElements.tsx', { adapter })
|
|
76
|
+
expect(findBF029(result.errors)).toHaveLength(0)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('does not fire for a non-"use client" component whose fragment branch renders no child component', () => {
|
|
80
|
+
const source = `
|
|
81
|
+
export function StaticFragmentBranch(props: { x: boolean }) {
|
|
82
|
+
if (props.x) return <a>link</a>
|
|
83
|
+
return <><span>static</span></>
|
|
84
|
+
}
|
|
85
|
+
`
|
|
86
|
+
const result = compileJSX(source, 'StaticFragmentBranch.tsx', { adapter })
|
|
87
|
+
expect(findBF029(result.errors)).toHaveLength(0)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('fires for a non-"use client" component whose fragment branch renders a child component', () => {
|
|
91
|
+
// The parent still gets `needsInit` and an `initChild` for the child,
|
|
92
|
+
// which only runs if hydration claims this branch's scope.
|
|
93
|
+
const source = `
|
|
94
|
+
import { Counter } from './counter'
|
|
95
|
+
|
|
96
|
+
export function ChildInFragmentBranch(props: { x: boolean }) {
|
|
97
|
+
if (props.x) return <a>link</a>
|
|
98
|
+
return <><Counter /><span>x</span></>
|
|
99
|
+
}
|
|
100
|
+
`
|
|
101
|
+
const result = compileJSX(source, 'ChildInFragmentBranch.tsx', { adapter })
|
|
102
|
+
expect(findBF029(result.errors)).toHaveLength(1)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('does not fire for a non-"use client" component whose child component sits only in a non-fragment branch', () => {
|
|
106
|
+
const source = `
|
|
107
|
+
import { Counter } from './counter'
|
|
108
|
+
|
|
109
|
+
export function ChildInElementBranch(props: { x: boolean }) {
|
|
110
|
+
if (props.x) return <div><Counter /></div>
|
|
111
|
+
return <><span>static</span></>
|
|
112
|
+
}
|
|
113
|
+
`
|
|
114
|
+
const result = compileJSX(source, 'ChildInElementBranch.tsx', { adapter })
|
|
115
|
+
expect(findBF029(result.errors)).toHaveLength(0)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
test('/* @client */ immediately before the fragment escapes the refusal', () => {
|
|
119
|
+
const source = `
|
|
120
|
+
'use client'
|
|
121
|
+
import { createSignal } from '@barefootjs/client'
|
|
122
|
+
|
|
123
|
+
export function EscapedFragmentBranch(props: { x: boolean }) {
|
|
124
|
+
const [count, setCount] = createSignal(0)
|
|
125
|
+
if (props.x) return <a>link</a>
|
|
126
|
+
return /* @client */ <><button onClick={() => setCount(count() + 1)}>button: {count()}</button></>
|
|
127
|
+
}
|
|
128
|
+
`
|
|
129
|
+
const result = compileJSX(source, 'EscapedFragmentBranch.tsx', { adapter })
|
|
130
|
+
expect(findBF029(result.errors)).toHaveLength(0)
|
|
131
|
+
})
|
|
132
|
+
})
|
|
@@ -90,7 +90,15 @@ describe('hydrate() template generation for signal-bearing components', () => {
|
|
|
90
90
|
// Stateless Child gets a static template (always useful).
|
|
91
91
|
// Non-exported helpers are file-scoped (`Child__<hash>`) so they
|
|
92
92
|
// cannot collide with same-named components in other modules.
|
|
93
|
-
|
|
93
|
+
//
|
|
94
|
+
// The init function is `initChild$`, not `initChild` (#3113):
|
|
95
|
+
// `Child` reactively mirrors the parent's signal into a slot, so this
|
|
96
|
+
// module also imports the RUNTIME's own `initChild` (to dispatch props
|
|
97
|
+
// into a mounted child); a bare `init${name}` here would declare a
|
|
98
|
+
// SECOND top-level `initChild` binding in the same module, which is a
|
|
99
|
+
// hard `SyntaxError` under real ES module semantics — see
|
|
100
|
+
// `initFunctionName`'s docstring (`ir-to-client-js/utils.ts`).
|
|
101
|
+
expect(content).toMatch(/hydrate\('Child(?:__[a-f0-9]+)?', \{ init: initChild\$, template:/)
|
|
94
102
|
|
|
95
103
|
// Parent also gets CSR fallback template for cross-file conditional use
|
|
96
104
|
expect(content).toMatch(/hydrate\('Parent',.*template:/)
|
|
@@ -37,7 +37,7 @@ export function StaticRefCase() {
|
|
|
37
37
|
return (
|
|
38
38
|
<ul>
|
|
39
39
|
{items.map(item => (
|
|
40
|
-
<li key={item.id} ref={trackMount}>{item.id}</li>
|
|
40
|
+
<li key={item.id} data-tracked="0" ref={trackMount}>{item.id}</li>
|
|
41
41
|
))}
|
|
42
42
|
</ul>
|
|
43
43
|
)
|
|
@@ -58,7 +58,7 @@ export function StaticNestedRefCase() {
|
|
|
58
58
|
{items.map(item => (
|
|
59
59
|
<li key={item.id}>
|
|
60
60
|
{item.children.map(child => (
|
|
61
|
-
<span key={child.id} ref={trackMount}>{child.id}</span>
|
|
61
|
+
<span key={child.id} data-tracked="0" ref={trackMount}>{child.id}</span>
|
|
62
62
|
))}
|
|
63
63
|
</li>
|
|
64
64
|
))}
|
|
@@ -27,7 +27,7 @@ const BRANCH_REF_SOURCE = `
|
|
|
27
27
|
<ul>{rows().map(row => (
|
|
28
28
|
<li key={row.key}>
|
|
29
29
|
{row.kind === 'a' ? (
|
|
30
|
-
<span ref={el => { el.dataset.mounted = 'yes' }}>{row.label}</span>
|
|
30
|
+
<span ref={el => { el.dataset.mounted = 'yes' }} data-mounted="yes">{row.label}</span>
|
|
31
31
|
) : (
|
|
32
32
|
<span>placeholder</span>
|
|
33
33
|
)}
|
|
@@ -68,7 +68,7 @@ describe('issue-3009 — loop-row conditional branch ref emission', () => {
|
|
|
68
68
|
export function C() {
|
|
69
69
|
const [rows] = createSignal<Row[]>([])
|
|
70
70
|
return <ul>{rows().map(row => (
|
|
71
|
-
<li key={row.key} ref={el => { el.dataset.mounted = 'yes' }}>{row.label}</li>
|
|
71
|
+
<li key={row.key} ref={el => { el.dataset.mounted = 'yes' }} data-mounted="yes">{row.label}</li>
|
|
72
72
|
))}</ul>
|
|
73
73
|
}
|
|
74
74
|
`)
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #3044 — a client component receiving a REACTIVE prop that is an OBJECT
|
|
3
|
+
* (`{ data }: { data: { items: T[] } }`), whose body maps a nested array
|
|
4
|
+
* property off that prop (`data.items.map(...)`), stayed on the static
|
|
5
|
+
* SSR-row-bind path instead of `mapArray`. `isArrayExprDirectPropRef`
|
|
6
|
+
* (jsx-to-ir.ts) recognized:
|
|
7
|
+
* (a) a bare identifier that is itself a destructured prop (`items.map(...)`
|
|
8
|
+
* when `items` is the prop), and
|
|
9
|
+
* (b) a property access rooted at the WHOLE props object (`props.items`,
|
|
10
|
+
* one member access deep).
|
|
11
|
+
* Neither covered a property access rooted at a destructured OBJECT-shaped
|
|
12
|
+
* prop (`data.items`, where `data` — not `items` — is the prop): the
|
|
13
|
+
* `.expression` of `data.items` is the identifier `data`, which is a
|
|
14
|
+
* destructured prop binding rather than the whole props object, so case (b)
|
|
15
|
+
* (gated on `propsObjName`, which is null in destructured-prop mode) never
|
|
16
|
+
* matched. The loop was classified `isStaticArray: true`, so when the
|
|
17
|
+
* parent signal driving `data` went from `{ items: [] }` (SSR) to
|
|
18
|
+
* `{ items: [...] }` (e.g. in `onMount`), the child's static `forEach`-bind
|
|
19
|
+
* init only ran once against the empty SSR row set and never inserted rows.
|
|
20
|
+
*
|
|
21
|
+
* Fix: `isArrayExprDirectPropRef`'s property-access branch now walks to the
|
|
22
|
+
* ROOT identifier of the (possibly chained) member-access expression and
|
|
23
|
+
* accepts it either as the whole props object OR as a destructured prop
|
|
24
|
+
* binding (via the same `isDirectPropBindingName` terminal (a) already
|
|
25
|
+
* uses), through the same alias-hop chain as before.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { describe, test, expect } from 'bun:test'
|
|
29
|
+
import { compileJSX } from '../compiler'
|
|
30
|
+
import { analyzeComponent } from '../analyzer'
|
|
31
|
+
import { jsxToIR } from '../jsx-to-ir'
|
|
32
|
+
import { TestAdapter } from '../adapters/test-adapter'
|
|
33
|
+
import type { IRNode } from '../types'
|
|
34
|
+
|
|
35
|
+
const adapter = new TestAdapter()
|
|
36
|
+
|
|
37
|
+
function getClientJs(source: string, filename: string): string {
|
|
38
|
+
const result = compileJSX(source, filename, { adapter })
|
|
39
|
+
expect(result.errors.filter(e => e.severity === 'error')).toHaveLength(0)
|
|
40
|
+
const clientJs = result.files.find(f => f.type === 'clientJs')
|
|
41
|
+
expect(clientJs).toBeDefined()
|
|
42
|
+
return clientJs!.content
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** First `IRLoop` node found in a DFS of the component IR. */
|
|
46
|
+
function findLoop(node: IRNode | null, predicate: (n: any) => boolean = () => true): any {
|
|
47
|
+
if (!node || typeof node !== 'object') return undefined
|
|
48
|
+
if ((node as any).type === 'loop' && predicate(node)) return node
|
|
49
|
+
for (const key of Object.keys(node)) {
|
|
50
|
+
const v = (node as any)[key]
|
|
51
|
+
if (Array.isArray(v)) {
|
|
52
|
+
for (const c of v) {
|
|
53
|
+
const found = findLoop(c, predicate)
|
|
54
|
+
if (found) return found
|
|
55
|
+
}
|
|
56
|
+
} else if (v && typeof v === 'object') {
|
|
57
|
+
const found = findLoop(v, predicate)
|
|
58
|
+
if (found) return found
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return undefined
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function loopFlags(source: string, filename: string, predicate?: (n: any) => boolean) {
|
|
65
|
+
const ctx = analyzeComponent(source, filename, 'ReproChild')
|
|
66
|
+
const ir = jsxToIR(ctx)
|
|
67
|
+
expect(ir).not.toBeNull()
|
|
68
|
+
const loop = findLoop(ir, predicate)
|
|
69
|
+
expect(loop).toBeDefined()
|
|
70
|
+
return { isStaticArray: loop.isStaticArray as boolean, isPropDerivedArray: loop.isPropDerivedArray as boolean | undefined }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
describe('#3044 — nested array off a destructured object prop uses mapArray, not the static path', () => {
|
|
74
|
+
test('headline repro: `data.items.map(...)` where `data` is a destructured object prop uses mapArray', () => {
|
|
75
|
+
const clientJs = getClientJs(`
|
|
76
|
+
'use client'
|
|
77
|
+
export type ReproData = { items: { id: string; label: string }[] }
|
|
78
|
+
export function ReproChild({ data }: { data: ReproData }) {
|
|
79
|
+
return (
|
|
80
|
+
<ul aria-label="items">
|
|
81
|
+
{data.items.map((item) => <li key={item.id}>{item.label}</li>)}
|
|
82
|
+
</ul>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
`, 'ReproChild.tsx')
|
|
86
|
+
expect(clientJs).toMatch(/\bmapArray(Lazy)?\s*\(/)
|
|
87
|
+
expect(clientJs).not.toMatch(/qsaChildScopes\(/)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('flags: `data.items.map(...)` is classified isPropDerivedArray / non-static', () => {
|
|
91
|
+
const flags = loopFlags(`
|
|
92
|
+
'use client'
|
|
93
|
+
export type ReproData = { items: { id: string; label: string }[] }
|
|
94
|
+
export function ReproChild({ data }: { data: ReproData }) {
|
|
95
|
+
return (
|
|
96
|
+
<ul aria-label="items">
|
|
97
|
+
{data.items.map((item) => <li key={item.id}>{item.label}</li>)}
|
|
98
|
+
</ul>
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
`, 'ReproChildFlags.tsx')
|
|
102
|
+
expect(flags.isStaticArray).toBe(false)
|
|
103
|
+
expect(flags.isPropDerivedArray).toBe(true)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('an alias hop of the destructured object prop also uses mapArray (`const d = data; d.items.map(...)`)', () => {
|
|
107
|
+
const flags = loopFlags(`
|
|
108
|
+
'use client'
|
|
109
|
+
export type ReproData = { items: { id: string; label: string }[] }
|
|
110
|
+
export function ReproChild({ data }: { data: ReproData }) {
|
|
111
|
+
const d = data
|
|
112
|
+
return <ul>{d.items.map((item) => <li key={item.id}>{item.label}</li>)}</ul>
|
|
113
|
+
}
|
|
114
|
+
`, 'AliasedObjectProp.tsx')
|
|
115
|
+
expect(flags.isStaticArray).toBe(false)
|
|
116
|
+
expect(flags.isPropDerivedArray).toBe(true)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
test('whole-props form, two-level chain (`props.data.items.map(...)`) also uses mapArray', () => {
|
|
120
|
+
const flags = loopFlags(`
|
|
121
|
+
'use client'
|
|
122
|
+
export type ReproData = { items: { id: string; label: string }[] }
|
|
123
|
+
export function ReproChild(props: { data: ReproData }) {
|
|
124
|
+
return <ul>{props.data.items.map((item) => <li key={item.id}>{item.label}</li>)}</ul>
|
|
125
|
+
}
|
|
126
|
+
`, 'WholePropsTwoLevel.tsx')
|
|
127
|
+
expect(flags.isStaticArray).toBe(false)
|
|
128
|
+
expect(flags.isPropDerivedArray).toBe(true)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('false-positive guard: a nested array off an unrelated local object (not a prop) stays static', () => {
|
|
132
|
+
const flags = loopFlags(`
|
|
133
|
+
'use client'
|
|
134
|
+
export function ReproChild({ data }: { data: { items: { id: string; label: string }[] } }) {
|
|
135
|
+
const state = { items: [{ id: 'z', label: 'z' }] }
|
|
136
|
+
return <ul>{state.items.map((item) => <li key={item.id}>{item.label}</li>)}</ul>
|
|
137
|
+
}
|
|
138
|
+
`, 'NameCollisionObjectProp.tsx')
|
|
139
|
+
expect(flags.isStaticArray).toBe(true)
|
|
140
|
+
expect(flags.isPropDerivedArray).toBeUndefined()
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
// Pullfrog review findings on the initial fix (both confirmed against the
|
|
144
|
+
// real compiler before being fixed):
|
|
145
|
+
|
|
146
|
+
test('pullfrog review finding: a local const aliasing `data.items` (one hop before .map()) also uses mapArray', () => {
|
|
147
|
+
// `const items = data.items; items.map(...)` — the extremely common
|
|
148
|
+
// "alias the array to a local const before mapping" pattern. The
|
|
149
|
+
// initial fix only widened `isArrayExprDirectPropRef`'s OWN property-
|
|
150
|
+
// access branch (the `.map()` array expression itself); it left
|
|
151
|
+
// `isDirectPropBindingName`'s member-parsed check — used to resolve a
|
|
152
|
+
// local const's value — still single-level (`parsed.object.kind ===
|
|
153
|
+
// 'identifier' && parsed.object.name === propsObjName`), so this shape
|
|
154
|
+
// reproduced #3044's exact silent-freeze bug one alias hop away.
|
|
155
|
+
const flags = loopFlags(`
|
|
156
|
+
'use client'
|
|
157
|
+
export type ReproData = { items: { id: string; label: string }[] }
|
|
158
|
+
export function ReproChild({ data }: { data: ReproData }) {
|
|
159
|
+
const items = data.items
|
|
160
|
+
return <ul>{items.map((item) => <li key={item.id}>{item.label}</li>)}</ul>
|
|
161
|
+
}
|
|
162
|
+
`, 'ConstAliasOfObjectProp.tsx')
|
|
163
|
+
expect(flags.isStaticArray).toBe(false)
|
|
164
|
+
expect(flags.isPropDerivedArray).toBe(true)
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('pullfrog review finding: a local const aliasing the whole-props two-level chain also uses mapArray', () => {
|
|
168
|
+
// `const items = props.data.items; items.map(...)` — same gap as above,
|
|
169
|
+
// reached through the whole-props (non-destructured) form instead.
|
|
170
|
+
const flags = loopFlags(`
|
|
171
|
+
'use client'
|
|
172
|
+
export type ReproData = { items: { id: string; label: string }[] }
|
|
173
|
+
export function ReproChild(props: { data: ReproData }) {
|
|
174
|
+
const items = props.data.items
|
|
175
|
+
return <ul>{items.map((item) => <li key={item.id}>{item.label}</li>)}</ul>
|
|
176
|
+
}
|
|
177
|
+
`, 'ConstAliasOfWholePropsChain.tsx')
|
|
178
|
+
expect(flags.isStaticArray).toBe(false)
|
|
179
|
+
expect(flags.isPropDerivedArray).toBe(true)
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
test('pullfrog review finding: a loop-row parameter shadowing the outer props-object name is not misclassified', () => {
|
|
183
|
+
// `props.rows.map((props) => props.items.map(...))` — the inner `props`
|
|
184
|
+
// is an arbitrary row value bound by the OUTER `.map()`, unrelated to
|
|
185
|
+
// the real props object it happens to share a name with. The initial
|
|
186
|
+
// fix's new property-access branch checked `name === propsObjName`
|
|
187
|
+
// without the shadow guard `isDirectPropBindingName` uses right next to
|
|
188
|
+
// it, and widened that unguarded check from a single member access
|
|
189
|
+
// (`props.foo`) to an arbitrarily deep chain — increasing the blast
|
|
190
|
+
// radius of a pre-existing gap. `isPropDerivedArray` feeds real
|
|
191
|
+
// Go-adapter codegen decisions for nested components, so a false
|
|
192
|
+
// positive here is a genuine misclassification risk, not just a
|
|
193
|
+
// redundant `mapArray`.
|
|
194
|
+
const ctx = analyzeComponent(`
|
|
195
|
+
'use client'
|
|
196
|
+
type Row = { items: { id: string; label: string }[] }
|
|
197
|
+
export function Foo(props: { rows: Row[] }) {
|
|
198
|
+
return (
|
|
199
|
+
<div>
|
|
200
|
+
{props.rows.map((props) => (
|
|
201
|
+
<ul>{props.items.map((item) => <li key={item.id}>{item.label}</li>)}</ul>
|
|
202
|
+
))}
|
|
203
|
+
</div>
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
`, 'ShadowedPropsParam.tsx', 'Foo')
|
|
207
|
+
const ir = jsxToIR(ctx)
|
|
208
|
+
const inner = findLoop(ir, (n: any) => n.array === 'props.items')
|
|
209
|
+
expect(inner).toBeDefined()
|
|
210
|
+
expect(inner.isStaticArray).toBe(true)
|
|
211
|
+
expect(inner.isPropDerivedArray).toBeUndefined()
|
|
212
|
+
})
|
|
213
|
+
})
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression test for #3113: a component literally named `Child` compiled
|
|
3
|
+
* a top-level `export function initChild(...)` — the compiler's own
|
|
4
|
+
* `init<Name>` naming convention (`generate-init.ts`) — into the SAME
|
|
5
|
+
* module that also `import { initChild } from '@barefootjs/client/runtime'`
|
|
6
|
+
* (the runtime dispatcher a parent calls to hand a live prop getter to a
|
|
7
|
+
* mounted child, `registry.ts`'s `initChild`). Two top-level declarations
|
|
8
|
+
* of the same identifier in one ES module is a hard `SyntaxError` under
|
|
9
|
+
* real module semantics — verified against a raw `<script type="module">`
|
|
10
|
+
* load, the same unbundled-ESM shape `bf build` ships (see
|
|
11
|
+
* `initFunctionName`'s docstring, `ir-to-client-js/utils.ts`) — so the
|
|
12
|
+
* ENTIRE hydration script failed to parse, breaking every action on the
|
|
13
|
+
* page, not just the child's own reactive text. `initFunctionName` now
|
|
14
|
+
* disambiguates the generated declaration (`initChild$`) whenever it would
|
|
15
|
+
* collide with a `RUNTIME_IMPORT_CANDIDATES` entry, and every emission
|
|
16
|
+
* site (`generate-init.ts`, `emit-registration.ts`, `ir-to-client-js/
|
|
17
|
+
* index.ts`'s static-template stub path, `source-map.ts`) computes the
|
|
18
|
+
* SAME name so the declaration and its `hydrate(...)` registration always
|
|
19
|
+
* agree.
|
|
20
|
+
*
|
|
21
|
+
* The bounded state-space exploration scenario
|
|
22
|
+
* (`packages/adapter-tests/explore/scenarios/child-prop-slots.ts`) is the
|
|
23
|
+
* end-to-end regression armor (real browser, real ES module load); this
|
|
24
|
+
* file pins the compiler-unit half: the generated code must neither carry
|
|
25
|
+
* a literal `export function initChild(` declaration nor otherwise emit
|
|
26
|
+
* a duplicate top-level `initChild` binding, whenever the component named
|
|
27
|
+
* `Child` needs BOTH its own compiled init (reactive prop-derived content)
|
|
28
|
+
* AND the runtime's `initChild` (because some ancestor mounts a further
|
|
29
|
+
* child by name).
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { describe, test, expect } from 'bun:test'
|
|
33
|
+
import { compileJSX } from '../compiler'
|
|
34
|
+
import { TestAdapter } from '../adapters/test-adapter'
|
|
35
|
+
import ts from 'typescript'
|
|
36
|
+
|
|
37
|
+
const adapter = new TestAdapter()
|
|
38
|
+
|
|
39
|
+
function getClientJs(source: string, filename: string): string {
|
|
40
|
+
const result = compileJSX(source, filename, { adapter })
|
|
41
|
+
expect(result.errors.filter(e => e.severity === 'error')).toHaveLength(0)
|
|
42
|
+
const clientJs = result.files.find(f => f.type === 'clientJs')
|
|
43
|
+
expect(clientJs).toBeDefined()
|
|
44
|
+
return clientJs!.content
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** No top-level identifier is declared more than once (mirrors real ESM semantics). */
|
|
48
|
+
function assertNoDuplicateTopLevelDeclarations(code: string, filename: string): void {
|
|
49
|
+
const sourceFile = ts.createSourceFile(filename, code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS)
|
|
50
|
+
const seen = new Set<string>()
|
|
51
|
+
const dupes = new Set<string>()
|
|
52
|
+
const noteName = (name: string) => {
|
|
53
|
+
if (seen.has(name)) dupes.add(name)
|
|
54
|
+
seen.add(name)
|
|
55
|
+
}
|
|
56
|
+
for (const stmt of sourceFile.statements) {
|
|
57
|
+
if (ts.isImportDeclaration(stmt) && stmt.importClause?.namedBindings && ts.isNamedImports(stmt.importClause.namedBindings)) {
|
|
58
|
+
for (const spec of stmt.importClause.namedBindings.elements) noteName(spec.name.text)
|
|
59
|
+
} else if (ts.isFunctionDeclaration(stmt) && stmt.name) {
|
|
60
|
+
noteName(stmt.name.text)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
expect([...dupes]).toEqual([])
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
describe('#3113: init<Name> disambiguated against runtime import names', () => {
|
|
67
|
+
test('a component literally named `Child` with a reactive prop-derived text child does not collide with the imported runtime initChild', () => {
|
|
68
|
+
// Mirrors the issue's exploration scenario: an inlined (non-"use
|
|
69
|
+
// client") `Child` reads a destructured object prop's field as text,
|
|
70
|
+
// and the "use client" parent passes it a live signal-derived value.
|
|
71
|
+
const source = `
|
|
72
|
+
'use client'
|
|
73
|
+
import { createSignal } from '@barefootjs/client'
|
|
74
|
+
|
|
75
|
+
type Data = { label: string }
|
|
76
|
+
|
|
77
|
+
function Child({ data }: { data: Data }) {
|
|
78
|
+
return <p aria-label="label">{data.label}</p>
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function ChildPropSlots({ initial }: { initial: { data: Data } }) {
|
|
82
|
+
const [data, setData] = createSignal<Data>(initial.data)
|
|
83
|
+
return (
|
|
84
|
+
<div>
|
|
85
|
+
<Child data={data()} />
|
|
86
|
+
<button onClick={() => setData({ label: 'loaded' })}>load</button>
|
|
87
|
+
</div>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
`
|
|
91
|
+
const clientJs = getClientJs(source, 'ChildPropSlots.tsx')
|
|
92
|
+
|
|
93
|
+
// The exact defect: a bare `export function initChild(` declaration
|
|
94
|
+
// sharing a module with `import { ..., initChild, ... }`.
|
|
95
|
+
expect(clientJs).not.toMatch(/\bexport function initChild\(/)
|
|
96
|
+
// The disambiguated name is used consistently for both the
|
|
97
|
+
// declaration and its `hydrate(...)` registration.
|
|
98
|
+
expect(clientJs).toContain('export function initChild$(')
|
|
99
|
+
expect(clientJs).toMatch(/hydrate\('Child[^']*',\s*\{\s*init:\s*initChild\$,/)
|
|
100
|
+
// The runtime dispatcher call (a DIFFERENT `initChild` — the import —
|
|
101
|
+
// invoked from the parent's own init to deliver live props) is
|
|
102
|
+
// untouched.
|
|
103
|
+
expect(clientJs).toMatch(/\binitChild\('Child[_a-f0-9]*',/)
|
|
104
|
+
|
|
105
|
+
assertNoDuplicateTopLevelDeclarations(clientJs, 'ChildPropSlots.client.js')
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('a component named anything else keeps the plain init<Name> convention (no needless disambiguation)', () => {
|
|
109
|
+
const source = `
|
|
110
|
+
'use client'
|
|
111
|
+
import { createSignal } from '@barefootjs/client'
|
|
112
|
+
|
|
113
|
+
type Data = { label: string }
|
|
114
|
+
|
|
115
|
+
function Leaf({ data }: { data: Data }) {
|
|
116
|
+
return <p aria-label="label">{data.label}</p>
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function Parent({ initial }: { initial: { data: Data } }) {
|
|
120
|
+
const [data, setData] = createSignal<Data>(initial.data)
|
|
121
|
+
return (
|
|
122
|
+
<div>
|
|
123
|
+
<Leaf data={data()} />
|
|
124
|
+
<button onClick={() => setData({ label: 'loaded' })}>load</button>
|
|
125
|
+
</div>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
`
|
|
129
|
+
const clientJs = getClientJs(source, 'Parent.tsx')
|
|
130
|
+
expect(clientJs).toContain('export function initLeaf(')
|
|
131
|
+
expect(clientJs).not.toContain('initLeaf$')
|
|
132
|
+
})
|
|
133
|
+
})
|