@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.cjs CHANGED
@@ -70,36 +70,52 @@ var COMPILER_RUNTIME_FEATURE_EXPORTS = {
70
70
  "keyed-rows": "keyedRowsRuntimeFeature",
71
71
  "keyed-rows-hinted": "keyedRowsHintedRuntimeFeature",
72
72
  "keyed-rows-position-hinted": "keyedRowsPositionHintedRuntimeFeature",
73
+ "keyed-rows-batch-position-hinted": "keyedRowsBatchPositionHintedRuntimeFeature",
74
+ "keyed-rows-window-position-hinted": "keyedRowsWindowPositionHintedRuntimeFeature",
73
75
  "keyed-rows-reorder-hinted": "keyedRowsReorderHintedRuntimeFeature",
74
76
  "keyed-rows-all-hinted": "keyedRowsAllHintedRuntimeFeature",
75
77
  "keyed-rows-every-hinted": "keyedRowsEveryHintedRuntimeFeature",
78
+ "keyed-rows-batch-every-hinted": "keyedRowsBatchEveryHintedRuntimeFeature",
79
+ "keyed-rows-window-every-hinted": "keyedRowsWindowEveryHintedRuntimeFeature",
76
80
  "keyed-rows-filter-hinted": "keyedRowsFilterHintedRuntimeFeature",
77
81
  "keyed-rows-prepend-hinted": "keyedRowsPrependHintedRuntimeFeature",
78
82
  "keyed-rows-filter-prepend-hinted": "keyedRowsFilterPrependHintedRuntimeFeature",
79
83
  "keyed-rows-conditional": "keyedRowsConditionalRuntimeFeature",
80
84
  "keyed-rows-conditional-hinted": "keyedRowsConditionalHintedRuntimeFeature",
81
85
  "keyed-rows-conditional-position-hinted": "keyedRowsConditionalPositionHintedRuntimeFeature",
86
+ "keyed-rows-conditional-batch-position-hinted": "keyedRowsConditionalBatchPositionHintedRuntimeFeature",
87
+ "keyed-rows-conditional-window-position-hinted": "keyedRowsConditionalWindowPositionHintedRuntimeFeature",
82
88
  "keyed-rows-conditional-reorder-hinted": "keyedRowsConditionalReorderHintedRuntimeFeature",
83
89
  "keyed-rows-conditional-all-hinted": "keyedRowsConditionalAllHintedRuntimeFeature",
84
90
  "keyed-rows-conditional-every-hinted": "keyedRowsConditionalEveryHintedRuntimeFeature",
91
+ "keyed-rows-conditional-batch-every-hinted": "keyedRowsConditionalBatchEveryHintedRuntimeFeature",
92
+ "keyed-rows-conditional-window-every-hinted": "keyedRowsConditionalWindowEveryHintedRuntimeFeature",
85
93
  "keyed-rows-conditional-filter-hinted": "keyedRowsConditionalFilterHintedRuntimeFeature",
86
94
  "keyed-rows-conditional-prepend-hinted": "keyedRowsConditionalPrependHintedRuntimeFeature",
87
95
  "keyed-rows-conditional-filter-prepend-hinted": "keyedRowsConditionalFilterPrependHintedRuntimeFeature",
88
96
  "keyed-rows-host": "keyedRowsHostRuntimeFeature",
89
97
  "keyed-rows-host-hinted": "keyedRowsHostHintedRuntimeFeature",
90
98
  "keyed-rows-host-position-hinted": "keyedRowsHostPositionHintedRuntimeFeature",
99
+ "keyed-rows-host-batch-position-hinted": "keyedRowsHostBatchPositionHintedRuntimeFeature",
100
+ "keyed-rows-host-window-position-hinted": "keyedRowsHostWindowPositionHintedRuntimeFeature",
91
101
  "keyed-rows-host-reorder-hinted": "keyedRowsHostReorderHintedRuntimeFeature",
92
102
  "keyed-rows-host-all-hinted": "keyedRowsHostAllHintedRuntimeFeature",
93
103
  "keyed-rows-host-every-hinted": "keyedRowsHostEveryHintedRuntimeFeature",
104
+ "keyed-rows-host-batch-every-hinted": "keyedRowsHostBatchEveryHintedRuntimeFeature",
105
+ "keyed-rows-host-window-every-hinted": "keyedRowsHostWindowEveryHintedRuntimeFeature",
94
106
  "keyed-rows-host-filter-hinted": "keyedRowsHostFilterHintedRuntimeFeature",
95
107
  "keyed-rows-host-prepend-hinted": "keyedRowsHostPrependHintedRuntimeFeature",
96
108
  "keyed-rows-host-filter-prepend-hinted": "keyedRowsHostFilterPrependHintedRuntimeFeature",
97
109
  "keyed-rows-complete": "keyedRowsCompleteRuntimeFeature",
98
110
  "keyed-rows-complete-hinted": "keyedRowsCompleteHintedRuntimeFeature",
99
111
  "keyed-rows-complete-position-hinted": "keyedRowsCompletePositionHintedRuntimeFeature",
112
+ "keyed-rows-complete-batch-position-hinted": "keyedRowsCompleteBatchPositionHintedRuntimeFeature",
113
+ "keyed-rows-complete-window-position-hinted": "keyedRowsCompleteWindowPositionHintedRuntimeFeature",
100
114
  "keyed-rows-complete-reorder-hinted": "keyedRowsCompleteReorderHintedRuntimeFeature",
101
115
  "keyed-rows-complete-all-hinted": "keyedRowsCompleteAllHintedRuntimeFeature",
102
116
  "keyed-rows-complete-every-hinted": "keyedRowsCompleteEveryHintedRuntimeFeature",
117
+ "keyed-rows-complete-batch-every-hinted": "keyedRowsCompleteBatchEveryHintedRuntimeFeature",
118
+ "keyed-rows-complete-window-every-hinted": "keyedRowsCompleteWindowEveryHintedRuntimeFeature",
103
119
  "keyed-rows-complete-filter-hinted": "keyedRowsCompleteFilterHintedRuntimeFeature",
104
120
  "keyed-rows-complete-prepend-hinted": "keyedRowsCompletePrependHintedRuntimeFeature",
105
121
  "keyed-rows-complete-filter-prepend-hinted": "keyedRowsCompleteFilterPrependHintedRuntimeFeature",
@@ -107,7 +123,7 @@ var COMPILER_RUNTIME_FEATURE_EXPORTS = {
107
123
  "mixed-ranges": "mixedRangesRuntimeFeature",
108
124
  component: "componentRuntimeFeature"
109
125
  };
110
- function runtimeFeaturesForPlans(plans, keyedMapUpdateHints, keyedArrayFilterHints, keyedArrayPrependHints, keyedArrayPositionHints, keyedArrayReorderHints, keyedArrayRollingWindowHints) {
126
+ function runtimeFeaturesForPlans(plans, keyedMapUpdateHints, keyedArrayFilterHints, keyedArrayPrependHints, keyedArrayPositionHints, keyedArrayBatchInsertHints, keyedArrayWindowReplaceHints, keyedArrayReorderHints, keyedArrayRollingWindowHints) {
111
127
  const features = /* @__PURE__ */ new Set();
112
128
  let keyedRowsHaveConditionals = false;
113
129
  let keyedRowsHaveHostBlocks = false;
@@ -124,7 +140,7 @@ function runtimeFeaturesForPlans(plans, keyedMapUpdateHints, keyedArrayFilterHin
124
140
  if (plans.some((plan) => plan.kind === "keyed-rows")) {
125
141
  const keyedRowsFeature = keyedRowsHaveConditionals && keyedRowsHaveHostBlocks ? "keyed-rows-complete" : keyedRowsHaveConditionals ? "keyed-rows-conditional" : keyedRowsHaveHostBlocks ? "keyed-rows-host" : "keyed-rows";
126
142
  const arrayRangeHints = keyedArrayRollingWindowHints || keyedArrayFilterHints || keyedArrayPrependHints;
127
- 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" : "";
143
+ 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" : "";
128
144
  features.add(`${keyedRowsFeature}${hintSuffix}`);
129
145
  }
130
146
  return [...features].sort();
@@ -852,13 +868,21 @@ function validateKeyedArrayPositionExpression(expression, safeGlobals) {
852
868
  }
853
869
  return validateDerivedExpression(expression, safeGlobals);
854
870
  }
855
- function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter, helperIdentifier, safeGlobals) {
871
+ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter, helperIdentifier, batchInsertHelperIdentifier, windowReplaceHelperIdentifier, safeGlobals) {
856
872
  if (hintedStateIndices.size === 0) {
857
- return { root: core.types.cloneNode(root, true), count: 0, stateIndices: /* @__PURE__ */ new Set() };
873
+ return {
874
+ root: core.types.cloneNode(root, true),
875
+ count: 0,
876
+ batchInsertCount: 0,
877
+ windowReplaceCount: 0,
878
+ stateIndices: /* @__PURE__ */ new Set()
879
+ };
858
880
  }
859
881
  const file = expressionFile(core.types.cloneNode(root, true));
860
882
  const stateIndices = /* @__PURE__ */ new Set();
861
883
  let count = 0;
884
+ let batchInsertCount = 0;
885
+ let windowReplaceCount = 0;
862
886
  core.traverse(file, {
863
887
  CallExpression(path) {
864
888
  const callee = path.get("callee");
@@ -873,11 +897,17 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
873
897
  }
874
898
  const methodName = updater.body.callee.property.name;
875
899
  const args = updater.body.arguments;
876
- const kind = methodName === "with" && args.length === 2 ? "replace" : methodName === "toSpliced" && args.length === 3 && core.types.isNumericLiteral(args[1], { value: 0 }) ? "insert" : methodName === "toSpliced" && args.length === 2 && core.types.isNumericLiteral(args[1], { value: 1 }) ? "remove" : void 0;
900
+ const toSplicedDeleteCount = methodName === "toSpliced" && args.length >= 2 && core.types.isNumericLiteral(args[1]) ? args[1].value : void 0;
901
+ const isBatchInsert = methodName === "toSpliced" && args.length >= 3 && core.types.isNumericLiteral(args[1], { value: 0 }) && (args.length > 3 || core.types.isSpreadElement(args[2]));
902
+ const isWindowReplace = methodName === "toSpliced" && args.length >= 3 && toSplicedDeleteCount !== void 0 && Number.isSafeInteger(toSplicedDeleteCount) && toSplicedDeleteCount > 0 && (toSplicedDeleteCount !== 1 || args.length > 3 || core.types.isSpreadElement(args[2]));
903
+ const kind = isBatchInsert ? "batch-insert" : isWindowReplace ? "window-replace" : methodName === "with" && args.length === 2 ? "replace" : methodName === "toSpliced" && args.length === 3 && core.types.isNumericLiteral(args[1], { value: 0 }) ? "insert" : methodName === "toSpliced" && args.length === 3 && core.types.isNumericLiteral(args[1], { value: 1 }) ? "replace" : args.length === 2 && toSplicedDeleteCount !== void 0 && Number.isSafeInteger(toSplicedDeleteCount) && toSplicedDeleteCount > 0 ? "remove" : void 0;
877
904
  if (!kind || !core.types.isExpression(args[0])) return;
878
905
  const position = args[0];
879
- const item = kind === "remove" ? void 0 : args.at(-1);
880
- if (validateKeyedArrayPositionExpression(position, safeGlobals) !== void 0 || item !== void 0 && (!core.types.isExpression(item) || validateDerivedExpression(item, safeGlobals) !== void 0)) {
906
+ const incoming = kind === "batch-insert" || kind === "window-replace" ? args.slice(2) : [args.at(-1)];
907
+ if (validateKeyedArrayPositionExpression(position, safeGlobals) !== void 0 || kind !== "remove" && incoming.some((item) => {
908
+ const expression = core.types.isSpreadElement(item) ? item.argument : item;
909
+ return !expression || !core.types.isExpression(expression) || validateDerivedExpression(expression, safeGlobals) !== void 0;
910
+ })) {
881
911
  return;
882
912
  }
883
913
  const previous = core.types.cloneNode(updater.params[0]);
@@ -894,7 +924,18 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
894
924
  )
895
925
  ]),
896
926
  core.types.returnStatement(
897
- core.types.callExpression(core.types.cloneNode(helperIdentifier), [
927
+ kind === "batch-insert" ? core.types.callExpression(core.types.cloneNode(batchInsertHelperIdentifier), [
928
+ core.types.cloneNode(previous),
929
+ core.types.cloneNode(method),
930
+ core.types.cloneNode(position, true),
931
+ ...args.slice(2).map((argument) => core.types.cloneNode(argument, true))
932
+ ]) : kind === "window-replace" ? core.types.callExpression(core.types.cloneNode(windowReplaceHelperIdentifier), [
933
+ core.types.cloneNode(previous),
934
+ core.types.cloneNode(method),
935
+ core.types.cloneNode(position, true),
936
+ core.types.cloneNode(args[1], true),
937
+ ...args.slice(2).map((argument) => core.types.cloneNode(argument, true))
938
+ ]) : core.types.callExpression(core.types.cloneNode(helperIdentifier), [
898
939
  core.types.cloneNode(previous),
899
940
  core.types.cloneNode(method),
900
941
  core.types.stringLiteral(kind),
@@ -904,6 +945,8 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
904
945
  ])
905
946
  );
906
947
  count += 1;
948
+ if (kind === "batch-insert") batchInsertCount += 1;
949
+ if (kind === "window-replace") windowReplaceCount += 1;
907
950
  stateIndices.add(state.index);
908
951
  path.skip();
909
952
  }
@@ -911,6 +954,8 @@ function rewriteKeyedArrayPositionHints(root, hintedStateIndices, statesBySetter
911
954
  return {
912
955
  root: file.program.body[0].expression,
913
956
  count,
957
+ batchInsertCount,
958
+ windowReplaceCount,
914
959
  stateIndices
915
960
  };
916
961
  }
@@ -4819,7 +4864,7 @@ function wrapperElement(definitionIdentifier, props) {
4819
4864
  const attributes = props ? [core.types.jsxSpreadAttribute(core.types.cloneNode(props))] : [];
4820
4865
  return core.types.jsxElement(core.types.jsxOpeningElement(name, attributes, true), null, [], true);
4821
4866
  }
4822
- function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateIdentifier, keyedArrayAppendIdentifier, keyedArrayFilterIdentifier, keyedArrayPrependIdentifier, keyedArrayPositionIdentifier, keyedArrayReorderIdentifier, keyedArraySortIdentifier, keyedArrayRollingWindowIdentifier, keyedArraySliceIdentifier, keyedCollectionUpdateIdentifier, keyedCollectionMutationIdentifier, runtimeFeatureIdentifiers, usedRuntimeFeatures, optimizationCounts, useStateNames, reactNames, listNames, moduleId, reactivity) {
4867
+ 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) {
4823
4868
  const { path, name, statementPath } = candidate;
4824
4869
  if (path.node.async || path.node.generator)
4825
4870
  return "async and generator components are not supported";
@@ -5191,9 +5236,13 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
5191
5236
  shiftedIndexIndependentStateIndices,
5192
5237
  statesBySetter,
5193
5238
  keyedArrayPositionIdentifier,
5239
+ keyedArrayBatchInsertIdentifier,
5240
+ keyedArrayWindowReplaceIdentifier,
5194
5241
  safeGlobals
5195
5242
  );
5196
5243
  let appliedKeyedArrayPositionHints = 0;
5244
+ let appliedKeyedArrayBatchInsertHints = 0;
5245
+ let appliedKeyedArrayWindowReplaceHints = 0;
5197
5246
  let appliedPositionHintedStateIndices = /* @__PURE__ */ new Set();
5198
5247
  if (positionHintedRoot.count > 0) {
5199
5248
  const hintedBlockAnalysis = analyzeComposableBlocks(
@@ -5217,8 +5266,12 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
5217
5266
  blockAnalysis = hintedBlockAnalysis;
5218
5267
  analysis = hintedAnalysis;
5219
5268
  appliedKeyedArrayPositionHints = positionHintedRoot.count;
5269
+ appliedKeyedArrayBatchInsertHints = positionHintedRoot.batchInsertCount;
5270
+ appliedKeyedArrayWindowReplaceHints = positionHintedRoot.windowReplaceCount;
5220
5271
  appliedPositionHintedStateIndices = positionHintedRoot.stateIndices;
5221
5272
  optimizationCounts.keyedArrayPositionHints += positionHintedRoot.count;
5273
+ compilerUsage.keyedArrayBatchInsertHints += positionHintedRoot.batchInsertCount;
5274
+ compilerUsage.keyedArrayWindowReplaceHints += positionHintedRoot.windowReplaceCount;
5222
5275
  }
5223
5276
  }
5224
5277
  const reorderHintedRoot = rewriteKeyedArrayReorderHints(
@@ -5432,6 +5485,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
5432
5485
  hasKeyedArrayRemovalHints,
5433
5486
  appliedKeyedArrayPrependHints > 0,
5434
5487
  appliedKeyedArrayPositionHints > 0,
5488
+ appliedKeyedArrayBatchInsertHints > 0,
5489
+ appliedKeyedArrayWindowReplaceHints > 0,
5435
5490
  appliedKeyedArrayReorderHints > 0 || appliedKeyedArraySortHints > 0,
5436
5491
  appliedKeyedArrayRollingWindowHints > 0
5437
5492
  );
@@ -5614,6 +5669,10 @@ async function compileReactModule(code, id, options) {
5614
5669
  keyedMembershipTargets: 0,
5615
5670
  keyedMapUpdateHints: 0
5616
5671
  };
5672
+ const compilerUsage = {
5673
+ keyedArrayBatchInsertHints: 0,
5674
+ keyedArrayWindowReplaceHints: 0
5675
+ };
5617
5676
  const plugin = () => ({
5618
5677
  name: "farm-react-aot",
5619
5678
  visitor: {
@@ -5658,6 +5717,12 @@ async function compileReactModule(code, id, options) {
5658
5717
  const keyedArrayPositionIdentifier = programPath.scope.generateUidIdentifier(
5659
5718
  "createCompilerKeyedArrayPositionUpdate"
5660
5719
  );
5720
+ const keyedArrayBatchInsertIdentifier = programPath.scope.generateUidIdentifier(
5721
+ "createCompilerKeyedArrayBatchInsert"
5722
+ );
5723
+ const keyedArrayWindowReplaceIdentifier = programPath.scope.generateUidIdentifier(
5724
+ "createCompilerKeyedArrayWindowReplace"
5725
+ );
5661
5726
  const keyedArrayReorderIdentifier = programPath.scope.generateUidIdentifier(
5662
5727
  "createCompilerKeyedArrayReorder"
5663
5728
  );
@@ -5698,6 +5763,8 @@ async function compileReactModule(code, id, options) {
5698
5763
  keyedArrayFilterIdentifier,
5699
5764
  keyedArrayPrependIdentifier,
5700
5765
  keyedArrayPositionIdentifier,
5766
+ keyedArrayBatchInsertIdentifier,
5767
+ keyedArrayWindowReplaceIdentifier,
5701
5768
  keyedArrayReorderIdentifier,
5702
5769
  keyedArraySortIdentifier,
5703
5770
  keyedArrayRollingWindowIdentifier,
@@ -5707,6 +5774,7 @@ async function compileReactModule(code, id, options) {
5707
5774
  runtimeFeatureIdentifiers,
5708
5775
  usedRuntimeFeatures,
5709
5776
  optimizationCounts,
5777
+ compilerUsage,
5710
5778
  useStateNames,
5711
5779
  reactNames,
5712
5780
  listNames,
@@ -5756,12 +5824,24 @@ async function compileReactModule(code, id, options) {
5756
5824
  core.types.identifier("createCompilerKeyedArrayPrepend")
5757
5825
  )
5758
5826
  ] : [],
5759
- ...optimizationCounts.keyedArrayPositionHints > 0 ? [
5827
+ ...optimizationCounts.keyedArrayPositionHints > compilerUsage.keyedArrayBatchInsertHints + compilerUsage.keyedArrayWindowReplaceHints ? [
5760
5828
  core.types.importSpecifier(
5761
5829
  keyedArrayPositionIdentifier,
5762
5830
  core.types.identifier("createCompilerKeyedArrayPositionUpdate")
5763
5831
  )
5764
5832
  ] : [],
5833
+ ...compilerUsage.keyedArrayBatchInsertHints > 0 ? [
5834
+ core.types.importSpecifier(
5835
+ keyedArrayBatchInsertIdentifier,
5836
+ core.types.identifier("createCompilerKeyedArrayBatchInsert")
5837
+ )
5838
+ ] : [],
5839
+ ...compilerUsage.keyedArrayWindowReplaceHints > 0 ? [
5840
+ core.types.importSpecifier(
5841
+ keyedArrayWindowReplaceIdentifier,
5842
+ core.types.identifier("createCompilerKeyedArrayWindowReplace")
5843
+ )
5844
+ ] : [],
5765
5845
  ...optimizationCounts.keyedArrayReorderHints > 0 ? [
5766
5846
  core.types.importSpecifier(
5767
5847
  keyedArrayReorderIdentifier,