Permalink
Browse files

initial README

  • Loading branch information...
1 parent 05fb282 commit bd363e5ad6c6ee703e346ea186cc53b5aaba202e @dresende committed Aug 24, 2011
Showing with 28 additions and 0 deletions.
  1. 0 README
  2. +28 −0 README.md
View
0 README
No changes.
View
@@ -0,0 +1,28 @@
+## UglifyJS AST Transformer
+
+The goal of this NodeJS module is to be able to make transformations on AST (Abstract Syntax Tree)
+other than mangling. The next example shows what you can do and the main purpose of this module.
+Imagin you have a file with this code:
+
+ // file.js
+ console.log(_("Hello, world!"));
+
+And you want to convert `_("...")` to `"..."` similar to what `gettext()` does.
+
+ var js_parser = require("uglify-js").parser,
+ js_compressor = require("uglify-js").uglify,
+ Transformer = require("ast-transformer").Transformer;
+
+ fs.readFileSync("file.js", function (err, data) {
+ if (err) return console.log(err);
+
+ var transformer = new Transformer(js_parser.parse(String(data)));
+ transformer.replaceFunctionCall("_", function (text) {
+ // text = "Hello, world!"
+ return "Hola, mundo!";
+ });
+
+ // will output:
+ // console.log("Hola, mundo!");
+ console.log(js_compressor.gen_code(transformer.get()));
+ });

0 comments on commit bd363e5

Please sign in to comment.