butternut
butternut copied to clipboard
Remove side-effect free statements
Input:
function foo() {
a; 5; 6;
}
expected:
function foo() {}
Thinking about this, the low-hanging fruit would be any ExpressionStatement nodes whose expression is anything except a CallExpression, NewExpression, AssignmentExpression or UpdateExpression... does that sound about right?
There's also assignments to unused variables etc, but that's a little trickier, wasn't planning to tackle that just yet 😀
Also,
-
o.foo
- getters -
instanceof
-Symbol.hasInstance
- The tricky ones are
a + ""
a.toString is called. So all of arithmetic operators are to be treated as impure.
Edit:
-
obj.valueOf