mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed wrong arrow function block scope detection
This commit is contained in:
+2
-9
@@ -6,15 +6,8 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo
|
||||
|
||||
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
`
|
||||
function foo (data, options) {
|
||||
function bar ({data, ...rest}) {
|
||||
function baz ({options}) {
|
||||
return data + options + rest;
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
const foo = 1;
|
||||
[].map(foo=>1).map(bar=>[foo]);
|
||||
`,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
|
||||
+56
@@ -436,4 +436,60 @@ describe('FunctionTransformer', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('correct block scope detection of arrow function expression', () => {
|
||||
describe('Variant #1: block statement body', () => {
|
||||
const regExpMatch: string = `` +
|
||||
`\\[]` +
|
||||
`\\['map']\\(_0x[a-f0-9]{4,6} *=> *\\{ *return 0x1; *\\}\\)` +
|
||||
`\\['map']\\(_0x[a-f0-9]{4,6} *=> *\\[foo]\\);` +
|
||||
``;
|
||||
const regExp: RegExp = new RegExp(regExpMatch);
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/arrow-function-with-expression-body-block-scope-detection-1.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should transform identifiers in arrow function expression body', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #1: expression statement body', () => {
|
||||
const regExpMatch: string = `` +
|
||||
`\\[]` +
|
||||
`\\['map']\\(_0x[a-f0-9]{4,6} *=> *0x1\\)` +
|
||||
`\\['map']\\(_0x[a-f0-9]{4,6} *=> *\\[foo]\\);` +
|
||||
``;
|
||||
const regExp: RegExp = new RegExp(regExpMatch);
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/arrow-function-with-expression-body-block-scope-detection-2.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should transform identifiers in arrow function expression body', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
const foo = 1;
|
||||
[]
|
||||
.map(foo => {
|
||||
return 1;
|
||||
})
|
||||
.map(bar => [foo]);
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
const foo = 1;
|
||||
[]
|
||||
.map(foo => 1)
|
||||
.map(bar => [foo]);
|
||||
Reference in New Issue
Block a user