unpeek 1.10.0 → 1.12.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.
- package/dist/ast/index.cjs +414 -93
- package/dist/ast/index.cjs.map +1 -1
- package/dist/ast/index.d.cts +6 -5
- package/dist/ast/index.d.ts +6 -5
- package/dist/ast/index.js +414 -93
- package/dist/ast/index.js.map +1 -1
- package/dist/browser.cjs +414 -93
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +414 -93
- package/dist/browser.js.map +1 -1
- package/dist/bundler/detector.cjs +132 -41
- package/dist/bundler/detector.cjs.map +1 -1
- package/dist/bundler/detector.d.cts +7 -3
- package/dist/bundler/detector.d.ts +7 -3
- package/dist/bundler/detector.js +129 -41
- package/dist/bundler/detector.js.map +1 -1
- package/dist/bundler/sourcemap-vault.cjs +136 -46
- package/dist/bundler/sourcemap-vault.cjs.map +1 -1
- package/dist/bundler/sourcemap-vault.d.cts +2 -1
- package/dist/bundler/sourcemap-vault.d.ts +2 -1
- package/dist/bundler/sourcemap-vault.js +136 -46
- package/dist/bundler/sourcemap-vault.js.map +1 -1
- package/dist/bundler/unplugin.cjs +419 -95
- package/dist/bundler/unplugin.cjs.map +1 -1
- package/dist/bundler/unplugin.js +419 -95
- package/dist/bundler/unplugin.js.map +1 -1
- package/dist/cli/index.cjs +911 -209
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +896 -194
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init.cjs +78 -29
- package/dist/cli/init.cjs.map +1 -1
- package/dist/cli/init.js +78 -29
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/protect.cjs +928 -226
- package/dist/cli/protect.cjs.map +1 -1
- package/dist/cli/protect.js +904 -202
- package/dist/cli/protect.js.map +1 -1
- package/dist/config.cjs +333 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +12 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.js +291 -0
- package/dist/config.js.map +1 -0
- package/dist/esbuild.cjs +419 -95
- package/dist/esbuild.cjs.map +1 -1
- package/dist/esbuild.d.cts +1 -1
- package/dist/esbuild.d.ts +1 -1
- package/dist/esbuild.js +419 -95
- package/dist/esbuild.js.map +1 -1
- package/dist/index.cjs +1006 -246
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +972 -219
- package/dist/index.js.map +1 -1
- package/dist/rollup.cjs +419 -95
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +419 -95
- package/dist/rollup.js.map +1 -1
- package/dist/runtime/index.cjs +3 -2
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.js +3 -2
- package/dist/runtime/index.js.map +1 -1
- package/dist/{types-DBNcJBCS.d.cts → types-CgWUnSfX.d.cts} +65 -1
- package/dist/{types-DBNcJBCS.d.ts → types-CgWUnSfX.d.ts} +65 -1
- package/dist/vite.cjs +419 -95
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +419 -95
- package/dist/vite.js.map +1 -1
- package/dist/webpack.cjs +419 -95
- package/dist/webpack.cjs.map +1 -1
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +419 -95
- package/dist/webpack.js.map +1 -1
- package/package.json +1 -1
package/dist/ast/index.cjs
CHANGED
|
@@ -62,8 +62,30 @@ 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
|
]);
|
|
72
|
+
var DEFAULT_IMPORT_SOURCES = {
|
|
73
|
+
"@react-three/fiber": ["useFrame"],
|
|
74
|
+
lenis: ["useLenis", "raf"],
|
|
75
|
+
"lenis/react": ["useLenis"],
|
|
76
|
+
three: ["onBeforeRender", "updateMatrixWorld", "useFrame"],
|
|
77
|
+
gsap: ["ticker"]
|
|
78
|
+
};
|
|
79
|
+
var DEFAULT_HOC_WRAPPERS = /* @__PURE__ */ new Set([
|
|
80
|
+
"memo",
|
|
81
|
+
"forwardRef",
|
|
82
|
+
"React.memo",
|
|
83
|
+
"React.forwardRef",
|
|
84
|
+
"observer",
|
|
85
|
+
"connect"
|
|
86
|
+
]);
|
|
87
|
+
var DEFAULT_EVENT_HANDLER_REGEX = /^(?:on|handle)(?!Tick|Render|Update|Frame|Animate|Physics)[A-Z]/;
|
|
88
|
+
var DEFAULT_HOOK_REGEX = /^use[A-Z0-9]/;
|
|
67
89
|
var REACT_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
|
|
68
90
|
"useState",
|
|
69
91
|
"useEffect",
|
|
@@ -71,6 +93,9 @@ var REACT_HOOK_OR_RENDER_CALLS = /* @__PURE__ */ new Set([
|
|
|
71
93
|
"useCallback",
|
|
72
94
|
"useRef",
|
|
73
95
|
"useLayoutEffect",
|
|
96
|
+
"useActionState",
|
|
97
|
+
"useFormStatus",
|
|
98
|
+
"useOptimistic",
|
|
74
99
|
"jsx",
|
|
75
100
|
"jsxs",
|
|
76
101
|
"_jsx",
|
|
@@ -101,7 +126,24 @@ function parseJavaScriptAst(code) {
|
|
|
101
126
|
}
|
|
102
127
|
}
|
|
103
128
|
}
|
|
104
|
-
function
|
|
129
|
+
function isHocCall(callNode, hocWrappers) {
|
|
130
|
+
if (!callNode || callNode.type !== "CallExpression") return false;
|
|
131
|
+
const callee = callNode.callee;
|
|
132
|
+
if (!callee) return false;
|
|
133
|
+
const wrappers = hocWrappers ?? DEFAULT_HOC_WRAPPERS;
|
|
134
|
+
if (callee.type === "Identifier") {
|
|
135
|
+
return wrappers.has(callee.name);
|
|
136
|
+
}
|
|
137
|
+
if (callee.type === "MemberExpression" && !callee.computed && callee.property?.type === "Identifier") {
|
|
138
|
+
if (wrappers.has(callee.property.name)) return true;
|
|
139
|
+
if (callee.object?.type === "Identifier") {
|
|
140
|
+
const full2 = `${callee.object.name}.${callee.property.name}`;
|
|
141
|
+
if (wrappers.has(full2)) return true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
function getFunctionLabel(node, ancestors, hocWrappers) {
|
|
105
147
|
if (node.id && typeof node.id.name === "string") {
|
|
106
148
|
return node.id.name;
|
|
107
149
|
}
|
|
@@ -124,14 +166,35 @@ function getFunctionLabel(node, ancestors) {
|
|
|
124
166
|
if (parent.type === "AssignmentExpression" && parent.left?.type === "Identifier") {
|
|
125
167
|
return parent.left.name;
|
|
126
168
|
}
|
|
169
|
+
if (parent.type === "CallExpression") {
|
|
170
|
+
let idx = ancestors.length - 2;
|
|
171
|
+
let matchedHoc = false;
|
|
172
|
+
while (idx >= 0 && ancestors[idx].type === "CallExpression") {
|
|
173
|
+
if (isHocCall(ancestors[idx], hocWrappers)) {
|
|
174
|
+
matchedHoc = true;
|
|
175
|
+
idx--;
|
|
176
|
+
} else {
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (matchedHoc && idx >= 0) {
|
|
181
|
+
const outer = ancestors[idx];
|
|
182
|
+
if (outer.type === "VariableDeclarator" && outer.id?.type === "Identifier") {
|
|
183
|
+
return outer.id.name;
|
|
184
|
+
}
|
|
185
|
+
if (outer.type === "AssignmentExpression" && outer.left?.type === "Identifier") {
|
|
186
|
+
return outer.left.name;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
127
190
|
}
|
|
128
191
|
return `anonymous_${node.start}`;
|
|
129
192
|
}
|
|
130
193
|
function isPascalCaseComponent(name) {
|
|
131
194
|
return /^[A-Z][a-zA-Z0-9]*$/.test(name);
|
|
132
195
|
}
|
|
133
|
-
function isEventHandlerName(name) {
|
|
134
|
-
return
|
|
196
|
+
function isEventHandlerName(name, regex = DEFAULT_EVENT_HANDLER_REGEX) {
|
|
197
|
+
return regex.test(name);
|
|
135
198
|
}
|
|
136
199
|
function findEnclosingScopeNode(ancestors, selfNode) {
|
|
137
200
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
@@ -173,7 +236,7 @@ function isZeroArgIifeFactoryFunction(node) {
|
|
|
173
236
|
const callee = retArg.callee;
|
|
174
237
|
return callee && (callee.type === "FunctionExpression" || callee.type === "ArrowFunctionExpression") && callee.body?.type === "BlockStatement";
|
|
175
238
|
}
|
|
176
|
-
function containsLoopOrAnimation(fnNode) {
|
|
239
|
+
function containsLoopOrAnimation(fnNode, animationCalls = ANIMATION_FRAME_CALLS) {
|
|
177
240
|
let found = false;
|
|
178
241
|
walk.simple(fnNode, {
|
|
179
242
|
ForStatement() {
|
|
@@ -199,14 +262,15 @@ function containsLoopOrAnimation(fnNode) {
|
|
|
199
262
|
} else if (callNode.callee?.type === "MemberExpression" && !callNode.callee.computed && callNode.callee.property?.type === "Identifier") {
|
|
200
263
|
mProp = callNode.callee.property.name;
|
|
201
264
|
}
|
|
202
|
-
|
|
265
|
+
const isTickerAdd = mProp === "add" && (callNode.callee?.object?.name === "ticker" || callNode.callee?.object?.property?.name === "ticker");
|
|
266
|
+
if (animationCalls.has(cName) || animationCalls.has(mProp) || isTickerAdd) {
|
|
203
267
|
found = true;
|
|
204
268
|
}
|
|
205
269
|
}
|
|
206
270
|
});
|
|
207
271
|
return found;
|
|
208
272
|
}
|
|
209
|
-
function analyzeAstHotPaths(ast) {
|
|
273
|
+
function analyzeAstHotPaths(ast, config) {
|
|
210
274
|
const hotFunctionNodes = /* @__PURE__ */ new WeakSet();
|
|
211
275
|
const coldFunctionNodes = /* @__PURE__ */ new WeakSet();
|
|
212
276
|
const hotExemptNodes = /* @__PURE__ */ new WeakSet();
|
|
@@ -225,7 +289,61 @@ function analyzeAstHotPaths(ast) {
|
|
|
225
289
|
const fnVarAliases = /* @__PURE__ */ new Map();
|
|
226
290
|
const callerToCallees = /* @__PURE__ */ new Map();
|
|
227
291
|
const pendingSerializedRefs = [];
|
|
292
|
+
const pendingHotRefs = [];
|
|
228
293
|
const allCallSites = [];
|
|
294
|
+
const animationCalls = new Set(ANIMATION_FRAME_CALLS);
|
|
295
|
+
if (config?.hotPath?.customAnimationCalls) {
|
|
296
|
+
for (const c of config.hotPath.customAnimationCalls) {
|
|
297
|
+
animationCalls.add(c);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const mergedImportSources = {
|
|
301
|
+
...DEFAULT_IMPORT_SOURCES,
|
|
302
|
+
...config?.hotPath?.importSources ?? {}
|
|
303
|
+
};
|
|
304
|
+
if (ast && Array.isArray(ast.body)) {
|
|
305
|
+
for (const stmt of ast.body) {
|
|
306
|
+
if (stmt.type === "ImportDeclaration" && stmt.source?.value) {
|
|
307
|
+
const sourcePkg = String(stmt.source.value);
|
|
308
|
+
const sourceMethods = mergedImportSources[sourcePkg];
|
|
309
|
+
for (const spec of stmt.specifiers || []) {
|
|
310
|
+
if (spec.type === "ImportSpecifier") {
|
|
311
|
+
const importedName = spec.imported?.name ?? spec.imported?.value;
|
|
312
|
+
const localName = spec.local?.name;
|
|
313
|
+
if (localName && importedName) {
|
|
314
|
+
const isKnownSource = sourceMethods !== void 0;
|
|
315
|
+
const isListedMethod = sourceMethods && (sourceMethods.includes(importedName) || sourceMethods.includes("*"));
|
|
316
|
+
const isKnownAnimCall = ANIMATION_FRAME_CALLS.has(importedName);
|
|
317
|
+
if (isKnownSource && isListedMethod || isKnownAnimCall) {
|
|
318
|
+
animationCalls.add(localName);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
const hocWrappers = new Set(DEFAULT_HOC_WRAPPERS);
|
|
327
|
+
if (config?.hotPath?.hocWrappers) {
|
|
328
|
+
for (const h of config.hotPath.hocWrappers) {
|
|
329
|
+
hocWrappers.add(h);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const arrayHofMethods = new Set(ARRAY_HOF_METHODS);
|
|
333
|
+
if (config?.hotPath?.arrayHofMethods) {
|
|
334
|
+
for (const m of config.hotPath.arrayHofMethods) {
|
|
335
|
+
arrayHofMethods.add(m);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const eventHandlerRegex = config?.hotPath?.eventHandlerRegex ?? DEFAULT_EVENT_HANDLER_REGEX;
|
|
339
|
+
const hookRegex = config?.hotPath?.hookPattern ?? DEFAULT_HOOK_REGEX;
|
|
340
|
+
const customHooksSet = new Set(config?.hotPath?.customHooks ?? []);
|
|
341
|
+
function isHookName(name) {
|
|
342
|
+
if (!name) return false;
|
|
343
|
+
return customHooksSet.has(name) || hookRegex.test(name);
|
|
344
|
+
}
|
|
345
|
+
const excludedComponents = new Set(config?.hotPath?.excludeComponents ?? []);
|
|
346
|
+
const maxPipelineCallers = config?.hotPath?.maxPipelineCallers ?? 2;
|
|
229
347
|
function ensureFnParams(fnNode) {
|
|
230
348
|
let paramSet = fnParams.get(fnNode);
|
|
231
349
|
if (!paramSet) {
|
|
@@ -268,7 +386,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
268
386
|
hotExemptNodes.add(node);
|
|
269
387
|
}
|
|
270
388
|
function registerFunctionNode(node, ancestors) {
|
|
271
|
-
const name = getFunctionLabel(node, ancestors);
|
|
389
|
+
const name = getFunctionLabel(node, ancestors, hocWrappers);
|
|
272
390
|
allFunctions.push({ node, name });
|
|
273
391
|
fnByName.set(name, node);
|
|
274
392
|
const paramSet = /* @__PURE__ */ new Set();
|
|
@@ -318,7 +436,13 @@ function analyzeAstHotPaths(ast) {
|
|
|
318
436
|
}
|
|
319
437
|
}
|
|
320
438
|
fnScopeChain.set(node, chain);
|
|
321
|
-
if (isPascalCaseComponent(name)) {
|
|
439
|
+
if (isPascalCaseComponent(name) && !excludedComponents.has(name)) {
|
|
440
|
+
shallowComponentNodes.add(node);
|
|
441
|
+
hotFunctionNodes.add(node);
|
|
442
|
+
directHotNodes.add(node);
|
|
443
|
+
hotExemptNodes.add(node);
|
|
444
|
+
}
|
|
445
|
+
if (isHookName(name)) {
|
|
322
446
|
shallowComponentNodes.add(node);
|
|
323
447
|
hotFunctionNodes.add(node);
|
|
324
448
|
directHotNodes.add(node);
|
|
@@ -454,7 +578,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
454
578
|
callerToCallees.set(enclosingFn, set);
|
|
455
579
|
}
|
|
456
580
|
if (qualifiedCall) set.add(qualifiedCall);
|
|
457
|
-
if (memberProp && !
|
|
581
|
+
if (memberProp && !arrayHofMethods.has(memberProp)) {
|
|
458
582
|
set.add(memberProp);
|
|
459
583
|
}
|
|
460
584
|
}
|
|
@@ -490,7 +614,8 @@ function analyzeAstHotPaths(ast) {
|
|
|
490
614
|
const outerFn = findOutermostModuleFunction(ancestors);
|
|
491
615
|
if (outerFn) markSerializedFunction(outerFn);
|
|
492
616
|
}
|
|
493
|
-
|
|
617
|
+
const isTickerAdd = memberProp === "add" && (callee?.object?.name === "ticker" || callee?.object?.property?.name === "ticker");
|
|
618
|
+
if (animationCalls.has(calleeName) || animationCalls.has(memberProp) || isTickerAdd) {
|
|
494
619
|
if (enclosingFn) {
|
|
495
620
|
trueHotNodes.add(enclosingFn);
|
|
496
621
|
hotFunctionNodes.add(enclosingFn);
|
|
@@ -503,6 +628,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
503
628
|
directHotNodes.add(arg);
|
|
504
629
|
hotExemptNodes.add(arg);
|
|
505
630
|
} else if (arg?.type === "Identifier") {
|
|
631
|
+
pendingHotRefs.push({ scopeNode: currentScope, name: arg.name });
|
|
506
632
|
allCallSites.push({
|
|
507
633
|
scopeNode: currentScope,
|
|
508
634
|
calleeKey: arg.name,
|
|
@@ -511,7 +637,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
511
637
|
}
|
|
512
638
|
}
|
|
513
639
|
}
|
|
514
|
-
if (
|
|
640
|
+
if (arrayHofMethods.has(memberProp)) {
|
|
515
641
|
if (enclosingFn !== null) {
|
|
516
642
|
for (const arg of node.arguments || []) {
|
|
517
643
|
if (FUNCTION_NODE_TYPES.has(arg.type)) {
|
|
@@ -529,7 +655,8 @@ function analyzeAstHotPaths(ast) {
|
|
|
529
655
|
}
|
|
530
656
|
} else {
|
|
531
657
|
for (const arg of node.arguments || []) {
|
|
532
|
-
|
|
658
|
+
const isAnonymousFunction = arg.type === "FunctionExpression" && !arg.id || arg.type === "ArrowFunctionExpression";
|
|
659
|
+
if (isAnonymousFunction) {
|
|
533
660
|
coldForcedNodes.add(arg);
|
|
534
661
|
}
|
|
535
662
|
}
|
|
@@ -538,11 +665,11 @@ function analyzeAstHotPaths(ast) {
|
|
|
538
665
|
if (calleeName === "useEffect" || memberProp === "useEffect" || calleeName === "useLayoutEffect" || memberProp === "useLayoutEffect") {
|
|
539
666
|
const effectArg = node.arguments?.[0];
|
|
540
667
|
if (effectArg && FUNCTION_NODE_TYPES.has(effectArg.type)) {
|
|
541
|
-
if (!containsLoopOrAnimation(effectArg)) {
|
|
668
|
+
if (!containsLoopOrAnimation(effectArg, animationCalls)) {
|
|
542
669
|
coldForcedNodes.add(effectArg);
|
|
543
670
|
if (effectArg.body?.type === "BlockStatement") {
|
|
544
671
|
for (const s of effectArg.body.body || []) {
|
|
545
|
-
if (s.type === "ReturnStatement" && s.argument && FUNCTION_NODE_TYPES.has(s.argument.type) && !containsLoopOrAnimation(s.argument)) {
|
|
672
|
+
if (s.type === "ReturnStatement" && s.argument && FUNCTION_NODE_TYPES.has(s.argument.type) && !containsLoopOrAnimation(s.argument, animationCalls)) {
|
|
546
673
|
coldForcedNodes.add(s.argument);
|
|
547
674
|
}
|
|
548
675
|
}
|
|
@@ -550,7 +677,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
550
677
|
}
|
|
551
678
|
}
|
|
552
679
|
}
|
|
553
|
-
if (REACT_HOOK_OR_RENDER_CALLS.has(calleeName) || REACT_HOOK_OR_RENDER_CALLS.has(memberProp)) {
|
|
680
|
+
if (REACT_HOOK_OR_RENDER_CALLS.has(calleeName) || REACT_HOOK_OR_RENDER_CALLS.has(memberProp) || isHookName(calleeName) || isHookName(memberProp)) {
|
|
554
681
|
if (enclosingFn) {
|
|
555
682
|
shallowComponentNodes.add(enclosingFn);
|
|
556
683
|
hotFunctionNodes.add(enclosingFn);
|
|
@@ -619,10 +746,21 @@ function analyzeAstHotPaths(ast) {
|
|
|
619
746
|
markSerializedFunction(targetNode);
|
|
620
747
|
}
|
|
621
748
|
}
|
|
749
|
+
for (const ref of pendingHotRefs) {
|
|
750
|
+
const targetNode = resolveCalleeNode(ref.scopeNode, ref.name);
|
|
751
|
+
if (targetNode) {
|
|
752
|
+
trueHotNodes.add(targetNode);
|
|
753
|
+
hotFunctionNodes.add(targetNode);
|
|
754
|
+
directHotNodes.add(targetNode);
|
|
755
|
+
hotExemptNodes.add(targetNode);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
622
758
|
for (const fn of allFunctions) {
|
|
623
|
-
if (!trueHotNodes.has(fn.node) && !containsLoopOrAnimation(fn.node)) {
|
|
624
|
-
if (
|
|
625
|
-
|
|
759
|
+
if (!trueHotNodes.has(fn.node) && !containsLoopOrAnimation(fn.node, animationCalls)) {
|
|
760
|
+
if (!shallowComponentNodes.has(fn.node)) {
|
|
761
|
+
if (fn.node.async === true || isEventHandlerName(fn.name, eventHandlerRegex)) {
|
|
762
|
+
coldForcedNodes.add(fn.node);
|
|
763
|
+
}
|
|
626
764
|
}
|
|
627
765
|
}
|
|
628
766
|
}
|
|
@@ -712,7 +850,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
712
850
|
const targetNode = resolveCalleeNode(callerNode, cName);
|
|
713
851
|
if (targetNode && trueHotNodes.has(targetNode)) {
|
|
714
852
|
const callers = calleeToCallers.get(targetNode);
|
|
715
|
-
const isDedicatedPipeline = callers && callers.size <=
|
|
853
|
+
const isDedicatedPipeline = callers && callers.size <= maxPipelineCallers;
|
|
716
854
|
if (isDedicatedPipeline) {
|
|
717
855
|
trueHotNodes.add(callerNode);
|
|
718
856
|
hotFunctionNodes.add(callerNode);
|
|
@@ -750,7 +888,7 @@ function analyzeAstHotPaths(ast) {
|
|
|
750
888
|
serializedFunctionNodes
|
|
751
889
|
};
|
|
752
890
|
}
|
|
753
|
-
function detectHotPaths(code) {
|
|
891
|
+
function detectHotPaths(code, config) {
|
|
754
892
|
const ast = parseJavaScriptAst(code);
|
|
755
893
|
if (!ast) {
|
|
756
894
|
return {
|
|
@@ -759,7 +897,7 @@ function detectHotPaths(code) {
|
|
|
759
897
|
coldFunctionsProtected: []
|
|
760
898
|
};
|
|
761
899
|
}
|
|
762
|
-
return analyzeAstHotPaths(ast).report;
|
|
900
|
+
return analyzeAstHotPaths(ast, config).report;
|
|
763
901
|
}
|
|
764
902
|
|
|
765
903
|
// src/ast/string-vault.ts
|
|
@@ -1137,7 +1275,7 @@ function createDeterrentSnippet(config) {
|
|
|
1137
1275
|
const fnName = deriveIntegrityFnName(seed);
|
|
1138
1276
|
const sym = config.windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
1139
1277
|
const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=function(){return 0;};" : "";
|
|
1140
|
-
return `(function ${fnName}(w){if(w){try{var s=Function.prototype.toString,n=w.navigator||0,src=s.call(${fnName}),t=s.call(s).indexOf('[native code]')<0||/\\n/.test(src)||n.webdriver||/HeadlessChrome/.test(n.userAgent);for(var h=0x811c9dc5,i=0;i<src.length;i++)h=Math.imul(h^src.charCodeAt(i),0x01000193)>>>0;var d=(h&31);if(t){w.__unpeek_tampered=!0;w.__unpeek_seed=((w.__unpeek_seed||${seed})^1)>>>0;String.prototype._u=14;w['${sym}']=d^29;try{${consoleSilence}w.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(e){}}else{w['${sym}']=d;}}catch(e){}}})(typeof window!=='undefined'
|
|
1278
|
+
return `(function ${fnName}(w){var G=typeof globalThis!=='undefined'?globalThis:(typeof window!=='undefined'?window:(typeof self!=='undefined'?self:this));if(w){try{var s=Function.prototype.toString,n=w.navigator||0,src=s.call(${fnName}),t=s.call(s).indexOf('[native code]')<0||/\\n/.test(src)||n.webdriver||/HeadlessChrome/.test(n.userAgent);for(var h=0x811c9dc5,i=0;i<src.length;i++)h=Math.imul(h^src.charCodeAt(i),0x01000193)>>>0;var d=(h&31);if(t){G.__unpeek_tampered=w.__unpeek_tampered=!0;G.__unpeek_seed=w.__unpeek_seed=((w.__unpeek_seed||${seed})^1)>>>0;String.prototype._u=14;G['${sym}']=w['${sym}']=d^29;G.__unpeek_delta=w.__unpeek_delta=d^29;try{${consoleSilence}if(typeof w.dispatchEvent==='function')w.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(e){}}else{G['${sym}']=w['${sym}']=d;}}catch(e){}}})(typeof window!=='undefined'?window:(typeof self!=='undefined'?self:0));`;
|
|
1141
1279
|
}
|
|
1142
1280
|
|
|
1143
1281
|
// src/runtime/index.ts
|
|
@@ -1150,7 +1288,8 @@ function generateRuntimeShield(config) {
|
|
|
1150
1288
|
windowKeySymbol
|
|
1151
1289
|
});
|
|
1152
1290
|
const fnStart = preambleCode.indexOf("function");
|
|
1153
|
-
const
|
|
1291
|
+
const endMarker = preambleCode.indexOf("})(");
|
|
1292
|
+
const fnEnd = endMarker !== -1 ? endMarker + 1 : preambleCode.lastIndexOf("(") - 1;
|
|
1154
1293
|
const fnDecl = preambleCode.slice(fnStart, fnEnd);
|
|
1155
1294
|
const computedHash = computeIntegrityHash(fnDecl, 0);
|
|
1156
1295
|
const expectedHash = config.expectedIntegrityHash !== void 0 ? config.expectedIntegrityHash >>> 0 : computedHash;
|
|
@@ -1368,17 +1507,11 @@ try {
|
|
|
1368
1507
|
}
|
|
1369
1508
|
|
|
1370
1509
|
// src/ast/salted-vault.ts
|
|
1371
|
-
var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
|
|
1372
|
-
"use strict",
|
|
1373
|
-
"use client",
|
|
1374
|
-
"use server",
|
|
1375
|
-
"use asm"
|
|
1376
|
-
]);
|
|
1377
1510
|
function computeCallSiteSalt(seed, idx) {
|
|
1378
1511
|
return ((seed & 15 ^ idx * 5 + 3) & 31) >>> 0;
|
|
1379
1512
|
}
|
|
1380
1513
|
function createSaltedDecryptorFnAst(seed, pChars, expectedDelta, windowKeySymbol, safeAlpha = SAFE_ALPHA) {
|
|
1381
|
-
const fBody = `var memo=[]
|
|
1514
|
+
const fBody = `var memo=[],s=Function.prototype.toString,G=typeof globalThis!=='undefined'?globalThis:(typeof window!=='undefined'?window:(typeof self!=='undefined'?self:this)),w=typeof window!=='undefined'?window:(typeof self!=='undefined'?self:0),src=s.call(f);for(var h=0x811c9dc5,j=0;j<src.length;j++)h=Math.imul(h^src.charCodeAt(j),0x01000193)>>>0;var delta=G['${windowKeySymbol}']!=null?G['${windowKeySymbol}']:(w?0:${expectedDelta}),rot=(h^((""._u||a._u||0))^delta)&31,A="${safeAlpha}",P="${pChars}";return function(i,s){if(memo[i]!==void 0)return memo[i];var p=a[i],o="";if(!p)return "";for(var j=0;j<p.length;j++){var c=p.charAt(j),k=A.indexOf(c);if(k<0)o+=c;else{var y=(k-s+rot+9200)%92;o+=A.charAt((A.indexOf(P.charAt(y))-rot+9200)%92);}}return(memo[i]=o);};`;
|
|
1382
1515
|
return acorn3.parse(`(function f(a){${fBody}})`, {
|
|
1383
1516
|
ecmaVersion: "latest",
|
|
1384
1517
|
sourceType: "script"
|
|
@@ -1449,7 +1582,7 @@ function replaceNodeInParent(parent, oldNode, newNode) {
|
|
|
1449
1582
|
}
|
|
1450
1583
|
return false;
|
|
1451
1584
|
}
|
|
1452
|
-
function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes) {
|
|
1585
|
+
function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, config) {
|
|
1453
1586
|
if (isAstAlreadySalted(ast)) {
|
|
1454
1587
|
return {
|
|
1455
1588
|
encryptedStringsCount: 0,
|
|
@@ -1458,16 +1591,32 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
1458
1591
|
decryptFnName: ""
|
|
1459
1592
|
};
|
|
1460
1593
|
}
|
|
1594
|
+
const minLen = config?.vault?.minStringLength ?? minStringLength;
|
|
1595
|
+
const activeDirectives = new Set(DIRECTIVE_STRINGS);
|
|
1596
|
+
if (config?.vault?.customDirectives) {
|
|
1597
|
+
for (const dir of config.vault.customDirectives) {
|
|
1598
|
+
activeDirectives.add(dir);
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
const customReserved = config?.vault?.reservedProps ? new Set(config.vault.reservedProps) : void 0;
|
|
1461
1602
|
const targetsToReplace = [];
|
|
1462
1603
|
const encryptedPayloads = [];
|
|
1463
1604
|
walk2.ancestor(ast, {
|
|
1464
1605
|
Literal(node, ancestors) {
|
|
1465
1606
|
if (typeof node.value !== "string") return;
|
|
1466
|
-
if (node.value.length <
|
|
1467
|
-
if (
|
|
1607
|
+
if (node.value.length < minLen) return;
|
|
1608
|
+
if (activeDirectives.has(node.value)) return;
|
|
1468
1609
|
const parent = ancestors[ancestors.length - 2];
|
|
1469
1610
|
if (!parent) return;
|
|
1470
|
-
if (
|
|
1611
|
+
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(node.value))) {
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1615
|
+
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
1616
|
+
return;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
if ((parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") && parent.source === node) {
|
|
1471
1620
|
return;
|
|
1472
1621
|
}
|
|
1473
1622
|
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
@@ -1483,6 +1632,9 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
1483
1632
|
}
|
|
1484
1633
|
}
|
|
1485
1634
|
}
|
|
1635
|
+
if (isReservedProp(node.value, customReserved)) return;
|
|
1636
|
+
if (isTailwindNoise(node.value)) return;
|
|
1637
|
+
if (isSvgPathString(node.value, parent)) return;
|
|
1486
1638
|
const callSiteIdx = targetsToReplace.length;
|
|
1487
1639
|
const localSalt = computeFnv1aHash(`salt:${seed}:${callSiteIdx}`, seed) & 2147483647 | 1;
|
|
1488
1640
|
targetsToReplace.push({
|
|
@@ -1535,11 +1687,13 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
1535
1687
|
}
|
|
1536
1688
|
const serializedTable = JSON.stringify(encryptedPayloads);
|
|
1537
1689
|
const integrityToken = computeFnv1aHash(serializedTable, seed);
|
|
1690
|
+
const sym = deriveWindowKeySymbol(seed);
|
|
1538
1691
|
const helperSnippet = `var ${vaultVarName} = ${serializedTable};
|
|
1539
1692
|
var ${cacheVarName} = [];
|
|
1540
1693
|
function ${decryptFnName}(i, s) {
|
|
1541
1694
|
if (${cacheVarName}[i] !== void 0) return ${cacheVarName}[i];
|
|
1542
|
-
var
|
|
1695
|
+
var G = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : (typeof self !== 'undefined' ? self : this));
|
|
1696
|
+
var d = G && G.__unpeek_delta != null ? G.__unpeek_delta : 0;
|
|
1543
1697
|
var k = ${kdfFnName}(i, s, d);
|
|
1544
1698
|
var p = ${vaultVarName}[i], o = '';
|
|
1545
1699
|
for (var j = 0; j < p.length; j++) {
|
|
@@ -1551,7 +1705,17 @@ function ${decryptFnName}(i, s) {
|
|
|
1551
1705
|
ecmaVersion: "latest",
|
|
1552
1706
|
sourceType: "script"
|
|
1553
1707
|
});
|
|
1554
|
-
|
|
1708
|
+
let insertIdx = 0;
|
|
1709
|
+
while (insertIdx < ast.body.length) {
|
|
1710
|
+
const stmt = ast.body[insertIdx];
|
|
1711
|
+
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())));
|
|
1712
|
+
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
1713
|
+
insertIdx++;
|
|
1714
|
+
} else {
|
|
1715
|
+
break;
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
ast.body.splice(insertIdx, 0, ...parsedHelper.body);
|
|
1555
1719
|
return {
|
|
1556
1720
|
encryptedStringsCount: targetsToReplace.length,
|
|
1557
1721
|
integrityToken,
|
|
@@ -1562,11 +1726,15 @@ function ${decryptFnName}(i, s) {
|
|
|
1562
1726
|
|
|
1563
1727
|
// src/ast/string-vault.ts
|
|
1564
1728
|
var SAFE_ALPHA = " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~";
|
|
1565
|
-
var
|
|
1729
|
+
var DIRECTIVE_STRINGS = /* @__PURE__ */ new Set([
|
|
1566
1730
|
"use strict",
|
|
1567
1731
|
"use client",
|
|
1568
1732
|
"use server",
|
|
1569
|
-
"use asm"
|
|
1733
|
+
"use asm",
|
|
1734
|
+
"use cache",
|
|
1735
|
+
"use worklet",
|
|
1736
|
+
"use worker",
|
|
1737
|
+
"use memo"
|
|
1570
1738
|
]);
|
|
1571
1739
|
var STANDARD_PROP_KEYS = /* @__PURE__ */ new Set([
|
|
1572
1740
|
"id",
|
|
@@ -1582,8 +1750,22 @@ var STANDARD_PROP_KEYS = /* @__PURE__ */ new Set([
|
|
|
1582
1750
|
"href",
|
|
1583
1751
|
"alt",
|
|
1584
1752
|
"role",
|
|
1585
|
-
"tabIndex"
|
|
1753
|
+
"tabIndex",
|
|
1754
|
+
"class",
|
|
1755
|
+
"part",
|
|
1756
|
+
"slot",
|
|
1757
|
+
"is",
|
|
1758
|
+
"innerHTML",
|
|
1759
|
+
"disabled",
|
|
1760
|
+
"title"
|
|
1586
1761
|
]);
|
|
1762
|
+
var STANDARD_PROP_PREFIX_RE = /^(?:data-|aria-|on[A-Z]|v-|bind:)/;
|
|
1763
|
+
function isReservedProp(propName, customReserved) {
|
|
1764
|
+
if (STANDARD_PROP_KEYS.has(propName)) return true;
|
|
1765
|
+
if (customReserved && customReserved.has(propName)) return true;
|
|
1766
|
+
if (STANDARD_PROP_PREFIX_RE.test(propName)) return true;
|
|
1767
|
+
return false;
|
|
1768
|
+
}
|
|
1587
1769
|
var LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
1588
1770
|
"ForStatement",
|
|
1589
1771
|
"ForInStatement",
|
|
@@ -1591,45 +1773,104 @@ var LOOP_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
|
1591
1773
|
"WhileStatement",
|
|
1592
1774
|
"DoWhileStatement"
|
|
1593
1775
|
]);
|
|
1594
|
-
function isReactDomSpecialProp(val, node, parent) {
|
|
1595
|
-
if (
|
|
1776
|
+
function isReactDomSpecialProp(val, node, parent, customReserved) {
|
|
1777
|
+
if (isReservedProp(val, customReserved)) return true;
|
|
1596
1778
|
if (!parent) return false;
|
|
1597
1779
|
if (parent.type === "Property") {
|
|
1598
1780
|
if (parent.key === node && !parent.computed) {
|
|
1599
1781
|
return true;
|
|
1600
1782
|
}
|
|
1601
1783
|
const keyName = parent.key?.type === "Identifier" ? parent.key.name : parent.key?.type === "Literal" ? String(parent.key.value) : "";
|
|
1602
|
-
if (keyName &&
|
|
1784
|
+
if (keyName && isReservedProp(keyName, customReserved)) {
|
|
1603
1785
|
return true;
|
|
1604
1786
|
}
|
|
1605
1787
|
}
|
|
1606
1788
|
return false;
|
|
1607
1789
|
}
|
|
1790
|
+
var TAILWIND_TOKEN_RE = /^(?:flex|grid|block|inline|hidden|relative|absolute|fixed|w-|h-|min-|max-|p[xytrbl]?-|m[xytrbl]?-|space-[xy]-|text-|font-|bg-|border|rounded|shadow|ring|outline|transition|duration|opacity|cursor|pointer-events|select-|items-|justify-|gap-|overflow-|z-|inset-|top-|left-|right-|bottom-|hover:|focus:|focus-visible:|disabled:|dark:|data-\[|aria-|\[&_)/;
|
|
1791
|
+
var TAILWIND_VARIANT_PREFIX_RE = /^(?:[a-zA-Z0-9_@-]+:)+/;
|
|
1792
|
+
function stripTailwindVariants(token) {
|
|
1793
|
+
return token.replace(TAILWIND_VARIANT_PREFIX_RE, "");
|
|
1794
|
+
}
|
|
1608
1795
|
function isTailwindNoise(val) {
|
|
1609
1796
|
const trimmed = val.trim();
|
|
1610
1797
|
if (!trimmed) return false;
|
|
1798
|
+
const isMatch = (t) => {
|
|
1799
|
+
const stripped = stripTailwindVariants(t);
|
|
1800
|
+
return TAILWIND_TOKEN_RE.test(stripped) || stripped.startsWith("btn") || stripped.startsWith("p-") || stripped.startsWith("m-");
|
|
1801
|
+
};
|
|
1611
1802
|
if (trimmed.includes(" ")) {
|
|
1612
1803
|
const tokens = trimmed.split(/\s+/);
|
|
1613
1804
|
let twHits = 0;
|
|
1614
1805
|
for (const t of tokens) {
|
|
1615
|
-
if (
|
|
1806
|
+
if (isMatch(t)) {
|
|
1616
1807
|
twHits++;
|
|
1617
1808
|
}
|
|
1618
1809
|
}
|
|
1619
1810
|
if (twHits / tokens.length >= 0.5) return true;
|
|
1620
1811
|
} else {
|
|
1621
|
-
if (
|
|
1812
|
+
if (isMatch(trimmed)) return true;
|
|
1813
|
+
}
|
|
1814
|
+
return false;
|
|
1815
|
+
}
|
|
1816
|
+
function isParentSvgPathProperty(parent) {
|
|
1817
|
+
if (!parent) return false;
|
|
1818
|
+
if (parent.type === "Property") {
|
|
1819
|
+
const keyName = parent.key?.type === "Identifier" ? parent.key.name : parent.key?.type === "Literal" ? String(parent.key.value) : "";
|
|
1820
|
+
if (keyName === "d" || keyName === "path") return true;
|
|
1821
|
+
}
|
|
1822
|
+
if (parent.type === "JSXAttribute") {
|
|
1823
|
+
const attrName = parent.name?.name;
|
|
1824
|
+
if (attrName === "d" || attrName === "path") return true;
|
|
1622
1825
|
}
|
|
1623
1826
|
return false;
|
|
1624
1827
|
}
|
|
1625
|
-
function isSvgPathString(val) {
|
|
1626
|
-
|
|
1828
|
+
function isSvgPathString(val, parent) {
|
|
1829
|
+
if (typeof val !== "string" || val.length < 4) return false;
|
|
1830
|
+
const trimmed = val.trim();
|
|
1831
|
+
if (!/^[Mm]\s*[-+]?(?:\d*\.\d+|\d+)/.test(trimmed)) {
|
|
1832
|
+
return false;
|
|
1833
|
+
}
|
|
1834
|
+
if (parent && isParentSvgPathProperty(parent)) {
|
|
1835
|
+
return true;
|
|
1836
|
+
}
|
|
1837
|
+
return /[zZ]$/.test(trimmed) || /[Mm]\s*[-+]?\d.*[a-df-zA-DF-Z]\s*[-+]?\d/.test(trimmed) || /^[Mm]\s*[-+]?\d+(?:\.\d+)?[\s,]+-?\d+(?:\.\d+)?(?:\s+[a-zA-Z][-+]?\d+.*)?$/.test(
|
|
1838
|
+
trimmed
|
|
1839
|
+
);
|
|
1840
|
+
}
|
|
1841
|
+
var DEFAULT_SEMANTIC_ANCHOR_RE = /(?:\bapi\/|\bcheckout\b|\badmin\b|\bauth\b|\btoken\b|\bcredential\b|\bsecret\b|\bpassword\b|\bbearer\b)/i;
|
|
1842
|
+
function isUiClassName(val, parent) {
|
|
1843
|
+
if (parent) {
|
|
1844
|
+
if (parent.type === "Property") {
|
|
1845
|
+
const k = parent.key?.type === "Identifier" ? parent.key.name : parent.key?.type === "Literal" ? String(parent.key.value) : "";
|
|
1846
|
+
if (k === "className" || k === "class" || k === "classList") return true;
|
|
1847
|
+
}
|
|
1848
|
+
if (parent.type === "JSXAttribute") {
|
|
1849
|
+
const name = parent.name?.name;
|
|
1850
|
+
if (name === "className" || name === "class") return true;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
if (isTailwindNoise(val)) return true;
|
|
1854
|
+
if (/^[a-z0-9_-]+(?:\s+[a-z0-9_-]+)+$/i.test(val.trim())) {
|
|
1855
|
+
return true;
|
|
1856
|
+
}
|
|
1857
|
+
return false;
|
|
1858
|
+
}
|
|
1859
|
+
function isAdversaryDecoy(val, seed) {
|
|
1860
|
+
if (val.startsWith("/api/v2/auth/") || val === "superadmin_token" || val === "elevate" || val === "_verifyMasterToken" || val === "mock_jwt_bypass_signature" || val === "debug_supervisor_override" || val.startsWith("_decoy_") || val.startsWith("_auth_bypass_")) {
|
|
1861
|
+
return true;
|
|
1862
|
+
}
|
|
1863
|
+
const s = (seed >>> 0 & 65535).toString(36);
|
|
1864
|
+
if (val.includes(s) && (val.includes("auth") || val.includes("token") || val.includes("decoy") || val.includes("elevate"))) {
|
|
1865
|
+
return true;
|
|
1866
|
+
}
|
|
1867
|
+
return false;
|
|
1627
1868
|
}
|
|
1628
|
-
function isEligibleHotLiteral(val, node, parent, ancestors, minLen) {
|
|
1629
|
-
if (val.length < minLen ||
|
|
1630
|
-
if (isReactDomSpecialProp(val, node, parent)) return false;
|
|
1869
|
+
function isEligibleHotLiteral(val, node, parent, ancestors, minLen, seed = 2654435769, customReserved, activeDirectives = DIRECTIVE_STRINGS, semanticAnchorPatterns, excludeUiClasses = true) {
|
|
1870
|
+
if (val.length < minLen || activeDirectives.has(val)) return false;
|
|
1871
|
+
if (isReactDomSpecialProp(val, node, parent, customReserved)) return false;
|
|
1631
1872
|
if (isTailwindNoise(val)) return false;
|
|
1632
|
-
if (isSvgPathString(val)) return false;
|
|
1873
|
+
if (isSvgPathString(val, parent)) return false;
|
|
1633
1874
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1634
1875
|
if (LOOP_NODE_TYPES.has(ancestors[i].type)) {
|
|
1635
1876
|
return false;
|
|
@@ -1641,9 +1882,15 @@ function isEligibleHotLiteral(val, node, parent, ancestors, minLen) {
|
|
|
1641
1882
|
}
|
|
1642
1883
|
}
|
|
1643
1884
|
if (val.startsWith("HOT_")) return false;
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1885
|
+
let isSemanticAnchor = false;
|
|
1886
|
+
if (semanticAnchorPatterns && semanticAnchorPatterns.length > 0) {
|
|
1887
|
+
isSemanticAnchor = semanticAnchorPatterns.some((re) => re.test(val));
|
|
1888
|
+
} else {
|
|
1889
|
+
isSemanticAnchor = DEFAULT_SEMANTIC_ANCHOR_RE.test(val);
|
|
1890
|
+
}
|
|
1891
|
+
if (isSemanticAnchor && excludeUiClasses && isUiClassName(val, parent)) {
|
|
1892
|
+
isSemanticAnchor = false;
|
|
1893
|
+
}
|
|
1647
1894
|
let isInsideRender = false;
|
|
1648
1895
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
1649
1896
|
const a = ancestors[i];
|
|
@@ -1659,7 +1906,7 @@ function isEligibleHotLiteral(val, node, parent, ancestors, minLen) {
|
|
|
1659
1906
|
}
|
|
1660
1907
|
}
|
|
1661
1908
|
if (!isSemanticAnchor && !isInsideRender) return false;
|
|
1662
|
-
if (
|
|
1909
|
+
if (isAdversaryDecoy(val, seed)) {
|
|
1663
1910
|
return false;
|
|
1664
1911
|
}
|
|
1665
1912
|
if (parent) {
|
|
@@ -1675,22 +1922,12 @@ function isEligibleHotLiteral(val, node, parent, ancestors, minLen) {
|
|
|
1675
1922
|
}
|
|
1676
1923
|
return true;
|
|
1677
1924
|
}
|
|
1678
|
-
var TAILWIND_TOKEN_RE = /^(?:flex|grid|block|inline|hidden|relative|absolute|fixed|w-|h-|min-|max-|p[xytrbl]?-|m[xytrbl]?-|space-[xy]-|text-|font-|bg-|border|rounded|shadow|ring|outline|transition|duration|opacity|cursor|pointer-events|select-|items-|justify-|gap-|overflow-|z-|inset-|top-|left-|right-|bottom-|hover:|focus:|focus-visible:|disabled:|dark:|data-\[|aria-|\[&_)/;
|
|
1679
|
-
var SVG_PATH_RE = /^[Mm]\s*-?\d+(?:\.\d+)?[\s,]+-?\d+/;
|
|
1680
1925
|
var SHADER_SIG_RE = /@group|@binding|@vertex|@fragment|@compute|vec4f|gl_Position|uniform/;
|
|
1681
|
-
function shouldEncryptString(val, minLen) {
|
|
1682
|
-
if (val.length < minLen ||
|
|
1683
|
-
if (
|
|
1684
|
-
if (val
|
|
1685
|
-
|
|
1686
|
-
if (tokens.length >= 3) {
|
|
1687
|
-
let twHits = 0;
|
|
1688
|
-
for (const t of tokens) {
|
|
1689
|
-
if (TAILWIND_TOKEN_RE.test(t)) twHits++;
|
|
1690
|
-
}
|
|
1691
|
-
if (twHits / tokens.length >= 0.5) return false;
|
|
1692
|
-
}
|
|
1693
|
-
}
|
|
1926
|
+
function shouldEncryptString(val, minLen, parent, activeDirectives = DIRECTIVE_STRINGS, customReserved) {
|
|
1927
|
+
if (val.length < minLen || activeDirectives.has(val)) return false;
|
|
1928
|
+
if (isReservedProp(val, customReserved)) return false;
|
|
1929
|
+
if (isSvgPathString(val, parent)) return false;
|
|
1930
|
+
if (isTailwindNoise(val)) return false;
|
|
1694
1931
|
return true;
|
|
1695
1932
|
}
|
|
1696
1933
|
function computeFnv1aHash(input, seed = 2166136261) {
|
|
@@ -1761,7 +1998,17 @@ function createShaderVaultAst(shaderVarName, shaderPayloads, seed) {
|
|
|
1761
1998
|
)};var k=${key};var b=B.map(function(s){var bin=typeof atob==='function'?atob(s):(typeof Buffer!=='undefined'?Buffer.from(s,'base64').toString('binary'):'');var u=new Uint8Array(bin.length);for(var i=0;i<bin.length;i++)u[i]=bin.charCodeAt(i);return u;});var d=typeof TextDecoder!=='undefined'?new TextDecoder():null;return function(i){var u=b[i];for(var j=0;j<u.length;j++)u[j]^=k;try{return d?d.decode(u):String.fromCharCode.apply(null,u);}finally{for(var j=0;j<u.length;j++)u[j]^=k;}};})();`;
|
|
1762
1999
|
return acorn4.parse(shaderCode, { ecmaVersion: "latest", sourceType: "script" }).body[0];
|
|
1763
2000
|
}
|
|
1764
|
-
function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta, deterrentMode) {
|
|
2001
|
+
function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta, deterrentMode, config) {
|
|
2002
|
+
const minLen = config?.vault?.minStringLength ?? minStringLength;
|
|
2003
|
+
const activeDirectives = new Set(DIRECTIVE_STRINGS);
|
|
2004
|
+
if (config?.vault?.customDirectives) {
|
|
2005
|
+
for (const dir of config.vault.customDirectives) {
|
|
2006
|
+
activeDirectives.add(dir);
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
const customReserved = config?.vault?.reservedProps ? new Set(config.vault.reservedProps) : void 0;
|
|
2010
|
+
const semanticPatterns = config?.vault?.semanticAnchors?.patterns;
|
|
2011
|
+
const excludeUi = config?.vault?.semanticAnchors?.excludeUiClasses !== false;
|
|
1765
2012
|
const suffix = (seed >>> 0 & 65535).toString(36);
|
|
1766
2013
|
const decryptFnName = `_uD${suffix}`;
|
|
1767
2014
|
const cacheVarName = derivePolymorphicIdent(seed, "vault");
|
|
@@ -1818,7 +2065,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1818
2065
|
Literal(node, _state, ancestors) {
|
|
1819
2066
|
if (typeof node.value !== "string") return;
|
|
1820
2067
|
const val = node.value;
|
|
1821
|
-
if (
|
|
2068
|
+
if (activeDirectives.has(val)) return;
|
|
1822
2069
|
let isHotExempt = false;
|
|
1823
2070
|
if (hotExemptNodes) {
|
|
1824
2071
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
@@ -1830,7 +2077,14 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1830
2077
|
}
|
|
1831
2078
|
const parent = ancestors[ancestors.length - 2];
|
|
1832
2079
|
if (!parent) return;
|
|
1833
|
-
if (parent.type === "ExpressionStatement" && parent.directive)
|
|
2080
|
+
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
2081
|
+
return;
|
|
2082
|
+
}
|
|
2083
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
2084
|
+
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
2085
|
+
return;
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
1834
2088
|
if (parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") {
|
|
1835
2089
|
if (parent.source === node) return;
|
|
1836
2090
|
}
|
|
@@ -1841,7 +2095,18 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1841
2095
|
return;
|
|
1842
2096
|
}
|
|
1843
2097
|
if (isHotExempt) {
|
|
1844
|
-
if (isEligibleHotLiteral(
|
|
2098
|
+
if (isEligibleHotLiteral(
|
|
2099
|
+
val,
|
|
2100
|
+
node,
|
|
2101
|
+
parent,
|
|
2102
|
+
ancestors,
|
|
2103
|
+
minLen,
|
|
2104
|
+
seed,
|
|
2105
|
+
customReserved,
|
|
2106
|
+
activeDirectives,
|
|
2107
|
+
semanticPatterns,
|
|
2108
|
+
excludeUi
|
|
2109
|
+
)) {
|
|
1845
2110
|
hotTargetsToReplace.push({
|
|
1846
2111
|
node,
|
|
1847
2112
|
parent,
|
|
@@ -1852,10 +2117,13 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1852
2117
|
return;
|
|
1853
2118
|
}
|
|
1854
2119
|
if (parent.type === "Property" && parent.key === node && !parent.computed) {
|
|
1855
|
-
if (
|
|
2120
|
+
if (isReservedProp(val, customReserved)) {
|
|
1856
2121
|
return;
|
|
1857
2122
|
}
|
|
1858
2123
|
}
|
|
2124
|
+
if (isReservedProp(val, customReserved)) return;
|
|
2125
|
+
if (isTailwindNoise(val)) return;
|
|
2126
|
+
if (isSvgPathString(val, parent)) return;
|
|
1859
2127
|
const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
|
|
1860
2128
|
if (isShader) {
|
|
1861
2129
|
let idx = shaderToIndex.get(val);
|
|
@@ -1866,7 +2134,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1866
2134
|
}
|
|
1867
2135
|
targetsToReplace.push({ type: "shader", node, parent, idx });
|
|
1868
2136
|
} else {
|
|
1869
|
-
if (!shouldEncryptString(val,
|
|
2137
|
+
if (!shouldEncryptString(val, minLen, parent, activeDirectives, customReserved)) return;
|
|
1870
2138
|
let idx = stringToIndex.get(val);
|
|
1871
2139
|
if (idx === void 0) {
|
|
1872
2140
|
idx = encryptedPayloads.length;
|
|
@@ -1883,7 +2151,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1883
2151
|
if (!node.quasis || node.quasis.length !== 1) return;
|
|
1884
2152
|
if (node.expressions && node.expressions.length !== 0) return;
|
|
1885
2153
|
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
1886
|
-
if (typeof val !== "string" ||
|
|
2154
|
+
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
1887
2155
|
let isHotExempt = false;
|
|
1888
2156
|
if (hotExemptNodes) {
|
|
1889
2157
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
@@ -1895,8 +2163,27 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1895
2163
|
}
|
|
1896
2164
|
const parent = ancestors[ancestors.length - 2];
|
|
1897
2165
|
if (!parent) return;
|
|
2166
|
+
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
2167
|
+
return;
|
|
2168
|
+
}
|
|
2169
|
+
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
2170
|
+
if (ancestors[i].type === "ExpressionStatement" && Boolean(ancestors[i].directive)) {
|
|
2171
|
+
return;
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
1898
2174
|
if (isHotExempt) {
|
|
1899
|
-
if (isEligibleHotLiteral(
|
|
2175
|
+
if (isEligibleHotLiteral(
|
|
2176
|
+
val,
|
|
2177
|
+
node,
|
|
2178
|
+
parent,
|
|
2179
|
+
ancestors,
|
|
2180
|
+
minLen,
|
|
2181
|
+
seed,
|
|
2182
|
+
customReserved,
|
|
2183
|
+
activeDirectives,
|
|
2184
|
+
semanticPatterns,
|
|
2185
|
+
excludeUi
|
|
2186
|
+
)) {
|
|
1900
2187
|
hotTargetsToReplace.push({
|
|
1901
2188
|
node,
|
|
1902
2189
|
parent,
|
|
@@ -1906,6 +2193,9 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1906
2193
|
}
|
|
1907
2194
|
return;
|
|
1908
2195
|
}
|
|
2196
|
+
if (isReservedProp(val, customReserved)) return;
|
|
2197
|
+
if (isTailwindNoise(val)) return;
|
|
2198
|
+
if (isSvgPathString(val, parent)) return;
|
|
1909
2199
|
const isShader = val.length >= 256 || SHADER_SIG_RE.test(val);
|
|
1910
2200
|
if (isShader) {
|
|
1911
2201
|
let idx = shaderToIndex.get(val);
|
|
@@ -1916,7 +2206,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1916
2206
|
}
|
|
1917
2207
|
targetsToReplace.push({ type: "shader", node, parent, idx });
|
|
1918
2208
|
} else {
|
|
1919
|
-
if (!shouldEncryptString(val,
|
|
2209
|
+
if (!shouldEncryptString(val, minLen, parent, activeDirectives, customReserved)) return;
|
|
1920
2210
|
let idx = stringToIndex.get(val);
|
|
1921
2211
|
if (idx === void 0) {
|
|
1922
2212
|
idx = encryptedPayloads.length;
|
|
@@ -2024,7 +2314,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
2024
2314
|
let insertIdx = 0;
|
|
2025
2315
|
while (insertIdx < ast.body.length) {
|
|
2026
2316
|
const stmt = ast.body[insertIdx];
|
|
2027
|
-
const isDirective = stmt.type === "ExpressionStatement" && (stmt.directive || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" &&
|
|
2317
|
+
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())));
|
|
2028
2318
|
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
2029
2319
|
insertIdx++;
|
|
2030
2320
|
} else {
|
|
@@ -2107,7 +2397,17 @@ var RESERVED_IDENTIFIERS = /* @__PURE__ */ new Set([
|
|
|
2107
2397
|
"require",
|
|
2108
2398
|
"module",
|
|
2109
2399
|
"exports",
|
|
2110
|
-
"React"
|
|
2400
|
+
"React",
|
|
2401
|
+
"navigator",
|
|
2402
|
+
"crypto",
|
|
2403
|
+
"location",
|
|
2404
|
+
"history",
|
|
2405
|
+
"indexedDB",
|
|
2406
|
+
"fetch",
|
|
2407
|
+
"WebSocket",
|
|
2408
|
+
"Worker",
|
|
2409
|
+
"AudioContext",
|
|
2410
|
+
"performance"
|
|
2111
2411
|
]);
|
|
2112
2412
|
var FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
2113
2413
|
"FunctionDeclaration",
|
|
@@ -2160,10 +2460,17 @@ function collectPatternTargets(pattern, out, shorthandProp) {
|
|
|
2160
2460
|
break;
|
|
2161
2461
|
}
|
|
2162
2462
|
}
|
|
2163
|
-
function isMangleableName(origName) {
|
|
2164
|
-
return origName.length > 2 && !
|
|
2463
|
+
function isMangleableName(origName, reservedSet = RESERVED_IDENTIFIERS, manglerConfig) {
|
|
2464
|
+
return origName.length > 2 && !reservedSet.has(origName) && !origName.startsWith("$") && !origName.startsWith("__") && !origName.startsWith("_u") && !origName.startsWith("_0x") && (!manglerConfig?.excludePrefixes || !manglerConfig.excludePrefixes.some((p) => origName.startsWith(p))) && (!manglerConfig?.excludePatterns || !manglerConfig.excludePatterns.some((re) => re.test(origName)));
|
|
2165
2465
|
}
|
|
2166
|
-
function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes) {
|
|
2466
|
+
function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes, config) {
|
|
2467
|
+
const activeReserved = new Set(RESERVED_IDENTIFIERS);
|
|
2468
|
+
if (config?.mangler?.reservedIdentifiers) {
|
|
2469
|
+
for (const id of config.mangler.reservedIdentifiers) {
|
|
2470
|
+
activeReserved.add(id);
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
const manglerConfig = config?.mangler;
|
|
2167
2474
|
const scopeRecords = /* @__PURE__ */ new Map();
|
|
2168
2475
|
const existingIdentifiers = /* @__PURE__ */ new Set();
|
|
2169
2476
|
let counter = 0;
|
|
@@ -2213,7 +2520,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
2213
2520
|
const scope = scopeRecords.get(scopeNode);
|
|
2214
2521
|
if (!scope) return;
|
|
2215
2522
|
const origName = target.idNode.name;
|
|
2216
|
-
let canMangle = shouldMangle && isMangleableName(origName);
|
|
2523
|
+
let canMangle = shouldMangle && isMangleableName(origName, activeReserved, manglerConfig);
|
|
2217
2524
|
if (canMangle && fnScope) {
|
|
2218
2525
|
if (serializedFunctionNodes && serializedFunctionNodes.has(fnScope)) {
|
|
2219
2526
|
canMangle = false;
|
|
@@ -2741,7 +3048,7 @@ function makeLiteral(value) {
|
|
|
2741
3048
|
};
|
|
2742
3049
|
}
|
|
2743
3050
|
function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArrowFn = false) {
|
|
2744
|
-
const family = Math.abs(seed + fnIndex
|
|
3051
|
+
const family = Math.abs((seed + fnIndex) % 5);
|
|
2745
3052
|
const c1 = (seed >>> 1) + Math.imul(family + 1, 22912827) & 524287;
|
|
2746
3053
|
const c2 = (c1 ^ 173477) & 524287;
|
|
2747
3054
|
const target = (seed ^ Math.imul(family + 1, 2654435761)) & 524287 | 1;
|
|
@@ -2814,7 +3121,7 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
2814
3121
|
const term3 = makeImul(vXorK1, vXorK2);
|
|
2815
3122
|
const sumTerms = makeBinary("+", shiftTerm, term3);
|
|
2816
3123
|
mbaExpr = makeBinary("-", term1, sumTerms);
|
|
2817
|
-
} else {
|
|
3124
|
+
} else if (family === 3) {
|
|
2818
3125
|
const vOrK1 = makeBinary("|", cloneNode(vNode), cloneNode(kNode));
|
|
2819
3126
|
const vOrK2 = makeBinary("|", cloneNode(vLit), cloneNode(kLit));
|
|
2820
3127
|
const term1 = makeImul(vOrK1, vOrK2);
|
|
@@ -2826,6 +3133,15 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
2826
3133
|
const term3 = makeImul(vXorK, vAddK);
|
|
2827
3134
|
const sumTerms = makeBinary("+", term2, term3);
|
|
2828
3135
|
mbaExpr = makeBinary("-", term1, sumTerms);
|
|
3136
|
+
} else {
|
|
3137
|
+
const kSq = makeImul(cloneNode(kLit), cloneNode(kLit));
|
|
3138
|
+
const sevenKSq = makeImul(makeLiteral(7), kSq);
|
|
3139
|
+
const sevenKSqSub1 = makeBinary("-", sevenKSq, makeLiteral(1));
|
|
3140
|
+
const term1 = makeBinary("&", sevenKSqSub1, makeLiteral(3));
|
|
3141
|
+
const vSq = makeImul(cloneNode(vNode), cloneNode(vLit));
|
|
3142
|
+
const term2 = makeBinary("&", vSq, makeLiteral(3));
|
|
3143
|
+
const isEq = makeBinary("===", term1, term2);
|
|
3144
|
+
mbaExpr = makeBinary("&", isEq, makeLiteral(1));
|
|
2829
3145
|
}
|
|
2830
3146
|
const decoyIdx = Math.abs(fnIndex) % 3;
|
|
2831
3147
|
const consequent = decoyIdent ? createSharedDecoyConsequent(decoyIdent, decoyIdx) : createDecoyConsequent(decoyIdx);
|
|
@@ -2841,6 +3157,7 @@ function createSotaMbaPredicate(seed, fnIndex = 0, paramNode, decoyIdent, isArro
|
|
|
2841
3157
|
alternate: null
|
|
2842
3158
|
};
|
|
2843
3159
|
}
|
|
3160
|
+
var MAX_COLD_GUARDS_PER_CHUNK = 12;
|
|
2844
3161
|
function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExemptNodes) {
|
|
2845
3162
|
const decoyIdent = "_d";
|
|
2846
3163
|
if (Array.isArray(ast.body)) {
|
|
@@ -2853,6 +3170,7 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
2853
3170
|
}
|
|
2854
3171
|
let guardedCount = 0;
|
|
2855
3172
|
function maybeInjectGuard(node) {
|
|
3173
|
+
if (guardedCount >= MAX_COLD_GUARDS_PER_CHUNK) return;
|
|
2856
3174
|
if (!coldFunctionNodes.has(node)) return;
|
|
2857
3175
|
if (!node.body || node.body.type !== "BlockStatement") return;
|
|
2858
3176
|
const firstParam = node.params?.[0];
|
|
@@ -3366,7 +3684,7 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
3366
3684
|
});
|
|
3367
3685
|
let virtualizedCount = 0;
|
|
3368
3686
|
for (const fn of candidates) {
|
|
3369
|
-
if (virtualizedCount >=
|
|
3687
|
+
if (virtualizedCount >= 5) break;
|
|
3370
3688
|
if (coldFunctionNodes && !coldFunctionNodes.has(fn)) {
|
|
3371
3689
|
continue;
|
|
3372
3690
|
}
|
|
@@ -3478,7 +3796,7 @@ function isAstAlreadyProtected(ast) {
|
|
|
3478
3796
|
}
|
|
3479
3797
|
function transformJavaScript(code, options = {}) {
|
|
3480
3798
|
const seed = options.seed ?? 2654435769;
|
|
3481
|
-
const minStringLength = options.minStringLength ?? 4;
|
|
3799
|
+
const minStringLength = options.minStringLength ?? options.config?.vault?.minStringLength ?? 4;
|
|
3482
3800
|
const isAggressive = options.aggressive ?? false;
|
|
3483
3801
|
if (!code || !code.trim()) {
|
|
3484
3802
|
return {
|
|
@@ -3517,7 +3835,7 @@ function transformJavaScript(code, options = {}) {
|
|
|
3517
3835
|
hotFunctionNodes,
|
|
3518
3836
|
hotExemptNodes,
|
|
3519
3837
|
serializedFunctionNodes
|
|
3520
|
-
} = analyzeAstHotPaths(ast);
|
|
3838
|
+
} = analyzeAstHotPaths(ast, options.config);
|
|
3521
3839
|
let virtualizedFunctionsCount = 0;
|
|
3522
3840
|
if (isAggressive) {
|
|
3523
3841
|
const vmRes = applyMicroVm(
|
|
@@ -3532,7 +3850,8 @@ function transformJavaScript(code, options = {}) {
|
|
|
3532
3850
|
const mangledSymbolsCount = applyPolymorphicMangler(
|
|
3533
3851
|
ast,
|
|
3534
3852
|
seed,
|
|
3535
|
-
serializedFunctionNodes
|
|
3853
|
+
serializedFunctionNodes,
|
|
3854
|
+
options.config
|
|
3536
3855
|
);
|
|
3537
3856
|
let encryptedStringsCount = 0;
|
|
3538
3857
|
let integrityToken = 0;
|
|
@@ -3543,7 +3862,8 @@ function transformJavaScript(code, options = {}) {
|
|
|
3543
3862
|
ast,
|
|
3544
3863
|
seed,
|
|
3545
3864
|
minStringLength,
|
|
3546
|
-
hotExemptNodes
|
|
3865
|
+
hotExemptNodes,
|
|
3866
|
+
options.config
|
|
3547
3867
|
);
|
|
3548
3868
|
encryptedStringsCount = saltedRes.encryptedStringsCount;
|
|
3549
3869
|
integrityToken = saltedRes.integrityToken;
|
|
@@ -3555,7 +3875,8 @@ function transformJavaScript(code, options = {}) {
|
|
|
3555
3875
|
hotExemptNodes,
|
|
3556
3876
|
void 0,
|
|
3557
3877
|
void 0,
|
|
3558
|
-
options.deterrentMode
|
|
3878
|
+
options.deterrentMode,
|
|
3879
|
+
options.config
|
|
3559
3880
|
);
|
|
3560
3881
|
encryptedStringsCount = vaultRes.encryptedStringsCount;
|
|
3561
3882
|
integrityToken = vaultRes.integrityToken;
|