babel-plugin-transform-remove-undefined
For functions, this removes return arguments that evaluate to undefined
.
Example
In
JavaScript
let a = void 0;
function foo() {
var b = undefined;
return undefined;
}
Out
JavaScript
let a;
function foo() {
var b;
return;
}
Installation
- npm
- Yarn
- pnpm
npm install babel-plugin-transform-remove-undefined --save-dev
yarn add babel-plugin-transform-remove-undefined --dev
pnpm add babel-plugin-transform-remove-undefined --save-dev
Usage
With a configuration file (Recommended)
babel.config.json
{
"plugins": ["babel-plugin-transform-remove-undefined"]
}
Via CLI
Shell
babel --plugins babel-plugin-transform-remove-undefined script.js
Via Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["babel-plugin-transform-remove-undefined"],
});
Options
tdz
- Detect usages before declaration/initialization in let/const(throws) and var(void 0)
tip
You can read more about configuring plugin options here