@barefootjs/jsx 0.38.0 → 0.39.1

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 (105) hide show
  1. package/dist/action-accessor.d.ts +159 -0
  2. package/dist/action-accessor.d.ts.map +1 -0
  3. package/dist/adapters/interface.d.ts +19 -0
  4. package/dist/adapters/interface.d.ts.map +1 -1
  5. package/dist/adapters/jsx-adapter.d.ts.map +1 -1
  6. package/dist/analyzer.d.ts +49 -1
  7. package/dist/analyzer.d.ts.map +1 -1
  8. package/dist/async-action-refusal.d.ts +45 -0
  9. package/dist/async-action-refusal.d.ts.map +1 -0
  10. package/dist/compiler.d.ts.map +1 -1
  11. package/dist/debug.d.ts +61 -5
  12. package/dist/debug.d.ts.map +1 -1
  13. package/dist/errors.d.ts +4 -0
  14. package/dist/errors.d.ts.map +1 -1
  15. package/dist/format-date-refusal.d.ts +2 -6
  16. package/dist/format-date-refusal.d.ts.map +1 -1
  17. package/dist/html-types.d.ts +5 -0
  18. package/dist/html-types.d.ts.map +1 -1
  19. package/dist/index.d.ts +3 -2
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1261 -422
  22. package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
  23. package/dist/ir-to-client-js/collect-elements.d.ts +17 -1
  24. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  25. package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
  26. package/dist/ir-to-client-js/compute-scope.d.ts.map +1 -1
  27. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -0
  28. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
  29. package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
  30. package/dist/ir-to-client-js/declaration-sort.d.ts +2 -1
  31. package/dist/ir-to-client-js/declaration-sort.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/emit-module-level.d.ts.map +1 -1
  33. package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
  34. package/dist/ir-to-client-js/plan/declaration-emit.d.ts +7 -5
  35. package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
  36. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  37. package/dist/ir-to-client-js/reactivity.d.ts +10 -2
  38. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  39. package/dist/ir-to-client-js/types.d.ts +4 -0
  40. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  41. package/dist/ir-to-client-js/utils.d.ts +52 -9
  42. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  43. package/dist/jsx-to-ir.d.ts.map +1 -1
  44. package/dist/signal-initializer.d.ts +24 -0
  45. package/dist/signal-initializer.d.ts.map +1 -0
  46. package/dist/ssr-defaults.d.ts.map +1 -1
  47. package/dist/ssr-seed-plan.d.ts.map +1 -1
  48. package/dist/template-position-walk.d.ts +68 -0
  49. package/dist/template-position-walk.d.ts.map +1 -0
  50. package/dist/types.d.ts +95 -0
  51. package/dist/types.d.ts.map +1 -1
  52. package/package.json +2 -2
  53. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +194 -4
  54. package/src/__tests__/action-accessor.test.ts +166 -0
  55. package/src/__tests__/adapter-output.test.ts +142 -0
  56. package/src/__tests__/create-mutation.test.ts +250 -0
  57. package/src/__tests__/create-query.test.ts +696 -0
  58. package/src/__tests__/csr-fragment-root-scope-shape.test.ts +156 -0
  59. package/src/__tests__/debug.test.ts +305 -0
  60. package/src/__tests__/doc-examples.test.ts +66 -3
  61. package/src/__tests__/ir-fragment-transparency.test.ts +23 -0
  62. package/src/__tests__/issue-3240-nested-static-map-event-delegation.test.ts +245 -0
  63. package/src/__tests__/jsx-text-linebreak-whitespace.test.ts +80 -0
  64. package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +445 -0
  65. package/src/__tests__/props-destructuring.test.ts +79 -4
  66. package/src/__tests__/reactive-factory-arity.test.ts +311 -0
  67. package/src/__tests__/ssr-portal-ref-callback.test.ts +5 -3
  68. package/src/action-accessor.ts +289 -0
  69. package/src/adapters/interface.ts +19 -0
  70. package/src/adapters/jsx-adapter.ts +47 -20
  71. package/src/analyzer.ts +593 -44
  72. package/src/async-action-refusal.ts +254 -0
  73. package/src/compiler.ts +81 -46
  74. package/src/debug.ts +351 -104
  75. package/src/errors.ts +39 -0
  76. package/src/format-date-refusal.ts +6 -125
  77. package/src/html-types.ts +14 -0
  78. package/src/index.ts +3 -1
  79. package/src/ir-to-client-js/build-references.ts +6 -2
  80. package/src/ir-to-client-js/collect-elements.ts +65 -4
  81. package/src/ir-to-client-js/compute-inlinability.ts +2 -1
  82. package/src/ir-to-client-js/compute-scope.ts +3 -1
  83. package/src/ir-to-client-js/control-flow/plan/build-insert.ts +1 -0
  84. package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -0
  85. package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +112 -3
  86. package/src/ir-to-client-js/control-flow/stringify/insert.ts +1 -1
  87. package/src/ir-to-client-js/csr-substitute.ts +11 -3
  88. package/src/ir-to-client-js/declaration-sort.ts +7 -3
  89. package/src/ir-to-client-js/emit-module-level.ts +7 -4
  90. package/src/ir-to-client-js/emit-registration.ts +5 -10
  91. package/src/ir-to-client-js/index.ts +7 -2
  92. package/src/ir-to-client-js/phases/ref-callbacks.ts +1 -1
  93. package/src/ir-to-client-js/plan/build-declaration-emit.ts +16 -15
  94. package/src/ir-to-client-js/plan/declaration-emit.ts +7 -5
  95. package/src/ir-to-client-js/prop-handling.ts +4 -0
  96. package/src/ir-to-client-js/reactivity.ts +32 -1
  97. package/src/ir-to-client-js/stringify/declaration-emit.ts +14 -7
  98. package/src/ir-to-client-js/types.ts +4 -0
  99. package/src/ir-to-client-js/utils.ts +184 -21
  100. package/src/jsx-to-ir.ts +111 -14
  101. package/src/signal-initializer.ts +36 -0
  102. package/src/ssr-defaults.ts +10 -0
  103. package/src/ssr-seed-plan.ts +12 -1
  104. package/src/template-position-walk.ts +203 -0
  105. package/src/types.ts +99 -0
@@ -12,6 +12,7 @@ import type {
12
12
  IRTemplatePart,
13
13
  ImportSpecifier,
14
14
  } from '../types.ts'
15
+ import { isElidedFactoryGetter } from '../types.ts'
15
16
  import { templatePartsToJsExpr } from '../template-parts.ts'
16
17
  import { BF_SCOPE, BF_SLOT, BF_COND } from '@barefootjs/shared'
17
18
  import { BaseAdapter } from './interface.ts'
@@ -150,26 +151,52 @@ export abstract class JsxAdapter extends BaseAdapter {
150
151
  }
151
152
  continue
152
153
  }
153
- // Create a getter that returns the initial value for SSR
154
- const rawInitialValue = preserveTypes
155
- ? (signal.typedInitialValue ?? signal.initialValue)
156
- : signal.initialValue
157
- const initialValue = rawInitialValue.trim().startsWith('{') ? `(${rawInitialValue})` : rawInitialValue
158
-
159
- // When preserveTypes and typedInitialValue is absent but signal.type has a meaningful
160
- // type from a generic parameter, add a type assertion to prevent TS inference issues.
161
- // A bare `object` raw is the analyzer's coarse KIND, not a real type — asserting
162
- // `as object` only destroys the initializer's inferred literal type (a
163
- // `{ x: 0, y: 0 }` signal getter stops matching `() => { x: number; y: number }`).
164
- const needsTypeAssertion = preserveTypes
165
- && !signal.typedInitialValue
166
- && signal.type.kind !== 'unknown'
167
- && signal.type.kind !== 'primitive'
168
- && signal.type.raw !== 'object'
169
- if (needsTypeAssertion) {
170
- lines.push(` const ${signal.getter} = () => ${initialValue} as ${signal.type.raw}`)
171
- } else {
172
- lines.push(` const ${signal.getter} = () => ${initialValue}`)
154
+ // An elided async-factory value (#3245) has no getter binding in the
155
+ // source at all — `signal.getter` is a synthesized internal name that
156
+ // nothing in the template or event handlers ever references. Emitting
157
+ // its SSR stub would leak that compiler-internal name into the SSR
158
+ // module for a binding nothing reads; the action's own SSR stub
159
+ // (below) is unaffected and still emitted when referenced. See
160
+ // `isElidedFactoryGetter`'s docstring for the full rationale.
161
+ if (!isElidedFactoryGetter(signal)) {
162
+ // Create a getter that returns the initial value for SSR
163
+ const rawInitialValue = preserveTypes
164
+ ? (signal.typedInitialValue ?? signal.initialValue)
165
+ : signal.initialValue
166
+ const initialValue = rawInitialValue.trim().startsWith('{') ? `(${rawInitialValue})` : rawInitialValue
167
+
168
+ // When preserveTypes and typedInitialValue is absent but signal.type has a meaningful
169
+ // type from a generic parameter, add a type assertion to prevent TS inference issues.
170
+ // A bare `object` raw is the analyzer's coarse KIND, not a real type — asserting
171
+ // `as object` only destroys the initializer's inferred literal type (a
172
+ // `{ x: 0, y: 0 }` signal getter stops matching `() => { x: number; y: number }`).
173
+ const needsTypeAssertion = preserveTypes
174
+ && !signal.typedInitialValue
175
+ && signal.type.kind !== 'unknown'
176
+ && signal.type.kind !== 'primitive'
177
+ && signal.type.raw !== 'object'
178
+ if (needsTypeAssertion) {
179
+ lines.push(` const ${signal.getter} = () => ${initialValue} as ${signal.type.raw}`)
180
+ } else {
181
+ lines.push(` const ${signal.getter} = () => ${initialValue}`)
182
+ }
183
+ }
184
+
185
+ // An async factory's action (#3165): the request function never runs on
186
+ // the server, so a reference that survives into SSR (e.g. forwarded to a
187
+ // child as a prop) gets a no-op. Since #3166, `action.isPending()` /
188
+ // `action.error()` are ordinary, IR-visible seeded values
189
+ // (`false` / `undefined`, spec/async.md §7.3) rather than refused —
190
+ // this SSR stub is what a template position's `fetchPosts.isPending()`
191
+ // actually calls at render time (this file's execution model runs the
192
+ // real JS text, unlike a DSL adapter's `parsedCondition`-based
193
+ // substitution), so it must carry working accessors, not just be
194
+ // callable itself.
195
+ const action = signal.factory?.action
196
+ if (action && identifierPattern(action).test(setterRefText)) {
197
+ lines.push(preserveTypes
198
+ ? ` const ${action}: any = Object.assign(() => {}, { isPending: () => false, error: () => undefined })`
199
+ : ` const ${action} = Object.assign(() => {}, { isPending: () => false, error: () => undefined })`)
173
200
  }
174
201
 
175
202
  // Create a no-op setter for SSR — omit entirely if not referenced anywhere