there is a question about esprima and inserting an ast node.
I try to generate one ast node to replace other node with new node , (node = newNode) , but It does't work.
estraverse.traverse(tree, {
enter(node, parent) {
try {
if (node.type === "ExpressionStatement") {
if(node.expression.right.type == "FunctionExpression"){
// the id attribution can be replaced
node.expression.right.id = node.expression.left;
// but node can not be replaced
node = node.expression.right;
node.type = "FunctionDeclaration";
}
}
} catch (error) {
}
},});