I have a function which runs string as javascript code through eval()
. It works fine if the string is es5
but doesn't work for es6
. I know babel can transport es6 to es5 but most of them use cases are done in compile stage. How can I use babel programmatically?
I assume you can do something like this:
eval(babel.transform(code, options).code)
However I would strongly reconsider that! First, eval
is usually a very, very dangerous thing, and next babel is huge. You don't want to deliver that to a browser if you don't have to.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.