@farm.js/react 0.1.0-beta.7 → 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();
@@ -850,13 +866,21 @@ function validateKeyedArrayPositionExpression(expression, safeGlobals) {
850
866
  }
851
867
  return validateDerivedExpression(expression, safeGlobals);
852
868
  }
853
- function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
869
+ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter, helperIdentifier, batchInsertHelperIdentifier, windowReplaceHelperIdentifier, safeGlobals) {
854
870
  if (hintedStateIndices.size === 0) {
855
- 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
+ };
856
878
  }
857
879
  const file = expressionFile(types.cloneNode(root, true));
858
880
  const stateIndices = /* @__PURE__ */ new Set();
859
881
  let count = 0;
882
+ let batchInsertCount = 0;
883
+ let windowReplaceCount = 0;
860
884
  traverse(file, {
861
885
  CallExpression(path) {
862
886
  const callee = path.get("callee");
@@ -871,11 +895,17 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
871
895
  }
872
896
  const methodName = updater.body.callee.property.name;
873
897
  const args = updater.body.arguments;
874
- const kind = methodName === "with" && args.length === 2 ? "replace" : methodName === "toSpliced" && args.length === 3 && types.isNumericLiteral(args[1], { value: 0 }) ? "insert" : methodName === "toSpliced" && args.length === 2 && types.isNumericLiteral(args[1], { value: 1 }) ? "remove" : 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;
875
902
  if (!kind || !types.isExpression(args[0])) return;
876
903
  const position = args[0];
877
- const item = kind === "remove" ? void 0 : args.at(-1);
878
- if (validateKeyedArrayPositionExpression(position, safeGlobals) !== void 0 || item !== void 0 && (!types.isExpression(item) || validateDerivedExpression(item, safeGlobals) !== void 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
+ })) {
879
909
  return;
880
910
  }
881
911
  const previous = types.cloneNode(updater.params[0]);
@@ -892,7 +922,18 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
892
922
  )
893
923
  ]),
894
924
  types.returnStatement(
895
- 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), [
896
937
  types.cloneNode(previous),
897
938
  types.cloneNode(method),
898
939
  types.stringLiteral(kind),
@@ -902,6 +943,8 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
902
943
  ])
903
944
  );
904
945
  count += 1;
946
+ if (kind === "batch-insert") batchInsertCount += 1;
947
+ if (kind === "window-replace") windowReplaceCount += 1;
905
948
  stateIndices.add(state.index);
906
949
  path.skip();
907
950
  }
@@ -909,6 +952,8 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
909
952
  return {
910
953
  root: file.program.body[0].expression,
911
954
  count,
955
+ batchInsertCount,
956
+ windowReplaceCount,
912
957
  stateIndices
913
958
  };
914
959
  }
@@ -4817,7 +4862,7 @@ function wrapperElement(definitionIdentifier, props) {
4817
4862
  const attributes = props ? [types.jsxSpreadAttribute(types.cloneNode(props))] : [];
4818
4863
  return types.jsxElement(types.jsxOpeningElement(name, attributes, true), null, [], true);
4819
4864
  }
4820
- function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateIdentifier, keyedArrayAppendIdentifier, keyedArrayFilterIdentifier, keyedArrayPrependIdentifier, keyedArrayPositionIdentifier, keyedArrayReorderIdentifier, keyedArraySortIdentifier, 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) {
4821
4866
  const { path, name, statementPath } = candidate;
4822
4867
  if (path.node.async || path.node.generator)
4823
4868
  return "async and generator components are not supported";
@@ -5189,9 +5234,13 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
5189
5234
  shiftedIndexIndependentStateIndices,
5190
5235
  statesBySetter,
5191
5236
  keyedArrayPositionIdentifier,
5237
+ keyedArrayBatchInsertIdentifier,
5238
+ keyedArrayWindowReplaceIdentifier,
5192
5239
  safeGlobals
5193
5240
  );
5194
5241
  let appliedKeyedArrayPositionHints = 0;
5242
+ let appliedKeyedArrayBatchInsertHints = 0;
5243
+ let appliedKeyedArrayWindowReplaceHints = 0;
5195
5244
  let appliedPositionHintedStateIndices = /* @__PURE__ */ new Set();
5196
5245
  if (positionHintedRoot.count > 0) {
5197
5246
  const hintedBlockAnalysis = analyzeComposableBlocks(
@@ -5215,8 +5264,12 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
5215
5264
  blockAnalysis = hintedBlockAnalysis;
5216
5265
  analysis = hintedAnalysis;
5217
5266
  appliedKeyedArrayPositionHints = positionHintedRoot.count;
5267
+ appliedKeyedArrayBatchInsertHints = positionHintedRoot.batchInsertCount;
5268
+ appliedKeyedArrayWindowReplaceHints = positionHintedRoot.windowReplaceCount;
5218
5269
  appliedPositionHintedStateIndices = positionHintedRoot.stateIndices;
5219
5270
  optimizationCounts.keyedArrayPositionHints += positionHintedRoot.count;
5271
+ compilerUsage.keyedArrayBatchInsertHints += positionHintedRoot.batchInsertCount;
5272
+ compilerUsage.keyedArrayWindowReplaceHints += positionHintedRoot.windowReplaceCount;
5220
5273
  }
5221
5274
  }
5222
5275
  const reorderHintedRoot = rewriteKeyedArrayReorderHints(
@@ -5430,6 +5483,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
5430
5483
  hasKeyedArrayRemovalHints,
5431
5484
  appliedKeyedArrayPrependHints > 0,
5432
5485
  appliedKeyedArrayPositionHints > 0,
5486
+ appliedKeyedArrayBatchInsertHints > 0,
5487
+ appliedKeyedArrayWindowReplaceHints > 0,
5433
5488
  appliedKeyedArrayReorderHints > 0 || appliedKeyedArraySortHints > 0,
5434
5489
  appliedKeyedArrayRollingWindowHints > 0
5435
5490
  );
@@ -5612,6 +5667,10 @@ async function compileReactModule(code, id, options) {
5612
5667
  keyedMembershipTargets: 0,
5613
5668
  keyedMapUpdateHints: 0
5614
5669
  };
5670
+ const compilerUsage = {
5671
+ keyedArrayBatchInsertHints: 0,
5672
+ keyedArrayWindowReplaceHints: 0
5673
+ };
5615
5674
  const plugin = () => ({
5616
5675
  name: "farm-react-aot",
5617
5676
  visitor: {
@@ -5656,6 +5715,12 @@ async function compileReactModule(code, id, options) {
5656
5715
  const keyedArrayPositionIdentifier = programPath.scope.generateUidIdentifier(
5657
5716
  "createCompilerKeyedArrayPositionUpdate"
5658
5717
  );
5718
+ const keyedArrayBatchInsertIdentifier = programPath.scope.generateUidIdentifier(
5719
+ "createCompilerKeyedArrayBatchInsert"
5720
+ );
5721
+ const keyedArrayWindowReplaceIdentifier = programPath.scope.generateUidIdentifier(
5722
+ "createCompilerKeyedArrayWindowReplace"
5723
+ );
5659
5724
  const keyedArrayReorderIdentifier = programPath.scope.generateUidIdentifier(
5660
5725
  "createCompilerKeyedArrayReorder"
5661
5726
  );
@@ -5696,6 +5761,8 @@ async function compileReactModule(code, id, options) {
5696
5761
  keyedArrayFilterIdentifier,
5697
5762
  keyedArrayPrependIdentifier,
5698
5763
  keyedArrayPositionIdentifier,
5764
+ keyedArrayBatchInsertIdentifier,
5765
+ keyedArrayWindowReplaceIdentifier,
5699
5766
  keyedArrayReorderIdentifier,
5700
5767
  keyedArraySortIdentifier,
5701
5768
  keyedArrayRollingWindowIdentifier,
@@ -5705,6 +5772,7 @@ async function compileReactModule(code, id, options) {
5705
5772
  runtimeFeatureIdentifiers,
5706
5773
  usedRuntimeFeatures,
5707
5774
  optimizationCounts,
5775
+ compilerUsage,
5708
5776
  useStateNames,
5709
5777
  reactNames,
5710
5778
  listNames,
@@ -5754,12 +5822,24 @@ async function compileReactModule(code, id, options) {
5754
5822
  types.identifier("createCompilerKeyedArrayPrepend")
5755
5823
  )
5756
5824
  ] : [],
5757
- ...optimizationCounts.keyedArrayPositionHints > 0 ? [
5825
+ ...optimizationCounts.keyedArrayPositionHints > compilerUsage.keyedArrayBatchInsertHints + compilerUsage.keyedArrayWindowReplaceHints ? [
5758
5826
  types.importSpecifier(
5759
5827
  keyedArrayPositionIdentifier,
5760
5828
  types.identifier("createCompilerKeyedArrayPositionUpdate")
5761
5829
  )
5762
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
+ ] : [],
5763
5843
  ...optimizationCounts.keyedArrayReorderHints > 0 ? [
5764
5844
  types.importSpecifier(
5765
5845
  keyedArrayReorderIdentifier,