mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
More correct fix of https://github.com/javascript-obfuscator/javascript-obfuscator/issues/297
This commit is contained in:
+9
-3
@@ -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,
|
||||
|
||||
+10
-5
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
+4
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user