babel/codemods/babel-plugin-codemod-optional-catch-binding
Daniel Tschinder b32d271fee
Migrate some duplicate binding tests to traverse (#9532)
* Migrate try-catch duplicate error

* Remove exception for functions and let in the same scope

* Migrate duplicate bindings tests to traverse

* Add test for subscope and let/const

* Add more test cases
2019-02-19 21:25:49 -08:00
..
2018-04-23 21:44:27 -04:00
2017-09-19 16:04:11 -04:00

@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

.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: