3 ms·
Not always, most do tricks like `!0` for `true` and `a && b` instead of `if (a) b`.
by prezjordan 11y ago
Not always, most do tricks like `!0` for `true` and `a && b` instead of `if (a) b`.
- userbinator 11y agoIMHO that's going into optimiser territory, and perhaps the reason why these minifier bugs exist - the minifier writers need to be very sure of the semantics of the language before attempting to rewrite code to have the same behaviour, and JS/ECMAscript semantics are not trivial especially w.r.t the (highly) dynamic type system as the example shows. Even renaming things is not as trivial as it seems because the names can themselves be dynamic, e.g. a.somefield vs a['s' + 'ome' + 'field']. (I'm not a JS developer so I might've missed a few other things, but minifying JS is definitely a much harder problem than doing it with something like C.)
- EGreg 11y agojust one nitpick on your comment - minifiers do not replace property names, only variable names in JS
- comex 11y agoClosure Compiler does rewrite property names in advanced mode.
- Arnavion 11y agoUglifyJS also rewrites property names if you tell it to. It's conservative so it only replaces the names you explicitly tell it to rename. Recently it gained the ability to let you give a regex, so if you have a convention of always prefixing private rename-safe properties with an underscore, you can now have those renamed.