plugin-preeval: (clickbait) running JS inside of swc plugins #7646
kwonoj
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
https://github.com/kwonoj/swc-plugin-preeval
A demo swc plugin that compile-time evaluates codes.
Say you have a code like this:
Transformed codes with this plugin will be:
By plugin runs, evaluate codes inside of
preeval
template tag. It is backed by boa engine, which is a JavaScript interpreter written in Rust.Since plugin only embeds JS interpreter but not the runtime, this is pretty much useless. For example, you can't have module imports, or any runtime apis from node.js or browsers. For those reason, this plugin is not published anywhere. The idea might be improved - this could be a step forward to something similar to
babel-plugin-macro
, or even making a pluginrunner
that runs JS-based plugin transformer inside of wasm plugins or any case that plugin want to evaluate some JS codes inside without help of host runtime.Beta Was this translation helpful? Give feedback.
All reactions