Added logic and tests to partial simplify consequent only if statements with prohibited nodes

This commit is contained in:
sanex3339
2020-07-01 01:34:18 +03:00
parent 8ab44490c2
commit edba004651
9 changed files with 206 additions and 94 deletions
@@ -381,8 +381,7 @@ describe('IfStatementSimplifyTransformer', () => {
const regExp: RegExp = new RegExp(
'if *\\(!!\\[]\\) *{ *' +
'const _0x([a-f0-9]){4,6} *= *baz\\(\\); *' +
'bark\\(\\); *' +
'return hawk\\(\\);' +
'bark\\(\\), *hawk\\(\\);' +
'}'
);
@@ -401,7 +400,37 @@ describe('IfStatementSimplifyTransformer', () => {
).getObfuscatedCode();
});
it('should not simplify if statement', () => {
it('should simplify if statement', () => {
assert.match(obfuscatedCode, regExp);
});
});
});
describe('With `ReturnStatement`', () => {
describe('Variant #1: multiple statements', () => {
const regExp: RegExp = new RegExp(
'if *\\(!!\\[]\\) *{ *' +
'const _0x([a-f0-9]){4,6} *= *baz\\(\\); *' +
'return bark\\(\\), *hawk\\(\\);' +
'}'
);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/partial-consequent-only-return-multiple-statements.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
minify: true
}
).getObfuscatedCode();
});
it('should simplify if statement', () => {
assert.match(obfuscatedCode, regExp);
});
});
@@ -3,7 +3,6 @@ function foo () {
const bar = baz();
bark();
return hawk();
hawk();
}
}
@@ -0,0 +1,9 @@
function foo () {
if (true) {
const bar = baz();
bark();
return hawk();
}
}