Socket
Socket
Sign inDemoInstall

ast-transformer

Package Overview
Dependencies
1
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ast-transformer

An UglifyJS AST transformer


Version published
Maintainers
1
Install size
335 kB
Created

Readme

Source

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());
});

Keywords

FAQs

Last updated on 30 Aug 2011

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc