#eval() difference dev/build in client

1 messages · Page 1 of 1 (latest)

gray wigeon
#

your question is fair. Dev and Build are total different beasts, Astro is using Vite, you can read Vite doc if you want to know the difference. As of why eval is a security risk, is that if connected to user input users can hack your site, you might say but you didn't connect it to user input, the compiler prefers to be on the safe side, rather safe than sorry.

lapis osprey
#

this isn't answering the question but it might be helpful (to avoid eval)
if in someDumbData you export default an object of those consts, like:

const tree_oak = "oak tree";
const tree_spruce = "spruce tree"; // or whatever your data is

export default { tree_oak, tree_spruce }

then you can

import trees from "./someDumbData";
function myFunction() {
  let theTree = "oak";
  alert(trees[`tree_${theTree}`]);
}

this code would only work for you if tree_oak and tree_spruce are the only data in someDumbData in which case you could rename it to trees.js/trees.ts

vernal sierra
#

Thank you, that is helpful

#

but im already using eval in a few different ways

vernal sierra
gray wigeon
vernal sierra
gray wigeon
vernal sierra