Added logic to skip variable declaration transformation

Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues
This commit is contained in:
sanex3339
2020-01-06 20:57:28 +03:00
parent a34fb4544f
commit 4dcff4eb4d
8 changed files with 152 additions and 9 deletions
+6 -5
View File
@@ -7,11 +7,12 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
`
function foo () {
var bar;
if (false)
bar = {baz: 1};
}
(function () {
var a, b;
({a, b} = {a: 1, b: 2});
console.log(a, b);
})();
`,
{
...NO_ADDITIONAL_NODES_PRESET,
@@ -605,4 +605,40 @@ describe('VariableDeclarationTransformer', () => {
assert.match(obfuscatedCode, objectRestRegExp);
});
});
describe('Variant #18: destructing assignment without declaration', () => {
const variablesDeclaration: RegExp = /var *a, *b, *_0x[a-f0-9]{4,6};/;
const destructingAssignmentRegExp: RegExp = /\({ *a, *b *} *= *{ *'a' *: *0x1, *'b' *: *0x2 *}\);/;
const identifierAssignmentRegExp: RegExp = /_0x[a-f0-9]{4,6} *= *0x3;/;
const variablesUsageRegExp: RegExp = /console\['log']\(a, *b, *_0x[a-f0-9]{4,6}\);/;
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/destructing-assignment-without-declaration.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET
}
).getObfuscatedCode();
});
it('match #1: should transform variables declaration', () => {
assert.match(obfuscatedCode, variablesDeclaration);
});
it('match #2: should transform destructing assignment without declaration', () => {
assert.match(obfuscatedCode, destructingAssignmentRegExp);
});
it('match #3: should transform identifier assignment', () => {
assert.match(obfuscatedCode, identifierAssignmentRegExp);
});
it('match #4: should transform variables usage', () => {
assert.match(obfuscatedCode, variablesUsageRegExp);
});
});
});
@@ -0,0 +1,7 @@
(function () {
var a, b, c;
({a, b} = {a: 1, b: 2});
c = 3;
console.log(a, b, c);
})();