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
Add "default pure" configuration option #1443
Comments
I think a good name for this would be edit: I checked that some of this is already implemented here. What needs to be added is a list of globals whose calls (and |
I don't know if it's a good fit, but maybe you could use the globals package and tie it to the specified environment. I guess the question then would be how you pass the environment - maybe |
I still want to do this, but it will be technically incorrect. People can re-assign Even removing things like But on the other hand, only null and undefined are assumed to be "== null", which is also technically incorrect, and in some niche places property access is considered to be pure, which could be overridden by effectful getters. On using the |
Great to hear! I think that very, very few people re-assign As long as it's a feature I'm happy :) |
Everything in |
It's not like it would add any more code. It's important to make sure that something that would crash before minify will also crash after minify, but if "process" is found as a global variable access in some bundle, it's probably a remnant of some isomorphic code, and likewise for "window" in a node environment. Making the option more specific, and letting you choose specific environments could be cool for the future, IE we could assume that the typeof |
It looks like I completely forgor about |
Bug report or Feature request?
Feature request
It would be great to be able to configure that certain global functions will always be pure, such as WeakMap, Map, Set, etc.
When having a very large library and relying on tree-shaking so that people who only use a little of it only get a little in their output, it's a continuous hunt of adding pure comments to side-effects.
It's quite easy to track down where to add a pure comment for most code, but there are always a random 50 calls left to for example
new Map
that are hard to find the culprit for.I think very very few people have a redefined Map function with side-effects so it would make things a lot simpler to just be able to say that certain functions are always pure.
Version (complete output of
terser -V
or specific git commit)5.19.4
Complete CLI command or
minify()
options usedhttps://try.terser.org/
terser
inputterser
output or errorExpected result
Terser config:
Output code:
The text was updated successfully, but these errors were encountered: