Let's say I have a JavaScript file with an array of literals:
[
"foo",
[
"bar",
123
],
"baz"
]
How could I rewrite that file by parsing and manipulating the AST (not process the values at runtime) to flatten the array, resulting in:
["foo", "bar", 123, "baz"]
I know I can get an ESTree from Acorn, for example, but have no idea how to proceed from there:
const code = fs.readFileSync(file, 'utf8')
const ast = acorn.parse(code)
const newCode = ast.???
fs.writeFileSync(file, newCode)