You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 plugin runner 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.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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