@barefootjs/vite 0.31.3 → 0.31.5

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.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { mkdir as mkdir2, readFile as readFile2, rm, writeFile as writeFile2 } f
3
3
  import { relative as relative2, resolve as resolve7, sep as sep3 } from "node:path";
4
4
 
5
5
  // ../jsx/src/compiler.ts
6
- import ts23 from "typescript";
6
+ import ts24 from "typescript";
7
7
 
8
8
  // ../jsx/src/analyzer.ts
9
9
  import ts9 from "typescript";
@@ -1655,6 +1655,24 @@ function templatePartsToJsExpr(parts, opts) {
1655
1655
  return result;
1656
1656
  }
1657
1657
 
1658
+ // ../jsx/src/identifier-pattern.ts
1659
+ function withUnicodeFlag(flags) {
1660
+ return flags.includes("u") ? flags : `${flags}u`;
1661
+ }
1662
+ function escapeIdentifierForRegex(name) {
1663
+ return name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1664
+ }
1665
+ var ID_BOUNDARY_BEFORE = "(?<![\\p{ID_Continue}$])";
1666
+ var ID_BOUNDARY_AFTER = "(?![\\p{ID_Continue}$])";
1667
+ function identifierPattern(name, flags = "") {
1668
+ const esc = escapeIdentifierForRegex(name);
1669
+ return new RegExp(`${ID_BOUNDARY_BEFORE}${esc}${ID_BOUNDARY_AFTER}`, withUnicodeFlag(flags));
1670
+ }
1671
+ function identifierCallPattern(name, flags = "") {
1672
+ const esc = escapeIdentifierForRegex(name);
1673
+ return new RegExp(`${ID_BOUNDARY_BEFORE}${esc}\\s*\\(`, withUnicodeFlag(flags));
1674
+ }
1675
+
1658
1676
  // ../jsx/src/scanner/js-scanner.ts
1659
1677
  import ts2 from "typescript";
1660
1678
  function* iterateJsTokens(text, start = 0, end = text.length) {
@@ -2227,9 +2245,6 @@ function inferDefaultValue(type) {
2227
2245
  return "{}";
2228
2246
  return "undefined";
2229
2247
  }
2230
- function escapeRegExp(s) {
2231
- return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2232
- }
2233
2248
  function freeIdsFromRefs(refs) {
2234
2249
  const out = new Set;
2235
2250
  if (!refs)
@@ -2357,16 +2372,16 @@ function wrapLoopParamAsAccessor(expr, paramName, bindings) {
2357
2372
  if (bindings && bindings.length > 0) {
2358
2373
  return rewriteLoopBindingRefs(expr, bindings, "__bfItem()");
2359
2374
  }
2360
- const re = new RegExp(`\\b${escapeRegExp(paramName)}\\b(?!\\s*\\()(?!-)`, "g");
2361
- return replaceInExprContexts(expr, re, `${paramName}()`);
2375
+ const re = new RegExp(`${ID_BOUNDARY_BEFORE}${escapeIdentifierForRegex(paramName)}(?!\\s*\\()(?!-)${ID_BOUNDARY_AFTER}`, "gu");
2376
+ return replaceInExprContexts(expr, re, () => `${paramName}()`);
2362
2377
  }
2363
2378
  function rewriteLoopBindingRefs(expr, bindings, accessor) {
2364
2379
  const byName = new Map;
2365
2380
  for (const b of bindings)
2366
2381
  byName.set(b.name, b);
2367
2382
  const preprocessed = expandShorthandBindings(expr, new Set(byName.keys()));
2368
- const alt = bindings.map((b) => escapeRegExp(b.name)).join("|");
2369
- const re = new RegExp(`\\b(${alt})\\b`, "g");
2383
+ const alt = bindings.map((b) => escapeIdentifierForRegex(b.name)).join("|");
2384
+ const re = new RegExp(`${ID_BOUNDARY_BEFORE}(${alt})${ID_BOUNDARY_AFTER}`, "gu");
2370
2385
  return replaceInExprContexts(preprocessed, re, (_m, name) => renderLoopBindingAccess(byName.get(name), accessor));
2371
2386
  }
2372
2387
  function expandShorthandBindings(expr, bindingNames) {
@@ -2633,7 +2648,7 @@ function stopAt(...kinds) {
2633
2648
 
2634
2649
  // ../jsx/src/ir-to-client-js/csr-substitute.ts
2635
2650
  import ts4 from "typescript";
2636
- function csrSubstitute(value, env) {
2651
+ function csrSubstitute(value, env, enclosingScope) {
2637
2652
  if (!value || value.trim().length === 0) {
2638
2653
  return { rewritten: value, freeIdentifiers: new Set };
2639
2654
  }
@@ -2641,7 +2656,7 @@ function csrSubstitute(value, env) {
2641
2656
  let current = value;
2642
2657
  let lastFreeIdentifiers = new Set;
2643
2658
  for (let i = 0;i < maxIter; i++) {
2644
- const step = csrSubstituteOnce(current, env);
2659
+ const step = csrSubstituteOnce(current, env, enclosingScope);
2645
2660
  lastFreeIdentifiers = step.freeIdentifiers;
2646
2661
  if (step.rewritten === current)
2647
2662
  break;
@@ -2649,7 +2664,7 @@ function csrSubstitute(value, env) {
2649
2664
  }
2650
2665
  return { rewritten: current, freeIdentifiers: lastFreeIdentifiers };
2651
2666
  }
2652
- function csrSubstituteOnce(value, env) {
2667
+ function csrSubstituteOnce(value, env, enclosingScope) {
2653
2668
  if (!value || value.trim().length === 0) {
2654
2669
  return { rewritten: value, freeIdentifiers: new Set };
2655
2670
  }
@@ -2667,7 +2682,7 @@ function csrSubstituteOnce(value, env) {
2667
2682
  if (boundStack[i].has(name))
2668
2683
  return true;
2669
2684
  }
2670
- return false;
2685
+ return enclosingScope?.isBound(name) ?? false;
2671
2686
  };
2672
2687
  const recordSubstitution = (start, end, sub) => {
2673
2688
  splices.push({ start: start - OFFSET, end: end - OFFSET, text: `(${sub.replacement})` });
@@ -2852,6 +2867,83 @@ function derivesScopeFromSlot(comp) {
2852
2867
  return comp.slotId != null && comp.loopItemRoot !== true;
2853
2868
  }
2854
2869
 
2870
+ // ../jsx/src/scope/binding-scope.ts
2871
+ class BindingScope {
2872
+ frames;
2873
+ static EMPTY = new BindingScope([]);
2874
+ constructor(frames) {
2875
+ this.frames = frames;
2876
+ }
2877
+ enterLoopRow(loop) {
2878
+ const bindings = new Map;
2879
+ if (loop.paramBindings && loop.paramBindings.length > 0) {
2880
+ for (const b of loop.paramBindings)
2881
+ bindings.set(b.name, { source: "destructure" });
2882
+ } else {
2883
+ bindings.set(loop.param, { source: "item" });
2884
+ }
2885
+ if (loop.index != null)
2886
+ bindings.set(loop.index, { source: "index" });
2887
+ for (const name of loop.preamble?.declaredNames ?? [])
2888
+ bindings.set(name, { source: "preamble" });
2889
+ const frame = { kind: "loop-row", bindings };
2890
+ return new BindingScope([frame, ...this.frames]);
2891
+ }
2892
+ enterCallback(params) {
2893
+ const bindings = new Map;
2894
+ for (const name of params)
2895
+ bindings.set(name, { source: "param" });
2896
+ const frame = { kind: "callback", bindings };
2897
+ return new BindingScope([frame, ...this.frames]);
2898
+ }
2899
+ isBound(name) {
2900
+ for (const frame of this.frames) {
2901
+ if (frame.bindings.has(name))
2902
+ return true;
2903
+ }
2904
+ return false;
2905
+ }
2906
+ lookup(name) {
2907
+ for (let depth = 0;depth < this.frames.length; depth++) {
2908
+ const frame = this.frames[depth];
2909
+ const binding = frame.bindings.get(name);
2910
+ if (binding)
2911
+ return { depth, frame, binding };
2912
+ }
2913
+ return null;
2914
+ }
2915
+ boundNames() {
2916
+ if (this.boundNamesCache)
2917
+ return this.boundNamesCache;
2918
+ const names = new Set;
2919
+ for (const frame of this.frames) {
2920
+ for (const name of frame.bindings.keys())
2921
+ names.add(name);
2922
+ }
2923
+ this.boundNamesCache = names;
2924
+ return names;
2925
+ }
2926
+ boundNamesCache;
2927
+ valueBoundNamesCache;
2928
+ valueBoundNames() {
2929
+ if (this.valueBoundNamesCache)
2930
+ return this.valueBoundNamesCache;
2931
+ const names = new Set;
2932
+ for (const frame of this.frames) {
2933
+ for (const [name, binding] of frame.bindings) {
2934
+ if (binding.source === "item" || binding.source === "index" || binding.source === "destructure") {
2935
+ names.add(name);
2936
+ }
2937
+ }
2938
+ }
2939
+ this.valueBoundNamesCache = names;
2940
+ return names;
2941
+ }
2942
+ asShadowPredicate() {
2943
+ return (name) => this.isBound(name);
2944
+ }
2945
+ }
2946
+
2855
2947
  // ../jsx/src/ir-to-client-js/html-template.ts
2856
2948
  function createStringProtector() {
2857
2949
  const strings = [];
@@ -4077,7 +4169,7 @@ function generateCsrTemplateWithOpts(node, opts) {
4077
4169
  const source = templateExpr ?? expr;
4078
4170
  if (!source)
4079
4171
  return source;
4080
- const { rewritten, freeIdentifiers: freeIdentifiers2 } = csrSubstitute(source, env);
4172
+ const { rewritten, freeIdentifiers: freeIdentifiers2 } = csrSubstitute(source, env, opts.scope);
4081
4173
  if (unsafeLocalNames && unsafeLocalNames.size > 0 && setIntersects(freeIdentifiers2, unsafeLocalNames)) {
4082
4174
  return UNSAFE_TEMPLATE_EXPR;
4083
4175
  }
@@ -4219,15 +4311,8 @@ function generateCsrTemplateWithOpts(node, opts) {
4219
4311
  return `\${renderChild('${nameForRegistryRef(node.name)}', ${propsExpr}${keyArg || (slotArg ? ", undefined" : "")}${slotArg})}`;
4220
4312
  }
4221
4313
  case "loop": {
4222
- const boundHere = new Set(opts.loopBoundNames ?? []);
4223
- if (node.paramBindings && node.paramBindings.length > 0) {
4224
- for (const b of node.paramBindings)
4225
- boundHere.add(b.name);
4226
- } else if (!node.param.startsWith("[") && !node.param.startsWith("{")) {
4227
- boundHere.add(node.param);
4228
- }
4229
- if (node.index)
4230
- boundHere.add(node.index);
4314
+ const childScope = (opts.scope ?? BindingScope.EMPTY).enterLoopRow(node);
4315
+ const boundHere = childScope.boundNames();
4231
4316
  const childEnv = {
4232
4317
  ...env,
4233
4318
  substitutions: new Map([...env.substitutions].filter(([name]) => !boundHere.has(name)))
@@ -4236,7 +4321,7 @@ function generateCsrTemplateWithOpts(node, opts) {
4236
4321
  ...opts,
4237
4322
  loopDepth: loopDepth + 1,
4238
4323
  inHoistedChildren: false,
4239
- loopBoundNames: boundHere,
4324
+ scope: childScope,
4240
4325
  csrEnv: childEnv
4241
4326
  });
4242
4327
  let childTemplate = node.children.map(recurseInLoopBody).join("");
@@ -8576,7 +8661,7 @@ function validateObjectFactoryDestructure(ctx, pattern, callee, loc) {
8576
8661
  }
8577
8662
 
8578
8663
  // ../jsx/src/jsx-to-ir.ts
8579
- import ts12 from "typescript";
8664
+ import ts13 from "typescript";
8580
8665
 
8581
8666
  // ../jsx/src/types.ts
8582
8667
  var SCOPE_FORBIDDEN = {
@@ -8675,6 +8760,7 @@ function pickAttrMetaFromIR(src) {
8675
8760
  }
8676
8761
 
8677
8762
  // ../jsx/src/module-exports.ts
8763
+ import ts10 from "typescript";
8678
8764
  function generateModuleExports(ir, extraInlineExported = new Set, rewriteRelativeImport, options) {
8679
8765
  const lines = [];
8680
8766
  for (const constant of options?.skipValueDeclarations ? [] : ir.metadata.localConstants) {
@@ -8754,7 +8840,7 @@ function findReachableNames(primaryRefs, declarations) {
8754
8840
  const reachable = new Set;
8755
8841
  const queue = [];
8756
8842
  for (const name of allNames) {
8757
- if (new RegExp(`\\b${name}\\b`).test(primaryRefs)) {
8843
+ if (identifierPattern(name).test(primaryRefs)) {
8758
8844
  reachable.add(name);
8759
8845
  queue.push(name);
8760
8846
  }
@@ -8763,7 +8849,7 @@ function findReachableNames(primaryRefs, declarations) {
8763
8849
  const current = queue.shift();
8764
8850
  const body = bodyMap.get(current) || "";
8765
8851
  for (const name of allNames) {
8766
- if (!reachable.has(name) && new RegExp(`\\b${name}\\b`).test(body)) {
8852
+ if (!reachable.has(name) && identifierPattern(name).test(body)) {
8767
8853
  reachable.add(name);
8768
8854
  queue.push(name);
8769
8855
  }
@@ -8771,6 +8857,49 @@ function findReachableNames(primaryRefs, declarations) {
8771
8857
  }
8772
8858
  return reachable;
8773
8859
  }
8860
+ function findAssignedNames(bodyText, candidates) {
8861
+ const assigned = new Set;
8862
+ if (candidates.size === 0)
8863
+ return assigned;
8864
+ const sf = ts10.createSourceFile("bf-assignment-scan.tsx", bodyText, ts10.ScriptTarget.Latest, false, ts10.ScriptKind.TSX);
8865
+ const record = (target) => {
8866
+ if (ts10.isIdentifier(target) && candidates.has(target.text)) {
8867
+ assigned.add(target.text);
8868
+ }
8869
+ };
8870
+ const visit2 = (node) => {
8871
+ if (ts10.isBinaryExpression(node) && isAssignmentOperator(node.operatorToken.kind)) {
8872
+ record(node.left);
8873
+ } else if ((ts10.isPrefixUnaryExpression(node) || ts10.isPostfixUnaryExpression(node)) && (node.operator === ts10.SyntaxKind.PlusPlusToken || node.operator === ts10.SyntaxKind.MinusMinusToken)) {
8874
+ record(node.operand);
8875
+ }
8876
+ ts10.forEachChild(node, visit2);
8877
+ };
8878
+ ts10.forEachChild(sf, visit2);
8879
+ return assigned;
8880
+ }
8881
+ function closeOverWritersOfMutableBindings(primaryRefs, declarations, mutableNames) {
8882
+ let reachable = findReachableNames(primaryRefs, declarations);
8883
+ if (mutableNames.size === 0)
8884
+ return reachable;
8885
+ let seedText = primaryRefs;
8886
+ for (let round = 0;round <= declarations.length; round++) {
8887
+ const survivingMutables = new Set([...reachable].filter((name) => mutableNames.has(name)));
8888
+ if (survivingMutables.size === 0)
8889
+ return reachable;
8890
+ const added = declarations.filter((d) => !reachable.has(d.name)).filter((d) => findAssignedNames(d.body, survivingMutables).size > 0).map((d) => d.name);
8891
+ if (added.length === 0)
8892
+ return reachable;
8893
+ seedText += `
8894
+ ` + added.join(`
8895
+ `);
8896
+ reachable = findReachableNames(seedText, declarations);
8897
+ }
8898
+ return reachable;
8899
+ }
8900
+ function isAssignmentOperator(kind) {
8901
+ return kind >= ts10.SyntaxKind.FirstAssignment && kind <= ts10.SyntaxKind.LastAssignment;
8902
+ }
8774
8903
 
8775
8904
  // ../jsx/src/builtins.ts
8776
8905
  var CLIENT_BUILTIN_SOURCE = "@barefootjs/client";
@@ -8793,7 +8922,7 @@ function stripClientBuiltinImports(imports) {
8793
8922
  }
8794
8923
 
8795
8924
  // ../jsx/src/reactivity-checker.ts
8796
- import ts10 from "typescript";
8925
+ import ts11 from "typescript";
8797
8926
  var REACTIVE_BRAND = "__reactive";
8798
8927
  function queryType(checker, node) {
8799
8928
  incrementCounter("typeCheckerQueries");
@@ -8811,7 +8940,7 @@ function safeGetText(node) {
8811
8940
  }
8812
8941
  }
8813
8942
  function analyze(node, checker) {
8814
- if (ts10.isPropertyAccessExpression(node)) {
8943
+ if (ts11.isPropertyAccessExpression(node)) {
8815
8944
  try {
8816
8945
  const type = queryType(checker, node);
8817
8946
  if (isReactiveType(type)) {
@@ -8835,7 +8964,7 @@ function analyze(node, checker) {
8835
8964
  }
8836
8965
  return NOT_REACTIVE;
8837
8966
  }
8838
- if (ts10.isIdentifier(node)) {
8967
+ if (ts11.isIdentifier(node)) {
8839
8968
  try {
8840
8969
  const type = queryType(checker, node);
8841
8970
  if (isReactiveType(type)) {
@@ -8847,7 +8976,7 @@ function analyze(node, checker) {
8847
8976
  } catch {}
8848
8977
  return NOT_REACTIVE;
8849
8978
  }
8850
- if (ts10.isCallExpression(node)) {
8979
+ if (ts11.isCallExpression(node)) {
8851
8980
  try {
8852
8981
  const calleeType = queryType(checker, node.expression);
8853
8982
  if (isReactiveType(calleeType)) {
@@ -8860,7 +8989,7 @@ function analyze(node, checker) {
8860
8989
  }
8861
8990
  let foundChild;
8862
8991
  let foundChildText = "";
8863
- ts10.forEachChild(node, (child) => {
8992
+ ts11.forEachChild(node, (child) => {
8864
8993
  if (foundChild?.isReactive)
8865
8994
  return;
8866
8995
  const result = analyze(child, checker);
@@ -8889,7 +9018,7 @@ function containsReactiveExpression(node, checker) {
8889
9018
  }
8890
9019
 
8891
9020
  // ../jsx/src/free-refs.ts
8892
- import ts11 from "typescript";
9021
+ import ts12 from "typescript";
8893
9022
  var _bindingMapCache = new WeakMap;
8894
9023
  function buildBindingMap(env) {
8895
9024
  const cached = _bindingMapCache.get(env);
@@ -8927,8 +9056,8 @@ function buildBindingMap(env) {
8927
9056
  for (const m of env.memos) {
8928
9057
  map.set(m.name, "memo-getter");
8929
9058
  }
8930
- if (env.loopParams) {
8931
- for (const name of env.loopParams)
9059
+ if (env.loopValueBoundNames) {
9060
+ for (const name of env.loopValueBoundNames)
8932
9061
  map.set(name, "render-item");
8933
9062
  }
8934
9063
  _bindingMapCache.set(env, map);
@@ -8957,20 +9086,20 @@ function defaultBindingScope(kind) {
8957
9086
  function collectIdentifiers2(node) {
8958
9087
  const out = [];
8959
9088
  const visit2 = (n, parent) => {
8960
- if (ts11.isIdentifier(n)) {
8961
- if (parent && ts11.isPropertyAccessExpression(parent) && parent.name === n)
9089
+ if (ts12.isIdentifier(n)) {
9090
+ if (parent && ts12.isPropertyAccessExpression(parent) && parent.name === n)
8962
9091
  return;
8963
- if (parent && ts11.isPropertyAssignment(parent) && parent.name === n)
9092
+ if (parent && ts12.isPropertyAssignment(parent) && parent.name === n)
8964
9093
  return;
8965
- if (parent && (ts11.isJsxOpeningElement(parent) || ts11.isJsxClosingElement(parent) || ts11.isJsxSelfClosingElement(parent)) && parent.tagName === n) {
9094
+ if (parent && (ts12.isJsxOpeningElement(parent) || ts12.isJsxClosingElement(parent) || ts12.isJsxSelfClosingElement(parent)) && parent.tagName === n) {
8966
9095
  return;
8967
9096
  }
8968
- if (parent && ts11.isJsxAttribute(parent) && parent.name === n)
9097
+ if (parent && ts12.isJsxAttribute(parent) && parent.name === n)
8969
9098
  return;
8970
9099
  out.push(n);
8971
9100
  return;
8972
9101
  }
8973
- ts11.forEachChild(n, (child) => visit2(child, n));
9102
+ ts12.forEachChild(n, (child) => visit2(child, n));
8974
9103
  };
8975
9104
  visit2(node);
8976
9105
  return out;
@@ -8979,7 +9108,7 @@ function collectReactiveBrandRefs(node, checker) {
8979
9108
  const out = [];
8980
9109
  const seen = new Set;
8981
9110
  const visit2 = (n) => {
8982
- if (ts11.isPropertyAccessExpression(n)) {
9111
+ if (ts12.isPropertyAccessExpression(n)) {
8983
9112
  try {
8984
9113
  const type = checker.getTypeAtLocation(n);
8985
9114
  if (isReactiveType(type)) {
@@ -8997,7 +9126,7 @@ function collectReactiveBrandRefs(node, checker) {
8997
9126
  incrementCounter("freeRefsTypeLookupFailures");
8998
9127
  }
8999
9128
  }
9000
- ts11.forEachChild(n, visit2);
9129
+ ts12.forEachChild(n, visit2);
9001
9130
  };
9002
9131
  visit2(node);
9003
9132
  return out;
@@ -9007,14 +9136,14 @@ function resolveConstantInitializerRefs(c, env, visited) {
9007
9136
  return [];
9008
9137
  if (c.containsArrow)
9009
9138
  return [];
9010
- const sf = ts11.createSourceFile("__const_init.ts", `const __probe = (${c.value});`, ts11.ScriptTarget.Latest, true);
9139
+ const sf = ts12.createSourceFile("__const_init.ts", `const __probe = (${c.value});`, ts12.ScriptTarget.Latest, true);
9011
9140
  const stmt = sf.statements[0];
9012
- if (!stmt || !ts11.isVariableStatement(stmt))
9141
+ if (!stmt || !ts12.isVariableStatement(stmt))
9013
9142
  return [];
9014
9143
  const decl = stmt.declarationList.declarations[0];
9015
9144
  if (!decl || !decl.initializer)
9016
9145
  return [];
9017
- const expr = ts11.isParenthesizedExpression(decl.initializer) ? decl.initializer.expression : decl.initializer;
9146
+ const expr = ts12.isParenthesizedExpression(decl.initializer) ? decl.initializer.expression : decl.initializer;
9018
9147
  return resolveFreeRefsInternal(expr, env, visited);
9019
9148
  }
9020
9149
  function resolveFreeRefsInternal(node, env, visited) {
@@ -9026,7 +9155,7 @@ function resolveFreeRefsInternal(node, env, visited) {
9026
9155
  const name = ident.text;
9027
9156
  if (env.propsObjectName === name) {
9028
9157
  const parent = ident.parent;
9029
- if (parent && ts11.isPropertyAccessExpression(parent) && parent.expression === ident && parent.name.text === "children") {
9158
+ if (parent && ts12.isPropertyAccessExpression(parent) && parent.expression === ident && parent.name.text === "children") {
9030
9159
  continue;
9031
9160
  }
9032
9161
  }
@@ -9429,83 +9558,6 @@ var toLocaleDatePlugin = {
9429
9558
  }
9430
9559
  };
9431
9560
 
9432
- // ../jsx/src/scope/binding-scope.ts
9433
- class BindingScope {
9434
- frames;
9435
- static EMPTY = new BindingScope([]);
9436
- constructor(frames) {
9437
- this.frames = frames;
9438
- }
9439
- enterLoopRow(loop) {
9440
- const bindings = new Map;
9441
- if (loop.paramBindings && loop.paramBindings.length > 0) {
9442
- for (const b of loop.paramBindings)
9443
- bindings.set(b.name, { source: "destructure" });
9444
- } else {
9445
- bindings.set(loop.param, { source: "item" });
9446
- }
9447
- if (loop.index != null)
9448
- bindings.set(loop.index, { source: "index" });
9449
- for (const name of loop.preamble?.declaredNames ?? [])
9450
- bindings.set(name, { source: "preamble" });
9451
- const frame = { kind: "loop-row", bindings };
9452
- return new BindingScope([frame, ...this.frames]);
9453
- }
9454
- enterCallback(params) {
9455
- const bindings = new Map;
9456
- for (const name of params)
9457
- bindings.set(name, { source: "param" });
9458
- const frame = { kind: "callback", bindings };
9459
- return new BindingScope([frame, ...this.frames]);
9460
- }
9461
- isBound(name) {
9462
- for (const frame of this.frames) {
9463
- if (frame.bindings.has(name))
9464
- return true;
9465
- }
9466
- return false;
9467
- }
9468
- lookup(name) {
9469
- for (let depth = 0;depth < this.frames.length; depth++) {
9470
- const frame = this.frames[depth];
9471
- const binding = frame.bindings.get(name);
9472
- if (binding)
9473
- return { depth, frame, binding };
9474
- }
9475
- return null;
9476
- }
9477
- boundNames() {
9478
- if (this.boundNamesCache)
9479
- return this.boundNamesCache;
9480
- const names = new Set;
9481
- for (const frame of this.frames) {
9482
- for (const name of frame.bindings.keys())
9483
- names.add(name);
9484
- }
9485
- this.boundNamesCache = names;
9486
- return names;
9487
- }
9488
- boundNamesCache;
9489
- valueBoundNamesCache;
9490
- valueBoundNames() {
9491
- if (this.valueBoundNamesCache)
9492
- return this.valueBoundNamesCache;
9493
- const names = new Set;
9494
- for (const frame of this.frames) {
9495
- for (const [name, binding] of frame.bindings) {
9496
- if (binding.source === "item" || binding.source === "index" || binding.source === "destructure") {
9497
- names.add(name);
9498
- }
9499
- }
9500
- }
9501
- this.valueBoundNamesCache = names;
9502
- return names;
9503
- }
9504
- asShadowPredicate() {
9505
- return (name) => this.isBound(name);
9506
- }
9507
- }
9508
-
9509
9561
  // ../jsx/src/jsx-to-ir.ts
9510
9562
  var CLIENT_DIRECTIVE_INTERIOR_RE2 = /^\s*@client\s*$/;
9511
9563
  var BLOCK_COMMENT_RE2 = /\/\*([\s\S]*?)\*\//g;
@@ -9531,13 +9583,13 @@ function exprCallsReactiveGetters(expr, ctx) {
9531
9583
  function visit2(n) {
9532
9584
  if (found)
9533
9585
  return;
9534
- if (ts12.isCallExpression(n) && ts12.isIdentifier(n.expression)) {
9586
+ if (ts13.isCallExpression(n) && ts13.isIdentifier(n.expression)) {
9535
9587
  if (names.has(n.expression.text)) {
9536
9588
  found = true;
9537
9589
  return;
9538
9590
  }
9539
9591
  }
9540
- ts12.forEachChild(n, visit2);
9592
+ ts13.forEachChild(n, visit2);
9541
9593
  }
9542
9594
  visit2(expr);
9543
9595
  return found;
@@ -9564,11 +9616,11 @@ function exprReferencesModuleClientSignal(expr, ctx) {
9564
9616
  function visit2(n) {
9565
9617
  if (found)
9566
9618
  return;
9567
- if (ts12.isCallExpression(n) && ts12.isIdentifier(n.expression) && names.has(n.expression.text)) {
9619
+ if (ts13.isCallExpression(n) && ts13.isIdentifier(n.expression) && names.has(n.expression.text)) {
9568
9620
  found = true;
9569
9621
  return;
9570
9622
  }
9571
- ts12.forEachChild(n, visit2);
9623
+ ts13.forEachChild(n, visit2);
9572
9624
  }
9573
9625
  visit2(expr);
9574
9626
  return found;
@@ -9578,11 +9630,11 @@ function exprHasFunctionCalls(expr) {
9578
9630
  function visit2(n) {
9579
9631
  if (found)
9580
9632
  return;
9581
- if (ts12.isCallExpression(n)) {
9633
+ if (ts13.isCallExpression(n)) {
9582
9634
  found = true;
9583
9635
  return;
9584
9636
  }
9585
- ts12.forEachChild(n, visit2);
9637
+ ts13.forEachChild(n, visit2);
9586
9638
  }
9587
9639
  visit2(expr);
9588
9640
  return found;
@@ -9619,10 +9671,10 @@ function lowerDateCalls(text, expr, ctx) {
9619
9671
  return text;
9620
9672
  const candidates = [];
9621
9673
  function visit2(n) {
9622
- if (ts12.isCallExpression(n) && n.arguments.length === 0 && ts12.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
9674
+ if (ts13.isCallExpression(n) && n.arguments.length === 0 && ts13.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
9623
9675
  candidates.push(n);
9624
9676
  }
9625
- ts12.forEachChild(n, visit2);
9677
+ ts13.forEachChild(n, visit2);
9626
9678
  }
9627
9679
  visit2(expr);
9628
9680
  if (candidates.length === 0)
@@ -9647,10 +9699,10 @@ function lowerToLocaleDateCalls(text, expr, ctx) {
9647
9699
  return text;
9648
9700
  const candidates = [];
9649
9701
  function visit2(n) {
9650
- if (ts12.isCallExpression(n) && n.arguments.length === 2 && ts12.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
9702
+ if (ts13.isCallExpression(n) && n.arguments.length === 2 && ts13.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
9651
9703
  candidates.push(n);
9652
9704
  }
9653
- ts12.forEachChild(n, visit2);
9705
+ ts13.forEachChild(n, visit2);
9654
9706
  }
9655
9707
  visit2(expr);
9656
9708
  if (candidates.length === 0)
@@ -9704,10 +9756,10 @@ function collectBranchLocalPropRefsViaSubstitution(node, ctx) {
9704
9756
  return;
9705
9757
  let acc;
9706
9758
  function visit2(n, parent) {
9707
- if (ts12.isIdentifier(n) && propDepsMap.has(n.text)) {
9708
- const isObjectKey = parent && ts12.isPropertyAssignment(parent) && parent.name === n;
9709
- const isShorthand = parent && ts12.isShorthandPropertyAssignment(parent) && parent.name === n;
9710
- const isAccessName = parent && ts12.isPropertyAccessExpression(parent) && parent.name === n;
9759
+ if (ts13.isIdentifier(n) && propDepsMap.has(n.text)) {
9760
+ const isObjectKey = parent && ts13.isPropertyAssignment(parent) && parent.name === n;
9761
+ const isShorthand = parent && ts13.isShorthandPropertyAssignment(parent) && parent.name === n;
9762
+ const isAccessName = parent && ts13.isPropertyAccessExpression(parent) && parent.name === n;
9711
9763
  if (!isObjectKey && !isShorthand && !isAccessName) {
9712
9764
  const deps = propDepsMap.get(n.text);
9713
9765
  if (deps && deps.size > 0) {
@@ -9718,7 +9770,7 @@ function collectBranchLocalPropRefsViaSubstitution(node, ctx) {
9718
9770
  }
9719
9771
  }
9720
9772
  }
9721
- ts12.forEachChild(n, (child) => visit2(child, n));
9773
+ ts13.forEachChild(n, (child) => visit2(child, n));
9722
9774
  }
9723
9775
  visit2(node);
9724
9776
  return acc;
@@ -9769,17 +9821,17 @@ function createTransformContext(analyzer) {
9769
9821
  patterns: {
9770
9822
  signals: analyzer.signals.map((s) => ({
9771
9823
  getter: s.getter,
9772
- pattern: new RegExp(`\\b${s.getter}\\s*\\(`)
9824
+ pattern: identifierCallPattern(s.getter)
9773
9825
  })),
9774
9826
  memos: analyzer.memos.map((m) => ({
9775
9827
  name: m.name,
9776
- pattern: new RegExp(`\\b${m.name}\\s*\\(`)
9828
+ pattern: identifierCallPattern(m.name)
9777
9829
  })),
9778
- props: analyzer.propsParams.filter((p) => p.name !== "children").map((p) => ({ name: p.name, pattern: new RegExp(`\\b${p.name}\\b`) })),
9830
+ props: analyzer.propsParams.filter((p) => p.name !== "children").map((p) => ({ name: p.name, pattern: identifierPattern(p.name) })),
9779
9831
  constants: analyzer.localConstants.map((c) => ({
9780
9832
  name: c.name,
9781
9833
  value: c.value,
9782
- pattern: new RegExp(`\\b${c.name}\\b`)
9834
+ pattern: identifierPattern(c.name)
9783
9835
  }))
9784
9836
  },
9785
9837
  getJS(node) {
@@ -9794,21 +9846,21 @@ function createTransformContext(analyzer) {
9794
9846
  function buildComponentNamespaces(ctx) {
9795
9847
  const result = new Map;
9796
9848
  for (const stmt of ctx.sourceFile.statements) {
9797
- if (!ts12.isVariableStatement(stmt))
9849
+ if (!ts13.isVariableStatement(stmt))
9798
9850
  continue;
9799
9851
  for (const decl of stmt.declarationList.declarations) {
9800
- if (!decl.initializer || !ts12.isIdentifier(decl.name))
9852
+ if (!decl.initializer || !ts13.isIdentifier(decl.name))
9801
9853
  continue;
9802
9854
  let init = decl.initializer;
9803
- while (ts12.isParenthesizedExpression(init))
9855
+ while (ts13.isParenthesizedExpression(init))
9804
9856
  init = init.expression;
9805
- if (!ts12.isObjectLiteralExpression(init))
9857
+ if (!ts13.isObjectLiteralExpression(init))
9806
9858
  continue;
9807
9859
  const members = new Map;
9808
9860
  for (const prop of init.properties) {
9809
- if (ts12.isShorthandPropertyAssignment(prop)) {
9861
+ if (ts13.isShorthandPropertyAssignment(prop)) {
9810
9862
  members.set(prop.name.text, prop.name.text);
9811
- } else if (ts12.isPropertyAssignment(prop) && (ts12.isIdentifier(prop.name) || ts12.isStringLiteral(prop.name)) && ts12.isIdentifier(prop.initializer)) {
9863
+ } else if (ts13.isPropertyAssignment(prop) && (ts13.isIdentifier(prop.name) || ts13.isStringLiteral(prop.name)) && ts13.isIdentifier(prop.initializer)) {
9812
9864
  members.set(prop.name.text, prop.initializer.text);
9813
9865
  }
9814
9866
  }
@@ -9820,11 +9872,11 @@ function buildComponentNamespaces(ctx) {
9820
9872
  return result;
9821
9873
  }
9822
9874
  function resolveMemberExpressionTag(tagNode, ctx) {
9823
- if (!ts12.isPropertyAccessExpression(tagNode))
9875
+ if (!ts13.isPropertyAccessExpression(tagNode))
9824
9876
  return null;
9825
- if (!ts12.isIdentifier(tagNode.expression))
9877
+ if (!ts13.isIdentifier(tagNode.expression))
9826
9878
  return null;
9827
- if (!ts12.isIdentifier(tagNode.name))
9879
+ if (!ts13.isIdentifier(tagNode.name))
9828
9880
  return null;
9829
9881
  if (!ctx._componentNamespaces) {
9830
9882
  ctx._componentNamespaces = buildComponentNamespaces(ctx);
@@ -9857,7 +9909,7 @@ function makeBindingEnv(ctx) {
9857
9909
  localFunctions: a.localFunctions,
9858
9910
  imports: a.imports,
9859
9911
  ambientGlobals: a.ambientGlobals,
9860
- loopParams: boundNames,
9912
+ loopValueBoundNames: boundNames,
9861
9913
  checker: a.checker
9862
9914
  };
9863
9915
  ctx._bindingEnv = env;
@@ -9981,7 +10033,7 @@ function buildIRRoot(analyzer) {
9981
10033
  return null;
9982
10034
  const ctx = createTransformContext(analyzer);
9983
10035
  const jsxReturn = analyzer.jsxReturn;
9984
- if (ts12.isJsxElement(jsxReturn) || ts12.isJsxSelfClosingElement(jsxReturn) || ts12.isJsxFragment(jsxReturn)) {
10036
+ if (ts13.isJsxElement(jsxReturn) || ts13.isJsxSelfClosingElement(jsxReturn) || ts13.isJsxFragment(jsxReturn)) {
9985
10037
  const ir2 = transformNode(jsxReturn, ctx);
9986
10038
  if (ir2 && needsScopeWrapper(ir2)) {
9987
10039
  return wrapInScopeElement(ir2);
@@ -10037,22 +10089,22 @@ function wrapInScopeElement(node) {
10037
10089
  };
10038
10090
  }
10039
10091
  function transformNode(node, ctx) {
10040
- if (ts12.isJsxElement(node)) {
10092
+ if (ts13.isJsxElement(node)) {
10041
10093
  return transformJsxElement(node, ctx);
10042
10094
  }
10043
- if (ts12.isJsxSelfClosingElement(node)) {
10095
+ if (ts13.isJsxSelfClosingElement(node)) {
10044
10096
  return transformSelfClosingElement(node, ctx);
10045
10097
  }
10046
- if (ts12.isJsxFragment(node)) {
10098
+ if (ts13.isJsxFragment(node)) {
10047
10099
  return transformFragment(node, ctx);
10048
10100
  }
10049
- if (ts12.isJsxText(node)) {
10101
+ if (ts13.isJsxText(node)) {
10050
10102
  return transformText(node, ctx);
10051
10103
  }
10052
- if (ts12.isJsxExpression(node)) {
10104
+ if (ts13.isJsxExpression(node)) {
10053
10105
  return transformExpression(node, ctx);
10054
10106
  }
10055
- if (ts12.isConditionalExpression(node)) {
10107
+ if (ts13.isConditionalExpression(node)) {
10056
10108
  return transformConditional(node, ctx);
10057
10109
  }
10058
10110
  return null;
@@ -10409,7 +10461,7 @@ function transformSelfClosingComponent(node, ctx, name) {
10409
10461
  }
10410
10462
  function isTransparentFragment(node, ctx) {
10411
10463
  const children = node.children.filter((child2) => {
10412
- if (ts12.isJsxText(child2)) {
10464
+ if (ts13.isJsxText(child2)) {
10413
10465
  return child2.text.trim() !== "";
10414
10466
  }
10415
10467
  return true;
@@ -10417,7 +10469,7 @@ function isTransparentFragment(node, ctx) {
10417
10469
  if (children.length !== 1)
10418
10470
  return false;
10419
10471
  const child = children[0];
10420
- if (!ts12.isJsxExpression(child))
10472
+ if (!ts13.isJsxExpression(child))
10421
10473
  return false;
10422
10474
  if (!child.expression)
10423
10475
  return false;
@@ -10461,7 +10513,7 @@ function transformChildren(children, ctx) {
10461
10513
  const result = [];
10462
10514
  for (let i = 0;i < children.length; i++) {
10463
10515
  const child = children[i];
10464
- if (ts12.isJsxExpression(child) && !child.expression) {
10516
+ if (ts13.isJsxExpression(child) && !child.expression) {
10465
10517
  continue;
10466
10518
  }
10467
10519
  const transformed = transformNode(child, ctx);
@@ -10476,10 +10528,10 @@ function transformChildren(children, ctx) {
10476
10528
  }
10477
10529
  function isRenderNothingLiteral(expr, ctx) {
10478
10530
  let e = expr;
10479
- while (ts12.isParenthesizedExpression(e) || ts12.isAsExpression(e) || ts12.isSatisfiesExpression(e) || ts12.isNonNullExpression(e)) {
10531
+ while (ts13.isParenthesizedExpression(e) || ts13.isAsExpression(e) || ts13.isSatisfiesExpression(e) || ts13.isNonNullExpression(e)) {
10480
10532
  e = e.expression;
10481
10533
  }
10482
- return e.kind === ts12.SyntaxKind.NullKeyword || e.kind === ts12.SyntaxKind.TrueKeyword || e.kind === ts12.SyntaxKind.FalseKeyword || ts12.isIdentifier(e) && e.text === "undefined" && !isNameBound("undefined", makeBindingEnv(ctx));
10534
+ return e.kind === ts13.SyntaxKind.NullKeyword || e.kind === ts13.SyntaxKind.TrueKeyword || e.kind === ts13.SyntaxKind.FalseKeyword || ts13.isIdentifier(e) && e.text === "undefined" && !isNameBound("undefined", makeBindingEnv(ctx));
10483
10535
  }
10484
10536
  function transformText(node, ctx) {
10485
10537
  const text = node.text.replace(/\s+/g, " ");
@@ -10505,7 +10557,7 @@ function transformExpressionInner(expr, ctx, node, isClientOnly) {
10505
10557
  return null;
10506
10558
  }
10507
10559
  checkBareSignalOrMemoIdentifier(expr, ctx);
10508
- if (ts12.isIdentifier(expr)) {
10560
+ if (ts13.isIdentifier(expr)) {
10509
10561
  const jsxNode = ctx.analyzer.jsxConstants.get(expr.text);
10510
10562
  if (jsxNode) {
10511
10563
  return transformNode(jsxNode, ctx);
@@ -10551,7 +10603,7 @@ function transformExpressionInner(expr, ctx, node, isClientOnly) {
10551
10603
  };
10552
10604
  const reactive = isReactiveExpression(exprText, ctx, expr) || isReactiveOrigin(origin);
10553
10605
  const scopeValueNames = ctx.scope.valueBoundNames();
10554
- const refsLoopParam = scopeValueNames.size > 0 && Array.from(scopeValueNames).some((p) => new RegExp(`\\b${p}\\b`).test(exprText));
10606
+ const refsLoopParam = scopeValueNames.size > 0 && Array.from(scopeValueNames).some((p) => identifierPattern(p).test(exprText));
10555
10607
  const callsReactive = exprCallsReactiveGetters(expr, ctx);
10556
10608
  const hasCalls = exprHasFunctionCalls(expr);
10557
10609
  const needsSlot = reactive || isClientOnly || refsLoopParam || callsReactive || hasCalls;
@@ -10586,7 +10638,7 @@ function transformJsxFunctionCall(callExpr, jsxFunc, ctx, _isClientOnly) {
10586
10638
  const substitutedGetJS = (node) => {
10587
10639
  let text = baseGetJS(node);
10588
10640
  for (const [paramName, argExpr] of substitutions) {
10589
- text = text.replace(new RegExp(`\\b${paramName}\\b`, "g"), argExpr);
10641
+ text = text.replace(identifierPattern(paramName, "g"), () => argExpr);
10590
10642
  }
10591
10643
  return text;
10592
10644
  };
@@ -10628,7 +10680,7 @@ function transformMultiReturnJsxFunctionCall(callExpr, info, ctx) {
10628
10680
  const substitutedGetJS = (node) => {
10629
10681
  let text = baseGetJS(node);
10630
10682
  for (const [paramName, argExpr] of substitutions) {
10631
- text = text.replace(new RegExp(`\\b${paramName}\\b`, "g"), argExpr);
10683
+ text = text.replace(identifierPattern(paramName, "g"), () => argExpr);
10632
10684
  }
10633
10685
  return text;
10634
10686
  };
@@ -10784,38 +10836,38 @@ function transformLogicalAnd(node, ctx) {
10784
10836
  };
10785
10837
  }
10786
10838
  function containsJsxInExpression(node) {
10787
- if (ts12.isJsxElement(node) || ts12.isJsxSelfClosingElement(node) || ts12.isJsxFragment(node)) {
10839
+ if (ts13.isJsxElement(node) || ts13.isJsxSelfClosingElement(node) || ts13.isJsxFragment(node)) {
10788
10840
  return true;
10789
10841
  }
10790
- return ts12.forEachChild(node, containsJsxInExpression) ?? false;
10842
+ return ts13.forEachChild(node, containsJsxInExpression) ?? false;
10791
10843
  }
10792
10844
  function callsJsxHelper(node, ctx) {
10793
10845
  let found = false;
10794
10846
  const visit2 = (n) => {
10795
10847
  if (found)
10796
10848
  return;
10797
- if (ts12.isCallExpression(n) && ts12.isIdentifier(n.expression)) {
10849
+ if (ts13.isCallExpression(n) && ts13.isIdentifier(n.expression)) {
10798
10850
  const name = n.expression.text;
10799
10851
  if (ctx.analyzer.jsxFunctions.has(name) || ctx.analyzer.jsxMultiReturnFunctions.has(name)) {
10800
10852
  found = true;
10801
10853
  return;
10802
10854
  }
10803
10855
  }
10804
- ts12.forEachChild(n, visit2);
10856
+ ts13.forEachChild(n, visit2);
10805
10857
  };
10806
10858
  visit2(node);
10807
10859
  return found;
10808
10860
  }
10809
10861
  function containsAwaitExpression(node) {
10810
- if (ts12.isAwaitExpression(node))
10862
+ if (ts13.isAwaitExpression(node))
10811
10863
  return true;
10812
- if (ts12.isFunctionDeclaration(node) || ts12.isFunctionExpression(node) || ts12.isArrowFunction(node))
10864
+ if (ts13.isFunctionDeclaration(node) || ts13.isFunctionExpression(node) || ts13.isArrowFunction(node))
10813
10865
  return false;
10814
- return ts12.forEachChild(node, containsAwaitExpression) ?? false;
10866
+ return ts13.forEachChild(node, containsAwaitExpression) ?? false;
10815
10867
  }
10816
10868
  function transformNullishCoalescing(node, ctx) {
10817
10869
  const leftText = ctx.getJS(node.left);
10818
- const isNullish = node.operatorToken.kind === ts12.SyntaxKind.QuestionQuestionToken;
10870
+ const isNullish = node.operatorToken.kind === ts13.SyntaxKind.QuestionQuestionToken;
10819
10871
  const condition = isNullish ? `${leftText} != null` : leftText;
10820
10872
  const leftOrigin = {
10821
10873
  phase: "tick",
@@ -10861,36 +10913,36 @@ function transformNullishCoalescing(node, ctx) {
10861
10913
  }
10862
10914
  function assertNever2(expr) {
10863
10915
  const kind = expr?.kind;
10864
- throw new Error(`transformJsxExpression: unhandled ts.SyntaxKind ${kind !== undefined ? ts12.SyntaxKind[kind] : "unknown"} ` + `(kind=${kind}). Update spec/compiler.md Appendix A and the switch in jsx-to-ir.ts.`);
10916
+ throw new Error(`transformJsxExpression: unhandled ts.SyntaxKind ${kind !== undefined ? ts13.SyntaxKind[kind] : "unknown"} ` + `(kind=${kind}). Update spec/compiler.md Appendix A and the switch in jsx-to-ir.ts.`);
10865
10917
  }
10866
10918
  function transformJsxExpression(expr, ctx, isClientOnly = false) {
10867
10919
  const node = expr;
10868
10920
  switch (node.kind) {
10869
- case ts12.SyntaxKind.ParenthesizedExpression:
10870
- case ts12.SyntaxKind.AsExpression:
10871
- case ts12.SyntaxKind.SatisfiesExpression:
10872
- case ts12.SyntaxKind.NonNullExpression:
10873
- case ts12.SyntaxKind.TypeAssertionExpression:
10874
- case ts12.SyntaxKind.PartiallyEmittedExpression:
10921
+ case ts13.SyntaxKind.ParenthesizedExpression:
10922
+ case ts13.SyntaxKind.AsExpression:
10923
+ case ts13.SyntaxKind.SatisfiesExpression:
10924
+ case ts13.SyntaxKind.NonNullExpression:
10925
+ case ts13.SyntaxKind.TypeAssertionExpression:
10926
+ case ts13.SyntaxKind.PartiallyEmittedExpression:
10875
10927
  return transformJsxExpression(node.expression, ctx, isClientOnly);
10876
- case ts12.SyntaxKind.JsxElement:
10928
+ case ts13.SyntaxKind.JsxElement:
10877
10929
  return transformJsxElement(node, ctx);
10878
- case ts12.SyntaxKind.JsxFragment:
10930
+ case ts13.SyntaxKind.JsxFragment:
10879
10931
  return transformFragment(node, ctx);
10880
- case ts12.SyntaxKind.JsxSelfClosingElement:
10932
+ case ts13.SyntaxKind.JsxSelfClosingElement:
10881
10933
  return transformSelfClosingElement(node, ctx);
10882
- case ts12.SyntaxKind.ConditionalExpression:
10934
+ case ts13.SyntaxKind.ConditionalExpression:
10883
10935
  return transformConditional(node, ctx);
10884
- case ts12.SyntaxKind.BinaryExpression: {
10885
- if (node.operatorToken.kind === ts12.SyntaxKind.AmpersandAmpersandToken) {
10936
+ case ts13.SyntaxKind.BinaryExpression: {
10937
+ if (node.operatorToken.kind === ts13.SyntaxKind.AmpersandAmpersandToken) {
10886
10938
  return transformLogicalAnd(node, ctx);
10887
10939
  }
10888
- if ((node.operatorToken.kind === ts12.SyntaxKind.QuestionQuestionToken || node.operatorToken.kind === ts12.SyntaxKind.BarBarToken) && (containsJsxInExpression(node.right) || callsJsxHelper(node.right, ctx))) {
10940
+ if ((node.operatorToken.kind === ts13.SyntaxKind.QuestionQuestionToken || node.operatorToken.kind === ts13.SyntaxKind.BarBarToken) && (containsJsxInExpression(node.right) || callsJsxHelper(node.right, ctx))) {
10889
10941
  return transformNullishCoalescing(node, ctx);
10890
10942
  }
10891
10943
  return null;
10892
10944
  }
10893
- case ts12.SyntaxKind.CallExpression: {
10945
+ case ts13.SyntaxKind.CallExpression: {
10894
10946
  const mapMethod = getMapLikeMethod(node);
10895
10947
  if (mapMethod) {
10896
10948
  const mapResult = transformMapCall(node, ctx, isClientOnly, mapMethod);
@@ -10898,7 +10950,7 @@ function transformJsxExpression(expr, ctx, isClientOnly = false) {
10898
10950
  return mapResult;
10899
10951
  }
10900
10952
  const callee = node.expression;
10901
- if (ts12.isIdentifier(callee)) {
10953
+ if (ts13.isIdentifier(callee)) {
10902
10954
  const jsxFunc = ctx.analyzer.jsxFunctions.get(callee.text);
10903
10955
  if (jsxFunc) {
10904
10956
  return transformJsxFunctionCall(node, jsxFunc, ctx, isClientOnly);
@@ -10910,39 +10962,39 @@ function transformJsxExpression(expr, ctx, isClientOnly = false) {
10910
10962
  }
10911
10963
  return null;
10912
10964
  }
10913
- case ts12.SyntaxKind.Identifier:
10914
- case ts12.SyntaxKind.StringLiteral:
10915
- case ts12.SyntaxKind.NumericLiteral:
10916
- case ts12.SyntaxKind.BigIntLiteral:
10917
- case ts12.SyntaxKind.RegularExpressionLiteral:
10918
- case ts12.SyntaxKind.NoSubstitutionTemplateLiteral:
10919
- case ts12.SyntaxKind.TemplateExpression:
10920
- case ts12.SyntaxKind.TaggedTemplateExpression:
10921
- case ts12.SyntaxKind.TrueKeyword:
10922
- case ts12.SyntaxKind.FalseKeyword:
10923
- case ts12.SyntaxKind.NullKeyword:
10924
- case ts12.SyntaxKind.ThisKeyword:
10925
- case ts12.SyntaxKind.SuperKeyword:
10926
- case ts12.SyntaxKind.ImportKeyword:
10927
- case ts12.SyntaxKind.PropertyAccessExpression:
10928
- case ts12.SyntaxKind.ElementAccessExpression:
10929
- case ts12.SyntaxKind.PrefixUnaryExpression:
10930
- case ts12.SyntaxKind.PostfixUnaryExpression:
10931
- case ts12.SyntaxKind.TypeOfExpression:
10932
- case ts12.SyntaxKind.VoidExpression:
10933
- case ts12.SyntaxKind.DeleteExpression:
10934
- case ts12.SyntaxKind.NewExpression:
10935
- case ts12.SyntaxKind.ObjectLiteralExpression:
10936
- case ts12.SyntaxKind.ArrowFunction:
10937
- case ts12.SyntaxKind.FunctionExpression:
10938
- case ts12.SyntaxKind.ClassExpression:
10939
- case ts12.SyntaxKind.MetaProperty:
10940
- case ts12.SyntaxKind.ExpressionWithTypeArguments:
10941
- case ts12.SyntaxKind.CommaListExpression:
10942
- case ts12.SyntaxKind.SyntheticExpression:
10943
- case ts12.SyntaxKind.ArrayLiteralExpression:
10965
+ case ts13.SyntaxKind.Identifier:
10966
+ case ts13.SyntaxKind.StringLiteral:
10967
+ case ts13.SyntaxKind.NumericLiteral:
10968
+ case ts13.SyntaxKind.BigIntLiteral:
10969
+ case ts13.SyntaxKind.RegularExpressionLiteral:
10970
+ case ts13.SyntaxKind.NoSubstitutionTemplateLiteral:
10971
+ case ts13.SyntaxKind.TemplateExpression:
10972
+ case ts13.SyntaxKind.TaggedTemplateExpression:
10973
+ case ts13.SyntaxKind.TrueKeyword:
10974
+ case ts13.SyntaxKind.FalseKeyword:
10975
+ case ts13.SyntaxKind.NullKeyword:
10976
+ case ts13.SyntaxKind.ThisKeyword:
10977
+ case ts13.SyntaxKind.SuperKeyword:
10978
+ case ts13.SyntaxKind.ImportKeyword:
10979
+ case ts13.SyntaxKind.PropertyAccessExpression:
10980
+ case ts13.SyntaxKind.ElementAccessExpression:
10981
+ case ts13.SyntaxKind.PrefixUnaryExpression:
10982
+ case ts13.SyntaxKind.PostfixUnaryExpression:
10983
+ case ts13.SyntaxKind.TypeOfExpression:
10984
+ case ts13.SyntaxKind.VoidExpression:
10985
+ case ts13.SyntaxKind.DeleteExpression:
10986
+ case ts13.SyntaxKind.NewExpression:
10987
+ case ts13.SyntaxKind.ObjectLiteralExpression:
10988
+ case ts13.SyntaxKind.ArrowFunction:
10989
+ case ts13.SyntaxKind.FunctionExpression:
10990
+ case ts13.SyntaxKind.ClassExpression:
10991
+ case ts13.SyntaxKind.MetaProperty:
10992
+ case ts13.SyntaxKind.ExpressionWithTypeArguments:
10993
+ case ts13.SyntaxKind.CommaListExpression:
10994
+ case ts13.SyntaxKind.SyntheticExpression:
10995
+ case ts13.SyntaxKind.ArrayLiteralExpression:
10944
10996
  return null;
10945
- case ts12.SyntaxKind.AwaitExpression:
10997
+ case ts13.SyntaxKind.AwaitExpression:
10946
10998
  ctx.analyzer.errors.push(createError(ErrorCodes.STAGE_AWAIT_IN_TEMPLATE, getSourceLocation(node, ctx.sourceFile, ctx.filePath)));
10947
10999
  return {
10948
11000
  type: "expression",
@@ -10953,16 +11005,16 @@ function transformJsxExpression(expr, ctx, isClientOnly = false) {
10953
11005
  loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath),
10954
11006
  origin: { phase: "tick", scope: "template", effect: "pure", freeRefs: [] }
10955
11007
  };
10956
- case ts12.SyntaxKind.YieldExpression:
11008
+ case ts13.SyntaxKind.YieldExpression:
10957
11009
  return null;
10958
- case ts12.SyntaxKind.SpreadElement:
10959
- case ts12.SyntaxKind.OmittedExpression:
10960
- case ts12.SyntaxKind.JsxExpression:
10961
- case ts12.SyntaxKind.JsxOpeningElement:
10962
- case ts12.SyntaxKind.JsxOpeningFragment:
10963
- case ts12.SyntaxKind.JsxClosingFragment:
10964
- case ts12.SyntaxKind.JsxAttributes:
10965
- case ts12.SyntaxKind.MissingDeclaration:
11010
+ case ts13.SyntaxKind.SpreadElement:
11011
+ case ts13.SyntaxKind.OmittedExpression:
11012
+ case ts13.SyntaxKind.JsxExpression:
11013
+ case ts13.SyntaxKind.JsxOpeningElement:
11014
+ case ts13.SyntaxKind.JsxOpeningFragment:
11015
+ case ts13.SyntaxKind.JsxClosingFragment:
11016
+ case ts13.SyntaxKind.JsxAttributes:
11017
+ case ts13.SyntaxKind.MissingDeclaration:
10966
11018
  return null;
10967
11019
  default:
10968
11020
  return assertNever2(node);
@@ -10999,7 +11051,7 @@ function transformConditionalBranch(node, ctx) {
10999
11051
  };
11000
11052
  }
11001
11053
  function getMapLikeMethod(node) {
11002
- if (!ts12.isPropertyAccessExpression(node.expression))
11054
+ if (!ts13.isPropertyAccessExpression(node.expression))
11003
11055
  return null;
11004
11056
  const name = node.expression.name.text;
11005
11057
  if (name === "map")
@@ -11009,9 +11061,9 @@ function getMapLikeMethod(node) {
11009
11061
  return null;
11010
11062
  }
11011
11063
  function isFilterCall(node) {
11012
- if (!ts12.isCallExpression(node))
11064
+ if (!ts13.isCallExpression(node))
11013
11065
  return null;
11014
- if (!ts12.isPropertyAccessExpression(node.expression))
11066
+ if (!ts13.isPropertyAccessExpression(node.expression))
11015
11067
  return null;
11016
11068
  if (node.expression.name.text !== "filter")
11017
11069
  return null;
@@ -11023,9 +11075,9 @@ function isFilterCall(node) {
11023
11075
  };
11024
11076
  }
11025
11077
  function isSortCall(node) {
11026
- if (!ts12.isCallExpression(node))
11078
+ if (!ts13.isCallExpression(node))
11027
11079
  return null;
11028
- if (!ts12.isPropertyAccessExpression(node.expression))
11080
+ if (!ts13.isPropertyAccessExpression(node.expression))
11029
11081
  return null;
11030
11082
  const methodName = node.expression.name.text;
11031
11083
  if (methodName !== "sort" && methodName !== "toSorted")
@@ -11039,9 +11091,9 @@ function isSortCall(node) {
11039
11091
  };
11040
11092
  }
11041
11093
  function isIteratorShapeCall(node) {
11042
- if (!ts12.isCallExpression(node))
11094
+ if (!ts13.isCallExpression(node))
11043
11095
  return null;
11044
- if (!ts12.isPropertyAccessExpression(node.expression))
11096
+ if (!ts13.isPropertyAccessExpression(node.expression))
11045
11097
  return null;
11046
11098
  if (node.arguments.length !== 0)
11047
11099
  return null;
@@ -11051,11 +11103,11 @@ function isIteratorShapeCall(node) {
11051
11103
  return { array: node.expression.expression, shape: name };
11052
11104
  }
11053
11105
  function isObjectIteratorCall(node) {
11054
- if (!ts12.isCallExpression(node))
11106
+ if (!ts13.isCallExpression(node))
11055
11107
  return null;
11056
- if (!ts12.isPropertyAccessExpression(node.expression))
11108
+ if (!ts13.isPropertyAccessExpression(node.expression))
11057
11109
  return null;
11058
- if (!ts12.isIdentifier(node.expression.expression))
11110
+ if (!ts13.isIdentifier(node.expression.expression))
11059
11111
  return null;
11060
11112
  if (node.expression.expression.text !== "Object")
11061
11113
  return null;
@@ -11080,7 +11132,7 @@ function extractSortComparator(callback, _method, ctx) {
11080
11132
  ` + `(reverse the operands for descending order).`
11081
11133
  });
11082
11134
  let resolvedNode = callback;
11083
- if (ts12.isIdentifier(callback)) {
11135
+ if (ts13.isIdentifier(callback)) {
11084
11136
  const resolved = resolveSortComparatorIdentifier(callback.text, ctx);
11085
11137
  if (!resolved) {
11086
11138
  return {
@@ -11090,7 +11142,7 @@ function extractSortComparator(callback, _method, ctx) {
11090
11142
  }
11091
11143
  resolvedNode = resolved;
11092
11144
  }
11093
- if (!ts12.isArrowFunction(resolvedNode) && !ts12.isFunctionExpression(resolvedNode)) {
11145
+ if (!ts13.isArrowFunction(resolvedNode) && !ts13.isFunctionExpression(resolvedNode)) {
11094
11146
  return {
11095
11147
  result: null,
11096
11148
  unsupportedReason: "Sort comparator must be an arrow function or function expression"
@@ -11117,11 +11169,11 @@ function resolveSortComparatorIdentifier(name, ctx) {
11117
11169
  return null;
11118
11170
  if (constInfo) {
11119
11171
  const ast = parseConstInitializer(constInfo);
11120
- return ast && (ts12.isArrowFunction(ast) || ts12.isFunctionExpression(ast)) ? ast : null;
11172
+ return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
11121
11173
  }
11122
11174
  if (fnInfo) {
11123
11175
  const ast = parseFunctionInfoAsExpr(fnInfo);
11124
- return ast && (ts12.isArrowFunction(ast) || ts12.isFunctionExpression(ast)) ? ast : null;
11176
+ return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
11125
11177
  }
11126
11178
  return null;
11127
11179
  }
@@ -11132,11 +11184,11 @@ function resolveCallbackMethodFunctionReferenceIdentifier(name, analyzer) {
11132
11184
  return null;
11133
11185
  if (constInfo) {
11134
11186
  const ast = parseConstInitializer(constInfo);
11135
- return ast && (ts12.isArrowFunction(ast) || ts12.isFunctionExpression(ast)) ? ast : null;
11187
+ return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
11136
11188
  }
11137
11189
  if (fnInfo) {
11138
11190
  const ast = parseFunctionInfoAsExpr(fnInfo);
11139
- return ast && (ts12.isArrowFunction(ast) || ts12.isFunctionExpression(ast)) ? ast : null;
11191
+ return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
11140
11192
  }
11141
11193
  return null;
11142
11194
  }
@@ -11192,13 +11244,13 @@ function resolveCallbackMethodFunctionReferences(expr, analyzer, bound = EMPTY_B
11192
11244
  return visit2(expr, bound);
11193
11245
  }
11194
11246
  function extractFilterPredicate(callback, ctx) {
11195
- if (!ts12.isArrowFunction(callback))
11247
+ if (!ts13.isArrowFunction(callback))
11196
11248
  return { result: null };
11197
11249
  if (callback.parameters.length < 1)
11198
11250
  return { result: null };
11199
11251
  const firstParam = callback.parameters[0];
11200
- if (!ts12.isIdentifier(firstParam.name)) {
11201
- if (ts12.isBlock(callback.body)) {
11252
+ if (!ts13.isIdentifier(firstParam.name)) {
11253
+ if (ts13.isBlock(callback.body)) {
11202
11254
  return {
11203
11255
  result: null,
11204
11256
  unsupportedReason: "Block body in a destructured filter param is not supported. Workaround: use an expression-body arrow, or add /* @client */."
@@ -11218,7 +11270,7 @@ function extractFilterPredicate(callback, ctx) {
11218
11270
  return { result: null };
11219
11271
  }
11220
11272
  const param = firstParam.name.getText(ctx.sourceFile);
11221
- if (ts12.isBlock(callback.body)) {
11273
+ if (ts13.isBlock(callback.body)) {
11222
11274
  const raw2 = ctx.getJS(callback.body);
11223
11275
  const statements = parseBlockBody(callback.body, ctx.sourceFile, (n) => ctx.getJS(n));
11224
11276
  if (!statements) {
@@ -11244,7 +11296,7 @@ function extractFilterPredicate(callback, ctx) {
11244
11296
  return { result: { param, predicate, raw } };
11245
11297
  }
11246
11298
  function extractLoopParamBindings(pattern) {
11247
- if (ts12.isIdentifier(pattern))
11299
+ if (ts13.isIdentifier(pattern))
11248
11300
  return null;
11249
11301
  const bindings = [];
11250
11302
  let unsupported = false;
@@ -11253,7 +11305,7 @@ function extractLoopParamBindings(pattern) {
11253
11305
  return false;
11254
11306
  for (let i = 0;i < key.length; ) {
11255
11307
  const cp = key.codePointAt(i);
11256
- const ok = i === 0 ? ts12.isIdentifierStart(cp, ts12.ScriptTarget.Latest) : ts12.isIdentifierPart(cp, ts12.ScriptTarget.Latest);
11308
+ const ok = i === 0 ? ts13.isIdentifierStart(cp, ts13.ScriptTarget.Latest) : ts13.isIdentifierPart(cp, ts13.ScriptTarget.Latest);
11257
11309
  if (!ok)
11258
11310
  return false;
11259
11311
  i += cp > 65535 ? 2 : 1;
@@ -11266,17 +11318,17 @@ function extractLoopParamBindings(pattern) {
11266
11318
  const walk = (p, prefix, segments) => {
11267
11319
  if (unsupported)
11268
11320
  return;
11269
- if (ts12.isArrayBindingPattern(p)) {
11321
+ if (ts13.isArrayBindingPattern(p)) {
11270
11322
  const elements2 = p.elements;
11271
11323
  for (let index = 0;index < elements2.length; index++) {
11272
11324
  if (unsupported)
11273
11325
  return;
11274
11326
  const el = elements2[index];
11275
- if (ts12.isOmittedExpression(el))
11327
+ if (ts13.isOmittedExpression(el))
11276
11328
  continue;
11277
11329
  if (el.dotDotDotToken) {
11278
11330
  internalInvariant(index === elements2.length - 1, "extractLoopParamBindings: array rest token in non-final position (parser should reject)");
11279
- internalInvariant(ts12.isIdentifier(el.name), "extractLoopParamBindings: array rest target is not an identifier (parser should reject)");
11331
+ internalInvariant(ts13.isIdentifier(el.name), "extractLoopParamBindings: array rest target is not an identifier (parser should reject)");
11280
11332
  bindings.push({
11281
11333
  name: el.name.text,
11282
11334
  path: prefix,
@@ -11287,7 +11339,7 @@ function extractLoopParamBindings(pattern) {
11287
11339
  }
11288
11340
  const path3 = `${prefix}[${index}]`;
11289
11341
  const nextSegments = [...segments, { kind: "index", index }];
11290
- if (ts12.isIdentifier(el.name)) {
11342
+ if (ts13.isIdentifier(el.name)) {
11291
11343
  bindings.push({ name: el.name.text, path: path3, segments: nextSegments });
11292
11344
  } else {
11293
11345
  walk(el.name, path3, nextSegments);
@@ -11303,7 +11355,7 @@ function extractLoopParamBindings(pattern) {
11303
11355
  const el = elements[i];
11304
11356
  if (el.dotDotDotToken) {
11305
11357
  internalInvariant(i === elements.length - 1, "extractLoopParamBindings: object rest token in non-final position (parser should reject)");
11306
- internalInvariant(ts12.isIdentifier(el.name), "extractLoopParamBindings: object rest target is not an identifier (parser should reject)");
11358
+ internalInvariant(ts13.isIdentifier(el.name), "extractLoopParamBindings: object rest target is not an identifier (parser should reject)");
11307
11359
  bindings.push({
11308
11360
  name: el.name.text,
11309
11361
  path: prefix,
@@ -11315,17 +11367,17 @@ function extractLoopParamBindings(pattern) {
11315
11367
  let keyText = null;
11316
11368
  if (el.propertyName) {
11317
11369
  const pn = el.propertyName;
11318
- if (ts12.isIdentifier(pn))
11370
+ if (ts13.isIdentifier(pn))
11319
11371
  keyText = pn.text;
11320
- else if (ts12.isStringLiteral(pn))
11372
+ else if (ts13.isStringLiteral(pn))
11321
11373
  keyText = pn.text;
11322
- else if (ts12.isNumericLiteral(pn))
11374
+ else if (ts13.isNumericLiteral(pn))
11323
11375
  keyText = pn.text;
11324
11376
  else {
11325
11377
  unsupported = true;
11326
11378
  return;
11327
11379
  }
11328
- } else if (ts12.isIdentifier(el.name)) {
11380
+ } else if (ts13.isIdentifier(el.name)) {
11329
11381
  keyText = el.name.text;
11330
11382
  } else {
11331
11383
  unsupported = true;
@@ -11335,14 +11387,14 @@ function extractLoopParamBindings(pattern) {
11335
11387
  collectedKeys.push({ key: keyText, isIdent: keyIsIdent });
11336
11388
  const path3 = appendDotAccess(prefix, keyText);
11337
11389
  const nextSegments = [...segments, { kind: "field", key: keyText, isIdent: keyIsIdent }];
11338
- if (ts12.isIdentifier(el.name)) {
11390
+ if (ts13.isIdentifier(el.name)) {
11339
11391
  bindings.push({ name: el.name.text, path: path3, segments: nextSegments });
11340
11392
  } else {
11341
11393
  walk(el.name, path3, nextSegments);
11342
11394
  }
11343
11395
  }
11344
11396
  };
11345
- if (ts12.isArrayBindingPattern(pattern) || ts12.isObjectBindingPattern(pattern)) {
11397
+ if (ts13.isArrayBindingPattern(pattern) || ts13.isObjectBindingPattern(pattern)) {
11346
11398
  walk(pattern, "", []);
11347
11399
  if (unsupported)
11348
11400
  return { unsupported: true };
@@ -11352,7 +11404,7 @@ function extractLoopParamBindings(pattern) {
11352
11404
  }
11353
11405
  function findKeyJsxAttribute(opening) {
11354
11406
  for (const prop of opening.attributes.properties) {
11355
- if (ts12.isJsxAttribute(prop) && prop.name.getText() === "key") {
11407
+ if (ts13.isJsxAttribute(prop) && prop.name.getText() === "key") {
11356
11408
  return prop;
11357
11409
  }
11358
11410
  }
@@ -11397,7 +11449,7 @@ function keyAttrValueToExpr(v) {
11397
11449
  function normalizeKeyExpr(expr) {
11398
11450
  let out = "";
11399
11451
  for (const tok of iterateJsTokens(expr)) {
11400
- if (tok.kind === ts12.SyntaxKind.WhitespaceTrivia || tok.kind === ts12.SyntaxKind.NewLineTrivia) {
11452
+ if (tok.kind === ts13.SyntaxKind.WhitespaceTrivia || tok.kind === ts13.SyntaxKind.NewLineTrivia) {
11401
11453
  continue;
11402
11454
  }
11403
11455
  out += expr.slice(tok.pos, tok.end);
@@ -11409,13 +11461,13 @@ function conditionalHasExplicitNullishBranch(cond) {
11409
11461
  }
11410
11462
  function branchHasExplicitNullish(branch) {
11411
11463
  let b = branch;
11412
- while (ts12.isParenthesizedExpression(b))
11464
+ while (ts13.isParenthesizedExpression(b))
11413
11465
  b = b.expression;
11414
- if (b.kind === ts12.SyntaxKind.NullKeyword)
11466
+ if (b.kind === ts13.SyntaxKind.NullKeyword)
11415
11467
  return true;
11416
- if (ts12.isIdentifier(b) && b.text === "undefined")
11468
+ if (ts13.isIdentifier(b) && b.text === "undefined")
11417
11469
  return true;
11418
- if (ts12.isConditionalExpression(b))
11470
+ if (ts13.isConditionalExpression(b))
11419
11471
  return conditionalHasExplicitNullishBranch(b);
11420
11472
  return false;
11421
11473
  }
@@ -11424,26 +11476,26 @@ function classifyKeyProblem(keyAttr, checker) {
11424
11476
  return "missing";
11425
11477
  if (!keyAttr.initializer)
11426
11478
  return "missing";
11427
- if (ts12.isJsxExpression(keyAttr.initializer) && !keyAttr.initializer.expression) {
11479
+ if (ts13.isJsxExpression(keyAttr.initializer) && !keyAttr.initializer.expression) {
11428
11480
  return "missing";
11429
11481
  }
11430
11482
  let expr;
11431
- if (ts12.isStringLiteral(keyAttr.initializer)) {
11483
+ if (ts13.isStringLiteral(keyAttr.initializer)) {
11432
11484
  return null;
11433
- } else if (ts12.isJsxExpression(keyAttr.initializer)) {
11485
+ } else if (ts13.isJsxExpression(keyAttr.initializer)) {
11434
11486
  expr = keyAttr.initializer.expression;
11435
11487
  }
11436
11488
  if (!expr)
11437
11489
  return null;
11438
- if (expr.kind === ts12.SyntaxKind.NullKeyword)
11490
+ if (expr.kind === ts13.SyntaxKind.NullKeyword)
11439
11491
  return null;
11440
- if (ts12.isIdentifier(expr) && expr.text === "undefined")
11492
+ if (ts13.isIdentifier(expr) && expr.text === "undefined")
11441
11493
  return null;
11442
- if (ts12.isConditionalExpression(expr) && conditionalHasExplicitNullishBranch(expr))
11494
+ if (ts13.isConditionalExpression(expr) && conditionalHasExplicitNullishBranch(expr))
11443
11495
  return null;
11444
11496
  if (checker) {
11445
11497
  const type = checker.getTypeAtLocation(expr);
11446
- const isNullable = type.isUnion() ? type.types.some((t) => (t.flags & (ts12.TypeFlags.Null | ts12.TypeFlags.Undefined | ts12.TypeFlags.Void)) !== 0) : (type.flags & (ts12.TypeFlags.Null | ts12.TypeFlags.Undefined | ts12.TypeFlags.Void)) !== 0;
11498
+ const isNullable = type.isUnion() ? type.types.some((t) => (t.flags & (ts13.TypeFlags.Null | ts13.TypeFlags.Undefined | ts13.TypeFlags.Void)) !== 0) : (type.flags & (ts13.TypeFlags.Null | ts13.TypeFlags.Undefined | ts13.TypeFlags.Void)) !== 0;
11447
11499
  if (isNullable)
11448
11500
  return "nullable-type";
11449
11501
  }
@@ -11469,81 +11521,81 @@ function checkLoopKey(callback, ctx, isNested) {
11469
11521
  ctx.analyzer.errors.push(createError(errorCode, getSourceLocation(locNode, ctx.sourceFile, ctx.filePath), { suggestion: { message: keyErrorSuggestion(problem) } }));
11470
11522
  }
11471
11523
  let body = callback.body;
11472
- if (ts12.isBlock(body)) {
11473
- const ret = body.statements.find((s) => ts12.isReturnStatement(s) && s.expression != null);
11524
+ if (ts13.isBlock(body)) {
11525
+ const ret = body.statements.find((s) => ts13.isReturnStatement(s) && s.expression != null);
11474
11526
  if (!ret?.expression)
11475
11527
  return;
11476
11528
  body = ret.expression;
11477
11529
  }
11478
- while (ts12.isParenthesizedExpression(body))
11530
+ while (ts13.isParenthesizedExpression(body))
11479
11531
  body = body.expression;
11480
11532
  function checkJsxOperand(node) {
11481
11533
  let n = node;
11482
- while (ts12.isParenthesizedExpression(n))
11534
+ while (ts13.isParenthesizedExpression(n))
11483
11535
  n = n.expression;
11484
- if (ts12.isJsxElement(n))
11536
+ if (ts13.isJsxElement(n))
11485
11537
  checkOpening(n.openingElement);
11486
- else if (ts12.isJsxSelfClosingElement(n))
11538
+ else if (ts13.isJsxSelfClosingElement(n))
11487
11539
  checkOpening(n);
11488
11540
  }
11489
- if (ts12.isConditionalExpression(body)) {
11541
+ if (ts13.isConditionalExpression(body)) {
11490
11542
  checkJsxOperand(body.whenTrue);
11491
11543
  checkJsxOperand(body.whenFalse);
11492
11544
  return;
11493
11545
  }
11494
- if (ts12.isBinaryExpression(body) && (body.operatorToken.kind === ts12.SyntaxKind.AmpersandAmpersandToken || body.operatorToken.kind === ts12.SyntaxKind.BarBarToken || body.operatorToken.kind === ts12.SyntaxKind.QuestionQuestionToken)) {
11546
+ if (ts13.isBinaryExpression(body) && (body.operatorToken.kind === ts13.SyntaxKind.AmpersandAmpersandToken || body.operatorToken.kind === ts13.SyntaxKind.BarBarToken || body.operatorToken.kind === ts13.SyntaxKind.QuestionQuestionToken)) {
11495
11547
  checkJsxOperand(body.left);
11496
11548
  checkJsxOperand(body.right);
11497
11549
  return;
11498
11550
  }
11499
- if (ts12.isJsxElement(body)) {
11551
+ if (ts13.isJsxElement(body)) {
11500
11552
  checkOpening(body.openingElement);
11501
11553
  return;
11502
11554
  }
11503
- if (ts12.isJsxSelfClosingElement(body)) {
11555
+ if (ts13.isJsxSelfClosingElement(body)) {
11504
11556
  checkOpening(body);
11505
11557
  return;
11506
11558
  }
11507
11559
  }
11508
11560
  function flatMapProjectionCall(body) {
11509
11561
  let expr;
11510
- if (ts12.isBlock(body)) {
11562
+ if (ts13.isBlock(body)) {
11511
11563
  const real = body.statements;
11512
- if (real.length !== 1 || !ts12.isReturnStatement(real[0]) || !real[0].expression)
11564
+ if (real.length !== 1 || !ts13.isReturnStatement(real[0]) || !real[0].expression)
11513
11565
  return null;
11514
11566
  expr = real[0].expression;
11515
11567
  } else {
11516
11568
  expr = body;
11517
11569
  }
11518
- while (ts12.isParenthesizedExpression(expr))
11570
+ while (ts13.isParenthesizedExpression(expr))
11519
11571
  expr = expr.expression;
11520
- if (!ts12.isCallExpression(expr))
11572
+ if (!ts13.isCallExpression(expr))
11521
11573
  return null;
11522
11574
  if (!getMapLikeMethod(expr))
11523
11575
  return null;
11524
11576
  const cb = expr.arguments[0];
11525
- if (!cb || !ts12.isArrowFunction(cb) && !ts12.isFunctionExpression(cb))
11577
+ if (!cb || !ts13.isArrowFunction(cb) && !ts13.isFunctionExpression(cb))
11526
11578
  return null;
11527
11579
  for (const p of cb.parameters) {
11528
- if (!ts12.isIdentifier(p.name))
11580
+ if (!ts13.isIdentifier(p.name))
11529
11581
  return null;
11530
11582
  }
11531
11583
  let innerBody = cb.body;
11532
- if (ts12.isBlock(innerBody)) {
11533
- const ret = innerBody.statements.find((s) => ts12.isReturnStatement(s) && s.expression != null);
11584
+ if (ts13.isBlock(innerBody)) {
11585
+ const ret = innerBody.statements.find((s) => ts13.isReturnStatement(s) && s.expression != null);
11534
11586
  if (innerBody.statements.length !== 1 || !ret?.expression)
11535
11587
  return null;
11536
11588
  innerBody = ret.expression;
11537
11589
  }
11538
- while (ts12.isParenthesizedExpression(innerBody))
11590
+ while (ts13.isParenthesizedExpression(innerBody))
11539
11591
  innerBody = innerBody.expression;
11540
11592
  const isElementish = (n) => {
11541
11593
  let m = n;
11542
- while (ts12.isParenthesizedExpression(m))
11594
+ while (ts13.isParenthesizedExpression(m))
11543
11595
  m = m.expression;
11544
- if (ts12.isJsxElement(m) || ts12.isJsxSelfClosingElement(m))
11596
+ if (ts13.isJsxElement(m) || ts13.isJsxSelfClosingElement(m))
11545
11597
  return leafIsWirelessElement(m);
11546
- if (ts12.isConditionalExpression(m))
11598
+ if (ts13.isConditionalExpression(m))
11547
11599
  return isElementish(m.whenTrue) && isElementish(m.whenFalse);
11548
11600
  return false;
11549
11601
  };
@@ -11556,19 +11608,19 @@ function leafIsWirelessElement(el) {
11556
11608
  const visit2 = (n) => {
11557
11609
  if (!ok)
11558
11610
  return;
11559
- if (ts12.isJsxOpeningElement(n) || ts12.isJsxSelfClosingElement(n)) {
11611
+ if (ts13.isJsxOpeningElement(n) || ts13.isJsxSelfClosingElement(n)) {
11560
11612
  const tagNode = n.tagName;
11561
- const isIntrinsic = ts12.isIdentifier(tagNode) ? !/^[A-Z]/.test(tagNode.text) : ts12.isJsxNamespacedName(tagNode);
11613
+ const isIntrinsic = ts13.isIdentifier(tagNode) ? !/^[A-Z]/.test(tagNode.text) : ts13.isJsxNamespacedName(tagNode);
11562
11614
  if (!isIntrinsic) {
11563
11615
  ok = false;
11564
11616
  return;
11565
11617
  }
11566
11618
  for (const attr of n.attributes.properties) {
11567
- if (ts12.isJsxSpreadAttribute(attr)) {
11619
+ if (ts13.isJsxSpreadAttribute(attr)) {
11568
11620
  ok = false;
11569
11621
  return;
11570
11622
  }
11571
- if (ts12.isJsxAttribute(attr)) {
11623
+ if (ts13.isJsxAttribute(attr)) {
11572
11624
  const name = attr.name.getText();
11573
11625
  if (/^on[A-Z]/.test(name)) {
11574
11626
  ok = false;
@@ -11577,11 +11629,11 @@ function leafIsWirelessElement(el) {
11577
11629
  }
11578
11630
  }
11579
11631
  }
11580
- if (ts12.isCallExpression(n) && getMapLikeMethod(n) && containsJsxInExpression(n)) {
11632
+ if (ts13.isCallExpression(n) && getMapLikeMethod(n) && containsJsxInExpression(n)) {
11581
11633
  ok = false;
11582
11634
  return;
11583
11635
  }
11584
- ts12.forEachChild(n, visit2);
11636
+ ts13.forEachChild(n, visit2);
11585
11637
  };
11586
11638
  visit2(el);
11587
11639
  return ok;
@@ -11761,7 +11813,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
11761
11813
  let children = [];
11762
11814
  let paramBindings;
11763
11815
  let flatMapCallback;
11764
- if (ts12.isArrowFunction(callback)) {
11816
+ if (ts13.isArrowFunction(callback)) {
11765
11817
  if (callback.parameters.length > 0) {
11766
11818
  const firstParam = callback.parameters[0];
11767
11819
  param = firstParam.name.getText(ctx.sourceFile);
@@ -11769,9 +11821,9 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
11769
11821
  paramType = firstParam.type.getText(ctx.sourceFile);
11770
11822
  }
11771
11823
  const isEntriesShape = iterationShape === "entries" || objectIteration === "entries";
11772
- if (isEntriesShape && ts12.isArrayBindingPattern(firstParam.name)) {
11773
- const elements = firstParam.name.elements.filter((el) => !ts12.isOmittedExpression(el));
11774
- if (elements.length === 2 && ts12.isBindingElement(elements[0]) && ts12.isIdentifier(elements[0].name) && ts12.isBindingElement(elements[1]) && ts12.isIdentifier(elements[1].name)) {
11824
+ if (isEntriesShape && ts13.isArrayBindingPattern(firstParam.name)) {
11825
+ const elements = firstParam.name.elements.filter((el) => !ts13.isOmittedExpression(el));
11826
+ if (elements.length === 2 && ts13.isBindingElement(elements[0]) && ts13.isIdentifier(elements[0].name) && ts13.isBindingElement(elements[1]) && ts13.isIdentifier(elements[1].name)) {
11775
11827
  index = elements[0].name.text;
11776
11828
  param = elements[1].name.text;
11777
11829
  } else {
@@ -11802,10 +11854,10 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
11802
11854
  ctx.scope = ctx.scope.enterLoopRow({ param, index, paramBindings });
11803
11855
  ctx.loopDepth++;
11804
11856
  const tryTransformRenderableBody = (expr) => {
11805
- if (!ts12.isBinaryExpression(expr))
11857
+ if (!ts13.isBinaryExpression(expr))
11806
11858
  return;
11807
11859
  const op = expr.operatorToken.kind;
11808
- if (op !== ts12.SyntaxKind.AmpersandAmpersandToken && op !== ts12.SyntaxKind.BarBarToken && op !== ts12.SyntaxKind.QuestionQuestionToken) {
11860
+ if (op !== ts13.SyntaxKind.AmpersandAmpersandToken && op !== ts13.SyntaxKind.BarBarToken && op !== ts13.SyntaxKind.QuestionQuestionToken) {
11809
11861
  return;
11810
11862
  }
11811
11863
  if (!containsJsxInExpression(expr) && !callsJsxHelper(expr, ctx))
@@ -11815,33 +11867,33 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
11815
11867
  children = [transformed];
11816
11868
  };
11817
11869
  const body = callback.body;
11818
- if (ts12.isJsxElement(body) || ts12.isJsxSelfClosingElement(body) || ts12.isJsxFragment(body)) {
11870
+ if (ts13.isJsxElement(body) || ts13.isJsxSelfClosingElement(body) || ts13.isJsxFragment(body)) {
11819
11871
  const transformed = transformNode(body, ctx);
11820
11872
  if (transformed) {
11821
11873
  children = [transformed];
11822
11874
  }
11823
- } else if (ts12.isConditionalExpression(body)) {
11875
+ } else if (ts13.isConditionalExpression(body)) {
11824
11876
  children = [transformConditional(body, ctx)];
11825
- } else if (ts12.isParenthesizedExpression(body)) {
11877
+ } else if (ts13.isParenthesizedExpression(body)) {
11826
11878
  let inner = body.expression;
11827
- while (ts12.isParenthesizedExpression(inner)) {
11879
+ while (ts13.isParenthesizedExpression(inner)) {
11828
11880
  inner = inner.expression;
11829
11881
  }
11830
- if (ts12.isJsxElement(inner) || ts12.isJsxSelfClosingElement(inner) || ts12.isJsxFragment(inner)) {
11882
+ if (ts13.isJsxElement(inner) || ts13.isJsxSelfClosingElement(inner) || ts13.isJsxFragment(inner)) {
11831
11883
  const transformed = transformNode(inner, ctx);
11832
11884
  if (transformed) {
11833
11885
  children = [transformed];
11834
11886
  }
11835
- } else if (ts12.isConditionalExpression(inner)) {
11887
+ } else if (ts13.isConditionalExpression(inner)) {
11836
11888
  children = [transformConditional(inner, ctx)];
11837
- } else if (method === "flatMap" && ts12.isArrayLiteralExpression(inner)) {
11889
+ } else if (method === "flatMap" && ts13.isArrayLiteralExpression(inner)) {
11838
11890
  children = transformArrayLiteralChildren(inner, ctx);
11839
11891
  } else {
11840
11892
  tryTransformRenderableBody(inner);
11841
11893
  }
11842
- } else if (method === "flatMap" && ts12.isArrayLiteralExpression(body)) {
11894
+ } else if (method === "flatMap" && ts13.isArrayLiteralExpression(body)) {
11843
11895
  children = transformArrayLiteralChildren(body, ctx);
11844
- } else if (ts12.isBlock(body)) {
11896
+ } else if (ts13.isBlock(body)) {
11845
11897
  const multiReturn = method !== "flatMap" ? extractMultiReturnJsxBranches(body, true) : null;
11846
11898
  if (multiReturn && multiReturn.branches.length > 0) {
11847
11899
  const loc = getSourceLocation(body, ctx.sourceFile, ctx.filePath);
@@ -11859,7 +11911,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
11859
11911
  }
11860
11912
  }
11861
11913
  }
11862
- const returnStmt = children.length === 0 ? body.statements.find((s) => ts12.isReturnStatement(s) && s.expression != null) : undefined;
11914
+ const returnStmt = children.length === 0 ? body.statements.find((s) => ts13.isReturnStatement(s) && s.expression != null) : undefined;
11863
11915
  let rowScopeBeforePreamble = null;
11864
11916
  if (returnStmt) {
11865
11917
  const preambleNames = new Set;
@@ -11880,10 +11932,10 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
11880
11932
  }
11881
11933
  if (returnStmt && returnStmt.expression) {
11882
11934
  let returnExpr = returnStmt.expression;
11883
- while (ts12.isParenthesizedExpression(returnExpr)) {
11935
+ while (ts13.isParenthesizedExpression(returnExpr)) {
11884
11936
  returnExpr = returnExpr.expression;
11885
11937
  }
11886
- if (ts12.isJsxElement(returnExpr) || ts12.isJsxSelfClosingElement(returnExpr) || ts12.isJsxFragment(returnExpr)) {
11938
+ if (ts13.isJsxElement(returnExpr) || ts13.isJsxSelfClosingElement(returnExpr) || ts13.isJsxFragment(returnExpr)) {
11887
11939
  const transformed = transformNode(returnExpr, ctx);
11888
11940
  if (transformed) {
11889
11941
  children = [transformed];
@@ -11965,7 +12017,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
11965
12017
  }
11966
12018
  }
11967
12019
  }
11968
- if (method === "flatMap" && children.length === 0 && !flatMapCallback && !ts12.isBlock(body)) {
12020
+ if (method === "flatMap" && children.length === 0 && !flatMapCallback && !ts13.isBlock(body)) {
11969
12021
  flatMapCallback = buildFlatMapCallback(callback, body, ctx);
11970
12022
  }
11971
12023
  if (flatMapCallback)
@@ -11983,7 +12035,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
11983
12035
  }
11984
12036
  if (children.length === 0 && !flatMapCallback) {
11985
12037
  const cb = node.arguments[0];
11986
- const cbBody = cb && (ts12.isArrowFunction(cb) || ts12.isFunctionExpression(cb)) ? cb.body : undefined;
12038
+ const cbBody = cb && (ts13.isArrowFunction(cb) || ts13.isFunctionExpression(cb)) ? cb.body : undefined;
11987
12039
  if (cbBody && containsJsxInExpression(cbBody) && ctx.analyzer.errors.length === diagCountAtEntry) {
11988
12040
  ctx.analyzer.errors.push(createError(ErrorCodes.UNSUPPORTED_JSX_PATTERN, getSourceLocation(cbBody, ctx.sourceFile, ctx.filePath), {
11989
12041
  message: `A .${method}() callback that builds JSX in this shape cannot be ` + "compiled — the JSX would leak verbatim into the client bundle. " + "Recognized bodies: a JSX element/fragment, a ternary or " + "&& / || / ?? expression, an array literal (flatMap), or a block " + "body whose return the compiler can lower.",
@@ -11994,7 +12046,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
11994
12046
  }
11995
12047
  return null;
11996
12048
  }
11997
- if (ts12.isArrowFunction(node.arguments[0]) && children.length > 0) {
12049
+ if (ts13.isArrowFunction(node.arguments[0]) && children.length > 0) {
11998
12050
  checkLoopKey(node.arguments[0], ctx, isNested);
11999
12051
  }
12000
12052
  const itemConditional = children.length > 0 ? loopBodyItemConditional(children) : null;
@@ -12048,6 +12100,9 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
12048
12100
  const preambleRegions = preamble && !isStaticArray ? collectPreambleRegions(children, new Set(preamble.declaredNames), ctx) : undefined;
12049
12101
  if (preamble && !isStaticArray) {
12050
12102
  markPreambleAttrSlots(children, new Set(preamble.declaredNames), ctx);
12103
+ if (preamble.reactiveNames && preamble.reactiveNames.length > 0) {
12104
+ markPreambleConditionalReactivity(children, new Set(preamble.reactiveNames), ctx);
12105
+ }
12051
12106
  }
12052
12107
  const nestedComponents = collectNestedComponents(children).filter((c) => c.name !== childComponent?.name);
12053
12108
  return {
@@ -12091,12 +12146,12 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
12091
12146
  function transformArrayLiteralChildren(arrayLiteral, ctx) {
12092
12147
  const children = [];
12093
12148
  for (const element of arrayLiteral.elements) {
12094
- if (ts12.isSpreadElement(element))
12149
+ if (ts13.isSpreadElement(element))
12095
12150
  continue;
12096
12151
  let inner = element;
12097
- while (ts12.isParenthesizedExpression(inner))
12152
+ while (ts13.isParenthesizedExpression(inner))
12098
12153
  inner = inner.expression;
12099
- if (ts12.isJsxElement(inner) || ts12.isJsxSelfClosingElement(inner) || ts12.isJsxFragment(inner)) {
12154
+ if (ts13.isJsxElement(inner) || ts13.isJsxSelfClosingElement(inner) || ts13.isJsxFragment(inner)) {
12100
12155
  const transformed = transformNode(inner, ctx);
12101
12156
  if (transformed)
12102
12157
  children.push(transformed);
@@ -12105,7 +12160,7 @@ function transformArrayLiteralChildren(arrayLiteral, ctx) {
12105
12160
  return children;
12106
12161
  }
12107
12162
  function containsJsx(node) {
12108
- if (ts12.isJsxElement(node) || ts12.isJsxSelfClosingElement(node) || ts12.isJsxFragment(node))
12163
+ if (ts13.isJsxElement(node) || ts13.isJsxSelfClosingElement(node) || ts13.isJsxFragment(node))
12109
12164
  return true;
12110
12165
  let found = false;
12111
12166
  node.forEachChild((child) => {
@@ -12121,7 +12176,7 @@ function buildFlatMapCallback(callback, body, ctx) {
12121
12176
  const leafIrs = [];
12122
12177
  let refusalNode;
12123
12178
  const collectJsx = (n, underTemplate) => {
12124
- if (ts12.isJsxElement(n) || ts12.isJsxSelfClosingElement(n) || ts12.isJsxFragment(n)) {
12179
+ if (ts13.isJsxElement(n) || ts13.isJsxSelfClosingElement(n) || ts13.isJsxFragment(n)) {
12125
12180
  if (underTemplate)
12126
12181
  refusalNode ??= n;
12127
12182
  leafSpans.push({ start: n.getStart(ctx.sourceFile), end: n.getEnd() });
@@ -12129,7 +12184,7 @@ function buildFlatMapCallback(callback, body, ctx) {
12129
12184
  leafIrs.push(ir ?? { type: "text", value: "", loc: getSourceLocation(n, ctx.sourceFile, ctx.filePath) });
12130
12185
  return;
12131
12186
  }
12132
- const inTemplate = underTemplate || ts12.isTemplateExpression(n) || ts12.isTaggedTemplateExpression(n);
12187
+ const inTemplate = underTemplate || ts13.isTemplateExpression(n) || ts13.isTaggedTemplateExpression(n);
12133
12188
  n.forEachChild((c) => collectJsx(c, inTemplate));
12134
12189
  };
12135
12190
  collectJsx(body, false);
@@ -12305,6 +12360,33 @@ function markPreambleAttrSlots(nodes, declared, ctx) {
12305
12360
  };
12306
12361
  visit2(nodes);
12307
12362
  }
12363
+ function markPreambleConditionalReactivity(nodes, reactiveNames, ctx) {
12364
+ if (reactiveNames.size === 0)
12365
+ return;
12366
+ const visit2 = (list) => {
12367
+ for (const node of list) {
12368
+ switch (node.type) {
12369
+ case "element":
12370
+ case "fragment":
12371
+ visit2(node.children);
12372
+ break;
12373
+ case "conditional": {
12374
+ if (!node.reactive) {
12375
+ const refs = extractFreeIdentifiersFromText(node.condition);
12376
+ if ([...refs].some((r) => reactiveNames.has(r))) {
12377
+ node.reactive = true;
12378
+ if (!node.slotId)
12379
+ node.slotId = generateSlotId(ctx);
12380
+ }
12381
+ }
12382
+ visit2([node.whenTrue, ...node.whenFalse ? [node.whenFalse] : []]);
12383
+ break;
12384
+ }
12385
+ }
12386
+ }
12387
+ };
12388
+ visit2(nodes);
12389
+ }
12308
12390
  function attrValueText(value) {
12309
12391
  if (value.kind === "expression")
12310
12392
  return value.expr;
@@ -12320,24 +12402,46 @@ function attrValueText(value) {
12320
12402
  return out.join(" ");
12321
12403
  }
12322
12404
  function collectBindingNames2(name, out) {
12323
- if (ts12.isIdentifier(name)) {
12405
+ if (ts13.isIdentifier(name)) {
12324
12406
  out.add(name.text);
12325
12407
  return;
12326
12408
  }
12327
12409
  for (const el of name.elements) {
12328
- if (ts12.isBindingElement(el))
12410
+ if (ts13.isBindingElement(el))
12329
12411
  collectBindingNames2(el.name, out);
12330
12412
  }
12331
12413
  }
12332
12414
  function collectPreambleDeclaredNames(stmt, out) {
12333
- if (ts12.isVariableStatement(stmt)) {
12415
+ if (ts13.isVariableStatement(stmt)) {
12334
12416
  for (const decl of stmt.declarationList.declarations) {
12335
12417
  collectBindingNames2(decl.name, out);
12336
12418
  }
12337
- } else if (ts12.isFunctionDeclaration(stmt) && stmt.name) {
12419
+ } else if (ts13.isFunctionDeclaration(stmt) && stmt.name) {
12338
12420
  out.add(stmt.name.text);
12339
12421
  }
12340
12422
  }
12423
+ function computePreambleReactiveNames(statements, ctx) {
12424
+ const reactiveNames = new Set;
12425
+ for (const stmt of statements) {
12426
+ if (!ts13.isVariableStatement(stmt))
12427
+ continue;
12428
+ for (const decl of stmt.declarationList.declarations) {
12429
+ if (!decl.initializer)
12430
+ continue;
12431
+ const boundNames = new Set;
12432
+ collectBindingNames2(decl.name, boundNames);
12433
+ const initText = ctx.getJS(decl.initializer);
12434
+ const initFreeRefs = extractFreeIdentifiersFromNode(decl.initializer);
12435
+ const readsEarlierReactive = [...initFreeRefs].some((r) => reactiveNames.has(r));
12436
+ const isReactive = readsEarlierReactive || isReactiveExpression(initText, ctx, decl.initializer);
12437
+ if (isReactive) {
12438
+ for (const n of boundNames)
12439
+ reactiveNames.add(n);
12440
+ }
12441
+ }
12442
+ }
12443
+ return reactiveNames;
12444
+ }
12341
12445
  function preambleFromValueStatements(statements, ctx) {
12342
12446
  const segments = [];
12343
12447
  const typedParts = [];
@@ -12352,21 +12456,23 @@ function preambleFromValueStatements(statements, ctx) {
12352
12456
  typedParts.push(raw0.endsWith(";") ? raw0 : raw0 + ";");
12353
12457
  segments.push(tjs !== js ? { kind: "js", text: js, templateText: tjs } : { kind: "js", text: js });
12354
12458
  }
12459
+ const reactiveNames = computePreambleReactiveNames(statements, ctx);
12355
12460
  return {
12356
12461
  segments: trimPreambleSegments(segments),
12357
12462
  ssrText: tsxSourceText(typedParts.join(" ")),
12358
12463
  declaredNames: [...declared],
12359
12464
  builderNames: [],
12360
- declarations: neutralPreambleDeclarations(statements, ctx) ?? undefined
12465
+ declarations: neutralPreambleDeclarations(statements, ctx) ?? undefined,
12466
+ reactiveNames: reactiveNames.size > 0 ? [...reactiveNames] : undefined
12361
12467
  };
12362
12468
  }
12363
12469
  function neutralPreambleDeclarations(statements, ctx) {
12364
12470
  const out = [];
12365
12471
  for (const stmt of statements) {
12366
- if (!ts12.isVariableStatement(stmt))
12472
+ if (!ts13.isVariableStatement(stmt))
12367
12473
  return null;
12368
12474
  for (const decl of stmt.declarationList.declarations) {
12369
- if (!ts12.isIdentifier(decl.name))
12475
+ if (!ts13.isIdentifier(decl.name))
12370
12476
  return null;
12371
12477
  if (!decl.initializer)
12372
12478
  return null;
@@ -12399,11 +12505,11 @@ function buildPreambleSegments(statements, returnStmt, ctx) {
12399
12505
  let refusalNode;
12400
12506
  const recordBuilderTarget = (leaf, stmt) => {
12401
12507
  for (let n = leaf.parent;n && n !== stmt.parent; n = n.parent) {
12402
- if (ts12.isCallExpression(n) && ts12.isPropertyAccessExpression(n.expression) && (n.expression.name.text === "push" || n.expression.name.text === "unshift") && ts12.isIdentifier(n.expression.expression)) {
12508
+ if (ts13.isCallExpression(n) && ts13.isPropertyAccessExpression(n.expression) && (n.expression.name.text === "push" || n.expression.name.text === "unshift") && ts13.isIdentifier(n.expression.expression)) {
12403
12509
  builders.add(n.expression.expression.text);
12404
12510
  return;
12405
12511
  }
12406
- if (ts12.isVariableDeclaration(n) && ts12.isIdentifier(n.name)) {
12512
+ if (ts13.isVariableDeclaration(n) && ts13.isIdentifier(n.name)) {
12407
12513
  builders.add(n.name.text);
12408
12514
  return;
12409
12515
  }
@@ -12416,7 +12522,7 @@ function buildPreambleSegments(statements, returnStmt, ctx) {
12416
12522
  const leafSpans = [];
12417
12523
  const leafIrs = [];
12418
12524
  const collect = (n, underTemplate) => {
12419
- if (ts12.isJsxElement(n) || ts12.isJsxSelfClosingElement(n) || ts12.isJsxFragment(n)) {
12525
+ if (ts13.isJsxElement(n) || ts13.isJsxSelfClosingElement(n) || ts13.isJsxFragment(n)) {
12420
12526
  if (underTemplate)
12421
12527
  refusalNode ??= n;
12422
12528
  recordBuilderTarget(n, stmt);
@@ -12427,7 +12533,7 @@ function buildPreambleSegments(statements, returnStmt, ctx) {
12427
12533
  leafIrs.push(ir ?? { type: "text", value: "", loc: getSourceLocation(n, ctx.sourceFile, ctx.filePath) });
12428
12534
  return;
12429
12535
  }
12430
- const inTemplate = underTemplate || ts12.isTemplateExpression(n) || ts12.isTaggedTemplateExpression(n);
12536
+ const inTemplate = underTemplate || ts13.isTemplateExpression(n) || ts13.isTaggedTemplateExpression(n);
12431
12537
  n.forEachChild((c) => collect(c, inTemplate));
12432
12538
  };
12433
12539
  collect(stmt, false);
@@ -12531,13 +12637,13 @@ function expandSpreadAttribute(attr, ctx) {
12531
12637
  }];
12532
12638
  }
12533
12639
  function attrFreeIdentifiers(attr) {
12534
- if (!attr.initializer || !ts12.isJsxExpression(attr.initializer) || !attr.initializer.expression) {
12640
+ if (!attr.initializer || !ts13.isJsxExpression(attr.initializer) || !attr.initializer.expression) {
12535
12641
  return;
12536
12642
  }
12537
12643
  return extractFreeIdentifiersFromNode(attr.initializer.expression);
12538
12644
  }
12539
12645
  function computeReactivityFlags(attr, ctx) {
12540
- if (!attr.initializer || !ts12.isJsxExpression(attr.initializer) || !attr.initializer.expression) {
12646
+ if (!attr.initializer || !ts13.isJsxExpression(attr.initializer) || !attr.initializer.expression) {
12541
12647
  return {};
12542
12648
  }
12543
12649
  const expr = attr.initializer.expression;
@@ -12563,22 +12669,22 @@ function processAttributes(attributes, ctx) {
12563
12669
  const events = [];
12564
12670
  let ref = null;
12565
12671
  for (const attr of attributes.properties) {
12566
- if (ts12.isJsxSpreadAttribute(attr)) {
12672
+ if (ts13.isJsxSpreadAttribute(attr)) {
12567
12673
  attrs.push(...expandSpreadAttribute(attr, ctx));
12568
12674
  continue;
12569
12675
  }
12570
- if (!ts12.isJsxAttribute(attr))
12676
+ if (!ts13.isJsxAttribute(attr))
12571
12677
  continue;
12572
12678
  const rawName = attr.name.getText(ctx.sourceFile);
12573
12679
  if (rawName === "ref") {
12574
- if (attr.initializer && ts12.isJsxExpression(attr.initializer) && attr.initializer.expression) {
12680
+ if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
12575
12681
  reportJsxBranchLocalInCallback(attr.initializer.expression, ctx);
12576
12682
  ref = ctx.getJS(attr.initializer.expression);
12577
12683
  }
12578
12684
  continue;
12579
12685
  }
12580
12686
  if (/^on[A-Z]/.test(rawName)) {
12581
- if (attr.initializer && ts12.isJsxExpression(attr.initializer) && attr.initializer.expression) {
12687
+ if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
12582
12688
  const eventName = rawName.slice(2).toLowerCase();
12583
12689
  reportJsxBranchLocalInCallback(attr.initializer.expression, ctx);
12584
12690
  events.push({
@@ -12593,7 +12699,7 @@ function processAttributes(attributes, ctx) {
12593
12699
  const name = toHTMLAttrName(rawName);
12594
12700
  let value = getAttributeValue(attr, ctx);
12595
12701
  let clientOnly;
12596
- if (attr.initializer && ts12.isJsxExpression(attr.initializer) && attr.initializer.expression) {
12702
+ if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
12597
12703
  if (value.kind === "expression" && value.templateExpr === undefined) {
12598
12704
  const rewritten = rewriteBarePropRefs2(value.expr, attr.initializer.expression, ctx);
12599
12705
  if (rewritten !== value.expr) {
@@ -12620,55 +12726,55 @@ function getAttributeValue(attr, ctx) {
12620
12726
  if (!attr.initializer) {
12621
12727
  return AttrValueOf.booleanAttr();
12622
12728
  }
12623
- if (ts12.isStringLiteral(attr.initializer)) {
12729
+ if (ts13.isStringLiteral(attr.initializer)) {
12624
12730
  return AttrValueOf.literal(decodeEntities(attr.initializer.text));
12625
12731
  }
12626
- if (ts12.isJsxExpression(attr.initializer) && attr.initializer.expression) {
12732
+ if (ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
12627
12733
  let expr = attr.initializer.expression;
12628
- if (ts12.isIdentifier(expr)) {
12734
+ if (ts13.isIdentifier(expr)) {
12629
12735
  const branchInit = ctx._branchScopeVars?.get(expr.text);
12630
12736
  if (branchInit && !initializerShapeContainsJsx(branchInit)) {
12631
12737
  expr = branchInit;
12632
12738
  }
12633
12739
  }
12634
12740
  expr = tryDesugarInterleaveTaggedTemplate(expr, ctx);
12635
- if (ts12.isAwaitExpression(expr)) {
12741
+ if (ts13.isAwaitExpression(expr)) {
12636
12742
  ctx.analyzer.errors.push(createError(ErrorCodes.STAGE_AWAIT_IN_TEMPLATE, getSourceLocation(expr, ctx.sourceFile, ctx.filePath)));
12637
12743
  return AttrValueOf.expression("undefined");
12638
12744
  }
12639
12745
  checkBareSignalOrMemoIdentifier(expr, ctx);
12640
- if (attr.name.getText(ctx.sourceFile) === "style" && ts12.isObjectLiteralExpression(expr)) {
12746
+ if (attr.name.getText(ctx.sourceFile) === "style" && ts13.isObjectLiteralExpression(expr)) {
12641
12747
  const cssString = tryStaticStyleObjectToCss(expr);
12642
12748
  if (cssString !== null) {
12643
12749
  return AttrValueOf.literal(cssString);
12644
12750
  }
12645
12751
  }
12646
- if (ts12.isTemplateExpression(expr)) {
12752
+ if (ts13.isTemplateExpression(expr)) {
12647
12753
  const parts = parseTemplateLiteral(expr, ctx);
12648
12754
  if (parts.some((p) => p.type === "ternary" || p.type === "lookup")) {
12649
12755
  return AttrValueOf.template(parts);
12650
12756
  }
12651
12757
  }
12652
- if (ts12.isElementAccessExpression(expr) && !ts12.isStringLiteralLike(expr.argumentExpression) && !ts12.isNumericLiteral(expr.argumentExpression)) {
12758
+ if (ts13.isElementAccessExpression(expr) && !ts13.isStringLiteralLike(expr.argumentExpression) && !ts13.isNumericLiteral(expr.argumentExpression)) {
12653
12759
  const parts = tryResolveTemplateSpanFromConst(expr, ctx);
12654
12760
  if (parts) {
12655
12761
  return AttrValueOf.template(parts);
12656
12762
  }
12657
12763
  }
12658
- if (ts12.isIdentifier(expr)) {
12764
+ if (ts13.isIdentifier(expr)) {
12659
12765
  const resolved = tryResolveIdentifierAsTemplateLiteral(expr, ctx);
12660
12766
  if (resolved) {
12661
12767
  return AttrValueOf.template(resolved);
12662
12768
  }
12663
12769
  }
12664
- if (ts12.isConditionalExpression(expr)) {
12770
+ if (ts13.isConditionalExpression(expr)) {
12665
12771
  const ternary = parseTernary(expr, ctx);
12666
12772
  if (ternary) {
12667
12773
  return AttrValueOf.template([ternary]);
12668
12774
  }
12669
12775
  }
12670
- if (ts12.isBinaryExpression(expr) && expr.operatorToken.kind === ts12.SyntaxKind.BarBarToken) {
12671
- if (ts12.isIdentifier(expr.right) && expr.right.text === "undefined") {
12776
+ if (ts13.isBinaryExpression(expr) && expr.operatorToken.kind === ts13.SyntaxKind.BarBarToken) {
12777
+ if (ts13.isIdentifier(expr.right) && expr.right.text === "undefined") {
12672
12778
  const baseExpr = ctx.getJS(expr.left);
12673
12779
  return AttrValueOf.expression(baseExpr, { presenceOrUndefined: true });
12674
12780
  }
@@ -12681,11 +12787,11 @@ function getAttributeValue(attr, ctx) {
12681
12787
  function tryStaticStyleObjectToCss(expr) {
12682
12788
  const parts = [];
12683
12789
  for (const prop of expr.properties) {
12684
- if (!ts12.isPropertyAssignment(prop))
12790
+ if (!ts13.isPropertyAssignment(prop))
12685
12791
  return null;
12686
- if (!ts12.isIdentifier(prop.name) && !ts12.isStringLiteral(prop.name))
12792
+ if (!ts13.isIdentifier(prop.name) && !ts13.isStringLiteral(prop.name))
12687
12793
  return null;
12688
- if (!ts12.isStringLiteral(prop.initializer))
12794
+ if (!ts13.isStringLiteral(prop.initializer))
12689
12795
  return null;
12690
12796
  const key = cssKebabCase(prop.name.text);
12691
12797
  parts.push(`${key}:${prop.initializer.text}`);
@@ -12698,7 +12804,7 @@ function parseTemplateLiteral(expr, ctx) {
12698
12804
  parts.push({ type: "string", value: expr.head.text });
12699
12805
  }
12700
12806
  for (const span of expr.templateSpans) {
12701
- if (ts12.isConditionalExpression(span.expression)) {
12807
+ if (ts13.isConditionalExpression(span.expression)) {
12702
12808
  const ternary = parseTernary(span.expression, ctx);
12703
12809
  if (ternary) {
12704
12810
  parts.push(ternary);
@@ -12724,7 +12830,7 @@ function parseTemplateLiteral(expr, ctx) {
12724
12830
  return parts;
12725
12831
  }
12726
12832
  function tryResolveTemplateSpanFromConst(expr, ctx) {
12727
- if (ts12.isIdentifier(expr)) {
12833
+ if (ts13.isIdentifier(expr)) {
12728
12834
  if (ctx.scope.isBound(expr.text))
12729
12835
  return null;
12730
12836
  const constInfo = findLocalConst(expr.text, ctx.analyzer);
@@ -12733,13 +12839,13 @@ function tryResolveTemplateSpanFromConst(expr, ctx) {
12733
12839
  const ast = parseConstInitializer(constInfo);
12734
12840
  if (!ast)
12735
12841
  return null;
12736
- if (ts12.isStringLiteral(ast) || ts12.isNoSubstitutionTemplateLiteral(ast)) {
12842
+ if (ts13.isStringLiteral(ast) || ts13.isNoSubstitutionTemplateLiteral(ast)) {
12737
12843
  return [{ type: "string", value: ast.text }];
12738
12844
  }
12739
12845
  return null;
12740
12846
  }
12741
- if (ts12.isElementAccessExpression(expr)) {
12742
- if (!ts12.isIdentifier(expr.expression))
12847
+ if (ts13.isElementAccessExpression(expr)) {
12848
+ if (!ts13.isIdentifier(expr.expression))
12743
12849
  return null;
12744
12850
  if (ctx.scope.isBound(expr.expression.text))
12745
12851
  return null;
@@ -12747,17 +12853,17 @@ function tryResolveTemplateSpanFromConst(expr, ctx) {
12747
12853
  if (!constInfo)
12748
12854
  return null;
12749
12855
  const ast = parseConstInitializer(constInfo);
12750
- if (!ast || !ts12.isObjectLiteralExpression(ast))
12856
+ if (!ast || !ts13.isObjectLiteralExpression(ast))
12751
12857
  return null;
12752
12858
  const cases = {};
12753
12859
  for (const prop of ast.properties) {
12754
- if (!ts12.isPropertyAssignment(prop))
12860
+ if (!ts13.isPropertyAssignment(prop))
12755
12861
  return null;
12756
- const keyName = prop.name && (ts12.isStringLiteral(prop.name) || ts12.isIdentifier(prop.name)) ? prop.name.text : null;
12862
+ const keyName = prop.name && (ts13.isStringLiteral(prop.name) || ts13.isIdentifier(prop.name)) ? prop.name.text : null;
12757
12863
  if (!keyName)
12758
12864
  return null;
12759
12865
  const value = prop.initializer;
12760
- if (ts12.isStringLiteral(value) || ts12.isNoSubstitutionTemplateLiteral(value)) {
12866
+ if (ts13.isStringLiteral(value) || ts13.isNoSubstitutionTemplateLiteral(value)) {
12761
12867
  cases[keyName] = value.text;
12762
12868
  } else {
12763
12869
  return null;
@@ -12804,17 +12910,17 @@ function hasDynamicTagBinding(name, sourceFile) {
12804
12910
  const visit2 = (node) => {
12805
12911
  if (found)
12806
12912
  return;
12807
- if (ts12.isVariableDeclaration(node) && ts12.isIdentifier(node.name) && node.name.text === name && node.initializer) {
12913
+ if (ts13.isVariableDeclaration(node) && ts13.isIdentifier(node.name) && node.name.text === name && node.initializer) {
12808
12914
  let init = node.initializer;
12809
- while (ts12.isAsExpression(init) || ts12.isSatisfiesExpression(init) || ts12.isParenthesizedExpression(init) || ts12.isNonNullExpression(init)) {
12915
+ while (ts13.isAsExpression(init) || ts13.isSatisfiesExpression(init) || ts13.isParenthesizedExpression(init) || ts13.isNonNullExpression(init)) {
12810
12916
  init = init.expression;
12811
12917
  }
12812
- if (ts12.isPropertyAccessExpression(init) && init.name.text === "tag") {
12918
+ if (ts13.isPropertyAccessExpression(init) && init.name.text === "tag") {
12813
12919
  found = true;
12814
12920
  return;
12815
12921
  }
12816
12922
  }
12817
- ts12.forEachChild(node, visit2);
12923
+ ts13.forEachChild(node, visit2);
12818
12924
  };
12819
12925
  visit2(sourceFile);
12820
12926
  return found;
@@ -12828,13 +12934,13 @@ function tryResolveIdentifierAsTemplateLiteral(ident, ctx) {
12828
12934
  const ast = parseConstInitializer(constInfo);
12829
12935
  if (!ast)
12830
12936
  return null;
12831
- if (ts12.isNoSubstitutionTemplateLiteral(ast) || ts12.isStringLiteral(ast)) {
12937
+ if (ts13.isNoSubstitutionTemplateLiteral(ast) || ts13.isStringLiteral(ast)) {
12832
12938
  return [{ type: "string", value: ast.text }];
12833
12939
  }
12834
- if (ts12.isElementAccessExpression(ast) && !ts12.isStringLiteralLike(ast.argumentExpression) && !ts12.isNumericLiteral(ast.argumentExpression)) {
12940
+ if (ts13.isElementAccessExpression(ast) && !ts13.isStringLiteralLike(ast.argumentExpression) && !ts13.isNumericLiteral(ast.argumentExpression)) {
12835
12941
  return tryResolveTemplateSpanFromConst(ast, ctx);
12836
12942
  }
12837
- if (!ts12.isTemplateExpression(ast))
12943
+ if (!ts13.isTemplateExpression(ast))
12838
12944
  return null;
12839
12945
  let resolvedAny = false;
12840
12946
  const parts = [];
@@ -12872,14 +12978,14 @@ function parseConstInitializerImpl(c) {
12872
12978
  if (!c.value)
12873
12979
  return null;
12874
12980
  const wrapped = `const __bf_resolve__ = (${c.value})`;
12875
- const sf = ts12.createSourceFile("__bf_resolve.ts", wrapped, ts12.ScriptTarget.Latest, true, ts12.ScriptKind.TS);
12981
+ const sf = ts13.createSourceFile("__bf_resolve.ts", wrapped, ts13.ScriptTarget.Latest, true, ts13.ScriptKind.TS);
12876
12982
  const stmt = sf.statements[0];
12877
- if (!stmt || !ts12.isVariableStatement(stmt))
12983
+ if (!stmt || !ts13.isVariableStatement(stmt))
12878
12984
  return null;
12879
12985
  const decl = stmt.declarationList.declarations[0];
12880
12986
  if (!decl?.initializer)
12881
12987
  return null;
12882
- return ts12.isParenthesizedExpression(decl.initializer) ? decl.initializer.expression : decl.initializer;
12988
+ return ts13.isParenthesizedExpression(decl.initializer) ? decl.initializer.expression : decl.initializer;
12883
12989
  }
12884
12990
  function astText(node) {
12885
12991
  return node.getText(node.getSourceFile());
@@ -12899,9 +13005,9 @@ function parseFunctionInfoAsExprImpl(fn) {
12899
13005
  const params = fn.typedParams !== undefined ? fn.typedParams : fn.params.map(formatParamWithType).join(", ");
12900
13006
  const body = fn.typedBody ?? fn.body;
12901
13007
  const wrapped = `const __bf_resolve_fn__ = function(${params}) ${body}`;
12902
- const sf = ts12.createSourceFile("__bf_resolve_fn.ts", wrapped, ts12.ScriptTarget.Latest, true, ts12.ScriptKind.TS);
13008
+ const sf = ts13.createSourceFile("__bf_resolve_fn.ts", wrapped, ts13.ScriptTarget.Latest, true, ts13.ScriptKind.TS);
12903
13009
  const stmt = sf.statements[0];
12904
- if (!stmt || !ts12.isVariableStatement(stmt))
13010
+ if (!stmt || !ts13.isVariableStatement(stmt))
12905
13011
  return null;
12906
13012
  const decl = stmt.declarationList.declarations[0];
12907
13013
  if (!decl?.initializer)
@@ -12909,9 +13015,9 @@ function parseFunctionInfoAsExprImpl(fn) {
12909
13015
  return decl.initializer;
12910
13016
  }
12911
13017
  function tryDesugarInterleaveTaggedTemplate(expr, ctx) {
12912
- if (!ts12.isTaggedTemplateExpression(expr))
13018
+ if (!ts13.isTaggedTemplateExpression(expr))
12913
13019
  return expr;
12914
- if (!ts12.isIdentifier(expr.tag))
13020
+ if (!ts13.isIdentifier(expr.tag))
12915
13021
  return expr;
12916
13022
  const resolvedTag = resolveInterleaveTagIdentifier(expr.tag.text, ctx);
12917
13023
  if (!resolvedTag)
@@ -12928,23 +13034,23 @@ function resolveInterleaveTagIdentifier(name, ctx) {
12928
13034
  return null;
12929
13035
  if (constInfo) {
12930
13036
  const ast = parseConstInitializer(constInfo);
12931
- return ast && (ts12.isArrowFunction(ast) || ts12.isFunctionExpression(ast)) ? ast : null;
13037
+ return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
12932
13038
  }
12933
13039
  if (fnInfo) {
12934
13040
  const ast = parseFunctionInfoAsExpr(fnInfo);
12935
- return ast && (ts12.isArrowFunction(ast) || ts12.isFunctionExpression(ast)) ? ast : null;
13041
+ return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
12936
13042
  }
12937
13043
  return null;
12938
13044
  }
12939
13045
  function isInterleaveTagFunction(fn) {
12940
- if (!ts12.isArrowFunction(fn) && !ts12.isFunctionExpression(fn))
13046
+ if (!ts13.isArrowFunction(fn) && !ts13.isFunctionExpression(fn))
12941
13047
  return false;
12942
13048
  if (fn.parameters.length !== 2)
12943
13049
  return false;
12944
13050
  const [partsParam, argsParam] = fn.parameters;
12945
- if (!ts12.isIdentifier(partsParam.name) || partsParam.dotDotDotToken)
13051
+ if (!ts13.isIdentifier(partsParam.name) || partsParam.dotDotDotToken)
12946
13052
  return false;
12947
- if (!ts12.isIdentifier(argsParam.name) || !argsParam.dotDotDotToken)
13053
+ if (!ts13.isIdentifier(argsParam.name) || !argsParam.dotDotDotToken)
12948
13054
  return false;
12949
13055
  const parsed = tsNodeToParsedExpr(fn);
12950
13056
  if (parsed.kind !== "arrow")
@@ -13001,7 +13107,7 @@ function isInterleaveSpanExpr(expr, i, argsName) {
13001
13107
  function buildUntaggedTemplateLiteral(node, ctx) {
13002
13108
  const template = node.template;
13003
13109
  let text;
13004
- if (ts12.isNoSubstitutionTemplateLiteral(template)) {
13110
+ if (ts13.isNoSubstitutionTemplateLiteral(template)) {
13005
13111
  text = "`" + (template.rawText ?? template.text) + "`";
13006
13112
  } else {
13007
13113
  let body = template.head.rawText ?? template.head.text;
@@ -13013,15 +13119,15 @@ function buildUntaggedTemplateLiteral(node, ctx) {
13013
13119
  text = "`" + body + "`";
13014
13120
  }
13015
13121
  const wrapped = `const __bf_resolve_tagged__ = (${text})`;
13016
- const sf = ts12.createSourceFile("__bf_resolve_tagged.tsx", wrapped, ts12.ScriptTarget.Latest, true, ts12.ScriptKind.TSX);
13122
+ const sf = ts13.createSourceFile("__bf_resolve_tagged.tsx", wrapped, ts13.ScriptTarget.Latest, true, ts13.ScriptKind.TSX);
13017
13123
  const stmt = sf.statements[0];
13018
- if (!stmt || !ts12.isVariableStatement(stmt))
13124
+ if (!stmt || !ts13.isVariableStatement(stmt))
13019
13125
  return null;
13020
13126
  const decl = stmt.declarationList.declarations[0];
13021
13127
  if (!decl?.initializer)
13022
13128
  return null;
13023
- const result = ts12.isParenthesizedExpression(decl.initializer) ? decl.initializer.expression : decl.initializer;
13024
- if (!ts12.isTemplateExpression(result) && !ts12.isNoSubstitutionTemplateLiteral(result))
13129
+ const result = ts13.isParenthesizedExpression(decl.initializer) ? decl.initializer.expression : decl.initializer;
13130
+ if (!ts13.isTemplateExpression(result) && !ts13.isNoSubstitutionTemplateLiteral(result))
13025
13131
  return null;
13026
13132
  return result;
13027
13133
  }
@@ -13041,10 +13147,10 @@ function parseTernary(expr, ctx) {
13041
13147
  return null;
13042
13148
  }
13043
13149
  function getStringValue(node) {
13044
- if (ts12.isStringLiteral(node)) {
13150
+ if (ts13.isStringLiteral(node)) {
13045
13151
  return node.text;
13046
13152
  }
13047
- if (ts12.isNoSubstitutionTemplateLiteral(node)) {
13153
+ if (ts13.isNoSubstitutionTemplateLiteral(node)) {
13048
13154
  return node.text;
13049
13155
  }
13050
13156
  return null;
@@ -13052,19 +13158,19 @@ function getStringValue(node) {
13052
13158
  function processComponentProps(attributes, ctx) {
13053
13159
  const props = [];
13054
13160
  for (const attr of attributes.properties) {
13055
- if (ts12.isJsxSpreadAttribute(attr)) {
13161
+ if (ts13.isJsxSpreadAttribute(attr)) {
13056
13162
  props.push(...expandSpreadAttribute(attr, ctx));
13057
13163
  continue;
13058
13164
  }
13059
- if (!ts12.isJsxAttribute(attr))
13165
+ if (!ts13.isJsxAttribute(attr))
13060
13166
  continue;
13061
13167
  const name = attr.name.getText(ctx.sourceFile);
13062
- if (attr.initializer && ts12.isJsxExpression(attr.initializer) && attr.initializer.expression) {
13168
+ if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
13063
13169
  let jsxExpr = attr.initializer.expression;
13064
- while (ts12.isParenthesizedExpression(jsxExpr)) {
13170
+ while (ts13.isParenthesizedExpression(jsxExpr)) {
13065
13171
  jsxExpr = jsxExpr.expression;
13066
13172
  }
13067
- if (ts12.isJsxElement(jsxExpr) || ts12.isJsxSelfClosingElement(jsxExpr) || ts12.isJsxFragment(jsxExpr)) {
13173
+ if (ts13.isJsxElement(jsxExpr) || ts13.isJsxSelfClosingElement(jsxExpr) || ts13.isJsxFragment(jsxExpr)) {
13068
13174
  const prevInsideComponentChildren = ctx.insideComponentChildren;
13069
13175
  ctx.insideComponentChildren = true;
13070
13176
  const irNode = transformNode(jsxExpr, ctx);
@@ -13091,7 +13197,7 @@ function processComponentProps(attributes, ctx) {
13091
13197
  value = AttrValueOf.booleanShorthand();
13092
13198
  }
13093
13199
  let clientOnly;
13094
- if (attr.initializer && ts12.isJsxExpression(attr.initializer) && attr.initializer.expression) {
13200
+ if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
13095
13201
  if (value.kind === "expression" && value.templateExpr === undefined) {
13096
13202
  const rewritten = rewriteBarePropRefs2(value.expr, attr.initializer.expression, ctx);
13097
13203
  if (rewritten !== value.expr) {
@@ -13115,7 +13221,7 @@ function processComponentProps(attributes, ctx) {
13115
13221
  return props;
13116
13222
  }
13117
13223
  function checkBareSignalOrMemoIdentifier(expr, ctx) {
13118
- if (!ts12.isIdentifier(expr))
13224
+ if (!ts13.isIdentifier(expr))
13119
13225
  return;
13120
13226
  const name = expr.text;
13121
13227
  for (const signal of ctx.analyzer.signals) {
@@ -13146,12 +13252,12 @@ function checkBareSignalOrMemoIdentifier(expr, ctx) {
13146
13252
  function isArrayExprDirectPropRef(arrayExpr, ctx) {
13147
13253
  const propNames = new Set(ctx.patterns.props.map((p) => p.name));
13148
13254
  const propsObjName = ctx.analyzer.propsObjectName;
13149
- if (ts12.isIdentifier(arrayExpr)) {
13255
+ if (ts13.isIdentifier(arrayExpr)) {
13150
13256
  return propNames.has(arrayExpr.text);
13151
13257
  }
13152
- if (ts12.isPropertyAccessExpression(arrayExpr) && propsObjName) {
13258
+ if (ts13.isPropertyAccessExpression(arrayExpr) && propsObjName) {
13153
13259
  const obj = arrayExpr.expression;
13154
- if (ts12.isIdentifier(obj) && obj.text === propsObjName) {
13260
+ if (ts13.isIdentifier(obj) && obj.text === propsObjName) {
13155
13261
  return true;
13156
13262
  }
13157
13263
  }
@@ -13173,7 +13279,7 @@ function referencesLoopParam(expr, ctx) {
13173
13279
  if (boundNames.size === 0)
13174
13280
  return false;
13175
13281
  for (const p of boundNames) {
13176
- if (new RegExp(`\\b${p}\\b`).test(expr))
13282
+ if (identifierPattern(p).test(expr))
13177
13283
  return true;
13178
13284
  }
13179
13285
  return false;
@@ -13255,7 +13361,7 @@ function hasReactiveAttributes(attrs, ctx) {
13255
13361
  const scopeValueNames = ctx.scope.valueBoundNames();
13256
13362
  if (scopeValueNames.size > 0) {
13257
13363
  for (const p of scopeValueNames) {
13258
- if (new RegExp(`\\b${p}\\b`).test(valueToCheck))
13364
+ if (identifierPattern(p).test(valueToCheck))
13259
13365
  return true;
13260
13366
  }
13261
13367
  }
@@ -13346,7 +13452,7 @@ function buildIfStatementChain(analyzer, ctx, opts) {
13346
13452
  jsxBranchLocalNames.add(n);
13347
13453
  }
13348
13454
  for (const decl of condReturn.scopeVariables) {
13349
- if (ts12.isIdentifier(decl.name) && decl.initializer) {
13455
+ if (ts13.isIdentifier(decl.name) && decl.initializer) {
13350
13456
  branchScopeVars.set(decl.name.text, decl.initializer);
13351
13457
  if (initializerShapeContainsJsx(decl.initializer)) {
13352
13458
  jsxBranchLocalNames.add(decl.name.text);
@@ -13413,7 +13519,7 @@ function buildIfStatementChain(analyzer, ctx, opts) {
13413
13519
  }
13414
13520
  const scopeVariables = [];
13415
13521
  for (const decl of condReturn.scopeVariables) {
13416
- if (ts12.isIdentifier(decl.name) && decl.initializer) {
13522
+ if (ts13.isIdentifier(decl.name) && decl.initializer) {
13417
13523
  const init = ctx.getJS(decl.initializer);
13418
13524
  const typedInit = decl.initializer.getText(ctx.sourceFile);
13419
13525
  scopeVariables.push({
@@ -13461,18 +13567,22 @@ function buildIfStatementChain(analyzer, ctx, opts) {
13461
13567
  }
13462
13568
 
13463
13569
  // ../jsx/src/ir-to-client-js/prop-handling.ts
13464
- function expandDynamicPropValue(value, ctx) {
13570
+ function expandDynamicPropValue(value, ctx, scope) {
13465
13571
  const trimmedValue = value.trim();
13572
+ if (scope?.isBound(trimmedValue))
13573
+ return value;
13466
13574
  const constant = ctx.localConstants.find((c) => c.name === trimmedValue);
13467
13575
  if (constant && constant.value) {
13468
13576
  return constant.value;
13469
13577
  }
13470
13578
  return value;
13471
13579
  }
13472
- function expandConstantForReactivity(expr, ctx, originalFreeIds) {
13580
+ function expandConstantForReactivity(expr, ctx, originalFreeIds, scope) {
13473
13581
  if (ctx.propsObjectName)
13474
13582
  return { expr, freeIds: originalFreeIds };
13475
13583
  const trimmedValue = expr.trim();
13584
+ if (scope?.isBound(trimmedValue))
13585
+ return { expr, freeIds: originalFreeIds };
13476
13586
  const constant = ctx.localConstants.find((c) => c.name === trimmedValue);
13477
13587
  if (constant && constant.value) {
13478
13588
  return { expr: constant.value, freeIds: constant.freeIdentifiers };
@@ -13508,6 +13618,16 @@ function getControlledPropName(signal, propsParams, propsObjectName = null) {
13508
13618
  }
13509
13619
 
13510
13620
  // ../jsx/src/ir-to-client-js/reactivity.ts
13621
+ function buildLoopRowScope(loopParam, loopParamBindings, preambleNames, loopIndex) {
13622
+ if (!loopParam)
13623
+ return;
13624
+ return BindingScope.EMPTY.enterLoopRow({
13625
+ param: loopParam,
13626
+ paramBindings: loopParamBindings,
13627
+ index: loopIndex,
13628
+ preamble: preambleNames && preambleNames.size > 0 ? { declaredNames: [...preambleNames] } : undefined
13629
+ });
13630
+ }
13511
13631
  function decideWrapFromAstFlags(node) {
13512
13632
  if (node.origin && isReactiveOrigin(node.origin)) {
13513
13633
  return { wrap: true, reason: "proven-reactive" };
@@ -13536,12 +13656,12 @@ function decideWrapForChildProp(expandedValue, ctx, prop) {
13536
13656
  }
13537
13657
  function needsEffectWrapper(expr, ctx, freeIdentifiers2) {
13538
13658
  for (const signal of ctx.signals) {
13539
- if (new RegExp(`\\b${signal.getter}\\s*\\(`).test(expr)) {
13659
+ if (identifierCallPattern(signal.getter).test(expr)) {
13540
13660
  return true;
13541
13661
  }
13542
13662
  }
13543
13663
  for (const memo of ctx.memos) {
13544
- if (new RegExp(`\\b${memo.name}\\s*\\(`).test(expr)) {
13664
+ if (identifierCallPattern(memo.name).test(expr)) {
13545
13665
  return true;
13546
13666
  }
13547
13667
  }
@@ -13731,8 +13851,9 @@ function traverseForComponents(node, components, skipConditionals = false) {
13731
13851
  }
13732
13852
  });
13733
13853
  }
13734
- function collectLoopChildReactiveTexts(node, ctx, loopParam, loopParamBindings, stopAtReactiveConditionals = false) {
13854
+ function collectLoopChildReactiveTexts(node, ctx, loopParam, loopParamBindings, stopAtReactiveConditionals = false, preambleNames, loopIndex) {
13735
13855
  const texts = [];
13856
+ const scope = buildLoopRowScope(loopParam, loopParamBindings, preambleNames, loopIndex);
13736
13857
  walkIR(node, false, {
13737
13858
  ...stopAt("loop", "async", "ifStatement"),
13738
13859
  expression: ({ node: n, scope: insideConditional }) => {
@@ -13741,7 +13862,7 @@ function collectLoopChildReactiveTexts(node, ctx, loopParam, loopParamBindings,
13741
13862
  if (n.preambleRegion)
13742
13863
  return;
13743
13864
  const originFreeIds = freeIdsFromRefs(n.origin?.freeRefs);
13744
- const expanded = expandConstantForReactivity(n.expr, ctx, originFreeIds);
13865
+ const expanded = expandConstantForReactivity(n.expr, ctx, originFreeIds, scope);
13745
13866
  const reactive = classifyReactivity(expanded.expr, ctx, loopParam, loopParamBindings, expanded.freeIds).kind !== "none" || decideWrapFromAstFlags(n).wrap;
13746
13867
  if (!reactive)
13747
13868
  return;
@@ -13765,8 +13886,9 @@ function anyNameIn(names, set) {
13765
13886
  return true;
13766
13887
  return false;
13767
13888
  }
13768
- function collectLoopChildReactiveAttrs(node, ctx, loopParam, loopParamBindings, stopAtReactiveConditionals = false, preambleNames) {
13889
+ function collectLoopChildReactiveAttrs(node, ctx, loopParam, loopParamBindings, stopAtReactiveConditionals = false, preambleNames, loopIndex) {
13769
13890
  const attrs = [];
13891
+ const scope = buildLoopRowScope(loopParam, loopParamBindings, preambleNames, loopIndex);
13770
13892
  traverseElements(node, (el) => {
13771
13893
  if (el.slotId) {
13772
13894
  for (const attr of el.attrs) {
@@ -13779,7 +13901,7 @@ function collectLoopChildReactiveAttrs(node, ctx, loopParam, loopParamBindings,
13779
13901
  const valueStr = attrValueToString(attr.value);
13780
13902
  if (!valueStr)
13781
13903
  continue;
13782
- const expanded = expandConstantForReactivity(valueStr, ctx, attr.freeIdentifiers);
13904
+ const expanded = expandConstantForReactivity(valueStr, ctx, attr.freeIdentifiers, scope);
13783
13905
  const readsPreamble = preambleNames !== undefined && preambleNames.size > 0 && anyNameIn(expanded.freeIds ?? extractFreeIdentifiersFromText(expanded.expr), preambleNames);
13784
13906
  const reactive = classifyReactivity(expanded.expr, ctx, loopParam, loopParamBindings, expanded.freeIds).kind !== "none" || readsPreamble || attr.callsReactiveGetters || attr.hasFunctionCalls;
13785
13907
  if (!attr.clientOnly && !reactive)
@@ -14084,13 +14206,13 @@ function collectInnerLoops(nodes, siblingOffsets, outerLoopParam, ctx, options)
14084
14206
  const emitDepth = fixedDepth ?? scope.depth + 1;
14085
14207
  const loopParamsForTemplate = outerLoopParam ? [outerLoopParam, { param: n.param, bindings: n.paramBindings }] : undefined;
14086
14208
  const template = n.children.map((c) => irToPlaceholderTemplate(c, undefined, emitDepth, loopParamsForTemplate)).join("");
14087
- const refsOuter = outerLoopParam ? new RegExp(`\\b${outerLoopParam}\\b`).test(n.array) : false;
14209
+ const refsOuter = outerLoopParam ? identifierPattern(outerLoopParam).test(n.array) : false;
14088
14210
  const bindings = emptyLoopChildBindings();
14089
14211
  const innerPreambleNames = preambleNamesOf(n);
14090
14212
  if (ctx) {
14091
14213
  for (const child of n.children) {
14092
- bindings.reactiveTexts.push(...collectLoopChildReactiveTexts(child, ctx, n.param, n.paramBindings));
14093
- bindings.reactiveAttrs.push(...collectLoopChildReactiveAttrs(child, ctx, n.param, n.paramBindings, false, innerPreambleNames));
14214
+ bindings.reactiveTexts.push(...collectLoopChildReactiveTexts(child, ctx, n.param, n.paramBindings, false, innerPreambleNames, n.index));
14215
+ bindings.reactiveAttrs.push(...collectLoopChildReactiveAttrs(child, ctx, n.param, n.paramBindings, false, innerPreambleNames, n.index));
14094
14216
  bindings.refs.push(...collectLoopChildRefs(child));
14095
14217
  }
14096
14218
  }
@@ -14117,7 +14239,7 @@ function collectInnerLoops(nodes, siblingOffsets, outerLoopParam, ctx, options)
14117
14239
  bindings.events.push(...collectLoopChildEventsWithNesting(child));
14118
14240
  }
14119
14241
  if (ctx) {
14120
- bindings.conditionals.push(...collectLoopChildConditionals({ type: "fragment", children: n.children, loc: n.loc }, ctx, siblingOffsets, n.param, n.paramBindings));
14242
+ bindings.conditionals.push(...collectLoopChildConditionals({ type: "fragment", children: n.children, loc: n.loc }, ctx, siblingOffsets, n.param, n.paramBindings, innerPreambleNames, n.index));
14121
14243
  }
14122
14244
  }
14123
14245
  result.push({
@@ -14313,7 +14435,7 @@ function collectElements(node, ctx, siblingOffsets, insideConditional = false) {
14313
14435
  return;
14314
14436
  const projectionInner = l.method === "flatMap" && l.children.length === 1 && l.children[0].type === "loop" ? l.children[0] : undefined;
14315
14437
  const childHandlers = [];
14316
- const bindings = projectionInner ? emptyLoopChildBindings() : collectLoopChildBindings(l.children, ctx, siblingOffsets, l.param, l.paramBindings, preambleNamesOf(l));
14438
+ const bindings = projectionInner ? emptyLoopChildBindings() : collectLoopChildBindings(l.children, ctx, siblingOffsets, l.param, l.paramBindings, preambleNamesOf(l), l.index);
14317
14439
  if (!projectionInner) {
14318
14440
  for (const child of l.children) {
14319
14441
  childHandlers.push(...collectEventHandlersFromIR(child));
@@ -14568,7 +14690,7 @@ function collectBranchLoops(node, ctx, siblingOffsets) {
14568
14690
  } else {
14569
14691
  childTemplate = n.children.map((c) => irToHtmlTemplate(c, undefined, 0, branchLoopParamSpec)).join("");
14570
14692
  }
14571
- const branchBindings = ctx && !projectionInner ? collectLoopChildBindings(n.children, ctx, siblingOffsets, n.param, n.paramBindings, preambleNamesOf(n)) : emptyLoopChildBindings();
14693
+ const branchBindings = ctx && !projectionInner ? collectLoopChildBindings(n.children, ctx, siblingOffsets, n.param, n.paramBindings, preambleNamesOf(n), n.index) : emptyLoopChildBindings();
14572
14694
  loops.push({
14573
14695
  kind: "branch",
14574
14696
  array: n.array,
@@ -14654,19 +14776,20 @@ function preambleNamesOf(loop) {
14654
14776
  const declared = loop.preamble?.declaredNames;
14655
14777
  return declared && declared.length > 0 ? new Set(declared) : undefined;
14656
14778
  }
14657
- function collectLoopChildBindings(children, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames) {
14779
+ function collectLoopChildBindings(children, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex) {
14658
14780
  const bindings = emptyLoopChildBindings();
14659
14781
  for (const child of children) {
14660
14782
  bindings.events.push(...collectLoopChildEventsWithNesting(child));
14661
- bindings.reactiveAttrs.push(...collectLoopChildReactiveAttrs(child, ctx, loopParam, loopParamBindings, true, preambleNames));
14662
- bindings.reactiveTexts.push(...collectLoopChildReactiveTexts(child, ctx, loopParam, loopParamBindings, true));
14783
+ bindings.reactiveAttrs.push(...collectLoopChildReactiveAttrs(child, ctx, loopParam, loopParamBindings, true, preambleNames, loopIndex));
14784
+ bindings.reactiveTexts.push(...collectLoopChildReactiveTexts(child, ctx, loopParam, loopParamBindings, true, preambleNames, loopIndex));
14663
14785
  bindings.refs.push(...collectLoopChildRefs(child));
14664
- bindings.conditionals.push(...collectLoopChildConditionals(child, ctx, siblingOffsets, loopParam, loopParamBindings));
14786
+ bindings.conditionals.push(...collectLoopChildConditionals(child, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex));
14665
14787
  }
14666
14788
  return bindings;
14667
14789
  }
14668
- function collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loopParamBindings) {
14790
+ function collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex) {
14669
14791
  const conditionals = [];
14792
+ const scope = buildLoopRowScope(loopParam, loopParamBindings, preambleNames, loopIndex);
14670
14793
  const refsAnyBindingViaFreeIds = (freeIds) => {
14671
14794
  if (loopParamBindings && loopParamBindings.length > 0) {
14672
14795
  for (const b of loopParamBindings) {
@@ -14686,8 +14809,9 @@ function collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loop
14686
14809
  const refsLoopParamInSource = refsAnyBindingViaFreeIds(sourceFreeIds);
14687
14810
  if (!n.reactive && !refsLoopParamInSource)
14688
14811
  return;
14689
- const expanded = expandConstantForReactivity(n.condition, ctx, sourceFreeIds);
14690
- if (classifyReactivity(expanded.expr, ctx, loopParam, loopParamBindings, expanded.freeIds).kind === "none")
14812
+ const expanded = expandConstantForReactivity(n.condition, ctx, sourceFreeIds, scope);
14813
+ const readsPreamble = preambleNames !== undefined && preambleNames.size > 0 && anyNameIn(expanded.freeIds ?? extractFreeIdentifiersFromText(expanded.expr), preambleNames);
14814
+ if (!readsPreamble && classifyReactivity(expanded.expr, ctx, loopParam, loopParamBindings, expanded.freeIds).kind === "none")
14691
14815
  return;
14692
14816
  const loopParamsForCond = loopParam ? [{ param: loopParam, bindings: loopParamBindings }] : undefined;
14693
14817
  const whenTrueHtml = irToHtmlTemplate(n.whenTrue, undefined, 0, loopParamsForCond, "__slots");
@@ -14697,23 +14821,24 @@ function collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loop
14697
14821
  condition: expanded.expr,
14698
14822
  whenTrueHtml,
14699
14823
  whenFalseHtml,
14700
- whenTrue: summarizeLoopChildBranch(n.whenTrue, ctx, siblingOffsets, loopParam, loopParamBindings),
14701
- whenFalse: summarizeLoopChildBranch(n.whenFalse, ctx, siblingOffsets, loopParam, loopParamBindings),
14702
- ...expanded.freeIds !== undefined && { conditionFreeIdentifiers: expanded.freeIds }
14824
+ whenTrue: summarizeLoopChildBranch(n.whenTrue, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex),
14825
+ whenFalse: summarizeLoopChildBranch(n.whenFalse, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex),
14826
+ ...expanded.freeIds !== undefined && { conditionFreeIdentifiers: expanded.freeIds },
14827
+ ...readsPreamble && { readsPreamble: true }
14703
14828
  });
14704
14829
  }
14705
14830
  });
14706
14831
  return conditionals;
14707
14832
  }
14708
- function summarizeLoopChildBranch(node, ctx, siblingOffsets, loopParam, loopParamBindings) {
14833
+ function summarizeLoopChildBranch(node, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex) {
14709
14834
  const inner = collectInnerLoops([node], siblingOffsets, loopParam, ctx, branchInnerLoopOptions);
14710
14835
  return {
14711
14836
  childComponents: collectConditionalBranchChildComponents(node),
14712
14837
  innerLoops: inner.length > 0 ? inner : undefined,
14713
- conditionals: collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loopParamBindings),
14838
+ conditionals: collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex),
14714
14839
  events: collectConditionalBranchEvents(node),
14715
- reactiveAttrs: collectLoopChildReactiveAttrs(node, ctx, loopParam, loopParamBindings, true),
14716
- reactiveTexts: node.type === "expression" && node.hasFunctionCalls ? [] : collectLoopChildReactiveTexts(node, ctx, loopParam, loopParamBindings, true)
14840
+ reactiveAttrs: collectLoopChildReactiveAttrs(node, ctx, loopParam, loopParamBindings, true, preambleNames, loopIndex),
14841
+ reactiveTexts: node.type === "expression" && node.hasFunctionCalls ? [] : collectLoopChildReactiveTexts(node, ctx, loopParam, loopParamBindings, true, preambleNames, loopIndex)
14717
14842
  };
14718
14843
  }
14719
14844
 
@@ -15075,7 +15200,7 @@ function graphDeclarationReferences(graph, kind, name) {
15075
15200
  }
15076
15201
 
15077
15202
  // ../jsx/src/ir-to-client-js/walk-prop-accesses.ts
15078
- import ts13 from "typescript";
15203
+ import ts14 from "typescript";
15079
15204
  function collectPropAccesses(source, propNames, out) {
15080
15205
  if (propNames.size === 0)
15081
15206
  return;
@@ -15089,7 +15214,7 @@ function collectPropAccesses(source, propNames, out) {
15089
15214
  if (!anyMentioned)
15090
15215
  return;
15091
15216
  for (const expr of normaliseExpressionParts(source)) {
15092
- const sourceFile = ts13.createSourceFile("p.ts", expr, ts13.ScriptTarget.Latest, false, ts13.ScriptKind.TS);
15217
+ const sourceFile = ts14.createSourceFile("p.ts", expr, ts14.ScriptTarget.Latest, false, ts14.ScriptKind.TS);
15093
15218
  visit2(sourceFile, propNames, out);
15094
15219
  }
15095
15220
  }
@@ -15099,15 +15224,15 @@ function normaliseExpressionParts(source) {
15099
15224
  return extractTemplateExpressions(source);
15100
15225
  }
15101
15226
  function visit2(node, propNames, out) {
15102
- if (ts13.isPropertyAccessExpression(node)) {
15227
+ if (ts14.isPropertyAccessExpression(node)) {
15103
15228
  recordIfPropAccess(node.expression, "property", propNames, out);
15104
- } else if (ts13.isElementAccessExpression(node)) {
15229
+ } else if (ts14.isElementAccessExpression(node)) {
15105
15230
  recordIfPropAccess(node.expression, "index", propNames, out);
15106
15231
  }
15107
- ts13.forEachChild(node, (child) => visit2(child, propNames, out));
15232
+ ts14.forEachChild(node, (child) => visit2(child, propNames, out));
15108
15233
  }
15109
15234
  function recordIfPropAccess(receiver, kind, propNames, out) {
15110
- if (!ts13.isIdentifier(receiver))
15235
+ if (!ts14.isIdentifier(receiver))
15111
15236
  return;
15112
15237
  const name = receiver.text;
15113
15238
  if (!propNames.has(name))
@@ -15160,56 +15285,56 @@ function propHasPropertyAccess(u) {
15160
15285
  }
15161
15286
 
15162
15287
  // ../jsx/src/value-references.ts
15163
- import ts14 from "typescript";
15288
+ import ts15 from "typescript";
15164
15289
  function isValueReferenceIdentifier(id) {
15165
15290
  const parent = id.parent;
15166
15291
  if (!parent)
15167
15292
  return false;
15168
- if (ts14.isPropertyAccessExpression(parent) && parent.name === id)
15293
+ if (ts15.isPropertyAccessExpression(parent) && parent.name === id)
15169
15294
  return false;
15170
- if (ts14.isPropertyAssignment(parent) && parent.name === id)
15295
+ if (ts15.isPropertyAssignment(parent) && parent.name === id)
15171
15296
  return false;
15172
- if ((ts14.isMethodDeclaration(parent) || ts14.isGetAccessorDeclaration(parent) || ts14.isSetAccessorDeclaration(parent)) && parent.name === id) {
15297
+ if ((ts15.isMethodDeclaration(parent) || ts15.isGetAccessorDeclaration(parent) || ts15.isSetAccessorDeclaration(parent)) && parent.name === id) {
15173
15298
  return false;
15174
15299
  }
15175
- if (ts14.isPropertyDeclaration(parent) && parent.name === id)
15300
+ if (ts15.isPropertyDeclaration(parent) && parent.name === id)
15176
15301
  return false;
15177
- if (ts14.isMetaProperty(parent) && parent.name === id)
15302
+ if (ts15.isMetaProperty(parent) && parent.name === id)
15178
15303
  return false;
15179
- if (ts14.isVariableDeclaration(parent) && parent.name === id)
15304
+ if (ts15.isVariableDeclaration(parent) && parent.name === id)
15180
15305
  return false;
15181
- if (ts14.isFunctionDeclaration(parent) && parent.name === id)
15306
+ if (ts15.isFunctionDeclaration(parent) && parent.name === id)
15182
15307
  return false;
15183
- if (ts14.isFunctionExpression(parent) && parent.name === id)
15308
+ if (ts15.isFunctionExpression(parent) && parent.name === id)
15184
15309
  return false;
15185
- if (ts14.isClassDeclaration(parent) && parent.name === id)
15310
+ if (ts15.isClassDeclaration(parent) && parent.name === id)
15186
15311
  return false;
15187
- if (ts14.isClassExpression(parent) && parent.name === id)
15312
+ if (ts15.isClassExpression(parent) && parent.name === id)
15188
15313
  return false;
15189
- if (ts14.isParameter(parent) && parent.name === id)
15314
+ if (ts15.isParameter(parent) && parent.name === id)
15190
15315
  return false;
15191
- if (ts14.isBindingElement(parent) && (parent.name === id || parent.propertyName === id))
15316
+ if (ts15.isBindingElement(parent) && (parent.name === id || parent.propertyName === id))
15192
15317
  return false;
15193
- if (ts14.isLabeledStatement(parent) && parent.label === id)
15318
+ if (ts15.isLabeledStatement(parent) && parent.label === id)
15194
15319
  return false;
15195
- if (ts14.isBreakOrContinueStatement(parent) && parent.label === id)
15320
+ if (ts15.isBreakOrContinueStatement(parent) && parent.label === id)
15196
15321
  return false;
15197
- if (ts14.isImportSpecifier(parent) && (parent.name === id || parent.propertyName === id))
15322
+ if (ts15.isImportSpecifier(parent) && (parent.name === id || parent.propertyName === id))
15198
15323
  return false;
15199
- if (ts14.isExportSpecifier(parent) && (parent.name === id || parent.propertyName === id))
15324
+ if (ts15.isExportSpecifier(parent) && (parent.name === id || parent.propertyName === id))
15200
15325
  return false;
15201
- if (ts14.isImportClause(parent) && parent.name === id)
15326
+ if (ts15.isImportClause(parent) && parent.name === id)
15202
15327
  return false;
15203
- if (ts14.isNamespaceImport(parent) && parent.name === id)
15328
+ if (ts15.isNamespaceImport(parent) && parent.name === id)
15204
15329
  return false;
15205
- if (ts14.isQualifiedName(parent) && parent.right === id)
15330
+ if (ts15.isQualifiedName(parent) && parent.right === id)
15206
15331
  return false;
15207
15332
  return true;
15208
15333
  }
15209
15334
  function collectValueReferencedNames(code) {
15210
15335
  let sourceFile;
15211
15336
  try {
15212
- sourceFile = ts14.createSourceFile("generated.js", code, ts14.ScriptTarget.Latest, true, ts14.ScriptKind.JS);
15337
+ sourceFile = ts15.createSourceFile("generated.js", code, ts15.ScriptTarget.Latest, true, ts15.ScriptKind.JS);
15213
15338
  } catch {
15214
15339
  return null;
15215
15340
  }
@@ -15218,10 +15343,10 @@ function collectValueReferencedNames(code) {
15218
15343
  return null;
15219
15344
  const names = new Set;
15220
15345
  function visit3(node) {
15221
- if (ts14.isIdentifier(node) && isValueReferenceIdentifier(node)) {
15346
+ if (ts15.isIdentifier(node) && isValueReferenceIdentifier(node)) {
15222
15347
  names.add(node.text);
15223
15348
  }
15224
- ts14.forEachChild(node, visit3);
15349
+ ts15.forEachChild(node, visit3);
15225
15350
  }
15226
15351
  visit3(sourceFile);
15227
15352
  return names;
@@ -15285,7 +15410,7 @@ var MODULE_CONSTANTS_PLACEHOLDER = "/* __MODULE_LEVEL_CONSTANTS__ */";
15285
15410
  function detectUsedImports(code) {
15286
15411
  const used = new Set;
15287
15412
  for (const name of RUNTIME_IMPORT_CANDIDATES) {
15288
- if (new RegExp(`\\b${name}\\s*\\(`).test(code)) {
15413
+ if (identifierCallPattern(name).test(code)) {
15289
15414
  used.add(name);
15290
15415
  }
15291
15416
  }
@@ -15389,7 +15514,7 @@ function collectComponentNames(node) {
15389
15514
  }
15390
15515
 
15391
15516
  // ../jsx/src/relocate.ts
15392
- import ts15 from "typescript";
15517
+ import ts16 from "typescript";
15393
15518
 
15394
15519
  // ../jsx/src/lowering-registry.ts
15395
15520
  var plugins = [];
@@ -15417,19 +15542,19 @@ function classify(name, env) {
15417
15542
  function collectFreeRefs(node) {
15418
15543
  const refs = new Map;
15419
15544
  function visit3(n, parent) {
15420
- if (ts15.isIdentifier(n)) {
15421
- if (parent && ts15.isPropertyAccessExpression(parent) && parent.name === n)
15545
+ if (ts16.isIdentifier(n)) {
15546
+ if (parent && ts16.isPropertyAccessExpression(parent) && parent.name === n)
15422
15547
  return;
15423
- if (parent && ts15.isPropertyAssignment(parent) && parent.name === n)
15548
+ if (parent && ts16.isPropertyAssignment(parent) && parent.name === n)
15424
15549
  return;
15425
- if (parent && ts15.isShorthandPropertyAssignment(parent) && parent.name === n)
15550
+ if (parent && ts16.isShorthandPropertyAssignment(parent) && parent.name === n)
15426
15551
  return;
15427
15552
  const list = refs.get(n.text) ?? [];
15428
15553
  list.push(n);
15429
15554
  refs.set(n.text, list);
15430
15555
  return;
15431
15556
  }
15432
- ts15.forEachChild(n, (child) => visit3(child, n));
15557
+ ts16.forEachChild(n, (child) => visit3(child, n));
15433
15558
  }
15434
15559
  visit3(node);
15435
15560
  return refs;
@@ -15533,11 +15658,11 @@ function isInlinableInTemplate(value, env) {
15533
15658
  return { ok: true, rewrittenValue: r.text, decisions: r.decisions };
15534
15659
  }
15535
15660
  function getCalleeIdentifierPath(callee) {
15536
- if (ts15.isParenthesizedExpression(callee))
15661
+ if (ts16.isParenthesizedExpression(callee))
15537
15662
  return getCalleeIdentifierPath(callee.expression);
15538
- if (ts15.isIdentifier(callee))
15663
+ if (ts16.isIdentifier(callee))
15539
15664
  return callee.text;
15540
- if (ts15.isPropertyAccessExpression(callee)) {
15665
+ if (ts16.isPropertyAccessExpression(callee)) {
15541
15666
  const left = getCalleeIdentifierPath(callee.expression);
15542
15667
  if (left === null)
15543
15668
  return null;
@@ -15546,11 +15671,11 @@ function getCalleeIdentifierPath(callee) {
15546
15671
  return null;
15547
15672
  }
15548
15673
  function getCalleeLeftmostIdentifier(callee) {
15549
- if (ts15.isParenthesizedExpression(callee))
15674
+ if (ts16.isParenthesizedExpression(callee))
15550
15675
  return getCalleeLeftmostIdentifier(callee.expression);
15551
- if (ts15.isIdentifier(callee))
15676
+ if (ts16.isIdentifier(callee))
15552
15677
  return callee.text;
15553
- if (ts15.isPropertyAccessExpression(callee)) {
15678
+ if (ts16.isPropertyAccessExpression(callee)) {
15554
15679
  return getCalleeLeftmostIdentifier(callee.expression);
15555
15680
  }
15556
15681
  return null;
@@ -15598,12 +15723,12 @@ function isCallAcceptedByAdapter(call, env) {
15598
15723
  }
15599
15724
  function parseExpressionNode(text) {
15600
15725
  try {
15601
- const sf = ts15.createSourceFile("__inline_check__.ts", `(${text});`, ts15.ScriptTarget.Latest, false, ts15.ScriptKind.TS);
15726
+ const sf = ts16.createSourceFile("__inline_check__.ts", `(${text});`, ts16.ScriptTarget.Latest, false, ts16.ScriptKind.TS);
15602
15727
  const stmt = sf.statements[0];
15603
- if (!stmt || !ts15.isExpressionStatement(stmt))
15728
+ if (!stmt || !ts16.isExpressionStatement(stmt))
15604
15729
  return null;
15605
15730
  const inner = stmt.expression;
15606
- return ts15.isParenthesizedExpression(inner) ? inner.expression : inner;
15731
+ return ts16.isParenthesizedExpression(inner) ? inner.expression : inner;
15607
15732
  } catch {
15608
15733
  return null;
15609
15734
  }
@@ -15620,8 +15745,8 @@ function hasCallWithBridgedArg(node, decisions, env) {
15620
15745
  function visit3(n) {
15621
15746
  if (found)
15622
15747
  return;
15623
- if (ts15.isCallExpression(n) || ts15.isNewExpression(n)) {
15624
- const accepted = ts15.isCallExpression(n) && isCallAcceptedByAdapter(n, env);
15748
+ if (ts16.isCallExpression(n) || ts16.isNewExpression(n)) {
15749
+ const accepted = ts16.isCallExpression(n) && isCallAcceptedByAdapter(n, env);
15625
15750
  if (!accepted) {
15626
15751
  const args = n.arguments;
15627
15752
  if (args) {
@@ -15634,7 +15759,7 @@ function hasCallWithBridgedArg(node, decisions, env) {
15634
15759
  }
15635
15760
  }
15636
15761
  }
15637
- ts15.forEachChild(n, visit3);
15762
+ ts16.forEachChild(n, visit3);
15638
15763
  }
15639
15764
  visit3(node);
15640
15765
  return found;
@@ -15644,13 +15769,13 @@ function hasZeroArgCall(node, env) {
15644
15769
  function visit3(n) {
15645
15770
  if (found)
15646
15771
  return;
15647
- if (ts15.isCallExpression(n) && n.arguments.length === 0) {
15772
+ if (ts16.isCallExpression(n) && n.arguments.length === 0) {
15648
15773
  if (!isCallAcceptedByAdapter(n, env)) {
15649
15774
  found = true;
15650
15775
  return;
15651
15776
  }
15652
15777
  }
15653
- ts15.forEachChild(n, visit3);
15778
+ ts16.forEachChild(n, visit3);
15654
15779
  }
15655
15780
  visit3(node);
15656
15781
  return found;
@@ -15660,25 +15785,25 @@ function containsAnyIdentifier(node, names) {
15660
15785
  function visit3(n) {
15661
15786
  if (found)
15662
15787
  return;
15663
- if (ts15.isPropertyAccessExpression(n)) {
15788
+ if (ts16.isPropertyAccessExpression(n)) {
15664
15789
  visit3(n.expression);
15665
15790
  return;
15666
15791
  }
15667
- if (ts15.isPropertyAssignment(n)) {
15792
+ if (ts16.isPropertyAssignment(n)) {
15668
15793
  visit3(n.initializer);
15669
15794
  return;
15670
15795
  }
15671
- if (ts15.isShorthandPropertyAssignment(n)) {
15672
- if (ts15.isIdentifier(n.name) && names.has(n.name.text)) {
15796
+ if (ts16.isShorthandPropertyAssignment(n)) {
15797
+ if (ts16.isIdentifier(n.name) && names.has(n.name.text)) {
15673
15798
  found = true;
15674
15799
  }
15675
15800
  return;
15676
15801
  }
15677
- if (ts15.isIdentifier(n) && names.has(n.text)) {
15802
+ if (ts16.isIdentifier(n) && names.has(n.text)) {
15678
15803
  found = true;
15679
15804
  return;
15680
15805
  }
15681
- ts15.forEachChild(n, visit3);
15806
+ ts16.forEachChild(n, visit3);
15682
15807
  }
15683
15808
  visit3(node);
15684
15809
  return found;
@@ -15686,7 +15811,7 @@ function containsAnyIdentifier(node, names) {
15686
15811
  function scanRefsByName(text, bindings) {
15687
15812
  const result = new Map;
15688
15813
  for (const name of bindings.keys()) {
15689
- const re = new RegExp(`\\b${name}\\b`);
15814
+ const re = identifierPattern(name);
15690
15815
  if (re.test(text))
15691
15816
  result.set(name, []);
15692
15817
  }
@@ -16957,23 +17082,23 @@ function resolveFinalImports(generatedCode, ir, localImportPrefixes) {
16957
17082
  }
16958
17083
 
16959
17084
  // ../jsx/src/ir-to-client-js/prune-unused-prop-extractions.ts
16960
- import ts16 from "typescript";
17085
+ import ts17 from "typescript";
16961
17086
  function propExtractionName(stmt) {
16962
- if (!ts16.isVariableStatement(stmt))
17087
+ if (!ts17.isVariableStatement(stmt))
16963
17088
  return null;
16964
17089
  const decls = stmt.declarationList.declarations;
16965
17090
  if (decls.length !== 1)
16966
17091
  return null;
16967
17092
  const decl = decls[0];
16968
- if (!ts16.isIdentifier(decl.name) || !decl.initializer)
17093
+ if (!ts17.isIdentifier(decl.name) || !decl.initializer)
16969
17094
  return null;
16970
17095
  let core = decl.initializer;
16971
- if (ts16.isBinaryExpression(core) && core.operatorToken.kind === ts16.SyntaxKind.QuestionQuestionToken) {
17096
+ if (ts17.isBinaryExpression(core) && core.operatorToken.kind === ts17.SyntaxKind.QuestionQuestionToken) {
16972
17097
  core = core.left;
16973
17098
  }
16974
- if (!ts16.isPropertyAccessExpression(core))
17099
+ if (!ts17.isPropertyAccessExpression(core))
16975
17100
  return null;
16976
- if (!ts16.isIdentifier(core.expression) || core.expression.text !== PROPS_PARAM)
17101
+ if (!ts17.isIdentifier(core.expression) || core.expression.text !== PROPS_PARAM)
16977
17102
  return null;
16978
17103
  if (core.name.text !== decl.name.text)
16979
17104
  return null;
@@ -16986,10 +17111,10 @@ function pruneUnusedPropExtractions(code) {
16986
17111
  console.warn("[barefootjs] pruneUnusedPropExtractions: generated code did not parse; skipping prune");
16987
17112
  return code;
16988
17113
  }
16989
- const sourceFile = ts16.createSourceFile("generated.js", code, ts16.ScriptTarget.Latest, false, ts16.ScriptKind.JS);
17114
+ const sourceFile = ts17.createSourceFile("generated.js", code, ts17.ScriptTarget.Latest, false, ts17.ScriptKind.JS);
16990
17115
  const spans = [];
16991
17116
  for (const stmt of sourceFile.statements) {
16992
- if (!ts16.isFunctionDeclaration(stmt) || !stmt.name?.text.startsWith("init") || !stmt.body)
17117
+ if (!ts17.isFunctionDeclaration(stmt) || !stmt.name?.text.startsWith("init") || !stmt.body)
16993
17118
  continue;
16994
17119
  for (const inner of stmt.body.statements) {
16995
17120
  const name = propExtractionName(inner);
@@ -17951,7 +18076,8 @@ function buildReactiveEffectsPlan(args) {
17951
18076
  whenTrueTemplateHtml: addCondAttrToTemplate(wrap(cond.whenTrueHtml), cond.slotId),
17952
18077
  whenFalseTemplateHtml: addCondAttrToTemplate(wrap(cond.whenFalseHtml), cond.slotId),
17953
18078
  whenTrueArm: buildOuterArm(cond.whenTrue, wrap, loopParam, loopParamBindings, profileComponentName),
17954
- whenFalseArm: buildOuterArm(cond.whenFalse, wrap, loopParam, loopParamBindings, profileComponentName)
18079
+ whenFalseArm: buildOuterArm(cond.whenFalse, wrap, loopParam, loopParamBindings, profileComponentName),
18080
+ ...cond.readsPreamble && { readsPreamble: true }
17955
18081
  });
17956
18082
  }
17957
18083
  }
@@ -18354,7 +18480,7 @@ function buildStaticArrayDelegationPlan(elem, profileComponentName) {
18354
18480
  function buildKeyedOrIndexLookup(args) {
18355
18481
  const hasBindings = (args.paramBindings?.length ?? 0) > 0;
18356
18482
  if (args.key !== null) {
18357
- const keyWithItem = hasBindings ? substituteLoopBindings(args.key, args.paramBindings, "item") : args.key.replace(new RegExp(`\\b${args.param}\\b`, "g"), "item");
18483
+ const keyWithItem = hasBindings ? substituteLoopBindings(args.key, args.paramBindings, "item") : args.key.replace(identifierPattern(args.param, "g"), "item");
18358
18484
  return {
18359
18485
  kind: "keyed",
18360
18486
  arrayExpr: args.array,
@@ -18432,7 +18558,7 @@ function analyzeLazyConditional(cond, indexParam, arms) {
18432
18558
  }
18433
18559
 
18434
18560
  // ../jsx/src/ir-to-client-js/control-flow/plan/lazy-preamble.ts
18435
- import ts17 from "typescript";
18561
+ import ts18 from "typescript";
18436
18562
  var NO_PREAMBLE = {
18437
18563
  lazySafe: true,
18438
18564
  facts: { declaredNames: new Set, freeNames: new Set }
@@ -18452,12 +18578,12 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
18452
18578
  if (text.trim().length === 0)
18453
18579
  return NO_PREAMBLE;
18454
18580
  const declaredNames = new Set;
18455
- const sf = ts17.createSourceFile("__lazy_preamble__.ts", text, ts17.ScriptTarget.Latest, true, ts17.ScriptKind.TS);
18581
+ const sf = ts18.createSourceFile("__lazy_preamble__.ts", text, ts18.ScriptTarget.Latest, true, ts18.ScriptKind.TS);
18456
18582
  for (const stmt of sf.statements) {
18457
- if (!ts17.isVariableStatement(stmt)) {
18458
- return NO2(`map-callback preamble has a non-declaration statement (${ts17.SyntaxKind[stmt.kind]})`);
18583
+ if (!ts18.isVariableStatement(stmt)) {
18584
+ return NO2(`map-callback preamble has a non-declaration statement (${ts18.SyntaxKind[stmt.kind]})`);
18459
18585
  }
18460
- const isConst = (stmt.declarationList.flags & ts17.NodeFlags.Const) !== 0;
18586
+ const isConst = (stmt.declarationList.flags & ts18.NodeFlags.Const) !== 0;
18461
18587
  if (!isConst)
18462
18588
  return NO2("map-callback preamble declares a mutable binding (let/var)");
18463
18589
  for (const decl of stmt.declarationList.declarations) {
@@ -18486,12 +18612,12 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
18486
18612
  return { lazySafe: true, facts: { declaredNames, freeNames } };
18487
18613
  }
18488
18614
  function collectBindingNames3(name, out) {
18489
- if (ts17.isIdentifier(name)) {
18615
+ if (ts18.isIdentifier(name)) {
18490
18616
  out.add(name.text);
18491
18617
  return;
18492
18618
  }
18493
18619
  for (const element of name.elements) {
18494
- if (ts17.isOmittedExpression(element))
18620
+ if (ts18.isOmittedExpression(element))
18495
18621
  continue;
18496
18622
  collectBindingNames3(element.name, out);
18497
18623
  }
@@ -18501,56 +18627,56 @@ function findImpureNode(root, primableNames) {
18501
18627
  const visit3 = (node) => {
18502
18628
  if (found)
18503
18629
  return;
18504
- if (ts17.isCallExpression(node)) {
18630
+ if (ts18.isCallExpression(node)) {
18505
18631
  const callee = node.expression;
18506
- const isSignalRead = ts17.isIdentifier(callee) && primableNames.has(callee.text) && node.arguments.length === 0 && node.questionDotToken === undefined;
18632
+ const isSignalRead = ts18.isIdentifier(callee) && primableNames.has(callee.text) && node.arguments.length === 0 && node.questionDotToken === undefined;
18507
18633
  if (!isSignalRead) {
18508
18634
  found = `call to ${callee.getText(callee.getSourceFile())}`;
18509
18635
  return;
18510
18636
  }
18511
18637
  }
18512
- if (ts17.isNewExpression(node)) {
18638
+ if (ts18.isNewExpression(node)) {
18513
18639
  found = "new expression";
18514
18640
  return;
18515
18641
  }
18516
- if (ts17.isTaggedTemplateExpression(node)) {
18642
+ if (ts18.isTaggedTemplateExpression(node)) {
18517
18643
  found = "tagged template";
18518
18644
  return;
18519
18645
  }
18520
- if (ts17.isAwaitExpression(node)) {
18646
+ if (ts18.isAwaitExpression(node)) {
18521
18647
  found = "await";
18522
18648
  return;
18523
18649
  }
18524
- if (ts17.isYieldExpression(node)) {
18650
+ if (ts18.isYieldExpression(node)) {
18525
18651
  found = "yield";
18526
18652
  return;
18527
18653
  }
18528
- if (ts17.isPrefixUnaryExpression(node) || ts17.isPostfixUnaryExpression(node)) {
18654
+ if (ts18.isPrefixUnaryExpression(node) || ts18.isPostfixUnaryExpression(node)) {
18529
18655
  const op = node.operator;
18530
- if (op === ts17.SyntaxKind.PlusPlusToken || op === ts17.SyntaxKind.MinusMinusToken) {
18656
+ if (op === ts18.SyntaxKind.PlusPlusToken || op === ts18.SyntaxKind.MinusMinusToken) {
18531
18657
  found = "increment/decrement";
18532
18658
  return;
18533
18659
  }
18534
18660
  }
18535
- if (ts17.isDeleteExpression(node)) {
18661
+ if (ts18.isDeleteExpression(node)) {
18536
18662
  found = "delete";
18537
18663
  return;
18538
18664
  }
18539
- if (ts17.isFunctionExpression(node) || ts17.isArrowFunction(node) || ts17.isClassExpression(node)) {
18665
+ if (ts18.isFunctionExpression(node) || ts18.isArrowFunction(node) || ts18.isClassExpression(node)) {
18540
18666
  found = "function or class expression";
18541
18667
  return;
18542
18668
  }
18543
- if (ts17.isBinaryExpression(node) && isAssignmentOperator(node.operatorToken.kind)) {
18669
+ if (ts18.isBinaryExpression(node) && isAssignmentOperator2(node.operatorToken.kind)) {
18544
18670
  found = "assignment";
18545
18671
  return;
18546
18672
  }
18547
- ts17.forEachChild(node, visit3);
18673
+ ts18.forEachChild(node, visit3);
18548
18674
  };
18549
18675
  visit3(root);
18550
18676
  return found;
18551
18677
  }
18552
- function isAssignmentOperator(kind) {
18553
- return kind >= ts17.SyntaxKind.FirstAssignment && kind <= ts17.SyntaxKind.LastAssignment;
18678
+ function isAssignmentOperator2(kind) {
18679
+ return kind >= ts18.SyntaxKind.FirstAssignment && kind <= ts18.SyntaxKind.LastAssignment;
18554
18680
  }
18555
18681
 
18556
18682
  // ../jsx/src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts
@@ -19080,7 +19206,7 @@ function buildArmBody(branch, options) {
19080
19206
  }
19081
19207
 
19082
19208
  // ../jsx/src/ir-to-client-js/emit-reactive.ts
19083
- import ts18 from "typescript";
19209
+ import ts19 from "typescript";
19084
19210
 
19085
19211
  // ../jsx/src/ir-to-client-js/control-flow/stringify/claim-plan.ts
19086
19212
  function slotSpecLiteral(slot) {
@@ -19184,20 +19310,20 @@ function lowerToLocaleCallsInReactiveExpr(expr, matcher) {
19184
19310
  return expr;
19185
19311
  let sourceFile;
19186
19312
  try {
19187
- sourceFile = ts18.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts18.ScriptTarget.Latest, true, ts18.ScriptKind.TS);
19313
+ sourceFile = ts19.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts19.ScriptTarget.Latest, true, ts19.ScriptKind.TS);
19188
19314
  } catch {
19189
19315
  return expr;
19190
19316
  }
19191
19317
  const stmt = sourceFile.statements[0];
19192
- if (!stmt || !ts18.isExpressionStatement(stmt))
19318
+ if (!stmt || !ts19.isExpressionStatement(stmt))
19193
19319
  return expr;
19194
- const root = ts18.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
19320
+ const root = ts19.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
19195
19321
  const candidates = [];
19196
19322
  const visit3 = (n) => {
19197
- if (ts18.isCallExpression(n) && n.arguments.length === 2 && ts18.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
19323
+ if (ts19.isCallExpression(n) && n.arguments.length === 2 && ts19.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
19198
19324
  candidates.push(n);
19199
19325
  }
19200
- ts18.forEachChild(n, visit3);
19326
+ ts19.forEachChild(n, visit3);
19201
19327
  };
19202
19328
  visit3(root);
19203
19329
  if (candidates.length === 0)
@@ -19233,20 +19359,20 @@ function lowerDateCallsInReactiveExpr(expr, matcher) {
19233
19359
  return expr;
19234
19360
  let sourceFile;
19235
19361
  try {
19236
- sourceFile = ts18.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts18.ScriptTarget.Latest, true, ts18.ScriptKind.TS);
19362
+ sourceFile = ts19.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts19.ScriptTarget.Latest, true, ts19.ScriptKind.TS);
19237
19363
  } catch {
19238
19364
  return expr;
19239
19365
  }
19240
19366
  const stmt = sourceFile.statements[0];
19241
- if (!stmt || !ts18.isExpressionStatement(stmt))
19367
+ if (!stmt || !ts19.isExpressionStatement(stmt))
19242
19368
  return expr;
19243
- const root = ts18.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
19369
+ const root = ts19.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
19244
19370
  const candidates = [];
19245
19371
  const visit3 = (n) => {
19246
- if (ts18.isCallExpression(n) && n.arguments.length === 0 && ts18.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
19372
+ if (ts19.isCallExpression(n) && n.arguments.length === 0 && ts19.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
19247
19373
  candidates.push(n);
19248
19374
  }
19249
- ts18.forEachChild(n, visit3);
19375
+ ts19.forEachChild(n, visit3);
19250
19376
  };
19251
19377
  visit3(root);
19252
19378
  if (candidates.length === 0)
@@ -19561,7 +19687,7 @@ function stringifyReactiveEffects(lines, plan, opts) {
19561
19687
  emitConsolidatedRowEffect(lines, indent, elVar, lookup, attrSlots, outerTexts, elementIndexBySlot, textClaimPathExprs, preambleRegions, mapPreambleWrapped);
19562
19688
  }
19563
19689
  for (const cond of conditionals) {
19564
- emitOuterConditional(lines, indent, elVar, cond, pc);
19690
+ emitOuterConditional(lines, indent, elVar, cond, pc, mapPreambleWrapped);
19565
19691
  }
19566
19692
  }
19567
19693
  function emitAttrSlotsGranular(lines, indent, elVar, lookup, attrSlots, elementIndexBySlot, bindingBfId, mapPreambleWrapped) {
@@ -19663,9 +19789,10 @@ function emitOuterTexts(lines, indent, elVar, texts, bindingBfId, textClaimPathE
19663
19789
  lines.push(`${indent}createEffect(() => { ${writer}('${text.slotId}', String(${text.wrappedExpression})) }${bindingBfId(text.slotId)})`);
19664
19790
  }
19665
19791
  }
19666
- function emitOuterConditional(lines, indent, elVar, cond, pc) {
19792
+ function emitOuterConditional(lines, indent, elVar, cond, pc, mapPreambleWrapped) {
19667
19793
  const armIndent = `${indent} `;
19668
- lines.push(`${indent}insert(${elVar}, '${cond.slotId}', () => ${cond.wrappedCondition}, {`);
19794
+ const conditionGetter = cond.readsPreamble && mapPreambleWrapped ? `() => { ${mapPreambleWrapped}; return (${cond.wrappedCondition}) }` : `() => ${cond.wrappedCondition}`;
19795
+ lines.push(`${indent}insert(${elVar}, '${cond.slotId}', ${conditionGetter}, {`);
19669
19796
  lines.push(`${indent} template: () => { const __slots = []; return { html: \`${cond.whenTrueTemplateHtml}\`, slots: __slots } },`);
19670
19797
  lines.push(`${indent} bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {`);
19671
19798
  stringifyLoopChildArm(lines, cond.whenTrueArm, armIndent, pc);
@@ -20560,7 +20687,7 @@ function emitKeyedLookup(ls, ev, handlerCall, lookup) {
20560
20687
  }
20561
20688
  for (const nested of ev.nestedLoops) {
20562
20689
  const rawKey = nested.key ?? "";
20563
- const innerKeyExpr = nested.paramBindings && nested.paramBindings.length > 0 ? substituteLoopBindings(rawKey, nested.paramBindings, "item") : rawKey.replace(new RegExp(`\\b${nested.param}\\b`, "g"), "item");
20690
+ const innerKeyExpr = nested.paramBindings && nested.paramBindings.length > 0 ? substituteLoopBindings(rawKey, nested.paramBindings, "item") : rawKey.replace(identifierPattern(nested.param, "g"), "item");
20564
20691
  const outerRef = hasBindings ? "__bfLoopItem" : param;
20565
20692
  ls.push(` const ${nested.param} = ${outerRef} && ${nested.array}.find(item => String(${innerKeyExpr}) === innerKey${nested.depth})`);
20566
20693
  }
@@ -21249,20 +21376,20 @@ var PHASES = [
21249
21376
  ];
21250
21377
 
21251
21378
  // ../jsx/src/ir-to-client-js/rewrite-props-object.ts
21252
- import ts19 from "typescript";
21379
+ import ts20 from "typescript";
21253
21380
  function rewritePropsObjectRef(code, propsObjectName) {
21254
21381
  const srcPropsName = propsObjectName ?? "props";
21255
21382
  if (srcPropsName === PROPS_PARAM)
21256
21383
  return code;
21257
- if (!new RegExp(`\\b${srcPropsName}\\b`).test(code))
21384
+ if (!identifierPattern(srcPropsName).test(code))
21258
21385
  return code;
21259
- const sourceFile = ts19.createSourceFile("init-body.ts", code, ts19.ScriptTarget.Latest, true, ts19.ScriptKind.TS);
21386
+ const sourceFile = ts20.createSourceFile("init-body.ts", code, ts20.ScriptTarget.Latest, true, ts20.ScriptKind.TS);
21260
21387
  const spans = [];
21261
21388
  function visit3(node) {
21262
- if (ts19.isIdentifier(node) && node.text === srcPropsName && shouldRewrite(node)) {
21389
+ if (ts20.isIdentifier(node) && node.text === srcPropsName && shouldRewrite(node)) {
21263
21390
  spans.push([node.getStart(sourceFile), node.getEnd()]);
21264
21391
  }
21265
- ts19.forEachChild(node, visit3);
21392
+ ts20.forEachChild(node, visit3);
21266
21393
  }
21267
21394
  visit3(sourceFile);
21268
21395
  if (spans.length === 0)
@@ -21278,17 +21405,17 @@ function shouldRewrite(node) {
21278
21405
  const parent = node.parent;
21279
21406
  if (!parent)
21280
21407
  return true;
21281
- if (ts19.isPropertyAccessExpression(parent) && parent.name === node)
21408
+ if (ts20.isPropertyAccessExpression(parent) && parent.name === node)
21282
21409
  return false;
21283
- if (ts19.isPropertyAssignment(parent) && parent.name === node)
21410
+ if (ts20.isPropertyAssignment(parent) && parent.name === node)
21284
21411
  return false;
21285
- if (ts19.isShorthandPropertyAssignment(parent) && parent.name === node)
21412
+ if (ts20.isShorthandPropertyAssignment(parent) && parent.name === node)
21286
21413
  return false;
21287
- if (ts19.isPropertySignature(parent) && parent.name === node)
21414
+ if (ts20.isPropertySignature(parent) && parent.name === node)
21288
21415
  return false;
21289
- if (ts19.isPropertyDeclaration(parent) && parent.name === node)
21416
+ if (ts20.isPropertyDeclaration(parent) && parent.name === node)
21290
21417
  return false;
21291
- if (ts19.isBindingElement(parent) && parent.name === node)
21418
+ if (ts20.isBindingElement(parent) && parent.name === node)
21292
21419
  return false;
21293
21420
  return true;
21294
21421
  }
@@ -21939,7 +22066,7 @@ function walkIR2(node, visitor) {
21939
22066
  }
21940
22067
 
21941
22068
  // ../jsx/src/preprocess-inline-jsx-callbacks.ts
21942
- import ts20 from "typescript";
22069
+ import ts21 from "typescript";
21943
22070
  var SYNTHETIC_PREFIX = "BFInlineJsxCallback";
21944
22071
  var MAX_FIXPOINT_ITERATIONS = 16;
21945
22072
  function preprocessInlineJsxCallbacks(source, filePath) {
@@ -21961,8 +22088,8 @@ function preprocessInlineJsxCallbacks(source, filePath) {
21961
22088
  return { source: current, errors, syntheticNames };
21962
22089
  }
21963
22090
  function runSinglePass(source, filePath, startingCounter) {
21964
- const sourceFile = ts20.createSourceFile(filePath, source, ts20.ScriptTarget.Latest, true, ts20.ScriptKind.TSX);
21965
- const hasUseClient = sourceFile.statements.some((stmt) => ts20.isExpressionStatement(stmt) && ts20.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
22091
+ const sourceFile = ts21.createSourceFile(filePath, source, ts21.ScriptTarget.Latest, true, ts21.ScriptKind.TSX);
22092
+ const hasUseClient = sourceFile.statements.some((stmt) => ts21.isExpressionStatement(stmt) && ts21.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
21966
22093
  if (!hasUseClient) {
21967
22094
  return { source, errors: [], syntheticNames: [], counterAfter: startingCounter };
21968
22095
  }
@@ -21984,22 +22111,22 @@ function runSinglePass(source, filePath, startingCounter) {
21984
22111
  }
21985
22112
  }
21986
22113
  function visit3(node) {
21987
- if (ts20.isJsxAttribute(node) && node.initializer && ts20.isJsxExpression(node.initializer) && node.initializer.expression) {
22114
+ if (ts21.isJsxAttribute(node) && node.initializer && ts21.isJsxExpression(node.initializer) && node.initializer.expression) {
21988
22115
  if (tryHandleArrowValue(node.initializer.expression)) {
21989
22116
  return;
21990
22117
  }
21991
22118
  }
21992
- if (ts20.isPropertyAssignment(node) && node.initializer) {
22119
+ if (ts21.isPropertyAssignment(node) && node.initializer) {
21993
22120
  if (tryHandleArrowValue(node.initializer))
21994
22121
  return;
21995
22122
  }
21996
- ts20.forEachChild(node, visit3);
22123
+ ts21.forEachChild(node, visit3);
21997
22124
  }
21998
22125
  function tryHandleArrowValue(initializer) {
21999
22126
  let expr = initializer;
22000
- while (ts20.isParenthesizedExpression(expr))
22127
+ while (ts21.isParenthesizedExpression(expr))
22001
22128
  expr = expr.expression;
22002
- if (ts20.isArrowFunction(expr) && arrowBodyContainsJsx(expr)) {
22129
+ if (ts21.isArrowFunction(expr) && arrowBodyContainsJsx(expr)) {
22003
22130
  return handleInlineArrow(expr);
22004
22131
  }
22005
22132
  return false;
@@ -22036,7 +22163,7 @@ function runSinglePass(source, filePath, startingCounter) {
22036
22163
  replacements.push({ start: arrowStart, end: arrowEnd, text: name });
22037
22164
  return true;
22038
22165
  }
22039
- ts20.forEachChild(sourceFile, visit3);
22166
+ ts21.forEachChild(sourceFile, visit3);
22040
22167
  if (replacements.length === 0) {
22041
22168
  return { source, errors, syntheticNames, counterAfter: counter };
22042
22169
  }
@@ -22059,11 +22186,11 @@ function errorMessageForCapture(captures) {
22059
22186
  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.`;
22060
22187
  }
22061
22188
  function arrowBodyContainsJsx(arrow) {
22062
- if (ts20.isBlock(arrow.body)) {
22189
+ if (ts21.isBlock(arrow.body)) {
22063
22190
  return blockReturnsJsx(arrow.body);
22064
22191
  }
22065
22192
  let body = arrow.body;
22066
- while (ts20.isParenthesizedExpression(body))
22193
+ while (ts21.isParenthesizedExpression(body))
22067
22194
  body = body.expression;
22068
22195
  return isJsxLike(body);
22069
22196
  }
@@ -22072,24 +22199,24 @@ function blockReturnsJsx(block) {
22072
22199
  function visit3(n) {
22073
22200
  if (found)
22074
22201
  return;
22075
- if (ts20.isReturnStatement(n) && n.expression) {
22202
+ if (ts21.isReturnStatement(n) && n.expression) {
22076
22203
  let e = n.expression;
22077
- while (ts20.isParenthesizedExpression(e))
22204
+ while (ts21.isParenthesizedExpression(e))
22078
22205
  e = e.expression;
22079
22206
  if (isJsxLike(e)) {
22080
22207
  found = true;
22081
22208
  return;
22082
22209
  }
22083
22210
  }
22084
- if (ts20.isArrowFunction(n) || ts20.isFunctionDeclaration(n) || ts20.isFunctionExpression(n))
22211
+ if (ts21.isArrowFunction(n) || ts21.isFunctionDeclaration(n) || ts21.isFunctionExpression(n))
22085
22212
  return;
22086
- ts20.forEachChild(n, visit3);
22213
+ ts21.forEachChild(n, visit3);
22087
22214
  }
22088
- ts20.forEachChild(block, visit3);
22215
+ ts21.forEachChild(block, visit3);
22089
22216
  return found;
22090
22217
  }
22091
22218
  function isJsxLike(expr) {
22092
- return ts20.isJsxElement(expr) || ts20.isJsxSelfClosingElement(expr) || ts20.isJsxFragment(expr);
22219
+ return ts21.isJsxElement(expr) || ts21.isJsxSelfClosingElement(expr) || ts21.isJsxFragment(expr);
22093
22220
  }
22094
22221
  function collectArrowParamNames(arrow) {
22095
22222
  const names = new Set;
@@ -22099,13 +22226,13 @@ function collectArrowParamNames(arrow) {
22099
22226
  }
22100
22227
  function collectBindingNames4(name, out) {
22101
22228
  const push = Array.isArray(out) ? (n) => out.push(n) : (n) => out.add(n);
22102
- if (ts20.isIdentifier(name)) {
22229
+ if (ts21.isIdentifier(name)) {
22103
22230
  push(name.text);
22104
- } else if (ts20.isObjectBindingPattern(name)) {
22231
+ } else if (ts21.isObjectBindingPattern(name)) {
22105
22232
  name.elements.forEach((el) => collectBindingNames4(el.name, out));
22106
- } else if (ts20.isArrayBindingPattern(name)) {
22233
+ } else if (ts21.isArrayBindingPattern(name)) {
22107
22234
  name.elements.forEach((el) => {
22108
- if (!ts20.isOmittedExpression(el))
22235
+ if (!ts21.isOmittedExpression(el))
22109
22236
  collectBindingNames4(el.name, out);
22110
22237
  });
22111
22238
  }
@@ -22132,48 +22259,48 @@ function collectFreeIdentifiers(arrow) {
22132
22259
  return bound.includes(name);
22133
22260
  }
22134
22261
  function visit3(node) {
22135
- if (ts20.isIdentifier(node)) {
22262
+ if (ts21.isIdentifier(node)) {
22136
22263
  const parent = node.parent;
22137
- if (parent && ts20.isPropertyAccessExpression(parent) && parent.name === node)
22264
+ if (parent && ts21.isPropertyAccessExpression(parent) && parent.name === node)
22138
22265
  return;
22139
- if (parent && ts20.isPropertyAssignment(parent) && parent.name === node)
22266
+ if (parent && ts21.isPropertyAssignment(parent) && parent.name === node)
22140
22267
  return;
22141
- if (parent && ts20.isPropertySignature(parent) && parent.name === node)
22268
+ if (parent && ts21.isPropertySignature(parent) && parent.name === node)
22142
22269
  return;
22143
- if (parent && ts20.isPropertyDeclaration(parent) && parent.name === node)
22270
+ if (parent && ts21.isPropertyDeclaration(parent) && parent.name === node)
22144
22271
  return;
22145
- if (parent && ts20.isMethodDeclaration(parent) && parent.name === node)
22272
+ if (parent && ts21.isMethodDeclaration(parent) && parent.name === node)
22146
22273
  return;
22147
- if (parent && ts20.isMethodSignature(parent) && parent.name === node)
22274
+ if (parent && ts21.isMethodSignature(parent) && parent.name === node)
22148
22275
  return;
22149
- if (parent && ts20.isGetAccessorDeclaration(parent) && parent.name === node)
22276
+ if (parent && ts21.isGetAccessorDeclaration(parent) && parent.name === node)
22150
22277
  return;
22151
- if (parent && ts20.isSetAccessorDeclaration(parent) && parent.name === node)
22278
+ if (parent && ts21.isSetAccessorDeclaration(parent) && parent.name === node)
22152
22279
  return;
22153
- if (parent && ts20.isEnumMember(parent) && parent.name === node)
22280
+ if (parent && ts21.isEnumMember(parent) && parent.name === node)
22154
22281
  return;
22155
- if (parent && ts20.isBindingElement(parent) && parent.propertyName === node)
22282
+ if (parent && ts21.isBindingElement(parent) && parent.propertyName === node)
22156
22283
  return;
22157
- if (parent && ts20.isShorthandPropertyAssignment(parent) && parent.name === node) {
22284
+ if (parent && ts21.isShorthandPropertyAssignment(parent) && parent.name === node) {
22158
22285
  if (!isBound(node.text))
22159
22286
  ids.add(node.text);
22160
22287
  return;
22161
22288
  }
22162
- if (parent && ts20.isParameter(parent) && parent.name === node)
22289
+ if (parent && ts21.isParameter(parent) && parent.name === node)
22163
22290
  return;
22164
- if (parent && ts20.isVariableDeclaration(parent) && parent.name === node)
22291
+ if (parent && ts21.isVariableDeclaration(parent) && parent.name === node)
22165
22292
  return;
22166
- if (parent && ts20.isFunctionDeclaration(parent) && parent.name === node)
22293
+ if (parent && ts21.isFunctionDeclaration(parent) && parent.name === node)
22167
22294
  return;
22168
- if (parent && ts20.isClassDeclaration(parent) && parent.name === node)
22295
+ if (parent && ts21.isClassDeclaration(parent) && parent.name === node)
22169
22296
  return;
22170
- if (parent && ts20.isJsxAttribute(parent) && parent.name === node)
22297
+ if (parent && ts21.isJsxAttribute(parent) && parent.name === node)
22171
22298
  return;
22172
- if (parent && ts20.isJsxOpeningElement(parent) && parent.tagName === node) {
22299
+ if (parent && ts21.isJsxOpeningElement(parent) && parent.tagName === node) {
22173
22300
  if (/^[a-z]/.test(node.text))
22174
22301
  return;
22175
22302
  }
22176
- if (parent && ts20.isJsxClosingElement(parent) && parent.tagName === node) {
22303
+ if (parent && ts21.isJsxClosingElement(parent) && parent.tagName === node) {
22177
22304
  if (/^[a-z]/.test(node.text))
22178
22305
  return;
22179
22306
  }
@@ -22182,43 +22309,43 @@ function collectFreeIdentifiers(arrow) {
22182
22309
  ids.add(node.text);
22183
22310
  return;
22184
22311
  }
22185
- if (ts20.isVariableDeclaration(node)) {
22312
+ if (ts21.isVariableDeclaration(node)) {
22186
22313
  const declared = pushBindings(node.name);
22187
22314
  if (node.initializer)
22188
22315
  visit3(node.initializer);
22189
22316
  return;
22190
22317
  }
22191
- if (ts20.isFunctionDeclaration(node)) {
22318
+ if (ts21.isFunctionDeclaration(node)) {
22192
22319
  if (node.name)
22193
22320
  bound.push(node.name.text);
22194
22321
  visitInsideNewScope(node);
22195
22322
  return;
22196
22323
  }
22197
- if (ts20.isClassDeclaration(node)) {
22324
+ if (ts21.isClassDeclaration(node)) {
22198
22325
  if (node.name)
22199
22326
  bound.push(node.name.text);
22200
- ts20.forEachChild(node, visit3);
22327
+ ts21.forEachChild(node, visit3);
22201
22328
  return;
22202
22329
  }
22203
- if (ts20.isArrowFunction(node) || ts20.isFunctionExpression(node)) {
22330
+ if (ts21.isArrowFunction(node) || ts21.isFunctionExpression(node)) {
22204
22331
  visitInsideNewScope(node);
22205
22332
  return;
22206
22333
  }
22207
- if (ts20.isCatchClause(node)) {
22334
+ if (ts21.isCatchClause(node)) {
22208
22335
  const before = bound.length;
22209
22336
  if (node.variableDeclaration)
22210
22337
  pushBindings(node.variableDeclaration.name);
22211
- ts20.forEachChild(node, visit3);
22338
+ ts21.forEachChild(node, visit3);
22212
22339
  popN(bound.length - before);
22213
22340
  return;
22214
22341
  }
22215
- if (ts20.isBlock(node)) {
22342
+ if (ts21.isBlock(node)) {
22216
22343
  const before = bound.length;
22217
- ts20.forEachChild(node, visit3);
22344
+ ts21.forEachChild(node, visit3);
22218
22345
  popN(bound.length - before);
22219
22346
  return;
22220
22347
  }
22221
- ts20.forEachChild(node, visit3);
22348
+ ts21.forEachChild(node, visit3);
22222
22349
  }
22223
22350
  function visitInsideNewScope(fn) {
22224
22351
  const before = bound.length;
@@ -22241,29 +22368,29 @@ function collectFreeIdentifiers(arrow) {
22241
22368
  function collectModuleScopeNames(sourceFile) {
22242
22369
  const names = new Set;
22243
22370
  for (const stmt of sourceFile.statements) {
22244
- if (ts20.isFunctionDeclaration(stmt) && stmt.name)
22371
+ if (ts21.isFunctionDeclaration(stmt) && stmt.name)
22245
22372
  names.add(stmt.name.text);
22246
- else if (ts20.isClassDeclaration(stmt) && stmt.name)
22373
+ else if (ts21.isClassDeclaration(stmt) && stmt.name)
22247
22374
  names.add(stmt.name.text);
22248
- else if (ts20.isVariableStatement(stmt)) {
22375
+ else if (ts21.isVariableStatement(stmt)) {
22249
22376
  for (const decl of stmt.declarationList.declarations)
22250
22377
  collectBindingNames4(decl.name, names);
22251
- } else if (ts20.isImportDeclaration(stmt) && stmt.importClause) {
22378
+ } else if (ts21.isImportDeclaration(stmt) && stmt.importClause) {
22252
22379
  const ic = stmt.importClause;
22253
22380
  if (ic.name)
22254
22381
  names.add(ic.name.text);
22255
22382
  if (ic.namedBindings) {
22256
- if (ts20.isNamespaceImport(ic.namedBindings))
22383
+ if (ts21.isNamespaceImport(ic.namedBindings))
22257
22384
  names.add(ic.namedBindings.name.text);
22258
22385
  else
22259
22386
  for (const e of ic.namedBindings.elements)
22260
22387
  names.add(e.name.text);
22261
22388
  }
22262
- } else if (ts20.isTypeAliasDeclaration(stmt))
22389
+ } else if (ts21.isTypeAliasDeclaration(stmt))
22263
22390
  names.add(stmt.name.text);
22264
- else if (ts20.isInterfaceDeclaration(stmt))
22391
+ else if (ts21.isInterfaceDeclaration(stmt))
22265
22392
  names.add(stmt.name.text);
22266
- else if (ts20.isEnumDeclaration(stmt))
22393
+ else if (ts21.isEnumDeclaration(stmt))
22267
22394
  names.add(stmt.name.text);
22268
22395
  }
22269
22396
  return names;
@@ -22271,7 +22398,7 @@ function collectModuleScopeNames(sourceFile) {
22271
22398
  function buildSyntheticDeclaration(name, arrow, sourceFile) {
22272
22399
  const paramsText = arrow.parameters.length === 0 ? "" : arrow.parameters.map((p) => p.getText(sourceFile)).join(", ");
22273
22400
  let bodyText;
22274
- if (ts20.isBlock(arrow.body)) {
22401
+ if (ts21.isBlock(arrow.body)) {
22275
22402
  bodyText = arrow.body.getText(sourceFile);
22276
22403
  } else {
22277
22404
  const expr = arrow.body.getText(sourceFile);
@@ -22281,7 +22408,7 @@ function buildSyntheticDeclaration(name, arrow, sourceFile) {
22281
22408
  }
22282
22409
 
22283
22410
  // ../jsx/src/ssr-defaults.ts
22284
- import ts21 from "typescript";
22411
+ import ts22 from "typescript";
22285
22412
  var UNRESOLVED = Symbol("unresolved");
22286
22413
  var NO_RETURN = Symbol("no-return");
22287
22414
  function extractSsrDefaults(metadata) {
@@ -22358,11 +22485,11 @@ function collectPropRefs(expr, propsObjectName, out) {
22358
22485
  if (!node)
22359
22486
  return;
22360
22487
  const visit3 = (n) => {
22361
- if (ts21.isPropertyAccessExpression(n) && ts21.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts21.isIdentifier(n.name)) {
22488
+ if (ts22.isPropertyAccessExpression(n) && ts22.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts22.isIdentifier(n.name)) {
22362
22489
  out.add(n.name.text);
22363
22490
  return;
22364
22491
  }
22365
- ts21.forEachChild(n, visit3);
22492
+ ts22.forEachChild(n, visit3);
22366
22493
  };
22367
22494
  visit3(node);
22368
22495
  }
@@ -22383,23 +22510,23 @@ function tryStaticEval(expr, ctx) {
22383
22510
  }
22384
22511
  function evalStatementsForReturn(statements, ctx) {
22385
22512
  for (const stmt of statements) {
22386
- if (ts21.isVariableStatement(stmt)) {
22513
+ if (ts22.isVariableStatement(stmt)) {
22387
22514
  for (const d of stmt.declarationList.declarations) {
22388
- if (!ts21.isIdentifier(d.name) || !d.initializer)
22515
+ if (!ts22.isIdentifier(d.name) || !d.initializer)
22389
22516
  continue;
22390
22517
  const v = evalNode(d.initializer, ctx);
22391
22518
  if (v !== UNRESOLVED)
22392
22519
  ctx.bindings[d.name.text] = v;
22393
22520
  }
22394
- } else if (ts21.isReturnStatement(stmt)) {
22521
+ } else if (ts22.isReturnStatement(stmt)) {
22395
22522
  return stmt.expression ? evalNode(stmt.expression, ctx) : UNRESOLVED;
22396
- } else if (ts21.isIfStatement(stmt)) {
22523
+ } else if (ts22.isIfStatement(stmt)) {
22397
22524
  const cond = evalNode(stmt.expression, ctx);
22398
22525
  if (cond === UNRESOLVED)
22399
22526
  return UNRESOLVED;
22400
22527
  const branch = cond ? stmt.thenStatement : stmt.elseStatement;
22401
22528
  if (branch) {
22402
- const taken = evalStatementsForReturn(ts21.isBlock(branch) ? branch.statements : [branch], ctx);
22529
+ const taken = evalStatementsForReturn(ts22.isBlock(branch) ? branch.statements : [branch], ctx);
22403
22530
  if (taken !== NO_RETURN)
22404
22531
  return taken;
22405
22532
  }
@@ -22410,45 +22537,45 @@ function evalStatementsForReturn(statements, ctx) {
22410
22537
  return NO_RETURN;
22411
22538
  }
22412
22539
  function parseExpression2(expr) {
22413
- const sf = ts21.createSourceFile("__ssr_default__.ts", `(${expr})`, ts21.ScriptTarget.Latest, false, ts21.ScriptKind.TS);
22540
+ const sf = ts22.createSourceFile("__ssr_default__.ts", `(${expr})`, ts22.ScriptTarget.Latest, false, ts22.ScriptKind.TS);
22414
22541
  const stmt = sf.statements[0];
22415
- if (!stmt || !ts21.isExpressionStatement(stmt))
22542
+ if (!stmt || !ts22.isExpressionStatement(stmt))
22416
22543
  return null;
22417
- const inner = ts21.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
22544
+ const inner = ts22.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
22418
22545
  return inner;
22419
22546
  }
22420
22547
  function evalNode(node, ctx) {
22421
- if (ts21.isParenthesizedExpression(node))
22548
+ if (ts22.isParenthesizedExpression(node))
22422
22549
  return evalNode(node.expression, ctx);
22423
- if (ts21.isAsExpression(node))
22550
+ if (ts22.isAsExpression(node))
22424
22551
  return evalNode(node.expression, ctx);
22425
- if (ts21.isSatisfiesExpression(node))
22552
+ if (ts22.isSatisfiesExpression(node))
22426
22553
  return evalNode(node.expression, ctx);
22427
- if (ts21.isTypeAssertionExpression(node))
22554
+ if (ts22.isTypeAssertionExpression(node))
22428
22555
  return evalNode(node.expression, ctx);
22429
- if (ts21.isNonNullExpression(node))
22556
+ if (ts22.isNonNullExpression(node))
22430
22557
  return evalNode(node.expression, ctx);
22431
- if (ts21.isArrowFunction(node)) {
22558
+ if (ts22.isArrowFunction(node)) {
22432
22559
  if (node.parameters.length !== 0)
22433
22560
  return UNRESOLVED;
22434
- if (!ts21.isBlock(node.body))
22561
+ if (!ts22.isBlock(node.body))
22435
22562
  return evalNode(node.body, ctx);
22436
22563
  const localBindings = { ...ctx.bindings };
22437
22564
  const localCtx = { ...ctx, bindings: localBindings };
22438
22565
  const result = evalStatementsForReturn(node.body.statements, localCtx);
22439
22566
  return result === NO_RETURN ? UNRESOLVED : result;
22440
22567
  }
22441
- if (ts21.isNumericLiteral(node))
22568
+ if (ts22.isNumericLiteral(node))
22442
22569
  return Number(node.text);
22443
- if (ts21.isStringLiteralLike(node))
22570
+ if (ts22.isStringLiteralLike(node))
22444
22571
  return node.text;
22445
- if (node.kind === ts21.SyntaxKind.TrueKeyword)
22572
+ if (node.kind === ts22.SyntaxKind.TrueKeyword)
22446
22573
  return true;
22447
- if (node.kind === ts21.SyntaxKind.FalseKeyword)
22574
+ if (node.kind === ts22.SyntaxKind.FalseKeyword)
22448
22575
  return false;
22449
- if (node.kind === ts21.SyntaxKind.NullKeyword)
22576
+ if (node.kind === ts22.SyntaxKind.NullKeyword)
22450
22577
  return null;
22451
- if (ts21.isIdentifier(node)) {
22578
+ if (ts22.isIdentifier(node)) {
22452
22579
  if (node.text === "undefined")
22453
22580
  return;
22454
22581
  if (node.text in ctx.bindings)
@@ -22457,29 +22584,29 @@ function evalNode(node, ctx) {
22457
22584
  return;
22458
22585
  return UNRESOLVED;
22459
22586
  }
22460
- if (ts21.isPrefixUnaryExpression(node)) {
22587
+ if (ts22.isPrefixUnaryExpression(node)) {
22461
22588
  const arg = evalNode(node.operand, ctx);
22462
22589
  if (arg === UNRESOLVED)
22463
22590
  return UNRESOLVED;
22464
22591
  switch (node.operator) {
22465
- case ts21.SyntaxKind.MinusToken:
22592
+ case ts22.SyntaxKind.MinusToken:
22466
22593
  return typeof arg === "number" ? -arg : UNRESOLVED;
22467
- case ts21.SyntaxKind.PlusToken:
22594
+ case ts22.SyntaxKind.PlusToken:
22468
22595
  return typeof arg === "number" ? +arg : UNRESOLVED;
22469
- case ts21.SyntaxKind.ExclamationToken:
22596
+ case ts22.SyntaxKind.ExclamationToken:
22470
22597
  return !arg;
22471
22598
  }
22472
22599
  return UNRESOLVED;
22473
22600
  }
22474
- if (ts21.isObjectLiteralExpression(node)) {
22601
+ if (ts22.isObjectLiteralExpression(node)) {
22475
22602
  const obj = {};
22476
22603
  for (const prop of node.properties) {
22477
- if (!ts21.isPropertyAssignment(prop))
22604
+ if (!ts22.isPropertyAssignment(prop))
22478
22605
  return UNRESOLVED;
22479
22606
  let key;
22480
- if (ts21.isIdentifier(prop.name) || ts21.isStringLiteralLike(prop.name)) {
22607
+ if (ts22.isIdentifier(prop.name) || ts22.isStringLiteralLike(prop.name)) {
22481
22608
  key = prop.name.text;
22482
- } else if (ts21.isNumericLiteral(prop.name)) {
22609
+ } else if (ts22.isNumericLiteral(prop.name)) {
22483
22610
  key = prop.name.text;
22484
22611
  } else {
22485
22612
  return UNRESOLVED;
@@ -22491,10 +22618,10 @@ function evalNode(node, ctx) {
22491
22618
  }
22492
22619
  return obj;
22493
22620
  }
22494
- if (ts21.isArrayLiteralExpression(node)) {
22621
+ if (ts22.isArrayLiteralExpression(node)) {
22495
22622
  const arr = [];
22496
22623
  for (const elem of node.elements) {
22497
- if (ts21.isOmittedExpression(elem))
22624
+ if (ts22.isOmittedExpression(elem))
22498
22625
  return UNRESOLVED;
22499
22626
  const v = evalNode(elem, ctx);
22500
22627
  if (v === UNRESOLVED)
@@ -22503,7 +22630,7 @@ function evalNode(node, ctx) {
22503
22630
  }
22504
22631
  return arr;
22505
22632
  }
22506
- if (ts21.isElementAccessExpression(node)) {
22633
+ if (ts22.isElementAccessExpression(node)) {
22507
22634
  const base = evalNode(node.expression, ctx);
22508
22635
  if (base === undefined)
22509
22636
  return;
@@ -22517,17 +22644,17 @@ function evalNode(node, ctx) {
22517
22644
  const k = String(key);
22518
22645
  return Object.prototype.hasOwnProperty.call(base, k) ? base[k] : undefined;
22519
22646
  }
22520
- if (ts21.isPropertyAccessExpression(node)) {
22647
+ if (ts22.isPropertyAccessExpression(node)) {
22521
22648
  const baseResult = evalNode(node.expression, ctx);
22522
22649
  if (baseResult === undefined)
22523
22650
  return;
22524
22651
  return UNRESOLVED;
22525
22652
  }
22526
- if (ts21.isCallExpression(node)) {
22527
- if (node.arguments.length === 0 && ts21.isIdentifier(node.expression) && node.expression.text in ctx.bindings) {
22653
+ if (ts22.isCallExpression(node)) {
22654
+ if (node.arguments.length === 0 && ts22.isIdentifier(node.expression) && node.expression.text in ctx.bindings) {
22528
22655
  return ctx.bindings[node.expression.text];
22529
22656
  }
22530
- if (ts21.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
22657
+ if (ts22.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
22531
22658
  const recv = evalNode(node.expression.expression, ctx);
22532
22659
  if (Array.isArray(recv)) {
22533
22660
  let sep = ",";
@@ -22543,27 +22670,27 @@ function evalNode(node, ctx) {
22543
22670
  }
22544
22671
  return UNRESOLVED;
22545
22672
  }
22546
- if (ts21.isConditionalExpression(node)) {
22673
+ if (ts22.isConditionalExpression(node)) {
22547
22674
  const cond = evalNode(node.condition, ctx);
22548
22675
  if (cond === UNRESOLVED)
22549
22676
  return UNRESOLVED;
22550
22677
  return cond ? evalNode(node.whenTrue, ctx) : evalNode(node.whenFalse, ctx);
22551
22678
  }
22552
- if (ts21.isBinaryExpression(node)) {
22679
+ if (ts22.isBinaryExpression(node)) {
22553
22680
  const op = node.operatorToken.kind;
22554
- if (op === ts21.SyntaxKind.QuestionQuestionToken) {
22681
+ if (op === ts22.SyntaxKind.QuestionQuestionToken) {
22555
22682
  const l2 = evalNode(node.left, ctx);
22556
22683
  if (l2 !== UNRESOLVED && l2 !== null && l2 !== undefined)
22557
22684
  return l2;
22558
22685
  return evalNode(node.right, ctx);
22559
22686
  }
22560
- if (op === ts21.SyntaxKind.BarBarToken) {
22687
+ if (op === ts22.SyntaxKind.BarBarToken) {
22561
22688
  const l2 = evalNode(node.left, ctx);
22562
22689
  if (l2 !== UNRESOLVED && l2)
22563
22690
  return l2;
22564
22691
  return evalNode(node.right, ctx);
22565
22692
  }
22566
- if (op === ts21.SyntaxKind.AmpersandAmpersandToken) {
22693
+ if (op === ts22.SyntaxKind.AmpersandAmpersandToken) {
22567
22694
  const l2 = evalNode(node.left, ctx);
22568
22695
  if (l2 === UNRESOLVED)
22569
22696
  return UNRESOLVED;
@@ -22576,30 +22703,30 @@ function evalNode(node, ctx) {
22576
22703
  if (l === UNRESOLVED || r === UNRESOLVED)
22577
22704
  return UNRESOLVED;
22578
22705
  switch (op) {
22579
- case ts21.SyntaxKind.PlusToken:
22706
+ case ts22.SyntaxKind.PlusToken:
22580
22707
  if (typeof l === "string" || typeof r === "string")
22581
22708
  return `${l}${r}`;
22582
22709
  if (typeof l === "number" && typeof r === "number")
22583
22710
  return l + r;
22584
22711
  return UNRESOLVED;
22585
- case ts21.SyntaxKind.MinusToken:
22712
+ case ts22.SyntaxKind.MinusToken:
22586
22713
  return typeof l === "number" && typeof r === "number" ? l - r : UNRESOLVED;
22587
- case ts21.SyntaxKind.AsteriskToken:
22714
+ case ts22.SyntaxKind.AsteriskToken:
22588
22715
  return typeof l === "number" && typeof r === "number" ? l * r : UNRESOLVED;
22589
- case ts21.SyntaxKind.SlashToken:
22716
+ case ts22.SyntaxKind.SlashToken:
22590
22717
  return typeof l === "number" && typeof r === "number" && r !== 0 ? l / r : UNRESOLVED;
22591
- case ts21.SyntaxKind.PercentToken:
22718
+ case ts22.SyntaxKind.PercentToken:
22592
22719
  return typeof l === "number" && typeof r === "number" && r !== 0 ? l % r : UNRESOLVED;
22593
- case ts21.SyntaxKind.EqualsEqualsEqualsToken:
22594
- case ts21.SyntaxKind.EqualsEqualsToken:
22720
+ case ts22.SyntaxKind.EqualsEqualsEqualsToken:
22721
+ case ts22.SyntaxKind.EqualsEqualsToken:
22595
22722
  return l === r;
22596
- case ts21.SyntaxKind.ExclamationEqualsEqualsToken:
22597
- case ts21.SyntaxKind.ExclamationEqualsToken:
22723
+ case ts22.SyntaxKind.ExclamationEqualsEqualsToken:
22724
+ case ts22.SyntaxKind.ExclamationEqualsToken:
22598
22725
  return l !== r;
22599
22726
  }
22600
22727
  return UNRESOLVED;
22601
22728
  }
22602
- if (ts21.isTemplateExpression(node)) {
22729
+ if (ts22.isTemplateExpression(node)) {
22603
22730
  if (node.templateSpans.length === 0)
22604
22731
  return node.head.text;
22605
22732
  let acc = node.head.text;
@@ -22611,41 +22738,41 @@ function evalNode(node, ctx) {
22611
22738
  }
22612
22739
  return acc;
22613
22740
  }
22614
- if (ts21.isNoSubstitutionTemplateLiteral(node))
22741
+ if (ts22.isNoSubstitutionTemplateLiteral(node))
22615
22742
  return node.text;
22616
22743
  return UNRESOLVED;
22617
22744
  }
22618
22745
 
22619
22746
  // ../jsx/src/augment-inherited-props.ts
22620
- import ts22 from "typescript";
22747
+ import ts23 from "typescript";
22621
22748
  function parseStaticStringConst(source) {
22622
- const sf = ts22.createSourceFile("__const.ts", `const __x = (${source});`, ts22.ScriptTarget.Latest, false);
22749
+ const sf = ts23.createSourceFile("__const.ts", `const __x = (${source});`, ts23.ScriptTarget.Latest, false);
22623
22750
  const stmt = sf.statements[0];
22624
- if (!stmt || !ts22.isVariableStatement(stmt))
22751
+ if (!stmt || !ts23.isVariableStatement(stmt))
22625
22752
  return null;
22626
22753
  let init = stmt.declarationList.declarations[0]?.initializer;
22627
- while (init && ts22.isParenthesizedExpression(init))
22754
+ while (init && ts23.isParenthesizedExpression(init))
22628
22755
  init = init.expression;
22629
22756
  if (!init)
22630
22757
  return null;
22631
- if (ts22.isStringLiteral(init) || ts22.isNoSubstitutionTemplateLiteral(init)) {
22758
+ if (ts23.isStringLiteral(init) || ts23.isNoSubstitutionTemplateLiteral(init)) {
22632
22759
  return init.text;
22633
22760
  }
22634
22761
  return evalStringArrayJoin(source);
22635
22762
  }
22636
22763
  function evalTemplateOfStringConsts(source, resolved) {
22637
- const sf = ts22.createSourceFile("__const.ts", `const __x = (${source});`, ts22.ScriptTarget.Latest, false);
22764
+ const sf = ts23.createSourceFile("__const.ts", `const __x = (${source});`, ts23.ScriptTarget.Latest, false);
22638
22765
  const stmt = sf.statements[0];
22639
- if (!stmt || !ts22.isVariableStatement(stmt))
22766
+ if (!stmt || !ts23.isVariableStatement(stmt))
22640
22767
  return null;
22641
22768
  let init = stmt.declarationList.declarations[0]?.initializer;
22642
- while (init && ts22.isParenthesizedExpression(init))
22769
+ while (init && ts23.isParenthesizedExpression(init))
22643
22770
  init = init.expression;
22644
- if (!init || !ts22.isTemplateExpression(init))
22771
+ if (!init || !ts23.isTemplateExpression(init))
22645
22772
  return null;
22646
22773
  let out = init.head.text;
22647
22774
  for (const span of init.templateSpans) {
22648
- if (!ts22.isIdentifier(span.expression))
22775
+ if (!ts23.isIdentifier(span.expression))
22649
22776
  return null;
22650
22777
  const value = resolved.get(span.expression.text);
22651
22778
  if (value === undefined)
@@ -22673,28 +22800,28 @@ function collectModuleStringConsts(constants) {
22673
22800
  return map;
22674
22801
  }
22675
22802
  function evalStringArrayJoin(source) {
22676
- const sf = ts22.createSourceFile("__join.ts", `const __x = (${source});`, ts22.ScriptTarget.Latest, false);
22803
+ const sf = ts23.createSourceFile("__join.ts", `const __x = (${source});`, ts23.ScriptTarget.Latest, false);
22677
22804
  const stmt = sf.statements[0];
22678
- if (!stmt || !ts22.isVariableStatement(stmt))
22805
+ if (!stmt || !ts23.isVariableStatement(stmt))
22679
22806
  return null;
22680
22807
  let node = stmt.declarationList.declarations[0]?.initializer;
22681
- while (node && ts22.isParenthesizedExpression(node))
22808
+ while (node && ts23.isParenthesizedExpression(node))
22682
22809
  node = node.expression;
22683
- if (!node || !ts22.isCallExpression(node))
22810
+ if (!node || !ts23.isCallExpression(node))
22684
22811
  return null;
22685
22812
  const callee = node.expression;
22686
- if (!ts22.isPropertyAccessExpression(callee))
22813
+ if (!ts23.isPropertyAccessExpression(callee))
22687
22814
  return null;
22688
22815
  if (callee.name.text !== "join")
22689
22816
  return null;
22690
22817
  let recv = callee.expression;
22691
- while (ts22.isParenthesizedExpression(recv))
22818
+ while (ts23.isParenthesizedExpression(recv))
22692
22819
  recv = recv.expression;
22693
- if (!ts22.isArrayLiteralExpression(recv))
22820
+ if (!ts23.isArrayLiteralExpression(recv))
22694
22821
  return null;
22695
22822
  const parts = [];
22696
22823
  for (const el of recv.elements) {
22697
- if (ts22.isStringLiteral(el) || ts22.isNoSubstitutionTemplateLiteral(el)) {
22824
+ if (ts23.isStringLiteral(el) || ts23.isNoSubstitutionTemplateLiteral(el)) {
22698
22825
  parts.push(el.text);
22699
22826
  } else {
22700
22827
  return null;
@@ -22703,7 +22830,7 @@ function evalStringArrayJoin(source) {
22703
22830
  let sep = ",";
22704
22831
  if (node.arguments.length >= 1) {
22705
22832
  const arg = node.arguments[0];
22706
- if (ts22.isStringLiteral(arg) || ts22.isNoSubstitutionTemplateLiteral(arg))
22833
+ if (ts23.isStringLiteral(arg) || ts23.isNoSubstitutionTemplateLiteral(arg))
22707
22834
  sep = arg.text;
22708
22835
  else
22709
22836
  return null;
@@ -23045,13 +23172,13 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
23045
23172
  if (entries.some((e) => e.componentIR.metadata.isClientComponent)) {
23046
23173
  const topLevelNames = new Set;
23047
23174
  {
23048
- const sf = ts23.createSourceFile(filePath, source, ts23.ScriptTarget.Latest, true, ts23.ScriptKind.TSX);
23175
+ const sf = ts24.createSourceFile(filePath, source, ts24.ScriptTarget.Latest, true, ts24.ScriptKind.TSX);
23049
23176
  for (const stmt of sf.statements) {
23050
- if (ts23.isFunctionDeclaration(stmt) && stmt.name)
23177
+ if (ts24.isFunctionDeclaration(stmt) && stmt.name)
23051
23178
  topLevelNames.add(stmt.name.text);
23052
- else if (ts23.isVariableStatement(stmt)) {
23179
+ else if (ts24.isVariableStatement(stmt)) {
23053
23180
  for (const d of stmt.declarationList.declarations) {
23054
- if (ts23.isIdentifier(d.name))
23181
+ if (ts24.isIdentifier(d.name))
23055
23182
  topLevelNames.add(d.name.text);
23056
23183
  }
23057
23184
  }
@@ -23110,7 +23237,7 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
23110
23237
  const moduleStatementSeen = new Set;
23111
23238
  const moduleStatementsOrdered = [];
23112
23239
  const collectModuleStatements = (block) => {
23113
- const sf = ts23.createSourceFile("__bf_module_decls.tsx", block, ts23.ScriptTarget.Latest, false, ts23.ScriptKind.TSX);
23240
+ const sf = ts24.createSourceFile("__bf_module_decls.tsx", block, ts24.ScriptTarget.Latest, false, ts24.ScriptKind.TSX);
23114
23241
  for (const stmt of sf.statements) {
23115
23242
  const text = stmt.getText(sf);
23116
23243
  if (moduleStatementSeen.has(text))
@@ -23347,6 +23474,12 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
23347
23474
  }
23348
23475
  return { files, errors };
23349
23476
  }
23477
+ function componentTypeParametersText(componentNode, sourceFile) {
23478
+ const typeParameters = componentNode?.typeParameters;
23479
+ if (!typeParameters || typeParameters.length === 0)
23480
+ return null;
23481
+ return `<${typeParameters.map((p) => p.getText(sourceFile)).join(", ")}>`;
23482
+ }
23350
23483
  function buildMetadata(ctx) {
23351
23484
  const metadata = {
23352
23485
  componentName: ctx.componentName || "Unknown",
@@ -23355,6 +23488,7 @@ function buildMetadata(ctx) {
23355
23488
  isClientComponent: ctx.hasUseClientDirective,
23356
23489
  typeDefinitions: ctx.typeDefinitions,
23357
23490
  propsType: ctx.propsType,
23491
+ typeParameters: componentTypeParametersText(ctx.componentNode, ctx.sourceFile),
23358
23492
  propsParams: ctx.propsParams,
23359
23493
  propsObjectName: ctx.propsObjectName,
23360
23494
  restPropsName: ctx.restPropsName,
@@ -23545,7 +23679,7 @@ function compileJSX(source, filePath, options) {
23545
23679
  return { files, errors };
23546
23680
  }
23547
23681
  // ../jsx/src/shared-program.ts
23548
- import ts24 from "typescript";
23682
+ import ts25 from "typescript";
23549
23683
  import path3 from "node:path";
23550
23684
  function commonParent(paths) {
23551
23685
  if (paths.length === 0)
@@ -23567,10 +23701,10 @@ function commonParent(paths) {
23567
23701
  function createProgramForCorpus(files, options = {}) {
23568
23702
  const baseUrl = options.baseUrl ?? commonParent(files);
23569
23703
  const compilerOptions = {
23570
- target: ts24.ScriptTarget.Latest,
23571
- module: ts24.ModuleKind.ESNext,
23572
- moduleResolution: ts24.ModuleResolutionKind.Bundler,
23573
- jsx: ts24.JsxEmit.ReactJSX,
23704
+ target: ts25.ScriptTarget.Latest,
23705
+ module: ts25.ModuleKind.ESNext,
23706
+ moduleResolution: ts25.ModuleResolutionKind.Bundler,
23707
+ jsx: ts25.JsxEmit.ReactJSX,
23574
23708
  strict: true,
23575
23709
  skipLibCheck: true,
23576
23710
  noEmit: true,
@@ -23580,7 +23714,7 @@ function createProgramForCorpus(files, options = {}) {
23580
23714
  ...options.compilerOptions
23581
23715
  };
23582
23716
  const absolute = files.map((f) => path3.resolve(f));
23583
- return ts24.createProgram(absolute, compilerOptions, undefined, options.oldProgram);
23717
+ return ts25.createProgram(absolute, compilerOptions, undefined, options.oldProgram);
23584
23718
  }
23585
23719
  // ../jsx/src/adapters/interface.ts
23586
23720
  class BaseAdapter {
@@ -23634,7 +23768,7 @@ class JsxAdapter extends BaseAdapter {
23634
23768
  ...localFunctions.map((f) => ({ name: f.name, body: f.body })),
23635
23769
  ...localConstants.map((c) => ({ name: c.name, body: c.value }))
23636
23770
  ];
23637
- const reachable = findReachableNames(primaryRefText, declarations);
23771
+ const reachable = closeOverWritersOfMutableBindings(primaryRefText, declarations, new Set(ir.metadata.localConstants.filter((c) => (c.declarationKind ?? "const") !== "const").map((c) => c.name)));
23638
23772
  const reachableBodies = [...reachable].map((name) => {
23639
23773
  const func = localFunctions.find((f) => f.name === name);
23640
23774
  if (func)
@@ -23664,9 +23798,10 @@ class JsxAdapter extends BaseAdapter {
23664
23798
  lines.push(` const ${signal.getter} = () => ${initialValue}`);
23665
23799
  }
23666
23800
  if (signal.setter) {
23667
- const setterUsed = new RegExp(`\\b${signal.setter}\\b`).test(setterRefText);
23801
+ const setterUsed = identifierPattern(signal.setter).test(setterRefText);
23668
23802
  if (setterUsed) {
23669
- lines.push(` const ${signal.setter} = (..._args: any[]) => {}`);
23803
+ const setterType = preserveTypes && signal.type.kind !== "unknown" ? `(valueOrFn: ${signal.type.raw} | ((prev: ${signal.type.raw}) => ${signal.type.raw})) => void` : null;
23804
+ lines.push(setterType ? ` const ${signal.setter}: ${setterType} = () => {}` : ` const ${signal.setter} = (..._args: any[]) => {}`);
23670
23805
  }
23671
23806
  }
23672
23807
  }
@@ -23862,6 +23997,7 @@ class JsxAdapter extends BaseAdapter {
23862
23997
  }
23863
23998
 
23864
23999
  // ../jsx/src/adapters/template-imports.ts
24000
+ import ts26 from "typescript";
23865
24001
  var CLIENT_PACKAGE_SOURCES = new Set([
23866
24002
  "@barefootjs/client",
23867
24003
  "@barefootjs/client/runtime"
@@ -24000,7 +24136,8 @@ export default ${this.componentName}` : "";
24000
24136
  const noArgDefault = hasRequiredProps ? "" : ` = {} as ${propsTypeExpr}`;
24001
24137
  const lines = [];
24002
24138
  const exportPrefix = ir.metadata.isExported === false ? "" : "export ";
24003
- lines.push(`${exportPrefix}function ${name}(${fullPropsDestructure}${typeAnnotation}${noArgDefault}) {`);
24139
+ const typeParameters = ir.metadata.typeParameters ?? "";
24140
+ lines.push(`${exportPrefix}function ${name}${typeParameters}(${fullPropsDestructure}${typeAnnotation}${noArgDefault}) {`);
24004
24141
  if (hasClientInteractivity) {
24005
24142
  lines.push(` const __scopeId = (/_s\\d/.test(__bfScope || '') ? __bfScope : null) || __instanceId || \`${name}_\${Math.random().toString(36).slice(2, 8)}\``);
24006
24143
  } else {
@@ -24251,11 +24388,11 @@ function registerBuiltinLoweringPlugins() {
24251
24388
  registerLoweringPlugin(plugin);
24252
24389
  }
24253
24390
  // ../jsx/src/combine-client-js.ts
24254
- import ts25 from "typescript";
24391
+ import ts27 from "typescript";
24255
24392
  // ../jsx/src/debug.ts
24256
- import ts26 from "typescript";
24393
+ import ts28 from "typescript";
24257
24394
  // ../jsx/src/profiler.ts
24258
- import ts27 from "typescript";
24395
+ import ts29 from "typescript";
24259
24396
 
24260
24397
  // ../jsx/src/index.ts
24261
24398
  registerBuiltinLoweringPlugins();