babel-plugin-transform-remove-undefined

This removes rvals that are equivalent to undefined wherever possible

MIT 81 个版本
安装
npm install babel-plugin-transform-remove-undefined
yarn add babel-plugin-transform-remove-undefined
pnpm add babel-plugin-transform-remove-undefined
bun add babel-plugin-transform-remove-undefined
README

babel-plugin-transform-remove-undefined

For variable assignments, this removes rvals that evaluate to undefined (vars in functions only). For functions, this removes return arguments that evaluate to undefined.

Example

In

let a = void 0;
function foo() {
  var b = undefined;
  return undefined;
}

Out

let a;
function foo() {
  var b;
  return;
}

Installation

npm install babel-plugin-transform-remove-undefined --save-dev

Usage

.babelrc

{
  "plugins": ["babel-plugin-transform-remove-undefined"]
}

Via CLI

babel --plugins babel-plugin-transform-remove-undefined script.js

Via Node API

require("@babel/core").transform("code", {
  plugins: ["babel-plugin-transform-remove-undefined"]
});

Options

  • tdz - Detect usages before declaration/initialization in let/const(throws) and var(void 0)
版本列表
0.5.0-alpha.9 2018-09-23
0.5.0 2018-09-24
0.4.3 2018-05-14
0.4.2 2018-05-14
0.4.1 2018-05-03
0.4.0 2018-04-08
0.3.0 2018-01-31
0.2.0 2017-08-14
0.1.2 2017-06-13
0.1.1 2017-05-22
0.1.0 2017-05-22
0.0.5 2017-02-08
0.0.4 2017-01-17
0.0.3 2016-11-18
0.0.1 2016-11-08