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