Skip to content
New issue

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

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

Already on GitHub? # to your account

Accessing property of object should be considered as side effect-able expression. #725

Closed
hyp3rflow opened this issue Jul 9, 2024 · 3 comments

Comments

@hyp3rflow
Copy link

If statement and its body should not be removed by minifier because it has obvious side effect.

const b = {
  get c() {
    console.log("hi");
  }
};

if (true){
  const d = b.c; // this makes side-effect ("hi")
}

this minifies into:

const b = {
  get c() {
    console.log("hi");
  }
};
@tdewolff
Copy link
Owner

Nice one, would simply const d = e never be a side-effect, or could e be some type that acts on its access?

@tdewolff
Copy link
Owner

I believe that simply and only using a variable in an expression is already considered a side-effect. I would be happy to hear otherwise because I don't know how that could cause a side-effect. Is there a function in a class that is called each time a variable is used?

Anyways, the bug you stated was fixed, thank you!

@hyp3rflow
Copy link
Author

well, I'm not confident on enumerating cases that accessing simple variable can make side-effect, but with with statement it could be possible like below.

with ({ get a() { console.log("hi") } }) {
  a; // console.log occurs!
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants