跳到主要内容

@babel/plugin-transform-optional-catch-binding

信息

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 install --save-dev @babel/plugin-transform-optional-catch-binding

Usage

babel.config.json
{
"plugins": ["@babel/plugin-transform-optional-catch-binding"]
}

Via CLI

Shell
babel --plugins @babel/plugin-transform-optional-catch-binding script.js

Via Node API

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

References