unpeek 4.0.0 → 4.0.1

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.
Files changed (34) hide show
  1. package/README.md +7 -6
  2. package/README.tr.md +6 -5
  3. package/dist/adapters/esbuild.cjs +5 -5
  4. package/dist/adapters/esbuild.js +3 -3
  5. package/dist/adapters/next/adapter.cjs +5 -5
  6. package/dist/adapters/next/adapter.js +4 -4
  7. package/dist/adapters/next/index.cjs +5 -5
  8. package/dist/adapters/next/index.js +4 -4
  9. package/dist/adapters/rollup.cjs +5 -5
  10. package/dist/adapters/rollup.js +3 -3
  11. package/dist/adapters/rspack.cjs +5 -5
  12. package/dist/adapters/rspack.js +3 -3
  13. package/dist/adapters/vite.cjs +5 -5
  14. package/dist/adapters/vite.js +3 -3
  15. package/dist/adapters/webpack.cjs +5 -5
  16. package/dist/adapters/webpack.js +3 -3
  17. package/dist/browser.cjs +2 -2
  18. package/dist/browser.js +1 -1
  19. package/dist/{chunk-3LWXEJU6.cjs → chunk-3GDHYBVH.cjs} +56 -18
  20. package/dist/{chunk-YCRMTXOE.js → chunk-4G2HCME5.js} +2 -2
  21. package/dist/{chunk-2JU3V7HW.js → chunk-4SOS3LRV.js} +50 -9
  22. package/dist/{chunk-7HXLHLLQ.cjs → chunk-7ZEVJ4OR.cjs} +121 -29
  23. package/dist/{chunk-4FNZNIBW.js → chunk-LGTXAAZH.js} +686 -344
  24. package/dist/{chunk-KLYFNMKS.cjs → chunk-M46SFJE7.cjs} +813 -471
  25. package/dist/{chunk-ZG7BIAUI.cjs → chunk-NNAAPDUS.cjs} +58 -17
  26. package/dist/{chunk-VG4Y26ZN.cjs → chunk-OTA75YI6.cjs} +14 -14
  27. package/dist/{chunk-ADKRENAP.js → chunk-TYL32LUK.js} +46 -8
  28. package/dist/{chunk-HHC7BUCK.js → chunk-XYN5NYSD.js} +95 -3
  29. package/dist/cli/index.js +921 -372
  30. package/dist/index.cjs +184 -45
  31. package/dist/index.js +170 -31
  32. package/dist/plugins/unplugin.cjs +4 -4
  33. package/dist/plugins/unplugin.js +3 -3
  34. package/package.json +1 -1
@@ -97,6 +97,8 @@ var DEFAULT_HOC_WRAPPERS = /* @__PURE__ */ new Set([
97
97
  "connect"
98
98
  ]);
99
99
  var DEFAULT_EVENT_HANDLER_REGEX = /^(?:on|handle)(?!Tick|Render|Update|Frame|Animate|Physics)[A-Z]/;
100
+ var CRITICAL_COLD_HANDLER_REGEX = /^(?:onSubmit|handleSubmit|submit[A-Z0-9_]*|validate[A-Z0-9_]*|login|signIn|register|checkout)$/i;
101
+ var CRITICAL_COLD_CALLEE_REGEX = /^(?:onSubmit|handleSubmit|submit[A-Z0-9_]*|validate[A-Z0-9_]*|login|signIn|register|checkout|createServerReference|fetch)$/i;
100
102
  var DEFAULT_HOOK_REGEX = /^use[A-Z0-9]/;
101
103
  var REACT_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
102
104
  "useState",
@@ -882,6 +884,26 @@ function analyzeAstHotPaths(ast, config) {
882
884
  }
883
885
  }
884
886
  }
887
+ for (const fn of allFunctions) {
888
+ if (!serializedWorkerNodes.has(fn.node) && !trueHotNodes.has(fn.node) && !shallowComponentNodes.has(fn.node) && !containsLoopOrAnimation(fn.node, animationCalls)) {
889
+ let isCriticalHandler = CRITICAL_COLD_HANDLER_REGEX.test(fn.name);
890
+ if (!isCriticalHandler) {
891
+ const callees = callerToCallees.get(fn.node);
892
+ if (callees) {
893
+ for (const cName of callees) {
894
+ const bare = cName.includes(".") ? cName.split(".").pop() : cName;
895
+ if (CRITICAL_COLD_CALLEE_REGEX.test(bare)) {
896
+ isCriticalHandler = true;
897
+ break;
898
+ }
899
+ }
900
+ }
901
+ }
902
+ if (isCriticalHandler) {
903
+ coldForcedNodes.add(fn.node);
904
+ }
905
+ }
906
+ }
885
907
  const calleeToCallers = /* @__PURE__ */ new Map();
886
908
  for (const [callerNode, calleeNames] of callerToCallees.entries()) {
887
909
  for (const cName of calleeNames) {
@@ -923,9 +945,10 @@ function analyzeAstHotPaths(ast, config) {
923
945
  hotFunctionNodes.delete(node);
924
946
  hotExemptNodes.delete(node);
925
947
  }
948
+ const criticalAnnotation = typeof config?.critical?.annotation === "string" && config.critical.annotation.length > 0 ? config.critical.annotation : "@unpeek-critical";
926
949
  const astComments = ast?.__unpeekComments ?? ast?.comments ?? [];
927
950
  const criticalComments = astComments.filter(
928
- (c) => typeof c?.value === "string" && c.value.includes("@unpeek-critical")
951
+ (c) => typeof c?.value === "string" && c.value.includes(criticalAnnotation)
929
952
  );
930
953
  const criticalCommentNodes = /* @__PURE__ */ new Set();
931
954
  if (criticalComments.length > 0 && allFunctions.length > 0) {
@@ -1021,30 +1044,89 @@ function computeNormalizedIntegrityHash(source, seed = 0) {
1021
1044
  (FNV_OFFSET_BASIS ^ seed >>> 0) >>> 0
1022
1045
  );
1023
1046
  }
1024
- function isNativeDescriptorIntact() {
1025
- if (typeof Reflect === "undefined" || typeof Reflect.apply !== "function") {
1047
+ var NATIVE_BUILTIN_RE = /^function (\w+)\(\)\s*\{\s*\[native code\]\s*\}$/;
1048
+ function hasTamperedDescriptor(obj, key) {
1049
+ try {
1050
+ let cur = obj ?? null;
1051
+ while (cur) {
1052
+ const desc = Object.getOwnPropertyDescriptor(cur, key);
1053
+ if (desc && (desc.set || !desc.writable)) {
1054
+ return true;
1055
+ }
1056
+ cur = Object.getPrototypeOf(cur);
1057
+ }
1058
+ return false;
1059
+ } catch {
1060
+ return true;
1061
+ }
1062
+ }
1063
+ function isNativeBuiltinSignature(fn, expectedName, expectedLength, toStr) {
1064
+ if (typeof fn !== "function" || Reflect.has(fn, "prototype") || fn.name !== expectedName || fn.length !== expectedLength) {
1026
1065
  return false;
1027
1066
  }
1028
1067
  try {
1029
- Reflect.apply(Object.getOwnPropertyDescriptor, null, []);
1068
+ const direct = Reflect.apply(toStr, fn, []);
1069
+ const nested = Reflect.apply(Reflect.apply, null, [toStr, fn, []]);
1070
+ if (typeof direct !== "string" || direct !== nested) {
1071
+ return false;
1072
+ }
1073
+ const match = NATIVE_BUILTIN_RE.exec(direct);
1074
+ return !!match && match[1] === expectedName;
1075
+ } catch {
1076
+ return false;
1077
+ }
1078
+ }
1079
+ function probeThrowsCleanTypeError(fn, thisArg, args) {
1080
+ const refLine = (new Error().stack || "").split("\n")[1] || "";
1081
+ const refMatch = /^\s*at\s+([^\s(]+)\s*\(/.exec(refLine);
1082
+ const callerMarker = refMatch ? `
1083
+ at ${refMatch[1]} (` : "";
1084
+ try {
1085
+ Reflect.apply(fn, thisArg, args);
1030
1086
  return false;
1031
1087
  } catch (err) {
1032
- if (!(err instanceof TypeError)) {
1088
+ const isTypeError = err instanceof TypeError || err !== null && typeof err === "object" && err.name === "TypeError";
1089
+ if (!isTypeError) {
1033
1090
  return false;
1034
1091
  }
1092
+ const stack = err !== null && typeof err === "object" && typeof err.stack === "string" ? err.stack : "";
1093
+ if (stack && callerMarker && stack.includes(callerMarker)) {
1094
+ const head = stack.slice(0, stack.indexOf(callerMarker));
1095
+ if (/(?:Object|Proxy)\.apply\b/.test(head) || /\n at (?!.* \(<anonymous>\)$)/m.test(head)) {
1096
+ return false;
1097
+ }
1098
+ } else if (stack && /(?:Object|Proxy)\.apply\b/.test(stack)) {
1099
+ return false;
1100
+ }
1101
+ return true;
1102
+ }
1103
+ }
1104
+ function isNativeDescriptorIntact() {
1105
+ if (typeof Reflect === "undefined" || typeof Reflect.apply !== "function") {
1106
+ return false;
1107
+ }
1108
+ if (hasTamperedDescriptor(Function.prototype, "toString") || hasTamperedDescriptor(Function.prototype, "call") || hasTamperedDescriptor(Reflect, "apply")) {
1109
+ return false;
1035
1110
  }
1036
1111
  const toStr = Function.prototype.toString;
1037
- if (typeof toStr !== "function" || Reflect.has(toStr, "prototype") || toStr.name !== "toString" || toStr.length !== 0) {
1112
+ const reflectApply = Reflect.apply;
1113
+ const fnCall = Function.prototype.call;
1114
+ if (!isNativeBuiltinSignature(reflectApply, "apply", 3, toStr) || !isNativeBuiltinSignature(toStr, "toString", 0, toStr) || !isNativeBuiltinSignature(fnCall, "call", 1, toStr)) {
1038
1115
  return false;
1039
1116
  }
1040
- try {
1041
- Reflect.apply(toStr, { toString() {
1042
- } }, []);
1117
+ if (!probeThrowsCleanTypeError(Object.getOwnPropertyDescriptor, null, []) || !probeThrowsCleanTypeError(toStr, { toString() {
1118
+ } }, []) || !probeThrowsCleanTypeError(reflectApply, toStr, [null, toStr, []])) {
1043
1119
  return false;
1044
- } catch (err) {
1045
- if (!(err instanceof TypeError)) {
1120
+ }
1121
+ try {
1122
+ const probeFn = function() {
1123
+ };
1124
+ const expectedProbe = reflectApply(toStr, probeFn, []);
1125
+ if (toStr.call(probeFn) !== expectedProbe || fnCall.call(toStr, probeFn) !== expectedProbe) {
1046
1126
  return false;
1047
1127
  }
1128
+ } catch {
1129
+ return false;
1048
1130
  }
1049
1131
  return true;
1050
1132
  }
@@ -1060,7 +1142,8 @@ function verifyCodeIntegrity(fnOrSource, expectedHash, seed = 0, normalized = fa
1060
1142
  try {
1061
1143
  const toStr = Function.prototype.toString;
1062
1144
  const selfStr = Reflect.apply(toStr, toStr, []);
1063
- if (typeof selfStr !== "string" || selfStr.indexOf("[native code]") < 0) {
1145
+ const match = typeof selfStr === "string" ? NATIVE_BUILTIN_RE.exec(selfStr) : null;
1146
+ if (!match || match[1] !== "toString") {
1064
1147
  return false;
1065
1148
  }
1066
1149
  raw = Reflect.apply(toStr, fnOrSource, []);
@@ -1112,24 +1195,25 @@ var DISALLOWED_IDENTS = /* @__PURE__ */ new Set([
1112
1195
  function derivePolymorphicIdent(seed, role) {
1113
1196
  let h = (2166136261 ^ seed >>> 0) >>> 0;
1114
1197
  for (let i = 0; i < role.length; i++) {
1115
- h ^= role.charCodeAt(i);
1198
+ h = (h ^ role.charCodeAt(i)) >>> 0;
1116
1199
  h = Math.imul(h, 16777619) >>> 0;
1117
1200
  }
1118
- h ^= h >>> 16;
1201
+ h = (h ^ h >>> 16) >>> 0;
1119
1202
  h = Math.imul(h, 2246822507) >>> 0;
1120
- h ^= h >>> 13;
1203
+ h = (h ^ h >>> 13) >>> 0;
1121
1204
  h = Math.imul(h, 3266489909) >>> 0;
1122
- h ^= h >>> 16;
1205
+ h = (h ^ h >>> 16) >>> 0;
1123
1206
  for (let attempt = 0; attempt < 32; attempt++) {
1124
- const c0 = IDENT_START_CHARS[h % IDENT_START_CHARS.length];
1125
- const c1 = IDENT_CONT_CHARS[(h >>> 6) % IDENT_CONT_CHARS.length];
1126
- const c2 = IDENT_CONT_CHARS[(h >>> 12) % IDENT_CONT_CHARS.length];
1127
- const c3 = IDENT_CONT_CHARS[(h >>> 18) % IDENT_CONT_CHARS.length];
1207
+ const u = h >>> 0;
1208
+ const c0 = IDENT_START_CHARS[u % IDENT_START_CHARS.length];
1209
+ const c1 = IDENT_CONT_CHARS[(u >>> 6) % IDENT_CONT_CHARS.length];
1210
+ const c2 = IDENT_CONT_CHARS[(u >>> 12) % IDENT_CONT_CHARS.length];
1211
+ const c3 = IDENT_CONT_CHARS[(u >>> 18) % IDENT_CONT_CHARS.length];
1128
1212
  const ident = `${c0}${c1}${c2}${c3}`;
1129
1213
  if (!DISALLOWED_IDENTS.has(ident) && !ident.startsWith("__") && !ident.startsWith("_u") && !ident.startsWith("_0")) {
1130
1214
  return ident;
1131
1215
  }
1132
- h = Math.imul(h ^ 2654435769 + attempt, 2246822507) >>> 0;
1216
+ h = Math.imul(u ^ 2654435769 + attempt, 2246822507) >>> 0;
1133
1217
  }
1134
1218
  return `_${(h >>> 0).toString(36).slice(0, 3).padStart(3, "0")}`;
1135
1219
  }
@@ -1762,13 +1846,12 @@ function createDeterrentSnippet(config) {
1762
1846
  const detectHeadless = config.detectHeadless ?? false;
1763
1847
  const fnName = deriveIntegrityFnName(seed);
1764
1848
  const sym = config.windowKeySymbol ?? deriveWindowKeySymbol(seed);
1765
- const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=function(){return 0;};" : "";
1849
+ const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=()=>0;" : "";
1766
1850
  const symLit = JSON.stringify(sym);
1767
- const stateLit = JSON.stringify(`${sym}_s`);
1768
1851
  const headlessDecl = detectHeadless ? ",n=w.navigator||0" : "";
1769
1852
  const headlessCond = detectHeadless ? "||n.webdriver||/HeadlessChrome/.test(n.userAgent)" : "";
1770
1853
  const k1Mul = (seed | 1) >>> 0;
1771
- return `(function ${fnName}(w){var G=typeof globalThis<'u'?globalThis:w;if(w){var O=Object,P=O.getOwnPropertyDescriptor,GP=O.getPrototypeOf,R=typeof Reflect<'u'&&Reflect.apply,SP=String.prototype,Q='__unpeek_',y=${symLit},z=${stateLit},U='__unpeek_tampered',T=function(o,k){try{while(o){var r=P&&P(o,k);if(r&&(r.set||!r.writable))return 1;o=GP?GP(o):0;}}catch(e){return 1;}},B=function(k,v,c){try{if(!c||!T(G,k))G[k]=v;}catch(e){}try{if(!c||!T(w,k))w[k]=v;}catch(e){}},s=Function.prototype.toString${headlessDecl},src='',t=0;if((G[z]||w[z]||0)[0]==2)t=1;try{if(typeof R!='function')t=1;else{var E=function(f,a,b){try{R(f,a,b);t=1;}catch(e){t|=!e||(!(e instanceof TypeError)&&e.name!='TypeError');}};E(P,null,[]);E(s,{toString(){}},[]);src=R(s,${fnName},[]);if(typeof s!='function'||'prototype'in s||s.name!='toString'||s.length!=0||R(s,s,[]).indexOf('[native code]')<0||/\\n/.test(src)${headlessCond})t=1;}}catch(e){t=1;}for(var j in K=[y,z,U])if(T(w,K[j])||T(G,K[j]))t=1;if(T(SP,'_u'))t=1;for(var h=0x811c9dc5,i=0;i<src.length;i++)h=Math.imul(h^src.charCodeAt(i),0x01000193)>>>0;var d=h&65535,k0=(h^${seed})>>>0,k1=(h^${k1Mul})>>>0,nc=(d^(h>>>16))>>>0;B(z,[t?2:1,k0^t,k1^t,1,nc],t);if(t){var pd=(d^((h>>>16^0x5a5b)||1))&65535;B(y,pd,1);B(y+'_t',!0);B(Q+'delta',pd);try{SP._u=14;}catch(e){}B(Q+'seed',((w.__unpeek_seed||${seed})^1)>>>0);B(U,!0);try{${consoleSilence}w.dispatchEvent&&w.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(e){}}else B(y,d);}})(typeof window!=='undefined'?window:typeof self<'u'?self:typeof globalThis<'u'?globalThis:0);`;
1854
+ return `(function ${fnName}(w){var G=globalThis||w;if(w){var O=Object,P=O.getOwnPropertyDescriptor,RF=G.Reflect,R=RF&&RF.apply,FP=Function.prototype,SP=String.prototype,Q='__unpeek_',y=${symLit},z=y+'_s',U='__unpeek_tampered',K=Q+'seed',T=(o,k)=>{try{for(var r;o;o=O.getPrototypeOf(o))if((r=P(o,k))&&(r.set||!r.writable))return 1;}catch(e){return 1;}},D=k=>T(w,k)|T(G,k),B=(k,v,c,W)=>{W=o=>{try{if(!c||!T(o,k))o[k]=v;}catch(e){}};W(G);W(w);},s=FP.toString${headlessDecl},src='',t=+((G[z]||w[z])?.[0]==2);try{var ps,E=(f,a,b)=>{try{R(f,a,b);t=1;}catch(e){t|=e?.name!='TypeError'||/\\n at (?!.* \\(<anonymous>\\)$)/m.test(e?.stack?.split('\\n at E (')[0]);}},F=(f,n,l)=>typeof f!='function'||'prototype'in f||f.name!=n||f.length!=l||/^function (\\w+)\\(\\)\\s*\\x7b\\s*\\[native code\\]\\s*}$/.exec(R(R,null,[s,f,[]]))?.[1]!=n;E(P,null,[]);E(s,{toString(){}},[]);E(R,s,[null,s,[]]);src=R(s,${fnName},[]);t|=F(R,'apply',3)|F(s,'toString',0)|s.call(T)!==(ps=R(s,T,[]))|FP.call.call(s,T)!==ps|/\\n/.test(src)${headlessCond};}catch(e){t=1;}t|=D(y)|D(z)|D(U)|T(SP,'_u')|T(FP,'toString')|T(FP,'call')|T(RF,'apply');for(var h=2166136261,i=0;i<src.length;)h=Math.imul(h^src.charCodeAt(i++),16777619);var d=h&65535,pd=t?d^((h>>>16^23131)||1):d;B(z,[t+1,h^${seed}^t,h^${k1Mul}^t,1,d^h>>>16],t);B(y,pd,t);if(t){B(y+'_t',!0);B(Q+'delta',pd);try{SP._u=14;}catch(e){}B(K,((w[K]||${seed})^1)>>>0);B(U,!0);try{${consoleSilence}w.dispatchEvent?.(new CustomEvent('unpeek:tamper'));}catch(e){}}}})(typeof window!=='undefined'?window:typeof self<'u'?self:typeof globalThis<'u'?globalThis:0);`;
1772
1855
  }
1773
1856
 
1774
1857
  // src/runtime/index.ts
@@ -2600,6 +2683,43 @@ function exemptWebpackPushArg(arg, exemptSubtreeRoots) {
2600
2683
  }
2601
2684
  exemptSubtreeRoots.add(arg);
2602
2685
  }
2686
+ function exemptTurbopackPropertyKeys(objNode, exemptSubtreeRoots) {
2687
+ if (!Array.isArray(objNode?.properties)) return;
2688
+ for (const prop of objNode.properties) {
2689
+ if (prop?.type === "Property" && prop.key && typeof prop.key === "object") {
2690
+ exemptSubtreeRoots.add(prop.key);
2691
+ }
2692
+ }
2693
+ }
2694
+ function exemptTurbopackPushArg(arg, exemptSubtreeRoots) {
2695
+ if (!arg || typeof arg !== "object") return;
2696
+ if (arg.type === "ArrayExpression" && Array.isArray(arg.elements)) {
2697
+ for (let i = 0; i < arg.elements.length; i++) {
2698
+ const el = arg.elements[i];
2699
+ if (!el || typeof el !== "object") continue;
2700
+ if (i === 0) {
2701
+ exemptSubtreeRoots.add(el);
2702
+ continue;
2703
+ }
2704
+ if (el.type === "Literal") {
2705
+ exemptSubtreeRoots.add(el);
2706
+ } else if (el.type === "ObjectExpression") {
2707
+ exemptTurbopackPropertyKeys(el, exemptSubtreeRoots);
2708
+ } else if (el.type === "FunctionExpression" || el.type === "ArrowFunctionExpression") {
2709
+ continue;
2710
+ }
2711
+ }
2712
+ return;
2713
+ }
2714
+ if (arg.type === "ObjectExpression") {
2715
+ exemptTurbopackPropertyKeys(arg, exemptSubtreeRoots);
2716
+ return;
2717
+ }
2718
+ if (arg.type === "FunctionExpression" || arg.type === "ArrowFunctionExpression") {
2719
+ return;
2720
+ }
2721
+ exemptSubtreeRoots.add(arg);
2722
+ }
2603
2723
  function isHostMember(node, matcher) {
2604
2724
  if (!node) return false;
2605
2725
  if (node.type === "Identifier" && matchesPropName(node.name, matcher)) {
@@ -2658,12 +2778,13 @@ function classifyChunkBoundary(ast) {
2658
2778
  }
2659
2779
  } else if (unwrapAssignedHostMember(callee.object, "TURBOPACK")) {
2660
2780
  hasEntryBootstrap = true;
2661
- exemptSubtreeRoots.add(node);
2781
+ exemptSubtreeRoots.add(callee);
2782
+ if (callee.object && typeof callee.object === "object") {
2783
+ exemptSubtreeRoots.add(callee.object);
2784
+ }
2662
2785
  if (Array.isArray(node.arguments)) {
2663
2786
  for (const arg of node.arguments) {
2664
- if (arg && typeof arg === "object") {
2665
- exemptSubtreeRoots.add(arg);
2666
- }
2787
+ exemptTurbopackPushArg(arg, exemptSubtreeRoots);
2667
2788
  }
2668
2789
  }
2669
2790
  } else if (unwrapAssignedHostMember(callee.object, isWebpackOrRspackChunkName)) {
@@ -2786,7 +2907,10 @@ function createSaltedDecryptorFnAst(seed, pChars, expectedDelta, windowKeySymbol
2786
2907
  fBody = `var m=[],c=Function.prototype.toString.call(f),_tk=${tkExpr};for(var h=0x811c9dc5,j=0;j<c.length;j++)h=Math.imul(h^c.charCodeAt(j),0x01000193)>>>0;var A="${safeAlpha}",P="${pChars}";return function(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||((""._u||a._u||0)!==0);if(!tm&&(i in m))return m[i];var d=tm?(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1):0;var q=(h^(""._u||a._u||0)^d)>>>0,p=a[i],o="";if(p)for(var t=q^s^Math.imul(i+1,0x01000193),j=0;j<p.length;j++){t=Math.imul(t^j+1,0x01000193)^0x811c9dc5;var ch=p[j],k=A.indexOf(ch);o+=k<0?ch:A[(A.indexOf(P[(k-(t&65535)%92+92)%92])-(t>>>16)%92+92)%92];}if(!tm)m[i]=o;return o;};`;
2787
2908
  } else {
2788
2909
  const edInit = buildRivestDeltaExpr(seed, expectedDelta, "_ed");
2789
- fBody = `var m=[],c=Function.prototype.toString.call(f),_tk=${tkExpr};for(var h=0x811c9dc5,j=0;j<c.length;j++)h=Math.imul(h^c.charCodeAt(j),0x01000193)>>>0;var A="${safeAlpha}",P="${pChars}";${edInit}return function(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0;var sv=G&&G${propAccess}!==void 0?G${propAccess}:w&&w${propAccess}!==void 0?w${propAccess}:void 0;var sr=G&&G${stateAccess}?G${stateAccess}:w&&w${stateAccess}?w${stateAccess}:void 0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||(sr&&sr[0]===2)||((""._u||a._u||0)!==0)||(sv!==void 0&&sv!==_ed);if(!tm&&sv===_ed&&(i in m))return m[i];var d=tm?((_ed^(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1))&65535):_ed;var q=(h^(""._u||a._u||0)^d)>>>0,p=a[i],o="";if(p)for(var t=q^s^Math.imul(i+1,0x01000193),j=0;j<p.length;j++){t=Math.imul(t^j+1,0x01000193)^0x811c9dc5;var ch=p[j],k=A.indexOf(ch);o+=k<0?ch:A[(A.indexOf(P[(k-(t&65535)%92+92)%92])-(t>>>16)%92+92)%92];}if(!tm&&sv===_ed)m[i]=o;return o;};`;
2910
+ const hasWindowKey = Boolean(windowKeySymbol);
2911
+ const brDecl = hasWindowKey ? `var _br=typeof window<"u"||typeof document<"u"||typeof self<"u";` : "";
2912
+ const svCheck = hasWindowKey ? `(sv===void 0?!_br:sv!==_ed)` : `(sv!==void 0&&sv!==_ed)`;
2913
+ fBody = `var m=[],c=Function.prototype.toString.call(f),_tk=${tkExpr};for(var h=0x811c9dc5,j=0;j<c.length;j++)h=Math.imul(h^c.charCodeAt(j),0x01000193)>>>0;var A="${safeAlpha}",P="${pChars}";${edInit}return function(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0;` + brDecl + `var sv=G&&G${propAccess}!==void 0?G${propAccess}:w&&w${propAccess}!==void 0?w${propAccess}:void 0;var sr=G&&G${stateAccess}?G${stateAccess}:w&&w${stateAccess}?w${stateAccess}:void 0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||(sr&&sr[0]===2)||((""._u||a._u||0)!==0)||${svCheck};if(!tm&&sv===_ed&&(i in m))return m[i];var d=tm?((_ed^(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1))&65535):_ed;var q=(h^(""._u||a._u||0)^d)>>>0,p=a[i],o="";if(p)for(var t=q^s^Math.imul(i+1,0x01000193),j=0;j<p.length;j++){t=Math.imul(t^j+1,0x01000193)^0x811c9dc5;var ch=p[j],k=A.indexOf(ch);o+=k<0?ch:A[(A.indexOf(P[(k-(t&65535)%92+92)%92])-(t>>>16)%92+92)%92];}if(!tm&&sv===_ed)m[i]=o;return o;};`;
2790
2914
  }
2791
2915
  return acorn3.parse(`(function f(a){${fBody}})`, {
2792
2916
  ecmaVersion: "latest",
@@ -2835,7 +2959,7 @@ function isAstAlreadySalted(ast) {
2835
2959
  if (!ast || !Array.isArray(ast.body)) return false;
2836
2960
  return ast.body.some((stmt) => {
2837
2961
  if (stmt.type === "VariableDeclaration" && stmt.declarations?.some(
2838
- (d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && d.id.name.startsWith("_uP")
2962
+ (d) => d.id?.type === "Identifier" && typeof d.id.name === "string" && (d.id.name.startsWith("_uP") || d.init?.type === "CallExpression" && d.init.callee?.type === "FunctionExpression" && d.init.callee?.id?.name === "f" && d.init.arguments?.[0]?.type === "ArrayExpression")
2839
2963
  )) {
2840
2964
  return true;
2841
2965
  }
@@ -2866,7 +2990,8 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
2866
2990
  encryptedStringsCount: 0,
2867
2991
  integrityToken: computeFnv1aHash("already-salted", seed),
2868
2992
  vaultVarName: "",
2869
- decryptFnName: ""
2993
+ decryptFnName: "",
2994
+ shaderBuffersCount: 0
2870
2995
  };
2871
2996
  }
2872
2997
  const minLen = config?.vault?.minStringLength ?? minStringLength;
@@ -2879,154 +3004,239 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
2879
3004
  const customReserved = config?.vault?.reservedProps ? new Set(config.vault.reservedProps) : void 0;
2880
3005
  const targetsToReplace = [];
2881
3006
  const encryptedPayloads = [];
3007
+ const shaderToIndex = /* @__PURE__ */ new Map();
3008
+ const shaderPayloads = [];
3009
+ const shaderTargets = [];
3010
+ function processSaltedCandidate(val, node, parent, ancestors) {
3011
+ if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
3012
+ return;
3013
+ }
3014
+ if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
3015
+ return;
3016
+ }
3017
+ for (let i = ancestors.length - 2; i >= 0; i--) {
3018
+ if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
3019
+ return;
3020
+ }
3021
+ }
3022
+ let isHotExempt = false;
3023
+ if (hotExemptNodes) {
3024
+ for (let i = ancestors.length - 2; i >= 0; i--) {
3025
+ if (hotExemptNodes.has(ancestors[i])) {
3026
+ isHotExempt = true;
3027
+ break;
3028
+ }
3029
+ }
3030
+ }
3031
+ if (isShaderPayload(
3032
+ val,
3033
+ node,
3034
+ parent,
3035
+ ancestors,
3036
+ seed,
3037
+ isHotExempt,
3038
+ customReserved
3039
+ )) {
3040
+ let idx = shaderToIndex.get(val);
3041
+ if (idx === void 0) {
3042
+ idx = shaderPayloads.length;
3043
+ shaderToIndex.set(val, idx);
3044
+ shaderPayloads.push(val);
3045
+ }
3046
+ shaderTargets.push({ node, parent, idx });
3047
+ return;
3048
+ }
3049
+ if (isHotExempt) {
3050
+ return;
3051
+ }
3052
+ if (!shouldEncryptString(
3053
+ val,
3054
+ minLen,
3055
+ parent,
3056
+ activeDirectives,
3057
+ customReserved
3058
+ )) {
3059
+ return;
3060
+ }
3061
+ const callSiteIdx = targetsToReplace.length;
3062
+ const [saltLo, saltHi] = computeCallSiteSalt64(
3063
+ seed >>> 0,
3064
+ callSiteIdx >>> 0,
3065
+ seed >>> 0
3066
+ );
3067
+ const localSalt = ((saltLo ^ saltHi) & 2147483647 | 1) >>> 0;
3068
+ targetsToReplace.push({
3069
+ node,
3070
+ parent,
3071
+ callSiteIdx,
3072
+ localSalt,
3073
+ rawString: val
3074
+ });
3075
+ }
2882
3076
  walk3.ancestor(ast, {
2883
3077
  Literal(node, ancestors) {
2884
3078
  if (typeof node.value !== "string") return;
2885
- if (node.value.length < minLen) return;
2886
- if (activeDirectives.has(node.value)) return;
3079
+ const val = node.value;
3080
+ if (activeDirectives.has(val)) return;
2887
3081
  const parent = ancestors[ancestors.length - 2];
2888
3082
  if (!parent) return;
2889
- if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
3083
+ if ((parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") && parent.source === node) {
2890
3084
  return;
2891
3085
  }
2892
- if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(node.value))) {
3086
+ if (parent.type === "Property" && parent.key === node && !parent.computed) {
2893
3087
  return;
2894
3088
  }
2895
- for (let i = ancestors.length - 2; i >= 0; i--) {
2896
- if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
2897
- return;
2898
- }
2899
- }
2900
- if ((parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") && parent.source === node) {
3089
+ if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
2901
3090
  return;
2902
3091
  }
2903
- if (parent.type === "Property" && parent.key === node && !parent.computed) {
3092
+ if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
2904
3093
  return;
2905
3094
  }
2906
- if ((parent.type === "MethodDefinition" || parent.type === "PropertyDefinition") && parent.key === node && !parent.computed) {
3095
+ processSaltedCandidate(val, node, parent, ancestors);
3096
+ },
3097
+ TemplateLiteral(node, ancestors) {
3098
+ if (!node.quasis || node.quasis.length !== 1) return;
3099
+ if (node.expressions && node.expressions.length !== 0) return;
3100
+ const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
3101
+ if (typeof val !== "string" || activeDirectives.has(val)) return;
3102
+ const parent = ancestors[ancestors.length - 2];
3103
+ if (!parent) return;
3104
+ if (parent.type === "TaggedTemplateExpression" && parent.quasi === node) {
2907
3105
  return;
2908
3106
  }
2909
- if (hotExemptNodes) {
2910
- for (let i = ancestors.length - 1; i >= 0; i--) {
2911
- if (hotExemptNodes.has(ancestors[i])) {
2912
- return;
2913
- }
2914
- }
3107
+ if (parent.type === "ImportExpression" && parent.source === node) {
3108
+ return;
2915
3109
  }
2916
- if (isReservedProp(node.value, customReserved)) return;
2917
- if (isTailwindNoise(node.value)) return;
2918
- if (isSvgPathString(node.value, parent)) return;
2919
- const callSiteIdx = targetsToReplace.length;
2920
- const [saltLo, saltHi] = computeCallSiteSalt64(
2921
- seed >>> 0,
2922
- callSiteIdx >>> 0,
2923
- seed >>> 0
2924
- );
2925
- const localSalt = ((saltLo ^ saltHi) & 2147483647 | 1) >>> 0;
2926
- targetsToReplace.push({
2927
- node,
2928
- parent,
2929
- callSiteIdx,
2930
- localSalt,
2931
- rawString: node.value
2932
- });
3110
+ processSaltedCandidate(val, node, parent, ancestors);
2933
3111
  }
2934
3112
  });
2935
- if (targetsToReplace.length === 0) {
3113
+ if (targetsToReplace.length === 0 && shaderTargets.length === 0) {
2936
3114
  return {
2937
3115
  encryptedStringsCount: 0,
2938
3116
  integrityToken: computeFnv1aHash("empty-salted", seed),
2939
3117
  vaultVarName: "",
2940
- decryptFnName: ""
3118
+ decryptFnName: "",
3119
+ shaderBuffersCount: 0
2941
3120
  };
2942
3121
  }
2943
- const wasmResult = injectWasmVault(ast, seed);
2944
- const kdfFnName = wasmResult.kdfFnName;
2945
- const suffix = computeFnv1aHash(`salted:${seed}`, seed).toString(36);
2946
- const vaultVarName = `_uP${suffix}`;
2947
- const cacheVarName = `_uCache${suffix}`;
2948
- const dCacheVarName = `_uDc${suffix}`;
2949
- const decryptFnName = `_uD${suffix}`;
2950
- const sym = windowKeySymbol ?? deriveWindowKeySymbol(seed);
2951
- let expDelta = expectedDelta;
2952
- if (shieldCoupled && expDelta === void 0) {
2953
- const shield = generateRuntimeShield({
2954
- seed,
2955
- windowKeySymbol: sym,
2956
- deterrentMode: deterrentMode ?? "passive",
2957
- detectHeadless
3122
+ let vaultVarName = "";
3123
+ let decryptFnName = "";
3124
+ let integrityToken = computeFnv1aHash("empty-salted", seed);
3125
+ if (targetsToReplace.length > 0) {
3126
+ const wasmResult = injectWasmVault(ast, seed);
3127
+ const kdfFnName = wasmResult.kdfFnName;
3128
+ const suffix = computeFnv1aHash(`salted:${seed}`, seed).toString(36);
3129
+ vaultVarName = `_uP${suffix}`;
3130
+ const cacheVarName = `_uCache${suffix}`;
3131
+ const dCacheVarName = `_uDc${suffix}`;
3132
+ decryptFnName = `_uD${suffix}`;
3133
+ const sym = windowKeySymbol ?? deriveWindowKeySymbol(seed);
3134
+ let expDelta = expectedDelta;
3135
+ if (shieldCoupled && expDelta === void 0) {
3136
+ const shield = generateRuntimeShield({
3137
+ seed,
3138
+ windowKeySymbol: sym,
3139
+ deterrentMode: deterrentMode ?? "passive",
3140
+ detectHeadless
3141
+ });
3142
+ expDelta = shield.expectedDelta ?? 0;
3143
+ }
3144
+ const propAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(sym) ? `.${sym}` : `[${JSON.stringify(sym)}]`;
3145
+ const stateSym = `${sym}_s`;
3146
+ const stateAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(stateSym) ? `.${stateSym}` : `[${JSON.stringify(stateSym)}]`;
3147
+ const flagSym = `${sym}_t`;
3148
+ const flagAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(flagSym) ? `.${flagSym}` : `[${JSON.stringify(flagSym)}]`;
3149
+ const tkExpr = `['__','unp','eek_t','ampered'].join('')`;
3150
+ const dkExpr = `['__','unp','eek_d','elta'].join('')`;
3151
+ let helperFnSnippet;
3152
+ if (!shieldCoupled) {
3153
+ helperFnSnippet = `function ${decryptFnName}(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0,_tk=${tkExpr},_dk=${dkExpr};var dv=(G&&G[_dk]!=null?G[_dk]:w&&w[_dk]!=null?w[_dk]:0)|0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||((""._u||0)!==0)||(dv!==0);if(!tm&&${cacheVarName}[i]!==void 0)return ${cacheVarName}[i];if(${dCacheVarName}===void 0){var c=Function.prototype.toString.call(${decryptFnName}),h=0x811c9dc5;for(var l=0;l<c.length;l++)h=Math.imul(h^c.charCodeAt(l),0x01000193)>>>0;${dCacheVarName}=h|0;}var effD=tm?((${dCacheVarName}^(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1))|0):${dCacheVarName};var k=${kdfFnName}(i,s,effD);var p=${vaultVarName}[i],o="",rk=k|0;for(var j=0;j<p.length;j++){rk=(Math.imul(rk^(j+1),0x45d9f3b)+0x9e3779b9)|0;o+=String.fromCharCode(p.charCodeAt(j)^(((rk>>>16)&127)|1));}if(!tm)${cacheVarName}[i]=o;return o;}`;
3154
+ } else {
3155
+ const edInit = buildRivestDeltaExpr(seed, (expDelta ?? 0) & 65535, "_ed");
3156
+ const hasWindowKey = Boolean(sym);
3157
+ const brDecl = hasWindowKey ? `var _br=typeof window<"u"||typeof document<"u"||typeof self<"u";` : "";
3158
+ const svCheck = hasWindowKey ? `(sv===void 0?!_br:sv!==_ed)` : `(sv!==void 0&&sv!==_ed)`;
3159
+ helperFnSnippet = `function ${decryptFnName}(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0,_tk=${tkExpr},_dk=${dkExpr};${edInit}` + brDecl + `var sv=G&&G${propAccess}!==void 0?G${propAccess}:w&&w${propAccess}!==void 0?w${propAccess}:void 0;var sr=G&&G${stateAccess}?G${stateAccess}:w&&w${stateAccess}?w${stateAccess}:void 0;var dv=(G&&G[_dk]!=null?G[_dk]:w&&w[_dk]!=null?w[_dk]:0)|0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||(sr&&sr[0]===2)||((""._u||0)!==0)||(dv!==0)||${svCheck};if(!tm&&sv===_ed&&${cacheVarName}[i]!==void 0)return ${cacheVarName}[i];if(${dCacheVarName}===void 0){var c=Function.prototype.toString.call(${decryptFnName}),h=0x811c9dc5;for(var l=0;l<c.length;l++)h=Math.imul(h^c.charCodeAt(l),0x01000193)>>>0;${dCacheVarName}=((h|0)^_ed)|0;}var effD=tm?((${dCacheVarName}^(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1))|0):${dCacheVarName};var k=${kdfFnName}(i,s,effD);var p=${vaultVarName}[i],o="",rk=k|0;for(var j=0;j<p.length;j++){rk=(Math.imul(rk^(j+1),0x45d9f3b)+0x9e3779b9)|0;o+=String.fromCharCode(p.charCodeAt(j)^(((rk>>>16)&127)|1));}if(!tm&&sv===_ed)${cacheVarName}[i]=o;return o;}`;
3160
+ }
3161
+ const parsedFn = acorn3.parse(helperFnSnippet, {
3162
+ ecmaVersion: "latest",
3163
+ sourceType: "script"
2958
3164
  });
2959
- expDelta = shield.expectedDelta ?? 0;
2960
- }
2961
- const propAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(sym) ? `.${sym}` : `[${JSON.stringify(sym)}]`;
2962
- const stateSym = `${sym}_s`;
2963
- const stateAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(stateSym) ? `.${stateSym}` : `[${JSON.stringify(stateSym)}]`;
2964
- const flagSym = `${sym}_t`;
2965
- const flagAccess = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(flagSym) ? `.${flagSym}` : `[${JSON.stringify(flagSym)}]`;
2966
- const tkExpr = `['__','unp','eek_t','ampered'].join('')`;
2967
- const dkExpr = `['__','unp','eek_d','elta'].join('')`;
2968
- let helperFnSnippet;
2969
- if (!shieldCoupled) {
2970
- helperFnSnippet = `function ${decryptFnName}(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0,_tk=${tkExpr},_dk=${dkExpr};var dv=(G&&G[_dk]!=null?G[_dk]:w&&w[_dk]!=null?w[_dk]:0)|0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||((""._u||0)!==0)||(dv!==0);if(!tm&&${cacheVarName}[i]!==void 0)return ${cacheVarName}[i];if(${dCacheVarName}===void 0){var c=Function.prototype.toString.call(${decryptFnName}),h=0x811c9dc5;for(var l=0;l<c.length;l++)h=Math.imul(h^c.charCodeAt(l),0x01000193)>>>0;${dCacheVarName}=h|0;}var effD=tm?((${dCacheVarName}^(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1))|0):${dCacheVarName};var k=${kdfFnName}(i,s,effD);var p=${vaultVarName}[i],o="",rk=k|0;for(var j=0;j<p.length;j++){rk=(Math.imul(rk^(j+1),0x45d9f3b)+0x9e3779b9)|0;o+=String.fromCharCode(p.charCodeAt(j)^(((rk>>>16)&127)|1));}if(!tm)${cacheVarName}[i]=o;return o;}`;
2971
- } else {
2972
- const edInit = buildRivestDeltaExpr(seed, (expDelta ?? 0) & 65535, "_ed");
2973
- helperFnSnippet = `function ${decryptFnName}(i,s){var G=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof self<"u"?self:this;var w=typeof window<"u"?window:typeof self<"u"?self:0,_tk=${tkExpr},_dk=${dkExpr};${edInit}var sv=G&&G${propAccess}!==void 0?G${propAccess}:w&&w${propAccess}!==void 0?w${propAccess}:void 0;var sr=G&&G${stateAccess}?G${stateAccess}:w&&w${stateAccess}?w${stateAccess}:void 0;var dv=(G&&G[_dk]!=null?G[_dk]:w&&w[_dk]!=null?w[_dk]:0)|0;var tm=(G&&(G[_tk]===!0||G${flagAccess}===!0))||(w&&(w[_tk]===!0||w${flagAccess}===!0))||(sr&&sr[0]===2)||((""._u||0)!==0)||(dv!==0)||(sv!==void 0&&sv!==_ed);if(!tm&&sv===_ed&&${cacheVarName}[i]!==void 0)return ${cacheVarName}[i];if(${dCacheVarName}===void 0){var c=Function.prototype.toString.call(${decryptFnName}),h=0x811c9dc5;for(var l=0;l<c.length;l++)h=Math.imul(h^c.charCodeAt(l),0x01000193)>>>0;${dCacheVarName}=((h|0)^_ed)|0;}var effD=tm?((${dCacheVarName}^(((Math.imul(i+1,0x9e3779b1)^0x5a5b)&65535)|1))|0):${dCacheVarName};var k=${kdfFnName}(i,s,effD);var p=${vaultVarName}[i],o="",rk=k|0;for(var j=0;j<p.length;j++){rk=(Math.imul(rk^(j+1),0x45d9f3b)+0x9e3779b9)|0;o+=String.fromCharCode(p.charCodeAt(j)^(((rk>>>16)&127)|1));}if(!tm&&sv===_ed)${cacheVarName}[i]=o;return o;}`;
2974
- }
2975
- const parsedFn = acorn3.parse(helperFnSnippet, {
2976
- ecmaVersion: "latest",
2977
- sourceType: "script"
2978
- });
2979
- const fnDeclAst = parsedFn.body[0];
2980
- const selfHash = computeFnv1aHash(generateCompactJs(fnDeclAst)) | 0;
2981
- const buildD = shieldCoupled ? selfHash ^ (expDelta ?? 0) & 65535 | 0 : selfHash | 0;
2982
- for (const target of targetsToReplace) {
2983
- const k = fallbackKdf(target.callSiteIdx, target.localSalt, buildD, seed);
2984
- encryptedPayloads.push(encodeSaltedString(target.rawString, k));
2985
- const callExpr = {
2986
- type: "CallExpression",
2987
- callee: {
2988
- type: "Identifier",
2989
- name: decryptFnName
2990
- },
2991
- arguments: [
2992
- {
2993
- type: "Literal",
2994
- value: target.callSiteIdx,
2995
- raw: String(target.callSiteIdx)
3165
+ const fnDeclAst = parsedFn.body[0];
3166
+ const selfHash = computeFnv1aHash(generateCompactJs(fnDeclAst)) | 0;
3167
+ const buildD = shieldCoupled ? selfHash ^ (expDelta ?? 0) & 65535 | 0 : selfHash | 0;
3168
+ for (const target of targetsToReplace) {
3169
+ const k = fallbackKdf(target.callSiteIdx, target.localSalt, buildD, seed);
3170
+ encryptedPayloads.push(encodeSaltedString(target.rawString, k));
3171
+ const callExpr = {
3172
+ type: "CallExpression",
3173
+ callee: {
3174
+ type: "Identifier",
3175
+ name: decryptFnName
2996
3176
  },
2997
- {
2998
- type: "Literal",
2999
- value: target.localSalt,
3000
- raw: String(target.localSalt)
3001
- }
3002
- ],
3003
- optional: false
3004
- };
3005
- replaceNodeInParent(target.parent, target.node, callExpr);
3177
+ arguments: [
3178
+ {
3179
+ type: "Literal",
3180
+ value: target.callSiteIdx,
3181
+ raw: String(target.callSiteIdx)
3182
+ },
3183
+ {
3184
+ type: "Literal",
3185
+ value: target.localSalt,
3186
+ raw: String(target.localSalt)
3187
+ }
3188
+ ],
3189
+ optional: false
3190
+ };
3191
+ replaceNodeInParent(target.parent, target.node, callExpr);
3192
+ }
3193
+ const serializedTable = JSON.stringify(encryptedPayloads);
3194
+ integrityToken = computeFnv1aHash(serializedTable, seed);
3195
+ const varsSnippet = `var ${vaultVarName}=${serializedTable};var ${cacheVarName}=[];var ${dCacheVarName};`;
3196
+ const parsedVars = acorn3.parse(varsSnippet, {
3197
+ ecmaVersion: "latest",
3198
+ sourceType: "script"
3199
+ });
3200
+ const insertIdx = findVaultInsertIndex(ast, activeDirectives);
3201
+ ast.body.splice(insertIdx, 0, ...parsedVars.body, fnDeclAst);
3006
3202
  }
3007
- const serializedTable = JSON.stringify(encryptedPayloads);
3008
- const integrityToken = computeFnv1aHash(serializedTable, seed);
3009
- const varsSnippet = `var ${vaultVarName}=${serializedTable};var ${cacheVarName}=[];var ${dCacheVarName};`;
3010
- const parsedVars = acorn3.parse(varsSnippet, {
3011
- ecmaVersion: "latest",
3012
- sourceType: "script"
3013
- });
3014
- let insertIdx = 0;
3015
- while (insertIdx < ast.body.length) {
3016
- const stmt = ast.body[insertIdx];
3017
- const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && (activeDirectives.has(stmt.expression.value) || /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim())));
3018
- if (isDirective || stmt.type === "ImportDeclaration") {
3019
- insertIdx++;
3020
- } else {
3021
- break;
3203
+ if (shaderPayloads.length > 0) {
3204
+ const shaderVarName = derivePolymorphicIdent(seed, "shader");
3205
+ for (const target of shaderTargets) {
3206
+ const callExpr = {
3207
+ type: "CallExpression",
3208
+ callee: {
3209
+ type: "Identifier",
3210
+ name: shaderVarName
3211
+ },
3212
+ arguments: [
3213
+ {
3214
+ type: "Literal",
3215
+ value: target.idx,
3216
+ raw: String(target.idx)
3217
+ }
3218
+ ],
3219
+ optional: false
3220
+ };
3221
+ replaceNodeInParent(target.parent, target.node, callExpr);
3222
+ }
3223
+ const shaderHelperStmt = createShaderVaultAst(
3224
+ shaderVarName,
3225
+ shaderPayloads,
3226
+ seed
3227
+ );
3228
+ const shaderInsertIdx = findVaultInsertIndex(ast, activeDirectives);
3229
+ ast.body.splice(shaderInsertIdx, 0, shaderHelperStmt);
3230
+ if (targetsToReplace.length === 0) {
3231
+ integrityToken = computeFnv1aHash(JSON.stringify(shaderPayloads), seed);
3022
3232
  }
3023
3233
  }
3024
- ast.body.splice(insertIdx, 0, ...parsedVars.body, fnDeclAst);
3025
3234
  return {
3026
3235
  encryptedStringsCount: targetsToReplace.length,
3027
3236
  integrityToken,
3028
3237
  vaultVarName,
3029
- decryptFnName
3238
+ decryptFnName,
3239
+ shaderBuffersCount: shaderPayloads.length
3030
3240
  };
3031
3241
  }
3032
3242
 
@@ -3229,7 +3439,44 @@ function isEligibleHotLiteral(val, node, parent, ancestors, minLen, seed = 26544
3229
3439
  }
3230
3440
  return true;
3231
3441
  }
3232
- var SHADER_SIG_RE = /@group|@binding|@vertex|@fragment|@compute|vec4f|gl_Position|uniform/;
3442
+ var SHADER_SIG_RE = /@group|@binding|@vertex|@fragment|@compute|@builtin|@location|@workgroup_size|\bstruct\s+[A-Za-z_]\w*\s*\{|\b[iub]?vec[234][fhiu]?\b|\bmat[234](?:x[234])?[fhi]?\b|\buniform\b|\bvar<(?:uniform|storage)|\bgl_(?:Position|FragColor|FragCoord|VertexID|InstanceID)\b|\bfn\s+main\b|\bvoid\s+main\s*\(|\bprecision\s+(?:lowp|mediump|highp)\s+float\b/;
3443
+ function isInsideLoopOrSerialized(ancestors) {
3444
+ for (let i = ancestors.length - 2; i >= 0; i--) {
3445
+ const anc = ancestors[i];
3446
+ if (LOOP_NODE_TYPES.has(anc.type) || Boolean(anc._unpeekSerialized)) {
3447
+ return true;
3448
+ }
3449
+ }
3450
+ return false;
3451
+ }
3452
+ function isShaderPayload(val, node, parent, ancestors, seed, isHotExempt, customReserved) {
3453
+ if (isInsideLoopOrSerialized(ancestors)) return false;
3454
+ if (parent?.type === "Property" && parent.key === node && !parent.computed) return false;
3455
+ if (isReservedProp(val, customReserved)) return false;
3456
+ if (isTailwindNoise(val)) return false;
3457
+ if (isSvgPathString(val, parent)) return false;
3458
+ if (isAdversaryDecoy(val, seed)) return false;
3459
+ if (val.startsWith("HOT_")) return false;
3460
+ const matchesSig = SHADER_SIG_RE.test(val);
3461
+ if (!matchesSig) {
3462
+ if (val.length < 256) return false;
3463
+ if (isHotExempt && isUiClassName(val, parent)) return false;
3464
+ }
3465
+ return true;
3466
+ }
3467
+ function findVaultInsertIndex(ast, activeDirectives = DIRECTIVE_STRINGS) {
3468
+ let insertIdx = 0;
3469
+ while (insertIdx < ast.body.length) {
3470
+ const stmt = ast.body[insertIdx];
3471
+ const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && (activeDirectives.has(stmt.expression.value) || /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim())));
3472
+ if (isDirective || stmt.type === "ImportDeclaration") {
3473
+ insertIdx++;
3474
+ } else {
3475
+ break;
3476
+ }
3477
+ }
3478
+ return insertIdx;
3479
+ }
3233
3480
  function shouldEncryptString(val, minLen, parent, activeDirectives = DIRECTIVE_STRINGS, customReserved) {
3234
3481
  if (val.length < minLen || activeDirectives.has(val)) return false;
3235
3482
  if (isReservedProp(val, customReserved)) return false;
@@ -3417,6 +3664,96 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
3417
3664
  if (node.value) c(node.value, st);
3418
3665
  }
3419
3666
  };
3667
+ function processVaultCandidate(val, node, parent, ancestors) {
3668
+ if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
3669
+ return;
3670
+ }
3671
+ if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
3672
+ return;
3673
+ }
3674
+ for (let i = ancestors.length - 2; i >= 0; i--) {
3675
+ if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
3676
+ return;
3677
+ }
3678
+ }
3679
+ let isHotExempt = false;
3680
+ if (hotExemptNodes) {
3681
+ for (let i = ancestors.length - 2; i >= 0; i--) {
3682
+ if (hotExemptNodes.has(ancestors[i])) {
3683
+ isHotExempt = true;
3684
+ break;
3685
+ }
3686
+ }
3687
+ }
3688
+ if (isShaderPayload(
3689
+ val,
3690
+ node,
3691
+ parent,
3692
+ ancestors,
3693
+ seed,
3694
+ isHotExempt,
3695
+ customReserved
3696
+ )) {
3697
+ let idx2 = shaderToIndex.get(val);
3698
+ if (idx2 === void 0) {
3699
+ idx2 = shaderPayloads.length;
3700
+ shaderToIndex.set(val, idx2);
3701
+ shaderPayloads.push(val);
3702
+ }
3703
+ targetsToReplace.push({
3704
+ type: "shader",
3705
+ node,
3706
+ parent,
3707
+ idx: idx2,
3708
+ scopeChain: extractScopeChain(ast, ancestors)
3709
+ });
3710
+ return;
3711
+ }
3712
+ if (isHotExempt) {
3713
+ if (isEligibleHotLiteral(
3714
+ val,
3715
+ node,
3716
+ parent,
3717
+ ancestors,
3718
+ minLen,
3719
+ seed,
3720
+ customReserved,
3721
+ activeDirectives,
3722
+ semanticPatterns,
3723
+ excludeUi
3724
+ )) {
3725
+ hotTargetsToReplace.push({
3726
+ node,
3727
+ parent,
3728
+ val,
3729
+ idx: hotTargetsToReplace.length
3730
+ });
3731
+ }
3732
+ return;
3733
+ }
3734
+ if (!shouldEncryptString(
3735
+ val,
3736
+ minLen,
3737
+ parent,
3738
+ activeDirectives,
3739
+ customReserved
3740
+ )) {
3741
+ return;
3742
+ }
3743
+ let idx = stringToIndex.get(val);
3744
+ if (idx === void 0) {
3745
+ idx = uniqueStrings.length;
3746
+ stringToIndex.set(val, idx);
3747
+ uniqueStrings.push(val);
3748
+ }
3749
+ targetsToReplace.push({
3750
+ type: "string",
3751
+ node,
3752
+ parent,
3753
+ idx,
3754
+ scopeChain: extractScopeChain(ast, ancestors)
3755
+ });
3756
+ }
3420
3757
  walk4.ancestor(
3421
3758
  ast,
3422
3759
  {
@@ -3424,28 +3761,8 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
3424
3761
  if (typeof node.value !== "string") return;
3425
3762
  const val = node.value;
3426
3763
  if (activeDirectives.has(val)) return;
3427
- let isHotExempt = false;
3428
- if (hotExemptNodes) {
3429
- for (let i = ancestors.length - 2; i >= 0; i--) {
3430
- if (hotExemptNodes.has(ancestors[i])) {
3431
- isHotExempt = true;
3432
- break;
3433
- }
3434
- }
3435
- }
3436
3764
  const parent = ancestors[ancestors.length - 2];
3437
3765
  if (!parent) return;
3438
- if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
3439
- return;
3440
- }
3441
- if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
3442
- return;
3443
- }
3444
- for (let i = ancestors.length - 2; i >= 0; i--) {
3445
- if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
3446
- return;
3447
- }
3448
- }
3449
3766
  if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
3450
3767
  if (parent.source === node) return;
3451
3768
  }
@@ -3455,154 +3772,22 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
3455
3772
  if (parent.type === "ImportAttribute" || parent.type === "ImportSpecifier" || parent.type === "ExportSpecifier") {
3456
3773
  return;
3457
3774
  }
3458
- if (isHotExempt) {
3459
- if (isEligibleHotLiteral(
3460
- val,
3461
- node,
3462
- parent,
3463
- ancestors,
3464
- minLen,
3465
- seed,
3466
- customReserved,
3467
- activeDirectives,
3468
- semanticPatterns,
3469
- excludeUi
3470
- )) {
3471
- hotTargetsToReplace.push({
3472
- node,
3473
- parent,
3474
- val,
3475
- idx: hotTargetsToReplace.length
3476
- });
3477
- }
3478
- return;
3479
- }
3480
- if (parent.type === "Property" && parent.key === node && !parent.computed) {
3481
- if (isReservedProp(val, customReserved)) {
3482
- return;
3483
- }
3484
- }
3485
- if (isReservedProp(val, customReserved)) return;
3486
- if (isTailwindNoise(val)) return;
3487
- if (isSvgPathString(val, parent)) return;
3488
- const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
3489
- if (isShader) {
3490
- let idx = shaderToIndex.get(val);
3491
- if (idx === void 0) {
3492
- idx = shaderPayloads.length;
3493
- shaderToIndex.set(val, idx);
3494
- shaderPayloads.push(val);
3495
- }
3496
- targetsToReplace.push({
3497
- type: "shader",
3498
- node,
3499
- parent,
3500
- idx,
3501
- scopeChain: extractScopeChain(ast, ancestors)
3502
- });
3503
- } else {
3504
- if (!shouldEncryptString(val, minLen, parent, activeDirectives, customReserved)) return;
3505
- let idx = stringToIndex.get(val);
3506
- if (idx === void 0) {
3507
- idx = uniqueStrings.length;
3508
- stringToIndex.set(val, idx);
3509
- uniqueStrings.push(val);
3510
- }
3511
- targetsToReplace.push({
3512
- type: "string",
3513
- node,
3514
- parent,
3515
- idx,
3516
- scopeChain: extractScopeChain(ast, ancestors)
3517
- });
3518
- }
3775
+ processVaultCandidate(val, node, parent, ancestors);
3519
3776
  },
3520
3777
  TemplateLiteral(node, _state, ancestors) {
3521
3778
  if (!node.quasis || node.quasis.length !== 1) return;
3522
3779
  if (node.expressions && node.expressions.length !== 0) return;
3523
3780
  const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
3524
3781
  if (typeof val !== "string" || activeDirectives.has(val)) return;
3525
- if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
3526
- return;
3527
- }
3528
- let isHotExempt = false;
3529
- if (hotExemptNodes) {
3530
- for (let i = ancestors.length - 2; i >= 0; i--) {
3531
- if (hotExemptNodes.has(ancestors[i])) {
3532
- isHotExempt = true;
3533
- break;
3534
- }
3535
- }
3536
- }
3537
3782
  const parent = ancestors[ancestors.length - 2];
3538
3783
  if (!parent) return;
3539
- if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
3784
+ if (parent.type === "TaggedTemplateExpression" && parent.quasi === node) {
3540
3785
  return;
3541
3786
  }
3542
- if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
3787
+ if (parent.type === "ImportExpression" && parent.source === node) {
3543
3788
  return;
3544
3789
  }
3545
- for (let i = ancestors.length - 2; i >= 0; i--) {
3546
- if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
3547
- return;
3548
- }
3549
- }
3550
- if (isHotExempt) {
3551
- if (isEligibleHotLiteral(
3552
- val,
3553
- node,
3554
- parent,
3555
- ancestors,
3556
- minLen,
3557
- seed,
3558
- customReserved,
3559
- activeDirectives,
3560
- semanticPatterns,
3561
- excludeUi
3562
- )) {
3563
- hotTargetsToReplace.push({
3564
- node,
3565
- parent,
3566
- val,
3567
- idx: hotTargetsToReplace.length
3568
- });
3569
- }
3570
- return;
3571
- }
3572
- if (isReservedProp(val, customReserved)) return;
3573
- if (isTailwindNoise(val)) return;
3574
- if (isSvgPathString(val, parent)) return;
3575
- const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
3576
- if (isShader) {
3577
- let idx = shaderToIndex.get(val);
3578
- if (idx === void 0) {
3579
- idx = shaderPayloads.length;
3580
- shaderToIndex.set(val, idx);
3581
- shaderPayloads.push(val);
3582
- }
3583
- targetsToReplace.push({
3584
- type: "shader",
3585
- node,
3586
- parent,
3587
- idx,
3588
- scopeChain: extractScopeChain(ast, ancestors)
3589
- });
3590
- } else {
3591
- if (!shouldEncryptString(val, minLen, parent, activeDirectives, customReserved)) return;
3592
- let idx = stringToIndex.get(val);
3593
- if (idx === void 0) {
3594
- idx = uniqueStrings.length;
3595
- stringToIndex.set(val, idx);
3596
- uniqueStrings.push(val);
3597
- }
3598
- targetsToReplace.push({
3599
- type: "string",
3600
- node,
3601
- parent,
3602
- idx,
3603
- scopeChain: extractScopeChain(ast, ancestors)
3604
- });
3605
- }
3790
+ processVaultCandidate(val, node, parent, ancestors);
3606
3791
  }
3607
3792
  },
3608
3793
  customWalkBase
@@ -3646,16 +3831,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
3646
3831
  delete node.quasis;
3647
3832
  delete node.expressions;
3648
3833
  }
3649
- let insertIdx = 0;
3650
- while (insertIdx < ast.body.length) {
3651
- const stmt = ast.body[insertIdx];
3652
- const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && (activeDirectives.has(stmt.expression.value) || /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim())));
3653
- if (isDirective || stmt.type === "ImportDeclaration") {
3654
- insertIdx++;
3655
- } else {
3656
- break;
3657
- }
3658
- }
3834
+ let insertIdx = findVaultInsertIndex(ast, activeDirectives);
3659
3835
  const wantFragmented = Boolean(config?.vault?.fragmented);
3660
3836
  let fragCount = Math.max(2, Math.min(8, Math.floor(config?.vault?.fragmentCount ?? 3)));
3661
3837
  while (fragCount > 2 && Math.floor(uniqueStrings.length / fragCount) < 4) {
@@ -4876,6 +5052,19 @@ function extractParamNames(paramNode, out = []) {
4876
5052
  }
4877
5053
  return out;
4878
5054
  }
5055
+ function makeSafeNumericParam(name) {
5056
+ return {
5057
+ type: "ConditionalExpression",
5058
+ test: {
5059
+ type: "BinaryExpression",
5060
+ operator: "===",
5061
+ left: makeUnary("typeof", { type: "Identifier", name }),
5062
+ right: makeLiteral("number")
5063
+ },
5064
+ consequent: makeBinary("|", { type: "Identifier", name }, makeLiteral(0)),
5065
+ alternate: makeLiteral(0)
5066
+ };
5067
+ }
4879
5068
  function buildLiveVariables4(seed, fnIndex, paramNode, isArrowFn = false, ctxOpts) {
4880
5069
  const candidates = [];
4881
5070
  const seenNames = /* @__PURE__ */ new Set();
@@ -4883,7 +5072,7 @@ function buildLiveVariables4(seed, fnIndex, paramNode, isArrowFn = false, ctxOpt
4883
5072
  for (const name of names) {
4884
5073
  if (name && name !== "arguments" && name !== "eval" && !seenNames.has(name)) {
4885
5074
  seenNames.add(name);
4886
- candidates.push(makeBinary("|", { type: "Identifier", name }, makeLiteral(0)));
5075
+ candidates.push(makeSafeNumericParam(name));
4887
5076
  }
4888
5077
  }
4889
5078
  if (ctxOpts?.aliasIdentA && ctxOpts?.aliasIdentB) {
@@ -4930,10 +5119,18 @@ function buildLiveVariables4(seed, fnIndex, paramNode, isArrowFn = false, ctxOpt
4930
5119
  }
4931
5120
  return [candidates[0], candidates[1], candidates[2], candidates[3]];
4932
5121
  }
5122
+ var QNR_RESIDUE_FAMILIES = [
5123
+ { add: 1, mask: 3, target: 3 },
5124
+ { add: 3, mask: 7, target: 6 },
5125
+ { add: 5, mask: 7, target: 3 },
5126
+ { add: 7, mask: 15, target: 13 }
5127
+ ];
4933
5128
  function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArrowFn = false, ctxOpts) {
4934
5129
  const domain = ctxOpts?.returnDomain ?? "object";
4935
5130
  const [x1, x2, x3, x4] = buildLiveVariables4(seed, fnIndex, paramNode, isArrowFn, ctxOpts);
4936
5131
  const mba4 = buildMba4Ast(seed, fnIndex, x1, x2, x3, x4);
5132
+ const qnrFamilyIdx = ((seed ^ Math.imul(fnIndex + 1, 2654435761)) >>> 0) % QNR_RESIDUE_FAMILIES.length;
5133
+ const qnrFamily = QNR_RESIDUE_FAMILIES[qnrFamilyIdx];
4937
5134
  let qnrLeft;
4938
5135
  let zRefForDecoy;
4939
5136
  if (ctxOpts?.scratchVarIdent) {
@@ -4961,11 +5158,29 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
4961
5158
  right: buildSboxMixAst(ctxOpts.sboxIdent, ctxOpts.scratchVarIdent)
4962
5159
  });
4963
5160
  }
5161
+ if (ctxOpts.aliasIdentA) {
5162
+ const aliasSlot = fnIndex + (seed & 3) & 3;
5163
+ const aliasMem = makeMemberIndex(ctxOpts.aliasIdentA, makeLiteral(aliasSlot));
5164
+ seqExprs.push({
5165
+ type: "AssignmentExpression",
5166
+ operator: "=",
5167
+ left: cloneNode(aliasMem),
5168
+ right: makeBinary(
5169
+ "|",
5170
+ makeBinary(
5171
+ "^",
5172
+ cloneNode(aliasMem),
5173
+ makeBinary("&", cloneNode(scratchId), makeLiteral(0))
5174
+ ),
5175
+ makeLiteral(0)
5176
+ )
5177
+ });
5178
+ }
4964
5179
  seqExprs.push(
4965
5180
  makeBinary(
4966
5181
  "&",
4967
- makeBinary("+", makeImul(cloneNode(scratchId), cloneNode(scratchId)), makeLiteral(1)),
4968
- makeLiteral(3)
5182
+ makeBinary("+", makeImul(cloneNode(scratchId), cloneNode(scratchId)), makeLiteral(qnrFamily.add)),
5183
+ makeLiteral(qnrFamily.mask)
4969
5184
  )
4970
5185
  );
4971
5186
  qnrLeft = {
@@ -4977,8 +5192,8 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
4977
5192
  const zExpr = buildRivestPermAst(seed, fnIndex, mba4);
4978
5193
  qnrLeft = makeBinary(
4979
5194
  "&",
4980
- makeBinary("+", makeImul(cloneNode(zExpr), cloneNode(zExpr)), makeLiteral(1)),
4981
- makeLiteral(3)
5195
+ makeBinary("+", makeImul(cloneNode(zExpr), cloneNode(zExpr)), makeLiteral(qnrFamily.add)),
5196
+ makeLiteral(qnrFamily.mask)
4982
5197
  );
4983
5198
  zRefForDecoy = zExpr;
4984
5199
  }
@@ -4995,7 +5210,7 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
4995
5210
  type: "BinaryExpression",
4996
5211
  operator: "===",
4997
5212
  left: qnrLeft,
4998
- right: makeLiteral(3)
5213
+ right: makeLiteral(qnrFamily.target)
4999
5214
  },
5000
5215
  consequent,
5001
5216
  alternate: null
@@ -5118,6 +5333,7 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
5118
5333
  if (guardedCount >= MAX_COLD_GUARDS_PER_CHUNK) return;
5119
5334
  if (!coldFunctionNodes.has(node)) return;
5120
5335
  if (hotExemptNodes?.has(node) || node._unpeekSerialized) return;
5336
+ if (node._unpeekVirtualized === true) return;
5121
5337
  if (!node.body || node.body.type !== "BlockStatement") return;
5122
5338
  const paramNames = [];
5123
5339
  for (const p of node.params || []) {
@@ -5334,34 +5550,41 @@ function generateOpcodeMap(seed, count = OPCODE_COUNT) {
5334
5550
  }
5335
5551
  return pool.slice(0, count);
5336
5552
  }
5337
- function makeHandlerMbaZeroExpr(seed, op) {
5553
+ function computeHandlerDelta(op) {
5554
+ const delta = (op + 1) * 7 & 31;
5555
+ return delta === 0 ? 7 : delta;
5556
+ }
5557
+ function makeHandlerMbaOffsetExpr(seed, op, deltaOp) {
5338
5558
  const variant = Math.abs(mixOpSeed(seed, op * 11 + 3)) % 4;
5339
5559
  const c1 = mixOpSeed(seed, op * 11 + 5);
5340
5560
  const c2 = mixOpSeed(seed, op * 11 + 7);
5341
5561
  if (variant === 0) {
5342
- const cSum = c1 + c2 | 0;
5562
+ const cSum = c1 + c2 - deltaOp | 0;
5343
5563
  return `(((((($f.ac|${c1})+($f.ac&${c1}))|0)|((($f.p^${c2})+(($f.p&${c2})<<1))|0))+((((($f.ac|${c1})+($f.ac&${c1}))|0)&((($f.p^${c2})+(($f.p&${c2})<<1))|0))))-(((((($f.ac^$f.p)+(($f.ac&$f.p)<<1))|0)|${cSum})+((((($f.ac^$f.p)+(($f.ac&$f.p)<<1))|0)&${cSum})))|0))|0`;
5344
5564
  }
5345
5565
  if (variant === 1) {
5346
- const cSum = c1 + c2 | 0;
5566
+ const cSum = c1 + c2 + deltaOp | 0;
5347
5567
  return `((((($f.ac|$f.p)<<1)-($f.ac^$f.p))+${cSum})-((($f.ac^${c1})+(($f.ac&${c1})<<1))+(($f.p|${c2})+($f.p&${c2}))))|0`;
5348
5568
  }
5349
5569
  if (variant === 2) {
5350
- const cFold = 1 - c1 - c2 | 0;
5351
- return `(((~$f.ac|${c1})+(~$f.ac&${c1}))+(($f.ac|${c2})+($f.ac&${c2}))+${cFold})|0`;
5570
+ const cFold2 = 1 + deltaOp - c1 - c2 | 0;
5571
+ return `(((~$f.ac|${c1})+(~$f.ac&${c1}))+(($f.ac|$f.p)-(~$f.ac&$f.p))+(($f.p&${c2})+(~$f.p&${c2}))+${cFold2})|0`;
5352
5572
  }
5353
- return `((($f.ac|$f.p)-(~$f.ac&$f.p))^((($f.ac&${c1})+($f.ac&~${c1}))))|0`;
5573
+ const cFold = c1 - deltaOp | 0;
5574
+ return `((((($f.ac|$f.p)-(~$f.ac&$f.p))|${c1})+((($f.ac|$f.p)-(~$f.ac&$f.p))&${c1}))-(((($f.ac&${c2})+($f.ac&~${c2}))^${cFold})+(((($f.ac&${c2})+($f.ac&~${c2}))&${cFold})<<1)))|0`;
5354
5575
  }
5355
5576
  function wrapHandlerWithMba(seed, op, coreBody, isTerminal = false) {
5356
- const zExpr = makeHandlerMbaZeroExpr(seed, op);
5577
+ const deltaOp = computeHandlerDelta(op);
5578
+ const zExpr = makeHandlerMbaOffsetExpr(seed, op, deltaOp);
5357
5579
  const shape = Math.abs(mixOpSeed(seed, op * 17 + 1)) % 3;
5358
5580
  const zVar = shape === 0 ? "$z0" : shape === 1 ? "$m0" : "$k0";
5359
5581
  const tail = isTerminal ? "return void 0;" : shape === 0 ? "return $step($f);" : shape === 1 ? "var $nx=$step($f);return $nx;" : "return $f.d?void 0:$step($f);";
5360
- const adjustedBody = coreBody.replace(/\$Z/g, zVar);
5582
+ const balancedOffset = `(${zVar}-${deltaOp})`;
5583
+ const adjustedBody = coreBody.replace(/\$Z/g, balancedOffset);
5361
5584
  if (coreBody.includes("$Z")) {
5362
5585
  return `function($f){var ${zVar}=${zExpr};${adjustedBody}${tail}}`;
5363
5586
  }
5364
- return `function($f){var ${zVar}=${zExpr};$f.r=($f.r+${zVar})|0;${adjustedBody}${tail}}`;
5587
+ return `function($f){var ${zVar}=${zExpr};$f.r=($f.r+${balancedOffset})|0;${adjustedBody}${tail}}`;
5365
5588
  }
5366
5589
  function createInterpreterSource(vmHelperName, opMap, seed = 2654435769, windowKeySymbol, expectedDelta) {
5367
5590
  const opCount = opMap.length;
@@ -5430,17 +5653,22 @@ function createInterpreterSource(vmHelperName, opMap, seed = 2654435769, windowK
5430
5653
  const spec = coreHandlers[op];
5431
5654
  handlers[slotMap[op]] = wrapHandlerWithMba(seed, op, spec.body, Boolean(spec.terminal));
5432
5655
  }
5433
- const hasSym = Boolean(windowKeySymbol && expectedDelta !== void 0);
5656
+ const hasSym = Boolean(windowKeySymbol);
5657
+ const hasExpDelta = Boolean(hasSym && expectedDelta !== void 0);
5434
5658
  const symPropAccess = hasSym ? /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(windowKeySymbol) ? `.${windowKeySymbol}` : `[${JSON.stringify(windowKeySymbol)}]` : "";
5435
5659
  const symTamperPropAccess = hasSym ? /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(`${windowKeySymbol}_t`) ? `.${windowKeySymbol}_t` : `[${JSON.stringify(`${windowKeySymbol}_t`)}]` : "";
5436
- const expD = hasSym ? expectedDelta & 65535 : 0;
5660
+ const symStatePropAccess = hasSym ? /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(`${windowKeySymbol}_s`) ? `.${windowKeySymbol}_s` : `[${JSON.stringify(`${windowKeySymbol}_s`)}]` : "";
5661
+ const expD = hasExpDelta ? expectedDelta & 65535 : 0;
5437
5662
  const seed32 = seed | 0;
5438
- const expDigest = hasSym ? Math.imul(expD ^ seed32 | 0, 2654435761) ^ (expD << 16 | seed32 >>> 16) ^ 2246822507 | 0 : 0;
5439
- const tamperCheckExpr = hasSym ? `var $bad=$G[$tk]===!0||$G${symTamperPropAccess}===!0,$sv=$G${symPropAccess};if(!$bad&&$sv!==void 0){if(Array.isArray($sv)){if($sv[0]===2)$bad=true;}else{var $sh=(Math.imul(($sv^$S)|0,0x9e3779b1)^(($sv<<16)|($S>>>16))^0x85ebca6b)|0;if($sh!==$D)$bad=true;}}` : `var $bad=$G[$tk]===!0;`;
5440
- const paramsList = hasSym ? "$P,$A,$B,$C,$S,$D" : "$P,$A,$B,$C,$S";
5441
- const factoryRaw = `(function $I(${paramsList}){var $G=typeof globalThis<"u"?globalThis:(typeof window<"u"?window:this);var $tk=['__','unp','eek','_ta','mpe','red'].join('');var $M=[],$ok=$A&255,$sk=$B&255,$vk=$C|0;for(var $j=0;$j<$P.length;$j+=2)$M[$P[$j]]=$P[$j+1];function $rd($f){var $p=$f.p++;var $x0=$f.st=(Math.imul($f.st^($p+1),0x45d9f3b)+(($f.ac|0x9e3779b9)+($f.ac&0x9e3779b9)))|0;var $w=$f.c[$p],$v=$w^(($x0>>>16)&0xffff);$f.st=($f.st^Math.imul($w+1,0x85ebca6b))|0;$f.ac=(Math.imul($f.ac^$v,0x27d4eb2d)^(($f.st>>>13)|($f.st<<19)))|0;return $v;}var $H=[${handlers.join(
5663
+ const seedU32 = seed >>> 0;
5664
+ const scopeKey = hasSym ? computeFnv1aHash(`${windowKeySymbol}:${hasExpDelta ? expD : ""}`, seed) >>> 0 : 0;
5665
+ const expDigest = hasExpDelta ? Math.imul(expD ^ seed32 | 0, 2654435761) ^ (expD << 16 | seed32 >>> 16) ^ 2246822507 | 0 : 0;
5666
+ const selfPrettyCheck = "$pp||/\\n/.test(Function.prototype.toString.call($vm))";
5667
+ const tamperCheckExpr = hasSym ? `var $bad=${selfPrettyCheck}||($G&&($G[$tk]===!0||$G${symTamperPropAccess}===!0||($G${symStatePropAccess}&&$G${symStatePropAccess}[0]===2))),$sv=$G?$G${symPropAccess}:void 0;if(!$bad){if($sv===void 0){if(typeof window>"u"&&typeof document>"u"&&typeof self>"u")$bad=!0;}else if(Array.isArray($sv)){if($sv[0]===2)$bad=!0;}${hasExpDelta ? `else if($sv!==($sv|0)){$bad=!0;}else{var $sh=(Math.imul(($sv^$S)|0,0x9e3779b1)^(($sv<<16)|($S>>>16))^0x85ebca6b)|0;if($sh!==$D)$bad=!0;}` : ""}}` : `var $bad=${selfPrettyCheck}||($G&&$G[$tk]===!0);`;
5668
+ const paramsList = hasExpDelta ? "$P,$A,$B,$C,$S,$D" : "$P,$A,$B,$C,$S";
5669
+ const factoryRaw = `(function $I(${paramsList}){var $G=typeof globalThis<"u"?globalThis:(typeof window<"u"?window:(typeof self<"u"?self:this));var $pp=/\\n/.test(Function.prototype.toString.call($I));var $rk=['__','unp','eek','_vm'].join('');var $rg=0,$rs=0;try{$rg=$G?($G[$rk]||($G[$rk]={})) : 0;$rs=$rg?($rg[${scopeKey}]||($rg[${scopeKey}]={})) : 0;if(!$pp&&$rs&&$rs[${seedU32}])return $rs[${seedU32}];}catch($e){}var $tk=['__','unp','eek','_ta','mpe','red'].join('');var $M=[],$ok=$A&255,$sk=$B&255,$vk=$C|0;for(var $j=0;$j<$P.length;$j+=2)$M[$P[$j]]=$P[$j+1];function $rd($f){var $p=$f.p++;var $x0=$f.st=(Math.imul($f.st^($p+1),0x45d9f3b)+(($f.ac|0x9e3779b9)+($f.ac&0x9e3779b9)))|0;var $w=$f.c[$p],$v=$w^(($x0>>>16)&0xffff);$f.st=($f.st^Math.imul($w+1,0x85ebca6b))|0;$f.ac=(Math.imul($f.ac^$v,0x27d4eb2d)^(($f.st>>>13)|($f.st<<19)))|0;return $v;}var $H=[${handlers.join(
5442
5670
  ","
5443
- )}];function $step($f){if($f.d||$f.p>=$f.c.length)return void 0;var $o=$rd($f),$m=$M[$o^$ok];return $m!==void 0?$H[$m^$sk]:void 0;}function $x($f){var $fn=$step($f);while($fn!==void 0){try{$fn=$fn($f);}catch($err){if($f.e.length>0){var $ex=$f.e.pop();$f.r=$ex.r;$f.q[$f.r++]=$err;$f.p=$ex.p;$f.st=$ex.s;$f.ac=$ex.a;$fn=$step($f);}else{throw $err;}}}return $f.v;}return function($c,$k,$s0,$t,$a,$u){${tamperCheckExpr}var $flt=$bad?(Math.imul($vk^$a,0x45d9f3b)|1):0;return $x({c:$c,k:$k,s:$s0,t:$t,u:$u||[],q:[],r:0,p:0,st:($vk^$a^$flt)|0,ac:($vk^($a<<5)^0x517cc1b7^$flt)|0,e:[],d:0,v:void 0});};})`;
5671
+ )}];function $step($f){if($f.d||$f.p>=$f.c.length)return void 0;var $o=$rd($f),$m=$M[$o^$ok];return $m!==void 0?$H[$m^$sk]:void 0;}function $x($f){var $fn=$step($f);while($fn!==void 0){try{$fn=$fn($f);}catch($err){if($f.e.length>0){var $ex=$f.e.pop();$f.r=$ex.r;$f.q[$f.r++]=$err;$f.p=$ex.p;$f.st=$ex.s;$f.ac=$ex.a;$fn=$step($f);}else{throw $err;}}}return $f.v;}var $vm=function($c,$k,$s0,$t,$a,$u){${tamperCheckExpr}var $flt=$bad?(Math.imul($vk^$a,0x45d9f3b)|1):0;return $x({c:$c,k:$k,s:$s0,t:$t,u:$u||[],q:[],r:0,p:0,st:($vk^$a^$flt)|0,ac:($vk^($a<<5)^0x517cc1b7^$flt)|0,e:[],d:0,v:void 0});};try{if(!$pp&&$rs)$rs[${seedU32}]=$vm;}catch($e){}return $vm;})`;
5444
5672
  const parsedFactory = acorn6.parse(factoryRaw, {
5445
5673
  ecmaVersion: "latest",
5446
5674
  sourceType: "script"
@@ -5449,7 +5677,7 @@ function createInterpreterSource(vmHelperName, opMap, seed = 2654435769, windowK
5449
5677
  const argA = opMask & 255;
5450
5678
  const argB = slotMask & 255;
5451
5679
  const argC = vmKey | 0;
5452
- return `var ${vmHelperName}=(${compactFactory})([${pairs.join(",")}],${argA},${argB},${argC},${seed32}${hasSym ? `,${expDigest}` : ""});`;
5680
+ return `var ${vmHelperName}=(${compactFactory})([${pairs.join(",")}],${argA},${argB},${argC},${seed32}${hasExpDelta ? `,${expDigest}` : ""});`;
5453
5681
  }
5454
5682
  function walkWithParent(node, parent, visitor) {
5455
5683
  if (!node || typeof node !== "object") return;
@@ -5659,6 +5887,33 @@ function prepareLoweredFunction(fnNode, enclosingBindings) {
5659
5887
  }
5660
5888
  return { loweredFn: clone, wrapperParams, paramPassExprs };
5661
5889
  }
5890
+ function definitelyTerminates(stmt) {
5891
+ if (!stmt) return false;
5892
+ switch (stmt.type) {
5893
+ case "ReturnStatement":
5894
+ case "ThrowStatement":
5895
+ return true;
5896
+ case "BlockStatement": {
5897
+ const stmts = stmt.body || [];
5898
+ for (const s of stmts) {
5899
+ if (definitelyTerminates(s)) return true;
5900
+ }
5901
+ return false;
5902
+ }
5903
+ case "IfStatement":
5904
+ return Boolean(
5905
+ stmt.alternate && definitelyTerminates(stmt.consequent) && definitelyTerminates(stmt.alternate)
5906
+ );
5907
+ case "TryStatement": {
5908
+ if (stmt.finalizer && definitelyTerminates(stmt.finalizer)) return true;
5909
+ if (!definitelyTerminates(stmt.block)) return false;
5910
+ if (stmt.handler && !definitelyTerminates(stmt.handler.body)) return false;
5911
+ return true;
5912
+ }
5913
+ default:
5914
+ return false;
5915
+ }
5916
+ }
5662
5917
  function compileFunctionToBytecode(fnNode, opMap, enclosingBindings) {
5663
5918
  const bytecode = [];
5664
5919
  const consts = [];
@@ -6374,10 +6629,15 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings) {
6374
6629
  const jzPos = emitJumpPlaceholder(OP_JZ);
6375
6630
  if (!compileStmt(stmt.consequent, false)) return false;
6376
6631
  if (stmt.alternate) {
6377
- const jmpPos = emitJumpPlaceholder(OP_JMP);
6632
+ let jmpPos = -1;
6633
+ if (!definitelyTerminates(stmt.consequent)) {
6634
+ jmpPos = emitJumpPlaceholder(OP_JMP);
6635
+ }
6378
6636
  patchJump(jzPos, bytecode.length);
6379
6637
  if (!compileStmt(stmt.alternate, false)) return false;
6380
- patchJump(jmpPos, bytecode.length);
6638
+ if (jmpPos !== -1) {
6639
+ patchJump(jmpPos, bytecode.length);
6640
+ }
6381
6641
  } else {
6382
6642
  patchJump(jzPos, bytecode.length);
6383
6643
  }
@@ -6647,14 +6907,19 @@ function compileFunctionToBytecode(fnNode, opMap, enclosingBindings) {
6647
6907
  return false;
6648
6908
  }
6649
6909
  }
6910
+ let endsWithTermination = false;
6650
6911
  if (fnNode.body.type === "BlockStatement") {
6651
6912
  if (!compileStmt(fnNode.body, true)) return null;
6913
+ endsWithTermination = definitelyTerminates(fnNode.body);
6652
6914
  } else {
6653
6915
  if (!compileExpr(fnNode.body, true)) return null;
6654
6916
  emit(OP_RET);
6917
+ endsWithTermination = true;
6918
+ }
6919
+ if (!endsWithTermination) {
6920
+ emit(OP_LDC, addConst(void 0));
6921
+ emit(OP_RET);
6655
6922
  }
6656
- emit(OP_LDC, addConst(void 0));
6657
- emit(OP_RET);
6658
6923
  return { bytecode, consts, localCount, stateSlots, accSlots, upvalues };
6659
6924
  }
6660
6925
  function findInjectedVmHelperName(ast) {
@@ -6673,6 +6938,80 @@ function findInjectedVmHelperName(ast) {
6673
6938
  }
6674
6939
  return null;
6675
6940
  }
6941
+ var PRIORITY_HANDLER_NAME_RE = /^(?:onSubmit|handleSubmit|submit[A-Za-z0-9_]*|validate[A-Za-z0-9_]*|login(?:[A-Z0-9_].*)?|signIn(?:[A-Z0-9_].*)?|register(?:[A-Z0-9_].*)?|checkout(?:[A-Z0-9_].*)?)$/i;
6942
+ var PRIORITY_CALL_NAME_RE = /^(?:onSubmit|handleSubmit|submit[A-Za-z0-9_]*|validate[A-Za-z0-9_]*|login(?:[A-Z0-9_].*)?|signIn(?:[A-Z0-9_].*)?|register(?:[A-Z0-9_].*)?|checkout(?:[A-Z0-9_].*)?|createServerReference|fetch)$/i;
6943
+ function getVmCandidateName(fn, ancestors) {
6944
+ if (fn.id?.type === "Identifier" && typeof fn.id.name === "string") {
6945
+ return fn.id.name;
6946
+ }
6947
+ const parent = ancestors.length >= 2 ? ancestors[ancestors.length - 2] : null;
6948
+ if (!parent) return "";
6949
+ if (parent.type === "VariableDeclarator" && parent.id?.type === "Identifier") {
6950
+ return parent.id.name;
6951
+ }
6952
+ if (parent.type === "Property") {
6953
+ if (parent.key?.type === "Identifier") return parent.key.name;
6954
+ if (parent.key?.type === "Literal" && typeof parent.key.value === "string") {
6955
+ return parent.key.value;
6956
+ }
6957
+ }
6958
+ if (parent.type === "MethodDefinition" && parent.key?.type === "Identifier") {
6959
+ return parent.key.name;
6960
+ }
6961
+ if (parent.type === "AssignmentExpression") {
6962
+ if (parent.left?.type === "Identifier") return parent.left.name;
6963
+ if (parent.left?.type === "MemberExpression" && !parent.left.computed && parent.left.property?.type === "Identifier") {
6964
+ return parent.left.property.name;
6965
+ }
6966
+ }
6967
+ return "";
6968
+ }
6969
+ function bodyHasPrioritySignal(fnNode) {
6970
+ let matched = false;
6971
+ walkWithParent(fnNode.body, fnNode, (n, parent) => {
6972
+ if (matched) return false;
6973
+ if (n !== fnNode && FUNCTION_NODE_TYPES2.has(n.type)) return false;
6974
+ if (n.type === "CallExpression") {
6975
+ const callee = n.callee;
6976
+ if (callee?.type === "Identifier" && PRIORITY_CALL_NAME_RE.test(callee.name)) {
6977
+ matched = true;
6978
+ return false;
6979
+ }
6980
+ if (callee?.type === "MemberExpression" && !callee.computed && callee.property?.type === "Identifier" && PRIORITY_CALL_NAME_RE.test(callee.property.name)) {
6981
+ matched = true;
6982
+ return false;
6983
+ }
6984
+ }
6985
+ if (n.type === "Identifier" && PRIORITY_CALL_NAME_RE.test(n.name)) {
6986
+ if (parent && parent.type === "MemberExpression" && !parent.computed && parent.property === n) {
6987
+ return;
6988
+ }
6989
+ if (parent && parent.type === "Property" && !parent.computed && parent.key === n && !parent.shorthand) {
6990
+ return;
6991
+ }
6992
+ matched = true;
6993
+ return false;
6994
+ }
6995
+ });
6996
+ return matched;
6997
+ }
6998
+ function scoreVmCandidate(fn, ancestors, criticalSet) {
6999
+ let score = 0;
7000
+ if (criticalSet?.has(fn)) {
7001
+ score += 1e3;
7002
+ }
7003
+ const candName = getVmCandidateName(fn, ancestors);
7004
+ if (candName && PRIORITY_HANDLER_NAME_RE.test(candName) || bodyHasPrioritySignal(fn)) {
7005
+ score += 500;
7006
+ }
7007
+ if (fn.body?.type === "BlockStatement" && Array.isArray(fn.body.body)) {
7008
+ const stmtCount = fn.body.body.length;
7009
+ if (stmtCount >= 2) {
7010
+ score += Math.min(200, 10 + (stmtCount - 2) * 15);
7011
+ }
7012
+ }
7013
+ return score;
7014
+ }
6676
7015
  function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 2654435769, windowKeySymbol, expectedDelta, extraOpts) {
6677
7016
  const suffix = computeFnv1aHash(`micro-vm:${seed}`, seed).toString(36);
6678
7017
  const vmHelperName = `_uVm${suffix}`;
@@ -6791,10 +7130,11 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
6791
7130
  }
6792
7131
  }
6793
7132
  });
6794
- const candidates = criticalSet ? [
6795
- ...rawCandidates.filter((c) => criticalSet.has(c.fn)),
6796
- ...rawCandidates.filter((c) => !criticalSet.has(c.fn))
6797
- ] : rawCandidates;
7133
+ const candidates = rawCandidates.map((c, idx) => ({
7134
+ ...c,
7135
+ score: scoreVmCandidate(c.fn, c.ancestors, criticalSet),
7136
+ idx
7137
+ })).sort((a, b) => b.score !== a.score ? b.score - a.score : a.idx - b.idx);
6798
7138
  let virtualizedCount = 0;
6799
7139
  for (const { fn, ancestors } of candidates) {
6800
7140
  if (virtualizedCount >= maxFunctions) break;
@@ -6958,6 +7298,7 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
6958
7298
  } else {
6959
7299
  fn.body = callExpr;
6960
7300
  }
7301
+ fn._unpeekVirtualized = true;
6961
7302
  virtualizedCount++;
6962
7303
  }
6963
7304
  if (virtualizedCount > 0) {
@@ -7313,6 +7654,7 @@ function transformJavaScript(code, options = {}) {
7313
7654
  );
7314
7655
  encryptedStringsCount = saltedRes.encryptedStringsCount;
7315
7656
  integrityToken = saltedRes.integrityToken;
7657
+ shaderBuffersCount = saltedRes.shaderBuffersCount ?? 0;
7316
7658
  } else {
7317
7659
  const vaultRes = applyStringVault(
7318
7660
  ast,