From 3a56ecaf4922904841779d45e96a85df0c274fed Mon Sep 17 00:00:00 2001 From: CodeMan62 Date: Thu, 14 Aug 2025 11:37:51 +0530 Subject: [PATCH 1/7] quick cleanup for refacotr --- .../src/nullish_coalescing.rs | 275 +----------------- 1 file changed, 13 insertions(+), 262 deletions(-) diff --git a/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs b/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs index d78cc6de7327..decbc8340f09 100644 --- a/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs +++ b/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs @@ -1,264 +1,15 @@ -use std::mem::take; - -use serde::Deserialize; -use swc_common::{util::take::Take, Span, DUMMY_SP}; -use swc_ecma_ast::*; -use swc_ecma_utils::{alias_ident_for_simple_assign_tatget, alias_if_required, StmtLike}; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; - -pub fn nullish_coalescing(c: Config) -> impl Pass + 'static { - visit_mut_pass(NullishCoalescing { - c, - ..Default::default() +use swc_ecma_ast::Pass; +pub use swc_ecma_compiler::es2020::nullish_coalescing::Config; +use swc_ecma_compiler::{Compiler, Features}; +use swc_ecma_transforms_base::assumptions::Assumptions; + +pub fn nullish_coalescing(c: Config) -> impl Pass { + let mut assumptions = Assumptions::default(); + assumptions.no_document_all = c.no_document_all; + + Compiler::new(swc_ecma_compiler::Config { + includes: Features::NULLISH_COALESCING, + excludes: Features::empty(), + assumptions, }) } - -#[derive(Debug, Default)] -struct NullishCoalescing { - vars: Vec, - c: Config, -} - -#[derive(Debug, Clone, Copy, Default, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Config { - #[serde(default)] - pub no_document_all: bool, -} - -impl NullishCoalescing { - fn visit_mut_stmt_like(&mut self, stmts: &mut Vec) - where - T: VisitMutWith + StmtLike, - { - let mut buf = Vec::with_capacity(stmts.len() + 2); - - for mut stmt in stmts.take() { - stmt.visit_mut_with(self); - - if !self.vars.is_empty() { - buf.push(T::from( - VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: take(&mut self.vars), - declare: false, - ..Default::default() - } - .into(), - )); - } - - buf.push(stmt); - } - - *stmts = buf - } -} - -impl VisitMut for NullishCoalescing { - noop_visit_mut_type!(fail); - - /// Prevents #1123 - fn visit_mut_block_stmt(&mut self, s: &mut BlockStmt) { - let old_vars = self.vars.take(); - s.visit_mut_children_with(self); - self.vars = old_vars; - } - - /// Prevents #1123 - fn visit_mut_switch_case(&mut self, s: &mut SwitchCase) { - // Prevents #6328 - s.test.visit_mut_with(self); - let old_vars = self.vars.take(); - s.cons.visit_mut_with(self); - self.vars = old_vars; - } - - fn visit_mut_module_items(&mut self, n: &mut Vec) { - self.visit_mut_stmt_like(n) - } - - fn visit_mut_stmts(&mut self, n: &mut Vec) { - self.visit_mut_stmt_like(n) - } - - fn visit_mut_expr(&mut self, e: &mut Expr) { - e.visit_mut_children_with(self); - - match e { - Expr::Bin(BinExpr { - span, - left, - op: op!("??"), - right, - }) => { - // - let (l, aliased) = alias_if_required(left, "ref"); - - if aliased { - self.vars.push(VarDeclarator { - span: DUMMY_SP, - name: l.clone().into(), - init: None, - definite: false, - }); - } - - let var_expr = if aliased { - AssignExpr { - span: DUMMY_SP, - op: op!("="), - left: l.clone().into(), - right: left.take(), - } - .into() - } else { - l.clone().into() - }; - - *e = make_cond(self.c, *span, &l, var_expr, right.take()); - } - - Expr::Assign(ref mut assign @ AssignExpr { op: op!("??="), .. }) => { - match &mut assign.left { - AssignTarget::Simple(SimpleAssignTarget::Ident(i)) => { - *e = AssignExpr { - span: assign.span, - op: op!("="), - left: i.clone().into(), - right: Box::new(make_cond( - self.c, - assign.span, - &Ident::from(&*i), - Expr::Ident(Ident::from(&*i)), - assign.right.take(), - )), - } - .into(); - } - - AssignTarget::Simple(left) => { - let alias = alias_ident_for_simple_assign_tatget(left, "refs"); - self.vars.push(VarDeclarator { - span: DUMMY_SP, - name: alias.clone().into(), - init: None, - definite: false, - }); - - // TODO: Check for computed. - let right_expr = AssignExpr { - span: assign.span, - left: left.clone().into(), - op: op!("="), - right: assign.right.take(), - } - .into(); - - let var_expr = AssignExpr { - span: DUMMY_SP, - op: op!("="), - left: alias.clone().into(), - right: left.take().into(), - } - .into(); - - *e = AssignExpr { - span: assign.span, - op: op!("="), - left: alias.clone().into(), - right: Box::new(make_cond( - self.c, - assign.span, - &alias, - var_expr, - right_expr, - )), - } - .into(); - } - - _ => {} - } - } - - _ => {} - } - } - - fn visit_mut_block_stmt_or_expr(&mut self, n: &mut BlockStmtOrExpr) { - let vars = self.vars.take(); - n.visit_mut_children_with(self); - - if !self.vars.is_empty() { - if let BlockStmtOrExpr::Expr(expr) = n { - // expr - // { var decl = init; return expr; } - let stmts = vec![ - VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: self.vars.take(), - declare: false, - ..Default::default() - } - .into(), - Stmt::Return(ReturnStmt { - span: DUMMY_SP, - arg: Some(expr.take()), - }), - ]; - *n = BlockStmtOrExpr::BlockStmt(BlockStmt { - span: DUMMY_SP, - stmts, - ..Default::default() - }); - } - } - - self.vars = vars; - } -} - -#[tracing::instrument(level = "debug", skip_all)] -fn make_cond(c: Config, span: Span, alias: &Ident, var_expr: Expr, init: Box) -> Expr { - if c.no_document_all { - CondExpr { - span, - test: BinExpr { - span: DUMMY_SP, - left: Box::new(var_expr), - op: op!("!="), - right: Box::new(Expr::Lit(Lit::Null(Null { span: DUMMY_SP }))), - } - .into(), - cons: alias.clone().into(), - alt: init, - } - } else { - CondExpr { - span, - test: BinExpr { - span: DUMMY_SP, - left: Box::new(Expr::Bin(BinExpr { - span: DUMMY_SP, - left: Box::new(var_expr), - op: op!("!=="), - right: Box::new(Expr::Lit(Lit::Null(Null { span: DUMMY_SP }))), - })), - op: op!("&&"), - right: Box::new(Expr::Bin(BinExpr { - span: DUMMY_SP, - left: Box::new(Expr::Ident(alias.clone())), - op: op!("!=="), - right: Expr::undefined(DUMMY_SP), - })), - } - .into(), - cons: alias.clone().into(), - alt: init, - } - } - .into() -} From 8f5c54c1180a87890bc41fc06afb74d5097c107b Mon Sep 17 00:00:00 2001 From: CodeMan62 Date: Mon, 29 Sep 2025 14:49:11 +0530 Subject: [PATCH 2/7] ref --- Cargo.lock | 1 + crates/swc_ecma_compat_es2020/src/lib.rs | 3 +- crates/swc_ecma_compiler/Cargo.toml | 1 + crates/swc_ecma_compiler/src/es2020/mod.rs | 1 + .../src/es2020/nullish_coalescing.rs | 248 ++++++++++++++++++ crates/swc_ecma_compiler/src/features.rs | 1 + crates/swc_ecma_compiler/src/lib.rs | 125 +++++---- .../swc_ecma_transforms_typescript/Cargo.toml | 1 + .../benches/compat.rs | 4 +- 9 files changed, 327 insertions(+), 58 deletions(-) create mode 100644 crates/swc_ecma_compiler/src/es2020/nullish_coalescing.rs diff --git a/Cargo.lock b/Cargo.lock index 4cc941edae8b..e7930e2bbdc5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5191,6 +5191,7 @@ version = "1.0.0" dependencies = [ "bitflags 2.6.0", "rustc-hash 2.1.1", + "serde", "swc_atoms", "swc_common", "swc_ecma_ast", diff --git a/crates/swc_ecma_compat_es2020/src/lib.rs b/crates/swc_ecma_compat_es2020/src/lib.rs index 743ead4312b2..7e7cf05de528 100644 --- a/crates/swc_ecma_compat_es2020/src/lib.rs +++ b/crates/swc_ecma_compat_es2020/src/lib.rs @@ -18,10 +18,9 @@ pub fn es2020(config: Config, unresolved_mark: Mark) -> impl Pass { assumptions.no_document_all = config.nullish_coalescing.no_document_all; ( - nullish_coalescing(config.nullish_coalescing), optional_chaining(config.optional_chaining, unresolved_mark), Compiler::new(swc_ecma_compiler::Config { - includes: Features::EXPORT_NAMESPACE_FROM, + includes: Features::EXPORT_NAMESPACE_FROM | Features::NULLISH_COALESCING, assumptions, ..Default::default() }), diff --git a/crates/swc_ecma_compiler/Cargo.toml b/crates/swc_ecma_compiler/Cargo.toml index 7282984ab8b6..2c97d5d9c6c3 100644 --- a/crates/swc_ecma_compiler/Cargo.toml +++ b/crates/swc_ecma_compiler/Cargo.toml @@ -12,6 +12,7 @@ version = "1.0.0" [dependencies] bitflags = { workspace = true } rustc-hash = { workspace = true } +serde = { workspace = true } tracing = { workspace = true } swc_atoms = { version = "7.0.0", path = "../swc_atoms" } diff --git a/crates/swc_ecma_compiler/src/es2020/mod.rs b/crates/swc_ecma_compiler/src/es2020/mod.rs index bfe80ea8cf01..421f38e29d0a 100644 --- a/crates/swc_ecma_compiler/src/es2020/mod.rs +++ b/crates/swc_ecma_compiler/src/es2020/mod.rs @@ -1 +1,2 @@ pub(crate) mod export_namespace_from; +pub mod nullish_coalescing; diff --git a/crates/swc_ecma_compiler/src/es2020/nullish_coalescing.rs b/crates/swc_ecma_compiler/src/es2020/nullish_coalescing.rs new file mode 100644 index 000000000000..df61de3f6dbf --- /dev/null +++ b/crates/swc_ecma_compiler/src/es2020/nullish_coalescing.rs @@ -0,0 +1,248 @@ +use serde::Deserialize; +use swc_common::{util::take::Take, Span, DUMMY_SP}; +use swc_ecma_ast::*; +use swc_ecma_utils::{alias_ident_for_simple_assign_tatget, alias_if_required, StmtLike}; +use swc_ecma_visit::VisitMutWith; + +use crate::{CompilerImpl, Features}; + +#[derive(Debug, Clone, Copy, Default, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Config { + #[serde(default)] + pub no_document_all: bool, +} + +impl<'a> CompilerImpl<'a> { + /// Transform nullish coalescing binary expressions (??) to conditional + /// expressions + pub(crate) fn transform_nullish_coalescing_bin_expr(&mut self, e: &mut Expr) -> bool { + if let Expr::Bin(BinExpr { + span, + left, + op: op!("??"), + right, + }) = e + { + let (l, aliased) = alias_if_required(left, "ref"); + + if aliased { + self.es2020_nullish_coalescing_vars.push(VarDeclarator { + span: DUMMY_SP, + name: l.clone().into(), + init: None, + definite: false, + }); + } + + let var_expr = if aliased { + AssignExpr { + span: DUMMY_SP, + op: op!("="), + left: l.clone().into(), + right: left.take(), + } + .into() + } else { + l.clone().into() + }; + + *e = self.make_nullish_coalescing_cond(*span, &l, var_expr, right.take()); + return true; + } + false + } + + /// Transform nullish coalescing assignment expressions (??=) to assignment + /// expressions + pub(crate) fn transform_nullish_coalescing_assign_expr(&mut self, e: &mut Expr) -> bool { + if let Expr::Assign(ref mut assign @ AssignExpr { op: op!("??="), .. }) = e { + match &mut assign.left { + AssignTarget::Simple(SimpleAssignTarget::Ident(i)) => { + *e = AssignExpr { + span: assign.span, + op: op!("="), + left: i.clone().into(), + right: Box::new(self.make_nullish_coalescing_cond( + assign.span, + &Ident::from(&*i), + Expr::Ident(Ident::from(&*i)), + assign.right.take(), + )), + } + .into(); + return true; + } + + AssignTarget::Simple(left) => { + let alias = alias_ident_for_simple_assign_tatget(left, "refs"); + self.es2020_nullish_coalescing_vars.push(VarDeclarator { + span: DUMMY_SP, + name: alias.clone().into(), + init: None, + definite: false, + }); + + let right_expr = AssignExpr { + span: assign.span, + left: left.clone().into(), + op: op!("="), + right: assign.right.take(), + } + .into(); + + let var_expr = AssignExpr { + span: DUMMY_SP, + op: op!("="), + left: alias.clone().into(), + right: left.take().into(), + } + .into(); + + *e = AssignExpr { + span: assign.span, + op: op!("="), + left: alias.clone().into(), + right: Box::new(self.make_nullish_coalescing_cond( + assign.span, + &alias, + var_expr, + right_expr, + )), + } + .into(); + return true; + } + + _ => {} + } + } + false + } + + /// Handle nullish coalescing variables in BlockStmtOrExpr contexts + pub(crate) fn handle_nullish_coalescing_in_block_stmt_or_expr( + &mut self, + n: &mut BlockStmtOrExpr, + ) { + if !self.config.includes.contains(Features::NULLISH_COALESCING) { + return; + } + + let vars = self.es2020_nullish_coalescing_vars.take(); + n.visit_mut_children_with(self); + + if !self.es2020_nullish_coalescing_vars.is_empty() { + if let BlockStmtOrExpr::Expr(expr) = n { + // expr + // { var decl = init; return expr; } + let stmts = vec![ + VarDecl { + span: DUMMY_SP, + kind: VarDeclKind::Var, + decls: self.es2020_nullish_coalescing_vars.take(), + declare: false, + ..Default::default() + } + .into(), + Stmt::Return(ReturnStmt { + span: DUMMY_SP, + arg: Some(expr.take()), + }), + ]; + *n = BlockStmtOrExpr::BlockStmt(BlockStmt { + span: DUMMY_SP, + stmts, + ..Default::default() + }); + } + } + + self.es2020_nullish_coalescing_vars = vars; + } + + /// Handle nullish coalescing variables in statement-like contexts + pub(crate) fn handle_nullish_coalescing_in_stmt_like(&mut self, stmts: &mut Vec) + where + T: VisitMutWith + StmtLike, + { + if !self.config.includes.contains(Features::NULLISH_COALESCING) { + for stmt in stmts.iter_mut() { + stmt.visit_mut_with(self); + } + return; + } + + let mut buf = Vec::with_capacity(stmts.len() + 2); + + for mut stmt in stmts.take() { + stmt.visit_mut_with(self); + + if !self.es2020_nullish_coalescing_vars.is_empty() { + buf.push(T::from( + VarDecl { + span: DUMMY_SP, + kind: VarDeclKind::Var, + decls: self.es2020_nullish_coalescing_vars.take(), + declare: false, + ..Default::default() + } + .into(), + )); + } + + buf.push(stmt); + } + + *stmts = buf; + } + + /// Create a conditional expression for nullish coalescing + fn make_nullish_coalescing_cond( + &self, + span: Span, + alias: &Ident, + var_expr: Expr, + init: Box, + ) -> Expr { + if self.config.assumptions.no_document_all { + CondExpr { + span, + test: BinExpr { + span: DUMMY_SP, + left: Box::new(var_expr), + op: op!("!="), + right: Box::new(Expr::Lit(Lit::Null(Null { span: DUMMY_SP }))), + } + .into(), + cons: alias.clone().into(), + alt: init, + } + } else { + CondExpr { + span, + test: BinExpr { + span: DUMMY_SP, + left: Box::new(Expr::Bin(BinExpr { + span: DUMMY_SP, + left: Box::new(var_expr), + op: op!("!=="), + right: Box::new(Expr::Lit(Lit::Null(Null { span: DUMMY_SP }))), + })), + op: op!("&&"), + right: Box::new(Expr::Bin(BinExpr { + span: DUMMY_SP, + left: Box::new(Expr::Ident(alias.clone())), + op: op!("!=="), + right: Expr::undefined(DUMMY_SP), + })), + } + .into(), + cons: alias.clone().into(), + alt: init, + } + } + .into() + } +} + diff --git a/crates/swc_ecma_compiler/src/features.rs b/crates/swc_ecma_compiler/src/features.rs index b0bf26f438c0..9f519ab53ee6 100644 --- a/crates/swc_ecma_compiler/src/features.rs +++ b/crates/swc_ecma_compiler/src/features.rs @@ -8,6 +8,7 @@ bitflags! { const PRIVATE_IN_OBJECT = 1 << 2; const LOGICAL_ASSIGNMENTS = 1 << 3; const EXPORT_NAMESPACE_FROM = 1 << 4; + const NULLISH_COALESCING = 1 << 5; } } diff --git a/crates/swc_ecma_compiler/src/lib.rs b/crates/swc_ecma_compiler/src/lib.rs index 968abf8bbe9e..b0fefcc90ee5 100644 --- a/crates/swc_ecma_compiler/src/lib.rs +++ b/crates/swc_ecma_compiler/src/lib.rs @@ -18,7 +18,7 @@ use crate::es2022::{ }; pub use crate::features::Features; -mod es2020; +pub mod es2020; mod es2021; mod es2022; mod features; @@ -60,6 +60,9 @@ struct CompilerImpl<'a> { // Logical assignments transformation state es2021_logical_assignment_vars: Vec, + + // ES2020: Nullish coalescing transformation state + es2020_nullish_coalescing_vars: Vec, } #[swc_trace] @@ -72,6 +75,7 @@ impl<'a> CompilerImpl<'a> { es2022_injected_weakset_vars: FxHashSet::default(), es2022_current_class_data: ClassData::default(), es2021_logical_assignment_vars: Vec::new(), + es2020_nullish_coalescing_vars: Vec::new(), } } @@ -527,6 +531,11 @@ impl<'a> VisitMut for CompilerImpl<'a> { let logical_transformed = self.config.includes.contains(Features::LOGICAL_ASSIGNMENTS) && self.transform_logical_assignment(e); + let nullish_transformed = !logical_transformed + && self.config.includes.contains(Features::NULLISH_COALESCING) + && (self.transform_nullish_coalescing_bin_expr(e) + || self.transform_nullish_coalescing_assign_expr(e)); + // Phase 2: Setup for private field expressions let prev_prepend_exprs = if self.config.includes.contains(Features::PRIVATE_IN_OBJECT) { Some(take(&mut self.es2022_private_field_init_exprs)) @@ -559,7 +568,7 @@ impl<'a> VisitMut for CompilerImpl<'a> { .into(); } } - } else if !logical_transformed { + } else if !logical_transformed && !nullish_transformed { // Transform private in expressions only if no other transformation occurred self.es2022_transform_private_in_to_weakset_has(e); } @@ -576,37 +585,39 @@ impl<'a> VisitMut for CompilerImpl<'a> { self.transform_export_namespace_from(ns); } - // Setup for variable hoisting - let need_var_hoisting = self.config.includes.contains(Features::LOGICAL_ASSIGNMENTS); - - let saved_logical_vars = if need_var_hoisting { - self.es2021_logical_assignment_vars.take() + // Handle nullish coalescing at statement level + if self.config.includes.contains(Features::NULLISH_COALESCING) { + self.handle_nullish_coalescing_in_stmt_like(ns); } else { - vec![] - }; + // Setup for variable hoisting (logical assignments only) + let need_var_hoisting = self.config.includes.contains(Features::LOGICAL_ASSIGNMENTS); - // Single recursive visit - ns.visit_mut_children_with(self); + let saved_logical_vars = if need_var_hoisting { + self.es2021_logical_assignment_vars.take() + } else { + vec![] + }; - // Post-processing: Handle variable hoisting - if need_var_hoisting { - let logical_vars = - std::mem::replace(&mut self.es2021_logical_assignment_vars, saved_logical_vars); + // Single recursive visit + ns.visit_mut_children_with(self); - let mut all_vars = Vec::new(); - all_vars.extend(logical_vars); + // Post-processing: Handle variable hoisting + if need_var_hoisting { + let logical_vars = + std::mem::replace(&mut self.es2021_logical_assignment_vars, saved_logical_vars); - if !all_vars.is_empty() { - prepend_stmt( - ns, - VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: all_vars, - ..Default::default() - } - .into(), - ); + if !logical_vars.is_empty() { + prepend_stmt( + ns, + VarDecl { + span: DUMMY_SP, + kind: VarDeclKind::Var, + decls: logical_vars, + ..Default::default() + } + .into(), + ); + } } } @@ -635,37 +646,39 @@ impl<'a> VisitMut for CompilerImpl<'a> { } fn visit_mut_stmts(&mut self, s: &mut Vec) { - // Setup for variable hoisting - let need_var_hoisting = self.config.includes.contains(Features::LOGICAL_ASSIGNMENTS); - - let saved_logical_vars = if need_var_hoisting { - self.es2021_logical_assignment_vars.take() + // Handle nullish coalescing at statement level + if self.config.includes.contains(Features::NULLISH_COALESCING) { + self.handle_nullish_coalescing_in_stmt_like(s); } else { - vec![] - }; + // Setup for variable hoisting (logical assignments only) + let need_var_hoisting = self.config.includes.contains(Features::LOGICAL_ASSIGNMENTS); - // Single recursive visit - s.visit_mut_children_with(self); + let saved_logical_vars = if need_var_hoisting { + self.es2021_logical_assignment_vars.take() + } else { + vec![] + }; - // Post-processing: Handle variable hoisting - if need_var_hoisting { - let logical_vars = - std::mem::replace(&mut self.es2021_logical_assignment_vars, saved_logical_vars); + // Single recursive visit + s.visit_mut_children_with(self); - let mut all_vars = Vec::new(); - all_vars.extend(logical_vars); + // Post-processing: Handle variable hoisting + if need_var_hoisting { + let logical_vars = + std::mem::replace(&mut self.es2021_logical_assignment_vars, saved_logical_vars); - if !all_vars.is_empty() { - prepend_stmt( - s, - VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: all_vars, - ..Default::default() - } - .into(), - ); + if !logical_vars.is_empty() { + prepend_stmt( + s, + VarDecl { + span: DUMMY_SP, + kind: VarDeclKind::Var, + decls: logical_vars, + ..Default::default() + } + .into(), + ); + } } } @@ -676,4 +689,8 @@ impl<'a> VisitMut for CompilerImpl<'a> { self.es2022_prepend_private_field_vars(s); } } + + fn visit_mut_block_stmt_or_expr(&mut self, n: &mut BlockStmtOrExpr) { + self.handle_nullish_coalescing_in_block_stmt_or_expr(n); + } } diff --git a/crates/swc_ecma_transforms_typescript/Cargo.toml b/crates/swc_ecma_transforms_typescript/Cargo.toml index 98e2888cb3c1..7ac0b869e138 100644 --- a/crates/swc_ecma_transforms_typescript/Cargo.toml +++ b/crates/swc_ecma_transforms_typescript/Cargo.toml @@ -32,6 +32,7 @@ swc_ecma_visit = { version = "14.0.0", path = "../swc_ecma_visit" } codspeed-criterion-compat = { workspace = true } swc_ecma_codegen = { version = "16.0.0", path = "../swc_ecma_codegen" } +swc_ecma_compat_es2020 = { version = "25.0.0", path = "../swc_ecma_compat_es2020" } swc_ecma_parser = { version = "22.0.3", path = "../swc_ecma_parser" } swc_ecma_transforms_compat = { version = "25.0.0", path = "../swc_ecma_transforms_compat" } swc_ecma_transforms_proposal = { version = "23.0.0", path = "../swc_ecma_transforms_proposal" } diff --git a/crates/swc_ecma_transforms_typescript/benches/compat.rs b/crates/swc_ecma_transforms_typescript/benches/compat.rs index 576aebc402a0..474e80817db1 100644 --- a/crates/swc_ecma_transforms_typescript/benches/compat.rs +++ b/crates/swc_ecma_transforms_typescript/benches/compat.rs @@ -143,8 +143,8 @@ fn es2020(b: &mut Bencher) { fn es2020_nullish_coalescing(b: &mut Bencher) { run(b, |_| { - swc_ecma_transforms_compat::es2020::nullish_coalescing( - swc_ecma_transforms_compat::es2020::nullish_coalescing::Config { + swc_ecma_compat_es2020::nullish_coalescing( + swc_ecma_compat_es2020::es2020::nullish_coalescing::Config { no_document_all: false, }, ) From b0a03e3f1e30c22d9f2eb818e9b3fc67c61d5176 Mon Sep 17 00:00:00 2001 From: CodeMan62 Date: Mon, 29 Sep 2025 15:01:07 +0530 Subject: [PATCH 3/7] fix CI --- crates/swc_ecma_transforms_typescript/Cargo.toml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/swc_ecma_transforms_typescript/Cargo.toml b/crates/swc_ecma_transforms_typescript/Cargo.toml index 534237e0cb39..ca381d1c9bd1 100644 --- a/crates/swc_ecma_transforms_typescript/Cargo.toml +++ b/crates/swc_ecma_transforms_typescript/Cargo.toml @@ -17,9 +17,7 @@ concurrent = ["swc_common/concurrent"] [dependencies] bytes-str = { workspace = true } -rustc-hash = { workspace = true } -serde = { workspace = true, features = ["derive"] } - +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } swc_atoms = { version = "7.0.0", path = "../swc_atoms" } swc_common = { version = "14.0.4", path = "../swc_common" } swc_ecma_ast = { version = "15.0.0", path = "../swc_ecma_ast" } @@ -31,12 +29,12 @@ swc_ecma_visit = { version = "15.0.0", path = "../swc_ecma_visit" } [dev-dependencies] codspeed-criterion-compat = { workspace = true } -swc_ecma_codegen = { version = "16.0.0", path = "../swc_ecma_codegen" } +swc_ecma_codegen = { version = "17.0.2", path = "../swc_ecma_codegen" } swc_ecma_compat_es2020 = { version = "25.0.0", path = "../swc_ecma_compat_es2020" } -swc_ecma_parser = { version = "22.0.3", path = "../swc_ecma_parser" } -swc_ecma_transforms_compat = { version = "25.0.0", path = "../swc_ecma_transforms_compat" } -swc_ecma_transforms_proposal = { version = "23.0.0", path = "../swc_ecma_transforms_proposal" } -swc_ecma_transforms_testing = { version = "26.0.0", path = "../swc_ecma_transforms_testing" } +swc_ecma_parser = { version = "24.0.2", path = "../swc_ecma_parser" } +swc_ecma_transforms_compat = { version = "30.0.0", path = "../swc_ecma_transforms_compat" } +swc_ecma_transforms_proposal = { version = "27.0.0", path = "../swc_ecma_transforms_proposal" } +swc_ecma_transforms_testing = { version = "30.0.0", path = "../swc_ecma_transforms_testing" } testing = { version = "15.0.0", path = "../testing" } [[bench]] From bc98a9b7274a179212b64ebab20daa74c8930932 Mon Sep 17 00:00:00 2001 From: CodeMan62 Date: Mon, 29 Sep 2025 15:05:38 +0530 Subject: [PATCH 4/7] fix toml --- crates/swc_ecma_transforms_typescript/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_typescript/Cargo.toml b/crates/swc_ecma_transforms_typescript/Cargo.toml index ca381d1c9bd1..889d1c9c6f88 100644 --- a/crates/swc_ecma_transforms_typescript/Cargo.toml +++ b/crates/swc_ecma_transforms_typescript/Cargo.toml @@ -17,7 +17,8 @@ concurrent = ["swc_common/concurrent"] [dependencies] bytes-str = { workspace = true } -rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } +rustc-hash = { workspace = true } +serde = { workspace = true, features = ["derive"] } swc_atoms = { version = "7.0.0", path = "../swc_atoms" } swc_common = { version = "14.0.4", path = "../swc_common" } swc_ecma_ast = { version = "15.0.0", path = "../swc_ecma_ast" } From 529a8a501a58e0418513a9cfc61fec0e1c9def5d Mon Sep 17 00:00:00 2001 From: CodeMan62 Date: Mon, 29 Sep 2025 15:08:22 +0530 Subject: [PATCH 5/7] bump version --- crates/swc_ecma_transforms_typescript/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_typescript/Cargo.toml b/crates/swc_ecma_transforms_typescript/Cargo.toml index 889d1c9c6f88..4d769e5559db 100644 --- a/crates/swc_ecma_transforms_typescript/Cargo.toml +++ b/crates/swc_ecma_transforms_typescript/Cargo.toml @@ -31,7 +31,7 @@ swc_ecma_visit = { version = "15.0.0", path = "../swc_ecma_visit" } codspeed-criterion-compat = { workspace = true } swc_ecma_codegen = { version = "17.0.2", path = "../swc_ecma_codegen" } -swc_ecma_compat_es2020 = { version = "25.0.0", path = "../swc_ecma_compat_es2020" } +swc_ecma_compat_es2020 = { version = "28.0.0", path = "../swc_ecma_compat_es2020" } swc_ecma_parser = { version = "24.0.2", path = "../swc_ecma_parser" } swc_ecma_transforms_compat = { version = "30.0.0", path = "../swc_ecma_transforms_compat" } swc_ecma_transforms_proposal = { version = "27.0.0", path = "../swc_ecma_transforms_proposal" } From cda8a764ba521ec8ab9c6d8a75c85a5328e3ef76 Mon Sep 17 00:00:00 2001 From: CodeMan62 Date: Mon, 29 Sep 2025 15:11:11 +0530 Subject: [PATCH 6/7] fmt --- Cargo.lock | 1 + crates/swc_ecma_compiler/src/es2020/nullish_coalescing.rs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index aea262b9bbbb..c6be02e3160d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6107,6 +6107,7 @@ dependencies = [ "swc_common", "swc_ecma_ast", "swc_ecma_codegen", + "swc_ecma_compat_es2020", "swc_ecma_parser", "swc_ecma_transforms_base", "swc_ecma_transforms_compat", diff --git a/crates/swc_ecma_compiler/src/es2020/nullish_coalescing.rs b/crates/swc_ecma_compiler/src/es2020/nullish_coalescing.rs index df61de3f6dbf..c2285c250a98 100644 --- a/crates/swc_ecma_compiler/src/es2020/nullish_coalescing.rs +++ b/crates/swc_ecma_compiler/src/es2020/nullish_coalescing.rs @@ -245,4 +245,3 @@ impl<'a> CompilerImpl<'a> { .into() } } - From ad5e6e4f9350723f13cf1973d7729737f2425a4d Mon Sep 17 00:00:00 2001 From: CodeMan62 Date: Mon, 29 Sep 2025 15:22:02 +0530 Subject: [PATCH 7/7] clippy --- crates/swc_ecma_transforms_typescript/benches/compat.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_typescript/benches/compat.rs b/crates/swc_ecma_transforms_typescript/benches/compat.rs index e68317ecc004..0829f9912a7e 100644 --- a/crates/swc_ecma_transforms_typescript/benches/compat.rs +++ b/crates/swc_ecma_transforms_typescript/benches/compat.rs @@ -144,7 +144,7 @@ fn es2020(b: &mut Bencher) { fn es2020_nullish_coalescing(b: &mut Bencher) { run(b, |_| { swc_ecma_compat_es2020::nullish_coalescing( - swc_ecma_compat_es2020::es2020::nullish_coalescing::Config { + swc_ecma_compat_es2020::nullish_coalescing::Config { no_document_all: false, }, )