Skip to main content

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

note

Syntax only

It's unlikely you want to use this plugin directly as it only enables Babel to parse this syntax. Instead, use plugin-transform-optional-catch-binding to both parse and transform this syntax.

Example

Syntax

JavaScript
try {
throw 0;
} catch {
doSomethingWhichDoesNotCareAboutTheValueThrown();
console.log("Yay, code executes!");
}

Installation

npm install --save-dev @babel/plugin-syntax-optional-catch-binding

Usage

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

Via CLI

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

Via Node API

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

References