@barefootjs/jsx 0.40.1 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/boolean-result.d.ts +32 -10
- package/dist/adapters/boolean-result.d.ts.map +1 -1
- package/dist/adapters/brace-delimiter-text.d.ts +18 -0
- package/dist/adapters/brace-delimiter-text.d.ts.map +1 -0
- package/dist/adapters/callback-method.d.ts +45 -5
- package/dist/adapters/callback-method.d.ts.map +1 -1
- package/dist/adapters/component-props.d.ts +3 -4
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/computed-const.d.ts +11 -1
- package/dist/adapters/computed-const.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +24 -12
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
- package/dist/adapters/loop-bound-names.d.ts +9 -1
- package/dist/adapters/loop-bound-names.d.ts.map +1 -1
- package/dist/adapters/loop-row-type.d.ts +59 -0
- package/dist/adapters/loop-row-type.d.ts.map +1 -0
- package/dist/adapters/nil-reading.d.ts +63 -0
- package/dist/adapters/nil-reading.d.ts.map +1 -0
- package/dist/adapters/non-primitive-equality.d.ts +33 -0
- package/dist/adapters/non-primitive-equality.d.ts.map +1 -0
- package/dist/adapters/number-value.d.ts +5 -3
- package/dist/adapters/number-value.d.ts.map +1 -1
- package/dist/adapters/operand-typing.d.ts +126 -0
- package/dist/adapters/operand-typing.d.ts.map +1 -0
- package/dist/adapters/parsed-expr-emitter.d.ts +80 -12
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/primitive-plan.d.ts +320 -0
- package/dist/adapters/primitive-plan.d.ts.map +1 -0
- package/dist/adapters/prop-classes.d.ts +5 -0
- package/dist/adapters/prop-classes.d.ts.map +1 -1
- package/dist/analyzer-context.d.ts +4 -0
- package/dist/analyzer-context.d.ts.map +1 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/augment-inherited-props.d.ts +63 -8
- package/dist/augment-inherited-props.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/event-handler-name.d.ts +12 -0
- package/dist/event-handler-name.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +8 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/index.d.ts +20 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4903 -2311
- package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
- package/dist/ir-to-client-js/child-props-object.d.ts +106 -0
- package/dist/ir-to-client-js/child-props-object.d.ts.map +1 -0
- 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.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts +4 -2
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.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 +2 -6
- package/dist/ir-to-client-js/index.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -3
- package/dist/ir-to-client-js/plan/build-declaration-emit.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/build-static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +30 -18
- package/dist/ir-to-client-js/plan/static-array-child-init.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 +3 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts +3 -2
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts +1 -0
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +51 -34
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/prop-rewrite.d.ts +7 -0
- package/dist/prop-rewrite.d.ts.map +1 -1
- package/dist/props-binding.d.ts +58 -13
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/props-object-whole-read.d.ts +15 -0
- package/dist/props-object-whole-read.d.ts.map +1 -0
- package/dist/rich-type-refusal.d.ts.map +1 -1
- package/dist/scope/binding-scope.d.ts +85 -10
- package/dist/scope/binding-scope.d.ts.map +1 -1
- package/dist/scope/lexical-scope-walk.d.ts +3 -2
- package/dist/scope/lexical-scope-walk.d.ts.map +1 -1
- package/dist/scope/root-prop-alias.d.ts +10 -7
- package/dist/scope/root-prop-alias.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +39 -3
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/strip-types.d.ts +13 -0
- package/dist/strip-types.d.ts.map +1 -1
- package/dist/template-position-walk.d.ts +21 -3
- package/dist/template-position-walk.d.ts.map +1 -1
- package/dist/types.d.ts +90 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +9 -9
- package/src/__tests__/binding-scope.test.ts +89 -1
- package/src/__tests__/body-destructure-props-object-alias.test.ts +123 -0
- package/src/__tests__/body-destructured-prop-default-arrow.test.ts +2 -2
- package/src/__tests__/body-destructured-props-live.test.ts +5 -5
- package/src/__tests__/boolean-result.test.ts +22 -5
- package/src/__tests__/brace-delimiter-text.test.ts +26 -0
- package/src/__tests__/callback-method.test.ts +62 -2
- package/src/__tests__/child-components-in-map.test.ts +1 -1
- package/src/__tests__/client-js-generation.test.ts +3 -3
- package/src/__tests__/computed-const.test.ts +103 -0
- package/src/__tests__/destructure-default-reads-earlier-param.test.ts +7 -7
- package/src/__tests__/destructured-props-live.test.ts +1 -1
- package/src/__tests__/emit-to-string-call.test.ts +2 -1
- package/src/__tests__/hydration-payload-analysis.test.ts +166 -0
- package/src/__tests__/issue-2724-prop-alias-loop-not-static.test.ts +7 -7
- package/src/__tests__/issue-2754-rest-spread-needs-slot.test.ts +5 -2
- package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +1 -1
- package/src/__tests__/issue-2835-props-type-member-name-collision.test.ts +4 -4
- package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +1 -1
- package/src/__tests__/issue-3688-props-spread-child-csr.test.ts +2 -1
- package/src/__tests__/issue-3713-props-spread-loop-row.test.ts +65 -0
- package/src/__tests__/issue-3861-object-spread-child.test.ts +102 -0
- package/src/__tests__/lookup-literal-const.test.ts +9 -3
- package/src/__tests__/loop-index-reactivity.test.ts +2 -2
- package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +1 -1
- package/src/__tests__/loop-plan.test.ts +1 -1
- package/src/__tests__/loop-row-const-initializer-shadow.test.ts +146 -0
- package/src/__tests__/loop-row-type.test.ts +64 -0
- package/src/__tests__/lowering-value-position.test.ts +4 -0
- package/src/__tests__/memo-body-expr.test.ts +2 -2
- package/src/__tests__/module-const-destructure-default.test.ts +156 -0
- package/src/__tests__/nested-loop-index-param.test.ts +1 -1
- package/src/__tests__/nested-loop-reactive-attrs.test.ts +2 -2
- package/src/__tests__/nested-row-shadowing.test.ts +2 -2
- package/src/__tests__/nil-reading.test.ts +78 -0
- package/src/__tests__/nullable-signal-attr.test.ts +109 -48
- package/src/__tests__/primitive-plan.test.ts +494 -0
- package/src/__tests__/profile-loop-binding-ids.test.ts +2 -2
- package/src/__tests__/profile-nested-binding-ids.test.ts +2 -2
- package/src/__tests__/prop-default-undefined-only.test.ts +115 -0
- package/src/__tests__/prop-references.test.ts +2 -2
- package/src/__tests__/props-destructuring.test.ts +17 -0
- package/src/__tests__/props-object-whole-read.test.ts +40 -0
- package/src/__tests__/prune-unused-prop-extractions.test.ts +3 -3
- package/src/__tests__/reactive-attrs-in-map.test.ts +1 -1
- package/src/__tests__/reactive-factory-inlining.test.ts +4 -1
- package/src/__tests__/renamed-body-destructure-template.test.ts +7 -7
- package/src/__tests__/rest-binding-gaps.test.ts +192 -0
- package/src/__tests__/rewrite-destructured-props.test.ts +1 -1
- package/src/__tests__/root-prop-alias.test.ts +53 -8
- package/src/__tests__/ssr-defaults.test.ts +113 -25
- package/src/__tests__/static-loop-csr-materialize.test.ts +2 -2
- package/src/__tests__/static-record-literal-array.test.ts +171 -0
- package/src/__tests__/string-concat-identifier.test.ts +40 -1
- package/src/__tests__/written-binding-substitution.test.ts +8 -8
- package/src/adapters/boolean-result.ts +72 -66
- package/src/adapters/brace-delimiter-text.ts +25 -0
- package/src/adapters/callback-method.ts +159 -27
- package/src/adapters/component-props.ts +3 -4
- package/src/adapters/computed-const.ts +238 -4
- package/src/adapters/dsl-template-adapter.ts +62 -26
- package/src/adapters/loop-bound-names.ts +9 -1
- package/src/adapters/loop-plan.ts +1 -1
- package/src/adapters/loop-row-type.ts +149 -0
- package/src/adapters/nil-reading.ts +295 -0
- package/src/adapters/non-primitive-equality.ts +92 -0
- package/src/adapters/number-value.ts +17 -4
- package/src/adapters/operand-typing.ts +522 -0
- package/src/adapters/parsed-expr-emitter.ts +183 -19
- package/src/adapters/primitive-plan.ts +765 -0
- package/src/adapters/prop-classes.ts +16 -3
- package/src/analyzer-context.ts +6 -0
- package/src/analyzer.ts +532 -26
- package/src/augment-inherited-props.ts +108 -10
- package/src/compiler.ts +17 -0
- package/src/event-handler-name.ts +15 -0
- package/src/expression-parser.ts +70 -1
- package/src/index.ts +35 -16
- package/src/ir-to-client-js/build-references.ts +69 -0
- package/src/ir-to-client-js/child-props-object.ts +240 -0
- package/src/ir-to-client-js/collect-elements.ts +31 -63
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +8 -1
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +31 -28
- package/src/ir-to-client-js/control-flow/shared.ts +20 -22
- package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +5 -3
- package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +2 -2
- package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +1 -1
- package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +2 -2
- package/src/ir-to-client-js/control-flow/stringify/loop.ts +1 -1
- package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +3 -3
- package/src/ir-to-client-js/html-template.ts +43 -17
- package/src/ir-to-client-js/imports.ts +2 -2
- package/src/ir-to-client-js/index.ts +53 -11
- package/src/ir-to-client-js/phases/props-extraction.ts +11 -7
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +40 -7
- package/src/ir-to-client-js/plan/build-static-array-child-init.ts +31 -14
- package/src/ir-to-client-js/plan/static-array-child-init.ts +27 -18
- package/src/ir-to-client-js/prop-handling.ts +22 -3
- package/src/ir-to-client-js/prune-unused-prop-extractions.ts +58 -5
- package/src/ir-to-client-js/rewrite-destructured-props.ts +31 -1
- package/src/ir-to-client-js/stringify/static-array-child-init.ts +26 -10
- package/src/jsx-to-ir.ts +459 -37
- package/src/nullable-signal-attr.ts +200 -110
- package/src/prop-rewrite.ts +30 -6
- package/src/props-binding.ts +84 -19
- package/src/props-object-whole-read.ts +87 -0
- package/src/rich-type-refusal.ts +2 -1
- package/src/scope/binding-scope.ts +182 -18
- package/src/scope/lexical-scope-walk.ts +4 -3
- package/src/scope/root-prop-alias.ts +15 -8
- package/src/ssr-defaults.ts +100 -11
- package/src/strip-types.ts +31 -3
- package/src/template-position-walk.ts +57 -28
- package/src/types.ts +87 -0
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts +0 -41
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +0 -1
- package/src/adapters/ambiguous-nil-arithmetic.ts +0 -94
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A body destructure whose initializer is a component-scope `const` alias of
|
|
3
|
+
* the props object (`const p = props; const { x } = p`) is a destructure of
|
|
4
|
+
* the props object: the analyzer expands it into one `props.<key>`
|
|
5
|
+
* `localConstants` entry per name, exactly like `const { x } = props`.
|
|
6
|
+
* Before, only the literal props identifier was recognized and the
|
|
7
|
+
* destructure was dropped with no diagnostic, so every read of `x` was an
|
|
8
|
+
* unbound name (Hono SSR threw `ReferenceError`).
|
|
9
|
+
*
|
|
10
|
+
* Shapes that are not provably the props object stay unrecognized: a `let`
|
|
11
|
+
* alias (a reassignment can repoint it), an alias declared after the
|
|
12
|
+
* destructure, a destructure in a nested block (a block-local binding
|
|
13
|
+
* can shadow the alias there), and any alias when the props parameter
|
|
14
|
+
* itself is reassigned (the alias keeps the object it captured).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { describe, test, expect } from 'bun:test'
|
|
18
|
+
import { analyzeComponent } from '../analyzer'
|
|
19
|
+
|
|
20
|
+
function destructured(body: string) {
|
|
21
|
+
const source = `
|
|
22
|
+
type P = { value: number; label?: string; onPick?: () => void }
|
|
23
|
+
export function C(props: P) {
|
|
24
|
+
${body}
|
|
25
|
+
return <div />
|
|
26
|
+
}
|
|
27
|
+
`
|
|
28
|
+
const ctx = analyzeComponent(source, 'test.tsx')
|
|
29
|
+
return ctx.localConstants
|
|
30
|
+
.filter(c => c.propsDestructure !== undefined)
|
|
31
|
+
.map(c => ({ name: c.name, value: c.value, sourceKey: c.propsDestructure?.sourceKey }))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const EXPANDED = [
|
|
35
|
+
{ name: 'value', value: 'props.value', sourceKey: 'value' },
|
|
36
|
+
{ name: 'label', value: "props.label ?? 'none'", sourceKey: 'label' },
|
|
37
|
+
{ name: 'pick', value: 'props.onPick', sourceKey: 'onPick' },
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
describe('body destructure of a const alias of the props object', () => {
|
|
41
|
+
test('the props object itself (baseline)', () => {
|
|
42
|
+
expect(destructured(`const { value, label = 'none', onPick: pick } = props`)).toEqual(EXPANDED)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('a const alias expands like the props object', () => {
|
|
46
|
+
expect(destructured(`
|
|
47
|
+
const p = props
|
|
48
|
+
const { value, label = 'none', onPick: pick } = p
|
|
49
|
+
`)).toEqual(EXPANDED)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('a chain of const aliases expands like the props object', () => {
|
|
53
|
+
expect(destructured(`
|
|
54
|
+
const p = props
|
|
55
|
+
const q = p
|
|
56
|
+
const { value, label = 'none', onPick: pick } = q
|
|
57
|
+
`)).toEqual(EXPANDED)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('a let alias is not the props object', () => {
|
|
61
|
+
expect(destructured(`
|
|
62
|
+
let p = props
|
|
63
|
+
const { value } = p
|
|
64
|
+
`)).toEqual([])
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('an alias of a let alias is not the props object', () => {
|
|
68
|
+
expect(destructured(`
|
|
69
|
+
let p = props
|
|
70
|
+
const q = p
|
|
71
|
+
const { value } = q
|
|
72
|
+
`)).toEqual([])
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('an alias of another object is not the props object', () => {
|
|
76
|
+
expect(destructured(`
|
|
77
|
+
const other = { value: 1 }
|
|
78
|
+
const { value } = other
|
|
79
|
+
`)).toEqual([])
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('an alias declared after the destructure is not resolved', () => {
|
|
83
|
+
expect(destructured(`
|
|
84
|
+
const { value } = p
|
|
85
|
+
const p = props
|
|
86
|
+
`)).toEqual([])
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
for (const [label, reassign] of [
|
|
90
|
+
['an assignment', `props = { value: 2 }`],
|
|
91
|
+
['a destructuring assignment', `;({ props } = { props: { value: 2 } })`],
|
|
92
|
+
['an assignment inside a handler', `const reset = () => { props = { value: 2 } }`],
|
|
93
|
+
['a for-of loop head inside a handler', `const reset = () => { for (props of [{ value: 2 }]) {} }`],
|
|
94
|
+
['a destructuring for-of loop head', `for ({ props } of [{ props: { value: 2 } }]) {}`],
|
|
95
|
+
['a for-in loop head', `for (props in { a: 1 }) {}`],
|
|
96
|
+
['an update expression', `props++`],
|
|
97
|
+
] as const) {
|
|
98
|
+
test(`an alias is not the props object when the props parameter is reassigned by ${label}`, () => {
|
|
99
|
+
expect(destructured(`
|
|
100
|
+
const p = props
|
|
101
|
+
${reassign}
|
|
102
|
+
const { value } = p
|
|
103
|
+
`)).toEqual([])
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
test('reassigning the props parameter still leaves a direct destructure of it alone', () => {
|
|
108
|
+
expect(destructured(`
|
|
109
|
+
props = { value: 2 }
|
|
110
|
+
const { value } = props
|
|
111
|
+
`)).toEqual([{ name: 'value', value: 'props.value', sourceKey: 'value' }])
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
test('a destructure in a nested block does not resolve the alias', () => {
|
|
115
|
+
expect(destructured(`
|
|
116
|
+
const p = props
|
|
117
|
+
if (p) {
|
|
118
|
+
const p = { value: 2 }
|
|
119
|
+
const { value } = p
|
|
120
|
+
}
|
|
121
|
+
`)).toEqual([])
|
|
122
|
+
})
|
|
123
|
+
})
|
|
@@ -136,7 +136,7 @@ describe('body-destructured prop with an arrow-function default (#2940)', () =>
|
|
|
136
136
|
const js = clientJs!.content
|
|
137
137
|
|
|
138
138
|
expect(parseDiagnosticCount(js)).toBe(0)
|
|
139
|
-
expect(js).toContain("(_p.fmt
|
|
140
|
-
expect(js).not.toContain("(_p.fmt
|
|
139
|
+
expect(js).toContain("(_p.fmt === undefined ? ((v) => 'v' + v) : _p.fmt)(1)")
|
|
140
|
+
expect(js).not.toContain("(_p.fmt === undefined ? (((v) => 'v' + v)) : _p.fmt)(1)")
|
|
141
141
|
})
|
|
142
142
|
})
|
|
@@ -76,7 +76,7 @@ describe('body-destructured props compile to live reads', () => {
|
|
|
76
76
|
|
|
77
77
|
// `items`'s destructure default survives as a live fallback, not a
|
|
78
78
|
// one-time extraction.
|
|
79
|
-
expect(content).toContain('(_p.items
|
|
79
|
+
expect(content).toContain('(_p.items === undefined ? [] : _p.items).length')
|
|
80
80
|
})
|
|
81
81
|
|
|
82
82
|
test('the CSR template lambda also reads a defaulted body alias live, matching the parameter form (#2934)', () => {
|
|
@@ -104,8 +104,8 @@ describe('body-destructured props compile to live reads', () => {
|
|
|
104
104
|
`
|
|
105
105
|
const { content } = compileClientJs(source, 'Child.tsx')
|
|
106
106
|
expect(content).not.toMatch(/const label = /)
|
|
107
|
-
expect(content).toContain("escapeAttr((_p.label
|
|
108
|
-
expect(content).toContain("escapeTextOrMarkup((_p.label
|
|
107
|
+
expect(content).toContain("escapeAttr((_p.label === undefined ? 'none' : _p.label))")
|
|
108
|
+
expect(content).toContain("escapeTextOrMarkup((_p.label === undefined ? 'none' : _p.label))")
|
|
109
109
|
// Never the bare, default-dropping form.
|
|
110
110
|
expect(content).not.toMatch(/\(_p\.label\) != null/)
|
|
111
111
|
})
|
|
@@ -124,8 +124,8 @@ describe('body-destructured props compile to live reads', () => {
|
|
|
124
124
|
`
|
|
125
125
|
const { content } = compileClientJs(source, 'Child.tsx')
|
|
126
126
|
expect(content).not.toMatch(/const text = /)
|
|
127
|
-
expect(content).toContain("escapeAttr((_p.label
|
|
128
|
-
expect(content).toContain("escapeTextOrMarkup((_p.label
|
|
127
|
+
expect(content).toContain("escapeAttr((_p.label === undefined ? 'none' : _p.label))")
|
|
128
|
+
expect(content).toContain("escapeTextOrMarkup((_p.label === undefined ? 'none' : _p.label))")
|
|
129
129
|
})
|
|
130
130
|
|
|
131
131
|
test('a renamed body-destructured prop (`onPick: pick`) reads the caller-facing key live everywhere', () => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { describe, test, expect } from 'bun:test'
|
|
2
|
-
import { collectBooleanValueNames, isBooleanResultParsed,
|
|
2
|
+
import { collectBooleanValueNames, isBooleanResultParsed, stringifyBooleanBranches } from '../adapters/boolean-result'
|
|
3
3
|
import { exprToString, parseExpression } from '../expression-parser'
|
|
4
4
|
|
|
5
|
-
const rewrite = (src: string) => exprToString(
|
|
5
|
+
const rewrite = (src: string) => exprToString(stringifyBooleanBranches(parseExpression(src)!))
|
|
6
6
|
|
|
7
|
-
describe('
|
|
7
|
+
describe('stringifyBooleanBranches (#3349, #3789)', () => {
|
|
8
8
|
test('a literal boolean branch next to a non-boolean branch becomes a string literal', () => {
|
|
9
9
|
expect(rewrite("yes() ? false : s()")).toBe(exprToString(parseExpression("yes() ? 'false' : s()")!))
|
|
10
10
|
})
|
|
@@ -17,12 +17,29 @@ describe('stringifyBooleanTernaryBranches (#3349)', () => {
|
|
|
17
17
|
expect(rewrite("a() ? (b() ? 'x' : false) : 'y'")).toBe(exprToString(parseExpression("a() ? (b() ? 'x' : 'false') : 'y'")!))
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
+
test('a comparison an && / || / ?? operand returns is stringified where it decides the result', () => {
|
|
21
|
+
expect(rewrite("n() > 0 && 'y'")).toBe(exprToString(parseExpression("n() > 0 ? 'y' : 'false'")!))
|
|
22
|
+
expect(rewrite("n() > 0 || 'y'")).toBe(exprToString(parseExpression("n() > 0 ? 'true' : 'y'")!))
|
|
23
|
+
expect(rewrite("!n() ?? 'y'")).toBe(exprToString(parseExpression("!n() ? 'true' : 'false'")!))
|
|
24
|
+
expect(rewrite("s() || n() > 0")).toBe(exprToString(parseExpression("s() || (n() > 0 ? 'true' : 'false')")!))
|
|
25
|
+
expect(rewrite("n() > 0 && (m() < 0 || 'y')")).toBe(exprToString(parseExpression("n() > 0 ? (m() < 0 ? 'true' : 'y') : 'false'")!))
|
|
26
|
+
const plain = parseExpression("s() && 'y'")!
|
|
27
|
+
expect(stringifyBooleanBranches(plain)).toBe(plain)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('a mixed left operand that can yield a boolean keeps its truthiness test and yields the rewritten form', () => {
|
|
31
|
+
expect(rewrite("(n() > 0 && 'y') && 'z'")).toBe(exprToString(parseExpression("(n() > 0 && 'y') ? 'z' : (n() > 0 ? 'y' : 'false')")!))
|
|
32
|
+
expect(rewrite("(n() ? 'y' : false) && 'z'")).toBe(exprToString(parseExpression("(n() ? 'y' : false) ? 'z' : (n() ? 'y' : 'false')")!))
|
|
33
|
+
expect(rewrite("(n() ? 'y' : false) || 'z'")).toBe(exprToString(parseExpression("(n() ? 'y' : false) ? (n() ? 'y' : 'false') : 'z'")!))
|
|
34
|
+
expect(rewrite("((n() > 0) && 'y') ?? 'z'")).toBe(exprToString(parseExpression("(n() > 0 ? 'y' : 'false') ?? 'z'")!))
|
|
35
|
+
})
|
|
36
|
+
|
|
20
37
|
test('a wholly boolean ternary and a non-ternary are left unchanged', () => {
|
|
21
38
|
const whole = parseExpression('c() ? true : false')!
|
|
22
39
|
expect(isBooleanResultParsed(whole)).toBe(true)
|
|
23
|
-
expect(
|
|
40
|
+
expect(stringifyBooleanBranches(whole)).toBe(whole)
|
|
24
41
|
const plain = parseExpression('s()')!
|
|
25
|
-
expect(
|
|
42
|
+
expect(stringifyBooleanBranches(plain)).toBe(plain)
|
|
26
43
|
})
|
|
27
44
|
})
|
|
28
45
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, test, expect } from 'bun:test'
|
|
2
|
+
import { escapeBraceDelimiters } from '../adapters/brace-delimiter-text'
|
|
3
|
+
|
|
4
|
+
describe('escapeBraceDelimiters (#3767)', () => {
|
|
5
|
+
const B = "{{ '{' }}"
|
|
6
|
+
const esc = (t: string) => escapeBraceDelimiters(t, '{%#', B)
|
|
7
|
+
|
|
8
|
+
test('rewrites a brace that opens a tag', () => {
|
|
9
|
+
expect(esc('{{ 1 }}')).toBe(`${B}{ 1 }}`)
|
|
10
|
+
expect(esc('{% if x %}')).toBe(`${B}% if x %}`)
|
|
11
|
+
expect(esc('{# c #}')).toBe(`${B}# c #}`)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('rewrites every brace of a run, so none is left before another', () => {
|
|
15
|
+
expect(esc('{{{')).toBe(B + B + B)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('rewrites a brace that ends the text', () => {
|
|
19
|
+
expect(esc('a{')).toBe(`a${B}`)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('leaves a brace that cannot open a tag, and closing braces', () => {
|
|
23
|
+
expect(esc('{a} }} %} #}')).toBe('{a} }} %} #}')
|
|
24
|
+
expect(escapeBraceDelimiters('{%', '{', '{{"{"}}')).toBe('{%')
|
|
25
|
+
})
|
|
26
|
+
})
|
|
@@ -30,9 +30,9 @@ function callOf(source: string) {
|
|
|
30
30
|
return call
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
const lower = (source: string, options = jinja) => {
|
|
33
|
+
const lower = (source: string, options = jinja, propsObject = 'props') => {
|
|
34
34
|
const call = callOf(source)
|
|
35
|
-
return lowerCallbackMethod(call.method, call.arrow, call.args, options)
|
|
35
|
+
return lowerCallbackMethod(call.method, call.arrow, call.args, options, propsObject)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
const spelling: CallbackEvalSpelling = {
|
|
@@ -262,3 +262,63 @@ describe('unloweredCallRefusal (#3493)', () => {
|
|
|
262
262
|
expect(refusal.suggestion).toContain('pass it as a prop')
|
|
263
263
|
})
|
|
264
264
|
})
|
|
265
|
+
|
|
266
|
+
describe('lowerCallbackMethod: props.X reads in an evaluator body', () => {
|
|
267
|
+
// A template has no `props` object, so the env binds each `props.X` read
|
|
268
|
+
// under a fresh name, spelled as the adapter spells `props.X` elsewhere.
|
|
269
|
+
const emitPropsRead = (e: ParsedExpr) =>
|
|
270
|
+
e.kind === 'member' && e.object.kind === 'identifier' && (e.object.name === 'props' || e.object.name === 'p')
|
|
271
|
+
? `$${e.property}`
|
|
272
|
+
: emitIdentifier(e)
|
|
273
|
+
const renderProps = (source: string, propsObject = 'props') => {
|
|
274
|
+
const plan = lower(source, jinja, propsObject)
|
|
275
|
+
if (plan.kind !== 'eval') throw new Error(`expected an eval plan, got ${plan.kind}`)
|
|
276
|
+
return emitCallbackEval(plan, 'RECV', emitPropsRead, spelling)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
test('a predicate reading props.n binds the read, not props', () => {
|
|
280
|
+
expect(renderProps('props.items.filter(i => i > props.n)')).toBe(
|
|
281
|
+
`bf.filter_eval(RECV, '{"kind":"binary","op":">","left":{"kind":"identifier","name":"i"},"right":{"kind":"identifier","name":"__bf_props_n"}}', 'i', {__bf_props_n=$n})`,
|
|
282
|
+
)
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
test('a param named like the prop keeps its own value', () => {
|
|
286
|
+
expect(renderProps('props.items.filter(n => n > props.n)')).toEndWith(`'n', {__bf_props_n=$n})`)
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
test('two reads of one prop share a name; other free names stay as they are', () => {
|
|
290
|
+
expect(renderProps('props.items.filter(i => i > props.n && i < props.n + limit)')).toEndWith(
|
|
291
|
+
`'i', {__bf_props_n=$n, limit=$limit})`,
|
|
292
|
+
)
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
test('the fresh name avoids every name the body uses', () => {
|
|
296
|
+
expect(renderProps('props.items.filter(__bf_props_n => __bf_props_n > props.n)')).toEndWith(
|
|
297
|
+
`'__bf_props_n', {__bf_props_n_=$n})`,
|
|
298
|
+
)
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
test('a param named props is not the props object', () => {
|
|
302
|
+
expect(renderProps('items.filter(props => props.n > 1)')).toEndWith(`'props', {})`)
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
test('a nested arrow that binds props shadows it in its body only', () => {
|
|
306
|
+
const out = renderProps('items.filter(i => i.tags.filter(props => props.on).length > props.n)')
|
|
307
|
+
expect(out).toContain('"object":{"kind":"identifier","name":"props"},"property":"on"')
|
|
308
|
+
expect(out).toEndWith(`'i', {__bf_props_n=$n})`)
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
test('sort, reduce and map bodies lift props.X reads too', () => {
|
|
312
|
+
expect(renderProps('props.items.toSorted((a, b) => props.desc ? b - a : a - b)')).toEndWith(
|
|
313
|
+
`{__bf_props_desc=$desc})`,
|
|
314
|
+
)
|
|
315
|
+
expect(renderProps('props.items.reduce((acc, i) => acc + i * props.k, 0)')).toEndWith(`{__bf_props_k=$k})`)
|
|
316
|
+
expect(renderProps('props.items.map(i => i * props.k)')).toEndWith(`{__bf_props_k=$k})`)
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
test('a props object named p lifts p.X reads, and props is then an ordinary name', () => {
|
|
320
|
+
expect(renderProps('p.items.filter(i => i > p.n)', 'p')).toEndWith(`'i', {__bf_props_n=$n})`)
|
|
321
|
+
expect(renderProps('p.items.some(p => p.on)', 'p')).toEndWith(`'p', {})`)
|
|
322
|
+
expect(renderProps('p.items.filter(i => i > props.n)', 'p')).toEndWith(`'i', {props=$props})`)
|
|
323
|
+
})
|
|
324
|
+
})
|
|
@@ -1230,7 +1230,7 @@ describe('child components inside .map() (#344)', () => {
|
|
|
1230
1230
|
// Document-order zip shape — a flat cursor over the queried scopes
|
|
1231
1231
|
// pairs each with its data item across the nested forEach. This shape
|
|
1232
1232
|
// is fragment-root safe (no per-group wrapper element to index).
|
|
1233
|
-
expect(content).toContain('
|
|
1233
|
+
expect(content).toContain('childScopesBySlot')
|
|
1234
1234
|
expect(content).toMatch(/__compScopes\[__ci\+\+\]/)
|
|
1235
1235
|
// No element-offset addressing (`__outerEl = ...children[...]`) — that
|
|
1236
1236
|
// would break for a fragment-rooted passthrough.
|
|
@@ -2541,7 +2541,7 @@ describe('Client JS generation', () => {
|
|
|
2541
2541
|
expect(content).toContain('sizeMap')
|
|
2542
2542
|
expect(content).not.toContain('sizeMap'.replace('size', 'props.size'))
|
|
2543
2543
|
// The standalone size reference should be rewritten
|
|
2544
|
-
expect(content).toContain("_p.size
|
|
2544
|
+
expect(content).toContain("_p.size === undefined ? 'sm' : _p.size")
|
|
2545
2545
|
})
|
|
2546
2546
|
|
|
2547
2547
|
test('default values from destructuring are included in rewrite', () => {
|
|
@@ -2566,7 +2566,7 @@ describe('Client JS generation', () => {
|
|
|
2566
2566
|
|
|
2567
2567
|
expect(content).toContain('createEffect')
|
|
2568
2568
|
// Should include the default value in the rewrite
|
|
2569
|
-
expect(content).toContain("_p.label
|
|
2569
|
+
expect(content).toContain("_p.label === undefined ? 'tag' : _p.label")
|
|
2570
2570
|
})
|
|
2571
2571
|
|
|
2572
2572
|
test('text node renders empty string for nullish reactive values', () => {
|
|
@@ -3077,7 +3077,7 @@ describe('Client JS generation', () => {
|
|
|
3077
3077
|
// The destructure default rides the signal seed (and its controlled
|
|
3078
3078
|
// effect) — the standalone `const size = …` extraction is pruned when
|
|
3079
3079
|
// nothing else in the init reads it.
|
|
3080
|
-
expect(js).toContain('_p.size
|
|
3080
|
+
expect(js).toContain('_p.size === undefined ? 5 : _p.size')
|
|
3081
3081
|
expect(js).not.toContain('_p.size ?? 0')
|
|
3082
3082
|
})
|
|
3083
3083
|
})
|
|
@@ -184,3 +184,106 @@ describe('only names the component scope binds shadow a module const (#3696)', (
|
|
|
184
184
|
expect(inliner(source)('m')).toBe('props.n * 2')
|
|
185
185
|
})
|
|
186
186
|
})
|
|
187
|
+
|
|
188
|
+
describe('a read of an object const reads what the object holds (#3844)', () => {
|
|
189
|
+
const source = `
|
|
190
|
+
'use client'
|
|
191
|
+
import { createSignal } from '@barefootjs/client'
|
|
192
|
+
const MODULE = { label: 'mod', inner: { mode: 'dark' } }
|
|
193
|
+
export function C(props: { n: number; kind: 'ok' | 'err'; other?: 'ok' | 'nope'; free: string; proto: 'ok' | 'toString' }) {
|
|
194
|
+
const [sel] = createSignal('ok')
|
|
195
|
+
const flags = { big: props.n > 1, label: 'L' + props.n }
|
|
196
|
+
const labels = { ok: 'Fine', err: 'Broken' }
|
|
197
|
+
const numbered = { 1: 'one', two: 'two' }
|
|
198
|
+
const mutated = { a: 1 }
|
|
199
|
+
mutated.a = 2
|
|
200
|
+
return <p>{flags.label}</p>
|
|
201
|
+
}
|
|
202
|
+
`
|
|
203
|
+
|
|
204
|
+
test('a member read is the value the literal gives the key, a missing key undefined', () => {
|
|
205
|
+
const inline = inliner(source)
|
|
206
|
+
expect(inline('flags.big ? "big" : "small"')).toBe('props.n > 1 ? "big" : "small"')
|
|
207
|
+
expect(inline("flags['label']")).toBe('"L" + props.n')
|
|
208
|
+
expect(inline('flags.missing')).toBe('undefined')
|
|
209
|
+
expect(inline('MODULE.inner.mode')).toBe('"dark"')
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
test('a read off a projected value keeps it as its object', () => {
|
|
213
|
+
const metadata = buildMetadata(analyzeComponent(source, 'test.tsx'))
|
|
214
|
+
const inlined = inlineComputedConsts(parseExpression('flags.label.length'), computedConstContext(metadata, () => false))
|
|
215
|
+
expect(inlined.kind === 'member' && inlined.property === 'length' && inlined.object.kind).toBe('binary')
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
test('an index typed as a union of string literals is the conditional over the keys it can hold', () => {
|
|
219
|
+
const inline = inliner(source)
|
|
220
|
+
expect(inline('labels[props.kind]')).toBe('props.kind === "ok" ? "Fine" : props.kind === "err" ? "Broken" : undefined')
|
|
221
|
+
expect(inline('labels[props.other]')).toBe('props.other === "ok" ? "Fine" : undefined')
|
|
222
|
+
expect(inline('numbered[props.kind]')).toBe('undefined')
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
test('an index whose keys are not all known reads the literal, for the adapter to refuse', () => {
|
|
226
|
+
const inline = inliner(source)
|
|
227
|
+
const literal = "({ ok: 'Fine', err: 'Broken' })"
|
|
228
|
+
expect(inline('labels[props.free]')).toBe(`${literal}[props.free]`)
|
|
229
|
+
expect(inline('labels[props.proto]')).toBe(`${literal}[props.proto]`)
|
|
230
|
+
expect(inline('labels[sel()]')).toBe(`${literal}[sel()]`)
|
|
231
|
+
expect(inline('labels[pick(props.kind)]')).toBe(`${literal}[pick(props.kind)]`)
|
|
232
|
+
expect(inline('rows.map(kind => labels[kind])')).toBe(`rows.map(kind => ${literal}[kind])`)
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
test('a whole read or an inherited key leaves the expression as written', () => {
|
|
236
|
+
const inline = inliner(source)
|
|
237
|
+
expect(inline('f(flags)')).toBe('f(flags)')
|
|
238
|
+
expect(inline('flags.label + flags.toString')).toBe('flags.label + flags.toString')
|
|
239
|
+
expect(inline('MODULE.inner')).toBe('MODULE.inner')
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
test('a mutated object, a shadowed name and a capturing callback param are left alone', () => {
|
|
243
|
+
expect(inliner(source)('mutated.a')).toBe('mutated.a')
|
|
244
|
+
expect(inliner(source, ['flags'])('flags.label')).toBe('flags.label')
|
|
245
|
+
expect(inliner(source)('rows.map(props => flags.label)')).toBe('rows.map(props => flags.label)')
|
|
246
|
+
expect(inliner(source)('rows.map(flags => flags.label)')).toBe('rows.map(flags => flags.label)')
|
|
247
|
+
})
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
describe('a body destructure of a const object is one const per binding (#3844)', () => {
|
|
251
|
+
const consts = (source: string) =>
|
|
252
|
+
Object.fromEntries(buildMetadata(analyzeComponent(source, 'test.tsx')).localConstants.filter(c => !c.isModule).map(c => [c.name, c.value]))
|
|
253
|
+
|
|
254
|
+
test('a local, a module and a rest source; renamed, nested and defaulted bindings', () => {
|
|
255
|
+
expect(consts(`
|
|
256
|
+
const MOD = { a: { b: 1 } }
|
|
257
|
+
export function C({ t, ...rest }: { t: string; tone: string }) {
|
|
258
|
+
const conf = { tone: 'info' }
|
|
259
|
+
const { tone: tn, missing = 'x' } = conf
|
|
260
|
+
const { a: { b } } = MOD
|
|
261
|
+
const { tone } = rest
|
|
262
|
+
return <p>{tn}{missing}{b}{tone}</p>
|
|
263
|
+
}
|
|
264
|
+
`)).toMatchObject({ tn: 'conf.tone', missing: 'conf.missing === undefined ? "x" : conf.missing', b: 'MOD.a.b', tone: 'rest.tone' })
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
test('a rest of a props-object body destructure reads the props object, a taken key its default', () => {
|
|
268
|
+
const metadata = buildMetadata(analyzeComponent(`
|
|
269
|
+
export function C(props: { label: string; id?: string }) {
|
|
270
|
+
const { label, ...rest } = props
|
|
271
|
+
const { id, label: gone = 'g' } = rest
|
|
272
|
+
return <p {...rest}>{label}{id}{gone}</p>
|
|
273
|
+
}
|
|
274
|
+
`, 'test.tsx'))
|
|
275
|
+
expect(metadata.restPropsName).toBe('rest')
|
|
276
|
+
expect(metadata.restPropsOmittedKeys).toEqual(['label'])
|
|
277
|
+
expect(metadata.restPropsExpandedKeys).toEqual(['id'])
|
|
278
|
+
const values = Object.fromEntries(metadata.localConstants.map(c => [c.name, c.value]))
|
|
279
|
+
expect(values).toMatchObject({ id: 'props.id', gone: '"g"' })
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
test('a source declared later, a let source, a rest element or a computed default is not collected', () => {
|
|
283
|
+
const names = (source: string) => buildMetadata(analyzeComponent(source, 'test.tsx')).localConstants.map(c => c.name)
|
|
284
|
+
expect(names(`export function C() { const { a } = later; const later = { a: 1 }; return <p>{a}</p> }`)).not.toContain('a')
|
|
285
|
+
expect(names(`export function C() { let conf = { a: 1 }; const { a } = conf; return <p>{a}</p> }`)).not.toContain('a')
|
|
286
|
+
expect(names(`export function C() { const conf = { a: 1, b: 2 }; const { a, ...more } = conf; return <p>{a}</p> }`)).not.toContain('a')
|
|
287
|
+
expect(names(`export function C({ d }: { d: number }) { const conf = { a: 1 }; const { a = d } = conf; return <p>{a}</p> }`)).not.toContain('a')
|
|
288
|
+
})
|
|
289
|
+
})
|
|
@@ -72,7 +72,7 @@ describe('client JS reads the earlier prop live', () => {
|
|
|
72
72
|
return <p>{String(on && true)}</p>
|
|
73
73
|
}
|
|
74
74
|
`)
|
|
75
|
-
expect(js).toContain('(_p.on
|
|
75
|
+
expect(js).toContain('(_p.on === undefined ? (_p.off === undefined ? false : _p.off) : _p.on)')
|
|
76
76
|
expect(js).not.toContain('_p.on ?? off)')
|
|
77
77
|
})
|
|
78
78
|
|
|
@@ -83,8 +83,8 @@ describe('client JS reads the earlier prop live', () => {
|
|
|
83
83
|
return <p>{c}{String(on)}</p>
|
|
84
84
|
}
|
|
85
85
|
`)
|
|
86
|
-
expect(js).toContain(`(_p.c
|
|
87
|
-
expect(js).toContain('(_p.on
|
|
86
|
+
expect(js).toContain(`(_p.c === undefined ? (_p.b === undefined ? (_p.a === undefined ? 'x' : _p.a) : _p.b) : _p.c)`)
|
|
87
|
+
expect(js).toContain('(_p.on === undefined ? !(_p.off === undefined ? false : _p.off) : _p.on)')
|
|
88
88
|
})
|
|
89
89
|
|
|
90
90
|
test('a renamed earlier binding reads its caller-facing key', () => {
|
|
@@ -94,7 +94,7 @@ describe('client JS reads the earlier prop live', () => {
|
|
|
94
94
|
return <p>{String(on)}</p>
|
|
95
95
|
}
|
|
96
96
|
`)
|
|
97
|
-
expect(js).toContain('(_p.on
|
|
97
|
+
expect(js).toContain('(_p.on === undefined ? (_p.off === undefined ? false : _p.off) : _p.on)')
|
|
98
98
|
})
|
|
99
99
|
|
|
100
100
|
test('body form: the init body reads the earlier prop live too', () => {
|
|
@@ -106,7 +106,7 @@ describe('client JS reads the earlier prop live', () => {
|
|
|
106
106
|
}
|
|
107
107
|
`)
|
|
108
108
|
expect(js).not.toMatch(/_p\.on \?\? off\b/)
|
|
109
|
-
expect(js).toContain('(_p.on
|
|
109
|
+
expect(js).toContain('(_p.on === undefined ? (_p.off === undefined ? false : _p.off) : _p.on)')
|
|
110
110
|
})
|
|
111
111
|
|
|
112
112
|
test('the CSR template reads a signal seed and a memo over the prop with its default', () => {
|
|
@@ -120,8 +120,8 @@ describe('client JS reads the earlier prop live', () => {
|
|
|
120
120
|
}
|
|
121
121
|
`)
|
|
122
122
|
const template = js.slice(js.indexOf('template: (_p) =>'))
|
|
123
|
-
expect(template).toContain('String(((_p.on
|
|
124
|
-
expect(template).toContain('String((!(_p.on
|
|
123
|
+
expect(template).toContain('String(((_p.on === undefined ? (_p.off === undefined ? false : _p.off) : _p.on)))')
|
|
124
|
+
expect(template).toContain('String((!(_p.on === undefined ? (_p.off === undefined ? false : _p.off) : _p.on)))')
|
|
125
125
|
})
|
|
126
126
|
|
|
127
127
|
test('a controlled signal seeded by the prop reads the earlier prop live', () => {
|
|
@@ -79,7 +79,7 @@ describe('destructured props compile to live reads', () => {
|
|
|
79
79
|
|
|
80
80
|
// `items`'s destructure default survives as a live fallback, not a
|
|
81
81
|
// one-time extraction.
|
|
82
|
-
expect(content).toContain('(_p.items
|
|
82
|
+
expect(content).toContain('(_p.items === undefined ? [] : _p.items).length')
|
|
83
83
|
|
|
84
84
|
// No BF043 diagnostic (retired) anywhere in errors/warnings.
|
|
85
85
|
expect(result.errors.some((e) => e.code === 'BF043')).toBe(false)
|
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { describe, test, expect } from 'bun:test'
|
|
9
|
-
import { emitParsedExpr, parseExpression, type ParsedExpr, type ParsedExprEmitter } from '../index'
|
|
9
|
+
import { BindingScope, EMPTY_OPERAND_TYPING, emitParsedExpr, parseExpression, primitivesAt, type ParsedExpr, type ParsedExprEmitter } from '../index'
|
|
10
10
|
|
|
11
11
|
// Spells every node as a JS-like string so the dispatched shape is visible.
|
|
12
12
|
function makeEmitter(): ParsedExprEmitter {
|
|
13
13
|
const callName = (callee: ParsedExpr, emit: (e: ParsedExpr) => string) =>
|
|
14
14
|
callee.kind === 'identifier' ? callee.name : emit(callee)
|
|
15
15
|
return {
|
|
16
|
+
primitives: primitivesAt(EMPTY_OPERAND_TYPING, BindingScope.EMPTY, {}),
|
|
16
17
|
identifier: name => name,
|
|
17
18
|
literal: value => JSON.stringify(value),
|
|
18
19
|
call: (callee, args, emit) => `${callName(callee, emit)}(${args.map(emit).join(', ')})`,
|