@barefootjs/jsx 0.39.4 → 0.39.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/adapters/array-method.d.ts +93 -0
- package/dist/adapters/array-method.d.ts.map +1 -0
- package/dist/adapters/attr-plan.d.ts +135 -0
- package/dist/adapters/attr-plan.d.ts.map +1 -0
- package/dist/adapters/boolean-result.d.ts +84 -9
- package/dist/adapters/boolean-result.d.ts.map +1 -1
- package/dist/adapters/callback-method.d.ts +126 -0
- package/dist/adapters/callback-method.d.ts.map +1 -0
- package/dist/adapters/component-props.d.ts +99 -0
- package/dist/adapters/component-props.d.ts.map +1 -0
- package/dist/adapters/component-tree.d.ts +25 -0
- package/dist/adapters/component-tree.d.ts.map +1 -0
- package/dist/adapters/filter-capture-collisions.d.ts +17 -0
- package/dist/adapters/filter-capture-collisions.d.ts.map +1 -0
- package/dist/adapters/literal-value.d.ts +22 -0
- package/dist/adapters/literal-value.d.ts.map +1 -0
- package/dist/adapters/loop-plan.d.ts +53 -0
- package/dist/adapters/loop-plan.d.ts.map +1 -0
- package/dist/adapters/parsed-expr-emitter.d.ts +8 -0
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/prop-classes.d.ts +37 -0
- package/dist/adapters/prop-classes.d.ts.map +1 -0
- package/dist/adapters/template-name-collisions.d.ts +21 -0
- package/dist/adapters/template-name-collisions.d.ts.map +1 -0
- package/dist/analyzer-context.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +48 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/index.d.ts +20 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2077 -1000
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts +8 -0
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts +3 -2
- 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/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +39 -1
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts +465 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +31 -0
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/scope/binding-scope.d.ts +10 -0
- package/dist/scope/binding-scope.d.ts.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +1 -1
- package/src/__tests__/action-accessor.test.ts +6 -24
- package/src/__tests__/array-method-catalogue.test.ts +99 -0
- package/src/__tests__/attr-plan.test.ts +121 -0
- package/src/__tests__/binding-scope-ratchet.test.ts +13 -13
- package/src/__tests__/binding-scope.test.ts +11 -0
- package/src/__tests__/boolean-result-expr.test.ts +106 -0
- package/src/__tests__/boolean-result.test.ts +34 -1
- package/src/__tests__/callback-method.test.ts +189 -0
- package/src/__tests__/compile-without-node-process.test.ts +78 -0
- package/src/__tests__/component-props.test.ts +148 -0
- package/src/__tests__/delegated-handler-preamble.test.ts +4 -4
- package/src/__tests__/doc-examples.test.ts +1 -0
- package/src/__tests__/dsl-shared-helpers.test.ts +166 -0
- package/src/__tests__/issue-3240-nested-static-map-event-delegation.test.ts +1 -1
- package/src/__tests__/loop-plan.test.ts +104 -0
- package/src/__tests__/map-call-decisions.test.ts +521 -0
- package/src/__tests__/nested-row-shadowing.test.ts +57 -0
- package/src/__tests__/nullable-signal-attr.test.ts +45 -0
- package/src/__tests__/rename-free-identifiers.test.ts +26 -0
- package/src/__tests__/template-name-collisions.test.ts +81 -0
- package/src/adapters/array-method.ts +193 -0
- package/src/adapters/attr-plan.ts +200 -0
- package/src/adapters/boolean-result.ts +208 -12
- package/src/adapters/callback-method.ts +301 -0
- package/src/adapters/component-props.ts +144 -0
- package/src/adapters/component-tree.ts +118 -0
- package/src/adapters/filter-capture-collisions.ts +29 -0
- package/src/adapters/literal-value.ts +36 -0
- package/src/adapters/loop-plan.ts +88 -0
- package/src/adapters/parsed-expr-emitter.ts +18 -0
- package/src/adapters/prop-classes.ts +73 -0
- package/src/adapters/template-name-collisions.ts +120 -0
- package/src/analyzer-context.ts +15 -1
- package/src/expression-parser.ts +569 -374
- package/src/index.ts +58 -3
- package/src/ir-to-client-js/collect-elements.ts +11 -7
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +31 -10
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +12 -5
- package/src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts +2 -2
- package/src/ir-to-client-js/control-flow/shared.ts +4 -1
- package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +9 -7
- package/src/ir-to-client-js/html-template.ts +13 -7
- package/src/ir-to-client-js/index.ts +7 -2
- package/src/ir-to-client-js/utils.ts +81 -7
- package/src/jsx-to-ir.ts +1328 -991
- package/src/nullable-signal-attr.ts +116 -6
- package/src/scope/binding-scope.ts +19 -0
- package/src/types.ts +7 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The higher-order callback chain shared by the DSL adapters (#3477): what
|
|
3
|
+
* each `CALLBACK_METHODS` call lowers to, independent of any DSL's spelling,
|
|
4
|
+
* and the support gate's refusal of a callback that reads its index.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, test, expect } from 'bun:test'
|
|
8
|
+
import {
|
|
9
|
+
emitCallbackEval,
|
|
10
|
+
lowerCallbackMethod,
|
|
11
|
+
type CallbackEvalSpelling,
|
|
12
|
+
type CallbackLoweringOptions,
|
|
13
|
+
} from '../adapters/callback-method'
|
|
14
|
+
import {
|
|
15
|
+
asCallbackMethodCall,
|
|
16
|
+
isSupported,
|
|
17
|
+
parseExpression,
|
|
18
|
+
unboundCallbackParamRead,
|
|
19
|
+
type ParsedExpr,
|
|
20
|
+
} from '../expression-parser'
|
|
21
|
+
|
|
22
|
+
const jinja: CallbackLoweringOptions = { adapterName: 'Jinja' }
|
|
23
|
+
const kolon: CallbackLoweringOptions = { adapterName: 'Xslate', nativePredicate: true }
|
|
24
|
+
|
|
25
|
+
function callOf(source: string) {
|
|
26
|
+
const call = asCallbackMethodCall(parseExpression(source))
|
|
27
|
+
if (!call) throw new Error(`not a callback method call: ${source}`)
|
|
28
|
+
return call
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const lower = (source: string, options = jinja) => {
|
|
32
|
+
const call = callOf(source)
|
|
33
|
+
return lowerCallbackMethod(call.method, call.arrow, call.args, options)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const spelling: CallbackEvalSpelling = {
|
|
37
|
+
call: (helper, operands) => `bf.${helper}(${operands.join(', ')})`,
|
|
38
|
+
string: (value) => `'${value.replace(/'/g, "\\'")}'`,
|
|
39
|
+
boolean: (value) => (value ? 'T' : 'F'),
|
|
40
|
+
env: (entries) => `{${entries.map(([name, value]) => `${name}=${value}`).join(', ')}}`,
|
|
41
|
+
}
|
|
42
|
+
const emitIdentifier = (e: ParsedExpr) => (e.kind === 'identifier' ? `$${e.name}` : '?')
|
|
43
|
+
|
|
44
|
+
function render(source: string, options = jinja): string {
|
|
45
|
+
const plan = lower(source, options)
|
|
46
|
+
if (plan.kind !== 'eval') throw new Error(`expected an eval plan, got ${plan.kind}`)
|
|
47
|
+
return emitCallbackEval(plan, 'RECV', emitIdentifier, spelling)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('lowerCallbackMethod: predicates', () => {
|
|
51
|
+
test('a serializable predicate goes to its evaluator helper with the captured names', () => {
|
|
52
|
+
expect(render('items.filter(x => x > limit)')).toBe(
|
|
53
|
+
`bf.filter_eval(RECV, '{"kind":"binary","op":">","left":{"kind":"identifier","name":"x"},"right":{"kind":"identifier","name":"limit"}}', 'x', {limit=$limit})`,
|
|
54
|
+
)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('the find family carries its direction', () => {
|
|
58
|
+
expect(render('items.find(x => x.done)')).toEndWith(`, 'x', T, {})`)
|
|
59
|
+
expect(render('items.findLast(x => x.done)')).toEndWith(`, 'x', F, {})`)
|
|
60
|
+
expect(render('items.findIndex(x => x.done)')).toStartWith('bf.find_index_eval(')
|
|
61
|
+
expect(render('items.findLastIndex(x => x.done)')).toEndWith(`, 'x', F, {})`)
|
|
62
|
+
expect(render('items.every(x => x.done)')).toStartWith('bf.every_eval(')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('a predicate the evaluator cannot model: BF101 naming the adapter, or the native form', () => {
|
|
66
|
+
const refused = lower('items.filter(x => x.name.localeCompare(q) > 0)')
|
|
67
|
+
expect(refused).toMatchObject({ kind: 'refuse' })
|
|
68
|
+
expect(refused.kind === 'refuse' && refused.message).toBe(
|
|
69
|
+
`'.filter(...)' predicate is outside the Jinja adapter's evaluable surface`,
|
|
70
|
+
)
|
|
71
|
+
expect(lower('items.filter(x => x.name.startsWith(q))', kolon)).toMatchObject({
|
|
72
|
+
kind: 'native-predicate',
|
|
73
|
+
method: 'filter',
|
|
74
|
+
param: 'x',
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test('the native form never takes an opaque call: it would read the callee instead', () => {
|
|
79
|
+
expect(lower('items.filter(x => x.name.localeCompare(q) > 0)', kolon)).toMatchObject({ kind: 'refuse' })
|
|
80
|
+
expect(lower('items.filter(x => isOk(x))', kolon)).toMatchObject({ kind: 'refuse' })
|
|
81
|
+
// A zero-arg call is a signal getter, which the native form reads correctly.
|
|
82
|
+
expect(lower('items.filter(x => x.n > limit())', kolon)).toMatchObject({ kind: 'native-predicate' })
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('the native form never takes a nested callback that reads its index: it binds the element only', () => {
|
|
86
|
+
const nested = `rows.filter(row => row.join(',').startsWith('a') && row.filter((x, i) => i > 0).length > 0)`
|
|
87
|
+
expect(lower(nested, kolon)).toMatchObject({ kind: 'refuse' })
|
|
88
|
+
expect(lower(`rows.filter(row => row.join(',').startsWith('a') && row.filter(x => x > 0).length > 0)`, kolon)).toMatchObject({
|
|
89
|
+
kind: 'native-predicate',
|
|
90
|
+
})
|
|
91
|
+
// The evaluator binds the nested index, so a serializable predicate keeps it.
|
|
92
|
+
expect(lower('rows.filter(row => row.filter((x, i) => i > 0).length > 0)', kolon)).toMatchObject({ kind: 'eval' })
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test('the identity filter goes native only on an adapter with a native form', () => {
|
|
96
|
+
expect(lower('items.filter(x => x)', kolon)).toMatchObject({ kind: 'native-predicate', method: 'filter' })
|
|
97
|
+
expect(lower('items.filter(x => x)')).toMatchObject({ kind: 'eval', helper: 'filter_eval' })
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
describe('lowerCallbackMethod: sort, reduce, projections', () => {
|
|
102
|
+
test('a sort comparator goes to the evaluator, then the structured descriptor, then BF101', () => {
|
|
103
|
+
expect(render('items.toSorted((a, b) => a.n - b.n)')).toStartWith(`bf.sort_eval(RECV, '{`)
|
|
104
|
+
expect(render('items.toSorted((a, b) => a.n - b.n)')).toEndWith(`, 'a', 'b', {})`)
|
|
105
|
+
expect(lower('items.sort((a, b) => a.name.localeCompare(b.name))')).toMatchObject({ kind: 'structured-sort' })
|
|
106
|
+
expect(lower('items.sort((a, b) => a.name.localeCompare(b.name, locale))')).toEqual({
|
|
107
|
+
kind: 'refuse',
|
|
108
|
+
message: `'.sort(...)' comparator is outside the Jinja adapter's evaluable / structured surface`,
|
|
109
|
+
suggestion: `Pre-compute the sorted array, or move this position to a '/* @client */' boundary.`,
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('a reducer needs a string or number literal seed', () => {
|
|
114
|
+
expect(render('items.reduce((acc, x) => acc + x.n, 0)')).toEndWith(`, 'acc', 'x', 0, 'left', {})`)
|
|
115
|
+
expect(render(`items.reduceRight((acc, x) => acc + x, '')`)).toEndWith(`, 'acc', 'x', '', 'right', {})`)
|
|
116
|
+
expect(render('items.reduce((acc, x) => acc + x, 1.5)')).toEndWith(`, 1.5, 'left', {})`)
|
|
117
|
+
for (const source of ['items.reduce((acc, x) => acc + x)', 'items.reduce((acc, x) => acc + x, start)', 'items.reduce((acc, x) => acc + x, true)']) {
|
|
118
|
+
const plan = lower(source)
|
|
119
|
+
expect(plan.kind === 'refuse' && plan.message).toBe(
|
|
120
|
+
`'.reduce(...)' is outside the Jinja adapter's evaluable surface (needs a literal initial value and an evaluable reducer body)`,
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
test('map and flatMap project through their evaluators', () => {
|
|
126
|
+
expect(render('items.map(x => x.n * k)')).toEndWith(`, 'x', {k=$k})`)
|
|
127
|
+
expect(render('items.flatMap(x => x.tags)')).toStartWith('bf.flat_map_eval(RECV, ')
|
|
128
|
+
const plan = lower('items.map(x => x.name.localeCompare(q))')
|
|
129
|
+
expect(plan.kind === 'refuse' && plan.message).toBe(`'.map(...)' projection is outside the Jinja adapter's evaluable surface`)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('the env names come after the receiver and the operands, in sorted order', () => {
|
|
133
|
+
const order: string[] = []
|
|
134
|
+
const plan = lower('items.filter(x => x > b && x < a)')
|
|
135
|
+
if (plan.kind !== 'eval') throw new Error(plan.kind)
|
|
136
|
+
emitCallbackEval(plan, 'RECV', (e) => (order.push(emitIdentifier(e)), emitIdentifier(e)), spelling)
|
|
137
|
+
expect(order).toEqual(['$a', '$b'])
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
describe('unboundCallbackParamRead: the index and array params', () => {
|
|
142
|
+
const read = (source: string) => {
|
|
143
|
+
const call = callOf(source)
|
|
144
|
+
return unboundCallbackParamRead(call.method, call.arrow)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
test('a callback that reads its index or array param is found', () => {
|
|
148
|
+
expect(read('items.map((x, i) => x + i)')).toBe('i')
|
|
149
|
+
expect(read('items.filter((x, i, all) => all.length > 1)')).toBe('all')
|
|
150
|
+
expect(read('items.reduce((acc, x, i) => acc + i, 0)')).toBe('i')
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
test("'evaluator' scope binds a .map / .filter index, nothing more", () => {
|
|
154
|
+
const call = callOf('items.map((x, i, all) => i)')
|
|
155
|
+
expect(unboundCallbackParamRead(call.method, call.arrow, 'evaluator')).toBeNull()
|
|
156
|
+
const arr = callOf('items.filter((x, i, all) => all.length)')
|
|
157
|
+
expect(unboundCallbackParamRead(arr.method, arr.arrow, 'evaluator')).toBe('all')
|
|
158
|
+
const some = callOf('items.some((x, i) => i > 0)')
|
|
159
|
+
expect(unboundCallbackParamRead(some.method, some.arrow, 'evaluator')).toBe('i')
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
test('declared but unread, shadowed, or within the bound params: not found', () => {
|
|
163
|
+
expect(read('items.map((x, i) => x)')).toBeNull()
|
|
164
|
+
expect(read('items.reduce((acc, x, i) => acc + x, 0)')).toBeNull()
|
|
165
|
+
expect(read('items.toSorted((a, b) => a - b)')).toBeNull()
|
|
166
|
+
expect(read('rows.filter((r, i) => r.tags.some(i => i > 0))')).toBeNull()
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
test('the support gate refuses it, at any depth', () => {
|
|
170
|
+
expect(isSupported(parseExpression('items.map((x, i) => x + i).join(",")'))).toMatchObject({
|
|
171
|
+
supported: false,
|
|
172
|
+
reason: expect.stringContaining(`'.map()' callback reads 'i', its index or array parameter`),
|
|
173
|
+
})
|
|
174
|
+
expect(isSupported(parseExpression('rows.filter(r => r.tags.some((t, j) => j > 1)).length')).supported).toBe(false)
|
|
175
|
+
expect(isSupported(parseExpression('items.map((x, i) => x).join(",")')).supported).toBe(true)
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
test('inside an evaluator body, a nested .map / .filter binds its index', () => {
|
|
179
|
+
expect(isSupported(parseExpression(`rows.map(r => r.map((x, i) => i).join(',')).join(';')`)).supported).toBe(true)
|
|
180
|
+
expect(isSupported(parseExpression(`rows.map(r => r.filter((x, i) => i > 0).length)`)).supported).toBe(true)
|
|
181
|
+
expect(isSupported(parseExpression(`rows.some(r => r.map((x, i) => x + i).join('') === q)`)).supported).toBe(true)
|
|
182
|
+
// The evaluator binds neither a nested callback's array param nor the index of
|
|
183
|
+
// a nested callback other than .map / .filter.
|
|
184
|
+
expect(isSupported(parseExpression('rows.map(r => r.map((x, i, all) => all.length))')).supported).toBe(false)
|
|
185
|
+
expect(isSupported(parseExpression('rows.map(r => r.some((x, i) => i > 0))')).supported).toBe(false)
|
|
186
|
+
// The receiver of the outer call is still lowered by the template.
|
|
187
|
+
expect(isSupported(parseExpression('rows.map((r, i) => r.slice(i)).map(r => r.length)')).supported).toBe(false)
|
|
188
|
+
})
|
|
189
|
+
})
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The compiler core must not depend on the Node `process` global.
|
|
3
|
+
*
|
|
4
|
+
* The site playground bundles `@barefootjs/jsx` into a browser Worker
|
|
5
|
+
* (site/core/playground/worker.ts) where `process` does not exist, so a bare
|
|
6
|
+
* `process.env.X` read anywhere on the compile path throws ReferenceError
|
|
7
|
+
* and takes the whole playground down ("Build failed" on first load).
|
|
8
|
+
*
|
|
9
|
+
* This test runs the exact pipeline the worker runs, with `globalThis.process`
|
|
10
|
+
* removed for the duration of the compile, so any new Node-only global read
|
|
11
|
+
* on that path fails here instead of in production.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, test, expect } from 'bun:test'
|
|
15
|
+
import {
|
|
16
|
+
analyzeComponent,
|
|
17
|
+
buildMetadata,
|
|
18
|
+
jsxToIR,
|
|
19
|
+
generateClientJs,
|
|
20
|
+
analyzeClientNeeds,
|
|
21
|
+
listComponentFunctions,
|
|
22
|
+
type ComponentIR,
|
|
23
|
+
} from '../index'
|
|
24
|
+
|
|
25
|
+
const SOURCE = `'use client'
|
|
26
|
+
|
|
27
|
+
import { createSignal } from '@barefootjs/client'
|
|
28
|
+
|
|
29
|
+
export function Counter() {
|
|
30
|
+
const [count, setCount] = createSignal(0)
|
|
31
|
+
return (
|
|
32
|
+
<div>
|
|
33
|
+
<p>Count: {count()}</p>
|
|
34
|
+
<button onClick={() => setCount(count() + 1)}>+1</button>
|
|
35
|
+
</div>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
`
|
|
39
|
+
|
|
40
|
+
const VIRTUAL_PATH = '/playground/component.tsx'
|
|
41
|
+
|
|
42
|
+
/** Mirrors site/core/playground/worker.ts `compile()`. */
|
|
43
|
+
function compileLikeThePlayground(source: string): string {
|
|
44
|
+
const names = listComponentFunctions(source, VIRTUAL_PATH)
|
|
45
|
+
const entryName = names[names.length - 1]
|
|
46
|
+
const ctx = analyzeComponent(source, VIRTUAL_PATH, entryName)
|
|
47
|
+
expect(ctx.errors.filter((e) => e.severity === 'error')).toEqual([])
|
|
48
|
+
const root = jsxToIR(ctx)
|
|
49
|
+
expect(root).toBeTruthy()
|
|
50
|
+
const ir: ComponentIR = {
|
|
51
|
+
version: '0.1',
|
|
52
|
+
metadata: buildMetadata(ctx),
|
|
53
|
+
root: root!,
|
|
54
|
+
errors: [],
|
|
55
|
+
}
|
|
56
|
+
ir.metadata.clientAnalysis = analyzeClientNeeds(ir)
|
|
57
|
+
return generateClientJs(ir)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function withoutNodeProcess<T>(fn: () => T): T {
|
|
61
|
+
const g = globalThis as { process?: unknown }
|
|
62
|
+
const saved = g.process
|
|
63
|
+
// `delete` (not `= undefined`) so a bare `process` identifier throws
|
|
64
|
+
// ReferenceError exactly as it does in a browser Worker.
|
|
65
|
+
delete g.process
|
|
66
|
+
try {
|
|
67
|
+
return fn()
|
|
68
|
+
} finally {
|
|
69
|
+
g.process = saved
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
describe('compiling without the Node `process` global', () => {
|
|
74
|
+
test('the playground compile pipeline produces client JS', () => {
|
|
75
|
+
const clientJs = withoutNodeProcess(() => compileLikeThePlayground(SOURCE))
|
|
76
|
+
expect(clientJs).toContain('Counter')
|
|
77
|
+
})
|
|
78
|
+
})
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The props a DSL adapter passes to a child component (#3479): which entries,
|
|
3
|
+
* spreads and captures `planComponentProps` makes of a component call, and
|
|
4
|
+
* the order `spellComponentProps` spells them in.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, test, expect } from 'bun:test'
|
|
8
|
+
import {
|
|
9
|
+
isEmptyComponentProps,
|
|
10
|
+
planComponentProps,
|
|
11
|
+
spellComponentProps,
|
|
12
|
+
type ComponentPropEntry,
|
|
13
|
+
type ComponentPropsOptions,
|
|
14
|
+
} from '../adapters/component-props'
|
|
15
|
+
import type { AttrValue, IRComponent, IRNode, IRProp } from '../types'
|
|
16
|
+
|
|
17
|
+
const loc = { file: 'x.tsx', start: { line: 1, column: 0 }, end: { line: 1, column: 0 } }
|
|
18
|
+
const text = (value: string): IRNode => ({ type: 'text', value, loc }) as IRNode
|
|
19
|
+
|
|
20
|
+
function prop(name: string, value: AttrValue): IRProp {
|
|
21
|
+
return { name, value, loc } as IRProp
|
|
22
|
+
}
|
|
23
|
+
const literal = (value: string): AttrValue => ({ kind: 'literal', value })
|
|
24
|
+
const expression = (expr: string): AttrValue => ({ kind: 'expression', expr }) as AttrValue
|
|
25
|
+
const spread = (expr: string): AttrValue => ({ kind: 'spread', expr }) as AttrValue
|
|
26
|
+
const jsx = (...children: IRNode[]): AttrValue => ({ kind: 'jsx-children', children }) as AttrValue
|
|
27
|
+
|
|
28
|
+
function component(props: IRProp[], extra: Partial<IRComponent> = {}): IRComponent {
|
|
29
|
+
return {
|
|
30
|
+
type: 'component',
|
|
31
|
+
name: 'Tag',
|
|
32
|
+
props,
|
|
33
|
+
propsType: null,
|
|
34
|
+
children: [],
|
|
35
|
+
template: 'tag',
|
|
36
|
+
slotId: 's0',
|
|
37
|
+
loc,
|
|
38
|
+
...extra,
|
|
39
|
+
} as IRComponent
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const noProps: ComponentPropsOptions = { propsObjectName: null, propsParams: [] }
|
|
43
|
+
const withProps: ComponentPropsOptions = {
|
|
44
|
+
propsObjectName: 'props',
|
|
45
|
+
propsParams: [{ name: 'tone' }, { name: 'size' }],
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The plan, spelled as `key=value` parts and `...spread`. */
|
|
49
|
+
function spell(comp: IRComponent, options = noProps): string[] {
|
|
50
|
+
const describe = (entry: ComponentPropEntry): string => {
|
|
51
|
+
switch (entry.kind) {
|
|
52
|
+
case 'value':
|
|
53
|
+
return `${entry.name}=${entry.value.kind === 'literal' ? `'${entry.value.value}'` : (entry.value as { expr: string }).expr}`
|
|
54
|
+
case 'named-slot':
|
|
55
|
+
return `${entry.name}=<slot>`
|
|
56
|
+
case 'props-param':
|
|
57
|
+
return `${entry.name}=$${entry.name}`
|
|
58
|
+
case 'slot-id':
|
|
59
|
+
return `_bf_slot='${entry.slotId}'`
|
|
60
|
+
case 'children':
|
|
61
|
+
return 'children=<children>'
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return spellComponentProps(planComponentProps(comp, options), {
|
|
65
|
+
entry: describe,
|
|
66
|
+
spread: (value) => value.expr,
|
|
67
|
+
}).map((segment) => (segment.kind === 'spread' ? `...${segment.expr}` : `{${segment.parts.join(', ')}}`))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
describe('planComponentProps', () => {
|
|
71
|
+
test('ordinary props, then the slot id', () => {
|
|
72
|
+
expect(spell(component([prop('tone', literal('warm')), prop('size', expression('size()'))]))).toEqual([
|
|
73
|
+
`{tone='warm', size=size(), _bf_slot='s0'}`,
|
|
74
|
+
])
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('callback props and ref are client-only; a callback-named literal is kept', () => {
|
|
78
|
+
const comp = component([
|
|
79
|
+
prop('onClick', expression('handle')),
|
|
80
|
+
prop('ref', expression('el')),
|
|
81
|
+
prop('onLabel', literal('on')),
|
|
82
|
+
])
|
|
83
|
+
expect(spell(comp)).toEqual([`{onLabel='on', _bf_slot='s0'}`])
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('a loop row root passes no slot id', () => {
|
|
87
|
+
expect(spell(component([prop('tone', literal('warm'))], { loopItemRoot: true }))).toEqual([`{tone='warm'}`])
|
|
88
|
+
expect(spell(component([], { slotId: null }))).toEqual(['{}'])
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test('a spread folds in at its source position', () => {
|
|
92
|
+
const comp = component([prop('tone', literal('a')), prop('', spread('rest')), prop('size', literal('b'))])
|
|
93
|
+
expect(spell(comp)).toEqual([`{tone='a'}`, '...rest', `{size='b', _bf_slot='s0'}`])
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('{...props} enumerates the props params', () => {
|
|
97
|
+
const comp = component([prop('', spread(' props ')), prop('label', literal('x'))])
|
|
98
|
+
expect(spell(comp, withProps)).toEqual([`{tone=$tone, size=$size, label='x', _bf_slot='s0'}`])
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('a repeated key keeps its first position and takes the later value', () => {
|
|
102
|
+
const later = component([prop('', spread('props')), prop('tone', literal('explicit'))])
|
|
103
|
+
expect(spell(later, withProps)).toEqual([`{tone='explicit', size=$size, _bf_slot='s0'}`])
|
|
104
|
+
const earlier = component([prop('tone', literal('first')), prop('', spread('props'))])
|
|
105
|
+
expect(spell(earlier, withProps)).toEqual([`{tone=$tone, size=$size, _bf_slot='s0'}`])
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('a key repeated across a spread stays twice: the spread may set it in between', () => {
|
|
109
|
+
const comp = component([prop('tone', literal('a')), prop('', spread('rest')), prop('tone', literal('b'))])
|
|
110
|
+
expect(spell(comp)).toEqual([`{tone='a'}`, '...rest', `{tone='b', _bf_slot='s0'}`])
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('named slots in place, the children last', () => {
|
|
114
|
+
const nested = component([prop('header', jsx(text('H'))), prop('tone', literal('x'))], { children: [text('C')] })
|
|
115
|
+
expect(spell(nested)).toEqual([`{header=<slot>, tone='x', _bf_slot='s0', children=<children>}`])
|
|
116
|
+
// `children={<jsx/>}` is the children entry, not an ordinary prop.
|
|
117
|
+
const attribute = component([prop('children', jsx(text('C'))), prop('tone', literal('x'))])
|
|
118
|
+
expect(spell(attribute)).toEqual([`{tone='x', _bf_slot='s0', children=<children>}`])
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('the children follow a trailing spread, so the spread cannot override them', () => {
|
|
122
|
+
const comp = component([prop('', spread('rest'))], { children: [text('C')], slotId: null })
|
|
123
|
+
expect(spell(comp)).toEqual(['{}', '...rest', '{children=<children>}'])
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
describe('spellComponentProps', () => {
|
|
128
|
+
test('spells entries in source order and drops an empty part', () => {
|
|
129
|
+
const order: string[] = []
|
|
130
|
+
const comp = component([prop('a', jsx(text('A'))), prop('b', literal('x')), prop('c', jsx(text('C')))], {
|
|
131
|
+
children: [text('D')],
|
|
132
|
+
})
|
|
133
|
+
const segments = spellComponentProps(planComponentProps(comp, noProps), {
|
|
134
|
+
entry: (entry) => {
|
|
135
|
+
order.push(entry.kind === 'slot-id' || entry.kind === 'children' ? entry.kind : entry.name)
|
|
136
|
+
return entry.kind === 'value' ? '' : 'part'
|
|
137
|
+
},
|
|
138
|
+
spread: () => '',
|
|
139
|
+
})
|
|
140
|
+
expect(order).toEqual(['a', 'b', 'c', 'slot-id', 'children'])
|
|
141
|
+
expect(segments).toEqual([{ kind: 'entries', parts: ['part', 'part', 'part', 'part'] }])
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
test('isEmptyComponentProps: no part in any segment', () => {
|
|
145
|
+
expect(isEmptyComponentProps([{ kind: 'entries', parts: [] }])).toBe(true)
|
|
146
|
+
expect(isEmptyComponentProps([{ kind: 'entries', parts: [] }, { kind: 'spread', expr: 'x' }])).toBe(false)
|
|
147
|
+
})
|
|
148
|
+
})
|
|
@@ -83,7 +83,7 @@ describe('delegated-handler preamble splicing (BUG-3 / BUG-4)', () => {
|
|
|
83
83
|
expect(js.split('cells.push')).toHaveLength(4) // three occurrences total
|
|
84
84
|
|
|
85
85
|
// The item guard still gates the handler call.
|
|
86
|
-
expect(handler).toContain('if (t) {')
|
|
86
|
+
expect(handler).toContain('if (t !== undefined) {')
|
|
87
87
|
expect(handler).toContain('(() => del(t.id))(__bfEvt)')
|
|
88
88
|
})
|
|
89
89
|
|
|
@@ -107,8 +107,8 @@ describe('delegated-handler preamble splicing (BUG-3 / BUG-4)', () => {
|
|
|
107
107
|
expect(handler).not.toContain('t().')
|
|
108
108
|
|
|
109
109
|
// Guard-order (part 3): the preamble line and the handler call both
|
|
110
|
-
// land AFTER `if (t) {`, i.e. inside the item-null guard.
|
|
111
|
-
const guardIdx = handler.indexOf('if (t) {')
|
|
110
|
+
// land AFTER `if (t !== undefined) {`, i.e. inside the item-null guard.
|
|
111
|
+
const guardIdx = handler.indexOf('if (t !== undefined) {')
|
|
112
112
|
const preambleIdx = handler.indexOf('const label = t.name')
|
|
113
113
|
const callIdx = handler.indexOf('(() => del(label))(__bfEvt)')
|
|
114
114
|
expect(guardIdx).toBeGreaterThanOrEqual(0)
|
|
@@ -143,7 +143,7 @@ describe('delegated-handler preamble splicing (BUG-3 / BUG-4)', () => {
|
|
|
143
143
|
expect(handler).toContain('(() => del(label))(__bfEvt)')
|
|
144
144
|
|
|
145
145
|
// Guard-order holds for the bindings-branch shape too.
|
|
146
|
-
const guardIdx = handler.indexOf('if (__bfLoopItem) {')
|
|
146
|
+
const guardIdx = handler.indexOf('if (__bfLoopItem !== undefined) {')
|
|
147
147
|
const preambleIdx = handler.indexOf('const label = name')
|
|
148
148
|
const callIdx = handler.indexOf('(() => del(label))(__bfEvt)')
|
|
149
149
|
expect(guardIdx).toBeGreaterThanOrEqual(0)
|
|
@@ -466,6 +466,7 @@ const ERROR_CODES_DOC_TOO_MINIMAL: Record<string, string> = {
|
|
|
466
466
|
BF021: 'BF021 has multiple ❌ snippets in placeholder form (`.map(...)`) — covered concretely by `jsx-compatibility.md` tests; the doc-form snippets here remain placeholder',
|
|
467
467
|
BF044: 'BF044 fires only when a real signal getter is bound. The doc snippet `<Child count={count} />` references an undeclared `count`, so the check is silent — doc snippet needs enrichment',
|
|
468
468
|
BF102: 'BF102 is raised only by the Go adapter, from a boolean-test position its template grammar cannot host (an `else if` predicate, a module-scope helper in an `if` condition) — `TestAdapter` is JS-runtime-style and executes the condition verbatim, so the check is correctly silent here. Covered by the Go adapter\'s conformance pins (`module-helper-boolcontext-call`).',
|
|
469
|
+
BF105: 'BF105 is raised only by the Jinja, MiniJinja, Twig, Pebble and Blade adapters, which rename `loop` to `__bf_loop` — `TestAdapter` keeps names as written, so the check is correctly silent here. Covered by those adapters\' conformance pins (`reserved-name-and-internal-twin`).',
|
|
469
470
|
BF101: 'BF101 is raised by the non-JS template adapters\' own per-adapter checks (Go/Mojo/Xslate/… `renderLoop` / callback lowering), not by the shared `isSupported` gate every adapter shares — `TestAdapter` here is JS-runtime-style like Hono and executes both doc snippets verbatim, so the check is correctly silent. Covered concretely (compiled against the real 8 template adapters, with verbatim diagnostic text) by `jsx-compatibility.md`\'s doc-examples coverage and the `filter-nested-callback-predicate` / `filter-nested-find-predicate` / `static-array-from-props` adapter-conformance fixtures.',
|
|
470
471
|
}
|
|
471
472
|
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The helpers the eight DSL template adapters (Blade, ERB, Jinja,
|
|
3
|
+
* MiniJinja, Mojolicious, Pebble, Twig, Xslate) used to carry one copy each
|
|
4
|
+
* of, now shared from `src/adapters/` (#3475). The adapters' own suites
|
|
5
|
+
* cover the lowering they drive; these pin each helper on its own.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, test, expect } from 'bun:test'
|
|
8
|
+
import { compileJSX } from '../compiler'
|
|
9
|
+
import { TestAdapter } from '../adapters/test-adapter'
|
|
10
|
+
import { isExplicitStringCall } from '../adapters/boolean-result'
|
|
11
|
+
import { collectImportedLoopChildComponentErrors, hasClientInteractivity } from '../adapters/component-tree'
|
|
12
|
+
import { isBareStringLiteral, isLiteralIndex, isStringTypeInfo } from '../adapters/literal-value'
|
|
13
|
+
import { collectBooleanTypedProps, collectNullableOptionalProps, isBooleanTypedPropRef } from '../adapters/prop-classes'
|
|
14
|
+
import { childTemplateName } from '../adapters/component-props'
|
|
15
|
+
import { parseExpression } from '../expression-parser'
|
|
16
|
+
import type { ComponentIR } from '../types'
|
|
17
|
+
|
|
18
|
+
function compileToIR(source: string, file = 'demo.tsx'): ComponentIR {
|
|
19
|
+
const result = compileJSX(source, file, { adapter: new TestAdapter(), outputIR: true })
|
|
20
|
+
const ir = result.files.find(f => f.type === 'ir')
|
|
21
|
+
if (!ir) throw new Error('No IR output')
|
|
22
|
+
return JSON.parse(ir.content) as ComponentIR
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('isExplicitStringCall', () => {
|
|
26
|
+
test('a one-argument String(x) call is explicit', () => {
|
|
27
|
+
expect(isExplicitStringCall('String(props.checked ?? false)')).toBe(true)
|
|
28
|
+
expect(isExplicitStringCall(' String(on()) ')).toBe(true)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('other arities, other callees and non-calls are not', () => {
|
|
32
|
+
expect(isExplicitStringCall('String()')).toBe(false)
|
|
33
|
+
expect(isExplicitStringCall('String(a, b)')).toBe(false)
|
|
34
|
+
expect(isExplicitStringCall('Number(x)')).toBe(false)
|
|
35
|
+
expect(isExplicitStringCall('obj.String(x)')).toBe(false)
|
|
36
|
+
expect(isExplicitStringCall('checked()')).toBe(false)
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
describe('literal-value', () => {
|
|
41
|
+
test('isStringTypeInfo holds only for the string primitive', () => {
|
|
42
|
+
expect(isStringTypeInfo({ kind: 'primitive', raw: 'string', primitive: 'string' })).toBe(true)
|
|
43
|
+
expect(isStringTypeInfo({ kind: 'primitive', raw: 'number', primitive: 'number' })).toBe(false)
|
|
44
|
+
expect(isStringTypeInfo(undefined)).toBe(false)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('isBareStringLiteral accepts a single- or double-quoted literal only', () => {
|
|
48
|
+
expect(isBareStringLiteral("'a'")).toBe(true)
|
|
49
|
+
expect(isBareStringLiteral(' "b" ')).toBe(true)
|
|
50
|
+
expect(isBareStringLiteral('`c`')).toBe(false)
|
|
51
|
+
expect(isBareStringLiteral('0')).toBe(false)
|
|
52
|
+
expect(isBareStringLiteral(undefined)).toBe(false)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('isLiteralIndex holds for a number or string literal index, not a variable or other literal', () => {
|
|
56
|
+
expect(isLiteralIndex(parseExpression('0'))).toBe(true)
|
|
57
|
+
expect(isLiteralIndex(parseExpression("'k'"))).toBe(true)
|
|
58
|
+
expect(isLiteralIndex(parseExpression('size'))).toBe(false)
|
|
59
|
+
expect(isLiteralIndex(parseExpression('true'))).toBe(false)
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
describe('prop-classes', () => {
|
|
64
|
+
const ir = compileToIR(`
|
|
65
|
+
type Props = { active: boolean; label?: string; rows?: number; tone: string; count?: number; items: string[]; flag?: boolean }
|
|
66
|
+
export function Demo({ active, label, rows, tone, count = 0, items, flag }: Props) {
|
|
67
|
+
return <div data-active={active} data-flag={flag}>{label}{rows}{tone}{count}{items.length}</div>
|
|
68
|
+
}
|
|
69
|
+
`)
|
|
70
|
+
|
|
71
|
+
test('collectBooleanTypedProps collects the boolean-typed props', () => {
|
|
72
|
+
expect([...collectBooleanTypedProps(ir)].sort()).toEqual(['active', 'flag'])
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('collectNullableOptionalProps collects no-default props that are optional or non-primitive', () => {
|
|
76
|
+
// `count` has a default; `active` / `tone` are required primitives.
|
|
77
|
+
expect([...collectNullableOptionalProps(ir)].sort()).toEqual(['flag', 'items', 'label', 'rows'])
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
describe('component-tree', () => {
|
|
82
|
+
test('hasClientInteractivity: a signal makes the component interactive, propless static markup does not', () => {
|
|
83
|
+
const reactive = compileToIR(`
|
|
84
|
+
'use client'
|
|
85
|
+
import { createSignal } from '@barefootjs/client'
|
|
86
|
+
export function Counter() {
|
|
87
|
+
const [n, setN] = createSignal(0)
|
|
88
|
+
return <button onClick={() => setN(n() + 1)}>{n()}</button>
|
|
89
|
+
}
|
|
90
|
+
`)
|
|
91
|
+
// A component that reads props still needs init (the analyzer's
|
|
92
|
+
// `needsInit`), so the inert case takes none.
|
|
93
|
+
const inert = compileToIR(`
|
|
94
|
+
export function Label() {
|
|
95
|
+
return <span>static</span>
|
|
96
|
+
}
|
|
97
|
+
`)
|
|
98
|
+
expect(hasClientInteractivity(reactive)).toBe(true)
|
|
99
|
+
expect(hasClientInteractivity(inert)).toBe(false)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
test('collectImportedLoopChildComponentErrors names the adapter and fires only inside a loop', () => {
|
|
103
|
+
const ir = compileToIR(`
|
|
104
|
+
import { Row } from './row'
|
|
105
|
+
export function List({ items }: { items: string[] }) {
|
|
106
|
+
return <ul>{items.map(item => <Row key={item} label={item} />)}<Row label="last" /></ul>
|
|
107
|
+
}
|
|
108
|
+
`, 'list.tsx')
|
|
109
|
+
const errors = collectImportedLoopChildComponentErrors(ir, 'List', 'Twig')
|
|
110
|
+
expect(errors).toHaveLength(1)
|
|
111
|
+
expect(errors[0]!.code).toBe('BF103')
|
|
112
|
+
expect(errors[0]!.message).toContain('The Twig adapter emits a cross-template call')
|
|
113
|
+
expect(errors[0]!.suggestion?.message).toContain('register the resulting Twig template alongside the parent')
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test('collectImportedLoopChildComponentErrors walks conditionals and component children, in render order', () => {
|
|
117
|
+
const ir = compileToIR(`
|
|
118
|
+
import { Row } from './row'
|
|
119
|
+
import { Card } from './card'
|
|
120
|
+
export function List({ items, open }: { items: string[]; open: boolean }) {
|
|
121
|
+
return (
|
|
122
|
+
<div>
|
|
123
|
+
{open ? <ul>{items.map(item => <Card key={item}>{item ? <Row label={item} /> : null}</Card>)}</ul> : null}
|
|
124
|
+
<Card><Row label="outside" /></Card>
|
|
125
|
+
</div>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
`, 'list.tsx')
|
|
129
|
+
const errors = collectImportedLoopChildComponentErrors(ir, 'List', 'Jinja')
|
|
130
|
+
expect(errors.map(e => e.message.match(/<(\w+)>/)?.[1])).toEqual(['Card', 'Row'])
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
test('collectImportedLoopChildComponentErrors ignores a non-relative import', () => {
|
|
134
|
+
const ir = compileToIR(`
|
|
135
|
+
import { Row } from '@acme/ui'
|
|
136
|
+
export function List({ items }: { items: string[] }) {
|
|
137
|
+
return <ul>{items.map(item => <Row key={item} label={item} />)}</ul>
|
|
138
|
+
}
|
|
139
|
+
`, 'list.tsx')
|
|
140
|
+
expect(collectImportedLoopChildComponentErrors(ir, 'List', 'Twig')).toEqual([])
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
describe('isBooleanTypedPropRef', () => {
|
|
145
|
+
const ctx = { propsObjectName: 'props', booleanTypedProps: new Set(['open']), isBound: (n: string) => n === 'row' }
|
|
146
|
+
|
|
147
|
+
test('a bare or props-object read of a boolean prop', () => {
|
|
148
|
+
expect(isBooleanTypedPropRef('open', ctx)).toBe(true)
|
|
149
|
+
expect(isBooleanTypedPropRef(' props.open ', ctx)).toBe(true)
|
|
150
|
+
expect(isBooleanTypedPropRef('label', ctx)).toBe(false)
|
|
151
|
+
expect(isBooleanTypedPropRef('open()', ctx)).toBe(false)
|
|
152
|
+
expect(isBooleanTypedPropRef('open.value', ctx)).toBe(false)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
test('a loop binding that shares the name is the row, not the prop (#2488)', () => {
|
|
156
|
+
expect(isBooleanTypedPropRef('open', { ...ctx, isBound: (n) => n === 'open' })).toBe(false)
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
describe('childTemplateName', () => {
|
|
161
|
+
test('snake_cases the declared name, through an import alias (#2822)', () => {
|
|
162
|
+
expect(childTemplateName('TodoItem', new Map())).toBe('todo_item')
|
|
163
|
+
expect(childTemplateName('Item', new Map([['Item', 'TodoItem']]))).toBe('todo_item')
|
|
164
|
+
expect(childTemplateName('Button', new Map())).toBe('button')
|
|
165
|
+
})
|
|
166
|
+
})
|
|
@@ -103,7 +103,7 @@ describe('static-index event delegation resolves nested .map() params (#3240)',
|
|
|
103
103
|
// static-index event — same shape as before #3240.
|
|
104
104
|
expect(content).not.toContain('__ic1')
|
|
105
105
|
expect(content).not.toContain('__iidx1')
|
|
106
|
-
expect(content).toMatch(/const item = ITEMS\[__idx\]\n\s*if \(item\) \{\n\s*;\(\(\) => setPicked\(item\)\)\(__bfEvt\)\n\s*\}/)
|
|
106
|
+
expect(content).toMatch(/const item = ITEMS\[__idx\]\n\s*if \(item !== undefined\) \{\n\s*;\(\(\) => setPicked\(item\)\)\(__bfEvt\)\n\s*\}/)
|
|
107
107
|
})
|
|
108
108
|
|
|
109
109
|
test('a nested array expression referencing the outer param resolves inside the outer guard', () => {
|