@farm.js/react 0.1.0-beta.23 → 0.1.0-beta.25

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
@@ -71,6 +71,7 @@ var COMPILER_RUNTIME_FEATURE_EXPORTS = {
71
71
  "keyed-rows-membership": "keyedRowsMembershipRuntimeFeature",
72
72
  "keyed-rows-map-lookup": "keyedRowsMapLookupRuntimeFeature",
73
73
  "keyed-rows-hinted": "keyedRowsHintedRuntimeFeature",
74
+ "keyed-rows-append-only": "keyedRowsAppendOnlyRuntimeFeature",
74
75
  "keyed-rows-position-hinted": "keyedRowsPositionHintedRuntimeFeature",
75
76
  "keyed-rows-batch-position-hinted": "keyedRowsBatchPositionHintedRuntimeFeature",
76
77
  "keyed-rows-window-position-hinted": "keyedRowsWindowPositionHintedRuntimeFeature",
@@ -82,6 +83,7 @@ var COMPILER_RUNTIME_FEATURE_EXPORTS = {
82
83
  "keyed-rows-batch-every-hinted": "keyedRowsBatchEveryHintedRuntimeFeature",
83
84
  "keyed-rows-window-every-hinted": "keyedRowsWindowEveryHintedRuntimeFeature",
84
85
  "keyed-rows-filter-hinted": "keyedRowsFilterHintedRuntimeFeature",
86
+ "keyed-rows-filter-only": "keyedRowsFilterOnlyRuntimeFeature",
85
87
  "keyed-rows-identity-filter-hinted": "keyedRowsIdentityFilterHintedRuntimeFeature",
86
88
  "keyed-rows-identity-filter-only": "keyedRowsIdentityFilterOnlyRuntimeFeature",
87
89
  "keyed-rows-structural-append-hinted": "keyedRowsStructuralAppendHintedRuntimeFeature",
@@ -89,6 +91,7 @@ var COMPILER_RUNTIME_FEATURE_EXPORTS = {
89
91
  "keyed-rows-structural-prepend-hinted": "keyedRowsStructuralPrependHintedRuntimeFeature",
90
92
  "keyed-rows-structural-prepend-map-hinted": "keyedRowsStructuralPrependMapHintedRuntimeFeature",
91
93
  "keyed-rows-prepend-hinted": "keyedRowsPrependHintedRuntimeFeature",
94
+ "keyed-rows-prepend-only": "keyedRowsPrependOnlyRuntimeFeature",
92
95
  "keyed-rows-filter-prepend-hinted": "keyedRowsFilterPrependHintedRuntimeFeature",
93
96
  "keyed-rows-conditional": "keyedRowsConditionalRuntimeFeature",
94
97
  "keyed-rows-conditional-hinted": "keyedRowsConditionalHintedRuntimeFeature",
@@ -148,7 +151,7 @@ var COMPILER_RUNTIME_FEATURE_EXPORTS = {
148
151
  "mixed-ranges": "mixedRangesRuntimeFeature",
149
152
  component: "componentRuntimeFeature"
150
153
  };
151
- function runtimeFeaturesForPlans(plans, keyedUpdateHints, keyedArrayFilterHints, keyedArrayStructuralAppendHints, keyedArrayStructuralAppendMapHints, keyedArrayPrependHints, keyedArrayStructuralPrependHints, keyedArrayStructuralPrependMapHints, keyedArrayPositionHints, keyedArrayBatchInsertHints, keyedArrayWindowReplaceHints, keyedArrayReorderHints, keyedArrayMapReorderHints, keyedArrayMappedRollingWindowChainHints, keyedArrayRollingWindowHints, keyedMapOrAppendHints) {
154
+ function runtimeFeaturesForPlans(plans, keyedUpdateHints, keyedArrayFilterHints, keyedArrayStructuralAppendHints, keyedArrayStructuralAppendMapHints, keyedArrayPrependHints, keyedArrayStructuralPrependHints, keyedArrayStructuralPrependMapHints, keyedArrayPositionHints, keyedArrayBatchInsertHints, keyedArrayWindowReplaceHints, keyedArrayReorderHints, keyedArrayMapReorderHints, keyedArrayMappedRollingWindowChainHints, keyedArrayRollingWindowHints, keyedMapOrAppendHints, keyedArrayAppendOnlyHints) {
152
155
  const features = /* @__PURE__ */ new Set();
153
156
  let keyedRowsHaveConditionals = false;
154
157
  let keyedRowsHaveHostBlocks = false;
@@ -173,7 +176,13 @@ function runtimeFeaturesForPlans(plans, keyedUpdateHints, keyedArrayFilterHints,
173
176
  const arrayRangeHints = keyedArrayRollingWindowHints || keyedArrayFilterHints || keyedArrayPrependHints;
174
177
  const needsCombinedStructuralPrependRuntime = keyedArrayStructuralPrependHints && (keyedArrayStructuralAppendMapHints || keyedArrayStructuralAppendHints || keyedArrayWindowReplaceHints || keyedArrayBatchInsertHints || keyedArrayPositionHints || keyedArrayReorderHints || keyedArrayRollingWindowHints);
175
178
  const hintSuffix = keyedArrayMappedRollingWindowChainHints ? "-mapped-rolling-window-hinted" : keyedArrayStructuralPrependMapHints ? "-structural-prepend-map-hinted" : needsCombinedStructuralPrependRuntime ? "-structural-prepend-hinted" : keyedArrayStructuralAppendMapHints ? "-structural-append-map-hinted" : keyedArrayStructuralAppendHints ? "-structural-append-hinted" : 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" : keyedArrayMapReorderHints && keyedRowsFeature === "keyed-rows" ? "-map-reorder-hinted" : keyedArrayReorderHints ? "-reorder-hinted" : keyedArrayFilterHints && keyedArrayPrependHints ? "-filter-prepend-hinted" : keyedArrayFilterHints ? "-filter-hinted" : keyedArrayPrependHints ? "-prepend-hinted" : keyedUpdateHints ? "-hinted" : "";
176
- if (keyedRowsFeature === "keyed-rows" && hintSuffix === "-filter-hinted" && keyedTargetKinds.size === 1 && keyedTargetKinds.has("identity")) {
179
+ if (keyedRowsFeature === "keyed-rows" && hintSuffix === "-hinted" && keyedTargetKinds.size === 0 && keyedArrayAppendOnlyHints) {
180
+ features.add("keyed-rows-append-only");
181
+ } else if (keyedRowsFeature === "keyed-rows" && hintSuffix === "-filter-hinted" && keyedTargetKinds.size === 0 && !keyedMapOrAppendHints) {
182
+ features.add("keyed-rows-filter-only");
183
+ } else if (keyedRowsFeature === "keyed-rows" && hintSuffix === "-prepend-hinted" && keyedTargetKinds.size === 0 && !keyedMapOrAppendHints) {
184
+ features.add("keyed-rows-prepend-only");
185
+ } else if (keyedRowsFeature === "keyed-rows" && hintSuffix === "-filter-hinted" && keyedTargetKinds.size === 1 && keyedTargetKinds.has("identity")) {
177
186
  features.add(
178
187
  keyedMapOrAppendHints ? "keyed-rows-identity-filter-hinted" : "keyed-rows-identity-filter-only"
179
188
  );
@@ -2760,6 +2769,54 @@ function rewriteKeyedCollectionUpdateHints(root, targetKinds, states, statesBySe
2760
2769
  count
2761
2770
  };
2762
2771
  }
2772
+ function snapshotDeferredHandlerReads(root, reactiveNames) {
2773
+ if (reactiveNames.size === 0) return root;
2774
+ const file = expressionFile(types.cloneNode(root, true));
2775
+ traverse(file, {
2776
+ JSXAttribute(path) {
2777
+ if (!types.isJSXIdentifier(path.node.name) || !/^on[A-Z]/.test(path.node.name.name)) return;
2778
+ const value = path.get("value");
2779
+ if (!value.isJSXExpressionContainer()) return;
2780
+ const handler = value.get("expression");
2781
+ if (!handler.isArrowFunctionExpression() && !handler.isFunctionExpression()) return;
2782
+ let defers = false;
2783
+ handler.traverse({
2784
+ AwaitExpression(inner) {
2785
+ defers = true;
2786
+ inner.stop();
2787
+ },
2788
+ Function(inner) {
2789
+ defers = true;
2790
+ inner.stop();
2791
+ }
2792
+ });
2793
+ if (!defers) return;
2794
+ const snapshots = /* @__PURE__ */ new Map();
2795
+ handler.traverse({
2796
+ ReferencedIdentifier(reference) {
2797
+ const name = reference.node.name;
2798
+ if (!reactiveNames.has(name) || reference.scope.hasBinding(name)) return;
2799
+ let snapshot = snapshots.get(name);
2800
+ if (!snapshot) {
2801
+ snapshot = handler.scope.generateUidIdentifier(name);
2802
+ snapshots.set(name, snapshot);
2803
+ }
2804
+ reference.replaceWith(types.cloneNode(snapshot));
2805
+ }
2806
+ });
2807
+ if (snapshots.size === 0) return;
2808
+ const declaration = types.variableDeclaration(
2809
+ "const",
2810
+ [...snapshots].map(
2811
+ ([name, snapshot]) => types.variableDeclarator(snapshot, types.identifier(name))
2812
+ )
2813
+ );
2814
+ const body = handler.node.body;
2815
+ handler.node.body = types.isBlockStatement(body) ? types.blockStatement([declaration, ...body.body], body.directives) : types.blockStatement([declaration, types.returnStatement(body)]);
2816
+ }
2817
+ });
2818
+ return file.program.body[0].expression;
2819
+ }
2763
2820
  function rewriteStateAccess(expression, stateParameter, statesByValue, statesBySetter) {
2764
2821
  const file = expressionFile(cloneExpression(expression));
2765
2822
  traverse(file, {
@@ -3357,7 +3414,8 @@ function analyzeKeyedRowTree(row, renderCallback, safeGlobals, compilerSetters,
3357
3414
  bindings.push({
3358
3415
  kind: "text",
3359
3416
  path: [...path],
3360
- value: types.arrayExpression(parts)
3417
+ // Normalization accepts scalars and arrays; only joined text needs a wrapper.
3418
+ value: parts.length === 1 ? parts[0] : types.arrayExpression(parts)
3361
3419
  });
3362
3420
  }
3363
3421
  let elementIndex = 0;
@@ -6195,8 +6253,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
6195
6253
  }
6196
6254
  if (types.isFunctionDeclaration(statement)) {
6197
6255
  if (!statement.id) return "named event handler declarations must have a name";
6198
- if (statement.async || statement.generator || statement.typeParameters) {
6199
- return `event handler ${statement.id.name} must be synchronous and non-generic`;
6256
+ if (statement.generator || statement.typeParameters) {
6257
+ return `event handler ${statement.id.name} must be a non-generator, non-generic function`;
6200
6258
  }
6201
6259
  locals.push({
6202
6260
  kind: "handler",
@@ -6226,8 +6284,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
6226
6284
  return "derived const values and event handlers must use one identifier and one expression";
6227
6285
  }
6228
6286
  if (types.isArrowFunctionExpression(declaration.init) || types.isFunctionExpression(declaration.init)) {
6229
- if (declaration.init.async || declaration.init.generator) {
6230
- return `event handler ${declaration.id.name} must be synchronous`;
6287
+ if (declaration.init.generator) {
6288
+ return `event handler ${declaration.id.name} cannot be a generator`;
6231
6289
  }
6232
6290
  locals.push({
6233
6291
  kind: "handler",
@@ -6293,8 +6351,12 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
6293
6351
  const handlerRewrite = rewriteHandlerAccess(rootWithDerived, handlersByName);
6294
6352
  if (handlerRewrite.reason) return handlerRewrite.reason;
6295
6353
  if (!handlerRewrite.root) return "event handlers could not be prepared safely";
6296
- const expandedRootWithDeferredEvents = rewriteDestructuredPropAccess(
6354
+ const snapshotRoot = snapshotDeferredHandlerReads(
6297
6355
  handlerRewrite.root,
6356
+ /* @__PURE__ */ new Set([...states.map((state) => state.valueName), ...propsPlan.destructuredNames])
6357
+ );
6358
+ const expandedRootWithDeferredEvents = rewriteDestructuredPropAccess(
6359
+ snapshotRoot,
6298
6360
  propsPlan.destructuredNames,
6299
6361
  propsPlan.definitionParameter
6300
6362
  );
@@ -7168,7 +7230,8 @@ function compileCandidate(candidate, createComponentIdentifier, keyedMapUpdateId
7168
7230
  appliedPipelineMapHints > 0 || appliedQueuedReorderMapHints > 0 || appliedQueuedMappedStructuralHints > 0 || appliedQueuedStructuralMapHints > 0,
7169
7231
  appliedMappedRollingWindowChainHints > 0,
7170
7232
  appliedKeyedArrayRollingWindowHints > appliedMappedRollingWindowHints,
7171
- appliedKeyedMapUpdateHints > 0 || appliedKeyedArrayAppendHints > 0
7233
+ appliedKeyedMapUpdateHints > 0 || appliedKeyedArrayAppendHints > 0,
7234
+ appliedKeyedArrayAppendHints > 0 && appliedKeyedMapUpdateHints === 0
7172
7235
  );
7173
7236
  markShortCircuitBindings(analysis.bindings || []);
7174
7237
  assignStableBindingTargets(analysis.bindings || []);