Skip to content

Object destructuring assignment does not work for variables initialized previously #361

Description

@skiritsis

Expected Behavior

Variable assignment without declaration when using object destructuring should work.

According to destructuring assignment in MDN

{a, b} = {a: 1, b: 2} is not valid stand-alone syntax, as the {a, b} on the left-hand side is considered a block and not an object literal.

However, ({a, b} = {a: 1, b: 2}) is valid, as is var {a, b} = {a: 1, b: 2}

Current Behavior

Currently the variable name on left-hand side part of the statement is not being changed by the obfuscator while the initial variable declaration is.

This is the obfuscator output for the function below:

functiontest(_0x4bb6ab){
	let_0x44c2ed=undefined;if(!![]){
		({
			a // <- notice how a is not obfuscated
		}=_0x4bb6ab);
	}console[_0x1b95('0x0')](_0x44c2ed);
}

Steps to Reproduce (for bugs)

  1. Simply run the obfuscator for the code example given below

Your Environment

  • Obfuscator version used: 0.18.1
  • Node version used: 8.2.1 (although it does matter)

Stack trace

Minimal working example that will help to reproduce issue

function test(obj) {
    let a = undefined;
    if(true){
        ({a} = obj);
    }
    console.log(a);
    // this should print 1, running the same example after the obfuscation prints undefined
}

test({a: 1});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions