@farm.js/react 0.1.0-beta.10 → 0.1.0-beta.11

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
@@ -1131,6 +1131,18 @@ function rewriteKeyedArrayReorderHints(root, hintedStateIndices, statesBySetter,
1131
1131
  stateIndices
1132
1132
  };
1133
1133
  }
1134
+ function normalizeSafeKeyedFilterPredicate(predicate, safeGlobals) {
1135
+ if (!types.isArrowFunctionExpression(predicate) || predicate.async || predicate.generator || predicate.params.length !== 1 || !types.isIdentifier(predicate.params[0]) || types.isBlockStatement(predicate.body) && predicate.body.directives.length > 0) {
1136
+ return void 0;
1137
+ }
1138
+ const returned = returnedExpression(predicate);
1139
+ if (!returned || validateDerivedExpression(returned, safeGlobals) !== void 0) {
1140
+ return void 0;
1141
+ }
1142
+ const normalized = types.cloneNode(predicate, true);
1143
+ normalized.body = types.cloneNode(returned, true);
1144
+ return normalized;
1145
+ }
1134
1146
  function keyedArrayReorderPipeline(expression, parameterName, safeGlobals) {
1135
1147
  const outerSteps = [];
1136
1148
  let current = expression;
@@ -1145,10 +1157,8 @@ function keyedArrayReorderPipeline(expression, parameterName, safeGlobals) {
1145
1157
  outerSteps.push({ callback, kind: "map" });
1146
1158
  } else if (methodName === "filter") {
1147
1159
  if (current.arguments.length !== 1) return void 0;
1148
- const predicate = current.arguments[0];
1149
- if (!types.isArrowFunctionExpression(predicate) || predicate.async || predicate.generator || predicate.params.length !== 1 || !types.isIdentifier(predicate.params[0]) || !types.isExpression(predicate.body) || validateDerivedExpression(predicate.body, safeGlobals)) {
1150
- return void 0;
1151
- }
1160
+ const predicate = normalizeSafeKeyedFilterPredicate(current.arguments[0], safeGlobals);
1161
+ if (!predicate) return void 0;
1152
1162
  outerSteps.push({ kind: "filter", predicate });
1153
1163
  } else if (methodName === "slice") {
1154
1164
  if (current.arguments.length < 1 || current.arguments.length > 2) return void 0;
@@ -2386,10 +2396,11 @@ function rewriteKeyedArrayFilterHints(root, hintedStateIndices, statesBySetter,
2386
2396
  }) || !types.isIdentifier(updateExpression.callee.property, { name: "filter" })) {
2387
2397
  return;
2388
2398
  }
2389
- const predicate = updateExpression.arguments[0];
2390
- if (!types.isArrowFunctionExpression(predicate) || predicate.async || predicate.generator || predicate.params.length !== 1 || !types.isIdentifier(predicate.params[0]) || !types.isExpression(predicate.body) || validateDerivedExpression(predicate.body, safeGlobals)) {
2391
- return;
2392
- }
2399
+ const predicate = normalizeSafeKeyedFilterPredicate(
2400
+ updateExpression.arguments[0],
2401
+ safeGlobals
2402
+ );
2403
+ if (!predicate) return;
2393
2404
  const previous = types.cloneNode(updater.params[0]);
2394
2405
  const filterMethod = path.scope.generateUidIdentifier("farmFilter");
2395
2406
  path.node.arguments[0] = types.arrowFunctionExpression(