Use `swc_ecma_compat_es2017::async_to_generator` for conditional async transformations

Hey team, I've been working on a plugin that takes async functions and transforms them to generators for usage with mobx flows. I've gotten reasonably far but came across: https://docs.rs/swc_ecma_compat_es2017/latest/src/swc_ecma_compat_es2017/async_to_generator.rs.html#39-46 This transformation is exactly what i've been aiming for and would make for a far more robust solution, as what i've written so far handles the conditional cases as I expect. The issue i'm running into is that I'd like to instantiate the AsyncToGenerator visitor to visit_children_with it when the conditions are met to perform this transformation, but async_to_generator returns Pass which does not satisfy VisitMut Would it be reasonable to export a function that does work this way from swc_ecma_compat_es2017? Or am I down the wrong path here?
async_to_generator.rs - source
Source of the Rust file src/async_to_generator.rs.
3 Replies
Codex
CodexOP•4d ago
I suppose I'm mainly wanting the:
AsyncToGenerator {
c,
fn_state: None,
in_subclass: false,
unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark),
}
AsyncToGenerator {
c,
fn_state: None,
in_subclass: false,
unresolved_ctxt: SyntaxContext::empty().apply_mark(unresolved_mark),
}
Without the visit_mut_pass call so I can then use it similarly 🤔 does this even make sense?
kdy1
kdy1•4d ago
Nope. I think you should just copy the code.
Codex
CodexOP•3d ago
Sweet, the only problem with that is the usage of the private API helper and helper_expr macros, but I suppose I can copy those too

Did you find this page helpful?