minify
minify copied to clipboard
JS: simplify static boolean expressions
Example of code which is not optimized:
if (true) {
console.log("true")
}
if (false) {
console.log("false")
}
It is minified into !0&&console.log("true"),!1&&console.log("false") while it would be better to pre-evaluate the expression and just minify it into console.log("true") (of course only static boolean values).
Thanks!
It may seem like an easy optimization, but it gets tricky when there are variable declarations (var, function) within the if scope, e.g.:
if (false) {
function f() {
console.log('executing f');
}
}
f() // should log the above message
This is also true for removing all code after a return, throw, break, or continue statement.
Let me take a stab at this next week!