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
I suppose I'm mainly wanting the:
Without the
visit_mut_pass
call so I can then use it similarly 🤔 does this even make sense?Nope. I think you should just copy the code.
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