or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-babel--plugin-syntax-optional-catch-binding

A Babel syntax plugin that enables parsing of optional catch bindings in JavaScript try/catch blocks

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@babel/plugin-syntax-optional-catch-binding@7.8.x

To install, run

npx @tessl/cli install tessl/npm-babel--plugin-syntax-optional-catch-binding@7.8.0

index.mddocs/

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

@babel/plugin-syntax-optional-catch-binding is a Babel syntax plugin that enables parsing of optional catch bindings in JavaScript try/catch blocks. This allows catch blocks to omit the error parameter when it's not needed, following the ECMAScript Optional Catch Binding proposal.

Package Information

  • Package Name: @babel/plugin-syntax-optional-catch-binding
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install --save-dev @babel/plugin-syntax-optional-catch-binding

Core Imports

The plugin is used through Babel's configuration system, not imported directly in application code. When used programmatically:

// Direct import/require (for programmatic Babel usage)
const optionalCatchBinding = require("@babel/plugin-syntax-optional-catch-binding");

// Used with Babel core
const babel = require("@babel/core");
const result = babel.transformSync(code, {
  plugins: [optionalCatchBinding]
});

Basic Usage

Configuration in babel.config.json

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

Configuration via CLI

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

Configuration via Node API

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

Syntax Example

Once configured, the plugin enables parsing of optional catch binding syntax:

try {
  throw new Error("Something went wrong");
} catch {  // No error parameter required
  console.log("An error occurred, but we don't need the error details");
  // Handle error without accessing the error object
}

Capabilities

Main Plugin Export

The default export that integrates with Babel's plugin system. This is an anonymous function created by the declare() utility from @babel/helper-plugin-utils.

/**
 * Babel plugin that adds "optionalCatchBinding" parser plugin support
 * Created using declare() from @babel/helper-plugin-utils
 * @returns {Object} Babel plugin object that modifies parser options
 */
function plugin(): BabelPlugin;

interface BabelPlugin {
  name: string;
  manipulateOptions(opts: any, parserOpts: ParserOptions): void;
}

interface ParserOptions {
  plugins: string[];
}

Plugin Configuration

The plugin is configured as part of Babel's plugin system and does not accept custom options.

// Plugin usage in Babel configuration
const pluginConfig = [
  "@babel/plugin-syntax-optional-catch-binding"
  // No options object - plugin takes no configuration
];

Types

/**
 * Babel plugin factory function type
 */
type BabelPluginFactory = () => BabelPlugin;

/**
 * Babel plugin object structure
 */
interface BabelPlugin {
  /** Plugin name for identification */
  name: string;
  /** Function to modify parser options */
  manipulateOptions(opts: any, parserOpts: ParserOptions): void;
}

/**
 * Parser options interface
 */
interface ParserOptions {
  /** Array of parser plugins to enable */
  plugins: string[];
}

Dependencies

The plugin has the following dependencies:

  • @babel/helper-plugin-utils: Provides the declare utility function for creating Babel plugins
  • @babel/core: Required as a peer dependency (^7.0.0-0) for the Babel transformation pipeline

Error Handling

The plugin relies on Babel's core error handling mechanisms. Parse errors for invalid optional catch binding syntax will be reported by Babel's parser with appropriate error messages and source locations.

Platform Support

  • Node.js: All versions supported by Babel 7+
  • Build Tool Integration: Compatible with webpack, Rollup, Parcel, and other tools that use Babel
  • Development Environment: Designed for build-time transformation, not runtime usage