簡體   English   中英

如何通過 JS function 表達式在 rust 中創建 swc 插件?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM