unpeek 1.10.0 → 1.11.0

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.
@@ -62,7 +62,12 @@ var ARRAY_HOF_METHODS = /* @__PURE__ */ new Set([
62
62
  var ANIMATION_FRAME_CALLS = /* @__PURE__ */ new Set([
63
63
  "requestAnimationFrame",
64
64
  "cancelAnimationFrame",
65
- "useFrame"
65
+ "useFrame",
66
+ "useLenis",
67
+ "setAnimationLoop",
68
+ "onBeforeRender",
69
+ "updateMatrixWorld",
70
+ "raf"
66
71
  ]);
67
72
  var REACT_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
68
73
  "useState",
@@ -71,6 +76,9 @@ var REACT_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
71
76
  "useCallback",
72
77
  "useRef",
73
78
  "useLayoutEffect",
79
+ "useActionState",
80
+ "useFormStatus",
81
+ "useOptimistic",
74
82
  "jsx",
75
83
  "jsxs",
76
84
  "_jsx",
@@ -199,7 +207,8 @@ function containsLoopOrAnimation(fnNode) {
199
207
  } else if (callNode.callee?.type === "MemberExpression" && !callNode.callee.computed && callNode.callee.property?.type === "Identifier") {
200
208
  mProp = callNode.callee.property.name;
201
209
  }
202
- if (ANIMATION_FRAME_CALLS.has(cName) || ANIMATION_FRAME_CALLS.has(mProp)) {
210
+ const isTickerAdd = mProp === "add" && (callNode.callee?.object?.name === "ticker" || callNode.callee?.object?.property?.name === "ticker");
211
+ if (ANIMATION_FRAME_CALLS.has(cName) || ANIMATION_FRAME_CALLS.has(mProp) || isTickerAdd) {
203
212
  found = true;
204
213
  }
205
214
  }
@@ -225,6 +234,7 @@ function analyzeAstHotPaths(ast) {
225
234
  const fnVarAliases = /* @__PURE__ */ new Map();
226
235
  const callerToCallees = /* @__PURE__ */ new Map();
227
236
  const pendingSerializedRefs = [];
237
+ const pendingHotRefs = [];
228
238
  const allCallSites = [];
229
239
  function ensureFnParams(fnNode) {
230
240
  let paramSet = fnParams.get(fnNode);
@@ -490,7 +500,8 @@ function analyzeAstHotPaths(ast) {
490
500
  const outerFn = findOutermostModuleFunction(ancestors);
491
501
  if (outerFn) markSerializedFunction(outerFn);
492
502
  }
493
- if (ANIMATION_FRAME_CALLS.has(calleeName) || ANIMATION_FRAME_CALLS.has(memberProp)) {
503
+ const isTickerAdd = memberProp === "add" && (callee?.object?.name === "ticker" || callee?.object?.property?.name === "ticker");
504
+ if (ANIMATION_FRAME_CALLS.has(calleeName) || ANIMATION_FRAME_CALLS.has(memberProp) || isTickerAdd) {
494
505
  if (enclosingFn) {
495
506
  trueHotNodes.add(enclosingFn);
496
507
  hotFunctionNodes.add(enclosingFn);
@@ -503,6 +514,7 @@ function analyzeAstHotPaths(ast) {
503
514
  directHotNodes.add(arg);
504
515
  hotExemptNodes.add(arg);
505
516
  } else if (arg?.type === "Identifier") {
517
+ pendingHotRefs.push({ scopeNode: currentScope, name: arg.name });
506
518
  allCallSites.push({
507
519
  scopeNode: currentScope,
508
520
  calleeKey: arg.name,
@@ -619,6 +631,15 @@ function analyzeAstHotPaths(ast) {
619
631
  markSerializedFunction(targetNode);
620
632
  }
621
633
  }
634
+ for (const ref of pendingHotRefs) {
635
+ const targetNode = resolveCalleeNode(ref.scopeNode, ref.name);
636
+ if (targetNode) {
637
+ trueHotNodes.add(targetNode);
638
+ hotFunctionNodes.add(targetNode);
639
+ directHotNodes.add(targetNode);
640
+ hotExemptNodes.add(targetNode);
641
+ }
642
+ }
622
643
  for (const fn of allFunctions) {
623
644
  if (!trueHotNodes.has(fn.node) && !containsLoopOrAnimation(fn.node)) {
624
645
  if (fn.node.async === true || isEventHandlerName(fn.name)) {
@@ -2741,7 +2762,7 @@ function makeLiteral(value) {
2741
2762
  };
2742
2763
  }
2743
2764
  function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArrowFn = false) {
2744
- const family = Math.abs(seed + fnIndex & 3);
2765
+ const family = Math.abs((seed + fnIndex) % 5);
2745
2766
  const c1 = (seed >>> 1) + Math.imul(family + 1, 22912827) & 524287;
2746
2767
  const c2 = (c1 ^ 173477) & 524287;
2747
2768
  const target = (seed ^ Math.imul(family + 1, 2654435761)) & 524287 | 1;
@@ -2814,7 +2835,7 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
2814
2835
  const term3 = makeImul(vXorK1, vXorK2);
2815
2836
  const sumTerms = makeBinary("+", shiftTerm, term3);
2816
2837
  mbaExpr = makeBinary("-", term1, sumTerms);
2817
- } else {
2838
+ } else if (family === 3) {
2818
2839
  const vOrK1 = makeBinary("|", cloneNode(vNode), cloneNode(kNode));
2819
2840
  const vOrK2 = makeBinary("|", cloneNode(vLit), cloneNode(kLit));
2820
2841
  const term1 = makeImul(vOrK1, vOrK2);
@@ -2826,6 +2847,15 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
2826
2847
  const term3 = makeImul(vXorK, vAddK);
2827
2848
  const sumTerms = makeBinary("+", term2, term3);
2828
2849
  mbaExpr = makeBinary("-", term1, sumTerms);
2850
+ } else {
2851
+ const kSq = makeImul(cloneNode(kLit), cloneNode(kLit));
2852
+ const sevenKSq = makeImul(makeLiteral(7), kSq);
2853
+ const sevenKSqSub1 = makeBinary("-", sevenKSq, makeLiteral(1));
2854
+ const term1 = makeBinary("&", sevenKSqSub1, makeLiteral(3));
2855
+ const vSq = makeImul(cloneNode(vNode), cloneNode(vLit));
2856
+ const term2 = makeBinary("&", vSq, makeLiteral(3));
2857
+ const isEq = makeBinary("===", term1, term2);
2858
+ mbaExpr = makeBinary("&", isEq, makeLiteral(1));
2829
2859
  }
2830
2860
  const decoyIdx = Math.abs(fnIndex) % 3;
2831
2861
  const consequent = decoyIdent ? createSharedDecoyConsequent(decoyIdent, decoyIdx) : createDecoyConsequent(decoyIdx);
@@ -2841,6 +2871,7 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
2841
2871
  alternate: null
2842
2872
  };
2843
2873
  }
2874
+ var MAX_COLD_GUARDS_PER_CHUNK = 12;
2844
2875
  function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes) {
2845
2876
  const decoyIdent = "_d";
2846
2877
  if (Array.isArray(ast.body)) {
@@ -2853,6 +2884,7 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
2853
2884
  }
2854
2885
  let guardedCount = 0;
2855
2886
  function maybeInjectGuard(node) {
2887
+ if (guardedCount >= MAX_COLD_GUARDS_PER_CHUNK) return;
2856
2888
  if (!coldFunctionNodes.has(node)) return;
2857
2889
  if (!node.body || node.body.type !== "BlockStatement") return;
2858
2890
  const firstParam = node.params?.[0];
@@ -3366,7 +3398,7 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
3366
3398
  });
3367
3399
  let virtualizedCount = 0;
3368
3400
  for (const fn of candidates) {
3369
- if (virtualizedCount >= 10) break;
3401
+ if (virtualizedCount >= 5) break;
3370
3402
  if (coldFunctionNodes && !coldFunctionNodes.has(fn)) {
3371
3403
  continue;
3372
3404
  }