@farm.js/react 0.1.0-beta.31 → 0.1.0-beta.32

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/vite.cjs CHANGED
@@ -332,12 +332,10 @@ function isPotentialKeyedMembershipCall(expression, reactiveByValue) {
332
332
  }
333
333
  function containsPotentialKeyedMembershipCall(expression, reactiveByValue) {
334
334
  let found = false;
335
- core.traverse(expressionFile(cloneExpression(expression)), {
336
- CallExpression(path) {
337
- if (!isPotentialKeyedMembershipCall(path.node, reactiveByValue)) return;
338
- found = true;
339
- path.stop();
340
- }
335
+ core.types.traverseFast(expression, (node) => {
336
+ if (!core.types.isCallExpression(node) || !isPotentialKeyedMembershipCall(node, reactiveByValue)) return;
337
+ found = true;
338
+ return core.types.traverseFast.stop;
341
339
  });
342
340
  return found;
343
341
  }
@@ -350,12 +348,10 @@ function isPotentialKeyedMapLookupCall(expression, reactiveByValue) {
350
348
  }
351
349
  function containsPotentialKeyedMapLookupCall(expression, reactiveByValue) {
352
350
  let found = false;
353
- core.traverse(expressionFile(cloneExpression(expression)), {
354
- CallExpression(path) {
355
- if (!isPotentialKeyedMapLookupCall(path.node, reactiveByValue)) return;
356
- found = true;
357
- path.stop();
358
- }
351
+ core.types.traverseFast(expression, (node) => {
352
+ if (!core.types.isCallExpression(node) || !isPotentialKeyedMapLookupCall(node, reactiveByValue)) return;
353
+ found = true;
354
+ return core.types.traverseFast.stop;
359
355
  });
360
356
  return found;
361
357
  }
@@ -433,6 +429,14 @@ function keyedMapLookupTarget(binding, keyCallback, renderCallback, reactiveByVa
433
429
  }
434
430
  function collectReferencedLocals(expression, names) {
435
431
  if (names.size === 0) return [];
432
+ let possible = false;
433
+ core.types.traverseFast(expression, (node) => {
434
+ if ((core.types.isIdentifier(node) || core.types.isJSXIdentifier(node)) && names.has(node.name)) {
435
+ possible = true;
436
+ return core.types.traverseFast.stop;
437
+ }
438
+ });
439
+ if (!possible) return [];
436
440
  const references = /* @__PURE__ */ new Set();
437
441
  core.traverse(expressionFile(cloneExpression(expression)), {
438
442
  ReferencedIdentifier(path) {
@@ -4895,6 +4899,57 @@ function canCloneKeyedRows(plan) {
4895
4899
  };
4896
4900
  return cloneable(plan.row);
4897
4901
  }
4902
+ function keyedRowBindingTargets(plan) {
4903
+ if (!canCloneKeyedRows(plan)) return void 0;
4904
+ const root = core.types.identifier("row");
4905
+ const targets = /* @__PURE__ */ new Map([["", root]]);
4906
+ const statements = [];
4907
+ let independentReads = 0;
4908
+ for (const binding of plan.bindings) {
4909
+ const path = [];
4910
+ for (const index of binding.path) {
4911
+ independentReads += index + 1;
4912
+ for (let sibling = 0; sibling <= index; sibling += 1) {
4913
+ const key = [...path, sibling].join(".");
4914
+ if (targets.has(key)) continue;
4915
+ if (statements.length === 32) return void 0;
4916
+ const parent = targets.get(
4917
+ sibling === 0 ? path.join(".") : [...path, sibling - 1].join(".")
4918
+ );
4919
+ const target = core.types.identifier(`target${statements.length}`);
4920
+ statements.push(
4921
+ core.types.variableDeclaration("const", [
4922
+ core.types.variableDeclarator(
4923
+ target,
4924
+ core.types.optionalMemberExpression(
4925
+ parent,
4926
+ core.types.identifier(sibling === 0 ? "firstElementChild" : "nextElementSibling"),
4927
+ false,
4928
+ true
4929
+ )
4930
+ )
4931
+ ])
4932
+ );
4933
+ targets.set(key, target);
4934
+ }
4935
+ path.push(index);
4936
+ }
4937
+ }
4938
+ if (statements.length >= independentReads) return void 0;
4939
+ return core.types.arrowFunctionExpression(
4940
+ [root],
4941
+ core.types.blockStatement([
4942
+ ...statements,
4943
+ core.types.returnStatement(
4944
+ core.types.arrayExpression(
4945
+ plan.bindings.map(
4946
+ (binding) => core.types.logicalExpression("??", targets.get(binding.path.join(".")), core.types.nullLiteral())
4947
+ )
4948
+ )
4949
+ )
4950
+ ])
4951
+ );
4952
+ }
4898
4953
  function keyedRowsBoundary(blockRuntime, plan, keyedMapUpdateHints, keyedArrayFilterHintedStateIndices, keyedArrayPrependHintedStateIndices, keyedArrayPositionHintedStateIndices, keyedArrayReorderHintedStateIndices) {
4899
4954
  const name = core.types.jsxMemberExpression(
4900
4955
  core.types.jsxIdentifier(blockRuntime.name),
@@ -4912,6 +4967,7 @@ function keyedRowsBoundary(blockRuntime, plan, keyedMapUpdateHints, keyedArrayFi
4912
4967
  ...plan.conditionals.map((conditional) => conditional.test)
4913
4968
  ]);
4914
4969
  const delegatedEvents = canDelegateKeyedRowEvents(plan);
4970
+ const bindingTargets = keyedRowBindingTargets(plan);
4915
4971
  const renderSource = keyedRowsRenderSource(plan, eventFactory, conditionalFactory);
4916
4972
  const renderFactoryParameters = plan.conditionals.length > 0 ? [core.types.cloneNode(eventFactory), core.types.cloneNode(conditionalFactory)] : plan.events.length > 0 ? [core.types.cloneNode(eventFactory)] : [];
4917
4973
  return core.types.jsxElement(
@@ -5032,6 +5088,7 @@ function keyedRowsBoundary(blockRuntime, plan, keyedMapUpdateHints, keyedArrayFi
5032
5088
  core.types.jsxExpressionContainer(core.types.booleanLiteral(true))
5033
5089
  )
5034
5090
  ] : [],
5091
+ ...bindingTargets ? [core.types.jsxAttribute(core.types.jsxIdentifier("targets"), core.types.jsxExpressionContainer(bindingTargets))] : [],
5035
5092
  ...canCloneKeyedRows(plan) ? [
5036
5093
  core.types.jsxAttribute(
5037
5094
  core.types.jsxIdentifier("cloneRows"),