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

7.2.1-26 • Public • Published

@gerhobbelt/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 @gerhobbelt/babel-plugin-codemod-optional-catch-binding

Usage

Via .babelrc (Recommended)

.babelrc

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

Via CLI

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

Via Node API

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

References

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

Package Sidebar

Install

npm i @gerhobbelt/babel-plugin-codemod-optional-catch-binding

Weekly Downloads

2

Version

7.2.1-26

License

MIT

Unpacked Size

3.52 kB

Total Files

4

Last publish

Collaborators

  • gerhobbelt