Can my vue application transform the given string into a callable function?
const test = 'import { pi } from "MathPie"; function test() { console.log(pi); } export default test;'
The desired output format is:
import { pi } from "MathPie";
function test() {
console.log(pi);
}
export default test;
I've attempted to use eval
but it does not support import
statements.
eval(test)()
> Cannot use import statement outside a module
> Should log '3.14159'
Note: This example is purely for demonstration purposes, I am aware of Math.PI
Is there a way to execute a string containing an import
statement? Any suggestions would be appreciated.