If the argument bound to the catch block is not referenced in the catch block, that argument and the catch binding is removed.
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");
}
npm install --save-dev @babel/plugin-codemod-optional-catch-binding
.babelrc
(Recommended).babelrc
{
"plugins": ["@babel/plugin-codemod-optional-catch-binding"]
}
babel --plugins @babel/plugin-codemod-optional-catch-binding script.js
require("@babel/core").transform("code", {
plugins: ["@babel/plugin-codemod-optional-catch-binding"]
});
This codemod updates your source code in line with the following proposal: