minify
minify copied to clipboard
Dead code elimination can eliminate side-effecting code
Copying from https://github.com/babel/minify/issues/930#issuecomment-439339599 to make sure it gets tracked:
'use strict';
function foo() {
if (bar(), true) {
baz();
} else {
NOT_REACHABLE();
}
}
with dead code and simplify gets transformed to
"use strict";function foo(){baz()}
which is wrong - the call to bar()
can have side effects.
I expect the bug is here: this code assumes that anything which .evaluate()
s confidently can be safely replaced with its evaluation, but that's not true - you can have side effects even for things you're confident about. Compare the more complex code in the path for IfStatement
, which was added in #386 to fix #385. I imagine the fix is basically copying that code to the ConditionalExpression
case; probably a good first issue for someone.
(This issue is pretty much the same as https://github.com/babel/minify/issues/385#issuecomment-274338700, just with slightly different input conditions.)