@farm.js/react 0.1.0-beta.6 → 0.1.0-beta.8

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
@@ -68,36 +68,52 @@ var COMPILER_RUNTIME_FEATURE_EXPORTS = {
68
68
  "keyed-rows": "keyedRowsRuntimeFeature",
69
69
  "keyed-rows-hinted": "keyedRowsHintedRuntimeFeature",
70
70
  "keyed-rows-position-hinted": "keyedRowsPositionHintedRuntimeFeature",
71
+ "keyed-rows-batch-position-hinted": "keyedRowsBatchPositionHintedRuntimeFeature",
72
+ "keyed-rows-window-position-hinted": "keyedRowsWindowPositionHintedRuntimeFeature",
71
73
  "keyed-rows-reorder-hinted": "keyedRowsReorderHintedRuntimeFeature",
72
74
  "keyed-rows-all-hinted": "keyedRowsAllHintedRuntimeFeature",
73
75
  "keyed-rows-every-hinted": "keyedRowsEveryHintedRuntimeFeature",
76
+ "keyed-rows-batch-every-hinted": "keyedRowsBatchEveryHintedRuntimeFeature",
77
+ "keyed-rows-window-every-hinted": "keyedRowsWindowEveryHintedRuntimeFeature",
74
78
  "keyed-rows-filter-hinted": "keyedRowsFilterHintedRuntimeFeature",
75
79
  "keyed-rows-prepend-hinted": "keyedRowsPrependHintedRuntimeFeature",
76
80
  "keyed-rows-filter-prepend-hinted": "keyedRowsFilterPrependHintedRuntimeFeature",
77
81
  "keyed-rows-conditional": "keyedRowsConditionalRuntimeFeature",
78
82
  "keyed-rows-conditional-hinted": "keyedRowsConditionalHintedRuntimeFeature",
79
83
  "keyed-rows-conditional-position-hinted": "keyedRowsConditionalPositionHintedRuntimeFeature",
84
+ "keyed-rows-conditional-batch-position-hinted": "keyedRowsConditionalBatchPositionHintedRuntimeFeature",
85
+ "keyed-rows-conditional-window-position-hinted": "keyedRowsConditionalWindowPositionHintedRuntimeFeature",
80
86
  "keyed-rows-conditional-reorder-hinted": "keyedRowsConditionalReorderHintedRuntimeFeature",
81
87
  "keyed-rows-conditional-all-hinted": "keyedRowsConditionalAllHintedRuntimeFeature",
82
88
  "keyed-rows-conditional-every-hinted": "keyedRowsConditionalEveryHintedRuntimeFeature",
89
+ "keyed-rows-conditional-batch-every-hinted": "keyedRowsConditionalBatchEveryHintedRuntimeFeature",
90
+ "keyed-rows-conditional-window-every-hinted": "keyedRowsConditionalWindowEveryHintedRuntimeFeature",
83
91
  "keyed-rows-conditional-filter-hinted": "keyedRowsConditionalFilterHintedRuntimeFeature",
84
92
  "keyed-rows-conditional-prepend-hinted": "keyedRowsConditionalPrependHintedRuntimeFeature",
85
93
  "keyed-rows-conditional-filter-prepend-hinted": "keyedRowsConditionalFilterPrependHintedRuntimeFeature",
86
94
  "keyed-rows-host": "keyedRowsHostRuntimeFeature",
87
95
  "keyed-rows-host-hinted": "keyedRowsHostHintedRuntimeFeature",
88
96
  "keyed-rows-host-position-hinted": "keyedRowsHostPositionHintedRuntimeFeature",
97
+ "keyed-rows-host-batch-position-hinted": "keyedRowsHostBatchPositionHintedRuntimeFeature",
98
+ "keyed-rows-host-window-position-hinted": "keyedRowsHostWindowPositionHintedRuntimeFeature",
89
99
  "keyed-rows-host-reorder-hinted": "keyedRowsHostReorderHintedRuntimeFeature",
90
100
  "keyed-rows-host-all-hinted": "keyedRowsHostAllHintedRuntimeFeature",
91
101
  "keyed-rows-host-every-hinted": "keyedRowsHostEveryHintedRuntimeFeature",
102
+ "keyed-rows-host-batch-every-hinted": "keyedRowsHostBatchEveryHintedRuntimeFeature",
103
+ "keyed-rows-host-window-every-hinted": "keyedRowsHostWindowEveryHintedRuntimeFeature",
92
104
  "keyed-rows-host-filter-hinted": "keyedRowsHostFilterHintedRuntimeFeature",
93
105
  "keyed-rows-host-prepend-hinted": "keyedRowsHostPrependHintedRuntimeFeature",
94
106
  "keyed-rows-host-filter-prepend-hinted": "keyedRowsHostFilterPrependHintedRuntimeFeature",
95
107
  "keyed-rows-complete": "keyedRowsCompleteRuntimeFeature",
96
108
  "keyed-rows-complete-hinted": "keyedRowsCompleteHintedRuntimeFeature",
97
109
  "keyed-rows-complete-position-hinted": "keyedRowsCompletePositionHintedRuntimeFeature",
110
+ "keyed-rows-complete-batch-position-hinted": "keyedRowsCompleteBatchPositionHintedRuntimeFeature",
111
+ "keyed-rows-complete-window-position-hinted": "keyedRowsCompleteWindowPositionHintedRuntimeFeature",
98
112
  "keyed-rows-complete-reorder-hinted": "keyedRowsCompleteReorderHintedRuntimeFeature",
99
113
  "keyed-rows-complete-all-hinted": "keyedRowsCompleteAllHintedRuntimeFeature",
100
114
  "keyed-rows-complete-every-hinted": "keyedRowsCompleteEveryHintedRuntimeFeature",
115
+ "keyed-rows-complete-batch-every-hinted": "keyedRowsCompleteBatchEveryHintedRuntimeFeature",
116
+ "keyed-rows-complete-window-every-hinted": "keyedRowsCompleteWindowEveryHintedRuntimeFeature",
101
117
  "keyed-rows-complete-filter-hinted": "keyedRowsCompleteFilterHintedRuntimeFeature",
102
118
  "keyed-rows-complete-prepend-hinted": "keyedRowsCompletePrependHintedRuntimeFeature",
103
119
  "keyed-rows-complete-filter-prepend-hinted": "keyedRowsCompleteFilterPrependHintedRuntimeFeature",
@@ -105,7 +121,7 @@ var COMPILER_RUNTIME_FEATURE_EXPORTS = {
105
121
  "mixed-ranges": "mixedRangesRuntimeFeature",
106
122
  component: "componentRuntimeFeature"
107
123
  };
108
- function runtimeFeaturesForPlans(plans, keyedMapUpdateHints, keyedArrayFilterHints, keyedArrayPrependHints, keyedArrayPositionHints, keyedArrayReorderHints, keyedArrayRollingWindowHints) {
124
+ function runtimeFeaturesForPlans(plans, keyedMapUpdateHints, keyedArrayFilterHints, keyedArrayPrependHints, keyedArrayPositionHints, keyedArrayBatchInsertHints, keyedArrayWindowReplaceHints, keyedArrayReorderHints, keyedArrayRollingWindowHints) {
109
125
  const features = /* @__PURE__ */ new Set();
110
126
  let keyedRowsHaveConditionals = false;
111
127
  let keyedRowsHaveHostBlocks = false;
@@ -122,7 +138,7 @@ function runtimeFeaturesForPlans(plans, keyedMapUpdateHints, keyedArrayFilterHin
122
138
  if (plans.some((plan) => plan.kind === "keyed-rows")) {
123
139
  const keyedRowsFeature = keyedRowsHaveConditionals && keyedRowsHaveHostBlocks ? "keyed-rows-complete" : keyedRowsHaveConditionals ? "keyed-rows-conditional" : keyedRowsHaveHostBlocks ? "keyed-rows-host" : "keyed-rows";
124
140
  const arrayRangeHints = keyedArrayRollingWindowHints || keyedArrayFilterHints || keyedArrayPrependHints;
125
- const hintSuffix = keyedArrayPositionHints && (arrayRangeHints || keyedArrayReorderHints) || keyedArrayReorderHints && arrayRangeHints ? "-every-hinted" : keyedArrayRollingWindowHints ? "-all-hinted" : keyedArrayPositionHints ? "-position-hinted" : keyedArrayReorderHints ? "-reorder-hinted" : keyedArrayFilterHints && keyedArrayPrependHints ? "-filter-prepend-hinted" : keyedArrayFilterHints ? "-filter-hinted" : keyedArrayPrependHints ? "-prepend-hinted" : keyedMapUpdateHints ? "-hinted" : "";
141
+ const hintSuffix = keyedArrayWindowReplaceHints ? arrayRangeHints || keyedArrayReorderHints ? "-window-every-hinted" : "-window-position-hinted" : keyedArrayBatchInsertHints ? arrayRangeHints || keyedArrayReorderHints ? "-batch-every-hinted" : "-batch-position-hinted" : keyedArrayPositionHints && (arrayRangeHints || keyedArrayReorderHints) || keyedArrayReorderHints && arrayRangeHints ? "-every-hinted" : keyedArrayRollingWindowHints ? "-all-hinted" : keyedArrayPositionHints ? "-position-hinted" : keyedArrayReorderHints ? "-reorder-hinted" : keyedArrayFilterHints && keyedArrayPrependHints ? "-filter-prepend-hinted" : keyedArrayFilterHints ? "-filter-hinted" : keyedArrayPrependHints ? "-prepend-hinted" : keyedMapUpdateHints ? "-hinted" : "";
126
142
  features.add(`${keyedRowsFeature}${hintSuffix}`);
127
143
  }
128
144
  return [...features].sort();
@@ -843,13 +859,28 @@ function staticSliceIndex(expression) {
843
859
  }
844
860
  return void 0;
845
861
  }
846
- function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
862
+ function validateKeyedArrayPositionExpression(expression, safeGlobals) {
863
+ const isNumericLiteral = types.isNumericLiteral(expression) || types.isUnaryExpression(expression) && (expression.operator === "+" || expression.operator === "-") && types.isNumericLiteral(expression.argument);
864
+ if (isNumericLiteral && staticSliceIndex(expression) === void 0) {
865
+ return "non-safe-integer position literals";
866
+ }
867
+ return validateDerivedExpression(expression, safeGlobals);
868
+ }
869
+ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter, helperIdentifier, batchInsertHelperIdentifier, windowReplaceHelperIdentifier, safeGlobals) {
847
870
  if (hintedStateIndices.size === 0) {
848
- return { root: types.cloneNode(root, true), count: 0, stateIndices: /* @__PURE__ */ new Set() };
871
+ return {
872
+ root: types.cloneNode(root, true),
873
+ count: 0,
874
+ batchInsertCount: 0,
875
+ windowReplaceCount: 0,
876
+ stateIndices: /* @__PURE__ */ new Set()
877
+ };
849
878
  }
850
879
  const file = expressionFile(types.cloneNode(root, true));
851
880
  const stateIndices = /* @__PURE__ */ new Set();
852
881
  let count = 0;
882
+ let batchInsertCount = 0;
883
+ let windowReplaceCount = 0;
853
884
  traverse(file, {
854
885
  CallExpression(path) {
855
886
  const callee = path.get("callee");
@@ -864,11 +895,17 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
864
895
  }
865
896
  const methodName = updater.body.callee.property.name;
866
897
  const args = updater.body.arguments;
867
- const kind = methodName === "with" && args.length === 2 ? "replace" : methodName === "toSpliced" && args.length === 3 && types.isNumericLiteral(args[1], { value: 0 }) ? "insert" : void 0;
868
- if (!kind || !types.isExpression(args[0]) || !types.isExpression(args.at(-1))) return;
869
- const position = staticSliceIndex(args[0]);
870
- const item = args.at(-1);
871
- if (position === void 0 || !types.isExpression(item) || validateDerivedExpression(item, safeGlobals) !== void 0) {
898
+ const toSplicedDeleteCount = methodName === "toSpliced" && args.length >= 2 && types.isNumericLiteral(args[1]) ? args[1].value : void 0;
899
+ const isBatchInsert = methodName === "toSpliced" && args.length >= 3 && types.isNumericLiteral(args[1], { value: 0 }) && (args.length > 3 || types.isSpreadElement(args[2]));
900
+ const isWindowReplace = methodName === "toSpliced" && args.length >= 3 && toSplicedDeleteCount !== void 0 && Number.isSafeInteger(toSplicedDeleteCount) && toSplicedDeleteCount > 0 && (toSplicedDeleteCount !== 1 || args.length > 3 || types.isSpreadElement(args[2]));
901
+ const kind = isBatchInsert ? "batch-insert" : isWindowReplace ? "window-replace" : methodName === "with" && args.length === 2 ? "replace" : methodName === "toSpliced" && args.length === 3 && types.isNumericLiteral(args[1], { value: 0 }) ? "insert" : methodName === "toSpliced" && args.length === 3 && types.isNumericLiteral(args[1], { value: 1 }) ? "replace" : args.length === 2 && toSplicedDeleteCount !== void 0 && Number.isSafeInteger(toSplicedDeleteCount) && toSplicedDeleteCount > 0 ? "remove" : void 0;
902
+ if (!kind || !types.isExpression(args[0])) return;
903
+ const position = args[0];
904
+ const incoming = kind === "batch-insert" || kind === "window-replace" ? args.slice(2) : [args.at(-1)];
905
+ if (validateKeyedArrayPositionExpression(position, safeGlobals) !== void 0 || kind !== "remove" && incoming.some((item) => {
906
+ const expression = types.isSpreadElement(item) ? item.argument : item;
907
+ return !expression || !types.isExpression(expression) || validateDerivedExpression(expression, safeGlobals) !== void 0;
908
+ })) {
872
909
  return;
873
910
  }
874
911
  const previous = types.cloneNode(updater.params[0]);
@@ -885,7 +922,18 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
885
922
  )
886
923
  ]),
887
924
  types.returnStatement(
888
- types.callExpression(types.cloneNode(helperIdentifier), [
925
+ kind === "batch-insert" ? types.callExpression(types.cloneNode(batchInsertHelperIdentifier), [
926
+ types.cloneNode(previous),
927
+ types.cloneNode(method),
928
+ types.cloneNode(position, true),
929
+ ...args.slice(2).map((argument) => types.cloneNode(argument, true))
930
+ ]) : kind === "window-replace" ? types.callExpression(types.cloneNode(windowReplaceHelperIdentifier), [
931
+ types.cloneNode(previous),
932
+ types.cloneNode(method),
933
+ types.cloneNode(position, true),
934
+ types.cloneNode(args[1], true),
935
+ ...args.slice(2).map((argument) => types.cloneNode(argument, true))
936
+ ]) : types.callExpression(types.cloneNode(helperIdentifier), [
889
937
  types.cloneNode(previous),
890
938
  types.cloneNode(method),
891
939
  types.stringLiteral(kind),
@@ -895,6 +943,8 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
895
943
  ])
896
944
  );
897
945
  count += 1;
946
+ if (kind === "batch-insert") batchInsertCount += 1;
947
+ if (kind === "window-replace") windowReplaceCount += 1;
898
948
  stateIndices.add(state.index);
899
949
  path.skip();
900
950
  }
@@ -902,6 +952,8 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
902
952
  return {
903
953
  root: file.program.body[0].expression,
904
954
  count,
955
+ batchInsertCount,
956
+ windowReplaceCount,
905
957
  stateIndices
906
958
  };
907
959
  }
@@ -954,6 +1006,61 @@ function rewriteKeyedArrayReorderHints(root, hintedStateIndices, statesBySetter,
954
1006
  stateIndices
955
1007
  };
956
1008
  }
1009
+ function rewriteKeyedArraySortHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
1010
+ if (hintedStateIndices.size === 0) {
1011
+ return { root: types.cloneNode(root, true), count: 0, stateIndices: /* @__PURE__ */ new Set() };
1012
+ }
1013
+ const file = expressionFile(types.cloneNode(root, true));
1014
+ const stateIndices = /* @__PURE__ */ new Set();
1015
+ let count = 0;
1016
+ traverse(file, {
1017
+ CallExpression(path) {
1018
+ const callee = path.get("callee");
1019
+ if (!callee.isIdentifier() || callee.scope.hasBinding(callee.node.name)) return;
1020
+ const state = statesBySetter.get(callee.node.name);
1021
+ if (!state || !hintedStateIndices.has(state.index) || path.node.arguments.length !== 1) {
1022
+ return;
1023
+ }
1024
+ const updater = path.node.arguments[0];
1025
+ if (!types.isArrowFunctionExpression(updater) || updater.async || updater.generator || updater.params.length !== 1 || !types.isIdentifier(updater.params[0]) || !types.isCallExpression(updater.body) || updater.body.arguments.length > 1 || !types.isMemberExpression(updater.body.callee) || updater.body.callee.computed || !types.isIdentifier(updater.body.callee.object, { name: updater.params[0].name }) || !types.isIdentifier(updater.body.callee.property, { name: "toSorted" })) {
1026
+ return;
1027
+ }
1028
+ const comparator = updater.body.arguments[0];
1029
+ if (comparator && !types.isArrowFunctionExpression(comparator) && !types.isFunctionExpression(comparator)) {
1030
+ return;
1031
+ }
1032
+ if (comparator && validateCollectionCallback(comparator, "toSorted", safeGlobals)) return;
1033
+ const previous = types.cloneNode(updater.params[0]);
1034
+ const method = path.scope.generateUidIdentifier("farmToSorted");
1035
+ path.node.arguments[0] = types.arrowFunctionExpression(
1036
+ [types.cloneNode(previous)],
1037
+ types.blockStatement([
1038
+ types.variableDeclaration("const", [
1039
+ types.variableDeclarator(
1040
+ types.cloneNode(method),
1041
+ types.memberExpression(types.cloneNode(previous), types.identifier("toSorted"))
1042
+ )
1043
+ ]),
1044
+ types.returnStatement(
1045
+ types.callExpression(types.cloneNode(helperIdentifier), [
1046
+ types.cloneNode(previous),
1047
+ types.cloneNode(method),
1048
+ ...comparator ? [types.cloneNode(comparator, true)] : []
1049
+ ])
1050
+ )
1051
+ ])
1052
+ );
1053
+ count += 1;
1054
+ stateIndices.add(state.index);
1055
+ path.skip();
1056
+ }
1057
+ });
1058
+ return {
1059
+ root: file.program.body[0].expression,
1060
+ count,
1061
+ stateIndices
1062
+ };
1063
+ }
957
1064
  function rewriteKeyedArraySliceHints(root, hintedStateIndices, statesBySetter, helperIdentifier) {
958
1065
  if (hintedStateIndices.size === 0) {
959
1066
  return { root: types.cloneNode(root, true), count: 0, stateIndices: /* @__PURE__ */ new Set() };
@@ -4755,7 +4862,7 @@ function wrapperElement(definitionIdentifier, props) {
4755
4862
  const attributes = props ? [types.jsxSpreadAttribute(types.cloneNode(props))] : [];
4756
4863
  return types.jsxElement(types.jsxOpeningElement(name, attributes, true), null, [], true);
4757
4864
  }
4758
- function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateIdentifier, keyedArrayAppendIdentifier, keyedArrayFilterIdentifier, keyedArrayPrependIdentifier, keyedArrayPositionIdentifier, keyedArrayReorderIdentifier, keyedArrayRollingWindowIdentifier, keyedArraySliceIdentifier, keyedCollectionUpdateIdentifier, keyedCollectionMutationIdentifier, runtimeFeatureIdentifiers, usedRuntimeFeatures, optimizationCounts, useStateNames, reactNames, listNames, moduleId, reactivity) {
4865
+ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateIdentifier, keyedArrayAppendIdentifier, keyedArrayFilterIdentifier, keyedArrayPrependIdentifier, keyedArrayPositionIdentifier, keyedArrayBatchInsertIdentifier, keyedArrayWindowReplaceIdentifier, keyedArrayReorderIdentifier, keyedArraySortIdentifier, keyedArrayRollingWindowIdentifier, keyedArraySliceIdentifier, keyedCollectionUpdateIdentifier, keyedCollectionMutationIdentifier, runtimeFeatureIdentifiers, usedRuntimeFeatures, optimizationCounts, compilerUsage, useStateNames, reactNames, listNames, moduleId, reactivity) {
4759
4866
  const { path, name, statementPath } = candidate;
4760
4867
  if (path.node.async || path.node.generator)
4761
4868
  return "async and generator components are not supported";
@@ -5127,9 +5234,13 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
5127
5234
  shiftedIndexIndependentStateIndices,
5128
5235
  statesBySetter,
5129
5236
  keyedArrayPositionIdentifier,
5237
+ keyedArrayBatchInsertIdentifier,
5238
+ keyedArrayWindowReplaceIdentifier,
5130
5239
  safeGlobals
5131
5240
  );
5132
5241
  let appliedKeyedArrayPositionHints = 0;
5242
+ let appliedKeyedArrayBatchInsertHints = 0;
5243
+ let appliedKeyedArrayWindowReplaceHints = 0;
5133
5244
  let appliedPositionHintedStateIndices = /* @__PURE__ */ new Set();
5134
5245
  if (positionHintedRoot.count > 0) {
5135
5246
  const hintedBlockAnalysis = analyzeComposableBlocks(
@@ -5153,8 +5264,12 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
5153
5264
  blockAnalysis = hintedBlockAnalysis;
5154
5265
  analysis = hintedAnalysis;
5155
5266
  appliedKeyedArrayPositionHints = positionHintedRoot.count;
5267
+ appliedKeyedArrayBatchInsertHints = positionHintedRoot.batchInsertCount;
5268
+ appliedKeyedArrayWindowReplaceHints = positionHintedRoot.windowReplaceCount;
5156
5269
  appliedPositionHintedStateIndices = positionHintedRoot.stateIndices;
5157
5270
  optimizationCounts.keyedArrayPositionHints += positionHintedRoot.count;
5271
+ compilerUsage.keyedArrayBatchInsertHints += positionHintedRoot.batchInsertCount;
5272
+ compilerUsage.keyedArrayWindowReplaceHints += positionHintedRoot.windowReplaceCount;
5158
5273
  }
5159
5274
  }
5160
5275
  const reorderHintedRoot = rewriteKeyedArrayReorderHints(
@@ -5191,6 +5306,41 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
5191
5306
  optimizationCounts.keyedArrayReorderHints += reorderHintedRoot.count;
5192
5307
  }
5193
5308
  }
5309
+ const sortHintedRoot = rewriteKeyedArraySortHints(
5310
+ expandedReactiveRoot,
5311
+ shiftedIndexIndependentStateIndices,
5312
+ statesBySetter,
5313
+ keyedArraySortIdentifier,
5314
+ safeGlobals
5315
+ );
5316
+ let appliedKeyedArraySortHints = 0;
5317
+ let appliedSortHintedStateIndices = /* @__PURE__ */ new Set();
5318
+ if (sortHintedRoot.count > 0) {
5319
+ const hintedBlockAnalysis = analyzeComposableBlocks(
5320
+ sortHintedRoot.root,
5321
+ reactiveByValue,
5322
+ safeGlobals,
5323
+ listNames,
5324
+ allowedComponentNames
5325
+ );
5326
+ const hintedAnalysis = analyzeHostTree(
5327
+ sortHintedRoot.root,
5328
+ reactiveByValue,
5329
+ safeGlobals,
5330
+ hintedBlockAnalysis.conditionalExpressions || /* @__PURE__ */ new Set(),
5331
+ hintedBlockAnalysis.keyedExpressions || /* @__PURE__ */ new Set(),
5332
+ hintedBlockAnalysis.ownedElements || /* @__PURE__ */ new Set(),
5333
+ hintedBlockAnalysis.componentElements || /* @__PURE__ */ new Set()
5334
+ );
5335
+ if (!hintedBlockAnalysis.reason && !hintedAnalysis.reason) {
5336
+ expandedReactiveRoot = sortHintedRoot.root;
5337
+ blockAnalysis = hintedBlockAnalysis;
5338
+ analysis = hintedAnalysis;
5339
+ appliedKeyedArraySortHints = sortHintedRoot.count;
5340
+ appliedSortHintedStateIndices = sortHintedRoot.stateIndices;
5341
+ optimizationCounts.keyedArraySortHints += sortHintedRoot.count;
5342
+ }
5343
+ }
5194
5344
  const sliceHintedRoot = rewriteKeyedArraySliceHints(
5195
5345
  expandedReactiveRoot,
5196
5346
  shiftedIndexIndependentStateIndices,
@@ -5325,7 +5475,7 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
5325
5475
  (count, plan) => count + (plan.kind === "keyed-rows" ? plan.bindings.filter((binding) => binding.mapLookupTarget !== void 0).length : 0),
5326
5476
  0
5327
5477
  );
5328
- const hasKeyedUpdateHints = appliedKeyedMapUpdateHints > 0 || appliedKeyedArrayAppendHints > 0 || appliedKeyedArrayFilterHints > 0 || appliedKeyedArrayPrependHints > 0 || appliedKeyedArrayPositionHints > 0 || appliedKeyedArrayReorderHints > 0 || appliedKeyedArrayRollingWindowHints > 0 || appliedKeyedArraySliceHints > 0;
5478
+ const hasKeyedUpdateHints = appliedKeyedMapUpdateHints > 0 || appliedKeyedArrayAppendHints > 0 || appliedKeyedArrayFilterHints > 0 || appliedKeyedArrayPrependHints > 0 || appliedKeyedArrayPositionHints > 0 || appliedKeyedArrayReorderHints > 0 || appliedKeyedArraySortHints > 0 || appliedKeyedArrayRollingWindowHints > 0 || appliedKeyedArraySliceHints > 0;
5329
5479
  const hasKeyedArrayRemovalHints = appliedKeyedArrayFilterHints > 0 || appliedKeyedArrayRollingWindowHints > 0 || appliedKeyedArraySliceHints > 0;
5330
5480
  const runtimeFeatures = runtimeFeaturesForPlans(
5331
5481
  blockPlans,
@@ -5333,7 +5483,9 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
5333
5483
  hasKeyedArrayRemovalHints,
5334
5484
  appliedKeyedArrayPrependHints > 0,
5335
5485
  appliedKeyedArrayPositionHints > 0,
5336
- appliedKeyedArrayReorderHints > 0,
5486
+ appliedKeyedArrayBatchInsertHints > 0,
5487
+ appliedKeyedArrayWindowReplaceHints > 0,
5488
+ appliedKeyedArrayReorderHints > 0 || appliedKeyedArraySortHints > 0,
5337
5489
  appliedKeyedArrayRollingWindowHints > 0
5338
5490
  );
5339
5491
  markShortCircuitBindings(analysis.bindings || []);
@@ -5362,7 +5514,7 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
5362
5514
  appliedRemovalHintedStateIndices,
5363
5515
  appliedPrependHintedStateIndices,
5364
5516
  appliedPositionHintedStateIndices,
5365
- appliedReorderHintedStateIndices
5517
+ /* @__PURE__ */ new Set([...appliedReorderHintedStateIndices, ...appliedSortHintedStateIndices])
5366
5518
  );
5367
5519
  const rewrittenRoot = rewriteStateAccess(
5368
5520
  rootWithBlocks,
@@ -5506,6 +5658,7 @@ async function compileReactModule(code, id, options) {
5506
5658
  keyedArrayPrependHints: 0,
5507
5659
  keyedArrayPositionHints: 0,
5508
5660
  keyedArrayReorderHints: 0,
5661
+ keyedArraySortHints: 0,
5509
5662
  keyedArrayRollingWindowHints: 0,
5510
5663
  keyedArraySliceHints: 0,
5511
5664
  keyedCollectionUpdateHints: 0,
@@ -5514,6 +5667,10 @@ async function compileReactModule(code, id, options) {
5514
5667
  keyedMembershipTargets: 0,
5515
5668
  keyedMapUpdateHints: 0
5516
5669
  };
5670
+ const compilerUsage = {
5671
+ keyedArrayBatchInsertHints: 0,
5672
+ keyedArrayWindowReplaceHints: 0
5673
+ };
5517
5674
  const plugin = () => ({
5518
5675
  name: "farm-react-aot",
5519
5676
  visitor: {
@@ -5558,9 +5715,18 @@ async function compileReactModule(code, id, options) {
5558
5715
  const keyedArrayPositionIdentifier = programPath.scope.generateUidIdentifier(
5559
5716
  "createCompilerKeyedArrayPositionUpdate"
5560
5717
  );
5718
+ const keyedArrayBatchInsertIdentifier = programPath.scope.generateUidIdentifier(
5719
+ "createCompilerKeyedArrayBatchInsert"
5720
+ );
5721
+ const keyedArrayWindowReplaceIdentifier = programPath.scope.generateUidIdentifier(
5722
+ "createCompilerKeyedArrayWindowReplace"
5723
+ );
5561
5724
  const keyedArrayReorderIdentifier = programPath.scope.generateUidIdentifier(
5562
5725
  "createCompilerKeyedArrayReorder"
5563
5726
  );
5727
+ const keyedArraySortIdentifier = programPath.scope.generateUidIdentifier(
5728
+ "createCompilerKeyedArraySort"
5729
+ );
5564
5730
  const keyedArrayRollingWindowIdentifier = programPath.scope.generateUidIdentifier(
5565
5731
  "createCompilerKeyedArrayRollingWindow"
5566
5732
  );
@@ -5595,7 +5761,10 @@ async function compileReactModule(code, id, options) {
5595
5761
  keyedArrayFilterIdentifier,
5596
5762
  keyedArrayPrependIdentifier,
5597
5763
  keyedArrayPositionIdentifier,
5764
+ keyedArrayBatchInsertIdentifier,
5765
+ keyedArrayWindowReplaceIdentifier,
5598
5766
  keyedArrayReorderIdentifier,
5767
+ keyedArraySortIdentifier,
5599
5768
  keyedArrayRollingWindowIdentifier,
5600
5769
  keyedArraySliceIdentifier,
5601
5770
  keyedCollectionUpdateIdentifier,
@@ -5603,6 +5772,7 @@ async function compileReactModule(code, id, options) {
5603
5772
  runtimeFeatureIdentifiers,
5604
5773
  usedRuntimeFeatures,
5605
5774
  optimizationCounts,
5775
+ compilerUsage,
5606
5776
  useStateNames,
5607
5777
  reactNames,
5608
5778
  listNames,
@@ -5652,18 +5822,36 @@ async function compileReactModule(code, id, options) {
5652
5822
  types.identifier("createCompilerKeyedArrayPrepend")
5653
5823
  )
5654
5824
  ] : [],
5655
- ...optimizationCounts.keyedArrayPositionHints > 0 ? [
5825
+ ...optimizationCounts.keyedArrayPositionHints > compilerUsage.keyedArrayBatchInsertHints + compilerUsage.keyedArrayWindowReplaceHints ? [
5656
5826
  types.importSpecifier(
5657
5827
  keyedArrayPositionIdentifier,
5658
5828
  types.identifier("createCompilerKeyedArrayPositionUpdate")
5659
5829
  )
5660
5830
  ] : [],
5831
+ ...compilerUsage.keyedArrayBatchInsertHints > 0 ? [
5832
+ types.importSpecifier(
5833
+ keyedArrayBatchInsertIdentifier,
5834
+ types.identifier("createCompilerKeyedArrayBatchInsert")
5835
+ )
5836
+ ] : [],
5837
+ ...compilerUsage.keyedArrayWindowReplaceHints > 0 ? [
5838
+ types.importSpecifier(
5839
+ keyedArrayWindowReplaceIdentifier,
5840
+ types.identifier("createCompilerKeyedArrayWindowReplace")
5841
+ )
5842
+ ] : [],
5661
5843
  ...optimizationCounts.keyedArrayReorderHints > 0 ? [
5662
5844
  types.importSpecifier(
5663
5845
  keyedArrayReorderIdentifier,
5664
5846
  types.identifier("createCompilerKeyedArrayReorder")
5665
5847
  )
5666
5848
  ] : [],
5849
+ ...optimizationCounts.keyedArraySortHints > 0 ? [
5850
+ types.importSpecifier(
5851
+ keyedArraySortIdentifier,
5852
+ types.identifier("createCompilerKeyedArraySort")
5853
+ )
5854
+ ] : [],
5667
5855
  ...optimizationCounts.keyedArrayRollingWindowHints > 0 ? [
5668
5856
  types.importSpecifier(
5669
5857
  keyedArrayRollingWindowIdentifier,
@@ -5739,6 +5927,7 @@ function createReactCompilerReport(projectRoot, observations) {
5739
5927
  let keyedArrayPrependHints = 0;
5740
5928
  let keyedArrayPositionHints = 0;
5741
5929
  let keyedArrayReorderHints = 0;
5930
+ let keyedArraySortHints = 0;
5742
5931
  let keyedArrayRollingWindowHints = 0;
5743
5932
  let keyedArraySliceHints = 0;
5744
5933
  let keyedCollectionUpdateHints = 0;
@@ -5755,6 +5944,7 @@ function createReactCompilerReport(projectRoot, observations) {
5755
5944
  keyedArrayPrependHints += result.optimizations.keyedArrayPrependHints || 0;
5756
5945
  keyedArrayPositionHints += result.optimizations.keyedArrayPositionHints || 0;
5757
5946
  keyedArrayReorderHints += result.optimizations.keyedArrayReorderHints || 0;
5947
+ keyedArraySortHints += result.optimizations.keyedArraySortHints || 0;
5758
5948
  keyedArrayRollingWindowHints += result.optimizations.keyedArrayRollingWindowHints || 0;
5759
5949
  keyedArraySliceHints += result.optimizations.keyedArraySliceHints || 0;
5760
5950
  keyedCollectionUpdateHints += result.optimizations.keyedCollectionUpdateHints || 0;
@@ -5787,6 +5977,7 @@ function createReactCompilerReport(projectRoot, observations) {
5787
5977
  keyedArrayPrependHints,
5788
5978
  keyedArrayPositionHints,
5789
5979
  keyedArrayReorderHints,
5980
+ keyedArraySortHints,
5790
5981
  keyedArrayRollingWindowHints,
5791
5982
  keyedArraySliceHints,
5792
5983
  keyedCollectionUpdateHints,