@barefootjs/jsx 0.39.7 → 0.39.8
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/callback-method.d.ts +17 -0
- package/dist/adapters/callback-method.d.ts.map +1 -1
- package/dist/adapters/component-props.d.ts +80 -13
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +151 -0
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -0
- package/dist/adapters/jsx-adapter.d.ts +4 -0
- package/dist/adapters/jsx-adapter.d.ts.map +1 -1
- package/dist/adapters/literal-value.d.ts +2 -2
- package/dist/adapters/literal-value.d.ts.map +1 -1
- package/dist/adapters/parsed-expr-emitter.d.ts +27 -0
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/style-object.d.ts +33 -0
- package/dist/adapters/style-object.d.ts.map +1 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/children-nullish.d.ts +22 -0
- package/dist/children-nullish.d.ts.map +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +9 -19
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/free-refs.d.ts +6 -0
- package/dist/free-refs.d.ts.map +1 -1
- package/dist/index.d.ts +14 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14685 -14000
- package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts +2 -1
- package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -2
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts +10 -9
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
- package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-registration.d.ts +10 -8
- package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
- package/dist/ir-to-client-js/generate-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts +0 -9
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/identifiers.d.ts +6 -8
- package/dist/ir-to-client-js/identifiers.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +23 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -2
- package/dist/ir-to-client-js/phases/props-extraction.d.ts.map +1 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +1 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/rewrite-destructured-props.d.ts +1 -1
- package/dist/ir-to-client-js/rewrite-destructured-props.d.ts.map +1 -1
- package/dist/ir-to-client-js/safe-html.d.ts +20 -2
- package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +3 -3
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +2 -11
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +40 -10
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/prop-rewrite.d.ts +18 -0
- package/dist/prop-rewrite.d.ts.map +1 -1
- package/dist/props-binding.d.ts +9 -1
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/scanner/js-scanner.d.ts.map +1 -1
- package/dist/scanner/js-scanner.js +30 -2
- package/dist/signal-prop-name-collision.d.ts +6 -5
- package/dist/signal-prop-name-collision.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +28 -0
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/ssr-seed-plan.d.ts +39 -14
- package/dist/ssr-seed-plan.d.ts.map +1 -1
- package/dist/types.d.ts +108 -18
- package/dist/types.d.ts.map +1 -1
- package/dist/value-references.d.ts +21 -0
- package/dist/value-references.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +18 -18
- package/src/__tests__/adapter-output.test.ts +5 -3
- package/src/__tests__/analyzer.test.ts +33 -0
- package/src/__tests__/arithmetic-lowering.test.ts +44 -0
- package/src/__tests__/children-read.test.ts +226 -0
- package/src/__tests__/client-template-escape-soundness.test.ts +31 -1
- package/src/__tests__/component-props.test.ts +68 -1
- package/src/__tests__/constant-inlining-tree.test.ts +136 -0
- package/src/__tests__/destructure-default-reads-earlier-param.test.ts +138 -0
- package/src/__tests__/dsl-template-adapter.test.ts +173 -0
- package/src/__tests__/event-handler-verbatim.test.ts +73 -0
- package/src/__tests__/expression-parser.test.ts +1 -44
- package/src/__tests__/nullable-signal-attr.test.ts +67 -3
- package/src/__tests__/reference-graph-identifiers.test.ts +161 -0
- package/src/__tests__/runtime-import-detection.test.ts +134 -0
- package/src/__tests__/signal-prop-name-collision.test.ts +30 -0
- package/src/__tests__/ssr-defaults.test.ts +19 -1
- package/src/__tests__/ssr-seed-plan.test.ts +119 -0
- package/src/__tests__/style-object-plan.test.ts +54 -0
- package/src/__tests__/zero-param-helper-inline.test.ts +57 -0
- package/src/adapters/callback-method.ts +23 -0
- package/src/adapters/component-props.ts +130 -12
- package/src/adapters/dsl-template-adapter.ts +248 -0
- package/src/adapters/jsx-adapter.ts +12 -6
- package/src/adapters/literal-value.ts +2 -2
- package/src/adapters/parsed-expr-emitter.ts +34 -0
- package/src/adapters/style-object.ts +61 -0
- package/src/analyzer.ts +114 -15
- package/src/children-nullish.ts +33 -0
- package/src/debug.ts +2 -2
- package/src/errors.ts +12 -0
- package/src/expression-parser.ts +56 -53
- package/src/free-refs.ts +28 -17
- package/src/index.ts +18 -8
- package/src/ir-to-client-js/compute-inlinability.ts +29 -2
- package/src/ir-to-client-js/control-flow/plan/event-collision.ts +2 -1
- package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -2
- package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +3 -2
- package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +13 -12
- package/src/ir-to-client-js/csr-substitute.ts +12 -2
- package/src/ir-to-client-js/emit-reactive.ts +2 -2
- package/src/ir-to-client-js/emit-registration.ts +28 -57
- package/src/ir-to-client-js/generate-init.ts +17 -1
- package/src/ir-to-client-js/html-template.ts +30 -50
- package/src/ir-to-client-js/identifiers.ts +75 -24
- package/src/ir-to-client-js/imports.ts +56 -19
- package/src/ir-to-client-js/index.ts +2 -1
- package/src/ir-to-client-js/phases/event-handlers.ts +2 -2
- package/src/ir-to-client-js/phases/props-extraction.ts +16 -15
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +2 -2
- package/src/ir-to-client-js/prune-unused-prop-extractions.ts +7 -4
- package/src/ir-to-client-js/reactivity.ts +2 -2
- package/src/ir-to-client-js/rewrite-destructured-props.ts +21 -4
- package/src/ir-to-client-js/safe-html.ts +29 -35
- package/src/ir-to-client-js/types.ts +3 -2
- package/src/ir-to-client-js/utils.ts +2 -26
- package/src/jsx-to-ir.ts +279 -78
- package/src/nullable-signal-attr.ts +149 -33
- package/src/prop-rewrite.ts +41 -0
- package/src/props-binding.ts +17 -2
- package/src/scanner/__tests__/js-scanner.test.ts +37 -0
- package/src/scanner/js-scanner.ts +64 -4
- package/src/signal-prop-name-collision.ts +50 -24
- package/src/ssr-defaults.ts +47 -20
- package/src/ssr-seed-plan.ts +103 -23
- package/src/types.ts +115 -19
- package/src/value-references.ts +132 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client-JS reference graph finds identifiers with TypeScript's scanner
|
|
3
|
+
* (#3536).
|
|
4
|
+
*
|
|
5
|
+
* The graph decides which locals the emitted `init` keeps. Its identifier
|
|
6
|
+
* scan used to be the regex `\b[a-zA-Z_][a-zA-Z0-9_]*\b`: `$` is not a word
|
|
7
|
+
* character, so a `$`-named local reached only through a helper was dropped
|
|
8
|
+
* and the handler threw ReferenceError. Words inside strings, comments and
|
|
9
|
+
* template static text were collected too.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { describe, test, expect } from 'bun:test'
|
|
13
|
+
import { compileJSX } from '../compiler'
|
|
14
|
+
import { TestAdapter } from '../adapters/test-adapter'
|
|
15
|
+
import { HonoAdapter } from '../../../adapter-hono/src/adapter/index'
|
|
16
|
+
import {
|
|
17
|
+
extractIdentifiers,
|
|
18
|
+
extractTemplateExpressions,
|
|
19
|
+
extractTemplateIdentifiers,
|
|
20
|
+
} from '../ir-to-client-js/identifiers'
|
|
21
|
+
|
|
22
|
+
const adapter = new TestAdapter()
|
|
23
|
+
|
|
24
|
+
function clientJsFor(locals: string, handlerBody: string): string {
|
|
25
|
+
const source = `
|
|
26
|
+
'use client'
|
|
27
|
+
import { createSignal } from '@barefootjs/client'
|
|
28
|
+
export function T(props: { n: number }) {
|
|
29
|
+
const [count, setCount] = createSignal(0)
|
|
30
|
+
${locals}
|
|
31
|
+
return <button onClick={() => setCount(${handlerBody})}>{count()}</button>
|
|
32
|
+
}
|
|
33
|
+
`
|
|
34
|
+
const result = compileJSX(source, 'T.tsx', { adapter })
|
|
35
|
+
expect(result.errors).toHaveLength(0)
|
|
36
|
+
return result.files.find(f => f.type === 'clientJs')!.content
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('reference graph keeps $-named locals (#3536)', () => {
|
|
40
|
+
for (const name of ['step$', '$step', '$', 'a$b']) {
|
|
41
|
+
test(`a local \`${name}\` reached only through a helper is emitted`, () => {
|
|
42
|
+
const js = clientJsFor(
|
|
43
|
+
`const ${name} = props.n * 2\n const _helper = (x: number) => x + ${name}`,
|
|
44
|
+
'_helper(count())',
|
|
45
|
+
)
|
|
46
|
+
expect(js).toContain(`const ${name} = `)
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
test('a contextual-keyword local (`type`) reached through a helper is emitted', () => {
|
|
51
|
+
const js = clientJsFor('const type = props.n + 1\n const _helper = (x: number) => x + type', '_helper(count())')
|
|
52
|
+
expect(js).toContain('const type = ')
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
describe('extractIdentifiers', () => {
|
|
57
|
+
const ids = (expr: string) => {
|
|
58
|
+
const set = new Set<string>()
|
|
59
|
+
extractIdentifiers(expr, set)
|
|
60
|
+
return [...set].sort()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
test('skips string contents, comments and template static text; keeps member names', () => {
|
|
64
|
+
// A member name stays in: the graph reads `props.value` as a use of the
|
|
65
|
+
// `value` prop in props-object mode.
|
|
66
|
+
expect(ids("obj.member + other?.deep + 'word in a string' /* note */ + `tpl ${inner}`")).toEqual([
|
|
67
|
+
'deep',
|
|
68
|
+
'inner',
|
|
69
|
+
'member',
|
|
70
|
+
'obj',
|
|
71
|
+
'other',
|
|
72
|
+
])
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('reports $ names and contextual keywords, never reserved words', () => {
|
|
76
|
+
expect(ids('(x) => x + step$ + $ + type + of')).toEqual(['$', 'of', 'step$', 'type', 'x'])
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
describe('template substitutions', () => {
|
|
81
|
+
test('a body with an object literal or a nested template stays whole', () => {
|
|
82
|
+
expect(extractTemplateExpressions('<p>${a ? { x: 1 }.x : b}</p>${`n${deep}`}')).toEqual([
|
|
83
|
+
'a ? { x: 1 }.x : b',
|
|
84
|
+
'`n${deep}`',
|
|
85
|
+
])
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('static text is not scanned for identifiers', () => {
|
|
89
|
+
const set = new Set<string>()
|
|
90
|
+
extractTemplateIdentifiers('<div class="btn size-lg ${cls}">${label$}</div>', set)
|
|
91
|
+
expect([...set].sort()).toEqual(['cls', 'label$'])
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
describe('regex literals and keyword-named members (#3536 review)', () => {
|
|
96
|
+
test('a quote inside a regex literal does not hide a later dependency', () => {
|
|
97
|
+
const js = clientJsFor('const step = props.n * 2\n const _helper = (x: string) => (/"/.test(x) ? step : 0)', "_helper('a')")
|
|
98
|
+
expect(js).toContain('const step = ')
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('division after a contextual-keyword local does not hide a later dependency', () => {
|
|
102
|
+
const js = clientJsFor('const type = props.n\n const step = props.n * 2\n const _helper = () => type / 2 + step / 3', '_helper()')
|
|
103
|
+
expect(js).toContain('const step = ')
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('division after a keyword-named member does not hide a later dependency', () => {
|
|
107
|
+
const js = clientJsFor('const step = props.n * 2\n const _helper = (o: { default: number }) => o.default / 2 + step / 3', '_helper({ default: 1 })')
|
|
108
|
+
expect(js).toContain('const step = ')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
test('a regex literal after the for-of separator does not hide a later dependency', () => {
|
|
112
|
+
const js = clientJsFor(
|
|
113
|
+
'const step = props.n * 2\n const _helper = (x: string) => { for (const hit of /"/.exec(x) || []) {} return step }',
|
|
114
|
+
"_helper('a')",
|
|
115
|
+
)
|
|
116
|
+
expect(js).toContain('const step = ')
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
test('a regex literal after a contextual-keyword for-of binding does not hide a later dependency', () => {
|
|
120
|
+
const js = clientJsFor(
|
|
121
|
+
'const step = props.n * 2\n const _helper = (x: string) => { for (const type of /"/.exec(x) || []) {} return step }',
|
|
122
|
+
"_helper('a')",
|
|
123
|
+
)
|
|
124
|
+
expect(js).toContain('const step = ')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('division on an `of` binding after a line break does not hide a later dependency', () => {
|
|
128
|
+
const js = clientJsFor(
|
|
129
|
+
'const step = props.n * 2\n const _helper = (x: number) => {\n let of = x\n of /= step\n return of\n }',
|
|
130
|
+
'_helper(12)',
|
|
131
|
+
)
|
|
132
|
+
expect(js).toContain('const step = ')
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('a brace inside a regex literal does not close a template substitution', () => {
|
|
136
|
+
expect(extractTemplateExpressions('<p>${/}/.test(dep) ? dep : fallback}</p>')).toEqual([
|
|
137
|
+
'/}/.test(dep) ? dep : fallback',
|
|
138
|
+
])
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('a reserved word read as a member name is reported; as a keyword it is not', () => {
|
|
142
|
+
const set = new Set<string>()
|
|
143
|
+
extractIdentifiers('props.default + obj?.enum + (x instanceof Y)', set)
|
|
144
|
+
expect([...set].sort()).toEqual(['Y', 'default', 'enum', 'obj', 'props', 'x'])
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('a keyword-named prop read only by a handler is still hydrated', () => {
|
|
148
|
+
const source = `
|
|
149
|
+
'use client'
|
|
150
|
+
import { createSignal } from '@barefootjs/client'
|
|
151
|
+
export function T(props: { default: number }) {
|
|
152
|
+
const [count, setCount] = createSignal(0)
|
|
153
|
+
return <button onClick={() => setCount(props.default)}>{count()}</button>
|
|
154
|
+
}
|
|
155
|
+
`
|
|
156
|
+
const hono = compileJSX(source, 'T.tsx', { adapter: new HonoAdapter() })
|
|
157
|
+
expect(hono.errors).toHaveLength(0)
|
|
158
|
+
const template = hono.files.find(f => f.type === 'markedTemplate')!.content
|
|
159
|
+
expect(template).toContain("__hydrateProps['default']")
|
|
160
|
+
})
|
|
161
|
+
})
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime imports come from the names the client JS leaves unbound (#3537).
|
|
3
|
+
*
|
|
4
|
+
* `detectUsedImports` used to regex-scan the emitted code for `name(`, so a
|
|
5
|
+
* user helper that shared a runtime export's name (`function insert`) got a
|
|
6
|
+
* runtime `import { insert }` next to its own `var insert`, a duplicate
|
|
7
|
+
* declaration. Detection now resolves scopes; a module-level binding that
|
|
8
|
+
* collides with a runtime helper is BF057, since it would capture the
|
|
9
|
+
* compiler's own calls to that helper.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { describe, test, expect } from 'bun:test'
|
|
13
|
+
import { compileJSX } from '../compiler'
|
|
14
|
+
import { TestAdapter } from '../adapters/test-adapter'
|
|
15
|
+
import { detectUsedImports } from '../ir-to-client-js/imports'
|
|
16
|
+
|
|
17
|
+
const adapter = new TestAdapter()
|
|
18
|
+
const transpiler = new Bun.Transpiler({ loader: 'js' })
|
|
19
|
+
|
|
20
|
+
function compile(moduleCode: string, body = '<button onClick={() => setItems(items().concat("a"))}>{items().length}</button>') {
|
|
21
|
+
const source = `
|
|
22
|
+
'use client'
|
|
23
|
+
import { createSignal } from '@barefootjs/client'
|
|
24
|
+
${moduleCode}
|
|
25
|
+
export function T() {
|
|
26
|
+
const [items, setItems] = createSignal<string[]>([])
|
|
27
|
+
return ${body}
|
|
28
|
+
}
|
|
29
|
+
`
|
|
30
|
+
const result = compileJSX(source, 'T.tsx', { adapter })
|
|
31
|
+
const clientJs = result.files.find(f => f.type === 'clientJs')?.content ?? ''
|
|
32
|
+
return { errors: result.errors, clientJs }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const runtimeImportLine = (js: string) => js.split('\n').find(l => l.includes("from '@barefootjs/client/runtime'")) ?? ''
|
|
36
|
+
|
|
37
|
+
describe('runtime import detection resolves scopes (#3537)', () => {
|
|
38
|
+
test('a module-level helper named like a runtime export is BF057', () => {
|
|
39
|
+
const { errors } = compile(
|
|
40
|
+
'function insert(list: string[], x: string) { return [...list, x] }',
|
|
41
|
+
'<button onClick={() => setItems(insert(items(), "a"))}>{items().length}</button>',
|
|
42
|
+
)
|
|
43
|
+
expect(errors.map(e => e.code)).toContain('BF057')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('a module-level binding named like a runtime export but never called stays legal', () => {
|
|
47
|
+
const { errors, clientJs } = compile(
|
|
48
|
+
'const qsa = { step: 1 }',
|
|
49
|
+
'<button onClick={() => setItems(items().concat(String(qsa.step)))}>{items().length}</button>',
|
|
50
|
+
)
|
|
51
|
+
expect(errors).toHaveLength(0)
|
|
52
|
+
expect(() => transpiler.transformSync(clientJs)).not.toThrow()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('a value import of a name the compiler always calls is BF057', () => {
|
|
56
|
+
// Every client module registers itself with `hydrate(…)`.
|
|
57
|
+
expect(compile("import hydrate from './lib'").errors.map(e => e.code)).toContain('BF057')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('an inlined literal const binds nothing in the client JS, so it is not BF057', () => {
|
|
61
|
+
const { errors, clientJs } = compile('const qsa = 1', '<p>{items().length + qsa}</p>')
|
|
62
|
+
expect(errors).toHaveLength(0)
|
|
63
|
+
expect(() => transpiler.transformSync(clientJs)).not.toThrow()
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('a value import named like a runtime export is BF057, an aliased one is not', () => {
|
|
67
|
+
expect(compile("import { hydrate } from './lib'").errors.map(e => e.code)).toContain('BF057')
|
|
68
|
+
expect(compile("import { hydrate as hydrateLib } from './lib'").errors.map(e => e.code)).not.toContain('BF057')
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test('a type-only import and a runtime import of the same name are not BF057', () => {
|
|
72
|
+
expect(compile("import type { insert } from './lib'").errors.map(e => e.code)).not.toContain('BF057')
|
|
73
|
+
expect(compile("import { batch } from '@barefootjs/client'").errors.map(e => e.code)).not.toContain('BF057')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('a nested binding that shadows a runtime name neither errors nor drops the import', () => {
|
|
77
|
+
const { errors, clientJs } = compile(
|
|
78
|
+
'',
|
|
79
|
+
'<button onClick={() => { const $ = items(); setItems($.concat("a")) }}>{items().length}</button>',
|
|
80
|
+
)
|
|
81
|
+
expect(errors).toHaveLength(0)
|
|
82
|
+
expect(() => transpiler.transformSync(clientJs)).not.toThrow()
|
|
83
|
+
// The compiler's own slot lookup still needs the runtime `$`.
|
|
84
|
+
expect(runtimeImportLine(clientJs)).toMatch(/[{ ,]\$[ ,}]/)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('a non-colliding module-level helper is emitted once and imported never', () => {
|
|
88
|
+
const { errors, clientJs } = compile(
|
|
89
|
+
'function appendItem(list: string[], x: string) { return [...list, x] }',
|
|
90
|
+
'<button onClick={() => setItems(appendItem(items(), "a"))}>{items().length}</button>',
|
|
91
|
+
)
|
|
92
|
+
expect(errors).toHaveLength(0)
|
|
93
|
+
expect(() => transpiler.transformSync(clientJs)).not.toThrow()
|
|
94
|
+
expect(runtimeImportLine(clientJs)).not.toContain('appendItem')
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
describe('class static blocks (#3537 review)', () => {
|
|
99
|
+
test('a component whose class static block declares `var $` still imports the runtime `$`', () => {
|
|
100
|
+
const source = `
|
|
101
|
+
'use client'
|
|
102
|
+
import { createSignal } from '@barefootjs/client'
|
|
103
|
+
export function T() {
|
|
104
|
+
const [n, setN] = createSignal(0)
|
|
105
|
+
const C = class { static { var $ } }
|
|
106
|
+
return <button onClick={() => { new C(); setN(n() + 1) }}>{n()}</button>
|
|
107
|
+
}
|
|
108
|
+
`
|
|
109
|
+
const result = compileJSX(source, 'T.tsx', { adapter })
|
|
110
|
+
expect(result.errors).toHaveLength(0)
|
|
111
|
+
const clientJs = result.files.find(f => f.type === 'clientJs')!.content
|
|
112
|
+
expect(clientJs).toContain('$(__scope')
|
|
113
|
+
expect(runtimeImportLine(clientJs)).toMatch(/[{,]\s*\$\s*[,}]/)
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
describe('detectUsedImports', () => {
|
|
118
|
+
test('reports a runtime name only where nothing binds it', () => {
|
|
119
|
+
const code = [
|
|
120
|
+
'var insert = insert ?? function (a) { return a }',
|
|
121
|
+
'export function initT(qsa) { qsa(); insert(); createEffect(() => {}) }',
|
|
122
|
+
"hydrate('T', {})",
|
|
123
|
+
].join('\n')
|
|
124
|
+
expect([...detectUsedImports(code)].sort()).toEqual(['createEffect', 'hydrate'])
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('a var inside a class static block binds only inside that block', () => {
|
|
128
|
+
expect([...detectUsedImports('const C = class { static { var $ } }; $(scope, "s0")')]).toEqual(['$'])
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('an object key or member name spelling a runtime name is not a reference', () => {
|
|
132
|
+
expect([...detectUsedImports('const o = { insert: 1 }; o.hydrate(); qsa.x')]).toEqual(['qsa'])
|
|
133
|
+
})
|
|
134
|
+
})
|
|
@@ -56,6 +56,36 @@ test('same-prop derived seeds and ordinary bindings stay unchanged', () => {
|
|
|
56
56
|
expect(ctx.signals.map(s => s.getter)).toEqual(['count', 'other'])
|
|
57
57
|
})
|
|
58
58
|
|
|
59
|
+
test('a signal seeded from another prop, a memo, and a case-folded name are separated', () => {
|
|
60
|
+
const ctx = analyzeComponent(`
|
|
61
|
+
'use client'
|
|
62
|
+
import { createSignal, createMemo } from '@barefootjs/client'
|
|
63
|
+
export function App(props: { label?: string; count?: number; title?: string; b?: string }) {
|
|
64
|
+
const [label] = createSignal(props.b ?? 'y')
|
|
65
|
+
const count = createMemo(() => label().length)
|
|
66
|
+
const [Title] = createSignal(props.b)
|
|
67
|
+
return <p>{label()}{count()}{Title()}{props.label}{props.count}{props.title}</p>
|
|
68
|
+
}
|
|
69
|
+
`, 'test.tsx')
|
|
70
|
+
expect(ctx.signals.map(s => s.getter)).toEqual(['bfSignal_label', 'bfSignal_Title'])
|
|
71
|
+
expect(ctx.memos.map(m => m.name)).toEqual(['bfMemo_count'])
|
|
72
|
+
expect(ctx.memos[0].computation).toContain('bfSignal_label()')
|
|
73
|
+
expect(ctx.sourceFile.text).toContain('{props.label}{props.count}{props.title}')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('a memo derived from its own same-named prop keeps its name', () => {
|
|
77
|
+
const ctx = analyzeComponent(`
|
|
78
|
+
'use client'
|
|
79
|
+
import { createMemo } from '@barefootjs/client'
|
|
80
|
+
export function App(props: { label?: string }) {
|
|
81
|
+
const fallback = props.label
|
|
82
|
+
const label = createMemo(() => (fallback ?? 'none') + '!')
|
|
83
|
+
return <p>{label()}</p>
|
|
84
|
+
}
|
|
85
|
+
`, 'test.tsx')
|
|
86
|
+
expect(ctx.memos.map(m => m.name)).toEqual(['label'])
|
|
87
|
+
})
|
|
88
|
+
|
|
59
89
|
test('signed literal seeds are separated without a type-based program', () => {
|
|
60
90
|
const ctx = analyzeComponent(`
|
|
61
91
|
'use client'
|
|
@@ -303,8 +303,12 @@ describe('extractSsrDefaults', () => {
|
|
|
303
303
|
}
|
|
304
304
|
`)
|
|
305
305
|
|
|
306
|
+
// Not self-derived, so the analyzer renames the getter apart from the
|
|
307
|
+
// prop (`separateSignalPropBindings`): the signal keeps a plain entry
|
|
308
|
+
// under its own name, and the prop keeps its prop entry.
|
|
306
309
|
const defaults = extractSsrDefaults(metadata)
|
|
307
|
-
expect(defaults?.
|
|
310
|
+
expect(defaults?.bfSignal_label).toEqual({ value: null })
|
|
311
|
+
expect(defaults?.label).toEqual({ propName: 'label', value: null })
|
|
308
312
|
})
|
|
309
313
|
|
|
310
314
|
test('aliased destructured prop (#2460): `propName` is the CALLER-facing key, not the local binding', () => {
|
|
@@ -660,6 +664,20 @@ describe('extractSsrDefaults', () => {
|
|
|
660
664
|
expect(defaults?.setCount).toEqual({ value: null })
|
|
661
665
|
expect(defaults?.setCountAlias).toEqual({ value: null })
|
|
662
666
|
})
|
|
667
|
+
|
|
668
|
+
test('a default reading an earlier prop seeds null, so the template applies it (#3531)', () => {
|
|
669
|
+
const metadata = metadataFor(`
|
|
670
|
+
function C({ off = false, on = !off }: { off?: boolean; on?: boolean }) {
|
|
671
|
+
return <p>{String(on)}</p>
|
|
672
|
+
}
|
|
673
|
+
`)
|
|
674
|
+
|
|
675
|
+
const defaults = extractSsrDefaults(metadata)
|
|
676
|
+
expect(defaults?.off).toEqual({ propName: 'off', value: false })
|
|
677
|
+
// A static `!off` would read `true` and win over the in-template
|
|
678
|
+
// `on ?? !off` whatever `off` the caller passed.
|
|
679
|
+
expect(defaults?.on).toEqual({ propName: 'on', value: null })
|
|
680
|
+
})
|
|
663
681
|
})
|
|
664
682
|
|
|
665
683
|
// TS twin of the Ruby/Python/PHP/Perl/Rust `derive*FromDefaults` runtime
|
|
@@ -327,6 +327,65 @@ describe('computeSsrSeedPlan', () => {
|
|
|
327
327
|
}
|
|
328
328
|
})
|
|
329
329
|
|
|
330
|
+
test('a seed calling a zero-param local arrow helper derives through its body (#3562)', () => {
|
|
331
|
+
const plan = planFor(`
|
|
332
|
+
'use client'
|
|
333
|
+
import { createSignal } from '@barefootjs/client'
|
|
334
|
+
function C(props: { mode?: string; label?: string }) {
|
|
335
|
+
const isWide = () => props.mode === 'wide'
|
|
336
|
+
const [shown] = createSignal(isWide() ? props.label : 'narrow')
|
|
337
|
+
return <p>{shown()}</p>
|
|
338
|
+
}
|
|
339
|
+
`)
|
|
340
|
+
const shown = step(plan, 'shown')
|
|
341
|
+
expect(shown.kind).toBe('derived')
|
|
342
|
+
if (shown.kind === 'derived') expect(shown.frees).toEqual(['props'])
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
test('a helper whose body a callback param would capture stays opaque (#3562)', () => {
|
|
346
|
+
const plan = planFor(`
|
|
347
|
+
'use client'
|
|
348
|
+
import { createSignal } from '@barefootjs/client'
|
|
349
|
+
function C(props: { items: string[]; tag?: string }) {
|
|
350
|
+
const tag = props.tag
|
|
351
|
+
const matches = () => tag === 'x'
|
|
352
|
+
const [n] = createSignal(props.items.filter(tag => matches()).length)
|
|
353
|
+
return <p>{n()}</p>
|
|
354
|
+
}
|
|
355
|
+
`)
|
|
356
|
+
expect(step(plan, 'n').kind).toBe('opaque')
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
test.each([
|
|
360
|
+
['an async arrow', 'const helper = async () => props.flag'],
|
|
361
|
+
['a generator function', 'const helper = function* () { return props.flag }'],
|
|
362
|
+
['a body that mutates state', 'let n = 0\n const helper = () => (n += 1)'],
|
|
363
|
+
])('a helper call to %s stays opaque (#3562 review)', (_label, decl) => {
|
|
364
|
+
const plan = planFor(`
|
|
365
|
+
'use client'
|
|
366
|
+
import { createSignal } from '@barefootjs/client'
|
|
367
|
+
function C(props: { flag?: boolean }) {
|
|
368
|
+
${decl}
|
|
369
|
+
const [shown] = createSignal(helper() ? 'yes' : 'no')
|
|
370
|
+
return <p>{shown()}</p>
|
|
371
|
+
}
|
|
372
|
+
`)
|
|
373
|
+
expect(step(plan, 'shown').kind).toBe('opaque')
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
test('a helper that takes params is not inlined at a call site (#3562)', () => {
|
|
377
|
+
const plan = planFor(`
|
|
378
|
+
'use client'
|
|
379
|
+
import { createSignal } from '@barefootjs/client'
|
|
380
|
+
function C(props: { mode?: string }) {
|
|
381
|
+
const is = (m: string) => props.mode === m
|
|
382
|
+
const [wide] = createSignal(is('wide'))
|
|
383
|
+
return <p>{String(wide())}</p>
|
|
384
|
+
}
|
|
385
|
+
`)
|
|
386
|
+
expect(step(plan, 'wide').kind).toBe('opaque')
|
|
387
|
+
})
|
|
388
|
+
|
|
330
389
|
test('multi-hop const chain THROUGH TWO component-scope consts (#2685 review): still derived', () => {
|
|
331
390
|
const plan = planFor(`
|
|
332
391
|
'use client'
|
|
@@ -367,4 +426,64 @@ describe('computeSsrSeedPlan', () => {
|
|
|
367
426
|
const on = step(plan, 'on')
|
|
368
427
|
expect(on.kind).toBe('opaque')
|
|
369
428
|
})
|
|
429
|
+
|
|
430
|
+
test('a derived step reading only inlined module consts, or nothing, is constant (#3542)', () => {
|
|
431
|
+
const plan = planFor(`
|
|
432
|
+
'use client'
|
|
433
|
+
import { createSignal, createMemo } from '@barefootjs/client'
|
|
434
|
+
const PREFIX = 'pre'
|
|
435
|
+
function C(props: { label: string }) {
|
|
436
|
+
const [first] = createSignal([{ a: 'p' }].map((t) => t.a).join(','))
|
|
437
|
+
const [tagged] = createSignal(PREFIX + '-x')
|
|
438
|
+
const [label] = createSignal(props.label + '!')
|
|
439
|
+
const both = createMemo(() => PREFIX + first())
|
|
440
|
+
return <p>{first()}{tagged()}{label()}{both()}</p>
|
|
441
|
+
}
|
|
442
|
+
`)
|
|
443
|
+
const constantOf = (name: string) => {
|
|
444
|
+
const s = step(plan, name)
|
|
445
|
+
return s.kind === 'derived' ? s.constant : null
|
|
446
|
+
}
|
|
447
|
+
expect(constantOf('first')).toBe(true)
|
|
448
|
+
expect(constantOf('tagged')).toBe(true)
|
|
449
|
+
expect(constantOf('label')).toBe(false)
|
|
450
|
+
expect(constantOf('both')).toBe(false)
|
|
451
|
+
})
|
|
452
|
+
|
|
453
|
+
test('a destructure default reading an earlier prop re-binds the prop first, in parameter order (#3531)', () => {
|
|
454
|
+
const plan = planFor(`
|
|
455
|
+
'use client'
|
|
456
|
+
import { createSignal } from '@barefootjs/client'
|
|
457
|
+
function C({ a = 'x', b = a, c = b, off = false, on = !off, plain = 1 }: { a?: string; b?: string; c?: string; off?: boolean; on?: boolean; plain?: number }) {
|
|
458
|
+
const [v] = createSignal(c)
|
|
459
|
+
return <p>{v()}{String(on)}{plain}</p>
|
|
460
|
+
}
|
|
461
|
+
`)
|
|
462
|
+
expect(plan.steps.map(s => s.name)).toEqual(['b', 'c', 'on', 'v'])
|
|
463
|
+
const b = step(plan, 'b')
|
|
464
|
+
expect(b.kind).toBe('derived')
|
|
465
|
+
if (b.kind === 'derived') {
|
|
466
|
+
expect(b.origin).toBe('prop')
|
|
467
|
+
expect(b.parsed).toEqual({
|
|
468
|
+
kind: 'logical',
|
|
469
|
+
op: '??',
|
|
470
|
+
left: { kind: 'identifier', name: 'b' },
|
|
471
|
+
right: { kind: 'identifier', name: 'a' },
|
|
472
|
+
})
|
|
473
|
+
expect(b.constant).toBe(false)
|
|
474
|
+
}
|
|
475
|
+
const on = step(plan, 'on')
|
|
476
|
+
if (on.kind === 'derived') expect(on.expr).toBe('on ?? !off')
|
|
477
|
+
})
|
|
478
|
+
|
|
479
|
+
test('dependent prop defaults follow the reads, not the props type order (#3531)', () => {
|
|
480
|
+
const plan = planFor(`
|
|
481
|
+
'use client'
|
|
482
|
+
function C(props: { c?: string; b?: string; a?: string }) {
|
|
483
|
+
const { a = 'x', b = a, c = b } = props
|
|
484
|
+
return <p>{a}{b}{c}</p>
|
|
485
|
+
}
|
|
486
|
+
`)
|
|
487
|
+
expect(plan.steps.map(s => s.name)).toEqual(['b', 'c'])
|
|
488
|
+
})
|
|
370
489
|
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `planStyleObject` lowers a `style={{ … }}` attribute from the IR's parsed
|
|
3
|
+
* object literal, once for every template adapter (#3541).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, test, expect } from 'bun:test'
|
|
7
|
+
import { planStyleObject } from '../adapters/style-object'
|
|
8
|
+
import { parseExpression } from '../expression-parser'
|
|
9
|
+
|
|
10
|
+
/** An attribute value as the IR carries it: `parsed` holds the object literal. */
|
|
11
|
+
const attr = (source: string) => ({ expr: source, parsed: parseExpression(`(${source})`) })
|
|
12
|
+
|
|
13
|
+
describe('planStyleObject', () => {
|
|
14
|
+
test('kebab-cases keys and splits literal vs expression values', () => {
|
|
15
|
+
expect(planStyleObject(attr("{ backgroundColor: color, padding: '8px' }"))).toEqual([
|
|
16
|
+
{ cssKey: 'background-color', kind: 'expr', expr: 'color', parsed: { kind: 'identifier', name: 'color' } },
|
|
17
|
+
{ cssKey: 'padding', kind: 'literal', value: '8px' },
|
|
18
|
+
])
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test('accepts the shorthand `{ color }` the text parser refused', () => {
|
|
22
|
+
expect(planStyleObject(attr('{ color }'))).toEqual([
|
|
23
|
+
{ cssKey: 'color', kind: 'expr', expr: 'color', parsed: { kind: 'identifier', name: 'color' } },
|
|
24
|
+
])
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('signal-getter calls and numbers are expressions; quoted and template keys are literals', () => {
|
|
28
|
+
const plan = planStyleObject(attr("{ background: bg(), 'z-index': '1', width: `10px`, padding: 8 }"))
|
|
29
|
+
expect(plan?.map(e => [e.cssKey, e.kind === 'literal' ? e.value : e.expr])).toEqual([
|
|
30
|
+
['background', 'bg()'],
|
|
31
|
+
['z-index', '1'],
|
|
32
|
+
['width', '10px'],
|
|
33
|
+
['padding', '8'],
|
|
34
|
+
])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('vendor-prefixed keys keep the leading dash', () => {
|
|
38
|
+
expect(planStyleObject(attr("{ WebkitTransform: 'none', msTransform: 'none' }"))?.map(e => e.cssKey)).toEqual([
|
|
39
|
+
'-webkit-transform',
|
|
40
|
+
'-ms-transform',
|
|
41
|
+
])
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('a spread, a numeric key or a non-object value stays on the refusal path', () => {
|
|
45
|
+
expect(planStyleObject(attr('{ ...rest }'))).toBeNull()
|
|
46
|
+
expect(planStyleObject(attr("{ 1: 'a' }"))).toBeNull()
|
|
47
|
+
expect(planStyleObject(attr('color'))).toBeNull()
|
|
48
|
+
expect(planStyleObject(attr('{}'))).toBeNull()
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('an attribute without a parsed tree stays on the refusal path', () => {
|
|
52
|
+
expect(planStyleObject({ expr: '{ color }' })).toBeNull()
|
|
53
|
+
})
|
|
54
|
+
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #3562: the CSR template substitutes a zero-param local helper
|
|
3
|
+
* (`const isWide = () => props.mode === 'wide'`) like any other const, so a
|
|
4
|
+
* template call `isWide()` reads its body instead of falling back to empty.
|
|
5
|
+
* A helper that is not a synchronous, pure value (a body that mutates state,
|
|
6
|
+
* an async arrow, a generator) is left alone: splicing `() => ({ id:
|
|
7
|
+
* ++nextId })` produced `++(0)`, a SyntaxError in the client bundle.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, test, expect } from 'bun:test'
|
|
11
|
+
import { compileJSX } from '../compiler'
|
|
12
|
+
import { HonoAdapter } from '../../../adapter-hono/src/adapter/hono-adapter'
|
|
13
|
+
|
|
14
|
+
const PRELUDE = "'use client'\nimport { createSignal } from '@barefootjs/client'\n"
|
|
15
|
+
|
|
16
|
+
function compile(body: string, jsx: string) {
|
|
17
|
+
const source = `${PRELUDE}export function S(props: { mode?: string; flag?: boolean }) {\n${body}\nreturn ${jsx}\n}`
|
|
18
|
+
const result = compileJSX(source, 'S.tsx', { adapter: new HonoAdapter() })
|
|
19
|
+
const clientJs = result.files.find((f) => f.path.endsWith('.client.js'))?.content ?? ''
|
|
20
|
+
const template = clientJs.split('\n').find((l) => l.includes('hydrate(')) ?? ''
|
|
21
|
+
return { clientJs, template }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Evaluate the registered `template:` lambda against `props`. */
|
|
25
|
+
function render(template: string, props: Record<string, unknown>): string {
|
|
26
|
+
const lambda = template.match(/template: (\(_p\) => `.*`) \}\)/)?.[1]
|
|
27
|
+
expect(lambda).toBeDefined()
|
|
28
|
+
return new Function('escapeAttr', 'escapeTextOrMarkup', `return ${lambda}`)(String, String)(props)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('zero-param helper in the CSR template (#3562)', () => {
|
|
32
|
+
test('a pure helper call reads its body', () => {
|
|
33
|
+
const { template } = compile(
|
|
34
|
+
"const isWide = () => props.mode === 'wide'\nconst [shown] = createSignal(isWide() ? 'wide' : 'narrow')",
|
|
35
|
+
'<p data-shown={shown()}>x</p>',
|
|
36
|
+
)
|
|
37
|
+
expect(render(template, { mode: 'wide' })).toContain('data-shown="wide"')
|
|
38
|
+
expect(render(template, { mode: 'tall' })).toContain('data-shown="narrow"')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('a helper that mutates state is not spliced, and the bundle still parses', () => {
|
|
42
|
+
const { clientJs } = compile(
|
|
43
|
+
"let nextId = 0\nconst createField = () => ({ id: ++nextId, value: '' })\nconst [fields] = createSignal([createField()])",
|
|
44
|
+
'<ul>{fields().map((f) => <li key={f.id}>{f.value}</li>)}</ul>',
|
|
45
|
+
)
|
|
46
|
+
expect(clientJs).not.toContain('++(')
|
|
47
|
+
expect(() => new Bun.Transpiler({ loader: 'js' }).transformSync(clientJs)).not.toThrow()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test.each([
|
|
51
|
+
['an async arrow', 'const helper = async () => props.flag'],
|
|
52
|
+
['a generator function', 'const helper = function* () { return props.flag }'],
|
|
53
|
+
])('%s is not spliced', (_label, decl) => {
|
|
54
|
+
const { template } = compile(`${decl}\nconst [shown] = createSignal(helper() ? 'yes' : 'no')`, '<p data-shown={shown()}>x</p>')
|
|
55
|
+
expect(template).not.toContain('_p.flag')
|
|
56
|
+
})
|
|
57
|
+
})
|
|
@@ -351,6 +351,29 @@ export function unloweredCallRefusal(
|
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
+
/**
|
|
355
|
+
* BF101 for a `.filter(...).map(...)` predicate shape a DSL adapter's filter
|
|
356
|
+
* emitter has no form for: a conditional, a template literal, an object
|
|
357
|
+
* literal, a standalone arrow or regex, or an unsupported node (#3534). The
|
|
358
|
+
* emitters used to stand a truthy constant in for these, so every row
|
|
359
|
+
* rendered; the same predicate outside a loop is evaluated or refused, never
|
|
360
|
+
* guessed.
|
|
361
|
+
*/
|
|
362
|
+
export function filterPredicateShapeRefusal(shape: string, adapterName: string): { message: string; suggestion: string } {
|
|
363
|
+
return {
|
|
364
|
+
message: `Filter predicate contains ${shape}, which has no ${adapterName} loop-filter form`,
|
|
365
|
+
suggestion: `Rewrite the predicate as comparisons joined with && / || / !, or add /* @client */ for client-only evaluation (no SSR).`,
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** BF101 for a loop filter whose predicate never reached the IR (#3534). */
|
|
370
|
+
export function missingFilterPredicateRefusal(raw: string, adapterName: string): { message: string; suggestion: string } {
|
|
371
|
+
return {
|
|
372
|
+
message: `Filter predicate '${raw}' has no ${adapterName} loop-filter form`,
|
|
373
|
+
suggestion: `Rewrite the predicate as an expression-body arrow, or add /* @client */ for client-only evaluation (no SSR).`,
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
354
377
|
/**
|
|
355
378
|
* The BF101 for a callback method nested inside a filter predicate, which a
|
|
356
379
|
* predicate emitter has no scalar form for.
|