Skip to content

wrwrwr/babel-remove-pure-exps

Repository files navigation

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$/}]
1. See [side-effects-safe][] for a full list and some caveats.

Installation

npm install babel-cli babel-plugin-transform-remove-pure-exps

About

Babel transform to remove no-op expression statements.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published