diff --git a/crates/swc/src/lib.rs b/crates/swc/src/lib.rs index cc9f5d2f25c..33a24fc1a5a 100644 --- a/crates/swc/src/lib.rs +++ b/crates/swc/src/lib.rs @@ -925,8 +925,8 @@ impl Compiler { program: Option, handler: &Handler, opts: &Options, - custom_before_pass: impl FnOnce(&Program) -> P1, - custom_after_pass: impl FnOnce(&Program) -> P2, + custom_before_pass: impl FnOnce(&Program, &SingleThreadedComments) -> P1, + custom_after_pass: impl FnOnce(&Program, &SingleThreadedComments) -> P2, ) -> Result where P1: swc_ecma_visit::Fold, @@ -942,7 +942,7 @@ impl Compiler { opts, &fm.name, Some(&comments), - custom_before_pass, + |program| custom_before_pass(program, &comments), ) })?; let config = match config { @@ -952,7 +952,7 @@ impl Compiler { } }; - let pass = chain!(config.pass, custom_after_pass(&config.program)); + let pass = chain!(config.pass, custom_after_pass(&config.program, &comments)); let config = BuiltInput { program: config.program, @@ -989,7 +989,7 @@ impl Compiler { handler: &Handler, opts: &Options, ) -> Result { - self.process_js_with_custom_pass(fm, None, handler, opts, |_| noop(), |_| noop()) + self.process_js_with_custom_pass(fm, None, handler, opts, |_, _| noop(), |_, _| noop()) } #[tracing::instrument(level = "info", skip_all)] @@ -1127,7 +1127,14 @@ impl Compiler { let loc = self.cm.lookup_char_pos(program.span().lo()); let fm = loc.file; - self.process_js_with_custom_pass(fm, Some(program), handler, opts, |_| noop(), |_| noop()) + self.process_js_with_custom_pass( + fm, + Some(program), + handler, + opts, + |_, _| noop(), + |_, _| noop(), + ) } #[tracing::instrument(level = "info", skip_all)] diff --git a/crates/swc/tests/rust_api.rs b/crates/swc/tests/rust_api.rs index c7a38a8d4f1..b957d02eda3 100644 --- a/crates/swc/tests/rust_api.rs +++ b/crates/swc/tests/rust_api.rs @@ -4,7 +4,7 @@ use swc::{ }, Compiler, }; -use swc_common::FileName; +use swc_common::{comments::SingleThreadedComments, FileName}; use swc_ecma_ast::*; use swc_ecma_parser::{EsConfig, Syntax, TsConfig}; use swc_ecma_transforms::{modules::common_js, pass::noop}; @@ -50,8 +50,8 @@ fn test_visit_mut() { ..Default::default() }, - |_| as_folder(PanicOnVisit), - |_| noop(), + |_, _| as_folder(PanicOnVisit), + |_, _| noop(), ); assert_ne!(res.unwrap().code, "console.log(5 as const)"); @@ -101,8 +101,11 @@ fn shopify_1_check_filename() { is_module: IsModule::Bool(true), ..Default::default() }, - |_| noop(), - |_| noop(), + |_, _: &SingleThreadedComments| { + // Ensure comment API + noop() + }, + |_, _: &SingleThreadedComments| noop(), ); if res.is_err() { @@ -181,7 +184,8 @@ fn shopify_2_same_opt() { .into(), ); - let res = c.process_js_with_custom_pass(fm, None, &handler, &opts, |_| noop(), |_| noop()); + let res = + c.process_js_with_custom_pass(fm, None, &handler, &opts, |_, _| noop(), |_, _| noop()); if res.is_err() { return Err(()); @@ -242,7 +246,8 @@ fn shopify_3_reduce_defaults() { .into(), ); - let res = c.process_js_with_custom_pass(fm, None, &handler, &opts, |_| noop(), |_| noop()); + let res = + c.process_js_with_custom_pass(fm, None, &handler, &opts, |_, _| noop(), |_, _| noop()); if res.is_err() { return Err(()); @@ -298,7 +303,8 @@ fn shopify_4_reduce_more() { .into(), ); - let res = c.process_js_with_custom_pass(fm, None, &handler, &opts, |_| noop(), |_| noop()); + let res = + c.process_js_with_custom_pass(fm, None, &handler, &opts, |_, _| noop(), |_, _| noop()); if res.is_err() { return Err(()); diff --git a/crates/swc_ecma_transforms_testing/src/lib.rs b/crates/swc_ecma_transforms_testing/src/lib.rs index 168a1b8a140..a057462feec 100644 --- a/crates/swc_ecma_transforms_testing/src/lib.rs +++ b/crates/swc_ecma_transforms_testing/src/lib.rs @@ -43,6 +43,12 @@ use testing::{assert_eq, find_executable, NormalizedOutput}; pub struct Tester<'a> { pub cm: Lrc, pub handler: &'a Handler, + /// This will be changed to [SingleThreadedComments] once `cargo-mono` + /// supports correct bumping logic, or we need to make a breaking change in + /// a upstream crate of this crate. + /// + /// Although type is `Rc`, it's fine to clone + /// `SingleThreadedComments` without `Rc`. pub comments: Rc, } diff --git a/cspell.json b/cspell.json index a094a3b92c5..f61c9c2b4b2 100644 --- a/cspell.json +++ b/cspell.json @@ -129,6 +129,7 @@ "sabi", "seqs", "sess", + "shopify", "skippable", "smallvec", "spanx",