I want to evaluate all the variables inside a function before converting the function to a string.
Example:
const x = "5";
function someFunc(){
console.log(x);
}
someFunc.toString()
Output:
function someFunc(){
console.log(x);
}
Expected output:
function someFunc(){
console.log("5");
}
I need it to work dynamically for any number of variables and any function without knowing the function or the variables first. I prefer a solution based on metaprogramming such as reflection, but any working solution is good, including Regex.
Any ideas on how to implement that?