I currently have a template read from a file into tstr and I replace placeholders in it like so:
const obj = { main: 3 };
const func = () => { const a = 2; };
let tstr = `
<fname func>
<fbare func>
<var obj.main>
`;
tstr = tstr.replace(/<var ([^>]+)>/g, function () { return eval(arguments[1]) });
tstr = tstr.replace(/<fbare ([^>]+)>/g, function () { return eval(arguments[1]).toString() });
tstr = tstr.replace(/<fname ([^>]+)>/g, function () { return arguments[1] + ' = ' + eval(arguments[1]).toString() });
console.log(tstr);
Is there a simple way to rewrite these replacements without eval?