@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
|
@@ -1,285 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Props
|
|
2
|
+
* Destructured-Props Type Resolution Tests
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Pins that a destructured prop's declared TYPE resolves from the param's
|
|
5
|
+
* type annotation (#2150). The reactivity half of this file is gone: BF043
|
|
6
|
+
* ("props destructuring breaks reactivity") is retired, and the live-read
|
|
7
|
+
* rewrite that replaced it is covered by `destructured-props-live.test.ts`.
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import { describe, test, expect } from 'bun:test'
|
|
10
11
|
import { analyzeComponent } from '../analyzer'
|
|
11
|
-
import { ErrorCodes } from '../errors'
|
|
12
12
|
|
|
13
|
-
describe('
|
|
14
|
-
test('warns on destructured props in stateful component', () => {
|
|
15
|
-
const source = `
|
|
16
|
-
'use client'
|
|
17
|
-
import { createSignal } from '@barefootjs/client'
|
|
18
|
-
|
|
19
|
-
interface Props {
|
|
20
|
-
checked: boolean
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function Component({ checked }: Props) {
|
|
24
|
-
const [count, setCount] = createSignal(0)
|
|
25
|
-
return <div>{checked}{count()}</div>
|
|
26
|
-
}
|
|
27
|
-
`
|
|
28
|
-
|
|
29
|
-
const ctx = analyzeComponent(source, 'Component.tsx')
|
|
30
|
-
|
|
31
|
-
const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
|
|
32
|
-
expect(propsWarnings).toHaveLength(1)
|
|
33
|
-
expect(propsWarnings[0].severity).toBe('warning')
|
|
34
|
-
expect(propsWarnings[0].suggestion?.message).toContain('props object')
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
test('no warning on destructured props in stateless component', () => {
|
|
38
|
-
const source = `
|
|
39
|
-
interface Props {
|
|
40
|
-
checked: boolean
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function Component({ checked }: Props) {
|
|
44
|
-
return <div>{checked}</div>
|
|
45
|
-
}
|
|
46
|
-
`
|
|
47
|
-
|
|
48
|
-
const ctx = analyzeComponent(source, 'Component.tsx')
|
|
49
|
-
|
|
50
|
-
const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
|
|
51
|
-
expect(propsWarnings).toHaveLength(0)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
test('warns on rest props in stateful component', () => {
|
|
55
|
-
const source = `
|
|
56
|
-
'use client'
|
|
57
|
-
import { createSignal } from '@barefootjs/client'
|
|
58
|
-
|
|
59
|
-
interface Props {
|
|
60
|
-
checked: boolean
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function Component({ ...props }: Props) {
|
|
64
|
-
const [count, setCount] = createSignal(0)
|
|
65
|
-
return <div>{props.checked}{count()}</div>
|
|
66
|
-
}
|
|
67
|
-
`
|
|
68
|
-
|
|
69
|
-
const ctx = analyzeComponent(source, 'Component.tsx')
|
|
70
|
-
|
|
71
|
-
const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
|
|
72
|
-
expect(propsWarnings).toHaveLength(1)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
test('warns on partial destructuring with rest props in stateful component', () => {
|
|
76
|
-
const source = `
|
|
77
|
-
'use client'
|
|
78
|
-
import { createSignal } from '@barefootjs/client'
|
|
79
|
-
|
|
80
|
-
interface Props {
|
|
81
|
-
onClick: () => void
|
|
82
|
-
checked: boolean
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function Component({ onClick, ...rest }: Props) {
|
|
86
|
-
const [count, setCount] = createSignal(0)
|
|
87
|
-
return <div onClick={onClick}>{rest.checked}{count()}</div>
|
|
88
|
-
}
|
|
89
|
-
`
|
|
90
|
-
|
|
91
|
-
const ctx = analyzeComponent(source, 'Component.tsx')
|
|
92
|
-
|
|
93
|
-
const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
|
|
94
|
-
expect(propsWarnings).toHaveLength(1)
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
test('no warning with @bf-ignore props-destructuring', () => {
|
|
98
|
-
const source = `
|
|
99
|
-
'use client'
|
|
100
|
-
import { createSignal } from '@barefootjs/client'
|
|
101
|
-
|
|
102
|
-
interface Props {
|
|
103
|
-
checked: boolean
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// @bf-ignore props-destructuring
|
|
107
|
-
export function Component({ checked }: Props) {
|
|
108
|
-
const [count, setCount] = createSignal(0)
|
|
109
|
-
return <div>{checked}{count()}</div>
|
|
110
|
-
}
|
|
111
|
-
`
|
|
112
|
-
|
|
113
|
-
const ctx = analyzeComponent(source, 'Component.tsx')
|
|
114
|
-
|
|
115
|
-
const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
|
|
116
|
-
expect(propsWarnings).toHaveLength(0)
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
test('no warning when props object is used', () => {
|
|
120
|
-
const source = `
|
|
121
|
-
'use client'
|
|
122
|
-
import { createSignal } from '@barefootjs/client'
|
|
123
|
-
|
|
124
|
-
interface Props {
|
|
125
|
-
checked: boolean
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export function Component(props: Props) {
|
|
129
|
-
const [count, setCount] = createSignal(0)
|
|
130
|
-
return <div>{props.checked}{count()}</div>
|
|
131
|
-
}
|
|
132
|
-
`
|
|
133
|
-
|
|
134
|
-
const ctx = analyzeComponent(source, 'Component.tsx')
|
|
135
|
-
|
|
136
|
-
const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
|
|
137
|
-
expect(propsWarnings).toHaveLength(0)
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
test('no warning when no props parameter', () => {
|
|
141
|
-
const source = `
|
|
142
|
-
'use client'
|
|
143
|
-
|
|
144
|
-
export function Component() {
|
|
145
|
-
return <div>Hello</div>
|
|
146
|
-
}
|
|
147
|
-
`
|
|
148
|
-
|
|
149
|
-
const ctx = analyzeComponent(source, 'Component.tsx')
|
|
150
|
-
|
|
151
|
-
const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
|
|
152
|
-
expect(propsWarnings).toHaveLength(0)
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
test('warns on arrow function component with destructuring when stateful', () => {
|
|
156
|
-
const source = `
|
|
157
|
-
'use client'
|
|
158
|
-
import { createSignal } from '@barefootjs/client'
|
|
159
|
-
|
|
160
|
-
interface Props {
|
|
161
|
-
checked: boolean
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export const Component = ({ checked }: Props) => {
|
|
165
|
-
const [count, setCount] = createSignal(0)
|
|
166
|
-
return <div>{checked}{count()}</div>
|
|
167
|
-
}
|
|
168
|
-
`
|
|
169
|
-
|
|
170
|
-
const ctx = analyzeComponent(source, 'Component.tsx')
|
|
171
|
-
|
|
172
|
-
const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
|
|
173
|
-
expect(propsWarnings).toHaveLength(1)
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
test('no warning on arrow function with @bf-ignore', () => {
|
|
177
|
-
const source = `
|
|
178
|
-
'use client'
|
|
179
|
-
import { createSignal } from '@barefootjs/client'
|
|
180
|
-
|
|
181
|
-
interface Props {
|
|
182
|
-
checked: boolean
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// @bf-ignore props-destructuring
|
|
186
|
-
export const Component = ({ checked }: Props) => {
|
|
187
|
-
const [count, setCount] = createSignal(0)
|
|
188
|
-
return <div>{checked}{count()}</div>
|
|
189
|
-
}
|
|
190
|
-
`
|
|
191
|
-
|
|
192
|
-
const ctx = analyzeComponent(source, 'Component.tsx')
|
|
193
|
-
|
|
194
|
-
const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
|
|
195
|
-
expect(propsWarnings).toHaveLength(0)
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
test('warns on multiple destructured props in stateful component', () => {
|
|
199
|
-
const source = `
|
|
200
|
-
'use client'
|
|
201
|
-
import { createSignal } from '@barefootjs/client'
|
|
202
|
-
|
|
203
|
-
interface Props {
|
|
204
|
-
checked: boolean
|
|
205
|
-
onChange: () => void
|
|
206
|
-
label: string
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export function Component({ checked, onChange, label }: Props) {
|
|
210
|
-
const [count, setCount] = createSignal(0)
|
|
211
|
-
return <div onClick={onChange}>{label}: {checked}{count()}</div>
|
|
212
|
-
}
|
|
213
|
-
`
|
|
214
|
-
|
|
215
|
-
const ctx = analyzeComponent(source, 'Component.tsx')
|
|
216
|
-
|
|
217
|
-
const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
|
|
218
|
-
expect(propsWarnings).toHaveLength(1) // One warning per component, not per prop
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
test('warns when component has memos (stateful)', () => {
|
|
222
|
-
const source = `
|
|
223
|
-
'use client'
|
|
224
|
-
import { createMemo } from '@barefootjs/client'
|
|
225
|
-
|
|
226
|
-
interface Props {
|
|
227
|
-
value: number
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export function Component({ value }: Props) {
|
|
231
|
-
const doubled = createMemo(() => value * 2)
|
|
232
|
-
return <div>{doubled()}</div>
|
|
233
|
-
}
|
|
234
|
-
`
|
|
235
|
-
|
|
236
|
-
const ctx = analyzeComponent(source, 'Component.tsx')
|
|
237
|
-
|
|
238
|
-
const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
|
|
239
|
-
expect(propsWarnings).toHaveLength(1)
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
test('warns when component has effects (stateful)', () => {
|
|
243
|
-
const source = `
|
|
244
|
-
'use client'
|
|
245
|
-
import { createEffect } from '@barefootjs/client'
|
|
246
|
-
|
|
247
|
-
interface Props {
|
|
248
|
-
value: number
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export function Component({ value }: Props) {
|
|
252
|
-
createEffect(() => console.log(value))
|
|
253
|
-
return <div>{value}</div>
|
|
254
|
-
}
|
|
255
|
-
`
|
|
256
|
-
|
|
257
|
-
const ctx = analyzeComponent(source, 'Component.tsx')
|
|
258
|
-
|
|
259
|
-
const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
|
|
260
|
-
expect(propsWarnings).toHaveLength(1)
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
test('no warning on stateless arrow function with destructuring', () => {
|
|
264
|
-
const source = `
|
|
265
|
-
interface Props {
|
|
266
|
-
className: string
|
|
267
|
-
variant: string
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
export const Button = ({ className, variant }: Props) => {
|
|
271
|
-
return <button className={className}>{variant}</button>
|
|
272
|
-
}
|
|
273
|
-
`
|
|
274
|
-
|
|
275
|
-
const ctx = analyzeComponent(source, 'Button.tsx')
|
|
276
|
-
|
|
277
|
-
const propsWarnings = ctx.errors.filter((e) => e.code === ErrorCodes.PROPS_DESTRUCTURING)
|
|
278
|
-
expect(propsWarnings).toHaveLength(0)
|
|
279
|
-
})
|
|
280
|
-
})
|
|
281
|
-
|
|
282
|
-
describe('Destructured props keep their declared types (BF043 fixture #2150)', () => {
|
|
13
|
+
describe('Destructured props keep their declared types (#2150)', () => {
|
|
283
14
|
const typeOf = (ctx: ReturnType<typeof analyzeComponent>, name: string) =>
|
|
284
15
|
ctx.propsParams.find((p) => p.name === name)?.type
|
|
285
16
|
|
|
@@ -52,9 +52,12 @@ export { Wrap }
|
|
|
52
52
|
expect(js).not.toContain('const children = _p.children')
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
-
test('props the init genuinely reads
|
|
56
|
-
// `config` is read by a handler, `items` by an init-scope constant
|
|
57
|
-
//
|
|
55
|
+
test('props the init genuinely reads compile to live `_p.x` reads, with no extraction to prune at all', () => {
|
|
56
|
+
// `config` is read by a handler, `items` by an init-scope constant.
|
|
57
|
+
// Neither produces an extraction for this pruner to decide about any
|
|
58
|
+
// more: both read live, with the same `?? {}` / `?? []` fallback at
|
|
59
|
+
// each read site. Only `children` (the test above) still goes through
|
|
60
|
+
// the pruner.
|
|
58
61
|
const js = clientJsOf(
|
|
59
62
|
`"use client"
|
|
60
63
|
|
|
@@ -72,7 +75,10 @@ export { Widget }
|
|
|
72
75
|
`,
|
|
73
76
|
'/virtual/widget.tsx',
|
|
74
77
|
)
|
|
75
|
-
expect(js).toContain('const config =
|
|
76
|
-
expect(js).toContain('const items =
|
|
78
|
+
expect(js).not.toContain('const config = ')
|
|
79
|
+
expect(js).not.toContain('const items = ')
|
|
80
|
+
expect(js).toContain('(_p.config ?? {}).startOpen')
|
|
81
|
+
expect(js).toContain('(_p.items ?? []).length')
|
|
82
|
+
expect(js).toContain('(_p.items ?? [])[0]')
|
|
77
83
|
})
|
|
78
84
|
})
|
|
@@ -327,6 +327,11 @@ describe('Signal Getter Not Called (BF044)', () => {
|
|
|
327
327
|
['component prop, object literal member', '<Child value={{ x: count }} />'],
|
|
328
328
|
['component prop, ternary', '<Child value={count ? 1 : 2} />'],
|
|
329
329
|
['component prop, call argument', '<Child value={String(count)} />'],
|
|
330
|
+
// #2760: a bare getter passed DIRECTLY to a component prop is the
|
|
331
|
+
// same idiom as the object-literal-wrapped form above, not a
|
|
332
|
+
// forgotten `()` — the two forms are one decision, not an
|
|
333
|
+
// inconsistency to resolve by tightening the direct one.
|
|
334
|
+
['component prop, bare getter', '<Child value={count} />'],
|
|
330
335
|
])('%s', (_label, body) => {
|
|
331
336
|
expect(bf044Of(body)).toHaveLength(0)
|
|
332
337
|
})
|
|
@@ -352,6 +352,89 @@ describe('extractSsrDefaults', () => {
|
|
|
352
352
|
expect(defaults?.text).toEqual({ propName: 'text', value: null })
|
|
353
353
|
})
|
|
354
354
|
|
|
355
|
+
test('bare-props-form BODY-destructured default (#2943) seeds the evaluated default, not null', () => {
|
|
356
|
+
// Before #2943, `extractPropsFromTypeMembers` built `propsParams` from
|
|
357
|
+
// the TYPE annotation alone, with no notion of a body destructure's
|
|
358
|
+
// own default — this entry seeded `value: null` regardless, and every
|
|
359
|
+
// non-Hono template adapter's presence-guard classification omitted
|
|
360
|
+
// the attribute entirely instead of falling back to `'none'`. The
|
|
361
|
+
// analyzer now overlays the default directly onto `propsParams`
|
|
362
|
+
// (`collectConstant`), so this is the SAME code path as the
|
|
363
|
+
// parameter-destructured "destructured prop defaults" test above —
|
|
364
|
+
// just reached through a body destructure instead.
|
|
365
|
+
const metadata = metadataFor(`
|
|
366
|
+
function Foo(props: { label?: string }) {
|
|
367
|
+
const { label = 'none' } = props
|
|
368
|
+
return <div data-label={label} />
|
|
369
|
+
}
|
|
370
|
+
`)
|
|
371
|
+
const defaults = extractSsrDefaults(metadata)
|
|
372
|
+
expect(defaults?.label).toEqual({ propName: 'label', value: 'none' })
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
test('bare-props-form BODY-destructured RENAMED default (#2943): two entries, each correctly classified', () => {
|
|
376
|
+
// `const { label: text = 'none' } = props` — `label` remains a real,
|
|
377
|
+
// separately-classified binding (no default of its own: a bare
|
|
378
|
+
// `props.label` read elsewhere in the same component still needs its
|
|
379
|
+
// own presence guard / stash entry), and `text` gets its OWN entry
|
|
380
|
+
// with `propName: 'label'` (the caller-facing key) and the evaluated
|
|
381
|
+
// default. `deriveStashFromDefaults` then seeds `text` from the
|
|
382
|
+
// caller's `label` when supplied, else `'none'` — never from `text`
|
|
383
|
+
// itself (`props` has no `text` key at all).
|
|
384
|
+
const metadata = metadataFor(`
|
|
385
|
+
function Foo(props: { label?: string }) {
|
|
386
|
+
const { label: text = 'none' } = props
|
|
387
|
+
return <div data-label={text} />
|
|
388
|
+
}
|
|
389
|
+
`)
|
|
390
|
+
const defaults = extractSsrDefaults(metadata)
|
|
391
|
+
expect(defaults?.label).toEqual({ propName: 'label', value: null })
|
|
392
|
+
expect(defaults?.text).toEqual({ propName: 'label', value: 'none' })
|
|
393
|
+
|
|
394
|
+
expect(deriveStashFromDefaults(defaults!, { label: 'named' })).toMatchObject({ text: 'named' })
|
|
395
|
+
expect(deriveStashFromDefaults(defaults!, {})).toMatchObject({ text: 'none' })
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
test('bare-props-form body-destructure rename (#2788) seeds the SSR stash under the LOCAL name', () => {
|
|
399
|
+
// `function Foo(props: Props) { const { children: kids } = props }` —
|
|
400
|
+
// propsParams here comes from the TYPE annotation and has no notion of
|
|
401
|
+
// the body-level rename, so the template-stash reads a LOCAL `kids`
|
|
402
|
+
// that pass-1 seeding would otherwise never populate. The safety-net
|
|
403
|
+
// loop in `extractSsrDefaults` (backed by `resolveBodyDestructuredPropAliases`)
|
|
404
|
+
// exists specifically to also seed the entry under `kids`.
|
|
405
|
+
const metadata = metadataFor(`
|
|
406
|
+
function Foo(props: { children?: string }) {
|
|
407
|
+
const { children: kids } = props
|
|
408
|
+
return <span>{kids}</span>
|
|
409
|
+
}
|
|
410
|
+
`)
|
|
411
|
+
|
|
412
|
+
const defaults = extractSsrDefaults(metadata)
|
|
413
|
+
expect(defaults?.children).toEqual({ propName: 'children', value: null })
|
|
414
|
+
expect(defaults?.kids).toEqual(defaults?.children)
|
|
415
|
+
})
|
|
416
|
+
|
|
417
|
+
// Pullfrog review (PR #2941): `resolveBodyDestructuredPropAliases` is now
|
|
418
|
+
// a filtered view over `resolveBodyPropAliases`, which excludes `let`
|
|
419
|
+
// bindings and mutated locals — a restriction that's correct for the
|
|
420
|
+
// LIVE client-JS rewrite (`rewriteBodyAliasReads`) but has no bearing on
|
|
421
|
+
// this SSR-stash safety net, which only needs the declaration-time
|
|
422
|
+
// local↔caller-key mapping. Without `requireLiveRewriteSafe: false`
|
|
423
|
+
// threaded through, a `let`-declared rename would silently lose its
|
|
424
|
+
// stash entry here — a reintroduction of #2788 for that one shape.
|
|
425
|
+
test('bare-props-form body-destructure rename via `let` (#2788 regression guard) still seeds the SSR stash', () => {
|
|
426
|
+
const metadata = metadataFor(`
|
|
427
|
+
function Foo(props: { children?: string }) {
|
|
428
|
+
let { children: kids } = props
|
|
429
|
+
return <span>{kids}</span>
|
|
430
|
+
}
|
|
431
|
+
`)
|
|
432
|
+
|
|
433
|
+
const defaults = extractSsrDefaults(metadata)
|
|
434
|
+
expect(defaults?.children).toEqual({ propName: 'children', value: null })
|
|
435
|
+
expect(defaults?.kids).toEqual(defaults?.children)
|
|
436
|
+
})
|
|
437
|
+
|
|
355
438
|
test('memo derived from a signal evaluates through the chain', () => {
|
|
356
439
|
const metadata = metadataFor(`
|
|
357
440
|
'use client'
|
|
@@ -37,9 +37,16 @@ describe('Shadow guards: bare names that shadow props are NOT rewritten to _p.X'
|
|
|
37
37
|
expect(initBody).not.toMatch(/_p\.count\(\)/)
|
|
38
38
|
})
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
// #2934: `label` here is a PURE alias of the `label` prop (the analyzer's
|
|
41
|
+
// IR can't distinguish `const label = props.label ?? 'fallback'` from a
|
|
42
|
+
// destructure default), not a genuinely distinct local shadowing an
|
|
43
|
+
// unrelated prop of the same name — so it is NOT a shadow-guard case
|
|
44
|
+
// after all. `resolveBodyPropAliases` now recognizes it, deletes its own
|
|
45
|
+
// extraction, and rewrites every reference (including from `upper`'s own
|
|
46
|
+
// initializer) to a live `_p.label` read, same as the parameter-
|
|
47
|
+
// destructured form. `upper` itself stays an ordinary once-evaluated
|
|
48
|
+
// local — `.toUpperCase()` is a real computation, not a passthrough.
|
|
49
|
+
test('a plain member-access prop alias is rewritten live, including from a dependent local', () => {
|
|
43
50
|
const { initBody, errors } = compile(`
|
|
44
51
|
'use client'
|
|
45
52
|
|
|
@@ -53,8 +60,8 @@ describe('Shadow guards: bare names that shadow props are NOT rewritten to _p.X'
|
|
|
53
60
|
`)
|
|
54
61
|
|
|
55
62
|
expect(errors).toEqual([])
|
|
56
|
-
expect(initBody).toMatch(/
|
|
57
|
-
expect(initBody).
|
|
63
|
+
expect(initBody).not.toMatch(/const\s+label\s*=/)
|
|
64
|
+
expect(initBody).toMatch(/upper\s*=\s*\(_p\.label\s*\?\?\s*'fallback'\)\.toUpperCase\(\)/)
|
|
58
65
|
})
|
|
59
66
|
|
|
60
67
|
test('nested arrow param shadowing prop name', () => {
|
|
@@ -3,9 +3,10 @@ import { parseExpression } from '../expression-parser'
|
|
|
3
3
|
import { evaluateStaticLiteral, isFullyStaticLiteral, resolveStaticLoopSource } from '../static-literal'
|
|
4
4
|
import type { ConstantInfo } from '../types'
|
|
5
5
|
|
|
6
|
-
// #2208: a
|
|
7
|
-
//
|
|
8
|
-
//
|
|
6
|
+
// #2208: a local const whose initializer is fully known at compile time (no
|
|
7
|
+
// prop/signal/function-call dependency) should bind as a loop source the
|
|
8
|
+
// same way an inline array literal does — module-scope and function-scope
|
|
9
|
+
// alike (#2946).
|
|
9
10
|
describe('evaluateStaticLiteral (#2208)', () => {
|
|
10
11
|
test('scalars', () => {
|
|
11
12
|
expect(evaluateStaticLiteral(parseExpression("'Alpha'"))).toEqual({ value: 'Alpha' })
|
|
@@ -97,11 +98,45 @@ describe('resolveStaticLoopSource (#2208)', () => {
|
|
|
97
98
|
expect(resolveStaticLoopSource(parseExpression('items'), locals)).toEqual([{ label: 'Alpha' }])
|
|
98
99
|
})
|
|
99
100
|
|
|
100
|
-
test('a MODULE-scope const
|
|
101
|
+
test('a MODULE-scope const with a static initializer resolves exactly like a function-scope one (#2946)', () => {
|
|
101
102
|
const locals = [constant({ name: 'items', parsed: parseExpression("[{ label: 'Alpha' }]"), isModule: true })]
|
|
103
|
+
expect(resolveStaticLoopSource(parseExpression('items'), locals)).toEqual([{ label: 'Alpha' }])
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('a MODULE-scope const whose initializer is runtime-computed still refuses (#2946)', () => {
|
|
107
|
+
const locals = [constant({ name: 'items', parsed: parseExpression('buildItems()'), isModule: true })]
|
|
102
108
|
expect(resolveStaticLoopSource(parseExpression('items'), locals)).toBeNull()
|
|
103
109
|
})
|
|
104
110
|
|
|
111
|
+
test('a MODULE-scope const shadowed by an enclosing loop param is excluded via isNameShadowed (#2946)', () => {
|
|
112
|
+
const locals = [constant({ name: 'items', parsed: parseExpression("[{ label: 'Alpha' }]"), isModule: true })]
|
|
113
|
+
const result = resolveStaticLoopSource(parseExpression('items'), locals, {
|
|
114
|
+
isNameShadowed: name => name === 'items',
|
|
115
|
+
})
|
|
116
|
+
expect(result).toBeNull()
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
test('a const mutated after its declaration (#2910) refuses regardless of scope', () => {
|
|
120
|
+
const moduleLocals = [
|
|
121
|
+
constant({
|
|
122
|
+
name: 'items',
|
|
123
|
+
parsed: parseExpression("[{ label: 'Alpha' }]"),
|
|
124
|
+
isModule: true,
|
|
125
|
+
mutatedAfterDeclaration: true,
|
|
126
|
+
}),
|
|
127
|
+
]
|
|
128
|
+
expect(resolveStaticLoopSource(parseExpression('items'), moduleLocals)).toBeNull()
|
|
129
|
+
|
|
130
|
+
const functionLocals = [
|
|
131
|
+
constant({
|
|
132
|
+
name: 'items',
|
|
133
|
+
parsed: parseExpression("[{ label: 'Alpha' }]"),
|
|
134
|
+
mutatedAfterDeclaration: true,
|
|
135
|
+
}),
|
|
136
|
+
]
|
|
137
|
+
expect(resolveStaticLoopSource(parseExpression('items'), functionLocals)).toBeNull()
|
|
138
|
+
})
|
|
139
|
+
|
|
105
140
|
test('a runtime-computed local const (#2069) still refuses', () => {
|
|
106
141
|
const locals = [constant({ name: 'entries', parsed: parseExpression('Object.entries(props.tags)') })]
|
|
107
142
|
expect(resolveStaticLoopSource(parseExpression('entries'), locals)).toBeNull()
|
package/src/analyzer-context.ts
CHANGED
|
@@ -29,12 +29,13 @@ import type { CallbackBodyAcceptor } from './adapters/interface.ts'
|
|
|
29
29
|
import { nodeContainsJsx } from './reactivity-checker.ts'
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
32
|
+
* The props destructuring pattern's own source location. Carries no
|
|
33
|
+
* diagnostic of its own — it is the more precise location other
|
|
34
|
+
* props-parameter diagnostics point at instead of the component root (see
|
|
35
|
+
* `compiler.ts`'s `checkRichTypePropSerialization`).
|
|
34
36
|
*/
|
|
35
37
|
export interface PropsDestructuringInfo {
|
|
36
38
|
loc: SourceLocation
|
|
37
|
-
hasIgnoreDirective: boolean
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
/**
|
|
@@ -182,7 +183,7 @@ export interface AnalyzerContext {
|
|
|
182
183
|
restPropsName: string | null
|
|
183
184
|
/** Keys that can be statically expanded from rest props (closed type) */
|
|
184
185
|
restPropsExpandedKeys: string[]
|
|
185
|
-
/**
|
|
186
|
+
/** Set when the props parameter is a destructuring pattern — see `PropsDestructuringInfo`. */
|
|
186
187
|
propsDestructuring: PropsDestructuringInfo | null
|
|
187
188
|
|
|
188
189
|
// JSX return — widened to any `ts.Expression` so the Phase 1 dispatcher
|
|
@@ -322,9 +323,9 @@ export function createAnalyzerContext(
|
|
|
322
323
|
// to compiles with no `error`-severity diagnostic: a compile that
|
|
323
324
|
// already refused loudly may take degraded fallback paths whose
|
|
324
325
|
// artifacts are gated by the error — the invariant this trips on is
|
|
325
|
-
// the SILENT leak. A `warning
|
|
326
|
-
//
|
|
327
|
-
//
|
|
326
|
+
// the SILENT leak. A `warning`-severity diagnostic does not gate
|
|
327
|
+
// anything, so it must not silently disarm this assertion too (#2867)
|
|
328
|
+
// — only `error` severity does.
|
|
328
329
|
if (
|
|
329
330
|
process.env.BF_ASSERT_NO_JSX_IN_GETJS === '1' &&
|
|
330
331
|
!this.errors.some((e) => e.severity === 'error') &&
|