A Babel transform removing effect-less expression statements.
The following:
a + b || Math.abs(c);
b - i++;
is transformed to:
b - i++;
The transform is fairly smart deciding what can be removed and what needs to be left, but you can help it with some hints.
Member expressions:
a.b['c'];
cannot be removed by default because a property getter may do something more than just return a value:
node.offsetHeight; // Triggers a browser reflow.
Pass a pureMembers
regex to mark some member chains as side-effects free:
['transform-remove-pure-exps': {pureMembers: /^a\.b\.c$/}]
By default a list of built-in functions, such as Object.is()
and Math.abs()
is assumed to be side-effects free. 1 You can take control of
this assumption by passing a custom "pure callees" regex:
['transform-remove-pure-exps': {pureCallees: /^JSON\.parse$/}]
npm install babel-cli babel-plugin-transform-remove-pure-exps