From 03532adb0d5fd48e3d5ddb1b7b7dffea3a8ce177 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Thu, 22 Aug 2024 15:48:11 +0800 Subject: [PATCH] docs(transformer): add documentation for optional-catch-binding plugin --- .../src/es2019/optional_catch_binding.rs | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/crates/oxc_transformer/src/es2019/optional_catch_binding.rs b/crates/oxc_transformer/src/es2019/optional_catch_binding.rs index d54dcff94017fa..84f0093347f14a 100644 --- a/crates/oxc_transformer/src/es2019/optional_catch_binding.rs +++ b/crates/oxc_transformer/src/es2019/optional_catch_binding.rs @@ -1,3 +1,37 @@ +//! ES2019: Optional Catch Binding +//! +//! This plugin transform catch clause without parameter to add a parameter called `unused` in catch clause. +//! +//! > This plugin is included in `preset-env`, in ES2019 +//! +//! ## Example +//! +//! Input: +//! ```js +//! try { +//! throw 0; +//! } catch (_unused) { +//! doSomethingWhichDoesNotCareAboutTheValueThrown(); +//! } +//! ``` +//! +//! Output: +//! ```js +//! try { +//! throw 0; +//! } catch (_unused) { +//! doSomethingWhichDoesNotCareAboutTheValueThrown(); +//! } +//! ``` +//! +//! ## Implementation +//! +//! Implementation based on [@babel/plugin-transform-optional-catch-binding](https://babel.dev/docs/babel-plugin-transform-optional-catch-binding). +//! +//! ## References: +//! * Babel plugin implementation: +//! * Optional catch binding TC39 proposal: + use std::cell::Cell; use oxc_ast::ast::*; @@ -7,11 +41,6 @@ use oxc_traverse::TraverseCtx; use crate::context::Ctx; -/// ES2019: Optional Catch Binding -/// -/// References: -/// * -/// * pub struct OptionalCatchBinding<'a> { _ctx: Ctx<'a>, }