babel-plugin-transform-remove-pure-exps
v0.0.1
Published
Babel transform to remove no-op expression statements.
Downloads
5
Maintainers
Readme
babel-remove-pure-exps
A Babel transform removing effect-less expression statements.
Example
The following:
a + b || Math.abs(c);
b - i++;
is transformed to:
b - i++;
Options
The transform is fairly smart deciding what can be removed and what needs to be left, but you can help it with some hints.
pureMembers
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$/}]
pureCallees
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$/}]
Installation
npm install babel-cli babel-plugin-transform-remove-pure-exps