@babel/plugin-codemod-optional-catch-binding

Remove unused catch bindings

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
39,446757Jul 31, 2021Sep 28, 2014Minified + gzip package size for @babel/plugin-codemod-optional-catch-binding in KB

Readme

@babel/plugin-codemod-optional-catch-binding

If the argument bound to the catch block is not referenced in the catch block, that argument and the catch binding is removed.

Examples

try {
  throw 0;
} catch (err) {
  console.log("it failed, but this code executes");
}

Is transformed to:

try {
  throw 0;
} catch {
  console.log("it failed, but this code executes");
}

Installation

npm install --save-dev @babel/plugin-codemod-optional-catch-binding

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["@babel/plugin-codemod-optional-catch-binding"]
}

Via CLI

babel --plugins @babel/plugin-codemod-optional-catch-binding script.js

Via Node API

require("@babel/core").transform("code", {
  plugins: ["@babel/plugin-codemod-optional-catch-binding"]
});

References

This codemod updates your source code in line with the following proposal:

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.