Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Oct 21, 2024
1 parent c3b102c commit fbdd963
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions plugins/swc-plugin-canyon/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#![allow(clippy::not_unsafe_ptr_arg_deref)]

use swc_core::plugin::proxies::TransformPluginProgramMetadata;
use swc_ecma_ast::{Program, Script, Expr, ExprStmt, Stmt, Lit, Str};
use swc_ecma_visit::{Fold, FoldWith};
use swc_ecma_ast::{Program, Script, Expr, ExprStmt, Stmt, Lit, Str, BinExpr};
use swc_ecma_visit::{as_folder, Fold, FoldWith, VisitMut};
use swc_plugin_macro::plugin_transform;
use swc_core::{
ecma::{
transforms::testing::test,
}
};

#[plugin_transform]
fn plugin(program: Program, metadata: TransformPluginProgramMetadata) -> Program {
Expand Down Expand Up @@ -48,4 +53,24 @@ impl Fold for AddSimpleCode {

script
}
}
}


pub struct TransformVisitor;

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 = Box::new(Ident::new("kdy1".into(), e.left.span()).into());
}
}
}

test!(
Default::default(),
|_| as_folder(TransformVisitor),
boo,
r#"foo === bar;"#
);

0 comments on commit fbdd963

Please sign in to comment.