mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
update tslint
BinaryExpressionControlFlowReplacer refactoring
This commit is contained in:
+65
-6
@@ -1,5 +1,4 @@
|
||||
'use strict';
|
||||
import { NO_CUSTOM_NODES_PRESET } from '../../src/preset-options/NoCustomNodesPreset';
|
||||
|
||||
if (!(<any>global)._babelPolyfill) {
|
||||
require('babel-polyfill');
|
||||
@@ -11,18 +10,78 @@ if (!(<any>global)._babelPolyfill) {
|
||||
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
`
|
||||
(function(){
|
||||
var result = 1,
|
||||
term1 = 0,
|
||||
term2 = 1,
|
||||
i = 1;
|
||||
while(i < 10)
|
||||
{
|
||||
var test = 10;
|
||||
result = term1 + term2;
|
||||
console.log(result);
|
||||
term1 = term2;
|
||||
term2 = result;
|
||||
i++;
|
||||
}
|
||||
|
||||
console.log(test);
|
||||
|
||||
var test = function (test) {
|
||||
console.log(test);
|
||||
|
||||
if (true) {
|
||||
var test = 5
|
||||
}
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
console.log(test(1));
|
||||
|
||||
function test2 (abc) {
|
||||
function test1 () {
|
||||
console.log('inside', abc.item);
|
||||
}
|
||||
|
||||
console.log('тест', abc);
|
||||
|
||||
var abc = {};
|
||||
|
||||
return abc.item = 15, test1();
|
||||
};
|
||||
|
||||
var regexptest = /version\\/(\\d+)/i;
|
||||
console.log(regexptest);
|
||||
|
||||
test2(22);
|
||||
console.log(105.4);
|
||||
console.log(true, false);
|
||||
|
||||
var sA = 'shorthand1';
|
||||
var sB = 'shorthand2';
|
||||
|
||||
console.log({sA, sB});
|
||||
|
||||
try {
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
function foo () {
|
||||
return function () {
|
||||
var sum = 1 + 2;
|
||||
var sum = 3 + 4;
|
||||
var sum = 5 + 6;
|
||||
var sum = 8 - 6;
|
||||
var sum1 = 10 + 20;
|
||||
var sum2 = 20 + 30;
|
||||
var sum3 = 30 + 50;
|
||||
var sub = sum3 - sum2;
|
||||
|
||||
return sum1 + sub;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(foo()());
|
||||
})();
|
||||
`,
|
||||
{
|
||||
...NO_CUSTOM_NODES_PRESET,
|
||||
compact: false,
|
||||
controlFlowFlattening: true,
|
||||
disableConsoleOutput: false
|
||||
|
||||
@@ -63,6 +63,29 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertStructureToCode (structure: ESTree.Node[]): string', () => {
|
||||
let structure: ESTree.Node[],
|
||||
expectedCode: string;
|
||||
|
||||
beforeEach(() => {
|
||||
structure = [
|
||||
NodeMocks.getProgramNode([
|
||||
NodeMocks.getVariableDeclarationNode([
|
||||
NodeMocks.getVariableDeclaratorNode(
|
||||
NodeMocks.getIdentifierNode('abc'),
|
||||
NodeMocks.getLiteralNode('cde')
|
||||
)
|
||||
])
|
||||
])
|
||||
];
|
||||
expectedCode = 'var abc = \'cde\';';
|
||||
});
|
||||
|
||||
it('should convert `ESTree.Node[]` structure to source code', () => {
|
||||
assert.deepEqual(NodeUtils.convertStructureToCode(structure), expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getBlockStatementNodeByIndex (node: ESTree.Node, index: number = 0): ESTree.Node', () => {
|
||||
let blockStatementNode: ESTree.BlockStatement,
|
||||
expressionStatementNode1: ESTree.ExpressionStatement,
|
||||
|
||||
Reference in New Issue
Block a user