Transform javascript string with `import` statement into a function in the browser

I will like my vue application to transform the following string:

const test = 'import { pi } from "MathPie"; function test() { console.log(pi); } export default test;'

into a function that I could call.

import { pi } from "MathPie";

function test() {
  console.log(pi);
}

export default test;

I already tried using eval (even if it’s evil), but it doens’t work because import statement aren’t supported by it.

eval(test)()
> Cannot use import statement outside a module
> Should log '3.14159'

The snippet is for presentation only, I’m aware of Math.PI

My question is how I can evaluate a string with import statement?