@babel/plugin-proposal-nullish-coalescing-operator

Example

In

  1. var foo = object.foo ?? "default";

Out

  1. var _object$foo;
  2. var foo = (_object$foo = object.foo) !== null && _object$foo !== void 0 ? _object$foo : "default";

NOTE: We cannot use != null here because document.all == null anddocument.all has been deemed not "nullish".

Installation

  1. npm install --save-dev @babel/plugin-proposal-nullish-coalescing-operator

Usage

  1. {
  2. "plugins": ["@babel/plugin-proposal-nullish-coalescing-operator"]
  3. }

Via CLI

  1. babel --plugins @babel/plugin-proposal-nullish-coalescing-operator script.js

Via Node API

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

Options

loose

boolean, defaults to false.

When true, this transform will pretend document.all does not exist,and perform loose equality checks with null instead of strict equality checksagainst both null and undefined.

Example

In

  1. var foo = object.foo ?? "default";

Out

  1. var _object$foo;
  2. var foo = (_object$foo = object.foo) != null ? _object$foo : "default";

You can read more about configuring plugin options here

References