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?.()