@barefootjs/jsx 0.39.1 → 0.39.3

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.
Files changed (72) hide show
  1. package/dist/adapters/line-statement-text.d.ts +17 -0
  2. package/dist/adapters/line-statement-text.d.ts.map +1 -0
  3. package/dist/adapters/parsed-expr-emitter.d.ts +2 -2
  4. package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
  5. package/dist/analyzer.d.ts +1 -0
  6. package/dist/analyzer.d.ts.map +1 -1
  7. package/dist/augment-inherited-props.d.ts +20 -0
  8. package/dist/augment-inherited-props.d.ts.map +1 -1
  9. package/dist/html-types.d.ts +15 -0
  10. package/dist/html-types.d.ts.map +1 -1
  11. package/dist/index.d.ts +6 -2
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +1527 -1169
  14. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  15. package/dist/ir-to-client-js/safe-html.d.ts +1 -1
  16. package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
  17. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  18. package/dist/jsx-to-ir.d.ts.map +1 -1
  19. package/dist/literal-member-index.d.ts +6 -0
  20. package/dist/literal-member-index.d.ts.map +1 -0
  21. package/dist/nullable-signal-attr.d.ts +73 -0
  22. package/dist/nullable-signal-attr.d.ts.map +1 -0
  23. package/dist/scope/binding-scope.d.ts +11 -0
  24. package/dist/scope/binding-scope.d.ts.map +1 -1
  25. package/dist/scope/root-prop-alias.d.ts +43 -0
  26. package/dist/scope/root-prop-alias.d.ts.map +1 -0
  27. package/dist/signal-prop-name-collision.d.ts +20 -0
  28. package/dist/signal-prop-name-collision.d.ts.map +1 -0
  29. package/dist/ssr-defaults.d.ts.map +1 -1
  30. package/dist/ssr-seed-plan.d.ts +3 -2
  31. package/dist/ssr-seed-plan.d.ts.map +1 -1
  32. package/package.json +2 -2
  33. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +3 -3
  34. package/src/__tests__/attribute-fallback-wrap.test.ts +24 -0
  35. package/src/__tests__/binding-scope.test.ts +27 -0
  36. package/src/__tests__/client-template-escape-soundness.test.ts +17 -0
  37. package/src/__tests__/compiler-stress-1244.test.ts +10 -13
  38. package/src/__tests__/conditional-fallback-wrap.test.ts +20 -0
  39. package/src/__tests__/conditional-nested-loop-bindings.test.ts +41 -0
  40. package/src/__tests__/destructured-from-props-localconst-value.test.ts +3 -2
  41. package/src/__tests__/html-event-handler-names.test.ts +107 -0
  42. package/src/__tests__/line-statement-text.test.ts +25 -0
  43. package/src/__tests__/literal-member-index.test.ts +14 -0
  44. package/src/__tests__/lookup-literal-const.test.ts +46 -0
  45. package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +66 -19
  46. package/src/__tests__/nullable-signal-attr.test.ts +124 -0
  47. package/src/__tests__/profile-binding-ids.test.ts +102 -0
  48. package/src/__tests__/root-prop-alias.test.ts +62 -0
  49. package/src/__tests__/signal-prop-name-collision.test.ts +171 -0
  50. package/src/__tests__/ssr-defaults.test.ts +6 -7
  51. package/src/__tests__/ssr-seed-plan.test.ts +23 -0
  52. package/src/__tests__/staged-ir/02-shadow-guards.test.ts +1 -1
  53. package/src/__tests__/staged-ir/08-relocate-unit.test.ts +6 -3
  54. package/src/adapters/line-statement-text.ts +24 -0
  55. package/src/adapters/parsed-expr-emitter.ts +3 -3
  56. package/src/analyzer.ts +60 -26
  57. package/src/augment-inherited-props.ts +49 -0
  58. package/src/html-types.ts +15 -0
  59. package/src/index.ts +14 -2
  60. package/src/ir-to-client-js/collect-elements.ts +15 -10
  61. package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +2 -2
  62. package/src/ir-to-client-js/safe-html.ts +19 -6
  63. package/src/ir-to-client-js/stringify/declaration-emit.ts +5 -5
  64. package/src/ir-to-client-js/utils.ts +88 -117
  65. package/src/jsx-to-ir.ts +21 -2
  66. package/src/literal-member-index.ts +12 -0
  67. package/src/nullable-signal-attr.ts +156 -0
  68. package/src/scope/binding-scope.ts +31 -1
  69. package/src/scope/root-prop-alias.ts +81 -0
  70. package/src/signal-prop-name-collision.ts +164 -0
  71. package/src/ssr-defaults.ts +3 -5
  72. package/src/ssr-seed-plan.ts +14 -2
@@ -0,0 +1,171 @@
1
+ import { expect, test } from 'bun:test'
2
+ import ts from 'typescript'
3
+ import { analyzeComponent } from '../analyzer.ts'
4
+ import { compileJSX } from '../compiler.ts'
5
+ import { programWithSeparatedSource } from '../signal-prop-name-collision.ts'
6
+ import { TestAdapter } from '../adapters/test-adapter.ts'
7
+ import { fixture } from '../../../adapter-tests/fixtures/signal-literal-prop-name-collision.ts'
8
+
9
+ test('literal-seeded signal and bare prop have independent binding names', () => {
10
+ const ctx = analyzeComponent(fixture.source, 'test.tsx')
11
+ expect(ctx.signals[0].getter).not.toBe('rows')
12
+ expect(ctx.propsParams[0].name).toBe('rows')
13
+ expect(ctx.sourceFile.text).toContain('props.rows.map')
14
+ expect(ctx.sourceFile.text).toContain(`${ctx.signals[0].getter}().map`)
15
+ })
16
+
17
+ test('rename follows binding identity, preserves keys, and avoids source names', () => {
18
+ const source = `
19
+ 'use client'
20
+ import { createSignal } from '@barefootjs/client'
21
+ export function App(props: { count: number }) {
22
+ const bfSignal_count = 8
23
+ const BfSignal_count_1 = 9
24
+ const [count, setCount] = createSignal(7)
25
+ const alias = count
26
+ const object = { count }
27
+ const shadow = (count: number) => ({ count, label: 'count', value: count })
28
+ return <button onClick={() => setCount(count() + 1)}>{props.count}{count()}{alias()}{object.count()}{shadow(2).count}</button>
29
+ }
30
+ `
31
+ const ctx = analyzeComponent(source, 'test.tsx')
32
+ const name = ctx.signals[0].getter
33
+ expect(name).not.toBe('count')
34
+ expect(name).not.toBe('bfSignal_count')
35
+ expect(name.toLowerCase()).not.toBe('bfsignal_count_1')
36
+ expect(ctx.sourceFile.text).toContain(`const alias = ${name}`)
37
+ expect(ctx.sourceFile.text).toContain(`{ count: ${name} }`)
38
+ expect(ctx.sourceFile.text).toContain("(count: number) => ({ count, label: 'count', value: count })")
39
+ expect(ctx.sourceFile.text).toContain('object.count()')
40
+ expect(ctx.sourceFile.text).toContain(`setCount(${name}() + 1)`)
41
+ const result = compileJSX(source, 'test.tsx', { adapter: new TestAdapter() })
42
+ expect(result.errors.filter(e => e.severity === 'error')).toEqual([])
43
+ expect(result.files.find(f => f.type === 'clientJs')?.content).toContain(name)
44
+ })
45
+
46
+ test('same-prop derived seeds and ordinary bindings stay unchanged', () => {
47
+ const ctx = analyzeComponent(`
48
+ 'use client'
49
+ import { createSignal } from '@barefootjs/client'
50
+ export function App(props: { count: number }) {
51
+ const [count] = createSignal(props.count ?? 7)
52
+ const [other] = createSignal(2)
53
+ return <p>{count()}{other()}</p>
54
+ }
55
+ `, 'test.tsx')
56
+ expect(ctx.signals.map(s => s.getter)).toEqual(['count', 'other'])
57
+ })
58
+
59
+ test('signed literal seeds are separated without a type-based program', () => {
60
+ const ctx = analyzeComponent(`
61
+ 'use client'
62
+ import { createSignal } from '@barefootjs/client'
63
+ export function App(props: { count: number }) {
64
+ const [count] = createSignal(-7)
65
+ return <p>{props.count}{count()}</p>
66
+ }
67
+ `, 'test.tsx')
68
+ expect(ctx.signals[0].getter).not.toBe('count')
69
+ expect(ctx.signals[0].initialValue).toBe('-7')
70
+ })
71
+
72
+ test('re-analysis preserves a supplied Program and its virtual imports', () => {
73
+ const source = `
74
+ 'use client'
75
+ import { createSignal } from '@barefootjs/client'
76
+ import { n } from './virtual'
77
+ export function App(props: { count: number }) {
78
+ const [count] = createSignal(7)
79
+ const extra = n
80
+ return <p>{props.count}{count()}{extra}</p>
81
+ }
82
+ `
83
+ const files = new Map([
84
+ ['/virtual/app.tsx', source],
85
+ ['/virtual/virtual.ts', 'export const n = 42'],
86
+ ])
87
+ const options: ts.CompilerOptions = {
88
+ noLib: true, module: ts.ModuleKind.ESNext,
89
+ moduleResolution: ts.ModuleResolutionKind.Bundler, jsx: ts.JsxEmit.Preserve,
90
+ }
91
+ const program = ts.createProgram([...files.keys()], options, {
92
+ ...ts.createCompilerHost(options),
93
+ getCurrentDirectory: () => '/virtual',
94
+ directoryExists: name => name === '/virtual',
95
+ fileExists: name => files.has(name),
96
+ readFile: name => files.get(name),
97
+ getSourceFile: (name, version) => files.has(name)
98
+ ? ts.createSourceFile(name, files.get(name)!, version, true, ts.ScriptKind.TSX) : undefined,
99
+ })
100
+ const ctx = analyzeComponent(source, '/virtual/app.tsx', undefined, program)
101
+ expect(ctx.signals[0].getter).not.toBe('count')
102
+ expect(ctx.checker).not.toBeNull()
103
+ let extra: ts.VariableDeclaration | undefined
104
+ function visit(node: ts.Node): void {
105
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === 'extra') extra = node
106
+ ts.forEachChild(node, visit)
107
+ }
108
+ visit(ctx.sourceFile)
109
+ expect(ctx.checker!.typeToString(ctx.checker!.getTypeAtLocation(extra!.initializer!))).toBe('42')
110
+ expect(program.getSourceFile('/virtual/app.tsx')!.text).toBe(source)
111
+ })
112
+
113
+ test('multi-component production compilation separates each component independently', () => {
114
+ const source = `
115
+ 'use client'
116
+ import { createSignal } from '@barefootjs/client'
117
+ export function First(props: { count: number }) {
118
+ const [count] = createSignal(7)
119
+ return <p>{props.count}{count()}</p>
120
+ }
121
+ export function Second(props: { count: number }) {
122
+ const [count] = createSignal(9)
123
+ return <p>{props.count}{count()}</p>
124
+ }
125
+ `
126
+ const result = compileJSX(source, 'test.tsx', { adapter: new TestAdapter() })
127
+ expect(result.errors.filter(e => e.severity === 'error')).toEqual([])
128
+ const clientJs = result.files.find(f => f.type === 'clientJs')!.content
129
+ expect(clientJs).toContain('initFirst')
130
+ expect(clientJs).toContain('initSecond')
131
+ expect(clientJs.match(/\[bfSignal_count\]/g)).toHaveLength(2)
132
+ })
133
+
134
+ test.each([false, true])('custom module and type resolutions survive reanalysis (automatic: %s)', automatic => {
135
+ const source = `${automatic ? '' : '/// <reference types="custom-globals" />'}
136
+ 'use client'
137
+ import { n } from 'custom-values'
138
+ export function App(props: { count: number }) {
139
+ const [count] = createSignal(7)
140
+ const extra = n
141
+ return <p>{props.count}{count()}{extra}</p>
142
+ }
143
+ `
144
+ const files = new Map([
145
+ ['/virtual/app.tsx', source],
146
+ ['/virtual/value.ts', 'export const n = 42'],
147
+ ['/virtual/globals.d.ts', 'declare function createSignal(v: number): [() => number]'],
148
+ ])
149
+ const options: ts.CompilerOptions = { noLib: true, module: ts.ModuleKind.ESNext, jsx: ts.JsxEmit.Preserve, types: automatic ? ['custom-globals'] : [] }
150
+ const program = ts.createProgram(['/virtual/app.tsx'], options, {
151
+ ...ts.createCompilerHost(options),
152
+ getCurrentDirectory: () => '/virtual',
153
+ directoryExists: name => name === '/virtual',
154
+ fileExists: name => files.has(name),
155
+ readFile: name => files.get(name),
156
+ getSourceFile: (name, version) => files.has(name)
157
+ ? ts.createSourceFile(name, files.get(name)!, version, true, ts.ScriptKind.TSX) : undefined,
158
+ resolveModuleNames: names => names.map(name => name === 'custom-values'
159
+ ? { resolvedFileName: '/virtual/value.ts', extension: ts.Extension.Ts } : undefined),
160
+ resolveTypeReferenceDirectives: names => names.map(() => ({ resolvedFileName: '/virtual/globals.d.ts', primary: true })),
161
+ })
162
+ const ctx = analyzeComponent(source, '/virtual/app.tsx', undefined, program)
163
+ expect(ctx.signals[0].getter).not.toBe('count')
164
+ const rebuilt = programWithSeparatedSource(program, '/virtual/app.tsx', ctx.sourceFile.text)
165
+ const originalDiagnostics = program.getSemanticDiagnostics().map(d => d.code)
166
+ expect(rebuilt.getSemanticDiagnostics().map(d => d.code)).toEqual(originalDiagnostics)
167
+ const module = rebuilt.getSourceFile('/virtual/value.ts')!
168
+ const declaration = (module.statements[0] as ts.VariableStatement).declarationList.declarations[0]
169
+ expect(rebuilt.getTypeChecker().typeToString(rebuilt.getTypeChecker().getTypeAtLocation(declaration.name))).toBe('42')
170
+ expect(rebuilt.getSourceFile('/virtual/globals.d.ts')).toBeDefined()
171
+ })
@@ -173,15 +173,13 @@ describe('extractSsrDefaults', () => {
173
173
  expect(defaults?.n).toEqual({ value: 0 })
174
174
  })
175
175
 
176
- test('NON-self-derived collision (#2669, shape C — out of scope, must be unchanged): signal value still wins, no `propName`', () => {
176
+ test('literal-seeded collision has distinct raw-prop and internal-signal defaults', () => {
177
177
  // Same-named `label` getter and `label` prop, but the signal's OWN
178
178
  // initializer does NOT derive from `props.label` (it's a plain
179
179
  // string literal) — the JSX body separately reads `label()` AND
180
- // `props.label`. That's a template-variable-ALIASING defect (both
181
- // expressions lower to the same template variable, so no seeding
182
- // choice can be right for both readers) — a different bug, tracked
183
- // separately, and this fix must leave it byte-identical: the entry
184
- // stays the plain evaluated-signal-value shape with no `propName`.
180
+ // `props.label`. Analysis separates the local binding before IR is
181
+ // built, so the prop keeps its caller-facing seed while the signal
182
+ // remains an internal entry without `propName`.
185
183
  const metadata = metadataFor(`
186
184
  'use client'
187
185
  import { createSignal } from '@barefootjs/client'
@@ -192,7 +190,8 @@ describe('extractSsrDefaults', () => {
192
190
  `)
193
191
 
194
192
  const defaults = extractSsrDefaults(metadata)
195
- expect(defaults?.label).toEqual({ value: 'sig' })
193
+ expect(defaults?.label).toEqual({ propName: 'label', value: null })
194
+ expect(defaults?.[metadata.signals[0].getter]).toEqual({ value: 'sig' })
196
195
  })
197
196
 
198
197
  test('self-derived signal collision THROUGH a component-scope const (#2685 review): entry stays a PROP entry', () => {
@@ -23,6 +23,29 @@ function step(plan: SsrSeedPlan, name: string): SsrSeedStep {
23
23
  }
24
24
 
25
25
  describe('computeSsrSeedPlan', () => {
26
+ test('getter aliases seed after their prop-derived memo, including alias hops', () => {
27
+ const plan = planFor(`
28
+ 'use client'
29
+ import { createSignal, createMemo } from '@barefootjs/client'
30
+ function App(props: { count: number }) {
31
+ const [n] = createSignal(1.5)
32
+ const total = createMemo(() => n() + props.count)
33
+ const totalAlias = total
34
+ const secondAlias = totalAlias
35
+ return <p>{totalAlias()}{secondAlias()}</p>
36
+ }
37
+ `)
38
+ expect(plan.steps.map(s => s.name)).toEqual(['n', 'total', 'totalAlias', 'secondAlias'])
39
+ for (const name of ['totalAlias', 'secondAlias']) {
40
+ const alias = step(plan, name)
41
+ expect(alias.kind).toBe('derived')
42
+ if (alias.kind === 'derived') {
43
+ expect(alias.parsed).toEqual({ kind: 'call', callee: { kind: 'identifier', name: 'total' }, args: [] })
44
+ expect(alias.frees).toContain('total')
45
+ }
46
+ }
47
+ })
48
+
26
49
  test('env signal (aliased) → env-reader step; derived memo over it', () => {
27
50
  const plan = planFor(`
28
51
  'use client'
@@ -33,7 +33,7 @@ describe('Shadow guards: bare names that shadow props are NOT rewritten to _p.X'
33
33
 
34
34
  expect(errors).toEqual([])
35
35
  // The local must use the signal getter, not _p.count.
36
- expect(initBody).toMatch(/doubled\s*=\s*count\(\)\s*\*\s*2/)
36
+ expect(initBody).toMatch(/doubled\s*=\s*bfSignal_count\(\)\s*\*\s*2/)
37
37
  expect(initBody).not.toMatch(/_p\.count\(\)/)
38
38
  })
39
39
 
@@ -219,9 +219,12 @@ describe('buildRelocateEnv: builds env from analyzer/IR state', () => {
219
219
  }
220
220
  `, 'Foo.tsx')
221
221
  const env = buildRelocateEnv(ctx)
222
- // `count` is the signal getter, NOT the prop. Critical for #1132.
223
- expect(env.bindings.get('count')).toBe('signal-getter')
224
- expect(env.propsForLift.has('count')).toBe(false)
222
+ // The local getter is distinct from the bare prop. It must still
223
+ // classify as a getter, never as a prop eligible for lifting.
224
+ const getter = ctx.signals[0].getter
225
+ expect(env.bindings.get(getter)).toBe('signal-getter')
226
+ expect(env.propsForLift.has(getter)).toBe(false)
227
+ expect(env.bindings.get('count')).toBe('prop')
225
228
  })
226
229
 
227
230
  test('pure prop alias stays classified as prop (eligible for lift)', async () => {
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Static text in a template engine with LINE statements — Mojolicious
3
+ * (`% if (…) {`) and Xslate Kolon (`: if (…) {`) — must never begin a
4
+ * template line with the statement sigil: the engine reads such a line as
5
+ * code, so `{c ? 'on' : 'off'} :y` (whose text lands on its own line right
6
+ * after the conditional's closing `: }`) fails to parse, or vanishes when the
7
+ * line happens to parse (#3311).
8
+ *
9
+ * Every sigil that is the first non-blank character of the text or of a line
10
+ * inside it is emitted through `literal` instead — an output expression for
11
+ * the sigil character itself (`<%= '%' %>`, `<: ':' :>`). The text cannot know
12
+ * whether it starts a template line (that depends on what precedes it), so a
13
+ * line-leading sigil is always rewritten; the expression renders the same
14
+ * character either way.
15
+ */
16
+ export function escapeLineStatementSigil(text: string, sigil: string, literal: string): string {
17
+ return text
18
+ .split('\n')
19
+ .map(line => {
20
+ const indent = line.length - line.trimStart().length
21
+ return line.startsWith(sigil, indent) ? line.slice(0, indent) + literal + line.slice(indent + sigil.length) : line
22
+ })
23
+ .join('\n')
24
+ }
@@ -244,14 +244,14 @@ export interface ParsedExprEmitter {
244
244
  * Consumed by `===`/`!==` lowering on backends whose `==` is numeric
245
245
  * (Perl `eq`/`ne`) and by `isStringConcatBinary` below.
246
246
  */
247
- export function isStringTypedOperand(expr: ParsedExpr, isStringName: (n: string) => boolean): boolean {
247
+ export function isStringTypedOperand(expr: ParsedExpr, isStringName: (n: string, componentProperty?: boolean) => boolean): boolean {
248
248
  if (expr.kind === 'literal' && expr.literalType === 'string') return true
249
249
  if (expr.kind === 'template-literal') return true
250
250
  if (expr.kind === 'call' && expr.callee.kind === 'identifier' && expr.args.length === 0) {
251
251
  return isStringName(expr.callee.name)
252
252
  }
253
253
  if (expr.kind === 'member' && expr.object.kind === 'identifier' && expr.object.name === 'props') {
254
- return isStringName(expr.property)
254
+ return isStringName(expr.property, true)
255
255
  }
256
256
  // A bare identifier (#2212): a destructured prop param or a same-file
257
257
  // local const, string-typed per the caller's `isStringName` set — each
@@ -282,7 +282,7 @@ export function isStringConcatBinary(
282
282
  op: string,
283
283
  left: ParsedExpr,
284
284
  right: ParsedExpr,
285
- isStringName: (n: string) => boolean,
285
+ isStringName: (n: string, componentProperty?: boolean) => boolean,
286
286
  ): boolean {
287
287
  return op === '+' && (isStringTypedOperand(left, isStringName) || isStringTypedOperand(right, isStringName))
288
288
  }
package/src/analyzer.ts CHANGED
@@ -32,6 +32,7 @@ import { CATALOGUED_RICH_TYPE_NAMES } from './date-lowering.ts'
32
32
  import path from 'node:path'
33
33
  import fs from 'node:fs'
34
34
  import { signalSecondBinding } from './signal-initializer.ts'
35
+ import { separateLiteralSignalPropBindings, programWithSeparatedSource } from './signal-prop-name-collision.ts'
35
36
 
36
37
  // =============================================================================
37
38
  // TypeScript Program Creation
@@ -375,6 +376,15 @@ export function analyzeComponent(
375
376
  if (parsed.kind !== 'unsupported') signal.parsed = parsed
376
377
  }
377
378
 
379
+ const separatedSource = separateLiteralSignalPropBindings(ctx, isNonReferenceIdentifierPosition)
380
+ if (separatedSource !== null) {
381
+ // The checker supplied by the caller names the old AST. Re-analyze the
382
+ // structurally renamed source, preserving the shared-program contract
383
+ // (BF050), just as the reactive-factory prepass does above.
384
+ const separatedProgram = program && programWithSeparatedSource(program, filePath, separatedSource)
385
+ return analyzeComponent(separatedSource, filePath, targetComponentName, separatedProgram, acceptsCallbackBody, hadSharedProgram)
386
+ }
387
+
378
388
  // #2040: fold a complete, value-producing block-bodied memo into a single
379
389
  // expression so it flows through the same `parsed` path as an expression-bodied
380
390
  // memo, instead of relying on per-idiom block recognizers (#1897 / #1945 /
@@ -1474,19 +1484,10 @@ function collectSignal(node: ts.VariableDeclaration, ctx: AnalyzerContext): void
1474
1484
  : null
1475
1485
  if (getterElided && !setter) return
1476
1486
  const getter = getterElided ? `__bfGet_${setter}` : (elements[0] as ts.BindingElement & { name: ts.Identifier }).name.text
1477
- const initialValue = callExpr.arguments[0] ? ctx.getJS(callExpr.arguments[0]) : ''
1487
+ const initialValue = signalInitialValueText(callExpr, ctx)
1478
1488
  const typedInitialValue = callExpr.arguments[0] ? callExpr.arguments[0].getText(ctx.sourceFile) : undefined
1479
1489
 
1480
- // Try to infer type from initial value or type argument
1481
- let type: TypeInfo = { kind: 'unknown', raw: 'unknown' }
1482
-
1483
- // Check for type argument: createSignal<number>(0)
1484
- if (callExpr.typeArguments && callExpr.typeArguments.length > 0) {
1485
- type = typeNodeToTypeInfo(callExpr.typeArguments[0], ctx.sourceFile) ?? type
1486
- } else {
1487
- // Infer from initial value
1488
- type = inferTypeFromValue(initialValue)
1489
- }
1490
+ const type = signalTypeInfo(callExpr, initialValue, ctx)
1490
1491
 
1491
1492
  const envReader = resolveEnvSignalKey(callExpr, ctx) ?? undefined
1492
1493
  // The factory as written (identifier, alias, or `ns.factory`), so emit re-emits
@@ -1720,6 +1721,44 @@ function isSignalIndexAccess(
1720
1721
  return null
1721
1722
  }
1722
1723
 
1724
+ /**
1725
+ * A `createSignal` call's initial value as JS text. A call with no argument
1726
+ * starts the signal as `undefined` (what the runtime does with a missing
1727
+ * argument), so it is recorded as `'undefined'` rather than `''` — every
1728
+ * consumer that splices the initial value into an expression (the SSR
1729
+ * getter, the CSR template, the client-JS call) would otherwise emit an
1730
+ * empty operand (#3215). `createQuery`'s factory path records the same.
1731
+ */
1732
+ function signalInitialValueText(callExpr: ts.CallExpression, ctx: AnalyzerContext): string {
1733
+ return callExpr.arguments[0] ? ctx.getJS(callExpr.arguments[0]) : 'undefined'
1734
+ }
1735
+
1736
+ /**
1737
+ * A `createSignal` call's value type: its type argument, else inferred from
1738
+ * the initial value. A zero-arg call with a type argument is `T | undefined`
1739
+ * (the zero-arg overload's return type), not `T` — a typed backend would
1740
+ * otherwise seed the type's zero value (`0`, `""`) where the signal holds
1741
+ * `undefined` (#3215).
1742
+ */
1743
+ function signalTypeInfo(callExpr: ts.CallExpression, initialValue: string, ctx: AnalyzerContext): TypeInfo {
1744
+ const typeArg = callExpr.typeArguments?.[0]
1745
+ if (!typeArg) return inferTypeFromValue(initialValue)
1746
+ const type = typeNodeToTypeInfo(typeArg, ctx.sourceFile) ?? { kind: 'unknown', raw: 'unknown' }
1747
+ return callExpr.arguments[0] ? type : withUndefined(type)
1748
+ }
1749
+
1750
+ /** `T | undefined`, flattening a union `T` and leaving one that already admits `undefined` as is. */
1751
+ function withUndefined(type: TypeInfo): TypeInfo {
1752
+ const members = type.kind === 'union' && type.unionTypes ? type.unionTypes : [type]
1753
+ if (members.some(t => t.kind === 'primitive' && t.primitive === 'undefined')) return type
1754
+ if (type.kind === 'unknown') return type
1755
+ return {
1756
+ kind: 'union',
1757
+ raw: `${type.raw} | undefined`,
1758
+ unionTypes: [...members, { kind: 'primitive', raw: 'undefined', primitive: 'undefined' }],
1759
+ }
1760
+ }
1761
+
1723
1762
  function collectSignalTupleRef(
1724
1763
  node: ts.VariableDeclaration,
1725
1764
  ctx: AnalyzerContext
@@ -1727,17 +1766,12 @@ function collectSignalTupleRef(
1727
1766
  const name = (node.name as ts.Identifier).text
1728
1767
  const callExpr = node.initializer as ts.CallExpression
1729
1768
 
1730
- const initialValue = callExpr.arguments[0] ? ctx.getJS(callExpr.arguments[0]) : ''
1769
+ const initialValue = signalInitialValueText(callExpr, ctx)
1731
1770
  const typedInitialValue = callExpr.arguments[0]
1732
1771
  ? callExpr.arguments[0].getText(ctx.sourceFile)
1733
1772
  : undefined
1734
1773
 
1735
- let type: TypeInfo = { kind: 'unknown', raw: 'unknown' }
1736
- if (callExpr.typeArguments && callExpr.typeArguments.length > 0) {
1737
- type = typeNodeToTypeInfo(callExpr.typeArguments[0], ctx.sourceFile) ?? type
1738
- } else {
1739
- type = inferTypeFromValue(initialValue)
1740
- }
1774
+ const type = signalTypeInfo(callExpr, initialValue, ctx)
1741
1775
 
1742
1776
  ctx.signalTupleRefs.set(name, {
1743
1777
  initialValue,
@@ -1763,17 +1797,12 @@ function collectSignalFromIndexAccess(
1763
1797
  // Pattern A — each declaration is a standalone signal. Pair [0] -> getter
1764
1798
  // or [1] -> setter; the missing half stays null.
1765
1799
  const callExpr = match.callExpr
1766
- const initialValue = callExpr.arguments[0] ? ctx.getJS(callExpr.arguments[0]) : ''
1800
+ const initialValue = signalInitialValueText(callExpr, ctx)
1767
1801
  const typedInitialValue = callExpr.arguments[0]
1768
1802
  ? callExpr.arguments[0].getText(ctx.sourceFile)
1769
1803
  : undefined
1770
1804
 
1771
- let type: TypeInfo = { kind: 'unknown', raw: 'unknown' }
1772
- if (callExpr.typeArguments && callExpr.typeArguments.length > 0) {
1773
- type = typeNodeToTypeInfo(callExpr.typeArguments[0], ctx.sourceFile) ?? type
1774
- } else {
1775
- type = inferTypeFromValue(initialValue)
1776
- }
1805
+ const type = signalTypeInfo(callExpr, initialValue, ctx)
1777
1806
 
1778
1807
  const loc = getSourceLocation(node, ctx.sourceFile, ctx.filePath)
1779
1808
  const initialFreeIdentifiers = callExpr.arguments[0]
@@ -2376,7 +2405,12 @@ function collectLocalDeclarations(root: ts.Node): Set<string> {
2376
2405
  // Reactive primitives are DOM-free. The context/portal entries here are
2377
2406
  // type-level shims — their implementations live in @barefootjs/client/runtime
2378
2407
  // and are emitted by the compiler for 'use client' components.
2379
- const CLIENT_EXPORTS = new Set([
2408
+ //
2409
+ // The compiler re-points a recognised import at `@barefootjs/client/runtime`
2410
+ // in client JS, and at the Hono SSR shim on the server, so every name here
2411
+ // must exist on both. `client-exports-contract.test.ts` (adapter-hono) pins
2412
+ // this set against both, and against the root entry's own exports (#3217).
2413
+ export const CLIENT_EXPORTS: ReadonlySet<string> = new Set([
2380
2414
  'createSignal', 'createEffect', 'createDisposableEffect', 'createMemo',
2381
2415
  'createRoot', 'onCleanup', 'onMount', 'untrack', 'batch', 'splitProps',
2382
2416
  'forwardProps', 'unwrap', '__slot',
@@ -514,6 +514,55 @@ export function lookupStaticRecordLiteral(
514
514
  return null
515
515
  }
516
516
 
517
+ /**
518
+ * Resolve a bare identifier bound to a literal-initialized `const` — module
519
+ * or component-function scope — to that literal, or `null` for any other
520
+ * shape so callers fall back to their generic lowering. The one decision
521
+ * every template-string adapter used to copy as its own `_resolveLiteralConst`
522
+ * (#3312): those copies matched numbers and strings by regex and missed
523
+ * booleans, so `const on = true` read as a ternary test lowered to an unbound
524
+ * template variable (the falsy branch, or a render-time error). Each adapter
525
+ * renders the returned literal — boolean, number, string or `null` — in its
526
+ * own syntax.
527
+ *
528
+ * Reads the analyzer's structured `parsed` literal when present (a negated
529
+ * number arrives as unary `-`), falling back to the value text for the same
530
+ * three shapes. `isShadowed` is REQUIRED, as in `lookupStaticRecordLiteral`:
531
+ * a name the enclosing loop binds is the row's own value (#2221).
532
+ */
533
+ export function lookupLiteralConst(
534
+ name: string,
535
+ constants: IRMetadata['localConstants'] | undefined,
536
+ isShadowed: (name: string) => boolean,
537
+ ): { kind: 'string' | 'number' | 'boolean' | 'null'; text: string } | null {
538
+ if (isShadowed(name)) return null
539
+ const c = (constants ?? []).find(lc => lc.name === name)
540
+ if (c?.value === undefined) return null
541
+ const p = c.parsed
542
+ if (p?.kind === 'literal') {
543
+ if (p.literalType === 'string' && typeof p.value === 'string') return { kind: 'string', text: p.value }
544
+ if (p.literalType === 'boolean' && typeof p.value === 'boolean') return { kind: 'boolean', text: String(p.value) }
545
+ if (p.literalType === 'null') return { kind: 'null', text: 'null' }
546
+ if (p.literalType === 'number' && typeof p.value === 'number' && Number.isFinite(p.value)) {
547
+ return { kind: 'number', text: String(p.value) }
548
+ }
549
+ }
550
+ if (
551
+ p?.kind === 'unary' && p.op === '-' &&
552
+ p.argument.kind === 'literal' && p.argument.literalType === 'number' &&
553
+ typeof p.argument.value === 'number' && Number.isFinite(p.argument.value)
554
+ ) {
555
+ return { kind: 'number', text: String(-p.argument.value) }
556
+ }
557
+ if (p) return null
558
+ const v = c.value.trim()
559
+ if (/^-?\d+(\.\d+)?$/.test(v)) return { kind: 'number', text: v }
560
+ if (v === 'true' || v === 'false') return { kind: 'boolean', text: v }
561
+ if (v === 'null') return { kind: 'null', text: 'null' }
562
+ const strLit = /^'([^'\\]*)'$/.exec(v) ?? /^"([^"\\]*)"$/.exec(v)
563
+ return strLit ? { kind: 'string', text: strLit[1] } : null
564
+ }
565
+
517
566
  /**
518
567
  * Statically evaluate `[<string literals>].join(<sep?>)` (e.g. a module-scope
519
568
  * `const stateClasses = ['…', …].join(' ')`) to its joined string, so SSR
package/src/html-types.ts CHANGED
@@ -51,7 +51,11 @@ export interface BaseEventAttributes {
51
51
  onAnimationStart?: (event: AnimationEvent) => void
52
52
  onAnimationEnd?: (event: AnimationEvent) => void
53
53
  onAnimationIteration?: (event: AnimationEvent) => void
54
+ onAnimationCancel?: (event: AnimationEvent) => void
55
+ onTransitionStart?: (event: TransitionEvent) => void
56
+ onTransitionRun?: (event: TransitionEvent) => void
54
57
  onTransitionEnd?: (event: TransitionEvent) => void
58
+ onTransitionCancel?: (event: TransitionEvent) => void
55
59
  onCopy?: (event: ClipboardEvent) => void
56
60
  onCut?: (event: ClipboardEvent) => void
57
61
  onPaste?: (event: ClipboardEvent) => void
@@ -134,6 +138,17 @@ export interface HTMLBaseAttributes extends BaseEventAttributes {
134
138
  onPointerMove?: (event: PointerEvent) => void
135
139
  onPointerEnter?: (event: PointerEvent) => void
136
140
  onPointerLeave?: (event: PointerEvent) => void
141
+ onPointerCancel?: (event: PointerEvent) => void
142
+ onPointerOver?: (event: PointerEvent) => void
143
+ onPointerOut?: (event: PointerEvent) => void
144
+ onGotPointerCapture?: (event: PointerEvent) => void
145
+ onLostPointerCapture?: (event: PointerEvent) => void
146
+ onMouseOver?: MouseEventHandler<HTMLElement>
147
+ onMouseOut?: MouseEventHandler<HTMLElement>
148
+ onAuxClick?: MouseEventHandler<HTMLElement>
149
+ onFocusIn?: FocusEventHandler<HTMLElement>
150
+ onFocusOut?: FocusEventHandler<HTMLElement>
151
+ onBeforeInput?: InputEventHandler<HTMLElement>
137
152
  onContextMenu?: MouseEventHandler<HTMLElement>
138
153
  onDoubleClick?: MouseEventHandler<HTMLElement>
139
154
 
package/src/index.ts CHANGED
@@ -90,7 +90,7 @@ export type {
90
90
  export { isElidedFactoryGetter } from './types.ts'
91
91
 
92
92
  // Analyzer
93
- export { analyzeComponent, listComponentFunctions, listComponentFunctions as listExportedComponents, scanComponentFile, createProgramForFile, createAnchoredProgram, needsTypeBasedDetection, resolveRelativeImportToFile, REACTIVE_PRIMITIVES, BROWSER_ONLY_CLIENT_APIS, type AnalyzerContext, type ComponentFileScan } from './analyzer.ts'
93
+ export { analyzeComponent, listComponentFunctions, listComponentFunctions as listExportedComponents, scanComponentFile, createProgramForFile, createAnchoredProgram, needsTypeBasedDetection, resolveRelativeImportToFile, REACTIVE_PRIMITIVES, CLIENT_EXPORTS, BROWSER_ONLY_CLIENT_APIS, type AnalyzerContext, type ComponentFileScan } from './analyzer.ts'
94
94
  export { createProgramForCorpus, type SharedProgramOptions } from './shared-program.ts'
95
95
 
96
96
  // JSX to IR transformer
@@ -122,6 +122,15 @@ export type { ParsedExprEmitter, LoweringEmitter, HigherOrderMethod, ArrayMethod
122
122
  export { collectLoopBoundNames } from './adapters/loop-bound-names.ts'
123
123
  export { derivesScopeFromSlot } from './adapters/child-scope.ts'
124
124
  export { evaluateStaticLiteral, isFullyStaticLiteral, resolveStaticLoopSource } from './static-literal.ts'
125
+ export {
126
+ attrValueMayBeNullish,
127
+ collectNullableSignalGetters,
128
+ collectNullishAttrContext,
129
+ isNullableSignal,
130
+ isNullishLiteral,
131
+ nullableSignalAttrGetter,
132
+ type NullishAttrContext,
133
+ } from './nullable-signal-attr.ts'
125
134
  export { importsSearchParams, searchParamsLocalNames, envSignalLocalNames, envSignalReaderFor, ENV_SIGNAL_READERS, queryHrefLocalNames, matchSearchParamsMethodCall } from './adapters/env-signal.ts'
126
135
  export type { EnvSignalReader } from './adapters/env-signal.ts'
127
136
  export { matchQueryHrefCall, queryHrefArgs, type QueryHrefCall, type QueryHrefTriple } from './query-href-lowering.ts'
@@ -152,6 +161,7 @@ export { emitIRNode } from './adapters/ir-node-emitter.ts'
152
161
  export type { IRNodeEmitter, EmitIRNode } from './adapters/ir-node-emitter.ts'
153
162
  export { emitAttrValue } from './adapters/attr-value-emitter.ts'
154
163
  export type { AttrValueEmitter } from './adapters/attr-value-emitter.ts'
164
+ export { escapeLineStatementSigil } from './adapters/line-statement-text.ts'
155
165
  export {
156
166
  isDangerousInnerHtmlAttr,
157
167
  resolveDangerousInnerHtml,
@@ -238,6 +248,7 @@ export { isValueReferenceIdentifier, collectValueReferencedNames } from './value
238
248
  // Expression Parser
239
249
  export { parseExpression, tsNodeToParsedExpr, asCallbackMethodCall, CALLBACK_METHODS, sortComparatorFromArrow, serializeParsedExpr, freeVarsInBody, freeIdentifiers, materializeGetterCalls, isSupported, isSupportedValue, exprToString, stringifyParsedExpr, identifierPath, parseBlockBody, parseBlockBodyTolerant, foldBlockToExpr, predicateTernaryToLogical, containsHigherOrder, extractArrowBodyExpression, parseStyleObjectEntries, hasUnsafeStyleValue, parseProviderObjectLiteral, isFunctionShapedExpression, type ProviderObjectMember, type FoldBlockOptions } from './expression-parser.ts'
240
250
  export type { StyleObjectEntry } from './expression-parser.ts'
251
+ export { literalMemberIndex } from './literal-member-index.ts'
241
252
  export { PARSED_EXPR_KINDS, ARRAY_METHOD_NAMES, SORT_KEY_TYPES, SORT_KEY_TARGETS, SORT_KEY_DIRECTIONS } from './expression-parser.ts'
242
253
  export type { ParsedExpr, ObjectLiteralProperty, ParsedStatement, SortComparator, SortKey, FlatDepth, SupportLevel, SupportResult, TemplatePart } from './expression-parser.ts'
243
254
  export { buildLoopChainExpr } from './loop-chain.ts'
@@ -247,6 +258,7 @@ export { isLowerableLoopDestructure, isLowerableObjectRestDestructure } from './
247
258
  // Binding scope (#2482) — shared loop-bound-name resolution service
248
259
  export { BindingScope } from './scope/binding-scope.ts'
249
260
  export type { ScopeBindingSource, ScopeBinding, ScopeFrame, LoopBindingSource } from './scope/binding-scope.ts'
261
+ export { rootPropAliasNames, rootPropAliasesForLoop, rootPropReadName } from './scope/root-prop-alias.ts'
250
262
 
251
263
  // Debug analysis
252
264
  export {
@@ -361,7 +373,7 @@ export { BOOLEAN_ATTRS, isBooleanAttr } from './html-constants.ts'
361
373
  export { USE_CLIENT_DIRECTIVE, CLIENT_EXPRESSION_DIRECTIVE } from './directives.ts'
362
374
 
363
375
  // Shared props-object-pattern helpers for the Go / Mojo template adapters
364
- export { augmentInheritedPropAccesses, parseRecordIndexAccess, evalStringArrayJoin, collectModuleStringConsts, lookupStaticRecordLiteral, collectContextConsumers } from './augment-inherited-props.ts'
376
+ export { augmentInheritedPropAccesses, parseRecordIndexAccess, evalStringArrayJoin, collectModuleStringConsts, lookupStaticRecordLiteral, lookupLiteralConst, collectContextConsumers } from './augment-inherited-props.ts'
365
377
  export type { RecordIndexAccess, RecordIndexEntry, ContextConsumer } from './augment-inherited-props.ts'
366
378
 
367
379
  // HTML element attribute types