跳到主要内容

babel-plugin-minify-guarded-expressions

In

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

Out

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

Installation

npm install babel-plugin-minify-guarded-expressions --save-dev

Usage

babel.config.json
{
"plugins": ["minify-guarded-expressions"]
}

Via CLI

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

Via Node API

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