@barefootjs/jsx 0.33.2 → 0.33.4

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 (61) hide show
  1. package/dist/analyzer.d.ts +17 -0
  2. package/dist/analyzer.d.ts.map +1 -1
  3. package/dist/compiler.d.ts +21 -5
  4. package/dist/compiler.d.ts.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +804 -445
  8. package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
  9. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  10. package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
  11. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +2 -4
  12. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
  13. package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
  14. package/dist/ir-to-client-js/control-flow/stringify/loop-child-arm.d.ts.map +1 -1
  15. package/dist/ir-to-client-js/control-flow.d.ts.map +1 -1
  16. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  17. package/dist/ir-to-client-js/imports.d.ts +60 -2
  18. package/dist/ir-to-client-js/imports.d.ts.map +1 -1
  19. package/dist/ir-to-client-js/prop-handling.d.ts +4 -7
  20. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  21. package/dist/ir-to-client-js/utils.d.ts +26 -2
  22. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  23. package/dist/jsx-to-ir.d.ts.map +1 -1
  24. package/dist/props-binding.d.ts +35 -0
  25. package/dist/props-binding.d.ts.map +1 -1
  26. package/dist/types.d.ts +63 -13
  27. package/dist/types.d.ts.map +1 -1
  28. package/package.json +2 -2
  29. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +145 -97
  30. package/src/__tests__/child-component-ref-not-mirrored.test.ts +90 -0
  31. package/src/__tests__/fragment-body-loop-key.test.ts +95 -0
  32. package/src/__tests__/ir-to-client-js/imports.test.ts +107 -0
  33. package/src/__tests__/ir-to-client-js/merge-compiled-client-js-imports.test.ts +138 -0
  34. package/src/__tests__/issue-2754-rest-spread-needs-slot.test.ts +85 -0
  35. package/src/__tests__/issue-2756-loop-row-honors-client-only.test.ts +173 -0
  36. package/src/__tests__/merge-template-imports.test.ts +41 -1
  37. package/src/__tests__/multi-component-shared-default-import.test.ts +55 -0
  38. package/src/__tests__/multi-root-loop-body.test.ts +7 -3
  39. package/src/__tests__/preamble-declarations.test.ts +42 -0
  40. package/src/__tests__/root-key-relay.test.ts +170 -0
  41. package/src/__tests__/signal-getter-not-called.test.ts +149 -0
  42. package/src/__tests__/state-only-file-default-import.test.ts +47 -0
  43. package/src/analyzer.ts +36 -0
  44. package/src/compiler.ts +94 -104
  45. package/src/index.ts +1 -1
  46. package/src/ir-to-client-js/build-references.ts +7 -0
  47. package/src/ir-to-client-js/collect-elements.ts +27 -5
  48. package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +19 -1
  49. package/src/ir-to-client-js/control-flow/plan/loop.ts +2 -4
  50. package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +7 -0
  51. package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +6 -2
  52. package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +5 -2
  53. package/src/ir-to-client-js/control-flow.ts +12 -0
  54. package/src/ir-to-client-js/html-template.ts +174 -23
  55. package/src/ir-to-client-js/imports.ts +178 -5
  56. package/src/ir-to-client-js/index.ts +5 -0
  57. package/src/ir-to-client-js/prop-handling.ts +6 -17
  58. package/src/ir-to-client-js/utils.ts +30 -2
  59. package/src/jsx-to-ir.ts +592 -58
  60. package/src/props-binding.ts +51 -0
  61. package/src/types.ts +60 -13
package/dist/index.js CHANGED
@@ -177,7 +177,7 @@ function findTopLevelTemplateLiterals(code) {
177
177
  }
178
178
 
179
179
  // src/compiler.ts
180
- import ts24 from "typescript";
180
+ import ts25 from "typescript";
181
181
 
182
182
  // src/analyzer.ts
183
183
  import ts9 from "typescript";
@@ -2384,11 +2384,16 @@ import {
2384
2384
  loopStartMarker,
2385
2385
  loopEndMarker,
2386
2386
  loopItemMarker,
2387
- toHTMLAttrName as toHtmlAttrName
2387
+ toHTMLAttrName as toHtmlAttrName,
2388
+ keyAttrName as sharedKeyAttrName
2388
2389
  } from "@barefootjs/shared";
2389
2390
  var PROPS_PARAM = "_p";
2390
- function keyAttrName(loopDepth) {
2391
- return loopDepth > 0 ? `${DATA_KEY_PREFIX}${loopDepth}` : DATA_KEY;
2391
+ var keyAttrName = sharedKeyAttrName;
2392
+ function mapArrayKeyArgs(bfIdArg, keyed, loopDepth) {
2393
+ if (!keyed || loopDepth <= 0)
2394
+ return bfIdArg;
2395
+ const bfIdSlot = bfIdArg || ", undefined";
2396
+ return `${bfIdSlot}, ${JSON.stringify(keyAttrName(loopDepth))}`;
2392
2397
  }
2393
2398
  function varSlotId(slotId) {
2394
2399
  return slotId.startsWith("^") ? slotId.slice(1) : slotId;
@@ -3378,6 +3383,14 @@ function escapeAttrValueExpr(valExpr) {
3378
3383
  function escapeTextSlotExpr(innerExpr, isMarkup = false) {
3379
3384
  return `${isMarkup ? "escapeTextOrMarkup" : "escapeText"}(${innerExpr})`;
3380
3385
  }
3386
+ function isChildrenPassthroughExpr(expr) {
3387
+ return /^([A-Za-z_$][\w$]*\.)?children$/.test(expr.trim());
3388
+ }
3389
+ function bareSpliceExpr(node, valueExpr) {
3390
+ const resolved = valueExpr.trim().replace(/^\(+|\)+$/g, "");
3391
+ const isChildren = isChildrenPassthroughExpr(node.expr) || isChildrenPassthroughExpr(resolved);
3392
+ return !node.joinArrayChild && isChildren ? `markupOrEmpty(${valueExpr})` : valueExpr;
3393
+ }
3381
3394
  function dangerouslyHtmlChildren(attrs, toExpr) {
3382
3395
  const attr = attrs.find((a) => a.name === "dangerouslySetInnerHTML");
3383
3396
  if (!attr || attr.value.kind !== "expression")
@@ -3425,6 +3438,9 @@ function renderTemplateAttrPart(attr, attrName, wrap, restSpreadNames) {
3425
3438
  return "";
3426
3439
  }
3427
3440
  }
3441
+ function resolvedKeyAttrName(node, loopDepth) {
3442
+ return node.keyAttr ? keyAttrName(loopDepth) : null;
3443
+ }
3428
3444
  function isMergeableAttr(a, ctx) {
3429
3445
  if (ctx.honorClientOnly && a.clientOnly)
3430
3446
  return false;
@@ -3585,7 +3601,7 @@ function irToHtmlTemplate(node, restSpreadNames, loopDepth = 0, loopParams, bran
3585
3601
  case "element": {
3586
3602
  const mergeCtx = {
3587
3603
  isFilteredSpread: (v) => !!restSpreadNames?.has(v.expr),
3588
- honorClientOnly: false
3604
+ honorClientOnly: true
3589
3605
  };
3590
3606
  const useMerge = shouldUseSpreadAttrsMerge(node.attrs, mergeCtx);
3591
3607
  const firstMergeableIdx = useMerge ? node.attrs.findIndex((a) => isMergeableAttr(a, mergeCtx)) : -1;
@@ -3596,11 +3612,16 @@ function irToHtmlTemplate(node, restSpreadNames, loopDepth = 0, loopParams, bran
3596
3612
  templateExprFor: (v) => wrapExpr(attrValueToString(v) ?? "")
3597
3613
  }) : null;
3598
3614
  const attrParts = node.attrs.map((a, idx) => {
3615
+ if (a.clientOnly)
3616
+ return "";
3599
3617
  if (useMerge && isMergeableAttr(a, mergeCtx)) {
3600
3618
  return idx === firstMergeableIdx ? mergeCall : "";
3601
3619
  }
3602
- const attrName = a.name === "..." ? "..." : a.name === "key" ? keyAttrName(loopDepth) : toHtmlAttrName(a.name);
3603
- return renderTemplateAttrPart(a, attrName, wrapExpr, restSpreadNames);
3620
+ if (a.name === "key") {
3621
+ const attrName = resolvedKeyAttrName(node, loopDepth);
3622
+ return attrName ? renderTemplateAttrPart(a, attrName, wrapExpr, restSpreadNames) : "";
3623
+ }
3624
+ return renderTemplateAttrPart(a, toHtmlAttrName(a.name), wrapExpr, restSpreadNames);
3604
3625
  }).filter(Boolean);
3605
3626
  const hoistedScopeAttr = maybeHoistedScopeAttr(inHoistedChildren, node);
3606
3627
  if (hoistedScopeAttr)
@@ -3621,17 +3642,18 @@ function irToHtmlTemplate(node, restSpreadNames, loopDepth = 0, loopParams, bran
3621
3642
  case "expression": {
3622
3643
  if (node.expr === "null" || node.expr === "undefined")
3623
3644
  return "";
3645
+ const escapeForClient = (e) => node.escapeInClientTemplate ? `escapeText(${e})` : e;
3624
3646
  if (node.markerless) {
3625
- const bare = wrapInterpolation(wrapExpr(node.expr));
3647
+ const bare = escapeForClient(wrapInterpolation(wrapExpr(node.expr)));
3626
3648
  return `\${${bare}}`;
3627
3649
  }
3628
- const inner = wrapInterpolation(wrapExpr(node.expr));
3650
+ const inner = escapeForClient(wrapInterpolation(wrapExpr(node.expr)));
3629
3651
  const valueExpr = node.joinArrayChild ? `Array.isArray(${inner}) ? ${inner}.join('') : (${inner} ?? '')` : inner;
3630
3652
  if (node.slotId) {
3631
3653
  const slotted = branchSlotsVar || node.joinArrayChild ? valueExpr : escapeTextSlotExpr(valueExpr);
3632
3654
  return `<!--bf:${node.slotId}-->\${${slotted}}<!--/-->`;
3633
3655
  }
3634
- return `\${${valueExpr}}`;
3656
+ return `\${${bareSpliceExpr(node, valueExpr)}}`;
3635
3657
  }
3636
3658
  case "conditional": {
3637
3659
  const trueBranch = recurse(node.whenTrue);
@@ -3724,7 +3746,9 @@ function buildLoopSkeletonTemplate(node, safe) {
3724
3746
  if (a.name === "dangerouslySetInnerHTML")
3725
3747
  return null;
3726
3748
  if (a.name === "key") {
3727
- attrParts.push(`${keyAttrName(0)}=""`);
3749
+ if (resolvedKeyAttrName(node, 0)) {
3750
+ attrParts.push(`${keyAttrName(0)}=""`);
3751
+ }
3728
3752
  continue;
3729
3753
  }
3730
3754
  const v = a.value;
@@ -3930,7 +3954,13 @@ function irToPlaceholderTemplate(node, restSpreadNames, loopDepth = 0, loopParam
3930
3954
  switch (node.type) {
3931
3955
  case "element": {
3932
3956
  const attrParts = node.attrs.map((a) => {
3933
- const attrName = a.name === "..." ? "..." : a.name === "key" ? keyAttrName(loopDepth) : toHtmlAttrName(a.name);
3957
+ if (a.clientOnly)
3958
+ return "";
3959
+ if (a.name === "key") {
3960
+ const attrName2 = resolvedKeyAttrName(node, loopDepth);
3961
+ return attrName2 ? renderTemplateAttrPart(a, attrName2, wrapExpr, restSpreadNames) : "";
3962
+ }
3963
+ const attrName = a.name === "..." ? "..." : toHtmlAttrName(a.name);
3934
3964
  return renderTemplateAttrPart(a, attrName, wrapExpr, restSpreadNames);
3935
3965
  }).filter(Boolean);
3936
3966
  if (node.slotId) {
@@ -3953,7 +3983,8 @@ function irToPlaceholderTemplate(node, restSpreadNames, loopDepth = 0, loopParam
3953
3983
  if (node.slotId) {
3954
3984
  return `<!--bf:${node.slotId}-->\${${node.joinArrayChild ? value : escapeTextSlotExpr(wrapped)}}<!--/-->`;
3955
3985
  }
3956
- return `\${${value}}`;
3986
+ const spliced = bareSpliceExpr(node, value);
3987
+ return `\${${node.escapeInClientTemplate ? `escapeText(${spliced})` : spliced}}`;
3957
3988
  }
3958
3989
  case "conditional": {
3959
3990
  const trueBranch = recurse(node.whenTrue);
@@ -4195,7 +4226,7 @@ function irToComponentTemplateWithOpts(node, opts) {
4195
4226
  const isMarkup = opts.markupSlotIds?.has(node.slotId) ?? false;
4196
4227
  return `<!--bf:${node.slotId}-->\${${node.joinArrayChild ? value : escapeTextSlotExpr(wrapped, isMarkup)}}<!--/-->`;
4197
4228
  }
4198
- return `\${${value}}`;
4229
+ return `\${${bareSpliceExpr(node, value)}}`;
4199
4230
  }
4200
4231
  case "conditional": {
4201
4232
  if (node.clientOnly && node.slotId) {
@@ -4478,7 +4509,27 @@ function generateCsrTemplateWithOpts(node, opts) {
4478
4509
  return "";
4479
4510
  return `\${spreadAttrs(${transformExpr(v.expr, v.templateExpr)})}`;
4480
4511
  }
4481
- const attrName = a.name === "key" ? keyAttrName(loopDepth) : toHtmlAttrName(a.name);
4512
+ if (a.name === "key") {
4513
+ const keyName = resolvedKeyAttrName(node, loopDepth);
4514
+ if (!keyName)
4515
+ return "";
4516
+ switch (v.kind) {
4517
+ case "boolean-attr":
4518
+ return keyName;
4519
+ case "literal":
4520
+ return `${keyName}="${escapeHtml(v.value)}"`;
4521
+ case "expression":
4522
+ return templateAttrExpr(keyName, transformExpr(v.expr, v.templateExpr), v.presenceOrUndefined);
4523
+ case "template": {
4524
+ const valueStr = attrValueToString(v, { useTemplate: true });
4525
+ return valueStr ? templateAttrExpr(keyName, transformExpr(valueStr)) : "";
4526
+ }
4527
+ case "boolean-shorthand":
4528
+ case "jsx-children":
4529
+ return "";
4530
+ }
4531
+ }
4532
+ const attrName = toHtmlAttrName(a.name);
4482
4533
  switch (v.kind) {
4483
4534
  case "boolean-attr":
4484
4535
  return attrName;
@@ -4526,7 +4577,7 @@ function generateCsrTemplateWithOpts(node, opts) {
4526
4577
  const isMarkup = opts.markupSlotIds?.has(node.slotId) ?? false;
4527
4578
  return `<!--bf:${node.slotId}-->\${${node.joinArrayChild ? value : escapeTextSlotExpr(expr, isMarkup)}}<!--/-->`;
4528
4579
  }
4529
- return `\${${value}}`;
4580
+ return `\${${bareSpliceExpr(node, value)}}`;
4530
4581
  }
4531
4582
  case "conditional": {
4532
4583
  if (node.clientOnly && node.slotId) {
@@ -4834,6 +4885,19 @@ function buildPropAliasMap(params) {
4834
4885
  }
4835
4886
  return map;
4836
4887
  }
4888
+ function resolveRestSpreadOriginCore(bindings, constantValues, name) {
4889
+ const visited = new Set;
4890
+ let current = name.trim();
4891
+ while (current !== undefined && !visited.has(current)) {
4892
+ if (bindings.restPropsName && current === bindings.restPropsName)
4893
+ return "rest";
4894
+ if (bindings.propsObjectName && current === bindings.propsObjectName)
4895
+ return "props";
4896
+ visited.add(current);
4897
+ current = constantValues.get(current)?.trim();
4898
+ }
4899
+ return null;
4900
+ }
4837
4901
 
4838
4902
  // src/instrumentation.ts
4839
4903
  var _enabled = false;
@@ -8323,6 +8387,16 @@ function importsBrowserOnlyClientApi(ctx) {
8323
8387
  }
8324
8388
  function listComponentFunctions(source, filePath) {
8325
8389
  const sourceFile = ts9.createSourceFile(filePath, source, ts9.ScriptTarget.Latest, true, ts9.ScriptKind.TSX);
8390
+ return listComponentFunctionsFromSourceFile(sourceFile);
8391
+ }
8392
+ function scanComponentFile(source, filePath) {
8393
+ const sourceFile = ts9.createSourceFile(filePath, source, ts9.ScriptTarget.Latest, true, ts9.ScriptKind.TSX);
8394
+ return {
8395
+ exports: listComponentFunctionsFromSourceFile(sourceFile),
8396
+ referencedComponents: [...collectJsxComponentTags(sourceFile)]
8397
+ };
8398
+ }
8399
+ function listComponentFunctionsFromSourceFile(sourceFile) {
8326
8400
  const componentNames = [];
8327
8401
  const hasUseClient = sourceFile.statements.some((stmt) => ts9.isExpressionStatement(stmt) && ts9.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
8328
8402
  const namedExports = collectNamedExports(sourceFile);
@@ -10264,7 +10338,7 @@ var toLocaleDatePlugin = {
10264
10338
  };
10265
10339
 
10266
10340
  // src/jsx-to-ir.ts
10267
- import { toHTMLAttrName, decodeEntities } from "@barefootjs/shared";
10341
+ import { toHTMLAttrName, decodeEntities, BF_KEY, keyAttrName as keyAttrName2 } from "@barefootjs/shared";
10268
10342
  var CLIENT_DIRECTIVE_INTERIOR_RE2 = /^\s*@client\s*$/;
10269
10343
  var BLOCK_COMMENT_RE2 = /\/\*([\s\S]*?)\*\//g;
10270
10344
  function hasLeadingClientDirective(expr, sourceFile) {
@@ -10717,10 +10791,44 @@ function attachParsedExpressions(node, analyzer, bound = EMPTY_BOUND) {
10717
10791
  break;
10718
10792
  }
10719
10793
  }
10794
+ function resolveRootKeyAttr(node) {
10795
+ if (!node)
10796
+ return;
10797
+ switch (node.type) {
10798
+ case "element":
10799
+ if (node.needsScope && !node.keyAttr)
10800
+ node.keyAttr = { name: BF_KEY };
10801
+ for (const c of node.children)
10802
+ resolveRootKeyAttr(c);
10803
+ return;
10804
+ case "fragment":
10805
+ case "component":
10806
+ case "provider":
10807
+ case "loop":
10808
+ for (const c of node.children)
10809
+ resolveRootKeyAttr(c);
10810
+ return;
10811
+ case "async":
10812
+ resolveRootKeyAttr(node.fallback);
10813
+ for (const c of node.children)
10814
+ resolveRootKeyAttr(c);
10815
+ return;
10816
+ case "conditional":
10817
+ resolveRootKeyAttr(node.whenTrue);
10818
+ resolveRootKeyAttr(node.whenFalse);
10819
+ return;
10820
+ case "if-statement":
10821
+ resolveRootKeyAttr(node.consequent);
10822
+ resolveRootKeyAttr(node.alternate);
10823
+ return;
10824
+ }
10825
+ }
10720
10826
  function jsxToIR(analyzer) {
10721
10827
  const root = buildIRRoot(analyzer);
10722
- if (root)
10828
+ if (root) {
10723
10829
  attachParsedExpressions(root, analyzer);
10830
+ resolveRootKeyAttr(root);
10831
+ }
10724
10832
  return root;
10725
10833
  }
10726
10834
  function buildIRRoot(analyzer) {
@@ -10909,6 +11017,7 @@ function lowerFormControlValueSsr(tagName, attrs, children) {
10909
11017
  type: "expression",
10910
11018
  expr,
10911
11019
  templateExpr: `escapeText(${templateExpr ?? expr})`,
11020
+ escapeInClientTemplate: true,
10912
11021
  typeInfo: null,
10913
11022
  reactive: false,
10914
11023
  slotId: null,
@@ -10946,7 +11055,7 @@ function transformHtmlElement(node, ctx, tagName) {
10946
11055
  ctx.isRoot = false;
10947
11056
  const children = transformChildren(node.children, ctx);
10948
11057
  lowerFormControlValueSsr(tagName, attrs, children);
10949
- const needsSlot = events.length > 0 || hasDynamicContent(children) || hasReactiveAttributes(attrs, ctx) || ref !== null;
11058
+ const needsSlot = events.length > 0 || hasDynamicContent(children) || hasReactiveAttributes(attrs, ctx) || ref !== null || forwardsCallerRestProps(attrs, ctx);
10950
11059
  const slotId = needsSlot ? generateSlotId(ctx) : null;
10951
11060
  if (slotId) {
10952
11061
  propagateSlotIdToLoops(children, slotId);
@@ -10979,7 +11088,7 @@ function transformSelfClosingElement(node, ctx) {
10979
11088
  const { attrs, events, ref } = processAttributes(node.attributes, ctx);
10980
11089
  const selfClosingChildren = [];
10981
11090
  lowerFormControlValueSsr(tagName, attrs, selfClosingChildren);
10982
- const needsSlot = events.length > 0 || hasReactiveAttributes(attrs, ctx) || ref !== null;
11091
+ const needsSlot = events.length > 0 || hasReactiveAttributes(attrs, ctx) || ref !== null || forwardsCallerRestProps(attrs, ctx);
10983
11092
  const slotId = needsSlot ? generateSlotId(ctx) : null;
10984
11093
  const needsScope = ctx.isRoot;
10985
11094
  ctx.isRoot = false;
@@ -11218,7 +11327,9 @@ function markDataKeyCarrier(children) {
11218
11327
  }
11219
11328
  function markCarrierIn(node) {
11220
11329
  if (node.type === "element") {
11221
- return { ...node, carriesDataKey: true };
11330
+ if (node.keyAttr)
11331
+ return null;
11332
+ return { ...node, keyAttr: { name: BF_KEY } };
11222
11333
  }
11223
11334
  if (node.type === "conditional") {
11224
11335
  const cond = node;
@@ -11293,7 +11404,7 @@ function transformExpressionInner(expr, ctx, node, isClientOnly) {
11293
11404
  if (isRenderNothingLiteral(expr, ctx)) {
11294
11405
  return null;
11295
11406
  }
11296
- checkBareSignalOrMemoIdentifier(expr, ctx);
11407
+ checkBareSignalOrMemoIdentifier(expr, ctx, { descendNested: true });
11297
11408
  if (ts13.isIdentifier(expr)) {
11298
11409
  const jsxNode = ctx.analyzer.jsxConstants.get(expr.text);
11299
11410
  if (jsxNode) {
@@ -12172,6 +12283,10 @@ function extractLoopKey(node) {
12172
12283
  return null;
12173
12284
  return normalizeKeyExpr(a) === normalizeKeyExpr(b) ? a : null;
12174
12285
  }
12286
+ if (node.type === "fragment") {
12287
+ const first = node.children.find((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
12288
+ return first ? extractLoopKey(first) : null;
12289
+ }
12175
12290
  return null;
12176
12291
  }
12177
12292
  function keyAttrValueToExpr(v) {
@@ -12362,7 +12477,7 @@ function leafIsWirelessElement(el) {
12362
12477
  }
12363
12478
  if (ts13.isJsxAttribute(attr)) {
12364
12479
  const name = attr.name.getText();
12365
- if (/^on[A-Z]/.test(name)) {
12480
+ if (isEventHandlerAttrName(name)) {
12366
12481
  ok = false;
12367
12482
  return;
12368
12483
  }
@@ -12410,6 +12525,22 @@ function tagLoopItemRootComponents(nodes) {
12410
12525
  }
12411
12526
  }
12412
12527
  }
12528
+ function applyLoopKeyAttr(node, name, value) {
12529
+ if (node.type === "element") {
12530
+ node.keyAttr = { name, value };
12531
+ return;
12532
+ }
12533
+ if (node.type === "conditional") {
12534
+ applyLoopKeyAttr(node.whenTrue, name, value);
12535
+ applyLoopKeyAttr(node.whenFalse, name, value);
12536
+ return;
12537
+ }
12538
+ if (node.type === "fragment") {
12539
+ const first = node.children.find((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
12540
+ if (first)
12541
+ applyLoopKeyAttr(first, name, value);
12542
+ }
12543
+ }
12413
12544
  function loopBodyItemConditional(children) {
12414
12545
  const real = children.filter((c) => !(c.type === "text" && typeof c.value === "string" && !c.value.trim()));
12415
12546
  if (real.length !== 1)
@@ -12640,7 +12771,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
12640
12771
  children = [foldMultiReturnBranches(multiReturn, ctx, loc, ctx.getJS)];
12641
12772
  const pre = multiReturn.preamble ?? [];
12642
12773
  if (pre.length > 0) {
12643
- preamble = preambleFromValueStatements(pre, ctx);
12774
+ preamble = preambleFromValueStatements(pre, ctx, body.statements);
12644
12775
  if (!preamble.declarations && !isClientOnly && !(ctx.analyzer.acceptsCallbackBody?.("map") ?? false)) {
12645
12776
  ctx.analyzer.errors.push(createError(ErrorCodes.UNSUPPORTED_JSX_PATTERN, loc, {
12646
12777
  message: "A .map() callback body with a preamble before its branches cannot be " + "lowered to a template: the preamble is not a sequence of value " + "declarations, so this backend has no per-row local to carry into the " + "branches.",
@@ -12727,7 +12858,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
12727
12858
  valueStmts.push(stmt);
12728
12859
  }
12729
12860
  if (valueStmts.length > 0) {
12730
- preamble = preambleFromValueStatements(valueStmts, ctx);
12861
+ preamble = preambleFromValueStatements(valueStmts, ctx, body.statements);
12731
12862
  if (!preamble.declarations && !isClientOnly && !(ctx.analyzer.acceptsCallbackBody?.("map") ?? false)) {
12732
12863
  ctx.analyzer.errors.push(createError(ErrorCodes.UNSUPPORTED_JSX_PATTERN, getSourceLocation(body, ctx.sourceFile, ctx.filePath), {
12733
12864
  message: "A .map() callback preamble that is not a sequence of value " + "declarations cannot be lowered to a template: this backend can " + "declare a per-row local, but cannot run arbitrary statements per row.",
@@ -12792,6 +12923,14 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
12792
12923
  const itemConditional = children.length > 0 ? loopBodyItemConditional(children) : null;
12793
12924
  const bodyIsItemConditional = itemConditional !== null;
12794
12925
  const key = bodyIsItemConditional ? extractItemConditionalKey(itemConditional) : children.length > 0 ? extractLoopKey(children[0]) : null;
12926
+ if (key !== null) {
12927
+ const resolvedKeyAttrName2 = keyAttrName2(depth);
12928
+ if (bodyIsItemConditional) {
12929
+ applyLoopKeyAttr(itemConditional, resolvedKeyAttrName2, key);
12930
+ } else if (children.length > 0) {
12931
+ applyLoopKeyAttr(children[0], resolvedKeyAttrName2, key);
12932
+ }
12933
+ }
12795
12934
  const declaredNameSet = preamble && preamble.declaredNames.length > 0 ? new Set(preamble.declaredNames) : undefined;
12796
12935
  if (key && declaredNameSet) {
12797
12936
  const keyRefs = extractFreeIdentifiersFromText(key);
@@ -13182,7 +13321,7 @@ function computePreambleReactiveNames(statements, ctx) {
13182
13321
  }
13183
13322
  return reactiveNames;
13184
13323
  }
13185
- function preambleFromValueStatements(statements, ctx) {
13324
+ function preambleFromValueStatements(statements, ctx, bodyStatements) {
13186
13325
  const segments = [];
13187
13326
  const typedParts = [];
13188
13327
  const declared = new Set;
@@ -13202,11 +13341,11 @@ function preambleFromValueStatements(statements, ctx) {
13202
13341
  ssrText: tsxSourceText(typedParts.join(" ")),
13203
13342
  declaredNames: [...declared],
13204
13343
  builderNames: [],
13205
- declarations: neutralPreambleDeclarations(statements, ctx) ?? undefined,
13344
+ declarations: neutralPreambleDeclarations(statements, ctx, bodyStatements) ?? undefined,
13206
13345
  reactiveNames: reactiveNames.size > 0 ? [...reactiveNames] : undefined
13207
13346
  };
13208
13347
  }
13209
- function neutralPreambleDeclarations(statements, ctx) {
13348
+ function neutralPreambleDeclarations(statements, ctx, bodyStatements) {
13210
13349
  const out = [];
13211
13350
  for (const stmt of statements) {
13212
13351
  if (!ts13.isVariableStatement(stmt))
@@ -13216,6 +13355,11 @@ function neutralPreambleDeclarations(statements, ctx) {
13216
13355
  return null;
13217
13356
  if (!decl.initializer)
13218
13357
  return null;
13358
+ if (isFunctionLiteral(decl.initializer)) {
13359
+ if (everyReadIsEventHandlerPropValue(decl.name.text, bodyStatements))
13360
+ continue;
13361
+ return null;
13362
+ }
13219
13363
  const valueParsed = tsNodeToParsedExpr(decl.initializer);
13220
13364
  if (!isSupported(valueParsed).supported)
13221
13365
  return null;
@@ -13226,7 +13370,30 @@ function neutralPreambleDeclarations(statements, ctx) {
13226
13370
  });
13227
13371
  }
13228
13372
  }
13229
- return out.length > 0 ? out : null;
13373
+ return out;
13374
+ }
13375
+ function isFunctionLiteral(node) {
13376
+ return ts13.isArrowFunction(node) || ts13.isFunctionExpression(node);
13377
+ }
13378
+ function everyReadIsEventHandlerPropValue(name, bodyStatements) {
13379
+ const findDisallowedRead = (node) => {
13380
+ if (ts13.isIdentifier(node) && node.text === name) {
13381
+ const isBindingName = ts13.isVariableDeclaration(node.parent) && node.parent.name === node;
13382
+ const isPropertyName = ts13.isPropertyAccessExpression(node.parent) && node.parent.name === node;
13383
+ if (!isBindingName && !isPropertyName) {
13384
+ const jsxExpr = node.parent;
13385
+ const attr = jsxExpr.parent;
13386
+ const isEventHandlerAttrValue = ts13.isJsxExpression(jsxExpr) && ts13.isJsxAttribute(attr) && attr.initializer === jsxExpr && ts13.isIdentifier(attr.name) && isEventHandlerAttrName(attr.name.text);
13387
+ if (!isEventHandlerAttrValue)
13388
+ return true;
13389
+ }
13390
+ }
13391
+ return ts13.forEachChild(node, findDisallowedRead);
13392
+ };
13393
+ return !bodyStatements.some(findDisallowedRead);
13394
+ }
13395
+ function isEventHandlerAttrName(name) {
13396
+ return /^on[A-Z]/.test(name);
13230
13397
  }
13231
13398
  function trimPreambleSegments(segments) {
13232
13399
  const last = segments[segments.length - 1];
@@ -13423,7 +13590,7 @@ function processAttributes(attributes, ctx) {
13423
13590
  }
13424
13591
  continue;
13425
13592
  }
13426
- if (/^on[A-Z]/.test(rawName)) {
13593
+ if (isEventHandlerAttrName(rawName)) {
13427
13594
  if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
13428
13595
  const eventName = rawName.slice(2).toLowerCase();
13429
13596
  reportJsxBranchLocalInCallback(attr.initializer.expression, ctx);
@@ -13482,7 +13649,7 @@ function getAttributeValue(attr, ctx) {
13482
13649
  ctx.analyzer.errors.push(createError(ErrorCodes.STAGE_AWAIT_IN_TEMPLATE, getSourceLocation(expr, ctx.sourceFile, ctx.filePath)));
13483
13650
  return AttrValueOf.expression("undefined");
13484
13651
  }
13485
- checkBareSignalOrMemoIdentifier(expr, ctx);
13652
+ checkBareSignalOrMemoIdentifier(expr, ctx, { descendNested: isRenderedElementAttribute(attr, ctx) });
13486
13653
  if (attr.name.getText(ctx.sourceFile) === "style" && ts13.isObjectLiteralExpression(expr)) {
13487
13654
  const cssString = tryStaticStyleObjectToCss(expr);
13488
13655
  if (cssString !== null) {
@@ -13990,34 +14157,142 @@ function processComponentProps(attributes, ctx) {
13990
14157
  }
13991
14158
  return props;
13992
14159
  }
13993
- function checkBareSignalOrMemoIdentifier(expr, ctx) {
13994
- if (!ts13.isIdentifier(expr))
14160
+ function isRenderedElementAttribute(attr, ctx) {
14161
+ const tagName = attr.parent.parent.tagName.getText(ctx.sourceFile);
14162
+ return !/^[A-Z]/.test(tagName);
14163
+ }
14164
+ function checkBareSignalOrMemoIdentifier(expr, ctx, options) {
14165
+ const reactiveNames = new Map;
14166
+ for (const signal of ctx.analyzer.signals)
14167
+ reactiveNames.set(signal.getter, "signal");
14168
+ for (const memo of ctx.analyzer.memos)
14169
+ reactiveNames.set(memo.name, "memo");
14170
+ if (reactiveNames.size === 0)
13995
14171
  return;
13996
- const name = expr.text;
13997
- for (const signal of ctx.analyzer.signals) {
13998
- if (signal.getter === name) {
13999
- ctx.analyzer.errors.push(createError(ErrorCodes.SIGNAL_GETTER_NOT_CALLED, getSourceLocation(expr, ctx.sourceFile, ctx.filePath), {
14000
- message: `Signal getter '${name}' passed without calling it`,
14001
- suggestion: {
14002
- message: `Signal getters must be called to read the value. Use \`${name}()\` instead of \`${name}\`.`,
14003
- replacement: `${name}()`
14004
- }
14005
- }));
14172
+ const report = (id, name, kind) => {
14173
+ const label = kind === "signal" ? "Signal" : "Memo";
14174
+ ctx.analyzer.errors.push(createError(ErrorCodes.SIGNAL_GETTER_NOT_CALLED, getSourceLocation(id, ctx.sourceFile, ctx.filePath), {
14175
+ message: `${label} getter '${name}' passed without calling it`,
14176
+ suggestion: {
14177
+ message: `${label} getters must be called to read the value. Use \`${name}()\` instead of \`${name}\`.`,
14178
+ replacement: `${name}()`
14179
+ }
14180
+ }));
14181
+ };
14182
+ if (ts13.isIdentifier(expr)) {
14183
+ const kind = reactiveNames.get(expr.text);
14184
+ if (kind && !ctx.scope.isBound(expr.text))
14185
+ report(expr, expr.text, kind);
14186
+ return;
14187
+ }
14188
+ if (!options?.descendNested)
14189
+ return;
14190
+ const boundStack = [];
14191
+ const isBound = (name) => {
14192
+ for (let i = boundStack.length - 1;i >= 0; i--) {
14193
+ if (boundStack[i].has(name))
14194
+ return true;
14195
+ }
14196
+ return ctx.scope.isBound(name);
14197
+ };
14198
+ const visitBindingDefaults = (name, bound) => {
14199
+ if (ts13.isIdentifier(name)) {
14200
+ bound.add(name.text);
14006
14201
  return;
14007
14202
  }
14008
- }
14009
- for (const memo of ctx.analyzer.memos) {
14010
- if (memo.name === name) {
14011
- ctx.analyzer.errors.push(createError(ErrorCodes.SIGNAL_GETTER_NOT_CALLED, getSourceLocation(expr, ctx.sourceFile, ctx.filePath), {
14012
- message: `Memo getter '${name}' passed without calling it`,
14013
- suggestion: {
14014
- message: `Memo getters must be called to read the value. Use \`${name}()\` instead of \`${name}\`.`,
14015
- replacement: `${name}()`
14016
- }
14017
- }));
14203
+ for (const el of name.elements) {
14204
+ if (ts13.isOmittedExpression(el))
14205
+ continue;
14206
+ if (el.initializer)
14207
+ visit2(el.initializer);
14208
+ visitBindingDefaults(el.name, bound);
14209
+ }
14210
+ };
14211
+ const collectBindingNames3 = (name, out) => {
14212
+ if (ts13.isIdentifier(name))
14213
+ out.add(name.text);
14214
+ else if (ts13.isObjectBindingPattern(name)) {
14215
+ for (const el of name.elements)
14216
+ collectBindingNames3(el.name, out);
14217
+ } else if (ts13.isArrayBindingPattern(name)) {
14218
+ for (const el of name.elements) {
14219
+ if (!ts13.isOmittedExpression(el))
14220
+ collectBindingNames3(el.name, out);
14221
+ }
14222
+ }
14223
+ };
14224
+ const collectBlockDeclarations = (block, out) => {
14225
+ for (const stmt of block.statements) {
14226
+ if (ts13.isVariableStatement(stmt)) {
14227
+ for (const decl of stmt.declarationList.declarations)
14228
+ collectBindingNames3(decl.name, out);
14229
+ } else if (ts13.isFunctionDeclaration(stmt) && stmt.name) {
14230
+ out.add(stmt.name.text);
14231
+ }
14232
+ }
14233
+ };
14234
+ function visit2(node) {
14235
+ if (ts13.isJsxElement(node) || ts13.isJsxSelfClosingElement(node) || ts13.isJsxFragment(node)) {
14236
+ return;
14237
+ }
14238
+ if (ts13.isTypeNode(node))
14239
+ return;
14240
+ if (ts13.isCallExpression(node) && node.arguments.length === 0 && ts13.isIdentifier(node.expression)) {
14241
+ return;
14242
+ }
14243
+ if (ts13.isPropertyAccessExpression(node)) {
14244
+ visit2(node.expression);
14245
+ return;
14246
+ }
14247
+ if (ts13.isPropertyAssignment(node)) {
14248
+ if (ts13.isComputedPropertyName(node.name))
14249
+ visit2(node.name.expression);
14250
+ visit2(node.initializer);
14251
+ return;
14252
+ }
14253
+ if (ts13.isShorthandPropertyAssignment(node)) {
14254
+ if (ts13.isIdentifier(node.name) && !isBound(node.name.text)) {
14255
+ const kind = reactiveNames.get(node.name.text);
14256
+ if (kind)
14257
+ report(node.name, node.name.text, kind);
14258
+ }
14259
+ return;
14260
+ }
14261
+ if (ts13.isArrowFunction(node) || ts13.isFunctionExpression(node)) {
14262
+ const bound = new Set;
14263
+ boundStack.push(bound);
14264
+ for (const p of node.parameters) {
14265
+ if (p.initializer)
14266
+ visit2(p.initializer);
14267
+ visitBindingDefaults(p.name, bound);
14268
+ }
14269
+ if (node.body && ts13.isBlock(node.body))
14270
+ collectBlockDeclarations(node.body, bound);
14271
+ if (node.body)
14272
+ visit2(node.body);
14273
+ boundStack.pop();
14274
+ return;
14275
+ }
14276
+ if (ts13.isVariableDeclaration(node)) {
14277
+ if (node.initializer)
14278
+ visit2(node.initializer);
14279
+ const declared = new Set;
14280
+ boundStack.push(declared);
14281
+ visitBindingDefaults(node.name, declared);
14282
+ boundStack.pop();
14283
+ return;
14284
+ }
14285
+ if (ts13.isIdentifier(node)) {
14286
+ if (isBound(node.text))
14287
+ return;
14288
+ const kind = reactiveNames.get(node.text);
14289
+ if (kind)
14290
+ report(node, node.text, kind);
14018
14291
  return;
14019
14292
  }
14293
+ ts13.forEachChild(node, visit2);
14020
14294
  }
14295
+ visit2(expr);
14021
14296
  }
14022
14297
  function isArrayExprDirectPropRef(arrayExpr, ctx) {
14023
14298
  const propNames = new Set(ctx.patterns.props.map((p) => p.name));
@@ -14116,6 +14391,31 @@ function isPropsReference(expr, ctx, visited) {
14116
14391
  }
14117
14392
  return false;
14118
14393
  }
14394
+ function forwardsCallerRestProps(attrs, ctx) {
14395
+ for (const attr of attrs) {
14396
+ if (attr.value.kind !== "spread")
14397
+ continue;
14398
+ const constants = restSpreadConstantValues(ctx);
14399
+ for (const name of new Set([attr.value.expr, attr.value.templateExpr])) {
14400
+ if (!name)
14401
+ continue;
14402
+ if (resolveRestSpreadOriginCore(ctx.analyzer, constants, name) !== null)
14403
+ return true;
14404
+ }
14405
+ }
14406
+ return false;
14407
+ }
14408
+ function restSpreadConstantValues(ctx) {
14409
+ if (ctx._restSpreadConstantValues)
14410
+ return ctx._restSpreadConstantValues;
14411
+ const byName = new Map;
14412
+ for (const constant of ctx.analyzer.localConstants) {
14413
+ if (!byName.has(constant.name))
14414
+ byName.set(constant.name, constant.value);
14415
+ }
14416
+ ctx._restSpreadConstantValues = byName;
14417
+ return byName;
14418
+ }
14119
14419
  function hasReactiveAttributes(attrs, ctx) {
14120
14420
  for (const attr of attrs) {
14121
14421
  if (attr.name === "key")
@@ -14338,18 +14638,7 @@ function buildIfStatementChain(analyzer, ctx, opts) {
14338
14638
 
14339
14639
  // src/ir-to-client-js/prop-handling.ts
14340
14640
  function resolveRestSpreadOrigin(ctx, name) {
14341
- const byName = localConstantValues(ctx);
14342
- const visited = new Set;
14343
- let current = name.trim();
14344
- while (current !== undefined && !visited.has(current)) {
14345
- if (ctx.restPropsName && current === ctx.restPropsName)
14346
- return "rest";
14347
- if (ctx.propsObjectName && current === ctx.propsObjectName)
14348
- return "props";
14349
- visited.add(current);
14350
- current = byName.get(current)?.trim();
14351
- }
14352
- return null;
14641
+ return resolveRestSpreadOriginCore(ctx, localConstantValues(ctx), name);
14353
14642
  }
14354
14643
  var _localConstantValuesCache = new WeakMap;
14355
14644
  function localConstantValues(ctx) {
@@ -14959,6 +15248,7 @@ function emitMultiRootTemplateCloneLines(template, indent, varEl, varExtras) {
14959
15248
  }
14960
15249
 
14961
15250
  // src/ir-to-client-js/collect-elements.ts
15251
+ import { classifyDOMProp } from "@barefootjs/shared";
14962
15252
  var EMPTY_RENDER_EXPRS = new Set(["null", "undefined", "false", "''", '""', "``"]);
14963
15253
  function domElementCount(node) {
14964
15254
  switch (node.type) {
@@ -15245,8 +15535,8 @@ function collectReactiveChildProps(node, ctx) {
15245
15535
  continue;
15246
15536
  if (prop.value.kind === "jsx-children")
15247
15537
  continue;
15248
- const isEventHandler = prop.name.startsWith("on") && prop.name.length > 2 && prop.name[2] === prop.name[2].toUpperCase();
15249
- if (isEventHandler)
15538
+ const domKind = classifyDOMProp(prop.name).kind;
15539
+ if (domKind === "ref" || domKind === "event" || domKind === "skip")
15250
15540
  continue;
15251
15541
  if (prop.value.kind !== "expression" && prop.value.kind !== "template")
15252
15542
  continue;
@@ -15956,6 +16246,8 @@ function buildReferencesGraph(ctx, irRoot) {
15956
16246
  }
15957
16247
  for (const ev of el.events)
15958
16248
  addExprEdges(ROOT_SOURCE, ev.handler, "init-body");
16249
+ if (el.ref)
16250
+ addExprEdges(ROOT_SOURCE, el.ref, "init-body");
15959
16251
  descend();
15960
16252
  },
15961
16253
  component: ({ node: c, descend, descendJsxChildren }) => {
@@ -16163,6 +16455,9 @@ function propHasPropertyAccess(u) {
16163
16455
  return u.accessKinds.has("property") || u.accessKinds.has("index");
16164
16456
  }
16165
16457
 
16458
+ // src/ir-to-client-js/imports.ts
16459
+ import ts16 from "typescript";
16460
+
16166
16461
  // src/value-references.ts
16167
16462
  import ts15 from "typescript";
16168
16463
  function isValueReferenceIdentifier(id) {
@@ -16269,6 +16564,7 @@ var RUNTIME_IMPORT_CANDIDATES = [
16269
16564
  "escapeTextOrNode",
16270
16565
  "bfMarkup",
16271
16566
  "escapeTextOrMarkup",
16567
+ "markupOrEmpty",
16272
16568
  "qsa",
16273
16569
  "qsaItem",
16274
16570
  "qsaChildScope",
@@ -16335,6 +16631,79 @@ function makeValueUsageTest(generatedCode) {
16335
16631
  return generatedCode.includes(localName);
16336
16632
  };
16337
16633
  }
16634
+ function renderUsedImportLines(source, usedDefault, usedNamespace, usedNamed) {
16635
+ const lines = [];
16636
+ const defaultAndNamed = [
16637
+ usedDefault,
16638
+ usedNamed.length > 0 ? `{ ${usedNamed.join(", ")} }` : null
16639
+ ].filter((part) => part !== null).join(", ");
16640
+ if (defaultAndNamed)
16641
+ lines.push(`import ${defaultAndNamed} from '${source}'`);
16642
+ if (usedNamespace)
16643
+ lines.push(`import * as ${usedNamespace} from '${source}'`);
16644
+ return lines;
16645
+ }
16646
+ function mergeCompiledClientJsImports(codeBlobs) {
16647
+ const sourceOrder = [];
16648
+ const namedBySource = new Map;
16649
+ const defaultBySource = new Map;
16650
+ const otherImports = [];
16651
+ const seenOther = new Set;
16652
+ const codeSections = [];
16653
+ const ensureSource = (source) => {
16654
+ if (!namedBySource.has(source)) {
16655
+ namedBySource.set(source, new Set);
16656
+ sourceOrder.push(source);
16657
+ }
16658
+ return namedBySource.get(source);
16659
+ };
16660
+ for (const content of codeBlobs) {
16661
+ const sourceFile = ts16.createSourceFile("combine.js", content, ts16.ScriptTarget.Latest, false, ts16.ScriptKind.JS);
16662
+ const importSpans = [];
16663
+ for (const stmt of sourceFile.statements) {
16664
+ if (!ts16.isImportDeclaration(stmt))
16665
+ continue;
16666
+ const start = stmt.getStart(sourceFile);
16667
+ const end = stmt.getEnd();
16668
+ importSpans.push([start, end]);
16669
+ const clause = stmt.importClause;
16670
+ const bindings = clause?.namedBindings;
16671
+ const specifier = ts16.isStringLiteral(stmt.moduleSpecifier) ? stmt.moduleSpecifier.text : "";
16672
+ const isNamespace = !!bindings && ts16.isNamespaceImport(bindings);
16673
+ const isNamed = !!bindings && ts16.isNamedImports(bindings);
16674
+ if (!isNamespace && (clause?.name || isNamed)) {
16675
+ const set = ensureSource(specifier);
16676
+ if (clause?.name && !defaultBySource.has(specifier)) {
16677
+ defaultBySource.set(specifier, clause.name.text);
16678
+ }
16679
+ if (isNamed) {
16680
+ for (const el of bindings.elements) {
16681
+ set.add(el.propertyName ? `${el.propertyName.text} as ${el.name.text}` : el.name.text);
16682
+ }
16683
+ }
16684
+ } else {
16685
+ const stmtText = content.slice(start, end);
16686
+ if (!seenOther.has(stmtText)) {
16687
+ seenOther.add(stmtText);
16688
+ otherImports.push(stmtText);
16689
+ }
16690
+ }
16691
+ }
16692
+ let code = "";
16693
+ let cursor = 0;
16694
+ for (const [start, end] of importSpans) {
16695
+ code += content.slice(cursor, start);
16696
+ cursor = end;
16697
+ }
16698
+ code += content.slice(cursor);
16699
+ code = code.trim();
16700
+ if (code)
16701
+ codeSections.push(code);
16702
+ }
16703
+ const mergedImports = sourceOrder.flatMap((source) => renderUsedImportLines(source, defaultBySource.get(source) ?? null, null, [...namedBySource.get(source)]));
16704
+ return [...mergedImports, ...otherImports, "", ...codeSections].join(`
16705
+ `);
16706
+ }
16338
16707
  function collectExternalImports(ir, generatedCode, localImportPrefixes) {
16339
16708
  const componentNames = collectComponentNames(ir.root);
16340
16709
  const importLines = [];
@@ -16350,23 +16719,31 @@ function collectExternalImports(ir, generatedCode, localImportPrefixes) {
16350
16719
  importLines.push(`import '${imp.source}'`);
16351
16720
  continue;
16352
16721
  }
16353
- const usedSpecs = [];
16722
+ const usedNamed = [];
16723
+ let usedDefault = null;
16724
+ let usedNamespace = null;
16354
16725
  for (const spec of imp.specifiers) {
16355
16726
  if (spec.isTypeOnly)
16356
16727
  continue;
16357
16728
  const localName = spec.alias || spec.name;
16358
16729
  if (componentNames.has(localName))
16359
16730
  continue;
16360
- if (isUsedAsValue(localName)) {
16361
- usedSpecs.push(spec.alias ? `${spec.name} as ${spec.alias}` : spec.name);
16731
+ if (!isUsedAsValue(localName))
16732
+ continue;
16733
+ if (spec.isDefault) {
16734
+ usedDefault = localName;
16735
+ } else if (spec.isNamespace) {
16736
+ usedNamespace = localName;
16737
+ } else {
16738
+ usedNamed.push(spec.alias ? `${spec.name} as ${spec.alias}` : spec.name);
16362
16739
  }
16363
16740
  }
16364
- if (usedSpecs.length > 0) {
16741
+ if (usedDefault || usedNamespace || usedNamed.length > 0) {
16365
16742
  let source = imp.source;
16366
16743
  if (ir.metadata.clientSignalImportSources?.has(source)) {
16367
16744
  source = source.replace(/\.tsx?$/, "") + ".client.js";
16368
16745
  }
16369
- importLines.push(`import { ${usedSpecs.join(", ")} } from '${source}'`);
16746
+ importLines.push(...renderUsedImportLines(source, usedDefault, usedNamespace, usedNamed));
16370
16747
  }
16371
16748
  }
16372
16749
  return importLines;
@@ -16396,7 +16773,7 @@ function collectComponentNames(node) {
16396
16773
  }
16397
16774
 
16398
16775
  // src/relocate.ts
16399
- import ts16 from "typescript";
16776
+ import ts17 from "typescript";
16400
16777
 
16401
16778
  // src/lowering-registry.ts
16402
16779
  var plugins = [];
@@ -16442,19 +16819,19 @@ function classify(name, env) {
16442
16819
  function collectFreeRefs(node) {
16443
16820
  const refs = new Map;
16444
16821
  function visit3(n, parent) {
16445
- if (ts16.isIdentifier(n)) {
16446
- if (parent && ts16.isPropertyAccessExpression(parent) && parent.name === n)
16822
+ if (ts17.isIdentifier(n)) {
16823
+ if (parent && ts17.isPropertyAccessExpression(parent) && parent.name === n)
16447
16824
  return;
16448
- if (parent && ts16.isPropertyAssignment(parent) && parent.name === n)
16825
+ if (parent && ts17.isPropertyAssignment(parent) && parent.name === n)
16449
16826
  return;
16450
- if (parent && ts16.isShorthandPropertyAssignment(parent) && parent.name === n)
16827
+ if (parent && ts17.isShorthandPropertyAssignment(parent) && parent.name === n)
16451
16828
  return;
16452
16829
  const list = refs.get(n.text) ?? [];
16453
16830
  list.push(n);
16454
16831
  refs.set(n.text, list);
16455
16832
  return;
16456
16833
  }
16457
- ts16.forEachChild(n, (child) => visit3(child, n));
16834
+ ts17.forEachChild(n, (child) => visit3(child, n));
16458
16835
  }
16459
16836
  visit3(node);
16460
16837
  return refs;
@@ -16558,11 +16935,11 @@ function isInlinableInTemplate(value, env) {
16558
16935
  return { ok: true, rewrittenValue: r.text, decisions: r.decisions };
16559
16936
  }
16560
16937
  function getCalleeIdentifierPath(callee) {
16561
- if (ts16.isParenthesizedExpression(callee))
16938
+ if (ts17.isParenthesizedExpression(callee))
16562
16939
  return getCalleeIdentifierPath(callee.expression);
16563
- if (ts16.isIdentifier(callee))
16940
+ if (ts17.isIdentifier(callee))
16564
16941
  return callee.text;
16565
- if (ts16.isPropertyAccessExpression(callee)) {
16942
+ if (ts17.isPropertyAccessExpression(callee)) {
16566
16943
  const left = getCalleeIdentifierPath(callee.expression);
16567
16944
  if (left === null)
16568
16945
  return null;
@@ -16571,11 +16948,11 @@ function getCalleeIdentifierPath(callee) {
16571
16948
  return null;
16572
16949
  }
16573
16950
  function getCalleeLeftmostIdentifier(callee) {
16574
- if (ts16.isParenthesizedExpression(callee))
16951
+ if (ts17.isParenthesizedExpression(callee))
16575
16952
  return getCalleeLeftmostIdentifier(callee.expression);
16576
- if (ts16.isIdentifier(callee))
16953
+ if (ts17.isIdentifier(callee))
16577
16954
  return callee.text;
16578
- if (ts16.isPropertyAccessExpression(callee)) {
16955
+ if (ts17.isPropertyAccessExpression(callee)) {
16579
16956
  return getCalleeLeftmostIdentifier(callee.expression);
16580
16957
  }
16581
16958
  return null;
@@ -16623,12 +17000,12 @@ function isCallAcceptedByAdapter(call, env) {
16623
17000
  }
16624
17001
  function parseExpressionNode(text) {
16625
17002
  try {
16626
- const sf = ts16.createSourceFile("__inline_check__.ts", `(${text});`, ts16.ScriptTarget.Latest, false, ts16.ScriptKind.TS);
17003
+ const sf = ts17.createSourceFile("__inline_check__.ts", `(${text});`, ts17.ScriptTarget.Latest, false, ts17.ScriptKind.TS);
16627
17004
  const stmt = sf.statements[0];
16628
- if (!stmt || !ts16.isExpressionStatement(stmt))
17005
+ if (!stmt || !ts17.isExpressionStatement(stmt))
16629
17006
  return null;
16630
17007
  const inner = stmt.expression;
16631
- return ts16.isParenthesizedExpression(inner) ? inner.expression : inner;
17008
+ return ts17.isParenthesizedExpression(inner) ? inner.expression : inner;
16632
17009
  } catch {
16633
17010
  return null;
16634
17011
  }
@@ -16645,8 +17022,8 @@ function hasCallWithBridgedArg(node, decisions, env) {
16645
17022
  function visit3(n) {
16646
17023
  if (found)
16647
17024
  return;
16648
- if (ts16.isCallExpression(n) || ts16.isNewExpression(n)) {
16649
- const accepted = ts16.isCallExpression(n) && isCallAcceptedByAdapter(n, env);
17025
+ if (ts17.isCallExpression(n) || ts17.isNewExpression(n)) {
17026
+ const accepted = ts17.isCallExpression(n) && isCallAcceptedByAdapter(n, env);
16650
17027
  if (!accepted) {
16651
17028
  const args = n.arguments;
16652
17029
  if (args) {
@@ -16659,7 +17036,7 @@ function hasCallWithBridgedArg(node, decisions, env) {
16659
17036
  }
16660
17037
  }
16661
17038
  }
16662
- ts16.forEachChild(n, visit3);
17039
+ ts17.forEachChild(n, visit3);
16663
17040
  }
16664
17041
  visit3(node);
16665
17042
  return found;
@@ -16669,13 +17046,13 @@ function hasZeroArgCall(node, env) {
16669
17046
  function visit3(n) {
16670
17047
  if (found)
16671
17048
  return;
16672
- if (ts16.isCallExpression(n) && n.arguments.length === 0) {
17049
+ if (ts17.isCallExpression(n) && n.arguments.length === 0) {
16673
17050
  if (!isCallAcceptedByAdapter(n, env)) {
16674
17051
  found = true;
16675
17052
  return;
16676
17053
  }
16677
17054
  }
16678
- ts16.forEachChild(n, visit3);
17055
+ ts17.forEachChild(n, visit3);
16679
17056
  }
16680
17057
  visit3(node);
16681
17058
  return found;
@@ -16685,25 +17062,25 @@ function containsAnyIdentifier(node, names) {
16685
17062
  function visit3(n) {
16686
17063
  if (found)
16687
17064
  return;
16688
- if (ts16.isPropertyAccessExpression(n)) {
17065
+ if (ts17.isPropertyAccessExpression(n)) {
16689
17066
  visit3(n.expression);
16690
17067
  return;
16691
17068
  }
16692
- if (ts16.isPropertyAssignment(n)) {
17069
+ if (ts17.isPropertyAssignment(n)) {
16693
17070
  visit3(n.initializer);
16694
17071
  return;
16695
17072
  }
16696
- if (ts16.isShorthandPropertyAssignment(n)) {
16697
- if (ts16.isIdentifier(n.name) && names.has(n.name.text)) {
17073
+ if (ts17.isShorthandPropertyAssignment(n)) {
17074
+ if (ts17.isIdentifier(n.name) && names.has(n.name.text)) {
16698
17075
  found = true;
16699
17076
  }
16700
17077
  return;
16701
17078
  }
16702
- if (ts16.isIdentifier(n) && names.has(n.text)) {
17079
+ if (ts17.isIdentifier(n) && names.has(n.text)) {
16703
17080
  found = true;
16704
17081
  return;
16705
17082
  }
16706
- ts16.forEachChild(n, visit3);
17083
+ ts17.forEachChild(n, visit3);
16707
17084
  }
16708
17085
  visit3(node);
16709
17086
  return found;
@@ -18014,23 +18391,23 @@ function resolveFinalImports(generatedCode, ir, localImportPrefixes) {
18014
18391
  }
18015
18392
 
18016
18393
  // src/ir-to-client-js/prune-unused-prop-extractions.ts
18017
- import ts17 from "typescript";
18394
+ import ts18 from "typescript";
18018
18395
  function propExtractionName(stmt) {
18019
- if (!ts17.isVariableStatement(stmt))
18396
+ if (!ts18.isVariableStatement(stmt))
18020
18397
  return null;
18021
18398
  const decls = stmt.declarationList.declarations;
18022
18399
  if (decls.length !== 1)
18023
18400
  return null;
18024
18401
  const decl = decls[0];
18025
- if (!ts17.isIdentifier(decl.name) || !decl.initializer)
18402
+ if (!ts18.isIdentifier(decl.name) || !decl.initializer)
18026
18403
  return null;
18027
18404
  let core = decl.initializer;
18028
- if (ts17.isBinaryExpression(core) && core.operatorToken.kind === ts17.SyntaxKind.QuestionQuestionToken) {
18405
+ if (ts18.isBinaryExpression(core) && core.operatorToken.kind === ts18.SyntaxKind.QuestionQuestionToken) {
18029
18406
  core = core.left;
18030
18407
  }
18031
- if (!ts17.isPropertyAccessExpression(core))
18408
+ if (!ts18.isPropertyAccessExpression(core))
18032
18409
  return null;
18033
- if (!ts17.isIdentifier(core.expression) || core.expression.text !== PROPS_PARAM)
18410
+ if (!ts18.isIdentifier(core.expression) || core.expression.text !== PROPS_PARAM)
18034
18411
  return null;
18035
18412
  if (core.name.text !== decl.name.text)
18036
18413
  return null;
@@ -18043,10 +18420,10 @@ function pruneUnusedPropExtractions(code) {
18043
18420
  console.warn("[barefootjs] pruneUnusedPropExtractions: generated code did not parse; skipping prune");
18044
18421
  return code;
18045
18422
  }
18046
- const sourceFile = ts17.createSourceFile("generated.js", code, ts17.ScriptTarget.Latest, false, ts17.ScriptKind.JS);
18423
+ const sourceFile = ts18.createSourceFile("generated.js", code, ts18.ScriptTarget.Latest, false, ts18.ScriptKind.JS);
18047
18424
  const spans = [];
18048
18425
  for (const stmt of sourceFile.statements) {
18049
- if (!ts17.isFunctionDeclaration(stmt) || !stmt.name?.text.startsWith("init") || !stmt.body)
18426
+ if (!ts18.isFunctionDeclaration(stmt) || !stmt.name?.text.startsWith("init") || !stmt.body)
18050
18427
  continue;
18051
18428
  for (const inner of stmt.body.statements) {
18052
18429
  const name = propExtractionName(inner);
@@ -19507,7 +19884,7 @@ function analyzeLazyConditional(cond, indexParam, arms) {
19507
19884
  }
19508
19885
 
19509
19886
  // src/ir-to-client-js/control-flow/plan/lazy-preamble.ts
19510
- import ts18 from "typescript";
19887
+ import ts19 from "typescript";
19511
19888
  var NO_PREAMBLE = {
19512
19889
  lazySafe: true,
19513
19890
  facts: { declaredNames: new Set, freeNames: new Set }
@@ -19527,12 +19904,12 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
19527
19904
  if (text.trim().length === 0)
19528
19905
  return NO_PREAMBLE;
19529
19906
  const declaredNames = new Set;
19530
- const sf = ts18.createSourceFile("__lazy_preamble__.ts", text, ts18.ScriptTarget.Latest, true, ts18.ScriptKind.TS);
19907
+ const sf = ts19.createSourceFile("__lazy_preamble__.ts", text, ts19.ScriptTarget.Latest, true, ts19.ScriptKind.TS);
19531
19908
  for (const stmt of sf.statements) {
19532
- if (!ts18.isVariableStatement(stmt)) {
19533
- return NO2(`map-callback preamble has a non-declaration statement (${ts18.SyntaxKind[stmt.kind]})`);
19909
+ if (!ts19.isVariableStatement(stmt)) {
19910
+ return NO2(`map-callback preamble has a non-declaration statement (${ts19.SyntaxKind[stmt.kind]})`);
19534
19911
  }
19535
- const isConst = (stmt.declarationList.flags & ts18.NodeFlags.Const) !== 0;
19912
+ const isConst = (stmt.declarationList.flags & ts19.NodeFlags.Const) !== 0;
19536
19913
  if (!isConst)
19537
19914
  return NO2("map-callback preamble declares a mutable binding (let/var)");
19538
19915
  for (const decl of stmt.declarationList.declarations) {
@@ -19561,12 +19938,12 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
19561
19938
  return { lazySafe: true, facts: { declaredNames, freeNames } };
19562
19939
  }
19563
19940
  function collectBindingNames3(name, out) {
19564
- if (ts18.isIdentifier(name)) {
19941
+ if (ts19.isIdentifier(name)) {
19565
19942
  out.add(name.text);
19566
19943
  return;
19567
19944
  }
19568
19945
  for (const element of name.elements) {
19569
- if (ts18.isOmittedExpression(element))
19946
+ if (ts19.isOmittedExpression(element))
19570
19947
  continue;
19571
19948
  collectBindingNames3(element.name, out);
19572
19949
  }
@@ -19576,56 +19953,56 @@ function findImpureNode(root, primableNames) {
19576
19953
  const visit3 = (node) => {
19577
19954
  if (found)
19578
19955
  return;
19579
- if (ts18.isCallExpression(node)) {
19956
+ if (ts19.isCallExpression(node)) {
19580
19957
  const callee = node.expression;
19581
- const isSignalRead = ts18.isIdentifier(callee) && primableNames.has(callee.text) && node.arguments.length === 0 && node.questionDotToken === undefined;
19958
+ const isSignalRead = ts19.isIdentifier(callee) && primableNames.has(callee.text) && node.arguments.length === 0 && node.questionDotToken === undefined;
19582
19959
  if (!isSignalRead) {
19583
19960
  found = `call to ${callee.getText(callee.getSourceFile())}`;
19584
19961
  return;
19585
19962
  }
19586
19963
  }
19587
- if (ts18.isNewExpression(node)) {
19964
+ if (ts19.isNewExpression(node)) {
19588
19965
  found = "new expression";
19589
19966
  return;
19590
19967
  }
19591
- if (ts18.isTaggedTemplateExpression(node)) {
19968
+ if (ts19.isTaggedTemplateExpression(node)) {
19592
19969
  found = "tagged template";
19593
19970
  return;
19594
19971
  }
19595
- if (ts18.isAwaitExpression(node)) {
19972
+ if (ts19.isAwaitExpression(node)) {
19596
19973
  found = "await";
19597
19974
  return;
19598
19975
  }
19599
- if (ts18.isYieldExpression(node)) {
19976
+ if (ts19.isYieldExpression(node)) {
19600
19977
  found = "yield";
19601
19978
  return;
19602
19979
  }
19603
- if (ts18.isPrefixUnaryExpression(node) || ts18.isPostfixUnaryExpression(node)) {
19980
+ if (ts19.isPrefixUnaryExpression(node) || ts19.isPostfixUnaryExpression(node)) {
19604
19981
  const op = node.operator;
19605
- if (op === ts18.SyntaxKind.PlusPlusToken || op === ts18.SyntaxKind.MinusMinusToken) {
19982
+ if (op === ts19.SyntaxKind.PlusPlusToken || op === ts19.SyntaxKind.MinusMinusToken) {
19606
19983
  found = "increment/decrement";
19607
19984
  return;
19608
19985
  }
19609
19986
  }
19610
- if (ts18.isDeleteExpression(node)) {
19987
+ if (ts19.isDeleteExpression(node)) {
19611
19988
  found = "delete";
19612
19989
  return;
19613
19990
  }
19614
- if (ts18.isFunctionExpression(node) || ts18.isArrowFunction(node) || ts18.isClassExpression(node)) {
19991
+ if (ts19.isFunctionExpression(node) || ts19.isArrowFunction(node) || ts19.isClassExpression(node)) {
19615
19992
  found = "function or class expression";
19616
19993
  return;
19617
19994
  }
19618
- if (ts18.isBinaryExpression(node) && isAssignmentOperator2(node.operatorToken.kind)) {
19995
+ if (ts19.isBinaryExpression(node) && isAssignmentOperator2(node.operatorToken.kind)) {
19619
19996
  found = "assignment";
19620
19997
  return;
19621
19998
  }
19622
- ts18.forEachChild(node, visit3);
19999
+ ts19.forEachChild(node, visit3);
19623
20000
  };
19624
20001
  visit3(root);
19625
20002
  return found;
19626
20003
  }
19627
20004
  function isAssignmentOperator2(kind) {
19628
- return kind >= ts18.SyntaxKind.FirstAssignment && kind <= ts18.SyntaxKind.LastAssignment;
20005
+ return kind >= ts19.SyntaxKind.FirstAssignment && kind <= ts19.SyntaxKind.LastAssignment;
19629
20006
  }
19630
20007
 
19631
20008
  // src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts
@@ -20155,7 +20532,7 @@ function buildArmBody(branch, options) {
20155
20532
  }
20156
20533
 
20157
20534
  // src/ir-to-client-js/emit-reactive.ts
20158
- import ts19 from "typescript";
20535
+ import ts20 from "typescript";
20159
20536
 
20160
20537
  // src/ir-to-client-js/control-flow/stringify/claim-plan.ts
20161
20538
  function slotSpecLiteral(slot) {
@@ -20267,20 +20644,20 @@ function lowerToLocaleCallsInReactiveExpr(expr, matcher) {
20267
20644
  return expr;
20268
20645
  let sourceFile;
20269
20646
  try {
20270
- sourceFile = ts19.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts19.ScriptTarget.Latest, true, ts19.ScriptKind.TS);
20647
+ sourceFile = ts20.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts20.ScriptTarget.Latest, true, ts20.ScriptKind.TS);
20271
20648
  } catch {
20272
20649
  return expr;
20273
20650
  }
20274
20651
  const stmt = sourceFile.statements[0];
20275
- if (!stmt || !ts19.isExpressionStatement(stmt))
20652
+ if (!stmt || !ts20.isExpressionStatement(stmt))
20276
20653
  return expr;
20277
- const root = ts19.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
20654
+ const root = ts20.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
20278
20655
  const candidates = [];
20279
20656
  const visit3 = (n) => {
20280
- if (ts19.isCallExpression(n) && n.arguments.length === 2 && ts19.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
20657
+ if (ts20.isCallExpression(n) && n.arguments.length === 2 && ts20.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
20281
20658
  candidates.push(n);
20282
20659
  }
20283
- ts19.forEachChild(n, visit3);
20660
+ ts20.forEachChild(n, visit3);
20284
20661
  };
20285
20662
  visit3(root);
20286
20663
  if (candidates.length === 0)
@@ -20316,20 +20693,20 @@ function lowerDateCallsInReactiveExpr(expr, matcher) {
20316
20693
  return expr;
20317
20694
  let sourceFile;
20318
20695
  try {
20319
- sourceFile = ts19.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts19.ScriptTarget.Latest, true, ts19.ScriptKind.TS);
20696
+ sourceFile = ts20.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts20.ScriptTarget.Latest, true, ts20.ScriptKind.TS);
20320
20697
  } catch {
20321
20698
  return expr;
20322
20699
  }
20323
20700
  const stmt = sourceFile.statements[0];
20324
- if (!stmt || !ts19.isExpressionStatement(stmt))
20701
+ if (!stmt || !ts20.isExpressionStatement(stmt))
20325
20702
  return expr;
20326
- const root = ts19.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
20703
+ const root = ts20.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
20327
20704
  const candidates = [];
20328
20705
  const visit3 = (n) => {
20329
- if (ts19.isCallExpression(n) && n.arguments.length === 0 && ts19.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
20706
+ if (ts20.isCallExpression(n) && n.arguments.length === 0 && ts20.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
20330
20707
  candidates.push(n);
20331
20708
  }
20332
- ts19.forEachChild(n, visit3);
20709
+ ts20.forEachChild(n, visit3);
20333
20710
  };
20334
20711
  visit3(root);
20335
20712
  if (candidates.length === 0)
@@ -20591,7 +20968,7 @@ function stringifyBranchInnerLoops(lines, plan, indent, pc) {
20591
20968
  stringifyLoopChildConditionals(lines, inner.nestedConditionals, `${indent} `, pc);
20592
20969
  }
20593
20970
  lines.push(`${indent} return __bel${uid}`);
20594
- lines.push(`${indent}}, '${inner.markerId}'${profileBindingId(pc, inner.slotId)}) }`);
20971
+ lines.push(`${indent}}, '${inner.markerId}'${mapArrayKeyArgs(profileBindingId(pc, inner.slotId), !!inner.wrappedKey, inner.keyDepth)}) }`);
20595
20972
  }
20596
20973
  }
20597
20974
  function stringifyLoopChildConditionals(lines, conditionals, indent, pc) {
@@ -20823,12 +21200,15 @@ function stringifyComponentLoop(lines, plan) {
20823
21200
  keyExpr,
20824
21201
  nestedComps,
20825
21202
  childConditionalEffects,
20826
- profileLoopId
21203
+ profileLoopId,
21204
+ mapPreambleWrapped
20827
21205
  } = plan;
20828
21206
  const loopBfId = profileLoopId ? `, ${JSON.stringify(profileLoopId)}` : "";
20829
21207
  lines.push(` mapArray(() => ${arrayExpr}, ${containerVar}, ${keyFn}, (${paramHead}, ${indexParam}, __existing) => {`);
20830
21208
  if (paramUnwrap)
20831
21209
  lines.push(` ${paramUnwrap}`);
21210
+ if (mapPreambleWrapped)
21211
+ lines.push(` ${mapPreambleWrapped}`);
20832
21212
  const scopedComp = nameForRegistryRef(componentName);
20833
21213
  if (nestedComps.length === 0) {
20834
21214
  lines.push(` if (__existing) { initChild('${scopedComp}', __existing, ${componentPropsExpr}); return __existing }`);
@@ -21440,7 +21820,7 @@ function emitReactive(lines, inner, indent, pc) {
21440
21820
  bodyIsMultiRoot: emit.bodyIsMultiRoot
21441
21821
  });
21442
21822
  lines.push(`${indent} return __innerEl${uid}`);
21443
- lines.push(`${indent}}, '${inner.markerId}'${profileBindingId(pc, inner.slotId)}) }`);
21823
+ lines.push(`${indent}}, '${inner.markerId}'${mapArrayKeyArgs(profileBindingId(pc, inner.slotId), !!emit.wrappedKey, inner.keyDepth)}) }`);
21444
21824
  }
21445
21825
  function emitStatic(lines, inner, indent, pc) {
21446
21826
  const uid = inner.uidSuffix;
@@ -21944,6 +22324,12 @@ function buildComponentLoopPlan(elem, profileComponentName) {
21944
22324
  const propsExpr = buildComponentPropsExpr2(elem.childComponent, elem.param);
21945
22325
  const keyExpr = wrapLoopParamAsAccessor(elem.key || "__idx", elem.param, elem.paramBindings);
21946
22326
  const { head: paramHead, unwrap: paramUnwrap } = destructureLoopParam(elem.param, elem.paramBindings);
22327
+ const mapPreambleWrapped = elem.preamble ? renderPreamble(elem.preamble, {
22328
+ transformJs: (text) => wrapLoopParamAsAccessor(text, elem.param, elem.paramBindings),
22329
+ renderLeaf: () => {
22330
+ internalInvariant(false, "component-root loop received a JSX-bearing preamble — Phase 1 should have refused it");
22331
+ }
22332
+ }) : "";
21947
22333
  const outerNestedComps = (elem.nestedComponents ?? []).filter((c) => !c.loopDepth);
21948
22334
  const nestedComps = outerNestedComps.map((comp) => {
21949
22335
  const isTextOnly = comp.children?.length ? comp.children.every((c) => c.type === "expression" || c.type === "text" || isTextOnlyConditional(c)) : false;
@@ -21961,6 +22347,7 @@ function buildComponentLoopPlan(elem, profileComponentName) {
21961
22347
  return {
21962
22348
  kind: "component",
21963
22349
  rowConstruction: "dom-ops",
22350
+ mapPreambleWrapped,
21964
22351
  containerVar: `_${varSlotId(elem.slotId)}`,
21965
22352
  markerId: elem.markerId,
21966
22353
  arrayExpr: buildChainedArrayExpr(elem),
@@ -22143,6 +22530,7 @@ function emitLoopUpdates(lines, ctx, unsafeLocalNames) {
22143
22530
  lazyScope
22144
22531
  });
22145
22532
  internalInvariant(!(elem.preamble && elem.preamble.builderNames.length > 0 && plan.rowConstruction === "dom-ops"), `loop variant '${plan.kind}' declares dom-ops row construction but received a JSX-bearing preamble — add a Phase-1 refusal (or wire renderPreamble support) for this shape`);
22533
+ internalInvariant(!(elem.preamble && elem.preamble.declaredNames.length > 0 && ("mapPreambleWrapped" in plan) && plan.mapPreambleWrapped === ""), `loop variant '${plan.kind}' has a preamble with declared names (${elem.preamble?.declaredNames.join(", ")}) but its plan's mapPreambleWrapped is empty — wire it up or the emitted call site references a name nothing declares`);
22146
22534
  stringifyLoop(lines, plan);
22147
22535
  emitLoopEventDelegation(lines, elem, plan.kind, ctx.profile ? ctx.componentName : undefined);
22148
22536
  }
@@ -22350,7 +22738,7 @@ var PHASES = [
22350
22738
  ];
22351
22739
 
22352
22740
  // src/ir-to-client-js/rewrite-props-object.ts
22353
- import ts20 from "typescript";
22741
+ import ts21 from "typescript";
22354
22742
  function rewritePropsObjectRef(code, propsObjectName, restPropsName = null) {
22355
22743
  let result = code;
22356
22744
  const seen = new Set;
@@ -22365,13 +22753,13 @@ function rewritePropsObjectRef(code, propsObjectName, restPropsName = null) {
22365
22753
  function rewriteOneName(code, srcPropsName) {
22366
22754
  if (!identifierPattern(srcPropsName).test(code))
22367
22755
  return code;
22368
- const sourceFile = ts20.createSourceFile("init-body.ts", code, ts20.ScriptTarget.Latest, true, ts20.ScriptKind.TS);
22756
+ const sourceFile = ts21.createSourceFile("init-body.ts", code, ts21.ScriptTarget.Latest, true, ts21.ScriptKind.TS);
22369
22757
  const spans = [];
22370
22758
  function visit3(node) {
22371
- if (ts20.isIdentifier(node) && node.text === srcPropsName && shouldRewrite(node)) {
22759
+ if (ts21.isIdentifier(node) && node.text === srcPropsName && shouldRewrite(node)) {
22372
22760
  spans.push([node.getStart(sourceFile), node.getEnd()]);
22373
22761
  }
22374
- ts20.forEachChild(node, visit3);
22762
+ ts21.forEachChild(node, visit3);
22375
22763
  }
22376
22764
  visit3(sourceFile);
22377
22765
  if (spans.length === 0)
@@ -22387,17 +22775,17 @@ function shouldRewrite(node) {
22387
22775
  const parent = node.parent;
22388
22776
  if (!parent)
22389
22777
  return true;
22390
- if (ts20.isPropertyAccessExpression(parent) && parent.name === node)
22778
+ if (ts21.isPropertyAccessExpression(parent) && parent.name === node)
22391
22779
  return false;
22392
- if (ts20.isPropertyAssignment(parent) && parent.name === node)
22780
+ if (ts21.isPropertyAssignment(parent) && parent.name === node)
22393
22781
  return false;
22394
- if (ts20.isShorthandPropertyAssignment(parent) && parent.name === node)
22782
+ if (ts21.isShorthandPropertyAssignment(parent) && parent.name === node)
22395
22783
  return false;
22396
- if (ts20.isPropertySignature(parent) && parent.name === node)
22784
+ if (ts21.isPropertySignature(parent) && parent.name === node)
22397
22785
  return false;
22398
- if (ts20.isPropertyDeclaration(parent) && parent.name === node)
22786
+ if (ts21.isPropertyDeclaration(parent) && parent.name === node)
22399
22787
  return false;
22400
- if (ts20.isBindingElement(parent) && parent.name === node)
22788
+ if (ts21.isBindingElement(parent) && parent.name === node)
22401
22789
  return false;
22402
22790
  return true;
22403
22791
  }
@@ -22709,7 +23097,7 @@ function createContext(ir, scope, adapterCapabilities, profile) {
22709
23097
  };
22710
23098
  }
22711
23099
  function needsClientJs(ctx) {
22712
- if (ctx.signals.length > 0 || ctx.memos.length > 0 || ctx.effects.length > 0 || ctx.onMounts.length > 0 || ctx.initStatements.length > 0 || ctx.interactiveElements.length > 0 || ctx.dynamicElements.length > 0 || ctx.conditionalElements.length > 0 || ctx.loopElements.length > 0 || ctx.refElements.length > 0 || ctx.childInits.length > 0 || ctx.reactiveAttrs.length > 0 || ctx.clientOnlyElements.length > 0 || ctx.clientOnlyConditionals.length > 0 || ctx.providerSetups.length > 0)
23100
+ if (ctx.signals.length > 0 || ctx.memos.length > 0 || ctx.effects.length > 0 || ctx.onMounts.length > 0 || ctx.initStatements.length > 0 || ctx.interactiveElements.length > 0 || ctx.dynamicElements.length > 0 || ctx.conditionalElements.length > 0 || ctx.loopElements.length > 0 || ctx.refElements.length > 0 || ctx.restAttrElements.length > 0 || ctx.childInits.length > 0 || ctx.reactiveAttrs.length > 0 || ctx.clientOnlyElements.length > 0 || ctx.clientOnlyConditionals.length > 0 || ctx.providerSetups.length > 0)
22713
23101
  return true;
22714
23102
  return hasInitScopeOnlyConstant(ctx);
22715
23103
  }
@@ -23047,7 +23435,7 @@ function walkIR2(node, visitor) {
23047
23435
  }
23048
23436
 
23049
23437
  // src/preprocess-inline-jsx-callbacks.ts
23050
- import ts21 from "typescript";
23438
+ import ts22 from "typescript";
23051
23439
  var SYNTHETIC_PREFIX = "BFInlineJsxCallback";
23052
23440
  var MAX_FIXPOINT_ITERATIONS = 16;
23053
23441
  function preprocessInlineJsxCallbacks(source, filePath) {
@@ -23069,8 +23457,8 @@ function preprocessInlineJsxCallbacks(source, filePath) {
23069
23457
  return { source: current, errors, syntheticNames };
23070
23458
  }
23071
23459
  function runSinglePass(source, filePath, startingCounter) {
23072
- const sourceFile = ts21.createSourceFile(filePath, source, ts21.ScriptTarget.Latest, true, ts21.ScriptKind.TSX);
23073
- const hasUseClient = sourceFile.statements.some((stmt) => ts21.isExpressionStatement(stmt) && ts21.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
23460
+ const sourceFile = ts22.createSourceFile(filePath, source, ts22.ScriptTarget.Latest, true, ts22.ScriptKind.TSX);
23461
+ const hasUseClient = sourceFile.statements.some((stmt) => ts22.isExpressionStatement(stmt) && ts22.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
23074
23462
  if (!hasUseClient) {
23075
23463
  return { source, errors: [], syntheticNames: [], counterAfter: startingCounter };
23076
23464
  }
@@ -23092,22 +23480,22 @@ function runSinglePass(source, filePath, startingCounter) {
23092
23480
  }
23093
23481
  }
23094
23482
  function visit3(node) {
23095
- if (ts21.isJsxAttribute(node) && node.initializer && ts21.isJsxExpression(node.initializer) && node.initializer.expression) {
23483
+ if (ts22.isJsxAttribute(node) && node.initializer && ts22.isJsxExpression(node.initializer) && node.initializer.expression) {
23096
23484
  if (tryHandleArrowValue(node.initializer.expression)) {
23097
23485
  return;
23098
23486
  }
23099
23487
  }
23100
- if (ts21.isPropertyAssignment(node) && node.initializer) {
23488
+ if (ts22.isPropertyAssignment(node) && node.initializer) {
23101
23489
  if (tryHandleArrowValue(node.initializer))
23102
23490
  return;
23103
23491
  }
23104
- ts21.forEachChild(node, visit3);
23492
+ ts22.forEachChild(node, visit3);
23105
23493
  }
23106
23494
  function tryHandleArrowValue(initializer) {
23107
23495
  let expr = initializer;
23108
- while (ts21.isParenthesizedExpression(expr))
23496
+ while (ts22.isParenthesizedExpression(expr))
23109
23497
  expr = expr.expression;
23110
- if (ts21.isArrowFunction(expr) && arrowBodyContainsJsx(expr)) {
23498
+ if (ts22.isArrowFunction(expr) && arrowBodyContainsJsx(expr)) {
23111
23499
  return handleInlineArrow(expr);
23112
23500
  }
23113
23501
  return false;
@@ -23144,7 +23532,7 @@ function runSinglePass(source, filePath, startingCounter) {
23144
23532
  replacements.push({ start: arrowStart, end: arrowEnd, text: name });
23145
23533
  return true;
23146
23534
  }
23147
- ts21.forEachChild(sourceFile, visit3);
23535
+ ts22.forEachChild(sourceFile, visit3);
23148
23536
  if (replacements.length === 0) {
23149
23537
  return { source, errors, syntheticNames, counterAfter: counter };
23150
23538
  }
@@ -23167,11 +23555,11 @@ function errorMessageForCapture(captures) {
23167
23555
  return `Inline JSX-returning arrow function captures non-module identifier(s): ` + `${captures.sort().join(", ")}. ` + `Extract the callback into a top-level '\\'use client\\'' component (e.g. ` + `\`function MyNode(n) { return <div/> }\` then \`renderNode={MyNode}\`) ` + `or pass captured values via component props.`;
23168
23556
  }
23169
23557
  function arrowBodyContainsJsx(arrow) {
23170
- if (ts21.isBlock(arrow.body)) {
23558
+ if (ts22.isBlock(arrow.body)) {
23171
23559
  return blockReturnsJsx(arrow.body);
23172
23560
  }
23173
23561
  let body = arrow.body;
23174
- while (ts21.isParenthesizedExpression(body))
23562
+ while (ts22.isParenthesizedExpression(body))
23175
23563
  body = body.expression;
23176
23564
  return isJsxLike(body);
23177
23565
  }
@@ -23180,24 +23568,24 @@ function blockReturnsJsx(block) {
23180
23568
  function visit3(n) {
23181
23569
  if (found)
23182
23570
  return;
23183
- if (ts21.isReturnStatement(n) && n.expression) {
23571
+ if (ts22.isReturnStatement(n) && n.expression) {
23184
23572
  let e = n.expression;
23185
- while (ts21.isParenthesizedExpression(e))
23573
+ while (ts22.isParenthesizedExpression(e))
23186
23574
  e = e.expression;
23187
23575
  if (isJsxLike(e)) {
23188
23576
  found = true;
23189
23577
  return;
23190
23578
  }
23191
23579
  }
23192
- if (ts21.isArrowFunction(n) || ts21.isFunctionDeclaration(n) || ts21.isFunctionExpression(n))
23580
+ if (ts22.isArrowFunction(n) || ts22.isFunctionDeclaration(n) || ts22.isFunctionExpression(n))
23193
23581
  return;
23194
- ts21.forEachChild(n, visit3);
23582
+ ts22.forEachChild(n, visit3);
23195
23583
  }
23196
- ts21.forEachChild(block, visit3);
23584
+ ts22.forEachChild(block, visit3);
23197
23585
  return found;
23198
23586
  }
23199
23587
  function isJsxLike(expr) {
23200
- return ts21.isJsxElement(expr) || ts21.isJsxSelfClosingElement(expr) || ts21.isJsxFragment(expr);
23588
+ return ts22.isJsxElement(expr) || ts22.isJsxSelfClosingElement(expr) || ts22.isJsxFragment(expr);
23201
23589
  }
23202
23590
  function collectArrowParamNames(arrow) {
23203
23591
  const names = new Set;
@@ -23207,13 +23595,13 @@ function collectArrowParamNames(arrow) {
23207
23595
  }
23208
23596
  function collectBindingNames4(name, out) {
23209
23597
  const push = Array.isArray(out) ? (n) => out.push(n) : (n) => out.add(n);
23210
- if (ts21.isIdentifier(name)) {
23598
+ if (ts22.isIdentifier(name)) {
23211
23599
  push(name.text);
23212
- } else if (ts21.isObjectBindingPattern(name)) {
23600
+ } else if (ts22.isObjectBindingPattern(name)) {
23213
23601
  name.elements.forEach((el) => collectBindingNames4(el.name, out));
23214
- } else if (ts21.isArrayBindingPattern(name)) {
23602
+ } else if (ts22.isArrayBindingPattern(name)) {
23215
23603
  name.elements.forEach((el) => {
23216
- if (!ts21.isOmittedExpression(el))
23604
+ if (!ts22.isOmittedExpression(el))
23217
23605
  collectBindingNames4(el.name, out);
23218
23606
  });
23219
23607
  }
@@ -23240,48 +23628,48 @@ function collectFreeIdentifiers(arrow) {
23240
23628
  return bound.includes(name);
23241
23629
  }
23242
23630
  function visit3(node) {
23243
- if (ts21.isIdentifier(node)) {
23631
+ if (ts22.isIdentifier(node)) {
23244
23632
  const parent = node.parent;
23245
- if (parent && ts21.isPropertyAccessExpression(parent) && parent.name === node)
23633
+ if (parent && ts22.isPropertyAccessExpression(parent) && parent.name === node)
23246
23634
  return;
23247
- if (parent && ts21.isPropertyAssignment(parent) && parent.name === node)
23635
+ if (parent && ts22.isPropertyAssignment(parent) && parent.name === node)
23248
23636
  return;
23249
- if (parent && ts21.isPropertySignature(parent) && parent.name === node)
23637
+ if (parent && ts22.isPropertySignature(parent) && parent.name === node)
23250
23638
  return;
23251
- if (parent && ts21.isPropertyDeclaration(parent) && parent.name === node)
23639
+ if (parent && ts22.isPropertyDeclaration(parent) && parent.name === node)
23252
23640
  return;
23253
- if (parent && ts21.isMethodDeclaration(parent) && parent.name === node)
23641
+ if (parent && ts22.isMethodDeclaration(parent) && parent.name === node)
23254
23642
  return;
23255
- if (parent && ts21.isMethodSignature(parent) && parent.name === node)
23643
+ if (parent && ts22.isMethodSignature(parent) && parent.name === node)
23256
23644
  return;
23257
- if (parent && ts21.isGetAccessorDeclaration(parent) && parent.name === node)
23645
+ if (parent && ts22.isGetAccessorDeclaration(parent) && parent.name === node)
23258
23646
  return;
23259
- if (parent && ts21.isSetAccessorDeclaration(parent) && parent.name === node)
23647
+ if (parent && ts22.isSetAccessorDeclaration(parent) && parent.name === node)
23260
23648
  return;
23261
- if (parent && ts21.isEnumMember(parent) && parent.name === node)
23649
+ if (parent && ts22.isEnumMember(parent) && parent.name === node)
23262
23650
  return;
23263
- if (parent && ts21.isBindingElement(parent) && parent.propertyName === node)
23651
+ if (parent && ts22.isBindingElement(parent) && parent.propertyName === node)
23264
23652
  return;
23265
- if (parent && ts21.isShorthandPropertyAssignment(parent) && parent.name === node) {
23653
+ if (parent && ts22.isShorthandPropertyAssignment(parent) && parent.name === node) {
23266
23654
  if (!isBound(node.text))
23267
23655
  ids.add(node.text);
23268
23656
  return;
23269
23657
  }
23270
- if (parent && ts21.isParameter(parent) && parent.name === node)
23658
+ if (parent && ts22.isParameter(parent) && parent.name === node)
23271
23659
  return;
23272
- if (parent && ts21.isVariableDeclaration(parent) && parent.name === node)
23660
+ if (parent && ts22.isVariableDeclaration(parent) && parent.name === node)
23273
23661
  return;
23274
- if (parent && ts21.isFunctionDeclaration(parent) && parent.name === node)
23662
+ if (parent && ts22.isFunctionDeclaration(parent) && parent.name === node)
23275
23663
  return;
23276
- if (parent && ts21.isClassDeclaration(parent) && parent.name === node)
23664
+ if (parent && ts22.isClassDeclaration(parent) && parent.name === node)
23277
23665
  return;
23278
- if (parent && ts21.isJsxAttribute(parent) && parent.name === node)
23666
+ if (parent && ts22.isJsxAttribute(parent) && parent.name === node)
23279
23667
  return;
23280
- if (parent && ts21.isJsxOpeningElement(parent) && parent.tagName === node) {
23668
+ if (parent && ts22.isJsxOpeningElement(parent) && parent.tagName === node) {
23281
23669
  if (/^[a-z]/.test(node.text))
23282
23670
  return;
23283
23671
  }
23284
- if (parent && ts21.isJsxClosingElement(parent) && parent.tagName === node) {
23672
+ if (parent && ts22.isJsxClosingElement(parent) && parent.tagName === node) {
23285
23673
  if (/^[a-z]/.test(node.text))
23286
23674
  return;
23287
23675
  }
@@ -23290,43 +23678,43 @@ function collectFreeIdentifiers(arrow) {
23290
23678
  ids.add(node.text);
23291
23679
  return;
23292
23680
  }
23293
- if (ts21.isVariableDeclaration(node)) {
23681
+ if (ts22.isVariableDeclaration(node)) {
23294
23682
  const declared = pushBindings(node.name);
23295
23683
  if (node.initializer)
23296
23684
  visit3(node.initializer);
23297
23685
  return;
23298
23686
  }
23299
- if (ts21.isFunctionDeclaration(node)) {
23687
+ if (ts22.isFunctionDeclaration(node)) {
23300
23688
  if (node.name)
23301
23689
  bound.push(node.name.text);
23302
23690
  visitInsideNewScope(node);
23303
23691
  return;
23304
23692
  }
23305
- if (ts21.isClassDeclaration(node)) {
23693
+ if (ts22.isClassDeclaration(node)) {
23306
23694
  if (node.name)
23307
23695
  bound.push(node.name.text);
23308
- ts21.forEachChild(node, visit3);
23696
+ ts22.forEachChild(node, visit3);
23309
23697
  return;
23310
23698
  }
23311
- if (ts21.isArrowFunction(node) || ts21.isFunctionExpression(node)) {
23699
+ if (ts22.isArrowFunction(node) || ts22.isFunctionExpression(node)) {
23312
23700
  visitInsideNewScope(node);
23313
23701
  return;
23314
23702
  }
23315
- if (ts21.isCatchClause(node)) {
23703
+ if (ts22.isCatchClause(node)) {
23316
23704
  const before = bound.length;
23317
23705
  if (node.variableDeclaration)
23318
23706
  pushBindings(node.variableDeclaration.name);
23319
- ts21.forEachChild(node, visit3);
23707
+ ts22.forEachChild(node, visit3);
23320
23708
  popN(bound.length - before);
23321
23709
  return;
23322
23710
  }
23323
- if (ts21.isBlock(node)) {
23711
+ if (ts22.isBlock(node)) {
23324
23712
  const before = bound.length;
23325
- ts21.forEachChild(node, visit3);
23713
+ ts22.forEachChild(node, visit3);
23326
23714
  popN(bound.length - before);
23327
23715
  return;
23328
23716
  }
23329
- ts21.forEachChild(node, visit3);
23717
+ ts22.forEachChild(node, visit3);
23330
23718
  }
23331
23719
  function visitInsideNewScope(fn) {
23332
23720
  const before = bound.length;
@@ -23349,29 +23737,29 @@ function collectFreeIdentifiers(arrow) {
23349
23737
  function collectModuleScopeNames(sourceFile) {
23350
23738
  const names = new Set;
23351
23739
  for (const stmt of sourceFile.statements) {
23352
- if (ts21.isFunctionDeclaration(stmt) && stmt.name)
23740
+ if (ts22.isFunctionDeclaration(stmt) && stmt.name)
23353
23741
  names.add(stmt.name.text);
23354
- else if (ts21.isClassDeclaration(stmt) && stmt.name)
23742
+ else if (ts22.isClassDeclaration(stmt) && stmt.name)
23355
23743
  names.add(stmt.name.text);
23356
- else if (ts21.isVariableStatement(stmt)) {
23744
+ else if (ts22.isVariableStatement(stmt)) {
23357
23745
  for (const decl of stmt.declarationList.declarations)
23358
23746
  collectBindingNames4(decl.name, names);
23359
- } else if (ts21.isImportDeclaration(stmt) && stmt.importClause) {
23747
+ } else if (ts22.isImportDeclaration(stmt) && stmt.importClause) {
23360
23748
  const ic = stmt.importClause;
23361
23749
  if (ic.name)
23362
23750
  names.add(ic.name.text);
23363
23751
  if (ic.namedBindings) {
23364
- if (ts21.isNamespaceImport(ic.namedBindings))
23752
+ if (ts22.isNamespaceImport(ic.namedBindings))
23365
23753
  names.add(ic.namedBindings.name.text);
23366
23754
  else
23367
23755
  for (const e of ic.namedBindings.elements)
23368
23756
  names.add(e.name.text);
23369
23757
  }
23370
- } else if (ts21.isTypeAliasDeclaration(stmt))
23758
+ } else if (ts22.isTypeAliasDeclaration(stmt))
23371
23759
  names.add(stmt.name.text);
23372
- else if (ts21.isInterfaceDeclaration(stmt))
23760
+ else if (ts22.isInterfaceDeclaration(stmt))
23373
23761
  names.add(stmt.name.text);
23374
- else if (ts21.isEnumDeclaration(stmt))
23762
+ else if (ts22.isEnumDeclaration(stmt))
23375
23763
  names.add(stmt.name.text);
23376
23764
  }
23377
23765
  return names;
@@ -23379,7 +23767,7 @@ function collectModuleScopeNames(sourceFile) {
23379
23767
  function buildSyntheticDeclaration(name, arrow, sourceFile) {
23380
23768
  const paramsText = arrow.parameters.length === 0 ? "" : arrow.parameters.map((p) => p.getText(sourceFile)).join(", ");
23381
23769
  let bodyText;
23382
- if (ts21.isBlock(arrow.body)) {
23770
+ if (ts22.isBlock(arrow.body)) {
23383
23771
  bodyText = arrow.body.getText(sourceFile);
23384
23772
  } else {
23385
23773
  const expr = arrow.body.getText(sourceFile);
@@ -23389,7 +23777,7 @@ function buildSyntheticDeclaration(name, arrow, sourceFile) {
23389
23777
  }
23390
23778
 
23391
23779
  // src/ssr-defaults.ts
23392
- import ts22 from "typescript";
23780
+ import ts23 from "typescript";
23393
23781
  function deriveStashFromDefaults(defaults, props) {
23394
23782
  const extra = {};
23395
23783
  for (const [name, d] of Object.entries(defaults)) {
@@ -23512,11 +23900,11 @@ function collectPropRefs(expr, propsObjectName, out) {
23512
23900
  if (!node)
23513
23901
  return;
23514
23902
  const visit3 = (n) => {
23515
- if (ts22.isPropertyAccessExpression(n) && ts22.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts22.isIdentifier(n.name)) {
23903
+ if (ts23.isPropertyAccessExpression(n) && ts23.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts23.isIdentifier(n.name)) {
23516
23904
  out.add(n.name.text);
23517
23905
  return;
23518
23906
  }
23519
- ts22.forEachChild(n, visit3);
23907
+ ts23.forEachChild(n, visit3);
23520
23908
  };
23521
23909
  visit3(node);
23522
23910
  }
@@ -23554,23 +23942,23 @@ function tryStaticEval(expr, ctx) {
23554
23942
  }
23555
23943
  function evalStatementsForReturn(statements, ctx) {
23556
23944
  for (const stmt of statements) {
23557
- if (ts22.isVariableStatement(stmt)) {
23945
+ if (ts23.isVariableStatement(stmt)) {
23558
23946
  for (const d of stmt.declarationList.declarations) {
23559
- if (!ts22.isIdentifier(d.name) || !d.initializer)
23947
+ if (!ts23.isIdentifier(d.name) || !d.initializer)
23560
23948
  continue;
23561
23949
  const v = evalNode(d.initializer, ctx);
23562
23950
  if (v !== UNRESOLVED)
23563
23951
  ctx.bindings[d.name.text] = v;
23564
23952
  }
23565
- } else if (ts22.isReturnStatement(stmt)) {
23953
+ } else if (ts23.isReturnStatement(stmt)) {
23566
23954
  return stmt.expression ? evalNode(stmt.expression, ctx) : UNRESOLVED;
23567
- } else if (ts22.isIfStatement(stmt)) {
23955
+ } else if (ts23.isIfStatement(stmt)) {
23568
23956
  const cond = evalNode(stmt.expression, ctx);
23569
23957
  if (cond === UNRESOLVED)
23570
23958
  return UNRESOLVED;
23571
23959
  const branch = cond ? stmt.thenStatement : stmt.elseStatement;
23572
23960
  if (branch) {
23573
- const taken = evalStatementsForReturn(ts22.isBlock(branch) ? branch.statements : [branch], ctx);
23961
+ const taken = evalStatementsForReturn(ts23.isBlock(branch) ? branch.statements : [branch], ctx);
23574
23962
  if (taken !== NO_RETURN)
23575
23963
  return taken;
23576
23964
  }
@@ -23581,45 +23969,45 @@ function evalStatementsForReturn(statements, ctx) {
23581
23969
  return NO_RETURN;
23582
23970
  }
23583
23971
  function parseExpression2(expr) {
23584
- const sf = ts22.createSourceFile("__ssr_default__.ts", `(${expr})`, ts22.ScriptTarget.Latest, true, ts22.ScriptKind.TS);
23972
+ const sf = ts23.createSourceFile("__ssr_default__.ts", `(${expr})`, ts23.ScriptTarget.Latest, true, ts23.ScriptKind.TS);
23585
23973
  const stmt = sf.statements[0];
23586
- if (!stmt || !ts22.isExpressionStatement(stmt))
23974
+ if (!stmt || !ts23.isExpressionStatement(stmt))
23587
23975
  return null;
23588
- const inner = ts22.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
23976
+ const inner = ts23.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
23589
23977
  return inner;
23590
23978
  }
23591
23979
  function evalNode(node, ctx) {
23592
- if (ts22.isParenthesizedExpression(node))
23980
+ if (ts23.isParenthesizedExpression(node))
23593
23981
  return evalNode(node.expression, ctx);
23594
- if (ts22.isAsExpression(node))
23982
+ if (ts23.isAsExpression(node))
23595
23983
  return evalNode(node.expression, ctx);
23596
- if (ts22.isSatisfiesExpression(node))
23984
+ if (ts23.isSatisfiesExpression(node))
23597
23985
  return evalNode(node.expression, ctx);
23598
- if (ts22.isTypeAssertionExpression(node))
23986
+ if (ts23.isTypeAssertionExpression(node))
23599
23987
  return evalNode(node.expression, ctx);
23600
- if (ts22.isNonNullExpression(node))
23988
+ if (ts23.isNonNullExpression(node))
23601
23989
  return evalNode(node.expression, ctx);
23602
- if (ts22.isArrowFunction(node)) {
23990
+ if (ts23.isArrowFunction(node)) {
23603
23991
  if (node.parameters.length !== 0)
23604
23992
  return UNRESOLVED;
23605
- if (!ts22.isBlock(node.body))
23993
+ if (!ts23.isBlock(node.body))
23606
23994
  return evalNode(node.body, ctx);
23607
23995
  const localBindings = { ...ctx.bindings };
23608
23996
  const localCtx = { ...ctx, bindings: localBindings };
23609
23997
  const result = evalStatementsForReturn(node.body.statements, localCtx);
23610
23998
  return result === NO_RETURN ? UNRESOLVED : result;
23611
23999
  }
23612
- if (ts22.isNumericLiteral(node))
24000
+ if (ts23.isNumericLiteral(node))
23613
24001
  return Number(node.text);
23614
- if (ts22.isStringLiteralLike(node))
24002
+ if (ts23.isStringLiteralLike(node))
23615
24003
  return node.text;
23616
- if (node.kind === ts22.SyntaxKind.TrueKeyword)
24004
+ if (node.kind === ts23.SyntaxKind.TrueKeyword)
23617
24005
  return true;
23618
- if (node.kind === ts22.SyntaxKind.FalseKeyword)
24006
+ if (node.kind === ts23.SyntaxKind.FalseKeyword)
23619
24007
  return false;
23620
- if (node.kind === ts22.SyntaxKind.NullKeyword)
24008
+ if (node.kind === ts23.SyntaxKind.NullKeyword)
23621
24009
  return null;
23622
- if (ts22.isIdentifier(node)) {
24010
+ if (ts23.isIdentifier(node)) {
23623
24011
  if (node.text === "undefined")
23624
24012
  return;
23625
24013
  if (node.text in ctx.bindings)
@@ -23628,29 +24016,29 @@ function evalNode(node, ctx) {
23628
24016
  return;
23629
24017
  return UNRESOLVED;
23630
24018
  }
23631
- if (ts22.isPrefixUnaryExpression(node)) {
24019
+ if (ts23.isPrefixUnaryExpression(node)) {
23632
24020
  const arg = evalNode(node.operand, ctx);
23633
24021
  if (arg === UNRESOLVED)
23634
24022
  return UNRESOLVED;
23635
24023
  switch (node.operator) {
23636
- case ts22.SyntaxKind.MinusToken:
24024
+ case ts23.SyntaxKind.MinusToken:
23637
24025
  return typeof arg === "number" ? -arg : UNRESOLVED;
23638
- case ts22.SyntaxKind.PlusToken:
24026
+ case ts23.SyntaxKind.PlusToken:
23639
24027
  return typeof arg === "number" ? +arg : UNRESOLVED;
23640
- case ts22.SyntaxKind.ExclamationToken:
24028
+ case ts23.SyntaxKind.ExclamationToken:
23641
24029
  return !arg;
23642
24030
  }
23643
24031
  return UNRESOLVED;
23644
24032
  }
23645
- if (ts22.isObjectLiteralExpression(node)) {
24033
+ if (ts23.isObjectLiteralExpression(node)) {
23646
24034
  const obj = {};
23647
24035
  for (const prop of node.properties) {
23648
- if (!ts22.isPropertyAssignment(prop))
24036
+ if (!ts23.isPropertyAssignment(prop))
23649
24037
  return UNRESOLVED;
23650
24038
  let key;
23651
- if (ts22.isIdentifier(prop.name) || ts22.isStringLiteralLike(prop.name)) {
24039
+ if (ts23.isIdentifier(prop.name) || ts23.isStringLiteralLike(prop.name)) {
23652
24040
  key = prop.name.text;
23653
- } else if (ts22.isNumericLiteral(prop.name)) {
24041
+ } else if (ts23.isNumericLiteral(prop.name)) {
23654
24042
  key = prop.name.text;
23655
24043
  } else {
23656
24044
  return UNRESOLVED;
@@ -23662,10 +24050,10 @@ function evalNode(node, ctx) {
23662
24050
  }
23663
24051
  return obj;
23664
24052
  }
23665
- if (ts22.isArrayLiteralExpression(node)) {
24053
+ if (ts23.isArrayLiteralExpression(node)) {
23666
24054
  const arr = [];
23667
24055
  for (const elem of node.elements) {
23668
- if (ts22.isOmittedExpression(elem))
24056
+ if (ts23.isOmittedExpression(elem))
23669
24057
  return UNRESOLVED;
23670
24058
  const v = evalNode(elem, ctx);
23671
24059
  if (v === UNRESOLVED)
@@ -23674,7 +24062,7 @@ function evalNode(node, ctx) {
23674
24062
  }
23675
24063
  return arr;
23676
24064
  }
23677
- if (ts22.isElementAccessExpression(node)) {
24065
+ if (ts23.isElementAccessExpression(node)) {
23678
24066
  const base = evalNode(node.expression, ctx);
23679
24067
  if (base === undefined)
23680
24068
  return;
@@ -23688,7 +24076,7 @@ function evalNode(node, ctx) {
23688
24076
  const k = String(key);
23689
24077
  return Object.prototype.hasOwnProperty.call(base, k) ? base[k] : undefined;
23690
24078
  }
23691
- if (ts22.isPropertyAccessExpression(node)) {
24079
+ if (ts23.isPropertyAccessExpression(node)) {
23692
24080
  const baseResult = evalNode(node.expression, ctx);
23693
24081
  if (baseResult === undefined)
23694
24082
  return;
@@ -23701,13 +24089,13 @@ function evalNode(node, ctx) {
23701
24089
  const key = node.name.text;
23702
24090
  return Object.prototype.hasOwnProperty.call(baseResult, key) ? baseResult[key] : undefined;
23703
24091
  }
23704
- if (ts22.isCallExpression(node)) {
23705
- if (node.arguments.length === 0 && ts22.isIdentifier(node.expression) && node.expression.text in ctx.bindings) {
24092
+ if (ts23.isCallExpression(node)) {
24093
+ if (node.arguments.length === 0 && ts23.isIdentifier(node.expression) && node.expression.text in ctx.bindings) {
23706
24094
  return ctx.bindings[node.expression.text];
23707
24095
  }
23708
- if (ts22.isPropertyAccessExpression(node.expression) && node.expression.name.text === "map" && node.arguments.length === 1) {
24096
+ if (ts23.isPropertyAccessExpression(node.expression) && node.expression.name.text === "map" && node.arguments.length === 1) {
23709
24097
  const arrow = node.arguments[0];
23710
- if (ts22.isArrowFunction(arrow) && arrow.parameters.length === 1 && ts22.isIdentifier(arrow.parameters[0].name) && !ts22.isBlock(arrow.body)) {
24098
+ if (ts23.isArrowFunction(arrow) && arrow.parameters.length === 1 && ts23.isIdentifier(arrow.parameters[0].name) && !ts23.isBlock(arrow.body)) {
23711
24099
  const recv = evalNode(node.expression.expression, ctx);
23712
24100
  if (Array.isArray(recv)) {
23713
24101
  const paramName = arrow.parameters[0].name.text;
@@ -23724,7 +24112,7 @@ function evalNode(node, ctx) {
23724
24112
  }
23725
24113
  return UNRESOLVED;
23726
24114
  }
23727
- if (ts22.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
24115
+ if (ts23.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
23728
24116
  const recv = evalNode(node.expression.expression, ctx);
23729
24117
  if (Array.isArray(recv)) {
23730
24118
  let sep2 = ",";
@@ -23740,27 +24128,27 @@ function evalNode(node, ctx) {
23740
24128
  }
23741
24129
  return UNRESOLVED;
23742
24130
  }
23743
- if (ts22.isConditionalExpression(node)) {
24131
+ if (ts23.isConditionalExpression(node)) {
23744
24132
  const cond = evalNode(node.condition, ctx);
23745
24133
  if (cond === UNRESOLVED)
23746
24134
  return UNRESOLVED;
23747
24135
  return cond ? evalNode(node.whenTrue, ctx) : evalNode(node.whenFalse, ctx);
23748
24136
  }
23749
- if (ts22.isBinaryExpression(node)) {
24137
+ if (ts23.isBinaryExpression(node)) {
23750
24138
  const op = node.operatorToken.kind;
23751
- if (op === ts22.SyntaxKind.QuestionQuestionToken) {
24139
+ if (op === ts23.SyntaxKind.QuestionQuestionToken) {
23752
24140
  const l2 = evalNode(node.left, ctx);
23753
24141
  if (l2 !== UNRESOLVED && l2 !== null && l2 !== undefined)
23754
24142
  return l2;
23755
24143
  return evalNode(node.right, ctx);
23756
24144
  }
23757
- if (op === ts22.SyntaxKind.BarBarToken) {
24145
+ if (op === ts23.SyntaxKind.BarBarToken) {
23758
24146
  const l2 = evalNode(node.left, ctx);
23759
24147
  if (l2 !== UNRESOLVED && l2)
23760
24148
  return l2;
23761
24149
  return evalNode(node.right, ctx);
23762
24150
  }
23763
- if (op === ts22.SyntaxKind.AmpersandAmpersandToken) {
24151
+ if (op === ts23.SyntaxKind.AmpersandAmpersandToken) {
23764
24152
  const l2 = evalNode(node.left, ctx);
23765
24153
  if (l2 === UNRESOLVED)
23766
24154
  return UNRESOLVED;
@@ -23773,30 +24161,30 @@ function evalNode(node, ctx) {
23773
24161
  if (l === UNRESOLVED || r === UNRESOLVED)
23774
24162
  return UNRESOLVED;
23775
24163
  switch (op) {
23776
- case ts22.SyntaxKind.PlusToken:
24164
+ case ts23.SyntaxKind.PlusToken:
23777
24165
  if (typeof l === "string" || typeof r === "string")
23778
24166
  return `${l}${r}`;
23779
24167
  if (typeof l === "number" && typeof r === "number")
23780
24168
  return l + r;
23781
24169
  return UNRESOLVED;
23782
- case ts22.SyntaxKind.MinusToken:
24170
+ case ts23.SyntaxKind.MinusToken:
23783
24171
  return typeof l === "number" && typeof r === "number" ? l - r : UNRESOLVED;
23784
- case ts22.SyntaxKind.AsteriskToken:
24172
+ case ts23.SyntaxKind.AsteriskToken:
23785
24173
  return typeof l === "number" && typeof r === "number" ? l * r : UNRESOLVED;
23786
- case ts22.SyntaxKind.SlashToken:
24174
+ case ts23.SyntaxKind.SlashToken:
23787
24175
  return typeof l === "number" && typeof r === "number" && r !== 0 ? l / r : UNRESOLVED;
23788
- case ts22.SyntaxKind.PercentToken:
24176
+ case ts23.SyntaxKind.PercentToken:
23789
24177
  return typeof l === "number" && typeof r === "number" && r !== 0 ? l % r : UNRESOLVED;
23790
- case ts22.SyntaxKind.EqualsEqualsEqualsToken:
23791
- case ts22.SyntaxKind.EqualsEqualsToken:
24178
+ case ts23.SyntaxKind.EqualsEqualsEqualsToken:
24179
+ case ts23.SyntaxKind.EqualsEqualsToken:
23792
24180
  return l === r;
23793
- case ts22.SyntaxKind.ExclamationEqualsEqualsToken:
23794
- case ts22.SyntaxKind.ExclamationEqualsToken:
24181
+ case ts23.SyntaxKind.ExclamationEqualsEqualsToken:
24182
+ case ts23.SyntaxKind.ExclamationEqualsToken:
23795
24183
  return l !== r;
23796
24184
  }
23797
24185
  return UNRESOLVED;
23798
24186
  }
23799
- if (ts22.isTemplateExpression(node)) {
24187
+ if (ts23.isTemplateExpression(node)) {
23800
24188
  if (node.templateSpans.length === 0)
23801
24189
  return node.head.text;
23802
24190
  let acc = node.head.text;
@@ -23808,13 +24196,13 @@ function evalNode(node, ctx) {
23808
24196
  }
23809
24197
  return acc;
23810
24198
  }
23811
- if (ts22.isNoSubstitutionTemplateLiteral(node))
24199
+ if (ts23.isNoSubstitutionTemplateLiteral(node))
23812
24200
  return node.text;
23813
24201
  return UNRESOLVED;
23814
24202
  }
23815
24203
 
23816
24204
  // src/augment-inherited-props.ts
23817
- import ts23 from "typescript";
24205
+ import ts24 from "typescript";
23818
24206
  function collectContextConsumers(metadata) {
23819
24207
  const constants = metadata.localConstants ?? [];
23820
24208
  const contextDefaults = new Map;
@@ -23846,47 +24234,47 @@ function collectContextConsumers(metadata) {
23846
24234
  }
23847
24235
  function parseUseContextArg(source) {
23848
24236
  const expr = parseSingleExpression(source);
23849
- if (!expr || !ts23.isCallExpression(expr))
24237
+ if (!expr || !ts24.isCallExpression(expr))
23850
24238
  return null;
23851
- if (!ts23.isIdentifier(expr.expression) || expr.expression.text !== "useContext")
24239
+ if (!ts24.isIdentifier(expr.expression) || expr.expression.text !== "useContext")
23852
24240
  return null;
23853
24241
  if (expr.arguments.length !== 1)
23854
24242
  return null;
23855
24243
  const arg = expr.arguments[0];
23856
- return ts23.isIdentifier(arg) ? arg.text : null;
24244
+ return ts24.isIdentifier(arg) ? arg.text : null;
23857
24245
  }
23858
24246
  function parseCreateContextDefault(source) {
23859
24247
  const expr = parseSingleExpression(source);
23860
- if (!expr || !ts23.isCallExpression(expr))
24248
+ if (!expr || !ts24.isCallExpression(expr))
23861
24249
  return null;
23862
24250
  if (expr.arguments.length === 0)
23863
24251
  return null;
23864
24252
  const arg = expr.arguments[0];
23865
- if (ts23.isStringLiteral(arg) || ts23.isNoSubstitutionTemplateLiteral(arg))
24253
+ if (ts24.isStringLiteral(arg) || ts24.isNoSubstitutionTemplateLiteral(arg))
23866
24254
  return arg.text;
23867
- if (ts23.isNumericLiteral(arg))
24255
+ if (ts24.isNumericLiteral(arg))
23868
24256
  return Number(arg.text);
23869
- if (arg.kind === ts23.SyntaxKind.TrueKeyword)
24257
+ if (arg.kind === ts24.SyntaxKind.TrueKeyword)
23870
24258
  return true;
23871
- if (arg.kind === ts23.SyntaxKind.FalseKeyword)
24259
+ if (arg.kind === ts24.SyntaxKind.FalseKeyword)
23872
24260
  return false;
23873
24261
  return null;
23874
24262
  }
23875
24263
  function isObjectLiteralCreateContextDefault(source) {
23876
24264
  const expr = parseSingleExpression(source);
23877
- if (!expr || !ts23.isCallExpression(expr))
24265
+ if (!expr || !ts24.isCallExpression(expr))
23878
24266
  return false;
23879
24267
  if (expr.arguments.length === 0)
23880
24268
  return false;
23881
- return ts23.isObjectLiteralExpression(expr.arguments[0]);
24269
+ return ts24.isObjectLiteralExpression(expr.arguments[0]);
23882
24270
  }
23883
24271
  function parseSingleExpression(source) {
23884
- const sf = ts23.createSourceFile("__ctx.ts", `(${source})`, ts23.ScriptTarget.Latest, false);
24272
+ const sf = ts24.createSourceFile("__ctx.ts", `(${source})`, ts24.ScriptTarget.Latest, false);
23885
24273
  const stmt = sf.statements[0];
23886
- if (!stmt || !ts23.isExpressionStatement(stmt))
24274
+ if (!stmt || !ts24.isExpressionStatement(stmt))
23887
24275
  return null;
23888
24276
  let e = stmt.expression;
23889
- while (ts23.isParenthesizedExpression(e))
24277
+ while (ts24.isParenthesizedExpression(e))
23890
24278
  e = e.expression;
23891
24279
  return e;
23892
24280
  }
@@ -23911,25 +24299,25 @@ function augmentInheritedPropAccesses(ir) {
23911
24299
  const pinCoalesceLiterals = (s) => {
23912
24300
  if (!s || !s.includes(propsObj))
23913
24301
  return;
23914
- const sf = ts23.createSourceFile("__aug.ts", `(${s})`, ts23.ScriptTarget.Latest, false);
24302
+ const sf = ts24.createSourceFile("__aug.ts", `(${s})`, ts24.ScriptTarget.Latest, false);
23915
24303
  const visit3 = (n) => {
23916
- if (ts23.isBinaryExpression(n) && (n.operatorToken.kind === ts23.SyntaxKind.QuestionQuestionToken || n.operatorToken.kind === ts23.SyntaxKind.BarBarToken)) {
24304
+ if (ts24.isBinaryExpression(n) && (n.operatorToken.kind === ts24.SyntaxKind.QuestionQuestionToken || n.operatorToken.kind === ts24.SyntaxKind.BarBarToken)) {
23917
24305
  let left = n.left;
23918
- while (ts23.isParenthesizedExpression(left))
24306
+ while (ts24.isParenthesizedExpression(left))
23919
24307
  left = left.expression;
23920
- if (ts23.isPropertyAccessExpression(left) && ts23.isIdentifier(left.expression) && left.expression.text === propsObj) {
24308
+ if (ts24.isPropertyAccessExpression(left) && ts24.isIdentifier(left.expression) && left.expression.text === propsObj) {
23921
24309
  const name = left.name.text;
23922
24310
  let right = n.right;
23923
- while (ts23.isParenthesizedExpression(right))
24311
+ while (ts24.isParenthesizedExpression(right))
23924
24312
  right = right.expression;
23925
- if (ts23.isPrefixUnaryExpression(right))
24313
+ if (ts24.isPrefixUnaryExpression(right))
23926
24314
  right = right.operand;
23927
- const kind = ts23.isNumericLiteral(right) ? "number" : right.kind === ts23.SyntaxKind.TrueKeyword || right.kind === ts23.SyntaxKind.FalseKeyword ? "boolean" : ts23.isStringLiteralLike(right) ? "string" : null;
24315
+ const kind = ts24.isNumericLiteral(right) ? "number" : right.kind === ts24.SyntaxKind.TrueKeyword || right.kind === ts24.SyntaxKind.FalseKeyword ? "boolean" : ts24.isStringLiteralLike(right) ? "string" : null;
23928
24316
  if (kind && !coalesceLiteralTypes.has(name))
23929
24317
  coalesceLiteralTypes.set(name, kind);
23930
24318
  }
23931
24319
  }
23932
- ts23.forEachChild(n, visit3);
24320
+ ts24.forEachChild(n, visit3);
23933
24321
  };
23934
24322
  visit3(sf);
23935
24323
  };
@@ -24040,33 +24428,33 @@ function augmentInheritedPropAccesses(ir) {
24040
24428
  }
24041
24429
  }
24042
24430
  function parseStaticStringConst(source) {
24043
- const sf = ts23.createSourceFile("__const.ts", `const __x = (${source});`, ts23.ScriptTarget.Latest, false);
24431
+ const sf = ts24.createSourceFile("__const.ts", `const __x = (${source});`, ts24.ScriptTarget.Latest, false);
24044
24432
  const stmt = sf.statements[0];
24045
- if (!stmt || !ts23.isVariableStatement(stmt))
24433
+ if (!stmt || !ts24.isVariableStatement(stmt))
24046
24434
  return null;
24047
24435
  let init = stmt.declarationList.declarations[0]?.initializer;
24048
- while (init && ts23.isParenthesizedExpression(init))
24436
+ while (init && ts24.isParenthesizedExpression(init))
24049
24437
  init = init.expression;
24050
24438
  if (!init)
24051
24439
  return null;
24052
- if (ts23.isStringLiteral(init) || ts23.isNoSubstitutionTemplateLiteral(init)) {
24440
+ if (ts24.isStringLiteral(init) || ts24.isNoSubstitutionTemplateLiteral(init)) {
24053
24441
  return init.text;
24054
24442
  }
24055
24443
  return evalStringArrayJoin(source);
24056
24444
  }
24057
24445
  function evalTemplateOfStringConsts(source, resolved) {
24058
- const sf = ts23.createSourceFile("__const.ts", `const __x = (${source});`, ts23.ScriptTarget.Latest, false);
24446
+ const sf = ts24.createSourceFile("__const.ts", `const __x = (${source});`, ts24.ScriptTarget.Latest, false);
24059
24447
  const stmt = sf.statements[0];
24060
- if (!stmt || !ts23.isVariableStatement(stmt))
24448
+ if (!stmt || !ts24.isVariableStatement(stmt))
24061
24449
  return null;
24062
24450
  let init = stmt.declarationList.declarations[0]?.initializer;
24063
- while (init && ts23.isParenthesizedExpression(init))
24451
+ while (init && ts24.isParenthesizedExpression(init))
24064
24452
  init = init.expression;
24065
- if (!init || !ts23.isTemplateExpression(init))
24453
+ if (!init || !ts24.isTemplateExpression(init))
24066
24454
  return null;
24067
24455
  let out = init.head.text;
24068
24456
  for (const span of init.templateSpans) {
24069
- if (!ts23.isIdentifier(span.expression))
24457
+ if (!ts24.isIdentifier(span.expression))
24070
24458
  return null;
24071
24459
  const value = resolved.get(span.expression.text);
24072
24460
  if (value === undefined)
@@ -24099,30 +24487,30 @@ function lookupStaticRecordLiteral(objectName, key, constants, isShadowed) {
24099
24487
  const constInfo = (constants ?? []).find((c) => c.name === objectName && c.isModule);
24100
24488
  if (constInfo?.value === undefined)
24101
24489
  return null;
24102
- const sf = ts23.createSourceFile("__rec.ts", `(${constInfo.value})`, ts23.ScriptTarget.Latest, true);
24490
+ const sf = ts24.createSourceFile("__rec.ts", `(${constInfo.value})`, ts24.ScriptTarget.Latest, true);
24103
24491
  if (sf.statements.length !== 1)
24104
24492
  return null;
24105
24493
  const stmt = sf.statements[0];
24106
- if (!ts23.isExpressionStatement(stmt))
24494
+ if (!ts24.isExpressionStatement(stmt))
24107
24495
  return null;
24108
24496
  let parsed = stmt.expression;
24109
- while (ts23.isParenthesizedExpression(parsed))
24497
+ while (ts24.isParenthesizedExpression(parsed))
24110
24498
  parsed = parsed.expression;
24111
- if (!ts23.isObjectLiteralExpression(parsed))
24499
+ if (!ts24.isObjectLiteralExpression(parsed))
24112
24500
  return null;
24113
24501
  for (const prop of parsed.properties) {
24114
- if (!ts23.isPropertyAssignment(prop))
24502
+ if (!ts24.isPropertyAssignment(prop))
24115
24503
  continue;
24116
24504
  const name = prop.name;
24117
- const propKey = ts23.isIdentifier(name) || ts23.isStringLiteral(name) || ts23.isNoSubstitutionTemplateLiteral(name) ? name.text : null;
24505
+ const propKey = ts24.isIdentifier(name) || ts24.isStringLiteral(name) || ts24.isNoSubstitutionTemplateLiteral(name) ? name.text : null;
24118
24506
  if (propKey !== key)
24119
24507
  continue;
24120
24508
  let v = prop.initializer;
24121
- while (ts23.isParenthesizedExpression(v))
24509
+ while (ts24.isParenthesizedExpression(v))
24122
24510
  v = v.expression;
24123
- if (ts23.isNumericLiteral(v))
24511
+ if (ts24.isNumericLiteral(v))
24124
24512
  return { kind: "number", text: v.text };
24125
- if (ts23.isStringLiteral(v) || ts23.isNoSubstitutionTemplateLiteral(v)) {
24513
+ if (ts24.isStringLiteral(v) || ts24.isNoSubstitutionTemplateLiteral(v)) {
24126
24514
  return { kind: "string", text: v.text };
24127
24515
  }
24128
24516
  return null;
@@ -24130,28 +24518,28 @@ function lookupStaticRecordLiteral(objectName, key, constants, isShadowed) {
24130
24518
  return null;
24131
24519
  }
24132
24520
  function evalStringArrayJoin(source) {
24133
- const sf = ts23.createSourceFile("__join.ts", `const __x = (${source});`, ts23.ScriptTarget.Latest, false);
24521
+ const sf = ts24.createSourceFile("__join.ts", `const __x = (${source});`, ts24.ScriptTarget.Latest, false);
24134
24522
  const stmt = sf.statements[0];
24135
- if (!stmt || !ts23.isVariableStatement(stmt))
24523
+ if (!stmt || !ts24.isVariableStatement(stmt))
24136
24524
  return null;
24137
24525
  let node = stmt.declarationList.declarations[0]?.initializer;
24138
- while (node && ts23.isParenthesizedExpression(node))
24526
+ while (node && ts24.isParenthesizedExpression(node))
24139
24527
  node = node.expression;
24140
- if (!node || !ts23.isCallExpression(node))
24528
+ if (!node || !ts24.isCallExpression(node))
24141
24529
  return null;
24142
24530
  const callee = node.expression;
24143
- if (!ts23.isPropertyAccessExpression(callee))
24531
+ if (!ts24.isPropertyAccessExpression(callee))
24144
24532
  return null;
24145
24533
  if (callee.name.text !== "join")
24146
24534
  return null;
24147
24535
  let recv = callee.expression;
24148
- while (ts23.isParenthesizedExpression(recv))
24536
+ while (ts24.isParenthesizedExpression(recv))
24149
24537
  recv = recv.expression;
24150
- if (!ts23.isArrayLiteralExpression(recv))
24538
+ if (!ts24.isArrayLiteralExpression(recv))
24151
24539
  return null;
24152
24540
  const parts = [];
24153
24541
  for (const el of recv.elements) {
24154
- if (ts23.isStringLiteral(el) || ts23.isNoSubstitutionTemplateLiteral(el)) {
24542
+ if (ts24.isStringLiteral(el) || ts24.isNoSubstitutionTemplateLiteral(el)) {
24155
24543
  parts.push(el.text);
24156
24544
  } else {
24157
24545
  return null;
@@ -24160,7 +24548,7 @@ function evalStringArrayJoin(source) {
24160
24548
  let sep2 = ",";
24161
24549
  if (node.arguments.length >= 1) {
24162
24550
  const arg = node.arguments[0];
24163
- if (ts23.isStringLiteral(arg) || ts23.isNoSubstitutionTemplateLiteral(arg))
24551
+ if (ts24.isStringLiteral(arg) || ts24.isNoSubstitutionTemplateLiteral(arg))
24164
24552
  sep2 = arg.text;
24165
24553
  else
24166
24554
  return null;
@@ -24168,11 +24556,11 @@ function evalStringArrayJoin(source) {
24168
24556
  return parts.join(sep2);
24169
24557
  }
24170
24558
  function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
24171
- if (!ts23.isElementAccessExpression(val))
24559
+ if (!ts24.isElementAccessExpression(val))
24172
24560
  return null;
24173
24561
  const obj = val.expression;
24174
24562
  const arg = val.argumentExpression;
24175
- if (!ts23.isIdentifier(obj) || !ts23.isIdentifier(arg))
24563
+ if (!ts24.isIdentifier(obj) || !ts24.isIdentifier(arg))
24176
24564
  return null;
24177
24565
  let indexPropName;
24178
24566
  let defaultKey;
@@ -24188,35 +24576,35 @@ function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
24188
24576
  const constInfo = localConstants.find((c) => c.name === obj.text && c.isModule);
24189
24577
  if (constInfo?.value === undefined)
24190
24578
  return null;
24191
- const sf = ts23.createSourceFile("__rec.ts", `(${constInfo.value})`, ts23.ScriptTarget.Latest, true);
24579
+ const sf = ts24.createSourceFile("__rec.ts", `(${constInfo.value})`, ts24.ScriptTarget.Latest, true);
24192
24580
  if (sf.statements.length !== 1)
24193
24581
  return null;
24194
24582
  const stmt = sf.statements[0];
24195
- if (!ts23.isExpressionStatement(stmt))
24583
+ if (!ts24.isExpressionStatement(stmt))
24196
24584
  return null;
24197
24585
  let parsed = stmt.expression;
24198
- while (ts23.isParenthesizedExpression(parsed))
24586
+ while (ts24.isParenthesizedExpression(parsed))
24199
24587
  parsed = parsed.expression;
24200
- if (!ts23.isObjectLiteralExpression(parsed))
24588
+ if (!ts24.isObjectLiteralExpression(parsed))
24201
24589
  return null;
24202
24590
  const entries = [];
24203
24591
  for (const prop of parsed.properties) {
24204
- if (!ts23.isPropertyAssignment(prop))
24592
+ if (!ts24.isPropertyAssignment(prop))
24205
24593
  return null;
24206
24594
  let key;
24207
- if (ts23.isIdentifier(prop.name)) {
24595
+ if (ts24.isIdentifier(prop.name)) {
24208
24596
  key = prop.name.text;
24209
- } else if (ts23.isStringLiteral(prop.name) || ts23.isNoSubstitutionTemplateLiteral(prop.name)) {
24597
+ } else if (ts24.isStringLiteral(prop.name) || ts24.isNoSubstitutionTemplateLiteral(prop.name)) {
24210
24598
  key = prop.name.text;
24211
24599
  } else {
24212
24600
  return null;
24213
24601
  }
24214
24602
  let v = prop.initializer;
24215
- while (ts23.isParenthesizedExpression(v))
24603
+ while (ts24.isParenthesizedExpression(v))
24216
24604
  v = v.expression;
24217
- if (ts23.isNumericLiteral(v)) {
24605
+ if (ts24.isNumericLiteral(v)) {
24218
24606
  entries.push({ key, value: { kind: "number", text: v.text } });
24219
- } else if (ts23.isStringLiteral(v) || ts23.isNoSubstitutionTemplateLiteral(v)) {
24607
+ } else if (ts24.isStringLiteral(v) || ts24.isNoSubstitutionTemplateLiteral(v)) {
24220
24608
  entries.push({ key, value: { kind: "string", text: v.text } });
24221
24609
  } else {
24222
24610
  return null;
@@ -24577,31 +24965,54 @@ function walkNode2(node, meta, bindings, matchers, errors, seen) {
24577
24965
  function mergeTemplateImports(lines) {
24578
24966
  const result = [];
24579
24967
  const valueIdx = new Map;
24968
+ const valueDefault = new Map;
24580
24969
  const valueNames = new Map;
24581
24970
  const typeIdx = new Map;
24582
24971
  const typeNames = new Map;
24583
24972
  const seenOther = new Set;
24584
- const fold = (src, rawNames, idx, names, render) => {
24585
- if (!idx.has(src)) {
24586
- idx.set(src, result.length);
24587
- names.set(src, new Set);
24973
+ const foldType = (src, rawNames) => {
24974
+ if (!typeIdx.has(src)) {
24975
+ typeIdx.set(src, result.length);
24976
+ typeNames.set(src, new Set);
24588
24977
  result.push("");
24589
24978
  }
24590
- const set = names.get(src);
24979
+ const set = typeNames.get(src);
24591
24980
  for (const n of rawNames.split(",").map((s) => s.trim()).filter(Boolean))
24592
24981
  set.add(n);
24593
- result[idx.get(src)] = render(src, set);
24982
+ result[typeIdx.get(src)] = `import type { ${[...set].join(", ")} } from '${src}'`;
24983
+ };
24984
+ const foldValue = (src, defaultName, rawNames) => {
24985
+ if (!valueIdx.has(src)) {
24986
+ valueIdx.set(src, result.length);
24987
+ valueNames.set(src, new Set);
24988
+ result.push("");
24989
+ }
24990
+ if (defaultName && !valueDefault.has(src))
24991
+ valueDefault.set(src, defaultName);
24992
+ if (rawNames) {
24993
+ const set = valueNames.get(src);
24994
+ for (const n of rawNames.split(",").map((s) => s.trim()).filter(Boolean))
24995
+ set.add(n);
24996
+ }
24997
+ result[valueIdx.get(src)] = renderUsedImportLines(src, valueDefault.get(src) ?? null, null, [...valueNames.get(src)]).join(`
24998
+ `);
24594
24999
  };
24595
25000
  for (const raw of lines) {
24596
25001
  const line = raw.trim();
24597
25002
  if (!line)
24598
25003
  continue;
24599
25004
  const typeMatch = line.match(/^import\s+type\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]\s*;?$/);
24600
- const valueMatch = line.match(/^import\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]\s*;?$/);
24601
- if (valueMatch) {
24602
- fold(valueMatch[2], valueMatch[1], valueIdx, valueNames, (s, n) => `import { ${[...n].join(", ")} } from '${s}'`);
24603
- } else if (typeMatch) {
24604
- fold(typeMatch[2], typeMatch[1], typeIdx, typeNames, (s, n) => `import type { ${[...n].join(", ")} } from '${s}'`);
25005
+ const namedMatch = line.match(/^import\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]\s*;?$/);
25006
+ const defaultNamedMatch = line.match(/^import\s+([A-Za-z_$][\w$]*)\s*,\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]\s*;?$/);
25007
+ const defaultOnlyMatch = line.match(/^import\s+([A-Za-z_$][\w$]*)\s*from\s*['"]([^'"]+)['"]\s*;?$/);
25008
+ if (typeMatch) {
25009
+ foldType(typeMatch[2], typeMatch[1]);
25010
+ } else if (namedMatch) {
25011
+ foldValue(namedMatch[2], null, namedMatch[1]);
25012
+ } else if (defaultNamedMatch) {
25013
+ foldValue(defaultNamedMatch[3], defaultNamedMatch[1], defaultNamedMatch[2]);
25014
+ } else if (defaultOnlyMatch) {
25015
+ foldValue(defaultOnlyMatch[2], defaultOnlyMatch[1], null);
24605
25016
  } else if (!seenOther.has(line)) {
24606
25017
  seenOther.add(line);
24607
25018
  result.push(line);
@@ -24643,13 +25054,13 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
24643
25054
  if (entries.some((e) => e.componentIR.metadata.isClientComponent)) {
24644
25055
  const topLevelNames = new Set;
24645
25056
  {
24646
- const sf = ts24.createSourceFile(filePath, source, ts24.ScriptTarget.Latest, true, ts24.ScriptKind.TSX);
25057
+ const sf = ts25.createSourceFile(filePath, source, ts25.ScriptTarget.Latest, true, ts25.ScriptKind.TSX);
24647
25058
  for (const stmt of sf.statements) {
24648
- if (ts24.isFunctionDeclaration(stmt) && stmt.name)
25059
+ if (ts25.isFunctionDeclaration(stmt) && stmt.name)
24649
25060
  topLevelNames.add(stmt.name.text);
24650
- else if (ts24.isVariableStatement(stmt)) {
25061
+ else if (ts25.isVariableStatement(stmt)) {
24651
25062
  for (const d of stmt.declarationList.declarations) {
24652
- if (ts24.isIdentifier(d.name))
25063
+ if (ts25.isIdentifier(d.name))
24653
25064
  topLevelNames.add(d.name.text);
24654
25065
  }
24655
25066
  }
@@ -24708,7 +25119,7 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
24708
25119
  const moduleStatementSeen = new Set;
24709
25120
  const moduleStatementsOrdered = [];
24710
25121
  const collectModuleStatements = (block) => {
24711
- const sf = ts24.createSourceFile("__bf_module_decls.tsx", block, ts24.ScriptTarget.Latest, false, ts24.ScriptKind.TSX);
25122
+ const sf = ts25.createSourceFile("__bf_module_decls.tsx", block, ts25.ScriptTarget.Latest, false, ts25.ScriptKind.TSX);
24712
25123
  for (const stmt of sf.statements) {
24713
25124
  const text = stmt.getText(sf);
24714
25125
  if (moduleStatementSeen.has(text))
@@ -24797,32 +25208,9 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
24797
25208
  }
24798
25209
  const clientJsOutputs2 = allOutputs.map((o) => o.clientJs).filter(Boolean);
24799
25210
  if (clientJsOutputs2.length > 0) {
24800
- const importsBySource = new Map;
24801
- const otherImports = [];
24802
- const allCode = [];
24803
- for (const js of clientJsOutputs2) {
24804
- for (const line of js.split(`
24805
- `)) {
24806
- if (line.startsWith("import ")) {
24807
- const match = line.match(/^import \{ ([^}]+) \} from ['"]([^'"]+)['"]$/);
24808
- if (match) {
24809
- const source2 = match[2];
24810
- if (!importsBySource.has(source2))
24811
- importsBySource.set(source2, new Set);
24812
- for (const n of match[1].split(",").map((n2) => n2.trim()))
24813
- importsBySource.get(source2).add(n);
24814
- } else if (!otherImports.includes(line)) {
24815
- otherImports.push(line);
24816
- }
24817
- }
24818
- }
24819
- allCode.push(js.replace(/^import .+\n/gm, "").trim());
24820
- }
24821
- const mergedClientImports = [...importsBySource].map(([src, names]) => `import { ${[...names].sort().join(", ")} } from '${src}'`);
24822
25211
  files.push({
24823
25212
  path: filePath.replace(/\.tsx?$/, ".client.js"),
24824
- content: [...mergedClientImports, ...otherImports, "", ...allCode.filter(Boolean)].join(`
24825
- `),
25213
+ content: mergeCompiledClientJsImports(clientJsOutputs2),
24826
25214
  type: "clientJs"
24827
25215
  });
24828
25216
  }
@@ -24893,53 +25281,9 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
24893
25281
  }
24894
25282
  const clientJsOutputs = allOutputs.map((o) => o.clientJs).filter(Boolean);
24895
25283
  if (clientJsOutputs.length > 0) {
24896
- const importsBySource = new Map;
24897
- const otherImports = [];
24898
- const allCode = [];
24899
- for (const js of clientJsOutputs) {
24900
- const lines = js.split(`
24901
- `);
24902
- const codeLines = [];
24903
- for (const line of lines) {
24904
- if (line.startsWith("import ")) {
24905
- const match = line.match(/^import \{ ([^}]+) \} from ['"]([^'"]+)['"]$/);
24906
- if (match) {
24907
- const names = match[1].split(",").map((n) => n.trim());
24908
- const source2 = match[2];
24909
- if (!importsBySource.has(source2)) {
24910
- importsBySource.set(source2, new Set);
24911
- }
24912
- const set = importsBySource.get(source2);
24913
- for (const name of names) {
24914
- set.add(name);
24915
- }
24916
- } else {
24917
- if (!otherImports.includes(line)) {
24918
- otherImports.push(line);
24919
- }
24920
- }
24921
- } else {
24922
- codeLines.push(line);
24923
- }
24924
- }
24925
- allCode.push(codeLines.join(`
24926
- `).trim());
24927
- }
24928
- const mergedImports2 = [];
24929
- for (const [source2, names] of importsBySource) {
24930
- const sortedNames = [...names].sort();
24931
- mergedImports2.push(`import { ${sortedNames.join(", ")} } from '${source2}'`);
24932
- }
24933
- const combinedClientJs = [
24934
- ...mergedImports2,
24935
- ...otherImports,
24936
- "",
24937
- ...allCode.filter(Boolean)
24938
- ].join(`
24939
- `);
24940
25284
  files.push({
24941
25285
  path: filePath.replace(/\.tsx?$/, ".client.js"),
24942
- content: combinedClientJs,
25286
+ content: mergeCompiledClientJsImports(clientJsOutputs),
24943
25287
  type: "clientJs"
24944
25288
  });
24945
25289
  }
@@ -25012,10 +25356,24 @@ function compileJSX(source, filePath, options) {
25012
25356
  externalImportLines.push(`import '${imp.source}'`);
25013
25357
  continue;
25014
25358
  }
25015
- const used = imp.specifiers.filter((s2) => !s2.isDefault && !s2.isNamespace && !s2.isTypeOnly && isUsedAsValue(s2.alias || s2.name)).map((s2) => s2.alias ? `${s2.name} as ${s2.alias}` : s2.name);
25016
- if (used.length > 0) {
25017
- externalImportLines.push(`import { ${used.join(", ")} } from '${imp.source}'`);
25359
+ const usedNamed = [];
25360
+ let usedDefault = null;
25361
+ let usedNamespace = null;
25362
+ for (const s2 of imp.specifiers) {
25363
+ if (s2.isTypeOnly)
25364
+ continue;
25365
+ const localName = s2.alias || s2.name;
25366
+ if (!isUsedAsValue(localName))
25367
+ continue;
25368
+ if (s2.isDefault) {
25369
+ usedDefault = localName;
25370
+ } else if (s2.isNamespace) {
25371
+ usedNamespace = localName;
25372
+ } else {
25373
+ usedNamed.push(s2.alias ? `${s2.name} as ${s2.alias}` : s2.name);
25374
+ }
25018
25375
  }
25376
+ externalImportLines.push(...renderUsedImportLines(imp.source, usedDefault, usedNamespace, usedNamed));
25019
25377
  }
25020
25378
  const allImports = [runtimeImportLine, ...externalImportLines].filter(Boolean).join(`
25021
25379
  `);
@@ -25151,7 +25509,7 @@ function compileJSX(source, filePath, options) {
25151
25509
  return { files, errors };
25152
25510
  }
25153
25511
  // src/shared-program.ts
25154
- import ts25 from "typescript";
25512
+ import ts26 from "typescript";
25155
25513
  function commonParent(paths) {
25156
25514
  if (paths.length === 0)
25157
25515
  return process.cwd();
@@ -25172,10 +25530,10 @@ function commonParent(paths) {
25172
25530
  function createProgramForCorpus(files, options = {}) {
25173
25531
  const baseUrl = options.baseUrl ?? commonParent(files);
25174
25532
  const compilerOptions = {
25175
- target: ts25.ScriptTarget.Latest,
25176
- module: ts25.ModuleKind.ESNext,
25177
- moduleResolution: ts25.ModuleResolutionKind.Bundler,
25178
- jsx: ts25.JsxEmit.ReactJSX,
25533
+ target: ts26.ScriptTarget.Latest,
25534
+ module: ts26.ModuleKind.ESNext,
25535
+ moduleResolution: ts26.ModuleResolutionKind.Bundler,
25536
+ jsx: ts26.JsxEmit.ReactJSX,
25179
25537
  strict: true,
25180
25538
  skipLibCheck: true,
25181
25539
  noEmit: true,
@@ -25185,7 +25543,7 @@ function createProgramForCorpus(files, options = {}) {
25185
25543
  ...options.compilerOptions
25186
25544
  };
25187
25545
  const absolute = files.map((f) => path_default.resolve(f));
25188
- return ts25.createProgram(absolute, compilerOptions, undefined, options.oldProgram);
25546
+ return ts26.createProgram(absolute, compilerOptions, undefined, options.oldProgram);
25189
25547
  }
25190
25548
  // src/adapters/interface.ts
25191
25549
  class BaseAdapter {
@@ -25469,7 +25827,7 @@ class JsxAdapter extends BaseAdapter {
25469
25827
  }
25470
25828
 
25471
25829
  // src/adapters/template-imports.ts
25472
- import ts26 from "typescript";
25830
+ import ts27 from "typescript";
25473
25831
  var CLIENT_PACKAGE_SOURCES = new Set([
25474
25832
  "@barefootjs/client",
25475
25833
  "@barefootjs/client/runtime"
@@ -25519,18 +25877,18 @@ function specKey(s) {
25519
25877
  function rewriteDynamicImportsInSource(sourceText, rewriteRelative) {
25520
25878
  if (!sourceText.includes("import"))
25521
25879
  return sourceText;
25522
- const sf = ts26.createSourceFile("bf-template-fragment.tsx", sourceText, ts26.ScriptTarget.Latest, false, ts26.ScriptKind.TSX);
25880
+ const sf = ts27.createSourceFile("bf-template-fragment.tsx", sourceText, ts27.ScriptTarget.Latest, false, ts27.ScriptKind.TSX);
25523
25881
  const edits = [];
25524
25882
  const visit3 = (node) => {
25525
- if (ts26.isCallExpression(node) && node.expression.kind === ts26.SyntaxKind.ImportKeyword && node.arguments.length > 0 && ts26.isStringLiteralLike(node.arguments[0])) {
25883
+ if (ts27.isCallExpression(node) && node.expression.kind === ts27.SyntaxKind.ImportKeyword && node.arguments.length > 0 && ts27.isStringLiteralLike(node.arguments[0])) {
25526
25884
  collect(node.arguments[0]);
25527
25885
  }
25528
- if (ts26.isImportTypeNode(node) && ts26.isLiteralTypeNode(node.argument)) {
25886
+ if (ts27.isImportTypeNode(node) && ts27.isLiteralTypeNode(node.argument)) {
25529
25887
  const literal = node.argument.literal;
25530
- if (ts26.isStringLiteralLike(literal))
25888
+ if (ts27.isStringLiteralLike(literal))
25531
25889
  collect(literal);
25532
25890
  }
25533
- ts26.forEachChild(node, visit3);
25891
+ ts27.forEachChild(node, visit3);
25534
25892
  };
25535
25893
  const collect = (literal) => {
25536
25894
  const specifier = literal.text;
@@ -25545,7 +25903,7 @@ function rewriteDynamicImportsInSource(sourceText, rewriteRelative) {
25545
25903
  text: `'${next}'`
25546
25904
  });
25547
25905
  };
25548
- ts26.forEachChild(sf, visit3);
25906
+ ts27.forEachChild(sf, visit3);
25549
25907
  if (edits.length === 0)
25550
25908
  return sourceText;
25551
25909
  let out = sourceText;
@@ -26310,7 +26668,7 @@ function dangerousInnerHtmlDiagnostic(expr, loc, reason) {
26310
26668
  };
26311
26669
  }
26312
26670
  // src/combine-client-js.ts
26313
- import ts27 from "typescript";
26671
+ import ts28 from "typescript";
26314
26672
  var CHILD_PLACEHOLDER_RE = /import '\/\* @bf-child:(\w+) \*\/'/g;
26315
26673
  function combineParentChildClientJs(files) {
26316
26674
  const result = new Map;
@@ -26367,10 +26725,10 @@ function combineParentChildClientJs(files) {
26367
26725
  return result;
26368
26726
  }
26369
26727
  function parseAndMerge(content, importsBySource, otherImports, codeSections) {
26370
- const sourceFile = ts27.createSourceFile("combine.js", content, ts27.ScriptTarget.Latest, false, ts27.ScriptKind.JS);
26728
+ const sourceFile = ts28.createSourceFile("combine.js", content, ts28.ScriptTarget.Latest, false, ts28.ScriptKind.JS);
26371
26729
  const importSpans = [];
26372
26730
  for (const stmt of sourceFile.statements) {
26373
- if (!ts27.isImportDeclaration(stmt))
26731
+ if (!ts28.isImportDeclaration(stmt))
26374
26732
  continue;
26375
26733
  const start = stmt.getStart(sourceFile);
26376
26734
  const end = stmt.getEnd();
@@ -26380,8 +26738,8 @@ function parseAndMerge(content, importsBySource, otherImports, codeSections) {
26380
26738
  continue;
26381
26739
  const clause = stmt.importClause;
26382
26740
  const bindings = clause?.namedBindings;
26383
- const specifier = ts27.isStringLiteral(stmt.moduleSpecifier) ? stmt.moduleSpecifier.text : "";
26384
- if (clause && !clause.name && bindings && ts27.isNamedImports(bindings)) {
26741
+ const specifier = ts28.isStringLiteral(stmt.moduleSpecifier) ? stmt.moduleSpecifier.text : "";
26742
+ if (clause && !clause.name && bindings && ts28.isNamedImports(bindings)) {
26385
26743
  if (!importsBySource.has(specifier)) {
26386
26744
  importsBySource.set(specifier, new Set);
26387
26745
  }
@@ -26548,7 +26906,7 @@ function escapeRe(s) {
26548
26906
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
26549
26907
  }
26550
26908
  // src/debug.ts
26551
- import ts28 from "typescript";
26909
+ import ts29 from "typescript";
26552
26910
  function buildComponentGraph(source, filePath, componentName) {
26553
26911
  const ctx = analyzeComponent(source, filePath, componentName);
26554
26912
  if (!ctx.jsxReturn) {
@@ -27836,7 +28194,7 @@ function truncateExpr(expr, max = 40) {
27836
28194
  function exprReadsPropMember(expr, propsObjectName) {
27837
28195
  let sf;
27838
28196
  try {
27839
- sf = ts28.createSourceFile("__attr.tsx", `(${expr})`, ts28.ScriptTarget.Latest, true, ts28.ScriptKind.TSX);
28197
+ sf = ts29.createSourceFile("__attr.tsx", `(${expr})`, ts29.ScriptTarget.Latest, true, ts29.ScriptKind.TSX);
27840
28198
  } catch {
27841
28199
  return false;
27842
28200
  }
@@ -27844,11 +28202,11 @@ function exprReadsPropMember(expr, propsObjectName) {
27844
28202
  const visit3 = (n) => {
27845
28203
  if (found)
27846
28204
  return;
27847
- if (ts28.isPropertyAccessExpression(n) && ts28.isIdentifier(n.expression) && n.expression.text === propsObjectName && n.name.text !== "children") {
28205
+ if (ts29.isPropertyAccessExpression(n) && ts29.isIdentifier(n.expression) && n.expression.text === propsObjectName && n.name.text !== "children") {
27848
28206
  found = true;
27849
28207
  return;
27850
28208
  }
27851
- ts28.forEachChild(n, visit3);
28209
+ ts29.forEachChild(n, visit3);
27852
28210
  };
27853
28211
  visit3(sf);
27854
28212
  return found;
@@ -27918,7 +28276,7 @@ function findSourceFile2(meta) {
27918
28276
  return null;
27919
28277
  }
27920
28278
  // src/profiler.ts
27921
- import ts29 from "typescript";
28279
+ import ts30 from "typescript";
27922
28280
  var PROFILE_SCHEMA_VERSION = 1;
27923
28281
  var DEFAULT_FANOUT_THRESHOLD = 8;
27924
28282
  function buildStaticBudget(source, filePath, componentName, options = {}) {
@@ -28188,15 +28546,15 @@ function joinProfilerEvents(events, index) {
28188
28546
  return { joined, unattributed, diagnostics };
28189
28547
  }
28190
28548
  function findUninstrumentedEffects(source, filePath, instrumentedLines) {
28191
- const sf = ts29.createSourceFile(filePath, source, ts29.ScriptTarget.Latest, true, ts29.ScriptKind.TSX);
28549
+ const sf = ts30.createSourceFile(filePath, source, ts30.ScriptTarget.Latest, true, ts30.ScriptKind.TSX);
28192
28550
  const out = [];
28193
28551
  const visit3 = (node) => {
28194
- if (ts29.isCallExpression(node) && ts29.isIdentifier(node.expression) && node.expression.text === "createEffect") {
28552
+ if (ts30.isCallExpression(node) && ts30.isIdentifier(node.expression) && node.expression.text === "createEffect") {
28195
28553
  const line = sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
28196
28554
  if (!instrumentedLines.has(line))
28197
28555
  out.push({ file: filePath, line });
28198
28556
  }
28199
- ts29.forEachChild(node, visit3);
28557
+ ts30.forEachChild(node, visit3);
28200
28558
  };
28201
28559
  visit3(sf);
28202
28560
  out.sort((a, b) => a.line - b.line);
@@ -28504,13 +28862,13 @@ function assessBatchSafety(args) {
28504
28862
  const signalGetters = new Set(args.graph.signals.map((s) => s.name));
28505
28863
  let sf;
28506
28864
  try {
28507
- sf = ts29.createSourceFile("__h.ts", `const __h = ${args.handler}`, ts29.ScriptTarget.Latest, true);
28865
+ sf = ts30.createSourceFile("__h.ts", `const __h = ${args.handler}`, ts30.ScriptTarget.Latest, true);
28508
28866
  } catch {
28509
28867
  return "unverified";
28510
28868
  }
28511
28869
  const calls = [];
28512
28870
  const visit3 = (node) => {
28513
- if (ts29.isCallExpression(node) && ts29.isIdentifier(node.expression)) {
28871
+ if (ts30.isCallExpression(node) && ts30.isIdentifier(node.expression)) {
28514
28872
  const name = node.expression.text;
28515
28873
  if (setters.has(name))
28516
28874
  calls.push({ pos: node.getStart(sf), kind: "write" });
@@ -28519,7 +28877,7 @@ function assessBatchSafety(args) {
28519
28877
  else if (!signalGetters.has(name) && !memoNames.has(name))
28520
28878
  calls.push({ pos: node.getStart(sf), kind: "risky" });
28521
28879
  }
28522
- ts29.forEachChild(node, visit3);
28880
+ ts30.forEachChild(node, visit3);
28523
28881
  };
28524
28882
  visit3(sf);
28525
28883
  calls.sort((a, b) => a.pos - b.pos);
@@ -29163,6 +29521,7 @@ export {
29163
29521
  sortComparatorFromArrow,
29164
29522
  serializeParsedExpr,
29165
29523
  searchParamsLocalNames,
29524
+ scanComponentFile,
29166
29525
  rewriteImportsForTemplate,
29167
29526
  rewriteDynamicImportsInSource,
29168
29527
  resolveStaticLoopSource,