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

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.mjs CHANGED
@@ -78,6 +78,7 @@ var COMPILER_RUNTIME_FEATURE_EXPORTS = {
78
78
  "keyed-rows-window-position-hinted": "keyedRowsWindowPositionHintedRuntimeFeature",
79
79
  "keyed-rows-reorder-hinted": "keyedRowsReorderHintedRuntimeFeature",
80
80
  "keyed-rows-plain-reorder-hinted": "keyedRowsPlainReorderHintedRuntimeFeature",
81
+ "keyed-rows-plain-map-reorder-hinted": "keyedRowsPlainMapReorderHintedRuntimeFeature",
81
82
  "keyed-rows-map-reorder-hinted": "keyedRowsMapReorderHintedRuntimeFeature",
82
83
  "keyed-rows-all-hinted": "keyedRowsAllHintedRuntimeFeature",
83
84
  "keyed-rows-mapped-rolling-window-hinted": "keyedRowsMappedRollingWindowHintedRuntimeFeature",
@@ -186,6 +187,8 @@ function runtimeFeaturesForPlans(plans, keyedUpdateHints, keyedArrayFilterHints,
186
187
  features.add("keyed-rows-prepend-only");
187
188
  } else if (keyedRowsFeature === "keyed-rows" && hintSuffix === "-reorder-hinted" && keyedTargetKinds.size === 0) {
188
189
  features.add("keyed-rows-plain-reorder-hinted");
190
+ } else if (keyedRowsFeature === "keyed-rows" && hintSuffix === "-map-reorder-hinted" && keyedTargetKinds.size === 0) {
191
+ features.add("keyed-rows-plain-map-reorder-hinted");
189
192
  } else if (keyedRowsFeature === "keyed-rows" && hintSuffix === "-filter-hinted" && keyedTargetKinds.size === 1 && keyedTargetKinds.has("identity")) {
190
193
  features.add(
191
194
  keyedMapOrAppendHints ? "keyed-rows-identity-filter-hinted" : "keyed-rows-identity-filter-only"
@@ -330,12 +333,10 @@ function isPotentialKeyedMembershipCall(expression, reactiveByValue) {
330
333
  }
331
334
  function containsPotentialKeyedMembershipCall(expression, reactiveByValue) {
332
335
  let found = false;
333
- traverse(expressionFile(cloneExpression(expression)), {
334
- CallExpression(path) {
335
- if (!isPotentialKeyedMembershipCall(path.node, reactiveByValue)) return;
336
- found = true;
337
- path.stop();
338
- }
336
+ types.traverseFast(expression, (node) => {
337
+ if (!types.isCallExpression(node) || !isPotentialKeyedMembershipCall(node, reactiveByValue)) return;
338
+ found = true;
339
+ return types.traverseFast.stop;
339
340
  });
340
341
  return found;
341
342
  }
@@ -348,12 +349,10 @@ function isPotentialKeyedMapLookupCall(expression, reactiveByValue) {
348
349
  }
349
350
  function containsPotentialKeyedMapLookupCall(expression, reactiveByValue) {
350
351
  let found = false;
351
- traverse(expressionFile(cloneExpression(expression)), {
352
- CallExpression(path) {
353
- if (!isPotentialKeyedMapLookupCall(path.node, reactiveByValue)) return;
354
- found = true;
355
- path.stop();
356
- }
352
+ types.traverseFast(expression, (node) => {
353
+ if (!types.isCallExpression(node) || !isPotentialKeyedMapLookupCall(node, reactiveByValue)) return;
354
+ found = true;
355
+ return types.traverseFast.stop;
357
356
  });
358
357
  return found;
359
358
  }
@@ -431,6 +430,14 @@ function keyedMapLookupTarget(binding, keyCallback, renderCallback, reactiveByVa
431
430
  }
432
431
  function collectReferencedLocals(expression, names) {
433
432
  if (names.size === 0) return [];
433
+ let possible = false;
434
+ types.traverseFast(expression, (node) => {
435
+ if ((types.isIdentifier(node) || types.isJSXIdentifier(node)) && names.has(node.name)) {
436
+ possible = true;
437
+ return types.traverseFast.stop;
438
+ }
439
+ });
440
+ if (!possible) return [];
434
441
  const references = /* @__PURE__ */ new Set();
435
442
  traverse(expressionFile(cloneExpression(expression)), {
436
443
  ReferencedIdentifier(path) {
@@ -4893,6 +4900,57 @@ function canCloneKeyedRows(plan) {
4893
4900
  };
4894
4901
  return cloneable(plan.row);
4895
4902
  }
4903
+ function keyedRowBindingTargets(plan) {
4904
+ if (!canCloneKeyedRows(plan)) return void 0;
4905
+ const root = types.identifier("row");
4906
+ const targets = /* @__PURE__ */ new Map([["", root]]);
4907
+ const statements = [];
4908
+ let independentReads = 0;
4909
+ for (const binding of plan.bindings) {
4910
+ const path = [];
4911
+ for (const index of binding.path) {
4912
+ independentReads += index + 1;
4913
+ for (let sibling = 0; sibling <= index; sibling += 1) {
4914
+ const key = [...path, sibling].join(".");
4915
+ if (targets.has(key)) continue;
4916
+ if (statements.length === 32) return void 0;
4917
+ const parent = targets.get(
4918
+ sibling === 0 ? path.join(".") : [...path, sibling - 1].join(".")
4919
+ );
4920
+ const target = types.identifier(`target${statements.length}`);
4921
+ statements.push(
4922
+ types.variableDeclaration("const", [
4923
+ types.variableDeclarator(
4924
+ target,
4925
+ types.optionalMemberExpression(
4926
+ parent,
4927
+ types.identifier(sibling === 0 ? "firstElementChild" : "nextElementSibling"),
4928
+ false,
4929
+ true
4930
+ )
4931
+ )
4932
+ ])
4933
+ );
4934
+ targets.set(key, target);
4935
+ }
4936
+ path.push(index);
4937
+ }
4938
+ }
4939
+ if (statements.length >= independentReads) return void 0;
4940
+ return types.arrowFunctionExpression(
4941
+ [root],
4942
+ types.blockStatement([
4943
+ ...statements,
4944
+ types.returnStatement(
4945
+ types.arrayExpression(
4946
+ plan.bindings.map(
4947
+ (binding) => types.logicalExpression("??", targets.get(binding.path.join(".")), types.nullLiteral())
4948
+ )
4949
+ )
4950
+ )
4951
+ ])
4952
+ );
4953
+ }
4896
4954
  function keyedRowsBoundary(blockRuntime, plan, keyedMapUpdateHints, keyedArrayFilterHintedStateIndices, keyedArrayPrependHintedStateIndices, keyedArrayPositionHintedStateIndices, keyedArrayReorderHintedStateIndices) {
4897
4955
  const name = types.jsxMemberExpression(
4898
4956
  types.jsxIdentifier(blockRuntime.name),
@@ -4910,6 +4968,7 @@ function keyedRowsBoundary(blockRuntime, plan, keyedMapUpdateHints, keyedArrayFi
4910
4968
  ...plan.conditionals.map((conditional) => conditional.test)
4911
4969
  ]);
4912
4970
  const delegatedEvents = canDelegateKeyedRowEvents(plan);
4971
+ const bindingTargets = keyedRowBindingTargets(plan);
4913
4972
  const renderSource = keyedRowsRenderSource(plan, eventFactory, conditionalFactory);
4914
4973
  const renderFactoryParameters = plan.conditionals.length > 0 ? [types.cloneNode(eventFactory), types.cloneNode(conditionalFactory)] : plan.events.length > 0 ? [types.cloneNode(eventFactory)] : [];
4915
4974
  return types.jsxElement(
@@ -5030,6 +5089,7 @@ function keyedRowsBoundary(blockRuntime, plan, keyedMapUpdateHints, keyedArrayFi
5030
5089
  types.jsxExpressionContainer(types.booleanLiteral(true))
5031
5090
  )
5032
5091
  ] : [],
5092
+ ...bindingTargets ? [types.jsxAttribute(types.jsxIdentifier("targets"), types.jsxExpressionContainer(bindingTargets))] : [],
5033
5093
  ...canCloneKeyedRows(plan) ? [
5034
5094
  types.jsxAttribute(
5035
5095
  types.jsxIdentifier("cloneRows"),