Logan Smyth 90566103a6 v7.0.0-beta.49 6 years ago
..
src 2afe9404fe Use Object Spread Syntax (#7777) 6 years ago
test 8659e1a88c Remove old expected.{js,json} files (#7187) 6 years ago
.npmignore 8597219ce5 move to codemods folder [skip ci] 6 years ago
README.md cee9ae48e0 [skip ci] removed shorthand usage of official babel scoped presets & plugins from README.md's (#6820) 6 years ago
package.json 90566103a6 v7.0.0-beta.49 6 years ago

README.md

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