@barefootjs/jsx 0.40.1 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/dist/adapters/boolean-result.d.ts +32 -10
  2. package/dist/adapters/boolean-result.d.ts.map +1 -1
  3. package/dist/adapters/brace-delimiter-text.d.ts +18 -0
  4. package/dist/adapters/brace-delimiter-text.d.ts.map +1 -0
  5. package/dist/adapters/callback-method.d.ts +45 -5
  6. package/dist/adapters/callback-method.d.ts.map +1 -1
  7. package/dist/adapters/component-props.d.ts +3 -4
  8. package/dist/adapters/component-props.d.ts.map +1 -1
  9. package/dist/adapters/computed-const.d.ts +11 -1
  10. package/dist/adapters/computed-const.d.ts.map +1 -1
  11. package/dist/adapters/dsl-template-adapter.d.ts +24 -12
  12. package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
  13. package/dist/adapters/loop-bound-names.d.ts +9 -1
  14. package/dist/adapters/loop-bound-names.d.ts.map +1 -1
  15. package/dist/adapters/loop-row-type.d.ts +59 -0
  16. package/dist/adapters/loop-row-type.d.ts.map +1 -0
  17. package/dist/adapters/nil-reading.d.ts +63 -0
  18. package/dist/adapters/nil-reading.d.ts.map +1 -0
  19. package/dist/adapters/non-primitive-equality.d.ts +33 -0
  20. package/dist/adapters/non-primitive-equality.d.ts.map +1 -0
  21. package/dist/adapters/number-value.d.ts +5 -3
  22. package/dist/adapters/number-value.d.ts.map +1 -1
  23. package/dist/adapters/operand-typing.d.ts +126 -0
  24. package/dist/adapters/operand-typing.d.ts.map +1 -0
  25. package/dist/adapters/parsed-expr-emitter.d.ts +80 -12
  26. package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
  27. package/dist/adapters/primitive-plan.d.ts +320 -0
  28. package/dist/adapters/primitive-plan.d.ts.map +1 -0
  29. package/dist/adapters/prop-classes.d.ts +5 -0
  30. package/dist/adapters/prop-classes.d.ts.map +1 -1
  31. package/dist/analyzer-context.d.ts +4 -0
  32. package/dist/analyzer-context.d.ts.map +1 -1
  33. package/dist/analyzer.d.ts.map +1 -1
  34. package/dist/augment-inherited-props.d.ts +63 -8
  35. package/dist/augment-inherited-props.d.ts.map +1 -1
  36. package/dist/compiler.d.ts.map +1 -1
  37. package/dist/event-handler-name.d.ts +12 -0
  38. package/dist/event-handler-name.d.ts.map +1 -1
  39. package/dist/expression-parser.d.ts +8 -0
  40. package/dist/expression-parser.d.ts.map +1 -1
  41. package/dist/index.d.ts +20 -11
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +4903 -2311
  44. package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
  45. package/dist/ir-to-client-js/child-props-object.d.ts +106 -0
  46. package/dist/ir-to-client-js/child-props-object.d.ts.map +1 -0
  47. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  48. package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
  49. package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
  50. package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
  51. package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts +4 -2
  52. package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
  53. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  54. package/dist/ir-to-client-js/imports.d.ts +2 -2
  55. package/dist/ir-to-client-js/imports.d.ts.map +1 -1
  56. package/dist/ir-to-client-js/index.d.ts +2 -6
  57. package/dist/ir-to-client-js/index.d.ts.map +1 -1
  58. package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -3
  59. package/dist/ir-to-client-js/plan/build-declaration-emit.d.ts.map +1 -1
  60. package/dist/ir-to-client-js/plan/build-static-array-child-init.d.ts.map +1 -1
  61. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +30 -18
  62. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
  63. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  64. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +3 -1
  65. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
  66. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts +3 -2
  67. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
  68. package/dist/jsx-to-ir.d.ts +1 -0
  69. package/dist/jsx-to-ir.d.ts.map +1 -1
  70. package/dist/nullable-signal-attr.d.ts +51 -34
  71. package/dist/nullable-signal-attr.d.ts.map +1 -1
  72. package/dist/prop-rewrite.d.ts +7 -0
  73. package/dist/prop-rewrite.d.ts.map +1 -1
  74. package/dist/props-binding.d.ts +58 -13
  75. package/dist/props-binding.d.ts.map +1 -1
  76. package/dist/props-object-whole-read.d.ts +15 -0
  77. package/dist/props-object-whole-read.d.ts.map +1 -0
  78. package/dist/rich-type-refusal.d.ts.map +1 -1
  79. package/dist/scope/binding-scope.d.ts +85 -10
  80. package/dist/scope/binding-scope.d.ts.map +1 -1
  81. package/dist/scope/lexical-scope-walk.d.ts +3 -2
  82. package/dist/scope/lexical-scope-walk.d.ts.map +1 -1
  83. package/dist/scope/root-prop-alias.d.ts +10 -7
  84. package/dist/scope/root-prop-alias.d.ts.map +1 -1
  85. package/dist/ssr-defaults.d.ts +39 -3
  86. package/dist/ssr-defaults.d.ts.map +1 -1
  87. package/dist/strip-types.d.ts +13 -0
  88. package/dist/strip-types.d.ts.map +1 -1
  89. package/dist/template-position-walk.d.ts +21 -3
  90. package/dist/template-position-walk.d.ts.map +1 -1
  91. package/dist/types.d.ts +90 -0
  92. package/dist/types.d.ts.map +1 -1
  93. package/package.json +2 -2
  94. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +9 -9
  95. package/src/__tests__/binding-scope.test.ts +89 -1
  96. package/src/__tests__/body-destructure-props-object-alias.test.ts +123 -0
  97. package/src/__tests__/body-destructured-prop-default-arrow.test.ts +2 -2
  98. package/src/__tests__/body-destructured-props-live.test.ts +5 -5
  99. package/src/__tests__/boolean-result.test.ts +22 -5
  100. package/src/__tests__/brace-delimiter-text.test.ts +26 -0
  101. package/src/__tests__/callback-method.test.ts +62 -2
  102. package/src/__tests__/child-components-in-map.test.ts +1 -1
  103. package/src/__tests__/client-js-generation.test.ts +3 -3
  104. package/src/__tests__/computed-const.test.ts +103 -0
  105. package/src/__tests__/destructure-default-reads-earlier-param.test.ts +7 -7
  106. package/src/__tests__/destructured-props-live.test.ts +1 -1
  107. package/src/__tests__/emit-to-string-call.test.ts +2 -1
  108. package/src/__tests__/hydration-payload-analysis.test.ts +166 -0
  109. package/src/__tests__/issue-2724-prop-alias-loop-not-static.test.ts +7 -7
  110. package/src/__tests__/issue-2754-rest-spread-needs-slot.test.ts +5 -2
  111. package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +1 -1
  112. package/src/__tests__/issue-2835-props-type-member-name-collision.test.ts +4 -4
  113. package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +1 -1
  114. package/src/__tests__/issue-3688-props-spread-child-csr.test.ts +2 -1
  115. package/src/__tests__/issue-3713-props-spread-loop-row.test.ts +65 -0
  116. package/src/__tests__/issue-3861-object-spread-child.test.ts +102 -0
  117. package/src/__tests__/lookup-literal-const.test.ts +9 -3
  118. package/src/__tests__/loop-index-reactivity.test.ts +2 -2
  119. package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +1 -1
  120. package/src/__tests__/loop-plan.test.ts +1 -1
  121. package/src/__tests__/loop-row-const-initializer-shadow.test.ts +146 -0
  122. package/src/__tests__/loop-row-type.test.ts +64 -0
  123. package/src/__tests__/lowering-value-position.test.ts +4 -0
  124. package/src/__tests__/memo-body-expr.test.ts +2 -2
  125. package/src/__tests__/module-const-destructure-default.test.ts +156 -0
  126. package/src/__tests__/nested-loop-index-param.test.ts +1 -1
  127. package/src/__tests__/nested-loop-reactive-attrs.test.ts +2 -2
  128. package/src/__tests__/nested-row-shadowing.test.ts +2 -2
  129. package/src/__tests__/nil-reading.test.ts +78 -0
  130. package/src/__tests__/nullable-signal-attr.test.ts +109 -48
  131. package/src/__tests__/primitive-plan.test.ts +494 -0
  132. package/src/__tests__/profile-loop-binding-ids.test.ts +2 -2
  133. package/src/__tests__/profile-nested-binding-ids.test.ts +2 -2
  134. package/src/__tests__/prop-default-undefined-only.test.ts +115 -0
  135. package/src/__tests__/prop-references.test.ts +2 -2
  136. package/src/__tests__/props-destructuring.test.ts +17 -0
  137. package/src/__tests__/props-object-whole-read.test.ts +40 -0
  138. package/src/__tests__/prune-unused-prop-extractions.test.ts +3 -3
  139. package/src/__tests__/reactive-attrs-in-map.test.ts +1 -1
  140. package/src/__tests__/reactive-factory-inlining.test.ts +4 -1
  141. package/src/__tests__/renamed-body-destructure-template.test.ts +7 -7
  142. package/src/__tests__/rest-binding-gaps.test.ts +192 -0
  143. package/src/__tests__/rewrite-destructured-props.test.ts +1 -1
  144. package/src/__tests__/root-prop-alias.test.ts +53 -8
  145. package/src/__tests__/ssr-defaults.test.ts +113 -25
  146. package/src/__tests__/static-loop-csr-materialize.test.ts +2 -2
  147. package/src/__tests__/static-record-literal-array.test.ts +171 -0
  148. package/src/__tests__/string-concat-identifier.test.ts +40 -1
  149. package/src/__tests__/written-binding-substitution.test.ts +8 -8
  150. package/src/adapters/boolean-result.ts +72 -66
  151. package/src/adapters/brace-delimiter-text.ts +25 -0
  152. package/src/adapters/callback-method.ts +159 -27
  153. package/src/adapters/component-props.ts +3 -4
  154. package/src/adapters/computed-const.ts +238 -4
  155. package/src/adapters/dsl-template-adapter.ts +62 -26
  156. package/src/adapters/loop-bound-names.ts +9 -1
  157. package/src/adapters/loop-plan.ts +1 -1
  158. package/src/adapters/loop-row-type.ts +149 -0
  159. package/src/adapters/nil-reading.ts +295 -0
  160. package/src/adapters/non-primitive-equality.ts +92 -0
  161. package/src/adapters/number-value.ts +17 -4
  162. package/src/adapters/operand-typing.ts +522 -0
  163. package/src/adapters/parsed-expr-emitter.ts +183 -19
  164. package/src/adapters/primitive-plan.ts +765 -0
  165. package/src/adapters/prop-classes.ts +16 -3
  166. package/src/analyzer-context.ts +6 -0
  167. package/src/analyzer.ts +532 -26
  168. package/src/augment-inherited-props.ts +108 -10
  169. package/src/compiler.ts +17 -0
  170. package/src/event-handler-name.ts +15 -0
  171. package/src/expression-parser.ts +70 -1
  172. package/src/index.ts +35 -16
  173. package/src/ir-to-client-js/build-references.ts +69 -0
  174. package/src/ir-to-client-js/child-props-object.ts +240 -0
  175. package/src/ir-to-client-js/collect-elements.ts +31 -63
  176. package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +8 -1
  177. package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +31 -28
  178. package/src/ir-to-client-js/control-flow/shared.ts +20 -22
  179. package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +5 -3
  180. package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +2 -2
  181. package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +1 -1
  182. package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +2 -2
  183. package/src/ir-to-client-js/control-flow/stringify/loop.ts +1 -1
  184. package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +3 -3
  185. package/src/ir-to-client-js/html-template.ts +43 -17
  186. package/src/ir-to-client-js/imports.ts +2 -2
  187. package/src/ir-to-client-js/index.ts +53 -11
  188. package/src/ir-to-client-js/phases/props-extraction.ts +11 -7
  189. package/src/ir-to-client-js/plan/build-declaration-emit.ts +40 -7
  190. package/src/ir-to-client-js/plan/build-static-array-child-init.ts +31 -14
  191. package/src/ir-to-client-js/plan/static-array-child-init.ts +27 -18
  192. package/src/ir-to-client-js/prop-handling.ts +22 -3
  193. package/src/ir-to-client-js/prune-unused-prop-extractions.ts +58 -5
  194. package/src/ir-to-client-js/rewrite-destructured-props.ts +31 -1
  195. package/src/ir-to-client-js/stringify/static-array-child-init.ts +26 -10
  196. package/src/jsx-to-ir.ts +459 -37
  197. package/src/nullable-signal-attr.ts +200 -110
  198. package/src/prop-rewrite.ts +30 -6
  199. package/src/props-binding.ts +84 -19
  200. package/src/props-object-whole-read.ts +87 -0
  201. package/src/rich-type-refusal.ts +2 -1
  202. package/src/scope/binding-scope.ts +182 -18
  203. package/src/scope/lexical-scope-walk.ts +4 -3
  204. package/src/scope/root-prop-alias.ts +15 -8
  205. package/src/ssr-defaults.ts +100 -11
  206. package/src/strip-types.ts +31 -3
  207. package/src/template-position-walk.ts +57 -28
  208. package/src/types.ts +87 -0
  209. package/dist/adapters/ambiguous-nil-arithmetic.d.ts +0 -41
  210. package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +0 -1
  211. package/src/adapters/ambiguous-nil-arithmetic.ts +0 -94
@@ -15,9 +15,9 @@
15
15
  * shadow the name are respected.
16
16
  */
17
17
 
18
- import { collectContextConsumers, lookupLiteralConst } from '../augment-inherited-props.ts'
19
- import { freeIdentifiers, inlineBinding, parseExpression, stringifyParsedExpr, type ParsedExpr } from '../expression-parser.ts'
20
- import type { ConstantInfo, ExpressionAttr, IRMetadata } from '../types.ts'
18
+ import { collectContextConsumers, lookupLiteralConst, resolveStaticConstBinding } from '../augment-inherited-props.ts'
19
+ import { freeIdentifiers, inlineBinding, mapParsedExpr, parseExpression, stringifyParsedExpr, type ParsedExpr } from '../expression-parser.ts'
20
+ import type { ConstantInfo, ExpressionAttr, IRMetadata, ParamInfo } from '../types.ts'
21
21
  import { componentBindings } from '../relocate.ts'
22
22
  import { PROPS_OBJECT_IDENTIFIER } from '../scope/binding-scope.ts'
23
23
 
@@ -46,6 +46,8 @@ export interface ComputedConstContext {
46
46
  * (`function C(props: { label: string })`) binds no name.
47
47
  */
48
48
  componentNames: ReadonlySet<string>
49
+ /** The component's props params and props object name, which type an index read (`keyedValue`). */
50
+ props: { params: readonly ParamInfo[]; objectName: string | null }
49
51
  /** Whether a loop row or callback binds `name` where the expression is read. */
50
52
  isShadowed(name: string): boolean
51
53
  /** Whether the adapter binds the const `name` itself, so a read of it stays as written. */
@@ -73,6 +75,7 @@ export function computedConstContext(
73
75
  propReads: propReadKeys(metadata, bindings),
74
76
  localFunctions: new Set(metadata.localFunctions.filter(f => !f.isModule).map(f => f.name)),
75
77
  componentNames: componentScopeNames(metadata),
78
+ props: { params: metadata.propsParams, objectName: metadata.propsObjectName },
76
79
  isShadowed,
77
80
  isAdapterBound,
78
81
  isGlobal: name => !bindings.has(name) && name !== metadata.restPropsName && !isShadowed(name),
@@ -108,7 +111,9 @@ function propsBindingNames(metadata: IRMetadata): Set<string> {
108
111
  * {@link ComputedConstContext.componentNames}. Not `componentBindings`, which
109
112
  * also lists every typed prop of a props object as a `prop` binding.
110
113
  */
111
- function componentScopeNames(metadata: IRMetadata): Set<string> {
114
+ export function componentScopeNames(
115
+ metadata: Pick<IRMetadata, 'propsObjectName' | 'propsParams' | 'restPropsName' | 'localConstants' | 'localFunctions' | 'signals' | 'memos'>,
116
+ ): Set<string> {
112
117
  const names = new Set<string>()
113
118
  if (metadata.propsObjectName !== null) names.add(metadata.propsObjectName)
114
119
  // With no props object the signature destructures, so every param is bound.
@@ -175,6 +180,11 @@ function inlineOnce(expr: ParsedExpr, ctx: ComputedConstContext): ParsedExpr {
175
180
  if (!free) return expr
176
181
  let result = expr
177
182
  for (const name of free) {
183
+ const object = objectConstInitializer(name, ctx)
184
+ if (object) {
185
+ result = projectObjectReads(result, name, object, ctx) ?? result
186
+ continue
187
+ }
178
188
  const init = inlinableInitializer(name, ctx)
179
189
  if (!init) continue
180
190
  result = inlineBinding(result, name, init) ?? inlineUnderCallbacks(result, name, init, ctx) ?? result
@@ -382,3 +392,227 @@ function callsOnlyGetters(init: ParsedExpr, getters: ReadonlySet<string>): boole
382
392
  visit(init)
383
393
  return ok
384
394
  }
395
+
396
+ /**
397
+ * The initializer of a `const` holding an object literal (`const flags = { a:
398
+ * n > 1, label: 'L' + n }`, `const labels = { ok: 'Fine', err: 'Broken' }`)
399
+ * that a read of `name` stands for, resolved in the scope the const is
400
+ * declared in, or `null` when the read stays as it is. The same visibility
401
+ * rules as {@link inlinableInitializer}, with the const a read reaches decided
402
+ * by `resolveStaticConstBinding`; the literal must list plain
403
+ * `key: value` entries only (no spread), so each key's value is known.
404
+ */
405
+ function objectConstInitializer(name: string, ctx: ComputedConstContext): ObjectLiteral | null {
406
+ if (ctx.componentNames.has(name) && !componentConst(name, ctx)) return null
407
+ const constant = resolveStaticConstBinding(name, ctx.constants, n => ctx.isShadowed(n))
408
+ const init = constant?.parsed
409
+ if (!constant || init?.kind !== 'object-literal' || constant.systemConstructKind) return null
410
+ if (literalValues(init) === null) return null
411
+ if (ctx.isShadowed(name) || ctx.getters.has(name) || ctx.contextConsumers.has(name) || ctx.propsBindings.has(name)) return null
412
+ if (ctx.isAdapterBound(name)) return null
413
+ if (!callsOnlyGetters(init, constant.isModule ? new Set() : ctx.getters)) return null
414
+ const resolved = resolveInitializer(init, ctx, n => ctx.isShadowed(n), constant.isModule ? 'module' : 'component')
415
+ return resolved?.kind === 'object-literal' ? resolved : null
416
+ }
417
+
418
+ /**
419
+ * `expr` with each read of a property of the object const `name` replaced by
420
+ * what JS reads there (#3844): `flags.label` by the value the literal gives
421
+ * `label` (`undefined` for a key it does not list), and `labels[kind]` by
422
+ * the conditional that picks the value of the key `kind` equals
423
+ * ({@link keyedValue}). A const that holds an object has no binding in a
424
+ * template, the same as a computed const.
425
+ *
426
+ * An index whose keys are not all known at compile time is read off the
427
+ * literal itself, which the adapter refuses (BF101). `null` (the read stays
428
+ * as written) when `expr` reads `name` whole or reads a key
429
+ * `Object.prototype` holds.
430
+ */
431
+ function projectObjectReads(
432
+ expr: ParsedExpr,
433
+ name: string,
434
+ object: ObjectLiteral,
435
+ ctx: ComputedConstContext,
436
+ ): ParsedExpr | null {
437
+ const objectFree = freeIdentifiers(object) ?? new Set<string>()
438
+ let ok = true
439
+ // What a read chain rooted at `name` (`flags`, `conf.inner`, `labels[k]`)
440
+ // holds, or null for a chain rooted elsewhere.
441
+ const resolve = (e: ParsedExpr, enclosing: ReadonlySet<string>): ParsedExpr | null => {
442
+ if (e.kind === 'identifier') return e.name === name && !enclosing.has(name) ? object : null
443
+ if (e.kind !== 'member' && e.kind !== 'index-access') return null
444
+ const base = resolve(e.object, enclosing)
445
+ if (base === null) return null
446
+ // A read off a value that is not an object (`flags.label.length`) is
447
+ // left to the walk, which projects the inner read.
448
+ if (base.kind !== 'object-literal') return null
449
+ const values = literalValues(base)
450
+ const value = values === null ? undefined : e.kind === 'member' ? memberValue(values, e.property) : keyedValue(values, e.index, enclosing, ctx)
451
+ if (value === undefined) ok = false
452
+ // An index whose keys are not known reads the literal itself, which no
453
+ // template lowers: the adapter refuses it (BF101) instead of reading an
454
+ // unbound name.
455
+ if (value === UNPROVABLE_INDEX && e.kind === 'index-access') return { kind: 'index-access', object: base, index: e.index }
456
+ return value ?? null
457
+ }
458
+ const result = mapParsedExpr(expr, (e, enclosing) => {
459
+ const value = resolve(e, enclosing)
460
+ if (value === null) return null
461
+ // A value read where a callback param rebinds one of its names, or an
462
+ // object read whole, has no projection.
463
+ if (value.kind === 'object-literal' || [...enclosing].some(p => objectFree.has(p))) ok = false
464
+ return value
465
+ })
466
+ return ok ? foldUndefinedTests(result) : null
467
+ }
468
+
469
+ /**
470
+ * `expr` with each conditional whose test compares two operands known at
471
+ * compile time against `undefined` (`'x' === undefined`, `undefined ===
472
+ * undefined`) replaced by the branch it takes. A projected read of a key
473
+ * the literal does or does not list leaves exactly this behind in a
474
+ * destructure default (`conf.tone === undefined ? 'x' : conf.tone`), and a
475
+ * backend need not spell `undefined` the same in every position.
476
+ */
477
+ function foldUndefinedTests(expr: ParsedExpr): ParsedExpr {
478
+ return mapParsedExpr(expr, e => {
479
+ if (e.kind !== 'conditional' || e.test.kind !== 'binary' || (e.test.op !== '===' && e.test.op !== '!==')) return null
480
+ const equal = undefinedEquality(e.test.left, e.test.right)
481
+ if (equal === null) return null
482
+ return foldUndefinedTests((equal === (e.test.op === '===')) ? e.consequent : e.alternate)
483
+ })
484
+ }
485
+
486
+ /** Whether `a === b` holds, when one side is `undefined` and the other a literal or `undefined`; null otherwise. */
487
+ function undefinedEquality(a: ParsedExpr, b: ParsedExpr): boolean | null {
488
+ const isUndefined = (e: ParsedExpr) => e.kind === 'identifier' && e.name === 'undefined'
489
+ const known = (e: ParsedExpr) => isUndefined(e) || e.kind === 'literal'
490
+ if (!known(a) || !known(b) || (!isUndefined(a) && !isUndefined(b))) return null
491
+ return isUndefined(a) && isUndefined(b)
492
+ }
493
+
494
+ type ObjectLiteral = Extract<ParsedExpr, { kind: 'object-literal' }>
495
+
496
+ /** The value of each key `object` lists (the last one for a repeated key), or null when it spreads another object. */
497
+ function literalValues(object: ObjectLiteral): Map<string, ParsedExpr> | null {
498
+ const values = new Map<string, ParsedExpr>()
499
+ for (const p of object.properties) {
500
+ if (p.kind === 'spread') return null
501
+ values.set(p.key, p.value)
502
+ }
503
+ return values
504
+ }
505
+
506
+ /**
507
+ * What `object.<key>` reads: the value the literal gives `key`, and
508
+ * `undefined` for a key it does not list. `undefined` (no projection) for a
509
+ * key `Object.prototype` holds, which JS reads from there.
510
+ */
511
+ function memberValue(values: ReadonlyMap<string, ParsedExpr>, key: string): ParsedExpr | undefined {
512
+ const value = values.get(key)
513
+ if (value) return value
514
+ return key in Object.prototype ? undefined : { kind: 'identifier', name: 'undefined' }
515
+ }
516
+
517
+ /** {@link keyedValue}'s answer for an index whose keys are not all known. */
518
+ const UNPROVABLE_INDEX: ParsedExpr = { kind: 'unsupported', raw: '', reason: 'index keys not known at compile time' }
519
+
520
+ /**
521
+ * `values[index]` as a conditional over the keys the index can hold, with
522
+ * `undefined` for one the literal does not list ({@link projectObjectReads}).
523
+ * Sound only when every key the index can hold is known: its type is a
524
+ * union of string literals (plus `null` / `undefined`) — a prop typed
525
+ * `'ok' | 'err'` — so strict equality with each key is the property lookup
526
+ * JS does. {@link UNPROVABLE_INDEX} otherwise, and also when the index calls
527
+ * something other than a signal or memo getter (the conditional repeats
528
+ * it), when a key it can hold is inherited from `Object.prototype`
529
+ * (`labels['toString']` reads a function), or when it can be `null` /
530
+ * `undefined` and the literal lists `'null'` / `'undefined'`.
531
+ */
532
+ function keyedValue(
533
+ values: ReadonlyMap<string, ParsedExpr>,
534
+ index: ParsedExpr,
535
+ enclosing: ReadonlySet<string>,
536
+ ctx: ComputedConstContext,
537
+ ): ParsedExpr {
538
+ if (!readsOnly(index, ctx.getters)) return UNPROVABLE_INDEX
539
+ // A computed const in the index (`const variant = props.variant ?? 'x'`)
540
+ // is typed as what it holds.
541
+ const domain = indexKeyDomain(inlineComputedConsts(index, ctx), enclosing, ctx)
542
+ if (domain === null) return UNPROVABLE_INDEX
543
+ if (domain.keys.some(k => !values.has(k) && k in Object.prototype)) return UNPROVABLE_INDEX
544
+ if (domain.nullish.some(k => values.has(k))) return UNPROVABLE_INDEX
545
+ let result: ParsedExpr = { kind: 'identifier', name: 'undefined' }
546
+ for (const key of [...domain.keys].reverse()) {
547
+ const value = values.get(key)
548
+ if (!value) continue
549
+ result = {
550
+ kind: 'conditional',
551
+ test: { kind: 'binary', op: '===', left: index, right: { kind: 'literal', value: key, literalType: 'string' } },
552
+ consequent: value,
553
+ alternate: result,
554
+ }
555
+ }
556
+ return result
557
+ }
558
+
559
+ /** The keys an index can hold ({@link keyedValue}): string keys, and whether it can be `null` / `undefined`. */
560
+ interface KeyDomain {
561
+ keys: string[]
562
+ nullish: Array<'null' | 'undefined'>
563
+ }
564
+
565
+ /**
566
+ * The keys an index read can hold, from its declared type: a prop read
567
+ * (`kind`, `props.kind`) whose declared type admits only string literals,
568
+ * `null` and `undefined` (`ParamInfo.literalKeys`; an optional prop adds
569
+ * `undefined`), or `a ?? 'x'` over such a read. `null` for any other index, including a name a loop row or callback
570
+ * binds.
571
+ */
572
+ function indexKeyDomain(index: ParsedExpr, enclosing: ReadonlySet<string>, ctx: ComputedConstContext): KeyDomain | null {
573
+ if (index.kind === 'logical' && index.op === '??') {
574
+ const left = indexKeyDomain(index.left, enclosing, ctx)
575
+ const right = index.right.kind === 'literal' && typeof index.right.value === 'string' ? index.right.value : null
576
+ if (!left || right === null) return left === null || right === null ? null : left
577
+ return left.nullish.length === 0 ? left : { keys: [...new Set([...left.keys, right])], nullish: [] }
578
+ }
579
+ const param = indexPropParam(index, enclosing, ctx)
580
+ if (!param) return null
581
+ if (!param.literalKeys) return null
582
+ const domain: KeyDomain = { keys: [...param.literalKeys.keys], nullish: [...param.literalKeys.nullish] }
583
+ const readsDefault = index.kind === 'identifier' && param.defaultValue !== undefined
584
+ if (param.optional && !readsDefault && !domain.nullish.includes('undefined')) domain.nullish.push('undefined')
585
+ return domain
586
+ }
587
+
588
+ /** The prop param an index read reads whole (`kind`, `props.kind`), or undefined. */
589
+ function indexPropParam(index: ParsedExpr, enclosing: ReadonlySet<string>, ctx: ComputedConstContext): ParamInfo | undefined {
590
+ const visible = (n: string) => !enclosing.has(n) && !ctx.isShadowed(n)
591
+ const params = ctx.props.params.filter(p => !p.isRest)
592
+ if (index.kind === 'identifier') {
593
+ if (!visible(index.name)) return undefined
594
+ if (ctx.props.objectName !== null && !ctx.propsBindings.has(index.name)) return undefined
595
+ return params.find(p => p.name === index.name)
596
+ }
597
+ if (index.kind !== 'member' || index.object.kind !== 'identifier' || index.object.name !== ctx.props.objectName) return undefined
598
+ if (!visible(index.object.name)) return undefined
599
+ return params.find(p => p.sourceName === undefined && p.name === index.property)
600
+ }
601
+
602
+ /** Whether evaluating `expr` twice reads the same value: it calls nothing but signal and memo getters, and holds no function. */
603
+ function readsOnly(expr: ParsedExpr, getters: ReadonlySet<string>): boolean {
604
+ let ok = true
605
+ const visit = (node: unknown): void => {
606
+ if (!ok || node === null || typeof node !== 'object') return
607
+ if (Array.isArray(node)) {
608
+ node.forEach(visit)
609
+ return
610
+ }
611
+ const e = node as ParsedExpr
612
+ if (e.kind === 'arrow' || e.kind === 'unsupported') ok = false
613
+ else if (e.kind === 'call' && !(e.callee.kind === 'identifier' && e.args.length === 0 && getters.has(e.callee.name))) ok = false
614
+ else for (const value of Object.values(e)) visit(value)
615
+ }
616
+ visit(expr)
617
+ return ok
618
+ }
@@ -10,12 +10,15 @@ import { buildImportAliasMap } from '../ir-to-client-js/component-scope.ts'
10
10
  import { prepareLoweringMatchers, type LoweringMatcher } from '../lowering-registry.ts'
11
11
  import type { ParsedExpr } from '../expression-parser.ts'
12
12
  import {
13
+ arithmeticOperandCoercion,
13
14
  collectNullableSignalGetters,
14
15
  collectNullishAttrContext,
15
16
  type ArithmeticCoercion,
16
17
  type NullishAttrContext,
17
18
  } from '../nullable-signal-attr.ts'
18
19
  import { BindingScope } from '../scope/binding-scope.ts'
20
+ import { declaredValueType, declaredValueTypes, loopRowType, type DeclaredValueTypes } from './loop-row-type.ts'
21
+ import { collectOperandTyping, EMPTY_OPERAND_TYPING, factsOfType, type OperandTyping, type ScopedOperandTyping } from './operand-typing.ts'
19
22
  import { rootPropAliasesForLoop, rootPropAliasNames } from '../scope/root-prop-alias.ts'
20
23
  import type {
21
24
  CompilerError,
@@ -26,12 +29,7 @@ import type {
26
29
  IRMetadata,
27
30
  PreambleValueDeclaration,
28
31
  } from '../types.ts'
29
- import {
30
- arithmeticCoercionOrRefuse,
31
- refuseAmbiguousNilArithmetic,
32
- refuseAmbiguousNilMemoArithmetic,
33
- type AmbiguousNilArithmeticSink,
34
- } from './ambiguous-nil-arithmetic.ts'
32
+ import { refuseNonPrimitiveStrictEquality, type NonPrimitiveEqualitySink } from './non-primitive-equality.ts'
35
33
  import { collectImportedLoopChildComponentErrors } from './component-tree.ts'
36
34
  import { computedConstContext, type ComputedConstContext } from './computed-const.ts'
37
35
  import { searchParamsLocalNames } from './env-signal.ts'
@@ -128,6 +126,14 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
128
126
  protected booleanTypedProps: Set<string> = new Set()
129
127
  /** Names (signal getters + props) whose value is a string (`stringValueNamesFor`). */
130
128
  protected stringValueNames: Set<string> = new Set()
129
+ /** The declared types a loop row's type is read from (`loopRowType`, #3762). */
130
+ protected declaredTypes: DeclaredValueTypes | null = null
131
+ /**
132
+ * The component's operand typing (`collectOperandTyping`), which the
133
+ * emitters' primitive plans read through the scope at the emission site
134
+ * (`operandTypingAt`, #3824).
135
+ */
136
+ protected operandTyping: OperandTyping = EMPTY_OPERAND_TYPING
131
137
  /**
132
138
  * Module-scope pure-string consts (`const x = 'literal'`), keyed by name →
133
139
  * unescaped value. A className template literal that references such a
@@ -221,6 +227,28 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
221
227
  */
222
228
  protected resetAdapterState(_ir: ComponentIR): void {}
223
229
 
230
+ /**
231
+ * Whether `name` (a signal getter, prop, local constant or loop binding)
232
+ * holds a string value at `scope`, which picks the template's string
233
+ * concatenation for a JS `+` (`isStringConcatBinary`). A loop row or
234
+ * callback binding of the same name shadows the outer typing; a row field
235
+ * read (`path`: `row.id`) takes the row type's declared field type.
236
+ * `componentProperty`: read as `props.<name>`.
237
+ */
238
+ protected isStringValueNameAt(
239
+ name: string,
240
+ componentProperty = false,
241
+ path: readonly string[] = [],
242
+ scope: BindingScope = this.scope,
243
+ ): boolean {
244
+ return scope.isStringValueName(name, n => this.stringValueNames.has(n), componentProperty, path, this.declaredTypes?.namedFields)
245
+ }
246
+
247
+ /** The component's operand typing at `scope` (the emission site's, by default). */
248
+ protected operandTypingAt(scope: BindingScope = this.scope): ScopedOperandTyping {
249
+ return this.operandTyping.at(scope)
250
+ }
251
+
224
252
  /** `render()` under `scope`, the current scope restored afterwards. */
225
253
  protected renderInScope<T>(scope: BindingScope, render: () => T): T {
226
254
  const outer = this.scope
@@ -234,9 +262,8 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
234
262
 
235
263
  /**
236
264
  * The coercion an arithmetic operand's emitter spells
237
- * (`arithmeticOperandCoercion`), refusing an operand whose nil the
238
- * declared type cannot classify (`arithmeticCoercionOrRefuse`, #3700).
239
- * `isShadowed` is the adapter's scope test at the emission site.
265
+ * (`arithmeticOperandCoercion`). `isShadowed` is the adapter's scope test
266
+ * at the emission site.
240
267
  */
241
268
  protected arithmeticCoercion(
242
269
  op: string,
@@ -244,21 +271,10 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
244
271
  other: ParsedExpr | undefined,
245
272
  isShadowed: (name: string) => boolean,
246
273
  ): ArithmeticCoercion {
247
- return arithmeticCoercionOrRefuse(op, operand, other, this.nullishAttrCtx, isShadowed, this.ambiguousNilSink())
274
+ return arithmeticOperandCoercion(op, operand, other, this.nullishAttrCtx, isShadowed)
248
275
  }
249
276
 
250
- /**
251
- * Refuse the ambiguous-nil arithmetic (#3700) in a whole expression the
252
- * adapter lowers through its own renderer rather than per operator: a
253
- * `.filter()` predicate, read in the current scope with the callback's
254
- * own `params` (its parameter and block locals) entered as a callback
255
- * frame.
256
- */
257
- protected refuseAmbiguousNilArithmeticIn(expr: ParsedExpr, params: readonly string[]): void {
258
- refuseAmbiguousNilArithmetic(expr, this.nullishAttrCtx, this.scope.enterCallback(params), this.ambiguousNilSink())
259
- }
260
-
261
- private ambiguousNilSink(): AmbiguousNilArithmeticSink {
277
+ private errorSink(): NonPrimitiveEqualitySink {
262
278
  return { errors: this.errors, componentName: this.componentName }
263
279
  }
264
280
 
@@ -317,7 +333,8 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
317
333
  */
318
334
  protected renderLoopRow(loop: IRLoop, spelling: LoopRowSpelling): LoopRow {
319
335
  const outside = this.scope
320
- const row = outside.enterLoopRow(loop)
336
+ const rowType = this.declaredTypes ? loopRowType(this.declaredTypes, loop, outside) : null
337
+ const row = outside.enterLoopRow(rowType ? { ...loop, rowType } : loop)
321
338
  return this.renderInScope(row, () => {
322
339
  spelling.enter?.(row, outside)
323
340
  const preamble = (loop.preamble?.declarations ?? []).map(d => spelling.preamble(d))
@@ -404,11 +421,16 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
404
421
  this.booleanTypedProps = collectBooleanTypedProps(ir)
405
422
  this.localConstants = ir.metadata.localConstants ?? []
406
423
  this.rootPropAliases = rootPropAliasNames(ir, this.propsParams.map(p => p.name))
407
- this.scope = BindingScope.EMPTY
424
+ this.scope = BindingScope.forComponent(this.propsObjectName)
408
425
  this.nullableOptionalProps = collectNullableOptionalProps(ir)
409
- this.nullableSignalGetters = collectNullableSignalGetters(ir)
410
426
  this.nullishAttrCtx = collectNullishAttrContext(ir)
411
427
  this.stringValueNames = this.stringValueNamesFor(ir)
428
+ this.declaredTypes = declaredValueTypes(ir)
429
+ this.nullableSignalGetters = new Set([
430
+ ...collectNullableSignalGetters(ir),
431
+ ...memberSeededNilSignals(ir, this.declaredTypes, this.scope),
432
+ ])
433
+ this.operandTyping = collectOperandTyping(ir.metadata, { namedFields: this.declaredTypes.namedFields })
412
434
  this.moduleStringConsts = collectModuleStringConsts(ir.metadata.localConstants)
413
435
  this._searchParamsLocals = searchParamsLocalNames(ir.metadata)
414
436
  this._loweringMatchers = prepareLoweringMatchers(ir.metadata)
@@ -435,6 +457,20 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
435
457
  if (!options?.siblingTemplatesRegistered) {
436
458
  this.errors.push(...collectImportedLoopChildComponentErrors(ir, this.componentName, this.loopChildDiagnosticName))
437
459
  }
438
- refuseAmbiguousNilMemoArithmetic(ir.metadata.memos ?? [], this.nullishAttrCtx, this.ambiguousNilSink())
460
+ // `===` / `!==` over an object or array (#3774, #3824 step 8).
461
+ refuseNonPrimitiveStrictEquality(ir, this.operandTyping, this.errorSink())
439
462
  }
440
463
  }
464
+
465
+ /**
466
+ * Getters of signals seeded from a member of a prop whose declared type
467
+ * admits `null` or `undefined` (`type Init = { label?: string }`,
468
+ * `createSignal(initial.label)`): the signal holds the field's JS value, so
469
+ * an attribute bound to it is omitted when that value is nullish, as for any
470
+ * other nullable signal (`collectNullableSignalGetters`).
471
+ */
472
+ function memberSeededNilSignals(ir: ComponentIR, types: DeclaredValueTypes, scope: BindingScope): string[] {
473
+ return (ir.metadata.signals ?? [])
474
+ .filter(s => s.parsed?.kind === 'member' && factsOfType(declaredValueType(types, s.parsed, scope)).types.has('nil'))
475
+ .map(s => s.getter)
476
+ }
@@ -1,7 +1,15 @@
1
1
  /**
2
2
  * Every name a `.map()`/`.filter()` loop callback binds as its item or
3
3
  * index parameter, anywhere in a component's IR tree (#2212 review
4
- * finding). `isStringTypedOperand`'s identifier arm resolves a bare
4
+ * finding).
5
+ *
6
+ * The string-typing use described below is retired: every template adapter
7
+ * now resolves a name's string typing at the read through the shared
8
+ * `BindingScope` (#3762), and no longer subtracts this set. The remaining
9
+ * callers use it as a whole-component "may be shadowed somewhere" set
10
+ * (root prop aliases, Go's static loop sources, Xslate's memo seeds).
11
+ *
12
+ * Original rationale: `isStringTypedOperand`'s identifier arm resolves a bare
5
13
  * identifier against `collectStringValueNames`'s flat, scope-BLIND
6
14
  * `Set<string>` — so a loop callback whose param happens to reuse a
7
15
  * string prop's name (`items.map((name) => ... 1 + name ...)`, where the
@@ -298,7 +298,7 @@ export function planLoop<Spelled>(loop: IRLoop, ctx: LoopPlanContext<Spelled>):
298
298
  destructure,
299
299
  staticSource,
300
300
  unresolvableConst: staticSource === null ? unresolvableConst(loop, ctx) : null,
301
- sort: loop.sortComparator ? lowerSortComparator('sort', loop.sortComparator.arrow, ctx.callbackLowering.adapterName) : null,
301
+ sort: loop.sortComparator ? lowerSortComparator('sort', loop.sortComparator.arrow, ctx.callbackLowering.adapterName, ctx.scope.propsObject) : null,
302
302
  captureAliases,
303
303
  filter: filterPlan(loop, captureAliases, ctx.callbackLowering.adapterName),
304
304
  itemVar: loop.iterationShape === 'keys' || destructure === 'lowerable' ? '__bf_item' : loop.param,
@@ -0,0 +1,149 @@
1
+ /**
2
+ * The declared element type of the array a loop ranges over, read from the
3
+ * component's IR: a prop (`props.rows`, a destructured `rows`), a signal or
4
+ * memo getter (`items()`), a row field of an enclosing loop (`r.tags`), an
5
+ * index into one of those, and a `filter` / `slice` / `sort` chain over them.
6
+ * A template adapter enters a loop row with it as
7
+ * `LoopBindingSource.rowType`, so the row's bindings resolve their field types
8
+ * at the read (`row.id`, a destructured `id`) through the shared
9
+ * `BindingScope` (#3762). The IR's `itemType` carries scalar evidence only.
10
+ */
11
+
12
+ import type { ParsedExpr } from '../expression-parser.ts'
13
+ import type { ComponentIR, TypeInfo } from '../types.ts'
14
+ import {
15
+ arrayElementType,
16
+ loopValueTypeAt,
17
+ unionOfLoopValueTypes,
18
+ type BindingScope,
19
+ type LoopValueType,
20
+ type NamedTypeFields,
21
+ } from '../scope/binding-scope.ts'
22
+
23
+ /**
24
+ * Array methods whose result has the receiver's element type. `concat` is
25
+ * not one: its result also holds its arguments' elements ({@link concatType}).
26
+ */
27
+ const SAME_ELEMENT_METHODS: ReadonlySet<string> = new Set([
28
+ 'filter', 'slice', 'sort', 'toSorted', 'reverse', 'toReversed',
29
+ ])
30
+
31
+ /** What a component declares about the types of the values it reads. */
32
+ export interface DeclaredValueTypes {
33
+ readonly propsParams: readonly {
34
+ readonly name: string
35
+ readonly type: TypeInfo
36
+ readonly declaredType?: TypeInfo
37
+ readonly isRest?: boolean
38
+ }[]
39
+ readonly signals: readonly { readonly getter: string; readonly type: TypeInfo }[]
40
+ readonly memos: readonly { readonly name: string; readonly type: TypeInfo }[]
41
+ /** The identifier the component reads its props object as (`props`); null for a destructured signature. */
42
+ readonly propsObjectName: string | null
43
+ readonly namedFields: NamedTypeFields
44
+ }
45
+
46
+ /** {@link DeclaredValueTypes} of a component. */
47
+ export function declaredValueTypes(ir: ComponentIR): DeclaredValueTypes {
48
+ const { propsParams, signals, memos, typeDefinitions, propsObjectName } = ir.metadata
49
+ return {
50
+ propsParams,
51
+ signals,
52
+ memos,
53
+ propsObjectName: propsObjectName ?? null,
54
+ namedFields: name => typeDefinitions.find(td => td.name === name)?.properties,
55
+ }
56
+ }
57
+
58
+ /** The element type of the array `loop` ranges over; null when it is not declared. */
59
+ export function loopRowType(
60
+ types: DeclaredValueTypes,
61
+ loop: { readonly arrayParsed?: ParsedExpr; readonly iterationShape?: string; readonly objectIteration?: unknown },
62
+ scope: BindingScope,
63
+ ): LoopValueType | null {
64
+ // An `.entries()` / `Object.entries(…)` row is a tuple, not an element.
65
+ if (loop.iterationShape !== undefined || loop.objectIteration || !loop.arrayParsed) return null
66
+ const type = valueType(types, loop.arrayParsed, scope)
67
+ return arrayElementType(type) ?? null
68
+ }
69
+
70
+ /**
71
+ * The declared type of the value `expr` reads in `scope` (a prop, a member
72
+ * path below one, a loop row, a signal or memo getter), or null when the
73
+ * declarations do not say. An optional field below the root admits
74
+ * `undefined` (`loopValueTypeAt`).
75
+ */
76
+ export function declaredValueType(types: DeclaredValueTypes, expr: ParsedExpr, scope: BindingScope): LoopValueType | null {
77
+ return valueType(types, expr, scope)
78
+ }
79
+
80
+ function valueType(types: DeclaredValueTypes, expr: ParsedExpr, scope: BindingScope): LoopValueType | null {
81
+ switch (expr.kind) {
82
+ case 'identifier': {
83
+ const hit = scope.lookup(expr.name)
84
+ if (!hit) return propType(types, expr.name)
85
+ const row = hit.binding.row
86
+ return row ? loopValueTypeAt(row.itemType, row.segments, types.namedFields) : null
87
+ }
88
+ case 'member': {
89
+ if (expr.computed) return null
90
+ if (expr.object.kind === 'identifier' && expr.object.name === types.propsObjectName && !scope.isBound(expr.object.name)) {
91
+ return propType(types, expr.property)
92
+ }
93
+ const object = valueType(types, expr.object, scope)
94
+ return object && loopValueTypeAt(object, [{ kind: 'field', key: expr.property, isIdent: true }], types.namedFields)
95
+ }
96
+ case 'index-access': {
97
+ const object = valueType(types, expr.object, scope)
98
+ return arrayElementType(object) ?? null
99
+ }
100
+ case 'call':
101
+ return callType(types, expr, scope)
102
+ case 'array-method':
103
+ if (expr.method === 'concat') {
104
+ return concatType(valueType(types, expr.object, scope), expr.args.map(arg => valueType(types, arg, scope)))
105
+ }
106
+ return SAME_ELEMENT_METHODS.has(expr.method) ? valueType(types, expr.object, scope) : null
107
+ default:
108
+ return null
109
+ }
110
+ }
111
+
112
+ /**
113
+ * The type of `receiver.concat(...args)`: an array whose element type is the
114
+ * union of the receiver's element type and each argument's (an array
115
+ * argument's elements, or the argument itself). A field read on a row of it
116
+ * is then a definite string only when it is one in every member
117
+ * (`loopValueTypeAt`), so an `any[]` argument or a field one member lacks
118
+ * types nothing (#3762 review). An argument of unknown type leaves the
119
+ * result with no element type.
120
+ */
121
+ export function concatType<T extends LoopValueType>(receiver: T | null, args: readonly (T | null)[]): T | null {
122
+ const element = arrayElementType(receiver)
123
+ if (!receiver || !element) return receiver
124
+ const asArray = (elementType: T | undefined): T => ({ ...receiver, kind: 'array', unionTypes: undefined, elementType })
125
+ if (args.some(arg => arg === null)) return asArray(undefined)
126
+ const members = [element, ...(args as T[]).map(arg => arrayElementType(arg) ?? arg)]
127
+ return asArray(unionOfLoopValueTypes(members))
128
+ }
129
+
130
+ /** A prop's declared type; a destructured prop whose type stays `unknown` carries it as `declaredType`. */
131
+ /** A signal or memo getter's type, or the receiver's type through an element-keeping array method. */
132
+ function callType(types: DeclaredValueTypes, expr: Extract<ParsedExpr, { kind: 'call' }>, scope: BindingScope): LoopValueType | null {
133
+ const callee = expr.callee
134
+ if (callee.kind === 'identifier' && expr.args.length === 0 && !scope.isBound(callee.name)) {
135
+ return types.signals.find(s => s.getter === callee.name)?.type ??
136
+ types.memos.find(m => m.name === callee.name)?.type ?? null
137
+ }
138
+ if (callee.kind !== 'member' || callee.computed) return null
139
+ if (callee.property === 'concat') {
140
+ return concatType(valueType(types, callee.object, scope), expr.args.map(arg => valueType(types, arg, scope)))
141
+ }
142
+ return SAME_ELEMENT_METHODS.has(callee.property) ? valueType(types, callee.object, scope) : null
143
+ }
144
+
145
+ function propType(types: DeclaredValueTypes, name: string): LoopValueType | null {
146
+ const param = types.propsParams.find(p => !p.isRest && p.name === name)
147
+ if (!param) return null
148
+ return param.type.kind === 'unknown' ? param.declaredType ?? null : param.type
149
+ }