![](/img/trans.png)
[英]In Rust how do I pass a diverging function as parameter to another function
[英]How do I pass a JS function expression for creating an swc plugin in rust?
我正在嘗試按照此SWC 文檔開發可以編譯為 wasm 的插件。 visit_mut_callee
function 有條件語句
if let Callee::Expr(expr) = callee {
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();
}
}
}
}
目標
要使用visit_mut_callee
在代碼庫中檢測 function 表達式,我想檢測的表達式是getMyFileMetaInfo
。
例子,
<SomeReactComponent metaInfo={getMyFileMetaInfo()} />
通過使用Box::new
來包裝Expr
類型來解決它。
let _box_expr = Box::new(build_get_file_claim_expr());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.