mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Added logic to skip variable declaration transformation
Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues
This commit is contained in:
+6
-5
@@ -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,
|
||||
|
||||
+36
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
(function () {
|
||||
var a, b, c;
|
||||
({a, b} = {a: 1, b: 2});
|
||||
c = 3;
|
||||
|
||||
console.log(a, b, c);
|
||||
})();
|
||||
Reference in New Issue
Block a user