@barefootjs/jsx 0.40.1 → 0.40.2
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/ambiguous-nil-arithmetic.d.ts +4 -3
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +1 -1
- 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 +38 -5
- package/dist/adapters/callback-method.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 +21 -0
- 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 +52 -0
- package/dist/adapters/loop-row-type.d.ts.map +1 -0
- package/dist/adapters/nil-reading.d.ts +68 -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 +70 -12
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/primitive-plan.d.ts +291 -0
- package/dist/adapters/primitive-plan.d.ts.map +1 -0
- 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 +19 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4628 -2198
- package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
- package/dist/ir-to-client-js/child-props-object.d.ts +64 -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/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/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 +68 -9
- 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-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/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 +3 -3
- package/src/__tests__/binding-scope.test.ts +89 -1
- package/src/__tests__/body-destructure-props-object-alias.test.ts +123 -0
- 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__/computed-const.test.ts +103 -0
- 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__/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__/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 +77 -0
- package/src/__tests__/nullable-signal-attr.test.ts +134 -0
- package/src/__tests__/primitive-plan.test.ts +416 -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__/props-object-whole-read.test.ts +40 -0
- package/src/__tests__/reactive-attrs-in-map.test.ts +1 -1
- package/src/__tests__/reactive-factory-inlining.test.ts +4 -1
- package/src/__tests__/rest-binding-gaps.test.ts +192 -0
- package/src/__tests__/root-prop-alias.test.ts +53 -8
- 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/adapters/ambiguous-nil-arithmetic.ts +22 -13
- package/src/adapters/boolean-result.ts +72 -66
- package/src/adapters/brace-delimiter-text.ts +25 -0
- package/src/adapters/callback-method.ts +151 -27
- package/src/adapters/computed-const.ts +238 -4
- package/src/adapters/dsl-template-adapter.ts +40 -2
- package/src/adapters/loop-bound-names.ts +9 -1
- package/src/adapters/loop-plan.ts +1 -1
- package/src/adapters/loop-row-type.ts +139 -0
- package/src/adapters/nil-reading.ts +297 -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 +154 -19
- package/src/adapters/primitive-plan.ts +696 -0
- package/src/analyzer-context.ts +6 -0
- package/src/analyzer.ts +505 -19
- 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 +33 -7
- package/src/ir-to-client-js/build-references.ts +69 -0
- package/src/ir-to-client-js/child-props-object.ts +106 -0
- package/src/ir-to-client-js/collect-elements.ts +30 -55
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +6 -1
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +29 -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 +25 -8
- package/src/ir-to-client-js/imports.ts +1 -1
- package/src/ir-to-client-js/index.ts +53 -11
- 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/stringify/static-array-child-init.ts +26 -10
- package/src/jsx-to-ir.ts +446 -37
- package/src/nullable-signal-attr.ts +246 -29
- package/src/prop-rewrite.ts +30 -6
- 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/strip-types.ts +31 -3
- package/src/template-position-walk.ts +57 -28
- package/src/types.ts +87 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JS primitive plan's classifier and decision (#3824,
|
|
3
|
+
* `spec/js-primitive-semantics.md` "Decision point"): `collectOperandTyping`
|
|
4
|
+
* and its scoped view, `operandFacts`, and `planPrimitive` over a
|
|
5
|
+
* `NativeSafeTable`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, test, expect } from 'bun:test'
|
|
9
|
+
import {
|
|
10
|
+
analyzeComponent,
|
|
11
|
+
BindingScope,
|
|
12
|
+
buildMetadata,
|
|
13
|
+
collectOperandTyping,
|
|
14
|
+
EMPTY_OPERAND_TYPING,
|
|
15
|
+
operandFacts,
|
|
16
|
+
parseExpression,
|
|
17
|
+
planPrimitive,
|
|
18
|
+
foldNegatedNumberLiteral,
|
|
19
|
+
mayHoldObject,
|
|
20
|
+
numberLiteralSpelling,
|
|
21
|
+
type IRMetadata,
|
|
22
|
+
type NativeSafeTable,
|
|
23
|
+
type OperandFacts,
|
|
24
|
+
type ScopedOperandTyping,
|
|
25
|
+
type TypeInfo,
|
|
26
|
+
} from '../index'
|
|
27
|
+
|
|
28
|
+
const prim = (primitive: 'string' | 'number' | 'boolean' | 'null' | 'undefined'): TypeInfo => ({ kind: 'primitive', raw: primitive, primitive })
|
|
29
|
+
const union = (...unionTypes: TypeInfo[]): TypeInfo => ({ kind: 'union', raw: unionTypes.map(t => t.raw).join(' | '), unionTypes })
|
|
30
|
+
const array = (elementType: TypeInfo): TypeInfo => ({ kind: 'array', raw: `${elementType.raw}[]`, elementType })
|
|
31
|
+
|
|
32
|
+
type Meta = Pick<IRMetadata, 'signals' | 'memos' | 'propsParams' | 'localConstants' | 'propsObjectName' | 'typeDefinitions'>
|
|
33
|
+
|
|
34
|
+
function meta(partial: Partial<Meta>): Meta {
|
|
35
|
+
return { signals: [], memos: [], propsParams: [], localConstants: [], propsObjectName: null, typeDefinitions: [], ...partial }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function param(name: string, type: TypeInfo, optional = false, defaultValue?: string): Meta['propsParams'][number] {
|
|
39
|
+
return { name, type, optional, ...(defaultValue !== undefined ? { defaultValue } : {}) } as Meta['propsParams'][number]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function signal(getter: string, type: TypeInfo, initialValue: string): Meta['signals'][number] {
|
|
43
|
+
return { getter, setter: null, type, initialValue, parsed: parseExpression(initialValue) } as unknown as Meta['signals'][number]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const COMPONENT = meta({
|
|
47
|
+
propsObjectName: 'props',
|
|
48
|
+
propsParams: [
|
|
49
|
+
param('n', prim('number')),
|
|
50
|
+
param('s', prim('string')),
|
|
51
|
+
param('on', prim('boolean')),
|
|
52
|
+
param('maybe', prim('number'), true),
|
|
53
|
+
param('nothing', union(prim('number'), prim('null'))),
|
|
54
|
+
param('either', union(prim('number'), prim('null')), true),
|
|
55
|
+
param('size', prim('string'), true, "'md'"),
|
|
56
|
+
param('rows', array(prim('number'))),
|
|
57
|
+
],
|
|
58
|
+
signals: [signal('count', prim('number'), '0'), signal('und', prim('number'), ''), signal('label', { kind: 'unknown', raw: 'unknown' }, "'x'")],
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
const typing = collectOperandTyping(COMPONENT).at(BindingScope.forComponent('props'))
|
|
62
|
+
|
|
63
|
+
/** `facts.types` as a sorted list, with the nil reading when there is one. */
|
|
64
|
+
function show(facts: OperandFacts): string {
|
|
65
|
+
const types = [...facts.types].sort().join('|')
|
|
66
|
+
return facts.nil ? `${types} (${facts.nil})` : types
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const factsOf = (src: string, at: ScopedOperandTyping = typing) => show(operandFacts(parseExpression(src), at))
|
|
70
|
+
|
|
71
|
+
describe('collectOperandTyping', () => {
|
|
72
|
+
test('a required prop is its declared type; an optional one without a default may be undefined', () => {
|
|
73
|
+
expect(factsOf('props.n')).toBe('number')
|
|
74
|
+
expect(factsOf('props.s')).toBe('string')
|
|
75
|
+
expect(factsOf('props.on')).toBe('boolean')
|
|
76
|
+
expect(factsOf('props.maybe')).toBe('nil|number (undefined)')
|
|
77
|
+
expect(factsOf('props.nothing')).toBe('nil|number (null)')
|
|
78
|
+
expect(factsOf('props.either')).toBe('nil|number (either)')
|
|
79
|
+
// With a props object, a default comes from a body destructure and
|
|
80
|
+
// types that local binding, not `props.size`.
|
|
81
|
+
expect(factsOf('props.size')).toBe('nil|string (undefined)')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('a signal is its declared type or literal seed, nil when it has none', () => {
|
|
85
|
+
expect(factsOf('count()')).toBe('number')
|
|
86
|
+
expect(factsOf('und()')).toBe('nil|number (undefined)')
|
|
87
|
+
expect(factsOf('label()')).toBe('string')
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('destructured props are bare names; a props object reads them only as members', () => {
|
|
91
|
+
const destructured = collectOperandTyping(meta({ propsParams: [param('n', prim('number'))] })).at(BindingScope.EMPTY)
|
|
92
|
+
expect(factsOf('n', destructured)).toBe('number')
|
|
93
|
+
expect(factsOf('n')).toBe('unknown')
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('a loop binding shadows an outer name; a loop index is a non-negative integer', () => {
|
|
97
|
+
const row = BindingScope.forComponent('props').enterLoopRow({ param: 'count', index: 'i' })
|
|
98
|
+
const at = collectOperandTyping(COMPONENT).at(row)
|
|
99
|
+
expect(factsOf('count', at)).toBe('unknown')
|
|
100
|
+
const index = operandFacts(parseExpression('i'), at)
|
|
101
|
+
expect(show(index)).toBe('number')
|
|
102
|
+
expect(index.index).toBe(true)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('a row read takes its type from the loop row type', () => {
|
|
106
|
+
const rowType: TypeInfo = {
|
|
107
|
+
kind: 'object',
|
|
108
|
+
raw: '{ id: string; n?: number }',
|
|
109
|
+
properties: [
|
|
110
|
+
{ name: 'id', type: prim('string'), optional: false, readonly: false },
|
|
111
|
+
{ name: 'n', type: prim('number'), optional: true, readonly: false },
|
|
112
|
+
],
|
|
113
|
+
}
|
|
114
|
+
const row = BindingScope.forComponent('props').enterLoopRow({ param: 'r', itemType: rowType })
|
|
115
|
+
const at = collectOperandTyping(COMPONENT).at(row)
|
|
116
|
+
expect(factsOf('r.id', at)).toBe('string')
|
|
117
|
+
expect(factsOf('r.n', at)).toBe('nil|number (undefined)')
|
|
118
|
+
expect(factsOf('r', at)).toBe('object')
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('a binding named `props` reads its own member, not the prop', () => {
|
|
122
|
+
const shadow = BindingScope.forComponent('props').enterCallback(['props'])
|
|
123
|
+
expect(factsOf('props.n', collectOperandTyping(COMPONENT).at(shadow))).toBe('unknown')
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
describe('operandFacts', () => {
|
|
128
|
+
test('literals and structural results', () => {
|
|
129
|
+
expect(factsOf("'a'")).toBe('string')
|
|
130
|
+
expect(factsOf('1')).toBe('number')
|
|
131
|
+
expect(factsOf('true')).toBe('boolean')
|
|
132
|
+
expect(factsOf('null')).toBe('nil (null)')
|
|
133
|
+
expect(factsOf('undefined')).toBe('nil (undefined)')
|
|
134
|
+
expect(factsOf('`a${props.n}`')).toBe('string')
|
|
135
|
+
expect(factsOf('props.n < 1')).toBe('boolean')
|
|
136
|
+
expect(factsOf('!props.n')).toBe('boolean')
|
|
137
|
+
expect(factsOf('-props.s')).toBe('number')
|
|
138
|
+
expect(factsOf('props.n % 2')).toBe('number')
|
|
139
|
+
expect(factsOf('[1, 2]')).toBe('object')
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
test('`+` is a string when either side is one, a number when neither can be', () => {
|
|
143
|
+
expect(factsOf("props.n + 'x'")).toBe('string')
|
|
144
|
+
expect(factsOf('props.n + count()')).toBe('number')
|
|
145
|
+
expect(factsOf('props.n + props.maybe')).toBe('number')
|
|
146
|
+
expect(factsOf('props.n + label2()')).toBe('unknown')
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
test('`&&` / `||` / `?:` are the union of their values; `??` drops the nil of its left side', () => {
|
|
150
|
+
expect(factsOf('props.on && props.n > 1')).toBe('boolean')
|
|
151
|
+
expect(factsOf("props.on ? 'a' : 1")).toBe('number|string')
|
|
152
|
+
expect(factsOf("props.on ? 'a' : null")).toBe('nil|string (null)')
|
|
153
|
+
expect(factsOf('props.maybe ?? 0')).toBe('number')
|
|
154
|
+
expect(factsOf('props.on || x()')).toBe('unknown')
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
test('a method result and an index read are not typed in step 0', () => {
|
|
158
|
+
expect(factsOf('props.rows.includes(1)')).toBe('unknown')
|
|
159
|
+
expect(factsOf('props.rows[0]')).toBe('unknown')
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const NONE: NativeSafeTable = {}
|
|
164
|
+
const ALL: NativeSafeTable = {
|
|
165
|
+
'to-boolean': ['boolean', 'unproven'],
|
|
166
|
+
'to-number': ['number-pair', 'number', 'unproven'],
|
|
167
|
+
plus: ['number-pair', 'string', 'unproven'],
|
|
168
|
+
'strict-eq': ['number-pair', 'string-pair', 'boolean-pair', 'unproven'],
|
|
169
|
+
relational: ['number-pair', 'unproven'],
|
|
170
|
+
neg: ['number', 'unproven'],
|
|
171
|
+
'number-literal': ['safe-integer', 'unproven'],
|
|
172
|
+
nullish: ['non-nil', 'unproven'],
|
|
173
|
+
get: ['array-index', 'unproven'],
|
|
174
|
+
}
|
|
175
|
+
const PROVEN_ONLY: NativeSafeTable = {
|
|
176
|
+
'to-boolean': ['boolean'],
|
|
177
|
+
'to-number': ['number-pair', 'number'],
|
|
178
|
+
plus: ['number-pair', 'string'],
|
|
179
|
+
'strict-eq': ['number-pair', 'string-pair', 'boolean-pair'],
|
|
180
|
+
relational: ['number-pair'],
|
|
181
|
+
neg: ['number'],
|
|
182
|
+
'number-literal': ['safe-integer'],
|
|
183
|
+
nullish: ['non-nil'],
|
|
184
|
+
get: ['array-index'],
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** The plan as `mode op proof|helper`. */
|
|
188
|
+
function plan(src: string, target: NativeSafeTable, at: ScopedOperandTyping = typing): string {
|
|
189
|
+
const p = planPrimitive(parseExpression(src), at, target)
|
|
190
|
+
if (p === null) return 'none'
|
|
191
|
+
if (p.mode === 'native') return `native ${p.op} ${p.proof}`
|
|
192
|
+
if (p.mode === 'helper') return `helper ${p.op} ${p.helper} ${p.proof}`
|
|
193
|
+
if (p.mode === 'const') return `const ${p.op} ${p.value}`
|
|
194
|
+
return `refuse ${p.op}`
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
describe('planPrimitive', () => {
|
|
198
|
+
test('ToBoolean (a test position) is native only for a proven boolean the target claims', () => {
|
|
199
|
+
expect(plan('!props.on', PROVEN_ONLY)).toBe('native to-boolean boolean')
|
|
200
|
+
expect(plan('!props.s', PROVEN_ONLY)).toBe('helper to-boolean truthy unproven')
|
|
201
|
+
expect(plan('!props.s', ALL)).toBe('native to-boolean unproven')
|
|
202
|
+
expect(plan('props.on ? 1 : 2', NONE)).toBe('helper to-boolean truthy boolean')
|
|
203
|
+
expect(plan('props.s && 1', PROVEN_ONLY)).toBe('helper to-boolean truthy unproven')
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
test('relational and arithmetic are native only for two proven non-nil numbers', () => {
|
|
207
|
+
expect(plan('props.n < count()', PROVEN_ONLY)).toBe('native relational number-pair')
|
|
208
|
+
expect(plan('props.n <= props.maybe', PROVEN_ONLY)).toBe('helper relational le unproven')
|
|
209
|
+
expect(plan("props.s > '9'", PROVEN_ONLY)).toBe('helper relational gt unproven')
|
|
210
|
+
expect(plan('props.n - 1', PROVEN_ONLY)).toBe('native to-number number-pair')
|
|
211
|
+
expect(plan('props.n * props.nothing', PROVEN_ONLY)).toBe('helper to-number mul unproven')
|
|
212
|
+
expect(plan('props.n - props.maybe', NONE)).toBe('helper to-number sub unproven')
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
test('`/` and `%` always name their helper', () => {
|
|
216
|
+
expect(plan('props.n / 2', ALL)).toBe('helper to-number div number-pair')
|
|
217
|
+
expect(plan('props.n % 2', ALL)).toBe('helper to-number mod number-pair')
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
test('`+` adds two numbers, concatenates over a proven string, and is `plus` otherwise', () => {
|
|
221
|
+
expect(plan('props.n + 1', PROVEN_ONLY)).toBe('native plus number-pair')
|
|
222
|
+
expect(plan('props.n + 1', NONE)).toBe('helper plus add number-pair')
|
|
223
|
+
expect(plan("props.n + 'x'", PROVEN_ONLY)).toBe('native plus string')
|
|
224
|
+
expect(plan('props.maybe + 1', PROVEN_ONLY)).toBe('helper plus plus unproven')
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
test('`===` is native for a same-typed pair the target pins, and constant across proven types', () => {
|
|
228
|
+
expect(plan("props.s === 'a'", PROVEN_ONLY)).toBe('native strict-eq string-pair')
|
|
229
|
+
expect(plan('props.n === count()', PROVEN_ONLY)).toBe('native strict-eq number-pair')
|
|
230
|
+
expect(plan('props.maybe === 1', PROVEN_ONLY)).toBe('helper strict-eq strict_eq unproven')
|
|
231
|
+
expect(plan("props.n === 'a'", ALL)).toBe('const strict-eq false')
|
|
232
|
+
expect(plan("props.n !== 'a'", ALL)).toBe('const strict-eq true')
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
test('unary minus over a non-zero number literal folds into the literal; any other operand takes `neg`', () => {
|
|
236
|
+
expect(plan('-1', PROVEN_ONLY)).toBe('native number-literal safe-integer')
|
|
237
|
+
expect(plan('-1.5', PROVEN_ONLY)).toBe('helper number-literal number unproven')
|
|
238
|
+
expect(plan('-1e21', ALL)).toBe('native number-literal unproven')
|
|
239
|
+
// `-0` does not fold: the zero operand is the case `neg` exists for.
|
|
240
|
+
expect(plan('-0', ALL)).toBe('native neg unproven')
|
|
241
|
+
expect(plan('-0', PROVEN_ONLY)).toBe('helper neg neg unproven')
|
|
242
|
+
expect(plan('-props.n', PROVEN_ONLY)).toBe('helper neg neg unproven')
|
|
243
|
+
expect(plan('+props.n', PROVEN_ONLY)).toBe('native to-number number')
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
test('a number literal is native only when it is a safe integer', () => {
|
|
247
|
+
expect(plan('42', PROVEN_ONLY)).toBe('native number-literal safe-integer')
|
|
248
|
+
expect(plan('9007199254740991', PROVEN_ONLY)).toBe('native number-literal safe-integer')
|
|
249
|
+
expect(plan('9007199254740992', PROVEN_ONLY)).toBe('helper number-literal number unproven')
|
|
250
|
+
expect(plan('1.5', PROVEN_ONLY)).toBe('helper number-literal number unproven')
|
|
251
|
+
expect(plan('1e21', PROVEN_ONLY)).toBe('helper number-literal number unproven')
|
|
252
|
+
expect(plan('100000000000000000000', PROVEN_ONLY)).toBe('helper number-literal number unproven')
|
|
253
|
+
expect(plan("'42'", PROVEN_ONLY)).toBe('none')
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
test('a number literal is spelled from its plan: host literal, `number` over the JS spelling, or `neg(0)`', () => {
|
|
257
|
+
const spell = (src: string) => {
|
|
258
|
+
const node = parseExpression(src)
|
|
259
|
+
const literal = foldNegatedNumberLiteral(node) ?? node
|
|
260
|
+
const value = literal.kind === 'literal' && typeof literal.value === 'number' ? literal.value : -0
|
|
261
|
+
return numberLiteralSpelling(value, planPrimitive(node, typing, PROVEN_ONLY))
|
|
262
|
+
}
|
|
263
|
+
expect(spell('42')).toEqual({ kind: 'native', text: '42' })
|
|
264
|
+
expect(spell('-3')).toEqual({ kind: 'native', text: '-3' })
|
|
265
|
+
expect(spell('1e21')).toEqual({ kind: 'parse', text: '1e+21' })
|
|
266
|
+
expect(spell('1e-7')).toEqual({ kind: 'parse', text: '1e-7' })
|
|
267
|
+
expect(spell('1e20')).toEqual({ kind: 'parse', text: '100000000000000000000' })
|
|
268
|
+
expect(spell('-1.5')).toEqual({ kind: 'parse', text: '-1.5' })
|
|
269
|
+
expect(spell('9007199254740993')).toEqual({ kind: 'parse', text: '9007199254740992' })
|
|
270
|
+
expect(numberLiteralSpelling(-0, null)).toEqual({ kind: 'negative-zero' })
|
|
271
|
+
// A null plan (an emitter reached outside the dispatcher) gets the safe-integer claim.
|
|
272
|
+
expect(numberLiteralSpelling(7, null)).toEqual({ kind: 'native', text: '7' })
|
|
273
|
+
expect(numberLiteralSpelling(0.5, null)).toEqual({ kind: 'parse', text: '0.5' })
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
test('`??` is native when its left side is proven never nil', () => {
|
|
277
|
+
expect(plan("props.s ?? 'x'", PROVEN_ONLY)).toBe('native nullish non-nil')
|
|
278
|
+
expect(plan('props.maybe ?? 0', PROVEN_ONLY)).toBe('helper nullish coalesce unproven')
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
test('an index read is native only for a proven array read by a loop index', () => {
|
|
282
|
+
const row = BindingScope.forComponent('props').enterLoopRow({ param: 'item', index: 'i' })
|
|
283
|
+
const at = collectOperandTyping(COMPONENT).at(row)
|
|
284
|
+
expect(plan('props.rows[i]', PROVEN_ONLY, at)).toBe('native get array-index')
|
|
285
|
+
expect(plan('props.rows[props.n]', PROVEN_ONLY, at)).toBe('helper get get unproven')
|
|
286
|
+
// A literal key is a computed member, never a proven index.
|
|
287
|
+
expect(plan('props.rows[0]', PROVEN_ONLY, at)).toBe('helper get get unproven')
|
|
288
|
+
expect(plan('props.rows.length', PROVEN_ONLY, at)).toBe('none')
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
test('loose equality and other operators are not planned', () => {
|
|
292
|
+
expect(plan('props.n == 1', ALL)).toBe('none')
|
|
293
|
+
expect(plan("'a' in props", ALL)).toBe('none')
|
|
294
|
+
expect(plan('typeof props.n', ALL)).toBe('none')
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
test('the empty typing proves only structure', () => {
|
|
298
|
+
const empty = EMPTY_OPERAND_TYPING.at(BindingScope.EMPTY)
|
|
299
|
+
expect(plan('!props.on', PROVEN_ONLY, empty)).toBe('helper to-boolean truthy unproven')
|
|
300
|
+
expect(plan('!(a < b)', PROVEN_ONLY, empty)).toBe('native to-boolean boolean')
|
|
301
|
+
})
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
/** The typing of the one component in `src`, at component scope, from the analyzer's metadata. */
|
|
305
|
+
function analyzed(src: string): ScopedOperandTyping {
|
|
306
|
+
const metadata = buildMetadata(analyzeComponent(src, 'foo.tsx'))
|
|
307
|
+
return collectOperandTyping(metadata).at(BindingScope.forComponent(metadata.propsObjectName))
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const NON_NIL_NULLISH: NativeSafeTable = { nullish: ['non-nil'] }
|
|
311
|
+
|
|
312
|
+
describe('defaults, from analyzed components', () => {
|
|
313
|
+
test('a renamed body-destructure default types the local binding, not the original property', () => {
|
|
314
|
+
const at = analyzed(
|
|
315
|
+
"export function Foo(props: { label?: string }) { const { label: text = 'none' } = props; return <div>{props.label ?? 'fallback'}{text}</div> }",
|
|
316
|
+
)
|
|
317
|
+
expect(factsOf('props.label', at)).toBe('nil|string (undefined)')
|
|
318
|
+
expect(plan("props.label ?? 'fallback'", NON_NIL_NULLISH, at)).toBe('helper nullish coalesce unproven')
|
|
319
|
+
expect(factsOf('text', at)).toBe('string')
|
|
320
|
+
expect(plan("text ?? 'fallback'", NON_NIL_NULLISH, at)).toBe('native nullish non-nil')
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
test('an unrenamed body-destructure default types the local binding, not the original property', () => {
|
|
324
|
+
const at = analyzed(
|
|
325
|
+
"export function Foo(props: { label?: string }) { const { label = 'none' } = props; return <div>{props.label ?? 'fallback'}{label}</div> }",
|
|
326
|
+
)
|
|
327
|
+
expect(factsOf('props.label', at)).toBe('nil|string (undefined)')
|
|
328
|
+
expect(plan("props.label ?? 'fallback'", NON_NIL_NULLISH, at)).toBe('helper nullish coalesce unproven')
|
|
329
|
+
expect(factsOf('label', at)).toBe('string')
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
test('a body destructure without a default keeps the optional nil', () => {
|
|
333
|
+
const at = analyzed('export function Foo(props: { label?: string }) { const { label } = props; return <div>{label}</div> }')
|
|
334
|
+
expect(factsOf('label', at)).toBe('nil|string (undefined)')
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
test('a literal parameter default proves its own type; an `undefined` default does not prove non-nil', () => {
|
|
338
|
+
const at = analyzed(
|
|
339
|
+
"export function Foo({ on = undefined, n = 1, size = 'md', off = false, alias = off }: { on?: boolean; n?: number; size?: string; off?: boolean; alias?: boolean }) { return <div>{on ?? true}{n}{size}{alias}</div> }",
|
|
340
|
+
)
|
|
341
|
+
expect(factsOf('on', at)).toBe('boolean|nil (undefined)')
|
|
342
|
+
expect(plan('on ?? true', NON_NIL_NULLISH, at)).toBe('helper nullish coalesce unproven')
|
|
343
|
+
expect(factsOf('n', at)).toBe('number')
|
|
344
|
+
expect(plan('n ?? 0', NON_NIL_NULLISH, at)).toBe('native nullish non-nil')
|
|
345
|
+
expect(factsOf('size', at)).toBe('string')
|
|
346
|
+
// A default reading an earlier binding takes that binding's facts.
|
|
347
|
+
expect(factsOf('alias', at)).toBe('boolean')
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
test('a destructuring default replaces only `undefined`: a declared `null` survives it', () => {
|
|
351
|
+
const param = analyzed("export function Foo({ label = 'none' }: { label?: string | null }) { return <div>{label ?? 'fallback'}</div> }")
|
|
352
|
+
expect(factsOf('label', param)).toBe('nil|string (null)')
|
|
353
|
+
expect(plan("label ?? 'fallback'", NON_NIL_NULLISH, param)).toBe('helper nullish coalesce unproven')
|
|
354
|
+
const renamed = analyzed(
|
|
355
|
+
"export function Foo(props: { label?: string | null }) { const { label: text = 'none' } = props; return <div>{text ?? 'fallback'}</div> }",
|
|
356
|
+
)
|
|
357
|
+
expect(factsOf('text', renamed)).toBe('nil|string (null)')
|
|
358
|
+
expect(plan("text ?? 'fallback'", NON_NIL_NULLISH, renamed)).toBe('helper nullish coalesce unproven')
|
|
359
|
+
const unrenamed = analyzed(
|
|
360
|
+
"export function Foo(props: { label?: string | null }) { const { label = 'none' } = props; return <div>{label ?? 'fallback'}</div> }",
|
|
361
|
+
)
|
|
362
|
+
expect(factsOf('label', unrenamed)).toBe('nil|string (null)')
|
|
363
|
+
// A required nullable prop keeps its `null` too.
|
|
364
|
+
const required = analyzed("export function Foo({ label = 'none' }: { label: string | null }) { return <div>{label}</div> }")
|
|
365
|
+
expect(factsOf('label', required)).toBe('nil|string (null)')
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
test('a hand-written `??` const is never nil: `??` replaces `null` too', () => {
|
|
369
|
+
const at = analyzed(
|
|
370
|
+
"export function Foo(props: { label?: string | null }) { const text = props.label ?? 'none'; return <div>{text ?? 'fallback'}</div> }",
|
|
371
|
+
)
|
|
372
|
+
expect(factsOf('text', at)).toBe('string')
|
|
373
|
+
expect(plan("text ?? 'fallback'", NON_NIL_NULLISH, at)).toBe('native nullish non-nil')
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
test('`||` and `&&` initializers prove nothing (a falsy non-nil left side survives `||`)', () => {
|
|
377
|
+
const at = analyzed(
|
|
378
|
+
"export function Foo(props: { label?: string | null; n: number }) { const a = props.label || 'none'; const b = props.n && 'x'; return <div>{a}{b}</div> }",
|
|
379
|
+
)
|
|
380
|
+
expect(factsOf('a', at)).toBe('unknown')
|
|
381
|
+
expect(factsOf('b', at)).toBe('unknown')
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
test('a default that may be nil, or proves nothing, does not prove non-nil', () => {
|
|
385
|
+
const at = analyzed(
|
|
386
|
+
'export function Foo({ a = null, b = make() }: { a?: number | null; b?: number }) { return <div>{a}{b}</div> }\nfunction make(): number { return 1 }',
|
|
387
|
+
)
|
|
388
|
+
expect(factsOf('a', at)).toBe('nil|number (null)')
|
|
389
|
+
expect(factsOf('b', at)).toBe('unknown')
|
|
390
|
+
expect(plan('b ?? 0', NON_NIL_NULLISH, at)).toBe('helper nullish coalesce unproven')
|
|
391
|
+
})
|
|
392
|
+
})
|
|
393
|
+
|
|
394
|
+
describe('array element evidence through a union (#3824 step 8)', () => {
|
|
395
|
+
const row: TypeInfo = { kind: 'interface', raw: 'Row' }
|
|
396
|
+
const withRows = (type: TypeInfo, optional = false) =>
|
|
397
|
+
collectOperandTyping(meta({ propsParams: [param('rows', type, optional)] })).at(BindingScope.EMPTY)
|
|
398
|
+
const isRow = (name: string) => name === 'Row'
|
|
399
|
+
|
|
400
|
+
test('an optional or nullable object array keeps its element evidence for the refusal', () => {
|
|
401
|
+
for (const at of [withRows(array(row), true), withRows(union(array(row), prim('null')))]) {
|
|
402
|
+
expect(mayHoldObject(parseExpression('rows[0]'), at, isRow)).toBe(true)
|
|
403
|
+
expect(mayHoldObject(parseExpression('rows.at(0)'), at, isRow)).toBe(true)
|
|
404
|
+
}
|
|
405
|
+
})
|
|
406
|
+
|
|
407
|
+
test('the kept element evidence does not prove a nullable array an array', () => {
|
|
408
|
+
const facts = operandFacts(parseExpression('rows'), withRows(array(row), true))
|
|
409
|
+
expect(facts.array).toBeUndefined()
|
|
410
|
+
expect(facts.types.has('nil')).toBe(true)
|
|
411
|
+
})
|
|
412
|
+
|
|
413
|
+
test('a primitive element array is still not refused', () => {
|
|
414
|
+
expect(mayHoldObject(parseExpression('rows[0]'), withRows(array(prim('number')), true), isRow)).toBe(false)
|
|
415
|
+
})
|
|
416
|
+
})
|
|
@@ -52,8 +52,8 @@ describe('loop-child binding-effect ids (#1795 Phase 2)', () => {
|
|
|
52
52
|
const on = clientJs(true)
|
|
53
53
|
// Both `{it.t}` and `{it.n}` text effects write through the row's
|
|
54
54
|
// claimed 'text' slot writer (slot unification A3).
|
|
55
|
-
expect(on).toMatch(/__bfw_\w+\('s\d+',
|
|
56
|
-
expect(on).toMatch(/__bfw_\w+\('s\d+',
|
|
55
|
+
expect(on).toMatch(/__bfw_\w+\('s\d+', textOrNode\(it\(\)\.t\)\) }, "List#binding:s\d+"\)/)
|
|
56
|
+
expect(on).toMatch(/__bfw_\w+\('s\d+', textOrNode\(it\(\)\.n\)\) }, "List#binding:s\d+"\)/)
|
|
57
57
|
})
|
|
58
58
|
|
|
59
59
|
test('profile on: the loop-child attribute effect carries a #binding id', () => {
|
|
@@ -122,7 +122,7 @@ describe('nested loop binding ids (#1795 Phase 3)', () => {
|
|
|
122
122
|
// a live Node passes through untouched.
|
|
123
123
|
expect(on).toMatch(/__bfw_\w+\('s\d+', escapeTextOrNode\(r\(\)\.label\)\) }, "Nested#binding:s\d+"\)/)
|
|
124
124
|
// The inner loop's child text (`{t}`).
|
|
125
|
-
expect(on).toMatch(/
|
|
125
|
+
expect(on).toMatch(/textOrNode\(t\(\)\)\) }, "Nested#binding:s\d+"\)/)
|
|
126
126
|
})
|
|
127
127
|
|
|
128
128
|
test('branch-scoped loop (loop inside a conditional) attributes its mapArray', () => {
|
|
@@ -137,7 +137,7 @@ describe('nested loop binding ids (#1795 Phase 3)', () => {
|
|
|
137
137
|
const emitted = assertNoCoverageGap(staticLoopSource, 'StaticLoop')
|
|
138
138
|
expect(emitted.length).toBeGreaterThanOrEqual(1)
|
|
139
139
|
const on = clientJs(staticLoopSource, 'StaticLoop', true)
|
|
140
|
-
expect(on).toMatch(/__bfw_\w+\('s\d+',
|
|
140
|
+
expect(on).toMatch(/__bfw_\w+\('s\d+', textOrNode\(n\(\)\)\) }, "StaticLoop#binding:s\d+"\)/)
|
|
141
141
|
})
|
|
142
142
|
|
|
143
143
|
test('component loop attributes its mapArray', () => {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import ts from 'typescript'
|
|
3
|
+
import { observesWholePropsObject } from '../props-object-whole-read'
|
|
4
|
+
import { analyzeComponent } from '../analyzer'
|
|
5
|
+
import { buildMetadata } from '../compiler'
|
|
6
|
+
|
|
7
|
+
const observes = (body: string): boolean => {
|
|
8
|
+
const sf = ts.createSourceFile('c.tsx', `function C(props: P) {\n${body}\n}`, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX)
|
|
9
|
+
const fn = sf.statements[0] as ts.FunctionDeclaration
|
|
10
|
+
return observesWholePropsObject(fn, 'props')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe('observesWholePropsObject', () => {
|
|
14
|
+
test('member reads with a known key are not whole reads', () => {
|
|
15
|
+
expect(observes('return <b title={props.title} data-x={props["x"]} data-y={props?.y}>{props[0]}</b>')).toBe(false)
|
|
16
|
+
expect(observes('const { a, b: c } = props; return <b>{a}{c}</b>')).toBe(false)
|
|
17
|
+
expect(observes('const t: typeof props = null as any; return <b />')).toBe(false)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('a spread, a dynamic key, a whole pass and a rest destructure are whole reads', () => {
|
|
21
|
+
expect(observes('return <b {...props} />')).toBe(true)
|
|
22
|
+
expect(observes('return <Inner {...props} />')).toBe(true)
|
|
23
|
+
expect(observes('const k = "a"; return <b>{props[k]}</b>')).toBe(true)
|
|
24
|
+
expect(observes('return <b>{Object.keys(props).join(",")}</b>')).toBe(true)
|
|
25
|
+
expect(observes('const { a, ...rest } = props; return <b {...rest}>{a}</b>')).toBe(true)
|
|
26
|
+
expect(observes('const o = { props }; return <b>{String(o)}</b>')).toBe(true)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('a nested binding of the same name shadows the props object', () => {
|
|
30
|
+
expect(observes('const f = (props: any) => ({ ...props }); return <b>{String(f)}</b>')).toBe(false)
|
|
31
|
+
expect(observes('const xs = [1].map(n => { const props = { n }; return { ...props } }); return <b>{xs.length}</b>')).toBe(false)
|
|
32
|
+
expect(observes('const f = (other: any) => ({ ...props }); return <b>{String(f)}</b>')).toBe(true)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test('IR metadata carries the answer for a props-object component', () => {
|
|
36
|
+
const meta = (src: string) => buildMetadata(analyzeComponent(src, 'c.tsx'))
|
|
37
|
+
expect(meta('export function Kid(props: { label: string }) { return <b {...props}>{props.label}</b> }').propsObjectObservedWhole).toBe(true)
|
|
38
|
+
expect(meta('export function Kid(props: { label: string }) { return <b>{props.label}</b> }').propsObjectObservedWhole).toBe(false)
|
|
39
|
+
})
|
|
40
|
+
})
|
|
@@ -232,7 +232,7 @@ describe('reactive attributes inside .map() callbacks', () => {
|
|
|
232
232
|
// claimed 'text' slot writer now (slot unification A3), not a bare
|
|
233
233
|
// `.textContent =` assignment.
|
|
234
234
|
expect(js).toContain("setAttribute('class'")
|
|
235
|
-
expect(js).toMatch(/__bfw_\w+\('s\d+',
|
|
235
|
+
expect(js).toMatch(/__bfw_\w+\('s\d+', textOrNode\(item\.name\)\)/)
|
|
236
236
|
// But there must be exactly one `items.forEach` call (not two).
|
|
237
237
|
const forEachMatches = js.match(/items\.forEach\(/g) ?? []
|
|
238
238
|
expect(forEachMatches.length).toBe(1)
|
|
@@ -203,9 +203,12 @@ describe('Reactive factory inlining (#931)', () => {
|
|
|
203
203
|
`
|
|
204
204
|
|
|
205
205
|
const result = compileJSX(source, 'Comp.tsx', { adapter })
|
|
206
|
-
expect(result.errors.filter(e => e.severity === 'error')).toHaveLength(0)
|
|
207
206
|
const bf110 = result.errors.find(e => e.code === 'BF110')
|
|
208
207
|
expect(bf110).toBeUndefined()
|
|
208
|
+
// Not a factory call, so the destructure is an ordinary body destructure
|
|
209
|
+
// of a call, which no backend binds: refused with BF101 (#3854), where
|
|
210
|
+
// it used to compile clean with `x` left unbound.
|
|
211
|
+
expect(result.errors.filter(e => e.severity === 'error').map(e => e.code)).toEqual(['BF101'])
|
|
209
212
|
})
|
|
210
213
|
})
|
|
211
214
|
|