@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
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { describe, test, expect } from 'bun:test'
|
|
2
2
|
import { analyzeComponent } from '../analyzer'
|
|
3
|
-
import {
|
|
3
|
+
import { parseExpression } from '../expression-parser'
|
|
4
4
|
import {
|
|
5
|
-
ambiguousNilArithmeticOperands,
|
|
6
5
|
arithmeticOperandCoercion,
|
|
7
6
|
arithmeticOperandIsNull,
|
|
8
7
|
arithmeticOperandIsUndefined,
|
|
9
|
-
arithmeticOperandNilIsAmbiguous,
|
|
10
8
|
attrValueMayBeNullish,
|
|
11
9
|
collectAbsentPropSeedReads,
|
|
12
10
|
collectNullableSignalGetters,
|
|
13
11
|
collectNullishAttrContext,
|
|
12
|
+
isNeverNullishOperand,
|
|
13
|
+
nullablePropsYieldedBy,
|
|
14
14
|
nullableSignalAttrGetter,
|
|
15
15
|
} from '../nullable-signal-attr'
|
|
16
|
-
import { BindingScope } from '../scope/binding-scope'
|
|
17
16
|
import type { ComponentIR } from '../types'
|
|
18
17
|
|
|
19
18
|
function nullableGetters(decls: string): Set<string> {
|
|
@@ -215,9 +214,9 @@ describe('arithmeticOperandCoercion (#3474)', () => {
|
|
|
215
214
|
for (const op of ['-', '*', '/', '%', '**']) expect(coercion(ctx, op, 'props.b', 'x')).toBe('undefined')
|
|
216
215
|
expect(coercion(ctx, '+', 'props.b', '-2')).toBe('undefined')
|
|
217
216
|
expect(coercion(ctx, '*', 'props.u', '2')).toBe('undefined')
|
|
218
|
-
// A type that admits both
|
|
219
|
-
//
|
|
220
|
-
expect(coercion(ctx, '*', 'props.both', '2')).
|
|
217
|
+
// A type that admits both is left to the runtime's helper, which reads
|
|
218
|
+
// `null` and `UNDEF` apart (spec/js-undefined-value.md).
|
|
219
|
+
expect(coercion(ctx, '*', 'props.both', '2')).toBeNull()
|
|
221
220
|
})
|
|
222
221
|
|
|
223
222
|
test('unary minus passes no other operand and coerces like binary minus (#3533)', () => {
|
|
@@ -228,6 +227,30 @@ describe('arithmeticOperandCoercion (#3474)', () => {
|
|
|
228
227
|
expect(unary('props.c')).toBeNull()
|
|
229
228
|
})
|
|
230
229
|
|
|
230
|
+
test('unary plus passes no other operand and coerces like unary minus (#3824 step 3)', () => {
|
|
231
|
+
const ctx = ctxOf('props: { a: number | null; b?: number; c: number }')
|
|
232
|
+
const unary = (operand: string) => arithmeticOperandCoercion('+', parseExpression(operand), undefined, ctx)
|
|
233
|
+
expect(unary('props.a')).toBe('null')
|
|
234
|
+
expect(unary('props.b')).toBe('undefined')
|
|
235
|
+
expect(unary('props.c')).toBeNull()
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
test('a string or boolean relational operand that may only be absent reads NaN and keeps a present value (#3824 step 3)', () => {
|
|
239
|
+
const ctx = ctxOf('props: { s?: string; b?: boolean; t: string | null; c: string; u: string | undefined }')
|
|
240
|
+
for (const op of ['<', '<=', '>', '>=']) {
|
|
241
|
+
expect(coercion(ctx, op, 'props.s', '1')).toBe('undefined-keep')
|
|
242
|
+
expect(coercion(ctx, op, 'props.s', "'a'")).toBe('undefined-keep')
|
|
243
|
+
expect(coercion(ctx, op, 'props.b', '1')).toBe('undefined-keep')
|
|
244
|
+
expect(coercion(ctx, op, 'props.u', '1')).toBe('undefined-keep')
|
|
245
|
+
// A `null` reading is the helper's own; a required prop has no nil.
|
|
246
|
+
expect(coercion(ctx, op, 'props.t', '1')).toBeNull()
|
|
247
|
+
expect(coercion(ctx, op, 'props.c', '1')).toBeNull()
|
|
248
|
+
}
|
|
249
|
+
// Arithmetic over a string prop is not a relational: left as it is.
|
|
250
|
+
expect(coercion(ctx, '*', 'props.s', '2')).toBeNull()
|
|
251
|
+
expect(arithmeticOperandCoercion('<', parseExpression('props.s'), parseExpression('1'), ctx, n => n === 'props')).toBeNull()
|
|
252
|
+
})
|
|
253
|
+
|
|
231
254
|
test('an absent-only prop is not certainly undefined: arithmeticOperandIsUndefined stays false', () => {
|
|
232
255
|
const ctx = ctxOf('props: { b?: number }')
|
|
233
256
|
expect(arithmeticOperandIsUndefined(parseExpression('props.b'), ctx)).toBe(false)
|
|
@@ -252,7 +275,7 @@ describe('arithmeticOperandCoercion (#3474)', () => {
|
|
|
252
275
|
})
|
|
253
276
|
})
|
|
254
277
|
|
|
255
|
-
describe('
|
|
278
|
+
describe("an operand whose nil may be either is left to the runtime's helper", () => {
|
|
256
279
|
function ctxOf(signature: string, decls = ''): ReturnType<typeof collectNullishAttrContext> {
|
|
257
280
|
const source = `
|
|
258
281
|
'use client'
|
|
@@ -264,65 +287,103 @@ describe('arithmeticOperandNilIsAmbiguous (#3700)', () => {
|
|
|
264
287
|
`
|
|
265
288
|
return collectNullishAttrContext({ metadata: analyzeComponent(source, 'C.tsx') } as unknown as ComponentIR)
|
|
266
289
|
}
|
|
267
|
-
const
|
|
268
|
-
|
|
290
|
+
const coercion = (ctx: ReturnType<typeof collectNullishAttrContext>, op: string, operand: string, other?: string) =>
|
|
291
|
+
arithmeticOperandCoercion(op, parseExpression(operand), other === undefined ? undefined : parseExpression(other), ctx)
|
|
269
292
|
|
|
270
293
|
test('a number prop that admits both null and absence, in either props form', () => {
|
|
271
294
|
for (const signature of ['props: { n?: number | null }', 'props: { n: number | null | undefined }']) {
|
|
272
295
|
const ctx = ctxOf(signature)
|
|
273
|
-
for (const op of ['-', '*', '/', '%', '**']) expect(
|
|
274
|
-
expect(
|
|
275
|
-
expect(
|
|
276
|
-
|
|
277
|
-
expect(ambiguous(ctx, '+', 'props.n', "'px'")).toBe(false)
|
|
296
|
+
for (const op of ['-', '*', '/', '%', '**']) expect(coercion(ctx, op, 'props.n', 'x')).toBeNull()
|
|
297
|
+
expect(coercion(ctx, '+', 'props.n', '1')).toBeNull()
|
|
298
|
+
expect(coercion(ctx, '-', 'props.n')).toBeNull()
|
|
299
|
+
expect(coercion(ctx, '+', 'props.n')).toBeNull()
|
|
278
300
|
}
|
|
279
301
|
const destructured = ctxOf('{ n, m: alias }: { n?: number | null; m?: null | number }')
|
|
280
|
-
expect(
|
|
281
|
-
expect(
|
|
302
|
+
expect(coercion(destructured, '*', 'n', '2')).toBeNull()
|
|
303
|
+
expect(coercion(destructured, '*', 'alias', '2')).toBeNull()
|
|
282
304
|
})
|
|
283
305
|
|
|
284
|
-
test('a
|
|
285
|
-
const ctx = ctxOf('props: { a: number | null; b?: number
|
|
286
|
-
for (const
|
|
287
|
-
|
|
306
|
+
test('a relational operand: only the one nil reading is spelled (#3824 step 3)', () => {
|
|
307
|
+
const ctx = ctxOf('props: { n?: number | null; a: number | null; b?: number }')
|
|
308
|
+
for (const op of ['<', '<=', '>', '>=']) {
|
|
309
|
+
expect(coercion(ctx, op, 'props.n', '1')).toBeNull()
|
|
310
|
+
expect(coercion(ctx, op, 'props.a', '1')).toBeNull()
|
|
311
|
+
expect(coercion(ctx, op, 'props.b', '1')).toBe('undefined')
|
|
312
|
+
}
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
test('a string or boolean prop admitting both nils under a comparison (#3824 step 3)', () => {
|
|
316
|
+
const ctx = ctxOf('props: { s?: string | null; b?: boolean | null; t?: string; m: string | null }', 'const id = createMemo(() => props.s)')
|
|
317
|
+
for (const op of ['<', '<=', '>', '>=']) {
|
|
318
|
+
expect(coercion(ctx, op, 'props.s', '1')).toBeNull()
|
|
319
|
+
expect(coercion(ctx, op, 'props.b', '1')).toBeNull()
|
|
320
|
+
expect(coercion(ctx, op, 'id()', '1')).toBeNull()
|
|
321
|
+
expect(coercion(ctx, op, 'props.t', '1')).toBe('undefined-keep')
|
|
322
|
+
expect(coercion(ctx, op, 'props.m', '1')).toBeNull()
|
|
323
|
+
}
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
test('a defaulted one and a shadowed one keep their own coercion', () => {
|
|
327
|
+
expect(coercion(ctxOf('{ n = 1 }: { n?: number | null }'), '*', 'n', '2')).toBeNull()
|
|
288
328
|
const destructured = ctxOf('{ n }: { n?: number | null }')
|
|
289
|
-
expect(
|
|
329
|
+
expect(arithmeticOperandCoercion('*', parseExpression('n'), parseExpression('2'), destructured, name => name === 'n')).toBeNull()
|
|
290
330
|
})
|
|
291
331
|
|
|
292
|
-
test('an identity memo over the prop is
|
|
332
|
+
test('an identity memo over the prop is left to the helper too', () => {
|
|
293
333
|
const ctx = ctxOf('props: { n?: number | null }', 'const m = createMemo(() => props.n)')
|
|
294
|
-
expect(
|
|
295
|
-
expect(arithmeticOperandCoercion('*', parseExpression('m()'), parseExpression('2'), ctx)).toBe('null')
|
|
334
|
+
expect(coercion(ctx, '*', 'm()', '2')).toBeNull()
|
|
296
335
|
expect(arithmeticOperandIsNull(parseExpression('m()'), ctx)).toBe(true)
|
|
297
336
|
})
|
|
298
337
|
|
|
299
338
|
test('a destructured union binding keeps its declared type for the classification', () => {
|
|
300
339
|
const ctx = ctxOf('{ a, u }: { a: number | null; u?: number | undefined }')
|
|
301
|
-
expect(
|
|
302
|
-
expect(
|
|
340
|
+
expect(coercion(ctx, '*', 'a', '2')).toBe('null')
|
|
341
|
+
expect(coercion(ctx, '*', 'u', '2')).toBe('undefined')
|
|
303
342
|
})
|
|
304
343
|
})
|
|
305
344
|
|
|
306
|
-
describe('
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
expect(
|
|
323
|
-
expect(
|
|
324
|
-
expect(
|
|
325
|
-
|
|
326
|
-
expect(
|
|
345
|
+
describe('a prop that can be absent, and an operand that is never nullish', () => {
|
|
346
|
+
function irOf(signature: string): ComponentIR {
|
|
347
|
+
const source = `
|
|
348
|
+
export function C(${signature}) {
|
|
349
|
+
return <p>x</p>
|
|
350
|
+
}
|
|
351
|
+
`
|
|
352
|
+
return { metadata: analyzeComponent(source, 'C.tsx') } as unknown as ComponentIR
|
|
353
|
+
}
|
|
354
|
+
const mayBeNullish = (ir: ComponentIR, src: string, shadowed: (n: string) => boolean = () => false) =>
|
|
355
|
+
attrValueMayBeNullish(parseExpression(src), collectNullishAttrContext(ir), shadowed)
|
|
356
|
+
|
|
357
|
+
test('an && / ternary over an absent-able prop may be nullish, in both props forms', () => {
|
|
358
|
+
const object = irOf('props: { on?: boolean; label: string | undefined; n: number; d?: string }')
|
|
359
|
+
expect(mayBeNullish(object, "props.on && 'y'")).toBe(true)
|
|
360
|
+
expect(mayBeNullish(object, "props.n > 0 ? props.label : 'x'")).toBe(true)
|
|
361
|
+
expect(mayBeNullish(object, "props.n && 'y'")).toBe(false)
|
|
362
|
+
expect(mayBeNullish(object, "props.on ?? 'y'")).toBe(false)
|
|
363
|
+
expect(mayBeNullish(object, "props.on && 'y'", n => n === 'props')).toBe(false)
|
|
364
|
+
const destructured = irOf("{ on, d = 'z' }: { on?: boolean; d?: string }")
|
|
365
|
+
expect(mayBeNullish(destructured, "on && 'y'")).toBe(true)
|
|
366
|
+
expect(mayBeNullish(destructured, "on && 'y'", n => n === 'on')).toBe(false)
|
|
367
|
+
expect(mayBeNullish(destructured, "d && 'y'")).toBe(false)
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
test('nullablePropsYieldedBy names the props a value can be read whole from', () => {
|
|
371
|
+
const ir = irOf('props: { on?: boolean; label?: string; n?: number }')
|
|
372
|
+
const nullable = collectNullishAttrContext(ir).nullableProps!
|
|
373
|
+
expect([...nullablePropsYieldedBy(parseExpression("props.on && (props.n > 0 ? props.label : 'x')"), nullable)].sort()).toEqual(['label', 'on'])
|
|
374
|
+
expect([...nullablePropsYieldedBy(parseExpression("props.on ?? props.label"), nullable)]).toEqual(['label'])
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
test('isNeverNullishOperand: a comparison and a required scalar prop, not an optional or shadowed one', () => {
|
|
378
|
+
const object = irOf("props: { flag: boolean; s: string; n: number; tone: 'a' | 'b'; opt?: boolean; u: string | undefined; list: string[] }").metadata
|
|
379
|
+
const never = (src: string, isBound: (n: string) => boolean = () => false) =>
|
|
380
|
+
isNeverNullishOperand(parseExpression(src)!, object, isBound)
|
|
381
|
+
for (const src of ['props.flag', 'props.s', 'props.n', 'props.tone', 'props.n > 1', '!props.opt']) expect(never(src)).toBe(true)
|
|
382
|
+
for (const src of ['props.opt', 'props.u', 'props.list', 'flag']) expect(never(src)).toBe(false)
|
|
383
|
+
expect(never('props.flag', n => n === 'props')).toBe(false)
|
|
384
|
+
const destructured = irOf('{ flag, opt }: { flag: boolean; opt?: boolean }').metadata
|
|
385
|
+
expect(isNeverNullishOperand(parseExpression('flag')!, destructured, () => false)).toBe(true)
|
|
386
|
+
expect(isNeverNullishOperand(parseExpression('flag')!, destructured, n => n === 'flag')).toBe(false)
|
|
387
|
+
expect(isNeverNullishOperand(parseExpression('opt')!, destructured, () => false)).toBe(false)
|
|
327
388
|
})
|
|
328
389
|
})
|