babel-plugin-transform-undefined-to-void

This plugin transforms undefined into void 0 which returns undefined regardless of if it's been reassigned.

Example

In

  1. foo === undefined;

Out

  1. foo === void 0;

Installation

  1. npm install babel-plugin-transform-undefined-to-void --save-dev

Usage

.babelrc

  1. {
  2. "plugins": ["transform-undefined-to-void"]
  3. }

Via CLI

  1. babel --plugins transform-undefined-to-void script.js

Via Node API

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