babel-plugin-transform-remove-undefined

For functions, this removes return arguments that evaluate to undefined.

Example

In

  1. let a = void 0;
  2. function foo() {
  3. var b = undefined;
  4. return undefined;
  5. }

Out

  1. let a;
  2. function foo() {
  3. var b;
  4. return;
  5. }

Installation

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

Usage

  1. {
  2. "plugins": ["babel-plugin-transform-remove-undefined"]
  3. }

Via CLI

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

Via Node API

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

Options

  • tdz - Detect usages before declaration/initialization in let/const(throws) and var(void 0)

You can read more about configuring plugin options here