UNPKG

vanzy-protect

Version:

Epic Obfuscator Yeahhh

49 lines (48 loc) 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.anonFunction = void 0; const cfg_1 = require("../config/cfg"); const warn_1 = require("../log/warn"); const comment_1 = require("../obfuscate/comment"); const obfuscateName_1 = require("../obfuscate/obfuscateName"); const arrayPattern_1 = require("./arrayPattern"); const assignmentExpression_1 = require("./assignmentExpression"); const objectPattern_1 = require("./objectPattern"); const rightExpression_1 = require("./rightExpression"); const traverse_1 = require("./traverse"); function anonFunction(expr, data = '') { if (expr.async) { data += 'async '; data += (0, comment_1.comment)(1); } data += 'function('; expr.params.forEach((i, n) => { if (i.type === 'Identifier') { var pname = i.name; if ((0, cfg_1.cfg)().transforms.obfuscateNames) pname = (0, obfuscateName_1.obfuscateName)(pname); data += pname + (0, comment_1.comment)(3) + ',' + (0, comment_1.comment)(3); } else if (i.type === 'AssignmentPattern') { data += (0, assignmentExpression_1.assignmentExpression)({ operator: '=', ...i }) + (0, comment_1.comment)(3) + ',' + (0, comment_1.comment)(3); } else if (i.type === 'ObjectPattern') { data += (0, objectPattern_1.objectPattern)(i) + (0, comment_1.comment)(3) + ',' + (0, comment_1.comment)(3); } else if (i.type === 'ArrayPattern') { data += (0, arrayPattern_1.arrayPattern)(i) + (0, comment_1.comment)(3) + ',' + (0, comment_1.comment)(3); } else (0, warn_1.warn)(`Unknown expression type in anonFunction(e) => e.params[${n}] : ${i.type}`); }); data += '){'; if (expr.body.type === 'BlockStatement') { data += (0, traverse_1.traverse)(expr.body.body) + ';'; } else { data += 'return ' + (0, comment_1.comment)(2) + '(' + (0, rightExpression_1.rightExpression)(expr.body) + ');'; } data += (0, comment_1.comment)(3) + '}' + (0, comment_1.comment)(1); return data; } exports.anonFunction = anonFunction;