Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

babel-plugin-transform-nullish-optional-chaining

weszane114MIT0.0.1TypeScript support: included

A powerful Babel plugin that transforms verbose null/undefined checking patterns into modern optional chaining syntax

babel-plugin, optional-chaining, typescript, plugin, babel, nullish-coalescing

readme

babel-plugin-transform-nullish-optional-chaining

A powerful Babel plugin that automatically transforms verbose null/undefined checking patterns into modern optional chaining syntax, making your code cleaner and more readable.

✨ Features

  • 🔄 Automatic Transformation: Converts ternary expressions with nullish checks to optional chaining
  • 🎯 Smart Pattern Recognition: Handles complex logical expressions and nested conditions
  • 🚀 Performance Optimized: Minimal overhead during transformation
  • 📦 Zero Dependencies: Lightweight plugin with no external runtime dependencies
  • 🛡️ Type Safe: Full TypeScript support with proper type definitions
  • 🔧 Configurable: Works seamlessly with your existing Babel configuration

📦 Installation

· Install the plugin using npm:

npm install --save-dev babel-plugin-transform-nullish-optional-chaining

Example

Simple null case:

null == a ? void 0 : a.id

// to
a?.id

Nested null case

null == a ? void 0 : null == a.b ? void 0 : a.b.c
// to
a?.b?.c

Nested null case with call and member

null == a().b ? void 0 : a().b()

// to

a().b?.()