Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object extraction fails with const #106

Open
j4k0xb opened this issue Jul 15, 2023 · 3 comments
Open

object extraction fails with const #106

j4k0xb opened this issue Jul 15, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@j4k0xb
Copy link

j4k0xb commented Jul 15, 2023

Describe the bug:

object extraction of a const variable errors at runtime

Config and Small code sample

Config:

{
  compact: true,
  identifierGenerator: 'randomized',
  objectExtraction: true,
  target: 'browser',
}

Code:

const obj = {prop: 0};
obj.prop = 1;
console.log(obj.prop);

Expected behavior

The program should output 1

Actual behavior

TypeError: Assignment to constant variable.

obfuscated code:

const obj_prop=0;!(obj_prop=1,console['log'](obj_prop))

Additional context

an easy fix would probably be to convert the declaration to let or var

@j4k0xb j4k0xb added the bug Something isn't working label Jul 15, 2023
@j4k0xb j4k0xb changed the title Destructuring assignment error object extraction fails with const Jul 15, 2023
@MichaelXF
Copy link
Owner

Great find, will fix this for next release.

@j4k0xb
Copy link
Author

j4k0xb commented Sep 14, 2023

just found an edge case: const can only be safely converted to let instead of var because of closures:

for (let i = 0; i < 3; i++) {
  const obj = { prop: i };

  setTimeout(() => {
    console.log(obj.prop); // outputs 0, 1, 2
  }, 100);
}

after obfuscation: 2, 2, 2

@MichaelXF
Copy link
Owner

I will get to work on this

@MichaelXF MichaelXF reopened this Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants