I am using SpiderMonkey for a project and I need it for 2 tasks:
- Getting AST node information given a JavaScript string.
- Writing JavaScript from an AST node.
The first task is accomplished by means of js Reflect.parse('var a = 13;');
which returns me the AST, fine!
From AST to JavaScript
The second task is what I need. I want to instruct js
(or probably the Reflect
object, I suppose) to take a node:
{
type:"Program",
body:[
{
type:"VariableDeclaration",
kind:"var",
declarations:[
{
type:"VariableDeclarator",
id:{type:"Identifier", name:"a"},
init:{type:"Literal", value:13}
}
]
}
]
}
And write down: var a = 13;
.
How can I achieve this which is sort of a reverse process to Reflect.parse
? Thanks