Is there a demo for transform plugin with tests #5129
-
I init a plugin project followed the doc Implementing a plugin . But having some trouble when writing test for this plugin. It should how to mock the parameter for the transform plugin,such as #[plugin_transform]
pub fn process_transform(program: Program, _metadata: TransformPluginProgramMetadata) -> Program {
program.fold_with(&mut as_folder(TransformVisitor))
} Test for typescript type stripper in the doc seems no need to deal with this problem. So is there any demo with test for the plugin inited by swc_cli. It seems hard to debug the plugin in rust without a test as an entry. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Finally got the demo working: https://github.com/chenjun1011/swc-plugin-demo There are some points need pay attention, when followed the doc to create a new plugin.
use swc_plugin::ast::*;
use swc_plugin::util::swc_common::Spanned;
impl VisitMut for TransformVisitor {
fn visit_mut_bin_expr(&mut self, e: &mut BinExpr) {
e.visit_mut_children_with(self);
if e.op == op!("===") {
- e.left = Ident::new("kdy1".into(), e.left.span()).into();
+ e.left = Box::new(Expr::Ident(Ident::new("kdy1".into(), e.left.span()).into()));
}
}
}
[lib]
bench = false
- crate-type = ["cdylib"]
+ crate-type = ["cdylib", "rlib"] |
Beta Was this translation helpful? Give feedback.
Finally got the demo working:
https://github.com/chenjun1011/swc-plugin-demo
There are some points need pay attention, when followed the doc to create a new plugin.
rlib
tocrate…