Skip to content

Is there a demo for transform plugin with tests #5129

Answered by chenjun1011
chenjun1011 asked this question in Q&A
Discussion options

You must be logged in to vote

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.

  1. Compiler Error:

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()));
        }
    }
}
  1. Compiler error when use the latest swc_plugin(0.73.0), 0.71.0 is ok.

  1. Need add rlib to crate…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by chenjun1011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant