-
I'm trying to get a hold of swc, but I haven't found a way to apply multiple transformations to the same source (via different structs that implement For example, for: use std::{path::Path, sync::Arc};
use swc::config::Options;
use swc_common::{
errors::{ColorConfig, Handler},
SourceMap,
};
use swc_ecmascript::{
ast::{ArrayLit, CallExpr, EsVersion},
parser::parse_file_as_program,
transforms::pass::noop,
visit::as_folder,
visit::{VisitMut, VisitMutWith},
};
const ES_VERSION: EsVersion = EsVersion::Es2022;
fn main() {
let cm = Arc::<SourceMap>::default();
let handler = Handler::with_tty_emitter(ColorConfig::Auto, true, false, Some(cm.clone()));
let c = swc::Compiler::new(cm.clone());
let fm = cm.load_file(Path::new("./main.js")).unwrap();
let program =
parse_file_as_program(&fm, Default::default(), ES_VERSION, None, &mut vec![]).unwrap();
let pass = c.process_js_with_custom_pass(
fm,
Some(program),
&handler,
&Options::default(),
|_, _| noop(),
|_, _| as_folder(Visitor1),
);
println!("{:#?}", pass.unwrap());
}
struct Visitor1;
impl VisitMut for Visitor1 {
fn visit_mut_call_expr(&mut self, expr: &mut CallExpr) {
expr.visit_mut_children_with(self);
}
}
struct Visitor2;
impl VisitMut for Visitor2 {
fn visit_mut_array_lit(&mut self, arr_expr: &mut ArrayLit) {
arr_expr.visit_mut_children_with(self)
}
}
Is there a way to do: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Did you try |
Beta Was this translation helpful? Give feedback.
Did you try
chain!
macro? https://github.com/vercel/next.js/blob/6356095481f0ecca38302c4e059e1d9470f4e08d/packages/next-swc/crates/core/src/lib.rs#L133