babel-plugin-extensible-destructuring

raw JSON →
4.3.1 verified Sat Apr 25 auth: no javascript

Babel plugin that transforms destructuring assignments to calls to a runtime function, enabling custom behavior like Immutable.js support or safe access (avoiding undefined). Version 4.3.1 works with Babel 6 and 7 (using full plugin name for Babel 7). It requires the separate runtime package `extensible-runtime` and offers three implementations: normal (ES6 compatible), immutable (for Immutable.js Maps/Lists), and safe (default, prevents undefined returns). Provides opt-in/opt-out per-file modes for gradual adoption.

error Error: Cannot find module 'extensible-runtime'
cause Runtime package not installed.
fix
npm install --save extensible-runtime
error ReferenceError: __extensible_get__ is not defined
cause Missing runtime import or Babel not transforming correctly.
fix
Ensure both plugin and runtime are installed and Babel is configured correctly.
error TypeError: Cannot destructure property 'x' of 'undefined' or 'null'
cause Using safe mode but the value is null, not undefined.
fix
Safe mode only prevents undefined; for null, use a default value or check beforehand.
breaking Babel 7 requires full plugin name 'babel-plugin-extensible-destructuring' instead of 'extensible-destructuring'.
fix Use 'babel-plugin-extensible-destructuring' in plugins array for Babel 7.
gotcha You must install both the plugin and runtime package: 'extensible-runtime' is required at runtime.
fix Run npm install --save extensible-runtime.
gotcha Opt-in mode is default; destructuring will not be transformed unless 'use extensible' directive is at top of file.
fix Add 'use extensible'; at the beginning of each file, or set mode to 'optout' in options.
npm install babel-plugin-extensible-destructuring
yarn add babel-plugin-extensible-destructuring
pnpm add babel-plugin-extensible-destructuring

Demonstrates setup with Babel 7 and immutable mode destructuring of an Immutable.js Map.

// Install dependencies
// npm install --save-dev babel-plugin-extensible-destructuring
// npm install --save extensible-runtime

// .babelrc
{
  "presets": ["@babel/preset-env"],
  "plugins": ["babel-plugin-extensible-destructuring"]
}

// src/index.js (opt-in mode by default)
'use extensible';
import { fromJS } from 'immutable';
const map = fromJS({ author: { name: { first: "John", last: "Doe" }, birthdate: "10-10-2010" } });
const { author: { name: { first, last }, birthdate } } = map;
console.log(first, last, birthdate); // John Doe 10-10-2010