sanex3339
2018-07-22 14:09:16 +03:00
parent 836f665cab
commit 0296b13616
7 changed files with 41 additions and 19 deletions
+9 -3
View File
@@ -6,9 +6,15 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
`
function foo (data) {
return ({data}) => data + 1;
}
function foo (data, options) {
function bar ({data, ...rest}) {
function baz ({options}) {
return data + options + rest;
}
}
return data;
}
`,
{
...NO_ADDITIONAL_NODES_PRESET,
@@ -114,8 +114,9 @@ describe('FunctionTransformer', () => {
});
describe('Variant #3: correct transformation when parent scope identifier conflicts with current scope object pattern identifier', () => {
const functionObjectPatternParameterRegExp: RegExp = /function _0x[a-f0-9]{4,6} *\({data, *\.\.\._0x[a-f0-9]{4,6}}\) *{/;
const returnRegExp1: RegExp = /return data *\+ *_0x[a-f0-9]{4,6};/;
const functionObjectPatternParameterRegExp1: RegExp = /function _0x[a-f0-9]{4,6} *\({data, *\.\.\._0x[a-f0-9]{4,6}}\) *{/;
const functionObjectPatternParameterRegExp2: RegExp = /function _0x[a-f0-9]{4,6} *\({options}\) *{/;
const returnRegExp1: RegExp = /return data *\+ *options *\+ *_0x[a-f0-9]{4,6};/;
const returnRegExp2: RegExp = /return _0x[a-f0-9]{4,6};/;
let obfuscatedCode: string;
@@ -133,14 +134,18 @@ describe('FunctionTransformer', () => {
});
it('match #1: should transform function parameter object pattern rest identifier', () => {
assert.match(obfuscatedCode, functionObjectPatternParameterRegExp);
assert.match(obfuscatedCode, functionObjectPatternParameterRegExp1);
});
it('match #2: should transform identifier in `ReturnStatement` of inner function', () => {
it('match #2: should transform function parameter object pattern rest identifier', () => {
assert.match(obfuscatedCode, functionObjectPatternParameterRegExp2);
});
it('match #3: should transform identifier in `ReturnStatement` of inner function', () => {
assert.match(obfuscatedCode, returnRegExp1);
});
it('match #2: should transform identifier in `ReturnStatement` of outer function', () => {
it('match #4: should transform identifier in `ReturnStatement` of outer function', () => {
assert.match(obfuscatedCode, returnRegExp2);
});
});
@@ -1,7 +1,9 @@
(function(){
function foo (data) {
function foo (data, options) {
function bar ({data, ...rest}) {
return data + rest;
function baz ({options}) {
return data + options + rest;
}
}
return data;