A Babel syntax plugin that enables parsing of optional catch bindings in JavaScript try/catch blocks
npx @tessl/cli install tessl/npm-babel--plugin-syntax-optional-catch-binding@7.8.0@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.
npm install --save-dev @babel/plugin-syntax-optional-catch-bindingThe 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]
});{
"plugins": ["@babel/plugin-syntax-optional-catch-binding"]
}babel --plugins @babel/plugin-syntax-optional-catch-binding script.jsrequire("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-syntax-optional-catch-binding"]
});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
}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[];
}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
];/**
* 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[];
}The plugin has the following dependencies:
declare utility function for creating Babel pluginsThe 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.