@barefootjs/jsx 0.39.7 → 0.39.9

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 (192) hide show
  1. package/dist/adapters/callback-method.d.ts +36 -7
  2. package/dist/adapters/callback-method.d.ts.map +1 -1
  3. package/dist/adapters/component-props.d.ts +80 -13
  4. package/dist/adapters/component-props.d.ts.map +1 -1
  5. package/dist/adapters/dsl-template-adapter.d.ts +153 -0
  6. package/dist/adapters/dsl-template-adapter.d.ts.map +1 -0
  7. package/dist/adapters/jsx-adapter.d.ts +4 -0
  8. package/dist/adapters/jsx-adapter.d.ts.map +1 -1
  9. package/dist/adapters/literal-value.d.ts +2 -2
  10. package/dist/adapters/literal-value.d.ts.map +1 -1
  11. package/dist/adapters/loop-plan.d.ts +133 -9
  12. package/dist/adapters/loop-plan.d.ts.map +1 -1
  13. package/dist/adapters/parsed-expr-emitter.d.ts +44 -0
  14. package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
  15. package/dist/adapters/style-object.d.ts +33 -0
  16. package/dist/adapters/style-object.d.ts.map +1 -0
  17. package/dist/analyzer.d.ts.map +1 -1
  18. package/dist/assignment-target.d.ts +26 -0
  19. package/dist/assignment-target.d.ts.map +1 -0
  20. package/dist/children-nullish.d.ts +22 -0
  21. package/dist/children-nullish.d.ts.map +1 -0
  22. package/dist/errors.d.ts +2 -0
  23. package/dist/errors.d.ts.map +1 -1
  24. package/dist/expression-parser.d.ts +9 -19
  25. package/dist/expression-parser.d.ts.map +1 -1
  26. package/dist/free-refs.d.ts +6 -0
  27. package/dist/free-refs.d.ts.map +1 -1
  28. package/dist/index.d.ts +17 -14
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +15040 -13899
  31. package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
  33. package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts +2 -1
  34. package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts.map +1 -1
  35. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -2
  36. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
  37. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +24 -1
  38. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
  39. package/dist/ir-to-client-js/control-flow/shared.d.ts +16 -1
  40. package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
  41. package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts +6 -1
  42. package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
  43. package/dist/ir-to-client-js/control-flow/stringify/event-delegation.d.ts.map +1 -1
  44. package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts +10 -9
  45. package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
  46. package/dist/ir-to-client-js/csr-substitute.d.ts +13 -2
  47. package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
  48. package/dist/ir-to-client-js/emit-reactive.d.ts +1 -1
  49. package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
  50. package/dist/ir-to-client-js/emit-registration.d.ts +10 -8
  51. package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
  52. package/dist/ir-to-client-js/generate-init.d.ts.map +1 -1
  53. package/dist/ir-to-client-js/html-template.d.ts +0 -9
  54. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  55. package/dist/ir-to-client-js/identifiers.d.ts +6 -8
  56. package/dist/ir-to-client-js/identifiers.d.ts.map +1 -1
  57. package/dist/ir-to-client-js/imports.d.ts +23 -2
  58. package/dist/ir-to-client-js/imports.d.ts.map +1 -1
  59. package/dist/ir-to-client-js/phases/props-extraction.d.ts +6 -3
  60. package/dist/ir-to-client-js/phases/props-extraction.d.ts.map +1 -1
  61. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +8 -0
  62. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
  63. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +1 -1
  64. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
  65. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  66. package/dist/ir-to-client-js/rewrite-destructured-props.d.ts +1 -1
  67. package/dist/ir-to-client-js/rewrite-destructured-props.d.ts.map +1 -1
  68. package/dist/ir-to-client-js/rewrite-props-object.d.ts.map +1 -1
  69. package/dist/ir-to-client-js/safe-html.d.ts +20 -2
  70. package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
  71. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts +1 -0
  72. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
  73. package/dist/ir-to-client-js/types.d.ts +3 -3
  74. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  75. package/dist/ir-to-client-js/utils.d.ts +2 -11
  76. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  77. package/dist/jsx-to-ir.d.ts.map +1 -1
  78. package/dist/nullable-signal-attr.d.ts +40 -10
  79. package/dist/nullable-signal-attr.d.ts.map +1 -1
  80. package/dist/prop-rewrite.d.ts +35 -8
  81. package/dist/prop-rewrite.d.ts.map +1 -1
  82. package/dist/props-binding.d.ts +66 -1
  83. package/dist/props-binding.d.ts.map +1 -1
  84. package/dist/scanner/js-scanner.d.ts.map +1 -1
  85. package/dist/scanner/js-scanner.js +30 -2
  86. package/dist/scope/binding-scope.d.ts +30 -2
  87. package/dist/scope/binding-scope.d.ts.map +1 -1
  88. package/dist/scope/lexical-scope-walk.d.ts +26 -0
  89. package/dist/scope/lexical-scope-walk.d.ts.map +1 -0
  90. package/dist/signal-prop-name-collision.d.ts +6 -5
  91. package/dist/signal-prop-name-collision.d.ts.map +1 -1
  92. package/dist/ssr-defaults.d.ts +28 -0
  93. package/dist/ssr-defaults.d.ts.map +1 -1
  94. package/dist/ssr-seed-plan.d.ts +39 -14
  95. package/dist/ssr-seed-plan.d.ts.map +1 -1
  96. package/dist/types.d.ts +133 -19
  97. package/dist/types.d.ts.map +1 -1
  98. package/dist/value-references.d.ts +21 -0
  99. package/dist/value-references.d.ts.map +1 -1
  100. package/package.json +2 -2
  101. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +18 -18
  102. package/src/__tests__/adapter-output.test.ts +5 -3
  103. package/src/__tests__/analyzer.test.ts +33 -0
  104. package/src/__tests__/arithmetic-lowering.test.ts +48 -0
  105. package/src/__tests__/binding-scope.test.ts +29 -0
  106. package/src/__tests__/children-read.test.ts +226 -0
  107. package/src/__tests__/client-template-escape-soundness.test.ts +31 -1
  108. package/src/__tests__/component-props.test.ts +68 -1
  109. package/src/__tests__/constant-inlining-tree.test.ts +136 -0
  110. package/src/__tests__/create-query.test.ts +1 -1
  111. package/src/__tests__/destructure-default-reads-earlier-param.test.ts +138 -0
  112. package/src/__tests__/dsl-template-adapter.test.ts +173 -0
  113. package/src/__tests__/emit-to-string-call.test.ts +58 -0
  114. package/src/__tests__/event-handler-verbatim.test.ts +73 -0
  115. package/src/__tests__/expression-parser.test.ts +1 -44
  116. package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +90 -31
  117. package/src/__tests__/loop-plan.test.ts +131 -1
  118. package/src/__tests__/loop-row-child-children-handler.test.ts +129 -0
  119. package/src/__tests__/loop-row-child-children-inner-loop-shadow.test.ts +74 -0
  120. package/src/__tests__/loop-row-child-children-ref.test.ts +117 -0
  121. package/src/__tests__/nullable-signal-attr.test.ts +67 -3
  122. package/src/__tests__/props-alias-const.test.ts +60 -1
  123. package/src/__tests__/props-named-callback-param.test.ts +256 -0
  124. package/src/__tests__/reference-graph-identifiers.test.ts +161 -0
  125. package/src/__tests__/renamed-body-destructure-template.test.ts +86 -0
  126. package/src/__tests__/rewrite-props-object.test.ts +90 -0
  127. package/src/__tests__/runtime-import-detection.test.ts +134 -0
  128. package/src/__tests__/signal-prop-name-collision.test.ts +30 -0
  129. package/src/__tests__/ssr-defaults.test.ts +19 -1
  130. package/src/__tests__/ssr-seed-plan.test.ts +119 -0
  131. package/src/__tests__/style-object-plan.test.ts +54 -0
  132. package/src/__tests__/written-binding-substitution.test.ts +430 -0
  133. package/src/__tests__/zero-param-helper-inline.test.ts +57 -0
  134. package/src/adapters/callback-method.ts +48 -10
  135. package/src/adapters/component-props.ts +130 -12
  136. package/src/adapters/dsl-template-adapter.ts +259 -0
  137. package/src/adapters/jsx-adapter.ts +12 -6
  138. package/src/adapters/literal-value.ts +2 -2
  139. package/src/adapters/loop-plan.ts +201 -13
  140. package/src/adapters/parsed-expr-emitter.ts +67 -0
  141. package/src/adapters/style-object.ts +61 -0
  142. package/src/analyzer.ts +396 -16
  143. package/src/assignment-target.ts +79 -0
  144. package/src/children-nullish.ts +33 -0
  145. package/src/debug.ts +2 -2
  146. package/src/errors.ts +23 -0
  147. package/src/expression-parser.ts +56 -53
  148. package/src/free-refs.ts +28 -17
  149. package/src/index.ts +31 -10
  150. package/src/ir-to-client-js/compute-inlinability.ts +35 -5
  151. package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +21 -5
  152. package/src/ir-to-client-js/control-flow/plan/event-collision.ts +2 -1
  153. package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -2
  154. package/src/ir-to-client-js/control-flow/plan/loop.ts +25 -1
  155. package/src/ir-to-client-js/control-flow/shared.ts +41 -3
  156. package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +23 -3
  157. package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +3 -2
  158. package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +13 -12
  159. package/src/ir-to-client-js/csr-substitute.ts +82 -24
  160. package/src/ir-to-client-js/emit-reactive.ts +3 -3
  161. package/src/ir-to-client-js/emit-registration.ts +34 -58
  162. package/src/ir-to-client-js/generate-init.ts +17 -1
  163. package/src/ir-to-client-js/html-template.ts +48 -57
  164. package/src/ir-to-client-js/identifiers.ts +75 -24
  165. package/src/ir-to-client-js/imports.ts +56 -19
  166. package/src/ir-to-client-js/index.ts +2 -1
  167. package/src/ir-to-client-js/phases/event-handlers.ts +2 -2
  168. package/src/ir-to-client-js/phases/props-extraction.ts +39 -17
  169. package/src/ir-to-client-js/plan/build-declaration-emit.ts +2 -2
  170. package/src/ir-to-client-js/plan/build-static-array-child-init.ts +7 -0
  171. package/src/ir-to-client-js/plan/static-array-child-init.ts +8 -0
  172. package/src/ir-to-client-js/prune-unused-prop-extractions.ts +7 -4
  173. package/src/ir-to-client-js/reactivity.ts +2 -2
  174. package/src/ir-to-client-js/rewrite-destructured-props.ts +22 -5
  175. package/src/ir-to-client-js/rewrite-props-object.ts +14 -8
  176. package/src/ir-to-client-js/safe-html.ts +29 -35
  177. package/src/ir-to-client-js/stringify/static-array-child-init.ts +4 -1
  178. package/src/ir-to-client-js/types.ts +3 -2
  179. package/src/ir-to-client-js/utils.ts +42 -122
  180. package/src/jsx-to-ir.ts +310 -90
  181. package/src/nullable-signal-attr.ts +149 -33
  182. package/src/prop-rewrite.ts +72 -72
  183. package/src/props-binding.ts +90 -3
  184. package/src/scanner/__tests__/js-scanner.test.ts +37 -0
  185. package/src/scanner/js-scanner.ts +64 -4
  186. package/src/scope/binding-scope.ts +34 -3
  187. package/src/scope/lexical-scope-walk.ts +167 -0
  188. package/src/signal-prop-name-collision.ts +50 -24
  189. package/src/ssr-defaults.ts +47 -20
  190. package/src/ssr-seed-plan.ts +103 -23
  191. package/src/types.ts +140 -20
  192. package/src/value-references.ts +132 -0
package/src/analyzer.ts CHANGED
@@ -9,11 +9,12 @@
9
9
  import ts from 'typescript'
10
10
  import { foldRenderReassignmentsInSource } from './fold-render-reassignments.ts'
11
11
  import { CLIENT_DIRECTIVE_INTERIOR_RE, USE_CLIENT_DIRECTIVE, isUseClientDirectiveText } from './directives.ts'
12
- import type { ImportSpecifier, TypeInfo, ParamInfo, ReactiveFactoryInfo, DeclinedReactiveFactory, RequiredFactoryImport, FactoryRenameSite, SourceLocation, SignalFactoryCall, MemoInfo } from './types.ts'
13
- import { parseExpression, parseBlockBodyTolerant, foldBlockToExpr, tsNodeToParsedExpr, stringifyParsedExpr, type ParsedExpr } from './expression-parser.ts'
12
+ import type { ImportSpecifier, TypeInfo, ParamInfo, PropDefaultPart, PropDefaultRead, ReactiveFactoryInfo, DeclinedReactiveFactory, RequiredFactoryImport, FactoryRenameSite, SourceLocation, SignalFactoryCall, MemoInfo } from './types.ts'
13
+ import { CALLBACK_METHODS, parseExpression, parseBlockBodyTolerant, foldBlockToExpr, tsNodeToParsedExpr, stringifyParsedExpr, type ParsedExpr } from './expression-parser.ts'
14
14
  import type { CallbackBodyAcceptor } from './adapters/interface.ts'
15
- import { rewriteBarePropRefs } from './prop-rewrite.ts'
16
- import { buildPropAliasMap, coalesceDefaultText, signalPropSeed } from './props-binding.ts'
15
+ import { collectAssignmentTargets, rewriteBarePropRefs, splitScopedValueRefs } from './prop-rewrite.ts'
16
+ import { isEventHandlerName } from './event-handler-name.ts'
17
+ import { buildPropAliasMap, coalesceDefaultText, livePropReadExpr, signalPropSeed } from './props-binding.ts'
17
18
  import { incrementCounter } from './instrumentation.ts'
18
19
  import {
19
20
  type AnalyzerContext,
@@ -33,7 +34,7 @@ import { CATALOGUED_RICH_TYPE_NAMES } from './date-lowering.ts'
33
34
  import path from 'node:path'
34
35
  import fs from 'node:fs'
35
36
  import { signalSecondBinding } from './signal-initializer.ts'
36
- import { separateLiteralSignalPropBindings, programWithSeparatedSource } from './signal-prop-name-collision.ts'
37
+ import { separateSignalPropBindings, programWithSeparatedSource } from './signal-prop-name-collision.ts'
37
38
 
38
39
  // =============================================================================
39
40
  // TypeScript Program Creation
@@ -399,7 +400,7 @@ export function analyzeComponent(
399
400
  // so imported signals are covered too.
400
401
  for (const signal of ctx.signals) parseSignalInitializer(signal, ctx)
401
402
 
402
- const separatedSource = separateLiteralSignalPropBindings(ctx, isNonReferenceIdentifierPosition)
403
+ const separatedSource = separateSignalPropBindings(ctx, isNonReferenceIdentifierPosition)
403
404
  if (separatedSource !== null) {
404
405
  // The checker supplied by the caller names the old AST. Re-analyze the
405
406
  // structurally renamed source, preserving the shared-program contract
@@ -502,10 +503,13 @@ function collectNamedExports(sourceFile: ts.SourceFile): Set<string> {
502
503
  * declarations of a module-level `const f = (…) => { … }` were collected
503
504
  * as module-level declarations of the FILE — hoisted into the init body
504
505
  * and into the marked template, where their references to the helper's
505
- * own parameters are unbound (#2986).
506
+ * own parameters are unbound (#2986). A class static block is its own scope
507
+ * too: `class { static { var $ } }` declares `$` in the block, not in the
508
+ * component body.
506
509
  */
507
510
  function isFunctionScope(node: ts.Node): boolean {
508
- return ts.isArrowFunction(node)
511
+ return ts.isClassStaticBlockDeclaration(node)
512
+ || ts.isArrowFunction(node)
509
513
  || ts.isFunctionExpression(node)
510
514
  || ts.isFunctionDeclaration(node)
511
515
  || ts.isMethodDeclaration(node)
@@ -1535,7 +1539,7 @@ function collectSignal(node: ts.VariableDeclaration, ctx: AnalyzerContext): void
1535
1539
  const propNames = new Set(ctx.propsParams.map(p => p.name))
1536
1540
  if (propNames.size > 0) {
1537
1541
  const propAliases = buildPropAliasMap(ctx.propsParams)
1538
- templateInitialValue = rewriteBarePropRefs(initialValue, callExpr.arguments[0], propNames, undefined, propAliases)
1542
+ templateInitialValue = rewriteBarePropRefs(initialValue, callExpr.arguments[0], propNames, undefined, propAliases, destructuredPropTemplateRead(ctx))
1539
1543
  }
1540
1544
  }
1541
1545
 
@@ -1627,7 +1631,7 @@ function collectFactorySignal(
1627
1631
  const propNames = new Set(ctx.propsParams.map(p => p.name))
1628
1632
  if (propNames.size > 0) {
1629
1633
  const propAliases = buildPropAliasMap(ctx.propsParams)
1630
- templateInitialValue = rewriteBarePropRefs(initialValue, initialNode.node, propNames, undefined, propAliases)
1634
+ templateInitialValue = rewriteBarePropRefs(initialValue, initialNode.node, propNames, undefined, propAliases, destructuredPropTemplateRead(ctx))
1631
1635
  }
1632
1636
  }
1633
1637
 
@@ -2080,7 +2084,7 @@ function memoBodyFields(
2080
2084
  const propNames = new Set(ctx.propsParams.map(p => p.name))
2081
2085
  if (propNames.size > 0) {
2082
2086
  const propAliases = buildPropAliasMap(ctx.propsParams)
2083
- const rewritten = rewriteBarePropRefs(ctx.getJS(body.node), body.node, propNames, undefined, propAliases)
2087
+ const rewritten = rewriteBarePropRefs(ctx.getJS(body.node), body.node, propNames, undefined, propAliases, destructuredPropTemplateRead(ctx))
2084
2088
  templateBodyExpr = rewritten === undefined ? undefined : asBodyExpr(rewritten)
2085
2089
  }
2086
2090
  }
@@ -2780,15 +2784,34 @@ function collectTypeAliasDefinition(
2780
2784
  const properties = ts.isTypeLiteralNode(node.type)
2781
2785
  ? membersToProperties(node.type.members, ctx.sourceFile)
2782
2786
  : undefined
2787
+ const stringLiteralUnion = stringLiteralMembers(node.type)
2783
2788
  ctx.typeDefinitions.push({
2784
2789
  kind: 'type',
2785
2790
  name: node.name.text,
2786
2791
  definition: node.getText(ctx.sourceFile),
2787
2792
  properties,
2793
+ ...(stringLiteralUnion ? { stringLiteralUnion } : {}),
2788
2794
  loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath),
2789
2795
  })
2790
2796
  }
2791
2797
 
2798
+ /**
2799
+ * The values of a type that is a string literal or a union of string
2800
+ * literals only, or `undefined` for any other type.
2801
+ */
2802
+ function stringLiteralMembers(type: ts.TypeNode): string[] | undefined {
2803
+ if (ts.isParenthesizedTypeNode(type)) return stringLiteralMembers(type.type)
2804
+ if (ts.isLiteralTypeNode(type)) return ts.isStringLiteral(type.literal) ? [type.literal.text] : undefined
2805
+ if (!ts.isUnionTypeNode(type)) return undefined
2806
+ const values: string[] = []
2807
+ for (const member of type.types) {
2808
+ const nested = stringLiteralMembers(member)
2809
+ if (!nested) return undefined
2810
+ values.push(...nested)
2811
+ }
2812
+ return values
2813
+ }
2814
+
2792
2815
  // =============================================================================
2793
2816
  // Function Collection
2794
2817
  // =============================================================================
@@ -3641,6 +3664,18 @@ function getSystemConstructKind(node: ts.Node): 'createContext' | 'weakMap' | un
3641
3664
  return undefined
3642
3665
  }
3643
3666
 
3667
+ /**
3668
+ * The CSR `template:` read of a destructured prop a signal seed or memo body
3669
+ * names (#2265): the live read every client site shares
3670
+ * (`livePropReadExpr`), so the module-scope arrow applies the prop's
3671
+ * destructure default too, including one that reads an earlier prop
3672
+ * (`{ off = false, on = off }` → `(_p.on ?? (_p.off ?? false))`, #3531).
3673
+ */
3674
+ function destructuredPropTemplateRead(ctx: AnalyzerContext): (localName: string, callerKey: string) => string {
3675
+ const byName = new Map(ctx.propsParams.filter(p => !p.isRest).map(p => [p.name, p]))
3676
+ return (localName, callerKey) => livePropReadExpr(byName.get(localName) ?? { name: localName, sourceName: callerKey }, undefined, false)
3677
+ }
3678
+
3644
3679
  /**
3645
3680
  * The default-value-shaped fields a binding element's own `initializer`
3646
3681
  * contributes to a `ParamInfo` — `defaultValue`'s source text, `parsed`'s
@@ -3654,14 +3689,70 @@ function getSystemConstructKind(node: ts.Node): 'createContext' | 'weakMap' | un
3654
3689
  function bindingElementDefaultFields(
3655
3690
  initializer: ts.Expression | undefined,
3656
3691
  ctx: AnalyzerContext,
3657
- ): Pick<ParamInfo, 'defaultValue' | 'parsed' | 'defaultContainsArrow'> {
3692
+ earlier: ReadonlyMap<string, PropDefaultRead> = new Map(),
3693
+ ): Pick<ParamInfo, 'defaultValue' | 'parsed' | 'defaultContainsArrow' | 'defaultParts'> {
3658
3694
  const defaultValue = initializer ? ctx.getJS(initializer) : undefined
3659
3695
  const defaultContainsArrow = initializer ? nodeContainsArrow(initializer) : false
3660
3696
  const parsedDefault = initializer ? tsNodeToParsedExpr(initializer) : undefined
3697
+ const defaultParts = initializer && defaultValue !== undefined
3698
+ ? defaultPartsReadingEarlierBindings(initializer, defaultValue, earlier)
3699
+ : undefined
3661
3700
  return {
3662
3701
  defaultValue,
3663
3702
  ...(parsedDefault && parsedDefault.kind !== 'unsupported' && { parsed: parsedDefault }),
3664
3703
  defaultContainsArrow: defaultContainsArrow || undefined,
3704
+ ...(defaultParts && { defaultParts }),
3705
+ }
3706
+ }
3707
+
3708
+ /**
3709
+ * A destructure default split at its reads of EARLIER bindings of the same
3710
+ * pattern (`ParamInfo.defaultParts`, #3531), or undefined when it reads none.
3711
+ * JS puts each earlier binding in scope for a later default
3712
+ * (`{ off = false, on = off }`), so a free `off` there is that binding, not an
3713
+ * outer name; a later binding is still in its TDZ and is left alone. The split
3714
+ * runs on the default's JS text with the same scope-aware walk the client
3715
+ * prop rewrite uses, so a nested callback parameter of the same name is not a
3716
+ * read.
3717
+ */
3718
+ function defaultPartsReadingEarlierBindings(
3719
+ initializer: ts.Expression,
3720
+ defaultValue: string,
3721
+ earlier: ReadonlyMap<string, PropDefaultRead>,
3722
+ ): PropDefaultPart[] | undefined {
3723
+ if (earlier.size === 0) return undefined
3724
+ const names = new Set([...extractFreeIdentifiersFromNode(initializer)].filter(n => earlier.has(n)))
3725
+ if (names.size === 0) return undefined
3726
+ const pieces = splitScopedValueRefs(defaultValue, names)
3727
+ if (pieces === null || !pieces.some(p => p.kind === 'ref')) return undefined
3728
+ return pieces.map((piece): PropDefaultPart =>
3729
+ piece.kind === 'text'
3730
+ ? { kind: 'text', text: piece.text }
3731
+ : { kind: 'param', param: earlier.get(piece.name)! },
3732
+ )
3733
+ }
3734
+
3735
+ /** {@link propDefaultReadOf} for a body destructure's binding (`const { label: text = 'x' } = props`). */
3736
+ function bodyBindingRead(
3737
+ localName: string,
3738
+ sourceKey: string,
3739
+ defaultFields: Pick<ParamInfo, 'defaultValue' | 'defaultContainsArrow' | 'defaultParts'> | undefined,
3740
+ ): PropDefaultRead {
3741
+ return propDefaultReadOf({
3742
+ name: localName,
3743
+ ...(sourceKey !== localName && { sourceName: sourceKey }),
3744
+ ...defaultFields,
3745
+ })
3746
+ }
3747
+
3748
+ /** The fields a later default's `param` part needs to read `p` (`PropDefaultRead`). */
3749
+ function propDefaultReadOf(p: PropDefaultRead): PropDefaultRead {
3750
+ return {
3751
+ name: p.name,
3752
+ ...(p.sourceName !== undefined && { sourceName: p.sourceName }),
3753
+ ...(p.defaultValue !== undefined && { defaultValue: p.defaultValue }),
3754
+ ...(p.defaultContainsArrow && { defaultContainsArrow: p.defaultContainsArrow }),
3755
+ ...(p.defaultParts && { defaultParts: p.defaultParts }),
3665
3756
  }
3666
3757
  }
3667
3758
 
@@ -3688,6 +3779,9 @@ function collectConstant(
3688
3779
  ctx.propsObjectName === node.initializer.text
3689
3780
  ) {
3690
3781
  const propsName = node.initializer.text
3782
+ // Bindings already destructured by this pattern, by local name: a later
3783
+ // default reads them (`const { off = false, on = off } = props`, #3531).
3784
+ const earlier = new Map<string, PropDefaultRead>()
3691
3785
  for (const el of node.name.elements) {
3692
3786
  if (!ts.isBindingElement(el) || !ts.isIdentifier(el.name) || el.dotDotDotToken) continue
3693
3787
  const localName = el.name.text
@@ -3695,7 +3789,8 @@ function collectConstant(
3695
3789
  // Shared with the #2943 `ParamInfo` overlay below so "what does this
3696
3790
  // default look like" (source text, `defaultContainsArrow`) has one
3697
3791
  // computation, not two independently-drifting ones.
3698
- const defaultFields = el.initializer ? bindingElementDefaultFields(el.initializer, ctx) : undefined
3792
+ const defaultFields = el.initializer ? bindingElementDefaultFields(el.initializer, ctx, earlier) : undefined
3793
+ earlier.set(localName, bodyBindingRead(localName, sourceKey, defaultFields))
3699
3794
  const baseValue = `${propsName}.${sourceKey}`
3700
3795
  // Parenthesize an arrow/function-expression default (#2940) — `??`
3701
3796
  // binds tighter than an arrow head, so a bare `props.fmt ?? (v) =>
@@ -4045,6 +4140,9 @@ function extractProps(param: ts.ParameterDeclaration, ctx: AnalyzerContext): voi
4045
4140
  // `props: Props` path instead of degrading to `unknown` (which typed
4046
4141
  // adapters emit as `interface{}` + an unchecked assertion). See issue #2150.
4047
4142
  const memberTypes = param.type ? collectMemberTypes(param.type, ctx) : null
4143
+ // Bindings already destructured, by local name: a later default reads
4144
+ // them (`{ off = false, on = off }`, #3531).
4145
+ const earlier = new Map<string, PropDefaultRead>()
4048
4146
 
4049
4147
  for (const element of param.name.elements) {
4050
4148
  if (ts.isBindingElement(element) && ts.isIdentifier(element.name)) {
@@ -4065,16 +4163,18 @@ function extractProps(param: ts.ParameterDeclaration, ctx: AnalyzerContext): voi
4065
4163
  const member = memberTypes?.get(sourcePropName)
4066
4164
  const resolvedType: TypeInfo = member?.type ?? { kind: 'unknown', raw: 'unknown' }
4067
4165
 
4068
- ctx.propsParams.push({
4166
+ const info: ParamInfo = {
4069
4167
  name: localName,
4070
4168
  type: resolvedType,
4071
4169
  // The type's `?` and a destructure default (`{ x = 1 }`) both mean
4072
4170
  // the caller may omit the prop.
4073
4171
  optional: !!member?.optional || !!element.initializer,
4074
- ...bindingElementDefaultFields(element.initializer, ctx),
4172
+ ...bindingElementDefaultFields(element.initializer, ctx, earlier),
4075
4173
  // Only aliased bindings carry the source key — see ParamInfo.sourceName.
4076
4174
  ...(sourcePropName !== localName && { sourceName: sourcePropName }),
4077
- })
4175
+ }
4176
+ ctx.propsParams.push(info)
4177
+ earlier.set(localName, propDefaultReadOf(info))
4078
4178
  }
4079
4179
  }
4080
4180
 
@@ -4606,6 +4706,7 @@ function validateContext(ctx: AnalyzerContext): void {
4606
4706
  // `localConstants` binding after its declaration — flag those bindings so
4607
4707
  // downstream inlining never re-embeds their stale initializer text (#2910).
4608
4708
  markMutatedConstants(ctx)
4709
+ markWrittenBindings(ctx)
4609
4710
 
4610
4711
  // BF052: init statements that write to an identifier with no visible
4611
4712
  // declaration cause a ReferenceError in ESM strict mode. Flag them
@@ -4914,6 +5015,285 @@ function markMutatedConstants(ctx: AnalyzerContext): void {
4914
5015
  }
4915
5016
  }
4916
5017
 
5018
+ /**
5019
+ * Flag the component-scope bindings the component writes anywhere in its
5020
+ * body, nested functions and markup included (`collectAssignmentTargets`),
5021
+ * which `markMutatedConstants` does not see: it reads only the top-level
5022
+ * statements, up to the first nested function.
5023
+ *
5024
+ * - Every written binding gets `reassigned` (`ParamInfo` and
5025
+ * `ConstantInfo` alike), so it fails `keepsDeclaredValue`: it is a local
5026
+ * the component owns, never rewritten into a live prop read (`++start`
5027
+ * would become `++(_p.start ?? 0)`, a SyntaxError).
5028
+ * - A `localConstants` binding a write changes during render (a markup
5029
+ * expression, not an event handler) gets `mutatedAfterDeclaration`, like
5030
+ * a top-level statement's write: its declared value is no longer what a
5031
+ * later read sees, so nothing inlines it (`{++nextId}` would become
5032
+ * `++(0)`). A write in an event handler or another callback leaves the
5033
+ * declared value in place for render, so the binding stays inlinable.
5034
+ */
5035
+ function markWrittenBindings(ctx: AnalyzerContext): void {
5036
+ const body = ctx.componentNode?.body
5037
+ if (!body) return
5038
+ const params = ctx.propsObjectName === null ? ctx.propsParams.filter(p => !p.isRest) : []
5039
+ const names = new Set<string>([...params.map(p => p.name), ...ctx.localConstants.map(c => c.name)])
5040
+ if (names.size === 0) return
5041
+
5042
+ const { written, writingInitializers } = collectBindingWrites(ctx, body, names)
5043
+ for (const p of params) {
5044
+ if (written.has(p.name)) p.reassigned = true
5045
+ }
5046
+ for (const c of ctx.localConstants) {
5047
+ const when = written.get(c.name)
5048
+ if (when) c.reassigned = true
5049
+ // A const whose initializer writes (`const label = ++start`) must run
5050
+ // once, where it is declared: inlining its value anywhere else would
5051
+ // repeat the write, or carry it into the template's module scope.
5052
+ if (when === 'render' || writingInitializers.has(c.name)) c.mutatedAfterDeclaration = true
5053
+ }
5054
+ }
5055
+
5056
+ /**
5057
+ * Every write `markWrittenBindings` acts on, by binding: whether one runs
5058
+ * during render, and which top-level declarations' initializers write. A
5059
+ * markup write is reported (BF065) on the way.
5060
+ */
5061
+ function collectBindingWrites(
5062
+ ctx: AnalyzerContext,
5063
+ body: ts.Node,
5064
+ names: ReadonlySet<string>,
5065
+ ): { written: Map<string, 'render' | 'deferred'>; writingInitializers: Set<string | undefined> } {
5066
+ const written = new Map<string, 'render' | 'deferred'>()
5067
+ const writingInitializers = new Set<string | undefined>()
5068
+ const roots: readonly ts.Node[] = ts.isBlock(body) ? body.statements : [body]
5069
+ for (const root of roots) {
5070
+ for (const id of collectAssignmentTargets(root, names)) {
5071
+ const when = writeTiming(id, root)
5072
+ if (when === 'markup') reportMarkupWrite(ctx, id)
5073
+ if (when === 'statement') writingInitializers.add(declaredByInitializer(id, root))
5074
+ if (written.get(id.text) !== 'render') written.set(id.text, when === 'deferred' ? 'deferred' : 'render')
5075
+ }
5076
+ }
5077
+ return { written, writingInitializers }
5078
+ }
5079
+
5080
+ /**
5081
+ * When the write `id` (inside the component-body statement `root`) runs:
5082
+ * `'markup'` while a markup expression renders, `'statement'` while a
5083
+ * top-level statement runs (init runs it too), `'deferred'` later.
5084
+ * `markupTiming` decides a write that markup reaches; any other write keeps
5085
+ * the statement rule (`statementTiming`).
5086
+ */
5087
+ function writeTiming(id: ts.Identifier, root: ts.Node): 'markup' | 'statement' | 'deferred' {
5088
+ const inMarkup = markupTiming(id, root)
5089
+ return inMarkup === 'outside' ? statementTiming(id, root) : inMarkup
5090
+ }
5091
+
5092
+ /**
5093
+ * The one compositional rule for a write markup reaches. From the write
5094
+ * site, climb to the nearest enclosing function literal F:
5095
+ *
5096
+ * - none before a markup expression (`JsxExpression` / spread attribute):
5097
+ * the write runs while that expression renders — `'markup'`, an
5098
+ * event-handler attribute included (`onClick={(++id, () => {})}`);
5099
+ * - F found: follow how F's value is used (`valueUseOf`: parentheses,
5100
+ * casts, a conditional's branches, `&&` / `||` / `??`, a comma's last
5101
+ * operand, object / array literal members — not a spread, which runs
5102
+ * getters or iterates), then
5103
+ * - the callee of a call (an IIFE, `(c ? f : g)()`): F runs when that
5104
+ * call is evaluated — the same rule from the call;
5105
+ * - directly a JSX attribute's value (a child prop, a context value's
5106
+ * `setApi`, an event handler): handed on, it runs when the receiver
5107
+ * calls it — `'deferred'`;
5108
+ * - an argument of a call: `'deferred'` only when that call is, by the
5109
+ * same value walk and through further wrapper calls, an
5110
+ * event-handler attribute's value (`onClick={wrap(() => ++n)}`,
5111
+ * `onInput={debounce(…)}`); otherwise the callee may run it while
5112
+ * rendering (`Array.from(xs, () => ++n)`, `.map`, `.replace`), so
5113
+ * the same rule from the call;
5114
+ * - anything else (stored in a variable, a JSX child): the same rule
5115
+ * from where its value lands, so unknown use inside markup refuses.
5116
+ *
5117
+ * `'outside'` when the climb reaches the component-body statement without
5118
+ * meeting markup.
5119
+ */
5120
+ function markupTiming(site: ts.Node, root: ts.Node): 'markup' | 'deferred' | 'outside' {
5121
+ for (let n: ts.Node = site; n !== root && n.parent; n = n.parent) {
5122
+ const parent = n.parent
5123
+ if (ts.isJsxExpression(parent) || ts.isJsxSpreadAttribute(parent)) return 'markup'
5124
+ if (isFunctionScope(parent)) return functionUseTiming(parent, root)
5125
+ }
5126
+ return 'outside'
5127
+ }
5128
+
5129
+ function functionUseTiming(fn: ts.Node, root: ts.Node): 'markup' | 'deferred' | 'outside' {
5130
+ const { use, dropped } = valueWalk(fn)
5131
+ // A setter an object spread meets is neither copied nor called.
5132
+ if (dropped) return 'deferred'
5133
+ const parent = use.parent
5134
+ if (ts.isJsxExpression(parent) && ts.isJsxAttribute(parent.parent)) return 'deferred'
5135
+ if (ts.isCallExpression(parent) && parent.expression !== use && isEventHandlerValue(parent)) return 'deferred'
5136
+ return markupTiming(ts.isCallExpression(parent) ? parent : use, root)
5137
+ }
5138
+
5139
+ /** Whether `call` is, through value-passing wrappers and further calls, an event-handler attribute's value. */
5140
+ function isEventHandlerValue(call: ts.CallExpression): boolean {
5141
+ const use = valueUseOf(call)
5142
+ const parent = use.parent
5143
+ if (ts.isJsxExpression(parent) && ts.isJsxAttribute(parent.parent)) {
5144
+ return ts.isIdentifier(parent.parent.name) && isEventHandlerName(parent.parent.name.text)
5145
+ }
5146
+ return ts.isCallExpression(parent) && parent.expression !== use && isEventHandlerValue(parent)
5147
+ }
5148
+
5149
+ /**
5150
+ * The outermost expression that carries `node`'s value unchanged: through
5151
+ * parentheses, casts, a conditional's branches (not its condition), `&&` /
5152
+ * `||` / `??`, a comma's last operand, object / array literal members, and a
5153
+ * spread that copies it (`spreadPassesOn`).
5154
+ */
5155
+ function valueUseOf(node: ts.Node): ts.Node {
5156
+ return valueWalk(node).use
5157
+ }
5158
+
5159
+ /**
5160
+ * `valueUseOf`'s walk. `dropped`: the value is a setter an object spread
5161
+ * meets, which the spread neither copies nor calls.
5162
+ */
5163
+ function valueWalk(node: ts.Node): { use: ts.Node; dropped: boolean } {
5164
+ let v = node
5165
+ let member: ts.Node | undefined
5166
+ for (;;) {
5167
+ const p = v.parent
5168
+ if (!p) return { use: v, dropped: false }
5169
+ if (ts.isSpreadAssignment(p) || ts.isSpreadElement(p)) {
5170
+ const spread = spreadPassesOn(p, v, member)
5171
+ if (spread === 'dropped') return { use: v, dropped: true }
5172
+ if (spread === 'consumed') return { use: v, dropped: false }
5173
+ } else if (!passesValueOn(v)) {
5174
+ return { use: v, dropped: false }
5175
+ }
5176
+ if (ts.isObjectLiteralExpression(p)) member = v
5177
+ v = p
5178
+ }
5179
+ }
5180
+
5181
+ /**
5182
+ * What a spread does with its operand `v`, per JavaScript:
5183
+ *
5184
+ * - an object spread copies the operand literal's data properties and
5185
+ * methods (`'passes'`), calls its getters (`'consumed'`: the rule
5186
+ * applies from the spread site) and skips its setters (`'dropped'`);
5187
+ * `member` is the operand member the walk came through;
5188
+ * - an array or argument spread of an array literal copies its elements
5189
+ * (`'passes'`); of anything else it runs the operand's iterator, which may
5190
+ * run any function in it (`'consumed'`).
5191
+ */
5192
+ function spreadPassesOn(
5193
+ p: ts.SpreadAssignment | ts.SpreadElement,
5194
+ v: ts.Node,
5195
+ member: ts.Node | undefined,
5196
+ ): 'passes' | 'consumed' | 'dropped' {
5197
+ if (ts.isSpreadElement(p)) return ts.isArrayLiteralExpression(v) ? 'passes' : 'consumed'
5198
+ if (!ts.isObjectLiteralExpression(v)) return 'consumed'
5199
+ if (member && ts.isGetAccessorDeclaration(member)) return 'consumed'
5200
+ if (member && ts.isSetAccessorDeclaration(member)) return 'dropped'
5201
+ return 'passes'
5202
+ }
5203
+
5204
+ function passesValueOn(v: ts.Node): boolean {
5205
+ const p = v.parent
5206
+ if (ts.isParenthesizedExpression(p) || ts.isAsExpression(p) || ts.isSatisfiesExpression(p)) return true
5207
+ if (ts.isNonNullExpression(p) || ts.isTypeAssertionExpression(p)) return true
5208
+ if (ts.isConditionalExpression(p)) return p.condition !== v
5209
+ if (ts.isBinaryExpression(p)) return isValuePassingOperator(p, v)
5210
+ if (ts.isPropertyAssignment(p)) return p.initializer === v
5211
+ return ts.isObjectLiteralExpression(p) || ts.isArrayLiteralExpression(p)
5212
+ }
5213
+
5214
+ function isValuePassingOperator(p: ts.BinaryExpression, v: ts.Node): boolean {
5215
+ const op = p.operatorToken.kind
5216
+ if (op === ts.SyntaxKind.CommaToken) return p.right === v
5217
+ return op === ts.SyntaxKind.AmpersandAmpersandToken || op === ts.SyntaxKind.BarBarToken || op === ts.SyntaxKind.QuestionQuestionToken
5218
+ }
5219
+
5220
+ /**
5221
+ * The statement rule for a write no markup reaches: a top-level statement
5222
+ * runs during render (`'statement'`) unless a function encloses the write
5223
+ * that is not invoked where it stands (`isInvokedInPlace`) — `'deferred'`.
5224
+ * That only decides whether a later read may inline the binding's declared
5225
+ * value (`mutatedAfterDeclaration`).
5226
+ */
5227
+ function statementTiming(id: ts.Identifier, root: ts.Node): 'statement' | 'deferred' {
5228
+ for (let n: ts.Node = id; n !== root && n.parent; n = n.parent) {
5229
+ if (isFunctionScope(n.parent) && !isInvokedInPlace(n.parent)) return 'deferred'
5230
+ }
5231
+ return 'statement'
5232
+ }
5233
+
5234
+ /**
5235
+ * Whether a function literal outside markup is called where it stands: the
5236
+ * callee of a call (an IIFE, `(() => …)()`), or the callback of an array
5237
+ * iteration method, which calls it before returning (`xs.map(cb)`, the
5238
+ * higher-order methods of `CALLBACK_METHODS`, plus `forEach`). Any other
5239
+ * function there is deferred, which only decides whether a later read may
5240
+ * inline the binding's declared value (`mutatedAfterDeclaration`).
5241
+ */
5242
+ function isInvokedInPlace(fn: ts.Node): boolean {
5243
+ let node = fn
5244
+ while (ts.isParenthesizedExpression(node.parent)) node = node.parent
5245
+ const call = node.parent
5246
+ if (!ts.isCallExpression(call)) return false
5247
+ if (call.expression === node) return true
5248
+ return call.arguments[0] === node && isArrayIterationCallee(call.expression)
5249
+ }
5250
+
5251
+ /** `<receiver>.<method>` where `method` is an array iteration method that calls its callback in place. */
5252
+ function isArrayIterationCallee(callee: ts.Expression): boolean {
5253
+ if (!ts.isPropertyAccessExpression(callee)) return false
5254
+ const method = callee.name.text
5255
+ return CALLBACK_METHODS.has(method) || method === 'forEach'
5256
+ }
5257
+
5258
+ /**
5259
+ * The name a top-level declaration binds when the write `id` sits in its
5260
+ * initializer (`const label = ++start` → `label`), or undefined.
5261
+ */
5262
+ function declaredByInitializer(id: ts.Identifier, root: ts.Node): string | undefined {
5263
+ for (let n: ts.Node = id; n !== root && n.parent; n = n.parent) {
5264
+ const parent = n.parent
5265
+ if (ts.isVariableDeclaration(parent) && parent.initializer === n && ts.isIdentifier(parent.name)) return parent.name.text
5266
+ }
5267
+ return undefined
5268
+ }
5269
+
5270
+ /**
5271
+ * BF065: a client component's markup writes a component binding while it
5272
+ * renders (`{++nextId}`, a `.map()` row that increments a counter). A
5273
+ * callback the markup hands on (an event handler, a child prop, a context
5274
+ * value) is not: it runs when called. The client renders markup in two places that
5275
+ * cannot share that write: the client template, which runs at module scope
5276
+ * with no binding to write, and init, which re-evaluates only reactive
5277
+ * positions. A client-side mount would lose the written value, so the
5278
+ * shape is refused rather than rendered empty. A server-only component has
5279
+ * no client side and renders it as JavaScript does.
5280
+ */
5281
+ function reportMarkupWrite(ctx: AnalyzerContext, id: ts.Identifier): void {
5282
+ if (!ctx.hasUseClientDirective) return
5283
+ ctx.errors.push(
5284
+ createError(ErrorCodes.STAGE_WRITE_IN_MARKUP, getSourceLocation(id, ctx.sourceFile, ctx.filePath), {
5285
+ message:
5286
+ `The markup writes '${id.text}' while it renders. The client template cannot write a component binding, ` +
5287
+ 'so a client-side mount would lose the written value.',
5288
+ suggestion: {
5289
+ message:
5290
+ `Compute the value before the return (\`const label = ++${id.text}\`) and render that, ` +
5291
+ 'or keep the value in a signal and update it from an event handler.',
5292
+ },
5293
+ }),
5294
+ )
5295
+ }
5296
+
4917
5297
  function validateInitStatementReferences(ctx: AnalyzerContext): void {
4918
5298
  if (ctx.initStatements.length === 0) return
4919
5299
 
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Whether an identifier is WRITTEN by the expression that contains it.
3
+ *
4
+ * Every substitution the compiler performs over a parsed expression (a
5
+ * destructured prop's live read `_p.x ?? d`, a constant's inlined value, a
6
+ * signal's initial value in the client template) replaces a READ of a
7
+ * binding with an expression that produces its value. A write position
8
+ * cannot take that replacement: `++nextId` becomes `++(0)` and `start += 1`
9
+ * becomes `(_p.start ?? 0) += 1`, both a SyntaxError that breaks the whole
10
+ * client module. The substitution walks ask this predicate first and leave
11
+ * a written identifier alone; the caller then decides what a write to the
12
+ * binding means in its scope (a local in the init body, a template slot
13
+ * left to init).
14
+ *
15
+ * Needs a tree built with parent pointers (`setParentNodes`).
16
+ */
17
+
18
+ import ts from 'typescript'
19
+
20
+ /** `=`, and every compound assignment (`+=`, `??=`, `<<=`, …). */
21
+ function isAssignmentOperator(kind: ts.SyntaxKind): boolean {
22
+ return kind >= ts.SyntaxKind.FirstAssignment && kind <= ts.SyntaxKind.LastAssignment
23
+ }
24
+
25
+ /** Wrappers that keep their operand an assignment target: `(x) = 1`, `x! = 1`, `(x as T) = 1`. */
26
+ function isTransparentWrapper(n: ts.Node): boolean {
27
+ return (
28
+ ts.isParenthesizedExpression(n) ||
29
+ ts.isNonNullExpression(n) ||
30
+ ts.isAsExpression(n) ||
31
+ ts.isTypeAssertionExpression(n) ||
32
+ ts.isSatisfiesExpression(n)
33
+ )
34
+ }
35
+
36
+ /**
37
+ * The node one level up a destructuring-assignment pattern from `node`, or
38
+ * null when `parent` is not a pattern piece that keeps `node` a target: an
39
+ * array element or spread (`[x, ...rest] = …`), an object shorthand or
40
+ * property value (`({ x, k: y } = …)`), or an object spread.
41
+ */
42
+ function patternContainer(node: ts.Node, parent: ts.Node): ts.Node | null {
43
+ if (ts.isArrayLiteralExpression(parent) || ts.isObjectLiteralExpression(parent)) return parent
44
+ if (ts.isSpreadElement(parent) || ts.isSpreadAssignment(parent)) return parent
45
+ if (ts.isShorthandPropertyAssignment(parent) && parent.name === node) return parent
46
+ if (ts.isPropertyAssignment(parent) && parent.initializer === node) return parent
47
+ return null
48
+ }
49
+
50
+ /**
51
+ * True when `id` is the target of an assignment (`x = …`, `x += …`), an
52
+ * update (`++x`, `x--`), a destructuring assignment (`[x, y] = …`,
53
+ * `({ x } = …)`, `[x = 1] = …`) or a `for (x of …)` / `for (x in …)` head.
54
+ * A member write (`x.a = 1`, `x[i]++`) writes the object, not the binding,
55
+ * so `x` there is a read.
56
+ */
57
+ export function isAssignmentTargetIdentifier(id: ts.Identifier): boolean {
58
+ let node: ts.Node = id
59
+ let parent: ts.Node | undefined = id.parent
60
+ while (parent) {
61
+ if (isTransparentWrapper(parent)) {
62
+ node = parent
63
+ parent = parent.parent
64
+ continue
65
+ }
66
+ if (ts.isPrefixUnaryExpression(parent) || ts.isPostfixUnaryExpression(parent)) {
67
+ return parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken
68
+ }
69
+ if (ts.isBinaryExpression(parent)) {
70
+ return parent.left === node && isAssignmentOperator(parent.operatorToken.kind)
71
+ }
72
+ if ((ts.isForOfStatement(parent) || ts.isForInStatement(parent)) && parent.initializer === node) return true
73
+ const container = patternContainer(node, parent)
74
+ if (!container) return false
75
+ node = container
76
+ parent = container.parent
77
+ }
78
+ return false
79
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The parts of a `??` / `||` read of the children prop, shared by the Phase 1
3
+ * classifier (`IRExpression.childrenRead`, #3539, #3554) and the emitters
4
+ * that splice the children markup and escape only the fallback.
5
+ */
6
+
7
+ import type { ParsedExpr } from './expression-parser.ts'
8
+
9
+ /**
10
+ * Split a left-nested chain of one fallback operator (`??` or `||`) into the
11
+ * value it reads first and the fallback taken when that value is nullish
12
+ * (`??`) or falsy (`||`): `(c ?? x) ?? y` reads `c`, else `x ?? y`, the same
13
+ * as `c ?? (x ?? y)`. `null` when `parsed` is not a `op` chain.
14
+ */
15
+ export function fallbackChainParts(
16
+ parsed: ParsedExpr,
17
+ op: '??' | '||',
18
+ ): { head: ParsedExpr; fallback: ParsedExpr } | null {
19
+ if (parsed.kind !== 'logical' || parsed.op !== op) return null
20
+ const fallbacks: ParsedExpr[] = []
21
+ let head: ParsedExpr = parsed
22
+ while (head.kind === 'logical' && head.op === op) {
23
+ fallbacks.unshift(head.right)
24
+ head = head.left
25
+ }
26
+ const fallback = fallbacks.reduceRight((right, left) => ({ kind: 'logical', op, left, right }))
27
+ return { head, fallback }
28
+ }
29
+
30
+ /** {@link fallbackChainParts} of a `??` chain. */
31
+ export function nullishChainParts(parsed: ParsedExpr): { head: ParsedExpr; fallback: ParsedExpr } | null {
32
+ return fallbackChainParts(parsed, '??')
33
+ }
package/src/debug.ts CHANGED
@@ -23,7 +23,7 @@ import type {
23
23
  SourceLocation,
24
24
  OriginInfo,
25
25
  } from './types.ts'
26
- import { isElidedFactoryGetter } from './types.ts'
26
+ import { isElidedFactoryGetter, isChildrenPropParam } from './types.ts'
27
27
  import { analyzeComponent, listComponentFunctions } from './analyzer.ts'
28
28
  import { jsxToIR } from './jsx-to-ir.ts'
29
29
  import { buildMetadata } from './compiler.ts'
@@ -411,7 +411,7 @@ export function buildGraphFromIR(ir: ComponentIR): ComponentGraph {
411
411
  // `reactive: true` (#2903). The collector therefore returns the prop NAMES
412
412
  // (not a boolean), so a prop read lands in `DomBinding.deps` on the same
413
413
  // footing as a signal or memo read.
414
- const destructuredPropNames = new Set(meta.propsParams.map(p => p.name).filter(n => n !== 'children'))
414
+ const destructuredPropNames = new Set(meta.propsParams.filter(p => !isChildrenPropParam(p)).map(p => p.name))
415
415
  const propsObjectName = meta.propsObjectName
416
416
  const propMemberDep = (member: string): string => `${propsObjectName}.${member}`
417
417