aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai.bazon@gmail.com>2014-08-04 23:05:29 +0300
committerMihai Bazon <mihai.bazon@gmail.com>2014-08-04 23:05:29 +0300
commite3066f957710f266484ce7f5e8dfb581f7a698cc (patch)
treeb33285d235b4f5858a88d2d09284e7c1e4d35d3a
parent18ddf2f7b5a09e4e4da15cba4bed0e83e0d40cce (diff)
parente391367488c8f7bfc5890e1fa51f4ad6e6f28a5f (diff)
downloadtracifyjs-e3066f957710f266484ce7f5e8dfb581f7a698cc.tar.gz
tracifyjs-e3066f957710f266484ce7f5e8dfb581f7a698cc.zip
Merge pull request #529 from RReverser/master
Added example for usage with SpiderMonkey AST
-rw-r--r--README.md32
1 files changed, 32 insertions, 0 deletions
diff --git a/README.md b/README.md
index 27d06cd6..c60a124d 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
-------------