@barefootjs/jsx 0.38.0 → 0.39.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/dist/action-accessor.d.ts +159 -0
  2. package/dist/action-accessor.d.ts.map +1 -0
  3. package/dist/adapters/interface.d.ts +19 -0
  4. package/dist/adapters/interface.d.ts.map +1 -1
  5. package/dist/adapters/jsx-adapter.d.ts.map +1 -1
  6. package/dist/analyzer.d.ts +49 -1
  7. package/dist/analyzer.d.ts.map +1 -1
  8. package/dist/async-action-refusal.d.ts +45 -0
  9. package/dist/async-action-refusal.d.ts.map +1 -0
  10. package/dist/compiler.d.ts.map +1 -1
  11. package/dist/debug.d.ts +61 -5
  12. package/dist/debug.d.ts.map +1 -1
  13. package/dist/errors.d.ts +4 -0
  14. package/dist/errors.d.ts.map +1 -1
  15. package/dist/format-date-refusal.d.ts +2 -6
  16. package/dist/format-date-refusal.d.ts.map +1 -1
  17. package/dist/html-types.d.ts +5 -0
  18. package/dist/html-types.d.ts.map +1 -1
  19. package/dist/index.d.ts +3 -2
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1261 -422
  22. package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
  23. package/dist/ir-to-client-js/collect-elements.d.ts +17 -1
  24. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  25. package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
  26. package/dist/ir-to-client-js/compute-scope.d.ts.map +1 -1
  27. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -0
  28. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
  29. package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
  30. package/dist/ir-to-client-js/declaration-sort.d.ts +2 -1
  31. package/dist/ir-to-client-js/declaration-sort.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/emit-module-level.d.ts.map +1 -1
  33. package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
  34. package/dist/ir-to-client-js/plan/declaration-emit.d.ts +7 -5
  35. package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
  36. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  37. package/dist/ir-to-client-js/reactivity.d.ts +10 -2
  38. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  39. package/dist/ir-to-client-js/types.d.ts +4 -0
  40. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  41. package/dist/ir-to-client-js/utils.d.ts +52 -9
  42. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  43. package/dist/jsx-to-ir.d.ts.map +1 -1
  44. package/dist/signal-initializer.d.ts +24 -0
  45. package/dist/signal-initializer.d.ts.map +1 -0
  46. package/dist/ssr-defaults.d.ts.map +1 -1
  47. package/dist/ssr-seed-plan.d.ts.map +1 -1
  48. package/dist/template-position-walk.d.ts +68 -0
  49. package/dist/template-position-walk.d.ts.map +1 -0
  50. package/dist/types.d.ts +95 -0
  51. package/dist/types.d.ts.map +1 -1
  52. package/package.json +2 -2
  53. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +194 -4
  54. package/src/__tests__/action-accessor.test.ts +166 -0
  55. package/src/__tests__/adapter-output.test.ts +142 -0
  56. package/src/__tests__/create-mutation.test.ts +250 -0
  57. package/src/__tests__/create-query.test.ts +696 -0
  58. package/src/__tests__/csr-fragment-root-scope-shape.test.ts +156 -0
  59. package/src/__tests__/debug.test.ts +305 -0
  60. package/src/__tests__/doc-examples.test.ts +66 -3
  61. package/src/__tests__/ir-fragment-transparency.test.ts +23 -0
  62. package/src/__tests__/issue-3240-nested-static-map-event-delegation.test.ts +245 -0
  63. package/src/__tests__/jsx-text-linebreak-whitespace.test.ts +80 -0
  64. package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +445 -0
  65. package/src/__tests__/props-destructuring.test.ts +79 -4
  66. package/src/__tests__/reactive-factory-arity.test.ts +311 -0
  67. package/src/__tests__/ssr-portal-ref-callback.test.ts +5 -3
  68. package/src/action-accessor.ts +289 -0
  69. package/src/adapters/interface.ts +19 -0
  70. package/src/adapters/jsx-adapter.ts +47 -20
  71. package/src/analyzer.ts +593 -44
  72. package/src/async-action-refusal.ts +254 -0
  73. package/src/compiler.ts +81 -46
  74. package/src/debug.ts +351 -104
  75. package/src/errors.ts +39 -0
  76. package/src/format-date-refusal.ts +6 -125
  77. package/src/html-types.ts +14 -0
  78. package/src/index.ts +3 -1
  79. package/src/ir-to-client-js/build-references.ts +6 -2
  80. package/src/ir-to-client-js/collect-elements.ts +65 -4
  81. package/src/ir-to-client-js/compute-inlinability.ts +2 -1
  82. package/src/ir-to-client-js/compute-scope.ts +3 -1
  83. package/src/ir-to-client-js/control-flow/plan/build-insert.ts +1 -0
  84. package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -0
  85. package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +112 -3
  86. package/src/ir-to-client-js/control-flow/stringify/insert.ts +1 -1
  87. package/src/ir-to-client-js/csr-substitute.ts +11 -3
  88. package/src/ir-to-client-js/declaration-sort.ts +7 -3
  89. package/src/ir-to-client-js/emit-module-level.ts +7 -4
  90. package/src/ir-to-client-js/emit-registration.ts +5 -10
  91. package/src/ir-to-client-js/index.ts +7 -2
  92. package/src/ir-to-client-js/phases/ref-callbacks.ts +1 -1
  93. package/src/ir-to-client-js/plan/build-declaration-emit.ts +16 -15
  94. package/src/ir-to-client-js/plan/declaration-emit.ts +7 -5
  95. package/src/ir-to-client-js/prop-handling.ts +4 -0
  96. package/src/ir-to-client-js/reactivity.ts +32 -1
  97. package/src/ir-to-client-js/stringify/declaration-emit.ts +14 -7
  98. package/src/ir-to-client-js/types.ts +4 -0
  99. package/src/ir-to-client-js/utils.ts +184 -21
  100. package/src/jsx-to-ir.ts +111 -14
  101. package/src/signal-initializer.ts +36 -0
  102. package/src/ssr-defaults.ts +10 -0
  103. package/src/ssr-seed-plan.ts +12 -1
  104. package/src/template-position-walk.ts +203 -0
  105. package/src/types.ts +99 -0
package/dist/index.js CHANGED
@@ -2461,7 +2461,8 @@ import {
2461
2461
  loopEndMarker,
2462
2462
  loopItemMarker,
2463
2463
  toHTMLAttrName as toHtmlAttrName,
2464
- keyAttrName as sharedKeyAttrName
2464
+ keyAttrName as sharedKeyAttrName,
2465
+ BF_PORTAL_OWNER
2465
2466
  } from "@barefootjs/shared";
2466
2467
 
2467
2468
  // src/ir-to-client-js/imports.ts
@@ -2813,7 +2814,18 @@ function initFunctionName(componentName) {
2813
2814
  return RESERVED_RUNTIME_NAMES.has(name) ? `${name}$` : name;
2814
2815
  }
2815
2816
  function isCommentScopedRoot(root) {
2816
- return root.type === "fragment" && !!root.needsScopeComment || root.type === "component";
2817
+ return isScopeCommentFragmentRoot(root) || root.type === "component";
2818
+ }
2819
+ function isScopeCommentFragmentRoot(root) {
2820
+ return root.type === "fragment" && !!root.needsScopeComment;
2821
+ }
2822
+ function componentDefScopeFlags(root) {
2823
+ const flags = [];
2824
+ if (isCommentScopedRoot(root))
2825
+ flags.push("comment: true");
2826
+ if (isScopeCommentFragmentRoot(root))
2827
+ flags.push("fragmentRoot: true");
2828
+ return flags;
2817
2829
  }
2818
2830
  var keyAttrName = sharedKeyAttrName;
2819
2831
  function mapArrayKeyArgs(bfIdArg, keyed, loopDepth) {
@@ -2917,13 +2929,13 @@ function wrapHandlerForTurn(handler, handlerId, loc) {
2917
2929
  const idArg = loc ? `${JSON.stringify(handlerId)}, ${JSON.stringify(loc)}` : JSON.stringify(handlerId);
2918
2930
  return `(...__bfa) => { beginTurn(${idArg}); try { return (${handler.trim()})(...__bfa) } finally { endTurn() } }`;
2919
2931
  }
2920
- function emitRefCall(callback, elementVar) {
2932
+ function emitRefCall(callback, elementVar, ssrPortalOwner = false) {
2921
2933
  const trimmed = callback.trim();
2922
2934
  const isBareIdent = /^[a-zA-Z_$][\w$]*$/.test(trimmed);
2923
- if (isBareIdent) {
2924
- return `(${callback})(${elementVar})`;
2925
- }
2926
- return `(${callback})?.(${elementVar})`;
2935
+ const call = isBareIdent ? `(${callback})(${elementVar})` : `(${callback})?.(${elementVar})`;
2936
+ if (!ssrPortalOwner)
2937
+ return call;
2938
+ return `{ ${call}; if (__scopeId) ${elementVar}.setAttribute('${BF_PORTAL_OWNER}', __scopeId) }`;
2927
2939
  }
2928
2940
  function inferDefaultValue(type) {
2929
2941
  if (type.kind === "primitive") {
@@ -3070,8 +3082,7 @@ function wrapLoopParamAsAccessor(expr, paramName, bindings, indexParam) {
3070
3082
  if (bindings && bindings.length > 0) {
3071
3083
  result = rewriteLoopBindingRefs(expr, bindings, "__bfItem()");
3072
3084
  } else {
3073
- const re = new RegExp(`${ID_BOUNDARY_BEFORE}${escapeIdentifierForRegex(paramName)}(?!\\s*\\()(?!-)${ID_BOUNDARY_AFTER}`, "gu");
3074
- result = replaceInExprContexts(expr, re, () => `${paramName}()`);
3085
+ result = rewriteIdentifierAsAccessor(expr, paramName);
3075
3086
  }
3076
3087
  if (indexParam && indexParam !== paramName) {
3077
3088
  result = wrapIndexParamAsAccessor(result, indexParam);
@@ -3079,8 +3090,44 @@ function wrapLoopParamAsAccessor(expr, paramName, bindings, indexParam) {
3079
3090
  return result;
3080
3091
  }
3081
3092
  function wrapIndexParamAsAccessor(expr, indexParam) {
3082
- const re = new RegExp(`${ID_BOUNDARY_BEFORE}${escapeIdentifierForRegex(indexParam)}(?!\\s*\\()(?!-)${ID_BOUNDARY_AFTER}`, "gu");
3083
- return replaceInExprContexts(expr, re, () => `${indexParam}()`);
3093
+ return rewriteIdentifierAsAccessor(expr, indexParam);
3094
+ }
3095
+ function rewriteIdentifierAsAccessor(expr, name) {
3096
+ if (!expr.includes(name))
3097
+ return expr;
3098
+ const wrapped = `(${expr})`;
3099
+ const sf = ts5.createSourceFile("__bf_expr.ts", wrapped, ts5.ScriptTarget.Latest, true);
3100
+ const edits = [];
3101
+ const visit = (node) => {
3102
+ if (ts5.isFunctionExpression(node) && node.name?.text === name)
3103
+ return;
3104
+ if (ts5.isIdentifier(node) && node.text === name) {
3105
+ const p = node.parent;
3106
+ if (isNonReferenceIdentifierPosition(node))
3107
+ return;
3108
+ if (ts5.isFunctionDeclaration(p) && p.name === node)
3109
+ return;
3110
+ if (ts5.isCallExpression(p) && p.expression === node)
3111
+ return;
3112
+ if (ts5.isNewExpression(p) && p.expression === node)
3113
+ return;
3114
+ const isShorthand = ts5.isShorthandPropertyAssignment(p) && p.name === node;
3115
+ const start = node.getStart(sf) - 1;
3116
+ const end = node.getEnd() - 1;
3117
+ edits.push({ start, end, replacement: isShorthand ? `${name}: ${name}()` : `${name}()` });
3118
+ return;
3119
+ }
3120
+ ts5.forEachChild(node, visit);
3121
+ };
3122
+ visit(sf);
3123
+ if (edits.length === 0)
3124
+ return expr;
3125
+ edits.sort((a, b) => b.start - a.start);
3126
+ let out = expr;
3127
+ for (const e of edits) {
3128
+ out = out.slice(0, e.start) + e.replacement + out.slice(e.end);
3129
+ }
3130
+ return out;
3084
3131
  }
3085
3132
  function rewriteLoopBindingRefs(expr, bindings, accessor) {
3086
3133
  const byName = new Map;
@@ -3728,6 +3775,75 @@ function resolveRestSpreadOriginCore(bindings, constantValues, name) {
3728
3775
  });
3729
3776
  }
3730
3777
 
3778
+ // src/adapters/env-signal.ts
3779
+ var ENV_SIGNAL_CLIENT_FACTORY = {
3780
+ search: "createSearchParams"
3781
+ };
3782
+ var ENV_SIGNAL_READERS = new Map([
3783
+ ["search", { key: "search", canonicalName: "searchParams", methods: new Set(["get"]) }]
3784
+ ]);
3785
+ function envSignalReaderFor(key) {
3786
+ if (key === undefined)
3787
+ return null;
3788
+ return ENV_SIGNAL_READERS.get(key) ?? null;
3789
+ }
3790
+ function envSignalLocalNames(metadata, key) {
3791
+ const names = new Set;
3792
+ for (const s of metadata.signals) {
3793
+ if (s.envReader !== undefined && (key === undefined || s.envReader === key)) {
3794
+ names.add(s.getter);
3795
+ }
3796
+ }
3797
+ return names;
3798
+ }
3799
+ function searchParamsLocalNames(metadata) {
3800
+ return envSignalLocalNames(metadata, "search");
3801
+ }
3802
+ function importsSearchParams(metadata) {
3803
+ return searchParamsLocalNames(metadata).size > 0;
3804
+ }
3805
+ function queryHrefLocalNames(metadata) {
3806
+ const names = new Set;
3807
+ for (const imp of metadata.imports) {
3808
+ if (!CLIENT_HELPER_SOURCES.has(imp.source) || imp.isTypeOnly)
3809
+ continue;
3810
+ for (const s of imp.specifiers) {
3811
+ if (s.isTypeOnly || s.isNamespace || s.isDefault)
3812
+ continue;
3813
+ if (s.name === "queryHref")
3814
+ names.add(s.alias ?? s.name);
3815
+ }
3816
+ }
3817
+ return names;
3818
+ }
3819
+ var CLIENT_HELPER_SOURCES = new Set([
3820
+ "@barefootjs/client",
3821
+ "@barefootjs/client/runtime"
3822
+ ]);
3823
+ function matchSearchParamsMethodCall(callee, args, localNames) {
3824
+ if (callee.kind !== "member" || callee.computed)
3825
+ return null;
3826
+ const recv = callee.object;
3827
+ if (recv.kind !== "call" || recv.args.length !== 0 || recv.callee.kind !== "identifier" || !localNames.has(recv.callee.name)) {
3828
+ return null;
3829
+ }
3830
+ return { method: callee.property, args };
3831
+ }
3832
+
3833
+ // src/signal-initializer.ts
3834
+ function signalFactoryInitializer(signal) {
3835
+ if (signal.factory)
3836
+ return `${signal.factory.callee}(${signal.factory.argsText})`;
3837
+ if (signal.envReader) {
3838
+ const factory = signal.envFactory ?? ENV_SIGNAL_CLIENT_FACTORY[signal.envReader];
3839
+ return factory ? `${factory}()` : null;
3840
+ }
3841
+ return null;
3842
+ }
3843
+ function signalSecondBinding(signal) {
3844
+ return signal.setter ?? signal.factory?.action ?? null;
3845
+ }
3846
+
3731
3847
  // src/ir-to-client-js/csr-substitute.ts
3732
3848
  function csrSubstitute(value, env, enclosingScope) {
3733
3849
  if (!value || value.trim().length === 0) {
@@ -3959,8 +4075,9 @@ function buildSignalMemoEnv(signals, memos, propsObjectName, localConstants = []
3959
4075
  replacement: normalizeSignalInitial(s, propsObjectName),
3960
4076
  freeIdentifiers: s.initialFreeIdentifiers ?? new Set
3961
4077
  });
3962
- if (s.setter) {
3963
- substitutions.set(s.setter, { kind: "identifier", replacement: "() => {}", freeIdentifiers: new Set });
4078
+ const second = signalSecondBinding(s);
4079
+ if (second) {
4080
+ substitutions.set(second, { kind: "identifier", replacement: "() => {}", freeIdentifiers: new Set });
3964
4081
  }
3965
4082
  }
3966
4083
  for (const m of memos) {
@@ -3979,7 +4096,7 @@ function normalizeSignalInitial(signal, propsObjectName) {
3979
4096
  const initialValue = signal.initialValue;
3980
4097
  const propsName = propsObjectName ?? "props";
3981
4098
  const propsPrefix = `${propsName}.`;
3982
- if (initialValue.startsWith(propsPrefix) && !initialValue.includes("??")) {
4099
+ if (!signal.factory && initialValue.startsWith(propsPrefix) && !initialValue.includes("??")) {
3983
4100
  return `${initialValue} ?? ${inferDefaultValue(signal.type)}`;
3984
4101
  }
3985
4102
  return signal.templateInitialValue ?? initialValue;
@@ -6779,7 +6896,11 @@ var ErrorCodes = {
6779
6896
  REACTIVE_FACTORY_RENAME_UNSUPPORTED: "BF111",
6780
6897
  REACTIVE_FACTORY_MODULE_CAPTURE: "BF112",
6781
6898
  REACTIVE_FACTORY_IMPORT_COLLISION: "BF113",
6782
- REACTIVE_FACTORY_PARAM_SHADOWED: "BF114"
6899
+ REACTIVE_FACTORY_PARAM_SHADOWED: "BF114",
6900
+ REACTIVE_FACTORY_ARITY_MISMATCH: "BF115",
6901
+ REACTIVE_FACTORY_EXTRA_ARGUMENTS: "BF116",
6902
+ ASYNC_ACTION_READ_IN_TEMPLATE: "BF117",
6903
+ MUTATION_INITIAL_OPTION: "BF118"
6783
6904
  };
6784
6905
  var errorMessages = {
6785
6906
  [ErrorCodes.MISSING_USE_CLIENT]: "'use client' directive required for components with createSignal or event handlers",
@@ -6814,7 +6935,11 @@ var errorMessages = {
6814
6935
  [ErrorCodes.REACTIVE_FACTORY_RENAME_UNSUPPORTED]: "Reactive factory object return/destructure must use shorthand properties only. " + "Property renames (`{ lists: myLists }`), defaults, and rest elements are not " + "supported — destructure with the factory's own property names.",
6815
6936
  [ErrorCodes.REACTIVE_FACTORY_MODULE_CAPTURE]: "Imported reactive factory references bindings from its own module scope, so its " + "body cannot be inlined into the component file. Move those helpers into the " + "component file, pass them to the factory as parameters, or define the factory " + "in the component file.",
6816
6937
  [ErrorCodes.REACTIVE_FACTORY_IMPORT_COLLISION]: "Inlining an imported reactive factory requires re-importing one of its helper " + "imports into this file, but that name is already bound here to something else. " + "Rename the conflicting binding in this file, or alias the import in the factory's own file.",
6817
- [ErrorCodes.REACTIVE_FACTORY_PARAM_SHADOWED]: "Reactive factory parameter is shadowed by a nested declaration inside the factory body, so argument substitution at the inline site would be ambiguous. Rename the inner binding so it does not collide with the parameter."
6938
+ [ErrorCodes.REACTIVE_FACTORY_PARAM_SHADOWED]: "Reactive factory parameter is shadowed by a nested declaration inside the factory body, so argument substitution at the inline site would be ambiguous. Rename the inner binding so it does not collide with the parameter.",
6939
+ [ErrorCodes.REACTIVE_FACTORY_ARITY_MISMATCH]: "Tuple destructure of 'createSignal'/'createMemo' does not match the number of " + "elements the factory returns. `createSignal` returns `[getter, setter]` (destructure " + "1 or 2 elements); `createMemo` returns a single getter (do not destructure it as an " + "array at all).",
6940
+ [ErrorCodes.REACTIVE_FACTORY_EXTRA_ARGUMENTS]: "'createSignal'/'createMemo' call passes more arguments than the primitive accepts " + "(`createSignal(initialValue?)`, `createMemo(computeFn)`, `createSearchParams()`). The extra argument(s) are " + "silently dropped from the compiled client JS.",
6941
+ [ErrorCodes.ASYNC_ACTION_READ_IN_TEMPLATE]: "An async action's accessors (`isPending()` / `error()`) cannot be read in this template position — " + "the request function never runs on the server, so there is no value to render.",
6942
+ [ErrorCodes.MUTATION_INITIAL_OPTION]: "`createMutation` takes no `initial` option — a mutation has no initial request to seed its value from. " + "Use `createQuery` for a value that needs an initial state."
6818
6943
  };
6819
6944
  function createError(code, loc, options) {
6820
6945
  if (code === undefined || !(code in errorMessages)) {
@@ -7047,6 +7172,24 @@ var { default: fs} = (() => ({}));
7047
7172
  var REACTIVE_BRAND_PACKAGES = [
7048
7173
  "@barefootjs/form"
7049
7174
  ];
7175
+ function isNonReferenceIdentifierPosition(id) {
7176
+ const p = id.parent;
7177
+ if (ts15.isPropertyAccessExpression(p) && p.name === id)
7178
+ return true;
7179
+ if (ts15.isPropertyAssignment(p) && p.name === id)
7180
+ return true;
7181
+ if (ts15.isBindingElement(p) && p.propertyName === id)
7182
+ return true;
7183
+ if ((ts15.isMethodDeclaration(p) || ts15.isGetAccessorDeclaration(p) || ts15.isSetAccessorDeclaration(p) || ts15.isPropertyDeclaration(p) || ts15.isEnumMember(p)) && p.name === id)
7184
+ return true;
7185
+ if (ts15.isJsxAttribute(p) && p.name === id)
7186
+ return true;
7187
+ if (ts15.isLabeledStatement(p) && p.label === id || (ts15.isBreakStatement(p) || ts15.isContinueStatement(p)) && p.label === id)
7188
+ return true;
7189
+ if ((ts15.isJsxOpeningElement(p) || ts15.isJsxSelfClosingElement(p) || ts15.isJsxClosingElement(p)) && p.tagName === id && /^[a-z]/.test(id.text))
7190
+ return true;
7191
+ return false;
7192
+ }
7050
7193
  function needsTypeBasedDetection(source) {
7051
7194
  if (REACTIVE_BRAND_PACKAGES.some((pkg) => source.includes(pkg)))
7052
7195
  return true;
@@ -7072,10 +7215,12 @@ function findBrandPackageImportLoc(sourceFile, filePath) {
7072
7215
  }
7073
7216
  return null;
7074
7217
  }
7075
- function createProgramForFile(source, filePath) {
7218
+ function createProgramForFile(source, filePath, hostOptions = {}) {
7076
7219
  incrementCounter("programCreations");
7077
7220
  try {
7078
- const normalizedPath = path_default.resolve(filePath);
7221
+ const { currentDirectory } = hostOptions;
7222
+ const resolveFrom = (fileName) => currentDirectory === undefined ? path_default.resolve(fileName) : path_default.resolve(currentDirectory, fileName);
7223
+ const normalizedPath = resolveFrom(filePath);
7079
7224
  const compilerOptions = {
7080
7225
  target: ts15.ScriptTarget.Latest,
7081
7226
  module: ts15.ModuleKind.ESNext,
@@ -7089,19 +7234,20 @@ function createProgramForFile(source, filePath) {
7089
7234
  const defaultHost = ts15.createCompilerHost(compilerOptions);
7090
7235
  const virtualHost = {
7091
7236
  ...defaultHost,
7237
+ ...currentDirectory === undefined ? {} : { getCurrentDirectory: () => currentDirectory },
7092
7238
  getSourceFile(fileName, languageVersion) {
7093
- if (path_default.resolve(fileName) === normalizedPath) {
7239
+ if (resolveFrom(fileName) === normalizedPath) {
7094
7240
  return ts15.createSourceFile(fileName, source, languageVersion, true, ts15.ScriptKind.TSX);
7095
7241
  }
7096
7242
  return defaultHost.getSourceFile(fileName, languageVersion);
7097
7243
  },
7098
7244
  fileExists(fileName) {
7099
- if (path_default.resolve(fileName) === normalizedPath)
7245
+ if (resolveFrom(fileName) === normalizedPath)
7100
7246
  return true;
7101
7247
  return defaultHost.fileExists(fileName);
7102
7248
  },
7103
7249
  readFile(fileName) {
7104
- if (path_default.resolve(fileName) === normalizedPath)
7250
+ if (resolveFrom(fileName) === normalizedPath)
7105
7251
  return source;
7106
7252
  return defaultHost.readFile(fileName);
7107
7253
  }
@@ -7115,6 +7261,11 @@ function createProgramForFile(source, filePath) {
7115
7261
  return null;
7116
7262
  }
7117
7263
  }
7264
+ function createAnchoredProgram(source, filename, anchorDir) {
7265
+ if (!needsTypeBasedDetection(source))
7266
+ return;
7267
+ return createProgramForFile(source, filename, { currentDirectory: anchorDir })?.program;
7268
+ }
7118
7269
  function analyzeComponent(source, filePath, targetComponentName, program, acceptsCallbackBody, programIsShared) {
7119
7270
  incrementCounter("filesAnalyzed");
7120
7271
  const hadSharedProgram = programIsShared ?? program !== undefined;
@@ -7587,7 +7738,13 @@ var PRIMITIVE_CANONICAL_NAMES = {
7587
7738
  createEffect: "effect",
7588
7739
  onMount: "onMount",
7589
7740
  onCleanup: "onCleanup",
7590
- createSearchParams: "signal"
7741
+ createSearchParams: "signal",
7742
+ createQuery: "signal",
7743
+ createMutation: "signal"
7744
+ };
7745
+ var SIGNAL_FACTORY_KINDS = {
7746
+ createQuery: "query",
7747
+ createMutation: "mutation"
7591
7748
  };
7592
7749
  var ENV_SIGNAL_FACTORIES = {
7593
7750
  createSearchParams: "search"
@@ -7642,17 +7799,23 @@ function resolveCanonicalClientExportName(ident, ctx) {
7642
7799
  return null;
7643
7800
  }
7644
7801
  function resolveEnvSignalKey(callExpr, ctx) {
7802
+ return resolveClientFactoryEntry(callExpr, ENV_SIGNAL_FACTORIES, ctx);
7803
+ }
7804
+ function resolveSignalFactoryKind(callExpr, ctx) {
7805
+ return resolveClientFactoryEntry(callExpr, SIGNAL_FACTORY_KINDS, ctx);
7806
+ }
7807
+ function resolveClientFactoryEntry(callExpr, table, ctx) {
7645
7808
  if (ts15.isIdentifier(callExpr.expression)) {
7646
- const key = ENV_SIGNAL_FACTORIES[callExpr.expression.text];
7647
- if (key)
7648
- return key;
7809
+ const hit = table[callExpr.expression.text];
7810
+ if (hit)
7811
+ return hit;
7649
7812
  const canonical = resolveCanonicalClientExportName(callExpr.expression, ctx);
7650
- return canonical ? ENV_SIGNAL_FACTORIES[canonical] ?? null : null;
7813
+ return canonical ? table[canonical] ?? null : null;
7651
7814
  }
7652
7815
  if (ts15.isPropertyAccessExpression(callExpr.expression)) {
7653
- const key = ENV_SIGNAL_FACTORIES[callExpr.expression.name.text];
7654
- if (key && isBarefootClientNamespace(callExpr.expression.expression, ctx))
7655
- return key;
7816
+ const hit = table[callExpr.expression.name.text];
7817
+ if (hit && isBarefootClientNamespace(callExpr.expression.expression, ctx))
7818
+ return hit;
7656
7819
  }
7657
7820
  return null;
7658
7821
  }
@@ -7692,6 +7855,11 @@ function isSignalDeclaration(node, ctx) {
7692
7855
  function collectSignal(node, ctx) {
7693
7856
  const pattern = node.name;
7694
7857
  const callExpr = node.initializer;
7858
+ const factoryKind = resolveSignalFactoryKind(callExpr, ctx);
7859
+ if (factoryKind) {
7860
+ collectFactorySignal(node, pattern, callExpr, factoryKind, ctx);
7861
+ return;
7862
+ }
7695
7863
  const elements = pattern.elements;
7696
7864
  const getterElided = elements.length === 2 && ts15.isOmittedExpression(elements[0]);
7697
7865
  if (elements.length < 1 || elements.length > 2 || !getterElided && (!ts15.isBindingElement(elements[0]) || !ts15.isIdentifier(elements[0].name))) {
@@ -7736,6 +7904,88 @@ function collectSignal(node, ctx) {
7736
7904
  envFactory
7737
7905
  });
7738
7906
  }
7907
+ function collectFactorySignal(node, pattern, callExpr, kind, ctx) {
7908
+ const elements = pattern.elements;
7909
+ const bindingName = (el) => el && ts15.isBindingElement(el) && ts15.isIdentifier(el.name) ? el.name.text : null;
7910
+ if (elements.length < 1 || elements.length > 2)
7911
+ return;
7912
+ const getterElided = ts15.isOmittedExpression(elements[0]);
7913
+ const valueName = getterElided ? null : bindingName(elements[0]);
7914
+ if (!getterElided && valueName === null)
7915
+ return;
7916
+ const action = elements.length === 2 ? bindingName(elements[1]) : null;
7917
+ if (elements.length === 2 && action === null)
7918
+ return;
7919
+ if (getterElided && action === null)
7920
+ return;
7921
+ const initialNode = kind === "mutation" ? { kind: "absent" } : factoryInitialNode(callExpr.arguments[1]);
7922
+ const initialValue = initialNode.kind === "expression" ? ctx.getJS(initialNode.node) : initialNode.kind === "member-read" ? `(${ctx.getJS(initialNode.options)}).initial` : "undefined";
7923
+ const typedInitialValue = initialNode.kind === "expression" ? initialNode.node.getText(ctx.sourceFile) : initialNode.kind === "member-read" ? `(${initialNode.options.getText(ctx.sourceFile)}).initial` : undefined;
7924
+ const initialFreeIdentifiers = initialNode.kind === "expression" ? extractFreeIdentifiersFromNode(initialNode.node) : initialNode.kind === "member-read" ? extractFreeIdentifiersFromNode(initialNode.options) : new Set;
7925
+ let type = { kind: "unknown", raw: "unknown" };
7926
+ if (callExpr.typeArguments && callExpr.typeArguments.length > 0) {
7927
+ type = typeNodeToTypeInfo(callExpr.typeArguments[0], ctx.sourceFile) ?? type;
7928
+ } else if (initialNode.kind !== "absent") {
7929
+ type = inferTypeFromValue(initialValue);
7930
+ }
7931
+ let templateInitialValue;
7932
+ if (!ctx.propsObjectName && initialNode.kind === "expression") {
7933
+ const propNames = new Set(ctx.propsParams.map((p) => p.name));
7934
+ if (propNames.size > 0) {
7935
+ const propAliases = buildPropAliasMap(ctx.propsParams);
7936
+ templateInitialValue = rewriteBarePropRefs(initialValue, initialNode.node, propNames, undefined, propAliases);
7937
+ }
7938
+ }
7939
+ const argTexts = callExpr.arguments.map((arg) => ctx.getJS(arg));
7940
+ const requestArg = callExpr.arguments[0];
7941
+ ctx.signals.push({
7942
+ getter: valueName ?? `__bfGet_${action}`,
7943
+ setter: null,
7944
+ getterElided: getterElided || undefined,
7945
+ initialValue,
7946
+ typedInitialValue: typedInitialValue !== undefined && typedInitialValue !== initialValue ? typedInitialValue : undefined,
7947
+ templateInitialValue,
7948
+ type,
7949
+ loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath),
7950
+ initialFreeIdentifiers,
7951
+ factory: {
7952
+ kind,
7953
+ callee: callExpr.expression.getText(ctx.sourceFile),
7954
+ argsText: argTexts.join(", "),
7955
+ requestText: argTexts[0] ?? "",
7956
+ requestFreeIdentifiers: requestArg ? extractFreeIdentifiersFromNode(requestArg) : new Set,
7957
+ action
7958
+ }
7959
+ });
7960
+ }
7961
+ function factoryInitialNode(options) {
7962
+ if (!options)
7963
+ return { kind: "absent" };
7964
+ let unwrapped = options;
7965
+ while (ts15.isParenthesizedExpression(unwrapped) || ts15.isAsExpression(unwrapped) || ts15.isSatisfiesExpression(unwrapped)) {
7966
+ unwrapped = unwrapped.expression;
7967
+ }
7968
+ if (!ts15.isObjectLiteralExpression(unwrapped))
7969
+ return { kind: "member-read", options };
7970
+ let found = null;
7971
+ for (const prop of unwrapped.properties) {
7972
+ if (ts15.isSpreadAssignment(prop))
7973
+ return { kind: "member-read", options };
7974
+ const name = prop.name;
7975
+ if (name === undefined || ts15.isComputedPropertyName(name))
7976
+ return { kind: "member-read", options };
7977
+ const key = ts15.isIdentifier(name) || ts15.isStringLiteral(name) || ts15.isNumericLiteral(name) ? name.text : null;
7978
+ if (key !== "initial")
7979
+ continue;
7980
+ if (ts15.isPropertyAssignment(prop))
7981
+ found = prop.initializer;
7982
+ else if (ts15.isShorthandPropertyAssignment(prop))
7983
+ found = prop.name;
7984
+ else
7985
+ return { kind: "member-read", options };
7986
+ }
7987
+ return found ? { kind: "expression", node: found } : { kind: "absent" };
7988
+ }
7739
7989
  function isSignalTupleDeclaration(node) {
7740
7990
  if (!ts15.isIdentifier(node.name))
7741
7991
  return false;
@@ -8189,6 +8439,10 @@ var CLIENT_EXPORTS = new Set([
8189
8439
  "isSSRPortal",
8190
8440
  "findSiblingSlot",
8191
8441
  "createSearchParams",
8442
+ "http",
8443
+ "HttpError",
8444
+ "createQuery",
8445
+ "createMutation",
8192
8446
  "queryHref",
8193
8447
  "formatDate",
8194
8448
  "Async",
@@ -8625,6 +8879,7 @@ function collectFunction(node, ctx, _isModule, isExported = false) {
8625
8879
  declarationKind: "function",
8626
8880
  isModule: _isModule || undefined,
8627
8881
  isJsxFunction: isJsxFunction || undefined,
8882
+ freeIdentifiers: extractFreeIdentifiersFromNode(node),
8628
8883
  loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath)
8629
8884
  });
8630
8885
  }
@@ -8959,6 +9214,11 @@ function collectConstant(node, ctx, _isModule, declarationKind = "const", isExpo
8959
9214
  }
8960
9215
  const freeIdentifiers2 = node.initializer ? extractFreeIdentifiersFromNode(node.initializer) : undefined;
8961
9216
  const containsArrow = node.initializer ? nodeContainsArrow(node.initializer) : false;
9217
+ let unwrappedInitializer = node.initializer;
9218
+ while (unwrappedInitializer && (ts15.isParenthesizedExpression(unwrappedInitializer) || ts15.isAsExpression(unwrappedInitializer) || ts15.isSatisfiesExpression(unwrappedInitializer))) {
9219
+ unwrappedInitializer = unwrappedInitializer.expression;
9220
+ }
9221
+ const isFunctionValue = unwrappedInitializer !== undefined && (ts15.isArrowFunction(unwrappedInitializer) || ts15.isFunctionExpression(unwrappedInitializer));
8962
9222
  const systemConstructKind = node.initializer ? getSystemConstructKind(node.initializer) : undefined;
8963
9223
  let templateValue;
8964
9224
  if (value && ctx.propsParams.length > 0 && node.initializer) {
@@ -8971,8 +9231,9 @@ function collectConstant(node, ctx, _isModule, declarationKind = "const", isExpo
8971
9231
  const shadowedByNonAlias = new Set;
8972
9232
  for (const s of ctx.signals) {
8973
9233
  shadowedByNonAlias.add(s.getter);
8974
- if (s.setter)
8975
- shadowedByNonAlias.add(s.setter);
9234
+ const second = signalSecondBinding(s);
9235
+ if (second)
9236
+ shadowedByNonAlias.add(second);
8976
9237
  }
8977
9238
  for (const m of ctx.memos)
8978
9239
  shadowedByNonAlias.add(m.name);
@@ -9013,6 +9274,7 @@ function collectConstant(node, ctx, _isModule, declarationKind = "const", isExpo
9013
9274
  isJsx,
9014
9275
  isJsxFunction: isJsxFunction || undefined,
9015
9276
  containsArrow: containsArrow || undefined,
9277
+ isFunctionValue: isFunctionValue || undefined,
9016
9278
  systemConstructKind,
9017
9279
  templateValue,
9018
9280
  origin: {
@@ -9099,28 +9361,75 @@ function collectKeysFromMembers(members, ctx) {
9099
9361
  }
9100
9362
  return keys;
9101
9363
  }
9102
- function isResolvableMemberType(info) {
9364
+ function isResolvableMemberType(info, localObjectMembers, visiting = new Set) {
9365
+ const recurse = (t) => isResolvableMemberType(t, localObjectMembers, visiting);
9103
9366
  switch (info.kind) {
9104
9367
  case "primitive":
9105
9368
  return info.primitive === "string" || info.primitive === "number" || info.primitive === "boolean";
9106
- case "interface":
9107
- return CATALOGUED_RICH_TYPE_NAMES.has(baseTypeName(info.raw));
9369
+ case "interface": {
9370
+ if (CATALOGUED_RICH_TYPE_NAMES.has(baseTypeName(info.raw)))
9371
+ return true;
9372
+ if (!localObjectMembers || visiting.has(info.raw))
9373
+ return false;
9374
+ const members = localObjectMembers(info.raw);
9375
+ if (!members)
9376
+ return false;
9377
+ const inner = new Set(visiting).add(info.raw);
9378
+ return members.every((t) => isResolvableMemberType(t, localObjectMembers, inner));
9379
+ }
9108
9380
  case "array":
9109
- return !!info.elementType && isResolvableMemberType(info.elementType);
9381
+ return !!info.elementType && recurse(info.elementType);
9110
9382
  case "object":
9111
- return info.properties !== undefined && info.properties.every((prop) => isResolvableMemberType(prop.type));
9383
+ return info.properties !== undefined && info.properties.every((prop) => recurse(prop.type));
9112
9384
  default:
9113
9385
  return false;
9114
9386
  }
9115
9387
  }
9388
+ function localObjectMemberTypesFor(ctx) {
9389
+ const cache = new Map;
9390
+ const lookup = (name) => {
9391
+ const decls = findTypeDeclarations(name, ctx.sourceFile);
9392
+ if (decls.length !== 1)
9393
+ return null;
9394
+ const decl = decls[0];
9395
+ if (decl.typeParameters?.length)
9396
+ return null;
9397
+ let members;
9398
+ if (ts15.isInterfaceDeclaration(decl)) {
9399
+ if (decl.heritageClauses?.length)
9400
+ return null;
9401
+ members = decl.members;
9402
+ } else if (ts15.isTypeLiteralNode(decl.type)) {
9403
+ members = decl.type.members;
9404
+ } else {
9405
+ return null;
9406
+ }
9407
+ const types = [];
9408
+ for (const member of members) {
9409
+ if (!ts15.isPropertySignature(member) || !member.type)
9410
+ return null;
9411
+ const info = typeNodeToTypeInfo(member.type, ctx.sourceFile);
9412
+ if (!info)
9413
+ return null;
9414
+ types.push(info);
9415
+ }
9416
+ return types;
9417
+ };
9418
+ return (name) => {
9419
+ if (!cache.has(name))
9420
+ cache.set(name, lookup(name));
9421
+ return cache.get(name) ?? null;
9422
+ };
9423
+ }
9116
9424
  function collectMemberTypes(typeNode, ctx) {
9425
+ const localObjectMembers = localObjectMemberTypesFor(ctx);
9117
9426
  const fromMembers = (members) => {
9118
9427
  const map = new Map;
9119
9428
  for (const member of members) {
9120
9429
  if (ts15.isPropertySignature(member) && member.name) {
9121
9430
  const info = member.type ? typeNodeToTypeInfo(member.type, ctx.sourceFile) : null;
9122
9431
  map.set(member.name.getText(ctx.sourceFile), {
9123
- type: info && isResolvableMemberType(info) ? info : null,
9432
+ type: info && isResolvableMemberType(info, localObjectMembers) ? info : null,
9124
9433
  optional: !!member.questionToken
9125
9434
  });
9126
9435
  }
@@ -9176,15 +9485,11 @@ function extractPropsFromTypeMembers(members, ctx) {
9176
9485
  }
9177
9486
  }
9178
9487
  }
9179
- function findTypeDeclaration(typeName, sourceFile) {
9180
- let result;
9488
+ function findTypeDeclarations(typeName, sourceFile) {
9489
+ const result = [];
9181
9490
  function visit3(node) {
9182
- if (ts15.isInterfaceDeclaration(node) && node.name.text === typeName) {
9183
- result = node;
9184
- return;
9185
- }
9186
- if (ts15.isTypeAliasDeclaration(node) && node.name.text === typeName) {
9187
- result = node;
9491
+ if ((ts15.isInterfaceDeclaration(node) || ts15.isTypeAliasDeclaration(node)) && node.name.text === typeName) {
9492
+ result.push(node);
9188
9493
  return;
9189
9494
  }
9190
9495
  ts15.forEachChild(node, visit3);
@@ -9192,6 +9497,9 @@ function findTypeDeclaration(typeName, sourceFile) {
9192
9497
  ts15.forEachChild(sourceFile, visit3);
9193
9498
  return result;
9194
9499
  }
9500
+ function findTypeDeclaration(typeName, sourceFile) {
9501
+ return findTypeDeclarations(typeName, sourceFile).at(-1);
9502
+ }
9195
9503
  function inferTypeFromValue(value) {
9196
9504
  const trimmed = value.trim();
9197
9505
  const nullishMatch = trimmed.match(/^.+\?\?\s*(.+)$/);
@@ -9274,6 +9582,7 @@ function validateContext(ctx) {
9274
9582
  markMutatedConstants(ctx);
9275
9583
  validateInitStatementReferences(ctx);
9276
9584
  validateReactiveFactoryCalls(ctx);
9585
+ validateReactiveFactoryArity(ctx);
9277
9586
  validateNamespaceQualifiedPrimitives(ctx);
9278
9587
  validateClientImports(ctx);
9279
9588
  }
@@ -9481,8 +9790,9 @@ function collectResolvedNames(ctx) {
9481
9790
  names.add(f.name);
9482
9791
  for (const s of ctx.signals) {
9483
9792
  names.add(s.getter);
9484
- if (s.setter)
9485
- names.add(s.setter);
9793
+ const second = signalSecondBinding(s);
9794
+ if (second)
9795
+ names.add(second);
9486
9796
  }
9487
9797
  for (const m of ctx.memos)
9488
9798
  names.add(m.name);
@@ -10118,19 +10428,7 @@ function detectReactiveFactory(node, sourceFile, filePath) {
10118
10428
  if (!relevantNames.has(id.text))
10119
10429
  return;
10120
10430
  const p = id.parent;
10121
- if (ts15.isPropertyAccessExpression(p) && p.name === id)
10122
- return;
10123
- if (ts15.isPropertyAssignment(p) && p.name === id)
10124
- return;
10125
- if (ts15.isBindingElement(p) && p.propertyName === id)
10126
- return;
10127
- if ((ts15.isMethodDeclaration(p) || ts15.isGetAccessorDeclaration(p) || ts15.isSetAccessorDeclaration(p) || ts15.isPropertyDeclaration(p) || ts15.isEnumMember(p)) && p.name === id)
10128
- return;
10129
- if (ts15.isJsxAttribute(p) && p.name === id)
10130
- return;
10131
- if (ts15.isLabeledStatement(p) && p.label === id || (ts15.isBreakStatement(p) || ts15.isContinueStatement(p)) && p.label === id)
10132
- return;
10133
- if ((ts15.isJsxOpeningElement(p) || ts15.isJsxSelfClosingElement(p) || ts15.isJsxClosingElement(p)) && p.tagName === id && /^[a-z]/.test(id.text))
10431
+ if (isNonReferenceIdentifierPosition(id))
10134
10432
  return;
10135
10433
  if (ts15.isShorthandPropertyAssignment(p) && p.name === id) {
10136
10434
  push(id, "shorthand");
@@ -10460,6 +10758,8 @@ function validateReactiveFactoryCalls(ctx) {
10460
10758
  continue;
10461
10759
  if (resolveEnvSignalKey(decl.initializer, ctx))
10462
10760
  continue;
10761
+ if (resolveSignalFactoryKind(decl.initializer, ctx))
10762
+ continue;
10463
10763
  const declinedEntry = ctx.declinedReactiveFactories.get(callee);
10464
10764
  if (declinedEntry) {
10465
10765
  ctx.errors.push(createError(declinedFactoryErrorCode(declinedEntry.code), loc, { severity: "error", message: declinedFactoryMessage(callee, declinedEntry) }));
@@ -10488,6 +10788,92 @@ function validateReactiveFactoryCalls(ctx) {
10488
10788
  }
10489
10789
  }
10490
10790
  }
10791
+ function validateReactiveFactoryArity(ctx) {
10792
+ if (!ctx.componentNode)
10793
+ return;
10794
+ const body = ts15.isFunctionDeclaration(ctx.componentNode) ? ctx.componentNode.body : ts15.isBlock(ctx.componentNode.body) ? ctx.componentNode.body : null;
10795
+ if (!body)
10796
+ return;
10797
+ checkStatementsForReactiveFactoryArity(body.statements, ctx);
10798
+ for (const stmt of body.statements) {
10799
+ if (!ts15.isIfStatement(stmt))
10800
+ continue;
10801
+ if (!findJsxReturnInBlock(stmt.thenStatement))
10802
+ continue;
10803
+ if (!ts15.isBlock(stmt.thenStatement))
10804
+ continue;
10805
+ checkStatementsForReactiveFactoryArity(stmt.thenStatement.statements, ctx);
10806
+ }
10807
+ }
10808
+ function checkStatementsForReactiveFactoryArity(statements, ctx) {
10809
+ for (const stmt of statements) {
10810
+ if (!ts15.isVariableStatement(stmt))
10811
+ continue;
10812
+ for (const decl of stmt.declarationList.declarations) {
10813
+ if (!decl.initializer || !ts15.isCallExpression(decl.initializer))
10814
+ continue;
10815
+ const callExpr = decl.initializer;
10816
+ const kind = resolvePrimitiveKind(callExpr, ctx);
10817
+ if (kind !== "signal" && kind !== "memo")
10818
+ continue;
10819
+ const loc = getSourceLocation(stmt, ctx.sourceFile, ctx.filePath);
10820
+ const calleeText = callExpr.expression.getText(ctx.sourceFile);
10821
+ const factoryKind = kind === "signal" ? resolveSignalFactoryKind(callExpr, ctx) : null;
10822
+ if (factoryKind !== null) {
10823
+ checkAsyncFactoryArity(decl, callExpr, calleeText, loc, ctx);
10824
+ if (factoryKind === "mutation")
10825
+ checkMutationInitialOption(callExpr, calleeText, ctx);
10826
+ continue;
10827
+ }
10828
+ if (ts15.isArrayBindingPattern(decl.name)) {
10829
+ const elementCount = decl.name.elements.length;
10830
+ const maxArity = kind === "signal" ? 2 : 0;
10831
+ if (elementCount < 1 || elementCount > maxArity) {
10832
+ ctx.errors.push(createError(ErrorCodes.REACTIVE_FACTORY_ARITY_MISMATCH, loc, {
10833
+ severity: "error",
10834
+ message: kind === "signal" ? elementCount === 0 ? `'${calleeText}(...)' returns a 2-element tuple '[getter, setter]' — this ` + `destructure binds 0 elements, so neither the getter nor the setter is ` + `reachable. Use 'const [get, set] = ${calleeText}(...)' or ` + `'const [get] = ${calleeText}(...)'.` : `'${calleeText}(...)' returns a 2-element tuple '[getter, setter]' (a ` + `1-element destructure keeps just the getter) — this destructure has ` + `${elementCount} elements. The extra binding(s) are silently dropped from ` + `the compiled output today. Use 'const [get, set] = ${calleeText}(...)' or ` + `'const [get] = ${calleeText}(...)'.` : `'${calleeText}(...)' returns a single getter function, not a tuple — this ` + `destructures ${elementCount} element${elementCount === 1 ? "" : "s"} from it. ` + `Use 'const value = ${calleeText}(...)' instead.`
10835
+ }));
10836
+ continue;
10837
+ }
10838
+ }
10839
+ const isEnvSignal = kind === "signal" && resolveEnvSignalKey(callExpr, ctx) !== null;
10840
+ const maxArgs = isEnvSignal ? 0 : 1;
10841
+ if (callExpr.arguments.length > maxArgs) {
10842
+ ctx.errors.push(createError(ErrorCodes.REACTIVE_FACTORY_EXTRA_ARGUMENTS, loc, {
10843
+ severity: "error",
10844
+ message: isEnvSignal ? `'${calleeText}()' takes no arguments (its value is read from the request ` + `environment), but this call passes ${callExpr.arguments.length}. The ` + `argument(s) are silently dropped from the compiled client JS today; remove them.` : `'${calleeText}(...)' accepts at most 1 argument (${kind === "signal" ? "the initial value" : "the compute function"}), ` + `but this call passes ${callExpr.arguments.length}. The extra argument(s) are ` + `silently dropped from the compiled client JS today; remove them, or fold ` + `whatever they configure into the ${kind === "signal" ? "initial value expression" : "compute function body"}.`
10845
+ }));
10846
+ }
10847
+ }
10848
+ }
10849
+ }
10850
+ function checkAsyncFactoryArity(decl, callExpr, calleeText, loc, ctx) {
10851
+ if (ts15.isArrayBindingPattern(decl.name)) {
10852
+ const elementCount = decl.name.elements.length;
10853
+ if (elementCount < 1 || elementCount > 2) {
10854
+ ctx.errors.push(createError(ErrorCodes.REACTIVE_FACTORY_ARITY_MISMATCH, loc, {
10855
+ severity: "error",
10856
+ message: `'${calleeText}(...)' returns a 2-element tuple '[value, action]' — this destructure has ` + `${elementCount} elements. Use 'const [value, action] = ${calleeText}(...)', ` + `'const [value] = ${calleeText}(...)' or 'const [, action] = ${calleeText}(...)'.`
10857
+ }));
10858
+ return;
10859
+ }
10860
+ }
10861
+ if (callExpr.arguments.length > 2) {
10862
+ ctx.errors.push(createError(ErrorCodes.REACTIVE_FACTORY_EXTRA_ARGUMENTS, loc, {
10863
+ severity: "error",
10864
+ message: `'${calleeText}(...)' accepts at most 2 arguments (the request function and the options), ` + `but this call passes ${callExpr.arguments.length}. The extra argument(s) are dropped from the ` + `compiled client JS; remove them.`
10865
+ }));
10866
+ }
10867
+ }
10868
+ function checkMutationInitialOption(callExpr, calleeText, ctx) {
10869
+ const initialNode = factoryInitialNode(callExpr.arguments[1]);
10870
+ if (initialNode.kind !== "expression")
10871
+ return;
10872
+ ctx.errors.push(createError(ErrorCodes.MUTATION_INITIAL_OPTION, getSourceLocation(initialNode.node, ctx.sourceFile, ctx.filePath), {
10873
+ severity: "error",
10874
+ message: `'${calleeText}(...)' takes no 'initial' option: a mutation's value is undefined until its action is ` + `called, so this value would never be used. Use 'createQuery' for a value that needs an initial state.`
10875
+ }));
10876
+ }
10491
10877
  function validateNamespaceQualifiedPrimitives(ctx) {
10492
10878
  if (!ctx.componentNode)
10493
10879
  return;
@@ -10719,6 +11105,9 @@ function pickAttrMetaFromIR(src) {
10719
11105
  ...src.freeIdentifiers !== undefined && { freeIdentifiers: src.freeIdentifiers }
10720
11106
  };
10721
11107
  }
11108
+ function isElidedFactoryGetter(signal) {
11109
+ return Boolean(signal.factory && signal.getterElided);
11110
+ }
10722
11111
  var ESCAPE_SSR_COST = {
10723
11112
  "client-directive": "client-render",
10724
11113
  "prop-precompute": "none",
@@ -11427,6 +11816,248 @@ var toLocaleDatePlugin = {
11427
11816
 
11428
11817
  // src/jsx-to-ir.ts
11429
11818
  import { toHTMLAttrName, decodeEntities, BF_KEY as BF_KEY2, keyAttrName as keyAttrName2 } from "@barefootjs/shared";
11819
+
11820
+ // src/template-position-walk.ts
11821
+ function walkTemplatePositions(root, visit3) {
11822
+ walkNode(root, visit3);
11823
+ }
11824
+ function walkTemplateParts(parts, loc, attrName, visit3) {
11825
+ const visitText = (text) => {
11826
+ const trimmed = text.trim();
11827
+ if (!trimmed)
11828
+ return;
11829
+ visit3({ expr: parseExpression(trimmed), loc, role: "template-part", attrName });
11830
+ };
11831
+ for (const part of parts) {
11832
+ if (part.type === "ternary") {
11833
+ visitText(part.condition);
11834
+ visitText(part.whenTrue);
11835
+ visitText(part.whenFalse);
11836
+ } else if (part.type === "lookup") {
11837
+ visitText(part.key);
11838
+ }
11839
+ }
11840
+ }
11841
+ function walkAttrValue(value, clientOnly, loc, attrName, onElement, visit3) {
11842
+ if (clientOnly)
11843
+ return;
11844
+ if (value.kind === "expression") {
11845
+ if (value.parsed) {
11846
+ visit3(onElement ? { expr: value.parsed, loc, role: "element-attr", attrName, host: { kind: "element-attr", value } } : { expr: value.parsed, loc, role: "prop", attrName });
11847
+ }
11848
+ if (value.parts)
11849
+ walkTemplateParts(value.parts, loc, attrName, visit3);
11850
+ } else if (value.kind === "spread") {
11851
+ if (value.parsed)
11852
+ visit3({ expr: value.parsed, loc, role: "spread", attrName });
11853
+ } else if (value.kind === "template") {
11854
+ walkTemplateParts(value.parts, loc, attrName, visit3);
11855
+ }
11856
+ }
11857
+ function walkNode(node, visit3) {
11858
+ if (node.type === "expression") {
11859
+ if (!node.clientOnly && node.parsed)
11860
+ visit3({ expr: node.parsed, loc: node.loc, role: "text" });
11861
+ } else if (node.type === "conditional") {
11862
+ if (!node.clientOnly && node.parsedCondition) {
11863
+ visit3({ expr: node.parsedCondition, loc: node.loc, role: "condition", host: { kind: "condition", node } });
11864
+ }
11865
+ } else if (node.type === "if-statement") {
11866
+ if (node.parsedCondition) {
11867
+ visit3({ expr: node.parsedCondition, loc: node.loc, role: "condition", host: { kind: "condition", node } });
11868
+ }
11869
+ }
11870
+ if (node.type === "element") {
11871
+ for (const attr of node.attrs)
11872
+ walkAttrValue(attr.value, attr.clientOnly, attr.loc, attr.name, true, visit3);
11873
+ } else if (node.type === "component") {
11874
+ for (const prop of node.props)
11875
+ walkAttrValue(prop.value, prop.clientOnly, prop.loc, prop.name, false, visit3);
11876
+ } else if (node.type === "provider") {
11877
+ walkAttrValue(node.valueProp.value, node.valueProp.clientOnly, node.valueProp.loc, "value", false, visit3);
11878
+ }
11879
+ switch (node.type) {
11880
+ case "element":
11881
+ case "component":
11882
+ case "fragment":
11883
+ case "provider":
11884
+ for (const child of node.children)
11885
+ walkNode(child, visit3);
11886
+ break;
11887
+ case "async":
11888
+ walkNode(node.fallback, visit3);
11889
+ for (const child of node.children)
11890
+ walkNode(child, visit3);
11891
+ break;
11892
+ case "loop": {
11893
+ if (node.clientOnly)
11894
+ break;
11895
+ if (node.arrayParsed)
11896
+ visit3({ expr: node.arrayParsed, loc: node.loc, role: "loop-array" });
11897
+ for (const child of node.children)
11898
+ walkNode(child, visit3);
11899
+ if (node.childComponent) {
11900
+ for (const child of node.childComponent.children)
11901
+ walkNode(child, visit3);
11902
+ }
11903
+ for (const nested of node.nestedComponents ?? []) {
11904
+ for (const child of nested.children)
11905
+ walkNode(child, visit3);
11906
+ }
11907
+ for (const seg of node.flatMapCallback?.segments ?? []) {
11908
+ if (seg.kind === "jsx")
11909
+ walkNode(seg.ir, visit3);
11910
+ }
11911
+ for (const seg of node.preamble?.segments ?? []) {
11912
+ if (seg.kind === "jsx")
11913
+ walkNode(seg.ir, visit3);
11914
+ }
11915
+ break;
11916
+ }
11917
+ case "conditional":
11918
+ if (node.clientOnly)
11919
+ break;
11920
+ walkNode(node.whenTrue, visit3);
11921
+ walkNode(node.whenFalse, visit3);
11922
+ break;
11923
+ case "if-statement":
11924
+ walkNode(node.consequent, visit3);
11925
+ if (node.alternate)
11926
+ walkNode(node.alternate, visit3);
11927
+ break;
11928
+ }
11929
+ }
11930
+
11931
+ // src/action-accessor.ts
11932
+ var ACTION_ACCESSOR_NAMES = new Set(["isPending", "error"]);
11933
+ function collectActionNames(signals) {
11934
+ const actions = new Set;
11935
+ for (const signal of signals) {
11936
+ if (signal.factory?.action)
11937
+ actions.add(signal.factory.action);
11938
+ }
11939
+ return actions;
11940
+ }
11941
+ function matchActionAccessorCall(expr, actions) {
11942
+ if (expr.kind !== "call" || expr.args.length !== 0)
11943
+ return null;
11944
+ const callee = expr.callee;
11945
+ if (callee.kind !== "member" || callee.computed)
11946
+ return null;
11947
+ if (callee.object.kind !== "identifier")
11948
+ return null;
11949
+ if (!actions.has(callee.object.name))
11950
+ return null;
11951
+ if (!ACTION_ACCESSOR_NAMES.has(callee.property))
11952
+ return null;
11953
+ return { action: callee.object.name, accessor: callee.property };
11954
+ }
11955
+ function parsedExprChildren(expr) {
11956
+ const all = (...exprs) => exprs.map((e) => ({ expr: e }));
11957
+ switch (expr.kind) {
11958
+ case "member":
11959
+ return all(expr.object);
11960
+ case "call":
11961
+ return all(expr.callee, ...expr.args);
11962
+ case "index-access":
11963
+ return all(expr.object, expr.index);
11964
+ case "binary":
11965
+ case "logical":
11966
+ return all(expr.left, expr.right);
11967
+ case "unary":
11968
+ return all(expr.argument);
11969
+ case "conditional":
11970
+ return all(expr.test, expr.consequent, expr.alternate);
11971
+ case "template-literal":
11972
+ return all(...expr.parts.flatMap((p) => p.type === "expression" ? [p.expr] : []));
11973
+ case "array-literal":
11974
+ return all(...expr.elements);
11975
+ case "object-literal":
11976
+ return all(...expr.properties.map((p) => p.kind === "spread" ? p.expr : p.value));
11977
+ case "array-method":
11978
+ return all(expr.object, ...expr.args, ...expr.method === "flat" && expr.depthExpr ? [expr.depthExpr] : []);
11979
+ case "arrow":
11980
+ return [{ expr: expr.body, params: expr.params }];
11981
+ case "identifier":
11982
+ case "literal":
11983
+ case "regex":
11984
+ case "unsupported":
11985
+ return [];
11986
+ }
11987
+ }
11988
+ function collectActionAccessorReads(expr, actions, isBound = () => false) {
11989
+ const reads = [];
11990
+ if (actions.size === 0)
11991
+ return reads;
11992
+ const visit3 = (e, bound) => {
11993
+ const read = matchActionAccessorCall(e, actions);
11994
+ if (read && !bound.has(read.action) && !isBound(read.action)) {
11995
+ if (!reads.some((r) => r.action === read.action && r.accessor === read.accessor))
11996
+ reads.push(read);
11997
+ return;
11998
+ }
11999
+ for (const child of parsedExprChildren(e)) {
12000
+ visit3(child.expr, child.params ? new Set([...bound, ...child.params]) : bound);
12001
+ }
12002
+ };
12003
+ visit3(expr, new Set);
12004
+ return reads;
12005
+ }
12006
+ var ARIA_BOOLEAN_STATE_ATTRS = new Set([
12007
+ "aria-atomic",
12008
+ "aria-busy",
12009
+ "aria-checked",
12010
+ "aria-disabled",
12011
+ "aria-expanded",
12012
+ "aria-hidden",
12013
+ "aria-modal",
12014
+ "aria-multiline",
12015
+ "aria-multiselectable",
12016
+ "aria-pressed",
12017
+ "aria-readonly",
12018
+ "aria-required",
12019
+ "aria-selected"
12020
+ ]);
12021
+ function seedableActionAccessorRead(position, actions) {
12022
+ const read = matchActionAccessorCall(position.expr, actions);
12023
+ if (!read)
12024
+ return null;
12025
+ switch (position.role) {
12026
+ case "condition":
12027
+ return read;
12028
+ case "element-attr":
12029
+ return read.accessor === "isPending" && position.attrName !== undefined && (ARIA_BOOLEAN_STATE_ATTRS.has(position.attrName) || isBooleanAttr(position.attrName)) ? read : null;
12030
+ default:
12031
+ return null;
12032
+ }
12033
+ }
12034
+ function seedActionAccessorReads(root, signals) {
12035
+ const actions = collectActionNames(signals);
12036
+ if (actions.size === 0)
12037
+ return;
12038
+ walkTemplatePositions(root, (position) => {
12039
+ const read = seedableActionAccessorRead(position, actions);
12040
+ if (!read || !position.host)
12041
+ return;
12042
+ const parsed = actionAccessorSeedParsed(read.accessor);
12043
+ const text = actionAccessorSeedText(read.accessor);
12044
+ if (position.host.kind === "condition") {
12045
+ position.host.node.parsedCondition = parsed;
12046
+ position.host.node.templateCondition = text;
12047
+ } else {
12048
+ position.host.value.parsed = parsed;
12049
+ position.host.value.templateExpr = text;
12050
+ }
12051
+ });
12052
+ }
12053
+ function actionAccessorSeedParsed(_accessor) {
12054
+ return { kind: "literal", value: false, literalType: "boolean" };
12055
+ }
12056
+ function actionAccessorSeedText(accessor) {
12057
+ return accessor === "isPending" ? "false" : "undefined";
12058
+ }
12059
+
12060
+ // src/jsx-to-ir.ts
11430
12061
  var BLOCK_COMMENT_RE2 = /\/\*([\s\S]*?)\*\//g;
11431
12062
  function hasLeadingClientDirective(expr, sourceFile) {
11432
12063
  const trivia = sourceFile.text.slice(expr.pos, expr.getStart(sourceFile));
@@ -11953,6 +12584,7 @@ function jsxToIR(analyzer) {
11953
12584
  if (root) {
11954
12585
  reportRefAttrsAbsentAtSsr(root, ctx);
11955
12586
  attachParsedExpressions(root, analyzer);
12587
+ seedActionAccessorReads(root, analyzer.signals);
11956
12588
  resolveRootKeyAttr(root);
11957
12589
  }
11958
12590
  return root;
@@ -12467,7 +13099,7 @@ function transformSelfClosingComponent(node, ctx, name) {
12467
13099
  function isTransparentFragment(node, ctx) {
12468
13100
  const children = node.children.filter((child2) => {
12469
13101
  if (ts18.isJsxText(child2)) {
12470
- return child2.text.trim() !== "";
13102
+ return cleanJsxWhitespace(child2.text) !== "";
12471
13103
  }
12472
13104
  return true;
12473
13105
  });
@@ -12523,6 +13155,11 @@ function markCarrierIn(node) {
12523
13155
  return null;
12524
13156
  return { ...cond, whenTrue: whenTrue ?? cond.whenTrue, whenFalse: whenFalse ?? cond.whenFalse };
12525
13157
  }
13158
+ if (node.type === "fragment") {
13159
+ const frag = node;
13160
+ const children = markDataKeyCarrier(frag.children);
13161
+ return children === frag.children ? null : { ...frag, children };
13162
+ }
12526
13163
  return null;
12527
13164
  }
12528
13165
  function transformFragment(node, ctx) {
@@ -12550,9 +13187,6 @@ function transformChildren(children, ctx) {
12550
13187
  }
12551
13188
  const transformed = transformNode(child, ctx);
12552
13189
  if (transformed) {
12553
- if (transformed.type === "text" && transformed.value.trim() === "") {
12554
- continue;
12555
- }
12556
13190
  result.push(transformed);
12557
13191
  }
12558
13192
  }
@@ -12566,8 +13200,8 @@ function isRenderNothingLiteral(expr, ctx) {
12566
13200
  return e.kind === ts18.SyntaxKind.NullKeyword || e.kind === ts18.SyntaxKind.TrueKeyword || e.kind === ts18.SyntaxKind.FalseKeyword || ts18.isIdentifier(e) && e.text === "undefined" && !isNameBound("undefined", makeBindingEnv(ctx));
12567
13201
  }
12568
13202
  function transformText(node, ctx) {
12569
- const text = node.text.replace(/\s+/g, " ");
12570
- if (text.trim() === "") {
13203
+ const text = cleanJsxWhitespace(node.text);
13204
+ if (text === "") {
12571
13205
  return null;
12572
13206
  }
12573
13207
  return {
@@ -12576,6 +13210,22 @@ function transformText(node, ctx) {
12576
13210
  loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath)
12577
13211
  };
12578
13212
  }
13213
+ function cleanJsxWhitespace(raw) {
13214
+ const lines = raw.split(/\r\n|\n|\r/);
13215
+ const kept = [];
13216
+ for (let i = 0;i < lines.length; i++) {
13217
+ const isFirstLine = i === 0;
13218
+ const isLastLine = i === lines.length - 1;
13219
+ let line = lines[i].replace(/\t/g, " ");
13220
+ if (!isFirstLine)
13221
+ line = line.replace(/^ +/, "");
13222
+ if (!isLastLine)
13223
+ line = line.replace(/ +$/, "");
13224
+ if (line !== "")
13225
+ kept.push(line);
13226
+ }
13227
+ return kept.join(" ");
13228
+ }
12579
13229
  function transformExpression(node, ctx) {
12580
13230
  if (!node.expression)
12581
13231
  return null;
@@ -14738,7 +15388,8 @@ function expandSpreadAttribute(attr, ctx) {
14738
15388
  name: key,
14739
15389
  value: AttrValueOf.expression(`${restName}.${key}`),
14740
15390
  loc,
14741
- freeIdentifiers: perKeyFreeIds
15391
+ freeIdentifiers: perKeyFreeIds,
15392
+ restExpandedKey: true
14742
15393
  }));
14743
15394
  }
14744
15395
  const slotId = generateSpreadSlotId(ctx);
@@ -15580,7 +16231,7 @@ function processComponentProps(attributes, ctx) {
15580
16231
  const props = [];
15581
16232
  for (const attr of attributes.properties) {
15582
16233
  if (ts18.isJsxSpreadAttribute(attr)) {
15583
- props.push(...expandSpreadAttribute(attr, ctx));
16234
+ props.push(...expandSpreadAttribute(attr, ctx).map(({ restExpandedKey: _restExpandedKey, ...prop }) => prop));
15584
16235
  continue;
15585
16236
  }
15586
16237
  if (!ts18.isJsxAttribute(attr))
@@ -15864,8 +16515,19 @@ function shouldAutoDeferReactiveBrand(expr, ctx) {
15864
16515
  return false;
15865
16516
  if (leaves.some((leaf) => isSignalOrMemoReference(ctx.getJS(leaf), ctx)))
15866
16517
  return false;
16518
+ if (leaves.some((leaf) => isAsyncActionLeaf(leaf, ctx)))
16519
+ return false;
15867
16520
  return true;
15868
16521
  }
16522
+ function isAsyncActionLeaf(leaf, ctx) {
16523
+ let node = leaf;
16524
+ while (ts18.isCallExpression(node) || ts18.isPropertyAccessExpression(node))
16525
+ node = node.expression;
16526
+ if (!ts18.isIdentifier(node))
16527
+ return false;
16528
+ const name = node.text;
16529
+ return ctx.analyzer.signals.some((s) => s.factory?.action === name);
16530
+ }
15869
16531
  function isSignalOrMemoReference(expr, ctx, visited) {
15870
16532
  for (const { pattern } of ctx.patterns.signals) {
15871
16533
  if (pattern.test(expr))
@@ -16230,6 +16892,8 @@ function expandConstantForReactivity(expr, ctx, originalFreeIds, scope) {
16230
16892
  return { expr, freeIds: originalFreeIds };
16231
16893
  }
16232
16894
  function getControlledPropName(signal, propsParams, propsObjectName = null) {
16895
+ if (signal.factory)
16896
+ return null;
16233
16897
  const initialValue = signal.initialValue.trim();
16234
16898
  const isDefaultProp = (propName) => propName.startsWith("default");
16235
16899
  const propsName = propsObjectName ?? "props";
@@ -16414,7 +17078,8 @@ function collectConditionalBranchRefs(node) {
16414
17078
  if (el.slotId && el.ref) {
16415
17079
  refs.push({
16416
17080
  slotId: el.slotId,
16417
- callback: el.ref
17081
+ callback: el.ref,
17082
+ ...el.ssrPortalOwnerScope && { ssrPortalOwner: true }
16418
17083
  });
16419
17084
  }
16420
17085
  }, true);
@@ -16441,7 +17106,7 @@ function emptyLoopChildBindings() {
16441
17106
  conditionals: []
16442
17107
  };
16443
17108
  }
16444
- function collectLoopChildEventsWithNesting(node, initialNestingStack = []) {
17109
+ function collectLoopChildEventsWithNesting(node, initialNestingStack = [], siblingOffsets) {
16445
17110
  const events = [];
16446
17111
  const initialScope = {
16447
17112
  nestingStack: initialNestingStack,
@@ -16481,7 +17146,8 @@ function collectLoopChildEventsWithNesting(node, initialNestingStack = []) {
16481
17146
  key: l.key,
16482
17147
  markerId: l.markerId,
16483
17148
  containerSlotId: scope.lastElementSlotId,
16484
- bindings: emptyLoopChildBindings()
17149
+ bindings: emptyLoopChildBindings(),
17150
+ offset: siblingOffsets ? resolveLoopOffset(siblingOffsets.get(l)) : undefined
16485
17151
  }
16486
17152
  ]
16487
17153
  });
@@ -16955,7 +17621,7 @@ function collectInnerLoops(nodes, siblingOffsets, outerLoopParam, ctx, options)
16955
17621
  }));
16956
17622
  }
16957
17623
  for (const child of n.children) {
16958
- bindings.events.push(...collectLoopChildEventsWithNesting(child));
17624
+ bindings.events.push(...collectLoopChildEventsWithNesting(child, [], siblingOffsets));
16959
17625
  }
16960
17626
  }
16961
17627
  result.push({
@@ -17312,7 +17978,8 @@ function collectFromElement(element, ctx, insideConditional = false) {
17312
17978
  if (element.ref && element.slotId) {
17313
17979
  ctx.refElements.push({
17314
17980
  slotId: element.slotId,
17315
- callback: element.ref
17981
+ callback: element.ref,
17982
+ ...element.ssrPortalOwnerScope && { ssrPortalOwner: true }
17316
17983
  });
17317
17984
  }
17318
17985
  if (element.slotId) {
@@ -17336,6 +18003,20 @@ function collectFromElement(element, ctx, insideConditional = false) {
17336
18003
  const valueStr = attrValueToString(attr.value);
17337
18004
  if (!valueStr)
17338
18005
  continue;
18006
+ const restKeyHtmlName = toHtmlAttrName(attr.name);
18007
+ const collidesWithExplicitAttr = element.attrs.some((other) => other !== attr && other.name !== "..." && toHtmlAttrName(other.name) === restKeyHtmlName);
18008
+ const restKeyDomKind = classifyDOMProp2(attr.name).kind;
18009
+ if (attr.restExpandedKey && !collidesWithExplicitAttr && restKeyDomKind !== "ref" && restKeyDomKind !== "event" && restKeyDomKind !== "skip") {
18010
+ if (insideConditional)
18011
+ continue;
18012
+ ctx.reactiveAttrs.push({
18013
+ slotId: element.slotId,
18014
+ attrName: attr.name,
18015
+ expression: `${PROPS_PARAM}.${attr.name}`,
18016
+ ...pickAttrMetaFromIR(attr)
18017
+ });
18018
+ continue;
18019
+ }
17339
18020
  const expandedResult = expandConstantForReactivity(valueStr, ctx, attr.freeIdentifiers);
17340
18021
  const expandedValueStr = expandedResult.expr;
17341
18022
  if (attr.clientOnly || decideWrapForAttr(expandedValueStr, ctx, attr).wrap) {
@@ -17516,7 +18197,7 @@ function preambleNamesOf(loop) {
17516
18197
  function collectLoopChildBindings(children, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex) {
17517
18198
  const bindings = emptyLoopChildBindings();
17518
18199
  for (const child of children) {
17519
- bindings.events.push(...collectLoopChildEventsWithNesting(child));
18200
+ bindings.events.push(...collectLoopChildEventsWithNesting(child, [], siblingOffsets));
17520
18201
  bindings.reactiveAttrs.push(...collectLoopChildReactiveAttrs(child, ctx, loopParam, loopParamBindings, true, preambleNames, loopIndex));
17521
18202
  bindings.reactiveTexts.push(...collectLoopChildReactiveTexts(child, ctx, loopParam, loopParamBindings, true, preambleNames, loopIndex));
17522
18203
  bindings.refs.push(...collectLoopChildRefs(child));
@@ -17586,8 +18267,9 @@ function buildReferencesGraph(ctx, irRoot) {
17586
18267
  declaredNames.add(f.name);
17587
18268
  for (const s of ctx.signals) {
17588
18269
  declaredNames.add(s.getter);
17589
- if (s.setter)
17590
- declaredNames.add(s.setter);
18270
+ const second = signalSecondBinding(s);
18271
+ if (second)
18272
+ declaredNames.add(second);
17591
18273
  }
17592
18274
  for (const m of ctx.memos)
17593
18275
  declaredNames.add(m.name);
@@ -17674,7 +18356,7 @@ function buildReferencesGraph(ctx, irRoot) {
17674
18356
  }
17675
18357
  }
17676
18358
  for (const signal of ctx.signals) {
17677
- addExprEdges({ kind: "signal", name: signal.getter }, signal.initialValue, "init-body");
18359
+ addExprEdges({ kind: "signal", name: signal.getter }, signal.factory?.argsText ?? signal.initialValue, "init-body");
17678
18360
  }
17679
18361
  for (const memo of ctx.memos) {
17680
18362
  addExprEdges({ kind: "memo", name: memo.name }, memo.computation, "init-body");
@@ -17885,8 +18567,9 @@ function computeDeclarationScopes(ctx, graph) {
17885
18567
  const initRequired = new Set;
17886
18568
  for (const s of ctx.signals) {
17887
18569
  initRequired.add(s.getter);
17888
- if (s.setter)
17889
- initRequired.add(s.setter);
18570
+ const second = signalSecondBinding(s);
18571
+ if (second)
18572
+ initRequired.add(second);
17890
18573
  }
17891
18574
  for (const m of ctx.memos)
17892
18575
  initRequired.add(m.name);
@@ -18503,7 +19186,7 @@ function computeInlinability(ctx, graph, irRoot) {
18503
19186
  functions.set(fn.name, functionScope.get(fn.name) === "module" ? { kind: "module-scope-safe" } : { kind: "references-component-scope" });
18504
19187
  }
18505
19188
  const signalGetters = new Set(ctx.signals.map((s) => s.getter));
18506
- const signalSetters = new Set(ctx.signals.filter((s) => s.setter).map((s) => s.setter));
19189
+ const signalSetters = new Set(ctx.signals.flatMap((s) => signalSecondBinding(s) ?? []));
18507
19190
  const memoNames = new Set(ctx.memos.map((m) => m.name));
18508
19191
  const getterAliases = resolveGetterAliases(ctx.localConstants, (n) => signalGetters.has(n) || memoNames.has(n));
18509
19192
  const env = buildEnvFromCtx(ctx);
@@ -18822,8 +19505,6 @@ function emitRegistrationAndHydration(lines, ctx, _ir, graph, inlinability) {
18822
19505
  const propNamesForStaticCheck = new Set(ctx.propsParams.map((p) => p.name));
18823
19506
  const { inlinableConstants, unsafeLocalNames } = inlinability ?? buildInlinableConstants(ctx, graph, _ir.root);
18824
19507
  const restSpreadNames = resolveRestSpreadNames(ctx);
18825
- const isFragmentRoot = _ir.root.type === "fragment" && !!_ir.root.needsScopeComment;
18826
- const isCommentScope = isCommentScopedRoot(_ir.root);
18827
19508
  const defParts = [`init: ${initFunctionName(name)}`];
18828
19509
  if (canGenerateStaticTemplate(_ir.root, propNamesForStaticCheck, inlinableConstants, unsafeLocalNames)) {
18829
19510
  const markupSlotIds = markupSlotIdsOf(ctx);
@@ -18838,12 +19519,7 @@ function emitRegistrationAndHydration(lines, ctx, _ir, graph, inlinability) {
18838
19519
  defParts.push(buildTemplateDefPart(ctx, templateHtml));
18839
19520
  }
18840
19521
  }
18841
- if (isCommentScope) {
18842
- defParts.push("comment: true");
18843
- }
18844
- if (isFragmentRoot) {
18845
- defParts.push("fragmentRoot: true");
18846
- }
19522
+ defParts.push(...componentDefScopeFlags(_ir.root));
18847
19523
  const registryKey = nameForRegistryRef(name);
18848
19524
  if (registryKey !== name) {
18849
19525
  defParts.push(`name: '${name}'`);
@@ -18930,8 +19606,10 @@ function providedNames(decl) {
18930
19606
  switch (decl.kind) {
18931
19607
  case "constant":
18932
19608
  return [decl.info.name];
18933
- case "signal":
18934
- return decl.info.setter ? [decl.info.getter, decl.info.setter] : [decl.info.getter];
19609
+ case "signal": {
19610
+ const second = signalSecondBinding(decl.info);
19611
+ return second ? [decl.info.getter, second] : [decl.info.getter];
19612
+ }
18935
19613
  case "memo":
18936
19614
  return [decl.info.name];
18937
19615
  case "function":
@@ -19013,76 +19691,21 @@ function sortDeclarations(declarations, declNameSet, graph) {
19013
19691
  }
19014
19692
  }
19015
19693
  ready.splice(insertAt, 0, dep);
19016
- }
19017
- }
19018
- }
19019
- if (result.length < n) {
19020
- const remaining = [];
19021
- for (let i = 0;i < n; i++) {
19022
- if (!visited.has(i))
19023
- remaining.push(i);
19024
- }
19025
- remaining.sort((a, b) => declarations[a].sourceIndex - declarations[b].sourceIndex);
19026
- for (const idx of remaining) {
19027
- result.push(declarations[idx]);
19028
- }
19029
- }
19030
- return result;
19031
- }
19032
-
19033
- // src/adapters/env-signal.ts
19034
- var ENV_SIGNAL_CLIENT_FACTORY = {
19035
- search: "createSearchParams"
19036
- };
19037
- var ENV_SIGNAL_READERS = new Map([
19038
- ["search", { key: "search", canonicalName: "searchParams", methods: new Set(["get"]) }]
19039
- ]);
19040
- function envSignalReaderFor(key) {
19041
- if (key === undefined)
19042
- return null;
19043
- return ENV_SIGNAL_READERS.get(key) ?? null;
19044
- }
19045
- function envSignalLocalNames(metadata, key) {
19046
- const names = new Set;
19047
- for (const s of metadata.signals) {
19048
- if (s.envReader !== undefined && (key === undefined || s.envReader === key)) {
19049
- names.add(s.getter);
19694
+ }
19050
19695
  }
19051
19696
  }
19052
- return names;
19053
- }
19054
- function searchParamsLocalNames(metadata) {
19055
- return envSignalLocalNames(metadata, "search");
19056
- }
19057
- function importsSearchParams(metadata) {
19058
- return searchParamsLocalNames(metadata).size > 0;
19059
- }
19060
- function queryHrefLocalNames(metadata) {
19061
- const names = new Set;
19062
- for (const imp of metadata.imports) {
19063
- if (!CLIENT_HELPER_SOURCES.has(imp.source) || imp.isTypeOnly)
19064
- continue;
19065
- for (const s of imp.specifiers) {
19066
- if (s.isTypeOnly || s.isNamespace || s.isDefault)
19067
- continue;
19068
- if (s.name === "queryHref")
19069
- names.add(s.alias ?? s.name);
19697
+ if (result.length < n) {
19698
+ const remaining = [];
19699
+ for (let i = 0;i < n; i++) {
19700
+ if (!visited.has(i))
19701
+ remaining.push(i);
19702
+ }
19703
+ remaining.sort((a, b) => declarations[a].sourceIndex - declarations[b].sourceIndex);
19704
+ for (const idx of remaining) {
19705
+ result.push(declarations[idx]);
19070
19706
  }
19071
19707
  }
19072
- return names;
19073
- }
19074
- var CLIENT_HELPER_SOURCES = new Set([
19075
- "@barefootjs/client",
19076
- "@barefootjs/client/runtime"
19077
- ]);
19078
- function matchSearchParamsMethodCall(callee, args, localNames) {
19079
- if (callee.kind !== "member" || callee.computed)
19080
- return null;
19081
- const recv = callee.object;
19082
- if (recv.kind !== "call" || recv.args.length !== 0 || recv.callee.kind !== "identifier" || !localNames.has(recv.callee.name)) {
19083
- return null;
19084
- }
19085
- return { method: callee.property, args };
19708
+ return result;
19086
19709
  }
19087
19710
 
19088
19711
  // src/ir-to-client-js/plan/build-declaration-emit.ts
@@ -19131,19 +19754,18 @@ function buildDeclarationEmitPlan(decl, ctx, lookups) {
19131
19754
  }
19132
19755
  }
19133
19756
  function buildSignalPlan(signal, ctx, lookups) {
19134
- if (signal.envReader) {
19135
- const factory = signal.envFactory ?? ENV_SIGNAL_CLIENT_FACTORY[signal.envReader];
19136
- if (factory) {
19137
- return {
19138
- kind: "signal",
19139
- getter: signal.getter,
19140
- setter: signal.setter,
19141
- getterElided: signal.getterElided,
19142
- initialValueExpr: "",
19143
- controlledEffect: null,
19144
- initializerOverride: `${factory}()`
19145
- };
19146
- }
19757
+ const initializerOverride = signalFactoryInitializer(signal);
19758
+ if (initializerOverride) {
19759
+ return {
19760
+ kind: "signal",
19761
+ getter: signal.getter,
19762
+ setter: signalSecondBinding(signal),
19763
+ getterElided: signal.getterElided,
19764
+ initialValueExpr: "",
19765
+ controlledEffect: null,
19766
+ initializerOverride,
19767
+ branchCondition: signal.factory ? signal.branchCondition : undefined
19768
+ };
19147
19769
  }
19148
19770
  const controlledEffect = buildControlledSignalEffect(signal, lookups);
19149
19771
  if (controlledEffect && ctx.profile) {
@@ -19227,11 +19849,15 @@ function bfIdArg(bfId) {
19227
19849
  function emitSignal(lines, plan) {
19228
19850
  const getterSlot = plan.getterElided ? "" : plan.getter;
19229
19851
  if (plan.initializerOverride) {
19230
- if (plan.setter) {
19231
- lines.push(` const [${getterSlot}, ${plan.setter}] = ${plan.initializerOverride}`);
19232
- } else {
19233
- lines.push(` const [${plan.getter}] = ${plan.initializerOverride}`);
19852
+ const bindings = plan.setter ? `${getterSlot}, ${plan.setter}` : plan.getter;
19853
+ if (plan.branchCondition) {
19854
+ lines.push(plan.setter ? plan.getterElided ? ` let ${plan.setter}` : ` let ${plan.getter}, ${plan.setter}` : ` let ${plan.getter}`);
19855
+ lines.push(` if (${plan.branchCondition}) {`);
19856
+ lines.push(` ;[${bindings}] = ${plan.initializerOverride}`);
19857
+ lines.push(` }`);
19858
+ return;
19234
19859
  }
19860
+ lines.push(` const [${bindings}] = ${plan.initializerOverride}`);
19235
19861
  return;
19236
19862
  }
19237
19863
  const id = bfIdArg(plan.bfId);
@@ -19427,13 +20053,15 @@ function emitModuleLevelDeclarations(moduleLevelConstants, moduleLevelFunctions,
19427
20053
  }
19428
20054
  for (const signal of moduleLevelSignals) {
19429
20055
  const tupleVar = `__bf_m_${signal.getter}_tuple`;
20056
+ const initializer = signalFactoryInitializer(signal) ?? `createSignal(${signal.initialValue})`;
20057
+ const second = signalSecondBinding(signal);
19430
20058
  if (signal.isExported) {
19431
- lines.push(`export const [${signal.getter}${signal.setter ? `, ${signal.setter}` : ""}] = createSignal(${signal.initialValue})`);
20059
+ lines.push(`export const [${signal.getter}${second ? `, ${second}` : ""}] = ${initializer}`);
19432
20060
  } else {
19433
- lines.push(`var ${tupleVar} = ${tupleVar} ?? createSignal(${signal.initialValue})`);
20061
+ lines.push(`var ${tupleVar} = ${tupleVar} ?? ${initializer}`);
19434
20062
  lines.push(`var ${signal.getter} = ${tupleVar}[0]`);
19435
- if (signal.setter) {
19436
- lines.push(`var ${signal.setter} = ${tupleVar}[1]`);
20063
+ if (second) {
20064
+ lines.push(`var ${second} = ${tupleVar}[1]`);
19437
20065
  }
19438
20066
  }
19439
20067
  }
@@ -21346,7 +21974,7 @@ function emitRefCallbacks(lines, ctx, conditionalSlotIds) {
21346
21974
  if (conditionalSlotIds.has(elem.slotId))
21347
21975
  continue;
21348
21976
  const v = varSlotId(elem.slotId);
21349
- lines.push(` if (_${v}) ${emitRefCall(elem.callback, `_${v}`)}`);
21977
+ lines.push(` if (_${v}) ${emitRefCall(elem.callback, `_${v}`, elem.ssrPortalOwner)}`);
21350
21978
  }
21351
21979
  }
21352
21980
 
@@ -23297,7 +23925,8 @@ function buildArmBody(branch, options) {
23297
23925
  })),
23298
23926
  refs: branch.refs.map((r) => ({
23299
23927
  slotId: r.slotId,
23300
- callback: r.callback
23928
+ callback: r.callback,
23929
+ ...r.ssrPortalOwner && { ssrPortalOwner: true }
23301
23930
  })),
23302
23931
  childComponents: branch.childComponents.map((c) => ({
23303
23932
  name: c.name,
@@ -23489,14 +24118,44 @@ function emitStaticIndexLookup(ls, ev, handlerCall, lookup, containerVar) {
23489
24118
  ls.push(` const __idx = Array.from(${containerVar}.children).indexOf(__el)${idxOffset}`);
23490
24119
  ls.push(` const ${param} = ${arrayExpr}[__idx]`);
23491
24120
  ls.push(` if (${param}) {`);
24121
+ const { guardNames: nestedGuardNames, paramLines: nestedParamLines } = emitNestedIndexParams(ls, ev, "__el", " ");
24122
+ const guarded = nestedGuardNames.length > 0;
24123
+ if (guarded)
24124
+ ls.push(` if (${nestedGuardNames.join(" && ")}) {`);
24125
+ const bodyIndent = guarded ? " " : " ";
24126
+ for (const line of nestedParamLines)
24127
+ ls.push(`${bodyIndent}${line}`);
23492
24128
  if (preambleLine)
23493
- ls.push(` ${preambleLine}`);
24129
+ ls.push(`${bodyIndent}${preambleLine}`);
23494
24130
  if (idxLine)
23495
- ls.push(` ${idxLine}`);
23496
- ls.push(` ;${handlerCall}`);
24131
+ ls.push(`${bodyIndent}${idxLine}`);
24132
+ ls.push(`${bodyIndent};${handlerCall}`);
24133
+ if (guarded)
24134
+ ls.push(` }`);
23497
24135
  ls.push(` }`);
23498
24136
  ls.push(` }`);
23499
24137
  }
24138
+ function emitNestedIndexParams(ls, ev, baseScopeVar, indent) {
24139
+ const evVar = varSlotId(ev.childSlotId);
24140
+ const guardNames = [];
24141
+ const paramLines = [];
24142
+ let scopeVar = baseScopeVar;
24143
+ for (const nested of ev.nestedLoops) {
24144
+ const containerVarName = `__ic${nested.depth}`;
24145
+ const rowVarName = `__ir${nested.depth}`;
24146
+ const idxVarName = `__iidx${nested.depth}`;
24147
+ const containerExpr = nested.containerSlotId ? `${scopeVar}.querySelector('[bf="${nested.containerSlotId}"]') || ${scopeVar}` : scopeVar;
24148
+ ls.push(`${indent}const ${containerVarName} = ${containerExpr}`);
24149
+ ls.push(`${indent}let ${rowVarName} = ${evVar}El`);
24150
+ ls.push(`${indent}while (${rowVarName}.parentElement && ${rowVarName}.parentElement !== ${containerVarName}) ${rowVarName} = ${rowVarName}.parentElement`);
24151
+ const offsetSuffix = buildLoopChildIndexSubtraction(nested.offset);
24152
+ ls.push(`${indent}const ${idxVarName} = ${rowVarName}.parentElement === ${containerVarName} ? Array.from(${containerVarName}.children).indexOf(${rowVarName})${offsetSuffix} : -1`);
24153
+ guardNames.push(`${idxVarName} >= 0`);
24154
+ paramLines.push(`const ${nested.param} = ${nested.array}[${idxVarName}]`);
24155
+ scopeVar = rowVarName;
24156
+ }
24157
+ return { guardNames, paramLines };
24158
+ }
23500
24159
 
23501
24160
  // src/ir-to-client-js/control-flow/stringify/branch-loop.ts
23502
24161
  function stringifyBranchLoop(lines, plan) {
@@ -23649,7 +24308,7 @@ function emitArmBody(lines, body, mode, indent, profileComponentName) {
23649
24308
  }
23650
24309
  for (const ref of body.refs) {
23651
24310
  const v = varSlotId(ref.slotId);
23652
- lines.push(`${indent}if (_${v}) ${emitRefCall(ref.callback, `_${v}`)}`);
24311
+ lines.push(`${indent}if (_${v}) ${emitRefCall(ref.callback, `_${v}`, ref.ssrPortalOwner)}`);
23653
24312
  }
23654
24313
  for (let i = 0;i < body.childComponents.length; i++) {
23655
24314
  const comp = body.childComponents[i];
@@ -24453,7 +25112,8 @@ function generateTemplateOnlyMount(ir, ctx) {
24453
25112
  lines.push(`function ${initName}() {}`);
24454
25113
  lines.push("");
24455
25114
  const nameField = registryKey !== name ? `, name: '${name}'` : "";
24456
- lines.push(`hydrate('${registryKey}', { init: ${initName}, template: (${PROPS_PARAM}) => \`${templateHtml}\`${nameField} })`);
25115
+ const scopeFlags = componentDefScopeFlags(ir.root).map((f) => `, ${f}`).join("");
25116
+ lines.push(`hydrate('${registryKey}', { init: ${initName}, template: (${PROPS_PARAM}) => \`${templateHtml}\`${scopeFlags}${nameField} })`);
24457
25117
  lines.push(`export function ${name}(${PROPS_PARAM}, __bfKey) { return createComponent('${registryKey}', ${PROPS_PARAM}, __bfKey) }`);
24458
25118
  const generatedCode = lines.join(`
24459
25119
  `);
@@ -24469,9 +25129,9 @@ ${externalImports.join(`
24469
25129
 
24470
25130
  // src/ir-to-client-js/client-only-elision.ts
24471
25131
  function decideClientOnlyElision(root) {
24472
- walkNode(root, [], new Set, { bailed: false });
25132
+ walkNode2(root, [], new Set, { bailed: false });
24473
25133
  }
24474
- function walkNode(node, path, forceCloseAncestors, state) {
25134
+ function walkNode2(node, path, forceCloseAncestors, state) {
24475
25135
  if (state.bailed)
24476
25136
  return;
24477
25137
  if (node.type === "element") {
@@ -24533,7 +25193,7 @@ function walkChildren(children, parentPath, forceCloseAncestors, state) {
24533
25193
  return;
24534
25194
  }
24535
25195
  if (!frozen) {
24536
- walkNode(child, [...parentPath, idx], forceCloseAncestors, state);
25196
+ walkNode2(child, [...parentPath, idx], forceCloseAncestors, state);
24537
25197
  }
24538
25198
  idx += 1;
24539
25199
  pendingText = false;
@@ -25162,6 +25822,8 @@ function extractSsrDefaults(metadata) {
25162
25822
  continue;
25163
25823
  if (sig.envReader)
25164
25824
  continue;
25825
+ if (isElidedFactoryGetter(sig))
25826
+ continue;
25165
25827
  const value = tryStaticEval(sig.initialValue, { bindings, propsLike });
25166
25828
  if (metadata.propsObjectName !== null && referencesOwnProp(sig.initialValue, metadata.propsObjectName, sig.getter, localConsts)) {
25167
25829
  if (!(sig.getter in out)) {
@@ -26026,7 +26688,7 @@ function computeSsrSeedPlan(metadata) {
26026
26688
  }
26027
26689
  }
26028
26690
  const expr = signal.initialValue.trim();
26029
- steps.push(expr === "" ? { kind: "opaque", name: signal.getter, origin: "signal" } : classify2(signal.getter, "signal", expr, resolveThroughLocalConsts(signal.parsed ?? parseExpression(`(${expr})`), localConsts), available));
26691
+ steps.push(expr === "" || isElidedFactoryGetter(signal) ? { kind: "opaque", name: signal.getter, origin: "signal" } : classify2(signal.getter, "signal", expr, resolveThroughLocalConsts(signal.parsed ?? parseExpression(`(${expr})`), localConsts), available));
26030
26692
  available.add(signal.getter);
26031
26693
  }
26032
26694
  for (const memo of metadata.memos) {
@@ -26045,7 +26707,7 @@ function checkRichTypeMethodCalls(root, metadata, errors) {
26045
26707
  return;
26046
26708
  const matchers = prepareLoweringMatchers(metadata);
26047
26709
  const seen = new Set;
26048
- walkNode2(root, metadata, EMPTY_BINDINGS2, matchers, errors, seen);
26710
+ walkNode3(root, metadata, EMPTY_BINDINGS2, matchers, errors, seen);
26049
26711
  }
26050
26712
  function checkRichTypePropSerialization(root, metadata, errors, declLoc) {
26051
26713
  if (!metadata.propsType || !metadata.clientAnalysis?.needsInit)
@@ -26204,7 +26866,7 @@ function checkExpr(expr, loc, meta, bindings, matchers, errors, seen) {
26204
26866
  break;
26205
26867
  }
26206
26868
  }
26207
- function walkTemplateParts(parts, loc, meta, bindings, matchers, errors, seen) {
26869
+ function walkTemplateParts2(parts, loc, meta, bindings, matchers, errors, seen) {
26208
26870
  for (const part of parts) {
26209
26871
  if (part.type === "ternary") {
26210
26872
  const trimmed = part.condition.trim();
@@ -26217,22 +26879,22 @@ function walkTemplateParts(parts, loc, meta, bindings, matchers, errors, seen) {
26217
26879
  }
26218
26880
  }
26219
26881
  }
26220
- function walkAttrValue(value, clientOnly, loc, meta, bindings, matchers, errors, seen) {
26882
+ function walkAttrValue2(value, clientOnly, loc, meta, bindings, matchers, errors, seen) {
26221
26883
  if (clientOnly)
26222
26884
  return;
26223
26885
  if (value.kind === "expression") {
26224
26886
  if (value.parsed)
26225
26887
  checkExpr(value.parsed, loc, meta, bindings, matchers, errors, seen);
26226
26888
  if (value.parts)
26227
- walkTemplateParts(value.parts, loc, meta, bindings, matchers, errors, seen);
26889
+ walkTemplateParts2(value.parts, loc, meta, bindings, matchers, errors, seen);
26228
26890
  } else if (value.kind === "spread") {
26229
26891
  if (value.parsed)
26230
26892
  checkExpr(value.parsed, loc, meta, bindings, matchers, errors, seen);
26231
26893
  } else if (value.kind === "template") {
26232
- walkTemplateParts(value.parts, loc, meta, bindings, matchers, errors, seen);
26894
+ walkTemplateParts2(value.parts, loc, meta, bindings, matchers, errors, seen);
26233
26895
  }
26234
26896
  }
26235
- function walkNode2(node, meta, bindings, matchers, errors, seen) {
26897
+ function walkNode3(node, meta, bindings, matchers, errors, seen) {
26236
26898
  if (node.type === "expression") {
26237
26899
  if (!node.clientOnly && node.parsed)
26238
26900
  checkExpr(node.parsed, node.loc, meta, bindings, matchers, errors, seen);
@@ -26245,12 +26907,12 @@ function walkNode2(node, meta, bindings, matchers, errors, seen) {
26245
26907
  }
26246
26908
  if (node.type === "element") {
26247
26909
  for (const attr of node.attrs)
26248
- walkAttrValue(attr.value, attr.clientOnly, attr.loc, meta, bindings, matchers, errors, seen);
26910
+ walkAttrValue2(attr.value, attr.clientOnly, attr.loc, meta, bindings, matchers, errors, seen);
26249
26911
  } else if (node.type === "component") {
26250
26912
  for (const prop of node.props)
26251
- walkAttrValue(prop.value, prop.clientOnly, prop.loc, meta, bindings, matchers, errors, seen);
26913
+ walkAttrValue2(prop.value, prop.clientOnly, prop.loc, meta, bindings, matchers, errors, seen);
26252
26914
  } else if (node.type === "provider") {
26253
- walkAttrValue(node.valueProp.value, node.valueProp.clientOnly, node.valueProp.loc, meta, bindings, matchers, errors, seen);
26915
+ walkAttrValue2(node.valueProp.value, node.valueProp.clientOnly, node.valueProp.loc, meta, bindings, matchers, errors, seen);
26254
26916
  }
26255
26917
  switch (node.type) {
26256
26918
  case "element":
@@ -26258,12 +26920,12 @@ function walkNode2(node, meta, bindings, matchers, errors, seen) {
26258
26920
  case "fragment":
26259
26921
  case "provider":
26260
26922
  for (const child of node.children)
26261
- walkNode2(child, meta, bindings, matchers, errors, seen);
26923
+ walkNode3(child, meta, bindings, matchers, errors, seen);
26262
26924
  break;
26263
26925
  case "async":
26264
- walkNode2(node.fallback, meta, bindings, matchers, errors, seen);
26926
+ walkNode3(node.fallback, meta, bindings, matchers, errors, seen);
26265
26927
  for (const child of node.children)
26266
- walkNode2(child, meta, bindings, matchers, errors, seen);
26928
+ walkNode3(child, meta, bindings, matchers, errors, seen);
26267
26929
  break;
26268
26930
  case "loop": {
26269
26931
  if (node.clientOnly)
@@ -26276,35 +26938,35 @@ function walkNode2(node, meta, bindings, matchers, errors, seen) {
26276
26938
  if (node.index)
26277
26939
  loopBindings.set(node.index, null);
26278
26940
  for (const child of node.children)
26279
- walkNode2(child, meta, loopBindings, matchers, errors, seen);
26941
+ walkNode3(child, meta, loopBindings, matchers, errors, seen);
26280
26942
  if (node.childComponent) {
26281
26943
  for (const child of node.childComponent.children)
26282
- walkNode2(child, meta, loopBindings, matchers, errors, seen);
26944
+ walkNode3(child, meta, loopBindings, matchers, errors, seen);
26283
26945
  }
26284
26946
  for (const nested of node.nestedComponents ?? []) {
26285
26947
  for (const child of nested.children)
26286
- walkNode2(child, meta, loopBindings, matchers, errors, seen);
26948
+ walkNode3(child, meta, loopBindings, matchers, errors, seen);
26287
26949
  }
26288
26950
  for (const seg of node.flatMapCallback?.segments ?? []) {
26289
26951
  if (seg.kind === "jsx")
26290
- walkNode2(seg.ir, meta, loopBindings, matchers, errors, seen);
26952
+ walkNode3(seg.ir, meta, loopBindings, matchers, errors, seen);
26291
26953
  }
26292
26954
  for (const seg of node.preamble?.segments ?? []) {
26293
26955
  if (seg.kind === "jsx")
26294
- walkNode2(seg.ir, meta, loopBindings, matchers, errors, seen);
26956
+ walkNode3(seg.ir, meta, loopBindings, matchers, errors, seen);
26295
26957
  }
26296
26958
  break;
26297
26959
  }
26298
26960
  case "conditional":
26299
26961
  if (node.clientOnly)
26300
26962
  break;
26301
- walkNode2(node.whenTrue, meta, bindings, matchers, errors, seen);
26302
- walkNode2(node.whenFalse, meta, bindings, matchers, errors, seen);
26963
+ walkNode3(node.whenTrue, meta, bindings, matchers, errors, seen);
26964
+ walkNode3(node.whenFalse, meta, bindings, matchers, errors, seen);
26303
26965
  break;
26304
26966
  case "if-statement":
26305
- walkNode2(node.consequent, meta, bindings, matchers, errors, seen);
26967
+ walkNode3(node.consequent, meta, bindings, matchers, errors, seen);
26306
26968
  if (node.alternate)
26307
- walkNode2(node.alternate, meta, bindings, matchers, errors, seen);
26969
+ walkNode3(node.alternate, meta, bindings, matchers, errors, seen);
26308
26970
  break;
26309
26971
  }
26310
26972
  }
@@ -26333,7 +26995,10 @@ function checkAuthoredFormatDateCalls(root, metadata, errors) {
26333
26995
  if (names.size === 0)
26334
26996
  return;
26335
26997
  const seen = new Set;
26336
- walkNode3(root, names, errors, seen);
26998
+ walkTemplatePositions(root, ({ expr, loc }) => {
26999
+ if (exprCallsName(expr, names))
27000
+ pushDiagnostic2(errors, seen, loc, anyName(names));
27001
+ });
26337
27002
  }
26338
27003
  function pushDiagnostic2(errors, seen, loc, name) {
26339
27004
  const key = `${loc.start.line}:${loc.start.column}`;
@@ -26400,112 +27065,144 @@ function anyName(names) {
26400
27065
  return n;
26401
27066
  return "formatDate";
26402
27067
  }
26403
- function walkTemplateParts2(parts, loc, names, errors, seen) {
26404
- const checkText = (text) => {
26405
- const trimmed = text.trim();
26406
- if (!trimmed)
26407
- return;
26408
- if (exprCallsName(parseExpression(trimmed), names))
26409
- pushDiagnostic2(errors, seen, loc, anyName(names));
26410
- };
26411
- for (const part of parts) {
26412
- if (part.type === "ternary") {
26413
- checkText(part.condition);
26414
- checkText(part.whenTrue);
26415
- checkText(part.whenFalse);
26416
- } else if (part.type === "lookup") {
26417
- checkText(part.key);
27068
+
27069
+ // src/async-action-refusal.ts
27070
+ function checkAsyncActionReads(root, metadata, errors) {
27071
+ const directActions = collectActionNames(metadata.signals);
27072
+ if (directActions.size === 0)
27073
+ return;
27074
+ const actions = new Set(directActions);
27075
+ for (let grew = true;grew; ) {
27076
+ grew = false;
27077
+ for (const constant of metadata.localConstants) {
27078
+ const target = aliasTarget(constant);
27079
+ if (target !== undefined && actions.has(target) && !actions.has(constant.name)) {
27080
+ actions.add(constant.name);
27081
+ grew = true;
27082
+ }
26418
27083
  }
26419
27084
  }
27085
+ const readers = localsReadingActions(metadata, actions);
27086
+ const seen = new Set;
27087
+ walkTemplatePositions(root, (position) => {
27088
+ const { expr, loc, attrName } = position;
27089
+ if (attrName !== undefined && isEventHandlerName(attrName))
27090
+ return;
27091
+ if (seedableActionAccessorRead(position, directActions))
27092
+ return;
27093
+ const read = findActionRead(expr, actions, readers, new Set);
27094
+ if (read)
27095
+ pushDiagnostic3(errors, seen, loc, read);
27096
+ });
26420
27097
  }
26421
- function walkAttrValue2(value, clientOnly, loc, names, errors, seen) {
26422
- if (clientOnly)
26423
- return;
26424
- if (value.kind === "expression") {
26425
- if (value.parsed && exprCallsName(value.parsed, names))
26426
- pushDiagnostic2(errors, seen, loc, anyName(names));
26427
- if (value.parts)
26428
- walkTemplateParts2(value.parts, loc, names, errors, seen);
26429
- } else if (value.kind === "spread") {
26430
- if (value.parsed && exprCallsName(value.parsed, names))
26431
- pushDiagnostic2(errors, seen, loc, anyName(names));
26432
- } else if (value.kind === "template") {
26433
- walkTemplateParts2(value.parts, loc, names, errors, seen);
27098
+ function localsReadingActions(metadata, actions) {
27099
+ const values = new Map;
27100
+ const callables = new Map;
27101
+ const candidates = [];
27102
+ for (const memo of metadata.memos) {
27103
+ candidates.push({ name: memo.name, declaration: "memo", callable: false, freeIds: memo.computationFreeIdentifiers ?? [] });
26434
27104
  }
26435
- }
26436
- function walkNode3(node, names, errors, seen) {
26437
- if (node.type === "expression") {
26438
- if (!node.clientOnly && node.parsed && exprCallsName(node.parsed, names)) {
26439
- pushDiagnostic2(errors, seen, node.loc, anyName(names));
26440
- }
26441
- } else if (node.type === "conditional") {
26442
- if (!node.clientOnly && node.parsedCondition && exprCallsName(node.parsedCondition, names)) {
26443
- pushDiagnostic2(errors, seen, node.loc, anyName(names));
26444
- }
26445
- } else if (node.type === "if-statement") {
26446
- if (node.parsedCondition && exprCallsName(node.parsedCondition, names)) {
26447
- pushDiagnostic2(errors, seen, node.loc, anyName(names));
26448
- }
27105
+ for (const constant of metadata.localConstants) {
27106
+ if (constant.isJsx || constant.isJsxFunction || actions.has(constant.name))
27107
+ continue;
27108
+ candidates.push({
27109
+ name: constant.name,
27110
+ declaration: "constant",
27111
+ callable: constant.isFunctionValue === true,
27112
+ freeIds: constant.freeIdentifiers ?? [],
27113
+ aliasOf: aliasTarget(constant)
27114
+ });
26449
27115
  }
26450
- if (node.type === "element") {
26451
- for (const attr of node.attrs)
26452
- walkAttrValue2(attr.value, attr.clientOnly, attr.loc, names, errors, seen);
26453
- } else if (node.type === "component") {
26454
- for (const prop of node.props)
26455
- walkAttrValue2(prop.value, prop.clientOnly, prop.loc, names, errors, seen);
26456
- } else if (node.type === "provider") {
26457
- walkAttrValue2(node.valueProp.value, node.valueProp.clientOnly, node.valueProp.loc, names, errors, seen);
27116
+ for (const fn of metadata.localFunctions) {
27117
+ if (fn.isJsxFunction)
27118
+ continue;
27119
+ candidates.push({ name: fn.name, declaration: "function", callable: true, freeIds: fn.freeIdentifiers ?? [] });
26458
27120
  }
26459
- switch (node.type) {
26460
- case "element":
26461
- case "component":
26462
- case "fragment":
26463
- case "provider":
26464
- for (const child of node.children)
26465
- walkNode3(child, names, errors, seen);
26466
- break;
26467
- case "async":
26468
- walkNode3(node.fallback, names, errors, seen);
26469
- for (const child of node.children)
26470
- walkNode3(child, names, errors, seen);
26471
- break;
26472
- case "loop": {
26473
- if (node.clientOnly)
26474
- break;
26475
- if (node.arrayParsed && exprCallsName(node.arrayParsed, names))
26476
- pushDiagnostic2(errors, seen, node.loc, anyName(names));
26477
- for (const child of node.children)
26478
- walkNode3(child, names, errors, seen);
26479
- if (node.childComponent) {
26480
- for (const child of node.childComponent.children)
26481
- walkNode3(child, names, errors, seen);
26482
- }
26483
- for (const nested of node.nestedComponents ?? []) {
26484
- for (const child of nested.children)
26485
- walkNode3(child, names, errors, seen);
26486
- }
26487
- for (const seg of node.flatMapCallback?.segments ?? []) {
26488
- if (seg.kind === "jsx")
26489
- walkNode3(seg.ir, names, errors, seen);
27121
+ let changed = true;
27122
+ while (changed) {
27123
+ changed = false;
27124
+ for (const candidate of candidates) {
27125
+ if (values.has(candidate.name) || callables.has(candidate.name))
27126
+ continue;
27127
+ if (candidate.aliasOf !== undefined) {
27128
+ const target = values.get(candidate.aliasOf) ?? callables.get(candidate.aliasOf);
27129
+ if (target === undefined)
27130
+ continue;
27131
+ const reader = { declaration: candidate.declaration, action: target.action };
27132
+ if (callables.has(candidate.aliasOf))
27133
+ callables.set(candidate.name, reader);
27134
+ else
27135
+ values.set(candidate.name, reader);
27136
+ changed = true;
27137
+ continue;
26490
27138
  }
26491
- for (const seg of node.preamble?.segments ?? []) {
26492
- if (seg.kind === "jsx")
26493
- walkNode3(seg.ir, names, errors, seen);
27139
+ for (const id of candidate.freeIds) {
27140
+ if (id === candidate.name)
27141
+ continue;
27142
+ const action = actions.has(id) ? id : (values.get(id) ?? callables.get(id))?.action;
27143
+ if (action === undefined)
27144
+ continue;
27145
+ const reader = { declaration: candidate.declaration, action };
27146
+ if (candidate.callable)
27147
+ callables.set(candidate.name, reader);
27148
+ else
27149
+ values.set(candidate.name, reader);
27150
+ changed = true;
27151
+ break;
26494
27152
  }
26495
- break;
26496
27153
  }
26497
- case "conditional":
26498
- if (node.clientOnly)
26499
- break;
26500
- walkNode3(node.whenTrue, names, errors, seen);
26501
- walkNode3(node.whenFalse, names, errors, seen);
27154
+ }
27155
+ return { values, callables };
27156
+ }
27157
+ function aliasTarget(constant) {
27158
+ return constant.parsed?.kind === "identifier" ? constant.parsed.name : undefined;
27159
+ }
27160
+ function findActionRead(expr, actions, readers, bound) {
27161
+ switch (expr.kind) {
27162
+ case "identifier": {
27163
+ if (bound.has(expr.name))
27164
+ return null;
27165
+ const reader = readers.values.get(expr.name);
27166
+ return reader ? { kind: "local", name: expr.name, ...reader } : null;
27167
+ }
27168
+ case "member":
27169
+ if (expr.object.kind === "identifier" && actions.has(expr.object.name) && !bound.has(expr.object.name) && ACTION_ACCESSOR_NAMES.has(expr.property)) {
27170
+ return { kind: "accessor", action: expr.object.name, accessor: expr.property };
27171
+ }
26502
27172
  break;
26503
- case "if-statement":
26504
- walkNode3(node.consequent, names, errors, seen);
26505
- if (node.alternate)
26506
- walkNode3(node.alternate, names, errors, seen);
27173
+ case "call":
27174
+ if (expr.callee.kind === "identifier" && !bound.has(expr.callee.name)) {
27175
+ if (actions.has(expr.callee.name))
27176
+ return { kind: "call", action: expr.callee.name };
27177
+ const reader = readers.callables.get(expr.callee.name);
27178
+ if (reader)
27179
+ return { kind: "local", name: expr.callee.name, ...reader };
27180
+ }
26507
27181
  break;
26508
27182
  }
27183
+ for (const child of parsedExprChildren(expr)) {
27184
+ const read = findActionRead(child.expr, actions, readers, child.params ? new Set([...bound, ...child.params]) : bound);
27185
+ if (read)
27186
+ return read;
27187
+ }
27188
+ return null;
27189
+ }
27190
+ function pushDiagnostic3(errors, seen, loc, read) {
27191
+ const key = `${loc.start.line}:${loc.start.column}`;
27192
+ if (seen.has(key))
27193
+ return;
27194
+ seen.add(key);
27195
+ const what = read.kind === "accessor" ? `'${read.action}.${read.accessor}' reads an async action's accessor` : read.kind === "call" ? `'${read.action}()' calls an async action, which sends a request,` : `${read.declaration} '${read.name}' reads the async action '${read.action}' and is used`;
27196
+ errors.push({
27197
+ code: ErrorCodes.ASYNC_ACTION_READ_IN_TEMPLATE,
27198
+ severity: "error",
27199
+ message: `${what} in a template position. The request function never runs on the server, so ` + `'${read.action}.isPending()' and '${read.action}.error()' have no value to render there yet.`,
27200
+ loc,
27201
+ suggestion: {
27202
+ message: "Defer the read to the client with /* @client */, or read it inside an event handler or " + "effect, which only run on the client.",
27203
+ escape: [{ kind: "client-directive" }]
27204
+ }
27205
+ });
26509
27206
  }
26510
27207
 
26511
27208
  // src/compiler.ts
@@ -26572,6 +27269,7 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
26572
27269
  const files = [];
26573
27270
  const errors = [];
26574
27271
  const adapter = options.adapter;
27272
+ const skipTemplateAssembly = adapter.emitsTemplates === false;
26575
27273
  const entries = [];
26576
27274
  const callerProgram = options.program?.getSourceFile(filePath)?.text === source ? options.program : undefined;
26577
27275
  const program = callerProgram ?? (needsTypeBasedDetection(source) ? createProgramForFile(source, filePath)?.program : undefined);
@@ -26596,6 +27294,7 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
26596
27294
  checkRichTypeMethodCalls(componentIR.root, componentIR.metadata, errors);
26597
27295
  checkRichTypePropSerialization(componentIR.root, componentIR.metadata, errors, ctx.propsDestructuring?.loc);
26598
27296
  checkAuthoredFormatDateCalls(componentIR.root, componentIR.metadata, errors);
27297
+ checkAsyncActionReads(componentIR.root, componentIR.metadata, errors);
26599
27298
  decideComponentRootScopeComment(componentIR);
26600
27299
  decideClientOnlyElision(componentIR.root);
26601
27300
  entries.push({ componentIR, ctx });
@@ -26703,7 +27402,7 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
26703
27402
  scriptAssets: options.scriptAssets,
26704
27403
  preloadAssets: options.preloadAssets
26705
27404
  });
26706
- const moduleExports = generateModuleExports(componentIR, fileWideInlineExported, options.rewriteRelativeImport, { skipValueDeclarations: adapterOutput.sections.moduleConstantsIncludeExports });
27405
+ const moduleExports = skipTemplateAssembly ? "" : generateModuleExports(componentIR, fileWideInlineExported, options.rewriteRelativeImport, { skipValueDeclarations: adapterOutput.sections.moduleConstantsIncludeExports });
26707
27406
  const s = adapterOutput.sections;
26708
27407
  const imports = s.imports;
26709
27408
  const types = s.types;
@@ -26769,43 +27468,48 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
26769
27468
  }
26770
27469
  return { files, errors };
26771
27470
  }
26772
- const mergedImports = mergeTemplateImports(allOutputs.flatMap((o) => o.imports ? o.imports.split(`
27471
+ let combinedTemplate;
27472
+ if (skipTemplateAssembly) {
27473
+ combinedTemplate = "";
27474
+ } else {
27475
+ const mergedImports = mergeTemplateImports(allOutputs.flatMap((o) => o.imports ? o.imports.split(`
26773
27476
  `) : []));
26774
- const seenTypes = new Set;
26775
- const uniqueTypes = [];
26776
- for (const output of allOutputs) {
26777
- if (output.types && !seenTypes.has(output.types)) {
26778
- seenTypes.add(output.types);
26779
- uniqueTypes.push(output.types);
26780
- }
26781
- }
26782
- const seenModuleExports = new Set;
26783
- const uniqueModuleExports = [];
26784
- for (const output of allOutputs) {
26785
- if (output.moduleExports) {
26786
- for (const line of output.moduleExports.split(`
27477
+ const seenTypes = new Set;
27478
+ const uniqueTypes = [];
27479
+ for (const output of allOutputs) {
27480
+ if (output.types && !seenTypes.has(output.types)) {
27481
+ seenTypes.add(output.types);
27482
+ uniqueTypes.push(output.types);
27483
+ }
27484
+ }
27485
+ const seenModuleExports = new Set;
27486
+ const uniqueModuleExports = [];
27487
+ for (const output of allOutputs) {
27488
+ if (output.moduleExports) {
27489
+ for (const line of output.moduleExports.split(`
26787
27490
  `)) {
26788
- if (line.trim() && !seenModuleExports.has(line)) {
26789
- seenModuleExports.add(line);
26790
- uniqueModuleExports.push(line);
27491
+ if (line.trim() && !seenModuleExports.has(line)) {
27492
+ seenModuleExports.add(line);
27493
+ uniqueModuleExports.push(line);
27494
+ }
26791
27495
  }
26792
27496
  }
26793
27497
  }
26794
- }
26795
- const combinedTemplate = [
26796
- mergedImports,
26797
- moduleStatementsOrdered.join(`
27498
+ combinedTemplate = [
27499
+ mergedImports,
27500
+ moduleStatementsOrdered.join(`
26798
27501
 
26799
27502
  `),
26800
- uniqueTypes.join(`
27503
+ uniqueTypes.join(`
26801
27504
 
26802
27505
  `),
26803
- uniqueModuleExports.length > 0 ? uniqueModuleExports.join(`
27506
+ uniqueModuleExports.length > 0 ? uniqueModuleExports.join(`
26804
27507
  `) : "",
26805
- ...allOutputs.map((o) => o.component)
26806
- ].filter(Boolean).join(`
27508
+ ...allOutputs.map((o) => o.component)
27509
+ ].filter(Boolean).join(`
26807
27510
 
26808
27511
  `);
27512
+ }
26809
27513
  files.push({
26810
27514
  path: filePath.replace(/\.tsx?$/, adapter.extension),
26811
27515
  content: combinedTemplate,
@@ -26952,6 +27656,7 @@ function compileJSX(source, filePath, options) {
26952
27656
  checkRichTypeMethodCalls(componentIR.root, componentIR.metadata, errors);
26953
27657
  checkRichTypePropSerialization(componentIR.root, componentIR.metadata, errors, ctx.propsDestructuring?.loc);
26954
27658
  checkAuthoredFormatDateCalls(componentIR.root, componentIR.metadata, errors);
27659
+ checkAsyncActionReads(componentIR.root, componentIR.metadata, errors);
26955
27660
  decideComponentRootScopeComment(componentIR);
26956
27661
  decideClientOnlyElision(componentIR.root);
26957
27662
  if (ctx.importedClientSignalNames.size > 0) {
@@ -26996,6 +27701,8 @@ function compileJSX(source, filePath, options) {
26996
27701
  let content;
26997
27702
  if (adapter.templatesPerComponent) {
26998
27703
  content = adapterOutput.template;
27704
+ } else if (adapter.emitsTemplates === false) {
27705
+ content = "";
26999
27706
  } else {
27000
27707
  const moduleExports = generateModuleExports(componentIR, undefined, options.rewriteRelativeImport, {
27001
27708
  skipValueDeclarations: s.moduleConstantsIncludeExports
@@ -27183,13 +27890,19 @@ class JsxAdapter extends BaseAdapter {
27183
27890
  }
27184
27891
  continue;
27185
27892
  }
27186
- const rawInitialValue = preserveTypes ? signal.typedInitialValue ?? signal.initialValue : signal.initialValue;
27187
- const initialValue = rawInitialValue.trim().startsWith("{") ? `(${rawInitialValue})` : rawInitialValue;
27188
- const needsTypeAssertion = preserveTypes && !signal.typedInitialValue && signal.type.kind !== "unknown" && signal.type.kind !== "primitive" && signal.type.raw !== "object";
27189
- if (needsTypeAssertion) {
27190
- lines.push(` const ${signal.getter} = () => ${initialValue} as ${signal.type.raw}`);
27191
- } else {
27192
- lines.push(` const ${signal.getter} = () => ${initialValue}`);
27893
+ if (!isElidedFactoryGetter(signal)) {
27894
+ const rawInitialValue = preserveTypes ? signal.typedInitialValue ?? signal.initialValue : signal.initialValue;
27895
+ const initialValue = rawInitialValue.trim().startsWith("{") ? `(${rawInitialValue})` : rawInitialValue;
27896
+ const needsTypeAssertion = preserveTypes && !signal.typedInitialValue && signal.type.kind !== "unknown" && signal.type.kind !== "primitive" && signal.type.raw !== "object";
27897
+ if (needsTypeAssertion) {
27898
+ lines.push(` const ${signal.getter} = () => ${initialValue} as ${signal.type.raw}`);
27899
+ } else {
27900
+ lines.push(` const ${signal.getter} = () => ${initialValue}`);
27901
+ }
27902
+ }
27903
+ const action = signal.factory?.action;
27904
+ if (action && identifierPattern(action).test(setterRefText)) {
27905
+ lines.push(preserveTypes ? ` const ${action}: any = Object.assign(() => {}, { isPending: () => false, error: () => undefined })` : ` const ${action} = Object.assign(() => {}, { isPending: () => false, error: () => undefined })`);
27193
27906
  }
27194
27907
  if (signal.setter) {
27195
27908
  const setterUsed = identifierPattern(signal.setter).test(setterRefText);
@@ -28468,6 +29181,8 @@ function buildComponentGraph(source, filePath, componentName) {
28468
29181
  memos: [],
28469
29182
  effects: [],
28470
29183
  props: [],
29184
+ factories: [],
29185
+ accessors: [],
28471
29186
  domBindings: []
28472
29187
  };
28473
29188
  }
@@ -28480,6 +29195,8 @@ function buildComponentGraph(source, filePath, componentName) {
28480
29195
  memos: [],
28481
29196
  effects: [],
28482
29197
  props: [],
29198
+ factories: [],
29199
+ accessors: [],
28483
29200
  domBindings: []
28484
29201
  };
28485
29202
  }
@@ -28550,89 +29267,107 @@ function buildGraphFromIR(ir) {
28550
29267
  }
28551
29268
  return [...out];
28552
29269
  };
29270
+ const actions = collectActionNames(meta.signals);
29271
+ const accessorNames = new Set;
29272
+ for (const action of actions)
29273
+ for (const accessor of ACTION_ACCESSOR_NAMES)
29274
+ accessorNames.add(`${action}.${accessor}`);
29275
+ const accessorDepsOf = (expr, isShadowed) => [...actions].some((action) => tokenContainsIdent(expr, action)) ? collectActionAccessorReads(parseExpression(expr), actions, isShadowed).map((r) => `${r.action}.${r.accessor}`) : [];
28553
29276
  const domBindings = [];
28554
- collectDomBindings(ir.root, domBindings, signalGetters, memoNames, undefined, BindingScope.EMPTY, propDepsOf);
28555
- const signalConsumers = new Map;
28556
- for (const s of meta.signals)
28557
- signalConsumers.set(s.getter, []);
28558
- for (const memo of meta.memos) {
28559
- for (const dep of memo.deps) {
28560
- signalConsumers.get(dep)?.push(`memo:${memo.name}`);
28561
- }
28562
- }
28563
- for (let i = 0;i < meta.effects.length; i++) {
28564
- const effect = meta.effects[i];
28565
- for (const dep of effect.deps) {
28566
- signalConsumers.get(dep)?.push(`effect:e${i}`);
28567
- }
28568
- }
28569
- for (const dom of domBindings) {
28570
- for (const dep of dom.deps) {
28571
- signalConsumers.get(dep)?.push(`dom:${dom.label}`);
28572
- }
28573
- }
28574
- const memoConsumers = new Map;
28575
- for (const m of meta.memos)
28576
- memoConsumers.set(m.name, []);
28577
- for (let i = 0;i < meta.effects.length; i++) {
28578
- const effect = meta.effects[i];
28579
- for (const dep of effect.deps) {
28580
- memoConsumers.get(dep)?.push(`effect:e${i}`);
28581
- }
28582
- }
28583
- for (const dom of domBindings) {
28584
- for (const dep of dom.deps) {
28585
- memoConsumers.get(dep)?.push(`dom:${dom.label}`);
28586
- }
28587
- }
28588
- for (const memo of meta.memos) {
28589
- for (const dep of memo.deps) {
28590
- memoConsumers.get(dep)?.push(`memo:${memo.name}`);
28591
- }
28592
- }
28593
- const propConsumers = new Map;
28594
- for (const dom of domBindings) {
28595
- if (dom.type === "event")
29277
+ collectDomBindings(ir.root, domBindings, signalGetters, memoNames, undefined, BindingScope.EMPTY, propDepsOf, accessorDepsOf);
29278
+ const factories = [];
29279
+ const factoryOf = new Map;
29280
+ for (const s of meta.signals) {
29281
+ if (!s.factory)
28596
29282
  continue;
28597
- for (const dep of dom.deps) {
28598
- if (signalGetters.has(dep) || memoNames.has(dep))
28599
- continue;
28600
- let consumers = propConsumers.get(dep);
28601
- if (!consumers) {
28602
- consumers = [];
28603
- propConsumers.set(dep, consumers);
28604
- }
28605
- consumers.push(`dom:${dom.label}`);
28606
- }
29283
+ const value = s.getterElided ? null : s.getter;
29284
+ const ids = s.factory.requestFreeIdentifiers;
29285
+ const info = {
29286
+ key: value ?? s.factory.action ?? s.getter,
29287
+ kind: s.factory.kind,
29288
+ callee: s.factory.callee,
29289
+ action: s.factory.action,
29290
+ value,
29291
+ requestDeps: s.factory.kind === "query" ? [
29292
+ ...[...ids].filter((id) => id !== s.getter && (signalGetters.has(id) || memoNames.has(id))),
29293
+ ...propDepsOf(s.factory.requestText, ids)
29294
+ ] : []
29295
+ };
29296
+ factories.push(info);
29297
+ factoryOf.set(s, info);
28607
29298
  }
28608
- const signals = meta.signals.map((s) => ({
28609
- kind: "signal",
28610
- name: s.getter,
28611
- setter: s.setter,
28612
- initialValue: s.initialValue,
28613
- consumers: signalConsumers.get(s.getter) ?? [],
28614
- loc: { file: s.loc.file, line: s.loc.start.line }
28615
- }));
28616
29299
  const memos = meta.memos.map((m) => ({
28617
29300
  kind: "memo",
28618
29301
  name: m.name,
28619
- deps: m.deps,
28620
- consumers: memoConsumers.get(m.name) ?? [],
29302
+ deps: [...m.deps, ...bodyAccessorDeps(m.computation, actions)],
29303
+ consumers: [],
28621
29304
  computation: m.computation,
28622
29305
  loc: { file: m.loc.file, line: m.loc.start.line }
28623
29306
  }));
28624
29307
  const effects = meta.effects.map((e, i) => ({
28625
29308
  kind: "effect",
28626
29309
  label: `e${i}`,
28627
- deps: e.deps,
29310
+ deps: [...e.deps, ...bodyAccessorDeps(e.body, actions)],
28628
29311
  body: e.body,
28629
29312
  loc: { file: e.loc.file, line: e.loc.start.line }
28630
29313
  }));
29314
+ const signalConsumers = new Map(meta.signals.map((s) => [s.getter, []]));
29315
+ const memoConsumers = new Map(meta.memos.map((m) => [m.name, []]));
29316
+ const accessorConsumers = new Map([...accessorNames].map((name) => [name, []]));
29317
+ const propConsumers = new Map;
29318
+ const addConsumer = (dep, consumer, props2) => {
29319
+ const consumers = signalConsumers.get(dep) ?? memoConsumers.get(dep) ?? accessorConsumers.get(dep);
29320
+ if (consumers) {
29321
+ consumers.push(consumer);
29322
+ } else if (props2) {
29323
+ const list = propConsumers.get(dep) ?? [];
29324
+ propConsumers.set(dep, list);
29325
+ list.push(consumer);
29326
+ }
29327
+ };
29328
+ for (const m of memos)
29329
+ for (const dep of m.deps)
29330
+ addConsumer(dep, `memo:${m.name}`, false);
29331
+ for (const e of effects)
29332
+ for (const dep of e.deps)
29333
+ addConsumer(dep, `effect:${e.label}`, false);
29334
+ for (const dom of domBindings) {
29335
+ for (const dep of dom.deps)
29336
+ addConsumer(dep, `dom:${dom.label}`, dom.type !== "event");
29337
+ }
29338
+ for (const f of factories)
29339
+ for (const dep of f.requestDeps)
29340
+ addConsumer(dep, `query:${f.key}`, true);
29341
+ for (const m of memos)
29342
+ m.consumers = memoConsumers.get(m.name) ?? [];
29343
+ const signals = meta.signals.filter((s) => !isElidedFactoryGetter(s)).map((s) => {
29344
+ const factory = factoryOf.get(s);
29345
+ return {
29346
+ kind: "signal",
29347
+ name: s.getter,
29348
+ setter: s.setter,
29349
+ initialValue: s.initialValue,
29350
+ consumers: signalConsumers.get(s.getter) ?? [],
29351
+ loc: { file: s.loc.file, line: s.loc.start.line },
29352
+ ...factory && { factory }
29353
+ };
29354
+ });
28631
29355
  const props = [...propConsumers].map(([name, consumers]) => ({
28632
29356
  kind: "prop",
28633
29357
  name,
28634
29358
  consumers
28635
29359
  }));
29360
+ const accessors = factories.flatMap((f) => f.action === null ? [] : [...ACTION_ACCESSOR_NAMES].map((accessor) => {
29361
+ const name = `${f.action}.${accessor}`;
29362
+ return {
29363
+ kind: "accessor",
29364
+ name,
29365
+ action: f.action,
29366
+ accessor,
29367
+ factory: f.key,
29368
+ consumers: accessorConsumers.get(name) ?? []
29369
+ };
29370
+ }));
28636
29371
  return {
28637
29372
  componentName: meta.componentName,
28638
29373
  sourceFile: findSourceFile2(meta) ?? "",
@@ -28640,9 +29375,32 @@ function buildGraphFromIR(ir) {
28640
29375
  memos,
28641
29376
  effects,
28642
29377
  props,
29378
+ factories,
29379
+ accessors,
28643
29380
  domBindings
28644
29381
  };
28645
29382
  }
29383
+ function bodyAccessorDeps(body, actions) {
29384
+ if (![...actions].some((action) => tokenContainsIdent(body, action)))
29385
+ return [];
29386
+ const found = new Set;
29387
+ const visit3 = (node) => {
29388
+ if (ts30.isExpression(node)) {
29389
+ const parsed = tsNodeToParsedExpr(node);
29390
+ if (!containsUnsupported(parsed)) {
29391
+ for (const r of collectActionAccessorReads(parsed, actions))
29392
+ found.add(`${r.action}.${r.accessor}`);
29393
+ return;
29394
+ }
29395
+ }
29396
+ ts30.forEachChild(node, visit3);
29397
+ };
29398
+ visit3(ts30.createSourceFile("__body.tsx", `(${body})`, ts30.ScriptTarget.Latest, true, ts30.ScriptKind.TSX));
29399
+ return [...found];
29400
+ }
29401
+ function containsUnsupported(expr) {
29402
+ return expr.kind === "unsupported" || parsedExprChildren(expr).some((child) => containsUnsupported(child.expr));
29403
+ }
28646
29404
  function buildComponentAnalysis(source, filePath, componentName, program) {
28647
29405
  const ctx = analyzeComponent(source, filePath, componentName, program);
28648
29406
  const emptyIR = {
@@ -29143,8 +29901,19 @@ function traceUpdatePath(graph, targetName) {
29143
29901
  const prop = graph.props.find((p) => p.name === targetName);
29144
29902
  if (prop)
29145
29903
  return { target: targetName, kind: "prop", dependents: traceConsumers(prop.consumers, graph) };
29904
+ const accessor = graph.accessors.find((a) => a.name === targetName);
29905
+ if (accessor)
29906
+ return { target: targetName, kind: "accessor", dependents: traceConsumers(accessor.consumers, graph) };
29146
29907
  return null;
29147
29908
  }
29909
+ function traceableNames(graph) {
29910
+ return [
29911
+ ...graph.signals.map((s) => s.name),
29912
+ ...graph.memos.map((m) => m.name),
29913
+ ...graph.props.map((p) => p.name),
29914
+ ...graph.accessors.map((a) => a.name)
29915
+ ];
29916
+ }
29148
29917
  function traceConsumers(consumers, graph) {
29149
29918
  return consumers.map((consumer) => buildUpdateEntry(consumer, graph, new Set));
29150
29919
  }
@@ -29173,6 +29942,15 @@ function buildUpdateEntry(consumer, graph, visited) {
29173
29942
  if (type === "dom") {
29174
29943
  return { name, kind: "dom", label: name, children: [] };
29175
29944
  }
29945
+ if (type === "query") {
29946
+ const value = graph.signals.find((s) => s.name === name);
29947
+ const readers = [
29948
+ ...value?.consumers ?? [],
29949
+ ...graph.accessors.filter((a) => a.factory === name).flatMap((a) => a.consumers)
29950
+ ];
29951
+ const children = [...new Set(readers)].map((c) => buildUpdateEntry(c, graph, new Set(visited)));
29952
+ return { name, kind: "query", label: `${name} (query)`, children };
29953
+ }
29176
29954
  return { name: consumer, kind: "effect", label: consumer, children: [] };
29177
29955
  }
29178
29956
  function buildWhyUpdate(source, filePath, bindingLabel, componentName) {
@@ -29194,15 +29972,29 @@ function buildWhyUpdate(source, filePath, bindingLabel, componentName) {
29194
29972
  if (s.setter)
29195
29973
  setterToSignal.set(s.setter, s.getter);
29196
29974
  }
29975
+ for (const f of graph.factories) {
29976
+ if (f.action)
29977
+ setterToSignal.set(f.action, f.key);
29978
+ }
29197
29979
  const fnSetters = buildLocalFunctionSetterMap(ir.metadata, setterToSignal);
29198
29980
  const events = collectEventBindings(ir.root, setterToSignal, fnSetters);
29981
+ const changedByOf = (key) => events.flatMap((ev) => ev.setterCalls.filter((sc) => sc.signal === key).map((sc) => ({ handler: ev.eventName, setter: sc.setter, elementContext: ev.elementContext, via: sc.via })));
29982
+ const factoryByKey = new Map(graph.factories.map((f) => [f.key, f]));
29199
29983
  const deps = [];
29200
29984
  const visited = new Set;
29201
29985
  function traceDep(name) {
29202
29986
  if (visited.has(name))
29203
29987
  return;
29204
29988
  visited.add(name);
29205
- const signal = graph.signals.find((s) => s.name === name);
29989
+ const accessor = graph.accessors.find((a) => a.name === name);
29990
+ const signal = accessor ? undefined : graph.signals.find((s) => s.name === name);
29991
+ const factory = factoryByKey.get(accessor?.factory ?? signal?.factory?.key ?? "");
29992
+ if (factory) {
29993
+ deps.push({ name, kind: accessor ? "accessor" : "signal", dependsOn: factory.requestDeps, changedBy: changedByOf(factory.key) });
29994
+ for (const dep of factory.requestDeps)
29995
+ traceDep(dep);
29996
+ return;
29997
+ }
29206
29998
  if (signal) {
29207
29999
  const changedBy = [];
29208
30000
  for (const ev of events) {
@@ -29264,7 +30056,9 @@ function formatWhyUpdate(result) {
29264
30056
  lines.push(" (prop — the parent component passes a new value)");
29265
30057
  } else {
29266
30058
  lines.push(`${dep.name} changes from:`);
29267
- if (dep.changedBy.length === 0) {
30059
+ for (const d of dep.dependsOn)
30060
+ lines.push(` ${d} (re-sends the request)`);
30061
+ if (dep.changedBy.length === 0 && dep.dependsOn.length === 0) {
29268
30062
  lines.push(" (no event handlers found)");
29269
30063
  }
29270
30064
  for (const src of dep.changedBy) {
@@ -29282,7 +30076,17 @@ function formatComponentGraph(graph) {
29282
30076
  if (graph.signals.length > 0) {
29283
30077
  lines.push(` signals:`);
29284
30078
  for (const s of graph.signals) {
29285
- lines.push(` ${s.name} (initial: ${s.initialValue})`);
30079
+ const factory = s.factory ? ` [${s.factory.callee}${s.factory.action ? `, action ${s.factory.action}` : ""}]` + (s.factory.requestDeps.length > 0 ? ` <- ${s.factory.requestDeps.join(", ")}` : "") : "";
30080
+ lines.push(` ${s.name} (initial: ${s.initialValue})${factory}`);
30081
+ }
30082
+ }
30083
+ if (graph.accessors.length > 0) {
30084
+ const factoryByKey = new Map(graph.factories.map((f) => [f.key, f]));
30085
+ lines.push(` accessors:`);
30086
+ for (const a of graph.accessors) {
30087
+ const f = factoryByKey.get(a.factory);
30088
+ const owner = f?.value ? `of ${f.value}` : `${f?.callee}, value not destructured`;
30089
+ lines.push(` ${a.name}() (${owner})`);
29286
30090
  }
29287
30091
  }
29288
30092
  if (graph.memos.length > 0) {
@@ -29332,7 +30136,7 @@ function formatComponentGraph(graph) {
29332
30136
  }
29333
30137
  }
29334
30138
  }
29335
- if (graph.signals.length > 0 || graph.memos.length > 0 || graph.props.length > 0) {
30139
+ if (graph.signals.length > 0 || graph.memos.length > 0 || graph.props.length > 0 || graph.accessors.length > 0) {
29336
30140
  lines.push(` dependency graph:`);
29337
30141
  for (const s of graph.signals) {
29338
30142
  for (const consumer of s.consumers) {
@@ -29349,6 +30153,11 @@ function formatComponentGraph(graph) {
29349
30153
  lines.push(` ${p.name} -> ${consumer}`);
29350
30154
  }
29351
30155
  }
30156
+ for (const a of graph.accessors) {
30157
+ for (const consumer of a.consumers) {
30158
+ lines.push(` ${a.name} -> ${consumer}`);
30159
+ }
30160
+ }
29352
30161
  }
29353
30162
  return lines.join(`
29354
30163
  `);
@@ -29384,7 +30193,8 @@ function graphToJSON(graph) {
29384
30193
  setter: s.setter,
29385
30194
  initialValue: s.initialValue,
29386
30195
  consumers: s.consumers,
29387
- loc: s.loc
30196
+ loc: s.loc,
30197
+ ...s.factory && { factory: s.factory }
29388
30198
  })),
29389
30199
  memos: graph.memos.map((m) => ({
29390
30200
  name: m.name,
@@ -29403,6 +30213,14 @@ function graphToJSON(graph) {
29403
30213
  name: p.name,
29404
30214
  consumers: p.consumers
29405
30215
  })),
30216
+ factories: graph.factories,
30217
+ accessors: graph.accessors.map((a) => ({
30218
+ name: a.name,
30219
+ action: a.action,
30220
+ accessor: a.accessor,
30221
+ factory: a.factory,
30222
+ consumers: a.consumers
30223
+ })),
29406
30224
  domBindings: graph.domBindings.map((d) => ({
29407
30225
  label: d.label,
29408
30226
  slotId: d.slotId,
@@ -29625,7 +30443,7 @@ function inferWrapReasonForAttrLike(hasStringReactive, hasPropsRef, flags) {
29625
30443
  const decision = decideWrapFromAstFlags(flags);
29626
30444
  return decision.wrap ? decision.reason : undefined;
29627
30445
  }
29628
- function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag, scope = BindingScope.EMPTY, propDepsOf = () => []) {
30446
+ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag, scope = BindingScope.EMPTY, propDepsOf = () => [], accessorDepsOf = () => []) {
29629
30447
  const boundNames = scope.valueBoundNames();
29630
30448
  const isShadowed = scope.asShadowPredicate();
29631
30449
  const setSomeIn = (names, other) => {
@@ -29647,7 +30465,10 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
29647
30465
  const expr = attrValueToString2(attr.value);
29648
30466
  if (!expr)
29649
30467
  continue;
29650
- const signalDeps = extractReactiveDeps(expr, signalGetters, memoNames);
30468
+ const signalDeps = [
30469
+ ...extractReactiveDeps(expr, signalGetters, memoNames),
30470
+ ...accessorDepsOf(expr, isShadowed)
30471
+ ];
29651
30472
  const isReactive = signalDeps.length > 0 || attrReadsLoopParam(attr.freeIdentifiers);
29652
30473
  const propDeps = propDepsOf(expr, attr.freeIdentifiers, isShadowed);
29653
30474
  const hasPropsRef = propDeps.length > 0;
@@ -29680,16 +30501,18 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
29680
30501
  });
29681
30502
  }
29682
30503
  for (const child of node.children) {
29683
- collectDomBindings(child, bindings, signalGetters, memoNames, node.tag, scope, propDepsOf);
30504
+ collectDomBindings(child, bindings, signalGetters, memoNames, node.tag, scope, propDepsOf, accessorDepsOf);
29684
30505
  }
29685
30506
  break;
29686
30507
  }
29687
30508
  case "expression": {
29688
30509
  const decision = decideWrapFromAstFlags(node);
29689
30510
  const loopReactive = exprReadsLoopParam(node);
29690
- if ((decision.wrap || loopReactive) && node.slotId) {
30511
+ const accessorDeps = accessorDepsOf(node.expr, isShadowed);
30512
+ if ((decision.wrap || loopReactive || accessorDeps.length > 0) && node.slotId) {
29691
30513
  const deps = [
29692
30514
  ...extractReactiveDeps(node.expr, signalGetters, memoNames),
30515
+ ...accessorDeps,
29693
30516
  ...propDepsOf(node.expr, freeIdsOf(node.origin), isShadowed)
29694
30517
  ];
29695
30518
  const preview = parentTag ? `<${parentTag}>{${truncateExpr(node.expr)}}</${parentTag}>` : `{${truncateExpr(node.expr)}}`;
@@ -29699,9 +30522,9 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
29699
30522
  slotId: node.slotId,
29700
30523
  deps,
29701
30524
  type: "text",
29702
- classification: decision.wrap && decision.reason === "proven-reactive" || loopReactive ? "reactive" : "fallback",
30525
+ classification: decision.wrap && decision.reason === "proven-reactive" || loopReactive || accessorDeps.length > 0 ? "reactive" : "fallback",
29703
30526
  expression: node.expr,
29704
- wrapReason: decision.wrap ? decision.reason : "string-reactive",
30527
+ wrapReason: decision.wrap && accessorDeps.length === 0 ? decision.reason : "string-reactive",
29705
30528
  loc: node.loc,
29706
30529
  jsxPreview: preview
29707
30530
  });
@@ -29711,9 +30534,11 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
29711
30534
  case "conditional": {
29712
30535
  const decision = decideWrapFromAstFlags(node);
29713
30536
  const loopReactive = boundNames.size > 0 && (node.origin?.freeRefs?.some((r) => boundNames.has(r.name)) ?? false);
29714
- if ((decision.wrap || loopReactive) && node.slotId) {
30537
+ const accessorDeps = accessorDepsOf(node.condition, isShadowed);
30538
+ if ((decision.wrap || loopReactive || accessorDeps.length > 0) && node.slotId) {
29715
30539
  const deps = [
29716
30540
  ...extractReactiveDeps(node.condition, signalGetters, memoNames),
30541
+ ...accessorDeps,
29717
30542
  ...propDepsOf(node.condition, freeIdsOf(node.origin), isShadowed)
29718
30543
  ];
29719
30544
  bindings.push({
@@ -29722,20 +30547,31 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
29722
30547
  slotId: node.slotId,
29723
30548
  deps,
29724
30549
  type: "conditional",
29725
- classification: decision.wrap && decision.reason === "proven-reactive" || loopReactive ? "reactive" : "fallback",
30550
+ classification: decision.wrap && decision.reason === "proven-reactive" || loopReactive || accessorDeps.length > 0 ? "reactive" : "fallback",
29726
30551
  expression: node.condition,
29727
- wrapReason: decision.wrap ? decision.reason : "string-reactive",
30552
+ wrapReason: decision.wrap && accessorDeps.length === 0 ? decision.reason : "string-reactive",
29728
30553
  loc: node.loc,
29729
30554
  jsxPreview: `{${truncateExpr(node.condition)} ? ... : ...}`
29730
30555
  });
29731
30556
  }
29732
- collectDomBindings(node.whenTrue, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf);
29733
- collectDomBindings(node.whenFalse, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf);
30557
+ collectDomBindings(node.whenTrue, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf);
30558
+ collectDomBindings(node.whenFalse, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf);
29734
30559
  break;
29735
30560
  }
29736
30561
  case "loop": {
29737
30562
  if (node.slotId) {
29738
- const deps = extractReactiveDeps(node.array, signalGetters, memoNames);
30563
+ const { filterPredicate, sortComparator } = node;
30564
+ const callbackDeps = (raw, params) => {
30565
+ const callbackScope = scope.enterCallback(params);
30566
+ return extractReactiveDeps(raw, signalGetters, memoNames).filter((name) => !callbackScope.isBound(name));
30567
+ };
30568
+ const deps = [
30569
+ ...new Set([
30570
+ ...extractReactiveDeps(node.array, signalGetters, memoNames),
30571
+ ...filterPredicate ? callbackDeps(filterPredicate.raw, [filterPredicate.param]) : [],
30572
+ ...sortComparator ? callbackDeps(sortComparator.raw, [sortComparator.paramA, sortComparator.paramB]) : []
30573
+ ])
30574
+ ];
29739
30575
  const loopReactive = boundNames.size > 0 && node.arrayFreeIdentifiers !== undefined && setSomeIn(boundNames, node.arrayFreeIdentifiers);
29740
30576
  const isReactive = deps.length > 0 || node.callsReactiveGetters === true || loopReactive;
29741
30577
  const isFallback = !isReactive && node.hasFunctionCalls === true;
@@ -29757,7 +30593,7 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
29757
30593
  }
29758
30594
  const childScope = scope.enterLoopRow(node);
29759
30595
  for (const child of node.children) {
29760
- collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, childScope, propDepsOf);
30596
+ collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, childScope, propDepsOf, accessorDepsOf);
29761
30597
  }
29762
30598
  break;
29763
30599
  }
@@ -29791,21 +30627,21 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
29791
30627
  }
29792
30628
  }
29793
30629
  for (const child of node.children) {
29794
- collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf);
30630
+ collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf);
29795
30631
  }
29796
30632
  break;
29797
30633
  }
29798
30634
  case "fragment":
29799
30635
  case "provider": {
29800
30636
  for (const child of node.children) {
29801
- collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf);
30637
+ collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf);
29802
30638
  }
29803
30639
  break;
29804
30640
  }
29805
30641
  case "if-statement": {
29806
- collectDomBindings(node.consequent, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf);
30642
+ collectDomBindings(node.consequent, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf);
29807
30643
  if (node.alternate) {
29808
- collectDomBindings(node.alternate, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf);
30644
+ collectDomBindings(node.alternate, bindings, signalGetters, memoNames, parentTag, scope, propDepsOf, accessorDepsOf);
29809
30645
  }
29810
30646
  break;
29811
30647
  }
@@ -31136,6 +31972,7 @@ function profileToJSON(profile) {
31136
31972
  registerBuiltinLoweringPlugins();
31137
31973
  export {
31138
31974
  tsNodeToParsedExpr,
31975
+ traceableNames,
31139
31976
  traceUpdatePath,
31140
31977
  testAdapter,
31141
31978
  stringifyParsedExpr,
@@ -31193,6 +32030,7 @@ export {
31193
32030
  isFunctionShapedExpression,
31194
32031
  isFullyStaticLiteral,
31195
32032
  isEventHandlerName,
32033
+ isElidedFactoryGetter,
31196
32034
  isDangerousInnerHtmlAttr,
31197
32035
  isBooleanAttr,
31198
32036
  importsSearchParams,
@@ -31257,6 +32095,7 @@ export {
31257
32095
  createProgramForFile,
31258
32096
  createProgramForCorpus,
31259
32097
  createError,
32098
+ createAnchoredProgram,
31260
32099
  containsHigherOrder,
31261
32100
  computeSsrSeedPlan,
31262
32101
  compileJSX,