I want to create a function bundleFunction() that gets as a parameter a function and bundles it into a string, including all the external dependencies that it uses.
Example usage:
const f1 = 1;
const f2 = 2;
function add(a, b) {
return a + b;
}
bundleFunction(() => {
const result = add(f1, f2);
return result;
});
And the return value of bundleFunction() to look something like this:
"function () { const result = ((a, b) => { return a + b })(1, 2); return result; }
Is it even possible to do something like this or something similar? Thanks in advance!
I was thinking to try to use eval() but wasn't able to come with any viable solution.