Added tests for prohibited single FunctionDeclaration

This commit is contained in:
sanex3339
2020-07-06 16:30:48 +03:00
parent 3a3d350d96
commit 0467620a08
4 changed files with 38 additions and 2 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
@@ -780,6 +780,35 @@ describe('IfStatementSimplifyTransformer', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('Variant #2: `FunctionDeclaration` as prohibited single statement', () => {
const regExp: RegExp = new RegExp(
'if *\\(!!\\[]\\) *{ *' +
'function _0x([a-f0-9]){4,6} *\\(\\) *{} *' +
'} *else *{ *' +
'function _0x([a-f0-9]){4,6} *\\(\\) *{} *' +
'}'
);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/function-declaration-as-prohibited-single-statement.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
minify: true
}
).getObfuscatedCode();
});
it('should not simplify if statement', () => {
assert.match(obfuscatedCode, regExp);
});
});
});
});
});
@@ -0,0 +1,7 @@
function foo() {
if (true) {
function foo() {}
} else {
function bar() {}
}
}