From 5d4dd73d80609f80f26f2c7b34302e89407be64a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 13:18:35 +0900 Subject: [PATCH 001/186] Remove `chain!` --- crates/swc_visit/src/lib.rs | 48 ------------------------------------- 1 file changed, 48 deletions(-) diff --git a/crates/swc_visit/src/lib.rs b/crates/swc_visit/src/lib.rs index b5b18401f803..f12738a5c988 100644 --- a/crates/swc_visit/src/lib.rs +++ b/crates/swc_visit/src/lib.rs @@ -129,39 +129,6 @@ pub trait Repeated { fn reset(&mut self); } -/// A visitor which applies `A` and then `B`. -#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] -pub struct AndThen { - pub first: A, - pub second: B, -} - -/// Chains multiple visitor. -#[macro_export] -macro_rules! chain { - ($a:expr, $b:expr) => {{ - use $crate::AndThen; - - AndThen { - first: $a, - second: $b, - } - }}; - - ($a:expr, $b:expr,) => { - chain!($a, $b) - }; - - ($a:expr, $b:expr, $($rest:tt)+) => {{ - use $crate::AndThen; - - AndThen{ - first: $a, - second: chain!($b, $($rest)*), - } - }}; -} - /// A visitor which applies `V` again and again if `V` modifies the node. /// /// # Note @@ -199,21 +166,6 @@ where } } -impl Repeated for AndThen -where - A: Repeated, - B: Repeated, -{ - fn changed(&self) -> bool { - self.first.changed() || self.second.changed() - } - - fn reset(&mut self) { - self.first.reset(); - self.second.reset(); - } -} - #[derive(Debug, Clone, PartialEq, Eq)] pub struct AstKindPath where From ad032c439a41f41e57a6d830d77ca88bc39e5573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 13:20:19 +0900 Subject: [PATCH 002/186] Patch `swc_common` --- crates/swc_common/src/lib.rs | 1 - crates/swc_common/src/pass.rs | 10 ---------- 2 files changed, 11 deletions(-) diff --git a/crates/swc_common/src/lib.rs b/crates/swc_common/src/lib.rs index 3ca6512cf68b..ba0b27e7a868 100644 --- a/crates/swc_common/src/lib.rs +++ b/crates/swc_common/src/lib.rs @@ -39,7 +39,6 @@ use std::fmt::Debug; pub use ast_node::{ast_node, ast_serde, DeserializeEnum, Spanned}; pub use from_variant::FromVariant; pub use swc_eq_ignore_macros::{EqIgnoreSpan, TypeEq}; -pub use swc_visit::chain; pub use self::{ eq::{EqIgnoreSpan, TypeEq}, diff --git a/crates/swc_common/src/pass.rs b/crates/swc_common/src/pass.rs index e91bab0724e2..7515d503d271 100644 --- a/crates/swc_common/src/pass.rs +++ b/crates/swc_common/src/pass.rs @@ -20,13 +20,3 @@ where Cow::Owned(format!("repeat({})", V::name())) } } - -impl CompilerPass for AndThen -where - A: CompilerPass, - B: CompilerPass, -{ - fn name() -> Cow<'static, str> { - Cow::Owned(format!("{} -> {}", A::name(), B::name())) - } -} From 4b3faf228a8dd097fa25c1a633227ea50f291418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 13:23:32 +0900 Subject: [PATCH 003/186] Fix `swc_ecma_visit` --- crates/swc_ecma_visit/src/lib.rs | 198 +------------------------------ 1 file changed, 3 insertions(+), 195 deletions(-) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 3f3c7a406a2d..3ad4b610a182 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -6,82 +6,15 @@ #[doc(hidden)] pub extern crate swc_ecma_ast; -use std::{borrow::Cow, fmt::Debug}; +use std::fmt::Debug; -use swc_common::{pass::CompilerPass, Span, DUMMY_SP}; +use swc_common::{Span, DUMMY_SP}; use swc_ecma_ast::*; -use swc_visit::{AndThen, Repeat, Repeated}; +use swc_visit::{Repeat, Repeated}; pub use crate::generated::*; mod generated; -impl Fold for AndThen -where - A: Fold, - - B: Fold, -{ - #[inline(always)] - fn fold_program(&mut self, n: Program) -> Program { - let n = self.first.fold_program(n); - self.second.fold_program(n) - } - - #[inline(always)] - fn fold_module(&mut self, n: Module) -> Module { - let n = self.first.fold_module(n); - self.second.fold_module(n) - } - - #[inline(always)] - fn fold_script(&mut self, n: Script) -> Script { - let n = self.first.fold_script(n); - self.second.fold_script(n) - } -} - -impl VisitMut for AndThen -where - A: VisitMut, - B: VisitMut, -{ - fn visit_mut_program(&mut self, n: &mut Program) { - self.first.visit_mut_program(n); - self.second.visit_mut_program(n); - } - - fn visit_mut_module(&mut self, n: &mut Module) { - self.first.visit_mut_module(n); - self.second.visit_mut_module(n) - } - - fn visit_mut_script(&mut self, n: &mut Script) { - self.first.visit_mut_script(n); - self.second.visit_mut_script(n) - } -} - -impl Visit for AndThen -where - A: Visit, - B: Visit, -{ - fn visit_program(&mut self, n: &Program) { - self.first.visit_program(n); - self.second.visit_program(n); - } - - fn visit_module(&mut self, n: &Module) { - self.first.visit_module(n); - self.second.visit_module(n); - } - - fn visit_script(&mut self, n: &Script) { - self.first.visit_script(n); - self.second.visit_script(n); - } -} - impl Fold for Repeat where V: Fold + Repeated, @@ -206,131 +139,6 @@ pub trait InjectVars { fn take_vars(&mut self) -> Vec; } -impl InjectVars for Folder -where - V: VisitMut + InjectVars, -{ - fn take_vars(&mut self) -> Vec { - self.0.take_vars() - } -} - -/// Wrap a [VisitMut] as a [Fold]. -/// -/// The returned folder only handles `fold_script` and `fold_module`, and -/// typescript nodes are ignored. So if your visitor needs to handle typescript -/// or low-level nodes, you should use [as_folder] instead. -#[inline] -pub fn as_folder(v: V) -> Folder -where - V: VisitMut, -{ - Folder(v) -} - -/// Wrap a [VisitMut] as a [Fold] -#[derive(Debug, Clone, Copy)] -pub struct Folder(V); - -impl Repeated for Folder -where - V: Repeated + VisitMut, -{ - fn changed(&self) -> bool { - self.0.changed() - } - - fn reset(&mut self) { - self.0.reset(); - } -} - -impl CompilerPass for Folder -where - V: VisitMut + CompilerPass, -{ - fn name() -> Cow<'static, str> { - V::name() - } -} - -macro_rules! delegate { - ($name:ident, $T:ty) => { - fn $name(&mut self, n: &mut $T) { - n.visit_mut_with(&mut self.0); - } - }; -} - -/// This only proxies subset of methods. -impl VisitMut for Folder -where - V: VisitMut, -{ - delegate!(visit_mut_ident, Ident); - - delegate!(visit_mut_span, Span); - - delegate!(visit_mut_expr, Expr); - - delegate!(visit_mut_decl, Decl); - - delegate!(visit_mut_stmt, Stmt); - - delegate!(visit_mut_pat, Pat); - - delegate!(visit_mut_ts_type, TsType); - - delegate!(visit_mut_module, Module); - - delegate!(visit_mut_script, Script); - - delegate!(visit_mut_program, Program); -} - -macro_rules! method { - ($name:ident, $T:ty) => { - fn $name(&mut self, mut n: $T) -> $T { - n.visit_mut_with(&mut self.0); - n - } - }; -} - -impl Fold for Folder -where - V: VisitMut, -{ - method!(fold_ident, Ident); - - method!(fold_span, Span); - - method!(fold_expr, Expr); - - method!(fold_decl, Decl); - - method!(fold_stmt, Stmt); - - method!(fold_pat, Pat); - - method!(fold_ts_type, TsType); - - method!(fold_script, Script); - - method!(fold_program, Program); - - #[inline(always)] - fn fold_module(&mut self, mut n: Module) -> Module { - #[cfg(all(debug_assertions, feature = "debug"))] - let _tracing = { - let visitor_name = std::any::type_name::(); - tracing::span!(tracing::Level::INFO, "as_folder", visitor = visitor_name).entered() - }; - n.visit_mut_with(&mut self.0); - n - } -} - /// Note: Ignoring more types is not considered as a breaking change. #[macro_export] macro_rules! noop_fold_type { From 6253539d8662ebd5babc0f75a92ae2a153e7f8e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 13:28:22 +0900 Subject: [PATCH 004/186] Take impl --- crates/swc_ecma_ast/src/module.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_ast/src/module.rs b/crates/swc_ecma_ast/src/module.rs index 68df93b3e461..8655d9d092a8 100644 --- a/crates/swc_ecma_ast/src/module.rs +++ b/crates/swc_ecma_ast/src/module.rs @@ -14,8 +14,14 @@ pub enum Program { Script(Script), } +impl Take for Program { + fn dummy() -> Self { + Program::Script(Script::default()) + } +} + #[ast_node("Module")] -#[derive(Eq, Hash, EqIgnoreSpan)] +#[derive(Eq, Hash, EqIgnoreSpan, Default)] pub struct Module { pub span: Span, @@ -50,7 +56,7 @@ impl Take for Module { } #[ast_node("Script")] -#[derive(Eq, Hash, EqIgnoreSpan)] +#[derive(Eq, Hash, EqIgnoreSpan, Default)] pub struct Script { pub span: Span, From f4b58768c0e4f6b096ac4de6d73922b6e80832e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 13:31:53 +0900 Subject: [PATCH 005/186] `Pass` --- crates/swc_ecma_visit/src/lib.rs | 87 +++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 3ad4b610a182..dc20fe83e922 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -8,13 +8,98 @@ pub extern crate swc_ecma_ast; use std::fmt::Debug; -use swc_common::{Span, DUMMY_SP}; +use swc_common::{util::take::Take, Span, DUMMY_SP}; use swc_ecma_ast::*; use swc_visit::{Repeat, Repeated}; pub use crate::generated::*; mod generated; +/// A map from the [Program] to the [Program] +pub trait Pass { + fn process(&mut self, program: &mut Program); +} + +pub fn folder(pass: V) -> impl Pass +where + V: Fold, +{ + Folder { pass } +} + +struct Folder { + pass: V, +} + +impl Pass for Folder +where + V: Fold, +{ + fn process(&mut self, program: &mut Program) { + program.map_with_mut(|p| p.fold_with(&mut self.pass)); + } +} + +pub fn visit_mut(pass: V) -> impl Pass +where + V: VisitMut, +{ + VisitMutFolder { pass } +} + +struct VisitMutFolder { + pass: V, +} + +impl Pass for VisitMutFolder +where + V: VisitMut, +{ + fn process(&mut self, program: &mut Program) { + program.visit_mut_with(&mut self.pass); + } +} + +pub fn visitor(pass: V) -> impl Pass +where + V: Visit, +{ + Visitor { pass } +} + +struct Visitor { + pass: V, +} + +impl Pass for Visitor +where + V: Visit, +{ + fn process(&mut self, program: &mut Program) { + program.visit_with(&mut self.pass); + } +} + +pub fn from_fn(f: impl FnMut(&mut Program)) -> impl Pass +where + V: Fold, +{ + FnPass { f } +} + +struct FnPass { + f: F, +} + +impl Pass for FnPass +where + F: FnMut(&mut Program), +{ + fn process(&mut self, program: &mut Program) { + (self.f)(program); + } +} + impl Fold for Repeat where V: Fold + Repeated, From a591a63cb558b66a00354b0eda588b77fc76f9da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 13:33:48 +0900 Subject: [PATCH 006/186] Consistent --- crates/swc_ecma_visit/src/lib.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index dc20fe83e922..921e48a60d00 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -20,18 +20,18 @@ pub trait Pass { fn process(&mut self, program: &mut Program); } -pub fn folder(pass: V) -> impl Pass +pub fn from_fold(pass: V) -> impl Pass where V: Fold, { - Folder { pass } + FoldPass { pass } } -struct Folder { +struct FoldPass { pass: V, } -impl Pass for Folder +impl Pass for FoldPass where V: Fold, { @@ -40,18 +40,18 @@ where } } -pub fn visit_mut(pass: V) -> impl Pass +pub fn from_visit_mut(pass: V) -> impl Pass where V: VisitMut, { - VisitMutFolder { pass } + VisitMutPass { pass } } -struct VisitMutFolder { +struct VisitMutPass { pass: V, } -impl Pass for VisitMutFolder +impl Pass for VisitMutPass where V: VisitMut, { @@ -64,14 +64,14 @@ pub fn visitor(pass: V) -> impl Pass where V: Visit, { - Visitor { pass } + VisitorPass { pass } } -struct Visitor { +struct VisitorPass { pass: V, } -impl Pass for Visitor +impl Pass for VisitorPass where V: Visit, { From 25065a74cd3d14ceb952b9dd609322bb6429d885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 13:35:34 +0900 Subject: [PATCH 007/186] fix more --- crates/swc_ecma_compat_common/src/regexp.rs | 6 +++--- crates/swc_ecma_ext_transforms/src/jest.rs | 6 +++--- crates/swc_ecma_transforms_base/src/fixer.rs | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/swc_ecma_compat_common/src/regexp.rs b/crates/swc_ecma_compat_common/src/regexp.rs index aea56f5fa5e5..34feb947aacc 100644 --- a/crates/swc_ecma_compat_common/src/regexp.rs +++ b/crates/swc_ecma_compat_common/src/regexp.rs @@ -1,10 +1,10 @@ use swc_common::util::take::Take; use swc_ecma_ast::{CallExpr, Expr, Lit, Regex}; use swc_ecma_utils::{quote_ident, ExprFactory}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Pass, VisitMut, VisitMutWith}; -pub fn regexp(config: Config) -> impl Fold + VisitMut { - as_folder(RegExp { config }) +pub fn regexp(config: Config) -> impl Pass { + from_visit_mut(RegExp { config }) } #[derive(Default, Clone, Copy)] diff --git a/crates/swc_ecma_ext_transforms/src/jest.rs b/crates/swc_ecma_ext_transforms/src/jest.rs index d0f792b3e802..6d41100f8ae9 100644 --- a/crates/swc_ecma_ext_transforms/src/jest.rs +++ b/crates/swc_ecma_ext_transforms/src/jest.rs @@ -2,7 +2,7 @@ use phf::phf_set; use swc_common::util::take::Take; use swc_ecma_ast::*; use swc_ecma_utils::{prepend_stmts, StmtLike}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Pass, VisitMut, VisitMutWith}; static HOIST_METHODS: phf::Set<&str> = phf_set![ "mock", @@ -12,8 +12,8 @@ static HOIST_METHODS: phf::Set<&str> = phf_set![ "deepUnmock" ]; -pub fn jest() -> impl Fold + VisitMut { - as_folder(Jest::default()) +pub fn jest() -> impl Pass { + from_visit_mut(Jest::default()) } #[derive(Default)] diff --git a/crates/swc_ecma_transforms_base/src/fixer.rs b/crates/swc_ecma_transforms_base/src/fixer.rs index 9c21d8f0ae91..119df267ebbf 100644 --- a/crates/swc_ecma_transforms_base/src/fixer.rs +++ b/crates/swc_ecma_transforms_base/src/fixer.rs @@ -5,15 +5,15 @@ use rustc_hash::FxHasher; use swc_common::{comments::Comments, util::take::Take, Span, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::stack_size::maybe_grow_default; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Pass, VisitMut, VisitMutWith}; /// Fixes ast nodes before printing so semantics are preserved. /// /// You don't have to bother to create appropriate parenthesis. /// The pass will insert parenthesis as needed. In other words, it's /// okay to store `a * (b + c)` as `Bin { a * Bin { b + c } }`. -pub fn fixer(comments: Option<&dyn Comments>) -> impl '_ + Fold + VisitMut { - as_folder(Fixer { +pub fn fixer(comments: Option<&dyn Comments>) -> impl '_ + Pass { + from_visit_mut(Fixer { comments, ctx: Default::default(), span_map: Default::default(), @@ -23,8 +23,8 @@ pub fn fixer(comments: Option<&dyn Comments>) -> impl '_ + Fold + VisitMut { }) } -pub fn paren_remover(comments: Option<&dyn Comments>) -> impl '_ + Fold + VisitMut { - as_folder(Fixer { +pub fn paren_remover(comments: Option<&dyn Comments>) -> impl '_ + Pass { + from_visit_mut(Fixer { comments, ctx: Default::default(), span_map: Default::default(), From c40f40a9487fa7877e0c8792c03af713536095b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 13:51:47 +0900 Subject: [PATCH 008/186] Fix `swc_ecma_visit` --- crates/swc_ecma_visit/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 921e48a60d00..dacc1860da32 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -80,10 +80,7 @@ where } } -pub fn from_fn(f: impl FnMut(&mut Program)) -> impl Pass -where - V: Fold, -{ +pub fn from_fn(f: impl FnMut(&mut Program)) -> impl Pass { FnPass { f } } From 4c2fc701a21a382134123aaa5e33ef675a73f371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 13:54:09 +0900 Subject: [PATCH 009/186] Make `Pass` take `self` --- crates/swc_ecma_visit/src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index dacc1860da32..66de4955cb5f 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -17,7 +17,7 @@ mod generated; /// A map from the [Program] to the [Program] pub trait Pass { - fn process(&mut self, program: &mut Program); + fn process(self, program: &mut Program); } pub fn from_fold(pass: V) -> impl Pass @@ -35,7 +35,7 @@ impl Pass for FoldPass where V: Fold, { - fn process(&mut self, program: &mut Program) { + fn process(mut self, program: &mut Program) { program.map_with_mut(|p| p.fold_with(&mut self.pass)); } } @@ -55,7 +55,7 @@ impl Pass for VisitMutPass where V: VisitMut, { - fn process(&mut self, program: &mut Program) { + fn process(mut self, program: &mut Program) { program.visit_mut_with(&mut self.pass); } } @@ -75,12 +75,12 @@ impl Pass for VisitorPass where V: Visit, { - fn process(&mut self, program: &mut Program) { + fn process(mut self, program: &mut Program) { program.visit_with(&mut self.pass); } } -pub fn from_fn(f: impl FnMut(&mut Program)) -> impl Pass { +pub fn from_fn(f: impl FnOnce(&mut Program)) -> impl Pass { FnPass { f } } @@ -90,9 +90,9 @@ struct FnPass { impl Pass for FnPass where - F: FnMut(&mut Program), + F: FnOnce(&mut Program), { - fn process(&mut self, program: &mut Program) { + fn process(self, program: &mut Program) { (self.f)(program); } } From 9db41e8077ed38b4d4fb1388aafe03641b87bee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 13:56:39 +0900 Subject: [PATCH 010/186] DropSpan --- crates/swc_ecma_utils/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/swc_ecma_utils/src/lib.rs b/crates/swc_ecma_utils/src/lib.rs index 3e5f07b0444d..61229602a7ec 100644 --- a/crates/swc_ecma_utils/src/lib.rs +++ b/crates/swc_ecma_utils/src/lib.rs @@ -22,7 +22,7 @@ use swc_common::{ }; use swc_ecma_ast::*; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, visit_mut_obj_and_computed, visit_obj_and_computed, + noop_visit_mut_type, noop_visit_type, visit_mut_obj_and_computed, visit_obj_and_computed, Pass, Visit, VisitMut, VisitMutWith, VisitWith, }; use tracing::trace; @@ -2400,6 +2400,13 @@ where } pub struct DropSpan; + +impl Pass for DropSpan { + fn process(mut self, program: &mut Program) { + program.visit_mut_with(&mut self); + } +} + impl VisitMut for DropSpan { fn visit_mut_span(&mut self, span: &mut Span) { *span = DUMMY_SP; From 74a88a5848ca1c661ace55cc318d5069927a460e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 13:58:50 +0900 Subject: [PATCH 011/186] Fix hygiene --- crates/swc_ecma_transforms_base/src/hygiene/mod.rs | 13 ++++++++----- .../swc_ecma_transforms_base/src/hygiene/tests.rs | 14 ++++++++------ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs index f80bec258084..4fca7d682edd 100644 --- a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs +++ b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs @@ -1,7 +1,7 @@ -use swc_common::{chain, Mark}; +use swc_common::Mark; use swc_ecma_ast::*; use swc_ecma_utils::stack_size::maybe_grow_default; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_fn, noop_visit_mut_type, Pass, VisitMut, VisitMutWith}; pub use crate::rename::rename; use crate::rename::{renamer, Renamer}; @@ -28,7 +28,7 @@ pub struct Config { /// See [hygiene_with_config] for doc. Creates a `hygiene` pass with default /// value of [Config]. -pub fn hygiene() -> impl Fold + VisitMut + 'static { +pub fn hygiene() -> impl Pass { hygiene_with_config(Default::default()) } @@ -58,8 +58,11 @@ pub fn hygiene() -> impl Fold + VisitMut + 'static { /// ## Third phase /// /// At third phase, we rename all identifiers in the queue. -pub fn hygiene_with_config(config: Config) -> impl 'static + Fold + VisitMut { - chain!(renamer(config, HygieneRenamer), as_folder(HygieneRemover)) +pub fn hygiene_with_config(config: Config) -> impl 'static + Pass { + from_fn(move |program| { + renamer(config, HygieneRenamer).process(program); + program.visit_mut_with(&mut HygieneRemover); + }) } struct HygieneRenamer; diff --git a/crates/swc_ecma_transforms_base/src/hygiene/tests.rs b/crates/swc_ecma_transforms_base/src/hygiene/tests.rs index 0bb4980b83b2..2e4b77679e8d 100644 --- a/crates/swc_ecma_transforms_base/src/hygiene/tests.rs +++ b/crates/swc_ecma_transforms_base/src/hygiene/tests.rs @@ -2,7 +2,7 @@ use swc_atoms::JsWord; use swc_common::{collections::AHashMap, hygiene::*, DUMMY_SP}; use swc_ecma_parser::Syntax; use swc_ecma_utils::quote_ident; -use swc_ecma_visit::FoldWith; +use swc_ecma_visit::{Fold, FoldWith}; use testing::{assert_eq, DebugUsingDisplay}; use super::*; @@ -82,19 +82,21 @@ where F: FnOnce(&mut crate::tests::Tester<'_>) -> Result, { crate::tests::Tester::run(|tester| { - let module = op(tester)?; + let mut module = Program::Module(op(tester)?); let hygiene_src = tester.print(&module.clone().fold_with(&mut HygieneVisualizer)); println!("----- Hygiene -----\n{}", hygiene_src); - let module = module.fold_with(&mut hygiene_with_config(config())); + hygiene_with_config(config()).process(&mut module); let actual = tester.print(&module); let expected = { - let expected = tester.with_parser("expected.js", Syntax::default(), expected, |p| { - p.parse_module() - })?; + let expected = tester + .with_parser("expected.js", Syntax::default(), expected, |p| { + p.parse_module() + }) + .map(Program::Module)?; tester.print(&expected) }; From eadaef7f396e7e1fc193587040e7207fcaf0e974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 14:05:15 +0900 Subject: [PATCH 012/186] Expose visitor --- crates/swc_ecma_visit/src/lib.rs | 39 ++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 66de4955cb5f..447b1fc51df7 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -15,7 +15,11 @@ use swc_visit::{Repeat, Repeated}; pub use crate::generated::*; mod generated; -/// A map from the [Program] to the [Program] +/// A map from the [Program] to the [Program]. +/// +/// This trait is used to implement transformations. The implementor may decide +/// to implement [Fold] or [VisitMut] if the transform is fine to start from an +/// arbitrary node. pub trait Pass { fn process(self, program: &mut Program); } @@ -40,6 +44,15 @@ where } } +impl Fold for FoldPass +where + V: Fold, +{ + fn fold_program(&mut self, node: Program) -> Program { + self.pass.fold_program(node) + } +} + pub fn from_visit_mut(pass: V) -> impl Pass where V: VisitMut, @@ -60,18 +73,27 @@ where } } +impl VisitMut for VisitMutPass +where + V: VisitMut, +{ + fn visit_mut_program(&mut self, program: &mut Program) { + self.pass.visit_mut_program(program); + } +} + pub fn visitor(pass: V) -> impl Pass where V: Visit, { - VisitorPass { pass } + VisitPass { pass } } -struct VisitorPass { +struct VisitPass { pass: V, } -impl Pass for VisitorPass +impl Pass for VisitPass where V: Visit, { @@ -80,6 +102,15 @@ where } } +impl Visit for VisitPass +where + V: Visit, +{ + fn visit_program(&mut self, program: &Program) { + self.pass.visit_program(program); + } +} + pub fn from_fn(f: impl FnOnce(&mut Program)) -> impl Pass { FnPass { f } } From e03be5bf4e642ba26003d9fabb466a5795025e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:04:42 +0900 Subject: [PATCH 013/186] ProgramExt --- crates/swc_ecma_visit/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 447b1fc51df7..e5b064fb23a6 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -15,6 +15,22 @@ use swc_visit::{Repeat, Repeated}; pub use crate::generated::*; mod generated; +pub trait ProgramExt { + fn apply

(&mut self, pass: P) + where + P: Pass; +} + +impl ProgramExt for Program { + #[inline(always)] + fn apply

(&mut self, pass: P) + where + P: Pass, + { + pass.process(self); + } +} + /// A map from the [Program] to the [Program]. /// /// This trait is used to implement transformations. The implementor may decide From 0c1ca9fa42436b38af3b27b609ecd6209370fbc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:08:14 +0900 Subject: [PATCH 014/186] Move `Pass` to `swc_ecma_ast` --- crates/swc_ecma_ast/src/lib.rs | 19 +++++++++++++++++++ crates/swc_ecma_visit/src/lib.rs | 25 ------------------------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index b9502b737920..157c5e3696a6 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -90,6 +90,25 @@ mod source_map; mod stmt; mod typescript; +/// A map from the [Program] to the [Program]. +/// +/// This trait is used to implement transformations. The implementor may decide +/// to implement [Fold] or [VisitMut] if the transform is fine to start from an +/// arbitrary node. +pub trait Pass { + fn process(self, program: &mut Program); +} + +impl Program { + #[inline(always)] + pub fn apply

(&mut self, pass: P) + where + P: Pass, + { + pass.process(self); + } +} + /// Represents a invalid node. #[ast_node("Invalid")] #[derive(Eq, Default, Hash, Copy, EqIgnoreSpan)] diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index e5b064fb23a6..c53c8597d7aa 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -15,31 +15,6 @@ use swc_visit::{Repeat, Repeated}; pub use crate::generated::*; mod generated; -pub trait ProgramExt { - fn apply

(&mut self, pass: P) - where - P: Pass; -} - -impl ProgramExt for Program { - #[inline(always)] - fn apply

(&mut self, pass: P) - where - P: Pass, - { - pass.process(self); - } -} - -/// A map from the [Program] to the [Program]. -/// -/// This trait is used to implement transformations. The implementor may decide -/// to implement [Fold] or [VisitMut] if the transform is fine to start from an -/// arbitrary node. -pub trait Pass { - fn process(self, program: &mut Program); -} - pub fn from_fold(pass: V) -> impl Pass where V: Fold, From e01128c545d977bd7f72e1c989e9d3180186e9c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:10:52 +0900 Subject: [PATCH 015/186] More work --- crates/swc_ecma_ext_transforms/src/jest.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_ext_transforms/src/jest.rs b/crates/swc_ecma_ext_transforms/src/jest.rs index 6d41100f8ae9..51fb758e53de 100644 --- a/crates/swc_ecma_ext_transforms/src/jest.rs +++ b/crates/swc_ecma_ext_transforms/src/jest.rs @@ -2,7 +2,7 @@ use phf::phf_set; use swc_common::util::take::Take; use swc_ecma_ast::*; use swc_ecma_utils::{prepend_stmts, StmtLike}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Pass, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; static HOIST_METHODS: phf::Set<&str> = phf_set![ "mock", From 451916a8179bf529e2d591c6abc61936d4ddfd25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:10:57 +0900 Subject: [PATCH 016/186] More work --- crates/swc_ecma_utils/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_utils/src/lib.rs b/crates/swc_ecma_utils/src/lib.rs index 61229602a7ec..a00605e69739 100644 --- a/crates/swc_ecma_utils/src/lib.rs +++ b/crates/swc_ecma_utils/src/lib.rs @@ -22,7 +22,7 @@ use swc_common::{ }; use swc_ecma_ast::*; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, visit_mut_obj_and_computed, visit_obj_and_computed, Pass, + noop_visit_mut_type, noop_visit_type, visit_mut_obj_and_computed, visit_obj_and_computed, Visit, VisitMut, VisitMutWith, VisitWith, }; use tracing::trace; From 80490017b6c5bf6b99b82c0b17e43b27ef5e2365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:11:19 +0900 Subject: [PATCH 017/186] More work --- crates/swc_ecma_compat_common/src/regexp.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_common/src/regexp.rs b/crates/swc_ecma_compat_common/src/regexp.rs index 34feb947aacc..ba34b1377509 100644 --- a/crates/swc_ecma_compat_common/src/regexp.rs +++ b/crates/swc_ecma_compat_common/src/regexp.rs @@ -1,7 +1,7 @@ use swc_common::util::take::Take; -use swc_ecma_ast::{CallExpr, Expr, Lit, Regex}; +use swc_ecma_ast::{CallExpr, Expr, Lit, Pass, Regex}; use swc_ecma_utils::{quote_ident, ExprFactory}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Pass, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; pub fn regexp(config: Config) -> impl Pass { from_visit_mut(RegExp { config }) From a1a12264ae06e7165baa16870b070499c63975fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:11:25 +0900 Subject: [PATCH 018/186] More work --- crates/swc_ecma_transforms_base/src/rename/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_base/src/rename/mod.rs b/crates/swc_ecma_transforms_base/src/rename/mod.rs index f427d94fb503..51caa0d3a8d0 100644 --- a/crates/swc_ecma_transforms_base/src/rename/mod.rs +++ b/crates/swc_ecma_transforms_base/src/rename/mod.rs @@ -7,7 +7,7 @@ use swc_atoms::Atom; use swc_common::collections::AHashMap; use swc_ecma_ast::*; use swc_ecma_utils::stack_size::maybe_grow_default; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith, VisitWith}; +use swc_ecma_visit::{noop_visit_mut_type, Fold, VisitMut, VisitMutWith, VisitWith}; #[cfg(feature = "concurrent-renamer")] use self::renamer_concurrent::{Send, Sync}; From 92d18c8044650680d4ff8dcb7583c105e3d02d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:11:29 +0900 Subject: [PATCH 019/186] More work --- crates/swc_ecma_transforms_base/src/fixer.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_base/src/fixer.rs b/crates/swc_ecma_transforms_base/src/fixer.rs index 119df267ebbf..33f9cf60c1df 100644 --- a/crates/swc_ecma_transforms_base/src/fixer.rs +++ b/crates/swc_ecma_transforms_base/src/fixer.rs @@ -5,7 +5,7 @@ use rustc_hash::FxHasher; use swc_common::{comments::Comments, util::take::Take, Span, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::stack_size::maybe_grow_default; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Pass, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; /// Fixes ast nodes before printing so semantics are preserved. /// @@ -1178,7 +1178,6 @@ fn will_eat_else_token(s: &Stmt) -> bool { #[cfg(test)] mod tests { - use crate::pass::noop; fn run_test(from: &str, to: &str) { crate::tests::test_transform( From 3e2d52cdfde961ddea441b8c8165c04a4f9aeef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:11:33 +0900 Subject: [PATCH 020/186] More work --- .../swc_ecma_transforms_base/src/helpers/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/swc_ecma_transforms_base/src/helpers/mod.rs b/crates/swc_ecma_transforms_base/src/helpers/mod.rs index 18fb5907dbe8..30ede46eff51 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/mod.rs +++ b/crates/swc_ecma_transforms_base/src/helpers/mod.rs @@ -6,7 +6,7 @@ use swc_atoms::JsWord; use swc_common::{FileName, FilePathMapping, Mark, SourceMap, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{prepend_stmts, quote_ident, DropSpan, ExprFactory}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; #[macro_export] macro_rules! enable_helper { @@ -420,8 +420,8 @@ define_helpers!(Helpers { using_ctx: (), }); -pub fn inject_helpers(global_mark: Mark) -> impl Fold + VisitMut { - as_folder(InjectHelpers { +pub fn inject_helpers(global_mark: Mark) -> impl Pass { + from_visit_mut(InjectHelpers { global_mark, helper_ctxt: None, }) @@ -631,7 +631,6 @@ impl VisitMut for Marker { #[cfg(test)] mod tests { - use swc_ecma_visit::FoldWith; use testing::DebugUsingDisplay; use super::*; @@ -643,7 +642,7 @@ mod tests { crate::tests::Tester::run(|tester| { HELPERS.set(&Helpers::new(true), || { let expected = tester.apply_transform( - as_folder(DropSpan), + DropSpan, "output.js", Default::default(), "import { _ as _throw } from \"@swc/helpers/_/_throw\"; @@ -655,9 +654,10 @@ _throw();", let tr = as_folder(inject_helpers(Mark::new())); let actual = tester - .apply_transform(tr, "input.js", Default::default(), input)? - .fold_with(&mut crate::hygiene::hygiene()) - .fold_with(&mut crate::fixer::fixer(None)); + .apply_transform(tr, "input.js", Default::default(), input) + .map(Program::Module)? + .apply(crate::hygiene::hygiene()) + .apply(crate::fixer::fixer(None)); if actual == expected { return Ok(()); From 084e65070f4f413e3706444889615fe064e7f5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:11:38 +0900 Subject: [PATCH 021/186] More work --- crates/swc_ecma_transforms_base/src/lib.rs | 1 - crates/swc_ecma_transforms_base/src/pass.rs | 29 -------------------- crates/swc_ecma_transforms_base/src/tests.rs | 16 +++++------ 3 files changed, 7 insertions(+), 39 deletions(-) delete mode 100644 crates/swc_ecma_transforms_base/src/pass.rs diff --git a/crates/swc_ecma_transforms_base/src/lib.rs b/crates/swc_ecma_transforms_base/src/lib.rs index 54696ee89274..67048e5baca1 100644 --- a/crates/swc_ecma_transforms_base/src/lib.rs +++ b/crates/swc_ecma_transforms_base/src/lib.rs @@ -13,7 +13,6 @@ pub mod feature; pub mod helpers; #[doc(hidden)] pub mod native; -pub mod pass; pub mod perf; pub mod quote; pub mod rename; diff --git a/crates/swc_ecma_transforms_base/src/pass.rs b/crates/swc_ecma_transforms_base/src/pass.rs deleted file mode 100644 index ac6465d165fb..000000000000 --- a/crates/swc_ecma_transforms_base/src/pass.rs +++ /dev/null @@ -1,29 +0,0 @@ -use swc_common::pass::CompilerPass; -pub use swc_common::pass::{Optional, Repeated}; -use swc_ecma_ast::{Module, Script}; -use swc_ecma_visit::Fold; - -pub fn noop() -> impl Fold { - Noop -} - -struct Noop; -impl Fold for Noop { - #[inline(always)] - fn fold_module(&mut self, m: Module) -> Module { - m - } - - #[inline(always)] - fn fold_script(&mut self, s: Script) -> Script { - s - } -} - -pub trait JsPass: CompilerPass + Fold {} - -impl JsPass for T where T: CompilerPass + Fold {} - -pub trait RepeatedJsPass: Repeated + JsPass {} - -impl RepeatedJsPass for T where T: Repeated + JsPass {} diff --git a/crates/swc_ecma_transforms_base/src/tests.rs b/crates/swc_ecma_transforms_base/src/tests.rs index 4cff1aefc944..625b1d798864 100644 --- a/crates/swc_ecma_transforms_base/src/tests.rs +++ b/crates/swc_ecma_transforms_base/src/tests.rs @@ -8,9 +8,9 @@ use swc_ecma_ast::*; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{error::Error, lexer::Lexer, Parser, StringInput, Syntax}; use swc_ecma_utils::DropSpan; -use swc_ecma_visit::{as_folder, Fold, FoldWith}; +use swc_ecma_visit::{as_folder, Fold, FoldWith, Pass}; -use crate::{fixer::fixer, helpers::HELPERS, hygiene::hygiene_with_config}; +use crate::{fixer::fixer, helpers::HELPERS, hygiene::hygiene_with_config, pass::JsPass}; pub struct Tester<'a> { pub cm: Lrc, @@ -84,7 +84,7 @@ impl Tester<'_> { Ok(stmts.pop().unwrap()) } - pub fn apply_transform( + pub fn apply_transform( &mut self, mut tr: T, name: &str, @@ -108,14 +108,12 @@ impl Tester<'_> { res? }; - let module = module - .fold_with(&mut tr) - .fold_with(&mut as_folder(DropSpan {})); + let module = Program::Module(module).apply(tr).apply(DropSpan); Ok(module) } - pub fn print(&mut self, module: &Module) -> String { + pub fn print(&mut self, program: &Program) -> String { let mut buf = Vec::new(); { let mut emitter = Emitter { @@ -131,7 +129,7 @@ impl Tester<'_> { }; // println!("Emitting: {:?}", module); - emitter.emit_module(module).unwrap(); + emitter.emit_program(program).unwrap(); } let s = String::from_utf8_lossy(&buf); @@ -158,7 +156,7 @@ pub(crate) fn test_transform( hygiene_config: impl FnOnce() -> crate::hygiene::Config, ) where F: FnOnce(&mut Tester) -> P, - P: Fold, + P: Pass, { crate::tests::Tester::run(|tester| { let expected = tester.apply_transform( From ff363c86aae247ca47e43aed9a1fcf4b4eba348a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:17:16 +0900 Subject: [PATCH 022/186] Rename --- crates/swc_ecma_ast/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index 157c5e3696a6..1ab6e432f01b 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -100,13 +100,21 @@ pub trait Pass { } impl Program { - #[inline(always)] - pub fn apply

(&mut self, pass: P) + pub fn mutate

(&mut self, pass: P) where P: Pass, { pass.process(self); } + + #[inline(always)] + pub fn apply

(mut self, pass: P) -> Self + where + P: Pass, + { + pass.process(&mut self); + self + } } /// Represents a invalid node. From a75bd5ff03c8e56c55a9e5dae6d1d3c857b1ed92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:17:46 +0900 Subject: [PATCH 023/186] More work --- crates/swc_ecma_transforms_base/src/helpers/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_base/src/helpers/mod.rs b/crates/swc_ecma_transforms_base/src/helpers/mod.rs index 30ede46eff51..4e1419b7e393 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/mod.rs +++ b/crates/swc_ecma_transforms_base/src/helpers/mod.rs @@ -634,7 +634,6 @@ mod tests { use testing::DebugUsingDisplay; use super::*; - use crate::pass::noop; #[test] fn external_helper() { @@ -652,7 +651,7 @@ _throw();", eprintln!("----- Actual -----"); - let tr = as_folder(inject_helpers(Mark::new())); + let tr = from_visit_mut(inject_helpers(Mark::new())); let actual = tester .apply_transform(tr, "input.js", Default::default(), input) .map(Program::Module)? From d600acc10a0d78dd4fcf8a748385758320c16096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:17:51 +0900 Subject: [PATCH 024/186] More work --- crates/swc_ecma_visit/tests/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_visit/tests/main.rs b/crates/swc_ecma_visit/tests/main.rs index 0fa7bf3e8e66..484394d16f89 100644 --- a/crates/swc_ecma_visit/tests/main.rs +++ b/crates/swc_ecma_visit/tests/main.rs @@ -1,4 +1,4 @@ -use swc_common::{chain, DUMMY_SP}; +use swc_common::DUMMY_SP; use swc_ecma_ast::*; use swc_ecma_visit::{NodeRef, Visit, VisitWith}; From 357f7f16ab5ecf9e79a6742f87836d7a20851291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:17:59 +0900 Subject: [PATCH 025/186] More work --- crates/swc_ecma_transforms_base/src/resolver/mod.rs | 6 +++--- crates/swc_ecma_transforms_base/src/resolver/tests.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/swc_ecma_transforms_base/src/resolver/mod.rs b/crates/swc_ecma_transforms_base/src/resolver/mod.rs index 599e600409b2..599b447b9479 100644 --- a/crates/swc_ecma_transforms_base/src/resolver/mod.rs +++ b/crates/swc_ecma_transforms_base/src/resolver/mod.rs @@ -7,7 +7,7 @@ use swc_common::{ use swc_ecma_ast::*; use swc_ecma_utils::{find_pat_ids, stack_size::maybe_grow_default}; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith, + from_visit_mut, noop_visit_mut_type, visit_mut_obj_and_computed, VisitMut, VisitMutWith, }; use tracing::{debug, span, Level}; @@ -134,7 +134,7 @@ pub fn resolver( unresolved_mark: Mark, top_level_mark: Mark, typescript: bool, -) -> impl 'static + Fold + VisitMut { +) -> impl 'static + Pass { assert_ne!( unresolved_mark, Mark::root(), @@ -144,7 +144,7 @@ pub fn resolver( let _ = SyntaxContext::empty().apply_mark(unresolved_mark); let _ = SyntaxContext::empty().apply_mark(top_level_mark); - as_folder(Resolver { + from_visit_mut(Resolver { current: Scope::new(ScopeKind::Fn, top_level_mark, None), ident_type: IdentType::Ref, in_type: false, diff --git a/crates/swc_ecma_transforms_base/src/resolver/tests.rs b/crates/swc_ecma_transforms_base/src/resolver/tests.rs index d2f9a068fb28..a324d829ef1f 100644 --- a/crates/swc_ecma_transforms_base/src/resolver/tests.rs +++ b/crates/swc_ecma_transforms_base/src/resolver/tests.rs @@ -48,7 +48,7 @@ fn run_test_with_config( config: impl FnOnce() -> crate::hygiene::Config, ) where F: FnOnce() -> V, - V: Fold, + V: Pass, { crate::tests::test_transform(syntax, |_| tr(), src, to, true, config); } From da8b380d2a82e3421e8793a958d82f053ea9a207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:18:55 +0900 Subject: [PATCH 026/186] Fix API --- crates/swc_ecma_visit/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index c53c8597d7aa..1b80a8e33882 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -15,7 +15,7 @@ use swc_visit::{Repeat, Repeated}; pub use crate::generated::*; mod generated; -pub fn from_fold(pass: V) -> impl Pass +pub fn from_fold(pass: V) -> impl Pass + Fold where V: Fold, { @@ -44,7 +44,7 @@ where } } -pub fn from_visit_mut(pass: V) -> impl Pass +pub fn from_visit_mut(pass: V) -> impl Pass + VisitMut where V: VisitMut, { @@ -73,7 +73,7 @@ where } } -pub fn visitor(pass: V) -> impl Pass +pub fn visitor(pass: V) -> impl Pass + Visit where V: Visit, { From 18ab6aa77e454ba780e133678fb87284dffdda91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:19:40 +0900 Subject: [PATCH 027/186] more --- .../swc_ecma_transforms_base/src/rename/mod.rs | 16 +++++++++------- crates/swc_ecma_transforms_base/src/tests.rs | 8 ++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/crates/swc_ecma_transforms_base/src/rename/mod.rs b/crates/swc_ecma_transforms_base/src/rename/mod.rs index 51caa0d3a8d0..6ee4db04be5c 100644 --- a/crates/swc_ecma_transforms_base/src/rename/mod.rs +++ b/crates/swc_ecma_transforms_base/src/rename/mod.rs @@ -7,7 +7,9 @@ use swc_atoms::Atom; use swc_common::collections::AHashMap; use swc_ecma_ast::*; use swc_ecma_utils::stack_size::maybe_grow_default; -use swc_ecma_visit::{noop_visit_mut_type, Fold, VisitMut, VisitMutWith, VisitWith}; +use swc_ecma_visit::{ + from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith, VisitWith, +}; #[cfg(feature = "concurrent-renamer")] use self::renamer_concurrent::{Send, Sync}; @@ -57,27 +59,27 @@ pub fn rename(map: &RenameMap) -> impl '_ + Fold + VisitMut { rename_with_config(map, Default::default()) } -pub fn rename_with_config(map: &RenameMap, config: Config) -> impl '_ + Fold + VisitMut { - as_folder(Operator { +pub fn rename_with_config(map: &RenameMap, config: Config) -> impl '_ + Pass + VisitMut { + from_visit_mut(Operator { rename: map, config, extra: Default::default(), }) } -pub fn remap(map: &FxHashMap, config: Config) -> impl '_ + Fold + VisitMut { - as_folder(Operator { +pub fn remap(map: &FxHashMap, config: Config) -> impl '_ + Pass + VisitMut { + from_visit_mut(Operator { rename: map, config, extra: Default::default(), }) } -pub fn renamer(config: Config, renamer: R) -> impl Fold + VisitMut +pub fn renamer(config: Config, renamer: R) -> impl Pass + VisitMut where R: Renamer, { - as_folder(RenamePass { + from_visit_mut(RenamePass { config, renamer, preserved: Default::default(), diff --git a/crates/swc_ecma_transforms_base/src/tests.rs b/crates/swc_ecma_transforms_base/src/tests.rs index 625b1d798864..cb1acbbc96e1 100644 --- a/crates/swc_ecma_transforms_base/src/tests.rs +++ b/crates/swc_ecma_transforms_base/src/tests.rs @@ -179,10 +179,10 @@ pub(crate) fn test_transform( _ => {} } - let actual = actual - .fold_with(&mut hygiene_with_config(hygiene_config())) - .fold_with(&mut fixer(None)) - .fold_with(&mut as_folder(DropSpan)); + let actual = Program::Module(actual) + .apply(hygiene_with_config(hygiene_config())) + .apply(fixer(None)) + .apply(DropSpan); if actual == expected { return Ok(()); From d61756a64525492961c100318e4c2d0e75775267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:21:17 +0900 Subject: [PATCH 028/186] more --- crates/swc_ecma_transforms_base/src/helpers/mod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/swc_ecma_transforms_base/src/helpers/mod.rs b/crates/swc_ecma_transforms_base/src/helpers/mod.rs index 4e1419b7e393..ab04c5791920 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/mod.rs +++ b/crates/swc_ecma_transforms_base/src/helpers/mod.rs @@ -651,10 +651,9 @@ _throw();", eprintln!("----- Actual -----"); - let tr = from_visit_mut(inject_helpers(Mark::new())); + let tr = inject_helpers(Mark::new()); let actual = tester - .apply_transform(tr, "input.js", Default::default(), input) - .map(Program::Module)? + .apply_transform(tr, "input.js", Default::default(), input)? .apply(crate::hygiene::hygiene()) .apply(crate::fixer::fixer(None)); @@ -704,7 +703,7 @@ function _throw(e) { Default::default(), |_| { enable_helper!(throw); - as_folder(inject_helpers(Mark::new())) + inject_helpers(Mark::new()) }, "let _throw = null", "function _throw(e) { From 02718ea1c2150d4f181b1bd7a7010db9af041eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:22:15 +0900 Subject: [PATCH 029/186] more --- crates/swc_ecma_transforms_base/src/helpers/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_base/src/helpers/mod.rs b/crates/swc_ecma_transforms_base/src/helpers/mod.rs index ab04c5791920..7fb140e1b3ba 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/mod.rs +++ b/crates/swc_ecma_transforms_base/src/helpers/mod.rs @@ -684,7 +684,7 @@ _throw();", Default::default(), |_| { enable_helper!(throw); - as_folder(inject_helpers(Mark::new())) + inject_helpers(Mark::new()) }, "'use strict'", "'use strict' @@ -738,7 +738,7 @@ let x = 4;", Default::default(), |_| { enable_helper!(using_ctx); - as_folder(inject_helpers(Mark::new())) + inject_helpers(Mark::new()) }, "let _throw = null", r#" From abb2d0c8b7ca874a843225a2d94aa6d192ceb9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:22:20 +0900 Subject: [PATCH 030/186] more --- crates/swc_ecma_transforms_base/src/hygiene/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs index 4fca7d682edd..5ec4104c9933 100644 --- a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs +++ b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs @@ -1,7 +1,7 @@ use swc_common::Mark; use swc_ecma_ast::*; use swc_ecma_utils::stack_size::maybe_grow_default; -use swc_ecma_visit::{from_fn, noop_visit_mut_type, Pass, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_fn, noop_visit_mut_type, VisitMut, VisitMutWith}; pub use crate::rename::rename; use crate::rename::{renamer, Renamer}; From 175e1657b912270174e10e11e571a52a3ed70595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:23:05 +0900 Subject: [PATCH 031/186] more --- crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs index 4391039f88ca..ceb6d4503506 100644 --- a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs +++ b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs @@ -4,7 +4,6 @@ use indexmap::IndexMap; use smallvec::SmallVec; use swc_atoms::JsWord; use swc_common::{ - chain, collections::{AHashMap, AHashSet}, util::take::Take, Mark, Spanned, SyntaxContext, DUMMY_SP, From b73cf27dee606d1e3f0762d76d36f4816af53893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:23:11 +0900 Subject: [PATCH 032/186] inline for AST --- crates/swc_ecma_ast/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index 1ab6e432f01b..eb0668cd9cd1 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -100,6 +100,7 @@ pub trait Pass { } impl Program { + #[inline(always)] pub fn mutate

(&mut self, pass: P) where P: Pass, From 9b6bee636ad5fe66814c5036806ce69df8a82656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:23:26 +0900 Subject: [PATCH 033/186] more --- crates/swc_ecma_compat_es2015/src/arrow.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/arrow.rs b/crates/swc_ecma_compat_es2015/src/arrow.rs index 9fa82b2bd090..b9f3021ae6b8 100644 --- a/crates/swc_ecma_compat_es2015/src/arrow.rs +++ b/crates/swc_ecma_compat_es2015/src/arrow.rs @@ -6,7 +6,9 @@ use swc_ecma_utils::{ function::{init_this, FnEnvHoister}, prepend_stmt, }; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, InjectVars, VisitMut, VisitMutWith}; +use swc_ecma_visit::{ + as_folder, from_visit_mut, noop_visit_mut_type, Fold, InjectVars, VisitMut, VisitMutWith, +}; use swc_trace_macro::swc_trace; /// Compile ES2015 arrow functions to ES5 @@ -57,8 +59,8 @@ use swc_trace_macro::swc_trace; /// }; /// console.log(bob.printFriends()); /// ``` -pub fn arrow(unresolved_mark: Mark) -> impl Fold + VisitMut + InjectVars { - as_folder(Arrow { +pub fn arrow(unresolved_mark: Mark) -> impl Pass + VisitMut + InjectVars { + from_visit_mut(Arrow { in_subclass: false, hoister: FnEnvHoister::new(SyntaxContext::empty().apply_mark(unresolved_mark)), }) From 91274fa2fad7a0d3b59ae78b5762c45c80a118dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:24:31 +0900 Subject: [PATCH 034/186] Improve Visitor API --- crates/swc_ecma_visit/src/lib.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 1b80a8e33882..a8ae01e8f4fb 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -243,6 +243,33 @@ pub trait InjectVars { fn take_vars(&mut self) -> Vec; } +impl InjectVars for FoldPass +where + V: Fold + InjectVars, +{ + fn take_vars(&mut self) -> Vec { + self.pass.take_vars() + } +} + +impl InjectVars for VisitMutPass +where + V: VisitMut + InjectVars, +{ + fn take_vars(&mut self) -> Vec { + self.pass.take_vars() + } +} + +impl InjectVars for VisitPass +where + V: Visit + InjectVars, +{ + fn take_vars(&mut self) -> Vec { + self.pass.take_vars() + } +} + /// Note: Ignoring more types is not considered as a breaking change. #[macro_export] macro_rules! noop_fold_type { From 9a2cbcdcce744416d413c394fa9b328ef08ed209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:25:08 +0900 Subject: [PATCH 035/186] Improve visitor API --- crates/swc_ecma_visit/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index a8ae01e8f4fb..6ab44b216936 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -15,14 +15,14 @@ use swc_visit::{Repeat, Repeated}; pub use crate::generated::*; mod generated; -pub fn from_fold(pass: V) -> impl Pass + Fold +pub fn from_fold(pass: V) -> FoldPass where V: Fold, { FoldPass { pass } } -struct FoldPass { +pub struct FoldPass { pass: V, } @@ -44,14 +44,14 @@ where } } -pub fn from_visit_mut(pass: V) -> impl Pass + VisitMut +pub fn from_visit_mut(pass: V) -> VisitMutPass where V: VisitMut, { VisitMutPass { pass } } -struct VisitMutPass { +pub struct VisitMutPass { pass: V, } @@ -73,14 +73,14 @@ where } } -pub fn visitor(pass: V) -> impl Pass + Visit +pub fn visitor(pass: V) -> VisitPass where V: Visit, { VisitPass { pass } } -struct VisitPass { +pub struct VisitPass { pass: V, } From 1d27315fcac59732df9868ae6ec7397b8d99cb31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:26:29 +0900 Subject: [PATCH 036/186] more --- crates/swc_ecma_compat_es2015/src/arrow.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/arrow.rs b/crates/swc_ecma_compat_es2015/src/arrow.rs index b9f3021ae6b8..c98cbacecedf 100644 --- a/crates/swc_ecma_compat_es2015/src/arrow.rs +++ b/crates/swc_ecma_compat_es2015/src/arrow.rs @@ -6,9 +6,7 @@ use swc_ecma_utils::{ function::{init_this, FnEnvHoister}, prepend_stmt, }; -use swc_ecma_visit::{ - as_folder, from_visit_mut, noop_visit_mut_type, Fold, InjectVars, VisitMut, VisitMutWith, -}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, InjectVars, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// Compile ES2015 arrow functions to ES5 From 377227cb6c929a8d4de3d86f2325e37e8c6efa53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:26:43 +0900 Subject: [PATCH 037/186] more --- crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs b/crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs index b6dfb9dc5c34..ec48667cbdfd 100644 --- a/crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs +++ b/crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs @@ -1,11 +1,11 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::IdentUsageFinder; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; -pub fn block_scoped_functions() -> impl Fold + VisitMut { - as_folder(BlockScopedFns) +pub fn block_scoped_functions() -> impl Pass { + from_visit_mut(BlockScopedFns) } #[derive(Clone, Copy)] From cce5e6fc7a7eb8c94d00c7eb6bf4fdeedecd5327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:26:50 +0900 Subject: [PATCH 038/186] more --- .../swc_ecma_transforms_base/src/rename/mod.rs | 2 +- crates/swc_ecma_transforms_base/src/tests.rs | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/crates/swc_ecma_transforms_base/src/rename/mod.rs b/crates/swc_ecma_transforms_base/src/rename/mod.rs index 6ee4db04be5c..a92b805a108c 100644 --- a/crates/swc_ecma_transforms_base/src/rename/mod.rs +++ b/crates/swc_ecma_transforms_base/src/rename/mod.rs @@ -55,7 +55,7 @@ pub trait Renamer: Send + Sync { pub type RenameMap = FxHashMap; -pub fn rename(map: &RenameMap) -> impl '_ + Fold + VisitMut { +pub fn rename(map: &RenameMap) -> impl '_ + Pass + VisitMut { rename_with_config(map, Default::default()) } diff --git a/crates/swc_ecma_transforms_base/src/tests.rs b/crates/swc_ecma_transforms_base/src/tests.rs index cb1acbbc96e1..c998cece3132 100644 --- a/crates/swc_ecma_transforms_base/src/tests.rs +++ b/crates/swc_ecma_transforms_base/src/tests.rs @@ -8,9 +8,9 @@ use swc_ecma_ast::*; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{error::Error, lexer::Lexer, Parser, StringInput, Syntax}; use swc_ecma_utils::DropSpan; -use swc_ecma_visit::{as_folder, Fold, FoldWith, Pass}; +use swc_ecma_visit::{Fold, FoldWith}; -use crate::{fixer::fixer, helpers::HELPERS, hygiene::hygiene_with_config, pass::JsPass}; +use crate::{fixer::fixer, helpers::HELPERS, hygiene::hygiene_with_config}; pub struct Tester<'a> { pub cm: Lrc, @@ -86,11 +86,11 @@ impl Tester<'_> { pub fn apply_transform( &mut self, - mut tr: T, + tr: T, name: &str, syntax: Syntax, src: &str, - ) -> Result { + ) -> Result { let fm = self .cm .new_source_file(FileName::Real(name.into()).into(), src.into()); @@ -159,12 +159,7 @@ pub(crate) fn test_transform( P: Pass, { crate::tests::Tester::run(|tester| { - let expected = tester.apply_transform( - as_folder(::swc_ecma_utils::DropSpan), - "output.js", - syntax, - expected, - )?; + let expected = tester.apply_transform(DropSpan, "output.js", syntax, expected)?; println!("----- Actual -----"); @@ -179,7 +174,7 @@ pub(crate) fn test_transform( _ => {} } - let actual = Program::Module(actual) + let actual = actual .apply(hygiene_with_config(hygiene_config())) .apply(fixer(None)) .apply(DropSpan); From c68cad74df382b876d97b9f937644e728e393f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:27:05 +0900 Subject: [PATCH 039/186] more --- crates/swc_ecma_visit/tests/main.rs | 30 +---------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/crates/swc_ecma_visit/tests/main.rs b/crates/swc_ecma_visit/tests/main.rs index 484394d16f89..4549d5a7dc44 100644 --- a/crates/swc_ecma_visit/tests/main.rs +++ b/crates/swc_ecma_visit/tests/main.rs @@ -1,34 +1,6 @@ use swc_common::DUMMY_SP; use swc_ecma_ast::*; -use swc_ecma_visit::{NodeRef, Visit, VisitWith}; - -#[test] -fn should_visit_program() { - struct Pass1<'a>(&'a mut usize); - struct Pass2; - - impl Visit for Pass1<'_> { - fn visit_program(&mut self, _program: &Program) { - *self.0 += 1; - } - } - - impl Visit for Pass2 {} - - let n = Program::Module(Module { - span: DUMMY_SP, - body: Vec::new(), - shebang: None, - }); - - let mut counter = 0; - let p1 = Pass1(&mut counter); - let p2 = Pass2; - let mut pass = chain!(p1, p2); - n.visit_with(&mut pass); - - assert_eq!(counter, 1); -} +use swc_ecma_visit::NodeRef; #[test] fn traverse_lookup() { From 46bc407e5f63095a4319ddc2ebab2bed42188c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:29:38 +0900 Subject: [PATCH 040/186] Replace --- crates/swc/src/builder.rs | 4 ++-- crates/swc/src/dropped_comments_preserver.rs | 4 ++-- crates/swc/tests/rust_api.rs | 4 ++-- crates/swc_cli_impl/src/commands/plugin.rs | 6 +++--- .../swc_ecma_compat_bugfixes/src/edge_default_param.rs | 4 ++-- ..._id_destructuring_collision_in_function_expression.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/classes/mod.rs | 5 +++-- crates/swc_ecma_compat_es2015/src/computed_props.rs | 5 +++-- crates/swc_ecma_compat_es2015/src/destructuring.rs | 5 +++-- crates/swc_ecma_compat_es2015/src/duplicate_keys.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/for_of.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/function_name.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/generator.rs | 5 +++-- crates/swc_ecma_compat_es2015/src/instanceof.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/new_target.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/object_super.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/parameters.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/shorthand_property.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/spread.rs | 5 +++-- crates/swc_ecma_compat_es2015/src/sticky_regex.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/template_literal.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/typeof_symbol.rs | 4 ++-- crates/swc_ecma_compat_es2016/src/exponentiation.rs | 4 ++-- crates/swc_ecma_compat_es2017/src/async_to_generator.rs | 5 +++-- crates/swc_ecma_compat_es2018/src/object_rest_spread.rs | 6 +++--- .../swc_ecma_compat_es2019/src/optional_catch_binding.rs | 8 ++++---- .../swc_ecma_compat_es2020/src/export_namespace_from.rs | 4 ++-- crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs | 4 ++-- crates/swc_ecma_compat_es2020/src/optional_chaining.rs | 4 ++-- crates/swc_ecma_compat_es2021/src/logical_assignments.rs | 4 ++-- .../swc_ecma_compat_es2022/src/class_properties/mod.rs | 5 +++-- crates/swc_ecma_compat_es2022/src/private_in_object.rs | 4 ++-- crates/swc_ecma_compat_es2022/src/static_blocks.rs | 4 ++-- crates/swc_ecma_compat_es3/src/reserved_word.rs | 4 ++-- crates/swc_ecma_minifier/src/compress/mod.rs | 6 +++--- crates/swc_ecma_minifier/src/compress/util/mod.rs | 9 ++++++--- crates/swc_ecma_minifier/src/util/unit.rs | 8 ++++---- crates/swc_ecma_preset_env/src/lib.rs | 4 ++-- crates/swc_ecma_preset_env/tests/test.rs | 6 +++--- crates/swc_ecma_transforms_base/tests/fixture.rs | 6 +++--- .../src/class_fields_use_set.rs | 4 ++-- crates/swc_ecma_transforms_compat/src/reserved_words.rs | 4 ++-- .../tests/es2015_block_scoping.rs | 4 ++-- crates/swc_ecma_transforms_module/src/amd.rs | 4 ++-- crates/swc_ecma_transforms_module/src/common_js.rs | 4 ++-- crates/swc_ecma_transforms_module/src/import_analysis.rs | 4 ++-- crates/swc_ecma_transforms_module/src/rewriter.rs | 4 ++-- crates/swc_ecma_transforms_module/src/umd.rs | 4 ++-- .../src/const_modules.rs | 4 ++-- .../src/inline_globals.rs | 6 +++--- .../swc_ecma_transforms_optimization/src/json_parse.rs | 4 ++-- .../src/simplify/branch/mod.rs | 4 ++-- .../src/simplify/branch/tests.rs | 4 ++-- .../src/simplify/const_propagation.rs | 4 ++-- .../src/simplify/dce/mod.rs | 5 +++-- .../src/simplify/expr/mod.rs | 4 ++-- .../src/simplify/expr/tests.rs | 4 ++-- .../src/simplify/inlining/mod.rs | 4 ++-- crates/swc_ecma_transforms_optimization/tests/fixture.rs | 4 ++-- .../swc_ecma_transforms_proposal/src/decorator_impl.rs | 4 ++-- .../swc_ecma_transforms_proposal/src/decorators/mod.rs | 6 +++--- .../src/explicit_resource_management.rs | 4 ++-- .../src/export_default_from.rs | 4 ++-- .../src/import_assertions.rs | 4 ++-- .../tests/decorator_evanw.rs | 4 ++-- crates/swc_ecma_transforms_react/src/display_name/mod.rs | 4 ++-- crates/swc_ecma_transforms_react/src/jsx/mod.rs | 4 ++-- crates/swc_ecma_transforms_react/src/jsx_self/mod.rs | 4 ++-- crates/swc_ecma_transforms_react/src/jsx_src/mod.rs | 4 ++-- .../src/pure_annotations/mod.rs | 4 ++-- crates/swc_ecma_transforms_react/src/refresh/mod.rs | 4 ++-- crates/swc_ecma_transforms_testing/src/lib.rs | 8 ++++---- crates/swc_ecma_transforms_typescript/src/transform.rs | 5 +++-- crates/swc_ecma_transforms_typescript/src/typescript.rs | 6 +++--- .../tests/fixture/swc_internal_plugin/src/lib.rs | 5 +++-- .../e2e/fixtures/plugin_transform_schema_v1/src/lib.rs | 2 +- .../fixtures/plugin_transform_schema_vtest/src/lib.rs | 2 +- 78 files changed, 182 insertions(+), 169 deletions(-) diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index cf91fc8fc4a3..06fb43e0f32b 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -22,7 +22,7 @@ use swc_ecma_transforms::{ pass::Optional, resolver, Assumptions, }; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; use crate::config::{GlobalPassOption, JsMinifyOptions, ModuleConfig}; @@ -349,7 +349,7 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { feature_flag, resolver, ), - as_folder(MinifierPass { + from_visit_mut(MinifierPass { options: self.minify, cm: self.cm.clone(), comments, diff --git a/crates/swc/src/dropped_comments_preserver.rs b/crates/swc/src/dropped_comments_preserver.rs index 0f3478b641a7..f65ff6e64b84 100644 --- a/crates/swc/src/dropped_comments_preserver.rs +++ b/crates/swc/src/dropped_comments_preserver.rs @@ -3,7 +3,7 @@ use swc_common::{ BytePos, Span, DUMMY_SP, }; use swc_ecma_ast::{Module, Script}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; /// Preserves comments that would otherwise be dropped. /// @@ -19,7 +19,7 @@ use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWit pub fn dropped_comments_preserver( comments: Option, ) -> impl Fold + VisitMut { - as_folder(DroppedCommentsPreserver { + from_visit_mut(DroppedCommentsPreserver { comments, is_first_span: true, known_spans: Vec::new(), diff --git a/crates/swc/tests/rust_api.rs b/crates/swc/tests/rust_api.rs index 7111005e456b..78b5b0b3f4f8 100644 --- a/crates/swc/tests/rust_api.rs +++ b/crates/swc/tests/rust_api.rs @@ -6,7 +6,7 @@ use swc_common::{comments::SingleThreadedComments, FileName}; use swc_ecma_ast::*; use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax}; use swc_ecma_transforms::pass::noop; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, VisitMut}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut}; struct PanicOnVisit; @@ -49,7 +49,7 @@ fn test_visit_mut() { ..Default::default() }, SingleThreadedComments::default(), - |_| as_folder(PanicOnVisit), + |_| from_visit_mut(PanicOnVisit), |_| noop(), ); diff --git a/crates/swc_cli_impl/src/commands/plugin.rs b/crates/swc_cli_impl/src/commands/plugin.rs index 981355537e6d..04dd2c823bc6 100644 --- a/crates/swc_cli_impl/src/commands/plugin.rs +++ b/crates/swc_cli_impl/src/commands/plugin.rs @@ -238,7 +238,7 @@ build-wasm32 = "build --target wasm32-unknown-unknown" r##"use swc_core::ecma::{ ast::Program, transforms::testing::test_inline, - visit::{as_folder, FoldWith, VisitMut}, + visit::{from_visit_mut, FoldWith, VisitMut}, }; use swc_core::plugin::{plugin_transform, proxies::TransformPluginProgramMetadata}; @@ -267,7 +267,7 @@ impl VisitMut for TransformVisitor { /// Refer swc_plugin_macro to see how does it work internally. #[plugin_transform] pub fn process_transform(program: Program, _metadata: TransformPluginProgramMetadata) -> Program { - program.fold_with(&mut as_folder(TransformVisitor)) + program.fold_with(&mut from_visit_mut(TransformVisitor)) } // An example to test plugin transform. @@ -276,7 +276,7 @@ pub fn process_transform(program: Program, _metadata: TransformPluginProgramMeta // unless explicitly required to do so. test_inline!( Default::default(), - |_| as_folder(TransformVisitor), + |_| from_visit_mut(TransformVisitor), boo, // Input codes r#"console.log("transform");"#, diff --git a/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs b/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs index 4c04127b090b..267b50e12aa9 100644 --- a/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs +++ b/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs @@ -1,5 +1,5 @@ use swc_ecma_ast::*; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// A bugfix pass for Edge. @@ -9,7 +9,7 @@ use swc_trace_macro::swc_trace; /// browsers (Edge 16 & 17). Use this plugin instead of /// @babel/plugin-transform-parameters when targeting ES Modules. pub fn edge_default_param() -> impl Fold + VisitMut { - as_folder(EdgeDefaultParam::default()) + from_visit_mut(EdgeDefaultParam::default()) } #[derive(Default, Clone, Copy)] struct EdgeDefaultParam { diff --git a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs index 425f297863e0..6eb00d3fc5a5 100644 --- a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs +++ b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs @@ -4,11 +4,11 @@ use swc_atoms::JsWord; use swc_common::{collections::AHashSet, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_transforms_base::hygiene::rename; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn safari_id_destructuring_collision_in_function_expression() -> impl Fold + VisitMut { - as_folder(SafariIdDestructuringCollisionInFunctionExpression::default()) + from_visit_mut(SafariIdDestructuringCollisionInFunctionExpression::default()) } #[derive(Default, Clone)] diff --git a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs index ceb6d4503506..b6557cb91e3d 100644 --- a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs +++ b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs @@ -15,7 +15,7 @@ use swc_ecma_utils::{ ExprFactory, StmtLike, }; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith, + from_visit_mut, noop_visit_mut_type, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith, }; use swc_trace_macro::swc_trace; @@ -35,7 +35,7 @@ mod vars; /// } /// ``` pub fn block_scoping(unresolved_mark: Mark) -> impl VisitMut + Fold { - as_folder(chain!( + from_visit_mut(chain!( self::vars::block_scoped_vars(), BlockScoping { unresolved_mark, diff --git a/crates/swc_ecma_compat_es2015/src/classes/mod.rs b/crates/swc_ecma_compat_es2015/src/classes/mod.rs index bf6136881586..6073c2812aec 100644 --- a/crates/swc_ecma_compat_es2015/src/classes/mod.rs +++ b/crates/swc_ecma_compat_es2015/src/classes/mod.rs @@ -15,7 +15,8 @@ use swc_ecma_utils::{ ExprFactory, ModuleItemLike, StmtLike, }; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, + from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + VisitWith, }; use swc_trace_macro::swc_trace; @@ -28,7 +29,7 @@ mod constructor; mod prop_name; pub fn classes(config: Config) -> impl Fold + VisitMut { - as_folder(Classes { + from_visit_mut(Classes { in_strict: false, config, diff --git a/crates/swc_ecma_compat_es2015/src/computed_props.rs b/crates/swc_ecma_compat_es2015/src/computed_props.rs index 16eee883f22c..529e241b4cc9 100644 --- a/crates/swc_ecma_compat_es2015/src/computed_props.rs +++ b/crates/swc_ecma_compat_es2015/src/computed_props.rs @@ -4,7 +4,8 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::helper; use swc_ecma_utils::{quote_ident, ExprFactory, StmtLike}; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, + from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + VisitWith, }; use swc_trace_macro::swc_trace; @@ -40,7 +41,7 @@ use swc_trace_macro::swc_trace; /// TODO(kdy1): cache reference like (_f = f, mutatorMap[_f].get = function(){}) /// instead of (mutatorMap[f].get = function(){} pub fn computed_properties(c: Config) -> impl Fold { - as_folder(ComputedProps { + from_visit_mut(ComputedProps { c, ..Default::default() }) diff --git a/crates/swc_ecma_compat_es2015/src/destructuring.rs b/crates/swc_ecma_compat_es2015/src/destructuring.rs index fc3d994b854c..508b8cf7f56b 100644 --- a/crates/swc_ecma_compat_es2015/src/destructuring.rs +++ b/crates/swc_ecma_compat_es2015/src/destructuring.rs @@ -11,7 +11,8 @@ use swc_ecma_utils::{ prop_name_to_expr, quote_ident, ExprFactory, StmtLike, }; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, + from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + VisitWith, }; use swc_trace_macro::swc_trace; @@ -37,7 +38,7 @@ use swc_trace_macro::swc_trace; /// rest = _arr2.slice(2); /// ``` pub fn destructuring(c: Config) -> impl Fold + VisitMut { - as_folder(Destructuring { c }) + from_visit_mut(Destructuring { c }) } struct Destructuring { diff --git a/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs b/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs index 0fe2d99392c9..42244653a37a 100644 --- a/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs +++ b/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs @@ -3,11 +3,11 @@ use swc_common::{collections::AHashSet, Spanned}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::quote_str; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn duplicate_keys() -> impl Fold + VisitMut { - as_folder(DuplicateKeys) + from_visit_mut(DuplicateKeys) } struct DuplicateKeys; diff --git a/crates/swc_ecma_compat_es2015/src/for_of.rs b/crates/swc_ecma_compat_es2015/src/for_of.rs index c04ec264126f..f60f29d0336c 100644 --- a/crates/swc_ecma_compat_es2015/src/for_of.rs +++ b/crates/swc_ecma_compat_es2015/src/for_of.rs @@ -11,7 +11,7 @@ use swc_ecma_transforms_macros::parallel; use swc_ecma_utils::{ alias_if_required, member_expr, prepend_stmt, private_ident, quote_ident, ExprFactory, }; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-for-of` @@ -49,7 +49,7 @@ use swc_trace_macro::swc_trace; /// } /// ``` pub fn for_of(c: Config) -> impl Fold + VisitMut { - as_folder(ForOf { + from_visit_mut(ForOf { c, top_level_vars: Default::default(), }) diff --git a/crates/swc_ecma_compat_es2015/src/function_name.rs b/crates/swc_ecma_compat_es2015/src/function_name.rs index 4ee03b5fa847..7dc572307308 100644 --- a/crates/swc_ecma_compat_es2015/src/function_name.rs +++ b/crates/swc_ecma_compat_es2015/src/function_name.rs @@ -2,7 +2,7 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{private_ident, IdentUsageFinder}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-function-name` @@ -23,7 +23,7 @@ use swc_trace_macro::swc_trace; /// var Foo = (class Foo {}); /// ``` pub fn function_name() -> impl 'static + Copy + Fold + VisitMut { - as_folder(FnName) + from_visit_mut(FnName) } #[derive(Clone, Copy)] diff --git a/crates/swc_ecma_compat_es2015/src/generator.rs b/crates/swc_ecma_compat_es2015/src/generator.rs index 346e0c660f91..bffdaa1ea7a9 100644 --- a/crates/swc_ecma_compat_es2015/src/generator.rs +++ b/crates/swc_ecma_compat_es2015/src/generator.rs @@ -17,7 +17,8 @@ use swc_ecma_utils::{ function::FnEnvHoister, private_ident, prop_name_to_expr_value, quote_ident, ExprFactory, }; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, + from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + VisitWith, }; use tracing::debug; @@ -26,7 +27,7 @@ pub fn generator(unresolved_mark: Mark, _comments: C) -> impl VisitMut + Fold where C: Comments, { - as_folder(Wrapper { + from_visit_mut(Wrapper { unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), }) } diff --git a/crates/swc_ecma_compat_es2015/src/instanceof.rs b/crates/swc_ecma_compat_es2015/src/instanceof.rs index 80557b182f19..b108137114c1 100644 --- a/crates/swc_ecma_compat_es2015/src/instanceof.rs +++ b/crates/swc_ecma_compat_es2015/src/instanceof.rs @@ -2,7 +2,7 @@ use swc_common::{util::take::Take, Span, Spanned}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Parallel}; use swc_ecma_utils::ExprFactory; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-instanceof` @@ -31,7 +31,7 @@ use swc_trace_macro::swc_trace; /// _instanceof(foo, Bar); /// ``` pub fn instance_of() -> impl Fold + VisitMut { - as_folder(InstanceOf) + from_visit_mut(InstanceOf) } struct InstanceOf; diff --git a/crates/swc_ecma_compat_es2015/src/new_target.rs b/crates/swc_ecma_compat_es2015/src/new_target.rs index d47bb3eacf0f..0d6aba86811e 100644 --- a/crates/swc_ecma_compat_es2015/src/new_target.rs +++ b/crates/swc_ecma_compat_es2015/src/new_target.rs @@ -5,12 +5,12 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{should_work, Check}; use swc_ecma_utils::{private_ident, quote_ident, ExprFactory}; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, }; use swc_trace_macro::swc_trace; pub fn new_target() -> impl Fold + VisitMut + CompilerPass { - as_folder(NewTarget { + from_visit_mut(NewTarget { ctx: Ctx::Constructor, }) } diff --git a/crates/swc_ecma_compat_es2015/src/object_super.rs b/crates/swc_ecma_compat_es2015/src/object_super.rs index f182a5ecd617..da96ab91e947 100644 --- a/crates/swc_ecma_compat_es2015/src/object_super.rs +++ b/crates/swc_ecma_compat_es2015/src/object_super.rs @@ -6,7 +6,7 @@ use swc_ecma_transforms_base::helper; use swc_ecma_utils::{ alias_ident_for, is_rest_arguments, prepend_stmt, private_ident, quote_ident, ExprFactory, }; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; struct ObjectSuper { @@ -14,7 +14,7 @@ struct ObjectSuper { } pub fn object_super() -> impl Fold + VisitMut { - as_folder(ObjectSuper { + from_visit_mut(ObjectSuper { extra_vars: Vec::new(), }) } diff --git a/crates/swc_ecma_compat_es2015/src/parameters.rs b/crates/swc_ecma_compat_es2015/src/parameters.rs index 91078a1d2233..098c6344135b 100644 --- a/crates/swc_ecma_compat_es2015/src/parameters.rs +++ b/crates/swc_ecma_compat_es2015/src/parameters.rs @@ -10,13 +10,13 @@ use swc_ecma_utils::{ function::{init_this, FnEnvHoister}, member_expr, prepend_stmt, prepend_stmts, private_ident, quote_ident, ExprFactory, }; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; use tracing::trace; pub fn parameters(c: Config, unresolved_mark: Mark) -> impl 'static + Fold { let unresolved_ctxt = SyntaxContext::empty().apply_mark(unresolved_mark); - as_folder(Params { + from_visit_mut(Params { c, unresolved_ctxt, hoister: FnEnvHoister::new(unresolved_ctxt), diff --git a/crates/swc_ecma_compat_es2015/src/shorthand_property.rs b/crates/swc_ecma_compat_es2015/src/shorthand_property.rs index f710e2bfe694..e79230173734 100644 --- a/crates/swc_ecma_compat_es2015/src/shorthand_property.rs +++ b/crates/swc_ecma_compat_es2015/src/shorthand_property.rs @@ -1,7 +1,7 @@ use swc_common::util::take::Take; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// Compile ES2015 shorthand properties to ES5 @@ -39,7 +39,7 @@ use swc_trace_macro::swc_trace; /// }; /// ``` pub fn shorthand() -> impl 'static + Fold + VisitMut { - as_folder(Shorthand) + from_visit_mut(Shorthand) } #[derive(Clone, Copy)] diff --git a/crates/swc_ecma_compat_es2015/src/spread.rs b/crates/swc_ecma_compat_es2015/src/spread.rs index f4276c53504a..c353d2014903 100644 --- a/crates/swc_ecma_compat_es2015/src/spread.rs +++ b/crates/swc_ecma_compat_es2015/src/spread.rs @@ -9,12 +9,13 @@ use swc_ecma_utils::{ alias_ident_for, member_expr, prepend_stmt, quote_ident, ExprFactory, StmtLike, }; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, + from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + VisitWith, }; use swc_trace_macro::swc_trace; pub fn spread(c: Config) -> impl Fold + VisitMut { - as_folder(Spread { + from_visit_mut(Spread { c, vars: Default::default(), }) diff --git a/crates/swc_ecma_compat_es2015/src/sticky_regex.rs b/crates/swc_ecma_compat_es2015/src/sticky_regex.rs index ee76f7936df8..a2eeaa65482a 100644 --- a/crates/swc_ecma_compat_es2015/src/sticky_regex.rs +++ b/crates/swc_ecma_compat_es2015/src/sticky_regex.rs @@ -1,7 +1,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{quote_ident, ExprFactory}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// Compile ES2015 sticky regex to an ES5 RegExp constructor @@ -19,7 +19,7 @@ use swc_trace_macro::swc_trace; /// new RegExp("o+", "y") /// ``` pub fn sticky_regex() -> impl 'static + Fold + VisitMut { - as_folder(StickyRegex) + from_visit_mut(StickyRegex) } struct StickyRegex; diff --git a/crates/swc_ecma_compat_es2015/src/template_literal.rs b/crates/swc_ecma_compat_es2015/src/template_literal.rs index 3f423ead6b68..e1ca147b0672 100644 --- a/crates/swc_ecma_compat_es2015/src/template_literal.rs +++ b/crates/swc_ecma_compat_es2015/src/template_literal.rs @@ -6,11 +6,11 @@ use swc_common::{util::take::Take, BytePos, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Parallel}; use swc_ecma_utils::{is_literal, prepend_stmts, private_ident, quote_ident, ExprFactory}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn template_literal(c: Config) -> impl Fold + VisitMut { - as_folder(TemplateLiteral { + from_visit_mut(TemplateLiteral { c, ..Default::default() }) diff --git a/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs b/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs index d34e91e812f3..347048ea62a9 100644 --- a/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs +++ b/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs @@ -2,11 +2,11 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Parallel}; use swc_ecma_utils::{quote_str, ExprFactory}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn typeof_symbol() -> impl VisitMut + Fold { - as_folder(TypeOfSymbol) + from_visit_mut(TypeOfSymbol) } #[derive(Clone, Copy)] diff --git a/crates/swc_ecma_compat_es2016/src/exponentiation.rs b/crates/swc_ecma_compat_es2016/src/exponentiation.rs index 84080545cb3a..6ac36ff83f62 100644 --- a/crates/swc_ecma_compat_es2016/src/exponentiation.rs +++ b/crates/swc_ecma_compat_es2016/src/exponentiation.rs @@ -3,7 +3,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{ParExplode, Parallel}; use swc_ecma_transforms_macros::parallel; use swc_ecma_utils::{member_expr, private_ident, ExprFactory}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-exponentiation-operator` @@ -26,7 +26,7 @@ use swc_trace_macro::swc_trace; /// x = Math.pow(x, 3); /// ``` pub fn exponentiation() -> impl Fold + VisitMut { - as_folder(Exponentiation::default()) + from_visit_mut(Exponentiation::default()) } #[derive(Default)] diff --git a/crates/swc_ecma_compat_es2017/src/async_to_generator.rs b/crates/swc_ecma_compat_es2017/src/async_to_generator.rs index 1c62f0d86172..972e3a17062f 100644 --- a/crates/swc_ecma_compat_es2017/src/async_to_generator.rs +++ b/crates/swc_ecma_compat_es2017/src/async_to_generator.rs @@ -11,7 +11,8 @@ use swc_ecma_utils::{ prepend_stmt, private_ident, quote_ident, ExprFactory, Remapper, StmtLike, }; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, + from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + VisitWith, }; use swc_trace_macro::swc_trace; @@ -36,7 +37,7 @@ use swc_trace_macro::swc_trace; /// }); /// ``` pub fn async_to_generator(c: Config, unresolved_mark: Mark) -> impl Fold + VisitMut { - as_folder(AsyncToGenerator { + from_visit_mut(AsyncToGenerator { c, in_subclass: false, unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), diff --git a/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs b/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs index 2024e160e849..f71adf6fcb0c 100644 --- a/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs +++ b/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs @@ -1,6 +1,6 @@ use serde::Deserialize; use swc_common::chain; -use swc_ecma_visit::{as_folder, Fold, VisitMut}; +use swc_ecma_visit::{from_visit_mut, Fold, VisitMut}; use super::{object_rest::ObjectRest, object_spread::ObjectSpread}; @@ -10,11 +10,11 @@ use super::{object_rest::ObjectRest, object_spread::ObjectSpread}; /// `@babel/plugin-proposal-object-rest-spread` pub fn object_rest_spread(config: Config) -> impl Fold + VisitMut { chain!( - as_folder(ObjectRest { + from_visit_mut(ObjectRest { config, ..Default::default() }), - as_folder(ObjectSpread { config }) + from_visit_mut(ObjectSpread { config }) ) } diff --git a/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs b/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs index 354a7520d0c5..2fbe46005aed 100644 --- a/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs +++ b/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs @@ -1,12 +1,12 @@ use swc_ecma_ast::*; use swc_ecma_utils::private_ident; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; struct OptionalCatchBinding; pub fn optional_catch_binding() -> impl Fold + VisitMut { - as_folder(OptionalCatchBinding) + from_visit_mut(OptionalCatchBinding) } #[swc_trace] @@ -28,14 +28,14 @@ mod tests { use swc_common::{chain, Mark}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::test; - use swc_ecma_visit::{as_folder, Fold}; + use swc_ecma_visit::{from_visit_mut, Fold}; use crate::optional_catch_binding::OptionalCatchBinding; pub fn tr() -> impl Fold { chain!( resolver(Mark::new(), Mark::new(), false), - as_folder(OptionalCatchBinding) + from_visit_mut(OptionalCatchBinding) ) } diff --git a/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs b/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs index 6a5b9c890aa5..d92c309c5f4f 100644 --- a/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs +++ b/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs @@ -1,11 +1,11 @@ use swc_atoms::JsWord; use swc_ecma_ast::*; use swc_ecma_utils::private_ident; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut}; use swc_trace_macro::swc_trace; pub fn export_namespace_from() -> impl Fold + VisitMut { - as_folder(ExportNamespaceFrom) + from_visit_mut(ExportNamespaceFrom) } struct ExportNamespaceFrom; diff --git a/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs b/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs index 0014262eef2b..2da91521cb6b 100644 --- a/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs +++ b/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs @@ -4,11 +4,11 @@ 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::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn nullish_coalescing(c: Config) -> impl Fold + VisitMut + 'static { - as_folder(NullishCoalescing { + from_visit_mut(NullishCoalescing { c, ..Default::default() }) diff --git a/crates/swc_ecma_compat_es2020/src/optional_chaining.rs b/crates/swc_ecma_compat_es2020/src/optional_chaining.rs index 66c74a203cdf..0673bd9b21e6 100644 --- a/crates/swc_ecma_compat_es2020/src/optional_chaining.rs +++ b/crates/swc_ecma_compat_es2020/src/optional_chaining.rs @@ -1,10 +1,10 @@ use serde::Deserialize; use swc_common::Mark; use swc_ecma_compat_es2022::optional_chaining_impl::optional_chaining_impl; -use swc_ecma_visit::{as_folder, Fold, VisitMut}; +use swc_ecma_visit::{from_visit_mut, Fold, VisitMut}; pub fn optional_chaining(c: Config, unresolved_mark: Mark) -> impl Fold + VisitMut { - as_folder(optional_chaining_impl( + from_visit_mut(optional_chaining_impl( swc_ecma_compat_es2022::optional_chaining_impl::Config { no_document_all: c.no_document_all, pure_getter: c.pure_getter, diff --git a/crates/swc_ecma_compat_es2021/src/logical_assignments.rs b/crates/swc_ecma_compat_es2021/src/logical_assignments.rs index 22b0f8856af2..1b36d75b3885 100644 --- a/crates/swc_ecma_compat_es2021/src/logical_assignments.rs +++ b/crates/swc_ecma_compat_es2021/src/logical_assignments.rs @@ -4,11 +4,11 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{alias_ident_for, prepend_stmt}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn logical_assignments() -> impl Fold + VisitMut { - as_folder(Operators::default()) + from_visit_mut(Operators::default()) } #[derive(Debug, Default)] diff --git a/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs b/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs index 48ad1b8a2e2f..e2a02e081470 100644 --- a/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs +++ b/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs @@ -12,7 +12,8 @@ use swc_ecma_utils::{ ModuleItemLike, StmtLike, }; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, + from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + VisitWith, }; use swc_trace_macro::swc_trace; @@ -41,7 +42,7 @@ mod used_name; /// /// We use custom helper to handle export default class pub fn class_properties(config: Config, unresolved_mark: Mark) -> impl Fold + VisitMut { - as_folder(ClassProperties { + from_visit_mut(ClassProperties { c: config, private: PrivateRecord::new(), extra: ClassExtra::default(), diff --git a/crates/swc_ecma_compat_es2022/src/private_in_object.rs b/crates/swc_ecma_compat_es2022/src/private_in_object.rs index f0bfe4a97062..0ac8b4597f4c 100644 --- a/crates/swc_ecma_compat_es2022/src/private_in_object.rs +++ b/crates/swc_ecma_compat_es2022/src/private_in_object.rs @@ -12,12 +12,12 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::pass::JsPass; use swc_ecma_utils::{default_constructor, prepend_stmt, private_ident, quote_ident, ExprFactory}; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, + from_visit_mut, noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, }; /// https://github.com/tc39/proposal-private-fields-in-in pub fn private_in_object() -> impl JsPass { - as_folder(PrivateInObject::default()) + from_visit_mut(PrivateInObject::default()) } #[derive(Debug)] diff --git a/crates/swc_ecma_compat_es2022/src/static_blocks.rs b/crates/swc_ecma_compat_es2022/src/static_blocks.rs index 1d4f109ab831..25a4cd811a12 100644 --- a/crates/swc_ecma_compat_es2022/src/static_blocks.rs +++ b/crates/swc_ecma_compat_es2022/src/static_blocks.rs @@ -2,7 +2,7 @@ use swc_atoms::JsWord; use swc_common::{collections::AHashSet, util::take::Take, Mark, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::ExprFactory; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; struct ClassStaticBlock { @@ -10,7 +10,7 @@ struct ClassStaticBlock { } pub fn static_blocks(static_block_mark: Mark) -> impl Fold + VisitMut { - as_folder(ClassStaticBlock { static_block_mark }) + from_visit_mut(ClassStaticBlock { static_block_mark }) } #[swc_trace] diff --git a/crates/swc_ecma_compat_es3/src/reserved_word.rs b/crates/swc_ecma_compat_es3/src/reserved_word.rs index ada479f5d787..af9348c5851c 100644 --- a/crates/swc_ecma_compat_es3/src/reserved_word.rs +++ b/crates/swc_ecma_compat_es3/src/reserved_word.rs @@ -1,6 +1,6 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; /// babel: `@babel/plugin-transform-reserved-words` /// @@ -20,7 +20,7 @@ use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWit /// var x = _abstract + 1; /// ``` pub fn reserved_words(preserve_import: bool) -> impl VisitMut + Fold { - as_folder(ReservedWord { preserve_import }) + from_visit_mut(ReservedWord { preserve_import }) } struct ReservedWord { pub preserve_import: bool, diff --git a/crates/swc_ecma_minifier/src/compress/mod.rs b/crates/swc_ecma_minifier/src/compress/mod.rs index af294241e8ba..d24145486ae0 100644 --- a/crates/swc_ecma_minifier/src/compress/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/mod.rs @@ -15,7 +15,7 @@ use swc_ecma_transforms_optimization::simplify::{ dead_branch_remover, expr_simplifier, ExprSimplifierConfig, }; use swc_ecma_usage_analyzer::{analyzer::UsageAnalyzer, marks::Marks}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, VisitMut, VisitMutWith, VisitWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith, VisitWith}; use swc_timer::timer; use tracing::{debug, error}; @@ -55,10 +55,10 @@ where }; chain!( - as_folder(compressor), + from_visit_mut(compressor), Optional { enabled: options.evaluate || options.side_effects, - visitor: as_folder(expr_simplifier( + visitor: from_visit_mut(expr_simplifier( marks.unresolved_mark, ExprSimplifierConfig {} )) diff --git a/crates/swc_ecma_minifier/src/compress/util/mod.rs b/crates/swc_ecma_minifier/src/compress/util/mod.rs index b6397b1fcc97..8964a120757c 100644 --- a/crates/swc_ecma_minifier/src/compress/util/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/util/mod.rs @@ -6,7 +6,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::fixer::fixer; use swc_ecma_utils::{number::JsNumber, ExprCtx, ExprExt, IdentUsageFinder, Value}; #[cfg(feature = "debug")] -use swc_ecma_visit::{as_folder, FoldWith}; +use swc_ecma_visit::{from_visit_mut, FoldWith}; use swc_ecma_visit::{ noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, }; @@ -356,7 +356,7 @@ pub(crate) fn negate_cost( { trace_op!( "negation cost of `{}` = {}", - dump(&e.clone().fold_with(&mut as_folder(fixer(None))), true), + dump(&e.clone().fold_with(&mut from_visit_mut(fixer(None))), true), cost, ); } @@ -368,7 +368,10 @@ pub(crate) fn negate_cost( trace_op!( "negation cost of `{}` = {}\nin_book_ctx={:?}\nis_ret_val_ignored={:?}", - dump(&e.clone().fold_with(&mut as_folder(fixer(None))), false), + dump( + &e.clone().fold_with(&mut from_visit_mut(fixer(None))), + false + ), cost, in_bool_ctx, is_ret_val_ignored diff --git a/crates/swc_ecma_minifier/src/util/unit.rs b/crates/swc_ecma_minifier/src/util/unit.rs index c3a5ac545174..ff0789e170b1 100644 --- a/crates/swc_ecma_minifier/src/util/unit.rs +++ b/crates/swc_ecma_minifier/src/util/unit.rs @@ -7,7 +7,7 @@ use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene}; use swc_ecma_utils::DropSpan; #[cfg(debug_assertions)] use swc_ecma_visit::VisitWith; -use swc_ecma_visit::{as_folder, FoldWith, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, FoldWith, VisitMut, VisitMutWith}; use crate::debug::dump; #[cfg(debug_assertions)] @@ -55,7 +55,7 @@ impl CompileUnit for Module { .clone() .fold_with(&mut fixer(None)) .fold_with(&mut hygiene()) - .fold_with(&mut as_folder(DropSpan {})), + .fold_with(&mut from_visit_mut(DropSpan {})), true, ) } @@ -84,7 +84,7 @@ impl CompileUnit for Script { .clone() .fold_with(&mut fixer(None)) .fold_with(&mut hygiene()) - .fold_with(&mut as_folder(DropSpan {})), + .fold_with(&mut from_visit_mut(DropSpan {})), true, ) } @@ -113,7 +113,7 @@ impl CompileUnit for FnExpr { .clone() .fold_with(&mut fixer(None)) .fold_with(&mut hygiene()) - .fold_with(&mut as_folder(DropSpan {})), + .fold_with(&mut from_visit_mut(DropSpan {})), true, ) } diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index f36724930927..1dee8cf4ed55 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -25,7 +25,7 @@ use swc_ecma_transforms::{ Assumptions, }; use swc_ecma_utils::{prepend_stmts, ExprFactory}; -use swc_ecma_visit::{as_folder, Fold, VisitMut, VisitMutWith, VisitWith}; +use swc_ecma_visit::{from_visit_mut, Fold, VisitMut, VisitMutWith, VisitWith}; pub use self::transform_data::Feature; @@ -340,7 +340,7 @@ where chain!( pass, - as_folder(Polyfills { + from_visit_mut(Polyfills { mode: c.mode, regenerator: should_enable!(Regenerator, true), corejs: c.core_js.unwrap_or(Version { diff --git a/crates/swc_ecma_preset_env/tests/test.rs b/crates/swc_ecma_preset_env/tests/test.rs index 74aac848570a..add7a1c3bf51 100644 --- a/crates/swc_ecma_preset_env/tests/test.rs +++ b/crates/swc_ecma_preset_env/tests/test.rs @@ -22,7 +22,7 @@ use swc_ecma_parser::{Parser, Syntax}; use swc_ecma_preset_env::{preset_env, Config, FeatureOrModule, Mode, Targets, Version}; use swc_ecma_transforms::{fixer, helpers}; use swc_ecma_utils::drop_span; -use swc_ecma_visit::{as_folder, FoldWith, VisitMut}; +use swc_ecma_visit::{from_visit_mut, FoldWith, VisitMut}; use testing::{NormalizedOutput, Tester}; /// options.json file @@ -261,8 +261,8 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { let expected_src = print(&expected); - if drop_span(actual.fold_with(&mut as_folder(Normalizer))) - == drop_span(expected.fold_with(&mut as_folder(Normalizer))) + if drop_span(actual.fold_with(&mut from_visit_mut(Normalizer))) + == drop_span(expected.fold_with(&mut from_visit_mut(Normalizer))) { return Ok(()); } diff --git a/crates/swc_ecma_transforms_base/tests/fixture.rs b/crates/swc_ecma_transforms_base/tests/fixture.rs index 581258c01217..25210735e19f 100644 --- a/crates/swc_ecma_transforms_base/tests/fixture.rs +++ b/crates/swc_ecma_transforms_base/tests/fixture.rs @@ -6,7 +6,7 @@ use swc_ecma_codegen::Emitter; use swc_ecma_parser::{lexer::Lexer, EsSyntax, Parser, StringInput, Syntax, TsSyntax}; use swc_ecma_transforms_base::{fixer::fixer, resolver}; use swc_ecma_visit::{ - as_folder, visit_mut_obj_and_computed, Fold, FoldWith, VisitMut, VisitMutWith, + from_visit_mut, visit_mut_obj_and_computed, Fold, FoldWith, VisitMut, VisitMutWith, }; use testing::{fixture, run_test2, NormalizedOutput}; @@ -78,7 +78,7 @@ fn test_resolver(input: PathBuf) { chain!( resolver(unresolved_mark, Mark::new(), false), - as_folder(TsHygiene { unresolved_mark }), + from_visit_mut(TsHygiene { unresolved_mark }), fixer(None) ) }, @@ -98,7 +98,7 @@ fn test_ts_resolver(input: PathBuf) { chain!( resolver(unresolved_mark, Mark::new(), true), - as_folder(TsHygiene { unresolved_mark }), + from_visit_mut(TsHygiene { unresolved_mark }), fixer(None) ) }, diff --git a/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs b/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs index d8f84f74d70b..b563e8c4f9da 100644 --- a/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs +++ b/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs @@ -6,7 +6,7 @@ use swc_ecma_utils::{ constructor::inject_after_super, default_constructor, is_literal, is_simple_pure_expr, private_ident, prop_name_to_member_prop, ExprFactory, ModuleItemLike, StmtLike, }; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; /// # What does this module do? /// @@ -84,7 +84,7 @@ use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWit /// } /// ``` pub fn class_fields_use_set(pure_getters: bool) -> impl Fold + VisitMut { - as_folder(ClassFieldsUseSet { pure_getters }) + from_visit_mut(ClassFieldsUseSet { pure_getters }) } #[derive(Debug)] diff --git a/crates/swc_ecma_transforms_compat/src/reserved_words.rs b/crates/swc_ecma_transforms_compat/src/reserved_words.rs index 41454a85af0b..7e5f21ee8602 100644 --- a/crates/swc_ecma_transforms_compat/src/reserved_words.rs +++ b/crates/swc_ecma_transforms_compat/src/reserved_words.rs @@ -2,11 +2,11 @@ use swc_atoms::JsWord; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith, + from_visit_mut, noop_visit_mut_type, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith, }; pub fn reserved_words() -> impl 'static + Fold + VisitMut { - as_folder(EsReservedWord) + from_visit_mut(EsReservedWord) } #[derive(Clone, Copy)] diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs b/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs index 26c553f591d1..f6d1c711562f 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs @@ -10,7 +10,7 @@ use swc_ecma_transforms_compat::{ es2017::async_to_generator, }; use swc_ecma_transforms_testing::{compare_stdout, test, test_exec, test_fixture, Tester}; -use swc_ecma_visit::{as_folder, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith}; fn tr() -> impl Fold { let unresolved_mark = Mark::new(); @@ -674,7 +674,7 @@ fn fixture(input: PathBuf) { chain!( resolver(unresolved_mark, Mark::new(), false), block_scoping(unresolved_mark), - as_folder(TsHygiene { unresolved_mark }) + from_visit_mut(TsHygiene { unresolved_mark }) ) }, &input, diff --git a/crates/swc_ecma_transforms_module/src/amd.rs b/crates/swc_ecma_transforms_module/src/amd.rs index 29849a85fbb8..821b9ba8da9f 100644 --- a/crates/swc_ecma_transforms_module/src/amd.rs +++ b/crates/swc_ecma_transforms_module/src/amd.rs @@ -13,7 +13,7 @@ use swc_ecma_transforms_base::{feature::FeatureFlag, helper_expr}; use swc_ecma_utils::{ member_expr, private_ident, quote_ident, quote_str, ExprFactory, FunctionFactory, IsDirective, }; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; pub use super::util::Config as InnerConfig; use crate::{ @@ -50,7 +50,7 @@ where { let Config { module_id, config } = config; - as_folder(Amd { + from_visit_mut(Amd { module_id, config, unresolved_mark, diff --git a/crates/swc_ecma_transforms_module/src/common_js.rs b/crates/swc_ecma_transforms_module/src/common_js.rs index 280ba2a5b80a..2529b1fdc04e 100644 --- a/crates/swc_ecma_transforms_module/src/common_js.rs +++ b/crates/swc_ecma_transforms_module/src/common_js.rs @@ -7,7 +7,7 @@ use swc_ecma_transforms_base::{feature::FeatureFlag, helper_expr}; use swc_ecma_utils::{ member_expr, private_ident, quote_expr, quote_ident, ExprFactory, FunctionFactory, IsDirective, }; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; pub use super::util::Config; use crate::{ @@ -29,7 +29,7 @@ pub fn common_js( config: Config, available_features: FeatureFlag, ) -> impl Fold + VisitMut { - as_folder(Cjs { + from_visit_mut(Cjs { config, resolver, unresolved_mark, diff --git a/crates/swc_ecma_transforms_module/src/import_analysis.rs b/crates/swc_ecma_transforms_module/src/import_analysis.rs index 0a89d6807892..c867745d78cf 100644 --- a/crates/swc_ecma_transforms_module/src/import_analysis.rs +++ b/crates/swc_ecma_transforms_module/src/import_analysis.rs @@ -3,7 +3,7 @@ use swc_common::collections::AHashMap; use swc_ecma_ast::*; use swc_ecma_transforms_base::enable_helper; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitWith, + from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitWith, }; use crate::{module_decl_strip::LinkFlag, util::ImportInterop}; @@ -12,7 +12,7 @@ pub fn import_analyzer( import_interop: ImportInterop, ignore_dynamic: bool, ) -> impl Fold + VisitMut { - as_folder(ImportAnalyzer { + from_visit_mut(ImportAnalyzer { import_interop, ignore_dynamic, flag_record: Default::default(), diff --git a/crates/swc_ecma_transforms_module/src/rewriter.rs b/crates/swc_ecma_transforms_module/src/rewriter.rs index 1bcf96502d4e..be299a57debd 100644 --- a/crates/swc_ecma_transforms_module/src/rewriter.rs +++ b/crates/swc_ecma_transforms_module/src/rewriter.rs @@ -3,13 +3,13 @@ use std::sync::Arc; use anyhow::Context; use swc_common::FileName; use swc_ecma_ast::*; -use swc_ecma_visit::{as_folder, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, Fold, VisitMut, VisitMutWith}; use crate::path::ImportResolver; /// Import rewriter, which rewrites imports as es modules. pub fn import_rewriter(base: FileName, resolver: Arc) -> impl Fold + VisitMut { - as_folder(Rewriter { base, resolver }) + from_visit_mut(Rewriter { base, resolver }) } struct Rewriter { diff --git a/crates/swc_ecma_transforms_module/src/umd.rs b/crates/swc_ecma_transforms_module/src/umd.rs index 54645fda5069..244e41071053 100644 --- a/crates/swc_ecma_transforms_module/src/umd.rs +++ b/crates/swc_ecma_transforms_module/src/umd.rs @@ -9,7 +9,7 @@ use swc_ecma_transforms_base::{feature::FeatureFlag, helper_expr}; use swc_ecma_utils::{ is_valid_prop_ident, private_ident, quote_ident, quote_str, ExprFactory, IsDirective, }; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use self::config::BuiltConfig; pub use self::config::Config; @@ -34,7 +34,7 @@ pub fn umd( config: Config, available_features: FeatureFlag, ) -> impl Fold + VisitMut { - as_folder(Umd { + from_visit_mut(Umd { config: config.build(cm.clone()), unresolved_mark, cm, diff --git a/crates/swc_ecma_transforms_optimization/src/const_modules.rs b/crates/swc_ecma_transforms_optimization/src/const_modules.rs index 99176f605617..9458899b9f8d 100644 --- a/crates/swc_ecma_transforms_optimization/src/const_modules.rs +++ b/crates/swc_ecma_transforms_optimization/src/const_modules.rs @@ -17,13 +17,13 @@ use swc_common::{ use swc_ecma_ast::*; use swc_ecma_parser::parse_file_as_expr; use swc_ecma_utils::drop_span; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; pub fn const_modules( cm: Lrc, globals: FxHashMap>, ) -> impl Fold { - as_folder(ConstModules { + from_visit_mut(ConstModules { globals: globals .into_iter() .map(|(src, map)| { diff --git a/crates/swc_ecma_transforms_optimization/src/inline_globals.rs b/crates/swc_ecma_transforms_optimization/src/inline_globals.rs index 6d5e0a407cae..f96288ba641d 100644 --- a/crates/swc_ecma_transforms_optimization/src/inline_globals.rs +++ b/crates/swc_ecma_transforms_optimization/src/inline_globals.rs @@ -6,7 +6,7 @@ use swc_common::{ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{ParVisitMut, Parallel}; use swc_ecma_utils::{collect_decls, parallel::cpu_count, NodeIgnoringSpan}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; /// The key will be compared using [EqIgnoreSpan::eq_ignore_span], and matched /// expressions will be replaced with the value. @@ -34,7 +34,7 @@ pub fn inline_globals2( global_exprs: GlobalExprMap, typeofs: Lrc>, ) -> impl Fold + VisitMut { - as_folder(InlineGlobals { + from_visit_mut(InlineGlobals { envs, globals, global_exprs, @@ -222,7 +222,7 @@ mod tests { let v = tester .apply_transform( - as_folder(DropSpan), + from_visit_mut(DropSpan), "global.js", ::swc_ecma_parser::Syntax::default(), None, diff --git a/crates/swc_ecma_transforms_optimization/src/json_parse.rs b/crates/swc_ecma_transforms_optimization/src/json_parse.rs index b829f43947f7..26c9e099ed33 100644 --- a/crates/swc_ecma_transforms_optimization/src/json_parse.rs +++ b/crates/swc_ecma_transforms_optimization/src/json_parse.rs @@ -3,7 +3,7 @@ use swc_common::{util::take::Take, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{calc_literal_cost, member_expr, ExprFactory}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; /// Transform to optimize performance of literals. /// @@ -28,7 +28,7 @@ use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWit /// /// See https://github.com/swc-project/swc/issues/409 pub fn json_parse(min_cost: usize) -> impl Fold { - as_folder(JsonParse { min_cost }) + from_visit_mut(JsonParse { min_cost }) } struct JsonParse { diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs index e2acb91e7d9b..aa39d5fd6f78 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs @@ -15,7 +15,7 @@ use swc_ecma_utils::{ StmtExt, StmtLike, Value::Known, }; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, + from_visit_mut, noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, }; use tracing::{debug, trace}; @@ -26,7 +26,7 @@ mod tests; /// /// Ported from `PeepholeRemoveDeadCode` of google closure compiler. pub fn dead_branch_remover(unresolved_mark: Mark) -> impl RepeatedJsPass + VisitMut + 'static { - as_folder(Remover { + from_visit_mut(Remover { changed: false, normal_block: Default::default(), expr_ctx: ExprCtx { diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs b/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs index 3844b6cbf409..b0fb7dc99e6e 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs @@ -1,7 +1,7 @@ use swc_common::{chain, Mark, SyntaxContext}; use swc_ecma_transforms_base::{fixer::paren_remover, resolver}; use swc_ecma_utils::ExprCtx; -use swc_ecma_visit::as_folder; +use swc_ecma_visit::from_visit_mut; use super::super::expr_simplifier; @@ -18,7 +18,7 @@ macro_rules! test_stmt { resolver(unresolved_mark, top_level_mark, false), paren_remover(None), expr_simplifier(top_level_mark, Default::default()), - as_folder(super::Remover { + from_visit_mut(super::Remover { changed: false, normal_block: Default::default(), expr_ctx: ExprCtx { diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs b/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs index 70edd3c67e36..c7d2be175411 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs @@ -2,11 +2,11 @@ use swc_common::{collections::AHashMap, util::take::Take}; use swc_ecma_ast::*; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; /// This pass is kind of inliner, but it's far faster. pub fn constant_propagation() -> impl 'static + Fold + VisitMut { - as_folder(ConstPropagation::default()) + from_visit_mut(ConstPropagation::default()) } #[derive(Default)] diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs index d3132804829f..38f235229aad 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs @@ -19,7 +19,8 @@ use swc_ecma_utils::{ collect_decls, find_pat_ids, ExprCtx, ExprExt, IsEmpty, ModuleItemLike, StmtLike, }; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, + from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + VisitWith, }; use swc_fast_graph::digraph::FastDiGraphMap; use tracing::{debug, span, Level}; @@ -31,7 +32,7 @@ pub fn dce( config: Config, unresolved_mark: Mark, ) -> impl Fold + VisitMut + Repeated + CompilerPass { - as_folder(TreeShaker { + from_visit_mut(TreeShaker { expr_ctx: ExprCtx { unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), is_unresolved_ref_safe: false, diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs index 289cdcaf47f5..02fde4bb162e 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs @@ -16,7 +16,7 @@ use swc_ecma_utils::{ is_literal, number::JsNumber, prop_name_eq, to_int32, BoolType, ExprCtx, ExprExt, NullType, NumberType, ObjectType, StringType, SymbolType, UndefinedType, Value, }; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; use Value::{Known, Unknown}; use crate::debug::debug_assert_valid; @@ -44,7 +44,7 @@ pub fn expr_simplifier( unresolved_mark: Mark, config: Config, ) -> impl RepeatedJsPass + VisitMut + 'static { - as_folder(SimplifyExpr { + from_visit_mut(SimplifyExpr { expr_ctx: ExprCtx { unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), is_unresolved_ref_safe: false, diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs b/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs index 89ace2edaced..4e48391ce244 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs @@ -2,7 +2,7 @@ use swc_common::{chain, Mark, SyntaxContext}; use swc_ecma_transforms_base::{fixer::paren_remover, resolver}; use swc_ecma_transforms_testing::test_transform; use swc_ecma_utils::ExprCtx; -use swc_ecma_visit::as_folder; +use swc_ecma_visit::from_visit_mut; use super::SimplifyExpr; @@ -17,7 +17,7 @@ fn fold(src: &str, expected: &str) { chain!( resolver(unresolved_mark, top_level_mark, false), paren_remover(None), - as_folder(SimplifyExpr { + from_visit_mut(SimplifyExpr { expr_ctx: ExprCtx { unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), // This is hack diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs index 2157c7ae14d6..ef48ebf74ede 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs @@ -8,7 +8,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::{pass::RepeatedJsPass, scope::IdentType}; use swc_ecma_utils::{contains_this_expr, find_pat_ids}; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, visit_obj_and_computed, Visit, VisitMut, + from_visit_mut, noop_visit_mut_type, noop_visit_type, visit_obj_and_computed, Visit, VisitMut, VisitMutWith, VisitWith, }; use tracing::{span, Level}; @@ -34,7 +34,7 @@ pub struct Config {} /// Currently all functions are treated as a black box, and all the pass gives /// up inlining variables across a function call or a constructor call. pub fn inlining(_: Config) -> impl 'static + RepeatedJsPass + VisitMut { - as_folder(Inlining { + from_visit_mut(Inlining { phase: Phase::Analysis, is_first_run: true, changed: false, diff --git a/crates/swc_ecma_transforms_optimization/tests/fixture.rs b/crates/swc_ecma_transforms_optimization/tests/fixture.rs index 9ecb1adb07f0..77fb3a1691c5 100644 --- a/crates/swc_ecma_transforms_optimization/tests/fixture.rs +++ b/crates/swc_ecma_transforms_optimization/tests/fixture.rs @@ -5,10 +5,10 @@ use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_base::fixer::paren_remover; use swc_ecma_transforms_optimization::simplify::{dce::dce, expr_simplifier}; use swc_ecma_transforms_testing::{test_fixture, Tester}; -use swc_ecma_visit::{as_folder, Fold, VisitMut}; +use swc_ecma_visit::{from_visit_mut, Fold, VisitMut}; fn remover(t: &Tester) -> impl VisitMut + Fold { - as_folder(paren_remover(Some( + from_visit_mut(paren_remover(Some( Box::leak(Box::new(t.comments.clone())) as _ ))) } diff --git a/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs b/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs index 862f8354b297..deb22fb16113 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs @@ -10,12 +10,12 @@ use swc_ecma_utils::{ is_maybe_branch_directive, private_ident, prop_name_to_expr_value, quote_ident, replace_ident, stack_size::maybe_grow_default, ExprFactory, IdentRenamer, }; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use crate::DecoratorVersion; pub(crate) fn decorator_impl(version: DecoratorVersion) -> impl VisitMut + Fold { - as_folder(DecoratorPass { + from_visit_mut(DecoratorPass { version, ..Default::default() }) diff --git a/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs b/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs index a2c48c4a14f2..9d5ed33488aa 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs @@ -10,7 +10,7 @@ use swc_ecma_utils::{ alias_ident_for, constructor::inject_after_super, default_constructor, prepend_stmt, private_ident, prop_name_to_expr, prop_name_to_expr_value, quote_ident, quote_str, ExprFactory, }; -use swc_ecma_visit::{as_folder, noop_fold_type, Fold, FoldWith, Visit, VisitWith}; +use swc_ecma_visit::{from_visit_mut, noop_fold_type, Fold, FoldWith, Visit, VisitWith}; mod legacy; @@ -56,7 +56,7 @@ mod legacy; /// ``` pub fn decorators(c: Config) -> impl Fold { if c.legacy { - Either::Left(as_folder(self::legacy::new(c.emit_metadata))) + Either::Left(from_visit_mut(self::legacy::new(c.emit_metadata))) } else { if c.emit_metadata { unimplemented!("emitting decorator metadata while using new proposal") @@ -331,7 +331,7 @@ impl Decorators { ($method:expr, $fn_name:expr, $key_prop_value:expr) => {{ let fn_name = $fn_name; let method = $method; - let mut folder = swc_ecma_visit::as_folder(SuperFieldAccessFolder { + let mut folder = swc_ecma_visit::from_visit_mut(SuperFieldAccessFolder { class_name: &ident, constructor_this_mark: None, is_static: method.is_static, diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index db84b979c064..734c0426efe4 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -5,10 +5,10 @@ use swc_ecma_utils::{ private_ident, quote_ident, stack_size::maybe_grow_default, ExprFactory, ModuleItemLike, StmtLike, }; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; pub fn explicit_resource_management() -> impl Fold + VisitMut { - as_folder(ExplicitResourceManagement::default()) + from_visit_mut(ExplicitResourceManagement::default()) } #[derive(Default)] diff --git a/crates/swc_ecma_transforms_proposal/src/export_default_from.rs b/crates/swc_ecma_transforms_proposal/src/export_default_from.rs index dfda16d920d8..4da7f96c5ba1 100644 --- a/crates/swc_ecma_transforms_proposal/src/export_default_from.rs +++ b/crates/swc_ecma_transforms_proposal/src/export_default_from.rs @@ -1,11 +1,11 @@ use swc_common::DUMMY_SP; use swc_ecma_ast::*; use swc_ecma_utils::quote_ident; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut}; /// `@babel/plugin-proposal-export-default-from` pub fn export_default_from() -> impl Fold + VisitMut { - as_folder(ExportDefaultFrom) + from_visit_mut(ExportDefaultFrom) } struct ExportDefaultFrom; diff --git a/crates/swc_ecma_transforms_proposal/src/import_assertions.rs b/crates/swc_ecma_transforms_proposal/src/import_assertions.rs index 5612a312f169..10d16c6f2dfe 100644 --- a/crates/swc_ecma_transforms_proposal/src/import_assertions.rs +++ b/crates/swc_ecma_transforms_proposal/src/import_assertions.rs @@ -1,11 +1,11 @@ use swc_ecma_ast::{ExportAll, ImportDecl, NamedExport}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut}; #[deprecated(note = "Please use `import_assertions` instead")] pub use self::import_attributes as import_assertions; pub fn import_attributes() -> impl VisitMut + Fold { - as_folder(ImportAssertions) + from_visit_mut(ImportAssertions) } struct ImportAssertions; diff --git a/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs b/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs index d077a1c645f4..349641fa71ff 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs +++ b/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs @@ -3,7 +3,7 @@ use std::{fs, path::PathBuf}; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_proposal::decorator_2022_03::decorator_2022_03; use swc_ecma_transforms_testing::exec_tr; -use swc_ecma_visit::as_folder; +use swc_ecma_visit::from_visit_mut; const HELPERS: &str = r###" function assertEq(callback, expected) { @@ -64,7 +64,7 @@ fn fixture(input: PathBuf) { auto_accessors: true, ..Default::default() }), - |_| as_folder(decorator_2022_03()), + |_| from_visit_mut(decorator_2022_03()), &code, ); } diff --git a/crates/swc_ecma_transforms_react/src/display_name/mod.rs b/crates/swc_ecma_transforms_react/src/display_name/mod.rs index 867b05d0eb54..1bad342c7014 100644 --- a/crates/swc_ecma_transforms_react/src/display_name/mod.rs +++ b/crates/swc_ecma_transforms_react/src/display_name/mod.rs @@ -2,7 +2,7 @@ use std::ops::DerefMut; use swc_common::DUMMY_SP; use swc_ecma_ast::*; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; #[cfg(test)] mod tests; @@ -11,7 +11,7 @@ mod tests; /// /// Add displayName to React.createClass calls pub fn display_name() -> impl Fold + VisitMut { - as_folder(DisplayName) + from_visit_mut(DisplayName) } struct DisplayName; diff --git a/crates/swc_ecma_transforms_react/src/jsx/mod.rs b/crates/swc_ecma_transforms_react/src/jsx/mod.rs index 3ed7374896f5..f559a24699d0 100644 --- a/crates/swc_ecma_transforms_react/src/jsx/mod.rs +++ b/crates/swc_ecma_transforms_react/src/jsx/mod.rs @@ -17,7 +17,7 @@ use swc_config::merge::Merge; use swc_ecma_ast::*; use swc_ecma_parser::{parse_file_as_expr, Syntax}; use swc_ecma_utils::{drop_span, prepend_stmt, private_ident, quote_ident, ExprFactory, StmtLike}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; use self::static_check::should_use_create_element; use crate::refresh::options::{deserialize_refresh, RefreshOptions}; @@ -193,7 +193,7 @@ pub fn jsx( where C: Comments, { - as_folder(Jsx { + from_visit_mut(Jsx { cm: cm.clone(), top_level_mark, unresolved_mark, diff --git a/crates/swc_ecma_transforms_react/src/jsx_self/mod.rs b/crates/swc_ecma_transforms_react/src/jsx_self/mod.rs index 0b4ba3a8c4f4..6fbf19649a87 100644 --- a/crates/swc_ecma_transforms_react/src/jsx_self/mod.rs +++ b/crates/swc_ecma_transforms_react/src/jsx_self/mod.rs @@ -2,7 +2,7 @@ use swc_common::DUMMY_SP; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::quote_ident; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut}; #[cfg(test)] mod tests; @@ -11,7 +11,7 @@ mod tests; /// /// Add a __self prop to all JSX Elements pub fn jsx_self(dev: bool) -> impl Fold + VisitMut { - as_folder(JsxSelf { dev }) + from_visit_mut(JsxSelf { dev }) } #[derive(Clone, Copy)] diff --git a/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs b/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs index cb8a1c2498ba..f62f3e7e62ff 100644 --- a/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs +++ b/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs @@ -2,14 +2,14 @@ use swc_common::{sync::Lrc, SourceMap, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::quote_ident; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; #[cfg(test)] mod tests; /// `@babel/plugin-transform-react-jsx-source` pub fn jsx_src(dev: bool, cm: Lrc) -> impl Fold + VisitMut { - as_folder(JsxSrc { cm, dev }) + from_visit_mut(JsxSrc { cm, dev }) } #[derive(Clone)] diff --git a/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs b/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs index f16b8ab83817..6a2eef5247ba 100644 --- a/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs +++ b/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs @@ -1,7 +1,7 @@ use swc_atoms::JsWord; use swc_common::{collections::AHashMap, comments::Comments, Span}; use swc_ecma_ast::*; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; #[cfg(test)] mod tests; @@ -16,7 +16,7 @@ pub fn pure_annotations(comments: Option) -> impl Fold + VisitMut where C: Comments, { - as_folder(PureAnnotations { + from_visit_mut(PureAnnotations { imports: Default::default(), comments, }) diff --git a/crates/swc_ecma_transforms_react/src/refresh/mod.rs b/crates/swc_ecma_transforms_react/src/refresh/mod.rs index 75d771d732c1..d798dabd359e 100644 --- a/crates/swc_ecma_transforms_react/src/refresh/mod.rs +++ b/crates/swc_ecma_transforms_react/src/refresh/mod.rs @@ -4,7 +4,7 @@ use swc_common::{ }; use swc_ecma_ast::*; use swc_ecma_utils::{private_ident, quote_ident, quote_str, ExprFactory}; -use swc_ecma_visit::{as_folder, Fold, Visit, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, Fold, Visit, VisitMut, VisitMutWith}; use self::{ hook::HookRegister, @@ -53,7 +53,7 @@ pub fn refresh( comments: Option, global_mark: Mark, ) -> impl Fold + VisitMut { - as_folder(Refresh { + from_visit_mut(Refresh { enable: dev && options.is_some(), cm, comments, diff --git a/crates/swc_ecma_transforms_testing/src/lib.rs b/crates/swc_ecma_transforms_testing/src/lib.rs index 3a5ec07e288f..9c5d28821f6b 100644 --- a/crates/swc_ecma_transforms_testing/src/lib.rs +++ b/crates/swc_ecma_transforms_testing/src/lib.rs @@ -38,7 +38,7 @@ use swc_ecma_transforms_base::{ pass::noop, }; use swc_ecma_utils::{quote_ident, quote_str, ExprFactory}; -use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, FoldWith, VisitMut}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, FoldWith, VisitMut}; use tempfile::tempdir_in; use testing::{ assert_eq, find_executable, NormalizedOutput, CARGO_TARGET_DIR, CARGO_WORKSPACE_ROOT, @@ -242,7 +242,7 @@ where F: FnOnce(&mut Tester<'_>) -> P, P: Fold, { - chain!(op(tester), as_folder(RegeneratorHandler)) + chain!(op(tester), from_visit_mut(RegeneratorHandler)) } #[track_caller] @@ -258,7 +258,7 @@ pub fn test_transform( { Tester::run(|tester| { let expected = tester.apply_transform( - as_folder(::swc_ecma_utils::DropSpan), + from_visit_mut(::swc_ecma_utils::DropSpan), "output.js", syntax, is_module, @@ -284,7 +284,7 @@ pub fn test_transform( } let actual = actual - .fold_with(&mut as_folder(::swc_ecma_utils::DropSpan)) + .fold_with(&mut from_visit_mut(::swc_ecma_utils::DropSpan)) .fold_with(&mut hygiene::hygiene()) .fold_with(&mut fixer::fixer(Some(&tester.comments))); diff --git a/crates/swc_ecma_transforms_typescript/src/transform.rs b/crates/swc_ecma_transforms_typescript/src/transform.rs index dde85e956b4b..8a6eba162e65 100644 --- a/crates/swc_ecma_transforms_typescript/src/transform.rs +++ b/crates/swc_ecma_transforms_typescript/src/transform.rs @@ -15,7 +15,8 @@ use swc_ecma_utils::{ ExprFactory, QueryRef, RefRewriter, StmtLikeInjector, }; use swc_ecma_visit::{ - as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith, + from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + VisitWith, }; use crate::{ @@ -84,7 +85,7 @@ pub fn transform( verbatim_module_syntax: bool, native_class_properties: bool, ) -> impl Fold + VisitMut { - as_folder(Transform { + from_visit_mut(Transform { unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), top_level_ctxt: SyntaxContext::empty().apply_mark(top_level_mark), import_export_assign_config, diff --git a/crates/swc_ecma_transforms_typescript/src/typescript.rs b/crates/swc_ecma_transforms_typescript/src/typescript.rs index f60fde8fb8e2..ed6468692be5 100644 --- a/crates/swc_ecma_transforms_typescript/src/typescript.rs +++ b/crates/swc_ecma_transforms_typescript/src/typescript.rs @@ -6,7 +6,7 @@ use swc_common::{ }; use swc_ecma_ast::*; use swc_ecma_transforms_react::{parse_expr_for_jsx, JsxDirectives}; -use swc_ecma_visit::{as_folder, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, Fold, VisitMut, VisitMutWith}; pub use crate::config::*; use crate::{strip_import_export::StripImportExport, strip_type::StripType, transform::transform}; @@ -18,7 +18,7 @@ pub fn typescript( ) -> impl Fold + VisitMut { debug_assert_ne!(unresolved_mark, top_level_mark); - as_folder(TypeScript { + from_visit_mut(TypeScript { config, unresolved_mark, top_level_mark, @@ -151,7 +151,7 @@ pub fn tsx( where C: Comments, { - as_folder(TypeScriptReact { + from_visit_mut(TypeScriptReact { config, tsx_config, id_usage: Default::default(), diff --git a/crates/swc_plugin_runner/tests/fixture/swc_internal_plugin/src/lib.rs b/crates/swc_plugin_runner/tests/fixture/swc_internal_plugin/src/lib.rs index 9f259f166196..191e73fb60e7 100644 --- a/crates/swc_plugin_runner/tests/fixture/swc_internal_plugin/src/lib.rs +++ b/crates/swc_plugin_runner/tests/fixture/swc_internal_plugin/src/lib.rs @@ -29,7 +29,8 @@ impl VisitMut for ConsoleOutputReplacer { span: DUMMY_SP, value: JsWord::from("changed_via_plugin"), raw: Some(Atom::from("\"changed_via_plugin\"")), - }).into(); + }) + .into(); } } } @@ -133,5 +134,5 @@ pub fn process(program: Program, metadata: TransformPluginProgramMetadata) -> Pr dbg!(); - program.fold_with(&mut as_folder(ConsoleOutputReplacer { metadata })) + program.fold_with(&mut from_visit_mut(ConsoleOutputReplacer { metadata })) } diff --git a/packages/core/e2e/fixtures/plugin_transform_schema_v1/src/lib.rs b/packages/core/e2e/fixtures/plugin_transform_schema_v1/src/lib.rs index 31127e438de5..1fb1c75d94c2 100644 --- a/packages/core/e2e/fixtures/plugin_transform_schema_v1/src/lib.rs +++ b/packages/core/e2e/fixtures/plugin_transform_schema_v1/src/lib.rs @@ -31,5 +31,5 @@ pub fn process(program: Program, _metadata: TransformPluginProgramMetadata) -> P Program::Module(_module) => {} } - program.fold_with(&mut as_folder(ConsoleOutputReplacer)) + program.fold_with(&mut from_visit_mut(ConsoleOutputReplacer)) } diff --git a/packages/core/e2e/fixtures/plugin_transform_schema_vtest/src/lib.rs b/packages/core/e2e/fixtures/plugin_transform_schema_vtest/src/lib.rs index 1e0a9df53d94..bc0a9e3443bc 100644 --- a/packages/core/e2e/fixtures/plugin_transform_schema_vtest/src/lib.rs +++ b/packages/core/e2e/fixtures/plugin_transform_schema_vtest/src/lib.rs @@ -34,5 +34,5 @@ pub fn process(program: Program, _metadata: TransformPluginProgramMetadata) -> P Program::Script(..) => {} Program::Module(..) => {} } - program.fold_with(&mut as_folder(ConsoleOutputReplacer)) + program.fold_with(&mut from_visit_mut(ConsoleOutputReplacer)) } From ead5357341e70045790ae57bff8b847a59d74a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:32:31 +0900 Subject: [PATCH 041/186] Move `from_fn` --- crates/swc_ecma_ast/src/lib.rs | 44 ++++++++++++++++++++++++++++++++ crates/swc_ecma_visit/src/lib.rs | 17 ------------ 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index eb0668cd9cd1..0bb764d02232 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -118,6 +118,50 @@ impl Program { } } +#[macro_export] +macro_rules! chain { + ( + $( + $pass:expr + ),* + ) => { + $crate::from_fn(move |program| { + $( + $pass.process(program); + )* + }) + }; + + ( + $( + $pass:expr, + )* + ) => { + $crate::from_fn(move |program| { + $( + $pass.process(program); + )* + }) + }; +} + +pub fn from_fn(f: impl FnOnce(&mut Program)) -> impl Pass { + FnPass { f } +} + +struct FnPass { + f: F, +} + +impl Pass for FnPass +where + F: FnOnce(&mut Program), +{ + fn process(self, program: &mut Program) { + (self.f)(program); + } +} + /// Represents a invalid node. #[ast_node("Invalid")] #[derive(Eq, Default, Hash, Copy, EqIgnoreSpan)] diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 6ab44b216936..d1ae5bd9a604 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -102,23 +102,6 @@ where } } -pub fn from_fn(f: impl FnOnce(&mut Program)) -> impl Pass { - FnPass { f } -} - -struct FnPass { - f: F, -} - -impl Pass for FnPass -where - F: FnOnce(&mut Program), -{ - fn process(self, program: &mut Program) { - (self.f)(program); - } -} - impl Fold for Repeat where V: Fold + Repeated, From efbb9688ad49aaa2ba73e6fbfa6fefef9ab353a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:33:08 +0900 Subject: [PATCH 042/186] Rename --- crates/swc_ecma_ast/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index 0bb764d02232..d2e5d631150b 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -125,7 +125,7 @@ macro_rules! chain { $pass:expr ),* ) => { - $crate::from_fn(move |program| { + $crate::fn_pass(move |program| { $( $pass.process(program); )* @@ -137,7 +137,7 @@ macro_rules! chain { $pass:expr, )* ) => { - $crate::from_fn(move |program| { + $crate::fn_pass(move |program| { $( $pass.process(program); )* @@ -145,7 +145,7 @@ macro_rules! chain { }; } -pub fn from_fn(f: impl FnOnce(&mut Program)) -> impl Pass { +pub fn fn_pass(f: impl FnOnce(&mut Program)) -> impl Pass { FnPass { f } } From 8eee307d95f1ce5e09f4835787bb61c115aaa953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:34:56 +0900 Subject: [PATCH 043/186] noop_pass --- crates/swc_ecma_ast/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index d2e5d631150b..5151d6b5955d 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -145,6 +145,14 @@ macro_rules! chain { }; } +#[inline(always)] +pub fn noop_pass() -> impl Pass { + fn noop(_: &mut Program) {} + + fn_pass(noop) +} + +#[inline(always)] pub fn fn_pass(f: impl FnOnce(&mut Program)) -> impl Pass { FnPass { f } } From e83a8d9bae6a4335a0d1ec55e4c493d8d381cbbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:35:05 +0900 Subject: [PATCH 044/186] inline attr --- crates/swc_ecma_visit/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index d1ae5bd9a604..ad5b77bab6e8 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -30,6 +30,7 @@ impl Pass for FoldPass where V: Fold, { + #[inline(always)] fn process(mut self, program: &mut Program) { program.map_with_mut(|p| p.fold_with(&mut self.pass)); } @@ -39,6 +40,7 @@ impl Fold for FoldPass where V: Fold, { + #[inline(always)] fn fold_program(&mut self, node: Program) -> Program { self.pass.fold_program(node) } @@ -59,6 +61,7 @@ impl Pass for VisitMutPass where V: VisitMut, { + #[inline(always)] fn process(mut self, program: &mut Program) { program.visit_mut_with(&mut self.pass); } @@ -68,6 +71,7 @@ impl VisitMut for VisitMutPass where V: VisitMut, { + #[inline(always)] fn visit_mut_program(&mut self, program: &mut Program) { self.pass.visit_mut_program(program); } @@ -88,6 +92,7 @@ impl Pass for VisitPass where V: Visit, { + #[inline(always)] fn process(mut self, program: &mut Program) { program.visit_with(&mut self.pass); } @@ -97,6 +102,7 @@ impl Visit for VisitPass where V: Visit, { + #[inline(always)] fn visit_program(&mut self, program: &Program) { self.pass.visit_program(program); } From 86de8eaaecb6cf97957e9cd64b8f028324dbe51a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:36:11 +0900 Subject: [PATCH 045/186] Fix AST --- crates/swc_ecma_ast/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index 5151d6b5955d..f1f6dea3a834 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -125,9 +125,9 @@ macro_rules! chain { $pass:expr ),* ) => { - $crate::fn_pass(move |program| { + $crate::fn_pass(move |mut program| { $( - $pass.process(program); + program.mutate($pass); )* }) }; @@ -137,9 +137,9 @@ macro_rules! chain { $pass:expr, )* ) => { - $crate::fn_pass(move |program| { + $crate::fn_pass(move |mut program| { $( - $pass.process(program); + program.mutate($pass); )* }) }; From 3dca4c89e1cae52a6350f0704249bd12c53c2e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:36:38 +0900 Subject: [PATCH 046/186] More work --- crates/swc_ecma_transforms_base/src/helpers/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_base/src/helpers/mod.rs b/crates/swc_ecma_transforms_base/src/helpers/mod.rs index 7fb140e1b3ba..626ada633b52 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/mod.rs +++ b/crates/swc_ecma_transforms_base/src/helpers/mod.rs @@ -720,7 +720,7 @@ let _throw1 = null; fn use_strict_abort() { crate::tests::test_transform( Default::default(), - |_| noop(), + |_| noop_pass(), "'use strict' let x = 4;", From a75d9943c4a78351d450126fc97aa1e5d5557264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:36:43 +0900 Subject: [PATCH 047/186] More work --- crates/swc_ecma_transforms_base/src/fixer.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_base/src/fixer.rs b/crates/swc_ecma_transforms_base/src/fixer.rs index 33f9cf60c1df..ec82f195a079 100644 --- a/crates/swc_ecma_transforms_base/src/fixer.rs +++ b/crates/swc_ecma_transforms_base/src/fixer.rs @@ -1178,12 +1178,13 @@ fn will_eat_else_token(s: &Stmt) -> bool { #[cfg(test)] mod tests { + use swc_ecma_ast::noop_pass; fn run_test(from: &str, to: &str) { crate::tests::test_transform( Default::default(), // test_transform has alreay included fixer - |_| noop(), + |_| noop_pass(), from, to, true, From b992b15e004fb9227ed5c672218906a6df48d692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:36:47 +0900 Subject: [PATCH 048/186] More work --- crates/swc_ecma_transforms_base/src/hygiene/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs index 5ec4104c9933..ad9abaf9fbb2 100644 --- a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs +++ b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs @@ -1,7 +1,7 @@ use swc_common::Mark; use swc_ecma_ast::*; use swc_ecma_utils::stack_size::maybe_grow_default; -use swc_ecma_visit::{from_fn, noop_visit_mut_type, VisitMut, VisitMutWith}; +use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; pub use crate::rename::rename; use crate::rename::{renamer, Renamer}; @@ -59,10 +59,10 @@ pub fn hygiene() -> impl Pass { /// /// At third phase, we rename all identifiers in the queue. pub fn hygiene_with_config(config: Config) -> impl 'static + Pass { - from_fn(move |program| { - renamer(config, HygieneRenamer).process(program); - program.visit_mut_with(&mut HygieneRemover); - }) + chain!( + renamer(config, HygieneRenamer), + from_visit_mut(HygieneRemover) + ) } struct HygieneRenamer; From e2d769f2e471a826d68543fc9ec8233722111744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:37:07 +0900 Subject: [PATCH 049/186] Rename `visit_mut_pass` --- crates/swc/src/builder.rs | 2 +- crates/swc/src/dropped_comments_preserver.rs | 4 ++-- crates/swc/tests/rust_api.rs | 4 ++-- crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs | 4 ++-- ...i_id_destructuring_collision_in_function_expression.rs | 4 ++-- crates/swc_ecma_compat_common/src/regexp.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/arrow.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/classes/mod.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/computed_props.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/destructuring.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/duplicate_keys.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/for_of.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/function_name.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/generator.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/instanceof.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/new_target.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/object_super.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/parameters.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/shorthand_property.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/spread.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/sticky_regex.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/template_literal.rs | 4 ++-- crates/swc_ecma_compat_es2015/src/typeof_symbol.rs | 4 ++-- crates/swc_ecma_compat_es2016/src/exponentiation.rs | 4 ++-- crates/swc_ecma_compat_es2017/src/async_to_generator.rs | 4 ++-- crates/swc_ecma_compat_es2018/src/object_rest_spread.rs | 2 +- .../swc_ecma_compat_es2019/src/optional_catch_binding.rs | 6 +++--- .../swc_ecma_compat_es2020/src/export_namespace_from.rs | 4 ++-- crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs | 4 ++-- crates/swc_ecma_compat_es2020/src/optional_chaining.rs | 4 ++-- crates/swc_ecma_compat_es2021/src/logical_assignments.rs | 4 ++-- crates/swc_ecma_compat_es2022/src/class_properties/mod.rs | 4 ++-- crates/swc_ecma_compat_es2022/src/private_in_object.rs | 4 ++-- crates/swc_ecma_compat_es2022/src/static_blocks.rs | 4 ++-- crates/swc_ecma_compat_es3/src/reserved_word.rs | 4 ++-- crates/swc_ecma_ext_transforms/src/jest.rs | 4 ++-- crates/swc_ecma_minifier/src/compress/mod.rs | 6 +++--- crates/swc_ecma_minifier/src/compress/util/mod.rs | 8 ++++---- crates/swc_ecma_minifier/src/util/unit.rs | 8 ++++---- crates/swc_ecma_preset_env/src/lib.rs | 4 ++-- crates/swc_ecma_preset_env/tests/test.rs | 6 +++--- crates/swc_ecma_transforms_base/src/fixer.rs | 6 +++--- crates/swc_ecma_transforms_base/src/helpers/mod.rs | 4 ++-- crates/swc_ecma_transforms_base/src/hygiene/mod.rs | 4 ++-- crates/swc_ecma_transforms_base/src/rename/mod.rs | 8 ++++---- crates/swc_ecma_transforms_base/src/resolver/mod.rs | 4 ++-- crates/swc_ecma_transforms_base/tests/fixture.rs | 6 +++--- .../src/class_fields_use_set.rs | 4 ++-- crates/swc_ecma_transforms_compat/src/reserved_words.rs | 4 ++-- .../tests/es2015_block_scoping.rs | 2 +- crates/swc_ecma_transforms_module/src/amd.rs | 4 ++-- crates/swc_ecma_transforms_module/src/common_js.rs | 4 ++-- crates/swc_ecma_transforms_module/src/import_analysis.rs | 4 ++-- crates/swc_ecma_transforms_module/src/rewriter.rs | 4 ++-- crates/swc_ecma_transforms_module/src/umd.rs | 4 ++-- .../swc_ecma_transforms_optimization/src/const_modules.rs | 4 ++-- .../src/inline_globals.rs | 6 +++--- crates/swc_ecma_transforms_optimization/src/json_parse.rs | 4 ++-- .../src/simplify/branch/mod.rs | 4 ++-- .../src/simplify/branch/tests.rs | 2 +- .../src/simplify/const_propagation.rs | 4 ++-- .../src/simplify/dce/mod.rs | 4 ++-- .../src/simplify/expr/mod.rs | 4 ++-- .../src/simplify/expr/tests.rs | 2 +- .../src/simplify/inlining/mod.rs | 4 ++-- crates/swc_ecma_transforms_optimization/tests/fixture.rs | 4 ++-- crates/swc_ecma_transforms_proposal/src/decorator_impl.rs | 4 ++-- crates/swc_ecma_transforms_proposal/src/decorators/mod.rs | 4 ++-- .../src/explicit_resource_management.rs | 4 ++-- .../src/export_default_from.rs | 4 ++-- .../swc_ecma_transforms_proposal/src/import_assertions.rs | 4 ++-- .../swc_ecma_transforms_proposal/tests/decorator_evanw.rs | 4 ++-- crates/swc_ecma_transforms_react/src/display_name/mod.rs | 4 ++-- crates/swc_ecma_transforms_react/src/jsx/mod.rs | 4 ++-- crates/swc_ecma_transforms_react/src/jsx_self/mod.rs | 4 ++-- crates/swc_ecma_transforms_react/src/jsx_src/mod.rs | 4 ++-- .../swc_ecma_transforms_react/src/pure_annotations/mod.rs | 4 ++-- crates/swc_ecma_transforms_react/src/refresh/mod.rs | 4 ++-- crates/swc_ecma_transforms_testing/src/lib.rs | 8 ++++---- crates/swc_ecma_transforms_typescript/src/transform.rs | 4 ++-- crates/swc_ecma_transforms_typescript/src/typescript.rs | 6 +++--- crates/swc_ecma_visit/src/lib.rs | 2 +- 84 files changed, 177 insertions(+), 177 deletions(-) diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index 06fb43e0f32b..6aef5f493d82 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -22,7 +22,7 @@ use swc_ecma_transforms::{ pass::Optional, resolver, Assumptions, }; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use crate::config::{GlobalPassOption, JsMinifyOptions, ModuleConfig}; diff --git a/crates/swc/src/dropped_comments_preserver.rs b/crates/swc/src/dropped_comments_preserver.rs index f65ff6e64b84..749a37ecae49 100644 --- a/crates/swc/src/dropped_comments_preserver.rs +++ b/crates/swc/src/dropped_comments_preserver.rs @@ -3,7 +3,7 @@ use swc_common::{ BytePos, Span, DUMMY_SP, }; use swc_ecma_ast::{Module, Script}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; /// Preserves comments that would otherwise be dropped. /// @@ -19,7 +19,7 @@ use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitM pub fn dropped_comments_preserver( comments: Option, ) -> impl Fold + VisitMut { - from_visit_mut(DroppedCommentsPreserver { + visit_mut_pass(DroppedCommentsPreserver { comments, is_first_span: true, known_spans: Vec::new(), diff --git a/crates/swc/tests/rust_api.rs b/crates/swc/tests/rust_api.rs index 78b5b0b3f4f8..c7f3f0bcc040 100644 --- a/crates/swc/tests/rust_api.rs +++ b/crates/swc/tests/rust_api.rs @@ -6,7 +6,7 @@ use swc_common::{comments::SingleThreadedComments, FileName}; use swc_ecma_ast::*; use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax}; use swc_ecma_transforms::pass::noop; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut}; struct PanicOnVisit; @@ -49,7 +49,7 @@ fn test_visit_mut() { ..Default::default() }, SingleThreadedComments::default(), - |_| from_visit_mut(PanicOnVisit), + |_| visit_mut_pass(PanicOnVisit), |_| noop(), ); diff --git a/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs b/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs index 267b50e12aa9..f0ebd7cc21b0 100644 --- a/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs +++ b/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs @@ -1,5 +1,5 @@ use swc_ecma_ast::*; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// A bugfix pass for Edge. @@ -9,7 +9,7 @@ use swc_trace_macro::swc_trace; /// browsers (Edge 16 & 17). Use this plugin instead of /// @babel/plugin-transform-parameters when targeting ES Modules. pub fn edge_default_param() -> impl Fold + VisitMut { - from_visit_mut(EdgeDefaultParam::default()) + visit_mut_pass(EdgeDefaultParam::default()) } #[derive(Default, Clone, Copy)] struct EdgeDefaultParam { diff --git a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs index 6eb00d3fc5a5..32088a4901a1 100644 --- a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs +++ b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs @@ -4,11 +4,11 @@ use swc_atoms::JsWord; use swc_common::{collections::AHashSet, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_transforms_base::hygiene::rename; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn safari_id_destructuring_collision_in_function_expression() -> impl Fold + VisitMut { - from_visit_mut(SafariIdDestructuringCollisionInFunctionExpression::default()) + visit_mut_pass(SafariIdDestructuringCollisionInFunctionExpression::default()) } #[derive(Default, Clone)] diff --git a/crates/swc_ecma_compat_common/src/regexp.rs b/crates/swc_ecma_compat_common/src/regexp.rs index ba34b1377509..7d5c141b6a57 100644 --- a/crates/swc_ecma_compat_common/src/regexp.rs +++ b/crates/swc_ecma_compat_common/src/regexp.rs @@ -1,10 +1,10 @@ use swc_common::util::take::Take; use swc_ecma_ast::{CallExpr, Expr, Lit, Pass, Regex}; use swc_ecma_utils::{quote_ident, ExprFactory}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; pub fn regexp(config: Config) -> impl Pass { - from_visit_mut(RegExp { config }) + visit_mut_pass(RegExp { config }) } #[derive(Default, Clone, Copy)] diff --git a/crates/swc_ecma_compat_es2015/src/arrow.rs b/crates/swc_ecma_compat_es2015/src/arrow.rs index c98cbacecedf..208d46738632 100644 --- a/crates/swc_ecma_compat_es2015/src/arrow.rs +++ b/crates/swc_ecma_compat_es2015/src/arrow.rs @@ -6,7 +6,7 @@ use swc_ecma_utils::{ function::{init_this, FnEnvHoister}, prepend_stmt, }; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, InjectVars, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, InjectVars, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// Compile ES2015 arrow functions to ES5 @@ -58,7 +58,7 @@ use swc_trace_macro::swc_trace; /// console.log(bob.printFriends()); /// ``` pub fn arrow(unresolved_mark: Mark) -> impl Pass + VisitMut + InjectVars { - from_visit_mut(Arrow { + visit_mut_pass(Arrow { in_subclass: false, hoister: FnEnvHoister::new(SyntaxContext::empty().apply_mark(unresolved_mark)), }) diff --git a/crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs b/crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs index ec48667cbdfd..1405c3da819d 100644 --- a/crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs +++ b/crates/swc_ecma_compat_es2015/src/block_scoped_fn.rs @@ -1,11 +1,11 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::IdentUsageFinder; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn block_scoped_functions() -> impl Pass { - from_visit_mut(BlockScopedFns) + visit_mut_pass(BlockScopedFns) } #[derive(Clone, Copy)] diff --git a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs index b6557cb91e3d..dd5bb12af797 100644 --- a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs +++ b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs @@ -15,7 +15,7 @@ use swc_ecma_utils::{ ExprFactory, StmtLike, }; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith, + noop_visit_mut_type, visit_mut_obj_and_computed, visit_mut_pass, Fold, VisitMut, VisitMutWith, }; use swc_trace_macro::swc_trace; @@ -35,7 +35,7 @@ mod vars; /// } /// ``` pub fn block_scoping(unresolved_mark: Mark) -> impl VisitMut + Fold { - from_visit_mut(chain!( + visit_mut_pass(chain!( self::vars::block_scoped_vars(), BlockScoping { unresolved_mark, diff --git a/crates/swc_ecma_compat_es2015/src/classes/mod.rs b/crates/swc_ecma_compat_es2015/src/classes/mod.rs index 6073c2812aec..904b61573050 100644 --- a/crates/swc_ecma_compat_es2015/src/classes/mod.rs +++ b/crates/swc_ecma_compat_es2015/src/classes/mod.rs @@ -15,7 +15,7 @@ use swc_ecma_utils::{ ExprFactory, ModuleItemLike, StmtLike, }; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -29,7 +29,7 @@ mod constructor; mod prop_name; pub fn classes(config: Config) -> impl Fold + VisitMut { - from_visit_mut(Classes { + visit_mut_pass(Classes { in_strict: false, config, diff --git a/crates/swc_ecma_compat_es2015/src/computed_props.rs b/crates/swc_ecma_compat_es2015/src/computed_props.rs index 529e241b4cc9..b60b24549cef 100644 --- a/crates/swc_ecma_compat_es2015/src/computed_props.rs +++ b/crates/swc_ecma_compat_es2015/src/computed_props.rs @@ -4,7 +4,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::helper; use swc_ecma_utils::{quote_ident, ExprFactory, StmtLike}; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -41,7 +41,7 @@ use swc_trace_macro::swc_trace; /// TODO(kdy1): cache reference like (_f = f, mutatorMap[_f].get = function(){}) /// instead of (mutatorMap[f].get = function(){} pub fn computed_properties(c: Config) -> impl Fold { - from_visit_mut(ComputedProps { + visit_mut_pass(ComputedProps { c, ..Default::default() }) diff --git a/crates/swc_ecma_compat_es2015/src/destructuring.rs b/crates/swc_ecma_compat_es2015/src/destructuring.rs index 508b8cf7f56b..c5cea4fffff0 100644 --- a/crates/swc_ecma_compat_es2015/src/destructuring.rs +++ b/crates/swc_ecma_compat_es2015/src/destructuring.rs @@ -11,7 +11,7 @@ use swc_ecma_utils::{ prop_name_to_expr, quote_ident, ExprFactory, StmtLike, }; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -38,7 +38,7 @@ use swc_trace_macro::swc_trace; /// rest = _arr2.slice(2); /// ``` pub fn destructuring(c: Config) -> impl Fold + VisitMut { - from_visit_mut(Destructuring { c }) + visit_mut_pass(Destructuring { c }) } struct Destructuring { diff --git a/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs b/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs index 42244653a37a..aa8a590e7ff0 100644 --- a/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs +++ b/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs @@ -3,11 +3,11 @@ use swc_common::{collections::AHashSet, Spanned}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::quote_str; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn duplicate_keys() -> impl Fold + VisitMut { - from_visit_mut(DuplicateKeys) + visit_mut_pass(DuplicateKeys) } struct DuplicateKeys; diff --git a/crates/swc_ecma_compat_es2015/src/for_of.rs b/crates/swc_ecma_compat_es2015/src/for_of.rs index f60f29d0336c..3099571c32fc 100644 --- a/crates/swc_ecma_compat_es2015/src/for_of.rs +++ b/crates/swc_ecma_compat_es2015/src/for_of.rs @@ -11,7 +11,7 @@ use swc_ecma_transforms_macros::parallel; use swc_ecma_utils::{ alias_if_required, member_expr, prepend_stmt, private_ident, quote_ident, ExprFactory, }; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-for-of` @@ -49,7 +49,7 @@ use swc_trace_macro::swc_trace; /// } /// ``` pub fn for_of(c: Config) -> impl Fold + VisitMut { - from_visit_mut(ForOf { + visit_mut_pass(ForOf { c, top_level_vars: Default::default(), }) diff --git a/crates/swc_ecma_compat_es2015/src/function_name.rs b/crates/swc_ecma_compat_es2015/src/function_name.rs index 7dc572307308..21666000c3ae 100644 --- a/crates/swc_ecma_compat_es2015/src/function_name.rs +++ b/crates/swc_ecma_compat_es2015/src/function_name.rs @@ -2,7 +2,7 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{private_ident, IdentUsageFinder}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-function-name` @@ -23,7 +23,7 @@ use swc_trace_macro::swc_trace; /// var Foo = (class Foo {}); /// ``` pub fn function_name() -> impl 'static + Copy + Fold + VisitMut { - from_visit_mut(FnName) + visit_mut_pass(FnName) } #[derive(Clone, Copy)] diff --git a/crates/swc_ecma_compat_es2015/src/generator.rs b/crates/swc_ecma_compat_es2015/src/generator.rs index bffdaa1ea7a9..fe9ceabeaba2 100644 --- a/crates/swc_ecma_compat_es2015/src/generator.rs +++ b/crates/swc_ecma_compat_es2015/src/generator.rs @@ -17,7 +17,7 @@ use swc_ecma_utils::{ function::FnEnvHoister, private_ident, prop_name_to_expr_value, quote_ident, ExprFactory, }; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use tracing::debug; @@ -27,7 +27,7 @@ pub fn generator(unresolved_mark: Mark, _comments: C) -> impl VisitMut + Fold where C: Comments, { - from_visit_mut(Wrapper { + visit_mut_pass(Wrapper { unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), }) } diff --git a/crates/swc_ecma_compat_es2015/src/instanceof.rs b/crates/swc_ecma_compat_es2015/src/instanceof.rs index b108137114c1..d60763d4a8f9 100644 --- a/crates/swc_ecma_compat_es2015/src/instanceof.rs +++ b/crates/swc_ecma_compat_es2015/src/instanceof.rs @@ -2,7 +2,7 @@ use swc_common::{util::take::Take, Span, Spanned}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Parallel}; use swc_ecma_utils::ExprFactory; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-instanceof` @@ -31,7 +31,7 @@ use swc_trace_macro::swc_trace; /// _instanceof(foo, Bar); /// ``` pub fn instance_of() -> impl Fold + VisitMut { - from_visit_mut(InstanceOf) + visit_mut_pass(InstanceOf) } struct InstanceOf; diff --git a/crates/swc_ecma_compat_es2015/src/new_target.rs b/crates/swc_ecma_compat_es2015/src/new_target.rs index 0d6aba86811e..b348611bd832 100644 --- a/crates/swc_ecma_compat_es2015/src/new_target.rs +++ b/crates/swc_ecma_compat_es2015/src/new_target.rs @@ -5,12 +5,12 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{should_work, Check}; use swc_ecma_utils::{private_ident, quote_ident, ExprFactory}; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, }; use swc_trace_macro::swc_trace; pub fn new_target() -> impl Fold + VisitMut + CompilerPass { - from_visit_mut(NewTarget { + visit_mut_pass(NewTarget { ctx: Ctx::Constructor, }) } diff --git a/crates/swc_ecma_compat_es2015/src/object_super.rs b/crates/swc_ecma_compat_es2015/src/object_super.rs index da96ab91e947..e9d0030224ba 100644 --- a/crates/swc_ecma_compat_es2015/src/object_super.rs +++ b/crates/swc_ecma_compat_es2015/src/object_super.rs @@ -6,7 +6,7 @@ use swc_ecma_transforms_base::helper; use swc_ecma_utils::{ alias_ident_for, is_rest_arguments, prepend_stmt, private_ident, quote_ident, ExprFactory, }; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; struct ObjectSuper { @@ -14,7 +14,7 @@ struct ObjectSuper { } pub fn object_super() -> impl Fold + VisitMut { - from_visit_mut(ObjectSuper { + visit_mut_pass(ObjectSuper { extra_vars: Vec::new(), }) } diff --git a/crates/swc_ecma_compat_es2015/src/parameters.rs b/crates/swc_ecma_compat_es2015/src/parameters.rs index 098c6344135b..b1f35de00ac8 100644 --- a/crates/swc_ecma_compat_es2015/src/parameters.rs +++ b/crates/swc_ecma_compat_es2015/src/parameters.rs @@ -10,13 +10,13 @@ use swc_ecma_utils::{ function::{init_this, FnEnvHoister}, member_expr, prepend_stmt, prepend_stmts, private_ident, quote_ident, ExprFactory, }; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; use tracing::trace; pub fn parameters(c: Config, unresolved_mark: Mark) -> impl 'static + Fold { let unresolved_ctxt = SyntaxContext::empty().apply_mark(unresolved_mark); - from_visit_mut(Params { + visit_mut_pass(Params { c, unresolved_ctxt, hoister: FnEnvHoister::new(unresolved_ctxt), diff --git a/crates/swc_ecma_compat_es2015/src/shorthand_property.rs b/crates/swc_ecma_compat_es2015/src/shorthand_property.rs index e79230173734..80251ced7c52 100644 --- a/crates/swc_ecma_compat_es2015/src/shorthand_property.rs +++ b/crates/swc_ecma_compat_es2015/src/shorthand_property.rs @@ -1,7 +1,7 @@ use swc_common::util::take::Take; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// Compile ES2015 shorthand properties to ES5 @@ -39,7 +39,7 @@ use swc_trace_macro::swc_trace; /// }; /// ``` pub fn shorthand() -> impl 'static + Fold + VisitMut { - from_visit_mut(Shorthand) + visit_mut_pass(Shorthand) } #[derive(Clone, Copy)] diff --git a/crates/swc_ecma_compat_es2015/src/spread.rs b/crates/swc_ecma_compat_es2015/src/spread.rs index c353d2014903..6e19c1fcd88b 100644 --- a/crates/swc_ecma_compat_es2015/src/spread.rs +++ b/crates/swc_ecma_compat_es2015/src/spread.rs @@ -9,13 +9,13 @@ use swc_ecma_utils::{ alias_ident_for, member_expr, prepend_stmt, quote_ident, ExprFactory, StmtLike, }; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; pub fn spread(c: Config) -> impl Fold + VisitMut { - from_visit_mut(Spread { + visit_mut_pass(Spread { c, vars: Default::default(), }) diff --git a/crates/swc_ecma_compat_es2015/src/sticky_regex.rs b/crates/swc_ecma_compat_es2015/src/sticky_regex.rs index a2eeaa65482a..90edd27c3d48 100644 --- a/crates/swc_ecma_compat_es2015/src/sticky_regex.rs +++ b/crates/swc_ecma_compat_es2015/src/sticky_regex.rs @@ -1,7 +1,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{quote_ident, ExprFactory}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// Compile ES2015 sticky regex to an ES5 RegExp constructor @@ -19,7 +19,7 @@ use swc_trace_macro::swc_trace; /// new RegExp("o+", "y") /// ``` pub fn sticky_regex() -> impl 'static + Fold + VisitMut { - from_visit_mut(StickyRegex) + visit_mut_pass(StickyRegex) } struct StickyRegex; diff --git a/crates/swc_ecma_compat_es2015/src/template_literal.rs b/crates/swc_ecma_compat_es2015/src/template_literal.rs index e1ca147b0672..a4813c0ec4d8 100644 --- a/crates/swc_ecma_compat_es2015/src/template_literal.rs +++ b/crates/swc_ecma_compat_es2015/src/template_literal.rs @@ -6,11 +6,11 @@ use swc_common::{util::take::Take, BytePos, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Parallel}; use swc_ecma_utils::{is_literal, prepend_stmts, private_ident, quote_ident, ExprFactory}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn template_literal(c: Config) -> impl Fold + VisitMut { - from_visit_mut(TemplateLiteral { + visit_mut_pass(TemplateLiteral { c, ..Default::default() }) diff --git a/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs b/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs index 347048ea62a9..5df64414df0b 100644 --- a/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs +++ b/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs @@ -2,11 +2,11 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Parallel}; use swc_ecma_utils::{quote_str, ExprFactory}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn typeof_symbol() -> impl VisitMut + Fold { - from_visit_mut(TypeOfSymbol) + visit_mut_pass(TypeOfSymbol) } #[derive(Clone, Copy)] diff --git a/crates/swc_ecma_compat_es2016/src/exponentiation.rs b/crates/swc_ecma_compat_es2016/src/exponentiation.rs index 6ac36ff83f62..1da05fcff74f 100644 --- a/crates/swc_ecma_compat_es2016/src/exponentiation.rs +++ b/crates/swc_ecma_compat_es2016/src/exponentiation.rs @@ -3,7 +3,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{ParExplode, Parallel}; use swc_ecma_transforms_macros::parallel; use swc_ecma_utils::{member_expr, private_ident, ExprFactory}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-exponentiation-operator` @@ -26,7 +26,7 @@ use swc_trace_macro::swc_trace; /// x = Math.pow(x, 3); /// ``` pub fn exponentiation() -> impl Fold + VisitMut { - from_visit_mut(Exponentiation::default()) + visit_mut_pass(Exponentiation::default()) } #[derive(Default)] diff --git a/crates/swc_ecma_compat_es2017/src/async_to_generator.rs b/crates/swc_ecma_compat_es2017/src/async_to_generator.rs index 972e3a17062f..9abe6c3bae2e 100644 --- a/crates/swc_ecma_compat_es2017/src/async_to_generator.rs +++ b/crates/swc_ecma_compat_es2017/src/async_to_generator.rs @@ -11,7 +11,7 @@ use swc_ecma_utils::{ prepend_stmt, private_ident, quote_ident, ExprFactory, Remapper, StmtLike, }; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -37,7 +37,7 @@ use swc_trace_macro::swc_trace; /// }); /// ``` pub fn async_to_generator(c: Config, unresolved_mark: Mark) -> impl Fold + VisitMut { - from_visit_mut(AsyncToGenerator { + visit_mut_pass(AsyncToGenerator { c, in_subclass: false, unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), diff --git a/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs b/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs index f71adf6fcb0c..3fa3fae7ea54 100644 --- a/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs +++ b/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs @@ -1,6 +1,6 @@ use serde::Deserialize; use swc_common::chain; -use swc_ecma_visit::{from_visit_mut, Fold, VisitMut}; +use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut}; use super::{object_rest::ObjectRest, object_spread::ObjectSpread}; diff --git a/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs b/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs index 2fbe46005aed..e39f44cd0ddc 100644 --- a/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs +++ b/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs @@ -1,12 +1,12 @@ use swc_ecma_ast::*; use swc_ecma_utils::private_ident; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; struct OptionalCatchBinding; pub fn optional_catch_binding() -> impl Fold + VisitMut { - from_visit_mut(OptionalCatchBinding) + visit_mut_pass(OptionalCatchBinding) } #[swc_trace] @@ -28,7 +28,7 @@ mod tests { use swc_common::{chain, Mark}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::test; - use swc_ecma_visit::{from_visit_mut, Fold}; + use swc_ecma_visit::{visit_mut_pass, Fold}; use crate::optional_catch_binding::OptionalCatchBinding; diff --git a/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs b/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs index d92c309c5f4f..ecc572208ce5 100644 --- a/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs +++ b/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs @@ -1,11 +1,11 @@ use swc_atoms::JsWord; use swc_ecma_ast::*; use swc_ecma_utils::private_ident; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut}; use swc_trace_macro::swc_trace; pub fn export_namespace_from() -> impl Fold + VisitMut { - from_visit_mut(ExportNamespaceFrom) + visit_mut_pass(ExportNamespaceFrom) } struct ExportNamespaceFrom; diff --git a/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs b/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs index 2da91521cb6b..7ab3ab3e505e 100644 --- a/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs +++ b/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs @@ -4,11 +4,11 @@ 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::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn nullish_coalescing(c: Config) -> impl Fold + VisitMut + 'static { - from_visit_mut(NullishCoalescing { + visit_mut_pass(NullishCoalescing { c, ..Default::default() }) diff --git a/crates/swc_ecma_compat_es2020/src/optional_chaining.rs b/crates/swc_ecma_compat_es2020/src/optional_chaining.rs index 0673bd9b21e6..703268a9450d 100644 --- a/crates/swc_ecma_compat_es2020/src/optional_chaining.rs +++ b/crates/swc_ecma_compat_es2020/src/optional_chaining.rs @@ -1,10 +1,10 @@ use serde::Deserialize; use swc_common::Mark; use swc_ecma_compat_es2022::optional_chaining_impl::optional_chaining_impl; -use swc_ecma_visit::{from_visit_mut, Fold, VisitMut}; +use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut}; pub fn optional_chaining(c: Config, unresolved_mark: Mark) -> impl Fold + VisitMut { - from_visit_mut(optional_chaining_impl( + visit_mut_pass(optional_chaining_impl( swc_ecma_compat_es2022::optional_chaining_impl::Config { no_document_all: c.no_document_all, pure_getter: c.pure_getter, diff --git a/crates/swc_ecma_compat_es2021/src/logical_assignments.rs b/crates/swc_ecma_compat_es2021/src/logical_assignments.rs index 1b36d75b3885..e56ff1e13124 100644 --- a/crates/swc_ecma_compat_es2021/src/logical_assignments.rs +++ b/crates/swc_ecma_compat_es2021/src/logical_assignments.rs @@ -4,11 +4,11 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{alias_ident_for, prepend_stmt}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; pub fn logical_assignments() -> impl Fold + VisitMut { - from_visit_mut(Operators::default()) + visit_mut_pass(Operators::default()) } #[derive(Debug, Default)] diff --git a/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs b/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs index e2a02e081470..83b0f16df0b9 100644 --- a/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs +++ b/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs @@ -12,7 +12,7 @@ use swc_ecma_utils::{ ModuleItemLike, StmtLike, }; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -42,7 +42,7 @@ mod used_name; /// /// We use custom helper to handle export default class pub fn class_properties(config: Config, unresolved_mark: Mark) -> impl Fold + VisitMut { - from_visit_mut(ClassProperties { + visit_mut_pass(ClassProperties { c: config, private: PrivateRecord::new(), extra: ClassExtra::default(), diff --git a/crates/swc_ecma_compat_es2022/src/private_in_object.rs b/crates/swc_ecma_compat_es2022/src/private_in_object.rs index 0ac8b4597f4c..f690c6e5b1f3 100644 --- a/crates/swc_ecma_compat_es2022/src/private_in_object.rs +++ b/crates/swc_ecma_compat_es2022/src/private_in_object.rs @@ -12,12 +12,12 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::pass::JsPass; use swc_ecma_utils::{default_constructor, prepend_stmt, private_ident, quote_ident, ExprFactory}; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith, VisitWith, }; /// https://github.com/tc39/proposal-private-fields-in-in pub fn private_in_object() -> impl JsPass { - from_visit_mut(PrivateInObject::default()) + visit_mut_pass(PrivateInObject::default()) } #[derive(Debug)] diff --git a/crates/swc_ecma_compat_es2022/src/static_blocks.rs b/crates/swc_ecma_compat_es2022/src/static_blocks.rs index 25a4cd811a12..a97df883f56e 100644 --- a/crates/swc_ecma_compat_es2022/src/static_blocks.rs +++ b/crates/swc_ecma_compat_es2022/src/static_blocks.rs @@ -2,7 +2,7 @@ use swc_atoms::JsWord; use swc_common::{collections::AHashSet, util::take::Take, Mark, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::ExprFactory; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; struct ClassStaticBlock { @@ -10,7 +10,7 @@ struct ClassStaticBlock { } pub fn static_blocks(static_block_mark: Mark) -> impl Fold + VisitMut { - from_visit_mut(ClassStaticBlock { static_block_mark }) + visit_mut_pass(ClassStaticBlock { static_block_mark }) } #[swc_trace] diff --git a/crates/swc_ecma_compat_es3/src/reserved_word.rs b/crates/swc_ecma_compat_es3/src/reserved_word.rs index af9348c5851c..20ceae2518ce 100644 --- a/crates/swc_ecma_compat_es3/src/reserved_word.rs +++ b/crates/swc_ecma_compat_es3/src/reserved_word.rs @@ -1,6 +1,6 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; /// babel: `@babel/plugin-transform-reserved-words` /// @@ -20,7 +20,7 @@ use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitM /// var x = _abstract + 1; /// ``` pub fn reserved_words(preserve_import: bool) -> impl VisitMut + Fold { - from_visit_mut(ReservedWord { preserve_import }) + visit_mut_pass(ReservedWord { preserve_import }) } struct ReservedWord { pub preserve_import: bool, diff --git a/crates/swc_ecma_ext_transforms/src/jest.rs b/crates/swc_ecma_ext_transforms/src/jest.rs index 51fb758e53de..b5c13bbd4853 100644 --- a/crates/swc_ecma_ext_transforms/src/jest.rs +++ b/crates/swc_ecma_ext_transforms/src/jest.rs @@ -2,7 +2,7 @@ use phf::phf_set; use swc_common::util::take::Take; use swc_ecma_ast::*; use swc_ecma_utils::{prepend_stmts, StmtLike}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; static HOIST_METHODS: phf::Set<&str> = phf_set![ "mock", @@ -13,7 +13,7 @@ static HOIST_METHODS: phf::Set<&str> = phf_set![ ]; pub fn jest() -> impl Pass { - from_visit_mut(Jest::default()) + visit_mut_pass(Jest::default()) } #[derive(Default)] diff --git a/crates/swc_ecma_minifier/src/compress/mod.rs b/crates/swc_ecma_minifier/src/compress/mod.rs index d24145486ae0..cf271ee2f131 100644 --- a/crates/swc_ecma_minifier/src/compress/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/mod.rs @@ -15,7 +15,7 @@ use swc_ecma_transforms_optimization::simplify::{ dead_branch_remover, expr_simplifier, ExprSimplifierConfig, }; use swc_ecma_usage_analyzer::{analyzer::UsageAnalyzer, marks::Marks}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith, VisitWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith, VisitWith}; use swc_timer::timer; use tracing::{debug, error}; @@ -55,10 +55,10 @@ where }; chain!( - from_visit_mut(compressor), + visit_mut_pass(compressor), Optional { enabled: options.evaluate || options.side_effects, - visitor: from_visit_mut(expr_simplifier( + visitor: visit_mut_pass(expr_simplifier( marks.unresolved_mark, ExprSimplifierConfig {} )) diff --git a/crates/swc_ecma_minifier/src/compress/util/mod.rs b/crates/swc_ecma_minifier/src/compress/util/mod.rs index 8964a120757c..4ac422672759 100644 --- a/crates/swc_ecma_minifier/src/compress/util/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/util/mod.rs @@ -5,11 +5,11 @@ use swc_ecma_ast::*; #[cfg(feature = "debug")] use swc_ecma_transforms_base::fixer::fixer; use swc_ecma_utils::{number::JsNumber, ExprCtx, ExprExt, IdentUsageFinder, Value}; -#[cfg(feature = "debug")] -use swc_ecma_visit::{from_visit_mut, FoldWith}; use swc_ecma_visit::{ noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, }; +#[cfg(feature = "debug")] +use swc_ecma_visit::{visit_mut_pass, FoldWith}; #[cfg(feature = "debug")] use crate::debug::dump; @@ -356,7 +356,7 @@ pub(crate) fn negate_cost( { trace_op!( "negation cost of `{}` = {}", - dump(&e.clone().fold_with(&mut from_visit_mut(fixer(None))), true), + dump(&e.clone().fold_with(&mut visit_mut_pass(fixer(None))), true), cost, ); } @@ -369,7 +369,7 @@ pub(crate) fn negate_cost( trace_op!( "negation cost of `{}` = {}\nin_book_ctx={:?}\nis_ret_val_ignored={:?}", dump( - &e.clone().fold_with(&mut from_visit_mut(fixer(None))), + &e.clone().fold_with(&mut visit_mut_pass(fixer(None))), false ), cost, diff --git a/crates/swc_ecma_minifier/src/util/unit.rs b/crates/swc_ecma_minifier/src/util/unit.rs index ff0789e170b1..73c1c90fa88d 100644 --- a/crates/swc_ecma_minifier/src/util/unit.rs +++ b/crates/swc_ecma_minifier/src/util/unit.rs @@ -7,7 +7,7 @@ use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene}; use swc_ecma_utils::DropSpan; #[cfg(debug_assertions)] use swc_ecma_visit::VisitWith; -use swc_ecma_visit::{from_visit_mut, FoldWith, VisitMut, VisitMutWith}; +use swc_ecma_visit::{visit_mut_pass, FoldWith, VisitMut, VisitMutWith}; use crate::debug::dump; #[cfg(debug_assertions)] @@ -55,7 +55,7 @@ impl CompileUnit for Module { .clone() .fold_with(&mut fixer(None)) .fold_with(&mut hygiene()) - .fold_with(&mut from_visit_mut(DropSpan {})), + .fold_with(&mut visit_mut_pass(DropSpan {})), true, ) } @@ -84,7 +84,7 @@ impl CompileUnit for Script { .clone() .fold_with(&mut fixer(None)) .fold_with(&mut hygiene()) - .fold_with(&mut from_visit_mut(DropSpan {})), + .fold_with(&mut visit_mut_pass(DropSpan {})), true, ) } @@ -113,7 +113,7 @@ impl CompileUnit for FnExpr { .clone() .fold_with(&mut fixer(None)) .fold_with(&mut hygiene()) - .fold_with(&mut from_visit_mut(DropSpan {})), + .fold_with(&mut visit_mut_pass(DropSpan {})), true, ) } diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index 1dee8cf4ed55..13b79ac99088 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -25,7 +25,7 @@ use swc_ecma_transforms::{ Assumptions, }; use swc_ecma_utils::{prepend_stmts, ExprFactory}; -use swc_ecma_visit::{from_visit_mut, Fold, VisitMut, VisitMutWith, VisitWith}; +use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut, VisitMutWith, VisitWith}; pub use self::transform_data::Feature; @@ -340,7 +340,7 @@ where chain!( pass, - from_visit_mut(Polyfills { + visit_mut_pass(Polyfills { mode: c.mode, regenerator: should_enable!(Regenerator, true), corejs: c.core_js.unwrap_or(Version { diff --git a/crates/swc_ecma_preset_env/tests/test.rs b/crates/swc_ecma_preset_env/tests/test.rs index add7a1c3bf51..9ab9e0371a21 100644 --- a/crates/swc_ecma_preset_env/tests/test.rs +++ b/crates/swc_ecma_preset_env/tests/test.rs @@ -22,7 +22,7 @@ use swc_ecma_parser::{Parser, Syntax}; use swc_ecma_preset_env::{preset_env, Config, FeatureOrModule, Mode, Targets, Version}; use swc_ecma_transforms::{fixer, helpers}; use swc_ecma_utils::drop_span; -use swc_ecma_visit::{from_visit_mut, FoldWith, VisitMut}; +use swc_ecma_visit::{visit_mut_pass, FoldWith, VisitMut}; use testing::{NormalizedOutput, Tester}; /// options.json file @@ -261,8 +261,8 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { let expected_src = print(&expected); - if drop_span(actual.fold_with(&mut from_visit_mut(Normalizer))) - == drop_span(expected.fold_with(&mut from_visit_mut(Normalizer))) + if drop_span(actual.fold_with(&mut visit_mut_pass(Normalizer))) + == drop_span(expected.fold_with(&mut visit_mut_pass(Normalizer))) { return Ok(()); } diff --git a/crates/swc_ecma_transforms_base/src/fixer.rs b/crates/swc_ecma_transforms_base/src/fixer.rs index ec82f195a079..3a0f8a465627 100644 --- a/crates/swc_ecma_transforms_base/src/fixer.rs +++ b/crates/swc_ecma_transforms_base/src/fixer.rs @@ -5,7 +5,7 @@ use rustc_hash::FxHasher; use swc_common::{comments::Comments, util::take::Take, Span, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::stack_size::maybe_grow_default; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; /// Fixes ast nodes before printing so semantics are preserved. /// @@ -13,7 +13,7 @@ use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith /// The pass will insert parenthesis as needed. In other words, it's /// okay to store `a * (b + c)` as `Bin { a * Bin { b + c } }`. pub fn fixer(comments: Option<&dyn Comments>) -> impl '_ + Pass { - from_visit_mut(Fixer { + visit_mut_pass(Fixer { comments, ctx: Default::default(), span_map: Default::default(), @@ -24,7 +24,7 @@ pub fn fixer(comments: Option<&dyn Comments>) -> impl '_ + Pass { } pub fn paren_remover(comments: Option<&dyn Comments>) -> impl '_ + Pass { - from_visit_mut(Fixer { + visit_mut_pass(Fixer { comments, ctx: Default::default(), span_map: Default::default(), diff --git a/crates/swc_ecma_transforms_base/src/helpers/mod.rs b/crates/swc_ecma_transforms_base/src/helpers/mod.rs index 626ada633b52..7abdefde61d9 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/mod.rs +++ b/crates/swc_ecma_transforms_base/src/helpers/mod.rs @@ -6,7 +6,7 @@ use swc_atoms::JsWord; use swc_common::{FileName, FilePathMapping, Mark, SourceMap, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{prepend_stmts, quote_ident, DropSpan, ExprFactory}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; #[macro_export] macro_rules! enable_helper { @@ -421,7 +421,7 @@ define_helpers!(Helpers { }); pub fn inject_helpers(global_mark: Mark) -> impl Pass { - from_visit_mut(InjectHelpers { + visit_mut_pass(InjectHelpers { global_mark, helper_ctxt: None, }) diff --git a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs index ad9abaf9fbb2..8858596e31de 100644 --- a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs +++ b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs @@ -1,7 +1,7 @@ use swc_common::Mark; use swc_ecma_ast::*; use swc_ecma_utils::stack_size::maybe_grow_default; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; pub use crate::rename::rename; use crate::rename::{renamer, Renamer}; @@ -61,7 +61,7 @@ pub fn hygiene() -> impl Pass { pub fn hygiene_with_config(config: Config) -> impl 'static + Pass { chain!( renamer(config, HygieneRenamer), - from_visit_mut(HygieneRemover) + visit_mut_pass(HygieneRemover) ) } diff --git a/crates/swc_ecma_transforms_base/src/rename/mod.rs b/crates/swc_ecma_transforms_base/src/rename/mod.rs index a92b805a108c..e8495391c734 100644 --- a/crates/swc_ecma_transforms_base/src/rename/mod.rs +++ b/crates/swc_ecma_transforms_base/src/rename/mod.rs @@ -8,7 +8,7 @@ use swc_common::collections::AHashMap; use swc_ecma_ast::*; use swc_ecma_utils::stack_size::maybe_grow_default; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith, VisitWith, + noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith, VisitWith, }; #[cfg(feature = "concurrent-renamer")] @@ -60,7 +60,7 @@ pub fn rename(map: &RenameMap) -> impl '_ + Pass + VisitMut { } pub fn rename_with_config(map: &RenameMap, config: Config) -> impl '_ + Pass + VisitMut { - from_visit_mut(Operator { + visit_mut_pass(Operator { rename: map, config, extra: Default::default(), @@ -68,7 +68,7 @@ pub fn rename_with_config(map: &RenameMap, config: Config) -> impl '_ + Pass + V } pub fn remap(map: &FxHashMap, config: Config) -> impl '_ + Pass + VisitMut { - from_visit_mut(Operator { + visit_mut_pass(Operator { rename: map, config, extra: Default::default(), @@ -79,7 +79,7 @@ pub fn renamer(config: Config, renamer: R) -> impl Pass + VisitMut where R: Renamer, { - from_visit_mut(RenamePass { + visit_mut_pass(RenamePass { config, renamer, preserved: Default::default(), diff --git a/crates/swc_ecma_transforms_base/src/resolver/mod.rs b/crates/swc_ecma_transforms_base/src/resolver/mod.rs index 599b447b9479..2ac61cd5d48c 100644 --- a/crates/swc_ecma_transforms_base/src/resolver/mod.rs +++ b/crates/swc_ecma_transforms_base/src/resolver/mod.rs @@ -7,7 +7,7 @@ use swc_common::{ use swc_ecma_ast::*; use swc_ecma_utils::{find_pat_ids, stack_size::maybe_grow_default}; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, visit_mut_obj_and_computed, VisitMut, VisitMutWith, + noop_visit_mut_type, visit_mut_obj_and_computed, visit_mut_pass, VisitMut, VisitMutWith, }; use tracing::{debug, span, Level}; @@ -144,7 +144,7 @@ pub fn resolver( let _ = SyntaxContext::empty().apply_mark(unresolved_mark); let _ = SyntaxContext::empty().apply_mark(top_level_mark); - from_visit_mut(Resolver { + visit_mut_pass(Resolver { current: Scope::new(ScopeKind::Fn, top_level_mark, None), ident_type: IdentType::Ref, in_type: false, diff --git a/crates/swc_ecma_transforms_base/tests/fixture.rs b/crates/swc_ecma_transforms_base/tests/fixture.rs index 25210735e19f..73ee09b54d96 100644 --- a/crates/swc_ecma_transforms_base/tests/fixture.rs +++ b/crates/swc_ecma_transforms_base/tests/fixture.rs @@ -6,7 +6,7 @@ use swc_ecma_codegen::Emitter; use swc_ecma_parser::{lexer::Lexer, EsSyntax, Parser, StringInput, Syntax, TsSyntax}; use swc_ecma_transforms_base::{fixer::fixer, resolver}; use swc_ecma_visit::{ - from_visit_mut, visit_mut_obj_and_computed, Fold, FoldWith, VisitMut, VisitMutWith, + visit_mut_obj_and_computed, visit_mut_pass, Fold, FoldWith, VisitMut, VisitMutWith, }; use testing::{fixture, run_test2, NormalizedOutput}; @@ -78,7 +78,7 @@ fn test_resolver(input: PathBuf) { chain!( resolver(unresolved_mark, Mark::new(), false), - from_visit_mut(TsHygiene { unresolved_mark }), + visit_mut_pass(TsHygiene { unresolved_mark }), fixer(None) ) }, @@ -98,7 +98,7 @@ fn test_ts_resolver(input: PathBuf) { chain!( resolver(unresolved_mark, Mark::new(), true), - from_visit_mut(TsHygiene { unresolved_mark }), + visit_mut_pass(TsHygiene { unresolved_mark }), fixer(None) ) }, diff --git a/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs b/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs index b563e8c4f9da..28566d9b6fe7 100644 --- a/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs +++ b/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs @@ -6,7 +6,7 @@ use swc_ecma_utils::{ constructor::inject_after_super, default_constructor, is_literal, is_simple_pure_expr, private_ident, prop_name_to_member_prop, ExprFactory, ModuleItemLike, StmtLike, }; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; /// # What does this module do? /// @@ -84,7 +84,7 @@ use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitM /// } /// ``` pub fn class_fields_use_set(pure_getters: bool) -> impl Fold + VisitMut { - from_visit_mut(ClassFieldsUseSet { pure_getters }) + visit_mut_pass(ClassFieldsUseSet { pure_getters }) } #[derive(Debug)] diff --git a/crates/swc_ecma_transforms_compat/src/reserved_words.rs b/crates/swc_ecma_transforms_compat/src/reserved_words.rs index 7e5f21ee8602..16293bc99305 100644 --- a/crates/swc_ecma_transforms_compat/src/reserved_words.rs +++ b/crates/swc_ecma_transforms_compat/src/reserved_words.rs @@ -2,11 +2,11 @@ use swc_atoms::JsWord; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith, + noop_visit_mut_type, visit_mut_obj_and_computed, visit_mut_pass, Fold, VisitMut, VisitMutWith, }; pub fn reserved_words() -> impl 'static + Fold + VisitMut { - from_visit_mut(EsReservedWord) + visit_mut_pass(EsReservedWord) } #[derive(Clone, Copy)] diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs b/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs index f6d1c711562f..849e19321b52 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs @@ -10,7 +10,7 @@ use swc_ecma_transforms_compat::{ es2017::async_to_generator, }; use swc_ecma_transforms_testing::{compare_stdout, test, test_exec, test_fixture, Tester}; -use swc_ecma_visit::{from_visit_mut, visit_mut_obj_and_computed, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{visit_mut_obj_and_computed, visit_mut_pass, Fold, VisitMut, VisitMutWith}; fn tr() -> impl Fold { let unresolved_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_module/src/amd.rs b/crates/swc_ecma_transforms_module/src/amd.rs index 821b9ba8da9f..9a6e012cad22 100644 --- a/crates/swc_ecma_transforms_module/src/amd.rs +++ b/crates/swc_ecma_transforms_module/src/amd.rs @@ -13,7 +13,7 @@ use swc_ecma_transforms_base::{feature::FeatureFlag, helper_expr}; use swc_ecma_utils::{ member_expr, private_ident, quote_ident, quote_str, ExprFactory, FunctionFactory, IsDirective, }; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; pub use super::util::Config as InnerConfig; use crate::{ @@ -50,7 +50,7 @@ where { let Config { module_id, config } = config; - from_visit_mut(Amd { + visit_mut_pass(Amd { module_id, config, unresolved_mark, diff --git a/crates/swc_ecma_transforms_module/src/common_js.rs b/crates/swc_ecma_transforms_module/src/common_js.rs index 2529b1fdc04e..b105088f7c60 100644 --- a/crates/swc_ecma_transforms_module/src/common_js.rs +++ b/crates/swc_ecma_transforms_module/src/common_js.rs @@ -7,7 +7,7 @@ use swc_ecma_transforms_base::{feature::FeatureFlag, helper_expr}; use swc_ecma_utils::{ member_expr, private_ident, quote_expr, quote_ident, ExprFactory, FunctionFactory, IsDirective, }; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; pub use super::util::Config; use crate::{ @@ -29,7 +29,7 @@ pub fn common_js( config: Config, available_features: FeatureFlag, ) -> impl Fold + VisitMut { - from_visit_mut(Cjs { + visit_mut_pass(Cjs { config, resolver, unresolved_mark, diff --git a/crates/swc_ecma_transforms_module/src/import_analysis.rs b/crates/swc_ecma_transforms_module/src/import_analysis.rs index c867745d78cf..cbe9783fcc61 100644 --- a/crates/swc_ecma_transforms_module/src/import_analysis.rs +++ b/crates/swc_ecma_transforms_module/src/import_analysis.rs @@ -3,7 +3,7 @@ use swc_common::collections::AHashMap; use swc_ecma_ast::*; use swc_ecma_transforms_base::enable_helper; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitWith, }; use crate::{module_decl_strip::LinkFlag, util::ImportInterop}; @@ -12,7 +12,7 @@ pub fn import_analyzer( import_interop: ImportInterop, ignore_dynamic: bool, ) -> impl Fold + VisitMut { - from_visit_mut(ImportAnalyzer { + visit_mut_pass(ImportAnalyzer { import_interop, ignore_dynamic, flag_record: Default::default(), diff --git a/crates/swc_ecma_transforms_module/src/rewriter.rs b/crates/swc_ecma_transforms_module/src/rewriter.rs index be299a57debd..f3f806fbc559 100644 --- a/crates/swc_ecma_transforms_module/src/rewriter.rs +++ b/crates/swc_ecma_transforms_module/src/rewriter.rs @@ -3,13 +3,13 @@ use std::sync::Arc; use anyhow::Context; use swc_common::FileName; use swc_ecma_ast::*; -use swc_ecma_visit::{from_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut, VisitMutWith}; use crate::path::ImportResolver; /// Import rewriter, which rewrites imports as es modules. pub fn import_rewriter(base: FileName, resolver: Arc) -> impl Fold + VisitMut { - from_visit_mut(Rewriter { base, resolver }) + visit_mut_pass(Rewriter { base, resolver }) } struct Rewriter { diff --git a/crates/swc_ecma_transforms_module/src/umd.rs b/crates/swc_ecma_transforms_module/src/umd.rs index 244e41071053..888520f76ea0 100644 --- a/crates/swc_ecma_transforms_module/src/umd.rs +++ b/crates/swc_ecma_transforms_module/src/umd.rs @@ -9,7 +9,7 @@ use swc_ecma_transforms_base::{feature::FeatureFlag, helper_expr}; use swc_ecma_utils::{ is_valid_prop_ident, private_ident, quote_ident, quote_str, ExprFactory, IsDirective, }; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use self::config::BuiltConfig; pub use self::config::Config; @@ -34,7 +34,7 @@ pub fn umd( config: Config, available_features: FeatureFlag, ) -> impl Fold + VisitMut { - from_visit_mut(Umd { + visit_mut_pass(Umd { config: config.build(cm.clone()), unresolved_mark, cm, diff --git a/crates/swc_ecma_transforms_optimization/src/const_modules.rs b/crates/swc_ecma_transforms_optimization/src/const_modules.rs index 9458899b9f8d..df17152b380a 100644 --- a/crates/swc_ecma_transforms_optimization/src/const_modules.rs +++ b/crates/swc_ecma_transforms_optimization/src/const_modules.rs @@ -17,13 +17,13 @@ use swc_common::{ use swc_ecma_ast::*; use swc_ecma_parser::parse_file_as_expr; use swc_ecma_utils::drop_span; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; pub fn const_modules( cm: Lrc, globals: FxHashMap>, ) -> impl Fold { - from_visit_mut(ConstModules { + visit_mut_pass(ConstModules { globals: globals .into_iter() .map(|(src, map)| { diff --git a/crates/swc_ecma_transforms_optimization/src/inline_globals.rs b/crates/swc_ecma_transforms_optimization/src/inline_globals.rs index f96288ba641d..50ae7c228c11 100644 --- a/crates/swc_ecma_transforms_optimization/src/inline_globals.rs +++ b/crates/swc_ecma_transforms_optimization/src/inline_globals.rs @@ -6,7 +6,7 @@ use swc_common::{ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{ParVisitMut, Parallel}; use swc_ecma_utils::{collect_decls, parallel::cpu_count, NodeIgnoringSpan}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; /// The key will be compared using [EqIgnoreSpan::eq_ignore_span], and matched /// expressions will be replaced with the value. @@ -34,7 +34,7 @@ pub fn inline_globals2( global_exprs: GlobalExprMap, typeofs: Lrc>, ) -> impl Fold + VisitMut { - from_visit_mut(InlineGlobals { + visit_mut_pass(InlineGlobals { envs, globals, global_exprs, @@ -222,7 +222,7 @@ mod tests { let v = tester .apply_transform( - from_visit_mut(DropSpan), + visit_mut_pass(DropSpan), "global.js", ::swc_ecma_parser::Syntax::default(), None, diff --git a/crates/swc_ecma_transforms_optimization/src/json_parse.rs b/crates/swc_ecma_transforms_optimization/src/json_parse.rs index 26c9e099ed33..f3ce32ba2281 100644 --- a/crates/swc_ecma_transforms_optimization/src/json_parse.rs +++ b/crates/swc_ecma_transforms_optimization/src/json_parse.rs @@ -3,7 +3,7 @@ use swc_common::{util::take::Take, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{calc_literal_cost, member_expr, ExprFactory}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; /// Transform to optimize performance of literals. /// @@ -28,7 +28,7 @@ use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitM /// /// See https://github.com/swc-project/swc/issues/409 pub fn json_parse(min_cost: usize) -> impl Fold { - from_visit_mut(JsonParse { min_cost }) + visit_mut_pass(JsonParse { min_cost }) } struct JsonParse { diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs index aa39d5fd6f78..4455c698074a 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs @@ -15,7 +15,7 @@ use swc_ecma_utils::{ StmtExt, StmtLike, Value::Known, }; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith, VisitWith, }; use tracing::{debug, trace}; @@ -26,7 +26,7 @@ mod tests; /// /// Ported from `PeepholeRemoveDeadCode` of google closure compiler. pub fn dead_branch_remover(unresolved_mark: Mark) -> impl RepeatedJsPass + VisitMut + 'static { - from_visit_mut(Remover { + visit_mut_pass(Remover { changed: false, normal_block: Default::default(), expr_ctx: ExprCtx { diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs b/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs index b0fb7dc99e6e..cd1e5ea4ad72 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs @@ -1,7 +1,7 @@ use swc_common::{chain, Mark, SyntaxContext}; use swc_ecma_transforms_base::{fixer::paren_remover, resolver}; use swc_ecma_utils::ExprCtx; -use swc_ecma_visit::from_visit_mut; +use swc_ecma_visit::visit_mut_pass; use super::super::expr_simplifier; diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs b/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs index c7d2be175411..70fa2091ab74 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs @@ -2,11 +2,11 @@ use swc_common::{collections::AHashMap, util::take::Take}; use swc_ecma_ast::*; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; /// This pass is kind of inliner, but it's far faster. pub fn constant_propagation() -> impl 'static + Fold + VisitMut { - from_visit_mut(ConstPropagation::default()) + visit_mut_pass(ConstPropagation::default()) } #[derive(Default)] diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs index 38f235229aad..9e8903e781bb 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs @@ -19,7 +19,7 @@ use swc_ecma_utils::{ collect_decls, find_pat_ids, ExprCtx, ExprExt, IsEmpty, ModuleItemLike, StmtLike, }; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_fast_graph::digraph::FastDiGraphMap; @@ -32,7 +32,7 @@ pub fn dce( config: Config, unresolved_mark: Mark, ) -> impl Fold + VisitMut + Repeated + CompilerPass { - from_visit_mut(TreeShaker { + visit_mut_pass(TreeShaker { expr_ctx: ExprCtx { unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), is_unresolved_ref_safe: false, diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs index 02fde4bb162e..349a92a08d02 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs @@ -16,7 +16,7 @@ use swc_ecma_utils::{ is_literal, number::JsNumber, prop_name_eq, to_int32, BoolType, ExprCtx, ExprExt, NullType, NumberType, ObjectType, StringType, SymbolType, UndefinedType, Value, }; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use Value::{Known, Unknown}; use crate::debug::debug_assert_valid; @@ -44,7 +44,7 @@ pub fn expr_simplifier( unresolved_mark: Mark, config: Config, ) -> impl RepeatedJsPass + VisitMut + 'static { - from_visit_mut(SimplifyExpr { + visit_mut_pass(SimplifyExpr { expr_ctx: ExprCtx { unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), is_unresolved_ref_safe: false, diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs b/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs index 4e48391ce244..77734718cd71 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs @@ -2,7 +2,7 @@ use swc_common::{chain, Mark, SyntaxContext}; use swc_ecma_transforms_base::{fixer::paren_remover, resolver}; use swc_ecma_transforms_testing::test_transform; use swc_ecma_utils::ExprCtx; -use swc_ecma_visit::from_visit_mut; +use swc_ecma_visit::visit_mut_pass; use super::SimplifyExpr; diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs index ef48ebf74ede..16b90c78165e 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs @@ -8,7 +8,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::{pass::RepeatedJsPass, scope::IdentType}; use swc_ecma_utils::{contains_this_expr, find_pat_ids}; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, noop_visit_type, visit_obj_and_computed, Visit, VisitMut, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, visit_obj_and_computed, Visit, VisitMut, VisitMutWith, VisitWith, }; use tracing::{span, Level}; @@ -34,7 +34,7 @@ pub struct Config {} /// Currently all functions are treated as a black box, and all the pass gives /// up inlining variables across a function call or a constructor call. pub fn inlining(_: Config) -> impl 'static + RepeatedJsPass + VisitMut { - from_visit_mut(Inlining { + visit_mut_pass(Inlining { phase: Phase::Analysis, is_first_run: true, changed: false, diff --git a/crates/swc_ecma_transforms_optimization/tests/fixture.rs b/crates/swc_ecma_transforms_optimization/tests/fixture.rs index 77fb3a1691c5..0ea19bde1f5b 100644 --- a/crates/swc_ecma_transforms_optimization/tests/fixture.rs +++ b/crates/swc_ecma_transforms_optimization/tests/fixture.rs @@ -5,10 +5,10 @@ use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_base::fixer::paren_remover; use swc_ecma_transforms_optimization::simplify::{dce::dce, expr_simplifier}; use swc_ecma_transforms_testing::{test_fixture, Tester}; -use swc_ecma_visit::{from_visit_mut, Fold, VisitMut}; +use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut}; fn remover(t: &Tester) -> impl VisitMut + Fold { - from_visit_mut(paren_remover(Some( + visit_mut_pass(paren_remover(Some( Box::leak(Box::new(t.comments.clone())) as _ ))) } diff --git a/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs b/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs index deb22fb16113..ec62ff4f59ab 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs @@ -10,12 +10,12 @@ use swc_ecma_utils::{ is_maybe_branch_directive, private_ident, prop_name_to_expr_value, quote_ident, replace_ident, stack_size::maybe_grow_default, ExprFactory, IdentRenamer, }; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use crate::DecoratorVersion; pub(crate) fn decorator_impl(version: DecoratorVersion) -> impl VisitMut + Fold { - from_visit_mut(DecoratorPass { + visit_mut_pass(DecoratorPass { version, ..Default::default() }) diff --git a/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs b/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs index 9d5ed33488aa..ea0205dcf306 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs @@ -10,7 +10,7 @@ use swc_ecma_utils::{ alias_ident_for, constructor::inject_after_super, default_constructor, prepend_stmt, private_ident, prop_name_to_expr, prop_name_to_expr_value, quote_ident, quote_str, ExprFactory, }; -use swc_ecma_visit::{from_visit_mut, noop_fold_type, Fold, FoldWith, Visit, VisitWith}; +use swc_ecma_visit::{noop_fold_type, visit_mut_pass, Fold, FoldWith, Visit, VisitWith}; mod legacy; @@ -56,7 +56,7 @@ mod legacy; /// ``` pub fn decorators(c: Config) -> impl Fold { if c.legacy { - Either::Left(from_visit_mut(self::legacy::new(c.emit_metadata))) + Either::Left(visit_mut_pass(self::legacy::new(c.emit_metadata))) } else { if c.emit_metadata { unimplemented!("emitting decorator metadata while using new proposal") diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index 734c0426efe4..4d8ba5c3ee20 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -5,10 +5,10 @@ use swc_ecma_utils::{ private_ident, quote_ident, stack_size::maybe_grow_default, ExprFactory, ModuleItemLike, StmtLike, }; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; pub fn explicit_resource_management() -> impl Fold + VisitMut { - from_visit_mut(ExplicitResourceManagement::default()) + visit_mut_pass(ExplicitResourceManagement::default()) } #[derive(Default)] diff --git a/crates/swc_ecma_transforms_proposal/src/export_default_from.rs b/crates/swc_ecma_transforms_proposal/src/export_default_from.rs index 4da7f96c5ba1..3db424add2d1 100644 --- a/crates/swc_ecma_transforms_proposal/src/export_default_from.rs +++ b/crates/swc_ecma_transforms_proposal/src/export_default_from.rs @@ -1,11 +1,11 @@ use swc_common::DUMMY_SP; use swc_ecma_ast::*; use swc_ecma_utils::quote_ident; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut}; /// `@babel/plugin-proposal-export-default-from` pub fn export_default_from() -> impl Fold + VisitMut { - from_visit_mut(ExportDefaultFrom) + visit_mut_pass(ExportDefaultFrom) } struct ExportDefaultFrom; diff --git a/crates/swc_ecma_transforms_proposal/src/import_assertions.rs b/crates/swc_ecma_transforms_proposal/src/import_assertions.rs index 10d16c6f2dfe..6b7105e61771 100644 --- a/crates/swc_ecma_transforms_proposal/src/import_assertions.rs +++ b/crates/swc_ecma_transforms_proposal/src/import_assertions.rs @@ -1,11 +1,11 @@ use swc_ecma_ast::{ExportAll, ImportDecl, NamedExport}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut}; #[deprecated(note = "Please use `import_assertions` instead")] pub use self::import_attributes as import_assertions; pub fn import_attributes() -> impl VisitMut + Fold { - from_visit_mut(ImportAssertions) + visit_mut_pass(ImportAssertions) } struct ImportAssertions; diff --git a/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs b/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs index 349641fa71ff..e14b06a4b6d6 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs +++ b/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs @@ -3,7 +3,7 @@ use std::{fs, path::PathBuf}; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_proposal::decorator_2022_03::decorator_2022_03; use swc_ecma_transforms_testing::exec_tr; -use swc_ecma_visit::from_visit_mut; +use swc_ecma_visit::visit_mut_pass; const HELPERS: &str = r###" function assertEq(callback, expected) { @@ -64,7 +64,7 @@ fn fixture(input: PathBuf) { auto_accessors: true, ..Default::default() }), - |_| from_visit_mut(decorator_2022_03()), + |_| visit_mut_pass(decorator_2022_03()), &code, ); } diff --git a/crates/swc_ecma_transforms_react/src/display_name/mod.rs b/crates/swc_ecma_transforms_react/src/display_name/mod.rs index 1bad342c7014..af4b56e0e647 100644 --- a/crates/swc_ecma_transforms_react/src/display_name/mod.rs +++ b/crates/swc_ecma_transforms_react/src/display_name/mod.rs @@ -2,7 +2,7 @@ use std::ops::DerefMut; use swc_common::DUMMY_SP; use swc_ecma_ast::*; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; #[cfg(test)] mod tests; @@ -11,7 +11,7 @@ mod tests; /// /// Add displayName to React.createClass calls pub fn display_name() -> impl Fold + VisitMut { - from_visit_mut(DisplayName) + visit_mut_pass(DisplayName) } struct DisplayName; diff --git a/crates/swc_ecma_transforms_react/src/jsx/mod.rs b/crates/swc_ecma_transforms_react/src/jsx/mod.rs index f559a24699d0..a148dee5335f 100644 --- a/crates/swc_ecma_transforms_react/src/jsx/mod.rs +++ b/crates/swc_ecma_transforms_react/src/jsx/mod.rs @@ -17,7 +17,7 @@ use swc_config::merge::Merge; use swc_ecma_ast::*; use swc_ecma_parser::{parse_file_as_expr, Syntax}; use swc_ecma_utils::{drop_span, prepend_stmt, private_ident, quote_ident, ExprFactory, StmtLike}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; use self::static_check::should_use_create_element; use crate::refresh::options::{deserialize_refresh, RefreshOptions}; @@ -193,7 +193,7 @@ pub fn jsx( where C: Comments, { - from_visit_mut(Jsx { + visit_mut_pass(Jsx { cm: cm.clone(), top_level_mark, unresolved_mark, diff --git a/crates/swc_ecma_transforms_react/src/jsx_self/mod.rs b/crates/swc_ecma_transforms_react/src/jsx_self/mod.rs index 6fbf19649a87..7bdfd482df96 100644 --- a/crates/swc_ecma_transforms_react/src/jsx_self/mod.rs +++ b/crates/swc_ecma_transforms_react/src/jsx_self/mod.rs @@ -2,7 +2,7 @@ use swc_common::DUMMY_SP; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::quote_ident; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut}; #[cfg(test)] mod tests; @@ -11,7 +11,7 @@ mod tests; /// /// Add a __self prop to all JSX Elements pub fn jsx_self(dev: bool) -> impl Fold + VisitMut { - from_visit_mut(JsxSelf { dev }) + visit_mut_pass(JsxSelf { dev }) } #[derive(Clone, Copy)] diff --git a/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs b/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs index f62f3e7e62ff..f2fe7215122b 100644 --- a/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs +++ b/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs @@ -2,14 +2,14 @@ use swc_common::{sync::Lrc, SourceMap, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::quote_ident; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; #[cfg(test)] mod tests; /// `@babel/plugin-transform-react-jsx-source` pub fn jsx_src(dev: bool, cm: Lrc) -> impl Fold + VisitMut { - from_visit_mut(JsxSrc { cm, dev }) + visit_mut_pass(JsxSrc { cm, dev }) } #[derive(Clone)] diff --git a/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs b/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs index 6a2eef5247ba..29af3edab3f7 100644 --- a/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs +++ b/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs @@ -1,7 +1,7 @@ use swc_atoms::JsWord; use swc_common::{collections::AHashMap, comments::Comments, Span}; use swc_ecma_ast::*; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; #[cfg(test)] mod tests; @@ -16,7 +16,7 @@ pub fn pure_annotations(comments: Option) -> impl Fold + VisitMut where C: Comments, { - from_visit_mut(PureAnnotations { + visit_mut_pass(PureAnnotations { imports: Default::default(), comments, }) diff --git a/crates/swc_ecma_transforms_react/src/refresh/mod.rs b/crates/swc_ecma_transforms_react/src/refresh/mod.rs index d798dabd359e..6115313447e0 100644 --- a/crates/swc_ecma_transforms_react/src/refresh/mod.rs +++ b/crates/swc_ecma_transforms_react/src/refresh/mod.rs @@ -4,7 +4,7 @@ use swc_common::{ }; use swc_ecma_ast::*; use swc_ecma_utils::{private_ident, quote_ident, quote_str, ExprFactory}; -use swc_ecma_visit::{from_visit_mut, Fold, Visit, VisitMut, VisitMutWith}; +use swc_ecma_visit::{visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith}; use self::{ hook::HookRegister, @@ -53,7 +53,7 @@ pub fn refresh( comments: Option, global_mark: Mark, ) -> impl Fold + VisitMut { - from_visit_mut(Refresh { + visit_mut_pass(Refresh { enable: dev && options.is_some(), cm, comments, diff --git a/crates/swc_ecma_transforms_testing/src/lib.rs b/crates/swc_ecma_transforms_testing/src/lib.rs index 9c5d28821f6b..71df03183acf 100644 --- a/crates/swc_ecma_transforms_testing/src/lib.rs +++ b/crates/swc_ecma_transforms_testing/src/lib.rs @@ -38,7 +38,7 @@ use swc_ecma_transforms_base::{ pass::noop, }; use swc_ecma_utils::{quote_ident, quote_str, ExprFactory}; -use swc_ecma_visit::{from_visit_mut, noop_visit_mut_type, Fold, FoldWith, VisitMut}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, FoldWith, VisitMut}; use tempfile::tempdir_in; use testing::{ assert_eq, find_executable, NormalizedOutput, CARGO_TARGET_DIR, CARGO_WORKSPACE_ROOT, @@ -242,7 +242,7 @@ where F: FnOnce(&mut Tester<'_>) -> P, P: Fold, { - chain!(op(tester), from_visit_mut(RegeneratorHandler)) + chain!(op(tester), visit_mut_pass(RegeneratorHandler)) } #[track_caller] @@ -258,7 +258,7 @@ pub fn test_transform( { Tester::run(|tester| { let expected = tester.apply_transform( - from_visit_mut(::swc_ecma_utils::DropSpan), + visit_mut_pass(::swc_ecma_utils::DropSpan), "output.js", syntax, is_module, @@ -284,7 +284,7 @@ pub fn test_transform( } let actual = actual - .fold_with(&mut from_visit_mut(::swc_ecma_utils::DropSpan)) + .fold_with(&mut visit_mut_pass(::swc_ecma_utils::DropSpan)) .fold_with(&mut hygiene::hygiene()) .fold_with(&mut fixer::fixer(Some(&tester.comments))); diff --git a/crates/swc_ecma_transforms_typescript/src/transform.rs b/crates/swc_ecma_transforms_typescript/src/transform.rs index 8a6eba162e65..081654acdcde 100644 --- a/crates/swc_ecma_transforms_typescript/src/transform.rs +++ b/crates/swc_ecma_transforms_typescript/src/transform.rs @@ -15,7 +15,7 @@ use swc_ecma_utils::{ ExprFactory, QueryRef, RefRewriter, StmtLikeInjector, }; use swc_ecma_visit::{ - from_visit_mut, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, VisitWith, }; @@ -85,7 +85,7 @@ pub fn transform( verbatim_module_syntax: bool, native_class_properties: bool, ) -> impl Fold + VisitMut { - from_visit_mut(Transform { + visit_mut_pass(Transform { unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), top_level_ctxt: SyntaxContext::empty().apply_mark(top_level_mark), import_export_assign_config, diff --git a/crates/swc_ecma_transforms_typescript/src/typescript.rs b/crates/swc_ecma_transforms_typescript/src/typescript.rs index ed6468692be5..42644e0e3581 100644 --- a/crates/swc_ecma_transforms_typescript/src/typescript.rs +++ b/crates/swc_ecma_transforms_typescript/src/typescript.rs @@ -6,7 +6,7 @@ use swc_common::{ }; use swc_ecma_ast::*; use swc_ecma_transforms_react::{parse_expr_for_jsx, JsxDirectives}; -use swc_ecma_visit::{from_visit_mut, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut, VisitMutWith}; pub use crate::config::*; use crate::{strip_import_export::StripImportExport, strip_type::StripType, transform::transform}; @@ -18,7 +18,7 @@ pub fn typescript( ) -> impl Fold + VisitMut { debug_assert_ne!(unresolved_mark, top_level_mark); - from_visit_mut(TypeScript { + visit_mut_pass(TypeScript { config, unresolved_mark, top_level_mark, @@ -151,7 +151,7 @@ pub fn tsx( where C: Comments, { - from_visit_mut(TypeScriptReact { + visit_mut_pass(TypeScriptReact { config, tsx_config, id_usage: Default::default(), diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index ad5b77bab6e8..6bbbdbb84f00 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -46,7 +46,7 @@ where } } -pub fn from_visit_mut(pass: V) -> VisitMutPass +pub fn visit_mut_pass(pass: V) -> VisitMutPass where V: VisitMut, { From a265312826c7592f0f3f95aa0d954630a3ab9c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:37:34 +0900 Subject: [PATCH 050/186] Rename `viistor` --- crates/swc_ecma_visit/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 6bbbdbb84f00..9d05d3c358b4 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -77,7 +77,7 @@ where } } -pub fn visitor(pass: V) -> VisitPass +pub fn visit_pass(pass: V) -> VisitPass where V: Visit, { From c511347a0eb9969ba7dd001582d3c7fac5c6918b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:37:48 +0900 Subject: [PATCH 051/186] Rename `from_fold` --- crates/swc_ecma_visit/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 9d05d3c358b4..0742e870b3f2 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -15,7 +15,7 @@ use swc_visit::{Repeat, Repeated}; pub use crate::generated::*; mod generated; -pub fn from_fold(pass: V) -> FoldPass +pub fn fold_pass(pass: V) -> FoldPass where V: Fold, { From fe2fba443ab7972eb43d2f0aa6916916319c2227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:38:29 +0900 Subject: [PATCH 052/186] more work --- .../src/block_scoping/mod.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs index dd5bb12af797..51915131edda 100644 --- a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs +++ b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs @@ -15,7 +15,7 @@ use swc_ecma_utils::{ ExprFactory, StmtLike, }; use swc_ecma_visit::{ - noop_visit_mut_type, visit_mut_obj_and_computed, visit_mut_pass, Fold, VisitMut, VisitMutWith, + noop_visit_mut_type, visit_mut_obj_and_computed, visit_mut_pass, VisitMut, VisitMutWith, }; use swc_trace_macro::swc_trace; @@ -34,16 +34,16 @@ mod vars; /// }); /// } /// ``` -pub fn block_scoping(unresolved_mark: Mark) -> impl VisitMut + Fold { - visit_mut_pass(chain!( - self::vars::block_scoped_vars(), - BlockScoping { +pub fn block_scoping(unresolved_mark: Mark) -> impl Pass { + chain!( + visit_mut_pass(self::vars::block_scoped_vars()), + visit_mut_pass(BlockScoping { unresolved_mark, scope: Default::default(), vars: Vec::new(), var_decl_kind: VarDeclKind::Var, - } - )) + }) + ) } type ScopeStack = SmallVec<[ScopeKind; 8]>; From a8b3e37d09905b3b8b0015645c3fd713d3abdb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:40:14 +0900 Subject: [PATCH 053/186] more work --- crates/swc_ecma_compat_es2015/src/classes/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/classes/mod.rs b/crates/swc_ecma_compat_es2015/src/classes/mod.rs index 904b61573050..100015bfc3b8 100644 --- a/crates/swc_ecma_compat_es2015/src/classes/mod.rs +++ b/crates/swc_ecma_compat_es2015/src/classes/mod.rs @@ -15,8 +15,7 @@ use swc_ecma_utils::{ ExprFactory, ModuleItemLike, StmtLike, }; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -28,7 +27,7 @@ use self::{ mod constructor; mod prop_name; -pub fn classes(config: Config) -> impl Fold + VisitMut { +pub fn classes(config: Config) -> impl Pass { visit_mut_pass(Classes { in_strict: false, config, From 0572103e08fa41d249c17f2b139dd75369924547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:40:18 +0900 Subject: [PATCH 054/186] more work --- crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs b/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs index e39f44cd0ddc..c441035a64c3 100644 --- a/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs +++ b/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs @@ -1,11 +1,11 @@ use swc_ecma_ast::*; use swc_ecma_utils::private_ident; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; struct OptionalCatchBinding; -pub fn optional_catch_binding() -> impl Fold + VisitMut { +pub fn optional_catch_binding() -> impl Pass { visit_mut_pass(OptionalCatchBinding) } From 15fd47396e2f841f8262696d8ca2d4b1754cfd58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:41:39 +0900 Subject: [PATCH 055/186] more work --- crates/swc_ecma_compat_es2015/src/computed_props.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/computed_props.rs b/crates/swc_ecma_compat_es2015/src/computed_props.rs index b60b24549cef..e63e5c9dc3d6 100644 --- a/crates/swc_ecma_compat_es2015/src/computed_props.rs +++ b/crates/swc_ecma_compat_es2015/src/computed_props.rs @@ -4,8 +4,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::helper; use swc_ecma_utils::{quote_ident, ExprFactory, StmtLike}; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -40,7 +39,7 @@ use swc_trace_macro::swc_trace; /// /// TODO(kdy1): cache reference like (_f = f, mutatorMap[_f].get = function(){}) /// instead of (mutatorMap[f].get = function(){} -pub fn computed_properties(c: Config) -> impl Fold { +pub fn computed_properties(c: Config) -> impl Pass { visit_mut_pass(ComputedProps { c, ..Default::default() From fe4ae14867c82cbee5f5c435e6757fbb5c9a15c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:42:25 +0900 Subject: [PATCH 056/186] more work --- crates/swc_ecma_compat_es2015/src/parameters.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_compat_es2015/src/parameters.rs b/crates/swc_ecma_compat_es2015/src/parameters.rs index b1f35de00ac8..ba599b879151 100644 --- a/crates/swc_ecma_compat_es2015/src/parameters.rs +++ b/crates/swc_ecma_compat_es2015/src/parameters.rs @@ -14,7 +14,7 @@ use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitM use swc_trace_macro::swc_trace; use tracing::trace; -pub fn parameters(c: Config, unresolved_mark: Mark) -> impl 'static + Fold { +pub fn parameters(c: Config, unresolved_mark: Mark) -> impl 'static + Pass { let unresolved_ctxt = SyntaxContext::empty().apply_mark(unresolved_mark); visit_mut_pass(Params { c, From ad8bad11958a4ee3fcdd415d76051bc2a9dbde07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:42:47 +0900 Subject: [PATCH 057/186] more work --- crates/swc_ecma_compat_es2015/src/new_target.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/new_target.rs b/crates/swc_ecma_compat_es2015/src/new_target.rs index b348611bd832..0d6c29059679 100644 --- a/crates/swc_ecma_compat_es2015/src/new_target.rs +++ b/crates/swc_ecma_compat_es2015/src/new_target.rs @@ -5,11 +5,11 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{should_work, Check}; use swc_ecma_utils::{private_ident, quote_ident, ExprFactory}; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith, }; use swc_trace_macro::swc_trace; -pub fn new_target() -> impl Fold + VisitMut + CompilerPass { +pub fn new_target() -> impl Pass { visit_mut_pass(NewTarget { ctx: Ctx::Constructor, }) From 2763b7c1f331c9df8056aa967e07ef2ffa981642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:42:52 +0900 Subject: [PATCH 058/186] more work --- crates/swc_ecma_compat_es2015/src/sticky_regex.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/sticky_regex.rs b/crates/swc_ecma_compat_es2015/src/sticky_regex.rs index 90edd27c3d48..f773f197d760 100644 --- a/crates/swc_ecma_compat_es2015/src/sticky_regex.rs +++ b/crates/swc_ecma_compat_es2015/src/sticky_regex.rs @@ -1,7 +1,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{quote_ident, ExprFactory}; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// Compile ES2015 sticky regex to an ES5 RegExp constructor @@ -18,7 +18,7 @@ use swc_trace_macro::swc_trace; /// ```js /// new RegExp("o+", "y") /// ``` -pub fn sticky_regex() -> impl 'static + Fold + VisitMut { +pub fn sticky_regex() -> impl Pass { visit_mut_pass(StickyRegex) } From 0c614b81729da252f6ad4b4c28e906499ae78237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:43:22 +0900 Subject: [PATCH 059/186] more work --- crates/swc_ecma_compat_es2015/src/shorthand_property.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/shorthand_property.rs b/crates/swc_ecma_compat_es2015/src/shorthand_property.rs index 80251ced7c52..75af36d78914 100644 --- a/crates/swc_ecma_compat_es2015/src/shorthand_property.rs +++ b/crates/swc_ecma_compat_es2015/src/shorthand_property.rs @@ -1,7 +1,7 @@ use swc_common::util::take::Take; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// Compile ES2015 shorthand properties to ES5 @@ -38,7 +38,7 @@ use swc_trace_macro::swc_trace; /// } /// }; /// ``` -pub fn shorthand() -> impl 'static + Fold + VisitMut { +pub fn shorthand() -> impl Pass { visit_mut_pass(Shorthand) } From 283a260ace8d3c2b7dd86557dd2c8dfd7b038d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:44:03 +0900 Subject: [PATCH 060/186] more work --- crates/swc_ecma_compat_es2015/src/spread.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/spread.rs b/crates/swc_ecma_compat_es2015/src/spread.rs index 6e19c1fcd88b..8592c7cf42f3 100644 --- a/crates/swc_ecma_compat_es2015/src/spread.rs +++ b/crates/swc_ecma_compat_es2015/src/spread.rs @@ -9,12 +9,11 @@ use swc_ecma_utils::{ alias_ident_for, member_expr, prepend_stmt, quote_ident, ExprFactory, StmtLike, }; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; -pub fn spread(c: Config) -> impl Fold + VisitMut { +pub fn spread(c: Config) -> impl Pass { visit_mut_pass(Spread { c, vars: Default::default(), From 2ccfaf92c2be39a890381141b41d120132378f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:44:08 +0900 Subject: [PATCH 061/186] more work --- crates/swc_ecma_compat_es2015/src/template_literal.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/template_literal.rs b/crates/swc_ecma_compat_es2015/src/template_literal.rs index a4813c0ec4d8..a98b169d1c36 100644 --- a/crates/swc_ecma_compat_es2015/src/template_literal.rs +++ b/crates/swc_ecma_compat_es2015/src/template_literal.rs @@ -6,10 +6,10 @@ use swc_common::{util::take::Take, BytePos, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Parallel}; use swc_ecma_utils::{is_literal, prepend_stmts, private_ident, quote_ident, ExprFactory}; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; -pub fn template_literal(c: Config) -> impl Fold + VisitMut { +pub fn template_literal(c: Config) -> impl Pass { visit_mut_pass(TemplateLiteral { c, ..Default::default() From e6ca08d38832f6a1499ce4dbe32d809089f9d369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:44:35 +0900 Subject: [PATCH 062/186] more work --- crates/swc_ecma_compat_es2015/src/parameters.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_compat_es2015/src/parameters.rs b/crates/swc_ecma_compat_es2015/src/parameters.rs index ba599b879151..39a662b6d4ec 100644 --- a/crates/swc_ecma_compat_es2015/src/parameters.rs +++ b/crates/swc_ecma_compat_es2015/src/parameters.rs @@ -10,7 +10,7 @@ use swc_ecma_utils::{ function::{init_this, FnEnvHoister}, member_expr, prepend_stmt, prepend_stmts, private_ident, quote_ident, ExprFactory, }; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; use tracing::trace; From e0dcb576a3d515d9335351a3cc3a96374656352a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:44:52 +0900 Subject: [PATCH 063/186] more work --- crates/swc_ecma_compat_es2015/src/function_name.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/function_name.rs b/crates/swc_ecma_compat_es2015/src/function_name.rs index 21666000c3ae..633d248bde5d 100644 --- a/crates/swc_ecma_compat_es2015/src/function_name.rs +++ b/crates/swc_ecma_compat_es2015/src/function_name.rs @@ -2,7 +2,7 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{private_ident, IdentUsageFinder}; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-function-name` @@ -22,7 +22,7 @@ use swc_trace_macro::swc_trace; /// } /// var Foo = (class Foo {}); /// ``` -pub fn function_name() -> impl 'static + Copy + Fold + VisitMut { +pub fn function_name() -> impl Pass { visit_mut_pass(FnName) } From 13a8991629fd211129daba55b367d33e035c7f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:45:50 +0900 Subject: [PATCH 064/186] more work --- crates/swc_ecma_compat_es2015/src/instanceof.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/instanceof.rs b/crates/swc_ecma_compat_es2015/src/instanceof.rs index d60763d4a8f9..f777e97a2164 100644 --- a/crates/swc_ecma_compat_es2015/src/instanceof.rs +++ b/crates/swc_ecma_compat_es2015/src/instanceof.rs @@ -2,7 +2,7 @@ use swc_common::{util::take::Take, Span, Spanned}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Parallel}; use swc_ecma_utils::ExprFactory; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-instanceof` @@ -30,7 +30,7 @@ use swc_trace_macro::swc_trace; /// /// _instanceof(foo, Bar); /// ``` -pub fn instance_of() -> impl Fold + VisitMut { +pub fn instance_of() -> impl Pass { visit_mut_pass(InstanceOf) } struct InstanceOf; From 7d7d4f9d1fd770af02d3c756119b57b9deb9eb26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:45:54 +0900 Subject: [PATCH 065/186] more work --- crates/swc_ecma_transforms_proposal/src/decorator_impl.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs b/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs index ec62ff4f59ab..0b76e405a7d9 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs @@ -10,11 +10,11 @@ use swc_ecma_utils::{ is_maybe_branch_directive, private_ident, prop_name_to_expr_value, quote_ident, replace_ident, stack_size::maybe_grow_default, ExprFactory, IdentRenamer, }; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use crate::DecoratorVersion; -pub(crate) fn decorator_impl(version: DecoratorVersion) -> impl VisitMut + Fold { +pub(crate) fn decorator_impl(version: DecoratorVersion) -> impl Pass { visit_mut_pass(DecoratorPass { version, ..Default::default() From 977047f9b73fb24ef076fecd754138cdf7062e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:46:03 +0900 Subject: [PATCH 066/186] more work --- crates/swc_ecma_transforms_react/src/jsx_src/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs b/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs index f2fe7215122b..615cfb194d29 100644 --- a/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs +++ b/crates/swc_ecma_transforms_react/src/jsx_src/mod.rs @@ -2,13 +2,13 @@ use swc_common::{sync::Lrc, SourceMap, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::quote_ident; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; #[cfg(test)] mod tests; /// `@babel/plugin-transform-react-jsx-source` -pub fn jsx_src(dev: bool, cm: Lrc) -> impl Fold + VisitMut { +pub fn jsx_src(dev: bool, cm: Lrc) -> impl Pass { visit_mut_pass(JsxSrc { cm, dev }) } From f4b3ee704e1588f9243fad30be4c4c7744d7c6be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:46:08 +0900 Subject: [PATCH 067/186] more work --- crates/swc_ecma_compat_es2018/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_compat_es2018/src/lib.rs b/crates/swc_ecma_compat_es2018/src/lib.rs index 041032b2102c..e5d86b642acf 100644 --- a/crates/swc_ecma_compat_es2018/src/lib.rs +++ b/crates/swc_ecma_compat_es2018/src/lib.rs @@ -2,7 +2,7 @@ #![allow(clippy::boxed_local)] use serde::Deserialize; -use swc_common::chain; +use swc_ecma_ast::chain; use swc_ecma_compat_common::regexp::{self, regexp}; use swc_ecma_visit::Fold; From c8d6666a8a3037eaf0e6124d3990c0a3a82cbe0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:47:16 +0900 Subject: [PATCH 068/186] more work --- crates/swc_ecma_transforms_module/src/common_js.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_module/src/common_js.rs b/crates/swc_ecma_transforms_module/src/common_js.rs index b105088f7c60..f85b0e7b1a2e 100644 --- a/crates/swc_ecma_transforms_module/src/common_js.rs +++ b/crates/swc_ecma_transforms_module/src/common_js.rs @@ -7,7 +7,7 @@ use swc_ecma_transforms_base::{feature::FeatureFlag, helper_expr}; use swc_ecma_utils::{ member_expr, private_ident, quote_expr, quote_ident, ExprFactory, FunctionFactory, IsDirective, }; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; pub use super::util::Config; use crate::{ @@ -28,7 +28,7 @@ pub fn common_js( unresolved_mark: Mark, config: Config, available_features: FeatureFlag, -) -> impl Fold + VisitMut { +) -> impl Pass { visit_mut_pass(Cjs { config, resolver, From 474b35ec09296775bc3e6267cd3e45e7b9bf33fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:47:22 +0900 Subject: [PATCH 069/186] more work --- crates/swc_ecma_transforms_module/src/umd.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_module/src/umd.rs b/crates/swc_ecma_transforms_module/src/umd.rs index 888520f76ea0..8aefd94498cd 100644 --- a/crates/swc_ecma_transforms_module/src/umd.rs +++ b/crates/swc_ecma_transforms_module/src/umd.rs @@ -9,7 +9,7 @@ use swc_ecma_transforms_base::{feature::FeatureFlag, helper_expr}; use swc_ecma_utils::{ is_valid_prop_ident, private_ident, quote_ident, quote_str, ExprFactory, IsDirective, }; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use self::config::BuiltConfig; pub use self::config::Config; @@ -33,7 +33,7 @@ pub fn umd( unresolved_mark: Mark, config: Config, available_features: FeatureFlag, -) -> impl Fold + VisitMut { +) -> impl Pass { visit_mut_pass(Umd { config: config.build(cm.clone()), unresolved_mark, From 0dbd6a9985b5b85df12433a6653f81c2c5391d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:48:40 +0900 Subject: [PATCH 070/186] more work --- crates/swc_ecma_compat_es2015/src/generator.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/generator.rs b/crates/swc_ecma_compat_es2015/src/generator.rs index fe9ceabeaba2..6303ab11178d 100644 --- a/crates/swc_ecma_compat_es2015/src/generator.rs +++ b/crates/swc_ecma_compat_es2015/src/generator.rs @@ -17,13 +17,12 @@ use swc_ecma_utils::{ function::FnEnvHoister, private_ident, prop_name_to_expr_value, quote_ident, ExprFactory, }; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith, VisitWith, }; use tracing::debug; /// Generator based on tsc generator at https://github.com/microsoft/TypeScript/blob/162224763681465b417274383317ca9a0a573835/src/compiler/transformers/generators.ts -pub fn generator(unresolved_mark: Mark, _comments: C) -> impl VisitMut + Fold +pub fn generator(unresolved_mark: Mark, _comments: C) -> impl Pass where C: Comments, { From 06cd5fd4233049b52aab9d253c36adc66e85b9d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:50:05 +0900 Subject: [PATCH 071/186] more --- crates/swc_ecma_compat_es2019/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2019/src/lib.rs b/crates/swc_ecma_compat_es2019/src/lib.rs index 417b961cb318..f9beb1b7595f 100644 --- a/crates/swc_ecma_compat_es2019/src/lib.rs +++ b/crates/swc_ecma_compat_es2019/src/lib.rs @@ -1,9 +1,9 @@ -use swc_ecma_visit::Fold; +use swc_ecma_ast::Pass; pub use self::optional_catch_binding::optional_catch_binding; mod optional_catch_binding; -pub fn es2019() -> impl Fold { +pub fn es2019() -> impl Pass { optional_catch_binding() } From a18a99066590ec798ad4e3f7450a84b88231c5c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:50:14 +0900 Subject: [PATCH 072/186] more --- crates/swc_ecma_compat_es2021/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2021/src/lib.rs b/crates/swc_ecma_compat_es2021/src/lib.rs index 5c7cb4944659..061287b9992e 100644 --- a/crates/swc_ecma_compat_es2021/src/lib.rs +++ b/crates/swc_ecma_compat_es2021/src/lib.rs @@ -1,9 +1,9 @@ -use swc_ecma_visit::{Fold, VisitMut}; +use swc_ecma_ast::Pass; pub use self::logical_assignments::logical_assignments; mod logical_assignments; -pub fn es2021() -> impl Fold + VisitMut { +pub fn es2021() -> impl Pass { logical_assignments() } From afa16656b0ab219a405bce972aea07c8be931398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:50:38 +0900 Subject: [PATCH 073/186] more --- crates/swc_ecma_compat_es2021/src/logical_assignments.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2021/src/logical_assignments.rs b/crates/swc_ecma_compat_es2021/src/logical_assignments.rs index e56ff1e13124..657d7d266a62 100644 --- a/crates/swc_ecma_compat_es2021/src/logical_assignments.rs +++ b/crates/swc_ecma_compat_es2021/src/logical_assignments.rs @@ -4,10 +4,10 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{alias_ident_for, prepend_stmt}; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; -pub fn logical_assignments() -> impl Fold + VisitMut { +pub fn logical_assignments() -> impl Pass { visit_mut_pass(Operators::default()) } From ae63398e7546332a088f0ce255830c642d076dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:50:42 +0900 Subject: [PATCH 074/186] more --- crates/swc_ecma_compat_es2022/src/class_properties/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs b/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs index 83b0f16df0b9..04204fd3247a 100644 --- a/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs +++ b/crates/swc_ecma_compat_es2022/src/class_properties/mod.rs @@ -12,8 +12,7 @@ use swc_ecma_utils::{ ModuleItemLike, StmtLike, }; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -41,7 +40,7 @@ mod used_name; /// # Impl note /// /// We use custom helper to handle export default class -pub fn class_properties(config: Config, unresolved_mark: Mark) -> impl Fold + VisitMut { +pub fn class_properties(config: Config, unresolved_mark: Mark) -> impl Pass { visit_mut_pass(ClassProperties { c: config, private: PrivateRecord::new(), From f582514a607668743b420f96c8e7f4e5a2f697c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:50:47 +0900 Subject: [PATCH 075/186] more --- crates/swc_ecma_compat_es2015/src/object_super.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/object_super.rs b/crates/swc_ecma_compat_es2015/src/object_super.rs index e9d0030224ba..5683af090cf8 100644 --- a/crates/swc_ecma_compat_es2015/src/object_super.rs +++ b/crates/swc_ecma_compat_es2015/src/object_super.rs @@ -6,14 +6,14 @@ use swc_ecma_transforms_base::helper; use swc_ecma_utils::{ alias_ident_for, is_rest_arguments, prepend_stmt, private_ident, quote_ident, ExprFactory, }; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; struct ObjectSuper { extra_vars: Vec, } -pub fn object_super() -> impl Fold + VisitMut { +pub fn object_super() -> impl Pass { visit_mut_pass(ObjectSuper { extra_vars: Vec::new(), }) From c8593335dfd52a51020aa90e7053cf501dd1c2b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:52:07 +0900 Subject: [PATCH 076/186] more --- crates/swc_ecma_lints/examples/all.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/swc_ecma_lints/examples/all.rs b/crates/swc_ecma_lints/examples/all.rs index 9504c5246456..68553302521b 100644 --- a/crates/swc_ecma_lints/examples/all.rs +++ b/crates/swc_ecma_lints/examples/all.rs @@ -3,7 +3,6 @@ use swc_ecma_ast::*; use swc_ecma_lints::{rule::Rule, rules::LintParams}; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; -use swc_ecma_visit::VisitMutWith; fn main() { // testing::run_test creates Lrc and `&Handler` for you @@ -33,7 +32,7 @@ fn main() { let unresolved_ctxt = SyntaxContext::empty().apply_mark(unresolved_mark); let top_level_ctxt = SyntaxContext::empty().apply_mark(top_level_mark); - program.visit_mut_with(&mut resolver(unresolved_mark, top_level_mark, false)); + program.mutate(resolver(unresolved_mark, top_level_mark, false)); let mut rules = swc_ecma_lints::rules::all(LintParams { program: &program, From 67cf6b38906f4ea070641d333a6bea2ea1d76f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:52:22 +0900 Subject: [PATCH 077/186] more --- crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs b/crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs index 3cd36353e6cc..bf4db8b8fef4 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs @@ -1,7 +1,7 @@ -use swc_ecma_visit::{Fold, VisitMut}; +use swc_ecma_ast::Pass; use crate::{decorator_impl::decorator_impl, DecoratorVersion}; -pub fn decorator_2022_03() -> impl VisitMut + Fold { +pub fn decorator_2022_03() -> impl Pass { decorator_impl(DecoratorVersion::V202203) } From b929b6d1fbbd3132f36d780c0885429b6e37c4ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:54:58 +0900 Subject: [PATCH 078/186] more --- crates/swc_ecma_compat_es2015/src/duplicate_keys.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs b/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs index aa8a590e7ff0..cfa66eca96d5 100644 --- a/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs +++ b/crates/swc_ecma_compat_es2015/src/duplicate_keys.rs @@ -3,10 +3,10 @@ use swc_common::{collections::AHashSet, Spanned}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::quote_str; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; -pub fn duplicate_keys() -> impl Fold + VisitMut { +pub fn duplicate_keys() -> impl Pass { visit_mut_pass(DuplicateKeys) } From a1dce2e9b0a0e8d514adcb836e0064f4519301fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:55:04 +0900 Subject: [PATCH 079/186] more --- crates/swc_ecma_compat_es2015/src/typeof_symbol.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs b/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs index 5df64414df0b..1e8c1b64011f 100644 --- a/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs +++ b/crates/swc_ecma_compat_es2015/src/typeof_symbol.rs @@ -2,10 +2,10 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Parallel}; use swc_ecma_utils::{quote_str, ExprFactory}; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; -pub fn typeof_symbol() -> impl VisitMut + Fold { +pub fn typeof_symbol() -> impl Pass { visit_mut_pass(TypeOfSymbol) } From 4eef92ec61f2d349b7b4b4571172cf5ab7f9182e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:58:02 +0900 Subject: [PATCH 080/186] more --- crates/swc_ecma_compat_es3/src/prop_lits.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_es3/src/prop_lits.rs b/crates/swc_ecma_compat_es3/src/prop_lits.rs index bf22ba042dc1..757c84d6158d 100644 --- a/crates/swc_ecma_compat_es3/src/prop_lits.rs +++ b/crates/swc_ecma_compat_es3/src/prop_lits.rs @@ -1,6 +1,6 @@ use swc_ecma_ast::*; use swc_ecma_utils::is_valid_ident; -use swc_ecma_visit::{standard_only_fold, Fold, FoldWith}; +use swc_ecma_visit::{fold_pass, standard_only_fold, Fold, FoldWith}; use swc_trace_macro::swc_trace; /// babel: `transform-property-literals` @@ -30,8 +30,8 @@ use swc_trace_macro::swc_trace; /// foo: 1 /// }; /// ``` -pub fn property_literals() -> impl Fold { - PropertyLiteral +pub fn property_literals() -> impl Pass { + fold_pass(PropertyLiteral) } struct PropertyLiteral; From fe74c4fc32ed2adc60a3e2a232e7131ccd54f7f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:58:07 +0900 Subject: [PATCH 081/186] more --- crates/swc_ecma_compat_es3/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_es3/src/lib.rs b/crates/swc_ecma_compat_es3/src/lib.rs index c8556f53aad9..e284cf701d5b 100644 --- a/crates/swc_ecma_compat_es3/src/lib.rs +++ b/crates/swc_ecma_compat_es3/src/lib.rs @@ -1,5 +1,4 @@ -use swc_common::chain; -use swc_ecma_visit::Fold; +use swc_ecma_ast::{chain, Pass}; pub use self::{ member_expr_lits::member_expression_literals, prop_lits::property_literals, @@ -11,7 +10,7 @@ mod prop_lits; mod reserved_word; /// Make output es3-compatible. -pub fn es3(preserve_import: bool) -> impl Fold { +pub fn es3(preserve_import: bool) -> impl Pass { chain!( property_literals(), member_expression_literals(), From cf0f2eb70b56e38f3267e9b3f8b7a1cf3ffe712a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:58:12 +0900 Subject: [PATCH 082/186] more --- crates/swc_ecma_compat_es3/src/reserved_word.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es3/src/reserved_word.rs b/crates/swc_ecma_compat_es3/src/reserved_word.rs index 20ceae2518ce..280c1575528b 100644 --- a/crates/swc_ecma_compat_es3/src/reserved_word.rs +++ b/crates/swc_ecma_compat_es3/src/reserved_word.rs @@ -1,6 +1,6 @@ use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; /// babel: `@babel/plugin-transform-reserved-words` /// @@ -19,7 +19,7 @@ use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitM /// var _abstract = 1; /// var x = _abstract + 1; /// ``` -pub fn reserved_words(preserve_import: bool) -> impl VisitMut + Fold { +pub fn reserved_words(preserve_import: bool) -> impl Pass { visit_mut_pass(ReservedWord { preserve_import }) } struct ReservedWord { From f29fc29dc200cc9ae084746f44eccf5e3c075e32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 15:59:17 +0900 Subject: [PATCH 083/186] impl Pass for Option --- crates/swc_ecma_ast/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index f1f6dea3a834..d32087d26ba3 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -99,6 +99,18 @@ pub trait Pass { fn process(self, program: &mut Program); } +/// Optional pass implementation. +impl

Pass for Option

+where + P: Pass, +{ + fn process(self, program: &mut Program) { + if let Some(pass) = self { + pass.process(program); + } + } +} + impl Program { #[inline(always)] pub fn mutate

(&mut self, pass: P) From 83cb704cb21a58bd68a4a98ddf0cbf43c7744550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:01:14 +0900 Subject: [PATCH 084/186] more --- crates/swc_ecma_compat_es2015/src/for_of.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/for_of.rs b/crates/swc_ecma_compat_es2015/src/for_of.rs index 3099571c32fc..133c4c00497b 100644 --- a/crates/swc_ecma_compat_es2015/src/for_of.rs +++ b/crates/swc_ecma_compat_es2015/src/for_of.rs @@ -11,7 +11,7 @@ use swc_ecma_transforms_macros::parallel; use swc_ecma_utils::{ alias_if_required, member_expr, prepend_stmt, private_ident, quote_ident, ExprFactory, }; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-for-of` @@ -48,7 +48,7 @@ use swc_trace_macro::swc_trace; /// } /// } /// ``` -pub fn for_of(c: Config) -> impl Fold + VisitMut { +pub fn for_of(c: Config) -> impl Pass { visit_mut_pass(ForOf { c, top_level_vars: Default::default(), From a3778d44b34f93f7dabd42ab1285d498511d702b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:01:19 +0900 Subject: [PATCH 085/186] more --- crates/swc_ecma_transforms_optimization/src/inline_globals.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_optimization/src/inline_globals.rs b/crates/swc_ecma_transforms_optimization/src/inline_globals.rs index 50ae7c228c11..1b7797d61c9b 100644 --- a/crates/swc_ecma_transforms_optimization/src/inline_globals.rs +++ b/crates/swc_ecma_transforms_optimization/src/inline_globals.rs @@ -18,7 +18,7 @@ pub fn inline_globals( envs: Lrc>, globals: Lrc>, typeofs: Lrc>, -) -> impl Fold + VisitMut { +) -> impl Pass { inline_globals2(envs, globals, Default::default(), typeofs) } @@ -33,7 +33,7 @@ pub fn inline_globals2( globals: Lrc>, global_exprs: GlobalExprMap, typeofs: Lrc>, -) -> impl Fold + VisitMut { +) -> impl Pass { visit_mut_pass(InlineGlobals { envs, globals, From 34f5a26b8d733b4ebad37f401cac7febf91f721e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:02:15 +0900 Subject: [PATCH 086/186] more --- crates/swc_ecma_transforms_module/src/import_analysis.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/swc_ecma_transforms_module/src/import_analysis.rs b/crates/swc_ecma_transforms_module/src/import_analysis.rs index cbe9783fcc61..e3fe05397304 100644 --- a/crates/swc_ecma_transforms_module/src/import_analysis.rs +++ b/crates/swc_ecma_transforms_module/src/import_analysis.rs @@ -3,15 +3,12 @@ use swc_common::collections::AHashMap; use swc_ecma_ast::*; use swc_ecma_transforms_base::enable_helper; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitWith, }; use crate::{module_decl_strip::LinkFlag, util::ImportInterop}; -pub fn import_analyzer( - import_interop: ImportInterop, - ignore_dynamic: bool, -) -> impl Fold + VisitMut { +pub fn import_analyzer(import_interop: ImportInterop, ignore_dynamic: bool) -> impl Pass { visit_mut_pass(ImportAnalyzer { import_interop, ignore_dynamic, From ed86e8a406dc3056020d2eb0097667761472a246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:02:20 +0900 Subject: [PATCH 087/186] more --- crates/swc_ecma_compat_es3/src/member_expr_lits.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_es3/src/member_expr_lits.rs b/crates/swc_ecma_compat_es3/src/member_expr_lits.rs index ef43cce475c8..3ebf21b1b52e 100644 --- a/crates/swc_ecma_compat_es3/src/member_expr_lits.rs +++ b/crates/swc_ecma_compat_es3/src/member_expr_lits.rs @@ -1,6 +1,6 @@ use swc_ecma_ast::*; use swc_ecma_utils::is_valid_ident; -use swc_ecma_visit::{standard_only_fold, Fold, FoldWith}; +use swc_ecma_visit::{fold_pass, standard_only_fold, Fold, FoldWith}; use swc_trace_macro::swc_trace; /// babel: `transform-member-expression-literals` @@ -20,8 +20,8 @@ use swc_trace_macro::swc_trace; /// obj["const"] = "isKeyword"; /// obj["var"] = "isKeyword"; /// ``` -pub fn member_expression_literals() -> impl Fold { - MemberExprLit +pub fn member_expression_literals() -> impl Pass { + fold_pass(MemberExprLit) } #[derive(Default, Clone, Copy)] struct MemberExprLit; From c23751ed67a1db449d54809258af197c7d51e9a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:02:24 +0900 Subject: [PATCH 088/186] more --- crates/swc_ecma_compat_es2016/src/exponentiation.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2016/src/exponentiation.rs b/crates/swc_ecma_compat_es2016/src/exponentiation.rs index 1da05fcff74f..2f515da4a2d5 100644 --- a/crates/swc_ecma_compat_es2016/src/exponentiation.rs +++ b/crates/swc_ecma_compat_es2016/src/exponentiation.rs @@ -3,7 +3,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{ParExplode, Parallel}; use swc_ecma_transforms_macros::parallel; use swc_ecma_utils::{member_expr, private_ident, ExprFactory}; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// `@babel/plugin-transform-exponentiation-operator` @@ -25,7 +25,7 @@ use swc_trace_macro::swc_trace; /// /// x = Math.pow(x, 3); /// ``` -pub fn exponentiation() -> impl Fold + VisitMut { +pub fn exponentiation() -> impl Pass { visit_mut_pass(Exponentiation::default()) } From af4f7a7ce06533f7f880dadc26176c20c2dbd2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:02:29 +0900 Subject: [PATCH 089/186] more --- crates/swc_ecma_compat_es2017/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2017/src/lib.rs b/crates/swc_ecma_compat_es2017/src/lib.rs index bded16d95c0e..208e9ed4f28f 100644 --- a/crates/swc_ecma_compat_es2017/src/lib.rs +++ b/crates/swc_ecma_compat_es2017/src/lib.rs @@ -1,12 +1,12 @@ use serde::Deserialize; use swc_common::Mark; -use swc_ecma_visit::Fold; +use swc_ecma_ast::Pass; pub use self::async_to_generator::async_to_generator; pub mod async_to_generator; -pub fn es2017(c: Config, unresolved_mark: Mark) -> impl Fold { +pub fn es2017(c: Config, unresolved_mark: Mark) -> impl Pass { async_to_generator(c.async_to_generator, unresolved_mark) } From c4dc590109a50ffcee2d2e81313c30952624bb76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:03:29 +0900 Subject: [PATCH 090/186] more --- crates/swc_ecma_compat_es2022/src/private_in_object.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2022/src/private_in_object.rs b/crates/swc_ecma_compat_es2022/src/private_in_object.rs index f690c6e5b1f3..6d35d7b4f415 100644 --- a/crates/swc_ecma_compat_es2022/src/private_in_object.rs +++ b/crates/swc_ecma_compat_es2022/src/private_in_object.rs @@ -9,14 +9,13 @@ use swc_common::{ DUMMY_SP, }; use swc_ecma_ast::*; -use swc_ecma_transforms_base::pass::JsPass; use swc_ecma_utils::{default_constructor, prepend_stmt, private_ident, quote_ident, ExprFactory}; use swc_ecma_visit::{ noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith, VisitWith, }; /// https://github.com/tc39/proposal-private-fields-in-in -pub fn private_in_object() -> impl JsPass { +pub fn private_in_object() -> impl Pass { visit_mut_pass(PrivateInObject::default()) } From 138f0a25094ff38ae0cfcd4228a5adb09f59d0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:03:34 +0900 Subject: [PATCH 091/186] more --- crates/swc_ecma_compat_es2016/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_compat_es2016/src/lib.rs b/crates/swc_ecma_compat_es2016/src/lib.rs index 570d698b9947..b7e53f0f3d98 100644 --- a/crates/swc_ecma_compat_es2016/src/lib.rs +++ b/crates/swc_ecma_compat_es2016/src/lib.rs @@ -1,12 +1,12 @@ #![allow(clippy::boxed_local)] #![allow(clippy::vec_box)] -use swc_ecma_visit::Fold; +use swc_ecma_ast::Pass; pub use self::exponentiation::exponentiation; mod exponentiation; -pub fn es2016() -> impl Fold { +pub fn es2016() -> impl Pass { exponentiation() } From 2d52db9f4cef8e014309c2336c56a473e463134d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:04:42 +0900 Subject: [PATCH 092/186] Improve Pass API --- crates/swc_ecma_ast/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index d32087d26ba3..f560b65d0f7b 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -104,6 +104,7 @@ impl

Pass for Option

where P: Pass, { + #[inline(always)] fn process(self, program: &mut Program) { if let Some(pass) = self { pass.process(program); @@ -111,6 +112,16 @@ where } } +impl

Pass for Box

+where + P: Pass, +{ + #[inline(always)] + fn process(self, program: &mut Program) { + (*self).process(program); + } +} + impl Program { #[inline(always)] pub fn mutate

(&mut self, pass: P) From 740a29e0db9529d7d8b7207bd5f99fc04fbbb45a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:05:29 +0900 Subject: [PATCH 093/186] more --- crates/swc_ecma_compat_es2018/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_es2018/src/lib.rs b/crates/swc_ecma_compat_es2018/src/lib.rs index e5d86b642acf..d10171d82f00 100644 --- a/crates/swc_ecma_compat_es2018/src/lib.rs +++ b/crates/swc_ecma_compat_es2018/src/lib.rs @@ -2,9 +2,8 @@ #![allow(clippy::boxed_local)] use serde::Deserialize; -use swc_ecma_ast::chain; +use swc_ecma_ast::{chain, Pass}; use swc_ecma_compat_common::regexp::{self, regexp}; -use swc_ecma_visit::Fold; pub use self::object_rest_spread::object_rest_spread; @@ -12,7 +11,7 @@ mod object_rest; pub mod object_rest_spread; mod object_spread; -pub fn es2018(c: Config) -> impl Fold { +pub fn es2018(c: Config) -> impl Pass { chain!( regexp(regexp::Config { dot_all_regex: true, From 8bd30d1eea8e044ec417aee34d995b210b8ad15c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:05:34 +0900 Subject: [PATCH 094/186] more --- .../swc_ecma_compat_es2018/src/object_rest_spread.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs b/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs index 3fa3fae7ea54..a70937f6cb1a 100644 --- a/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs +++ b/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs @@ -1,20 +1,20 @@ use serde::Deserialize; -use swc_common::chain; -use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut}; +use swc_ecma_ast::{chain, Pass}; +use swc_ecma_visit::visit_mut_pass; -use super::{object_rest::ObjectRest, object_spread::ObjectSpread}; +use crate::{object_rest::ObjectRest, object_spread::ObjectSpread}; // TODO: currently swc behaves like babel with // `ignoreFunctionLength` on /// `@babel/plugin-proposal-object-rest-spread` -pub fn object_rest_spread(config: Config) -> impl Fold + VisitMut { +pub fn object_rest_spread(config: Config) -> impl Pass { chain!( - from_visit_mut(ObjectRest { + visit_mut_pass(ObjectRest { config, ..Default::default() }), - from_visit_mut(ObjectSpread { config }) + visit_mut_pass(ObjectSpread { config }) ) } From 8288697d22c7d68cc6b5cc0c0dcb7f6acb9b0835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:05:39 +0900 Subject: [PATCH 095/186] more --- crates/swc_ecma_lints/tests/fixture.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/swc_ecma_lints/tests/fixture.rs b/crates/swc_ecma_lints/tests/fixture.rs index 57a1d79c65be..bf09c5fa0b8d 100644 --- a/crates/swc_ecma_lints/tests/fixture.rs +++ b/crates/swc_ecma_lints/tests/fixture.rs @@ -9,7 +9,6 @@ use swc_ecma_lints::{ }; use swc_ecma_parser::{lexer::Lexer, Parser, Syntax}; use swc_ecma_transforms_base::resolver; -use swc_ecma_visit::VisitMutWith; #[testing::fixture("tests/pass/**/input.js")] #[testing::fixture("tests/pass/**/input.ts")] @@ -42,7 +41,7 @@ fn pass(input: PathBuf) { let need_ts = input.extension().unwrap() == "ts" || input.extension().unwrap() == "tsx"; - program.visit_mut_with(&mut resolver(unresolved_mark, top_level_mark, need_ts)); + program.mutate(resolver(unresolved_mark, top_level_mark, need_ts)); let unresolved_ctxt = SyntaxContext::empty().apply_mark(unresolved_mark); let top_level_ctxt = SyntaxContext::empty().apply_mark(top_level_mark); From 8abadf90642a14865e9678992c4ac862f2307417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:06:46 +0900 Subject: [PATCH 096/186] more --- .../swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs b/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs index 6d2bbc251af2..b3395741ab60 100644 --- a/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs +++ b/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs @@ -2,7 +2,7 @@ use swc_common::{util::take::Take, Mark, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_compat_es2015::arrow; use swc_ecma_utils::prepend_stmt; -use swc_ecma_visit::{standard_only_fold, Fold, FoldWith, InjectVars}; +use swc_ecma_visit::{standard_only_fold, Fold, FoldWith, InjectVars, VisitMutWith}; use swc_trace_macro::swc_trace; /// A bugfix pass for Safari 10.3. @@ -45,7 +45,7 @@ impl Fold for AsyncArrowsInClass { } fn fold_expr(&mut self, n: Expr) -> Expr { - let n = n.fold_children_with(self); + let mut n = n.fold_children_with(self); if !self.in_class_method { return n; } @@ -54,7 +54,7 @@ impl Fold for AsyncArrowsInClass { Expr::Arrow(ref a) => { if a.is_async { let mut v = arrow(self.unresolved_mark); - let n = n.fold_with(&mut v); + n.visit_mut_with(&mut v); self.vars.extend(v.take_vars()); n } else { From 05ebfc9d11d47bc660912e3f17ee48d4ba47a1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:08:04 +0900 Subject: [PATCH 097/186] more --- crates/swc_ecma_compat_es2015/src/lib.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/lib.rs b/crates/swc_ecma_compat_es2015/src/lib.rs index d1a10b3de8cc..d554bb2c6dd9 100644 --- a/crates/swc_ecma_compat_es2015/src/lib.rs +++ b/crates/swc_ecma_compat_es2015/src/lib.rs @@ -2,9 +2,9 @@ #![allow(clippy::boxed_local)] use serde::Deserialize; -use swc_common::{chain, comments::Comments, pass::Optional, Mark}; +use swc_common::{comments::Comments, Mark}; +use swc_ecma_ast::{chain, Pass}; use swc_ecma_compat_common::regexp::{self, regexp}; -use swc_ecma_visit::Fold; pub use self::{ arrow::arrow, block_scoped_fn::block_scoped_functions, block_scoping::block_scoping, @@ -36,7 +36,7 @@ mod sticky_regex; pub mod template_literal; mod typeof_symbol; -fn exprs(unresolved_mark: Mark) -> impl Fold { +fn exprs(unresolved_mark: Mark) -> impl Pass { chain!( arrow(unresolved_mark), duplicate_keys(), @@ -55,7 +55,7 @@ fn exprs(unresolved_mark: Mark) -> impl Fold { /// Used to generate `require` calls. /// See the documentation of [regenerator](self::regenerator::regenerator) for /// more details. -pub fn es2015(unresolved_mark: Mark, comments: Option, c: Config) -> impl Fold +pub fn es2015(unresolved_mark: Mark, comments: Option, c: Config) -> impl Pass where C: Comments + Clone, { @@ -76,7 +76,11 @@ where new_target(), spread(c.spread), // https://github.com/Microsoft/TypeScript/issues/5441 - Optional::new(object_super(), !c.typescript), + if !c.typescript { + Some(object_super()) + } else { + None + }, shorthand(), function_name(), for_of(c.for_of), From c8b581d319f2839445590591a95c9b20a590f051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:08:22 +0900 Subject: [PATCH 098/186] more --- crates/swc_ecma_compat_es2015/src/destructuring.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/destructuring.rs b/crates/swc_ecma_compat_es2015/src/destructuring.rs index c5cea4fffff0..7e7c93bafeb8 100644 --- a/crates/swc_ecma_compat_es2015/src/destructuring.rs +++ b/crates/swc_ecma_compat_es2015/src/destructuring.rs @@ -11,8 +11,7 @@ use swc_ecma_utils::{ prop_name_to_expr, quote_ident, ExprFactory, StmtLike, }; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -37,7 +36,7 @@ use swc_trace_macro::swc_trace; /// b = _arr2[1], /// rest = _arr2.slice(2); /// ``` -pub fn destructuring(c: Config) -> impl Fold + VisitMut { +pub fn destructuring(c: Config) -> impl Pass { visit_mut_pass(Destructuring { c }) } From 1572bd7bf075587e3fe87519456793f49ecbbda0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:08:40 +0900 Subject: [PATCH 099/186] more --- crates/swc_ecma_compat_es2017/src/async_to_generator.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_es2017/src/async_to_generator.rs b/crates/swc_ecma_compat_es2017/src/async_to_generator.rs index 9abe6c3bae2e..2592c8eac62f 100644 --- a/crates/swc_ecma_compat_es2017/src/async_to_generator.rs +++ b/crates/swc_ecma_compat_es2017/src/async_to_generator.rs @@ -11,8 +11,7 @@ use swc_ecma_utils::{ prepend_stmt, private_ident, quote_ident, ExprFactory, Remapper, StmtLike, }; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_trace_macro::swc_trace; @@ -36,7 +35,7 @@ use swc_trace_macro::swc_trace; /// yield bar(); /// }); /// ``` -pub fn async_to_generator(c: Config, unresolved_mark: Mark) -> impl Fold + VisitMut { +pub fn async_to_generator(c: Config, unresolved_mark: Mark) -> impl Pass { visit_mut_pass(AsyncToGenerator { c, in_subclass: false, From 19d47f17ab7ddf3371bf6b54983312f93c0a9aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:10:02 +0900 Subject: [PATCH 100/186] more --- crates/swc_ecma_transforms_react/src/display_name/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_react/src/display_name/mod.rs b/crates/swc_ecma_transforms_react/src/display_name/mod.rs index af4b56e0e647..e4527cc545d6 100644 --- a/crates/swc_ecma_transforms_react/src/display_name/mod.rs +++ b/crates/swc_ecma_transforms_react/src/display_name/mod.rs @@ -2,7 +2,7 @@ use std::ops::DerefMut; use swc_common::DUMMY_SP; use swc_ecma_ast::*; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; #[cfg(test)] mod tests; @@ -10,7 +10,7 @@ mod tests; /// `@babel/plugin-transform-react-display-name` /// /// Add displayName to React.createClass calls -pub fn display_name() -> impl Fold + VisitMut { +pub fn display_name() -> impl Pass { visit_mut_pass(DisplayName) } From a2a816af561541acde01dced957e5569019356ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:10:10 +0900 Subject: [PATCH 101/186] more --- .../swc_ecma_transforms_proposal/src/import_assertions.rs | 6 +++--- crates/swc_ecma_transforms_react/src/jsx_self/mod.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/swc_ecma_transforms_proposal/src/import_assertions.rs b/crates/swc_ecma_transforms_proposal/src/import_assertions.rs index 6b7105e61771..7d3f0800a44e 100644 --- a/crates/swc_ecma_transforms_proposal/src/import_assertions.rs +++ b/crates/swc_ecma_transforms_proposal/src/import_assertions.rs @@ -1,10 +1,10 @@ -use swc_ecma_ast::{ExportAll, ImportDecl, NamedExport}; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut}; +use swc_ecma_ast::{ExportAll, ImportDecl, NamedExport, Pass}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut}; #[deprecated(note = "Please use `import_assertions` instead")] pub use self::import_attributes as import_assertions; -pub fn import_attributes() -> impl VisitMut + Fold { +pub fn import_attributes() -> impl Pass { visit_mut_pass(ImportAssertions) } diff --git a/crates/swc_ecma_transforms_react/src/jsx_self/mod.rs b/crates/swc_ecma_transforms_react/src/jsx_self/mod.rs index 7bdfd482df96..1bdeeccb945b 100644 --- a/crates/swc_ecma_transforms_react/src/jsx_self/mod.rs +++ b/crates/swc_ecma_transforms_react/src/jsx_self/mod.rs @@ -2,7 +2,7 @@ use swc_common::DUMMY_SP; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::quote_ident; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut}; #[cfg(test)] mod tests; @@ -10,7 +10,7 @@ mod tests; /// `@babel/plugin-transform-react-jsx-self` /// /// Add a __self prop to all JSX Elements -pub fn jsx_self(dev: bool) -> impl Fold + VisitMut { +pub fn jsx_self(dev: bool) -> impl Pass { visit_mut_pass(JsxSelf { dev }) } From 867e412ef04b8b5c3c379ccd4bf9b126c9b6fc7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:10:38 +0900 Subject: [PATCH 102/186] more --- crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs b/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs index 29af3edab3f7..ec96c2f89fa2 100644 --- a/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs +++ b/crates/swc_ecma_transforms_react/src/pure_annotations/mod.rs @@ -1,7 +1,7 @@ use swc_atoms::JsWord; use swc_common::{collections::AHashMap, comments::Comments, Span}; use swc_ecma_ast::*; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; #[cfg(test)] mod tests; @@ -12,7 +12,7 @@ mod tests; /// React methods, so that terser and other minifiers can safely remove them /// during dead code elimination. /// See https://reactjs.org/docs/react-api.html -pub fn pure_annotations(comments: Option) -> impl Fold + VisitMut +pub fn pure_annotations(comments: Option) -> impl Pass where C: Comments, { From 28e6fd1c549b5250536064c492cf957447abd940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:12:49 +0900 Subject: [PATCH 103/186] more --- crates/swc_ecma_compat_es2022/src/static_blocks.rs | 4 ++-- crates/swc_ecma_transforms_react/src/refresh/mod.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/swc_ecma_compat_es2022/src/static_blocks.rs b/crates/swc_ecma_compat_es2022/src/static_blocks.rs index a97df883f56e..f7c41dc3a94e 100644 --- a/crates/swc_ecma_compat_es2022/src/static_blocks.rs +++ b/crates/swc_ecma_compat_es2022/src/static_blocks.rs @@ -2,14 +2,14 @@ use swc_atoms::JsWord; use swc_common::{collections::AHashSet, util::take::Take, Mark, SyntaxContext, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::ExprFactory; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; struct ClassStaticBlock { static_block_mark: Mark, } -pub fn static_blocks(static_block_mark: Mark) -> impl Fold + VisitMut { +pub fn static_blocks(static_block_mark: Mark) -> impl Pass { visit_mut_pass(ClassStaticBlock { static_block_mark }) } diff --git a/crates/swc_ecma_transforms_react/src/refresh/mod.rs b/crates/swc_ecma_transforms_react/src/refresh/mod.rs index 6115313447e0..600ebaa00da1 100644 --- a/crates/swc_ecma_transforms_react/src/refresh/mod.rs +++ b/crates/swc_ecma_transforms_react/src/refresh/mod.rs @@ -4,7 +4,7 @@ use swc_common::{ }; use swc_ecma_ast::*; use swc_ecma_utils::{private_ident, quote_ident, quote_str, ExprFactory}; -use swc_ecma_visit::{visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith}; +use swc_ecma_visit::{visit_mut_pass, Visit, VisitMut, VisitMutWith}; use self::{ hook::HookRegister, @@ -52,7 +52,7 @@ pub fn refresh( cm: Lrc, comments: Option, global_mark: Mark, -) -> impl Fold + VisitMut { +) -> impl Pass { visit_mut_pass(Refresh { enable: dev && options.is_some(), cm, From 026305dae9b2309818bf9b4304ff7ba941259232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:13:29 +0900 Subject: [PATCH 104/186] Pass : Sized --- crates/swc_ecma_ast/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index f560b65d0f7b..07640b64508a 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -95,7 +95,7 @@ mod typescript; /// This trait is used to implement transformations. The implementor may decide /// to implement [Fold] or [VisitMut] if the transform is fine to start from an /// arbitrary node. -pub trait Pass { +pub trait Pass: Sized { fn process(self, program: &mut Program); } From 3cd855ca4006eeee7015a34e44e06de2838956ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:14:39 +0900 Subject: [PATCH 105/186] more --- crates/swc_ecma_transforms_module/src/amd.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_transforms_module/src/amd.rs b/crates/swc_ecma_transforms_module/src/amd.rs index 9a6e012cad22..c7fe26afd9f3 100644 --- a/crates/swc_ecma_transforms_module/src/amd.rs +++ b/crates/swc_ecma_transforms_module/src/amd.rs @@ -13,7 +13,7 @@ use swc_ecma_transforms_base::{feature::FeatureFlag, helper_expr}; use swc_ecma_utils::{ member_expr, private_ident, quote_ident, quote_str, ExprFactory, FunctionFactory, IsDirective, }; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; pub use super::util::Config as InnerConfig; use crate::{ @@ -44,7 +44,7 @@ pub fn amd( config: Config, available_features: FeatureFlag, comments: Option, -) -> impl Fold + VisitMut +) -> impl Pass where C: Comments, { From d40198656aad4f372d2903185ee83916944fe9b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:16:16 +0900 Subject: [PATCH 106/186] more --- .../tests/fixer_test262.rs | 18 +++++++++++------- .../tests/ts_resolver.rs | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/swc_ecma_transforms_base/tests/fixer_test262.rs b/crates/swc_ecma_transforms_base/tests/fixer_test262.rs index 89c1f6b53a21..bd6feababb68 100644 --- a/crates/swc_ecma_transforms_base/tests/fixer_test262.rs +++ b/crates/swc_ecma_transforms_base/tests/fixer_test262.rs @@ -208,13 +208,15 @@ fn identity_tests(tests: &mut Vec) -> Result<(), io::Error> { let module = parser .parse_module() .map(normalize) - .map(|p| p.fold_with(&mut fixer(None))) + .map(Program::Module) + .map(|p| p.apply(fixer(None))) .map_err(|e| { e.into_diagnostic(handler).emit(); })?; let module2 = e_parser .parse_module() .map(normalize) + .map(Program::Module) .map_err(|e| { e.into_diagnostic(handler).emit(); }) @@ -222,20 +224,22 @@ fn identity_tests(tests: &mut Vec) -> Result<(), io::Error> { if module == module2 { return Ok(()); } - emitter.emit_module(&module).unwrap(); - expected_emitter.emit_module(&module2).unwrap(); + emitter.emit_program(&module).unwrap(); + expected_emitter.emit_program(&module2).unwrap(); } else { let script = parser .parse_script() .map(normalize) - .map(|p| p.fold_with(&mut fixer(None))) + .map(Program::Script) + .map(|p| p.apply(fixer(None))) .map_err(|e| { e.into_diagnostic(handler).emit(); })?; let script2 = e_parser .parse_script() .map(normalize) - .map(|p| p.fold_with(&mut fixer(None))) + .map(Program::Script) + .map(|p| p.apply(fixer(None))) .map_err(|e| { e.into_diagnostic(handler).emit(); })?; @@ -243,8 +247,8 @@ fn identity_tests(tests: &mut Vec) -> Result<(), io::Error> { if script == script2 { return Ok(()); } - emitter.emit_script(&script).unwrap(); - expected_emitter.emit_script(&script2).unwrap(); + emitter.emit_program(&script).unwrap(); + expected_emitter.emit_program(&script2).unwrap(); } } diff --git a/crates/swc_ecma_transforms_base/tests/ts_resolver.rs b/crates/swc_ecma_transforms_base/tests/ts_resolver.rs index e6a033a6452a..ba3c9b7573c4 100644 --- a/crates/swc_ecma_transforms_base/tests/ts_resolver.rs +++ b/crates/swc_ecma_transforms_base/tests/ts_resolver.rs @@ -6,7 +6,7 @@ use swc_common::{Mark, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_parser::{parse_file_as_module, Syntax, TsSyntax}; use swc_ecma_transforms_base::resolver; -use swc_ecma_visit::{FoldWith, Visit, VisitWith}; +use swc_ecma_visit::{Visit, VisitWith}; use testing::fixture; #[fixture("../swc_ecma_parser/tests/**/*.ts")] @@ -34,7 +34,7 @@ fn no_empty(input: PathBuf) { Err(..) => return Ok(()), }; - let module = module.fold_with(&mut resolver(Mark::new(), Mark::new(), true)); + let module = Program::Module(module).apply(resolver(Mark::new(), Mark::new(), true)); module.visit_with(&mut AssertNoEmptyCtxt); From 86d9ea9f6d7a16e85ecdc51b21fcd6f52596d4a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:20:40 +0900 Subject: [PATCH 107/186] more --- .../src/const_modules.rs | 4 ++-- .../swc_ecma_transforms_optimization/src/simplify/mod.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/swc_ecma_transforms_optimization/src/const_modules.rs b/crates/swc_ecma_transforms_optimization/src/const_modules.rs index df17152b380a..cd7ed4fc6682 100644 --- a/crates/swc_ecma_transforms_optimization/src/const_modules.rs +++ b/crates/swc_ecma_transforms_optimization/src/const_modules.rs @@ -17,12 +17,12 @@ use swc_common::{ use swc_ecma_ast::*; use swc_ecma_parser::parse_file_as_expr; use swc_ecma_utils::drop_span; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; pub fn const_modules( cm: Lrc, globals: FxHashMap>, -) -> impl Fold { +) -> impl Pass { visit_mut_pass(ConstModules { globals: globals .into_iter() diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs index 3d45ee1089f8..00f6730df1fd 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs @@ -1,6 +1,9 @@ //! Ported from closure compiler. -use swc_common::{chain, pass::Repeat, Mark}; -use swc_ecma_transforms_base::pass::RepeatedJsPass; +use swc_common::{ + pass::{CompilerPass, Repeat, Repeated}, + Mark, +}; +use swc_ecma_ast::{chain, Pass}; pub use self::{ branch::dead_branch_remover, @@ -22,7 +25,7 @@ pub struct Config { /// Performs simplify-expr, inlining, remove-dead-branch and dce until nothing /// changes. -pub fn simplifier(unresolved_mark: Mark, c: Config) -> impl RepeatedJsPass { +pub fn simplifier(unresolved_mark: Mark, c: Config) -> impl CompilerPass + Pass + Repeated { Repeat::new(chain!( expr_simplifier(unresolved_mark, c.expr), dead_branch_remover(unresolved_mark), From a15693d0e900a22df3e6ea73827d6f3ba1546013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:20:49 +0900 Subject: [PATCH 108/186] Repeated passes --- crates/swc_ecma_visit/src/lib.rs | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 0742e870b3f2..c06f001ee3e8 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -46,6 +46,19 @@ where } } +impl Repeated for FoldPass +where + V: Fold + Repeated, +{ + fn changed(&self) -> bool { + self.pass.changed() + } + + fn reset(&mut self) { + self.pass.reset(); + } +} + pub fn visit_mut_pass(pass: V) -> VisitMutPass where V: VisitMut, @@ -77,6 +90,19 @@ where } } +impl Repeated for VisitMutPass +where + V: VisitMut + Repeated, +{ + fn changed(&self) -> bool { + self.pass.changed() + } + + fn reset(&mut self) { + self.pass.reset(); + } +} + pub fn visit_pass(pass: V) -> VisitPass where V: Visit, @@ -108,6 +134,19 @@ where } } +impl Repeated for VisitPass +where + V: Visit + Repeated, +{ + fn changed(&self) -> bool { + self.pass.changed() + } + + fn reset(&mut self) { + self.pass.reset(); + } +} + impl Fold for Repeat where V: Fold + Repeated, From cc71ba64f5aa53c7fe7aae441e60972cb93ac92b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:22:50 +0900 Subject: [PATCH 109/186] more --- crates/swc/src/dropped_comments_preserver.rs | 4 +--- .../swc_ecma_compat_es2020/src/export_namespace_from.rs | 2 +- crates/swc_ecma_compat_es2020/src/optional_chaining.rs | 2 +- .../src/class_fields_use_set.rs | 2 +- crates/swc_ecma_transforms_typescript/src/transform.rs | 2 +- crates/swc_ecma_transforms_typescript/src/typescript.rs | 8 ++------ 6 files changed, 7 insertions(+), 13 deletions(-) diff --git a/crates/swc/src/dropped_comments_preserver.rs b/crates/swc/src/dropped_comments_preserver.rs index 749a37ecae49..377ada685b4d 100644 --- a/crates/swc/src/dropped_comments_preserver.rs +++ b/crates/swc/src/dropped_comments_preserver.rs @@ -16,9 +16,7 @@ use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitM /// This transformer shifts orphaned comments to the next closest known span /// while making a best-effort to preserve the "general orientation" of /// comments. -pub fn dropped_comments_preserver( - comments: Option, -) -> impl Fold + VisitMut { +pub fn dropped_comments_preserver(comments: Option) -> impl Pass { visit_mut_pass(DroppedCommentsPreserver { comments, is_first_span: true, diff --git a/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs b/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs index ecc572208ce5..882020c9840a 100644 --- a/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs +++ b/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs @@ -4,7 +4,7 @@ use swc_ecma_utils::private_ident; use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut}; use swc_trace_macro::swc_trace; -pub fn export_namespace_from() -> impl Fold + VisitMut { +pub fn export_namespace_from() -> impl Pass { visit_mut_pass(ExportNamespaceFrom) } diff --git a/crates/swc_ecma_compat_es2020/src/optional_chaining.rs b/crates/swc_ecma_compat_es2020/src/optional_chaining.rs index 703268a9450d..22a794f9161a 100644 --- a/crates/swc_ecma_compat_es2020/src/optional_chaining.rs +++ b/crates/swc_ecma_compat_es2020/src/optional_chaining.rs @@ -3,7 +3,7 @@ use swc_common::Mark; use swc_ecma_compat_es2022::optional_chaining_impl::optional_chaining_impl; use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut}; -pub fn optional_chaining(c: Config, unresolved_mark: Mark) -> impl Fold + VisitMut { +pub fn optional_chaining(c: Config, unresolved_mark: Mark) -> impl Pass { visit_mut_pass(optional_chaining_impl( swc_ecma_compat_es2022::optional_chaining_impl::Config { no_document_all: c.no_document_all, diff --git a/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs b/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs index 28566d9b6fe7..133e1a49586c 100644 --- a/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs +++ b/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs @@ -83,7 +83,7 @@ use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitM /// } /// } /// ``` -pub fn class_fields_use_set(pure_getters: bool) -> impl Fold + VisitMut { +pub fn class_fields_use_set(pure_getters: bool) -> impl Pass { visit_mut_pass(ClassFieldsUseSet { pure_getters }) } diff --git a/crates/swc_ecma_transforms_typescript/src/transform.rs b/crates/swc_ecma_transforms_typescript/src/transform.rs index 081654acdcde..60251412d4de 100644 --- a/crates/swc_ecma_transforms_typescript/src/transform.rs +++ b/crates/swc_ecma_transforms_typescript/src/transform.rs @@ -84,7 +84,7 @@ pub fn transform( ts_enum_is_mutable: bool, verbatim_module_syntax: bool, native_class_properties: bool, -) -> impl Fold + VisitMut { +) -> impl Pass { visit_mut_pass(Transform { unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), top_level_ctxt: SyntaxContext::empty().apply_mark(top_level_mark), diff --git a/crates/swc_ecma_transforms_typescript/src/typescript.rs b/crates/swc_ecma_transforms_typescript/src/typescript.rs index 42644e0e3581..5b9bbe88d061 100644 --- a/crates/swc_ecma_transforms_typescript/src/typescript.rs +++ b/crates/swc_ecma_transforms_typescript/src/typescript.rs @@ -11,11 +11,7 @@ use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut, VisitMutWith}; pub use crate::config::*; use crate::{strip_import_export::StripImportExport, strip_type::StripType, transform::transform}; -pub fn typescript( - config: Config, - unresolved_mark: Mark, - top_level_mark: Mark, -) -> impl Fold + VisitMut { +pub fn typescript(config: Config, unresolved_mark: Mark, top_level_mark: Mark) -> impl Pass { debug_assert_ne!(unresolved_mark, top_level_mark); visit_mut_pass(TypeScript { @@ -26,7 +22,7 @@ pub fn typescript( }) } -pub fn strip(unresolved_mark: Mark, top_level_mark: Mark) -> impl Fold + VisitMut { +pub fn strip(unresolved_mark: Mark, top_level_mark: Mark) -> impl Pass { typescript(Config::default(), unresolved_mark, top_level_mark) } From f66d48ce83ebdfeedf5db04eced0bae9cb5a1742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:29:13 +0900 Subject: [PATCH 110/186] Make pass not : Sized --- crates/swc_ecma_ast/src/lib.rs | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index 07640b64508a..52a802c0b1be 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -95,36 +95,45 @@ mod typescript; /// This trait is used to implement transformations. The implementor may decide /// to implement [Fold] or [VisitMut] if the transform is fine to start from an /// arbitrary node. -pub trait Pass: Sized { - fn process(self, program: &mut Program); +pub trait Pass { + fn process(&mut self, program: &mut Program); } - /// Optional pass implementation. impl

Pass for Option

where P: Pass, { #[inline(always)] - fn process(self, program: &mut Program) { + fn process(&mut self, program: &mut Program) { if let Some(pass) = self { pass.process(program); } } } -impl

Pass for Box

+impl Pass for Box

+where + P: Pass, +{ + #[inline(always)] + fn process(&mut self, program: &mut Program) { + (**self).process(program); + } +} + +impl Pass for &'_ mut P where P: Pass, { #[inline(always)] - fn process(self, program: &mut Program) { - (*self).process(program); + fn process(&mut self, program: &mut Program) { + (**self).process(program); } } impl Program { #[inline(always)] - pub fn mutate

(&mut self, pass: P) + pub fn mutate

(&mut self, mut pass: P) where P: Pass, { @@ -132,7 +141,7 @@ impl Program { } #[inline(always)] - pub fn apply

(mut self, pass: P) -> Self + pub fn apply

(mut self, mut pass: P) -> Self where P: Pass, { @@ -176,7 +185,7 @@ pub fn noop_pass() -> impl Pass { } #[inline(always)] -pub fn fn_pass(f: impl FnOnce(&mut Program)) -> impl Pass { +pub fn fn_pass(f: impl FnMut(&mut Program)) -> impl Pass { FnPass { f } } @@ -186,9 +195,9 @@ struct FnPass { impl Pass for FnPass where - F: FnOnce(&mut Program), + F: FnMut(&mut Program), { - fn process(self, program: &mut Program) { + fn process(&mut self, program: &mut Program) { (self.f)(program); } } From 0f8019ac4a55272ca56e92f4d3188d06223538d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:29:34 +0900 Subject: [PATCH 111/186] fixup --- crates/swc_ecma_visit/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index c06f001ee3e8..079d4d36177f 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -31,7 +31,7 @@ where V: Fold, { #[inline(always)] - fn process(mut self, program: &mut Program) { + fn process(&mut self, program: &mut Program) { program.map_with_mut(|p| p.fold_with(&mut self.pass)); } } @@ -75,7 +75,7 @@ where V: VisitMut, { #[inline(always)] - fn process(mut self, program: &mut Program) { + fn process(&mut self, program: &mut Program) { program.visit_mut_with(&mut self.pass); } } @@ -119,7 +119,7 @@ where V: Visit, { #[inline(always)] - fn process(mut self, program: &mut Program) { + fn process(&mut self, program: &mut Program) { program.visit_with(&mut self.pass); } } From 4c4db2023e26b503a440f84fdbaead381f3e1730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:29:44 +0900 Subject: [PATCH 112/186] fixup --- crates/swc_ecma_utils/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_utils/src/lib.rs b/crates/swc_ecma_utils/src/lib.rs index a00605e69739..7d0bbfde58c3 100644 --- a/crates/swc_ecma_utils/src/lib.rs +++ b/crates/swc_ecma_utils/src/lib.rs @@ -2402,8 +2402,8 @@ where pub struct DropSpan; impl Pass for DropSpan { - fn process(mut self, program: &mut Program) { - program.visit_mut_with(&mut self); + fn process(&mut self, program: &mut Program) { + program.visit_mut_with(self); } } From 73bfea046608263545b60442eda502c99faec57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:31:24 +0900 Subject: [PATCH 113/186] more --- .../swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs | 8 ++++---- crates/swc_ecma_compat_es2015/src/lib.rs | 2 +- crates/swc_ecma_transforms_base/src/hygiene/mod.rs | 2 +- crates/swc_ecma_transforms_module/src/rewriter.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs b/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs index b3395741ab60..f15c289f399a 100644 --- a/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs +++ b/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs @@ -2,7 +2,7 @@ use swc_common::{util::take::Take, Mark, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_compat_es2015::arrow; use swc_ecma_utils::prepend_stmt; -use swc_ecma_visit::{standard_only_fold, Fold, FoldWith, InjectVars, VisitMutWith}; +use swc_ecma_visit::{fold_pass, standard_only_fold, Fold, FoldWith, InjectVars, VisitMutWith}; use swc_trace_macro::swc_trace; /// A bugfix pass for Safari 10.3. @@ -12,11 +12,11 @@ use swc_trace_macro::swc_trace; /// instance via `this` within those methods would also throw. This is fixed by /// converting arrow functions in class methods into equivalent function /// expressions. See https://bugs.webkit.org/show_bug.cgi?id=166879 -pub fn async_arrows_in_class(unresolved_mark: Mark) -> impl Fold { - AsyncArrowsInClass { +pub fn async_arrows_in_class(unresolved_mark: Mark) -> impl Pass { + fold_pass(AsyncArrowsInClass { unresolved_mark, ..Default::default() - } + }) } #[derive(Default, Clone)] struct AsyncArrowsInClass { diff --git a/crates/swc_ecma_compat_es2015/src/lib.rs b/crates/swc_ecma_compat_es2015/src/lib.rs index d554bb2c6dd9..f44e7d087295 100644 --- a/crates/swc_ecma_compat_es2015/src/lib.rs +++ b/crates/swc_ecma_compat_es2015/src/lib.rs @@ -91,7 +91,7 @@ where computed_properties(c.computed_props), destructuring(c.destructuring), block_scoping(unresolved_mark), - generator::generator(unresolved_mark, comments), + generator::generator(unresolved_mark, comments.clone()), ) } diff --git a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs index 8858596e31de..e4c9cd04b68d 100644 --- a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs +++ b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs @@ -60,7 +60,7 @@ pub fn hygiene() -> impl Pass { /// At third phase, we rename all identifiers in the queue. pub fn hygiene_with_config(config: Config) -> impl 'static + Pass { chain!( - renamer(config, HygieneRenamer), + renamer(config.clone(), HygieneRenamer), visit_mut_pass(HygieneRemover) ) } diff --git a/crates/swc_ecma_transforms_module/src/rewriter.rs b/crates/swc_ecma_transforms_module/src/rewriter.rs index f3f806fbc559..b0d174bbcdc8 100644 --- a/crates/swc_ecma_transforms_module/src/rewriter.rs +++ b/crates/swc_ecma_transforms_module/src/rewriter.rs @@ -3,12 +3,12 @@ use std::sync::Arc; use anyhow::Context; use swc_common::FileName; use swc_ecma_ast::*; -use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{visit_mut_pass, VisitMut, VisitMutWith}; use crate::path::ImportResolver; /// Import rewriter, which rewrites imports as es modules. -pub fn import_rewriter(base: FileName, resolver: Arc) -> impl Fold + VisitMut { +pub fn import_rewriter(base: FileName, resolver: Arc) -> impl Pass { visit_mut_pass(Rewriter { base, resolver }) } From 2093562e5c6158526d91c6ec75f580c6234339e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:33:30 +0900 Subject: [PATCH 114/186] more --- ...afari_id_destructuring_collision_in_function_expression.rs | 4 ++-- .../src/explicit_resource_management.rs | 4 ++-- .../swc_ecma_transforms_proposal/src/export_default_from.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs index 32088a4901a1..7822dd2c913f 100644 --- a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs +++ b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs @@ -4,10 +4,10 @@ use swc_atoms::JsWord; use swc_common::{collections::AHashSet, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_transforms_base::hygiene::rename; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; -pub fn safari_id_destructuring_collision_in_function_expression() -> impl Fold + VisitMut { +pub fn safari_id_destructuring_collision_in_function_expression() -> impl Pass { visit_mut_pass(SafariIdDestructuringCollisionInFunctionExpression::default()) } diff --git a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs index 4d8ba5c3ee20..30f470d9e235 100644 --- a/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/src/explicit_resource_management.rs @@ -5,9 +5,9 @@ use swc_ecma_utils::{ private_ident, quote_ident, stack_size::maybe_grow_default, ExprFactory, ModuleItemLike, StmtLike, }; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; -pub fn explicit_resource_management() -> impl Fold + VisitMut { +pub fn explicit_resource_management() -> impl Pass { visit_mut_pass(ExplicitResourceManagement::default()) } diff --git a/crates/swc_ecma_transforms_proposal/src/export_default_from.rs b/crates/swc_ecma_transforms_proposal/src/export_default_from.rs index 3db424add2d1..489b42da9055 100644 --- a/crates/swc_ecma_transforms_proposal/src/export_default_from.rs +++ b/crates/swc_ecma_transforms_proposal/src/export_default_from.rs @@ -1,10 +1,10 @@ use swc_common::DUMMY_SP; use swc_ecma_ast::*; use swc_ecma_utils::quote_ident; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut}; /// `@babel/plugin-proposal-export-default-from` -pub fn export_default_from() -> impl Fold + VisitMut { +pub fn export_default_from() -> impl Pass { visit_mut_pass(ExportDefaultFrom) } From 26207675da45e3ba00e82bda9bbd0bfb00d23966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:45:30 +0900 Subject: [PATCH 115/186] Pass: `impl_pass_for_tuple` --- crates/swc_ecma_ast/src/lib.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index 52a802c0b1be..d49931916d96 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -150,6 +150,30 @@ impl Program { } } +macro_rules! impl_pass_for_tuple { + ( + [$idx:tt, $name:ident], $([$idx_rest:tt, $name_rest:ident]),* + ) => { + impl<$name, $($name_rest),*> Pass for ($name, $($name_rest),*) + where + $name: Pass, + $($name_rest: Pass),* + { + #[inline] + fn process(&mut self, program: &mut Program) { + self.$idx.process(program); + + $( + self.$idx_rest.process(program); + )* + + } + } + }; +} + +impl_pass_for_tuple!([0, A], [1, B]); + #[macro_export] macro_rules! chain { ( From 45e73136bf5176c176f8fbad9cd0de26274c0e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:46:00 +0900 Subject: [PATCH 116/186] More `impl_pass_for_tuple` invocation --- crates/swc_ecma_ast/src/lib.rs | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index d49931916d96..368e8fb70382 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -173,6 +173,57 @@ macro_rules! impl_pass_for_tuple { } impl_pass_for_tuple!([0, A], [1, B]); +impl_pass_for_tuple!([0, A], [1, B], [2, C]); +impl_pass_for_tuple!([0, A], [1, B], [2, C], [3, D]); +impl_pass_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E]); +impl_pass_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E], [5, F]); +impl_pass_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E], [5, F], [6, G]); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K] +); #[macro_export] macro_rules! chain { From f0d1f91664174cf67f44e658bf6fe6c3b636eb1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:49:02 +0900 Subject: [PATCH 117/186] Improve `chain!` macro --- crates/swc_ecma_ast/src/lib.rs | 303 +++++++++++++++++++++++++++++++-- 1 file changed, 293 insertions(+), 10 deletions(-) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index 368e8fb70382..d3513fa051e0 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -224,7 +224,298 @@ impl_pass_for_tuple!( [9, J], [10, K] ); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R], + [18, S] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R], + [18, S], + [19, T] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R], + [18, S], + [19, T], + [20, U] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R], + [18, S], + [19, T], + [20, U], + [21, V] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R], + [18, S], + [19, T], + [20, U], + [21, V], + [22, W] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R], + [18, S], + [19, T], + [20, U], + [21, V], + [22, W], + [23, X] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R], + [18, S], + [19, T], + [20, U], + [21, V], + [22, W], + [23, X], + [24, Y] +); +/// Chain multiple passes. +/// +/// For compile time efficiency, this macro only supports up to 24 passes. You +/// can nest `chain!` calls to chain more passes. #[macro_export] macro_rules! chain { ( @@ -232,11 +523,7 @@ macro_rules! chain { $pass:expr ),* ) => { - $crate::fn_pass(move |mut program| { - $( - program.mutate($pass); - )* - }) + ($($pass),*) }; ( @@ -244,11 +531,7 @@ macro_rules! chain { $pass:expr, )* ) => { - $crate::fn_pass(move |mut program| { - $( - program.mutate($pass); - )* - }) + ($($pass),*) }; } From 86315817d6981b86f07e8b7eee9d0905d909b0a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:49:45 +0900 Subject: [PATCH 118/186] More --- .../src/edge_default_param.rs | 4 ++-- crates/swc_ecma_compat_bugfixes/src/lib.rs | 6 +++--- .../src/template_literal_caching.rs | 6 +++--- crates/swc_ecma_compat_es2020/src/lib.rs | 3 ++- .../src/nullish_coalescing.rs | 4 ++-- crates/swc_ecma_compat_es2022/src/lib.rs | 6 +++--- crates/swc_ecma_transforms_base/src/hygiene/mod.rs | 2 +- crates/swc_ecma_transforms_react/src/lib.rs | 12 ++++++------ .../swc_ecma_transforms_testing/src/babel_like.rs | 13 ++++++------- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs b/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs index f0ebd7cc21b0..2797b4ccb52b 100644 --- a/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs +++ b/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs @@ -1,5 +1,5 @@ use swc_ecma_ast::*; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; /// A bugfix pass for Edge. @@ -8,7 +8,7 @@ use swc_trace_macro::swc_trace; /// syntax. This fixes the only arguments-related bug in ES Modules-supporting /// browsers (Edge 16 & 17). Use this plugin instead of /// @babel/plugin-transform-parameters when targeting ES Modules. -pub fn edge_default_param() -> impl Fold + VisitMut { +pub fn edge_default_param() -> impl Pass { visit_mut_pass(EdgeDefaultParam::default()) } #[derive(Default, Clone, Copy)] diff --git a/crates/swc_ecma_compat_bugfixes/src/lib.rs b/crates/swc_ecma_compat_bugfixes/src/lib.rs index 9731cf74aa18..a21e3aeac474 100644 --- a/crates/swc_ecma_compat_bugfixes/src/lib.rs +++ b/crates/swc_ecma_compat_bugfixes/src/lib.rs @@ -1,5 +1,5 @@ -use swc_common::{chain, Mark}; -use swc_ecma_visit::Fold; +use swc_common::Mark; +use swc_ecma_ast::{chain, Pass}; pub use self::{ async_arrows_in_class::async_arrows_in_class, edge_default_param::edge_default_param, @@ -12,7 +12,7 @@ mod edge_default_param; mod safari_id_destructuring_collision_in_function_expression; mod template_literal_caching; -pub fn bugfixes(unresolved_mark: Mark) -> impl Fold { +pub fn bugfixes(unresolved_mark: Mark) -> impl Pass { chain!( async_arrows_in_class(unresolved_mark), edge_default_param(), diff --git a/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs b/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs index 10d29e62acbc..b8fc6693686d 100644 --- a/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs +++ b/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs @@ -1,7 +1,7 @@ use swc_common::DUMMY_SP; use swc_ecma_ast::*; use swc_ecma_utils::{prepend_stmt, private_ident, ExprFactory}; -use swc_ecma_visit::{standard_only_fold, Fold, FoldWith}; +use swc_ecma_visit::{fold_pass, standard_only_fold, Fold, FoldWith}; use swc_trace_macro::swc_trace; // Converts destructured parameters with default values to non-shorthand syntax. @@ -19,8 +19,8 @@ use swc_trace_macro::swc_trace; // Object``===Object`` // true, should be false. // // Benchmarks: https://jsperf.com/compiled-tagged-template-performance -pub fn template_literal_caching() -> impl Fold { - TemplateLiteralCaching::default() +pub fn template_literal_caching() -> impl Pass { + fold_pass(TemplateLiteralCaching::default()) } #[derive(Default, Clone)] struct TemplateLiteralCaching { diff --git a/crates/swc_ecma_compat_es2020/src/lib.rs b/crates/swc_ecma_compat_es2020/src/lib.rs index c116b3c6ded3..4b6439d25be7 100644 --- a/crates/swc_ecma_compat_es2020/src/lib.rs +++ b/crates/swc_ecma_compat_es2020/src/lib.rs @@ -1,5 +1,6 @@ use serde::Deserialize; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_visit::Fold; pub use self::{ diff --git a/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs b/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs index 7ab3ab3e505e..6b1e8dcdcd68 100644 --- a/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs +++ b/crates/swc_ecma_compat_es2020/src/nullish_coalescing.rs @@ -4,10 +4,10 @@ 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, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use swc_trace_macro::swc_trace; -pub fn nullish_coalescing(c: Config) -> impl Fold + VisitMut + 'static { +pub fn nullish_coalescing(c: Config) -> impl Pass + 'static { visit_mut_pass(NullishCoalescing { c, ..Default::default() diff --git a/crates/swc_ecma_compat_es2022/src/lib.rs b/crates/swc_ecma_compat_es2022/src/lib.rs index 28b937f8d7be..776a237262a7 100644 --- a/crates/swc_ecma_compat_es2022/src/lib.rs +++ b/crates/swc_ecma_compat_es2022/src/lib.rs @@ -1,8 +1,8 @@ #![allow(clippy::vec_box)] -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::{chain, Pass}; use swc_ecma_compat_common::regexp::{self, regexp}; -use swc_ecma_visit::Fold; pub use self::{ class_properties::class_properties, private_in_object::private_in_object, @@ -14,7 +14,7 @@ pub mod optional_chaining_impl; pub mod private_in_object; pub mod static_blocks; -pub fn es2022(config: Config, unresolved_mark: Mark) -> impl Fold { +pub fn es2022(config: Config, unresolved_mark: Mark) -> impl Pass { chain!( regexp(regexp::Config { dot_all_regex: true, diff --git a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs index e4c9cd04b68d..8858596e31de 100644 --- a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs +++ b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs @@ -60,7 +60,7 @@ pub fn hygiene() -> impl Pass { /// At third phase, we rename all identifiers in the queue. pub fn hygiene_with_config(config: Config) -> impl 'static + Pass { chain!( - renamer(config.clone(), HygieneRenamer), + renamer(config, HygieneRenamer), visit_mut_pass(HygieneRemover) ) } diff --git a/crates/swc_ecma_transforms_react/src/lib.rs b/crates/swc_ecma_transforms_react/src/lib.rs index d1b76383349f..ce29f5a18359 100644 --- a/crates/swc_ecma_transforms_react/src/lib.rs +++ b/crates/swc_ecma_transforms_react/src/lib.rs @@ -3,8 +3,8 @@ #![allow(clippy::arc_with_non_send_sync)] #![allow(rustc::untranslatable_diagnostic_trivial)] -use swc_common::{chain, comments::Comments, sync::Lrc, Mark, SourceMap}; -use swc_ecma_visit::{Fold, VisitMut}; +use swc_common::{comments::Comments, sync::Lrc, Mark, SourceMap}; +use swc_ecma_ast::{chain, Pass}; pub use self::{ display_name::display_name, @@ -41,7 +41,7 @@ pub fn react( mut options: Options, top_level_mark: Mark, unresolved_mark: Mark, -) -> impl Fold + VisitMut +) -> impl Pass where C: Comments + Clone, { @@ -55,19 +55,19 @@ where jsx_self(development), refresh( development, - refresh_options, + refresh_options.clone(), cm.clone(), comments.clone(), top_level_mark ), jsx( - cm, + cm.clone(), comments.clone(), options, top_level_mark, unresolved_mark ), display_name(), - pure_annotations(comments), + pure_annotations(comments.clone()), ) } diff --git a/crates/swc_ecma_transforms_testing/src/babel_like.rs b/crates/swc_ecma_transforms_testing/src/babel_like.rs index 1cd8974c5aa8..06fc7db5a35a 100644 --- a/crates/swc_ecma_transforms_testing/src/babel_like.rs +++ b/crates/swc_ecma_transforms_testing/src/babel_like.rs @@ -3,8 +3,8 @@ use std::{fs::read_to_string, path::Path}; use ansi_term::Color; use serde::Deserialize; use serde_json::Value; -use swc_common::{chain, comments::SingleThreadedComments, sync::Lrc, Mark, SourceMap}; -use swc_ecma_ast::{EsVersion, Program}; +use swc_common::{comments::SingleThreadedComments, sync::Lrc, Mark, SourceMap}; +use swc_ecma_ast::{chain, EsVersion, Pass, Program}; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{parse_file_as_program, Syntax}; use swc_ecma_transforms_base::{ @@ -14,13 +14,12 @@ use swc_ecma_transforms_base::{ hygiene::hygiene, resolver, }; -use swc_ecma_visit::{Fold, FoldWith, VisitMutWith}; use testing::NormalizedOutput; use crate::{exec_with_node_test_runner, parse_options, stdout_of}; pub type PassFactory<'a> = - Box) -> Option>>; + Box) -> Option>>; /// These tests use `options.json`. /// @@ -87,7 +86,7 @@ impl<'a> BabelLikeFixtureTest<'a> { comments: comments.clone(), }; - let mut pass: Box = Box::new(resolver( + let mut pass: Box = Box::new(resolver( builder.unresolved_mark, builder.top_level_mark, self.syntax.typescript(), @@ -164,12 +163,12 @@ impl<'a> BabelLikeFixtureTest<'a> { let helpers = Helpers::new(output_path.is_some()); let (code_without_helper, output_program) = HELPERS.set(&helpers, || { - let mut p = input_program.fold_with(&mut *pass); + let mut p = input_program.apply(pass); let code_without_helper = builder.print(&p); if output_path.is_none() { - p.visit_mut_with(&mut inject_helpers(builder.unresolved_mark)) + p.mutate(inject_helpers(builder.unresolved_mark)) } (code_without_helper, p) From 7449d7f7cbcec343761f49ca6b9f429589fb81b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:50:48 +0900 Subject: [PATCH 119/186] More --- crates/swc_ecma_compat_es2020/src/export_namespace_from.rs | 2 +- crates/swc_ecma_compat_es2020/src/lib.rs | 5 ++--- crates/swc_ecma_compat_es2020/src/optional_chaining.rs | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs b/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs index 882020c9840a..5bc25196bb7c 100644 --- a/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs +++ b/crates/swc_ecma_compat_es2020/src/export_namespace_from.rs @@ -1,7 +1,7 @@ use swc_atoms::JsWord; use swc_ecma_ast::*; use swc_ecma_utils::private_ident; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut}; use swc_trace_macro::swc_trace; pub fn export_namespace_from() -> impl Pass { diff --git a/crates/swc_ecma_compat_es2020/src/lib.rs b/crates/swc_ecma_compat_es2020/src/lib.rs index 4b6439d25be7..fa6cd8e10e12 100644 --- a/crates/swc_ecma_compat_es2020/src/lib.rs +++ b/crates/swc_ecma_compat_es2020/src/lib.rs @@ -1,7 +1,6 @@ use serde::Deserialize; use swc_common::Mark; -use swc_ecma_ast::chain; -use swc_ecma_visit::Fold; +use swc_ecma_ast::{chain, Pass}; pub use self::{ export_namespace_from::export_namespace_from, nullish_coalescing::nullish_coalescing, @@ -12,7 +11,7 @@ mod export_namespace_from; pub mod nullish_coalescing; pub mod optional_chaining; -pub fn es2020(config: Config, unresolved_mark: Mark) -> impl Fold { +pub fn es2020(config: Config, unresolved_mark: Mark) -> impl Pass { chain!( nullish_coalescing(config.nullish_coalescing), optional_chaining(config.optional_chaining, unresolved_mark), diff --git a/crates/swc_ecma_compat_es2020/src/optional_chaining.rs b/crates/swc_ecma_compat_es2020/src/optional_chaining.rs index 22a794f9161a..e2a2fc7a5688 100644 --- a/crates/swc_ecma_compat_es2020/src/optional_chaining.rs +++ b/crates/swc_ecma_compat_es2020/src/optional_chaining.rs @@ -1,7 +1,8 @@ use serde::Deserialize; use swc_common::Mark; +use swc_ecma_ast::Pass; use swc_ecma_compat_es2022::optional_chaining_impl::optional_chaining_impl; -use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut}; +use swc_ecma_visit::visit_mut_pass; pub fn optional_chaining(c: Config, unresolved_mark: Mark) -> impl Pass { visit_mut_pass(optional_chaining_impl( From d375b8c03de570f672471fd48b18c65c3160d861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:51:37 +0900 Subject: [PATCH 120/186] More --- crates/swc_ecma_transforms_base/benches/base.rs | 10 ++++------ crates/swc_ecma_transforms_react/src/jsx/mod.rs | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/swc_ecma_transforms_base/benches/base.rs b/crates/swc_ecma_transforms_base/benches/base.rs index 95309fa0c40e..a1a7597d2879 100644 --- a/crates/swc_ecma_transforms_base/benches/base.rs +++ b/crates/swc_ecma_transforms_base/benches/base.rs @@ -3,10 +3,10 @@ extern crate swc_malloc; use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; -use swc_common::{chain, errors::HANDLER, FileName, Mark}; +use swc_common::{errors::HANDLER, FileName, Mark}; +use swc_ecma_ast::{chain, Program}; use swc_ecma_parser::{Parser, StringInput, Syntax}; use swc_ecma_transforms_base::helpers; -use swc_ecma_visit::FoldWith; static SOURCE: &str = include_str!("../../swc_ecma_minifier/benches/full/typescript.js"); @@ -24,11 +24,9 @@ macro_rules! tr { ); let module = parser.parse_module().map_err(|_| ()).unwrap(); helpers::HELPERS.set(&Default::default(), || { - let mut tr = $tr(); - $b.iter(|| { - let module = module.clone(); - black_box(module.fold_with(&mut tr)) + let module = Program::Module(module.clone()); + black_box(module.apply($tr())) }); Ok(()) }) diff --git a/crates/swc_ecma_transforms_react/src/jsx/mod.rs b/crates/swc_ecma_transforms_react/src/jsx/mod.rs index a148dee5335f..f496f8f7de25 100644 --- a/crates/swc_ecma_transforms_react/src/jsx/mod.rs +++ b/crates/swc_ecma_transforms_react/src/jsx/mod.rs @@ -17,7 +17,7 @@ use swc_config::merge::Merge; use swc_ecma_ast::*; use swc_ecma_parser::{parse_file_as_expr, Syntax}; use swc_ecma_utils::{drop_span, prepend_stmt, private_ident, quote_ident, ExprFactory, StmtLike}; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; use self::static_check::should_use_create_element; use crate::refresh::options::{deserialize_refresh, RefreshOptions}; @@ -189,7 +189,7 @@ pub fn jsx( options: Options, top_level_mark: Mark, unresolved_mark: Mark, -) -> impl Fold + VisitMut +) -> impl Pass + VisitMut where C: Comments, { From 5fbd9e8c8470bf22b615f25f12a9155606c12f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:52:59 +0900 Subject: [PATCH 121/186] More --- crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs | 2 +- crates/swc_ecma_transforms_typescript/src/transform.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs b/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs index 133e1a49586c..6e929f2a33d1 100644 --- a/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs +++ b/crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs @@ -6,7 +6,7 @@ use swc_ecma_utils::{ constructor::inject_after_super, default_constructor, is_literal, is_simple_pure_expr, private_ident, prop_name_to_member_prop, ExprFactory, ModuleItemLike, StmtLike, }; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; /// # What does this module do? /// diff --git a/crates/swc_ecma_transforms_typescript/src/transform.rs b/crates/swc_ecma_transforms_typescript/src/transform.rs index 60251412d4de..6a13f5c1b796 100644 --- a/crates/swc_ecma_transforms_typescript/src/transform.rs +++ b/crates/swc_ecma_transforms_typescript/src/transform.rs @@ -15,8 +15,7 @@ use swc_ecma_utils::{ ExprFactory, QueryRef, RefRewriter, StmtLikeInjector, }; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith, VisitWith, }; use crate::{ From 1e62b6e97526a4a953c1914b97074a6921944704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:56:15 +0900 Subject: [PATCH 122/186] More --- .../swc_ecma_transforms_base/benches/deps.rs | 25 +++++++++++-------- .../benches/parallel.rs | 8 +++--- .../swc_ecma_transforms_base/tests/fixture.rs | 10 +++----- .../src/reserved_words.rs | 4 +-- .../src/inline_globals.rs | 2 +- .../src/json_parse.rs | 4 +-- 6 files changed, 28 insertions(+), 25 deletions(-) diff --git a/crates/swc_ecma_transforms_base/benches/deps.rs b/crates/swc_ecma_transforms_base/benches/deps.rs index f912b1b2110f..0ff1e1c611de 100644 --- a/crates/swc_ecma_transforms_base/benches/deps.rs +++ b/crates/swc_ecma_transforms_base/benches/deps.rs @@ -2,9 +2,8 @@ use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Benc use swc_common::{FileName, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_parser::{lexer::Lexer, parse_file_as_module, Parser, StringInput, Syntax}; -use swc_ecma_transforms_base::pass::noop; use swc_ecma_utils::ExprFactory; -use swc_ecma_visit::{FoldWith, Visit, VisitWith}; +use swc_ecma_visit::{Fold, FoldWith, Visit, VisitWith}; static SOURCE: &str = include_str!("assets/AjaxObservable.ts"); @@ -55,9 +54,9 @@ fn fold_empty(b: &mut Bencher) { e.into_diagnostic(handler).emit(); } - let mut folder = noop(); + let mut folder = noop_pass(); - b.iter(|| black_box(module.clone().fold_with(&mut folder))); + b.iter(|| black_box(Program::Module(module.clone()).apply(&mut folder))); Ok(()) }); } @@ -82,9 +81,9 @@ fn fold_noop_impl_all(b: &mut Bencher) { e.into_diagnostic(handler).emit(); } - let mut folder = noop(); + let mut folder = noop_pass(); - b.iter(|| black_box(module.clone().fold_with(&mut folder))); + b.iter(|| black_box(Program::Module(module.clone()).apply(&mut folder))); Ok(()) }); } @@ -110,9 +109,9 @@ fn fold_noop_impl_vec(b: &mut Bencher) { e.into_diagnostic(handler).emit(); } - let mut folder = noop(); + let mut folder = noop_pass(); - b.iter(|| black_box(module.clone().fold_with(&mut folder))); + b.iter(|| black_box(Program::Module(module.clone()).apply(&mut folder))); Ok(()) }); } @@ -147,7 +146,7 @@ fn boxing_unboxed_clone(b: &mut Bencher) { fn boxing_boxed(b: &mut Bencher) { let _ = ::testing::run_test(false, |_, _| { - let mut folder = noop(); + let mut folder = noop_fold(); let expr = Box::new(mk_expr()); b.iter(|| black_box(expr.clone().fold_with(&mut folder))); @@ -157,7 +156,7 @@ fn boxing_boxed(b: &mut Bencher) { fn boxing_unboxed(b: &mut Bencher) { let _ = ::testing::run_test(false, |_, _| { - let mut folder = noop(); + let mut folder = noop_fold(); let expr = mk_expr(); b.iter(|| black_box(expr.clone().fold_with(&mut folder))); @@ -233,3 +232,9 @@ fn bench_cases(c: &mut Criterion) { criterion_group!(benches, bench_cases); criterion_main!(benches); + +fn noop_fold() -> impl Fold { + struct Noop; + impl Fold for Noop {} + Noop +} diff --git a/crates/swc_ecma_transforms_base/benches/parallel.rs b/crates/swc_ecma_transforms_base/benches/parallel.rs index 31346f8c63d0..c1feae49c58c 100644 --- a/crates/swc_ecma_transforms_base/benches/parallel.rs +++ b/crates/swc_ecma_transforms_base/benches/parallel.rs @@ -5,9 +5,9 @@ extern crate swc_malloc; use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; use rayon::prelude::*; use swc_common::{errors::HANDLER, FileName, Mark, GLOBALS}; +use swc_ecma_ast::Program; use swc_ecma_parser::{Parser, StringInput, Syntax}; use swc_ecma_transforms_base::helpers; -use swc_ecma_visit::FoldWith; static SOURCE: &str = include_str!("../../swc_ecma_minifier/benches/full/typescript.js"); @@ -22,7 +22,7 @@ macro_rules! tr { StringInput::from(&*fm), None, ); - let module = parser.parse_module().map_err(|_| ()).unwrap(); + let module = Program::Module(parser.parse_module().map_err(|_| ()).unwrap()); $b.iter(|| { GLOBALS.with(|globals| { @@ -30,10 +30,10 @@ macro_rules! tr { GLOBALS.set(globals, || { HANDLER.set(&handler, || { helpers::HELPERS.set(&Default::default(), || { - let mut tr = $tr(); + let tr = $tr(); let module = module.clone(); - black_box(module.fold_with(&mut tr)); + black_box(module.apply(tr)); }) }) }) diff --git a/crates/swc_ecma_transforms_base/tests/fixture.rs b/crates/swc_ecma_transforms_base/tests/fixture.rs index 73ee09b54d96..a7f1b2ce53de 100644 --- a/crates/swc_ecma_transforms_base/tests/fixture.rs +++ b/crates/swc_ecma_transforms_base/tests/fixture.rs @@ -1,13 +1,11 @@ use std::path::{Path, PathBuf}; -use swc_common::{chain, sync::Lrc, Mark, SourceMap, SyntaxContext}; +use swc_common::{sync::Lrc, Mark, SourceMap, SyntaxContext}; use swc_ecma_ast::*; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{lexer::Lexer, EsSyntax, Parser, StringInput, Syntax, TsSyntax}; use swc_ecma_transforms_base::{fixer::fixer, resolver}; -use swc_ecma_visit::{ - visit_mut_obj_and_computed, visit_mut_pass, Fold, FoldWith, VisitMut, VisitMutWith, -}; +use swc_ecma_visit::{visit_mut_obj_and_computed, visit_mut_pass, VisitMut, VisitMutWith}; use testing::{fixture, run_test2, NormalizedOutput}; pub fn print(cm: Lrc, program: &Program) -> String { @@ -33,7 +31,7 @@ pub fn print(cm: Lrc, program: &Program) -> String { fn run(syntax: Syntax, input: &Path, op: F) where F: FnOnce() -> P, - P: Fold, + P: Pass, { let dir = input.parent().unwrap(); let output = dir.join(format!( @@ -53,7 +51,7 @@ where let mut folder = op(); - let program = program.fold_with(&mut folder); + let program = program.apply(&mut folder); let actual = print(cm, &program); let actual = NormalizedOutput::from(actual); diff --git a/crates/swc_ecma_transforms_compat/src/reserved_words.rs b/crates/swc_ecma_transforms_compat/src/reserved_words.rs index 16293bc99305..40188c4e192e 100644 --- a/crates/swc_ecma_transforms_compat/src/reserved_words.rs +++ b/crates/swc_ecma_transforms_compat/src/reserved_words.rs @@ -2,10 +2,10 @@ use swc_atoms::JsWord; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_visit::{ - noop_visit_mut_type, visit_mut_obj_and_computed, visit_mut_pass, Fold, VisitMut, VisitMutWith, + noop_visit_mut_type, visit_mut_obj_and_computed, visit_mut_pass, VisitMut, VisitMutWith, }; -pub fn reserved_words() -> impl 'static + Fold + VisitMut { +pub fn reserved_words() -> impl 'static + Pass + VisitMut { visit_mut_pass(EsReservedWord) } diff --git a/crates/swc_ecma_transforms_optimization/src/inline_globals.rs b/crates/swc_ecma_transforms_optimization/src/inline_globals.rs index 1b7797d61c9b..82b5d77204e6 100644 --- a/crates/swc_ecma_transforms_optimization/src/inline_globals.rs +++ b/crates/swc_ecma_transforms_optimization/src/inline_globals.rs @@ -6,7 +6,7 @@ use swc_common::{ use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::{ParVisitMut, Parallel}; use swc_ecma_utils::{collect_decls, parallel::cpu_count, NodeIgnoringSpan}; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; /// The key will be compared using [EqIgnoreSpan::eq_ignore_span], and matched /// expressions will be replaced with the value. diff --git a/crates/swc_ecma_transforms_optimization/src/json_parse.rs b/crates/swc_ecma_transforms_optimization/src/json_parse.rs index f3ce32ba2281..0c2d41933215 100644 --- a/crates/swc_ecma_transforms_optimization/src/json_parse.rs +++ b/crates/swc_ecma_transforms_optimization/src/json_parse.rs @@ -3,7 +3,7 @@ use swc_common::{util::take::Take, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::perf::Parallel; use swc_ecma_utils::{calc_literal_cost, member_expr, ExprFactory}; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; /// Transform to optimize performance of literals. /// @@ -27,7 +27,7 @@ use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitM /// - Object literal is deeply nested (threshold: ) /// /// See https://github.com/swc-project/swc/issues/409 -pub fn json_parse(min_cost: usize) -> impl Fold { +pub fn json_parse(min_cost: usize) -> impl Pass { visit_mut_pass(JsonParse { min_cost }) } From 4013444f03670b27da9af676310916e260a1befc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 16:58:33 +0900 Subject: [PATCH 123/186] CompilerPass --- crates/swc_common/src/pass.rs | 6 +++--- crates/swc_ecma_visit/src/lib.rs | 31 +++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/crates/swc_common/src/pass.rs b/crates/swc_common/src/pass.rs index 7515d503d271..a89a1b4b11d5 100644 --- a/crates/swc_common/src/pass.rs +++ b/crates/swc_common/src/pass.rs @@ -9,14 +9,14 @@ pub trait CompilerPass { /// /// - name should follow hyphen-case. /// - an implementation should return same name - fn name() -> Cow<'static, str>; + fn name(&self) -> Cow<'static, str>; } impl CompilerPass for Repeat where V: CompilerPass + Repeated, { - fn name() -> Cow<'static, str> { - Cow::Owned(format!("repeat({})", V::name())) + fn name(&self) -> Cow<'static, str> { + Cow::Owned(format!("repeat({})", self.pass.name())) } } diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 079d4d36177f..89c555687b94 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -6,9 +6,9 @@ #[doc(hidden)] pub extern crate swc_ecma_ast; -use std::fmt::Debug; +use std::{borrow::Cow, fmt::Debug}; -use swc_common::{util::take::Take, Span, DUMMY_SP}; +use swc_common::{pass::CompilerPass, util::take::Take, Span, DUMMY_SP}; use swc_ecma_ast::*; use swc_visit::{Repeat, Repeated}; @@ -59,6 +59,15 @@ where } } +impl CompilerPass for FoldPass +where + V: Fold + CompilerPass, +{ + fn name(&self) -> Cow<'static, str> { + self.pass.name() + } +} + pub fn visit_mut_pass(pass: V) -> VisitMutPass where V: VisitMut, @@ -103,6 +112,15 @@ where } } +impl CompilerPass for VisitMutPass +where + V: VisitMut + CompilerPass, +{ + fn name(&self) -> Cow<'static, str> { + self.pass.name() + } +} + pub fn visit_pass(pass: V) -> VisitPass where V: Visit, @@ -147,6 +165,15 @@ where } } +impl CompilerPass for VisitPass +where + V: Visit + CompilerPass, +{ + fn name(&self) -> Cow<'static, str> { + self.pass.name() + } +} + impl Fold for Repeat where V: Fold + Repeated, From 6a880f94fa271a5a949bd48f2a3e7b88f40346c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 17:00:09 +0900 Subject: [PATCH 124/186] More --- crates/swc_ecma_compat_es2015/src/new_target.rs | 2 +- .../swc_ecma_compat_es2022/src/private_in_object.rs | 2 +- .../src/simplify/branch/mod.rs | 13 ++++++------- .../src/simplify/const_propagation.rs | 4 ++-- .../src/simplify/dce/mod.rs | 7 +++---- .../src/simplify/expr/mod.rs | 5 ++--- .../src/simplify/inlining/mod.rs | 6 +++--- 7 files changed, 18 insertions(+), 21 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/new_target.rs b/crates/swc_ecma_compat_es2015/src/new_target.rs index 0d6c29059679..a4c5bf81a2c0 100644 --- a/crates/swc_ecma_compat_es2015/src/new_target.rs +++ b/crates/swc_ecma_compat_es2015/src/new_target.rs @@ -138,7 +138,7 @@ impl VisitMut for NewTarget { } impl CompilerPass for NewTarget { - fn name() -> Cow<'static, str> { + fn name(&self) -> Cow<'static, str> { Cow::Borrowed("new-target") } } diff --git a/crates/swc_ecma_compat_es2022/src/private_in_object.rs b/crates/swc_ecma_compat_es2022/src/private_in_object.rs index 6d35d7b4f415..d6f41993b0c5 100644 --- a/crates/swc_ecma_compat_es2022/src/private_in_object.rs +++ b/crates/swc_ecma_compat_es2022/src/private_in_object.rs @@ -106,7 +106,7 @@ struct ClassData { } impl CompilerPass for PrivateInObject { - fn name() -> Cow<'static, str> { + fn name(&self) -> Cow<'static, str> { Cow::Borrowed("private-in-object") } } diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs index 4455c698074a..d4cf689b29ed 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/branch/mod.rs @@ -6,10 +6,7 @@ use swc_common::{ Mark, Spanned, SyntaxContext, DUMMY_SP, }; use swc_ecma_ast::*; -use swc_ecma_transforms_base::{ - pass::RepeatedJsPass, - perf::{cpu_count, Parallel, ParallelExt}, -}; +use swc_ecma_transforms_base::perf::{cpu_count, Parallel, ParallelExt}; use swc_ecma_utils::{ extract_var_ids, is_literal, prepend_stmt, ExprCtx, ExprExt, ExprFactory, Hoister, IsEmpty, StmtExt, StmtLike, Value::Known, @@ -25,7 +22,9 @@ mod tests; /// Not intended for general use. Use [simplifier] instead. /// /// Ported from `PeepholeRemoveDeadCode` of google closure compiler. -pub fn dead_branch_remover(unresolved_mark: Mark) -> impl RepeatedJsPass + VisitMut + 'static { +pub fn dead_branch_remover( + unresolved_mark: Mark, +) -> impl Repeated + Pass + CompilerPass + VisitMut + 'static { visit_mut_pass(Remover { changed: false, normal_block: Default::default(), @@ -37,8 +36,8 @@ pub fn dead_branch_remover(unresolved_mark: Mark) -> impl RepeatedJsPass + Visit } impl CompilerPass for Remover { - fn name() -> Cow<'static, str> { - Cow::Borrowed("branch") + fn name(&self) -> Cow<'static, str> { + Cow::Borrowed("dead_branch_remover") } } diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs b/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs index 70fa2091ab74..6b3391343376 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/const_propagation.rs @@ -2,10 +2,10 @@ use swc_common::{collections::AHashMap, util::take::Take}; use swc_ecma_ast::*; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; /// This pass is kind of inliner, but it's far faster. -pub fn constant_propagation() -> impl 'static + Fold + VisitMut { +pub fn constant_propagation() -> impl 'static + Pass + VisitMut { visit_mut_pass(ConstPropagation::default()) } diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs index 9e8903e781bb..ad3fb5d28faa 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/dce/mod.rs @@ -19,8 +19,7 @@ use swc_ecma_utils::{ collect_decls, find_pat_ids, ExprCtx, ExprExt, IsEmpty, ModuleItemLike, StmtLike, }; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, visit_mut_pass, Fold, Visit, VisitMut, VisitMutWith, - VisitWith, + noop_visit_mut_type, noop_visit_type, visit_mut_pass, Visit, VisitMut, VisitMutWith, VisitWith, }; use swc_fast_graph::digraph::FastDiGraphMap; use tracing::{debug, span, Level}; @@ -31,7 +30,7 @@ use crate::debug_assert_valid; pub fn dce( config: Config, unresolved_mark: Mark, -) -> impl Fold + VisitMut + Repeated + CompilerPass { +) -> impl Pass + VisitMut + Repeated + CompilerPass { visit_mut_pass(TreeShaker { expr_ctx: ExprCtx { unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), @@ -97,7 +96,7 @@ struct TreeShaker { } impl CompilerPass for TreeShaker { - fn name() -> Cow<'static, str> { + fn name(&self) -> Cow<'static, str> { Cow::Borrowed("tree-shaker") } } diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs index 349a92a08d02..30528bf5d3fe 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs @@ -9,7 +9,6 @@ use swc_common::{ use swc_ecma_ast::*; use swc_ecma_transforms_base::{ ext::ExprRefExt, - pass::RepeatedJsPass, perf::{cpu_count, Parallel, ParallelExt}, }; use swc_ecma_utils::{ @@ -43,7 +42,7 @@ pub struct Config {} pub fn expr_simplifier( unresolved_mark: Mark, config: Config, -) -> impl RepeatedJsPass + VisitMut + 'static { +) -> impl Repeated + Pass + CompilerPass + VisitMut + 'static { visit_mut_pass(SimplifyExpr { expr_ctx: ExprCtx { unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), @@ -82,7 +81,7 @@ struct SimplifyExpr { } impl CompilerPass for SimplifyExpr { - fn name() -> Cow<'static, str> { + fn name(&self) -> Cow<'static, str> { Cow::Borrowed("simplify-expr") } } diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs index 16b90c78165e..d1692ab94cca 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/inlining/mod.rs @@ -5,7 +5,7 @@ use swc_common::{ util::take::Take, }; use swc_ecma_ast::*; -use swc_ecma_transforms_base::{pass::RepeatedJsPass, scope::IdentType}; +use swc_ecma_transforms_base::scope::IdentType; use swc_ecma_utils::{contains_this_expr, find_pat_ids}; use swc_ecma_visit::{ noop_visit_mut_type, noop_visit_type, visit_mut_pass, visit_obj_and_computed, Visit, VisitMut, @@ -33,7 +33,7 @@ pub struct Config {} /// /// Currently all functions are treated as a black box, and all the pass gives /// up inlining variables across a function call or a constructor call. -pub fn inlining(_: Config) -> impl 'static + RepeatedJsPass + VisitMut { +pub fn inlining(_: Config) -> impl 'static + Repeated + CompilerPass + Pass + VisitMut { visit_mut_pass(Inlining { phase: Phase::Analysis, is_first_run: true, @@ -54,7 +54,7 @@ enum Phase { } impl CompilerPass for Inlining<'_> { - fn name() -> Cow<'static, str> { + fn name(&self) -> Cow<'static, str> { Cow::Borrowed("inlining") } } From d759a7ef829353a4caf071fcfb467abcfcc254f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 17:01:50 +0900 Subject: [PATCH 125/186] More --- .../swc_ecma_transforms_typescript/src/typescript.rs | 6 +++--- crates/swc_fast_ts_strip/src/lib.rs | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/swc_ecma_transforms_typescript/src/typescript.rs b/crates/swc_ecma_transforms_typescript/src/typescript.rs index 5b9bbe88d061..c6005a22caca 100644 --- a/crates/swc_ecma_transforms_typescript/src/typescript.rs +++ b/crates/swc_ecma_transforms_typescript/src/typescript.rs @@ -6,7 +6,7 @@ use swc_common::{ }; use swc_ecma_ast::*; use swc_ecma_transforms_react::{parse_expr_for_jsx, JsxDirectives}; -use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{visit_mut_pass, VisitMut, VisitMutWith}; pub use crate::config::*; use crate::{strip_import_export::StripImportExport, strip_type::StripType, transform::transform}; @@ -48,7 +48,7 @@ impl VisitMut for TypeScript { n.visit_mut_with(&mut StripType::default()); - n.visit_mut_with(&mut transform( + n.mutate(transform( self.unresolved_mark, self.top_level_mark, self.config.import_export_assign_config, @@ -143,7 +143,7 @@ pub fn tsx( comments: C, unresolved_mark: Mark, top_level_mark: Mark, -) -> impl Fold + VisitMut +) -> impl Pass where C: Comments, { diff --git a/crates/swc_fast_ts_strip/src/lib.rs b/crates/swc_fast_ts_strip/src/lib.rs index 710595d94ada..d7a7f6dfead7 100644 --- a/crates/swc_fast_ts_strip/src/lib.rs +++ b/crates/swc_fast_ts_strip/src/lib.rs @@ -32,7 +32,7 @@ use swc_ecma_transforms_base::{ resolver, }; use swc_ecma_transforms_typescript::typescript; -use swc_ecma_visit::{Visit, VisitMutWith, VisitWith}; +use swc_ecma_visit::{Visit, VisitWith}; #[cfg(feature = "wasm-bindgen")] use wasm_bindgen::prelude::*; @@ -285,19 +285,19 @@ pub fn operate( let top_level_mark = Mark::new(); HELPERS.set(&Helpers::new(false), || { - program.visit_mut_with(&mut resolver(unresolved_mark, top_level_mark, true)); + program.mutate(&mut resolver(unresolved_mark, top_level_mark, true)); - program.visit_mut_with(&mut typescript::typescript( + program.mutate(&mut typescript::typescript( options.transform.unwrap_or_default(), unresolved_mark, top_level_mark, )); - program.visit_mut_with(&mut inject_helpers(unresolved_mark)); + program.mutate(&mut inject_helpers(unresolved_mark)); - program.visit_mut_with(&mut hygiene()); + program.mutate(&mut hygiene()); - program.visit_mut_with(&mut fixer(Some(&comments))); + program.mutate(&mut fixer(Some(&comments))); }); let mut src = std::vec::Vec::new(); From ffc8f223770964fa606ab588f444940993402d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 17:02:56 +0900 Subject: [PATCH 126/186] More --- crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs | 4 ++-- crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs b/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs index f15c289f399a..3a10ed1ef0b7 100644 --- a/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs +++ b/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs @@ -106,13 +106,13 @@ impl Fold for AsyncArrowsInClass { #[cfg(test)] mod tests { - use swc_common::chain; + use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::test; use super::*; - fn tr() -> impl Fold { + fn tr() -> impl Pass { let unresolved = Mark::new(); chain!( resolver(unresolved, Mark::new(), false), diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs b/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs index 49f65d687104..2accb8951c01 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs @@ -1,6 +1,7 @@ use std::{fs::read_to_string, path::PathBuf}; -use swc_common::{chain, comments::NoopComments, Mark}; +use swc_common::{comments::NoopComments, Mark}; +use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2015::{ From 509e251d303de7b462bb30995612893cb762c807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 17:07:29 +0900 Subject: [PATCH 127/186] More --- crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs | 5 +++-- ...fari_id_destructuring_collision_in_function_expression.rs | 5 +++-- .../swc_ecma_compat_bugfixes/src/template_literal_caching.rs | 5 +++-- .../swc_ecma_transforms_optimization/tests/const_modules.rs | 2 +- .../tests/remove_imports_with_side_effects.rs | 2 +- .../swc_ecma_transforms_optimization/tests/simplify_dce.rs | 2 +- .../tests/simplify_inlining.rs | 5 +++-- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs b/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs index 2797b4ccb52b..3cc9d8ab7985 100644 --- a/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs +++ b/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs @@ -62,13 +62,14 @@ impl VisitMut for EdgeDefaultParam { #[cfg(test)] mod tests { - use swc_common::{chain, Mark}; + use swc_common::Mark; + use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::test; use super::*; - fn tr() -> impl Fold { + fn tr() -> impl Pass { chain!( resolver(Mark::new(), Mark::new(), false), edge_default_param() diff --git a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs index 7822dd2c913f..9ef2b315d6ad 100644 --- a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs +++ b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs @@ -103,14 +103,15 @@ impl VisitMut for SafariIdDestructuringCollisionInFunctionExpression { #[cfg(test)] mod tests { - use swc_common::{chain, Mark}; + use swc_common::Mark; + use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::{test, HygieneTester}; use super::*; - fn tr() -> impl Fold { + fn tr() -> impl Pass { chain!( resolver(Mark::new(), Mark::new(), false), safari_id_destructuring_collision_in_function_expression() diff --git a/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs b/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs index b8fc6693686d..578ad75ba078 100644 --- a/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs +++ b/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs @@ -161,13 +161,14 @@ impl Fold for TemplateLiteralCaching { #[cfg(test)] mod tests { - use swc_common::{chain, Mark}; + use swc_common::Mark; + use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::test; use super::*; - fn tr() -> impl Fold { + fn tr() -> impl Pass { chain!( resolver(Mark::new(), Mark::new(), false), template_literal_caching() diff --git a/crates/swc_ecma_transforms_optimization/tests/const_modules.rs b/crates/swc_ecma_transforms_optimization/tests/const_modules.rs index 5e536929f6c8..7e0733f2e31f 100644 --- a/crates/swc_ecma_transforms_optimization/tests/const_modules.rs +++ b/crates/swc_ecma_transforms_optimization/tests/const_modules.rs @@ -4,7 +4,7 @@ use swc_ecma_transforms_optimization::const_modules; use swc_ecma_transforms_testing::{test, test_fixture, Tester}; use swc_ecma_visit::Fold; -fn tr(t: &mut Tester<'_>, sources: &[(&str, &[(&str, &str)])]) -> impl Fold { +fn tr(t: &mut Tester<'_>, sources: &[(&str, &[(&str, &str)])]) -> impl Pass { let mut m = HashMap::default(); for (src, values) in sources { diff --git a/crates/swc_ecma_transforms_optimization/tests/remove_imports_with_side_effects.rs b/crates/swc_ecma_transforms_optimization/tests/remove_imports_with_side_effects.rs index d98b0385b240..dde72282efe8 100644 --- a/crates/swc_ecma_transforms_optimization/tests/remove_imports_with_side_effects.rs +++ b/crates/swc_ecma_transforms_optimization/tests/remove_imports_with_side_effects.rs @@ -5,7 +5,7 @@ use swc_ecma_transforms_optimization::simplify::dce::{dce, Config}; use swc_ecma_transforms_testing::test; use swc_ecma_visit::Fold; -fn tr() -> impl Fold { +fn tr() -> impl Pass { Repeat::new(dce( Config { top_level: true, diff --git a/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs b/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs index 9e5cce5180dd..a3b2a0995bd3 100644 --- a/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs +++ b/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs @@ -8,7 +8,7 @@ use swc_ecma_transforms_testing::test; use swc_ecma_transforms_typescript::strip; use swc_ecma_visit::Fold; -fn tr() -> impl Fold { +fn tr() -> impl Pass { Repeat::new(dce( Config { top_level: true, diff --git a/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs b/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs index 14359428850c..12f43feea6f0 100644 --- a/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs +++ b/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs @@ -1,6 +1,7 @@ //! Copied from https://github.com/google/closure-compiler/blob/6ca3b62990064488074a1a8931b9e8dc39b148b3/test/com/google/javascript/jscomp/InlineVariablesTest.java -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_parser::{Syntax, TsSyntax}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2022::class_properties; @@ -9,7 +10,7 @@ use swc_ecma_transforms_testing::test; use swc_ecma_transforms_typescript::typescript; use swc_ecma_visit::Fold; -fn simple_strip(unresolved_mark: Mark, top_level_mark: Mark) -> impl Fold { +fn simple_strip(unresolved_mark: Mark, top_level_mark: Mark) -> impl Pass { typescript( typescript::Config { no_empty_export: true, From bd453ae3cd55176a6d88bc3e809e0703f93810f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 17:07:45 +0900 Subject: [PATCH 128/186] More --- crates/swc_ecma_transforms_module/tests/amd.rs | 2 +- crates/swc_ecma_transforms_module/tests/umd.rs | 5 +++-- .../src/simplify/branch/tests.rs | 3 ++- .../src/simplify/expr/tests.rs | 3 ++- crates/swc_ecma_transforms_proposal/tests/export.rs | 2 +- .../swc_ecma_transforms_proposal/tests/import_assertions.rs | 2 +- crates/swc_ecma_transforms_react/src/display_name/tests.rs | 2 +- crates/swc_ecma_transforms_react/src/jsx_self/tests.rs | 2 +- crates/swc_ecma_transforms_react/src/jsx_src/tests.rs | 2 +- 9 files changed, 13 insertions(+), 10 deletions(-) diff --git a/crates/swc_ecma_transforms_module/tests/amd.rs b/crates/swc_ecma_transforms_module/tests/amd.rs index 1fd4b111813f..38484ca1efd2 100644 --- a/crates/swc_ecma_transforms_module/tests/amd.rs +++ b/crates/swc_ecma_transforms_module/tests/amd.rs @@ -17,7 +17,7 @@ fn ts_syntax() -> Syntax { Syntax::Typescript(TsSyntax::default()) } -fn tr(config: amd::Config, is_ts: bool, comments: Rc) -> impl Fold { +fn tr(config: amd::Config, is_ts: bool, comments: Rc) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_module/tests/umd.rs b/crates/swc_ecma_transforms_module/tests/umd.rs index 6d1cbaec3227..0ca72be6242d 100644 --- a/crates/swc_ecma_transforms_module/tests/umd.rs +++ b/crates/swc_ecma_transforms_module/tests/umd.rs @@ -1,6 +1,7 @@ use std::{fs::File, path::PathBuf}; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_parser::{Syntax, TsSyntax}; use swc_ecma_transforms_base::{feature::FeatureFlag, resolver}; use swc_ecma_transforms_module::umd::{umd, Config}; @@ -16,7 +17,7 @@ fn ts_syntax() -> Syntax { Syntax::Typescript(TsSyntax::default()) } -fn tr(tester: &mut Tester<'_>, config: Config, typescript: bool) -> impl Fold { +fn tr(tester: &mut Tester<'_>, config: Config, typescript: bool) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs b/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs index cd1e5ea4ad72..ad09f637ee49 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs @@ -1,4 +1,5 @@ -use swc_common::{chain, Mark, SyntaxContext}; +use swc_common::{Mark, SyntaxContext}; +use swc_ecma_ast::chain; use swc_ecma_transforms_base::{fixer::paren_remover, resolver}; use swc_ecma_utils::ExprCtx; use swc_ecma_visit::visit_mut_pass; diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs b/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs index 77734718cd71..69168134fc82 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs @@ -1,4 +1,5 @@ -use swc_common::{chain, Mark, SyntaxContext}; +use swc_common::{Mark, SyntaxContext}; +use swc_ecma_ast::chain; use swc_ecma_transforms_base::{fixer::paren_remover, resolver}; use swc_ecma_transforms_testing::test_transform; use swc_ecma_utils::ExprCtx; diff --git a/crates/swc_ecma_transforms_proposal/tests/export.rs b/crates/swc_ecma_transforms_proposal/tests/export.rs index b5397987a376..857ee1b04a8a 100644 --- a/crates/swc_ecma_transforms_proposal/tests/export.rs +++ b/crates/swc_ecma_transforms_proposal/tests/export.rs @@ -15,7 +15,7 @@ fn syntax_namespace() -> Syntax { Syntax::Es(Default::default()) } -fn tr() -> impl Fold { +fn tr() -> impl Pass { chain!(export_default_from(), export_namespace_from()) } diff --git a/crates/swc_ecma_transforms_proposal/tests/import_assertions.rs b/crates/swc_ecma_transforms_proposal/tests/import_assertions.rs index ec349abb8a71..9f90910cf74e 100644 --- a/crates/swc_ecma_transforms_proposal/tests/import_assertions.rs +++ b/crates/swc_ecma_transforms_proposal/tests/import_assertions.rs @@ -3,7 +3,7 @@ use swc_ecma_transforms_proposal::import_assertions; use swc_ecma_transforms_testing::test; use swc_ecma_visit::Fold; -fn tr() -> impl Fold { +fn tr() -> impl Pass { import_assertions() } diff --git a/crates/swc_ecma_transforms_react/src/display_name/tests.rs b/crates/swc_ecma_transforms_react/src/display_name/tests.rs index ec11f08bb40b..02bbbc098678 100644 --- a/crates/swc_ecma_transforms_react/src/display_name/tests.rs +++ b/crates/swc_ecma_transforms_react/src/display_name/tests.rs @@ -2,7 +2,7 @@ use swc_ecma_transforms_testing::test; use super::*; -fn tr() -> impl Fold { +fn tr() -> impl Pass { display_name() } diff --git a/crates/swc_ecma_transforms_react/src/jsx_self/tests.rs b/crates/swc_ecma_transforms_react/src/jsx_self/tests.rs index 1315aecf2a64..8beb2294c854 100644 --- a/crates/swc_ecma_transforms_react/src/jsx_self/tests.rs +++ b/crates/swc_ecma_transforms_react/src/jsx_self/tests.rs @@ -2,7 +2,7 @@ use swc_ecma_transforms_testing::test; use super::*; -fn tr() -> impl Fold { +fn tr() -> impl Pass { jsx_self(true) } diff --git a/crates/swc_ecma_transforms_react/src/jsx_src/tests.rs b/crates/swc_ecma_transforms_react/src/jsx_src/tests.rs index 9523617842f0..79e24b9e50d3 100644 --- a/crates/swc_ecma_transforms_react/src/jsx_src/tests.rs +++ b/crates/swc_ecma_transforms_react/src/jsx_src/tests.rs @@ -3,7 +3,7 @@ use swc_ecma_transforms_testing::{test, test_exec}; use super::*; -fn tr() -> impl Fold { +fn tr() -> impl Pass { let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); jsx_src(true, cm) } From 8e05f2de3964b8cfcc79e8a457f95a71e3435ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 17:08:56 +0900 Subject: [PATCH 129/186] Work by myself --- crates/swc/src/builder.rs | 2 +- crates/swc/src/plugin.rs | 2 +- crates/swc_cli_impl/src/commands/plugin.rs | 6 +- .../src/object_super.rs | 3 +- .../src/optional_catch_binding.rs | 9 ++- .../swc_ecma_transforms/tests/decorators.rs | 11 +-- crates/swc_ecma_transforms/tests/deno.rs | 3 +- .../tests/es2015_function_name.rs | 5 +- .../swc_ecma_transforms_base/benches/deps.rs | 2 +- .../tests/es2015_arrow.rs | 5 +- .../tests/es2015_block_scoping.rs | 8 +- .../tests/es2015_classes.rs | 7 +- .../tests/es2015_computed_props.rs | 2 +- .../tests/es2015_destructuring.rs | 5 +- .../tests/es2015_generator.rs | 6 +- .../tests/es2015_new_target.rs | 3 +- .../tests/es2015_object_super.rs | 5 +- .../tests/es2015_parameters.rs | 5 +- .../tests/es2015_shorthand_propertie.rs | 3 +- .../tests/es2015_spread.rs | 5 +- .../tests/es2015_template_literals.rs | 2 +- .../tests/es2017_async_to_generator.rs | 4 +- .../tests/es2018_object_rest_spread.rs | 5 +- .../tests/es2020_nullish_coalescing.rs | 2 +- .../tests/es2020_optional_chaining.rs | 5 +- .../tests/es2021_logcal_assignments.rs | 3 +- .../tests/es2022_class_properties.rs | 5 +- .../tests/es2022_private_in_object.rs | 3 +- .../tests/es2022_static_blocks.rs | 3 +- .../src/system_js.rs | 2 +- .../tests/common_js.rs | 5 +- .../tests/system_js.rs | 5 +- .../src/simplify/branch/tests.rs | 2 +- .../src/simplify/expr/tests.rs | 2 +- .../src/decorators/mod.rs | 10 +-- .../tests/explicit_resource_management.rs | 3 +- .../src/jsx/tests.rs | 6 +- .../src/refresh/tests.rs | 2 +- crates/swc_ecma_transforms_testing/src/lib.rs | 80 +++++++++---------- .../tests/strip.rs | 8 +- .../fixture/swc_internal_plugin/src/lib.rs | 2 +- .../plugin_transform_schema_v1/src/lib.rs | 2 +- .../plugin_transform_schema_vtest/src/lib.rs | 2 +- 43 files changed, 139 insertions(+), 121 deletions(-) diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index 6aef5f493d82..f0ce4cb128e8 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -349,7 +349,7 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { feature_flag, resolver, ), - from_visit_mut(MinifierPass { + visit_mut_pass(MinifierPass { options: self.minify, cm: self.cm.clone(), comments, diff --git a/crates/swc/src/plugin.rs b/crates/swc/src/plugin.rs index 2f6e13977e25..71d096247a70 100644 --- a/crates/swc/src/plugin.rs +++ b/crates/swc/src/plugin.rs @@ -30,7 +30,7 @@ pub fn plugins( comments: Option, source_map: std::sync::Arc, unresolved_mark: swc_common::Mark, -) -> impl Fold { +) -> impl Pass { RustPlugins { plugins: configured_plugins, metadata_context, diff --git a/crates/swc_cli_impl/src/commands/plugin.rs b/crates/swc_cli_impl/src/commands/plugin.rs index 04dd2c823bc6..a481b46b1d24 100644 --- a/crates/swc_cli_impl/src/commands/plugin.rs +++ b/crates/swc_cli_impl/src/commands/plugin.rs @@ -238,7 +238,7 @@ build-wasm32 = "build --target wasm32-unknown-unknown" r##"use swc_core::ecma::{ ast::Program, transforms::testing::test_inline, - visit::{from_visit_mut, FoldWith, VisitMut}, + visit::{visit_mut_pass, FoldWith, VisitMut}, }; use swc_core::plugin::{plugin_transform, proxies::TransformPluginProgramMetadata}; @@ -267,7 +267,7 @@ impl VisitMut for TransformVisitor { /// Refer swc_plugin_macro to see how does it work internally. #[plugin_transform] pub fn process_transform(program: Program, _metadata: TransformPluginProgramMetadata) -> Program { - program.fold_with(&mut from_visit_mut(TransformVisitor)) + program.fold_with(&mut visit_mut_pass(TransformVisitor)) } // An example to test plugin transform. @@ -276,7 +276,7 @@ pub fn process_transform(program: Program, _metadata: TransformPluginProgramMeta // unless explicitly required to do so. test_inline!( Default::default(), - |_| from_visit_mut(TransformVisitor), + |_| visit_mut_pass(TransformVisitor), boo, // Input codes r#"console.log("transform");"#, diff --git a/crates/swc_ecma_compat_es2015/src/object_super.rs b/crates/swc_ecma_compat_es2015/src/object_super.rs index 5683af090cf8..4082156d361c 100644 --- a/crates/swc_ecma_compat_es2015/src/object_super.rs +++ b/crates/swc_ecma_compat_es2015/src/object_super.rs @@ -484,7 +484,8 @@ impl SuperReplacer { } #[cfg(test)] mod tests { - use swc_common::{chain, Mark}; + use swc_common::Mark; + use swc_ecma_ast::chain; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::test; diff --git a/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs b/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs index c441035a64c3..4969ec520262 100644 --- a/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs +++ b/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs @@ -25,17 +25,18 @@ impl VisitMut for OptionalCatchBinding { #[cfg(test)] mod tests { - use swc_common::{chain, Mark}; + use swc_common::Mark; + use swc_ecma_ast::{chain, Pass}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::test; - use swc_ecma_visit::{visit_mut_pass, Fold}; + use swc_ecma_visit::visit_mut_pass; use crate::optional_catch_binding::OptionalCatchBinding; - pub fn tr() -> impl Fold { + pub fn tr() -> impl Pass { chain!( resolver(Mark::new(), Mark::new(), false), - from_visit_mut(OptionalCatchBinding) + visit_mut_pass(OptionalCatchBinding) ) } diff --git a/crates/swc_ecma_transforms/tests/decorators.rs b/crates/swc_ecma_transforms/tests/decorators.rs index 03d0082d40cc..c1f7648b6431 100644 --- a/crates/swc_ecma_transforms/tests/decorators.rs +++ b/crates/swc_ecma_transforms/tests/decorators.rs @@ -7,7 +7,8 @@ use std::{fs, path::PathBuf}; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -36,7 +37,7 @@ fn syntax(decorators_before_export: bool) -> Syntax { }) } -fn tr(_: &Tester) -> impl Fold { +fn tr(_: &Tester) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); @@ -48,7 +49,7 @@ fn tr(_: &Tester) -> impl Fold { ) } -fn ts_transform(t: &Tester) -> impl Fold { +fn ts_transform(t: &Tester) -> impl Pass { simple_strip( t, Config { @@ -58,7 +59,7 @@ fn ts_transform(t: &Tester) -> impl Fold { ) } -fn simple_strip(_: &Tester, config: Config) -> impl Fold { +fn simple_strip(_: &Tester, config: Config) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); @@ -85,7 +86,7 @@ fn simple_strip(_: &Tester, config: Config) -> impl Fold { } /// Folder for `transformation_*` tests -fn transformation(t: &Tester) -> impl Fold { +fn transformation(t: &Tester) -> impl Pass { simple_strip(t, Default::default()) } diff --git a/crates/swc_ecma_transforms/tests/deno.rs b/crates/swc_ecma_transforms/tests/deno.rs index 4b00541d3078..21d385974b10 100644 --- a/crates/swc_ecma_transforms/tests/deno.rs +++ b/crates/swc_ecma_transforms/tests/deno.rs @@ -4,7 +4,8 @@ ))] use std::path::PathBuf; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms::{fixer, helpers::inject_helpers, hygiene, resolver}; use swc_ecma_transforms_proposal::{ diff --git a/crates/swc_ecma_transforms/tests/es2015_function_name.rs b/crates/swc_ecma_transforms/tests/es2015_function_name.rs index 6945bc0238e2..6d29d6e4d997 100644 --- a/crates/swc_ecma_transforms/tests/es2015_function_name.rs +++ b/crates/swc_ecma_transforms/tests/es2015_function_name.rs @@ -5,7 +5,8 @@ feature = "swc_ecma_transforms_proposal", ))] -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -21,7 +22,7 @@ fn syntax() -> Syntax { Default::default() } -fn tr() -> impl Fold { +fn tr() -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_base/benches/deps.rs b/crates/swc_ecma_transforms_base/benches/deps.rs index 0ff1e1c611de..8feee9f96aed 100644 --- a/crates/swc_ecma_transforms_base/benches/deps.rs +++ b/crates/swc_ecma_transforms_base/benches/deps.rs @@ -233,7 +233,7 @@ fn bench_cases(c: &mut Criterion) { criterion_group!(benches, bench_cases); criterion_main!(benches); -fn noop_fold() -> impl Fold { +fn noop_fold() -> impl Pass { struct Noop; impl Fold for Noop {} Noop diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index 9f8738033a89..ca0236cabdba 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -1,12 +1,13 @@ use std::path::PathBuf; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2015::arrow; use swc_ecma_transforms_testing::{compare_stdout, test_fixture}; use swc_ecma_visit::Fold; -fn tr() -> impl Fold { +fn tr() -> impl Pass { let unresolved = Mark::new(); let global = Mark::new(); chain!(resolver(unresolved, global, false), arrow(unresolved)) diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs b/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs index 849e19321b52..52ec3c8c8959 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs @@ -1,7 +1,7 @@ use std::{fs::read_to_string, path::PathBuf}; -use swc_common::{chain, Mark, SyntaxContext}; -use swc_ecma_ast::{Ident, PropName, TsQualifiedName}; +use swc_common::{Mark, SyntaxContext}; +use swc_ecma_ast::{chain, Ident, PropName, TsQualifiedName}; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -12,7 +12,7 @@ use swc_ecma_transforms_compat::{ use swc_ecma_transforms_testing::{compare_stdout, test, test_exec, test_fixture, Tester}; use swc_ecma_visit::{visit_mut_obj_and_computed, visit_mut_pass, Fold, VisitMut, VisitMutWith}; -fn tr() -> impl Fold { +fn tr() -> impl Pass { let unresolved_mark = Mark::new(); chain!( resolver(unresolved_mark, Mark::new(), false), @@ -674,7 +674,7 @@ fn fixture(input: PathBuf) { chain!( resolver(unresolved_mark, Mark::new(), false), block_scoping(unresolved_mark), - from_visit_mut(TsHygiene { unresolved_mark }) + visit_mut_pass(TsHygiene { unresolved_mark }) ) }, &input, diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs b/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs index 64df8c18bc5e..c2cf57f39ac2 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs @@ -1,6 +1,7 @@ use std::{fs::read_to_string, path::PathBuf}; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::{chain, Pass}; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -16,11 +17,11 @@ fn syntax() -> Syntax { Syntax::default() } -fn tr(_: &Tester) -> impl Fold { +fn tr(_: &Tester) -> impl Pass { classes(Default::default()) } -fn spec_tr(_: &Tester) -> impl Fold { +fn spec_tr(_: &Tester) -> impl Pass { let unresolved_mark = Mark::new(); chain!( resolver(unresolved_mark, Mark::new(), false), diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_computed_props.rs b/crates/swc_ecma_transforms_compat/tests/es2015_computed_props.rs index 3b0bd78803f1..dffbe6fc20dc 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_computed_props.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_computed_props.rs @@ -9,7 +9,7 @@ fn syntax() -> Syntax { ::swc_ecma_parser::Syntax::default() } -fn tr(_: ()) -> impl Fold { +fn tr(_: ()) -> impl Pass { computed_properties(Default::default()) } diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs b/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs index 020f4561cd3f..00f69b29e74e 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -19,7 +20,7 @@ fn syntax() -> Syntax { Default::default() } -fn tr() -> impl Fold { +fn tr() -> impl Pass { chain!( resolver(Mark::new(), Mark::new(), false), destructuring(Config { loose: true }) diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs b/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs index 69fac8cf95a4..47820773c924 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs @@ -1,10 +1,10 @@ #![allow(clippy::unit_arg)] use swc_common::{ - chain, comments::{NoopComments, SingleThreadedComments}, Mark, }; +use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -18,7 +18,7 @@ fn syntax() -> Syntax { Syntax::default() } -fn tr(_: ()) -> impl Fold { +fn tr(_: ()) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); chain!( @@ -27,7 +27,7 @@ fn tr(_: ()) -> impl Fold { ) } -fn tr_with_async() -> impl Fold { +fn tr_with_async() -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); chain!( diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs index add83ff25d10..d90ac877fe0e 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs @@ -1,7 +1,8 @@ use std::{fs::read_to_string, path::PathBuf}; use serde::Deserialize; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ es2015::{arrow, classes, new_target::new_target}, diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs b/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs index ae6e78545a65..158b0a9094ad 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs @@ -1,4 +1,5 @@ -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::{chain, Pass}; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2015::{function_name, object_super, shorthand}; @@ -9,7 +10,7 @@ fn syntax() -> Syntax { ::swc_ecma_parser::Syntax::default() } -fn tr() -> impl Fold { +fn tr() -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs b/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs index aec8c84f6d01..047d8e4b4415 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -16,7 +17,7 @@ fn syntax() -> Syntax { Default::default() } -fn tr(c: Config) -> impl Fold { +fn tr(c: Config) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_shorthand_propertie.rs b/crates/swc_ecma_transforms_compat/tests/es2015_shorthand_propertie.rs index d2a49cc38e56..e9b42702adc6 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_shorthand_propertie.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_shorthand_propertie.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2015::shorthand; use swc_ecma_transforms_testing::test_fixture; diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs b/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs index da6a65aea201..73b0a16343ca 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs @@ -1,4 +1,5 @@ -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2015::{block_scoping, parameters, spread}; use swc_ecma_transforms_testing::{test, test_exec}; @@ -8,7 +9,7 @@ fn syntax() -> ::swc_ecma_parser::Syntax { Default::default() } -fn tr() -> impl Fold { +fn tr() -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_template_literals.rs b/crates/swc_ecma_transforms_compat/tests/es2015_template_literals.rs index 867c67d904a5..b1fda9fd9435 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_template_literals.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_template_literals.rs @@ -7,7 +7,7 @@ fn syntax() -> Syntax { Default::default() } -fn tr(config: template_literal::Config) -> impl Fold { +fn tr(config: template_literal::Config) -> impl Pass { template_literal(config) } diff --git a/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs b/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs index 6d3035dd6d7c..b038309f62ae 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs @@ -38,7 +38,7 @@ fn syntax() -> Syntax { Syntax::default() } -fn tr() -> impl Fold { +fn tr() -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); @@ -54,7 +54,7 @@ fn tr() -> impl Fold { ) } -fn with_resolver() -> impl Fold { +fn with_resolver() -> impl Pass { let unresolved = Mark::new(); let top_level = Mark::new(); chain!( diff --git a/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs b/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs index b5560095d2d5..a3b3aeb5bf32 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -14,7 +15,7 @@ fn syntax() -> Syntax { Syntax::default() } -fn tr(c: Config) -> impl Fold { +fn tr(c: Config) -> impl Pass { object_rest_spread(c) } diff --git a/crates/swc_ecma_transforms_compat/tests/es2020_nullish_coalescing.rs b/crates/swc_ecma_transforms_compat/tests/es2020_nullish_coalescing.rs index 8bbd07d6c9b9..738e62d9b37b 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2020_nullish_coalescing.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2020_nullish_coalescing.rs @@ -3,7 +3,7 @@ use swc_ecma_transforms_compat::es2020::nullish_coalescing::{nullish_coalescing, use swc_ecma_transforms_testing::{compare_stdout, test, test_exec}; use swc_ecma_visit::Fold; -fn tr(c: Config) -> impl Fold { +fn tr(c: Config) -> impl Pass { nullish_coalescing(c) } diff --git a/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs b/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs index 12d8f38d8e81..968145eb0c58 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs @@ -1,6 +1,7 @@ use std::{fs::read_to_string, path::PathBuf}; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -10,7 +11,7 @@ use swc_ecma_transforms_compat::{ use swc_ecma_transforms_testing::{compare_stdout, test, test_exec, test_fixture}; use swc_ecma_visit::Fold; -fn tr(c: Config) -> impl Fold { +fn tr(c: Config) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); chain!( diff --git a/crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs b/crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs index 5ab0ae08e3de..cd9bfaba553a 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs @@ -1,9 +1,10 @@ +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_compat::es2021; use swc_ecma_transforms_testing::{test, test_exec}; use swc_ecma_visit::Fold; -fn tr() -> impl Fold { +fn tr() -> impl Pass { es2021::logical_assignments() } diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs b/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs index a16f09c9cfe7..ccdffb0dc90a 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs @@ -2,7 +2,8 @@ use std::{fs::read_to_string, path::PathBuf}; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -20,7 +21,7 @@ fn syntax() -> Syntax { Syntax::Es(Default::default()) } -fn tr(_: &Tester) -> impl Fold { +fn tr(_: &Tester) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs b/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs index 2d9d4b77a7a3..fc2011e05d8c 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs @@ -1,7 +1,8 @@ use std::path::PathBuf; use serde::Deserialize; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ es2015::classes, diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs b/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs index e208c9e39fab..69f4dc14b1c4 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2022::{class_properties, static_blocks}; diff --git a/crates/swc_ecma_transforms_module/src/system_js.rs b/crates/swc_ecma_transforms_module/src/system_js.rs index b982c1cf4a5c..c65a7defc07c 100644 --- a/crates/swc_ecma_transforms_module/src/system_js.rs +++ b/crates/swc_ecma_transforms_module/src/system_js.rs @@ -41,7 +41,7 @@ struct SystemJs { context_ident: Ident, } -pub fn system_js(resolver: Resolver, unresolved_mark: Mark, config: Config) -> impl Fold { +pub fn system_js(resolver: Resolver, unresolved_mark: Mark, config: Config) -> impl Pass { SystemJs { unresolved_mark, resolver, diff --git a/crates/swc_ecma_transforms_module/tests/common_js.rs b/crates/swc_ecma_transforms_module/tests/common_js.rs index 65e7abe90439..b66a98d0bb38 100644 --- a/crates/swc_ecma_transforms_module/tests/common_js.rs +++ b/crates/swc_ecma_transforms_module/tests/common_js.rs @@ -1,6 +1,7 @@ use std::{fs::File, path::PathBuf}; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_parser::{Syntax, TsSyntax}; use swc_ecma_transforms_base::{feature::FeatureFlag, resolver}; use swc_ecma_transforms_compat::es2015::for_of; @@ -17,7 +18,7 @@ fn ts_syntax() -> Syntax { Syntax::Typescript(TsSyntax::default()) } -fn tr(config: common_js::Config, is_ts: bool) -> impl Fold { +fn tr(config: common_js::Config, is_ts: bool) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_module/tests/system_js.rs b/crates/swc_ecma_transforms_module/tests/system_js.rs index 98706027c11f..963b57e1a599 100644 --- a/crates/swc_ecma_transforms_module/tests/system_js.rs +++ b/crates/swc_ecma_transforms_module/tests/system_js.rs @@ -2,7 +2,8 @@ use std::path::PathBuf; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_module::system_js::{system_js, Config}; @@ -13,7 +14,7 @@ fn syntax() -> Syntax { Syntax::Es(Default::default()) } -fn tr(_tester: &mut Tester<'_>, config: Config) -> impl Fold { +fn tr(_tester: &mut Tester<'_>, config: Config) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); chain!( diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs b/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs index ad09f637ee49..041d4f77bf0e 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs @@ -19,7 +19,7 @@ macro_rules! test_stmt { resolver(unresolved_mark, top_level_mark, false), paren_remover(None), expr_simplifier(top_level_mark, Default::default()), - from_visit_mut(super::Remover { + visit_mut_pass(super::Remover { changed: false, normal_block: Default::default(), expr_ctx: ExprCtx { diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs b/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs index 69168134fc82..34c686a4f6a0 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs @@ -18,7 +18,7 @@ fn fold(src: &str, expected: &str) { chain!( resolver(unresolved_mark, top_level_mark, false), paren_remover(None), - from_visit_mut(SimplifyExpr { + visit_mut_pass(SimplifyExpr { expr_ctx: ExprCtx { unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark), // This is hack diff --git a/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs b/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs index ea0205dcf306..5eedc126fd81 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs @@ -3,7 +3,7 @@ use std::{iter, mem::take}; use either::Either; use serde::Deserialize; use swc_common::{Spanned, DUMMY_SP}; -use swc_ecma_ast::*; +use swc_ecma_ast::{Pass, *}; use swc_ecma_transforms_base::helper; use swc_ecma_transforms_classes::super_field::SuperFieldAccessFolder; use swc_ecma_utils::{ @@ -54,7 +54,7 @@ mod legacy; /// } /// } /// ``` -pub fn decorators(c: Config) -> impl Fold { +pub fn decorators(c: Config) -> impl Pass { if c.legacy { Either::Left(visit_mut_pass(self::legacy::new(c.emit_metadata))) } else { @@ -331,7 +331,7 @@ impl Decorators { ($method:expr, $fn_name:expr, $key_prop_value:expr) => {{ let fn_name = $fn_name; let method = $method; - let mut folder = swc_ecma_visit::from_visit_mut(SuperFieldAccessFolder { + let mut folder = SuperFieldAccessFolder { class_name: &ident, constructor_this_mark: None, is_static: method.is_static, @@ -343,9 +343,9 @@ impl Decorators { constant_super: false, super_class: &None, in_pat: false, - }); + }; - let method = method.fold_with(&mut folder); + method.visit_mut_with(&mut folder); // kind: "method", // key: getKeyJ(), diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/tests/explicit_resource_management.rs index 562231392b13..858d3a24d194 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit_resource_management.rs @@ -1,6 +1,7 @@ use std::{fs::read_to_string, path::PathBuf}; -use swc_common::{chain, Mark}; +use swc_common::Mark; +use swc_ecma_ast::chain; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_proposal::explicit_resource_management::explicit_resource_management; diff --git a/crates/swc_ecma_transforms_react/src/jsx/tests.rs b/crates/swc_ecma_transforms_react/src/jsx/tests.rs index 66541a384d34..424c57b1749a 100644 --- a/crates/swc_ecma_transforms_react/src/jsx/tests.rs +++ b/crates/swc_ecma_transforms_react/src/jsx/tests.rs @@ -20,7 +20,7 @@ use testing::NormalizedOutput; use super::*; use crate::{display_name, pure_annotations, react}; -fn tr(t: &mut Tester, options: Options, top_level_mark: Mark) -> impl Fold { +fn tr(t: &mut Tester, options: Options, top_level_mark: Mark) -> impl Pass { let unresolved_mark = Mark::new(); chain!( @@ -61,7 +61,7 @@ fn true_by_default() -> bool { true } -fn fixture_tr(t: &mut Tester, mut options: FixtureOptions) -> impl Fold { +fn fixture_tr(t: &mut Tester, mut options: FixtureOptions) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); @@ -85,7 +85,7 @@ fn fixture_tr(t: &mut Tester, mut options: FixtureOptions) -> impl Fold { ) } -fn integration_tr(t: &mut Tester, mut options: FixtureOptions) -> impl Fold { +fn integration_tr(t: &mut Tester, mut options: FixtureOptions) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_react/src/refresh/tests.rs b/crates/swc_ecma_transforms_react/src/refresh/tests.rs index 8d5c63c1d332..ab2d9f1f8374 100644 --- a/crates/swc_ecma_transforms_react/src/refresh/tests.rs +++ b/crates/swc_ecma_transforms_react/src/refresh/tests.rs @@ -5,7 +5,7 @@ use swc_ecma_transforms_testing::{test, Tester}; use super::*; use crate::jsx; -fn tr(t: &mut Tester) -> impl Fold { +fn tr(t: &mut Tester) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_testing/src/lib.rs b/crates/swc_ecma_transforms_testing/src/lib.rs index 71df03183acf..9653b8dc2940 100644 --- a/crates/swc_ecma_transforms_testing/src/lib.rs +++ b/crates/swc_ecma_transforms_testing/src/lib.rs @@ -20,7 +20,6 @@ use base64::prelude::{Engine, BASE64_STANDARD}; use serde::de::DeserializeOwned; use sha2::{Digest, Sha256}; use swc_common::{ - chain, comments::{Comments, SingleThreadedComments}, errors::{Handler, HANDLER}, source_map::SourceMapGenConfig, @@ -35,7 +34,6 @@ use swc_ecma_transforms_base::{ fixer, helpers::{inject_helpers, HELPERS}, hygiene, - pass::noop, }; use swc_ecma_utils::{quote_ident, quote_str, ExprFactory}; use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, FoldWith, VisitMut}; @@ -162,9 +160,9 @@ impl Tester<'_> { Ok(stmts.pop().unwrap()) } - pub fn apply_transform( + pub fn apply_transform( &mut self, - mut tr: T, + tr: T, name: &str, syntax: Syntax, is_module: Option, @@ -182,7 +180,7 @@ impl Tester<'_> { }, )?; - Ok(program.fold_with(&mut tr)) + Ok(program.apply(tr)) } pub fn print(&mut self, program: &Program, comments: &Rc) -> String { @@ -237,14 +235,6 @@ impl VisitMut for RegeneratorHandler { } } -fn make_tr(op: F, tester: &mut Tester<'_>) -> impl Fold -where - F: FnOnce(&mut Tester<'_>) -> P, - P: Fold, -{ - chain!(op(tester), visit_mut_pass(RegeneratorHandler)) -} - #[track_caller] pub fn test_transform( syntax: Syntax, @@ -254,11 +244,11 @@ pub fn test_transform( expected: &str, ) where F: FnOnce(&mut Tester) -> P, - P: Fold, + P: Pass, { Tester::run(|tester| { let expected = tester.apply_transform( - visit_mut_pass(::swc_ecma_utils::DropSpan), + swc_ecma_utils::DropSpan, "output.js", syntax, is_module, @@ -269,7 +259,7 @@ pub fn test_transform( println!("----- Actual -----"); - let tr = make_tr(tr, tester); + let tr = chain!(tr(tester), visit_mut_pass(RegeneratorHandler)); let actual = tester.apply_transform(tr, "input.js", syntax, is_module, input)?; match ::std::env::var("PRINT_HYGIENE") { @@ -284,9 +274,9 @@ pub fn test_transform( } let actual = actual - .fold_with(&mut visit_mut_pass(::swc_ecma_utils::DropSpan)) - .fold_with(&mut hygiene::hygiene()) - .fold_with(&mut fixer::fixer(Some(&tester.comments))); + .apply(::swc_ecma_utils::DropSpan) + .apply(hygiene::hygiene()) + .apply(fixer::fixer(Some(&tester.comments))); println!("{:?}", tester.comments); println!("{:?}", expected_comments); @@ -338,7 +328,7 @@ pub fn test_inline_input_output( output: &str, ) where F: FnOnce(&mut Tester) -> P, - P: Fold, + P: Pass, { let _logger = testing::init(); @@ -346,7 +336,7 @@ pub fn test_inline_input_output( let expected_src = Tester::run(|tester| { let expected_program = - tester.apply_transform(noop(), "expected.js", syntax, is_module, expected)?; + tester.apply_transform(noop_pass(), "expected.js", syntax, is_module, expected)?; let expected_src = tester.print(&expected_program, &Default::default()); @@ -384,8 +374,8 @@ pub fn test_inline_input_output( } let actual = actual - .fold_with(&mut crate::hygiene::hygiene()) - .fold_with(&mut crate::fixer::fixer(Some(&tester.comments))); + .apply(crate::hygiene::hygiene()) + .apply(crate::fixer::fixer(Some(&tester.comments))); let actual_src = tester.print(&actual, &Default::default()); @@ -411,7 +401,7 @@ pub fn test_inlined_transform( input: &str, ) where F: FnOnce(&mut Tester) -> P, - P: Fold, + P: Pass, { let loc = panic::Location::caller(); @@ -467,7 +457,7 @@ macro_rules! test_inline { test_inline!( ignore, Syntax::default(), - |_| noop(), + |_| noop_pass(), test_inline_ignored, "class Foo {}", "class Foo {}" @@ -475,7 +465,7 @@ test_inline!( test_inline!( Syntax::default(), - |_| noop(), + |_| noop_pass(), test_inline_pass, "class Foo {}", "class Foo {}" @@ -484,7 +474,13 @@ test_inline!( #[test] #[should_panic] fn test_inline_should_fail() { - test_inline_input_output(Default::default(), None, |_| noop(), "class Foo {}", ""); + test_inline_input_output( + Default::default(), + None, + |_| noop_pass(), + "class Foo {}", + "", + ); } #[macro_export] @@ -537,10 +533,10 @@ macro_rules! test { pub fn compare_stdout(syntax: Syntax, tr: F, input: &str) where F: FnOnce(&mut Tester<'_>) -> P, - P: Fold, + P: Pass, { Tester::run(|tester| { - let tr = make_tr(tr, tester); + let tr = chain!(tr(tester), visit_mut_pass(RegeneratorHandler)); let program = tester.apply_transform(tr, "input.js", syntax, Some(true), input)?; @@ -556,11 +552,11 @@ where } let mut program = program - .fold_with(&mut hygiene::hygiene()) - .fold_with(&mut fixer::fixer(Some(&tester.comments))); + .apply(hygiene::hygiene()) + .apply(fixer::fixer(Some(&tester.comments))); let src_without_helpers = tester.print(&program, &tester.comments.clone()); - program = program.fold_with(&mut inject_helpers(Mark::fresh(Mark::root()))); + program = program.apply(inject_helpers(Mark::fresh(Mark::root()))); let transformed_src = tester.print(&program, &tester.comments.clone()); @@ -585,10 +581,10 @@ where pub fn exec_tr(_test_name: &str, syntax: Syntax, tr: F, input: &str) where F: FnOnce(&mut Tester<'_>) -> P, - P: Fold, + P: Pass, { Tester::run(|tester| { - let tr = make_tr(tr, tester); + let tr = chain!(tr(tester), visit_mut_pass(RegeneratorHandler)); let program = tester.apply_transform( tr, @@ -614,11 +610,11 @@ where } let mut program = program - .fold_with(&mut hygiene::hygiene()) - .fold_with(&mut fixer::fixer(Some(&tester.comments))); + .apply(hygiene::hygiene()) + .apply(fixer::fixer(Some(&tester.comments))); let src_without_helpers = tester.print(&program, &tester.comments.clone()); - program = program.fold_with(&mut inject_helpers(Mark::fresh(Mark::root()))); + program = program.apply(inject_helpers(Mark::fresh(Mark::root()))); let src = tester.print(&program, &tester.comments.clone()); @@ -862,7 +858,7 @@ pub fn test_fixture

( output: &Path, config: FixtureTestConfig, ) where - P: Fold, + P: Pass, { let input = fs::read_to_string(input).unwrap(); @@ -877,7 +873,7 @@ pub fn test_fixture

( fn test_fixture_inner<'a>( syntax: Syntax, - tr: Box Box>, + tr: Box Box>, input: &str, output: &Path, config: FixtureTestConfig, @@ -890,7 +886,7 @@ fn test_fixture_inner<'a>( let expected_src = Tester::run(|tester| { let expected_program = - tester.apply_transform(noop(), "expected.js", syntax, config.module, &expected)?; + tester.apply_transform(noop_pass(), "expected.js", syntax, config.module, &expected)?; let expected_src = tester.print(&expected_program, &tester.comments.clone()); @@ -939,8 +935,8 @@ fn test_fixture_inner<'a>( } let actual = actual - .fold_with(&mut crate::hygiene::hygiene()) - .fold_with(&mut crate::fixer::fixer(Some(&tester.comments))); + .apply(crate::hygiene::hygiene()) + .apply(crate::fixer::fixer(Some(&tester.comments))); let actual_src = { let module = &actual; diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index b0686311fbda..ce95fd5c066d 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -18,7 +18,7 @@ use swc_ecma_transforms_typescript::{ }; use swc_ecma_visit::Fold; -fn tr(t: &mut Tester) -> impl Fold { +fn tr(t: &mut Tester) -> impl Pass { tr_config(t, None, None, false) } @@ -27,7 +27,7 @@ fn tr_config( config: Option, decorators_config: Option, use_define_for_class_fields: bool, -) -> impl Fold { +) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); let has_decorators = decorators_config.is_some(); @@ -54,7 +54,7 @@ fn tr_config( ) } -fn tsxr(t: &Tester) -> impl Fold { +fn tsxr(t: &Tester) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); @@ -82,7 +82,7 @@ fn tsxr(t: &Tester) -> impl Fold { ) } -fn properties(_: &Tester, loose: bool) -> impl Fold { +fn properties(_: &Tester, loose: bool) -> impl Pass { let static_blocks_mark = Mark::new(); let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); diff --git a/crates/swc_plugin_runner/tests/fixture/swc_internal_plugin/src/lib.rs b/crates/swc_plugin_runner/tests/fixture/swc_internal_plugin/src/lib.rs index 191e73fb60e7..5ba106abe91f 100644 --- a/crates/swc_plugin_runner/tests/fixture/swc_internal_plugin/src/lib.rs +++ b/crates/swc_plugin_runner/tests/fixture/swc_internal_plugin/src/lib.rs @@ -134,5 +134,5 @@ pub fn process(program: Program, metadata: TransformPluginProgramMetadata) -> Pr dbg!(); - program.fold_with(&mut from_visit_mut(ConsoleOutputReplacer { metadata })) + program.fold_with(&mut visit_mut_pass(ConsoleOutputReplacer { metadata })) } diff --git a/packages/core/e2e/fixtures/plugin_transform_schema_v1/src/lib.rs b/packages/core/e2e/fixtures/plugin_transform_schema_v1/src/lib.rs index 1fb1c75d94c2..5328dcb554c7 100644 --- a/packages/core/e2e/fixtures/plugin_transform_schema_v1/src/lib.rs +++ b/packages/core/e2e/fixtures/plugin_transform_schema_v1/src/lib.rs @@ -31,5 +31,5 @@ pub fn process(program: Program, _metadata: TransformPluginProgramMetadata) -> P Program::Module(_module) => {} } - program.fold_with(&mut from_visit_mut(ConsoleOutputReplacer)) + program.fold_with(&mut visit_mut_pass(ConsoleOutputReplacer)) } diff --git a/packages/core/e2e/fixtures/plugin_transform_schema_vtest/src/lib.rs b/packages/core/e2e/fixtures/plugin_transform_schema_vtest/src/lib.rs index bc0a9e3443bc..153ce4d69253 100644 --- a/packages/core/e2e/fixtures/plugin_transform_schema_vtest/src/lib.rs +++ b/packages/core/e2e/fixtures/plugin_transform_schema_vtest/src/lib.rs @@ -34,5 +34,5 @@ pub fn process(program: Program, _metadata: TransformPluginProgramMetadata) -> P Program::Script(..) => {} Program::Module(..) => {} } - program.fold_with(&mut from_visit_mut(ConsoleOutputReplacer)) + program.fold_with(&mut visit_mut_pass(ConsoleOutputReplacer)) } From 95ac3b41b03b218df4b26f0f89bdb0cb1fd7a919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 17:11:50 +0900 Subject: [PATCH 130/186] Fix more --- crates/swc_ecma_compat_es3/src/member_expr_lits.rs | 8 ++++---- .../swc_ecma_transforms_compat/tests/es2015_new_target.rs | 4 ++-- .../tests/es2018_object_rest_spread.rs | 3 +-- .../tests/es2022_class_properties.rs | 3 +-- crates/swc_ecma_transforms_proposal/tests/export.rs | 2 +- crates/swc_ecma_transforms_react/src/jsx/tests.rs | 2 +- .../src/pure_annotations/tests.rs | 6 +++--- crates/swc_ecma_transforms_react/src/refresh/tests.rs | 2 +- 8 files changed, 14 insertions(+), 16 deletions(-) diff --git a/crates/swc_ecma_compat_es3/src/member_expr_lits.rs b/crates/swc_ecma_compat_es3/src/member_expr_lits.rs index 3ebf21b1b52e..b29b0bde5de2 100644 --- a/crates/swc_ecma_compat_es3/src/member_expr_lits.rs +++ b/crates/swc_ecma_compat_es3/src/member_expr_lits.rs @@ -31,7 +31,7 @@ impl Fold for MemberExprLit { standard_only_fold!(); fn fold_member_expr(&mut self, e: MemberExpr) -> MemberExpr { - let e = e.fold_children_with(self); + let e: MemberExpr = e.fold_children_with(self); if let MemberProp::Ident(i) = e.prop { if i.sym.is_reserved() || i.sym.is_reserved_in_strict_mode(true) @@ -71,7 +71,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_| MemberExprLit, + |_| fold_pass(MemberExprLit), basic, r#"obj["foo"] = "isValid"; @@ -82,14 +82,14 @@ obj["var"] = "isKeyword";"#, test!( ::swc_ecma_parser::Syntax::default(), - |_| MemberExprLit, + |_| fold_pass(MemberExprLit), issue_206, "const number = foo[bar1][baz1]" ); test!( ::swc_ecma_parser::Syntax::default(), - |_| MemberExprLit, + |_| fold_pass(MemberExprLit), issue_211, "_query[idx]=$this.attr('data-ref');" ); diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs index d90ac877fe0e..59b534011004 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs @@ -2,7 +2,7 @@ use std::{fs::read_to_string, path::PathBuf}; use serde::Deserialize; use swc_common::Mark; -use swc_ecma_ast::chain; +use swc_ecma_ast::{chain, Pass}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ es2015::{arrow, classes, new_target::new_target}, @@ -15,7 +15,7 @@ fn get_passes(_: &Tester, plugins: &[PluginConfig]) -> Box { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - let mut pass: Box = Box::new(resolver(unresolved_mark, top_level_mark, true)); + let mut pass: Box = Box::new(resolver(unresolved_mark, top_level_mark, true)); for plugin in plugins { let (name, option) = match plugin { diff --git a/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs b/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs index a3b3aeb5bf32..3473c26c6836 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use swc_common::Mark; -use swc_ecma_ast::chain; +use swc_ecma_ast::{chain, Pass}; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -9,7 +9,6 @@ use swc_ecma_transforms_compat::{ es2018::{object_rest_spread, object_rest_spread::Config}, }; use swc_ecma_transforms_testing::{compare_stdout, test, test_exec, test_fixture}; -use swc_ecma_visit::Fold; fn syntax() -> Syntax { Syntax::default() diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs b/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs index ccdffb0dc90a..cccaec9ea3ec 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs @@ -3,7 +3,7 @@ use std::{fs::read_to_string, path::PathBuf}; use swc_common::Mark; -use swc_ecma_ast::chain; +use swc_ecma_ast::{chain, Pass}; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -15,7 +15,6 @@ use swc_ecma_transforms_compat::{ es3::reserved_words, }; use swc_ecma_transforms_testing::{compare_stdout, test, test_exec, test_fixture, Tester}; -use swc_ecma_visit::Fold; fn syntax() -> Syntax { Syntax::Es(Default::default()) diff --git a/crates/swc_ecma_transforms_proposal/tests/export.rs b/crates/swc_ecma_transforms_proposal/tests/export.rs index 857ee1b04a8a..d2d31cf6a89e 100644 --- a/crates/swc_ecma_transforms_proposal/tests/export.rs +++ b/crates/swc_ecma_transforms_proposal/tests/export.rs @@ -1,4 +1,4 @@ -use swc_common::chain; +use swc_ecma_ast::chain; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_compat::es2020::export_namespace_from; use swc_ecma_transforms_proposal::export_default_from; diff --git a/crates/swc_ecma_transforms_react/src/jsx/tests.rs b/crates/swc_ecma_transforms_react/src/jsx/tests.rs index 424c57b1749a..7508f6269d02 100644 --- a/crates/swc_ecma_transforms_react/src/jsx/tests.rs +++ b/crates/swc_ecma_transforms_react/src/jsx/tests.rs @@ -5,7 +5,7 @@ use std::{ path::{Path, PathBuf}, }; -use swc_common::chain; +use swc_ecma_ast::chain; use swc_ecma_codegen::{Config, Emitter}; use swc_ecma_parser::{EsSyntax, Parser, StringInput}; use swc_ecma_transforms_base::{fixer::fixer, hygiene, resolver}; diff --git a/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs b/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs index ed6162833fc7..a169547d2fd8 100644 --- a/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs +++ b/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs @@ -11,7 +11,7 @@ use super::*; fn parse( tester: &mut Tester, src: &str, -) -> Result<(Module, Lrc, Lrc), ()> { +) -> Result<(Program, Lrc, Lrc), ()> { let syntax = ::swc_ecma_parser::Syntax::Es(::swc_ecma_parser::EsSyntax { jsx: true, ..Default::default() @@ -69,8 +69,8 @@ fn run_test(input: &str, expected: &str) { let (actual, actual_sm, actual_comments) = parse(tester, input)?; let actual = actual - .fold_with(&mut resolver(unresolved_mark, top_level_mark, false)) - .fold_with(&mut crate::react( + .apply(&mut resolver(unresolved_mark, top_level_mark, false)) + .apply(&mut crate::react( actual_sm.clone(), Some(&actual_comments), Default::default(), diff --git a/crates/swc_ecma_transforms_react/src/refresh/tests.rs b/crates/swc_ecma_transforms_react/src/refresh/tests.rs index ab2d9f1f8374..c72c84c9a9dc 100644 --- a/crates/swc_ecma_transforms_react/src/refresh/tests.rs +++ b/crates/swc_ecma_transforms_react/src/refresh/tests.rs @@ -1,4 +1,4 @@ -use swc_common::chain; +use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::{test, Tester}; From 2aab07fc21f0483c9c4ca656136a4142b7ad72c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 17:14:19 +0900 Subject: [PATCH 131/186] more --- crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs | 3 +-- .../swc_ecma_transforms_compat/tests/es2015_computed_props.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index ca0236cabdba..1aa19869bc5d 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -1,11 +1,10 @@ use std::path::PathBuf; use swc_common::Mark; -use swc_ecma_ast::chain; +use swc_ecma_ast::{chain, Pass}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2015::arrow; use swc_ecma_transforms_testing::{compare_stdout, test_fixture}; -use swc_ecma_visit::Fold; fn tr() -> impl Pass { let unresolved = Mark::new(); diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_computed_props.rs b/crates/swc_ecma_transforms_compat/tests/es2015_computed_props.rs index dffbe6fc20dc..4ba28624ea95 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_computed_props.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_computed_props.rs @@ -1,9 +1,9 @@ #![allow(clippy::unit_arg)] +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_compat::es2015::computed_props::{computed_properties, Config}; use swc_ecma_transforms_testing::{test, test_exec}; -use swc_ecma_visit::Fold; fn syntax() -> Syntax { ::swc_ecma_parser::Syntax::default() From 37b1580dd85e6fe52df37482877f891862415eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 17:18:58 +0900 Subject: [PATCH 132/186] more fix --- .../tests/es2015_destructuring.rs | 3 +- .../tests/es2015_new_target.rs | 2 +- .../tests/es2015_parameters.rs | 3 +- .../tests/es2020_optional_chaining.rs | 3 +- .../tests/es2022_private_in_object.rs | 4 +- crates/swc_visit/src/lib.rs | 361 ++++++++++++++++++ 6 files changed, 367 insertions(+), 9 deletions(-) diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs b/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs index 00f69b29e74e..574934ddd5ff 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use swc_common::Mark; -use swc_ecma_ast::chain; +use swc_ecma_ast::{chain, Pass}; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -14,7 +14,6 @@ use swc_ecma_transforms_compat::{ es2018::object_rest_spread, }; use swc_ecma_transforms_testing::{test, test_exec, test_fixture}; -use swc_ecma_visit::Fold; fn syntax() -> Syntax { Default::default() diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs index 59b534011004..d6ecd5b2bc8b 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs @@ -11,7 +11,7 @@ use swc_ecma_transforms_compat::{ use swc_ecma_transforms_testing::{exec_tr, parse_options, test, test_fixture, Tester}; use swc_ecma_visit::Fold; -fn get_passes(_: &Tester, plugins: &[PluginConfig]) -> Box { +fn get_passes(_: &Tester, plugins: &[PluginConfig]) -> Box { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs b/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs index 047d8e4b4415..e0575659ff5c 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use swc_common::Mark; -use swc_ecma_ast::chain; +use swc_ecma_ast::{chain, Pass}; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -11,7 +11,6 @@ use swc_ecma_transforms_compat::{ es2017::async_to_generator, }; use swc_ecma_transforms_testing::{test, test_exec, test_fixture}; -use swc_ecma_visit::Fold; fn syntax() -> Syntax { Default::default() diff --git a/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs b/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs index 968145eb0c58..f764b17429aa 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs @@ -1,7 +1,7 @@ use std::{fs::read_to_string, path::PathBuf}; use swc_common::Mark; -use swc_ecma_ast::chain; +use swc_ecma_ast::{chain, Pass}; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -9,7 +9,6 @@ use swc_ecma_transforms_compat::{ es2022::class_properties, }; use swc_ecma_transforms_testing::{compare_stdout, test, test_exec, test_fixture}; -use swc_ecma_visit::Fold; fn tr(c: Config) -> impl Pass { let unresolved_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs b/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs index fc2011e05d8c..779c31bf7b60 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use serde::Deserialize; use swc_common::Mark; -use swc_ecma_ast::chain; +use swc_ecma_ast::{chain, Pass}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ es2015::classes, @@ -37,7 +37,7 @@ fn fixture(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - let mut pass: Box = + let mut pass: Box = Box::new(resolver(unresolved_mark, top_level_mark, false)); let mut class_props = false; diff --git a/crates/swc_visit/src/lib.rs b/crates/swc_visit/src/lib.rs index f12738a5c988..ee83e8cf2c41 100644 --- a/crates/swc_visit/src/lib.rs +++ b/crates/swc_visit/src/lib.rs @@ -129,6 +129,367 @@ pub trait Repeated { fn reset(&mut self); } +macro_rules! impl_repeated_for_tuple { + ( + [$idx:tt, $name:ident], $([$idx_rest:tt, $name_rest:ident]),* + ) => { + impl<$name, $($name_rest),*> Repeated for ($name, $($name_rest),*) + where + $name: Repeated, + $($name_rest: Repeated),* + { + fn changed(&self) -> bool { + self.$idx.changed() || $(self.$idx_rest.changed() ||)* false + } + + fn reset(&mut self) { + self.$idx.reset(); + $(self.$idx_rest.reset();)* + } + } + }; +} + +impl_repeated_for_tuple!([0, A], [1, B]); +impl_repeated_for_tuple!([0, A], [1, B], [2, C]); +impl_repeated_for_tuple!([0, A], [1, B], [2, C], [3, D]); +impl_repeated_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E]); +impl_repeated_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E], [5, F]); +impl_repeated_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E], [5, F], [6, G]); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R], + [18, S] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R], + [18, S], + [19, T] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R], + [18, S], + [19, T], + [20, U] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R], + [18, S], + [19, T], + [20, U], + [21, V] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R], + [18, S], + [19, T], + [20, U], + [21, V], + [22, W] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R], + [18, S], + [19, T], + [20, U], + [21, V], + [22, W], + [23, X] +); +impl_repeated_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M], + [13, N], + [14, O], + [15, P], + [16, Q], + [17, R], + [18, S], + [19, T], + [20, U], + [21, V], + [22, W], + [23, X], + [24, Y] +); + /// A visitor which applies `V` again and again if `V` modifies the node. /// /// # Note From 6cd729b772edea071561ea21c217154f2898f2e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 17:20:57 +0900 Subject: [PATCH 133/186] Remove chain! --- crates/swc/src/builder.rs | 68 ++-- crates/swc/src/config/mod.rs | 24 +- crates/swc/src/lib.rs | 2 +- crates/swc/tests/projects.rs | 2 +- .../src/async_arrows_in_class.rs | 4 +- .../src/edge_default_param.rs | 4 +- crates/swc_ecma_compat_bugfixes/src/lib.rs | 4 +- ...turing_collision_in_function_expression.rs | 6 +- .../src/template_literal_caching.rs | 4 +- .../src/block_scoping/mod.rs | 4 +- crates/swc_ecma_compat_es2015/src/lib.rs | 8 +- .../src/object_super.rs | 10 +- crates/swc_ecma_compat_es2018/src/lib.rs | 4 +- .../src/object_rest_spread.rs | 4 +- .../src/optional_catch_binding.rs | 4 +- crates/swc_ecma_compat_es2020/src/lib.rs | 2 +- crates/swc_ecma_compat_es2022/src/lib.rs | 2 +- crates/swc_ecma_compat_es3/src/lib.rs | 4 +- crates/swc_ecma_minifier/src/compress/mod.rs | 8 +- crates/swc_ecma_preset_env/src/lib.rs | 20 +- crates/swc_ecma_preset_env/tests/test.rs | 4 +- .../swc_ecma_transforms/tests/decorators.rs | 94 ++--- crates/swc_ecma_transforms/tests/deno.rs | 4 +- .../tests/es2015_function_name.rs | 42 +- .../swc_ecma_transforms_base/benches/base.rs | 2 +- .../src/hygiene/mod.rs | 4 +- .../swc_ecma_transforms_base/tests/fixture.rs | 8 +- .../tests/es2015_arrow.rs | 6 +- .../tests/es2015_block_scoping.rs | 48 +-- .../tests/es2015_classes.rs | 44 +-- .../tests/es2015_destructuring.rs | 70 ++-- .../tests/es2015_for_of.rs | 12 +- .../tests/es2015_generator.rs | 26 +- .../tests/es2015_new_target.rs | 10 +- .../tests/es2015_object_super.rs | 2 +- .../tests/es2015_parameters.rs | 42 +- .../tests/es2015_shorthand_propertie.rs | 2 +- .../tests/es2015_spread.rs | 8 +- .../tests/es2017_async_to_generator.rs | 68 ++-- .../tests/es2018_object_rest_spread.rs | 10 +- .../tests/es2020_optional_chaining.rs | 20 +- .../tests/es2022_class_properties.rs | 370 +++++++++--------- .../tests/es2022_private_in_object.rs | 12 +- .../tests/es2022_static_blocks.rs | 8 +- .../swc_ecma_transforms_module/tests/amd.rs | 6 +- .../tests/common_js.rs | 4 +- .../tests/system_js.rs | 4 +- .../swc_ecma_transforms_module/tests/umd.rs | 2 +- .../src/simplify/branch/tests.rs | 4 +- .../src/simplify/expr/tests.rs | 4 +- .../src/simplify/mod.rs | 4 +- .../tests/fixture.rs | 12 +- .../tests/remove_imports_with_side_effects.rs | 2 +- .../tests/simplify.rs | 34 +- .../tests/simplify_dce.rs | 28 +- .../tests/simplify_inlining.rs | 28 +- .../tests/decorators.rs | 2 +- .../tests/explicit_resource_management.rs | 8 +- .../tests/export.rs | 2 +- .../src/jsx/tests.rs | 30 +- crates/swc_ecma_transforms_react/src/lib.rs | 6 +- .../src/refresh/tests.rs | 18 +- .../src/babel_like.rs | 4 +- crates/swc_ecma_transforms_testing/src/lib.rs | 6 +- .../benches/compat.rs | 6 +- .../tests/strip.rs | 48 +-- 66 files changed, 683 insertions(+), 683 deletions(-) diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index f0ce4cb128e8..d239812c2682 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -80,7 +80,7 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { where N: swc_ecma_visit::Fold, { - let pass = chain!(self.pass, next); + let pass = (self.pass, next); PassBuilder { cm: self.cm, handler: self.handler, @@ -206,7 +206,7 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { feature_flag = enable_available_feature_from_es_version(self.target); - Either::Right(chain!( + Either::Right(( Optional::new( compat::class_fields_use_set::class_fields_use_set(assumptions.pure_getters), assumptions.set_public_class_fields, @@ -221,60 +221,60 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { no_document_all: assumptions.no_document_all, static_blocks_mark: Mark::new(), pure_getter: assumptions.pure_getters, - } + }, }, - self.unresolved_mark + self.unresolved_mark, ), - should_enable(self.target, EsVersion::Es2022) + should_enable(self.target, EsVersion::Es2022), ), Optional::new( compat::es2021::es2021(), - should_enable(self.target, EsVersion::Es2021) + should_enable(self.target, EsVersion::Es2021), ), Optional::new( compat::es2020::es2020( compat::es2020::Config { nullish_coalescing: compat::es2020::nullish_coalescing::Config { - no_document_all: assumptions.no_document_all + no_document_all: assumptions.no_document_all, }, optional_chaining: compat::es2020::optional_chaining::Config { no_document_all: assumptions.no_document_all, - pure_getter: assumptions.pure_getters - } + pure_getter: assumptions.pure_getters, + }, }, - self.unresolved_mark + self.unresolved_mark, ), - should_enable(self.target, EsVersion::Es2020) + should_enable(self.target, EsVersion::Es2020), ), Optional::new( compat::es2019::es2019(), - should_enable(self.target, EsVersion::Es2019) + should_enable(self.target, EsVersion::Es2019), ), Optional::new( compat::es2018(compat::es2018::Config { object_rest_spread: compat::es2018::object_rest_spread::Config { no_symbol: assumptions.object_rest_no_symbols, set_property: assumptions.set_spread_properties, - pure_getters: assumptions.pure_getters - } + pure_getters: assumptions.pure_getters, + }, }), - should_enable(self.target, EsVersion::Es2018) + should_enable(self.target, EsVersion::Es2018), ), Optional::new( compat::es2017( compat::es2017::Config { async_to_generator: compat::es2017::async_to_generator::Config { ignore_function_name: assumptions.ignore_function_name, - ignore_function_length: assumptions.ignore_function_length + ignore_function_length: assumptions.ignore_function_length, }, }, - self.unresolved_mark + self.unresolved_mark, ), - should_enable(self.target, EsVersion::Es2017) + should_enable(self.target, EsVersion::Es2017), ), Optional::new( compat::es2016(), - should_enable(self.target, EsVersion::Es2016) + should_enable(self.target, EsVersion::Es2016), ), Optional::new( compat::es2015( @@ -286,36 +286,36 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { no_class_calls: assumptions.no_class_calls, set_class_methods: assumptions.set_class_methods, super_is_callable_constructor: assumptions - .super_is_callable_constructor + .super_is_callable_constructor, }, computed_props: compat::es2015::computed_props::Config { - loose: self.loose + loose: self.loose, }, for_of: compat::es2015::for_of::Config { assume_array: false, - loose: self.loose + loose: self.loose, }, spread: compat::es2015::spread::Config { loose: self.loose }, destructuring: compat::es2015::destructuring::Config { - loose: self.loose + loose: self.loose, }, regenerator: self.regenerator, template_literal: compat::es2015::template_literal::Config { ignore_to_primitive: assumptions.ignore_to_primitive_hint, - mutable_template: assumptions.mutable_template_object + mutable_template: assumptions.mutable_template_object, }, parameters: compat::es2015::parameters::Config { ignore_function_length: assumptions.ignore_function_length, }, - typescript: syntax.typescript() - } + typescript: syntax.typescript(), + }, ), - should_enable(self.target, EsVersion::Es2015) + should_enable(self.target, EsVersion::Es2015), ), Optional::new( compat::es3(true), - cfg!(feature = "es3") && self.target == EsVersion::Es3 - ) + cfg!(feature = "es3") && self.target == EsVersion::Es3, + ), )) }; @@ -325,21 +325,21 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { .map(|v| v.mangle.is_obj() || v.mangle.is_true()) .unwrap_or(false); - chain!( + ( self.pass, Optional::new( paren_remover(comments.map(|v| v as &dyn Comments)), - self.fixer + self.fixer, ), compat_pass, // module / helper Optional::new( modules::import_analysis::import_analyzer(import_interop, ignore_dynamic), - need_analyzer + need_analyzer, ), Optional::new( helpers::inject_helpers(self.unresolved_mark), - self.inject_helpers + self.inject_helpers, ), ModuleConfig::build( self.cm.clone(), @@ -360,7 +360,7 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { top_level_mark: self.top_level_mark, ..self.hygiene.clone().unwrap_or_default() }), - self.hygiene.is_some() && !is_mangler_enabled + self.hygiene.is_some() && !is_mangler_enabled, ), Optional::new(fixer(comments.map(|v| v as &dyn Comments)), self.fixer), ) diff --git a/crates/swc/src/config/mod.rs b/crates/swc/src/config/mod.rs index 3d9854a5550c..a2b34250fd7b 100644 --- a/crates/swc/src/config/mod.rs +++ b/crates/swc/src/config/mod.rs @@ -508,12 +508,12 @@ impl Options { let unresolved_ctxt = SyntaxContext::empty().apply_mark(unresolved_mark); let top_level_ctxt = SyntaxContext::empty().apply_mark(top_level_mark); - let pass = chain!( + let pass = ( const_modules, optimization, Optional::new(export_default_from(), syntax.export_default_from()), simplifier_pass, - json_parse_pass + json_parse_pass, ); let import_export_assign_config = match cfg.module { @@ -699,7 +699,7 @@ impl Options { DecoratorVersion::V202311 => todo!("2023-11 decorator"), }; - Box::new(chain!( + Box::new(( if experimental.run_plugin_first.into_bool() { option_pass(plugin_transforms.take()) } else { @@ -714,13 +714,13 @@ impl Options { es_version, source_map: cm.clone(), })), - !disable_all_lints + !disable_all_lints, ), // Decorators may use type information Optional::new(decorator_pass, syntax.decorators()), Optional::new( explicit_resource_management(), - syntax.explicit_resource_management() + syntax.explicit_resource_management(), ), // The transform strips import assertions, so it's only enabled if // keep_import_assertions is false. @@ -739,21 +739,21 @@ impl Options { .react .pragma .clone() - .unwrap_or_else(default_pragma) + .unwrap_or_else(default_pragma), ), pragma_frag: Some( transform .react .pragma_frag .clone() - .unwrap_or_else(default_pragma_frag) + .unwrap_or_else(default_pragma_frag), ), }, comments.map(|v| v as _), unresolved_mark, - top_level_mark + top_level_mark, ), - syntax.typescript() + syntax.typescript(), ), option_pass(plugin_transforms.take()), custom_before_pass(&program), @@ -764,15 +764,15 @@ impl Options { comments.map(|v| v as _), transform.react, top_level_mark, - unresolved_mark + unresolved_mark, ), - syntax.jsx() + syntax.jsx(), ), pass, Optional::new(jest::jest(), transform.hidden.jest.into_bool()), Optional::new( dropped_comments_preserver(comments.cloned()), - preserve_all_comments + preserve_all_comments, ), )) }; diff --git a/crates/swc/src/lib.rs b/crates/swc/src/lib.rs index ee1a6b3a099f..ac0a6b153d42 100644 --- a/crates/swc/src/lib.rs +++ b/crates/swc/src/lib.rs @@ -708,7 +708,7 @@ impl Compiler { let after_pass = custom_after_pass(&config.program); - let config = config.with_pass(|pass| chain!(pass, after_pass)); + let config = config.with_pass(|pass| (pass, after_pass)); let orig = if config.source_maps.enabled() { self.get_orig_src_map( diff --git a/crates/swc/tests/projects.rs b/crates/swc/tests/projects.rs index eda7252199ac..8252a1077494 100644 --- a/crates/swc/tests/projects.rs +++ b/crates/swc/tests/projects.rs @@ -739,7 +739,7 @@ fn should_visit() { dbg!(config.syntax); - let config = config.with_pass(|pass| chain!(Panicking, pass)); + let config = config.with_pass(|pass| (Panicking, pass)); if config.minify { let preserve_excl = |_: &BytePos, vc: &mut Vec| -> bool { diff --git a/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs b/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs index 3a10ed1ef0b7..9fe28a234c7c 100644 --- a/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs +++ b/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs @@ -114,9 +114,9 @@ mod tests { fn tr() -> impl Pass { let unresolved = Mark::new(); - chain!( + ( resolver(unresolved, Mark::new(), false), - async_arrows_in_class(unresolved) + async_arrows_in_class(unresolved), ) } diff --git a/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs b/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs index 3cc9d8ab7985..5e88b0868afd 100644 --- a/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs +++ b/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs @@ -70,9 +70,9 @@ mod tests { use super::*; fn tr() -> impl Pass { - chain!( + ( resolver(Mark::new(), Mark::new(), false), - edge_default_param() + edge_default_param(), ) } diff --git a/crates/swc_ecma_compat_bugfixes/src/lib.rs b/crates/swc_ecma_compat_bugfixes/src/lib.rs index a21e3aeac474..429e2591cbd1 100644 --- a/crates/swc_ecma_compat_bugfixes/src/lib.rs +++ b/crates/swc_ecma_compat_bugfixes/src/lib.rs @@ -13,10 +13,10 @@ mod safari_id_destructuring_collision_in_function_expression; mod template_literal_caching; pub fn bugfixes(unresolved_mark: Mark) -> impl Pass { - chain!( + ( async_arrows_in_class(unresolved_mark), edge_default_param(), template_literal_caching(), - safari_id_destructuring_collision_in_function_expression() + safari_id_destructuring_collision_in_function_expression(), ) } diff --git a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs index 9ef2b315d6ad..66e911458899 100644 --- a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs +++ b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs @@ -112,9 +112,9 @@ mod tests { use super::*; fn tr() -> impl Pass { - chain!( + ( resolver(Mark::new(), Mark::new(), false), - safari_id_destructuring_collision_in_function_expression() + safari_id_destructuring_collision_in_function_expression(), ) } @@ -167,7 +167,7 @@ mod tests { test!( Syntax::default(), - |_| chain!(tr(), HygieneTester), + |_| (tr(), HygieneTester), issue_4488_1, " export default function _type_of() { diff --git a/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs b/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs index 578ad75ba078..448ac354e200 100644 --- a/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs +++ b/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs @@ -169,9 +169,9 @@ mod tests { use super::*; fn tr() -> impl Pass { - chain!( + ( resolver(Mark::new(), Mark::new(), false), - template_literal_caching() + template_literal_caching(), ) } diff --git a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs index 51915131edda..40c0f05b82cb 100644 --- a/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs +++ b/crates/swc_ecma_compat_es2015/src/block_scoping/mod.rs @@ -35,14 +35,14 @@ mod vars; /// } /// ``` pub fn block_scoping(unresolved_mark: Mark) -> impl Pass { - chain!( + ( visit_mut_pass(self::vars::block_scoped_vars()), visit_mut_pass(BlockScoping { unresolved_mark, scope: Default::default(), vars: Vec::new(), var_decl_kind: VarDeclKind::Var, - }) + }), ) } diff --git a/crates/swc_ecma_compat_es2015/src/lib.rs b/crates/swc_ecma_compat_es2015/src/lib.rs index f44e7d087295..d3604ce52bae 100644 --- a/crates/swc_ecma_compat_es2015/src/lib.rs +++ b/crates/swc_ecma_compat_es2015/src/lib.rs @@ -37,7 +37,7 @@ pub mod template_literal; mod typeof_symbol; fn exprs(unresolved_mark: Mark) -> impl Pass { - chain!( + ( arrow(unresolved_mark), duplicate_keys(), sticky_regex(), @@ -59,7 +59,7 @@ pub fn es2015(unresolved_mark: Mark, comments: Option, c: Config) -> impl where C: Comments + Clone, { - chain!( + ( regexp(regexp::Config { dot_all_regex: false, has_indices: false, @@ -178,7 +178,7 @@ class HomePage extends React.Component {} test!( ::swc_ecma_parser::Syntax::default(), - |_| chain!( + |_| ( block_scoped_functions(), resolver(Mark::new(), Mark::new(), false) ), @@ -196,7 +196,7 @@ function foo(scope) { // test!( // ::swc_ecma_parser::Syntax::default(), - // |_| chain!( + // |_| ( // resolver(), // class_properties(), // // Optional::new(compat::es2018(), target <= EsVersion::Es2018), diff --git a/crates/swc_ecma_compat_es2015/src/object_super.rs b/crates/swc_ecma_compat_es2015/src/object_super.rs index 4082156d361c..a5fbb5ed7e4f 100644 --- a/crates/swc_ecma_compat_es2015/src/object_super.rs +++ b/crates/swc_ecma_compat_es2015/src/object_super.rs @@ -497,7 +497,7 @@ mod tests { |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), object_super(), shorthand(), @@ -514,7 +514,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), |_| { - chain!( + ( resolver(Mark::new(), Mark::new(), false), object_super(), shorthand(), @@ -531,7 +531,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), |_| { - chain!( + ( resolver(Mark::new(), Mark::new(), false), object_super(), shorthand(), @@ -548,7 +548,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), |_| { - chain!( + ( resolver(Mark::new(), Mark::new(), false), object_super(), shorthand(), @@ -573,7 +573,7 @@ mod tests { ..Default::default() }), |_| { - chain!( + ( resolver(Mark::new(), Mark::new(), false), object_super(), shorthand(), diff --git a/crates/swc_ecma_compat_es2018/src/lib.rs b/crates/swc_ecma_compat_es2018/src/lib.rs index d10171d82f00..b1514830d189 100644 --- a/crates/swc_ecma_compat_es2018/src/lib.rs +++ b/crates/swc_ecma_compat_es2018/src/lib.rs @@ -12,7 +12,7 @@ pub mod object_rest_spread; mod object_spread; pub fn es2018(c: Config) -> impl Pass { - chain!( + ( regexp(regexp::Config { dot_all_regex: true, has_indices: false, @@ -23,7 +23,7 @@ pub fn es2018(c: Config) -> impl Pass { unicode_regex: false, unicode_sets_regex: false, }), - object_rest_spread(c.object_rest_spread) + object_rest_spread(c.object_rest_spread), ) } diff --git a/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs b/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs index a70937f6cb1a..196999b91e40 100644 --- a/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs +++ b/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs @@ -9,12 +9,12 @@ use crate::{object_rest::ObjectRest, object_spread::ObjectSpread}; /// `@babel/plugin-proposal-object-rest-spread` pub fn object_rest_spread(config: Config) -> impl Pass { - chain!( + ( visit_mut_pass(ObjectRest { config, ..Default::default() }), - visit_mut_pass(ObjectSpread { config }) + visit_mut_pass(ObjectSpread { config }), ) } diff --git a/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs b/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs index 4969ec520262..84ebad25cb12 100644 --- a/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs +++ b/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs @@ -34,9 +34,9 @@ mod tests { use crate::optional_catch_binding::OptionalCatchBinding; pub fn tr() -> impl Pass { - chain!( + ( resolver(Mark::new(), Mark::new(), false), - visit_mut_pass(OptionalCatchBinding) + visit_mut_pass(OptionalCatchBinding), ) } diff --git a/crates/swc_ecma_compat_es2020/src/lib.rs b/crates/swc_ecma_compat_es2020/src/lib.rs index fa6cd8e10e12..e64c6f9dd2a1 100644 --- a/crates/swc_ecma_compat_es2020/src/lib.rs +++ b/crates/swc_ecma_compat_es2020/src/lib.rs @@ -12,7 +12,7 @@ pub mod nullish_coalescing; pub mod optional_chaining; pub fn es2020(config: Config, unresolved_mark: Mark) -> impl Pass { - chain!( + ( nullish_coalescing(config.nullish_coalescing), optional_chaining(config.optional_chaining, unresolved_mark), export_namespace_from(), diff --git a/crates/swc_ecma_compat_es2022/src/lib.rs b/crates/swc_ecma_compat_es2022/src/lib.rs index 776a237262a7..937cdc5111db 100644 --- a/crates/swc_ecma_compat_es2022/src/lib.rs +++ b/crates/swc_ecma_compat_es2022/src/lib.rs @@ -15,7 +15,7 @@ pub mod private_in_object; pub mod static_blocks; pub fn es2022(config: Config, unresolved_mark: Mark) -> impl Pass { - chain!( + ( regexp(regexp::Config { dot_all_regex: true, has_indices: true, diff --git a/crates/swc_ecma_compat_es3/src/lib.rs b/crates/swc_ecma_compat_es3/src/lib.rs index e284cf701d5b..861a5c5ce974 100644 --- a/crates/swc_ecma_compat_es3/src/lib.rs +++ b/crates/swc_ecma_compat_es3/src/lib.rs @@ -11,9 +11,9 @@ mod reserved_word; /// Make output es3-compatible. pub fn es3(preserve_import: bool) -> impl Pass { - chain!( + ( property_literals(), member_expression_literals(), - reserved_words(preserve_import) + reserved_words(preserve_import), ) } diff --git a/crates/swc_ecma_minifier/src/compress/mod.rs b/crates/swc_ecma_minifier/src/compress/mod.rs index cf271ee2f131..d606bf360775 100644 --- a/crates/swc_ecma_minifier/src/compress/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/mod.rs @@ -54,15 +54,15 @@ where mode, }; - chain!( + ( visit_mut_pass(compressor), Optional { enabled: options.evaluate || options.side_effects, visitor: visit_mut_pass(expr_simplifier( marks.unresolved_mark, - ExprSimplifierConfig {} - )) - } + ExprSimplifierConfig {}, + )), + }, ) } diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index 13b79ac99088..76d8101b2a51 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -82,16 +82,16 @@ where if c.debug { println!("{}: {:?}", f.as_str(), enable); } - chain!($prev, Optional::new($pass, enable)) + ($prev, Optional::new($pass, enable)) }}; } - let pass = chain!( + let pass = ( pass, Optional::new( class_fields_use_set(assumptions.pure_getters), - assumptions.set_public_class_fields - ) + assumptions.set_public_class_fields, + ), ); let pass = { @@ -108,7 +108,7 @@ where || enable_unicode_property_regex || enable_unicode_regex; - chain!( + ( pass, Optional::new( regexp(regexp::Config { @@ -123,8 +123,8 @@ where unicode_regex: enable_unicode_regex, unicode_sets_regex: enable_unicode_sets_regex, }), - enable - ) + enable, + ), ) }; @@ -338,7 +338,7 @@ where println!("Targets: {:?}", targets); } - chain!( + ( pass, visit_mut_pass(Polyfills { mode: c.mode, @@ -346,14 +346,14 @@ where corejs: c.core_js.unwrap_or(Version { major: 3, minor: 0, - patch: 0 + patch: 0, }), shipped_proposals: c.shipped_proposals, targets, includes: included_modules, excludes: excluded_modules, unresolved_mark, - }) + }), ) } diff --git a/crates/swc_ecma_preset_env/tests/test.rs b/crates/swc_ecma_preset_env/tests/test.rs index 9ab9e0371a21..93b20032785e 100644 --- a/crates/swc_ecma_preset_env/tests/test.rs +++ b/crates/swc_ecma_preset_env/tests/test.rs @@ -121,7 +121,7 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { Tester::new() .print_errors(|cm, handler| { - let mut pass = chain!( + let mut pass = ( preset_env( Mark::fresh(Mark::root()), Some(SingleThreadedComments::default()), @@ -152,7 +152,7 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { Default::default(), &mut Default::default(), ), - fixer(None) + fixer(None), ); let print = |m: &Module| { diff --git a/crates/swc_ecma_transforms/tests/decorators.rs b/crates/swc_ecma_transforms/tests/decorators.rs index c1f7648b6431..4a8d8e64af5c 100644 --- a/crates/swc_ecma_transforms/tests/decorators.rs +++ b/crates/swc_ecma_transforms/tests/decorators.rs @@ -41,7 +41,7 @@ fn tr(_: &Tester) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(Default::default()), class_fields_use_set(true), @@ -63,7 +63,7 @@ fn simple_strip(_: &Tester, config: Config) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( decorators(config), resolver(unresolved_mark, top_level_mark, false), typescript( @@ -72,7 +72,7 @@ fn simple_strip(_: &Tester, config: Config) -> impl Pass { ..Default::default() }, unresolved_mark, - top_level_mark + top_level_mark, ), class_fields_use_set(true), class_properties( @@ -80,8 +80,8 @@ fn simple_strip(_: &Tester, config: Config) -> impl Pass { set_public_fields: true, ..Default::default() }, - unresolved_mark - ) + unresolved_mark, + ), ) } @@ -1636,7 +1636,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -1671,7 +1671,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -1705,7 +1705,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -1826,7 +1826,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -1859,7 +1859,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -1912,7 +1912,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -2051,7 +2051,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -2084,7 +2084,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -2207,7 +2207,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -2241,7 +2241,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -2360,7 +2360,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -2392,7 +2392,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -2533,7 +2533,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -2583,7 +2583,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -2618,7 +2618,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -2744,7 +2744,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -2780,7 +2780,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -2833,7 +2833,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -2968,7 +2968,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -3106,7 +3106,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -3243,7 +3243,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -3278,7 +3278,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, @@ -3327,7 +3327,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -3543,14 +3543,14 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), decorators(decorators::Config { legacy: true, ..Default::default() }), class_properties(Default::default(), unresolved_mark), - classes(Default::default()) + classes(Default::default()), ) }, decorators_legacy_interop_local_define_property, @@ -3580,7 +3580,7 @@ fn issue_395_syntax() -> ::swc_ecma_parser::Syntax { test!( issue_395_syntax(), - |_| chain!( + |_| ( decorators(Default::default()), common_js( Default::default(), @@ -3609,7 +3609,7 @@ class Demo { test!( issue_395_syntax(), - |_| chain!( + |_| ( decorators(Default::default()), common_js::common_js( Default::default(), @@ -3643,7 +3643,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -3681,7 +3681,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -3725,14 +3725,14 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), function_name(), classes(Default::default()), decorators(decorators::Config { legacy: true, ..Default::default() - }) + }), ) }, function_name_object, @@ -3765,14 +3765,14 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), function_name(), classes(Default::default()), decorators(decorators::Config { legacy: true, ..Default::default() - }) + }), ) }, function_name_export, @@ -3809,7 +3809,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -3837,7 +3837,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -3875,14 +3875,14 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), function_name(), classes(Default::default()), decorators(decorators::Config { legacy: true, ..Default::default() - }) + }), ) }, function_name_eval, @@ -3954,7 +3954,7 @@ fn fixture_exec(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(Config { legacy: true, @@ -3979,13 +3979,13 @@ fn legacy_only(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(Config { legacy: true, emit_metadata: false, use_define_for_class_fields: false, - }) + }), ) }, &input, @@ -4004,13 +4004,13 @@ fn legacy_metadata(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(Config { legacy: true, emit_metadata: true, use_define_for_class_fields: false, - }) + }), ) }, &input, diff --git a/crates/swc_ecma_transforms/tests/deno.rs b/crates/swc_ecma_transforms/tests/deno.rs index 21d385974b10..2cb30113e01a 100644 --- a/crates/swc_ecma_transforms/tests/deno.rs +++ b/crates/swc_ecma_transforms/tests/deno.rs @@ -29,7 +29,7 @@ fn run_test(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorator_2022_03(), explicit_resource_management(), @@ -45,7 +45,7 @@ fn run_test(input: PathBuf) { ts_enum_is_mutable: true, }, unresolved_mark, - top_level_mark + top_level_mark, ), fixer(None), hygiene(), diff --git a/crates/swc_ecma_transforms/tests/es2015_function_name.rs b/crates/swc_ecma_transforms/tests/es2015_function_name.rs index 6d29d6e4d997..be4e3331782f 100644 --- a/crates/swc_ecma_transforms/tests/es2015_function_name.rs +++ b/crates/swc_ecma_transforms/tests/es2015_function_name.rs @@ -26,10 +26,10 @@ fn tr() -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), function_name(), - block_scoping(unresolved_mark) + block_scoping(unresolved_mark), ) } @@ -199,7 +199,7 @@ export const y = function () {}; test!( ignore, syntax(), - |_| chain!(arrow(Mark::new()), function_name()), + |_| (arrow(Mark::new()), function_name()), function_name_with_arrow_functions_transform, r#" const x = () => x; @@ -216,7 +216,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), function_name(), classes(Default::default()), @@ -228,8 +228,8 @@ test!( Default::default(), unresolved_mark, Default::default(), - Default::default() - ) + Default::default(), + ), ) }, function_name_modules_3, @@ -252,7 +252,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -277,7 +277,7 @@ test!( syntax(), |_| { let unresolved_mark = Mark::new(); - chain!( + ( arrow(unresolved_mark), shorthand(), function_name(), @@ -286,7 +286,7 @@ test!( unresolved_mark, Default::default(), Default::default(), - ) + ), ) }, function_name_export_default_arrow_renaming, @@ -391,14 +391,14 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, ..Default::default() }), function_name(), - classes(Default::default()) + classes(Default::default()), ) }, function_name_self_reference, @@ -416,7 +416,7 @@ f = null; test!( ignore, syntax(), - |_| chain!(arrow(Mark::new()), function_name()), + |_| (arrow(Mark::new()), function_name()), function_name_with_arrow_functions_transform_spec, r#" // These are actually handled by transform-arrow-functions @@ -434,7 +434,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -455,7 +455,7 @@ test!( test!( ignore, syntax(), - |_| chain!(arrow(Mark::new()), shorthand(), function_name()), + |_| (arrow(Mark::new()), shorthand(), function_name()), function_name_export_default_arrow_renaming_module_es6, r#" export default (a) => { @@ -495,7 +495,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -533,7 +533,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -566,7 +566,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -612,7 +612,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -645,7 +645,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, @@ -658,7 +658,7 @@ test!( unresolved_mark, Default::default(), Default::default(), - ) + ), ) }, function_name_modules_2, @@ -685,7 +685,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), decorators(decorators::Config { legacy: true, diff --git a/crates/swc_ecma_transforms_base/benches/base.rs b/crates/swc_ecma_transforms_base/benches/base.rs index a1a7597d2879..2525492f53c4 100644 --- a/crates/swc_ecma_transforms_base/benches/base.rs +++ b/crates/swc_ecma_transforms_base/benches/base.rs @@ -52,7 +52,7 @@ fn hygiene(b: &mut Bencher) { } fn resolver_with_hygiene(b: &mut Bencher) { - tr!(b, || chain!( + tr!(b, || ( swc_ecma_transforms_base::resolver(Mark::new(), Mark::new(), false), swc_ecma_transforms_base::hygiene::hygiene() )); diff --git a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs index 8858596e31de..1f6769fd0be9 100644 --- a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs +++ b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs @@ -59,9 +59,9 @@ pub fn hygiene() -> impl Pass { /// /// At third phase, we rename all identifiers in the queue. pub fn hygiene_with_config(config: Config) -> impl 'static + Pass { - chain!( + ( renamer(config, HygieneRenamer), - visit_mut_pass(HygieneRemover) + visit_mut_pass(HygieneRemover), ) } diff --git a/crates/swc_ecma_transforms_base/tests/fixture.rs b/crates/swc_ecma_transforms_base/tests/fixture.rs index a7f1b2ce53de..a1272c88c98b 100644 --- a/crates/swc_ecma_transforms_base/tests/fixture.rs +++ b/crates/swc_ecma_transforms_base/tests/fixture.rs @@ -74,10 +74,10 @@ fn test_resolver(input: PathBuf) { || { let unresolved_mark = Mark::fresh(Mark::root()); - chain!( + ( resolver(unresolved_mark, Mark::new(), false), visit_mut_pass(TsHygiene { unresolved_mark }), - fixer(None) + fixer(None), ) }, ); @@ -94,10 +94,10 @@ fn test_ts_resolver(input: PathBuf) { || { let unresolved_mark = Mark::fresh(Mark::root()); - chain!( + ( resolver(unresolved_mark, Mark::new(), true), visit_mut_pass(TsHygiene { unresolved_mark }), - fixer(None) + fixer(None), ) }, ); diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index 1aa19869bc5d..7abec6854516 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -9,7 +9,7 @@ use swc_ecma_transforms_testing::{compare_stdout, test_fixture}; fn tr() -> impl Pass { let unresolved = Mark::new(); let global = Mark::new(); - chain!(resolver(unresolved, global, false), arrow(unresolved)) + (resolver(unresolved, global, false), arrow(unresolved)) } compare_stdout!( @@ -60,9 +60,9 @@ fn fixture(input: PathBuf) { Default::default(), &|_| { let unresolved_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, Mark::new(), false), - arrow(unresolved_mark) + arrow(unresolved_mark), ) }, &input, diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs b/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs index 52ec3c8c8959..950eb875b344 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs @@ -14,9 +14,9 @@ use swc_ecma_visit::{visit_mut_obj_and_computed, visit_mut_pass, Fold, VisitMut, fn tr() -> impl Pass { let unresolved_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, Mark::new(), false), - block_scoping(unresolved_mark) + block_scoping(unresolved_mark), ) } @@ -87,7 +87,7 @@ expect(functions[1]()).toBe(3); test_exec!( ::swc_ecma_parser::Syntax::default(), - |_| chain!(for_of(Default::default()), block_scoping(Mark::new())), + |_| (for_of(Default::default()), block_scoping(Mark::new())), issue_609_1, "let functions = []; for (let i of [1, 3, 5, 7, 9]) { @@ -221,9 +221,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - es2015::es2015(unresolved_mark, Some(comments.clone()), Default::default()) + es2015::es2015(unresolved_mark, Some(comments.clone()), Default::default()), ) }, issue_1022_1, @@ -240,9 +240,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - es2015::es2015(unresolved_mark, Some(comments.clone()), Default::default()) + es2015::es2015(unresolved_mark, Some(comments.clone()), Default::default()), ) }, issue_1022_2, @@ -260,9 +260,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - es2015::es2015(unresolved_mark, Some(comments.clone()), Default::default()) + es2015::es2015(unresolved_mark, Some(comments.clone()), Default::default()), ) }, issue_1022_3, @@ -310,9 +310,9 @@ test!( Syntax::default(), |Tester { comments, .. }| { let mark = Mark::fresh(Mark::root()); - chain!( + ( async_to_generator(Default::default(), mark), - es2015::es2015(mark, Some(comments.clone()), Default::default(),) + es2015::es2015(mark, Some(comments.clone()), Default::default()), ) }, issue_1036_2, @@ -329,9 +329,9 @@ test_exec!( Syntax::default(), |Tester { comments, .. }| { let mark = Mark::fresh(Mark::root()); - chain!( + ( async_to_generator(Default::default(), mark), - es2015::es2015(mark, Some(comments.clone()), Default::default(),) + es2015::es2015(mark, Some(comments.clone()), Default::default()), ) }, issue_1036_3, @@ -420,9 +420,9 @@ test!( ::swc_ecma_parser::Syntax::default(), |Tester { comments, .. }| { let mark = Mark::new(); - chain!( + ( resolver(mark, Mark::new(), false), - es2015::es2015(mark, Some(comments.clone()), Default::default(),) + es2015::es2015(mark, Some(comments.clone()), Default::default()), ) }, arguments_loop, @@ -457,9 +457,9 @@ compare_stdout!( ::swc_ecma_parser::Syntax::default(), |Tester { comments, .. }| { let mark = Mark::fresh(Mark::root()); - chain!( + ( resolver(mark, Mark::new(), false), - es2015::es2015(mark, Some(comments.clone()), Default::default(),) + es2015::es2015(mark, Some(comments.clone()), Default::default()), ) }, arguments_arrow, @@ -638,9 +638,9 @@ fn exec(input: PathBuf) { Default::default(), |_| { let unresolved_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, Mark::new(), false), - block_scoping(unresolved_mark) + block_scoping(unresolved_mark), ) }, &input, @@ -650,13 +650,13 @@ fn exec(input: PathBuf) { Default::default(), |t| { let unresolved_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, Mark::new(), false), es2015( unresolved_mark, Some(t.comments.clone()), - Default::default() - ) + Default::default(), + ), ) }, &input, @@ -671,10 +671,10 @@ fn fixture(input: PathBuf) { Default::default(), &|_| { let unresolved_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, Mark::new(), false), block_scoping(unresolved_mark), - visit_mut_pass(TsHygiene { unresolved_mark }) + visit_mut_pass(TsHygiene { unresolved_mark }), ) }, &input, diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs b/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs index c2cf57f39ac2..d19d862ab938 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs @@ -23,7 +23,7 @@ fn tr(_: &Tester) -> impl Pass { fn spec_tr(_: &Tester) -> impl Pass { let unresolved_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, Mark::new(), false), classes(Default::default()), spread(Default::default()), @@ -319,7 +319,7 @@ expect(constructor).toBe(CustomElement); // regression_5817 test!( syntax(), - |t| chain!(tr(t), arrow(Mark::new())), + |t| (tr(t), arrow(Mark::new())), regression_5817, r#" class A extends B { @@ -2603,7 +2603,7 @@ test!( test!( syntax(), - |_| chain!( + |_| ( resolver(Mark::new(), Mark::new(), false), classes(Default::default()) ), @@ -2726,7 +2726,7 @@ class List extends Array {} // extend_builtins_imported_babel_plugin_transform_builtin_classes test_exec!( syntax(), - |_| chain!(classes(Default::default()), block_scoping(Mark::new())), + |_| (classes(Default::default()), block_scoping(Mark::new())), extend_builtins_imported_babel_plugin_transform_builtin_classes_exec, r#" // Imported from @@ -3027,7 +3027,7 @@ expect(obj.test).toBe(3); // extend_builtins_spec test_exec!( syntax(), - |_| chain!(classes(Default::default()), block_scoping(Mark::new())), + |_| (classes(Default::default()), block_scoping(Mark::new())), extend_builtins_spec_exec, r#" class List extends Array {} @@ -3159,7 +3159,7 @@ test!( // TODO: Unignore this ignore, syntax(), - |t| chain!(tr(t), block_scoping(Mark::new())), + |t| (tr(t), block_scoping(Mark::new())), regression_t7010, r#" class Foo { @@ -3415,7 +3415,7 @@ expect(obj.test).toBe(3); // extend_builtins_builtin_objects_throw_when_wrapped test_exec!( syntax(), - |_| chain!(classes(Default::default()), block_scoping(Mark::new())), + |_| (classes(Default::default()), block_scoping(Mark::new())), extend_builtins_builtin_objects_throw_when_wrapped_exec, r#" // JSON is wrapped because it starts with an uppercase letter, but it @@ -3464,7 +3464,7 @@ test_exec!( // Just don't do this. ignore, syntax(), - |_| chain!(classes(Default::default()), block_scoping(Mark::new())), + |_| (classes(Default::default()), block_scoping(Mark::new())), extend_builtins_overwritten_null_exec, r#" var env = { @@ -3485,7 +3485,7 @@ test_exec!( // Just don't do this. With is evil. ignore, syntax(), - |_| chain!(classes(Default::default()), block_scoping(Mark::new())), + |_| (classes(Default::default()), block_scoping(Mark::new())), extend_builtins_super_called_exec, r#" var called = false; @@ -3676,7 +3676,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), es2022::es2022(Default::default(), unresolved_mark), es2018::es2018(Default::default()), @@ -3685,7 +3685,7 @@ test!( es2015::es2015( unresolved_mark, Some(t.comments.clone()), - Default::default() + Default::default(), ), ) }, @@ -3701,13 +3701,13 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), es2015::es2015( unresolved_mark, Some(t.comments.clone()), - Default::default() + Default::default(), ), ) }, @@ -3745,13 +3745,13 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), es2015::es2015( unresolved_mark, Some(t.comments.clone()), - Default::default() + Default::default(), ), ) }, @@ -3771,13 +3771,13 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), es2015::es2015( unresolved_mark, Some(t.comments.clone()), - Default::default() + Default::default(), ), ) }, @@ -3800,10 +3800,10 @@ fn exec(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - classes(Default::default()) + classes(Default::default()), ) }, &src, @@ -3820,10 +3820,10 @@ fn fixture(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - classes(Default::default()) + classes(Default::default()), ) }, &input, @@ -4079,7 +4079,7 @@ class Thing extends B { test!( syntax(), - |_| chain!(classes(Default::default()), block_scoping(Mark::new())), + |_| (classes(Default::default()), block_scoping(Mark::new())), issue_5102, r#" let C = class {} diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs b/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs index 574934ddd5ff..642a26999895 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs @@ -20,9 +20,9 @@ fn syntax() -> Syntax { } fn tr() -> impl Pass { - chain!( + ( resolver(Mark::new(), Mark::new(), false), - destructuring(Config { loose: true }) + destructuring(Config { loose: true }), ) } @@ -91,7 +91,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -590,12 +590,12 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), es2015( unresolved_mark, Some(t.comments.clone()), - Default::default() + Default::default(), ), ) }, @@ -619,7 +619,7 @@ test!( // destructuring_function_key_with_object_rest_spread test_exec!( syntax(), - |_| chain!( + |_| ( object_rest_spread(Default::default()), destructuring(Default::default()) ), @@ -650,7 +650,7 @@ function isBetween(x, a, b) { // destructuring_for_of test!( syntax(), - |_| chain!( + |_| ( spread(Default::default()), destructuring(Default::default()), block_scoping(Mark::new()), @@ -676,7 +676,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -700,7 +700,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -723,7 +723,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -754,7 +754,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -779,7 +779,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -807,7 +807,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), object_rest_spread(Default::default()), spread(Default::default()), @@ -863,7 +863,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -894,7 +894,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -983,7 +983,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -1020,7 +1020,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -1061,7 +1061,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -1085,7 +1085,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), object_rest_spread(Default::default()), spread(Default::default()), @@ -1130,7 +1130,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), object_rest_spread(Default::default()), spread(Default::default()), @@ -1154,7 +1154,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), object_rest_spread(Default::default()), spread(Default::default()), @@ -1179,7 +1179,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), object_rest_spread(Default::default()), spread(Default::default()), @@ -1206,7 +1206,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), object_rest_spread(Default::default()), spread(Default::default()), @@ -1226,7 +1226,7 @@ var {topLeft: [x1, y1], bottomRight: [x2, y2] } = rect; // destructuring_assignment_statement test!( syntax(), - |_| chain!( + |_| ( destructuring(Default::default()), spread(Default::default()), block_scoping(Mark::new()), @@ -1241,7 +1241,7 @@ test!( // destructuring_assignment_statement_loose test!( syntax(), - |_| chain!( + |_| ( destructuring(Config { loose: true }), spread(Default::default()), block_scoping(Mark::new()), @@ -1260,7 +1260,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -1284,7 +1284,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -1307,7 +1307,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), object_rest_spread(Default::default()), spread(Default::default()), @@ -1336,7 +1336,7 @@ const { // destructuring_number_key_with_object_rest_spread test_exec!( syntax(), - |_| chain!( + |_| ( object_rest_spread(Default::default()), destructuring(Default::default()) ), @@ -1359,7 +1359,7 @@ expect(rest).toEqual({ 2: "b", 3: "c" }); // destructuring_for_in test!( syntax(), - |_| chain!( + |_| ( spread(Default::default()), destructuring(Default::default()), block_scoping(Mark::new()), @@ -1381,7 +1381,7 @@ for ([name, value] in obj) { // destructuring_for_in_loose test!( syntax(), - |_| chain!( + |_| ( spread(Default::default()), destructuring(Config { loose: true }), block_scoping(Mark::new()), @@ -1407,7 +1407,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -1430,7 +1430,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), spread(Default::default()), parameters(Default::default(), unresolved_mark), @@ -1663,10 +1663,10 @@ fn fixture(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), object_rest_spread(Default::default()), - destructuring(Default::default()) + destructuring(Default::default()), ) }, &input, diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs b/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs index 2accb8951c01..921c496c8a4e 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs @@ -279,12 +279,12 @@ fn exec(input: PathBuf) { |_| { let top_level_mark = Mark::new(); - chain!( + ( resolver(Mark::new(), top_level_mark, false), for_of(Config { assume_array: false, ..Default::default() - }) + }), ) }, &input, @@ -300,12 +300,12 @@ fn fixture(input: PathBuf) { &|_| { let top_level_mark = Mark::new(); - chain!( + ( resolver(Mark::new(), top_level_mark, false), for_of(Config { assume_array: false, ..Default::default() - }) + }), ) }, &input, @@ -324,9 +324,9 @@ fn exec_es2015(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - es2015::es2015(unresolved_mark, Some(NoopComments), Default::default()) + es2015::es2015(unresolved_mark, Some(NoopComments), Default::default()), ) }, &input, diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs b/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs index 47820773c924..fca036256de0 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs @@ -21,19 +21,19 @@ fn syntax() -> Syntax { fn tr(_: ()) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - generator(unresolved_mark, NoopComments) + generator(unresolved_mark, NoopComments), ) } fn tr_with_async() -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), async_to_generator(Default::default(), unresolved_mark), - generator(unresolved_mark, NoopComments) + generator(unresolved_mark, NoopComments), ) } @@ -910,13 +910,13 @@ test_exec!( syntax(), |t| { let unresolved_mark = Mark::new(); - chain!( + ( es2017(Default::default(), unresolved_mark), es2016(), es2015( unresolved_mark, Some(t.comments.clone()), - Default::default() + Default::default(), ), ) }, @@ -932,7 +932,7 @@ test_exec!( syntax(), |t| { let unresolved_mark = Mark::new(); - chain!( + ( async_to_generator(Default::default(), unresolved_mark), es2015::for_of(Default::default()), generator(unresolved_mark, t.comments.clone()), @@ -1368,9 +1368,9 @@ test!( Syntax::default(), |_| { let mark = Mark::fresh(Mark::root()); - chain!( + ( async_to_generator(Default::default(), mark), - es2015::(mark, None, Default::default()) + es2015::(mark, None, Default::default()), ) }, issue_1799_2, @@ -1385,7 +1385,7 @@ test!( Syntax::default(), |_| { let mark = Mark::fresh(Mark::root()); - chain!( + ( async_to_generator(Default::default(), mark), es2016(), es2015::(mark, None, Default::default()), @@ -1405,7 +1405,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), es2022(Default::default(), unresolved_mark), es2021(), @@ -1443,10 +1443,10 @@ test_exec!( Syntax::default(), |t| { let mark = Mark::fresh(Mark::root()); - chain!( + ( async_to_generator(Default::default(), mark), es2015::for_of(Default::default()), - generator(mark, t.comments.clone()) + generator(mark, t.comments.clone()), ) }, issue_1918_1, diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs index d6ecd5b2bc8b..938b1a353f0e 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs @@ -39,7 +39,7 @@ fn get_passes(_: &Tester, plugins: &[PluginConfig]) -> Box { "transform-new-target" => {} "proposal-class-properties" => { - pass = Box::new(chain!( + pass = Box::new(( pass, class_properties( class_properties::Config { @@ -51,12 +51,12 @@ fn get_passes(_: &Tester, plugins: &[PluginConfig]) -> Box { pure_getter: loose, }, unresolved_mark, - ) + ), )); } "transform-arrow-functions" => { - pass = Box::new(chain!(pass, arrow(Mark::new()))); + pass = Box::new((pass, arrow(Mark::new()))); } _ => { @@ -65,7 +65,7 @@ fn get_passes(_: &Tester, plugins: &[PluginConfig]) -> Box { } } - pass = Box::new(chain!(pass, new_target())); + pass = Box::new((pass, new_target())); pass } @@ -111,7 +111,7 @@ fn fixture(input: PathBuf) { test!( ::swc_ecma_parser::Syntax::default(), - |_| chain!(classes(Default::default()), new_target()), + |_| (classes(Default::default()), new_target()), issue_6259, r#" (() => { diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs b/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs index 158b0a9094ad..1abae93639de 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs @@ -14,7 +14,7 @@ fn tr() -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), object_super(), shorthand(), diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs b/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs index e0575659ff5c..07032bbc4508 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs @@ -20,7 +20,7 @@ fn tr(c: Config) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), parameters(c, unresolved_mark), destructuring(destructuring::Config { loose: false }), @@ -138,7 +138,7 @@ foo(1, 2, 3);"# test!( syntax(), - |_| chain!(classes(Default::default()), tr(Default::default())), + |_| (classes(Default::default()), tr(Default::default())), default_iife_4253, r#"class Ref { constructor(id = ++Ref.nextID) { @@ -167,7 +167,7 @@ expect(new Ref().id).toBe(2);"# test!( syntax(), - |_| chain!(classes(Default::default()), tr(Default::default())), + |_| (classes(Default::default()), tr(Default::default())), default_iife_self, r#"class Ref { constructor(ref = Ref) { @@ -476,7 +476,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( arrow(unresolved_mark), resolver(unresolved_mark, top_level_mark, false), parameters(Default::default(), unresolved_mark), @@ -722,7 +722,7 @@ function d(thing, ...args) { test!( syntax(), - |_| chain!( + |_| ( tr(Default::default()), classes(Default::default()), spread(Default::default()) @@ -791,7 +791,7 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), async_to_generator(Default::default(), unresolved_mark), arrow(unresolved_mark), @@ -815,7 +815,7 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), async_to_generator(Default::default(), unresolved_mark), arrow(unresolved_mark), @@ -838,7 +838,7 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), parameters(Default::default(), unresolved_mark), ) @@ -860,10 +860,10 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), parameters(Default::default(), unresolved_mark), - block_scoping(unresolved_mark) + block_scoping(unresolved_mark), ) }, parameters_regression_4333, @@ -881,10 +881,10 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), parameters(Default::default(), unresolved_mark), - destructuring(Default::default()) + destructuring(Default::default()), ) }, issue_760, @@ -898,7 +898,7 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), parameters(Default::default(), unresolved_mark), ) @@ -916,7 +916,7 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), parameters(Default::default(), unresolved_mark), ) @@ -934,7 +934,7 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), parameters(Default::default(), unresolved_mark), ) @@ -952,7 +952,7 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), parameters(Default::default(), unresolved_mark), ) @@ -970,7 +970,7 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), parameters(Default::default(), unresolved_mark), ) @@ -1018,7 +1018,7 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), parameters(Default::default(), unresolved_mark), ) @@ -1038,7 +1038,7 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), parameters(Default::default(), unresolved_mark), ) @@ -1286,9 +1286,9 @@ fn fixture(input: PathBuf) { Default::default(), &|_| { let unresolved_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, Mark::new(), false), - parameters(Default::default(), unresolved_mark) + parameters(Default::default(), unresolved_mark), ) }, &input, diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_shorthand_propertie.rs b/crates/swc_ecma_transforms_compat/tests/es2015_shorthand_propertie.rs index e9b42702adc6..86524ef4b4ae 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_shorthand_propertie.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_shorthand_propertie.rs @@ -14,7 +14,7 @@ fn fixture(input: PathBuf) { Default::default(), &|_| { let unresolved_mark = Mark::new(); - chain!(resolver(unresolved_mark, Mark::new(), false), shorthand()) + (resolver(unresolved_mark, Mark::new(), false), shorthand()) }, &input, &output, diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs b/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs index 73b0a16343ca..4c470ee57674 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs @@ -13,10 +13,10 @@ fn tr() -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), parameters(Default::default(), unresolved_mark), - spread(Default::default()) + spread(Default::default()), ) } @@ -468,11 +468,11 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), parameters(Default::default(), unresolved_mark), spread(Default::default()), - block_scoping(unresolved_mark) + block_scoping(unresolved_mark), ) }, spread_known_rest, diff --git a/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs b/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs index b038309f62ae..38662e12d490 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs @@ -42,7 +42,7 @@ fn tr() -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), ParenRemover, arrow(unresolved_mark), @@ -50,16 +50,16 @@ fn tr() -> impl Pass { destructuring(destructuring::Config { loose: false }), function_name(), async_to_generator(Default::default(), unresolved_mark), - fixer(None) + fixer(None), ) } fn with_resolver() -> impl Pass { let unresolved = Mark::new(); let top_level = Mark::new(); - chain!( + ( resolver(unresolved, top_level, false), - async_to_generator(Default::default(), unresolved) + async_to_generator(Default::default(), unresolved), ) } @@ -412,7 +412,7 @@ test!( test_exec!( syntax(), - |t| chain!( + |t| ( tr(), es2015( Mark::fresh(Mark::root()), @@ -480,13 +480,13 @@ test_exec!( syntax(), |t| { let unresolved_mark = Mark::new(); - chain!( + ( async_to_generator(Default::default(), unresolved_mark), es2015( unresolved_mark, Some(t.comments.clone()), - Default::default() - ) + Default::default(), + ), ) }, issue_400_3, @@ -506,7 +506,7 @@ return (new A()).print();" //// regression_7178 //test!( // syntax(), -// |_| chain!(jsx(), jsc_constant_elements(), +// |_| (jsx(), jsc_constant_elements(), // async_to_generator(Default::default()),), regression_7178, // r#" //const title = "Neem contact op"; @@ -586,9 +586,9 @@ test!( syntax(), |_| { let unresolved_mark = Mark::new(); - chain!( + ( async_to_generator(Default::default(), unresolved_mark), - arrow(unresolved_mark) + arrow(unresolved_mark), ) }, regression_t7194, @@ -693,7 +693,7 @@ test!( syntax(), |_| { let unresolved_mark = Mark::new(); - chain!( + ( async_to_generator(Default::default(), unresolved_mark), //regenerator(), arrow(unresolved_mark), @@ -793,7 +793,7 @@ var foo = async function bar() { //// async_to_generator_async_iife_with_regenerator_spec //test!( // syntax(), -// |_| chain!(async_to_generator(Default::default()), arrow(), +// |_| (async_to_generator(Default::default()), arrow(), // regenerator(),), async_to_generator_async_iife_with_regenerator_spec, // r#" //(async function() { await 'ok' })(); @@ -924,7 +924,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), async_to_generator(Default::default(), unresolved_mark), parameters(Default::default(), unresolved_mark), @@ -1362,10 +1362,10 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - async_to_generator(Default::default(), Mark::new()) + async_to_generator(Default::default(), Mark::new()), ) }, issue_1341_1_exec, @@ -1406,10 +1406,10 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - async_to_generator(Default::default(), Mark::new()) + async_to_generator(Default::default(), Mark::new()), ) }, issue_1341_2_exec, @@ -1464,9 +1464,9 @@ test_exec!( Syntax::default(), |t| { let mark = Mark::fresh(Mark::root()); - chain!( + ( async_to_generator(Default::default(), mark), - generator(mark, t.comments.clone()) + generator(mark, t.comments.clone()), ) }, issue_1575_2, @@ -1539,9 +1539,9 @@ test!( Syntax::default(), |t| { let unresolved_mark = Mark::fresh(Mark::root()); - chain!( + ( async_to_generator(Default::default(), unresolved_mark), - generator(unresolved_mark, t.comments.clone()) + generator(unresolved_mark, t.comments.clone()), ) }, issue_1684_2, @@ -1652,9 +1652,9 @@ test!( Syntax::default(), |t| { let unresolved_mark = Mark::fresh(Mark::root()); - chain!( + ( async_to_generator(Default::default(), unresolved_mark), - generator(unresolved_mark, t.comments.clone()) + generator(unresolved_mark, t.comments.clone()), ) }, issue_2402_2, @@ -1713,9 +1713,9 @@ test!( Syntax::default(), |t| { let unresolved_mark = Mark::fresh(Mark::root()); - chain!( + ( async_to_generator(Default::default(), unresolved_mark), - generator(unresolved_mark, t.comments.clone()) + generator(unresolved_mark, t.comments.clone()), ) }, issue_2305_2, @@ -1750,9 +1750,9 @@ test!( Syntax::default(), |t| { let unresolved_mark = Mark::fresh(Mark::root()); - chain!( + ( async_to_generator(Default::default(), unresolved_mark), - generator(unresolved_mark, t.comments.clone()) + generator(unresolved_mark, t.comments.clone()), ) }, issue_2677_1, @@ -1774,9 +1774,9 @@ test!( Syntax::default(), |t| { let unresolved_mark = Mark::fresh(Mark::root()); - chain!( + ( async_to_generator(Default::default(), unresolved_mark), - generator(unresolved_mark, t.comments.clone()) + generator(unresolved_mark, t.comments.clone()), ) }, issue_2677_2, @@ -2112,10 +2112,10 @@ fn exec(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties(Default::default(), unresolved_mark), - async_to_generator(Default::default(), unresolved_mark) + async_to_generator(Default::default(), unresolved_mark), ) }, &input, @@ -2131,13 +2131,13 @@ fn exec_regenerator(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties(Default::default(), unresolved_mark), async_to_generator(Default::default(), unresolved_mark), es2015::for_of(Default::default()), block_scoping(unresolved_mark), - generator(unresolved_mark, t.comments.clone()) + generator(unresolved_mark, t.comments.clone()), ) }, &input, diff --git a/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs b/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs index 3473c26c6836..dd9cbc9e07d7 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs @@ -165,7 +165,7 @@ export var [ dd, ee ] = ads; test!( syntax(), - |_| chain!(tr(Default::default()), spread(Default::default())), + |_| (tr(Default::default()), spread(Default::default())), rest_for_x, r#" // ForXStatement @@ -2458,13 +2458,13 @@ test_exec!( // let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), tr(Default::default()), es2015::es2015( unresolved_mark, Some(t.comments.clone()), - Default::default() + Default::default(), ), ) }, @@ -2485,7 +2485,7 @@ compare_stdout!( // let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), tr(Default::default()), ) @@ -2510,7 +2510,7 @@ fn fixture(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), object_rest_spread(Default::default()), ) diff --git a/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs b/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs index f764b17429aa..dd079eef17ef 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs @@ -13,9 +13,9 @@ use swc_ecma_transforms_testing::{compare_stdout, test, test_exec, test_fixture} fn tr(c: Config) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - optional_chaining(c, unresolved_mark) + optional_chaining(c, unresolved_mark), ) } @@ -257,7 +257,7 @@ fn exec(input: PathBuf) { |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), optional_chaining( Config { @@ -265,7 +265,7 @@ fn exec(input: PathBuf) { ..Default::default() }, Mark::new(), - ) + ), ) }, &src, @@ -281,16 +281,16 @@ fn fixture(input: PathBuf) { &|_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties( swc_ecma_transforms_compat::es2022::class_properties::Config { private_as_properties: false, ..Default::default() }, - unresolved_mark + unresolved_mark, ), - optional_chaining(Default::default(), unresolved_mark) + optional_chaining(Default::default(), unresolved_mark), ) }, &input, @@ -308,7 +308,7 @@ fn fixture_loose(input: PathBuf) { &|_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties( swc_ecma_transforms_compat::es2022::class_properties::Config { @@ -318,7 +318,7 @@ fn fixture_loose(input: PathBuf) { ..Default::default() }, - unresolved_mark + unresolved_mark, ), optional_chaining( Config { @@ -326,7 +326,7 @@ fn fixture_loose(input: PathBuf) { pure_getter: true, }, Mark::new(), - ) + ), ) }, &input, diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs b/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs index cccaec9ea3ec..2d7428503d64 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs @@ -24,7 +24,7 @@ fn tr(_: &Tester) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), function_name(), class_properties(Default::default(), unresolved_mark), @@ -114,7 +114,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), function_name(), class_properties(Default::default(), unresolved_mark), @@ -1756,9 +1756,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - class_properties(Default::default(), unresolved_mark) + class_properties(Default::default(), unresolved_mark), ) }, issue_308, @@ -1780,10 +1780,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties(Default::default(), unresolved_mark), - classes(Default::default()) + classes(Default::default()), ) }, issue_342, @@ -1804,10 +1804,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties(Default::default(), unresolved_mark), - block_scoping(unresolved_mark) + block_scoping(unresolved_mark), ) }, issue_443, @@ -1831,10 +1831,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - async_to_generator(Default::default(), Mark::new()) + async_to_generator(Default::default(), Mark::new()), ) }, public_regression_t7364, @@ -1867,10 +1867,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_regression_t6719, @@ -1900,10 +1900,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_reevaluated, @@ -1941,10 +1941,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_static, @@ -1975,11 +1975,11 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), classes(Default::default()), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_destructuring_object_pattern_1, @@ -2002,10 +2002,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_static_inherited, @@ -2050,9 +2050,9 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, private_destructuring_object_pattern_1_exec, @@ -2085,10 +2085,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_static_undefined, @@ -2115,11 +2115,11 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), classes(Default::default()), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_destructuring_array_pattern, @@ -2142,10 +2142,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_regression_t2983, @@ -2168,11 +2168,11 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), async_to_generator(Default::default(), unresolved_mark), - block_scoping(unresolved_mark) + block_scoping(unresolved_mark), ) }, private_regression_t7364, @@ -2205,11 +2205,11 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), classes(Default::default()), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_destructuring_array_pattern_1, @@ -2232,9 +2232,9 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, regression_8882_exec, @@ -2271,9 +2271,9 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,), + class_properties(Default::default(), unresolved_mark), ) }, regression_8882_exec_2, @@ -2310,9 +2310,9 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, private_field_reinitialized, @@ -2340,10 +2340,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_static_export, @@ -2366,10 +2366,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - classes(Default::default()) + classes(Default::default()), ) }, static_property_tdz_edgest_case, @@ -2387,10 +2387,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - classes(Default::default()) + classes(Default::default()), ) }, static_property_tdz_false_alarm, @@ -2408,10 +2408,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - arrow(Mark::new()) + arrow(Mark::new()), ) }, regression_6153, @@ -2455,7 +2455,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), arrow(unresolved_mark), @@ -2572,9 +2572,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, private_optional_chain_call, @@ -2595,9 +2595,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, private_optional_chain_member, @@ -2618,11 +2618,11 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), classes(Default::default()), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_canonical, @@ -2658,9 +2658,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, regression_8882, @@ -2696,11 +2696,11 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), classes(Default::default()), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_destructuring_array_pattern_3, @@ -2721,9 +2721,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, staic_private_destructuring_array_pattern, @@ -2744,9 +2744,9 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, public_static_super_exec, @@ -2777,11 +2777,11 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), classes(Default::default()), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_destructuring_array_pattern_2, @@ -2803,10 +2803,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_non_block_arrow_func, @@ -2833,9 +2833,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, regression_8110, @@ -2856,9 +2856,9 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, public_computed_without_block_exec, @@ -2878,7 +2878,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), exponentiation(), @@ -2902,10 +2902,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - classes(Default::default()) + classes(Default::default()), ) }, static_property_tdz_general, @@ -2924,10 +2924,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, public_native_classes, @@ -2963,10 +2963,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_static_infer_name, @@ -2985,9 +2985,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - class_properties(Default::default(), unresolved_mark) + class_properties(Default::default(), unresolved_mark), ) }, regression_7951, @@ -3008,10 +3008,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, private_native_classes, @@ -3039,11 +3039,11 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), classes(Default::default()), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, public_computed_without_block, @@ -3060,9 +3060,9 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, private_destructuring_array_pattern_2_exec, @@ -3093,11 +3093,11 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), classes(Default::default()), - block_scoping(Mark::new()) + block_scoping(Mark::new()), ) }, public_static_super, @@ -3122,9 +3122,9 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, private_destructuring_array_pattern_exec, @@ -3154,9 +3154,9 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, private_destructuring_array_pattern_1_exec, @@ -3188,9 +3188,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_1306_1, @@ -3215,9 +3215,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_1306_2, @@ -3242,9 +3242,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_1333_1, @@ -3265,9 +3265,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_1333_2, @@ -3368,9 +3368,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_1333_3, @@ -3405,9 +3405,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_1333_4, @@ -3435,9 +3435,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_1333_5, @@ -3457,9 +3457,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_1333_6, @@ -3479,9 +3479,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_1660_1, @@ -3496,9 +3496,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_3055_1, @@ -3524,9 +3524,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_3618, @@ -3546,10 +3546,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - async_to_generator(Default::default(), Mark::new()) + async_to_generator(Default::default(), Mark::new()), ) }, issue_1694_1, @@ -3571,10 +3571,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties(Default::default(), unresolved_mark), - async_to_generator(Default::default(), Mark::new()) + async_to_generator(Default::default(), Mark::new()), ) }, issue_1694_2, @@ -3596,10 +3596,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), class_properties(Default::default(), unresolved_mark), - async_to_generator(Default::default(), Mark::new()) + async_to_generator(Default::default(), Mark::new()), ) }, issue_1702_1, @@ -3629,9 +3629,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_1711_1, @@ -3655,9 +3655,9 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_1742_1, @@ -3687,10 +3687,10 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties(Default::default(), unresolved_mark), - template_literal(Default::default()) + template_literal(Default::default()), ) }, issue_1742_2, @@ -3720,9 +3720,9 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, new_target_in_class_prop, @@ -3745,9 +3745,9 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, class_field_evalutaion_order, @@ -3770,9 +3770,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_1742_3, @@ -3802,9 +3802,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_1869_1, @@ -3829,9 +3829,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_1869_2, @@ -3855,9 +3855,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_2021_1, @@ -3878,9 +3878,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_3229_1, @@ -3902,9 +3902,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_3229_2, @@ -3927,9 +3927,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_3368, @@ -3955,9 +3955,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, nested_class_in_arrow, @@ -3979,9 +3979,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_2481, @@ -4001,9 +4001,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_4473, @@ -4027,7 +4027,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties( class_properties::Config { @@ -4035,7 +4035,7 @@ test!( ..Default::default() }, unresolved_mark, - ) + ), ) }, constant_super_complex_super, @@ -4052,7 +4052,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties( class_properties::Config { @@ -4060,7 +4060,7 @@ test!( ..Default::default() }, unresolved_mark, - ) + ), ) }, constant_super_field, @@ -4078,7 +4078,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties( class_properties::Config { @@ -4086,7 +4086,7 @@ test!( ..Default::default() }, unresolved_mark, - ) + ), ) }, private_optional_chain_member_loose, @@ -4106,7 +4106,7 @@ test_exec!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties( class_properties::Config { @@ -4114,7 +4114,7 @@ test_exec!( ..Default::default() }, unresolved_mark, - ) + ), ) }, set_public_fields_initialization_order, @@ -4166,7 +4166,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties( class_properties::Config { @@ -4174,7 +4174,7 @@ test!( ..Default::default() }, unresolved_mark, - ) + ), ) }, set_public_fields_computed, @@ -4213,15 +4213,15 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties( class_properties::Config { set_public_fields: true, ..Default::default() }, - unresolved_mark - ) + unresolved_mark, + ), ) }, set_public_constructor_collision, @@ -4246,7 +4246,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties( class_properties::Config { @@ -4254,7 +4254,7 @@ test!( ..Default::default() }, unresolved_mark, - ) + ), ) }, set_public_static_undefined, @@ -4271,7 +4271,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties( class_properties::Config { @@ -4279,7 +4279,7 @@ test!( ..Default::default() }, unresolved_mark, - ) + ), ) }, private_as_properties_basic, @@ -4316,7 +4316,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties( class_properties::Config { @@ -4324,7 +4324,7 @@ test!( ..Default::default() }, unresolved_mark, - ) + ), ) }, private_as_properties_static, @@ -4343,7 +4343,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties( class_properties::Config { @@ -4351,7 +4351,7 @@ test!( ..Default::default() }, unresolved_mark, - ) + ), ) }, private_as_properties_getter_only, @@ -4377,7 +4377,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties( class_properties::Config { @@ -4386,7 +4386,7 @@ test!( ..Default::default() }, unresolved_mark, - ) + ), ) }, loose_update, @@ -4447,9 +4447,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, set_only_getter, @@ -4483,9 +4483,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, get_only_setter, @@ -4510,7 +4510,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties( class_properties::Config { @@ -4518,7 +4518,7 @@ test!( ..Default::default() }, unresolved_mark, - ) + ), ) }, loose_keyword_method, @@ -4552,9 +4552,9 @@ fn exec(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, &src, @@ -4569,9 +4569,9 @@ fn fixture(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - class_properties(Default::default(), unresolved_mark) + class_properties(Default::default(), unresolved_mark), ) }, &input, @@ -4586,9 +4586,9 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), - class_properties(Default::default(), unresolved_mark,) + class_properties(Default::default(), unresolved_mark), ) }, issue_6305, @@ -4601,10 +4601,10 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), class_properties(Default::default(), unresolved_mark), - optional_chaining(Default::default(), unresolved_mark) + optional_chaining(Default::default(), unresolved_mark), ) }, issue_8003, diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs b/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs index 779c31bf7b60..62b5fd92d03b 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs @@ -56,7 +56,7 @@ fn fixture(input: PathBuf) { "proposal-class-properties" => { if !class_props { class_props = true; - pass = Box::new(chain!( + pass = Box::new(( pass, class_properties( class_properties::Config { @@ -67,7 +67,7 @@ fn fixture(input: PathBuf) { pure_getter: loose, static_blocks_mark: Mark::new(), }, - unresolved_mark + unresolved_mark, ), )); } @@ -76,7 +76,7 @@ fn fixture(input: PathBuf) { "proposal-private-methods" => { if !class_props { class_props = true; - pass = Box::new(chain!( + pass = Box::new(( pass, class_properties( class_properties::Config { @@ -88,13 +88,13 @@ fn fixture(input: PathBuf) { static_blocks_mark: Mark::new(), }, unresolved_mark, - ) + ), )); } } "transform-classes" => { - pass = Box::new(chain!(pass, classes(Default::default()))); + pass = Box::new((pass, classes(Default::default()))); } _ => { @@ -103,7 +103,7 @@ fn fixture(input: PathBuf) { } } - pass = Box::new(chain!(pass, private_in_object())); + pass = Box::new((pass, private_in_object())); pass }, diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs b/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs index 69f4dc14b1c4..3b69030047bb 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs @@ -21,15 +21,15 @@ fn fixture(input: PathBuf) { let config = class_properties::Config::default(); let pass: Box = if input.to_string_lossy().contains("class-properties") { - Box::new(chain!( + Box::new(( resolver(unresolved_mark, top_level_mark, false), static_blocks(config.static_blocks_mark), - class_properties(config, unresolved_mark) + class_properties(config, unresolved_mark), )) } else { - Box::new(chain!( + Box::new(( resolver(unresolved_mark, top_level_mark, false), - static_blocks(config.static_blocks_mark) + static_blocks(config.static_blocks_mark), )) }; pass diff --git a/crates/swc_ecma_transforms_module/tests/amd.rs b/crates/swc_ecma_transforms_module/tests/amd.rs index 38484ca1efd2..4c048c662fe3 100644 --- a/crates/swc_ecma_transforms_module/tests/amd.rs +++ b/crates/swc_ecma_transforms_module/tests/amd.rs @@ -23,7 +23,7 @@ fn tr(config: amd::Config, is_ts: bool, comments: Rc) -> let avalible_set = FeatureFlag::all(); - chain!( + ( resolver(unresolved_mark, top_level_mark, is_ts), typescript::typescript(Default::default(), unresolved_mark, top_level_mark), amd( @@ -31,7 +31,7 @@ fn tr(config: amd::Config, is_ts: bool, comments: Rc) -> unresolved_mark, config, avalible_set, - Some(comments) + Some(comments), ), ) } @@ -75,7 +75,7 @@ fn esm_to_amd(input: PathBuf) { test!( module, syntax(), - |t| chain!( + |t| ( for_of(for_of::Config { assume_array: true, ..Default::default() diff --git a/crates/swc_ecma_transforms_module/tests/common_js.rs b/crates/swc_ecma_transforms_module/tests/common_js.rs index b66a98d0bb38..f4f1076bc229 100644 --- a/crates/swc_ecma_transforms_module/tests/common_js.rs +++ b/crates/swc_ecma_transforms_module/tests/common_js.rs @@ -24,7 +24,7 @@ fn tr(config: common_js::Config, is_ts: bool) -> impl Pass { let available_set = FeatureFlag::all(); - chain!( + ( resolver(unresolved_mark, top_level_mark, is_ts), typescript::typescript(Default::default(), unresolved_mark, top_level_mark), common_js(Default::default(), unresolved_mark, config, available_set), @@ -69,7 +69,7 @@ fn esm_to_cjs(input: PathBuf) { test!( module, syntax(), - |_| chain!( + |_| ( for_of(for_of::Config { assume_array: true, ..Default::default() diff --git a/crates/swc_ecma_transforms_module/tests/system_js.rs b/crates/swc_ecma_transforms_module/tests/system_js.rs index 963b57e1a599..04226883e0b0 100644 --- a/crates/swc_ecma_transforms_module/tests/system_js.rs +++ b/crates/swc_ecma_transforms_module/tests/system_js.rs @@ -17,9 +17,9 @@ fn syntax() -> Syntax { fn tr(_tester: &mut Tester<'_>, config: Config) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - system_js(Default::default(), unresolved_mark, config) + system_js(Default::default(), unresolved_mark, config), ) } diff --git a/crates/swc_ecma_transforms_module/tests/umd.rs b/crates/swc_ecma_transforms_module/tests/umd.rs index 0ca72be6242d..77568b5bd32f 100644 --- a/crates/swc_ecma_transforms_module/tests/umd.rs +++ b/crates/swc_ecma_transforms_module/tests/umd.rs @@ -23,7 +23,7 @@ fn tr(tester: &mut Tester<'_>, config: Config, typescript: bool) -> impl Pass { let avalible_set = FeatureFlag::all(); - chain!( + ( resolver(unresolved_mark, top_level_mark, typescript), typescript::typescript(Default::default(), unresolved_mark, top_level_mark), umd( diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs b/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs index 041d4f77bf0e..41fee78061ec 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs @@ -15,7 +15,7 @@ macro_rules! test_stmt { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), paren_remover(None), expr_simplifier(top_level_mark, Default::default()), @@ -27,7 +27,7 @@ macro_rules! test_stmt { // This is hack is_unresolved_ref_safe: true, }, - }) + }), ) }, $l, diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs b/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs index 34c686a4f6a0..254736a5dace 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs @@ -15,7 +15,7 @@ fn fold(src: &str, expected: &str) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), paren_remover(None), visit_mut_pass(SimplifyExpr { @@ -29,7 +29,7 @@ fn fold(src: &str, expected: &str) { is_arg_of_update: false, is_modifying: false, in_callee: false, - }) + }), ) }, src, diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs index 00f6730df1fd..940faab74980 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs @@ -26,9 +26,9 @@ pub struct Config { /// Performs simplify-expr, inlining, remove-dead-branch and dce until nothing /// changes. pub fn simplifier(unresolved_mark: Mark, c: Config) -> impl CompilerPass + Pass + Repeated { - Repeat::new(chain!( + Repeat::new(( expr_simplifier(unresolved_mark, c.expr), dead_branch_remover(unresolved_mark), - dce::dce(c.dce, unresolved_mark) + dce::dce(c.dce, unresolved_mark), )) } diff --git a/crates/swc_ecma_transforms_optimization/tests/fixture.rs b/crates/swc_ecma_transforms_optimization/tests/fixture.rs index 0ea19bde1f5b..00cd48f9d06a 100644 --- a/crates/swc_ecma_transforms_optimization/tests/fixture.rs +++ b/crates/swc_ecma_transforms_optimization/tests/fixture.rs @@ -25,7 +25,7 @@ fn dce_single_pass(input: PathBuf) { &|t| { let unresolved_mark = Mark::new(); - chain!(remover(t), dce(Default::default(), unresolved_mark)) + (remover(t), dce(Default::default(), unresolved_mark)) }, &input, &output, @@ -43,9 +43,9 @@ fn dce_repeated(input: PathBuf) { ..Default::default() }), &|t| { - chain!( + ( remover(t), - Repeat::new(dce(Default::default(), Mark::new())) + Repeat::new(dce(Default::default(), Mark::new())), ) }, &input, @@ -64,7 +64,7 @@ fn dce_jsx(input: PathBuf) { jsx: true, ..Default::default() }), - &|t| chain!(remover(t), dce(Default::default(), Mark::new())), + &|t| (remover(t), dce(Default::default(), Mark::new())), &input, &output, Default::default(), @@ -80,9 +80,9 @@ fn expr(input: PathBuf) { &|t| { let top_level_mark = Mark::fresh(Mark::root()); - chain!( + ( remover(t), - Repeat::new(expr_simplifier(top_level_mark, Default::default())) + Repeat::new(expr_simplifier(top_level_mark, Default::default())), ) }, &input, diff --git a/crates/swc_ecma_transforms_optimization/tests/remove_imports_with_side_effects.rs b/crates/swc_ecma_transforms_optimization/tests/remove_imports_with_side_effects.rs index dde72282efe8..3465abab89d3 100644 --- a/crates/swc_ecma_transforms_optimization/tests/remove_imports_with_side_effects.rs +++ b/crates/swc_ecma_transforms_optimization/tests/remove_imports_with_side_effects.rs @@ -23,7 +23,7 @@ macro_rules! to { decorators: true, ..Default::default() }), - |_| chain!(resolver(Mark::new(), Mark::new(), false), tr()), + |_| (resolver(Mark::new(), Mark::new(), false), tr()), $name, $src ); diff --git a/crates/swc_ecma_transforms_optimization/tests/simplify.rs b/crates/swc_ecma_transforms_optimization/tests/simplify.rs index 3a8ee1291d3c..2de6e2733d3b 100644 --- a/crates/swc_ecma_transforms_optimization/tests/simplify.rs +++ b/crates/swc_ecma_transforms_optimization/tests/simplify.rs @@ -24,13 +24,13 @@ fn test(src: &str, expected: &str) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - Repeat::new(chain!( + Repeat::new(( expr_simplifier(unresolved_mark, Default::default()), inlining::inlining(Default::default()), dead_branch_remover(unresolved_mark), - dce::dce(Default::default(), unresolved_mark) + dce::dce(Default::default(), unresolved_mark), )), ) }, @@ -51,13 +51,13 @@ macro_rules! to { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - Repeat::new(chain!( + Repeat::new(( expr_simplifier(unresolved_mark, Default::default()), inlining::inlining(Default::default()), dead_branch_remover(unresolved_mark), - dce::dce(Default::default(), unresolved_mark) + dce::dce(Default::default(), unresolved_mark), )), ) }, @@ -498,7 +498,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), strip(unresolved_mark, top_level_mark), class_properties( @@ -506,10 +506,10 @@ test!( set_public_fields: true, ..Default::default() }, - unresolved_mark + unresolved_mark, ), dce(Default::default(), unresolved_mark), - inlining(Default::default()) + inlining(Default::default()), ) }, issue_1156_1, @@ -549,16 +549,16 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( decorators(Default::default()), resolver(unresolved_mark, top_level_mark, false), strip(unresolved_mark, top_level_mark), class_properties(Default::default(), unresolved_mark), - Repeat::new(chain!( + Repeat::new(( expr_simplifier(unresolved_mark, Default::default()), inlining::inlining(Default::default()), dead_branch_remover(unresolved_mark), - dce::dce(Default::default(), unresolved_mark) + dce::dce(Default::default(), unresolved_mark), )), es2018(Default::default()), es2017(Default::default(), unresolved_mark), @@ -566,7 +566,7 @@ test!( es2015( unresolved_mark, Some(t.comments.clone()), - Default::default() + Default::default(), ), es3(true), import_analyzer(false.into(), false), @@ -644,12 +644,12 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - Repeat::new(chain!( + Repeat::new(( inlining(Default::default()), - dead_branch_remover(unresolved_mark) - )) + dead_branch_remover(unresolved_mark), + )), ) }, issue_4173, diff --git a/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs b/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs index a3b2a0995bd3..1da29953b4dd 100644 --- a/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs +++ b/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs @@ -25,7 +25,7 @@ macro_rules! to { decorators: true, ..Default::default() }), - |_| chain!(resolver(Mark::new(), Mark::new(), false), tr()), + |_| (resolver(Mark::new(), Mark::new(), false), tr()), $name, $src ); @@ -375,7 +375,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( decorators(decorators::Config { legacy: true, emit_metadata: false, @@ -383,7 +383,7 @@ test!( }), resolver(unresolved_mark, top_level_mark, false), strip(unresolved_mark, top_level_mark), - tr() + tr(), ) }, issue_898_2, @@ -407,7 +407,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( decorators(decorators::Config { legacy: true, emit_metadata: false, @@ -415,7 +415,7 @@ test!( }), resolver(unresolved_mark, top_level_mark, false), strip(unresolved_mark, top_level_mark), - tr() + tr(), ) }, issue_1111, @@ -434,7 +434,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!(resolver(unresolved_mark, top_level_mark, false), tr()) + (resolver(unresolved_mark, top_level_mark, false), tr()) }, issue_1150_1, " @@ -469,7 +469,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), strip(unresolved_mark, top_level_mark), class_properties( @@ -477,9 +477,9 @@ test!( set_public_fields: true, ..Default::default() }, - unresolved_mark + unresolved_mark, ), - tr() + tr(), ) }, issue_1156_1, @@ -508,7 +508,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), strip(unresolved_mark, top_level_mark), class_properties( @@ -516,7 +516,7 @@ test!( set_public_fields: true, ..Default::default() }, - unresolved_mark + unresolved_mark, ), tr(), ) @@ -561,7 +561,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), strip(unresolved_mark, top_level_mark), tr(), @@ -590,7 +590,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), strip(unresolved_mark, top_level_mark), class_properties( @@ -598,7 +598,7 @@ test!( set_public_fields: true, ..Default::default() }, - unresolved_mark + unresolved_mark, ), tr(), ) diff --git a/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs b/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs index 12f43feea6f0..909bdf245025 100644 --- a/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs +++ b/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs @@ -25,7 +25,7 @@ macro_rules! to { ($name:ident, $src:expr) => { test!( Default::default(), - |_| chain!( + |_| ( resolver(Mark::new(), Mark::new(), false), inlining(Default::default()) ), @@ -38,7 +38,7 @@ macro_rules! to { test!( ignore, Default::default(), - |_| chain!( + |_| ( resolver(Mark::new(), Mark::new(), false), inlining(Default::default()) ), @@ -63,9 +63,9 @@ fn test(src: &str, expected: &str) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - inlining(Default::default()) + inlining(Default::default()), ) }, src, @@ -2066,7 +2066,7 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::fresh(Mark::root()); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), simple_strip(unresolved_mark, top_level_mark), class_properties( @@ -2074,9 +2074,9 @@ test!( set_public_fields: true, ..Default::default() }, - unresolved_mark + unresolved_mark, ), - inlining(Default::default()) + inlining(Default::default()), ) }, issue_1156_1, @@ -2104,7 +2104,7 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), simple_strip(unresolved_mark, top_level_mark), class_properties( @@ -2112,9 +2112,9 @@ test!( set_public_fields: true, ..Default::default() }, - unresolved_mark + unresolved_mark, ), - inlining(Default::default()) + inlining(Default::default()), ) }, issue_1156_2, @@ -2156,10 +2156,10 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), simple_strip(unresolved_mark, top_level_mark), - inlining(Default::default()) + inlining(Default::default()), ) }, deno_8180_1, @@ -2190,10 +2190,10 @@ test!( |_| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), simple_strip(unresolved_mark, top_level_mark), - inlining(Default::default()) + inlining(Default::default()), ) }, deno_8189_1, diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators.rs b/crates/swc_ecma_transforms_proposal/tests/decorators.rs index 82fd7340f8de..257d3393a174 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators.rs +++ b/crates/swc_ecma_transforms_proposal/tests/decorators.rs @@ -122,7 +122,7 @@ fn create_pass(comments: Rc, input: &Path) -> Box {{ - pass = Box::new(chain!(pass, $e)); + pass = Box::new((pass, $e)); }}; } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/tests/explicit_resource_management.rs index 858d3a24d194..45ff022240c9 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit_resource_management.rs @@ -20,9 +20,9 @@ fn exec(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - explicit_resource_management() + explicit_resource_management(), ) }, &read_to_string(input).unwrap(), @@ -50,9 +50,9 @@ fn run_fixture(input: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), - explicit_resource_management() + explicit_resource_management(), ) }, &input, diff --git a/crates/swc_ecma_transforms_proposal/tests/export.rs b/crates/swc_ecma_transforms_proposal/tests/export.rs index d2d31cf6a89e..d3547982f248 100644 --- a/crates/swc_ecma_transforms_proposal/tests/export.rs +++ b/crates/swc_ecma_transforms_proposal/tests/export.rs @@ -16,7 +16,7 @@ fn syntax_namespace() -> Syntax { } fn tr() -> impl Pass { - chain!(export_default_from(), export_namespace_from()) + (export_default_from(), export_namespace_from()) } test!( diff --git a/crates/swc_ecma_transforms_react/src/jsx/tests.rs b/crates/swc_ecma_transforms_react/src/jsx/tests.rs index 7508f6269d02..e0d1397cbc16 100644 --- a/crates/swc_ecma_transforms_react/src/jsx/tests.rs +++ b/crates/swc_ecma_transforms_react/src/jsx/tests.rs @@ -23,14 +23,14 @@ use crate::{display_name, pure_annotations, react}; fn tr(t: &mut Tester, options: Options, top_level_mark: Mark) -> impl Pass { let unresolved_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), jsx( t.cm.clone(), Some(t.comments.clone()), options, top_level_mark, - unresolved_mark + unresolved_mark, ), display_name(), classes(Default::default()), @@ -71,7 +71,7 @@ fn fixture_tr(t: &mut Tester, mut options: FixtureOptions) -> impl Pass { options.options.runtime = Some(Runtime::Classic); } - chain!( + ( resolver(unresolved_mark, top_level_mark, false), jsx( t.cm.clone(), @@ -81,7 +81,7 @@ fn fixture_tr(t: &mut Tester, mut options: FixtureOptions) -> impl Pass { unresolved_mark, ), display_name(), - pure_annotations(Some(t.comments.clone())) + pure_annotations(Some(t.comments.clone())), ) } @@ -95,14 +95,14 @@ fn integration_tr(t: &mut Tester, mut options: FixtureOptions) -> impl Pass { options.options.runtime = Some(Runtime::Classic); } - chain!( + ( resolver(unresolved_mark, top_level_mark, false), react( t.cm.clone(), Some(t.comments.clone()), options.options, top_level_mark, - unresolved_mark + unresolved_mark, ), display_name(), ) @@ -413,7 +413,7 @@ test!( jsx: true, ..Default::default() }), - |t| chain!( + |t| ( tr(t, Default::default(), Mark::fresh(Mark::root())), property_literals(), ), @@ -986,15 +986,15 @@ test!( let top_level_mark = Mark::fresh(Mark::root()); let unresolved_mark = Mark::fresh(Mark::root()); - chain!( + ( classes(Default::default()), jsx( t.cm.clone(), Some(t.comments.clone()), Default::default(), top_level_mark, - unresolved_mark - ) + unresolved_mark, + ), ) }, regression_2775, @@ -1028,15 +1028,15 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), jsx( t.cm.clone(), Some(t.comments.clone()), Default::default(), top_level_mark, - unresolved_mark - ) + unresolved_mark, + ), ) }, issue_4956, @@ -1126,7 +1126,7 @@ fn test_script(src: &str, output: &Path, options: Options) { let top_level_mark = Mark::new(); let unresolved_mark = Mark::new(); - let script = script.fold_with(&mut chain!( + let script = script.fold_with(&mut ( resolver(Mark::new(), top_level_mark, false), react( tester.cm.clone(), @@ -1136,7 +1136,7 @@ fn test_script(src: &str, output: &Path, options: Options) { unresolved_mark, ), hygiene::hygiene(), - fixer(Some(&tester.comments)) + fixer(Some(&tester.comments)), )); let mut buf = Vec::new(); diff --git a/crates/swc_ecma_transforms_react/src/lib.rs b/crates/swc_ecma_transforms_react/src/lib.rs index ce29f5a18359..3163dd497371 100644 --- a/crates/swc_ecma_transforms_react/src/lib.rs +++ b/crates/swc_ecma_transforms_react/src/lib.rs @@ -50,7 +50,7 @@ where let refresh_options = options.refresh.take(); - chain!( + ( jsx_src(development, cm.clone()), jsx_self(development), refresh( @@ -58,14 +58,14 @@ where refresh_options.clone(), cm.clone(), comments.clone(), - top_level_mark + top_level_mark, ), jsx( cm.clone(), comments.clone(), options, top_level_mark, - unresolved_mark + unresolved_mark, ), display_name(), pure_annotations(comments.clone()), diff --git a/crates/swc_ecma_transforms_react/src/refresh/tests.rs b/crates/swc_ecma_transforms_react/src/refresh/tests.rs index c72c84c9a9dc..bb8a74d8b125 100644 --- a/crates/swc_ecma_transforms_react/src/refresh/tests.rs +++ b/crates/swc_ecma_transforms_react/src/refresh/tests.rs @@ -9,7 +9,7 @@ fn tr(t: &mut Tester) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), refresh( true, @@ -19,8 +19,8 @@ fn tr(t: &mut Tester) -> impl Pass { }), t.cm.clone(), Some(t.comments.clone()), - top_level_mark - ) + top_level_mark, + ), ) } @@ -569,7 +569,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), refresh( true, @@ -579,14 +579,14 @@ test!( }), t.cm.clone(), Some(t.comments.clone()), - top_level_mark + top_level_mark, ), jsx( t.cm.clone(), Some(t.comments.clone()), Default::default(), top_level_mark, - unresolved_mark + unresolved_mark, ), ) }, @@ -706,7 +706,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), refresh( true, @@ -717,8 +717,8 @@ test!( }), t.cm.clone(), Some(t.comments.clone()), - top_level_mark - ) + top_level_mark, + ), ) }, custom_identifier, diff --git a/crates/swc_ecma_transforms_testing/src/babel_like.rs b/crates/swc_ecma_transforms_testing/src/babel_like.rs index 06fc7db5a35a..b40a080b23a1 100644 --- a/crates/swc_ecma_transforms_testing/src/babel_like.rs +++ b/crates/swc_ecma_transforms_testing/src/babel_like.rs @@ -104,7 +104,7 @@ impl<'a> BabelLikeFixtureTest<'a> { let mut done = false; for factory in &mut factories { if let Some(built) = factory(&builder, &name, options.clone()) { - pass = Box::new(chain!(pass, built)); + pass = Box::new((pass, built)); done = true; break; } @@ -115,7 +115,7 @@ impl<'a> BabelLikeFixtureTest<'a> { } } - pass = Box::new(chain!(pass, hygiene(), fixer(Some(&comments)))); + pass = Box::new((pass, hygiene(), fixer(Some(&comments)))); // Run pass diff --git a/crates/swc_ecma_transforms_testing/src/lib.rs b/crates/swc_ecma_transforms_testing/src/lib.rs index 9653b8dc2940..38bb0231e1a1 100644 --- a/crates/swc_ecma_transforms_testing/src/lib.rs +++ b/crates/swc_ecma_transforms_testing/src/lib.rs @@ -259,7 +259,7 @@ pub fn test_transform( println!("----- Actual -----"); - let tr = chain!(tr(tester), visit_mut_pass(RegeneratorHandler)); + let tr = (tr(tester), visit_mut_pass(RegeneratorHandler)); let actual = tester.apply_transform(tr, "input.js", syntax, is_module, input)?; match ::std::env::var("PRINT_HYGIENE") { @@ -536,7 +536,7 @@ where P: Pass, { Tester::run(|tester| { - let tr = chain!(tr(tester), visit_mut_pass(RegeneratorHandler)); + let tr = (tr(tester), visit_mut_pass(RegeneratorHandler)); let program = tester.apply_transform(tr, "input.js", syntax, Some(true), input)?; @@ -584,7 +584,7 @@ where P: Pass, { Tester::run(|tester| { - let tr = chain!(tr(tester), visit_mut_pass(RegeneratorHandler)); + let tr = (tr(tester), visit_mut_pass(RegeneratorHandler)); let program = tester.apply_transform( tr, diff --git a/crates/swc_ecma_transforms_typescript/benches/compat.rs b/crates/swc_ecma_transforms_typescript/benches/compat.rs index b3df1af10146..d354cc00d01e 100644 --- a/crates/swc_ecma_transforms_typescript/benches/compat.rs +++ b/crates/swc_ecma_transforms_typescript/benches/compat.rs @@ -297,7 +297,7 @@ fn es3(b: &mut Bencher) { fn full_es2016(b: &mut Bencher) { run(b, |unresolved_mark| { - chain!( + ( swc_ecma_transforms_compat::es2022(Default::default(), unresolved_mark), swc_ecma_transforms_compat::es2019(), swc_ecma_transforms_compat::es2018(Default::default()), @@ -309,7 +309,7 @@ fn full_es2016(b: &mut Bencher) { fn full_es2017(b: &mut Bencher) { run(b, |unresolved_mark| { - chain!( + ( swc_ecma_transforms_compat::es2022(Default::default(), unresolved_mark), swc_ecma_transforms_compat::es2019(), swc_ecma_transforms_compat::es2018(Default::default()), @@ -320,7 +320,7 @@ fn full_es2017(b: &mut Bencher) { fn full_es2018(b: &mut Bencher) { run(b, |unresolved_mark| { - chain!( + ( swc_ecma_transforms_compat::es2022(Default::default(), unresolved_mark), swc_ecma_transforms_compat::es2019(), swc_ecma_transforms_compat::es2018(Default::default()), diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index ce95fd5c066d..71959cf6a988 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -36,7 +36,7 @@ fn tr_config( ..Default::default() }); - chain!( + ( Optional::new( decorators(decorators_config.unwrap_or_default()), has_decorators, @@ -48,7 +48,7 @@ fn tr_config( None::, Default::default(), top_level_mark, - unresolved_mark + unresolved_mark, ), Optional::new(class_fields_use_set(true), !use_define_for_class_fields), ) @@ -58,7 +58,7 @@ fn tsxr(t: &Tester) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), tsx( t.cm.clone(), @@ -77,7 +77,7 @@ fn tsxr(t: &Tester) -> impl Pass { Some(t.comments.clone()), swc_ecma_transforms_react::Options::default(), top_level_mark, - unresolved_mark + unresolved_mark, ), ) } @@ -87,7 +87,7 @@ fn properties(_: &Tester, loose: bool) -> impl Pass { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), static_blocks(static_blocks_mark), class_properties( @@ -96,8 +96,8 @@ fn properties(_: &Tester, loose: bool) -> impl Pass { set_public_fields: loose, ..Default::default() }, - unresolved_mark - ) + unresolved_mark, + ), ) } @@ -108,7 +108,7 @@ macro_rules! to { decorators: true, ..Default::default() }), - |t| chain!(tr(t), properties(t, true)), + |t| (tr(t), properties(t, true)), $name, $from ); @@ -140,14 +140,14 @@ test!( |t| { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, true), tr(t), parameters( parameters::Config { - ignore_function_length: true + ignore_function_length: true, }, - unresolved_mark + unresolved_mark, ), destructuring(destructuring::Config { loose: false }), block_scoping(unresolved_mark), @@ -558,7 +558,7 @@ test!( test!( ::swc_ecma_parser::Syntax::Typescript(Default::default()), - |t| chain!(tr(t), properties(t, true)), + |t| (tr(t), properties(t, true)), issue_930_static, "class A { static b = 'foo'; @@ -569,7 +569,7 @@ test!( test!( ::swc_ecma_parser::Syntax::Typescript(Default::default()), - |t| chain!(tr(t), properties(t, true)), + |t| (tr(t), properties(t, true)), typescript_001, "class A { foo = new Subject() @@ -612,7 +612,7 @@ test!( decorators: true, ..Default::default() }), - |t| chain!( + |t| ( decorators(decorators::Config { legacy: true, ..Default::default() @@ -647,7 +647,7 @@ test_exec!( decorators: true, ..Default::default() }), - |t| chain!( + |t| ( decorators(decorators::Config { legacy: true, ..Default::default() @@ -1858,8 +1858,8 @@ test!( no_empty_export: true, ..Default::default() }; - chain!( - Optional::new(decorators(Default::default()), false,), + ( + Optional::new(decorators(Default::default()), false), resolver(unresolved_mark, top_level_mark, true), typescript(config, unresolved_mark, top_level_mark), async_to_generator(Default::default(), unresolved_mark), @@ -1888,11 +1888,11 @@ test!( no_empty_export: true, ..Default::default() }; - chain!( - Optional::new(decorators(Default::default()), false,), + ( + Optional::new(decorators(Default::default()), false), resolver(unresolved_mark, top_level_mark, true), typescript(config, unresolved_mark, top_level_mark), - optional_chaining(Default::default(), unresolved_mark) + optional_chaining(Default::default(), unresolved_mark), ) }, issue_1149_1, @@ -1903,7 +1903,7 @@ test!( test!( Syntax::Typescript(Default::default()), - |t| chain!(tr(t), nullish_coalescing(Default::default())), + |t| (tr(t), nullish_coalescing(Default::default())), issue_1123_1, r#" interface SuperSubmission { @@ -2661,7 +2661,7 @@ fn exec(input: PathBuf) { tsx: input.to_string_lossy().ends_with(".tsx"), ..Default::default() }), - &|t| chain!(tr(t), properties(t, true)), + &|t| (tr(t), properties(t, true)), &input, &output, Default::default(), @@ -2818,7 +2818,7 @@ test!( let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - chain!( + ( resolver(unresolved_mark, top_level_mark, false), tsx( t.cm.clone(), @@ -2830,7 +2830,7 @@ test!( t.comments.clone(), unresolved_mark, top_level_mark, - ) + ), ) }, ts_jsx_bad_pragma, From f165438304578aa12ae11ff532da0c375b317234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 17:21:12 +0900 Subject: [PATCH 134/186] chain --- crates/swc_ecma_ast/src/lib.rs | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index d3513fa051e0..f37404e612b5 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -512,29 +512,6 @@ impl_pass_for_tuple!( [24, Y] ); -/// Chain multiple passes. -/// -/// For compile time efficiency, this macro only supports up to 24 passes. You -/// can nest `chain!` calls to chain more passes. -#[macro_export] -macro_rules! chain { - ( - $( - $pass:expr - ),* - ) => { - ($($pass),*) - }; - - ( - $( - $pass:expr, - )* - ) => { - ($($pass),*) - }; -} - #[inline(always)] pub fn noop_pass() -> impl Pass { fn noop(_: &mut Program) {} From 6e93fe20aafe0b8badfebfcabebe7ccce6530199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 21:22:30 +0900 Subject: [PATCH 135/186] Pass for Either --- crates/swc_ecma_ast/src/lib.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index f37404e612b5..bb6889e4215f 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -12,7 +12,7 @@ pub use num_bigint::BigInt as BigIntValue; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use swc_common::{ast_node, util::take::Take, EqIgnoreSpan, Span}; +use swc_common::{ast_node, pass::Either, util::take::Take, EqIgnoreSpan, Span}; pub use self::{ class::{ @@ -131,6 +131,20 @@ where } } +impl Pass for Either +where + L: Pass, + R: Pass, +{ + #[inline] + fn process(&mut self, program: &mut Program) { + match self { + Either::Left(l) => l.process(program), + Either::Right(r) => r.process(program), + } + } +} + impl Program { #[inline(always)] pub fn mutate

(&mut self, mut pass: P) From fc99a45c3f6811086280814135133265af3aa3c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 21:23:01 +0900 Subject: [PATCH 136/186] Fix more --- crates/swc_ecma_compat_es2015/src/lib.rs | 2 +- crates/swc_ecma_transforms_proposal/src/decorators/mod.rs | 6 +++--- crates/swc_ecma_transforms_react/src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/lib.rs b/crates/swc_ecma_compat_es2015/src/lib.rs index d3604ce52bae..edebf3138a1e 100644 --- a/crates/swc_ecma_compat_es2015/src/lib.rs +++ b/crates/swc_ecma_compat_es2015/src/lib.rs @@ -3,7 +3,7 @@ use serde::Deserialize; use swc_common::{comments::Comments, Mark}; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_compat_common::regexp::{self, regexp}; pub use self::{ diff --git a/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs b/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs index 5eedc126fd81..a3c696622928 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs @@ -10,7 +10,7 @@ use swc_ecma_utils::{ alias_ident_for, constructor::inject_after_super, default_constructor, prepend_stmt, private_ident, prop_name_to_expr, prop_name_to_expr_value, quote_ident, quote_str, ExprFactory, }; -use swc_ecma_visit::{noop_fold_type, visit_mut_pass, Fold, FoldWith, Visit, VisitWith}; +use swc_ecma_visit::{fold_pass, noop_fold_type, visit_mut_pass, Fold, FoldWith, Visit, VisitWith}; mod legacy; @@ -61,10 +61,10 @@ pub fn decorators(c: Config) -> impl Pass { if c.emit_metadata { unimplemented!("emitting decorator metadata while using new proposal") } - Either::Right(Decorators { + Either::Right(fold_pass(Decorators { is_in_strict: false, vars: Default::default(), - }) + })) } } diff --git a/crates/swc_ecma_transforms_react/src/lib.rs b/crates/swc_ecma_transforms_react/src/lib.rs index 3163dd497371..97a2a5324f46 100644 --- a/crates/swc_ecma_transforms_react/src/lib.rs +++ b/crates/swc_ecma_transforms_react/src/lib.rs @@ -4,7 +4,7 @@ #![allow(rustc::untranslatable_diagnostic_trivial)] use swc_common::{comments::Comments, sync::Lrc, Mark, SourceMap}; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; pub use self::{ display_name::display_name, From 59ff145e06165a21eaf35f822851d109510da2a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 21:38:18 +0900 Subject: [PATCH 137/186] Fix more --- crates/swc_ecma_transforms_base/benches/deps.rs | 2 +- crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs | 1 - crates/swc_ecma_transforms_compat/tests/es2015_generator.rs | 2 +- .../tests/es2015_shorthand_propertie.rs | 1 - crates/swc_ecma_transforms_module/src/system_js.rs | 6 +++--- crates/swc_ecma_transforms_optimization/src/simplify/mod.rs | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/swc_ecma_transforms_base/benches/deps.rs b/crates/swc_ecma_transforms_base/benches/deps.rs index 8feee9f96aed..0ff1e1c611de 100644 --- a/crates/swc_ecma_transforms_base/benches/deps.rs +++ b/crates/swc_ecma_transforms_base/benches/deps.rs @@ -233,7 +233,7 @@ fn bench_cases(c: &mut Criterion) { criterion_group!(benches, bench_cases); criterion_main!(benches); -fn noop_fold() -> impl Pass { +fn noop_fold() -> impl Fold { struct Noop; impl Fold for Noop {} Noop diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs b/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs index 921c496c8a4e..72f2faca0539 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_for_of.rs @@ -1,7 +1,6 @@ use std::{fs::read_to_string, path::PathBuf}; use swc_common::{comments::NoopComments, Mark}; -use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2015::{ diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs b/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs index fca036256de0..4e4f1792de44 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs @@ -4,7 +4,6 @@ use swc_common::{ comments::{NoopComments, SingleThreadedComments}, Mark, }; -use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -1250,6 +1249,7 @@ async function foo(a) { } foo(1) + .then((t) => .then((t) => t(2)) .then(console.log); "# diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_shorthand_propertie.rs b/crates/swc_ecma_transforms_compat/tests/es2015_shorthand_propertie.rs index 86524ef4b4ae..1af4fb4056a5 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_shorthand_propertie.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_shorthand_propertie.rs @@ -1,7 +1,6 @@ use std::path::PathBuf; use swc_common::Mark; -use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2015::shorthand; use swc_ecma_transforms_testing::test_fixture; diff --git a/crates/swc_ecma_transforms_module/src/system_js.rs b/crates/swc_ecma_transforms_module/src/system_js.rs index c65a7defc07c..526f0a50462b 100644 --- a/crates/swc_ecma_transforms_module/src/system_js.rs +++ b/crates/swc_ecma_transforms_module/src/system_js.rs @@ -6,7 +6,7 @@ use swc_ecma_ast::*; use swc_ecma_utils::{ member_expr, private_ident, quote_ident, quote_str, var::VarCollector, ExprFactory, }; -use swc_ecma_visit::{standard_only_fold, Fold, FoldWith, VisitWith}; +use swc_ecma_visit::{fold_pass, standard_only_fold, Fold, FoldWith, VisitWith}; use crate::{ path::Resolver, @@ -42,7 +42,7 @@ struct SystemJs { } pub fn system_js(resolver: Resolver, unresolved_mark: Mark, config: Config) -> impl Pass { - SystemJs { + fold_pass(SystemJs { unresolved_mark, resolver, config, @@ -57,7 +57,7 @@ pub fn system_js(resolver: Resolver, unresolved_mark: Mark, config: Config) -> i import_idents: Vec::new(), export_ident: private_ident!("_export"), context_ident: private_ident!("_context"), - } + }) } struct ModuleItemMeta { diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs b/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs index 940faab74980..32fa5d3f5179 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/mod.rs @@ -3,7 +3,7 @@ use swc_common::{ pass::{CompilerPass, Repeat, Repeated}, Mark, }; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; pub use self::{ branch::dead_branch_remover, From 2ed695d69dc5531011c96c7459bd202935cbe9ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 21:52:41 +0900 Subject: [PATCH 138/186] Fix more --- crates/swc_ecma_compat_bugfixes/src/lib.rs | 2 +- crates/swc_ecma_compat_es2018/src/lib.rs | 2 +- crates/swc_ecma_compat_es2018/src/object_rest_spread.rs | 2 +- crates/swc_ecma_compat_es2020/src/lib.rs | 2 +- crates/swc_ecma_compat_es2022/src/lib.rs | 2 +- crates/swc_ecma_compat_es3/src/lib.rs | 2 +- crates/swc_ecma_transforms_base/benches/base.rs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/swc_ecma_compat_bugfixes/src/lib.rs b/crates/swc_ecma_compat_bugfixes/src/lib.rs index 429e2591cbd1..385775e0720d 100644 --- a/crates/swc_ecma_compat_bugfixes/src/lib.rs +++ b/crates/swc_ecma_compat_bugfixes/src/lib.rs @@ -1,5 +1,5 @@ use swc_common::Mark; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; pub use self::{ async_arrows_in_class::async_arrows_in_class, edge_default_param::edge_default_param, diff --git a/crates/swc_ecma_compat_es2018/src/lib.rs b/crates/swc_ecma_compat_es2018/src/lib.rs index b1514830d189..2495f17e23bf 100644 --- a/crates/swc_ecma_compat_es2018/src/lib.rs +++ b/crates/swc_ecma_compat_es2018/src/lib.rs @@ -2,7 +2,7 @@ #![allow(clippy::boxed_local)] use serde::Deserialize; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_compat_common::regexp::{self, regexp}; pub use self::object_rest_spread::object_rest_spread; diff --git a/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs b/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs index 196999b91e40..a591ad19d766 100644 --- a/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs +++ b/crates/swc_ecma_compat_es2018/src/object_rest_spread.rs @@ -1,5 +1,5 @@ use serde::Deserialize; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_visit::visit_mut_pass; use crate::{object_rest::ObjectRest, object_spread::ObjectSpread}; diff --git a/crates/swc_ecma_compat_es2020/src/lib.rs b/crates/swc_ecma_compat_es2020/src/lib.rs index e64c6f9dd2a1..67a811850b69 100644 --- a/crates/swc_ecma_compat_es2020/src/lib.rs +++ b/crates/swc_ecma_compat_es2020/src/lib.rs @@ -1,6 +1,6 @@ use serde::Deserialize; use swc_common::Mark; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; pub use self::{ export_namespace_from::export_namespace_from, nullish_coalescing::nullish_coalescing, diff --git a/crates/swc_ecma_compat_es2022/src/lib.rs b/crates/swc_ecma_compat_es2022/src/lib.rs index 937cdc5111db..6c8178140edc 100644 --- a/crates/swc_ecma_compat_es2022/src/lib.rs +++ b/crates/swc_ecma_compat_es2022/src/lib.rs @@ -1,7 +1,7 @@ #![allow(clippy::vec_box)] use swc_common::Mark; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_compat_common::regexp::{self, regexp}; pub use self::{ diff --git a/crates/swc_ecma_compat_es3/src/lib.rs b/crates/swc_ecma_compat_es3/src/lib.rs index 861a5c5ce974..a93ccd6de627 100644 --- a/crates/swc_ecma_compat_es3/src/lib.rs +++ b/crates/swc_ecma_compat_es3/src/lib.rs @@ -1,4 +1,4 @@ -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; pub use self::{ member_expr_lits::member_expression_literals, prop_lits::property_literals, diff --git a/crates/swc_ecma_transforms_base/benches/base.rs b/crates/swc_ecma_transforms_base/benches/base.rs index 2525492f53c4..b263f3224faf 100644 --- a/crates/swc_ecma_transforms_base/benches/base.rs +++ b/crates/swc_ecma_transforms_base/benches/base.rs @@ -4,7 +4,7 @@ extern crate swc_malloc; use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; use swc_common::{errors::HANDLER, FileName, Mark}; -use swc_ecma_ast::{chain, Program}; +use swc_ecma_ast::Program; use swc_ecma_parser::{Parser, StringInput, Syntax}; use swc_ecma_transforms_base::helpers; From f7f3f0447145632e425b3694f13bdca9cd419674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 21:54:36 +0900 Subject: [PATCH 139/186] Fix more --- .../swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs | 1 - crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs | 1 - ...ari_id_destructuring_collision_in_function_expression.rs | 1 - .../src/template_literal_caching.rs | 1 - crates/swc_ecma_compat_es2015/src/object_super.rs | 1 - crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs | 2 +- crates/swc_ecma_transforms/tests/decorators.rs | 1 - crates/swc_ecma_transforms/tests/deno.rs | 1 - crates/swc_ecma_transforms/tests/es2015_function_name.rs | 1 - .../tests/es2015_block_scoping.rs | 2 +- crates/swc_ecma_transforms_compat/tests/es2015_classes.rs | 2 +- crates/swc_ecma_transforms_compat/tests/es2015_spread.rs | 1 - .../tests/es2022_static_blocks.rs | 4 ++-- crates/swc_ecma_transforms_module/tests/common_js.rs | 1 - crates/swc_ecma_transforms_module/tests/system_js.rs | 1 - crates/swc_ecma_transforms_module/tests/umd.rs | 1 - .../src/simplify/branch/tests.rs | 1 - .../src/simplify/expr/tests.rs | 1 - .../tests/simplify_inlining.rs | 1 - crates/swc_ecma_transforms_proposal/src/decorators/mod.rs | 6 ++++-- .../tests/explicit_resource_management.rs | 1 - crates/swc_ecma_transforms_proposal/tests/export.rs | 1 - crates/swc_ecma_transforms_react/src/jsx/tests.rs | 1 - crates/swc_ecma_transforms_react/src/refresh/tests.rs | 1 - crates/swc_ecma_transforms_testing/src/babel_like.rs | 2 +- 25 files changed, 10 insertions(+), 27 deletions(-) diff --git a/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs b/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs index 9fe28a234c7c..278a44022991 100644 --- a/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs +++ b/crates/swc_ecma_compat_bugfixes/src/async_arrows_in_class.rs @@ -106,7 +106,6 @@ impl Fold for AsyncArrowsInClass { #[cfg(test)] mod tests { - use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::test; diff --git a/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs b/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs index 5e88b0868afd..73ff3be97d92 100644 --- a/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs +++ b/crates/swc_ecma_compat_bugfixes/src/edge_default_param.rs @@ -63,7 +63,6 @@ impl VisitMut for EdgeDefaultParam { #[cfg(test)] mod tests { use swc_common::Mark; - use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::test; diff --git a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs index 66e911458899..3a69251d7fa6 100644 --- a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs +++ b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs @@ -104,7 +104,6 @@ impl VisitMut for SafariIdDestructuringCollisionInFunctionExpression { #[cfg(test)] mod tests { use swc_common::Mark; - use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::{test, HygieneTester}; diff --git a/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs b/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs index 448ac354e200..1f5cb6a008c3 100644 --- a/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs +++ b/crates/swc_ecma_compat_bugfixes/src/template_literal_caching.rs @@ -162,7 +162,6 @@ impl Fold for TemplateLiteralCaching { #[cfg(test)] mod tests { use swc_common::Mark; - use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::test; diff --git a/crates/swc_ecma_compat_es2015/src/object_super.rs b/crates/swc_ecma_compat_es2015/src/object_super.rs index a5fbb5ed7e4f..85b4fea6d3f1 100644 --- a/crates/swc_ecma_compat_es2015/src/object_super.rs +++ b/crates/swc_ecma_compat_es2015/src/object_super.rs @@ -485,7 +485,6 @@ impl SuperReplacer { #[cfg(test)] mod tests { use swc_common::Mark; - use swc_ecma_ast::chain; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::test; diff --git a/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs b/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs index 84ebad25cb12..5eeede447ba4 100644 --- a/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs +++ b/crates/swc_ecma_compat_es2019/src/optional_catch_binding.rs @@ -26,7 +26,7 @@ impl VisitMut for OptionalCatchBinding { #[cfg(test)] mod tests { use swc_common::Mark; - use swc_ecma_ast::{chain, Pass}; + use swc_ecma_ast::Pass; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::test; use swc_ecma_visit::visit_mut_pass; diff --git a/crates/swc_ecma_transforms/tests/decorators.rs b/crates/swc_ecma_transforms/tests/decorators.rs index 4a8d8e64af5c..c08ad0f63fe1 100644 --- a/crates/swc_ecma_transforms/tests/decorators.rs +++ b/crates/swc_ecma_transforms/tests/decorators.rs @@ -8,7 +8,6 @@ use std::{fs, path::PathBuf}; use swc_common::Mark; -use swc_ecma_ast::chain; use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ diff --git a/crates/swc_ecma_transforms/tests/deno.rs b/crates/swc_ecma_transforms/tests/deno.rs index 2cb30113e01a..2f2cc81062e9 100644 --- a/crates/swc_ecma_transforms/tests/deno.rs +++ b/crates/swc_ecma_transforms/tests/deno.rs @@ -5,7 +5,6 @@ use std::path::PathBuf; use swc_common::Mark; -use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms::{fixer, helpers::inject_helpers, hygiene, resolver}; use swc_ecma_transforms_proposal::{ diff --git a/crates/swc_ecma_transforms/tests/es2015_function_name.rs b/crates/swc_ecma_transforms/tests/es2015_function_name.rs index be4e3331782f..7419265be448 100644 --- a/crates/swc_ecma_transforms/tests/es2015_function_name.rs +++ b/crates/swc_ecma_transforms/tests/es2015_function_name.rs @@ -6,7 +6,6 @@ ))] use swc_common::Mark; -use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs b/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs index 950eb875b344..ee101bc7317c 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs @@ -1,7 +1,7 @@ use std::{fs::read_to_string, path::PathBuf}; use swc_common::{Mark, SyntaxContext}; -use swc_ecma_ast::{chain, Ident, PropName, TsQualifiedName}; +use swc_ecma_ast::{Ident, Pass, PropName, TsQualifiedName}; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs b/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs index d19d862ab938..0067e32bb492 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs @@ -1,7 +1,7 @@ use std::{fs::read_to_string, path::PathBuf}; use swc_common::Mark; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs b/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs index 4c470ee57674..9e8332f15dff 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs @@ -1,5 +1,4 @@ use swc_common::Mark; -use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2015::{block_scoping, parameters, spread}; use swc_ecma_transforms_testing::{test, test_exec}; diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs b/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs index 3b69030047bb..e671597fa7aa 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use swc_common::Mark; -use swc_ecma_ast::chain; +use swc_ecma_ast::{chain, Pass}; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2022::{class_properties, static_blocks}; @@ -20,7 +20,7 @@ fn fixture(input: PathBuf) { let top_level_mark = Mark::new(); let config = class_properties::Config::default(); - let pass: Box = if input.to_string_lossy().contains("class-properties") { + let pass: Box = if input.to_string_lossy().contains("class-properties") { Box::new(( resolver(unresolved_mark, top_level_mark, false), static_blocks(config.static_blocks_mark), diff --git a/crates/swc_ecma_transforms_module/tests/common_js.rs b/crates/swc_ecma_transforms_module/tests/common_js.rs index f4f1076bc229..df4c63bf870b 100644 --- a/crates/swc_ecma_transforms_module/tests/common_js.rs +++ b/crates/swc_ecma_transforms_module/tests/common_js.rs @@ -1,7 +1,6 @@ use std::{fs::File, path::PathBuf}; use swc_common::Mark; -use swc_ecma_ast::chain; use swc_ecma_parser::{Syntax, TsSyntax}; use swc_ecma_transforms_base::{feature::FeatureFlag, resolver}; use swc_ecma_transforms_compat::es2015::for_of; diff --git a/crates/swc_ecma_transforms_module/tests/system_js.rs b/crates/swc_ecma_transforms_module/tests/system_js.rs index 04226883e0b0..c700542b783e 100644 --- a/crates/swc_ecma_transforms_module/tests/system_js.rs +++ b/crates/swc_ecma_transforms_module/tests/system_js.rs @@ -3,7 +3,6 @@ use std::path::PathBuf; use swc_common::Mark; -use swc_ecma_ast::chain; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_module::system_js::{system_js, Config}; diff --git a/crates/swc_ecma_transforms_module/tests/umd.rs b/crates/swc_ecma_transforms_module/tests/umd.rs index 77568b5bd32f..3e48da63bb97 100644 --- a/crates/swc_ecma_transforms_module/tests/umd.rs +++ b/crates/swc_ecma_transforms_module/tests/umd.rs @@ -1,7 +1,6 @@ use std::{fs::File, path::PathBuf}; use swc_common::Mark; -use swc_ecma_ast::chain; use swc_ecma_parser::{Syntax, TsSyntax}; use swc_ecma_transforms_base::{feature::FeatureFlag, resolver}; use swc_ecma_transforms_module::umd::{umd, Config}; diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs b/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs index 41fee78061ec..8754ac202cf8 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/branch/tests.rs @@ -1,5 +1,4 @@ use swc_common::{Mark, SyntaxContext}; -use swc_ecma_ast::chain; use swc_ecma_transforms_base::{fixer::paren_remover, resolver}; use swc_ecma_utils::ExprCtx; use swc_ecma_visit::visit_mut_pass; diff --git a/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs b/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs index 254736a5dace..155b21fe5ca3 100644 --- a/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs +++ b/crates/swc_ecma_transforms_optimization/src/simplify/expr/tests.rs @@ -1,5 +1,4 @@ use swc_common::{Mark, SyntaxContext}; -use swc_ecma_ast::chain; use swc_ecma_transforms_base::{fixer::paren_remover, resolver}; use swc_ecma_transforms_testing::test_transform; use swc_ecma_utils::ExprCtx; diff --git a/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs b/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs index 909bdf245025..87bb20171281 100644 --- a/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs +++ b/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs @@ -1,7 +1,6 @@ //! Copied from https://github.com/google/closure-compiler/blob/6ca3b62990064488074a1a8931b9e8dc39b148b3/test/com/google/javascript/jscomp/InlineVariablesTest.java use swc_common::Mark; -use swc_ecma_ast::chain; use swc_ecma_parser::{Syntax, TsSyntax}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2022::class_properties; diff --git a/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs b/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs index a3c696622928..303677548331 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorators/mod.rs @@ -10,7 +10,9 @@ use swc_ecma_utils::{ alias_ident_for, constructor::inject_after_super, default_constructor, prepend_stmt, private_ident, prop_name_to_expr, prop_name_to_expr_value, quote_ident, quote_str, ExprFactory, }; -use swc_ecma_visit::{fold_pass, noop_fold_type, visit_mut_pass, Fold, FoldWith, Visit, VisitWith}; +use swc_ecma_visit::{ + fold_pass, noop_fold_type, visit_mut_pass, Fold, FoldWith, Visit, VisitMutWith, VisitWith, +}; mod legacy; @@ -330,7 +332,7 @@ impl Decorators { macro_rules! fold_method { ($method:expr, $fn_name:expr, $key_prop_value:expr) => {{ let fn_name = $fn_name; - let method = $method; + let mut method = $method; let mut folder = SuperFieldAccessFolder { class_name: &ident, constructor_this_mark: None, diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit_resource_management.rs b/crates/swc_ecma_transforms_proposal/tests/explicit_resource_management.rs index 45ff022240c9..3f98b812b714 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit_resource_management.rs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit_resource_management.rs @@ -1,7 +1,6 @@ use std::{fs::read_to_string, path::PathBuf}; use swc_common::Mark; -use swc_ecma_ast::chain; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_proposal::explicit_resource_management::explicit_resource_management; diff --git a/crates/swc_ecma_transforms_proposal/tests/export.rs b/crates/swc_ecma_transforms_proposal/tests/export.rs index d3547982f248..b1221f358d79 100644 --- a/crates/swc_ecma_transforms_proposal/tests/export.rs +++ b/crates/swc_ecma_transforms_proposal/tests/export.rs @@ -1,4 +1,3 @@ -use swc_ecma_ast::chain; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_compat::es2020::export_namespace_from; use swc_ecma_transforms_proposal::export_default_from; diff --git a/crates/swc_ecma_transforms_react/src/jsx/tests.rs b/crates/swc_ecma_transforms_react/src/jsx/tests.rs index e0d1397cbc16..d22aee8caccc 100644 --- a/crates/swc_ecma_transforms_react/src/jsx/tests.rs +++ b/crates/swc_ecma_transforms_react/src/jsx/tests.rs @@ -5,7 +5,6 @@ use std::{ path::{Path, PathBuf}, }; -use swc_ecma_ast::chain; use swc_ecma_codegen::{Config, Emitter}; use swc_ecma_parser::{EsSyntax, Parser, StringInput}; use swc_ecma_transforms_base::{fixer::fixer, hygiene, resolver}; diff --git a/crates/swc_ecma_transforms_react/src/refresh/tests.rs b/crates/swc_ecma_transforms_react/src/refresh/tests.rs index bb8a74d8b125..49958ceafdf1 100644 --- a/crates/swc_ecma_transforms_react/src/refresh/tests.rs +++ b/crates/swc_ecma_transforms_react/src/refresh/tests.rs @@ -1,4 +1,3 @@ -use swc_ecma_ast::chain; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::{test, Tester}; diff --git a/crates/swc_ecma_transforms_testing/src/babel_like.rs b/crates/swc_ecma_transforms_testing/src/babel_like.rs index b40a080b23a1..dad9d68a5542 100644 --- a/crates/swc_ecma_transforms_testing/src/babel_like.rs +++ b/crates/swc_ecma_transforms_testing/src/babel_like.rs @@ -4,7 +4,7 @@ use ansi_term::Color; use serde::Deserialize; use serde_json::Value; use swc_common::{comments::SingleThreadedComments, sync::Lrc, Mark, SourceMap}; -use swc_ecma_ast::{chain, EsVersion, Pass, Program}; +use swc_ecma_ast::{EsVersion, Pass, Program}; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{parse_file_as_program, Syntax}; use swc_ecma_transforms_base::{ From 15de1f33a5db99dd7314f0b1c62bce6b40aa2b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 21:54:51 +0900 Subject: [PATCH 140/186] replace --- crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs | 2 +- crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs | 2 +- crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs | 2 +- crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs | 2 +- crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs | 2 +- .../tests/es2018_object_rest_spread.rs | 2 +- .../tests/es2020_optional_chaining.rs | 2 +- .../swc_ecma_transforms_compat/tests/es2022_class_properties.rs | 2 +- .../tests/es2022_private_in_object.rs | 2 +- crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs index 7abec6854516..1815098f6983 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_arrow.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use swc_common::Mark; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2015::arrow; use swc_ecma_transforms_testing::{compare_stdout, test_fixture}; diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs b/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs index 642a26999895..028b313215d8 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_destructuring.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use swc_common::Mark; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs index 938b1a353f0e..e94a3cd35a14 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs @@ -2,7 +2,7 @@ use std::{fs::read_to_string, path::PathBuf}; use serde::Deserialize; use swc_common::Mark; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ es2015::{arrow, classes, new_target::new_target}, diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs b/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs index 1abae93639de..8f2ef597c53d 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs @@ -1,5 +1,5 @@ use swc_common::Mark; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2015::{function_name, object_super, shorthand}; diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs b/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs index 07032bbc4508..ef1040978b6b 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_parameters.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use swc_common::Mark; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ diff --git a/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs b/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs index dd9cbc9e07d7..f61dfd103033 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2018_object_rest_spread.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use swc_common::Mark; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ diff --git a/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs b/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs index dd079eef17ef..338c9eed32d0 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2020_optional_chaining.rs @@ -1,7 +1,7 @@ use std::{fs::read_to_string, path::PathBuf}; use swc_common::Mark; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs b/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs index 2d7428503d64..e82c1efd4a5a 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs @@ -3,7 +3,7 @@ use std::{fs::read_to_string, path::PathBuf}; use swc_common::Mark; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs b/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs index 62b5fd92d03b..f2d519529ff2 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use serde::Deserialize; use swc_common::Mark; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ es2015::classes, diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs b/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs index e671597fa7aa..0dd48d6a0a9a 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use swc_common::Mark; -use swc_ecma_ast::{chain, Pass}; +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2022::{class_properties, static_blocks}; From 6ac173be57b2f472c83db5131ae2a53911e76e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 21:57:04 +0900 Subject: [PATCH 141/186] More fix --- crates/swc_ecma_transforms_compat/tests/es2015_generator.rs | 2 +- crates/swc_ecma_transforms_compat/tests/es2015_spread.rs | 2 +- .../tests/es2015_template_literals.rs | 2 +- .../tests/es2017_async_to_generator.rs | 6 +++--- .../tests/es2020_nullish_coalescing.rs | 2 +- crates/swc_ecma_transforms_module/tests/amd.rs | 4 ++-- crates/swc_ecma_transforms_module/tests/common_js.rs | 2 +- crates/swc_ecma_transforms_module/tests/system_js.rs | 2 +- crates/swc_ecma_transforms_module/tests/umd.rs | 2 +- crates/swc_ecma_transforms_proposal/tests/decorators.rs | 5 +++-- 10 files changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs b/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs index 4e4f1792de44..5713c78c7396 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs @@ -4,6 +4,7 @@ use swc_common::{ comments::{NoopComments, SingleThreadedComments}, Mark, }; +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -11,7 +12,6 @@ use swc_ecma_transforms_compat::{ es2021, es2022, }; use swc_ecma_transforms_testing::{test, test_exec}; -use swc_ecma_visit::Fold; fn syntax() -> Syntax { Syntax::default() diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs b/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs index 9e8332f15dff..af98530f1888 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_spread.rs @@ -1,8 +1,8 @@ use swc_common::Mark; +use swc_ecma_ast::Pass; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2015::{block_scoping, parameters, spread}; use swc_ecma_transforms_testing::{test, test_exec}; -use swc_ecma_visit::Fold; fn syntax() -> ::swc_ecma_parser::Syntax { Default::default() diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_template_literals.rs b/crates/swc_ecma_transforms_compat/tests/es2015_template_literals.rs index b1fda9fd9435..d459f0da7b90 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_template_literals.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_template_literals.rs @@ -1,7 +1,7 @@ +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_compat::es2015::template_literal; use swc_ecma_transforms_testing::{test, test_exec}; -use swc_ecma_visit::Fold; fn syntax() -> Syntax { Default::default() diff --git a/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs b/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs index 38662e12d490..3b25257b3d43 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs @@ -1,6 +1,6 @@ use std::{fs::read_to_string, path::PathBuf}; -use swc_common::{chain, Mark, Spanned}; +use swc_common::{Mark, Spanned}; use swc_ecma_ast::*; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::{fixer::fixer, resolver}; @@ -13,7 +13,7 @@ use swc_ecma_transforms_compat::{ es2022::class_properties, }; use swc_ecma_transforms_testing::{compare_stdout, test, test_exec}; -use swc_ecma_visit::{Fold, FoldWith}; +use swc_ecma_visit::{fold_pass, Fold, FoldWith}; struct ParenRemover; impl Fold for ParenRemover { @@ -44,7 +44,7 @@ fn tr() -> impl Pass { ( resolver(unresolved_mark, top_level_mark, false), - ParenRemover, + fold_pass(ParenRemover), arrow(unresolved_mark), parameters(Default::default(), unresolved_mark), destructuring(destructuring::Config { loose: false }), diff --git a/crates/swc_ecma_transforms_compat/tests/es2020_nullish_coalescing.rs b/crates/swc_ecma_transforms_compat/tests/es2020_nullish_coalescing.rs index 738e62d9b37b..a63b13e58f3f 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2020_nullish_coalescing.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2020_nullish_coalescing.rs @@ -1,7 +1,7 @@ +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_compat::es2020::nullish_coalescing::{nullish_coalescing, Config}; use swc_ecma_transforms_testing::{compare_stdout, test, test_exec}; -use swc_ecma_visit::Fold; fn tr(c: Config) -> impl Pass { nullish_coalescing(c) diff --git a/crates/swc_ecma_transforms_module/tests/amd.rs b/crates/swc_ecma_transforms_module/tests/amd.rs index 4c048c662fe3..faf7a4e327d1 100644 --- a/crates/swc_ecma_transforms_module/tests/amd.rs +++ b/crates/swc_ecma_transforms_module/tests/amd.rs @@ -1,13 +1,13 @@ use std::{fs::File, path::PathBuf, rc::Rc}; -use swc_common::{chain, comments::SingleThreadedComments, Mark}; +use swc_common::{comments::SingleThreadedComments, Mark}; +use swc_ecma_ast::Pass; use swc_ecma_parser::{Syntax, TsSyntax}; use swc_ecma_transforms_base::{feature::FeatureFlag, resolver}; use swc_ecma_transforms_compat::es2015::for_of; use swc_ecma_transforms_module::amd::{self, amd}; use swc_ecma_transforms_testing::{test, test_fixture, FixtureTestConfig}; use swc_ecma_transforms_typescript::typescript; -use swc_ecma_visit::Fold; fn syntax() -> Syntax { Default::default() diff --git a/crates/swc_ecma_transforms_module/tests/common_js.rs b/crates/swc_ecma_transforms_module/tests/common_js.rs index df4c63bf870b..83bc7fcae1f5 100644 --- a/crates/swc_ecma_transforms_module/tests/common_js.rs +++ b/crates/swc_ecma_transforms_module/tests/common_js.rs @@ -1,13 +1,13 @@ use std::{fs::File, path::PathBuf}; use swc_common::Mark; +use swc_ecma_ast::Pass; use swc_ecma_parser::{Syntax, TsSyntax}; use swc_ecma_transforms_base::{feature::FeatureFlag, resolver}; use swc_ecma_transforms_compat::es2015::for_of; use swc_ecma_transforms_module::common_js::{self, common_js}; use swc_ecma_transforms_testing::{test, test_fixture, FixtureTestConfig}; use swc_ecma_transforms_typescript::typescript; -use swc_ecma_visit::Fold; fn syntax() -> Syntax { Default::default() diff --git a/crates/swc_ecma_transforms_module/tests/system_js.rs b/crates/swc_ecma_transforms_module/tests/system_js.rs index c700542b783e..1526f683753b 100644 --- a/crates/swc_ecma_transforms_module/tests/system_js.rs +++ b/crates/swc_ecma_transforms_module/tests/system_js.rs @@ -3,11 +3,11 @@ use std::path::PathBuf; use swc_common::Mark; +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_module::system_js::{system_js, Config}; use swc_ecma_transforms_testing::{test, test_fixture, FixtureTestConfig, Tester}; -use swc_ecma_visit::Fold; fn syntax() -> Syntax { Syntax::Es(Default::default()) diff --git a/crates/swc_ecma_transforms_module/tests/umd.rs b/crates/swc_ecma_transforms_module/tests/umd.rs index 3e48da63bb97..f811a5962c87 100644 --- a/crates/swc_ecma_transforms_module/tests/umd.rs +++ b/crates/swc_ecma_transforms_module/tests/umd.rs @@ -1,12 +1,12 @@ use std::{fs::File, path::PathBuf}; use swc_common::Mark; +use swc_ecma_ast::Pass; use swc_ecma_parser::{Syntax, TsSyntax}; use swc_ecma_transforms_base::{feature::FeatureFlag, resolver}; use swc_ecma_transforms_module::umd::{umd, Config}; use swc_ecma_transforms_testing::{test_fixture, FixtureTestConfig, Tester}; use swc_ecma_transforms_typescript::typescript; -use swc_ecma_visit::Fold; fn syntax() -> Syntax { Default::default() diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators.rs b/crates/swc_ecma_transforms_proposal/tests/decorators.rs index 257d3393a174..fadd428855a5 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators.rs +++ b/crates/swc_ecma_transforms_proposal/tests/decorators.rs @@ -7,6 +7,7 @@ use std::{ use serde::Deserialize; use swc_common::{chain, comments::SingleThreadedComments, Mark}; +use swc_ecma_ast::Pass; use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax}; use swc_ecma_transforms_base::{assumptions::Assumptions, resolver}; use swc_ecma_transforms_proposal::{decorator_2022_03::decorator_2022_03, DecoratorVersion}; @@ -111,14 +112,14 @@ enum BabelPluginOption { Decorator { version: DecoratorVersion }, } -fn create_pass(comments: Rc, input: &Path) -> Box { +fn create_pass(comments: Rc, input: &Path) -> Box { let options_json: BabelTestOptions = swc_ecma_transforms_testing::parse_options(input.parent().unwrap()); let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - let mut pass: Box = Box::new(resolver(unresolved_mark, top_level_mark, false)); + let mut pass: Box = Box::new(resolver(unresolved_mark, top_level_mark, false)); macro_rules! add { ($e:expr) => {{ From 1a519e52d339f0a29363b91dc79b8dcdc8d69208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 21:57:44 +0900 Subject: [PATCH 142/186] More fix --- .../benches/compat.rs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/swc_ecma_transforms_typescript/benches/compat.rs b/crates/swc_ecma_transforms_typescript/benches/compat.rs index d354cc00d01e..592ed4be77ee 100644 --- a/crates/swc_ecma_transforms_typescript/benches/compat.rs +++ b/crates/swc_ecma_transforms_typescript/benches/compat.rs @@ -1,10 +1,10 @@ use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; use swc_common::{chain, comments::SingleThreadedComments, sync::Lrc, FileName, Mark, SourceMap}; -use swc_ecma_ast::{Module, Program}; +use swc_ecma_ast::{Module, Pass, Program}; use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax}; use swc_ecma_transforms_base::{helpers, resolver}; use swc_ecma_transforms_typescript::strip; -use swc_ecma_visit::{Fold, FoldWith}; +use swc_ecma_visit::{fold_pass, Fold, FoldWith}; static SOURCE: &str = include_str!("assets/AjaxObservable.ts"); @@ -27,15 +27,15 @@ fn module(cm: Lrc) -> Program { fn run(b: &mut Bencher, tr: impl Fn(Mark) -> V) where - V: Fold, + V: Pass, { let _ = ::testing::run_test(false, |cm, _| { let module = module(cm); let unresolved_mark = Mark::fresh(Mark::root()); let top_level_mark = Mark::fresh(Mark::root()); let module = module - .fold_with(&mut resolver(unresolved_mark, top_level_mark, true)) - .fold_with(&mut strip(unresolved_mark, top_level_mark)); + .apply(resolver(unresolved_mark, top_level_mark, true)) + .apply(strip(unresolved_mark, top_level_mark)); b.iter(|| { let module = module.clone(); @@ -43,7 +43,7 @@ where helpers::HELPERS.set(&Default::default(), || { let mut tr = tr(unresolved_mark); - black_box(module.fold_with(&mut tr)); + black_box(module.apply(tr)); }); }); @@ -77,14 +77,14 @@ fn common_typescript(b: &mut Bencher) { let unresolved_mark = Mark::fresh(Mark::root()); let top_level_mark = Mark::fresh(Mark::root()); let module = module - .fold_with(&mut resolver(unresolved_mark, top_level_mark, true)) - .fold_with(&mut strip(unresolved_mark, top_level_mark)); + .apply(resolver(unresolved_mark, top_level_mark, true)) + .apply(strip(unresolved_mark, top_level_mark)); b.iter(|| { let module = module.clone(); helpers::HELPERS.set(&Default::default(), || { - black_box(module.fold_with(&mut strip(unresolved_mark, top_level_mark))); + black_box(module.apply(strip(unresolved_mark, top_level_mark))); }); }); @@ -94,7 +94,7 @@ fn common_typescript(b: &mut Bencher) { fn common_reserved_word(b: &mut Bencher) { run(b, |_| { - swc_ecma_transforms_compat::reserved_words::reserved_words() + fold_pass(swc_ecma_transforms_compat::reserved_words::reserved_words()) }); } From 7291cfea7c5ab7cabf40ed97b8425676b1b59d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 21:59:10 +0900 Subject: [PATCH 143/186] More fix --- .../tests/es2015_object_super.rs | 1 - crates/swc_ecma_transforms_proposal/tests/export.rs | 1 + crates/swc_ecma_transforms_react/src/jsx/tests.rs | 2 +- crates/swc_ecma_transforms_typescript/benches/compat.rs | 2 +- .../swc_ecma_transforms_typescript/examples/ts_to_js.rs | 9 ++++----- crates/swc_ecma_transforms_typescript/tests/strip.rs | 4 ++-- .../tests/strip_correctness.rs | 8 ++++---- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs b/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs index 8f2ef597c53d..f2b731a0681c 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs @@ -4,7 +4,6 @@ use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2015::{function_name, object_super, shorthand}; use swc_ecma_transforms_testing::test; -use swc_ecma_visit::Fold; fn syntax() -> Syntax { ::swc_ecma_parser::Syntax::default() diff --git a/crates/swc_ecma_transforms_proposal/tests/export.rs b/crates/swc_ecma_transforms_proposal/tests/export.rs index b1221f358d79..3d115c4bb61c 100644 --- a/crates/swc_ecma_transforms_proposal/tests/export.rs +++ b/crates/swc_ecma_transforms_proposal/tests/export.rs @@ -1,3 +1,4 @@ +use swc_ecma_ast::Pass; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_compat::es2020::export_namespace_from; use swc_ecma_transforms_proposal::export_default_from; diff --git a/crates/swc_ecma_transforms_react/src/jsx/tests.rs b/crates/swc_ecma_transforms_react/src/jsx/tests.rs index d22aee8caccc..50a4e97520c9 100644 --- a/crates/swc_ecma_transforms_react/src/jsx/tests.rs +++ b/crates/swc_ecma_transforms_react/src/jsx/tests.rs @@ -1125,7 +1125,7 @@ fn test_script(src: &str, output: &Path, options: Options) { let top_level_mark = Mark::new(); let unresolved_mark = Mark::new(); - let script = script.fold_with(&mut ( + let script = Program::Script(script).apply(( resolver(Mark::new(), top_level_mark, false), react( tester.cm.clone(), diff --git a/crates/swc_ecma_transforms_typescript/benches/compat.rs b/crates/swc_ecma_transforms_typescript/benches/compat.rs index 592ed4be77ee..f765687cefbe 100644 --- a/crates/swc_ecma_transforms_typescript/benches/compat.rs +++ b/crates/swc_ecma_transforms_typescript/benches/compat.rs @@ -94,7 +94,7 @@ fn common_typescript(b: &mut Bencher) { fn common_reserved_word(b: &mut Bencher) { run(b, |_| { - fold_pass(swc_ecma_transforms_compat::reserved_words::reserved_words()) + swc_ecma_transforms_compat::reserved_words::reserved_words() }); } diff --git a/crates/swc_ecma_transforms_typescript/examples/ts_to_js.rs b/crates/swc_ecma_transforms_typescript/examples/ts_to_js.rs index 48585b609bd2..793b35ae66b6 100644 --- a/crates/swc_ecma_transforms_typescript/examples/ts_to_js.rs +++ b/crates/swc_ecma_transforms_typescript/examples/ts_to_js.rs @@ -14,7 +14,6 @@ use swc_ecma_codegen::to_code_default; use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax, TsSyntax}; use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene, resolver}; use swc_ecma_transforms_typescript::strip; -use swc_ecma_visit::FoldWith; fn main() { let cm: Lrc = Default::default(); @@ -65,16 +64,16 @@ fn main() { // as it might produce runtime declarations. // Conduct identifier scope analysis - let module = module.fold_with(&mut resolver(unresolved_mark, top_level_mark, true)); + let module = module.apply(resolver(unresolved_mark, top_level_mark, true)); // Remove typescript types - let module = module.fold_with(&mut strip(unresolved_mark, top_level_mark)); + let module = module.apply(strip(unresolved_mark, top_level_mark)); // Fix up any identifiers with the same name, but different contexts - let module = module.fold_with(&mut hygiene()); + let module = module.apply(hygiene()); // Ensure that we have enough parenthesis. - let program = module.fold_with(&mut fixer(Some(&comments))); + let program = module.apply(fixer(Some(&comments))); println!("{}", to_code_default(cm, Some(&comments), &program)); }) diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 71959cf6a988..4a63ca020170 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; -use swc_common::{chain, comments::NoopComments, pass::Optional, Mark}; +use swc_common::{comments::NoopComments, pass::Optional, Mark}; +use swc_ecma_ast::Pass; use swc_ecma_parser::{Syntax, TsSyntax}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -16,7 +17,6 @@ use swc_ecma_transforms_testing::{test, test_exec, test_fixture, Tester}; use swc_ecma_transforms_typescript::{ tsx, typescript, ImportsNotUsedAsValues, TsImportExportAssignConfig, TsxConfig, }; -use swc_ecma_visit::Fold; fn tr(t: &mut Tester) -> impl Pass { tr_config(t, None, None, false) diff --git a/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs b/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs index db01f04c1e40..2ae131716e6e 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs @@ -101,8 +101,8 @@ fn identity(entry: PathBuf) { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); Program::Module(p) - .fold_with(&mut resolver(unresolved_mark, top_level_mark, true)) - .fold_with(&mut typescript( + .apply(resolver(unresolved_mark, top_level_mark, true)) + .apply(typescript( typescript::Config { no_empty_export: true, ..Default::default() @@ -110,8 +110,8 @@ fn identity(entry: PathBuf) { unresolved_mark, top_level_mark, )) - .fold_with(&mut hygiene()) - .fold_with(&mut fixer(None)) + .apply(hygiene()) + .apply(fixer(None)) }) .map_err(|e| { eprintln!("failed to parse as typescript module"); From 2c3c7d75556cf7fffa8ae961970bb91d217b21bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:01:13 +0900 Subject: [PATCH 144/186] More fix --- .../swc_ecma_transforms_compat/tests/es2015_block_scoping.rs | 2 +- crates/swc_ecma_transforms_compat/tests/es2015_classes.rs | 1 - crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs | 1 - .../tests/es2021_logcal_assignments.rs | 1 - .../tests/es2022_private_in_object.rs | 1 - .../swc_ecma_transforms_compat/tests/es2022_static_blocks.rs | 1 - crates/swc_ecma_transforms_proposal/tests/export.rs | 1 - .../swc_ecma_transforms_proposal/tests/import_assertions.rs | 2 +- crates/swc_ecma_transforms_react/src/jsx/tests.rs | 3 +-- .../swc_ecma_transforms_react/src/pure_annotations/tests.rs | 1 - crates/swc_ecma_transforms_testing/tests/visited.rs | 4 ++-- crates/swc_ecma_transforms_typescript/benches/compat.rs | 2 +- crates/swc_ecma_transforms_typescript/tests/strip.rs | 1 - 13 files changed, 6 insertions(+), 15 deletions(-) diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs b/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs index ee101bc7317c..4895e2babc71 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_block_scoping.rs @@ -10,7 +10,7 @@ use swc_ecma_transforms_compat::{ es2017::async_to_generator, }; use swc_ecma_transforms_testing::{compare_stdout, test, test_exec, test_fixture, Tester}; -use swc_ecma_visit::{visit_mut_obj_and_computed, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_visit::{visit_mut_obj_and_computed, visit_mut_pass, VisitMut, VisitMutWith}; fn tr() -> impl Pass { let unresolved_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs b/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs index 0067e32bb492..c21e9db1756d 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs @@ -11,7 +11,6 @@ use swc_ecma_transforms_compat::{ es2022::class_properties, }; use swc_ecma_transforms_testing::{compare_stdout, test, test_exec, test_fixture, Tester}; -use swc_ecma_visit::Fold; fn syntax() -> Syntax { Syntax::default() diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs index e94a3cd35a14..c2d2ae4f235a 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs @@ -9,7 +9,6 @@ use swc_ecma_transforms_compat::{ es2022::class_properties, }; use swc_ecma_transforms_testing::{exec_tr, parse_options, test, test_fixture, Tester}; -use swc_ecma_visit::Fold; fn get_passes(_: &Tester, plugins: &[PluginConfig]) -> Box { let unresolved_mark = Mark::new(); diff --git a/crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs b/crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs index cd9bfaba553a..ff8ec09793fa 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2021_logcal_assignments.rs @@ -2,7 +2,6 @@ use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_compat::es2021; use swc_ecma_transforms_testing::{test, test_exec}; -use swc_ecma_visit::Fold; fn tr() -> impl Pass { es2021::logical_assignments() diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs b/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs index f2d519529ff2..14e69c5afe86 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_private_in_object.rs @@ -9,7 +9,6 @@ use swc_ecma_transforms_compat::{ es2022::{class_properties, private_in_object}, }; use swc_ecma_transforms_testing::{parse_options, test_fixture}; -use swc_ecma_visit::Fold; #[derive(Debug, Clone, Deserialize)] #[serde(deny_unknown_fields)] diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs b/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs index 0dd48d6a0a9a..749a0857a322 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_static_blocks.rs @@ -6,7 +6,6 @@ use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2022::{class_properties, static_blocks}; use swc_ecma_transforms_testing::test_fixture; -use swc_ecma_visit::Fold; #[testing::fixture("tests/static-blocks/**/input.js")] fn fixture(input: PathBuf) { diff --git a/crates/swc_ecma_transforms_proposal/tests/export.rs b/crates/swc_ecma_transforms_proposal/tests/export.rs index 3d115c4bb61c..7c68ab27eace 100644 --- a/crates/swc_ecma_transforms_proposal/tests/export.rs +++ b/crates/swc_ecma_transforms_proposal/tests/export.rs @@ -3,7 +3,6 @@ use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_compat::es2020::export_namespace_from; use swc_ecma_transforms_proposal::export_default_from; use swc_ecma_transforms_testing::test; -use swc_ecma_visit::Fold; fn syntax_default() -> Syntax { Syntax::Es(EsSyntax { diff --git a/crates/swc_ecma_transforms_proposal/tests/import_assertions.rs b/crates/swc_ecma_transforms_proposal/tests/import_assertions.rs index 9f90910cf74e..3c9b5abd28eb 100644 --- a/crates/swc_ecma_transforms_proposal/tests/import_assertions.rs +++ b/crates/swc_ecma_transforms_proposal/tests/import_assertions.rs @@ -1,7 +1,7 @@ +use swc_ecma_ast::Pass; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_proposal::import_assertions; use swc_ecma_transforms_testing::test; -use swc_ecma_visit::Fold; fn tr() -> impl Pass { import_assertions() diff --git a/crates/swc_ecma_transforms_react/src/jsx/tests.rs b/crates/swc_ecma_transforms_react/src/jsx/tests.rs index 50a4e97520c9..7b3eb2aee19d 100644 --- a/crates/swc_ecma_transforms_react/src/jsx/tests.rs +++ b/crates/swc_ecma_transforms_react/src/jsx/tests.rs @@ -13,7 +13,6 @@ use swc_ecma_transforms_compat::{ es3::property_literals, }; use swc_ecma_transforms_testing::{parse_options, test, test_fixture, FixtureTestConfig, Tester}; -use swc_ecma_visit::FoldWith; use testing::NormalizedOutput; use super::*; @@ -1155,7 +1154,7 @@ fn test_script(src: &str, output: &Path, options: Options) { }; // println!("Emitting: {:?}", module); - emitter.emit_script(&script).unwrap(); + emitter.emit_program(&script).unwrap(); let s = String::from_utf8_lossy(&buf).to_string(); assert!(NormalizedOutput::new_raw(s).compare_to_file(output).is_ok()); diff --git a/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs b/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs index a169547d2fd8..83c86df7ee94 100644 --- a/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs +++ b/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs @@ -4,7 +4,6 @@ use swc_ecma_codegen::{text_writer::JsWriter, Emitter}; use swc_ecma_parser::{Parser, StringInput}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::Tester; -use swc_ecma_visit::FoldWith; use super::*; diff --git a/crates/swc_ecma_transforms_testing/tests/visited.rs b/crates/swc_ecma_transforms_testing/tests/visited.rs index 6621303e0aeb..3f3721ce0eaa 100644 --- a/crates/swc_ecma_transforms_testing/tests/visited.rs +++ b/crates/swc_ecma_transforms_testing/tests/visited.rs @@ -1,7 +1,7 @@ use swc_ecma_ast::*; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_testing::test_transform; -use swc_ecma_visit::Fold; +use swc_ecma_visit::{fold_pass, Fold}; struct Panicking; @@ -27,7 +27,7 @@ fn ensure_visited() { ..Default::default() }), None, - |_| Panicking, + |_| fold_pass(Panicking), " import React from 'react'; const comp = () => ; diff --git a/crates/swc_ecma_transforms_typescript/benches/compat.rs b/crates/swc_ecma_transforms_typescript/benches/compat.rs index f765687cefbe..9c7899b553a5 100644 --- a/crates/swc_ecma_transforms_typescript/benches/compat.rs +++ b/crates/swc_ecma_transforms_typescript/benches/compat.rs @@ -68,7 +68,7 @@ fn base(b: &mut Bencher) { m } } - run(b, |_| Noop); + run(b, |_| fold_pass(Noop)); } fn common_typescript(b: &mut Bencher) { diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 4a63ca020170..1fbb2d598825 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -1859,7 +1859,6 @@ test!( ..Default::default() }; ( - Optional::new(decorators(Default::default()), false), resolver(unresolved_mark, top_level_mark, true), typescript(config, unresolved_mark, top_level_mark), async_to_generator(Default::default(), unresolved_mark), From d77fcf66353fddb301b2779e44b4a71c8199ffd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:02:43 +0900 Subject: [PATCH 145/186] More fix --- crates/swc_ecma_ast/Cargo.toml | 21 +++++++++++---------- crates/swc_ecma_ast/src/lib.rs | 11 +++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/crates/swc_ecma_ast/Cargo.toml b/crates/swc_ecma_ast/Cargo.toml index 8ab8bea3687d..0b480cf65d36 100644 --- a/crates/swc_ecma_ast/Cargo.toml +++ b/crates/swc_ecma_ast/Cargo.toml @@ -32,16 +32,17 @@ serde-impl = ["serde"] arbitrary = { workspace = true, features = ["derive"], optional = true } bitflags = { workspace = true } # bytecheck version should be in sync with rkyv version. Do not bump individually. -bytecheck = { workspace = true, optional = true } -is-macro = { workspace = true } -num-bigint = { workspace = true, features = ["serde"] } -phf = { workspace = true, features = ["macros"] } -rkyv = { workspace = true, features = ["validation"], optional = true } -scoped-tls = { workspace = true } -serde = { workspace = true, features = ["derive"], optional = true } -string_enum = { version = "1.0.0", path = "../string_enum" } -swc_atoms = { version = "2.0.0", path = "../swc_atoms" } -swc_common = { version = "1.0.0", path = "../swc_common" } +bytecheck = { workspace = true, optional = true } +is-macro = { workspace = true } +num-bigint = { workspace = true, features = ["serde"] } +phf = { workspace = true, features = ["macros"] } +rkyv = { workspace = true, features = ["validation"], optional = true } +scoped-tls = { workspace = true } +serde = { workspace = true, features = ["derive"], optional = true } +string_enum = { version = "1.0.0", path = "../string_enum" } +swc_atoms = { version = "2.0.0", path = "../swc_atoms" } +swc_common = { version = "1.0.0", path = "../swc_common" } +swc_visit = { version = "1.0.0", path = "../swc_visit" } unicode-id-start = { workspace = true } [dev-dependencies] diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index bb6889e4215f..99612f3e62a4 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -145,6 +145,17 @@ where } } +impl

Pass for swc_visit::Optional

+where + P: Pass, +{ + fn process(&mut self, program: &mut Program) { + if self.enabled { + self.visitor.process(program); + } + } +} + impl Program { #[inline(always)] pub fn mutate

(&mut self, mut pass: P) From 212eaa4ca61452a972c664f64f1f34196593eb5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:02:50 +0900 Subject: [PATCH 146/186] cargo lockfile --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index 6bb9693bbd02..d1c529818c24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4372,6 +4372,7 @@ dependencies = [ "string_enum", "swc_atoms", "swc_common", + "swc_visit", "unicode-id-start", ] From a89b75017794cd6949a92a2332a76dcdf32ea4fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:04:38 +0900 Subject: [PATCH 147/186] More fix --- crates/swc_ecma_compat_es3/src/prop_lits.rs | 4 ++-- crates/swc_ecma_transforms_typescript/benches/compat.rs | 6 +++--- .../tests/strip_correctness.rs | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/swc_ecma_compat_es3/src/prop_lits.rs b/crates/swc_ecma_compat_es3/src/prop_lits.rs index 757c84d6158d..81d2e213eadd 100644 --- a/crates/swc_ecma_compat_es3/src/prop_lits.rs +++ b/crates/swc_ecma_compat_es3/src/prop_lits.rs @@ -78,7 +78,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_| PropertyLiteral, + |_| fold_pass(PropertyLiteral), babel_basic, r#"var foo = { // changed @@ -95,7 +95,7 @@ mod tests { test!( ::swc_ecma_parser::Syntax::default(), - |_| PropertyLiteral, + |_| fold_pass(PropertyLiteral), str_lit, r#"'use strict'; var x = { diff --git a/crates/swc_ecma_transforms_typescript/benches/compat.rs b/crates/swc_ecma_transforms_typescript/benches/compat.rs index 9c7899b553a5..aa296d72fabb 100644 --- a/crates/swc_ecma_transforms_typescript/benches/compat.rs +++ b/crates/swc_ecma_transforms_typescript/benches/compat.rs @@ -1,10 +1,10 @@ use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; -use swc_common::{chain, comments::SingleThreadedComments, sync::Lrc, FileName, Mark, SourceMap}; +use swc_common::{comments::SingleThreadedComments, sync::Lrc, FileName, Mark, SourceMap}; use swc_ecma_ast::{Module, Pass, Program}; use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax}; use swc_ecma_transforms_base::{helpers, resolver}; use swc_ecma_transforms_typescript::strip; -use swc_ecma_visit::{fold_pass, Fold, FoldWith}; +use swc_ecma_visit::{fold_pass, Fold}; static SOURCE: &str = include_str!("assets/AjaxObservable.ts"); @@ -41,7 +41,7 @@ where let module = module.clone(); helpers::HELPERS.set(&Default::default(), || { - let mut tr = tr(unresolved_mark); + let tr = tr(unresolved_mark); black_box(module.apply(tr)); }); diff --git a/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs b/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs index 2ae131716e6e..3ece0ce609dd 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip_correctness.rs @@ -6,7 +6,6 @@ use swc_ecma_codegen::to_code_default; use swc_ecma_parser::{lexer::Lexer, EsSyntax, Parser, Syntax, TsSyntax}; use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene, resolver}; use swc_ecma_transforms_typescript::typescript; -use swc_ecma_visit::FoldWith; #[testing::fixture("../swc_ecma_parser/tests/tsc/**/*.ts")] #[testing::fixture("../swc_ecma_parser/tests/tsc/**/*.tsx")] From 6bcf8585f31f819ea5b86881ab281b2e201420f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:06:08 +0900 Subject: [PATCH 148/186] More fix --- ...d_destructuring_collision_in_function_expression.rs | 3 ++- .../tests/decorator_evanw.rs | 3 +-- .../swc_ecma_transforms_proposal/tests/decorators.rs | 2 +- .../src/pure_annotations/tests.rs | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs index 3a69251d7fa6..fe0fa5d2e56a 100644 --- a/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs +++ b/crates/swc_ecma_compat_bugfixes/src/safari_id_destructuring_collision_in_function_expression.rs @@ -107,6 +107,7 @@ mod tests { use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_testing::{test, HygieneTester}; + use swc_ecma_visit::fold_pass; use super::*; @@ -166,7 +167,7 @@ mod tests { test!( Syntax::default(), - |_| (tr(), HygieneTester), + |_| (tr(), fold_pass(HygieneTester)), issue_4488_1, " export default function _type_of() { diff --git a/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs b/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs index e14b06a4b6d6..5ee0e0446103 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs +++ b/crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs @@ -3,7 +3,6 @@ use std::{fs, path::PathBuf}; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_proposal::decorator_2022_03::decorator_2022_03; use swc_ecma_transforms_testing::exec_tr; -use swc_ecma_visit::visit_mut_pass; const HELPERS: &str = r###" function assertEq(callback, expected) { @@ -64,7 +63,7 @@ fn fixture(input: PathBuf) { auto_accessors: true, ..Default::default() }), - |_| visit_mut_pass(decorator_2022_03()), + |_| decorator_2022_03(), &code, ); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators.rs b/crates/swc_ecma_transforms_proposal/tests/decorators.rs index fadd428855a5..3306680b1f33 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators.rs +++ b/crates/swc_ecma_transforms_proposal/tests/decorators.rs @@ -6,7 +6,7 @@ use std::{ }; use serde::Deserialize; -use swc_common::{chain, comments::SingleThreadedComments, Mark}; +use swc_common::{comments::SingleThreadedComments, Mark}; use swc_ecma_ast::Pass; use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax}; use swc_ecma_transforms_base::{assumptions::Assumptions, resolver}; diff --git a/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs b/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs index 83c86df7ee94..600bb0fc0f0a 100644 --- a/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs +++ b/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs @@ -19,7 +19,7 @@ fn parse( let source_file = source_map.new_source_file(FileName::Anon.into(), src.into()); let comments = Lrc::new(SingleThreadedComments::default()); - let module = { + let program = { let mut p = Parser::new(syntax, StringInput::from(&*source_file), Some(&comments)); let res = p .parse_module() @@ -29,16 +29,16 @@ fn parse( e.into_diagnostic(tester.handler).emit() } - res? + Program::Module(res?) }; - Ok((module, source_map, comments)) + Ok((program, source_map, comments)) } fn emit( source_map: Lrc, comments: Lrc, - program: &Module, + program: &Program, ) -> String { let mut src_map_buf = Vec::new(); let mut buf = std::vec::Vec::new(); @@ -55,7 +55,7 @@ fn emit( cm: source_map, wr: writer, }; - emitter.emit_module(program).unwrap(); + emitter.emit_program(program).unwrap(); } String::from_utf8(buf).unwrap() From 25aa2c667a6fe2a20af9430505a1f3f0b55636db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:07:48 +0900 Subject: [PATCH 149/186] Document --- crates/swc_ecma_ast/src/lib.rs | 262 +-------------------------------- crates/swc_visit/src/lib.rs | 258 -------------------------------- 2 files changed, 4 insertions(+), 516 deletions(-) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index 99612f3e62a4..45508fef7383 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -95,6 +95,10 @@ mod typescript; /// This trait is used to implement transformations. The implementor may decide /// to implement [Fold] or [VisitMut] if the transform is fine to start from an /// arbitrary node. +/// +/// Tuple of [Pass] implementations also implements [Pass], but it's limited to +/// 12 items for fast compile time. If you have more passes, nest it like `(a, +/// (b, c), (d, e))` pub trait Pass { fn process(&mut self, program: &mut Program); } @@ -278,264 +282,6 @@ impl_pass_for_tuple!( [11, L], [12, M] ); -impl_pass_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N] -); -impl_pass_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O] -); -impl_pass_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P] -); -impl_pass_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q] -); -impl_pass_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R] -); -impl_pass_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R], - [18, S] -); -impl_pass_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R], - [18, S], - [19, T] -); -impl_pass_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R], - [18, S], - [19, T], - [20, U] -); -impl_pass_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R], - [18, S], - [19, T], - [20, U], - [21, V] -); -impl_pass_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R], - [18, S], - [19, T], - [20, U], - [21, V], - [22, W] -); -impl_pass_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R], - [18, S], - [19, T], - [20, U], - [21, V], - [22, W], - [23, X] -); -impl_pass_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R], - [18, S], - [19, T], - [20, U], - [21, V], - [22, W], - [23, X], - [24, Y] -); #[inline(always)] pub fn noop_pass() -> impl Pass { diff --git a/crates/swc_visit/src/lib.rs b/crates/swc_visit/src/lib.rs index ee83e8cf2c41..07d1d7893474 100644 --- a/crates/swc_visit/src/lib.rs +++ b/crates/swc_visit/src/lib.rs @@ -231,264 +231,6 @@ impl_repeated_for_tuple!( [11, L], [12, M] ); -impl_repeated_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N] -); -impl_repeated_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O] -); -impl_repeated_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P] -); -impl_repeated_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q] -); -impl_repeated_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R] -); -impl_repeated_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R], - [18, S] -); -impl_repeated_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R], - [18, S], - [19, T] -); -impl_repeated_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R], - [18, S], - [19, T], - [20, U] -); -impl_repeated_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R], - [18, S], - [19, T], - [20, U], - [21, V] -); -impl_repeated_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R], - [18, S], - [19, T], - [20, U], - [21, V], - [22, W] -); -impl_repeated_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R], - [18, S], - [19, T], - [20, U], - [21, V], - [22, W], - [23, X] -); -impl_repeated_for_tuple!( - [0, A], - [1, B], - [2, C], - [3, D], - [4, E], - [5, F], - [6, G], - [7, H], - [8, I], - [9, J], - [10, K], - [11, L], - [12, M], - [13, N], - [14, O], - [15, P], - [16, Q], - [17, R], - [18, S], - [19, T], - [20, U], - [21, V], - [22, W], - [23, X], - [24, Y] -); /// A visitor which applies `V` again and again if `V` modifies the node. /// From 46988eacc5fcfa36ca9c253d5f4879b9c40b5fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:08:32 +0900 Subject: [PATCH 150/186] Document --- crates/swc_ecma_compat_es2015/src/lib.rs | 44 +++++++++++++----------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/crates/swc_ecma_compat_es2015/src/lib.rs b/crates/swc_ecma_compat_es2015/src/lib.rs index edebf3138a1e..54e9ff568ebb 100644 --- a/crates/swc_ecma_compat_es2015/src/lib.rs +++ b/crates/swc_ecma_compat_es2015/src/lib.rs @@ -60,21 +60,23 @@ where C: Comments + Clone, { ( - regexp(regexp::Config { - dot_all_regex: false, - has_indices: false, - lookbehind_assertion: false, - named_capturing_groups_regex: false, - sticky_regex: true, - unicode_property_regex: false, - unicode_regex: true, - unicode_sets_regex: false, - }), - block_scoped_functions(), - template_literal(c.template_literal), - classes(c.classes), - new_target(), - spread(c.spread), + ( + regexp(regexp::Config { + dot_all_regex: false, + has_indices: false, + lookbehind_assertion: false, + named_capturing_groups_regex: false, + sticky_regex: true, + unicode_property_regex: false, + unicode_regex: true, + unicode_sets_regex: false, + }), + block_scoped_functions(), + template_literal(c.template_literal), + classes(c.classes), + new_target(), + spread(c.spread), + ), // https://github.com/Microsoft/TypeScript/issues/5441 if !c.typescript { Some(object_super()) @@ -87,11 +89,13 @@ where // Should come before parameters // See: https://github.com/swc-project/swc/issues/1036 parameters(c.parameters, unresolved_mark), - exprs(unresolved_mark), - computed_properties(c.computed_props), - destructuring(c.destructuring), - block_scoping(unresolved_mark), - generator::generator(unresolved_mark, comments.clone()), + ( + exprs(unresolved_mark), + computed_properties(c.computed_props), + destructuring(c.destructuring), + block_scoping(unresolved_mark), + generator::generator(unresolved_mark, comments.clone()), + ), ) } From 52bf04416461236eb385c712037dd8f56d785b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:10:28 +0900 Subject: [PATCH 151/186] done --- crates/swc_ecma_ast/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/swc_ecma_ast/src/lib.rs b/crates/swc_ecma_ast/src/lib.rs index 45508fef7383..942cf099b914 100644 --- a/crates/swc_ecma_ast/src/lib.rs +++ b/crates/swc_ecma_ast/src/lib.rs @@ -102,6 +102,7 @@ mod typescript; pub trait Pass { fn process(&mut self, program: &mut Program); } + /// Optional pass implementation. impl

Pass for Option

where @@ -153,6 +154,7 @@ impl

Pass for swc_visit::Optional

where P: Pass, { + #[inline] fn process(&mut self, program: &mut Program) { if self.enabled { self.visitor.process(program); @@ -160,6 +162,23 @@ where } } +impl

Pass for swc_visit::Repeat

+where + P: Pass + swc_visit::Repeated, +{ + #[inline] + fn process(&mut self, program: &mut Program) { + loop { + self.pass.reset(); + self.pass.process(program); + + if !self.pass.changed() { + break; + } + } + } +} + impl Program { #[inline(always)] pub fn mutate

(&mut self, mut pass: P) From 0ab16cf873081d1df20741fe6db01546f1a61afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:12:45 +0900 Subject: [PATCH 152/186] fix --- crates/swc_common/src/pass.rs | 105 ++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/crates/swc_common/src/pass.rs b/crates/swc_common/src/pass.rs index a89a1b4b11d5..8255d464bc2f 100644 --- a/crates/swc_common/src/pass.rs +++ b/crates/swc_common/src/pass.rs @@ -20,3 +20,108 @@ where Cow::Owned(format!("repeat({})", self.pass.name())) } } + +macro_rules! impl_pass_for_tuple { + ( + [$idx:tt, $name:ident], $([$idx_rest:tt, $name_rest:ident]),* + ) => { + impl<$name, $($name_rest),*> CompilerPass for ($name, $($name_rest),*) + where + $name: CompilerPass, + $($name_rest: CompilerPass),* + { + #[inline] + fn name(&self) -> Cow<'static, str> { + use std::fmt::Write; + + let mut name = self.$idx.name().to_string(); + $( + write!(name, " / {}", self.$idx_rest.name()).unwrap(); + )* + Cow::Owned(name) + } + } + }; +} + +impl_pass_for_tuple!([0, A], [1, B]); +impl_pass_for_tuple!([0, A], [1, B], [2, C]); +impl_pass_for_tuple!([0, A], [1, B], [2, C], [3, D]); +impl_pass_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E]); +impl_pass_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E], [5, F]); +impl_pass_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E], [5, F], [6, G]); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L] +); +impl_pass_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M] +); From ed43585dac06da9238a7dc0bd66037724a3841f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:13:54 +0900 Subject: [PATCH 153/186] fix --- crates/swc_bundler/src/bundler/finalize.rs | 6 +++--- crates/swc_ecma_transforms_base/src/fixer.rs | 4 ++-- crates/swc_ecma_transforms_base/src/hygiene/mod.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/swc_bundler/src/bundler/finalize.rs b/crates/swc_bundler/src/bundler/finalize.rs index 58208ccd0117..839e04645164 100644 --- a/crates/swc_bundler/src/bundler/finalize.rs +++ b/crates/swc_bundler/src/bundler/finalize.rs @@ -10,7 +10,7 @@ use swc_ecma_transforms_base::{ hygiene::hygiene, }; use swc_ecma_utils::{contains_top_level_await, find_pat_ids, private_ident, ExprFactory}; -use swc_ecma_visit::{noop_fold_type, Fold, FoldWith}; +use swc_ecma_visit::{noop_fold_type, Fold, FoldWith, VisitMutWith}; use crate::{hash::calc_hash, Bundle, BundleKind, Bundler, Load, ModuleType, Resolve}; @@ -37,13 +37,13 @@ where bundle.module = self.optimize(bundle.module); if !self.config.disable_hygiene { - bundle.module = bundle.module.fold_with(&mut hygiene()); + bundle.module.visit_mut_with(&mut hygiene()); } bundle.module = self.may_wrap_with_iife(bundle.module); if !self.config.disable_fixer { - bundle.module = bundle.module.fold_with(&mut fixer(None)); + bundle.module.visit_mut_with(&mut fixer(None)); } { diff --git a/crates/swc_ecma_transforms_base/src/fixer.rs b/crates/swc_ecma_transforms_base/src/fixer.rs index 3a0f8a465627..546862ffc445 100644 --- a/crates/swc_ecma_transforms_base/src/fixer.rs +++ b/crates/swc_ecma_transforms_base/src/fixer.rs @@ -12,7 +12,7 @@ use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith /// You don't have to bother to create appropriate parenthesis. /// The pass will insert parenthesis as needed. In other words, it's /// okay to store `a * (b + c)` as `Bin { a * Bin { b + c } }`. -pub fn fixer(comments: Option<&dyn Comments>) -> impl '_ + Pass { +pub fn fixer(comments: Option<&dyn Comments>) -> impl '_ + Pass + VisitMut { visit_mut_pass(Fixer { comments, ctx: Default::default(), @@ -23,7 +23,7 @@ pub fn fixer(comments: Option<&dyn Comments>) -> impl '_ + Pass { }) } -pub fn paren_remover(comments: Option<&dyn Comments>) -> impl '_ + Pass { +pub fn paren_remover(comments: Option<&dyn Comments>) -> impl '_ + Pass + VisitMut { visit_mut_pass(Fixer { comments, ctx: Default::default(), diff --git a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs index 1f6769fd0be9..924efcf12dff 100644 --- a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs +++ b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs @@ -28,7 +28,7 @@ pub struct Config { /// See [hygiene_with_config] for doc. Creates a `hygiene` pass with default /// value of [Config]. -pub fn hygiene() -> impl Pass { +pub fn hygiene() -> impl Pass + VisitMut { hygiene_with_config(Default::default()) } From 479f40372e34847534fff6b1075aa43eff8c46e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:15:49 +0900 Subject: [PATCH 154/186] More work --- crates/swc_common/src/pass.rs | 26 +++++++++---------- .../src/hygiene/mod.rs | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/swc_common/src/pass.rs b/crates/swc_common/src/pass.rs index 8255d464bc2f..a53bd8d749f5 100644 --- a/crates/swc_common/src/pass.rs +++ b/crates/swc_common/src/pass.rs @@ -21,7 +21,7 @@ where } } -macro_rules! impl_pass_for_tuple { +macro_rules! impl_compiler_pass_for_tuple { ( [$idx:tt, $name:ident], $([$idx_rest:tt, $name_rest:ident]),* ) => { @@ -44,13 +44,13 @@ macro_rules! impl_pass_for_tuple { }; } -impl_pass_for_tuple!([0, A], [1, B]); -impl_pass_for_tuple!([0, A], [1, B], [2, C]); -impl_pass_for_tuple!([0, A], [1, B], [2, C], [3, D]); -impl_pass_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E]); -impl_pass_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E], [5, F]); -impl_pass_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E], [5, F], [6, G]); -impl_pass_for_tuple!( +impl_compiler_pass_for_tuple!([0, A], [1, B]); +impl_compiler_pass_for_tuple!([0, A], [1, B], [2, C]); +impl_compiler_pass_for_tuple!([0, A], [1, B], [2, C], [3, D]); +impl_compiler_pass_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E]); +impl_compiler_pass_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E], [5, F]); +impl_compiler_pass_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E], [5, F], [6, G]); +impl_compiler_pass_for_tuple!( [0, A], [1, B], [2, C], @@ -60,7 +60,7 @@ impl_pass_for_tuple!( [6, G], [7, H] ); -impl_pass_for_tuple!( +impl_compiler_pass_for_tuple!( [0, A], [1, B], [2, C], @@ -71,7 +71,7 @@ impl_pass_for_tuple!( [7, H], [8, I] ); -impl_pass_for_tuple!( +impl_compiler_pass_for_tuple!( [0, A], [1, B], [2, C], @@ -83,7 +83,7 @@ impl_pass_for_tuple!( [8, I], [9, J] ); -impl_pass_for_tuple!( +impl_compiler_pass_for_tuple!( [0, A], [1, B], [2, C], @@ -96,7 +96,7 @@ impl_pass_for_tuple!( [9, J], [10, K] ); -impl_pass_for_tuple!( +impl_compiler_pass_for_tuple!( [0, A], [1, B], [2, C], @@ -110,7 +110,7 @@ impl_pass_for_tuple!( [10, K], [11, L] ); -impl_pass_for_tuple!( +impl_compiler_pass_for_tuple!( [0, A], [1, B], [2, C], diff --git a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs index 924efcf12dff..f7e27f71b42b 100644 --- a/crates/swc_ecma_transforms_base/src/hygiene/mod.rs +++ b/crates/swc_ecma_transforms_base/src/hygiene/mod.rs @@ -58,7 +58,7 @@ pub fn hygiene() -> impl Pass + VisitMut { /// ## Third phase /// /// At third phase, we rename all identifiers in the queue. -pub fn hygiene_with_config(config: Config) -> impl 'static + Pass { +pub fn hygiene_with_config(config: Config) -> impl 'static + Pass + VisitMut { ( renamer(config, HygieneRenamer), visit_mut_pass(HygieneRemover), From aafaa25514c69ef519604fdc51fa7c3e9b3c34b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:19:14 +0900 Subject: [PATCH 155/186] visitmut --- crates/swc_ecma_visit/src/lib.rs | 151 +++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 89c555687b94..ae839efcc316 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -951,3 +951,154 @@ macro_rules! visit_mut_obj_and_computed { } }; } + +macro_rules! impl_traits_for_tuple { + ( + [$idx:tt, $name:ident], $([$idx_rest:tt, $name_rest:ident]),* + ) => { + impl<$name, $($name_rest),*> VisitMut for ($name, $($name_rest),*) + where + $name: VisitMut, + $($name_rest: VisitMut),* + { + + fn visit_mut_program(&mut self, program: &mut Program) { + self.$idx.visit_mut_program(program); + + $( + self.$idx_rest.visit_mut_program(program); + )* + } + + fn visit_mut_module(&mut self, module: &mut Module) { + self.$idx.visit_mut_module(module); + + $( + self.$idx_rest.visit_mut_module(module); + )* + } + + fn visit_mut_script(&mut self, script: &mut Script) { + self.$idx.visit_mut_script(script); + + $( + self.$idx_rest.visit_mut_script(script); + )* + } + + fn visit_mut_stmt(&mut self, stmt: &mut Stmt) { + self.$idx.visit_mut_stmt(stmt); + + $( + self.$idx_rest.visit_mut_stmt(stmt); + )* + } + + fn visit_mut_expr(&mut self, expr: &mut Expr) { + self.$idx.visit_mut_expr(expr); + + $( + self.$idx_rest.visit_mut_expr(expr); + )* + } + + fn visit_mut_pat(&mut self, pat: &mut Pat) { + self.$idx.visit_mut_pat(pat); + + $( + self.$idx_rest.visit_mut_pat(pat); + )* + } + + fn visit_mut_assign_target(&mut self, target: &mut AssignTarget) { + self.$idx.visit_mut_assign_target(target); + + $( + self.$idx_rest.visit_mut_assign_target(target); + )* + } + } + }; +} + +impl_traits_for_tuple!([0, A], [1, B]); +impl_traits_for_tuple!([0, A], [1, B], [2, C]); +impl_traits_for_tuple!([0, A], [1, B], [2, C], [3, D]); +impl_traits_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E]); +impl_traits_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E], [5, F]); +impl_traits_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E], [5, F], [6, G]); +impl_traits_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H] +); +impl_traits_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I] +); +impl_traits_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J] +); +impl_traits_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K] +); +impl_traits_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L] +); +impl_traits_for_tuple!( + [0, A], + [1, B], + [2, C], + [3, D], + [4, E], + [5, F], + [6, G], + [7, H], + [8, I], + [9, J], + [10, K], + [11, L], + [12, M] +); From bbb86aa32863e5ed94933da02551668e994252ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:20:18 +0900 Subject: [PATCH 156/186] Is --- crates/swc_ecma_ast/src/lit.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/swc_ecma_ast/src/lit.rs b/crates/swc_ecma_ast/src/lit.rs index bb7555c59a4b..9df499510689 100644 --- a/crates/swc_ecma_ast/src/lit.rs +++ b/crates/swc_ecma_ast/src/lit.rs @@ -4,6 +4,7 @@ use std::{ hash::{Hash, Hasher}, }; +use is_macro::Is; use num_bigint::BigInt as BigIntValue; use swc_atoms::{js_word, Atom}; use swc_common::{ast_node, util::take::Take, EqIgnoreSpan, Span, DUMMY_SP}; @@ -11,7 +12,7 @@ use swc_common::{ast_node, util::take::Take, EqIgnoreSpan, Span, DUMMY_SP}; use crate::jsx::JSXText; #[ast_node] -#[derive(Eq, Hash, EqIgnoreSpan)] +#[derive(Eq, Hash, EqIgnoreSpan, Is)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub enum Lit { #[tag("StringLiteral")] From 79b770ca15063d2d1ed4524d37bb13113f504417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:21:23 +0900 Subject: [PATCH 157/186] More woerk --- crates/swc_bundler/src/bundler/finalize.rs | 8 ++++---- crates/swc_ecma_minifier/src/debug.rs | 7 +++---- crates/swc_ecma_transforms_base/src/helpers/mod.rs | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/swc_bundler/src/bundler/finalize.rs b/crates/swc_bundler/src/bundler/finalize.rs index 839e04645164..d558b6c55199 100644 --- a/crates/swc_bundler/src/bundler/finalize.rs +++ b/crates/swc_bundler/src/bundler/finalize.rs @@ -55,10 +55,10 @@ where .swc_helpers .lock(); - let module = bundle.module; - - bundle.module = HELPERS.set(&Helpers::from_data(swc_helpers), || { - module.fold_with(&mut inject_helpers(unresolved_mark)) + HELPERS.set(&Helpers::from_data(swc_helpers), || { + bundle + .module + .visit_mut_with(&mut inject_helpers(unresolved_mark)); }); } diff --git a/crates/swc_ecma_minifier/src/debug.rs b/crates/swc_ecma_minifier/src/debug.rs index 13ff42c63fdc..f0a38ada4f28 100644 --- a/crates/swc_ecma_minifier/src/debug.rs +++ b/crates/swc_ecma_minifier/src/debug.rs @@ -79,10 +79,9 @@ pub(crate) fn invoke_module(module: &Module) { return; } - let module = module - .clone() - .fold_with(&mut hygiene()) - .fold_with(&mut fixer(None)); + let module = Program::Module(module.clone()) + .apply(hygiene()) + .apply(fixer(None)); let module = drop_span(module); let mut buf = Vec::new(); diff --git a/crates/swc_ecma_transforms_base/src/helpers/mod.rs b/crates/swc_ecma_transforms_base/src/helpers/mod.rs index 7abdefde61d9..58fc87e6a2fc 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/mod.rs +++ b/crates/swc_ecma_transforms_base/src/helpers/mod.rs @@ -420,7 +420,7 @@ define_helpers!(Helpers { using_ctx: (), }); -pub fn inject_helpers(global_mark: Mark) -> impl Pass { +pub fn inject_helpers(global_mark: Mark) -> impl Pass + VisitMut { visit_mut_pass(InjectHelpers { global_mark, helper_ctxt: None, From 492386819583fb2bff435e055b87901a3d627dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:23:53 +0900 Subject: [PATCH 158/186] More work --- crates/swc_bundler/src/bundler/load.rs | 17 +++++++-------- crates/swc_ecma_minifier/src/compress/mod.rs | 2 +- .../src/compress/util/mod.rs | 21 ------------------- .../src/resolver/mod.rs | 2 +- .../tests/const_modules.rs | 2 +- .../tests/fixture.rs | 4 ++-- .../tests/simplify_dce.rs | 4 ++-- 7 files changed, 14 insertions(+), 38 deletions(-) diff --git a/crates/swc_bundler/src/bundler/load.rs b/crates/swc_bundler/src/bundler/load.rs index 0c543c2e1a4d..9035bde60e06 100644 --- a/crates/swc_bundler/src/bundler/load.rs +++ b/crates/swc_bundler/src/bundler/load.rs @@ -14,7 +14,7 @@ use swc_ecma_ast::{ }; use swc_ecma_transforms_base::resolver; use swc_ecma_visit::{ - noop_visit_mut_type, noop_visit_type, FoldWith, Visit, VisitMut, VisitMutWith, VisitWith, + noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, }; use super::{export::Exports, helpers::Helpers, Bundler}; @@ -139,9 +139,8 @@ where data.module.visit_mut_with(&mut ClearMark); - let mut module = - data.module - .fold_with(&mut resolver(self.unresolved_mark, local_mark, false)); + data.module + .visit_mut_with(&mut resolver(self.unresolved_mark, local_mark, false)); // { // let code = self @@ -158,7 +157,7 @@ where // println!("Resolved:\n{}\n\n", code); // } - let imports = self.extract_import_info(file_name, &mut module, local_mark); + let imports = self.extract_import_info(file_name, &mut data.module, local_mark); // { // let code = self @@ -177,7 +176,7 @@ where let exports = self.extract_export_info( file_name, - &mut module, + &mut data.module, SyntaxContext::empty().apply_mark(export_mark), ); @@ -188,7 +187,7 @@ where forced_es6: false, found_other: false, }; - module.visit_with(&mut v); + data.module.visit_with(&mut v); v.forced_es6 || !v.found_other }; @@ -200,13 +199,11 @@ where let (exports, reexport_files) = exports?; import_files.extend(reexport_files); - let module = Lrc::new(module); - Ok(( TransformedModule { id, fm: data.fm, - module, + module: Lrc::new(data.module), imports: Lrc::new(imports), exports: Lrc::new(exports), is_es6, diff --git a/crates/swc_ecma_minifier/src/compress/mod.rs b/crates/swc_ecma_minifier/src/compress/mod.rs index d606bf360775..51d801304a5d 100644 --- a/crates/swc_ecma_minifier/src/compress/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/mod.rs @@ -79,7 +79,7 @@ struct Compressor<'a> { } impl CompilerPass for Compressor<'_> { - fn name() -> Cow<'static, str> { + fn name(&self) -> Cow<'static, str> { "compressor".into() } } diff --git a/crates/swc_ecma_minifier/src/compress/util/mod.rs b/crates/swc_ecma_minifier/src/compress/util/mod.rs index 4ac422672759..5392635c1829 100644 --- a/crates/swc_ecma_minifier/src/compress/util/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/util/mod.rs @@ -351,32 +351,11 @@ pub(crate) fn negate_cost( } })(); - // Print more info while testing negate_cost - #[cfg(test)] - { - trace_op!( - "negation cost of `{}` = {}", - dump(&e.clone().fold_with(&mut visit_mut_pass(fixer(None))), true), - cost, - ); - } - cost } let cost = cost(expr_ctx, e, in_bool_ctx, None, is_ret_val_ignored); - trace_op!( - "negation cost of `{}` = {}\nin_book_ctx={:?}\nis_ret_val_ignored={:?}", - dump( - &e.clone().fold_with(&mut visit_mut_pass(fixer(None))), - false - ), - cost, - in_bool_ctx, - is_ret_val_ignored - ); - cost } diff --git a/crates/swc_ecma_transforms_base/src/resolver/mod.rs b/crates/swc_ecma_transforms_base/src/resolver/mod.rs index 2ac61cd5d48c..cdc807094dfa 100644 --- a/crates/swc_ecma_transforms_base/src/resolver/mod.rs +++ b/crates/swc_ecma_transforms_base/src/resolver/mod.rs @@ -134,7 +134,7 @@ pub fn resolver( unresolved_mark: Mark, top_level_mark: Mark, typescript: bool, -) -> impl 'static + Pass { +) -> impl 'static + Pass + VisitMut { assert_ne!( unresolved_mark, Mark::root(), diff --git a/crates/swc_ecma_transforms_optimization/tests/const_modules.rs b/crates/swc_ecma_transforms_optimization/tests/const_modules.rs index 7e0733f2e31f..6a7b45004ace 100644 --- a/crates/swc_ecma_transforms_optimization/tests/const_modules.rs +++ b/crates/swc_ecma_transforms_optimization/tests/const_modules.rs @@ -1,8 +1,8 @@ use std::{collections::HashMap, fs::read_to_string, path::PathBuf}; +use swc_ecma_ast::Pass; use swc_ecma_transforms_optimization::const_modules; use swc_ecma_transforms_testing::{test, test_fixture, Tester}; -use swc_ecma_visit::Fold; fn tr(t: &mut Tester<'_>, sources: &[(&str, &[(&str, &str)])]) -> impl Pass { let mut m = HashMap::default(); diff --git a/crates/swc_ecma_transforms_optimization/tests/fixture.rs b/crates/swc_ecma_transforms_optimization/tests/fixture.rs index 00cd48f9d06a..3b65bf913dee 100644 --- a/crates/swc_ecma_transforms_optimization/tests/fixture.rs +++ b/crates/swc_ecma_transforms_optimization/tests/fixture.rs @@ -1,13 +1,13 @@ use std::path::PathBuf; -use swc_common::{chain, pass::Repeat, Mark}; +use swc_common::{pass::Repeat, Mark}; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_base::fixer::paren_remover; use swc_ecma_transforms_optimization::simplify::{dce::dce, expr_simplifier}; use swc_ecma_transforms_testing::{test_fixture, Tester}; use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut}; -fn remover(t: &Tester) -> impl VisitMut + Fold { +fn remover(t: &Tester) -> impl Pass { visit_mut_pass(paren_remover(Some( Box::leak(Box::new(t.comments.clone())) as _ ))) diff --git a/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs b/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs index 1da29953b4dd..8235ee21ed3e 100644 --- a/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs +++ b/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs @@ -1,4 +1,5 @@ -use swc_common::{chain, pass::Repeat, Mark}; +use swc_common::{pass::Repeat, Mark}; +use swc_ecma_ast::Pass; use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2022::class_properties; @@ -6,7 +7,6 @@ use swc_ecma_transforms_optimization::simplify::dce::{dce, Config}; use swc_ecma_transforms_proposal::decorators; use swc_ecma_transforms_testing::test; use swc_ecma_transforms_typescript::strip; -use swc_ecma_visit::Fold; fn tr() -> impl Pass { Repeat::new(dce( From 75b3d812ae6f4e6591bb635f4695f68dc6c9a561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:25:12 +0900 Subject: [PATCH 159/186] More work --- crates/swc_bundler/src/bundler/optimize.rs | 6 +++--- crates/swc_ecma_minifier/src/compress/mod.rs | 5 +---- crates/swc_ecma_minifier/src/debug.rs | 7 +++---- crates/swc_ecma_transforms_optimization/tests/fixture.rs | 3 ++- .../tests/remove_imports_with_side_effects.rs | 4 ++-- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/crates/swc_bundler/src/bundler/optimize.rs b/crates/swc_bundler/src/bundler/optimize.rs index fd4998af6cd7..f72a30e49359 100644 --- a/crates/swc_bundler/src/bundler/optimize.rs +++ b/crates/swc_bundler/src/bundler/optimize.rs @@ -1,7 +1,7 @@ use swc_common::pass::Repeat; use swc_ecma_ast::*; use swc_ecma_transforms_optimization::simplify::{const_propagation::constant_propagation, dce}; -use swc_ecma_visit::FoldWith; +use swc_ecma_visit::VisitMutWith; use crate::{Bundler, Load, Resolve}; @@ -17,10 +17,10 @@ where pub(super) fn optimize(&self, mut node: Module) -> Module { self.run(|| { if !self.config.disable_inliner { - node = node.fold_with(&mut constant_propagation()) + node.visit_mut_with(&mut constant_propagation()) } if !self.config.disable_dce { - node = node.fold_with(&mut Repeat::new(dce::dce( + node.visit_mut_with(&mut Repeat::new(dce::dce( dce::Config { // TODO(kdy1): Apply mark to wrapped esms and use it at here. module_mark: None, diff --git a/crates/swc_ecma_minifier/src/compress/mod.rs b/crates/swc_ecma_minifier/src/compress/mod.rs index 51d801304a5d..bddeb124447a 100644 --- a/crates/swc_ecma_minifier/src/compress/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/mod.rs @@ -6,10 +6,7 @@ use std::{borrow::Cow, fmt::Write, time::Instant}; #[cfg(feature = "pretty_assertions")] use pretty_assertions::assert_eq; -use swc_common::{ - chain, - pass::{CompilerPass, Optional, Repeated}, -}; +use swc_common::pass::{CompilerPass, Optional, Repeated}; use swc_ecma_ast::*; use swc_ecma_transforms_optimization::simplify::{ dead_branch_remover, expr_simplifier, ExprSimplifierConfig, diff --git a/crates/swc_ecma_minifier/src/debug.rs b/crates/swc_ecma_minifier/src/debug.rs index f0a38ada4f28..4f3ac3c3766a 100644 --- a/crates/swc_ecma_minifier/src/debug.rs +++ b/crates/swc_ecma_minifier/src/debug.rs @@ -170,10 +170,9 @@ pub(crate) fn invoke_script(script: &Script) { return; } - let script = script - .clone() - .fold_with(&mut hygiene()) - .fold_with(&mut fixer(None)); + let script = Program::Script(script.clone()) + .apply(hygiene()) + .apply(fixer(None)); let script = drop_span(script); let mut buf = Vec::new(); diff --git a/crates/swc_ecma_transforms_optimization/tests/fixture.rs b/crates/swc_ecma_transforms_optimization/tests/fixture.rs index 3b65bf913dee..9a04f3a83696 100644 --- a/crates/swc_ecma_transforms_optimization/tests/fixture.rs +++ b/crates/swc_ecma_transforms_optimization/tests/fixture.rs @@ -1,11 +1,12 @@ use std::path::PathBuf; use swc_common::{pass::Repeat, Mark}; +use swc_ecma_ast::Pass; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_base::fixer::paren_remover; use swc_ecma_transforms_optimization::simplify::{dce::dce, expr_simplifier}; use swc_ecma_transforms_testing::{test_fixture, Tester}; -use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut}; +use swc_ecma_visit::visit_mut_pass; fn remover(t: &Tester) -> impl Pass { visit_mut_pass(paren_remover(Some( diff --git a/crates/swc_ecma_transforms_optimization/tests/remove_imports_with_side_effects.rs b/crates/swc_ecma_transforms_optimization/tests/remove_imports_with_side_effects.rs index 3465abab89d3..e747d68a17f1 100644 --- a/crates/swc_ecma_transforms_optimization/tests/remove_imports_with_side_effects.rs +++ b/crates/swc_ecma_transforms_optimization/tests/remove_imports_with_side_effects.rs @@ -1,9 +1,9 @@ -use swc_common::{chain, pass::Repeat, Mark}; +use swc_common::{pass::Repeat, Mark}; +use swc_ecma_ast::Pass; use swc_ecma_parser::{EsSyntax, Syntax}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_optimization::simplify::dce::{dce, Config}; use swc_ecma_transforms_testing::test; -use swc_ecma_visit::Fold; fn tr() -> impl Pass { Repeat::new(dce( From f1f58f2d39328b2217a0a93667f99056d1127494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:25:56 +0900 Subject: [PATCH 160/186] More work --- .../src/compress/util/tests.rs | 6 ++-- .../swc_ecma_minifier/src/pass/global_defs.rs | 2 +- crates/swc_ecma_minifier/src/util/unit.rs | 31 ------------------- 3 files changed, 4 insertions(+), 35 deletions(-) diff --git a/crates/swc_ecma_minifier/src/compress/util/tests.rs b/crates/swc_ecma_minifier/src/compress/util/tests.rs index 4cef11b2941c..2b347009f582 100644 --- a/crates/swc_ecma_minifier/src/compress/util/tests.rs +++ b/crates/swc_ecma_minifier/src/compress/util/tests.rs @@ -40,8 +40,8 @@ fn assert_negate_cost(s: &str, in_bool_ctx: bool, is_ret_val_ignored: bool, expe e.visit_mut_with(&mut UnwrapParen); let input = { - let e = e.clone(); - let e = e.fold_with(&mut fixer(None)); + let mut e = e.clone(); + e.visit_mut_with(&mut fixer(None)); dump(&e, true) }; @@ -53,7 +53,7 @@ fn assert_negate_cost(s: &str, in_bool_ctx: bool, is_ret_val_ignored: bool, expe let real = { let mut real = e.clone(); negate(&expr_ctx, &mut real, in_bool_ctx, is_ret_val_ignored); - let real = real.fold_with(&mut fixer(None)); + real.visit_mut_with(&mut fixer(None)); dump(&real, true) }; diff --git a/crates/swc_ecma_minifier/src/pass/global_defs.rs b/crates/swc_ecma_minifier/src/pass/global_defs.rs index 84ea6df30d59..137830989ac7 100644 --- a/crates/swc_ecma_minifier/src/pass/global_defs.rs +++ b/crates/swc_ecma_minifier/src/pass/global_defs.rs @@ -28,7 +28,7 @@ struct GlobalDefs { } impl CompilerPass for GlobalDefs { - fn name() -> Cow<'static, str> { + fn name(&self) -> Cow<'static, str> { Cow::Borrowed("global-defs") } } diff --git a/crates/swc_ecma_minifier/src/util/unit.rs b/crates/swc_ecma_minifier/src/util/unit.rs index 73c1c90fa88d..ec6517b6d3ad 100644 --- a/crates/swc_ecma_minifier/src/util/unit.rs +++ b/crates/swc_ecma_minifier/src/util/unit.rs @@ -98,34 +98,3 @@ impl CompileUnit for Script { crate::debug::invoke_script(self); } } - -impl CompileUnit for FnExpr { - fn is_module() -> bool { - false - } - - fn force_dump(&self) -> String { - let _noop_sub = - tracing::subscriber::set_default(tracing::subscriber::NoSubscriber::default()); - - dump( - &self - .clone() - .fold_with(&mut fixer(None)) - .fold_with(&mut hygiene()) - .fold_with(&mut visit_mut_pass(DropSpan {})), - true, - ) - } - - fn apply(&mut self, visitor: &mut V) - where - V: VisitMut, - { - self.visit_mut_with(&mut *visitor); - #[cfg(debug_assertions)] - { - self.visit_with(&mut AssertValid); - } - } -} From 30f86efa4c66f74becd11a7bc32ee8f76dce50d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:27:14 +0900 Subject: [PATCH 161/186] More workd --- crates/swc_ecma_minifier/src/compress/util/tests.rs | 2 +- crates/swc_ecma_minifier/src/util/unit.rs | 9 ++++----- crates/swc_ecma_preset_env/src/lib.rs | 6 +++--- crates/swc_ecma_transforms/src/lib.rs | 2 +- .../swc_ecma_transforms_optimization/tests/simplify.rs | 2 +- .../tests/simplify_inlining.rs | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/crates/swc_ecma_minifier/src/compress/util/tests.rs b/crates/swc_ecma_minifier/src/compress/util/tests.rs index 2b347009f582..9a6a0ab31d21 100644 --- a/crates/swc_ecma_minifier/src/compress/util/tests.rs +++ b/crates/swc_ecma_minifier/src/compress/util/tests.rs @@ -3,7 +3,7 @@ use swc_ecma_ast::*; use swc_ecma_parser::parse_file_as_expr; use swc_ecma_transforms_base::fixer::fixer; use swc_ecma_utils::ExprCtx; -use swc_ecma_visit::{noop_visit_mut_type, FoldWith, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use tracing::{info, warn}; use super::negate_cost; diff --git a/crates/swc_ecma_minifier/src/util/unit.rs b/crates/swc_ecma_minifier/src/util/unit.rs index ec6517b6d3ad..cea083eb8ab1 100644 --- a/crates/swc_ecma_minifier/src/util/unit.rs +++ b/crates/swc_ecma_minifier/src/util/unit.rs @@ -80,11 +80,10 @@ impl CompileUnit for Script { tracing::subscriber::set_default(tracing::subscriber::NoSubscriber::default()); dump( - &self - .clone() - .fold_with(&mut fixer(None)) - .fold_with(&mut hygiene()) - .fold_with(&mut visit_mut_pass(DropSpan {})), + &Program::Script(self.clone()) + .apply(fixer(None)) + .apply(hygiene()) + .apply(visit_mut_pass(DropSpan {})), true, ) } diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index 76d8101b2a51..1129cadbc4ee 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -9,7 +9,8 @@ pub use preset_env_base::{query::Targets, version::Version, BrowserData, Version use serde::Deserialize; use swc_atoms::{js_word, JsWord}; use swc_common::{ - chain, collections::AHashSet, comments::Comments, FromVariant, Mark, SyntaxContext, DUMMY_SP, + collections::AHashSet, comments::Comments, pass::Optional, FromVariant, Mark, SyntaxContext, + DUMMY_SP, }; use swc_ecma_ast::*; use swc_ecma_transforms::{ @@ -21,7 +22,6 @@ use swc_ecma_transforms::{ regexp::{self, regexp}, }, feature::FeatureFlag, - pass::{noop, Optional}, Assumptions, }; use swc_ecma_utils::{prepend_stmts, ExprFactory}; @@ -53,7 +53,7 @@ where let (include, included_modules) = FeatureOrModule::split(c.include); let (exclude, excluded_modules) = FeatureOrModule::split(c.exclude); - let pass = noop(); + let pass = noop_pass(); macro_rules! should_enable { ($feature:ident, $default:expr) => {{ diff --git a/crates/swc_ecma_transforms/src/lib.rs b/crates/swc_ecma_transforms/src/lib.rs index e59c20e2a5b3..82d82503e847 100644 --- a/crates/swc_ecma_transforms/src/lib.rs +++ b/crates/swc_ecma_transforms/src/lib.rs @@ -3,7 +3,7 @@ #![deny(unused)] pub use swc_ecma_transforms_base::{ - assumptions::Assumptions, feature, fixer, helpers, hygiene, pass, perf, resolver, + assumptions::Assumptions, feature, fixer, helpers, hygiene, perf, resolver, }; // TODO: May remove these reexports once swc_core directly reexports all #[cfg(feature = "swc_ecma_transforms_compat")] diff --git a/crates/swc_ecma_transforms_optimization/tests/simplify.rs b/crates/swc_ecma_transforms_optimization/tests/simplify.rs index 2de6e2733d3b..de09e6ea629a 100644 --- a/crates/swc_ecma_transforms_optimization/tests/simplify.rs +++ b/crates/swc_ecma_transforms_optimization/tests/simplify.rs @@ -2,7 +2,7 @@ #![deny(warnings)] -use swc_common::{chain, pass::Repeat, Mark}; +use swc_common::{pass::Repeat, Mark}; use swc_ecma_parser::{Syntax, TsSyntax}; use swc_ecma_transforms_base::{helpers::inject_helpers, resolver}; use swc_ecma_transforms_compat::{es2015, es2016, es2017, es2018, es2022::class_properties, es3}; diff --git a/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs b/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs index 87bb20171281..7e6b860cad7c 100644 --- a/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs +++ b/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs @@ -1,13 +1,13 @@ //! Copied from https://github.com/google/closure-compiler/blob/6ca3b62990064488074a1a8931b9e8dc39b148b3/test/com/google/javascript/jscomp/InlineVariablesTest.java use swc_common::Mark; +use swc_ecma_ast::Pass; use swc_ecma_parser::{Syntax, TsSyntax}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::es2022::class_properties; use swc_ecma_transforms_optimization::simplify::inlining::inlining; use swc_ecma_transforms_testing::test; use swc_ecma_transforms_typescript::typescript; -use swc_ecma_visit::Fold; fn simple_strip(unresolved_mark: Mark, top_level_mark: Mark) -> impl Pass { typescript( From bc1650d99d1e082609777f6f052ff057dfbd66b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:29:17 +0900 Subject: [PATCH 162/186] More work --- .../swc_ecma_minifier/src/compress/util/mod.rs | 4 ---- crates/swc_ecma_minifier/src/debug.rs | 2 +- crates/swc_ecma_minifier/src/util/unit.rs | 4 ---- crates/swc_ecma_preset_env/benches/polyfills.rs | 3 ++- crates/swc_ecma_preset_env/src/lib.rs | 2 +- crates/swc_ecma_preset_env/tests/test.rs | 16 ++++++++-------- crates/swc_ecma_transforms/tests/decorators.rs | 2 +- .../tests/es2015_function_name.rs | 2 +- 8 files changed, 14 insertions(+), 21 deletions(-) diff --git a/crates/swc_ecma_minifier/src/compress/util/mod.rs b/crates/swc_ecma_minifier/src/compress/util/mod.rs index 5392635c1829..c185e0d588f1 100644 --- a/crates/swc_ecma_minifier/src/compress/util/mod.rs +++ b/crates/swc_ecma_minifier/src/compress/util/mod.rs @@ -2,14 +2,10 @@ use std::{cmp::Ordering, f64}; use swc_common::{util::take::Take, DUMMY_SP}; use swc_ecma_ast::*; -#[cfg(feature = "debug")] -use swc_ecma_transforms_base::fixer::fixer; use swc_ecma_utils::{number::JsNumber, ExprCtx, ExprExt, IdentUsageFinder, Value}; use swc_ecma_visit::{ noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, }; -#[cfg(feature = "debug")] -use swc_ecma_visit::{visit_mut_pass, FoldWith}; #[cfg(feature = "debug")] use crate::debug::dump; diff --git a/crates/swc_ecma_minifier/src/debug.rs b/crates/swc_ecma_minifier/src/debug.rs index 4f3ac3c3766a..2251b9ad1005 100644 --- a/crates/swc_ecma_minifier/src/debug.rs +++ b/crates/swc_ecma_minifier/src/debug.rs @@ -95,7 +95,7 @@ pub(crate) fn invoke_module(module: &Module) { wr: Box::new(JsWriter::new(cm, "\n", &mut buf, None)), }; - emitter.emit_module(&module).unwrap(); + emitter.emit_program(&module).unwrap(); } let code = String::from_utf8(buf).unwrap(); diff --git a/crates/swc_ecma_minifier/src/util/unit.rs b/crates/swc_ecma_minifier/src/util/unit.rs index cea083eb8ab1..04816966d09b 100644 --- a/crates/swc_ecma_minifier/src/util/unit.rs +++ b/crates/swc_ecma_minifier/src/util/unit.rs @@ -5,13 +5,9 @@ use std::fmt::Debug; use swc_ecma_ast::*; use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene}; use swc_ecma_utils::DropSpan; -#[cfg(debug_assertions)] -use swc_ecma_visit::VisitWith; use swc_ecma_visit::{visit_mut_pass, FoldWith, VisitMut, VisitMutWith}; use crate::debug::dump; -#[cfg(debug_assertions)] -use crate::debug::AssertValid; /// Indicates a unit of minifaction. pub(crate) trait CompileUnit: diff --git a/crates/swc_ecma_preset_env/benches/polyfills.rs b/crates/swc_ecma_preset_env/benches/polyfills.rs index ad3c5b4b6710..b02a68c0f439 100644 --- a/crates/swc_ecma_preset_env/benches/polyfills.rs +++ b/crates/swc_ecma_preset_env/benches/polyfills.rs @@ -1,5 +1,6 @@ use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; use swc_common::{comments::SingleThreadedComments, FileName, Mark}; +use swc_ecma_ast::Program; use swc_ecma_parser::{Parser, StringInput, Syntax}; use swc_ecma_preset_env::{preset_env, Config}; use swc_ecma_transforms::helpers::{Helpers, HELPERS}; @@ -28,7 +29,7 @@ fn run(b: &mut Bencher, src: &str, config: Config) { &mut Default::default(), ); - b.iter(|| black_box(module.clone().fold_with(&mut folder))); + b.iter(|| black_box(Program::Module(module.clone()).apply(&mut folder))); Ok(()) }) }); diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index 1129cadbc4ee..66c50dd2e533 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -42,7 +42,7 @@ pub fn preset_env( c: Config, assumptions: Assumptions, feature_set: &mut FeatureFlag, -) -> impl Fold +) -> impl Pass where C: Comments + Clone, { diff --git a/crates/swc_ecma_preset_env/tests/test.rs b/crates/swc_ecma_preset_env/tests/test.rs index 93b20032785e..27ea2f065af5 100644 --- a/crates/swc_ecma_preset_env/tests/test.rs +++ b/crates/swc_ecma_preset_env/tests/test.rs @@ -13,8 +13,8 @@ use pretty_assertions::assert_eq; use serde::Deserialize; use serde_json::Value; use swc_common::{ - chain, collections::AHashMap, comments::SingleThreadedComments, errors::HANDLER, - input::StringInput, FromVariant, Mark, + collections::AHashMap, comments::SingleThreadedComments, errors::HANDLER, input::StringInput, + FromVariant, Mark, }; use swc_ecma_ast::*; use swc_ecma_codegen::Emitter; @@ -155,7 +155,7 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { fixer(None), ); - let print = |m: &Module| { + let print = |m: &Program| { let mut buf = Vec::new(); { let mut emitter = Emitter { @@ -170,7 +170,7 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { )), }; - emitter.emit_module(m).expect("failed to emit module"); + emitter.emit_program(m).expect("failed to emit module"); } String::from_utf8(buf).expect("invalid utf8 character detected") }; @@ -193,7 +193,7 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { } let actual = helpers::HELPERS.set(&Default::default(), || { - HANDLER.set(&handler, || module.fold_with(&mut pass)) + HANDLER.set(&handler, || Program::Module(module).apply(pass)) }); // debug mode? @@ -256,13 +256,13 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { _ => Ordering::Equal, }); - m + Program::Module(m) }; let expected_src = print(&expected); - if drop_span(actual.fold_with(&mut visit_mut_pass(Normalizer))) - == drop_span(expected.fold_with(&mut visit_mut_pass(Normalizer))) + if drop_span(actual.apply(&mut visit_mut_pass(Normalizer))) + == drop_span(expected.apply(&mut visit_mut_pass(Normalizer))) { return Ok(()); } diff --git a/crates/swc_ecma_transforms/tests/decorators.rs b/crates/swc_ecma_transforms/tests/decorators.rs index c08ad0f63fe1..d84ff6333d23 100644 --- a/crates/swc_ecma_transforms/tests/decorators.rs +++ b/crates/swc_ecma_transforms/tests/decorators.rs @@ -8,6 +8,7 @@ use std::{fs, path::PathBuf}; use swc_common::Mark; +use swc_ecma_ast::Pass; use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax}; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -19,7 +20,6 @@ use swc_ecma_transforms_module::common_js; use swc_ecma_transforms_proposal::{decorators, decorators::Config}; use swc_ecma_transforms_testing::{test, test_exec, test_fixture, Tester}; use swc_ecma_transforms_typescript::{strip, typescript}; -use swc_ecma_visit::Fold; fn ts() -> Syntax { Syntax::Typescript(TsSyntax { diff --git a/crates/swc_ecma_transforms/tests/es2015_function_name.rs b/crates/swc_ecma_transforms/tests/es2015_function_name.rs index 7419265be448..acd9ddaa9760 100644 --- a/crates/swc_ecma_transforms/tests/es2015_function_name.rs +++ b/crates/swc_ecma_transforms/tests/es2015_function_name.rs @@ -6,6 +6,7 @@ ))] use swc_common::Mark; +use swc_ecma_ast::Pass; use swc_ecma_parser::Syntax; use swc_ecma_transforms_base::resolver; use swc_ecma_transforms_compat::{ @@ -15,7 +16,6 @@ use swc_ecma_transforms_compat::{ use swc_ecma_transforms_module::common_js::common_js; use swc_ecma_transforms_proposal::decorators; use swc_ecma_transforms_testing::test; -use swc_ecma_visit::Fold; fn syntax() -> Syntax { Default::default() From e28178299904dd6368a79c58c109734dbfda795e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:30:12 +0900 Subject: [PATCH 163/186] More work --- crates/swc_ecma_minifier/src/debug.rs | 4 ++-- crates/swc_ecma_minifier/src/util/unit.rs | 11 +++++------ crates/swc_ecma_preset_env/benches/polyfills.rs | 1 - crates/swc_ecma_preset_env/src/lib.rs | 2 +- crates/swc_ecma_preset_env/tests/test.rs | 4 ++-- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/crates/swc_ecma_minifier/src/debug.rs b/crates/swc_ecma_minifier/src/debug.rs index 2251b9ad1005..72854e825bac 100644 --- a/crates/swc_ecma_minifier/src/debug.rs +++ b/crates/swc_ecma_minifier/src/debug.rs @@ -9,7 +9,7 @@ use swc_ecma_codegen::{text_writer::JsWriter, Emitter}; use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene}; pub use swc_ecma_transforms_optimization::{debug_assert_valid, AssertValid}; use swc_ecma_utils::{drop_span, DropSpan}; -use swc_ecma_visit::{noop_visit_mut_type, FoldWith, VisitMut, VisitMutWith}; +use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; use tracing::debug; pub(crate) struct Debugger {} @@ -186,7 +186,7 @@ pub(crate) fn invoke_script(script: &Script) { wr: Box::new(JsWriter::new(cm, "\n", &mut buf, None)), }; - emitter.emit_script(&script).unwrap(); + emitter.emit_program(&script).unwrap(); } let code = String::from_utf8(buf).unwrap(); diff --git a/crates/swc_ecma_minifier/src/util/unit.rs b/crates/swc_ecma_minifier/src/util/unit.rs index 04816966d09b..703504803c21 100644 --- a/crates/swc_ecma_minifier/src/util/unit.rs +++ b/crates/swc_ecma_minifier/src/util/unit.rs @@ -5,7 +5,7 @@ use std::fmt::Debug; use swc_ecma_ast::*; use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene}; use swc_ecma_utils::DropSpan; -use swc_ecma_visit::{visit_mut_pass, FoldWith, VisitMut, VisitMutWith}; +use swc_ecma_visit::{visit_mut_pass, VisitMut, VisitMutWith}; use crate::debug::dump; @@ -47,11 +47,10 @@ impl CompileUnit for Module { tracing::subscriber::set_default(tracing::subscriber::NoSubscriber::default()); dump( - &self - .clone() - .fold_with(&mut fixer(None)) - .fold_with(&mut hygiene()) - .fold_with(&mut visit_mut_pass(DropSpan {})), + &Program::Module(self.clone()) + .apply(fixer(None)) + .apply(hygiene()) + .apply(visit_mut_pass(DropSpan {})), true, ) } diff --git a/crates/swc_ecma_preset_env/benches/polyfills.rs b/crates/swc_ecma_preset_env/benches/polyfills.rs index b02a68c0f439..ca718fb3b3e9 100644 --- a/crates/swc_ecma_preset_env/benches/polyfills.rs +++ b/crates/swc_ecma_preset_env/benches/polyfills.rs @@ -4,7 +4,6 @@ use swc_ecma_ast::Program; use swc_ecma_parser::{Parser, StringInput, Syntax}; use swc_ecma_preset_env::{preset_env, Config}; use swc_ecma_transforms::helpers::{Helpers, HELPERS}; -use swc_ecma_visit::FoldWith; fn run(b: &mut Bencher, src: &str, config: Config) { let _ = ::testing::run_test(false, |cm, handler| { diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index 66c50dd2e533..591efc200a1b 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -25,7 +25,7 @@ use swc_ecma_transforms::{ Assumptions, }; use swc_ecma_utils::{prepend_stmts, ExprFactory}; -use swc_ecma_visit::{visit_mut_pass, Fold, VisitMut, VisitMutWith, VisitWith}; +use swc_ecma_visit::{visit_mut_pass, VisitMut, VisitMutWith, VisitWith}; pub use self::transform_data::Feature; diff --git a/crates/swc_ecma_preset_env/tests/test.rs b/crates/swc_ecma_preset_env/tests/test.rs index 27ea2f065af5..a4401e9b2ff5 100644 --- a/crates/swc_ecma_preset_env/tests/test.rs +++ b/crates/swc_ecma_preset_env/tests/test.rs @@ -22,7 +22,7 @@ use swc_ecma_parser::{Parser, Syntax}; use swc_ecma_preset_env::{preset_env, Config, FeatureOrModule, Mode, Targets, Version}; use swc_ecma_transforms::{fixer, helpers}; use swc_ecma_utils::drop_span; -use swc_ecma_visit::{visit_mut_pass, FoldWith, VisitMut}; +use swc_ecma_visit::{visit_mut_pass, VisitMut}; use testing::{NormalizedOutput, Tester}; /// options.json file @@ -121,7 +121,7 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { Tester::new() .print_errors(|cm, handler| { - let mut pass = ( + let pass = ( preset_env( Mark::fresh(Mark::root()), Some(SingleThreadedComments::default()), From e466be380a458437ff05366d9d419acb5c14bd35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:30:56 +0900 Subject: [PATCH 164/186] More work --- crates/swc_ecma_minifier/examples/compress.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_minifier/examples/compress.rs b/crates/swc_ecma_minifier/examples/compress.rs index af4805c6558c..30f3a7823ee6 100644 --- a/crates/swc_ecma_minifier/examples/compress.rs +++ b/crates/swc_ecma_minifier/examples/compress.rs @@ -9,6 +9,7 @@ extern crate swc_malloc; use std::{env::args, fs, path::Path}; use swc_common::{sync::Lrc, Mark, SourceMap}; +use swc_ecma_ast::Program; use swc_ecma_codegen::text_writer::JsWriter; use swc_ecma_minifier::{ optimize, @@ -42,8 +43,9 @@ fn main() { .map_err(|err| { err.into_diagnostic(&handler).emit(); }) - .map(|module| module.fold_with(&mut resolver(unresolved_mark, top_level_mark, false))) - .map(|module| module.fold_with(&mut paren_remover(None))) + .map(Program::Module) + .map(|module| module.apply(resolver(unresolved_mark, top_level_mark, false))) + .map(|module| module.apply(paren_remover(None))) .unwrap(); let output = optimize( From 6546cb98b1409d6cd1771d5f66b349eb69d4d50a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:33:03 +0900 Subject: [PATCH 165/186] More work --- crates/swc/src/plugin.rs | 3 +-- crates/swc_bundler/tests/common/mod.rs | 11 +++++------ crates/swc_bundler/tests/fixture.rs | 5 ++--- crates/swc_ecma_minifier/benches/full.rs | 9 +++++---- crates/swc_ecma_minifier/examples/compress.rs | 8 +++----- crates/swc_ecma_minifier/examples/minifier.rs | 6 ++++-- crates/swc_ecma_minifier/tests/compress.rs | 2 +- 7 files changed, 21 insertions(+), 23 deletions(-) diff --git a/crates/swc/src/plugin.rs b/crates/swc/src/plugin.rs index 71d096247a70..17431f85b3e0 100644 --- a/crates/swc/src/plugin.rs +++ b/crates/swc/src/plugin.rs @@ -7,10 +7,9 @@ )] use serde::{Deserialize, Serialize}; +use swc_ecma_ast::Pass; #[cfg(feature = "plugin")] use swc_ecma_ast::*; -#[cfg(not(any(feature = "plugin")))] -use swc_ecma_transforms::pass::noop; use swc_ecma_visit::{noop_fold_type, Fold}; /// A tuple represents a plugin. diff --git a/crates/swc_bundler/tests/common/mod.rs b/crates/swc_bundler/tests/common/mod.rs index 8a453a5d7981..78f863189999 100644 --- a/crates/swc_bundler/tests/common/mod.rs +++ b/crates/swc_bundler/tests/common/mod.rs @@ -26,7 +26,6 @@ use swc_ecma_transforms_base::{ use swc_ecma_transforms_proposal::decorators; use swc_ecma_transforms_react::react; use swc_ecma_transforms_typescript::strip; -use swc_ecma_visit::FoldWith; pub struct Loader { pub cm: Lrc, @@ -135,21 +134,21 @@ impl Load for Loader { let module = HELPERS.set(&Helpers::new(false), || { Program::Module(module) - .fold_with(&mut resolver(unresolved_mark, top_level_mark, false)) - .fold_with(&mut decorators(decorators::Config { + .apply(resolver(unresolved_mark, top_level_mark, false)) + .apply(decorators(decorators::Config { legacy: true, emit_metadata: Default::default(), use_define_for_class_fields: false, })) - .fold_with(&mut strip(unresolved_mark, top_level_mark)) - .fold_with(&mut react::( + .apply(strip(unresolved_mark, top_level_mark)) + .apply(react::( self.cm.clone(), None, Default::default(), top_level_mark, unresolved_mark, )) - .fold_with(&mut inject_helpers(unresolved_mark)) + .apply(inject_helpers(unresolved_mark)) .module() .unwrap() }); diff --git a/crates/swc_bundler/tests/fixture.rs b/crates/swc_bundler/tests/fixture.rs index 7c8bed4151d6..8a3a87a85e1b 100644 --- a/crates/swc_bundler/tests/fixture.rs +++ b/crates/swc_bundler/tests/fixture.rs @@ -10,12 +10,11 @@ use swc_bundler::{BundleKind, Bundler, Config, ModuleRecord}; use swc_common::{errors::HANDLER, FileName, Globals, Span}; use swc_ecma_ast::{ Bool, Expr, IdentName, KeyValueProp, Lit, MemberExpr, MemberProp, MetaPropExpr, MetaPropKind, - PropName, Str, + Program, PropName, Str, }; use swc_ecma_codegen::{text_writer::JsWriter, Emitter}; use swc_ecma_loader::NODE_BUILTINS; use swc_ecma_transforms_base::fixer::fixer; -use swc_ecma_visit::FoldWith; use testing::NormalizedOutput; use self::common::*; @@ -62,7 +61,7 @@ fn do_test(entry: &Path, entries: HashMap, inline: bool) { }; emitter - .emit_module(&bundled.module.fold_with(&mut fixer(None))) + .emit_program(&Program::Module(bundled.module).apply(fixer(None))) .unwrap(); } diff --git a/crates/swc_ecma_minifier/benches/full.rs b/crates/swc_ecma_minifier/benches/full.rs index 02f6b22c371a..ae82a0998790 100644 --- a/crates/swc_ecma_minifier/benches/full.rs +++ b/crates/swc_ecma_minifier/benches/full.rs @@ -7,6 +7,7 @@ use std::fs::read_to_string; use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Criterion}; use swc_allocator::Allocator; use swc_common::{errors::HANDLER, sync::Lrc, FileName, Mark, SourceMap}; +use swc_ecma_ast::Program; use swc_ecma_codegen::text_writer::JsWriter; use swc_ecma_minifier::{ optimize, @@ -69,7 +70,8 @@ fn run(src: &str) { .map_err(|err| { err.into_diagnostic(&handler).emit(); }) - .map(|module| module.fold_with(&mut resolver(unresolved_mark, top_level_mark, false))) + .map(Program::Module) + .map(|module| module.apply(resolver(unresolved_mark, top_level_mark, false))) .unwrap(); let output = optimize( @@ -97,10 +99,9 @@ fn run(src: &str) { top_level_mark, mangle_name_cache: None, }, - ) - .expect_module(); + ); - let output = output.fold_with(&mut fixer(None)); + let output = output.apply(fixer(None)); let code = print(cm, &[output], true); diff --git a/crates/swc_ecma_minifier/examples/compress.rs b/crates/swc_ecma_minifier/examples/compress.rs index 30f3a7823ee6..f72c99a9f63b 100644 --- a/crates/swc_ecma_minifier/examples/compress.rs +++ b/crates/swc_ecma_minifier/examples/compress.rs @@ -20,7 +20,6 @@ use swc_ecma_transforms_base::{ fixer::{fixer, paren_remover}, resolver, }; -use swc_ecma_visit::FoldWith; fn main() { let file = args().nth(1).expect("should provide a path to file"); @@ -49,7 +48,7 @@ fn main() { .unwrap(); let output = optimize( - program.into(), + program, cm.clone(), None, None, @@ -63,10 +62,9 @@ fn main() { top_level_mark, mangle_name_cache: None, }, - ) - .expect_module(); + ); - let output = output.fold_with(&mut fixer(None)); + let output = output.apply(fixer(None)); let code = print(cm, &[output], false); diff --git a/crates/swc_ecma_minifier/examples/minifier.rs b/crates/swc_ecma_minifier/examples/minifier.rs index eeb423488a15..0f733ef14012 100644 --- a/crates/swc_ecma_minifier/examples/minifier.rs +++ b/crates/swc_ecma_minifier/examples/minifier.rs @@ -5,6 +5,7 @@ extern crate swc_malloc; use std::{env::args, fs, path::Path, sync::Arc}; use swc_common::{errors::HANDLER, sync::Lrc, Mark, SourceMap}; +use swc_ecma_ast::Program; use swc_ecma_codegen::text_writer::{omit_trailing_semi, JsWriter}; use swc_ecma_minifier::{ optimize, @@ -39,8 +40,9 @@ fn main() { .map_err(|err| { err.into_diagnostic(&handler).emit(); }) - .map(|module| module.fold_with(&mut resolver(unresolved_mark, top_level_mark, false))) - .map(|module| module.fold_with(&mut paren_remover(None))) + .map(Program::Module) + .map(|module| module.apply(resolver(unresolved_mark, top_level_mark, false))) + .map(|module| module.apply(paren_remover(None))) .unwrap(); let output = optimize( diff --git a/crates/swc_ecma_minifier/tests/compress.rs b/crates/swc_ecma_minifier/tests/compress.rs index 7b3696c05a9d..992e4834b13f 100644 --- a/crates/swc_ecma_minifier/tests/compress.rs +++ b/crates/swc_ecma_minifier/tests/compress.rs @@ -595,7 +595,7 @@ fn fixture(input: PathBuf) { err.into_diagnostic(&handler).emit(); }) .ok()?; - let mut expected = expected.fold_with(&mut fixer(None)); + let mut expected = expected.apply(fixer(None)); expected = drop_span(expected); match &mut expected { Program::Module(m) => { From 6212bfd6ffb20df8f9c66248d0a3a738caab0db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:34:18 +0900 Subject: [PATCH 166/186] More work --- crates/swc_ecma_minifier/examples/minifier.rs | 8 +++----- .../swc_ecma_minifier/examples/minify-all.rs | 18 +++++++----------- crates/swc_ecma_minifier/tests/compress.rs | 4 ++-- crates/swc_ecma_minifier/tests/exec.rs | 3 ++- crates/swc_ecma_minifier/tests/terser_exec.rs | 2 +- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/crates/swc_ecma_minifier/examples/minifier.rs b/crates/swc_ecma_minifier/examples/minifier.rs index 0f733ef14012..4cd71a427f75 100644 --- a/crates/swc_ecma_minifier/examples/minifier.rs +++ b/crates/swc_ecma_minifier/examples/minifier.rs @@ -16,7 +16,6 @@ use swc_ecma_transforms_base::{ fixer::{fixer, paren_remover}, resolver, }; -use swc_ecma_visit::FoldWith; fn main() { let file = args().nth(1).expect("should provide a path to file"); @@ -46,7 +45,7 @@ fn main() { .unwrap(); let output = optimize( - program.into(), + program, cm.clone(), None, None, @@ -64,10 +63,9 @@ fn main() { // Mangle name cache example. You may not need this. mangle_name_cache: Some(Arc::new(SimpleMangleCache::default())), }, - ) - .expect_module(); + ); - let output = output.fold_with(&mut fixer(None)); + let output = output.apply(fixer(None)); let code = print(cm, &[output], true); diff --git a/crates/swc_ecma_minifier/examples/minify-all.rs b/crates/swc_ecma_minifier/examples/minify-all.rs index 215eaaa4fd2c..e7ab881ddb89 100644 --- a/crates/swc_ecma_minifier/examples/minify-all.rs +++ b/crates/swc_ecma_minifier/examples/minify-all.rs @@ -7,6 +7,7 @@ use std::{env, fs, path::PathBuf, time::Instant}; use anyhow::Result; use rayon::prelude::*; use swc_common::{errors::HANDLER, sync::Lrc, Mark, SourceMap, GLOBALS}; +use swc_ecma_ast::Program; use swc_ecma_codegen::text_writer::JsWriter; use swc_ecma_minifier::{ optimize, @@ -17,7 +18,6 @@ use swc_ecma_transforms_base::{ fixer::{fixer, paren_remover}, resolver, }; -use swc_ecma_visit::FoldWith; use walkdir::WalkDir; fn main() { @@ -48,18 +48,15 @@ fn main() { .map_err(|err| { err.into_diagnostic(&handler).emit(); }) + .map(Program::Module) .map(|module| { - module.fold_with(&mut resolver( - unresolved_mark, - top_level_mark, - false, - )) + module.apply(&mut resolver(unresolved_mark, top_level_mark, false)) }) - .map(|module| module.fold_with(&mut paren_remover(None))) + .map(|module| module.apply(&mut paren_remover(None))) .unwrap(); let output = optimize( - program.into(), + program, cm.clone(), None, None, @@ -76,10 +73,9 @@ fn main() { top_level_mark, mangle_name_cache: None, }, - ) - .expect_module(); + ); - let output = output.fold_with(&mut fixer(None)); + let output = output.apply(&mut fixer(None)); let code = print(cm.clone(), &[output], true); diff --git a/crates/swc_ecma_minifier/tests/compress.rs b/crates/swc_ecma_minifier/tests/compress.rs index 992e4834b13f..36bd2a3c9fa1 100644 --- a/crates/swc_ecma_minifier/tests/compress.rs +++ b/crates/swc_ecma_minifier/tests/compress.rs @@ -261,7 +261,7 @@ fn run( output.visit_mut_with(&mut hygiene()) } - let output = output.fold_with(&mut fixer(None)); + let output = output.apply(&mut fixer(None)); let end = Instant::now(); tracing::info!( @@ -539,7 +539,7 @@ fn fixture(input: PathBuf) { let expected = parser.parse_program().map_err(|err| { err.into_diagnostic(&handler).emit(); })?; - let mut expected = expected.fold_with(&mut fixer(None)); + let mut expected = expected.apply(&mut fixer(None)); expected = drop_span(expected); match &mut expected { diff --git a/crates/swc_ecma_minifier/tests/exec.rs b/crates/swc_ecma_minifier/tests/exec.rs index 750c79b59493..07fd0a18c189 100644 --- a/crates/swc_ecma_minifier/tests/exec.rs +++ b/crates/swc_ecma_minifier/tests/exec.rs @@ -11,7 +11,7 @@ use swc_common::{ sync::Lrc, FileName, Mark, SourceMap, }; -use swc_ecma_ast::Module; +use swc_ecma_ast::{Module, Program}; use swc_ecma_codegen::{ text_writer::{omit_trailing_semi, JsWriter, WriteJs}, Emitter, @@ -125,6 +125,7 @@ fn run( .map_err(|err| { err.into_diagnostic(handler).emit(); }) + .map(Program::Module) .map(|module| module.fold_with(&mut resolver(unresolved_mark, top_level_mark, false))); // Ignore parser errors. diff --git a/crates/swc_ecma_minifier/tests/terser_exec.rs b/crates/swc_ecma_minifier/tests/terser_exec.rs index 89a2beb4fb28..0f9801cdd60e 100644 --- a/crates/swc_ecma_minifier/tests/terser_exec.rs +++ b/crates/swc_ecma_minifier/tests/terser_exec.rs @@ -245,7 +245,7 @@ fn run(cm: Lrc, handler: &Handler, input: &Path, config: &str) -> Opt output.visit_mut_with(&mut hygiene()); - let output = output.fold_with(&mut fixer(None)); + let output = output.apply(&mut fixer(None)); let end = Instant::now(); tracing::info!( From 543f8666675e02425c9d3e55cf37dd004bd5f7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:35:41 +0900 Subject: [PATCH 167/186] More work --- crates/swc/src/builder.rs | 5 ++--- crates/swc_ecma_minifier/benches/full.rs | 1 - crates/swc_ecma_minifier/tests/compress.rs | 2 +- crates/swc_ecma_minifier/tests/exec.rs | 13 ++++++------- crates/swc_html_minifier/src/lib.rs | 6 ++---- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index d239812c2682..e77ce6074217 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -5,8 +5,7 @@ use either::Either; use rustc_hash::FxHashMap; use swc_atoms::JsWord; use swc_common::{ - chain, comments::Comments, errors::Handler, sync::Lrc, util::take::Take, FileName, Mark, - SourceMap, + comments::Comments, errors::Handler, sync::Lrc, util::take::Take, FileName, Mark, SourceMap, }; use swc_ecma_ast::{EsVersion, Module, Script}; use swc_ecma_minifier::option::{terser::TerserTopLevelOptions, MinifyOptions}; @@ -19,10 +18,10 @@ use swc_ecma_transforms::{ hygiene::{self, hygiene_with_config}, modules::{self, path::ImportResolver}, optimization::const_modules, - pass::Optional, resolver, Assumptions, }; use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; +use swc_visit::Optional; use crate::config::{GlobalPassOption, JsMinifyOptions, ModuleConfig}; diff --git a/crates/swc_ecma_minifier/benches/full.rs b/crates/swc_ecma_minifier/benches/full.rs index ae82a0998790..227f39800bec 100644 --- a/crates/swc_ecma_minifier/benches/full.rs +++ b/crates/swc_ecma_minifier/benches/full.rs @@ -15,7 +15,6 @@ use swc_ecma_minifier::{ }; use swc_ecma_parser::parse_file_as_module; use swc_ecma_transforms_base::{fixer::fixer, resolver}; -use swc_ecma_visit::FoldWith; pub fn bench_files(c: &mut Criterion) { let mut group = c.benchmark_group("es/minifier/libs"); diff --git a/crates/swc_ecma_minifier/tests/compress.rs b/crates/swc_ecma_minifier/tests/compress.rs index 36bd2a3c9fa1..d0695854ea11 100644 --- a/crates/swc_ecma_minifier/tests/compress.rs +++ b/crates/swc_ecma_minifier/tests/compress.rs @@ -45,7 +45,7 @@ use swc_ecma_transforms_base::{ resolver, }; use swc_ecma_utils::drop_span; -use swc_ecma_visit::{FoldWith, VisitMut, VisitMutWith}; +use swc_ecma_visit::{VisitMut, VisitMutWith}; use testing::{assert_eq, unignore_fixture, DebugUsingDisplay, NormalizedOutput}; fn load_txt(filename: &str) -> Vec { diff --git a/crates/swc_ecma_minifier/tests/exec.rs b/crates/swc_ecma_minifier/tests/exec.rs index 07fd0a18c189..dea3b74e3c68 100644 --- a/crates/swc_ecma_minifier/tests/exec.rs +++ b/crates/swc_ecma_minifier/tests/exec.rs @@ -11,7 +11,7 @@ use swc_common::{ sync::Lrc, FileName, Mark, SourceMap, }; -use swc_ecma_ast::{Module, Program}; +use swc_ecma_ast::Program; use swc_ecma_codegen::{ text_writer::{omit_trailing_semi, JsWriter, WriteJs}, Emitter, @@ -26,7 +26,7 @@ use swc_ecma_minifier::{ use swc_ecma_parser::{parse_file_as_module, EsSyntax, Syntax}; use swc_ecma_testing::{exec_node_js, JsExecOptions}; use swc_ecma_transforms_base::{fixer::fixer, hygiene::hygiene, resolver}; -use swc_ecma_visit::{FoldWith, VisitMutWith}; +use swc_ecma_visit::VisitMutWith; use testing::DebugUsingDisplay; use tracing::{info, span, Level}; @@ -97,7 +97,7 @@ fn run( input: &str, config: Option<&str>, mangle: Option, -) -> Option { +) -> Option { let _ = rayon::ThreadPoolBuilder::new() .thread_name(|i| format!("rayon-{}", i + 1)) .build_global(); @@ -126,7 +126,7 @@ fn run( err.into_diagnostic(handler).emit(); }) .map(Program::Module) - .map(|module| module.fold_with(&mut resolver(unresolved_mark, top_level_mark, false))); + .map(|module| module.apply(&mut resolver(unresolved_mark, top_level_mark, false))); // Ignore parser errors. // @@ -153,14 +153,13 @@ fn run( top_level_mark, mangle_name_cache: None, }, - ) - .expect_module(); + ); if run_hygiene { output.visit_mut_with(&mut hygiene()); } - let output = output.fold_with(&mut fixer(None)); + let output = output.apply(&mut fixer(None)); Some(output) } diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index faff9cdfbd1a..2eb411da5f10 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -1935,10 +1935,8 @@ impl Minifier<'_, C> { ); } - let left_program = swc_ecma_visit::FoldWith::fold_with( - left_program, - &mut swc_ecma_transforms_base::fixer::fixer(Some(&comments)), - ); + let left_program = + left_program.apply(swc_ecma_transforms_base::fixer::fixer(Some(&comments))); let mut buf = Vec::new(); From ecb5ae0c57dcb9faf1ca2410807d502df733e368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:36:38 +0900 Subject: [PATCH 168/186] Pass --- crates/swc/src/builder.rs | 6 +++--- crates/swc_ecma_minifier/tests/exec.rs | 2 +- crates/swc_html_minifier/src/lib.rs | 12 ++++-------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index e77ce6074217..05eda8badd57 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -7,7 +7,7 @@ use swc_atoms::JsWord; use swc_common::{ comments::Comments, errors::Handler, sync::Lrc, util::take::Take, FileName, Mark, SourceMap, }; -use swc_ecma_ast::{EsVersion, Module, Script}; +use swc_ecma_ast::{EsVersion, Module, Pass, Script}; use swc_ecma_minifier::option::{terser::TerserTopLevelOptions, MinifyOptions}; use swc_ecma_parser::Syntax; use swc_ecma_transforms::{ @@ -75,9 +75,9 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { } } - pub fn then(self, next: N) -> PassBuilder<'a, 'b, swc_visit::AndThen> + pub fn then(self, next: N) -> PassBuilder<'a, 'b, (P, N)> where - N: swc_ecma_visit::Fold, + N: Pass, { let pass = (self.pass, next); PassBuilder { diff --git a/crates/swc_ecma_minifier/tests/exec.rs b/crates/swc_ecma_minifier/tests/exec.rs index dea3b74e3c68..f993d64ec9d1 100644 --- a/crates/swc_ecma_minifier/tests/exec.rs +++ b/crates/swc_ecma_minifier/tests/exec.rs @@ -139,7 +139,7 @@ fn run( let run_hygiene = mangle.is_none(); let mut output = optimize( - program.into(), + program, cm, Some(&comments), None, diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index 2eb411da5f10..587a464863aa 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -2034,10 +2034,9 @@ impl Minifier<'_, C> { &mut swc_ecma_transforms_base::resolver(unresolved_mark, top_level_mark, false), ); - let program = swc_ecma_visit::FoldWith::fold_with( - program, - &mut swc_ecma_transforms_base::fixer::paren_remover(Some(&comments)), - ); + let program = program.apply(swc_ecma_transforms_base::fixer::paren_remover(Some( + &comments, + ))); let program = swc_ecma_minifier::optimize( program, @@ -2057,10 +2056,7 @@ impl Minifier<'_, C> { }, ); - let program = swc_ecma_visit::FoldWith::fold_with( - program, - &mut swc_ecma_transforms_base::fixer::fixer(Some(&comments)), - ); + let program = program.apply(swc_ecma_transforms_base::fixer::fixer(Some(&comments))); let mut buf = Vec::new(); From bfe100740029e3c8971b8f34568f79a1b559177d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:38:26 +0900 Subject: [PATCH 169/186] Pass --- crates/swc/src/builder.rs | 13 +++++-------- crates/swc/src/config/mod.rs | 13 ++++++------- crates/swc/src/dropped_comments_preserver.rs | 4 ++-- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index 05eda8badd57..0b06b2961eaa 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -26,7 +26,7 @@ use swc_visit::Optional; use crate::config::{GlobalPassOption, JsMinifyOptions, ModuleConfig}; /// Builder is used to create a high performance `Compiler`. -pub struct PassBuilder<'a, 'b, P: swc_ecma_visit::Fold> { +pub struct PassBuilder<'a, 'b, P: Pass> { cm: &'a Arc, handler: &'b Handler, env: Option, @@ -47,7 +47,7 @@ pub struct PassBuilder<'a, 'b, P: swc_ecma_visit::Fold> { regenerator: regenerator::Config, } -impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { +impl<'a, 'b, P: Pass> PassBuilder<'a, 'b, P> { pub fn new( cm: &'a Arc, handler: &'b Handler, @@ -125,15 +125,12 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { pub fn const_modules( self, globals: FxHashMap>, - ) -> PassBuilder<'a, 'b, impl swc_ecma_visit::Fold> { + ) -> PassBuilder<'a, 'b, (P, impl Pass)> { let cm = self.cm.clone(); self.then(const_modules(cm, globals)) } - pub fn inline_globals( - self, - c: GlobalPassOption, - ) -> PassBuilder<'a, 'b, impl swc_ecma_visit::Fold> { + pub fn inline_globals(self, c: GlobalPassOption) -> PassBuilder<'a, 'b, (P, impl Pass)> { let pass = c.build(self.cm, self.handler); self.then(pass) } @@ -171,7 +168,7 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { module: Option, comments: Option<&'cmt dyn Comments>, resolver: Option<(FileName, Arc)>, - ) -> impl 'cmt + swc_ecma_visit::Fold + ) -> impl 'cmt + Pass where P: 'cmt, { diff --git a/crates/swc/src/config/mod.rs b/crates/swc/src/config/mod.rs index a2b34250fd7b..d33fe298035d 100644 --- a/crates/swc/src/config/mod.rs +++ b/crates/swc/src/config/mod.rs @@ -17,7 +17,6 @@ use swc_cached::regex::CachedRegex; #[allow(unused)] use swc_common::plugin::metadata::TransformPluginMetadataContext; use swc_common::{ - chain, collections::{AHashMap, AHashSet, ARandomState}, comments::{Comments, SingleThreadedComments}, errors::Handler, @@ -28,7 +27,7 @@ use swc_config::{ config_types::{BoolConfig, BoolOr, BoolOrDataConfig, MergingOption}, merge::Merge, }; -use swc_ecma_ast::{EsVersion, Expr, Program}; +use swc_ecma_ast::{EsVersion, Expr, Pass, Program}; use swc_ecma_ext_transforms::jest; use swc_ecma_lints::{ config::LintConfig, @@ -53,7 +52,6 @@ use swc_ecma_transforms::{ EsModuleConfig, }, optimization::{const_modules, json_parse, simplifier}, - pass::{noop, Optional}, proposals::{ decorators, explicit_resource_management::explicit_resource_management, export_default_from, import_assertions, @@ -71,6 +69,7 @@ use swc_ecma_transforms_optimization::{ }; use swc_ecma_utils::NodeIgnoringSpan; use swc_ecma_visit::{Fold, VisitMutWith}; +use swc_visit::Optional; pub use crate::plugin::PluginConfig; use crate::{ @@ -464,9 +463,9 @@ impl Options { let json_parse_pass = { if let Some(ref cfg) = optimizer.as_ref().and_then(|v| v.jsonify) { - Either::Left(json_parse(cfg.min_cost)) + Some(json_parse(cfg.min_cost)) } else { - Either::Right(noop()) + None } }; @@ -1318,7 +1317,7 @@ impl ModuleConfig { unresolved_mark: Mark, available_features: FeatureFlag, resolver: Option<(FileName, Arc)>, - ) -> Box { + ) -> Box { let resolver = if let Some((base, resolver)) = resolver { Resolver::Real { base, resolver } } else { @@ -1540,7 +1539,7 @@ impl Default for GlobalInliningPassEnvs { } impl GlobalPassOption { - pub fn build(self, cm: &SourceMap, handler: &Handler) -> impl 'static + Fold { + pub fn build(self, cm: &SourceMap, handler: &Handler) -> impl 'static + Pass { type ValuesMap = Arc>; fn expr(cm: &SourceMap, handler: &Handler, src: String) -> Box { diff --git a/crates/swc/src/dropped_comments_preserver.rs b/crates/swc/src/dropped_comments_preserver.rs index 377ada685b4d..19609d5f0dea 100644 --- a/crates/swc/src/dropped_comments_preserver.rs +++ b/crates/swc/src/dropped_comments_preserver.rs @@ -2,8 +2,8 @@ use swc_common::{ comments::{Comment, Comments, SingleThreadedComments}, BytePos, Span, DUMMY_SP, }; -use swc_ecma_ast::{Module, Script}; -use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, Fold, VisitMut, VisitMutWith}; +use swc_ecma_ast::{Module, Pass, Script}; +use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith}; /// Preserves comments that would otherwise be dropped. /// From ec8703631fa030f5265d9c19a5498befd45fc249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:39:38 +0900 Subject: [PATCH 170/186] Pass --- crates/swc/src/config/mod.rs | 27 +++++++++++++-------------- crates/swc/src/lib.rs | 5 ++--- crates/swc/src/plugin.rs | 6 +++--- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/crates/swc/src/config/mod.rs b/crates/swc/src/config/mod.rs index d33fe298035d..723c9f83029c 100644 --- a/crates/swc/src/config/mod.rs +++ b/crates/swc/src/config/mod.rs @@ -7,7 +7,6 @@ use std::{ use anyhow::{bail, Context, Error}; use dashmap::DashMap; -use either::Either; use indexmap::IndexMap; use once_cell::sync::Lazy; use rustc_hash::FxHashMap; @@ -27,7 +26,7 @@ use swc_config::{ config_types::{BoolConfig, BoolOr, BoolOrDataConfig, MergingOption}, merge::Merge, }; -use swc_ecma_ast::{EsVersion, Expr, Pass, Program}; +use swc_ecma_ast::{noop_pass, EsVersion, Expr, Pass, Program}; use swc_ecma_ext_transforms::jest; use swc_ecma_lints::{ config::LintConfig, @@ -474,12 +473,12 @@ impl Options { match opts { SimplifyOption::Bool(allow_simplify) => { if *allow_simplify { - Either::Left(simplifier(top_level_mark, Default::default())) + Some(simplifier(top_level_mark, Default::default())) } else { - Either::Right(noop()) + None } } - SimplifyOption::Json(cfg) => Either::Left(simplifier( + SimplifyOption::Json(cfg) => Some(simplifier( top_level_mark, SimplifyConfig { dce: DceConfig { @@ -492,15 +491,15 @@ impl Options { )), } } else { - Either::Right(noop()) + None } }; let optimization = { if let Some(opts) = optimizer.and_then(|o| o.globals) { - Either::Left(opts.build(cm, handler)) + Some(opts.build(cm, handler)) } else { - Either::Right(noop()) + None } }; @@ -581,7 +580,7 @@ impl Options { let disable_all_lints = experimental.disable_all_lints.into_bool(); #[cfg(feature = "plugin")] - let plugin_transforms: Box = { + let plugin_transforms: Box = { let transform_filename = match base { FileName::Real(path) => path.as_os_str().to_str().map(String::from), FileName::Custom(filename) => Some(filename.to_owned()), @@ -667,25 +666,25 @@ impl Options { }; #[cfg(not(feature = "plugin"))] - let plugin_transforms: Box = { + let plugin_transforms: Box = { if experimental.plugins.is_some() { handler.warn( "Plugin is not supported with current @swc/core. Plugin transform will be \ skipped.", ); } - Box::new(noop()) + Box::new(noop_pass()) }; let mut plugin_transforms = Some(plugin_transforms); - let pass: Box = if experimental + let pass: Box = if experimental .disable_builtin_transforms_for_internal_testing .into_bool() { plugin_transforms.unwrap() } else { - let decorator_pass: Box = + let decorator_pass: Box = match transform.decorator_version.unwrap_or_default() { DecoratorVersion::V202112 => Box::new(decorators(decorators::Config { legacy: transform.legacy_decorator.into_bool(), @@ -1761,7 +1760,7 @@ fn build_resolver( r } -fn option_pass(pass: Option>) -> Box { +fn option_pass(pass: Option>) -> Box { match pass { None => Box::new(noop()), Some(pass) => pass, diff --git a/crates/swc/src/lib.rs b/crates/swc/src/lib.rs index ac0a6b153d42..a61afe086647 100644 --- a/crates/swc/src/lib.rs +++ b/crates/swc/src/lib.rs @@ -131,8 +131,8 @@ use once_cell::sync::Lazy; use serde_json::error::Category; pub use sourcemap; use swc_common::{ - chain, comments::Comments, errors::Handler, sync::Lrc, FileName, Mark, SourceFile, SourceMap, - Spanned, GLOBALS, + comments::Comments, errors::Handler, sync::Lrc, FileName, Mark, SourceFile, SourceMap, Spanned, + GLOBALS, }; pub use swc_compiler_base::{PrintArgs, TransformOutput}; pub use swc_config::config_types::{BoolConfig, BoolOr, BoolOrDataConfig}; @@ -148,7 +148,6 @@ use swc_ecma_transforms::{ helpers::{self, Helpers}, hygiene, modules::{path::NodeImportResolver, rewriter::import_rewriter}, - pass::noop, resolver, }; use swc_ecma_transforms_base::fixer::paren_remover; diff --git a/crates/swc/src/plugin.rs b/crates/swc/src/plugin.rs index 17431f85b3e0..0afba9e4ef1a 100644 --- a/crates/swc/src/plugin.rs +++ b/crates/swc/src/plugin.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; use swc_ecma_ast::Pass; #[cfg(feature = "plugin")] use swc_ecma_ast::*; -use swc_ecma_visit::{noop_fold_type, Fold}; +use swc_ecma_visit::{fold_pass, noop_fold_type, Fold}; /// A tuple represents a plugin. /// @@ -30,13 +30,13 @@ pub fn plugins( source_map: std::sync::Arc, unresolved_mark: swc_common::Mark, ) -> impl Pass { - RustPlugins { + fold_pass(RustPlugins { plugins: configured_plugins, metadata_context, comments, source_map, unresolved_mark, - } + }) } struct RustPlugins { From c37be511b7a5d05b780d24ff6514c7bb1a48a7fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:40:36 +0900 Subject: [PATCH 171/186] Pass --- crates/swc/src/config/mod.rs | 149 +++++++++++++++++------------------ 1 file changed, 74 insertions(+), 75 deletions(-) diff --git a/crates/swc/src/config/mod.rs b/crates/swc/src/config/mod.rs index 723c9f83029c..a4854e726390 100644 --- a/crates/swc/src/config/mod.rs +++ b/crates/swc/src/config/mod.rs @@ -698,79 +698,85 @@ impl Options { }; Box::new(( - if experimental.run_plugin_first.into_bool() { - option_pass(plugin_transforms.take()) - } else { - Box::new(noop()) - }, - Optional::new( - lint_to_fold(swc_ecma_lints::rules::all(LintParams { - program: &program, - lint_config: &lints, - top_level_ctxt, - unresolved_ctxt, - es_version, - source_map: cm.clone(), - })), - !disable_all_lints, - ), - // Decorators may use type information - Optional::new(decorator_pass, syntax.decorators()), - Optional::new( - explicit_resource_management(), - syntax.explicit_resource_management(), + ( + if experimental.run_plugin_first.into_bool() { + plugin_transforms.take() + } else { + None + }, + Optional::new( + lint_to_fold(swc_ecma_lints::rules::all(LintParams { + program: &program, + lint_config: &lints, + top_level_ctxt, + unresolved_ctxt, + es_version, + source_map: cm.clone(), + })), + !disable_all_lints, + ), + // Decorators may use type information + Optional::new(decorator_pass, syntax.decorators()), + Optional::new( + explicit_resource_management(), + syntax.explicit_resource_management(), + ), ), // The transform strips import assertions, so it's only enabled if // keep_import_assertions is false. - Optional::new(import_assertions(), !keep_import_attributes), - Optional::new( - typescript::tsx::>( - cm.clone(), - typescript::Config { - import_export_assign_config, - verbatim_module_syntax, - ..Default::default() - }, - typescript::TsxConfig { - pragma: Some( - transform - .react - .pragma - .clone() - .unwrap_or_else(default_pragma), - ), - pragma_frag: Some( - transform - .react - .pragma_frag - .clone() - .unwrap_or_else(default_pragma_frag), - ), - }, - comments.map(|v| v as _), - unresolved_mark, - top_level_mark, + ( + Optional::new(import_assertions(), !keep_import_attributes), + Optional::new( + typescript::tsx::>( + cm.clone(), + typescript::Config { + import_export_assign_config, + verbatim_module_syntax, + ..Default::default() + }, + typescript::TsxConfig { + pragma: Some( + transform + .react + .pragma + .clone() + .unwrap_or_else(default_pragma), + ), + pragma_frag: Some( + transform + .react + .pragma_frag + .clone() + .unwrap_or_else(default_pragma_frag), + ), + }, + comments.map(|v| v as _), + unresolved_mark, + top_level_mark, + ), + syntax.typescript(), ), - syntax.typescript(), ), - option_pass(plugin_transforms.take()), - custom_before_pass(&program), - // handle jsx - Optional::new( - react::react::<&dyn Comments>( - cm.clone(), - comments.map(|v| v as _), - transform.react, - top_level_mark, - unresolved_mark, + ( + plugin_transforms.take(), + custom_before_pass(&program), + // handle jsx + Optional::new( + react::react::<&dyn Comments>( + cm.clone(), + comments.map(|v| v as _), + transform.react, + top_level_mark, + unresolved_mark, + ), + syntax.jsx(), + ), + pass, + Optional::new(jest::jest(), transform.hidden.jest.into_bool()), + Optional::new( + dropped_comments_preserver(comments.cloned()), + preserve_all_comments, ), - syntax.jsx(), - ), - pass, - Optional::new(jest::jest(), transform.hidden.jest.into_bool()), - Optional::new( - dropped_comments_preserver(comments.cloned()), - preserve_all_comments, ), )) }; @@ -1079,7 +1085,7 @@ impl Config { /// One `BuiltConfig` per a directory with swcrc #[non_exhaustive] -pub struct BuiltInput { +pub struct BuiltInput { pub program: Program, pub pass: P, pub syntax: Syntax, @@ -1759,10 +1765,3 @@ fn build_resolver( r } - -fn option_pass(pass: Option>) -> Box { - match pass { - None => Box::new(noop()), - Some(pass) => pass, - } -} From d8350fa523b5d6f72f55288dcdfe58fe4f922401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:43:07 +0900 Subject: [PATCH 172/186] Pass --- crates/swc/src/config/mod.rs | 12 ++++---- crates/swc_ecma_lints/src/rules/mod.rs | 28 ++++++------------- crates/swc_ecma_minifier/tests/terser_exec.rs | 2 +- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/crates/swc/src/config/mod.rs b/crates/swc/src/config/mod.rs index a4854e726390..5d8229c51742 100644 --- a/crates/swc/src/config/mod.rs +++ b/crates/swc/src/config/mod.rs @@ -67,7 +67,7 @@ use swc_ecma_transforms_optimization::{ GlobalExprMap, }; use swc_ecma_utils::NodeIgnoringSpan; -use swc_ecma_visit::{Fold, VisitMutWith}; +use swc_ecma_visit::VisitMutWith; use swc_visit::Optional; pub use crate::plugin::PluginConfig; @@ -229,9 +229,9 @@ impl Options { config: Option, comments: Option<&'a SingleThreadedComments>, custom_before_pass: impl FnOnce(&Program) -> P, - ) -> Result>, Error> + ) -> Result>, Error> where - P: 'a + swc_ecma_visit::Fold, + P: 'a + Pass, { let mut cfg = self.config.clone(); @@ -1117,11 +1117,11 @@ pub struct BuiltInput { impl

BuiltInput

where - P: swc_ecma_visit::Fold, + P: Pass, { pub fn with_pass(self, map: impl FnOnce(P) -> N) -> BuiltInput where - N: swc_ecma_visit::Fold, + N: Pass, { BuiltInput { program: self.program, @@ -1332,7 +1332,7 @@ impl ModuleConfig { match config { None | Some(ModuleConfig::Es6(..)) | Some(ModuleConfig::NodeNext(..)) => match resolver { - Resolver::Default => Box::new(noop()), + Resolver::Default => Box::new(noop_pass()), Resolver::Real { base, resolver } => Box::new(import_rewriter(base, resolver)), }, Some(ModuleConfig::CommonJs(config)) => Box::new(modules::common_js::common_js( diff --git a/crates/swc_ecma_lints/src/rules/mod.rs b/crates/swc_ecma_lints/src/rules/mod.rs index 94ba9a69881e..0745f79e6dbc 100644 --- a/crates/swc_ecma_lints/src/rules/mod.rs +++ b/crates/swc_ecma_lints/src/rules/mod.rs @@ -2,7 +2,6 @@ use std::sync::Arc; use swc_common::{SourceMap, SyntaxContext}; use swc_ecma_ast::*; -use swc_ecma_visit::{noop_fold_type, Fold}; use crate::{config::LintConfig, rule::Rule}; @@ -217,34 +216,25 @@ pub fn all(lint_params: LintParams) -> Vec> { rules } -pub fn lint_to_fold(r: R) -> impl Fold +pub fn lint_to_fold(r: R) -> impl Pass where R: Rule, { - LintFolder(r) + LintPass(r) } -struct LintFolder(R) +struct LintPass(R) where R: Rule; -impl Fold for LintFolder +impl Pass for LintPass where R: Rule, { - noop_fold_type!(); - - #[inline(always)] - fn fold_module(&mut self, program: Module) -> Module { - self.0.lint_module(&program); - - program - } - - #[inline(always)] - fn fold_script(&mut self, program: Script) -> Script { - self.0.lint_script(&program); - - program + fn process(&mut self, program: &mut Program) { + match program { + Program::Module(m) => self.0.lint_module(m), + Program::Script(s) => self.0.lint_script(s), + } } } diff --git a/crates/swc_ecma_minifier/tests/terser_exec.rs b/crates/swc_ecma_minifier/tests/terser_exec.rs index 0f9801cdd60e..fd13cab795de 100644 --- a/crates/swc_ecma_minifier/tests/terser_exec.rs +++ b/crates/swc_ecma_minifier/tests/terser_exec.rs @@ -37,7 +37,7 @@ use swc_ecma_transforms_base::{ hygiene::hygiene, resolver, }; -use swc_ecma_visit::{FoldWith, VisitMutWith}; +use swc_ecma_visit::VisitMutWith; use testing::assert_eq; #[testing::fixture( From 9d60d7ed5291c6d75611654db545f4f024726888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:46:55 +0900 Subject: [PATCH 173/186] Pass --- crates/swc/src/lib.rs | 44 ++++++++++++------------ crates/swc_ecma_minifier/benches/full.rs | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/crates/swc/src/lib.rs b/crates/swc/src/lib.rs index a61afe086647..28f2176bf332 100644 --- a/crates/swc/src/lib.rs +++ b/crates/swc/src/lib.rs @@ -136,7 +136,7 @@ use swc_common::{ }; pub use swc_compiler_base::{PrintArgs, TransformOutput}; pub use swc_config::config_types::{BoolConfig, BoolOr, BoolOrDataConfig}; -use swc_ecma_ast::{EsVersion, Program}; +use swc_ecma_ast::{noop_pass, EsVersion, Pass, Program}; use swc_ecma_codegen::{to_code_with_comments, Node}; use swc_ecma_loader::resolvers::{ lru::CachingResolver, node::NodeModulesResolver, tsc::TsConfigResolver, @@ -589,9 +589,9 @@ impl Compiler { name: &FileName, comments: Option<&'a SingleThreadedComments>, before_pass: impl 'a + FnOnce(&Program) -> P, - ) -> Result>, Error> + ) -> Result>, Error> where - P: 'a + swc_ecma_visit::Fold, + P: 'a + Pass, { self.run(move || { let _timer = timer!("Compiler.parse"); @@ -683,8 +683,8 @@ impl Compiler { custom_after_pass: impl FnOnce(&Program) -> P2, ) -> Result where - P1: swc_ecma_visit::Fold, - P2: swc_ecma_visit::Fold, + P1: Pass, + P2: Pass, { self.run(|| -> Result<_, Error> { let config = self.run(|| { @@ -741,8 +741,8 @@ impl Compiler { handler, opts, SingleThreadedComments::default(), - |_| noop(), - |_| noop(), + |_| noop_pass(), + |_| noop_pass(), ) } @@ -809,7 +809,7 @@ impl Compiler { let comments = SingleThreadedComments::default(); - let program = self + let mut program = self .parse_js( fm.clone(), handler, @@ -857,14 +857,13 @@ impl Compiler { let is_mangler_enabled = min_opts.mangle.is_some(); - let module = self.run_transform(handler, false, || { - let module = program.fold_with(&mut paren_remover(Some(&comments))); + program = self.run_transform(handler, false, || { + program.mutate(&mut paren_remover(Some(&comments))); - let module = - module.fold_with(&mut resolver(unresolved_mark, top_level_mark, false)); + program.mutate(&mut resolver(unresolved_mark, top_level_mark, false)); - let mut module = swc_ecma_minifier::optimize( - module, + let mut program = swc_ecma_minifier::optimize( + program, self.cm.clone(), Some(&comments), None, @@ -877,9 +876,10 @@ impl Compiler { ); if !is_mangler_enabled { - module.visit_mut_with(&mut hygiene()) + program.visit_mut_with(&mut hygiene()) } - module.fold_with(&mut fixer(Some(&comments as &dyn Comments))) + program.mutate(&mut fixer(Some(&comments as &dyn Comments))); + program }); let preserve_comments = opts @@ -891,7 +891,7 @@ impl Compiler { swc_compiler_base::minify_file_comments(&comments, preserve_comments); self.print( - &module, + &program, PrintArgs { source_root: None, source_file_name: Some(&fm.name.to_string()), @@ -935,8 +935,8 @@ impl Compiler { handler, opts, SingleThreadedComments::default(), - |_| noop(), - |_| noop(), + |_| noop_pass(), + |_| noop_pass(), ) } @@ -947,7 +947,7 @@ impl Compiler { comments: SingleThreadedComments, fm: Arc, orig: Option<&sourcemap::SourceMap>, - config: BuiltInput, + config: BuiltInput, ) -> Result { self.run(|| { let program = config.program; @@ -982,7 +982,7 @@ impl Compiler { let mut module = program.clone().expect_module(); if let Some((base, resolver)) = config.resolver { - module = module.fold_with(&mut import_rewriter(base, resolver)); + program.mutate(import_rewriter(base, resolver)); } let issues = checker.transform(&mut module); @@ -1012,7 +1012,7 @@ impl Compiler { helpers::HELPERS.set(&Helpers::new(config.external_helpers), || { HANDLER.set(handler, || { // Fold module - program.fold_with(&mut pass) + program.apply(pass) }) }) }); diff --git a/crates/swc_ecma_minifier/benches/full.rs b/crates/swc_ecma_minifier/benches/full.rs index 227f39800bec..2c4f9a588a3a 100644 --- a/crates/swc_ecma_minifier/benches/full.rs +++ b/crates/swc_ecma_minifier/benches/full.rs @@ -74,7 +74,7 @@ fn run(src: &str) { .unwrap(); let output = optimize( - program.into(), + program, cm.clone(), None, None, From 2cfeee26819540e971758bc184aba49243a96788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:48:15 +0900 Subject: [PATCH 174/186] Pass --- crates/swc/src/lib.rs | 4 +-- crates/swc_estree_compat/benches/babelify.rs | 6 ++-- crates/swc_node_bundler/src/loaders/swc.rs | 37 ++++++++------------ 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/crates/swc/src/lib.rs b/crates/swc/src/lib.rs index 28f2176bf332..02cb9391e16f 100644 --- a/crates/swc/src/lib.rs +++ b/crates/swc/src/lib.rs @@ -950,7 +950,7 @@ impl Compiler { config: BuiltInput, ) -> Result { self.run(|| { - let program = config.program; + let mut program = config.program; if config.emit_isolated_dts && !config.syntax.typescript() { handler.warn( @@ -1000,7 +1000,7 @@ impl Compiler { None }; - let mut pass = config.pass; + let pass = config.pass; let (program, output) = swc_transform_common::output::capture(|| { if let Some(dts_code) = dts_code { emit( diff --git a/crates/swc_estree_compat/benches/babelify.rs b/crates/swc_estree_compat/benches/babelify.rs index 31d3eab1fec7..2644f6bc5050 100644 --- a/crates/swc_estree_compat/benches/babelify.rs +++ b/crates/swc_estree_compat/benches/babelify.rs @@ -53,9 +53,9 @@ fn babelify_only(b: &mut Bencher) { let top_level_mark = Mark::new(); module - .fold_with(&mut resolver(unresolved_mark, top_level_mark, true)) - .fold_with(&mut typescript::strip(unresolved_mark, top_level_mark)) - .fold_with(&mut es2020(Default::default(), unresolved_mark)) + .apply(&mut resolver(unresolved_mark, top_level_mark, true)) + .apply(&mut typescript::strip(unresolved_mark, top_level_mark)) + .apply(&mut es2020(Default::default(), unresolved_mark)) }); b.iter(|| { diff --git a/crates/swc_node_bundler/src/loaders/swc.rs b/crates/swc_node_bundler/src/loaders/swc.rs index 0de49ef81635..c69ea892b19e 100644 --- a/crates/swc_node_bundler/src/loaders/swc.rs +++ b/crates/swc_node_bundler/src/loaders/swc.rs @@ -15,7 +15,7 @@ use swc_common::{ sync::Lrc, FileName, Mark, DUMMY_SP, }; -use swc_ecma_ast::{EsVersion, Expr, Lit, Module, Program, Str}; +use swc_ecma_ast::{noop_pass, EsVersion, Expr, Lit, Module, Program, Str}; use swc_ecma_parser::{parse_file_as_module, Syntax}; use swc_ecma_transforms::{ helpers, @@ -23,7 +23,6 @@ use swc_ecma_transforms::{ inline_globals, simplify::{dead_branch_remover, expr_simplifier}, }, - pass::noop, react::jsx, resolver, typescript::typescript, @@ -171,14 +170,14 @@ impl SwcLoader { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - program.visit_mut_with(&mut resolver(unresolved_mark, top_level_mark, false)); - program.visit_mut_with(&mut typescript( + program.mutate(&mut resolver(unresolved_mark, top_level_mark, false)); + program.mutate(&mut typescript( Default::default(), unresolved_mark, top_level_mark, )); - program.visit_mut_with(&mut jsx( + program.mutate(&mut jsx( self.compiler.cm.clone(), None::, Default::default(), @@ -186,16 +185,15 @@ impl SwcLoader { unresolved_mark, )); - program.visit_mut_with(&mut inline_globals( + program.mutate(&mut inline_globals( self.env_map(), Default::default(), Default::default(), )); - let program = program - .fold_with(&mut expr_simplifier(unresolved_mark, Default::default())); + program.mutate(&mut expr_simplifier(unresolved_mark, Default::default())); - program.fold_with(&mut dead_branch_remover(unresolved_mark)) + program.mutate(&mut dead_branch_remover(unresolved_mark)) }) }) } else { @@ -248,7 +246,7 @@ impl SwcLoader { }, &fm.name, Some(&comments), - |_| noop(), + |_| noop_pass(), )?; tracing::trace!("JsLoader.load: loaded config"); @@ -265,18 +263,14 @@ impl SwcLoader { let unresolved_mark = Mark::new(); let top_level_mark = Mark::new(); - program.visit_mut_with(&mut resolver( - unresolved_mark, - top_level_mark, - false, - )); - program.visit_mut_with(&mut typescript( + program.mutate(&mut resolver(unresolved_mark, top_level_mark, false)); + program.mutate(&mut typescript( Default::default(), unresolved_mark, top_level_mark, )); - program.visit_mut_with(&mut jsx( + program.mutate(&mut jsx( self.compiler.cm.clone(), None::, Default::default(), @@ -284,17 +278,16 @@ impl SwcLoader { unresolved_mark, )); - let program = program.fold_with(&mut inline_globals( + program.mutate(&mut inline_globals( self.env_map(), Default::default(), Default::default(), )); - let program = program - .fold_with(&mut expr_simplifier(unresolved_mark, Default::default())); - let program = program.fold_with(&mut dead_branch_remover(unresolved_mark)); + program.mutate(&mut expr_simplifier(unresolved_mark, Default::default())); + program.mutate(&mut dead_branch_remover(unresolved_mark)); - program.fold_with(&mut pass) + program.apply(pass) }) }) } else { From 94705bd259b97d13d736328c269264b5c65c8818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:49:45 +0900 Subject: [PATCH 175/186] Pass --- crates/swc/benches/typescript.rs | 6 +++--- crates/swc/tests/projects.rs | 8 ++------ crates/swc_node_bundler/src/loaders/swc.rs | 4 +++- crates/swc_node_bundler/tests/fixture.rs | 4 ++-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/crates/swc/benches/typescript.rs b/crates/swc/benches/typescript.rs index a9e9ab3a15bc..50976a98b595 100644 --- a/crates/swc/benches/typescript.rs +++ b/crates/swc/benches/typescript.rs @@ -52,8 +52,8 @@ fn as_es(c: &swc::Compiler) -> Program { let top_level_mark = Mark::new(); program - .fold_with(&mut resolver(unresolved_mark, top_level_mark, true)) - .fold_with(&mut typescript::strip(unresolved_mark, top_level_mark)) + .apply(&mut resolver(unresolved_mark, top_level_mark, true)) + .apply(&mut typescript::strip(unresolved_mark, top_level_mark)) } fn base_tr_group(c: &mut Criterion) { @@ -73,7 +73,7 @@ fn base_tr_fixer(b: &mut Bencher) { GLOBALS.set(&Default::default(), || { let handler = Handler::with_emitter_writer(Box::new(stderr()), Some(c.cm.clone())); black_box(c.run_transform(&handler, true, || { - module.clone().fold_with(&mut fixer(Some(c.comments()))) + module.clone().apply(&mut fixer(Some(c.comments()))) })) }) }); diff --git a/crates/swc/tests/projects.rs b/crates/swc/tests/projects.rs index 8252a1077494..e1cf48e826f0 100644 --- a/crates/swc/tests/projects.rs +++ b/crates/swc/tests/projects.rs @@ -14,7 +14,6 @@ use swc::{ try_with_handler, BoolOrDataConfig, Compiler, TransformOutput, }; use swc_common::{ - chain, comments::{Comment, SingleThreadedComments}, errors::{EmitterWriter, Handler, HANDLER}, sync::Lrc, @@ -24,11 +23,8 @@ use swc_compiler_base::{IsModule, PrintArgs}; use swc_ecma_ast::*; use swc_ecma_minifier::option::MangleOptions; use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax}; -use swc_ecma_transforms::{ - helpers::{self, Helpers}, - pass::noop, -}; -use swc_ecma_visit::{Fold, FoldWith}; +use swc_ecma_transforms::helpers::{self, Helpers}; +use swc_ecma_visit::Fold; use testing::{NormalizedOutput, StdErr, Tester}; use walkdir::WalkDir; diff --git a/crates/swc_node_bundler/src/loaders/swc.rs b/crates/swc_node_bundler/src/loaders/swc.rs index c69ea892b19e..807af3b03524 100644 --- a/crates/swc_node_bundler/src/loaders/swc.rs +++ b/crates/swc_node_bundler/src/loaders/swc.rs @@ -193,7 +193,9 @@ impl SwcLoader { program.mutate(&mut expr_simplifier(unresolved_mark, Default::default())); - program.mutate(&mut dead_branch_remover(unresolved_mark)) + program.mutate(&mut dead_branch_remover(unresolved_mark)); + + program }) }) } else { diff --git a/crates/swc_node_bundler/tests/fixture.rs b/crates/swc_node_bundler/tests/fixture.rs index 35d1b7375996..82dab18ef4af 100644 --- a/crates/swc_node_bundler/tests/fixture.rs +++ b/crates/swc_node_bundler/tests/fixture.rs @@ -12,7 +12,7 @@ use swc_bundler::{BundleKind, Bundler, Config, ModuleRecord}; use swc_common::{errors::HANDLER, FileName, Globals, Span, GLOBALS}; use swc_ecma_ast::{ Bool, EsVersion, Expr, IdentName, KeyValueProp, Lit, MemberExpr, MemberProp, MetaPropExpr, - MetaPropKind, PropName, Str, + MetaPropKind, Program, PropName, Str, }; use swc_ecma_loader::{TargetEnv, NODE_BUILTINS}; use swc_ecma_transforms::fixer; @@ -86,7 +86,7 @@ fn pass(input_dir: PathBuf) { let comments = compiler.comments().clone(); let code = compiler .print( - &bundled.module.fold_with(&mut fixer(None)), + &Program::Module(bundled.module).apply(&mut fixer(None)), PrintArgs { comments: Some(&comments), codegen_config: swc_ecma_codegen::Config::default() From 30cd5fb3dd14761a0dfcdbf730cd43fb49a8e5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 25 Oct 2024 22:51:35 +0900 Subject: [PATCH 176/186] Pass --- crates/swc/benches/typescript.rs | 1 - crates/swc/src/config/mod.rs | 18 ++++++++---------- crates/swc/tests/projects.rs | 12 ++++++------ crates/swc/tests/rust_api.rs | 19 +++++++++---------- crates/swc_estree_compat/benches/babelify.rs | 1 - crates/swc_node_bundler/src/loaders/swc.rs | 3 +-- crates/swc_node_bundler/tests/fixture.rs | 1 - 7 files changed, 24 insertions(+), 31 deletions(-) diff --git a/crates/swc/benches/typescript.rs b/crates/swc/benches/typescript.rs index 50976a98b595..e9cf30ae3cf1 100644 --- a/crates/swc/benches/typescript.rs +++ b/crates/swc/benches/typescript.rs @@ -14,7 +14,6 @@ use swc_compiler_base::PrintArgs; use swc_ecma_ast::{EsVersion, Program}; use swc_ecma_parser::Syntax; use swc_ecma_transforms::{fixer, resolver, typescript}; -use swc_ecma_visit::FoldWith; static SOURCE: &str = include_str!("assets/Observable.ts"); diff --git a/crates/swc/src/config/mod.rs b/crates/swc/src/config/mod.rs index 5d8229c51742..39c2fd929560 100644 --- a/crates/swc/src/config/mod.rs +++ b/crates/swc/src/config/mod.rs @@ -461,11 +461,11 @@ impl Options { }; let json_parse_pass = { - if let Some(ref cfg) = optimizer.as_ref().and_then(|v| v.jsonify) { - Some(json_parse(cfg.min_cost)) - } else { - None - } + optimizer + .as_ref() + .and_then(|v| v.jsonify) + .as_ref() + .map(|cfg| json_parse(cfg.min_cost)) }; let simplifier_pass = { @@ -496,11 +496,9 @@ impl Options { }; let optimization = { - if let Some(opts) = optimizer.and_then(|o| o.globals) { - Some(opts.build(cm, handler)) - } else { - None - } + optimizer + .and_then(|o| o.globals) + .map(|opts| opts.build(cm, handler)) }; let unresolved_ctxt = SyntaxContext::empty().apply_mark(unresolved_mark); diff --git a/crates/swc/tests/projects.rs b/crates/swc/tests/projects.rs index e1cf48e826f0..d2d29382b0fd 100644 --- a/crates/swc/tests/projects.rs +++ b/crates/swc/tests/projects.rs @@ -24,7 +24,7 @@ use swc_ecma_ast::*; use swc_ecma_minifier::option::MangleOptions; use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax}; use swc_ecma_transforms::helpers::{self, Helpers}; -use swc_ecma_visit::Fold; +use swc_ecma_visit::{fold_pass, Fold}; use testing::{NormalizedOutput, StdErr, Tester}; use walkdir::WalkDir; @@ -728,14 +728,14 @@ fn should_visit() { }, &fm.name, Some(&comments), - |_| noop(), + |_| noop_pass(), ) .unwrap() .unwrap(); dbg!(config.syntax); - let config = config.with_pass(|pass| (Panicking, pass)); + let config = config.with_pass(|pass| (fold_pass(Panicking), pass)); if config.minify { let preserve_excl = |_: &BytePos, vc: &mut Vec| -> bool { @@ -745,12 +745,12 @@ fn should_visit() { c.comments().leading.retain(preserve_excl); c.comments().trailing.retain(preserve_excl); } - let mut pass = config.pass; + let pass = config.pass; let program = config.program; let program = helpers::HELPERS.set(&Helpers::new(config.external_helpers), || { HANDLER.set(&handler, || { // Fold module - program.fold_with(&mut pass) + program.apply(pass) }) }); @@ -1068,7 +1068,7 @@ fn issue_6009() { // test parsing input let config = c .parse_js_as_input(fm.clone(), None, &handler, &options, &fm.name, None, |_| { - noop() + noop_pass() }) .unwrap(); diff --git a/crates/swc/tests/rust_api.rs b/crates/swc/tests/rust_api.rs index c7f3f0bcc040..b1a048f7c6a6 100644 --- a/crates/swc/tests/rust_api.rs +++ b/crates/swc/tests/rust_api.rs @@ -5,7 +5,6 @@ use swc::{ use swc_common::{comments::SingleThreadedComments, FileName}; use swc_ecma_ast::*; use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax}; -use swc_ecma_transforms::pass::noop; use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut}; struct PanicOnVisit; @@ -50,7 +49,7 @@ fn test_visit_mut() { }, SingleThreadedComments::default(), |_| visit_mut_pass(PanicOnVisit), - |_| noop(), + |_| noop_pass(), ); assert_ne!(res.unwrap().code, "console.log(5 as const)"); @@ -100,9 +99,9 @@ fn shopify_1_check_filename() { SingleThreadedComments::default(), |_| { // Ensure comment API - noop() + noop_pass() }, - |_| noop(), + |_| noop_pass(), ); if res.is_err() { @@ -184,8 +183,8 @@ fn shopify_2_same_opt() { &handler, &opts, SingleThreadedComments::default(), - |_| noop(), - |_| noop(), + |_| noop_pass(), + |_| noop_pass(), ); if res.is_err() { @@ -252,8 +251,8 @@ fn shopify_3_reduce_defaults() { &handler, &opts, SingleThreadedComments::default(), - |_| noop(), - |_| noop(), + |_| noop_pass(), + |_| noop_pass(), ); if res.is_err() { @@ -315,8 +314,8 @@ fn shopify_4_reduce_more() { &handler, &opts, SingleThreadedComments::default(), - |_| noop(), - |_| noop(), + |_| noop_pass(), + |_| noop_pass(), ); if res.is_err() { diff --git a/crates/swc_estree_compat/benches/babelify.rs b/crates/swc_estree_compat/benches/babelify.rs index 2644f6bc5050..aa22f294dcd8 100644 --- a/crates/swc_estree_compat/benches/babelify.rs +++ b/crates/swc_estree_compat/benches/babelify.rs @@ -8,7 +8,6 @@ use swc_common::{ use swc_ecma_ast::{EsVersion, Program}; use swc_ecma_parser::Syntax; use swc_ecma_transforms::{compat::es2020, resolver, typescript}; -use swc_ecma_visit::FoldWith; use swc_estree_compat::babelify::{Babelify, Context}; static SOURCE: &str = include_str!("assets/AjaxObservable.ts"); diff --git a/crates/swc_node_bundler/src/loaders/swc.rs b/crates/swc_node_bundler/src/loaders/swc.rs index 807af3b03524..a53fd54c4ace 100644 --- a/crates/swc_node_bundler/src/loaders/swc.rs +++ b/crates/swc_node_bundler/src/loaders/swc.rs @@ -27,7 +27,6 @@ use swc_ecma_transforms::{ resolver, typescript::typescript, }; -use swc_ecma_visit::{FoldWith, VisitMutWith}; use crate::loaders::json::load_json_as_module; @@ -258,7 +257,7 @@ impl SwcLoader { // Note that we don't apply compat transform at loading phase. let program = if let Some(config) = config { let mut program = config.program; - let mut pass = config.pass; + let pass = config.pass; helpers::HELPERS.set(&helpers, || { HANDLER.set(handler, || { diff --git a/crates/swc_node_bundler/tests/fixture.rs b/crates/swc_node_bundler/tests/fixture.rs index 82dab18ef4af..ca48f638cb0b 100644 --- a/crates/swc_node_bundler/tests/fixture.rs +++ b/crates/swc_node_bundler/tests/fixture.rs @@ -16,7 +16,6 @@ use swc_ecma_ast::{ }; use swc_ecma_loader::{TargetEnv, NODE_BUILTINS}; use swc_ecma_transforms::fixer; -use swc_ecma_visit::FoldWith; use swc_node_bundler::loaders::swc::SwcLoader; use testing::NormalizedOutput; From aacccc7dff4abd887d108e9d9183db145c4d4f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Sat, 26 Oct 2024 17:31:25 +0900 Subject: [PATCH 177/186] * --- crates/swc_core/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/swc_core/src/lib.rs b/crates/swc_core/src/lib.rs index 89b7165fb3f6..1439bc9e790d 100644 --- a/crates/swc_core/src/lib.rs +++ b/crates/swc_core/src/lib.rs @@ -53,9 +53,7 @@ pub mod ecma { )] pub mod transforms { pub mod base { - pub use swc_ecma_transforms_base::{ - assumptions::Assumptions, feature, fixer, helpers, hygiene, pass, perf, resolver, - }; + pub use swc_ecma_transforms_base::*; } #[cfg(feature = "ecma_transforms_optimization")] #[cfg_attr(docsrs, doc(cfg(feature = "transforms_optimization")))] From 4a4164a7f33bc34c082f298fcba33397256af2ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 28 Oct 2024 06:48:56 +0900 Subject: [PATCH 178/186] visit_mut_ident --- crates/swc_ecma_visit/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index ae839efcc316..69b42649d53f 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -1017,6 +1017,14 @@ macro_rules! impl_traits_for_tuple { self.$idx_rest.visit_mut_assign_target(target); )* } + + fn visit_mut_ident(&mut self, ident: &mut Ident) { + self.$idx.visit_mut_ident(ident); + + $( + self.$idx_rest.visit_mut_ident(ident); + )* + } } }; } From 3a834d1009dc3ccb15602d764e0b098f88727972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 28 Oct 2024 06:56:21 +0900 Subject: [PATCH 179/186] fix visit/fold --- crates/swc_ecma_visit/src/lib.rs | 90 ++++++++++++++++++++++++++++---- 1 file changed, 80 insertions(+), 10 deletions(-) diff --git a/crates/swc_ecma_visit/src/lib.rs b/crates/swc_ecma_visit/src/lib.rs index 69b42649d53f..87d9d463dea7 100644 --- a/crates/swc_ecma_visit/src/lib.rs +++ b/crates/swc_ecma_visit/src/lib.rs @@ -44,6 +44,46 @@ where fn fold_program(&mut self, node: Program) -> Program { self.pass.fold_program(node) } + + #[inline(always)] + fn fold_module(&mut self, node: Module) -> Module { + self.pass.fold_module(node) + } + + #[inline(always)] + fn fold_script(&mut self, node: Script) -> Script { + self.pass.fold_script(node) + } + + #[inline(always)] + fn fold_stmt(&mut self, node: Stmt) -> Stmt { + self.pass.fold_stmt(node) + } + + #[inline(always)] + fn fold_module_item(&mut self, item: ModuleItem) -> ModuleItem { + self.pass.fold_module_item(item) + } + + #[inline(always)] + fn fold_expr(&mut self, expr: Expr) -> Expr { + self.pass.fold_expr(expr) + } + + #[inline(always)] + fn fold_pat(&mut self, pat: Pat) -> Pat { + self.pass.fold_pat(pat) + } + + #[inline(always)] + fn fold_assign_target(&mut self, target: AssignTarget) -> AssignTarget { + self.pass.fold_assign_target(target) + } + + #[inline(always)] + fn fold_ident(&mut self, ident: Ident) -> Ident { + self.pass.fold_ident(ident) + } } impl Repeated for FoldPass @@ -97,6 +137,46 @@ where fn visit_mut_program(&mut self, program: &mut Program) { self.pass.visit_mut_program(program); } + + #[inline(always)] + fn visit_mut_module(&mut self, module: &mut Module) { + self.pass.visit_mut_module(module); + } + + #[inline(always)] + fn visit_mut_script(&mut self, script: &mut Script) { + self.pass.visit_mut_script(script); + } + + #[inline(always)] + fn visit_mut_module_item(&mut self, item: &mut ModuleItem) { + self.pass.visit_mut_module_item(item); + } + + #[inline(always)] + fn visit_mut_stmt(&mut self, stmt: &mut Stmt) { + self.pass.visit_mut_stmt(stmt); + } + + #[inline(always)] + fn visit_mut_expr(&mut self, expr: &mut Expr) { + self.pass.visit_mut_expr(expr); + } + + #[inline(always)] + fn visit_mut_pat(&mut self, pat: &mut Pat) { + self.pass.visit_mut_pat(pat); + } + + #[inline(always)] + fn visit_mut_assign_target(&mut self, target: &mut AssignTarget) { + self.pass.visit_mut_assign_target(target); + } + + #[inline(always)] + fn visit_mut_ident(&mut self, ident: &mut Ident) { + self.pass.visit_mut_ident(ident); + } } impl Repeated for VisitMutPass @@ -142,16 +222,6 @@ where } } -impl Visit for VisitPass -where - V: Visit, -{ - #[inline(always)] - fn visit_program(&mut self, program: &Program) { - self.pass.visit_program(program); - } -} - impl Repeated for VisitPass where V: Visit + Repeated, From ee3b7aaa1ff892fb167571d2419a0a373da9841a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Mon, 28 Oct 2024 06:57:28 +0900 Subject: [PATCH 180/186] Create few-pigs-shout.md --- .changeset/few-pigs-shout.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/few-pigs-shout.md diff --git a/.changeset/few-pigs-shout.md b/.changeset/few-pigs-shout.md new file mode 100644 index 000000000000..2d84a886c2be --- /dev/null +++ b/.changeset/few-pigs-shout.md @@ -0,0 +1,6 @@ +--- +swc_visit: major +swc_common: major +--- + +perf(visit): Introduce `Pass` API and adjust visitor APIs for it From 1b570ee46033330a86a1b6665a6399a4f8e28b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 28 Oct 2024 07:23:31 +0900 Subject: [PATCH 181/186] Fix --- crates/swc_ecma_transforms_compat/tests/es2015_generator.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs b/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs index 5713c78c7396..bf8cfd507e20 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_generator.rs @@ -1249,7 +1249,6 @@ async function foo(a) { } foo(1) - .then((t) => .then((t) => t(2)) .then(console.log); "# From dc823ab00751373811167e91da6dbc13e08edc1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Mon, 28 Oct 2024 07:31:31 +0900 Subject: [PATCH 182/186] fix --- crates/swc_ecma_transforms_classes/src/super_field.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_classes/src/super_field.rs b/crates/swc_ecma_transforms_classes/src/super_field.rs index 3bc4b9a26c12..5023f9a74e7f 100644 --- a/crates/swc_ecma_transforms_classes/src/super_field.rs +++ b/crates/swc_ecma_transforms_classes/src/super_field.rs @@ -64,7 +64,7 @@ macro_rules! mark_nested { } impl VisitMut for SuperFieldAccessFolder<'_> { - noop_visit_mut_type!(fail); + noop_visit_mut_type!(); // mark_nested!(fold_function, Function); mark_nested!(visit_mut_class, Class); From a153f20d2b45b3512bbbe1e18ebe55e2906158d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Tue, 29 Oct 2024 10:52:42 +0900 Subject: [PATCH 183/186] Update few-pigs-shout.md --- .changeset/few-pigs-shout.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/few-pigs-shout.md b/.changeset/few-pigs-shout.md index 2d84a886c2be..c7cafce9af0b 100644 --- a/.changeset/few-pigs-shout.md +++ b/.changeset/few-pigs-shout.md @@ -1,6 +1,7 @@ --- swc_visit: major swc_common: major +swc_plugin_proxy: major --- perf(visit): Introduce `Pass` API and adjust visitor APIs for it From a51ec2c367ad4b2ec99f48e40968a0de75388671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Tue, 29 Oct 2024 10:57:19 +0900 Subject: [PATCH 184/186] fix --- bindings/binding_minifier_node/src/minify.rs | 2 +- crates/binding_macros/src/wasm.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bindings/binding_minifier_node/src/minify.rs b/bindings/binding_minifier_node/src/minify.rs index 051e2d2fe5e8..7cb2181bbdbe 100644 --- a/bindings/binding_minifier_node/src/minify.rs +++ b/bindings/binding_minifier_node/src/minify.rs @@ -184,7 +184,7 @@ fn do_work( let is_mangler_enabled = min_opts.mangle.is_some(); let module = { - let module = module.fold_with(&mut resolver(unresolved_mark, top_level_mark, false)); + let module = module.apply(resolver(unresolved_mark, top_level_mark, false)); let mut module = swc_core::ecma::minifier::optimize( module, diff --git a/crates/binding_macros/src/wasm.rs b/crates/binding_macros/src/wasm.rs index e4655fc0de27..c75e0f1e6a49 100644 --- a/crates/binding_macros/src/wasm.rs +++ b/crates/binding_macros/src/wasm.rs @@ -25,9 +25,11 @@ pub use swc_common::{ }; use swc_common::{sync::Lrc, FilePathMapping, SourceMap}; #[doc(hidden)] +pub use swc_ecma_ast::noop_pass; +#[doc(hidden)] pub use swc_ecma_ast::{EsVersion, Program}; #[doc(hidden)] -pub use swc_ecma_transforms::{pass::noop, resolver}; +pub use swc_ecma_transforms::resolver; #[doc(hidden)] pub use swc_ecma_visit::VisitMutWith; #[doc(hidden)] @@ -293,7 +295,7 @@ macro_rules! build_print { #[macro_export] macro_rules! build_transform_sync { ($(#[$m:meta])*) => { - build_transform_sync!($(#[$m])*, |_| $crate::wasm::noop(), |_| $crate::wasm::noop(), Default::default()); + build_transform_sync!($(#[$m])*, |_| $crate::wasm::noop_pass(), |_| $crate::wasm::noop_pass(), Default::default()); }; ($(#[$m:meta])*, $before_pass: expr, $after_pass: expr) => { build_transform_sync!($(#[$m])*, $before_pass, $after_pass, Default::default()); From 7c153c098c58d9d565a597889c6cd023fa433eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Tue, 29 Oct 2024 11:06:30 +0900 Subject: [PATCH 185/186] fix --- .../tests/fixture/swc_internal_plugin/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/swc_plugin_runner/tests/fixture/swc_internal_plugin/src/lib.rs b/crates/swc_plugin_runner/tests/fixture/swc_internal_plugin/src/lib.rs index 5ba106abe91f..6e291c9d4049 100644 --- a/crates/swc_plugin_runner/tests/fixture/swc_internal_plugin/src/lib.rs +++ b/crates/swc_plugin_runner/tests/fixture/swc_internal_plugin/src/lib.rs @@ -59,7 +59,7 @@ impl VisitMut for ConsoleOutputReplacer { /// important steps manually need to be performed like sending transformed /// results back to host. Refer swc_plugin_macro how does it work internally. #[plugin_transform] -pub fn process(program: Program, metadata: TransformPluginProgramMetadata) -> Program { +pub fn process(mut program: Program, metadata: TransformPluginProgramMetadata) -> Program { dbg!(); HANDLER.with(|handler| { handler @@ -134,5 +134,6 @@ pub fn process(program: Program, metadata: TransformPluginProgramMetadata) -> Pr dbg!(); - program.fold_with(&mut visit_mut_pass(ConsoleOutputReplacer { metadata })) + program.visit_mut_with(&mut ConsoleOutputReplacer { metadata }); + program } From 078e9f2b221c5edb1e20e069f7cd5a44dd654c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Tue, 29 Oct 2024 11:12:22 +0900 Subject: [PATCH 186/186] fix --- crates/swc/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/swc/src/lib.rs b/crates/swc/src/lib.rs index 02cb9391e16f..6f53258c7303 100644 --- a/crates/swc/src/lib.rs +++ b/crates/swc/src/lib.rs @@ -950,7 +950,7 @@ impl Compiler { config: BuiltInput, ) -> Result { self.run(|| { - let mut program = config.program; + let program = config.program; if config.emit_isolated_dts && !config.syntax.typescript() { handler.warn( @@ -979,12 +979,13 @@ impl Compiler { let comments = SingleThreadedComments::from_leading_and_trailing(leading, trailing); let mut checker = FastDts::new(fm.name.clone()); - let mut module = program.clone().expect_module(); + let mut module = program.clone(); if let Some((base, resolver)) = config.resolver { - program.mutate(import_rewriter(base, resolver)); + module.mutate(import_rewriter(base, resolver)); } + let mut module = module.expect_module(); let issues = checker.transform(&mut module); for issue in issues {