@babel/plugin-proposal-optional-catch-binding
NOTE: This plugin is included in
@babel/preset-env
, in ES2019
Examples
JavaScript
try {
throw 0;
} catch {
doSomethingWhichDoesNotCareAboutTheValueThrown();
}
JavaScript
try {
throw 0;
} catch {
doSomethingWhichDoesNotCareAboutTheValueThrown();
} finally {
doSomeCleanup();
}
Installation
- npm
- Yarn
npm install --save-dev @babel/plugin-proposal-optional-catch-binding
yarn add --dev @babel/plugin-proposal-optional-catch-binding
Usage
With a configuration file (Recommended)
babel.config.json
{
"plugins": ["@babel/plugin-proposal-optional-catch-binding"]
}
Via CLI
Shell
babel --plugins @babel/plugin-proposal-optional-catch-binding script.js
Via Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-optional-catch-binding"],
});