[Pkg-javascript-commits] [uglifyjs] 11/26: Added example for usage with SpiderMonkey AST.

Jonas Smedegaard dr at jones.dk
Tue May 19 00:02:21 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag v2.4.16
in repository uglifyjs.

commit e391367488c8f7bfc5890e1fa51f4ad6e6f28a5f
Author: Ingvar Stepanyan <me at rreverser.com>
Date:   Mon Aug 4 20:48:14 2014 +0300

    Added example for usage with SpiderMonkey AST.
---
 README.md | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/README.md b/README.md
index 27d06cd..c60a124 100644
--- a/README.md
+++ b/README.md
@@ -400,6 +400,38 @@ Acorn is really fast (e.g. 250ms instead of 380ms on some 650K code), but
 converting the SpiderMonkey tree that Acorn produces takes another 150ms so
 in total it's a bit more than just using UglifyJS's own parser.
 
+### Using UglifyJS to transform SpiderMonkey AST
+
+Now you can use UglifyJS as any other intermediate tool for transforming
+JavaScript ASTs in SpiderMonkey format.
+
+Example:
+
+```javascript
+function uglify(ast, options, mangle) {
+  // Conversion from SpiderMonkey AST to internal format
+  var uAST = UglifyJS.AST_Node.from_mozilla_ast(ast);
+
+  // Compression
+  uAST.figure_out_scope();
+  uAST = uAST.transform(UglifyJS.Compressor(options));
+
+  // Mangling (optional)
+  if (mangle) {
+    uAST.figure_out_scope();
+    uAST.compute_char_frequency();
+    uAST.mangle_names();
+  }
+
+  // Back-conversion to SpiderMonkey AST
+  return uAST.to_mozilla_ast();
+}
+```
+
+Check out
+[original blog post](http://rreverser.com/using-mozilla-ast-with-uglifyjs/)
+for details.
+
 API Reference
 -------------
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list