UglifyJS can be used in both the browser and NodeJS, similar to Esprima's functionality (though it's advisable to verify browser compatibility specs for each). You can experiment with UglifyJS in the browser (Chrome is recommended) by visiting the UglifyJS site and accessing your inspector console to enter:
var ast = UglifyJS.parse("var foo= 1")
You can then analyze the AST data. For instance, to retrieve the name of the variable declaration, use:
ast.body[0].definitions[0].name.name // returns "foo"
If you wish to alter the AST tree structure, review the architecture and create your own AST nodes to expand the tree. The UglifyJS documentation is decent, although the format for examining the structure may seem a bit customized (pop-up dialogs can become tedious; I ended up developing my own documentation parser for a more enjoyable study experience). The AST nodes are simply basic objects (no need for constructors or prototypes, just object literals containing straightforward property values or sub objects/arrays of objects); as long as they possess all necessary properties and AST structures, you'll have a valid AST tree. For example, you could modify the variable name like so:
ast.body[0].definitions[0].name.name = "bar";
After modifying the tree, you can convert it back into Javascript source code using the code generator feature. For example:
// assuming the variable ast already exists as mentioned above
var stream = UglifyJS.OutputStream(); // there are customizable options available for basic formatting
ast.print(stream);
var code = stream.toString();
console.log(code); // results in "var bar=1;"
Both UglifyJS and Esprima are fantastic tools. Esprima utilizes the Spider Monkey AST format, a widely recognized standard for Javascript ASTs, while Uglify employs its own AST model. Personally, I find that Esprima's AST format is neat yet lengthy, whereas UglifyJS opts for brevity although cleanliness may vary. Additionally, tools like Escodegen are available for Esprima to generate code akin to UglifyJS.
It's beneficial to explore these tools and determine which suits your preferences best; they all offer similar capabilities and enable efficient automation of refactoring and code analysis tasks like never before.