Minify guarded expressions

输入

!x && foo();
alert(0 && new Foo());

输出

x || foo();
alert(0);

安装

npm install babel-plugin-minify-guarded-expressions

使用

.babelrc

{
  "plugins": ["minify-guarded-expressions"]
}

通过 CLI

babel --plugins minify-guarded-expressions script.js

通过 Node API

require("babel-core").transform("code", {
  plugins: ["minify-guarded-expressions"]
});