https://github.com/dresende/node-ast-transformer
Node UglifyJS AST Transformer
https://github.com/dresende/node-ast-transformer
Last synced: 5 months ago
JSON representation
Node UglifyJS AST Transformer
- Host: GitHub
- URL: https://github.com/dresende/node-ast-transformer
- Owner: dresende
- Created: 2011-08-24T22:04:01.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2011-08-30T13:23:36.000Z (over 14 years ago)
- Last Synced: 2025-01-31T18:37:21.808Z (12 months ago)
- Language: JavaScript
- Homepage:
- Size: 102 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## 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 transformer = require("ast-transformer");
fs.readFileSync("file.js", function (err, data) {
if (err) return console.log(err);
var code = new transformer.Transformer(transformer.parse(data));
code.replaceFunctionCall("_", function (text) {
return "Hola, mundo!";
});
// will output:
// console.log("Hola, mundo!");
console.log(code.generate());
});