Skip to content

Incorrect simplification for nested if #864

@wfwf1997

Description

@wfwf1997

After fixing simplify in 2.10.2, the simplification for nested if statements seems to become wrong.

Original Code

function foo () {
  if (bar) {
    if (baz) {
      const a = aa()
    }
  } else {
    bb()
  }
}

Expected Behavior

It should be and is translated in 2.10.1 to:

function foo () {
  if (bar) {
    if (baz) {
      const a = aa();
    }
  } else
    bb();
}

Current Behavior

But it is translated in 2.10.2 to:

function foo () {
  if (bar)
    if (baz) {
      const a = aa();
    }
  else
    bb();
}

The missing braces in the then branch of the first if makes the else branch matches to the second if. As a result, the program goes wrong.

And interestingly, if I use ES5’s var to declare the variable, everything’s good. The let and const would result in a bad code.

Steps to Reproduce

Just try above code with default configuration.

Your Environment

  • Obfuscator version used: 2.10.2
  • Node version used: 12.16.1

Minimal working example that will help to reproduce issue

See above.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions