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

optional-catch-binding - 图1info

This plugin is included in @babel/preset-env, in ES2019

Examples

JavaScript

  1. try {
  2. throw 0;
  3. } catch {
  4. doSomethingWhichDoesNotCareAboutTheValueThrown();
  5. }

JavaScript

  1. try {
  2. throw 0;
  3. } catch {
  4. doSomethingWhichDoesNotCareAboutTheValueThrown();
  5. } finally {
  6. doSomeCleanup();
  7. }

Installation

  • npm
  • Yarn
  • pnpm
  1. npm install --save-dev @babel/plugin-transform-optional-catch-binding
  1. yarn add --dev @babel/plugin-transform-optional-catch-binding
  1. pnpm add --save-dev @babel/plugin-transform-optional-catch-binding

Usage

babel.config.json

  1. {
  2. "plugins": ["@babel/plugin-transform-optional-catch-binding"]
  3. }

Via CLI

Shell

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

Via Node API

JavaScript

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

References