@barefootjs/jsx 0.37.1 → 0.39.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/action-accessor.d.ts +159 -0
- package/dist/action-accessor.d.ts.map +1 -0
- package/dist/adapters/env-signal.d.ts +0 -8
- package/dist/adapters/env-signal.d.ts.map +1 -1
- package/dist/adapters/interface.d.ts +12 -0
- package/dist/adapters/interface.d.ts.map +1 -1
- package/dist/adapters/jsx-adapter.d.ts.map +1 -1
- package/dist/analyzer.d.ts +61 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/async-action-refusal.d.ts +45 -0
- package/dist/async-action-refusal.d.ts.map +1 -0
- package/dist/builtin-lowering-plugins.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/component-root-scope-comment.d.ts +36 -0
- package/dist/component-root-scope-comment.d.ts.map +1 -0
- package/dist/debug.d.ts +61 -5
- package/dist/debug.d.ts.map +1 -1
- package/dist/errors.d.ts +7 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/event-handler-name.d.ts +13 -0
- package/dist/event-handler-name.d.ts.map +1 -0
- package/dist/expression-parser.d.ts +9 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/format-date-refusal.d.ts +33 -0
- package/dist/format-date-refusal.d.ts.map +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3260 -1914
- package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
- package/dist/ir-to-client-js/compute-scope.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-branch-loop.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-composite-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/plan/build-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/lazy-row-eligibility.d.ts +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +57 -12
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/shared.d.ts +44 -3
- package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts +7 -5
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
- package/dist/ir-to-client-js/declaration-sort.d.ts +2 -1
- package/dist/ir-to-client-js/declaration-sort.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-module-level.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts +43 -2
- package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts +7 -5
- package/dist/ir-to-client-js/plan/declaration-emit.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 +9 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/source-map.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +4 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +66 -1
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/opaque-local-accessor.d.ts +27 -0
- package/dist/opaque-local-accessor.d.ts.map +1 -0
- package/dist/signal-initializer.d.ts +24 -0
- package/dist/signal-initializer.d.ts.map +1 -0
- package/dist/template-position-walk.d.ts +68 -0
- package/dist/template-position-walk.d.ts.map +1 -0
- package/dist/to-locale-date-lowering.d.ts +7 -4
- package/dist/to-locale-date-lowering.d.ts.map +1 -1
- package/dist/types.d.ts +104 -17
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +878 -4528
- package/src/__tests__/action-accessor.test.ts +166 -0
- package/src/__tests__/binding-scope-ratchet.test.ts +21 -10
- package/src/__tests__/branch-local-in-raw-capture.test.ts +1 -1
- package/src/__tests__/branch-local-same-name-collision.test.ts +9 -9
- package/src/__tests__/client-js-generation.test.ts +175 -0
- package/src/__tests__/component-root-scope-comment.test.ts +106 -0
- package/src/__tests__/create-mutation.test.ts +220 -0
- package/src/__tests__/create-query.test.ts +644 -0
- package/src/__tests__/csr-fragment-root-scope-shape.test.ts +156 -0
- package/src/__tests__/debug.test.ts +222 -0
- package/src/__tests__/doc-examples.test.ts +78 -25
- package/src/__tests__/event-handler-name.test.ts +74 -0
- package/src/__tests__/flatmap-segments.test.ts +11 -9
- package/src/__tests__/format-date-refusal.test.ts +134 -0
- package/src/__tests__/fragment-wrapped-conditional-return-branch.test.ts +132 -0
- package/src/__tests__/hydrate-template.test.ts +9 -1
- package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +2 -2
- package/src/__tests__/issue-3009-loop-branch-ref.test.ts +2 -2
- package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +213 -0
- package/src/__tests__/issue-3113-init-fn-name-collision.test.ts +133 -0
- package/src/__tests__/jsx-return-type-assertion.test.ts +2 -2
- package/src/__tests__/lazy-row-eligibility.test.ts +5 -4
- package/src/__tests__/loop-row-child-children-reactive-attrs.test.ts +108 -0
- package/src/__tests__/loop-row-child-text-children-markers.test.ts +158 -0
- package/src/__tests__/opaque-local-accessor.test.ts +90 -0
- package/src/__tests__/profiler-e2e.test.ts +13 -8
- package/src/__tests__/props-destructuring.test.ts +79 -4
- package/src/__tests__/reactive-factory-arity.test.ts +311 -0
- package/src/__tests__/ref-attr-absent-at-ssr.test.ts +472 -0
- package/src/__tests__/ssr-portal-ref-callback.test.ts +219 -0
- package/src/action-accessor.ts +289 -0
- package/src/adapters/env-signal.ts +2 -21
- package/src/adapters/interface.ts +13 -0
- package/src/adapters/jsx-adapter.ts +17 -0
- package/src/analyzer.ts +589 -60
- package/src/async-action-refusal.ts +254 -0
- package/src/builtin-lowering-plugins.ts +0 -2
- package/src/compiler.ts +27 -0
- package/src/component-root-scope-comment.ts +59 -0
- package/src/debug.ts +318 -103
- package/src/errors.ts +83 -1
- package/src/event-handler-name.ts +14 -0
- package/src/expression-parser.ts +41 -17
- package/src/format-date-refusal.ts +147 -0
- package/src/index.ts +14 -3
- package/src/ir-to-client-js/build-references.ts +6 -2
- package/src/ir-to-client-js/child-components.ts +8 -3
- package/src/ir-to-client-js/collect-elements.ts +28 -13
- package/src/ir-to-client-js/compute-inlinability.ts +2 -1
- package/src/ir-to-client-js/compute-scope.ts +3 -1
- package/src/ir-to-client-js/control-flow/plan/build-branch-loop.ts +2 -4
- package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +67 -5
- package/src/ir-to-client-js/control-flow/plan/build-composite-loop.ts +3 -6
- package/src/ir-to-client-js/control-flow/plan/build-insert.ts +1 -0
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +2 -1
- package/src/ir-to-client-js/control-flow/plan/build-loop.ts +23 -11
- package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -0
- package/src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts +3 -3
- package/src/ir-to-client-js/control-flow/plan/loop.ts +51 -10
- package/src/ir-to-client-js/control-flow/shared.ts +78 -5
- package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +25 -12
- package/src/ir-to-client-js/control-flow/stringify/insert.ts +1 -1
- package/src/ir-to-client-js/csr-substitute.ts +11 -3
- package/src/ir-to-client-js/declaration-sort.ts +7 -3
- package/src/ir-to-client-js/emit-module-level.ts +7 -4
- package/src/ir-to-client-js/emit-reactive.ts +140 -10
- package/src/ir-to-client-js/emit-registration.ts +6 -11
- package/src/ir-to-client-js/generate-init.ts +2 -2
- package/src/ir-to-client-js/html-template.ts +41 -19
- package/src/ir-to-client-js/index.ts +9 -3
- package/src/ir-to-client-js/phases/ref-callbacks.ts +1 -1
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +16 -15
- package/src/ir-to-client-js/plan/declaration-emit.ts +7 -5
- package/src/ir-to-client-js/prop-handling.ts +4 -0
- package/src/ir-to-client-js/reactivity.ts +21 -16
- package/src/ir-to-client-js/source-map.ts +2 -1
- package/src/ir-to-client-js/stringify/declaration-emit.ts +14 -7
- package/src/ir-to-client-js/types.ts +4 -0
- package/src/ir-to-client-js/utils.ts +89 -7
- package/src/jsx-to-ir.ts +772 -50
- package/src/opaque-local-accessor.ts +44 -0
- package/src/rich-type-refusal.ts +1 -1
- package/src/signal-initializer.ts +36 -0
- package/src/template-position-walk.ts +203 -0
- package/src/to-locale-date-lowering.ts +7 -4
- package/src/types.ts +103 -15
- package/dist/format-date-lowering.d.ts +0 -30
- package/dist/format-date-lowering.d.ts.map +0 -1
- package/src/__tests__/create-selector.test.ts +0 -124
- package/src/__tests__/format-date-lowering.test.ts +0 -125
- package/src/format-date-lowering.ts +0 -55
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the shared recognition/gate/seed module (#3166, part B of
|
|
3
|
+
* #3158). `async-action-refusal.ts` (BF117's refusal-lift) and the seed pass
|
|
4
|
+
* (`seedActionAccessorReads`, run from `jsx-to-ir.ts`) both call the same
|
|
5
|
+
* gate, `seedableActionAccessorRead`, so they can never drift apart.
|
|
6
|
+
* Cross-adapter output and end-to-end compiler behaviour are covered by
|
|
7
|
+
* `create-query.test.ts` and the `create-query-action-read` conformance
|
|
8
|
+
* fixture; this file pins the module's own contract in isolation.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, test, expect } from 'bun:test'
|
|
12
|
+
import {
|
|
13
|
+
matchActionAccessorCall,
|
|
14
|
+
actionAccessorSeedParsed,
|
|
15
|
+
actionAccessorSeedText,
|
|
16
|
+
collectActionNames,
|
|
17
|
+
seedableActionAccessorRead,
|
|
18
|
+
ARIA_BOOLEAN_STATE_ATTRS,
|
|
19
|
+
} from '../action-accessor.ts'
|
|
20
|
+
import { parseExpression } from '../expression-parser.ts'
|
|
21
|
+
import type { TemplatePositionRole } from '../template-position-walk.ts'
|
|
22
|
+
import type { SignalInfo } from '../types.ts'
|
|
23
|
+
import { isAriaBooleanAttr as bladeIsAriaBooleanAttr } from '../../../adapter-blade/src/adapter/boolean-result'
|
|
24
|
+
import { isAriaBooleanAttr as erbIsAriaBooleanAttr } from '../../../adapter-erb/src/adapter/boolean-result'
|
|
25
|
+
import { isAriaBooleanAttr as jinjaIsAriaBooleanAttr } from '../../../adapter-jinja/src/adapter/boolean-result'
|
|
26
|
+
import { isAriaBooleanAttr as mojoIsAriaBooleanAttr } from '../../../adapter-mojolicious/src/adapter/boolean-result'
|
|
27
|
+
import { isAriaBooleanAttr as pebbleIsAriaBooleanAttr } from '../../../adapter-pebble/src/adapter/boolean-result'
|
|
28
|
+
import { isAriaBooleanAttr as rustIsAriaBooleanAttr } from '../../../adapter-rust/src/adapter/boolean-result'
|
|
29
|
+
import { isAriaBooleanAttr as twigIsAriaBooleanAttr } from '../../../adapter-twig/src/adapter/boolean-result'
|
|
30
|
+
import { isAriaBooleanAttr as xslateIsAriaBooleanAttr } from '../../../adapter-xslate/src/adapter/boolean-result'
|
|
31
|
+
|
|
32
|
+
function factorySignal(action: string): Pick<SignalInfo, 'factory'> {
|
|
33
|
+
return { factory: { kind: 'query', callee: 'createQuery', argsText: '', requestText: '', requestFreeIdentifiers: new Set(), action } }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('collectActionNames', () => {
|
|
37
|
+
test('collects only signals with a recognised factory action', () => {
|
|
38
|
+
const actions = collectActionNames([factorySignal('fetchPosts'), {}, factorySignal('fetchUsers')])
|
|
39
|
+
expect([...actions].sort()).toEqual(['fetchPosts', 'fetchUsers'])
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('empty for a component with no async factory', () => {
|
|
43
|
+
expect(collectActionNames([{}, {}]).size).toBe(0)
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
describe('matchActionAccessorCall', () => {
|
|
48
|
+
const actions = new Set(['fetchPosts'])
|
|
49
|
+
|
|
50
|
+
test('matches a direct isPending()/error() call on a recognised action', () => {
|
|
51
|
+
expect(matchActionAccessorCall(parseExpression('fetchPosts.isPending()'), actions))
|
|
52
|
+
.toEqual({ action: 'fetchPosts', accessor: 'isPending' })
|
|
53
|
+
expect(matchActionAccessorCall(parseExpression('fetchPosts.error()'), actions))
|
|
54
|
+
.toEqual({ action: 'fetchPosts', accessor: 'error' })
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('rejects an unrecognised object, even with the same accessor name', () => {
|
|
58
|
+
expect(matchActionAccessorCall(parseExpression('otherThing.isPending()'), actions)).toBeNull()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('rejects an accessor name the action does not carry', () => {
|
|
62
|
+
expect(matchActionAccessorCall(parseExpression('fetchPosts.refetch()'), actions)).toBeNull()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('rejects a call with arguments — the real accessors take none', () => {
|
|
66
|
+
expect(matchActionAccessorCall(parseExpression('fetchPosts.isPending(true)'), actions)).toBeNull()
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test('rejects the uncalled member access — only the CALL is a seeded value', () => {
|
|
70
|
+
expect(matchActionAccessorCall(parseExpression('fetchPosts.isPending'), actions)).toBeNull()
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('rejects a computed member access', () => {
|
|
74
|
+
expect(matchActionAccessorCall(parseExpression("fetchPosts['isPending']()"), actions)).toBeNull()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('rejects a compound expression — only the WHOLE expression matches', () => {
|
|
78
|
+
expect(matchActionAccessorCall(parseExpression('!fetchPosts.isPending()'), actions)).toBeNull()
|
|
79
|
+
expect(matchActionAccessorCall(parseExpression('fetchPosts.isPending() && x'), actions)).toBeNull()
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('empty actions set matches nothing', () => {
|
|
83
|
+
expect(matchActionAccessorCall(parseExpression('fetchPosts.isPending()'), new Set())).toBeNull()
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe('seeds (spec/async.md §7.3)', () => {
|
|
88
|
+
test('actionAccessorSeedParsed is the boolean literal false for both accessors', () => {
|
|
89
|
+
expect(actionAccessorSeedParsed('isPending')).toEqual({ kind: 'literal', value: false, literalType: 'boolean' })
|
|
90
|
+
expect(actionAccessorSeedParsed('error')).toEqual({ kind: 'literal', value: false, literalType: 'boolean' })
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('actionAccessorSeedText is JS source text: false / undefined', () => {
|
|
94
|
+
expect(actionAccessorSeedText('isPending')).toBe('false')
|
|
95
|
+
expect(actionAccessorSeedText('error')).toBe('undefined')
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
describe('seedableActionAccessorRead — the one gate for the BF117 lift and the seed', () => {
|
|
100
|
+
const actions = new Set(['fetchPosts'])
|
|
101
|
+
const at = (source: string, role: TemplatePositionRole, attrName?: string) =>
|
|
102
|
+
seedableActionAccessorRead({ expr: parseExpression(source), role, attrName }, actions)
|
|
103
|
+
|
|
104
|
+
test('a condition admits both accessors (truthiness only: false ≡ undefined)', () => {
|
|
105
|
+
expect(at('fetchPosts.isPending()', 'condition')).toEqual({ action: 'fetchPosts', accessor: 'isPending' })
|
|
106
|
+
expect(at('fetchPosts.error()', 'condition')).toEqual({ action: 'fetchPosts', accessor: 'error' })
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('an ARIA boolean-state element attribute admits isPending() only', () => {
|
|
110
|
+
expect(at('fetchPosts.isPending()', 'element-attr', 'aria-busy')).toEqual({ action: 'fetchPosts', accessor: 'isPending' })
|
|
111
|
+
expect(at('fetchPosts.isPending()', 'element-attr', 'aria-hidden')).not.toBeNull()
|
|
112
|
+
// Hono omits an `undefined` attribute; the `false` seed would render it.
|
|
113
|
+
expect(at('fetchPosts.error()', 'element-attr', 'aria-busy')).toBeNull()
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test('an HTML boolean attribute admits isPending() only (#3210)', () => {
|
|
117
|
+
expect(at('fetchPosts.isPending()', 'element-attr', 'disabled')).toEqual({ action: 'fetchPosts', accessor: 'isPending' })
|
|
118
|
+
expect(at('fetchPosts.isPending()', 'element-attr', 'readonly')).not.toBeNull()
|
|
119
|
+
// Only truthiness is observed here, so `error()` would render the same,
|
|
120
|
+
// but it is not a boolean and no fixture covers it: the gate admits only
|
|
121
|
+
// what the conformance corpus pins.
|
|
122
|
+
expect(at('fetchPosts.error()', 'element-attr', 'disabled')).toBeNull()
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
test('any other attribute refuses — Mojolicious / Xslate render the false literal as 0 there', () => {
|
|
126
|
+
expect(at('fetchPosts.isPending()', 'element-attr', 'aria-label')).toBeNull()
|
|
127
|
+
expect(at('fetchPosts.isPending()', 'element-attr', 'title')).toBeNull()
|
|
128
|
+
expect(at('fetchPosts.isPending()', 'element-attr', 'data-pending')).toBeNull()
|
|
129
|
+
expect(at('fetchPosts.error()', 'element-attr', 'title')).toBeNull()
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('text, prop, spread, template-part and loop-array positions refuse', () => {
|
|
133
|
+
for (const role of ['text', 'prop', 'spread', 'template-part', 'loop-array'] as const) {
|
|
134
|
+
expect(at('fetchPosts.isPending()', role, role === 'prop' ? 'aria-busy' : undefined)).toBeNull()
|
|
135
|
+
expect(at('fetchPosts.error()', role)).toBeNull()
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
test('an unrecognised or compound read is never admitted, whatever the position', () => {
|
|
140
|
+
expect(at('other.isPending()', 'condition')).toBeNull()
|
|
141
|
+
expect(at('!fetchPosts.isPending()', 'condition')).toBeNull()
|
|
142
|
+
expect(at('other.isPending()', 'element-attr', 'aria-busy')).toBeNull()
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
describe('ARIA_BOOLEAN_STATE_ATTRS agrees with every DSL adapter', () => {
|
|
147
|
+
// The seed renders `aria-x={false}` as `aria-x="false"` (Hono's output) only
|
|
148
|
+
// where the adapter stringifies a boolean JS-style; outside its own
|
|
149
|
+
// `isAriaBooleanAttr` set, Mojolicious / Xslate render the literal as `0`.
|
|
150
|
+
// Go renders `{{false}}` as `false` on every attribute, so it has no set.
|
|
151
|
+
const adapters: Array<[string, (name: string) => boolean]> = [
|
|
152
|
+
['blade', bladeIsAriaBooleanAttr],
|
|
153
|
+
['erb', erbIsAriaBooleanAttr],
|
|
154
|
+
['jinja', jinjaIsAriaBooleanAttr],
|
|
155
|
+
['mojolicious', mojoIsAriaBooleanAttr],
|
|
156
|
+
['pebble', pebbleIsAriaBooleanAttr],
|
|
157
|
+
['rust', rustIsAriaBooleanAttr],
|
|
158
|
+
['twig', twigIsAriaBooleanAttr],
|
|
159
|
+
['xslate', xslateIsAriaBooleanAttr],
|
|
160
|
+
]
|
|
161
|
+
for (const [adapter, isAriaBooleanAttr] of adapters) {
|
|
162
|
+
test(`${adapter} stringifies every gated attribute as a boolean`, () => {
|
|
163
|
+
expect([...ARIA_BOOLEAN_STATE_ATTRS].filter((name) => !isAriaBooleanAttr(name))).toEqual([])
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
})
|
|
@@ -120,7 +120,7 @@ const ALLOWLIST: Record<string, Partial<Record<Pattern, number>>> = {
|
|
|
120
120
|
// for a follow-up rather than fixed speculatively here.
|
|
121
121
|
'packages/adapter-go-template/src/adapter/expr/helper-inline.ts': { 'localConstants.find(': 1 },
|
|
122
122
|
'packages/adapter-go-template/src/adapter/go-template-adapter.ts': {
|
|
123
|
-
// FLOOR: of the
|
|
123
|
+
// FLOOR: of the 6 `.find(` sites — `resolveDynamicPropValue` (child-prop
|
|
124
124
|
// passthrough, called only from `generateNewPropsFunction`'s
|
|
125
125
|
// `emitStaticChildInstances`), `computeDerivedConstFields` and
|
|
126
126
|
// `isStringExpr` (same `generateNewPropsFunction` constructor-context
|
|
@@ -132,17 +132,28 @@ const ALLOWLIST: Record<string, Partial<Record<Pattern, number>>> = {
|
|
|
132
132
|
// Stage 4 (a real gap: an enclosing loop's own item param could shadow
|
|
133
133
|
// a same-named module const and misfire a BF101) — MIGRATED in place,
|
|
134
134
|
// the `.find(` call itself stays as the legitimate lookup once shadow
|
|
135
|
-
// is ruled out.
|
|
136
|
-
|
|
135
|
+
// is ruled out. The 6th (#3164) is `resolveLoopArraySourceConst`'s own
|
|
136
|
+
// `.find(` — it REPLACES an ad-hoc `.find()` that `emitStaticBodyWrappers`
|
|
137
|
+
// used to inline directly (module-scope-only, and with no shadow guard
|
|
138
|
+
// at all), routing it through the same shape-1 shadow-name check as
|
|
139
|
+
// `getBakedStaticChildLoop` below instead — a consolidation onto the
|
|
140
|
+
// existing floor bucket, not a new unguarded use.
|
|
141
|
+
'localConstants.find(': 6,
|
|
137
142
|
// #2482 Stage 3: `loopParamStack` eliminated entirely (0, down from 35)
|
|
138
143
|
// — replaced by the threaded `this.scope: BindingScope`. The remaining
|
|
139
|
-
//
|
|
140
|
-
// `getBakedStaticChildLoop` shadow guard
|
|
141
|
-
//
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
|
|
144
|
+
// 3 `staticLoopSourceBoundNames` uses (down from 3, then #3164 added a
|
|
145
|
+
// third) are the `getBakedStaticChildLoop` shadow guard PLUS (#3164)
|
|
146
|
+
// `resolveLoopArraySourceConst`'s own guard, shared across call sites
|
|
147
|
+
// OUTSIDE the live `renderLoop` tree walk as well as inside it (no live
|
|
148
|
+
// `scope` to consult in the `emitStaticBodyWrappers` prepass — shape 1;
|
|
149
|
+
// reused as-is, rather than threaded, at the one live-walk call site
|
|
150
|
+
// for the same reason `getBakedStaticChildLoop` already is: the coarser
|
|
151
|
+
// whole-component check only ever over-excludes, never silently wrong,
|
|
152
|
+
// per this ledger's shape-1 rule) — a genuinely-legitimate surviving
|
|
153
|
+
// use, confirmed FLOOR in Stage 4 (`primeCompileState`'s own comment
|
|
154
|
+
// documents the three-call-site agreement requirement) and extended by
|
|
155
|
+
// one more call site in #3164.
|
|
156
|
+
staticLoopSourceBoundNames: 3,
|
|
146
157
|
},
|
|
147
158
|
// FLOOR (shape 1 for the field; the doc-only `loopParamStack` mention this
|
|
148
159
|
// file's top-level comment used to carry was reworded in Stage 4 — that
|
|
@@ -118,7 +118,7 @@ describe('branch-local references inside raw-captured JS (#1414 follow-ups)', ()
|
|
|
118
118
|
const [count] = createSignal(0)
|
|
119
119
|
if (props.kind === 'a') {
|
|
120
120
|
const label = 'highlighted'
|
|
121
|
-
return <div ref={(el) => { el.dataset.flag = label }}>A: {count()}</div>
|
|
121
|
+
return <div ref={(el) => { el.dataset.flag = label }} data-flag="highlighted">A: {count()}</div>
|
|
122
122
|
}
|
|
123
123
|
return <div>B: {count()}</div>
|
|
124
124
|
}
|
|
@@ -43,13 +43,13 @@ describe('same-name branch-local const referenced from nested function decl (#14
|
|
|
43
43
|
function attachA(el: HTMLElement) {
|
|
44
44
|
el.dataset.size = size
|
|
45
45
|
}
|
|
46
|
-
return <div ref={attachA}>A</div>
|
|
46
|
+
return <div ref={attachA} data-size="small">A</div>
|
|
47
47
|
}
|
|
48
48
|
const size = 'large'
|
|
49
49
|
function attachB(el: HTMLElement) {
|
|
50
50
|
el.dataset.size = size
|
|
51
51
|
}
|
|
52
|
-
return <div ref={attachB}>B</div>
|
|
52
|
+
return <div ref={attachB} data-size="large">B</div>
|
|
53
53
|
}
|
|
54
54
|
`
|
|
55
55
|
const result = compileJSX(source, 'TwoBranches.tsx', { adapter })
|
|
@@ -82,20 +82,20 @@ describe('same-name branch-local const referenced from nested function decl (#14
|
|
|
82
82
|
function attachA(el: HTMLElement) {
|
|
83
83
|
el.dataset.size = size
|
|
84
84
|
}
|
|
85
|
-
return <div ref={attachA}>A</div>
|
|
85
|
+
return <div ref={attachA} data-size="small">A</div>
|
|
86
86
|
}
|
|
87
87
|
if (props.mode === 'b') {
|
|
88
88
|
const size = 'medium'
|
|
89
89
|
function attachB(el: HTMLElement) {
|
|
90
90
|
el.dataset.size = size
|
|
91
91
|
}
|
|
92
|
-
return <div ref={attachB}>B</div>
|
|
92
|
+
return <div ref={attachB} data-size="medium">B</div>
|
|
93
93
|
}
|
|
94
94
|
const size = 'large'
|
|
95
95
|
function attachC(el: HTMLElement) {
|
|
96
96
|
el.dataset.size = size
|
|
97
97
|
}
|
|
98
|
-
return <div ref={attachC}>C</div>
|
|
98
|
+
return <div ref={attachC} data-size="large">C</div>
|
|
99
99
|
}
|
|
100
100
|
`
|
|
101
101
|
const result = compileJSX(source, 'ThreeBranches.tsx', { adapter })
|
|
@@ -129,20 +129,20 @@ describe('same-name branch-local const referenced from nested function decl (#14
|
|
|
129
129
|
function attachA(el: HTMLElement) {
|
|
130
130
|
el.dataset.value = String(value)
|
|
131
131
|
}
|
|
132
|
-
return <div ref={attachA}>A</div>
|
|
132
|
+
return <div ref={attachA} data-value="string-value">A</div>
|
|
133
133
|
}
|
|
134
134
|
if (props.mode === 'b') {
|
|
135
135
|
const value = 42
|
|
136
136
|
function attachB(el: HTMLElement) {
|
|
137
137
|
el.dataset.value = String(value)
|
|
138
138
|
}
|
|
139
|
-
return <div ref={attachB}>B</div>
|
|
139
|
+
return <div ref={attachB} data-value="42">B</div>
|
|
140
140
|
}
|
|
141
141
|
const value = true
|
|
142
142
|
function attachC(el: HTMLElement) {
|
|
143
143
|
el.dataset.value = String(value)
|
|
144
144
|
}
|
|
145
|
-
return <div ref={attachC}>C</div>
|
|
145
|
+
return <div ref={attachC} data-value="true">C</div>
|
|
146
146
|
}
|
|
147
147
|
`
|
|
148
148
|
const result = compileJSX(source, 'MixedKinds.tsx', { adapter })
|
|
@@ -244,7 +244,7 @@ describe('same-name branch-local const referenced from nested function decl (#14
|
|
|
244
244
|
function attach(el: HTMLElement) {
|
|
245
245
|
el.dataset.value = String(b)
|
|
246
246
|
}
|
|
247
|
-
return <div ref={attach}>A</div>
|
|
247
|
+
return <div ref={attach} data-value="2">A</div>
|
|
248
248
|
}
|
|
249
249
|
return <div>B</div>
|
|
250
250
|
}
|
|
@@ -1286,6 +1286,57 @@ describe('Client JS generation', () => {
|
|
|
1286
1286
|
expect(clientJs!.content).not.toContain("setAttribute('disabled'")
|
|
1287
1287
|
})
|
|
1288
1288
|
|
|
1289
|
+
// #3065 (accordion/radio-group): a boolean-IDL-named prop like `open`
|
|
1290
|
+
// is only a REAL property on the elements that natively expose it
|
|
1291
|
+
// (`<details>`, `<dialog>`) — most child components receiving it are
|
|
1292
|
+
// plain elements (a `<div>`, here) that merely happen to accept a
|
|
1293
|
+
// prop sharing that name for their OWN unrelated purposes. Before this
|
|
1294
|
+
// fix the mirror wrote `target.open = …` unconditionally (unlike the
|
|
1295
|
+
// `presenceOrUndefined`/generic branches, which already seed-gate on
|
|
1296
|
+
// `hasAttribute`), planting a live DOM property SSR never had and
|
|
1297
|
+
// that `captureDomState`'s STATE_PROPS check (`open` is one of the
|
|
1298
|
+
// properties it diffs) then saw appear only after hydration —
|
|
1299
|
+
// discovered via the accordion oracle once its OWN aria-expanded/
|
|
1300
|
+
// data-state divergence (the actual target of #3065) was fixed.
|
|
1301
|
+
test('mirrors a child component `open` prop gated on hasAttribute, not unconditionally (#3065)', () => {
|
|
1302
|
+
const source = `
|
|
1303
|
+
'use client'
|
|
1304
|
+
import { createSignal } from '@barefootjs/client'
|
|
1305
|
+
import { Section } from './Section'
|
|
1306
|
+
|
|
1307
|
+
export function Accordion() {
|
|
1308
|
+
const [expanded, setExpanded] = createSignal(false)
|
|
1309
|
+
return (
|
|
1310
|
+
<div>
|
|
1311
|
+
<Section open={expanded()} />
|
|
1312
|
+
</div>
|
|
1313
|
+
)
|
|
1314
|
+
}
|
|
1315
|
+
`
|
|
1316
|
+
|
|
1317
|
+
const result = compileJSX(source, 'Accordion.tsx', { adapter })
|
|
1318
|
+
expect(result.errors).toHaveLength(0)
|
|
1319
|
+
|
|
1320
|
+
const clientJs = result.files.find(f => f.type === 'clientJs')
|
|
1321
|
+
expect(clientJs).toBeDefined()
|
|
1322
|
+
expect(clientJs!.content).toContain(".hasAttribute('open')")
|
|
1323
|
+
expect(clientJs!.content).toContain('.open = !!')
|
|
1324
|
+
// A bare `open={signal()}` reaches BOTH the named-prop-binding mirror
|
|
1325
|
+
// (`emitReactivePropBindings`, ctx.reactiveProps) and the child-prop
|
|
1326
|
+
// mirror (`emitReactiveChildProps`, ctx.reactiveChildProps) for the
|
|
1327
|
+
// same slot — a regression in EITHER path's gate would still leave
|
|
1328
|
+
// the OTHER path's gated write in the output, so asserting presence
|
|
1329
|
+
// of a gated write alone can't catch one path regressing back to
|
|
1330
|
+
// unconditional. Each gated write is emitted on its own single line
|
|
1331
|
+
// (`emitAttrUpdate`'s mirrorSeed branch), so require every line that
|
|
1332
|
+
// writes `.open = !!` to also carry its `hasAttribute('open')` gate.
|
|
1333
|
+
const openWriteLines = clientJs!.content.split('\n').filter((line) => line.includes('.open = !!'))
|
|
1334
|
+
expect(openWriteLines.length).toBeGreaterThan(0)
|
|
1335
|
+
for (const line of openWriteLines) {
|
|
1336
|
+
expect(line).toContain("hasAttribute('open')")
|
|
1337
|
+
}
|
|
1338
|
+
})
|
|
1339
|
+
|
|
1289
1340
|
// #2716: a `value` prop passed to a CHILD COMPONENT (above) drives the
|
|
1290
1341
|
// no-SSR-fallback mirror path; a `value` ATTRIBUTE the developer writes
|
|
1291
1342
|
// directly on a plain HOST element is the opposite case — SSR renders
|
|
@@ -1314,6 +1365,68 @@ describe('Client JS generation', () => {
|
|
|
1314
1365
|
expect(clientJs!.content).toContain('.value =')
|
|
1315
1366
|
expect(clientJs!.content).toContain("setAttribute('value'")
|
|
1316
1367
|
})
|
|
1368
|
+
|
|
1369
|
+
// #3066: a controlled <select> whose value matches no <option> falls
|
|
1370
|
+
// back to selectedIndex 0 (the #2852 SSR placeholder) instead of
|
|
1371
|
+
// leaving the browser's own out-of-range resolution (selectedIndex -1)
|
|
1372
|
+
// as the live post-hydration state, which SSR never rendered.
|
|
1373
|
+
test('a controlled <select> value falls back to selectedIndex 0 on no match (#3066)', () => {
|
|
1374
|
+
const source = `
|
|
1375
|
+
'use client'
|
|
1376
|
+
import { createSignal } from '@barefootjs/client'
|
|
1377
|
+
|
|
1378
|
+
export function OutOfRangeSelect() {
|
|
1379
|
+
const [val] = createSignal(7)
|
|
1380
|
+
return (
|
|
1381
|
+
<select value={String(val())}>
|
|
1382
|
+
<option value="0">Zero</option>
|
|
1383
|
+
<option value="1">One</option>
|
|
1384
|
+
</select>
|
|
1385
|
+
)
|
|
1386
|
+
}
|
|
1387
|
+
`
|
|
1388
|
+
|
|
1389
|
+
const result = compileJSX(source, 'OutOfRangeSelect.tsx', { adapter })
|
|
1390
|
+
expect(result.errors).toHaveLength(0)
|
|
1391
|
+
|
|
1392
|
+
const clientJs = result.files.find(f => f.type === 'clientJs')
|
|
1393
|
+
expect(clientJs).toBeDefined()
|
|
1394
|
+
expect(clientJs!.content).toContain("tagName === 'SELECT'")
|
|
1395
|
+
expect(clientJs!.content).toContain('!')
|
|
1396
|
+
expect(clientJs!.content).toContain('.multiple')
|
|
1397
|
+
expect(clientJs!.content).toContain('.size <= 1')
|
|
1398
|
+
expect(clientJs!.content).toContain('.selectedIndex = 0')
|
|
1399
|
+
})
|
|
1400
|
+
|
|
1401
|
+
// A list box is `multiple` OR a `size` > 1 (`jsx-to-ir.ts`'s
|
|
1402
|
+
// `isMultiSelection`, which the SSR placeholder decision already keys
|
|
1403
|
+
// off) — checking `.multiple` alone here would force `selectedIndex =
|
|
1404
|
+
// 0` on a bare `size={2}` select whose SSR leg (correctly, per
|
|
1405
|
+
// `isMultiSelection`) left nothing selected on an out-of-range value,
|
|
1406
|
+
// reintroducing exactly the divergence #3066 fixed for `multiple`.
|
|
1407
|
+
test('does not force selectedIndex 0 on an out-of-range size>1 (list box) select (#3066)', () => {
|
|
1408
|
+
const source = `
|
|
1409
|
+
'use client'
|
|
1410
|
+
import { createSignal } from '@barefootjs/client'
|
|
1411
|
+
|
|
1412
|
+
export function OutOfRangeListBox() {
|
|
1413
|
+
const [val] = createSignal(7)
|
|
1414
|
+
return (
|
|
1415
|
+
<select size={2} value={String(val())}>
|
|
1416
|
+
<option value="0">Zero</option>
|
|
1417
|
+
<option value="1">One</option>
|
|
1418
|
+
</select>
|
|
1419
|
+
)
|
|
1420
|
+
}
|
|
1421
|
+
`
|
|
1422
|
+
|
|
1423
|
+
const result = compileJSX(source, 'OutOfRangeListBox.tsx', { adapter })
|
|
1424
|
+
expect(result.errors).toHaveLength(0)
|
|
1425
|
+
|
|
1426
|
+
const clientJs = result.files.find(f => f.type === 'clientJs')
|
|
1427
|
+
expect(clientJs).toBeDefined()
|
|
1428
|
+
expect(clientJs!.content).toContain('.size <= 1')
|
|
1429
|
+
})
|
|
1317
1430
|
})
|
|
1318
1431
|
|
|
1319
1432
|
describe('comment scope flag for fragment roots (#381)', () => {
|
|
@@ -2613,6 +2726,68 @@ describe('Client JS generation', () => {
|
|
|
2613
2726
|
// Should have initChild with props in the bindEvents callback
|
|
2614
2727
|
expect(content).toMatch(/initChild\('Alert'/)
|
|
2615
2728
|
})
|
|
2729
|
+
|
|
2730
|
+
test('a branch-owned child is initialized only by the branch, and still imported', () => {
|
|
2731
|
+
// The branch is active at hydration: `insert()`'s first run adopts
|
|
2732
|
+
// (or re-renders) it and its bindEvents inits the child. A second,
|
|
2733
|
+
// static `initChild` on the `$c` handle would init the same child a
|
|
2734
|
+
// second time — on a node the branch may already have replaced — so
|
|
2735
|
+
// its onMount/effects would run in two instances.
|
|
2736
|
+
const source = `
|
|
2737
|
+
'use client'
|
|
2738
|
+
import { createSignal } from '@barefootjs/client'
|
|
2739
|
+
import { Spinner } from './spinner'
|
|
2740
|
+
|
|
2741
|
+
export function Parent() {
|
|
2742
|
+
const [show, setShow] = createSignal(true)
|
|
2743
|
+
return (
|
|
2744
|
+
<div>
|
|
2745
|
+
<button onClick={() => setShow(!show())}>Toggle</button>
|
|
2746
|
+
{show() && <Spinner />}
|
|
2747
|
+
</div>
|
|
2748
|
+
)
|
|
2749
|
+
}
|
|
2750
|
+
`
|
|
2751
|
+
|
|
2752
|
+
const result = compileJSX(source, 'Parent.tsx', { adapter })
|
|
2753
|
+
expect(result.errors).toHaveLength(0)
|
|
2754
|
+
const content = result.files.find(f => f.type === 'clientJs')!.content
|
|
2755
|
+
|
|
2756
|
+
expect(content.match(/initChild\('Spinner'/g)).toHaveLength(1)
|
|
2757
|
+
expect(content).toMatch(/bindEvents:.*\n[\s\S]*?initChild\('Spinner'/)
|
|
2758
|
+
expect(content).not.toContain('$c(__scope')
|
|
2759
|
+
// The bundler still needs the child's module: the import marker is
|
|
2760
|
+
// collected from the branch, not from the (now absent) static init.
|
|
2761
|
+
expect(content).toContain("import '/* @bf-child:Spinner */'")
|
|
2762
|
+
})
|
|
2763
|
+
|
|
2764
|
+
test('a client-only branch-owned child is initialized only by the branch', () => {
|
|
2765
|
+
// Same ownership rule on the `/* @client */` path, which records its
|
|
2766
|
+
// conditional through `clientOnlyConditionals` instead.
|
|
2767
|
+
const source = `
|
|
2768
|
+
'use client'
|
|
2769
|
+
import { createSignal } from '@barefootjs/client'
|
|
2770
|
+
import { Spinner } from './spinner'
|
|
2771
|
+
|
|
2772
|
+
export function Parent() {
|
|
2773
|
+
const [show, setShow] = createSignal(true)
|
|
2774
|
+
return (
|
|
2775
|
+
<div>
|
|
2776
|
+
<button onClick={() => setShow(!show())}>Toggle</button>
|
|
2777
|
+
{/* @client */ show() && <Spinner />}
|
|
2778
|
+
</div>
|
|
2779
|
+
)
|
|
2780
|
+
}
|
|
2781
|
+
`
|
|
2782
|
+
|
|
2783
|
+
const result = compileJSX(source, 'Parent.tsx', { adapter })
|
|
2784
|
+
expect(result.errors).toHaveLength(0)
|
|
2785
|
+
const content = result.files.find(f => f.type === 'clientJs')!.content
|
|
2786
|
+
|
|
2787
|
+
expect(content.match(/initChild\('Spinner'/g)).toHaveLength(1)
|
|
2788
|
+
expect(content).not.toContain('$c(__scope')
|
|
2789
|
+
expect(content).toContain("import '/* @bf-child:Spinner */'")
|
|
2790
|
+
})
|
|
2616
2791
|
})
|
|
2617
2792
|
|
|
2618
2793
|
describe('reactive props.xxx detection (#789)', () => {
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `decideComponentRootScopeComment` (#3141) — the shared flag every
|
|
3
|
+
* adapter's `IRNodeEmitter.emitComponent` reads instead of re-deriving
|
|
4
|
+
* "is this component root client-interactive" locally.
|
|
5
|
+
*
|
|
6
|
+
* Runs through `compileJSX` — the SAME entry point `@barefootjs/vite`'s
|
|
7
|
+
* plugin and the CLI call in production (`packages/vite/src/plugin.ts`,
|
|
8
|
+
* `packages/cli/src/lib/preview/compile.ts`) — rather than calling
|
|
9
|
+
* `jsxToIR`/`buildMetadata` directly, with `outputIR: true` to inspect the
|
|
10
|
+
* exact `ComponentIR` the adapter itself renders from. This exercises the
|
|
11
|
+
* real ordering guarantee the fix depends on: `decideComponentRootScopeComment`
|
|
12
|
+
* must run AFTER `metadata.clientAnalysis` is computed and BEFORE
|
|
13
|
+
* `adapter.generate` reads `ir.root`, on the multi-component path
|
|
14
|
+
* (`compileMultipleComponents`) this fixture's two-component file — `Kid` +
|
|
15
|
+
* the exported root — takes, not the single-component one.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { describe, test, expect } from 'bun:test'
|
|
19
|
+
import { compileJSX } from '../compiler.ts'
|
|
20
|
+
import { TestAdapter } from '../adapters/test-adapter.ts'
|
|
21
|
+
import type { ComponentIR, IRComponent } from '../types.ts'
|
|
22
|
+
|
|
23
|
+
function irFor(source: string, filePath: string, componentName: string): ComponentIR {
|
|
24
|
+
const result = compileJSX(source, filePath, { adapter: new TestAdapter(), outputIR: true })
|
|
25
|
+
expect(result.errors).toEqual([])
|
|
26
|
+
const irFile = result.files.find(
|
|
27
|
+
(f) => f.type === 'ir' && f.path.includes(`.${componentName}.ir.json`),
|
|
28
|
+
) ?? result.files.find((f) => f.type === 'ir')
|
|
29
|
+
expect(irFile).toBeDefined()
|
|
30
|
+
return JSON.parse(irFile!.content) as ComponentIR
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('decideComponentRootScopeComment', () => {
|
|
34
|
+
test('flags a client component whose root is a bare child-component call', () => {
|
|
35
|
+
const ir = irFor(
|
|
36
|
+
`
|
|
37
|
+
'use client'
|
|
38
|
+
import { createSignal } from '@barefootjs/client'
|
|
39
|
+
|
|
40
|
+
function Kid({ label, children }: { label: string; children?: unknown }) {
|
|
41
|
+
return (
|
|
42
|
+
<div>
|
|
43
|
+
<p>{label}</p>
|
|
44
|
+
{children}
|
|
45
|
+
</div>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function ComponentRootClientScope({ label }: { label: string }) {
|
|
50
|
+
const [text, setText] = createSignal(label)
|
|
51
|
+
return (
|
|
52
|
+
<Kid label={text()}>
|
|
53
|
+
<button onClick={() => setText('loaded')}>load</button>
|
|
54
|
+
</Kid>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
`,
|
|
58
|
+
'ComponentRootClientScope.tsx',
|
|
59
|
+
'ComponentRootClientScope',
|
|
60
|
+
)
|
|
61
|
+
expect(ir.root.type).toBe('component')
|
|
62
|
+
expect((ir.root as IRComponent).needsScopeComment).toBe(true)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('also flags a non-"use client" component whose root is a bare child-component call', () => {
|
|
66
|
+
// No `'use client'` directive and no signals here — but ANY nested
|
|
67
|
+
// component reference forces `clientAnalysis.needsInit` regardless
|
|
68
|
+
// (`childInits.length > 0` in `needsClientJs`, `ir-to-client-js/index.ts`):
|
|
69
|
+
// the parent always needs an init call to register/mount its child. So
|
|
70
|
+
// `hasClientInteractivity` (this function's formula, matching Hono's
|
|
71
|
+
// existing one) is true for EVERY `root.type === 'component'` shape,
|
|
72
|
+
// not only explicit `'use client'` ones — this pins that down rather
|
|
73
|
+
// than assuming the registry entry's `'use client'`-only `given` clause
|
|
74
|
+
// is the actual gate.
|
|
75
|
+
const ir = irFor(
|
|
76
|
+
`
|
|
77
|
+
function Kid({ label }: { label: string }) {
|
|
78
|
+
return <div>{label}</div>
|
|
79
|
+
}
|
|
80
|
+
export function StaticWrapper({ label }: { label: string }) {
|
|
81
|
+
return <Kid label={label} />
|
|
82
|
+
}
|
|
83
|
+
`,
|
|
84
|
+
'StaticWrapper.tsx',
|
|
85
|
+
'StaticWrapper',
|
|
86
|
+
)
|
|
87
|
+
expect(ir.root.type).toBe('component')
|
|
88
|
+
expect((ir.root as IRComponent).needsScopeComment).toBe(true)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test('leaves a client component with a wrapping element root unflagged (nothing to change there)', () => {
|
|
92
|
+
const ir = irFor(
|
|
93
|
+
`
|
|
94
|
+
'use client'
|
|
95
|
+
import { createSignal } from '@barefootjs/client'
|
|
96
|
+
export function Wrapped({ label }: { label: string }) {
|
|
97
|
+
const [text] = createSignal(label)
|
|
98
|
+
return <div>{text()}</div>
|
|
99
|
+
}
|
|
100
|
+
`,
|
|
101
|
+
'Wrapped.tsx',
|
|
102
|
+
'Wrapped',
|
|
103
|
+
)
|
|
104
|
+
expect(ir.root.type).toBe('element')
|
|
105
|
+
})
|
|
106
|
+
})
|