@barefootjs/jsx 0.40.0 → 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 +42 -0
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +1 -0
- package/dist/adapters/attr-plan.d.ts.map +1 -1
- package/dist/adapters/boolean-carrier.d.ts +31 -0
- package/dist/adapters/boolean-carrier.d.ts.map +1 -0
- 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/component-props.d.ts +22 -7
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/computed-const.d.ts +28 -1
- package/dist/adapters/computed-const.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +39 -1
- 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 +45 -0
- package/dist/adapters/number-value.d.ts.map +1 -0
- 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 +11 -0
- package/dist/analyzer-context.d.ts.map +1 -1
- package/dist/analyzer.d.ts +34 -0
- 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 +24 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5671 -2586
- 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-component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts +29 -0
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.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/plan/build-reactive-effects.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts +5 -4
- package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +15 -0
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/reactive-effects.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 +22 -0
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/lazy-row.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts +3 -2
- 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 +37 -19
- 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/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/safe-html.d.ts +9 -3
- package/dist/ir-to-client-js/safe-html.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/ir-to-client-js/types.d.ts +30 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +8 -0
- package/dist/ir-to-client-js/utils.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 +95 -10
- 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 +27 -3
- 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 +100 -4
- 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 +16 -0
- package/dist/scope/root-prop-alias.d.ts.map +1 -1
- package/dist/signal-prop-name-collision.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +4 -2
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/ssr-seed-plan.d.ts +14 -0
- package/dist/ssr-seed-plan.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-parts.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 +120 -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-ratchet.test.ts +12 -2
- 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-carrier.test.ts +74 -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__/component-props.test.ts +14 -0
- package/src/__tests__/computed-const.test.ts +188 -0
- package/src/__tests__/emit-to-string-call.test.ts +2 -1
- package/src/__tests__/expression-parser.test.ts +24 -0
- 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 +143 -0
- 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-prop-read.test.ts +111 -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 +137 -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 +231 -2
- package/src/__tests__/primitive-plan.test.ts +416 -0
- package/src/__tests__/profile-binding-ids.test.ts +14 -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 +79 -1
- package/src/__tests__/signal-prop-name-collision.test.ts +102 -2
- package/src/__tests__/source-file-cache.test.ts +105 -0
- package/src/__tests__/ssr-seed-plan.test.ts +43 -0
- 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__/template-parts-literal-boundary.test.ts +19 -0
- package/src/adapters/ambiguous-nil-arithmetic.ts +103 -0
- package/src/adapters/attr-plan.ts +6 -2
- package/src/adapters/boolean-carrier.ts +76 -0
- 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/component-props.ts +28 -8
- package/src/adapters/computed-const.ts +443 -10
- package/src/adapters/dsl-template-adapter.ts +79 -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 +108 -0
- 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 +14 -0
- package/src/analyzer.ts +692 -85
- 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 +74 -2
- package/src/index.ts +45 -9
- 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 +100 -67
- package/src/ir-to-client-js/compute-inlinability.ts +1 -1
- package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +15 -1
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +85 -5
- package/src/ir-to-client-js/control-flow/plan/build-lazy-row.ts +3 -0
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +30 -28
- package/src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts +1 -0
- package/src/ir-to-client-js/control-flow/plan/inner-loop.ts +5 -4
- package/src/ir-to-client-js/control-flow/plan/loop-child-arm.ts +2 -0
- package/src/ir-to-client-js/control-flow/plan/loop.ts +12 -0
- package/src/ir-to-client-js/control-flow/plan/reactive-effects.ts +2 -0
- package/src/ir-to-client-js/control-flow/shared.ts +23 -24
- package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +29 -0
- package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +8 -2
- package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +8 -1
- package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +8 -7
- package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +8 -7
- package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +4 -4
- package/src/ir-to-client-js/control-flow/stringify/loop.ts +3 -3
- package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +6 -6
- package/src/ir-to-client-js/emit-reactive.ts +1 -1
- package/src/ir-to-client-js/html-template.ts +95 -38
- 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 +42 -15
- package/src/ir-to-client-js/plan/static-array-child-init.ts +34 -19
- package/src/ir-to-client-js/prop-handling.ts +22 -3
- package/src/ir-to-client-js/reactivity.ts +14 -0
- package/src/ir-to-client-js/safe-html.ts +11 -4
- package/src/ir-to-client-js/stringify/static-array-child-init.ts +30 -12
- package/src/ir-to-client-js/types.ts +23 -0
- package/src/ir-to-client-js/utils.ts +15 -1
- package/src/jsx-to-ir.ts +510 -58
- package/src/nullable-signal-attr.ts +366 -28
- package/src/prop-rewrite.ts +30 -6
- package/src/props-binding.ts +54 -3
- package/src/props-object-whole-read.ts +87 -0
- package/src/rich-type-refusal.ts +2 -1
- package/src/scope/binding-scope.ts +203 -11
- package/src/scope/lexical-scope-walk.ts +4 -3
- package/src/scope/root-prop-alias.ts +23 -0
- package/src/signal-prop-name-collision.ts +113 -22
- package/src/ssr-defaults.ts +10 -4
- package/src/ssr-seed-plan.ts +82 -17
- package/src/strip-types.ts +31 -3
- package/src/template-parts.ts +21 -1
- package/src/template-position-walk.ts +57 -28
- package/src/types.ts +117 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { describe, test, expect } from 'bun:test'
|
|
2
|
+
import { collectBooleanCarrierNames, mayYieldBooleanCarrier } from '../adapters/boolean-carrier'
|
|
3
|
+
import { parseExpression } from '../expression-parser'
|
|
4
|
+
import type { TypeInfo } from '../types'
|
|
5
|
+
|
|
6
|
+
const bool: TypeInfo = { kind: 'primitive', raw: 'boolean', primitive: 'boolean' }
|
|
7
|
+
const str: TypeInfo = { kind: 'primitive', raw: 'string', primitive: 'string' }
|
|
8
|
+
const undef: TypeInfo = { kind: 'primitive', raw: 'undefined', primitive: 'undefined' }
|
|
9
|
+
const unknown: TypeInfo = { kind: 'unknown', raw: 'unknown' }
|
|
10
|
+
const union = (...unionTypes: TypeInfo[]): TypeInfo => ({ kind: 'union', raw: 'union', unionTypes })
|
|
11
|
+
|
|
12
|
+
describe('collectBooleanCarrierNames (#3783)', () => {
|
|
13
|
+
test('an optional boolean, a boolean union and a destructured union prop carry a boolean', () => {
|
|
14
|
+
const { names, props } = collectBooleanCarrierNames({
|
|
15
|
+
signals: [],
|
|
16
|
+
memos: [],
|
|
17
|
+
propsParams: [
|
|
18
|
+
{ name: 'off', type: bool, optional: true },
|
|
19
|
+
{ name: 'either', type: union(bool, str), optional: false },
|
|
20
|
+
// A destructured union-typed prop: `type` is unresolved, `declaredType` keeps the union.
|
|
21
|
+
{ name: 'flag', type: unknown, declaredType: union(bool, undef), optional: false },
|
|
22
|
+
{ name: 'label', type: str, optional: false },
|
|
23
|
+
],
|
|
24
|
+
})
|
|
25
|
+
expect([...names].sort()).toEqual(['either', 'flag', 'off'])
|
|
26
|
+
expect([...props].sort()).toEqual(['either', 'flag', 'off'])
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('a props object keeps only the caller-facing keys', () => {
|
|
30
|
+
const { names, props } = collectBooleanCarrierNames({
|
|
31
|
+
signals: [],
|
|
32
|
+
memos: [],
|
|
33
|
+
propsObjectName: 'props',
|
|
34
|
+
propsParams: [{ name: 'off', type: bool, optional: true }],
|
|
35
|
+
})
|
|
36
|
+
expect([...names]).toEqual([])
|
|
37
|
+
expect([...props]).toEqual(['off'])
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('a boolean-typed or untyped boolean-seeded signal carries a boolean; a string signal does not', () => {
|
|
41
|
+
// The seed is classified from its parsed tree, as the analyzer attaches it.
|
|
42
|
+
const signal = (getter: string, type: TypeInfo, initialValue: string) =>
|
|
43
|
+
({ getter, setter: null, type, initialValue, parsed: parseExpression(initialValue) }) as never
|
|
44
|
+
const { names } = collectBooleanCarrierNames({
|
|
45
|
+
signals: [signal('flag', union(bool, undef), 'false'), signal('open', unknown, 'true'), signal('text', str, "'x'")],
|
|
46
|
+
memos: [],
|
|
47
|
+
propsParams: [],
|
|
48
|
+
})
|
|
49
|
+
expect([...names].sort()).toEqual(['flag', 'open'])
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
describe('mayYieldBooleanCarrier (#3783)', () => {
|
|
54
|
+
const carriers = new Set(['off', 'flag'])
|
|
55
|
+
const isCarrier = (n: string, componentProperty?: boolean) => (componentProperty ? n === 'off' : carriers.has(n))
|
|
56
|
+
const yields = (src: string) => mayYieldBooleanCarrier(parseExpression(src)!, isCarrier)
|
|
57
|
+
|
|
58
|
+
test('a carrier read through ?? / || / && or a ternary branch may yield it', () => {
|
|
59
|
+
expect(yields("off ?? 'none'")).toBe(true)
|
|
60
|
+
expect(yields("props.off ?? 'none'")).toBe(true)
|
|
61
|
+
expect(yields("flag() ?? 'none'")).toBe(true)
|
|
62
|
+
expect(yields("on && (off ?? 'none')")).toBe(true)
|
|
63
|
+
expect(yields("label || off")).toBe(true)
|
|
64
|
+
expect(yields("on ? (off ?? 'none') : 'x'")).toBe(true)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('a carrier only in a ternary test, a call argument or a computed member does not', () => {
|
|
68
|
+
expect(yields("off ? 'a' : 'b'")).toBe(false)
|
|
69
|
+
expect(yields("label ?? 'none'")).toBe(false)
|
|
70
|
+
expect(yields("fmt(off)")).toBe(false)
|
|
71
|
+
expect(yields("props['off'] ?? 'none'")).toBe(false)
|
|
72
|
+
expect(yields("flag(1) ?? 'none'")).toBe(false)
|
|
73
|
+
})
|
|
74
|
+
})
|
|
@@ -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.
|
|
@@ -130,6 +130,16 @@ describe('planComponentProps', () => {
|
|
|
130
130
|
expect(spell(comp, withProps)).toEqual([`{tone='a'}`, '...tone?=$tone', `{size=$size, tone='z', _bf_slot='s0'}`])
|
|
131
131
|
})
|
|
132
132
|
|
|
133
|
+
test('with caller keys, {...props} carries every optional param only when the caller passed it', () => {
|
|
134
|
+
const callerKeys: ComponentPropsOptions = {
|
|
135
|
+
propsObjectName: 'props',
|
|
136
|
+
propsParams: [{ name: 'tone', optional: false }, { name: 'size' }],
|
|
137
|
+
callerKeys: true,
|
|
138
|
+
}
|
|
139
|
+
const comp = component([prop('', spread('props'))])
|
|
140
|
+
expect(spell(comp, callerKeys)).toEqual([`{tone=$tone}`, '...size?=$size', `{_bf_slot='s0'}`])
|
|
141
|
+
})
|
|
142
|
+
|
|
133
143
|
test('a key repeated across a spread stays twice: the spread may set it in between', () => {
|
|
134
144
|
const comp = component([prop('tone', literal('a')), prop('', spread('rest')), prop('tone', literal('b'))])
|
|
135
145
|
expect(spell(comp)).toEqual([`{tone='a'}`, '...rest', `{tone='b', _bf_slot='s0'}`])
|
|
@@ -161,6 +171,10 @@ describe('propsSpreadParam', () => {
|
|
|
161
171
|
test('a required param is always passed, so it always wins', () => {
|
|
162
172
|
expect(propsSpreadParam({ name: 'tone', optional: false }, { keys: new Set(['tone']), spread: true })).toBe('entry')
|
|
163
173
|
})
|
|
174
|
+
test('with caller keys, an optional param is carried only when passed even with nothing earlier', () => {
|
|
175
|
+
expect(propsSpreadParam({ name: 'tone' }, none, true)).toBe('present')
|
|
176
|
+
expect(propsSpreadParam({ name: 'tone', optional: false }, none, true)).toBe('entry')
|
|
177
|
+
})
|
|
164
178
|
})
|
|
165
179
|
|
|
166
180
|
describe('resolveComponentPropKeys', () => {
|
|
@@ -99,3 +99,191 @@ describe('inlineComputedConsts (#3494)', () => {
|
|
|
99
99
|
expect(inline('label')).toBe('props.label ?? "Default"')
|
|
100
100
|
})
|
|
101
101
|
})
|
|
102
|
+
|
|
103
|
+
describe('a const hop resolved where each const is declared (#3696)', () => {
|
|
104
|
+
const source = `
|
|
105
|
+
'use client'
|
|
106
|
+
import { createSignal } from '@barefootjs/client'
|
|
107
|
+
const x = 'module'
|
|
108
|
+
const a = x
|
|
109
|
+
const base = 'm-base'
|
|
110
|
+
const tag = base + '!'
|
|
111
|
+
const alias = tag
|
|
112
|
+
const k = 'mk'
|
|
113
|
+
const ka = k
|
|
114
|
+
function helper() { return 'h' }
|
|
115
|
+
const viaHelper = helper
|
|
116
|
+
export function C({ rows, base }: { rows: string[]; base: string }) {
|
|
117
|
+
const [k] = createSignal('sig')
|
|
118
|
+
const x = 'local'
|
|
119
|
+
const b = a
|
|
120
|
+
const c = alias
|
|
121
|
+
const d = ka
|
|
122
|
+
const helper = 'local-helper'
|
|
123
|
+
const e = viaHelper
|
|
124
|
+
return <ul>{rows.map((a, x) => <li key={a}>{b}{c}{d}{e}</li>)}</ul>
|
|
125
|
+
}
|
|
126
|
+
`
|
|
127
|
+
|
|
128
|
+
test('a module const read under a row that shadows its name reads the module binding', () => {
|
|
129
|
+
const inline = inliner(source, ['a', 'x'])
|
|
130
|
+
expect(inline('b')).toBe('"module"')
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
test('a module const initializer reads module consts, not the component prop or const of the same name', () => {
|
|
134
|
+
expect(inliner(source, ['alias', 'tag'])('c')).toBe('"m-base" + "!"')
|
|
135
|
+
expect(inliner(source, ['ka'])('d')).toBe('"mk"')
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test('the same module const read with nothing shadowed still reads the module binding', () => {
|
|
139
|
+
const inline = inliner(source)
|
|
140
|
+
expect(inline('b')).toBe('"module"')
|
|
141
|
+
expect(inline('c')).toBe('"m-base" + "!"')
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
test('a component const shadows a module const of the same name', () => {
|
|
145
|
+
expect(inliner(source)('x')).toBe('x')
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
test('a module binding with no const to read is left alone when the component rebinds its name', () => {
|
|
149
|
+
expect(inliner(source, ['viaHelper'])('e')).toBe('e')
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
describe('only names the component scope binds shadow a module const (#3696)', () => {
|
|
154
|
+
const source = `
|
|
155
|
+
'use client'
|
|
156
|
+
const label = 'module' + '!'
|
|
157
|
+
const tagged = label + '?'
|
|
158
|
+
const title = 'm-title'
|
|
159
|
+
const viaTitle = title
|
|
160
|
+
const n = 1
|
|
161
|
+
export function C(props: { label: string; title: string; n: number; rows: string[] }) {
|
|
162
|
+
const { title } = props
|
|
163
|
+
const n = props.n * 2
|
|
164
|
+
const shown = label
|
|
165
|
+
const hop = tagged
|
|
166
|
+
const t = viaTitle
|
|
167
|
+
const m = n
|
|
168
|
+
return <ul>{props.rows.map(tagged => <li key={tagged}>{shown}{hop}{t}{m}</li>)}</ul>
|
|
169
|
+
}
|
|
170
|
+
`
|
|
171
|
+
|
|
172
|
+
test('a prop reached only through the props object does not shadow a module const', () => {
|
|
173
|
+
const inline = inliner(source)
|
|
174
|
+
expect(inline('shown')).toBe('"module" + "!"')
|
|
175
|
+
expect(inline('label')).toBe('"module" + "!"')
|
|
176
|
+
expect(inliner(source, ['tagged'])('hop')).toBe('"module" + "!" + "?"')
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
test('a module const named like a props destructure binding is still the module const', () => {
|
|
180
|
+
expect(inliner(source, ['viaTitle'])('t')).toBe('"m-title"')
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
test('a computed component const shadows a literal module const of the same name', () => {
|
|
184
|
+
expect(inliner(source)('m')).toBe('props.n * 2')
|
|
185
|
+
})
|
|
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
|
+
})
|
|
@@ -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(', ')})`,
|
|
@@ -110,6 +110,30 @@ describe('expression-parser', () => {
|
|
|
110
110
|
}
|
|
111
111
|
})
|
|
112
112
|
|
|
113
|
+
test('folds a no-substitution template-literal key like the equivalent string key (#3763)', () => {
|
|
114
|
+
// Same static key, same `member` shape — adapters lower `props[`x`]`
|
|
115
|
+
// exactly as `props['x']` (a prop read), not as a dynamic index.
|
|
116
|
+
const pairs: Array<[string, string]> = [
|
|
117
|
+
['props[`title`]', "props['title']"],
|
|
118
|
+
['props?.[`title`]', "props?.['title']"],
|
|
119
|
+
['obj[`a\\u0062`]', "obj['a\\u0062']"],
|
|
120
|
+
['obj[`a\\nb`]', "obj['a\\nb']"],
|
|
121
|
+
['obj[`a\nb`]', "obj['a\\nb']"],
|
|
122
|
+
['obj[``]', "obj['']"],
|
|
123
|
+
]
|
|
124
|
+
for (const [templateKey, stringKey] of pairs) {
|
|
125
|
+
expect(parseExpression(templateKey)).toEqual(parseExpression(stringKey))
|
|
126
|
+
}
|
|
127
|
+
const folded = parseExpression('props[`title`]')
|
|
128
|
+
expect(folded.kind).toBe('member')
|
|
129
|
+
if (folded.kind === 'member') {
|
|
130
|
+
expect(folded.property).toBe('title')
|
|
131
|
+
expect(folded.computed).toBe(true)
|
|
132
|
+
}
|
|
133
|
+
// A key WITH a substitution is dynamic and stays an index access.
|
|
134
|
+
expect(parseExpression('props[`${k}`]').kind).toBe('index-access')
|
|
135
|
+
})
|
|
136
|
+
|
|
113
137
|
test('parses .length access', () => {
|
|
114
138
|
const result = parseExpression('items().length')
|
|
115
139
|
expect(result.kind).toBe('member')
|