From 72ff2c67b9600b3ce98be6826c8e2a2920f9ec38 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Tue, 20 Aug 2024 01:06:35 +0000 Subject: [PATCH] feat(transformer/nullish-coalescing-operator): add comments in top of file (#4972) part of #4881 --- .../src/es2020/nullish_coalescing_operator.rs | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs b/crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs index 0603a734488b3..b900fcbd94a42 100644 --- a/crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs +++ b/crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs @@ -1,3 +1,33 @@ +//! ES2020: Nullish Coalescing Operator +//! +//! This plugin transforms nullish coalescing operators (`??`) to a series of ternary expressions. +//! +//! > This plugin is included in `preset-env`, in ES2020 +//! +//! ## Example +//! +//! Input: +//! ```js +//! var foo = object.foo ?? "default"; +//! ``` +//! +//! Output: +//! ```js +//! var _object$foo; +//! var foo = +//! (_object$foo = object.foo) !== null && _object$foo !== void 0 +//! ? _object$foo +//! : "default"; +//! ``` +//! +//! ## Implementation +//! +//! Implementation based on [@babel/plugin-transform-nullish-coalescing-operator](https://babeljs.io/docs/babel-plugin-transform-nullish-coalescing-operator). +//! +//! ## References: +//! * Babel plugin implementation: +//! * Nullish coalescing TC39 proposal: + use std::cell::Cell; use oxc_semantic::{ReferenceFlag, SymbolFlags}; @@ -10,11 +40,6 @@ use oxc_syntax::operator::{AssignmentOperator, BinaryOperator, LogicalOperator}; use crate::context::Ctx; -/// ES2020: Nullish Coalescing Operator -/// -/// References: -/// * -/// * pub struct NullishCoalescingOperator<'a> { _ctx: Ctx<'a>, var_declarations: std::vec::Vec>>,