[英]How do I pass a JS function expression for creating an swc plugin in rust?
I am trying to follow this SWC documentation for developing a plugin that can compile to wasm.我正在尝试按照此SWC 文档开发可以编译为 wasm 的插件。 The
visit_mut_callee
function has a conditional statement visit_mut_callee
function 有条件语句
if let Callee::Expr(expr) = callee {
Callee::Expr(expr)
accepts a Box<Expr>
as per documentation, being new to rust I am unsure of what exactly needs to be passed. Callee::Expr(expr)
根据文档接受Box<Expr>
,是 rust 的新手,我不确定究竟需要传递什么。
use swc_plugin::*;
struct MatchExample;
impl VisitMut for MatchExample {
fn visit_mut_callee(&mut self, callee: &mut Callee) {
callee.visit_mut_children_with(self);
if let Callee::Expr(expr) = callee {
// expr is `Box<Expr>`
if let Expr::Ident(i) = &mut **expr {
i.sym = "foo".into();
}
}
}
}
Goal目标
To use the visit_mut_callee
to detect a function expression within a codebase, the expression I would like to detect is getMyFileMetaInfo
.要使用
visit_mut_callee
在代码库中检测 function 表达式,我想检测的表达式是getMyFileMetaInfo
。
Example,例子,
<SomeReactComponent metaInfo={getMyFileMetaInfo()} />
Resolved it by using Box::new
to wrap the Expr
type with it.通过使用
Box::new
来包装Expr
类型来解决它。
let _box_expr = Box::new(build_get_file_claim_expr());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.