How to use the uglify-js.uglify.ast_mangle function in uglify-js

To help you get started, we’ve selected a few uglify-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ashblue / canvas-prime / compiler / controller.js View on Github external
// Use the userFiles array to add in all the files needed
        var userJS = _fs.readFileSync('js/setup.js', 'utf8');
        var userFiles = userJS;
        userFiles = _strings.getStringBetween(userFiles, 'cp.load.loadFiles = ', ';');
        userFiles = userFiles.replace(/'/g, '"');
        userFiles = JSON.parse(userFiles);
        userFiles.forEach(function (val, i) {
            jsOutput += _fs.readFileSync('js/objects/' + val + '.js', 'utf8');
        });

        // Get setup.js and find cp.load.loadFiles. Comment it out, then put in jsOutput
        jsOutput += _strings.setStringBetween(userJS, 'cp.load.loadFiles = ', ';', '');

        // Uglify jsOutput, options https://github.com/mishoo/UglifyJS
        var ast = _jsp.parse(jsOutput);
        ast = _pro.ast_mangle(ast);
        ast = _pro.ast_squeeze(ast);
        jsOutput = _pro.gen_code(ast);

        return jsOutput;
    },
github nhunzaker / nodebot / actions / compile / javascript.js View on Github external
function compress (filename, content) {

    var ret = "";

    content = jsp.parse(content.toString());
    content = pro.ast_mangle(content);
    content = pro.ast_squeeze(content);

    // Add the records
    ret += "\/\/ " + filename;
    ret += "\n" + pro.gen_code(content) + ";\n\n";

    return ret;

};
github creationix / creationix / autoloader.js View on Github external
function done(err) {
      var js = header;
      scripts.forEach(function (tuple) {
        var name = tuple[0];
        var content = tuple[1];
        js += "\ndefine('" + name + "', function (module, exports) {\n\n" + content + "\n})\n";
      });
      
      if (uglify) {
        var ast = jsp.parse(js); // parse code and get the initial AST
        ast = pro.ast_mangle(ast); // get a new AST with mangled names
        ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
        js = pro.gen_code(ast); // compressed code here
      }
      
      res.writeHead(200, {
        "Content-Type": "application/javascript",
        "Content-Length": Buffer.byteLength(js)
      });
      res.end(js);
    }
  };
github krasimir / assets-pack / lib / pack.js View on Github external
js: function(files) {
            try {
                var content = this.mergeFiles(files);
                if(this.asset.minify) {
                    var jsp = require("uglify-js").parser;
                    var pro = require("uglify-js").uglify;
                    var ast = jsp.parse(content); // parse code and get the initial AST
                    ast = pro.ast_mangle(ast); // get a new AST with mangled names
                    ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
                    content = pro.gen_code(ast); // compressed code here
                }
                this.output(content);
            } catch (err) {
                for(var i=0; i
github WolframHempel / photobooth-js / build / build.js View on Github external
var fMinifyJs = function( sJavasScript )
{
	var ast = jsp.parse( sJavasScript ); // parse code and get the initial AST
	ast = pro.ast_mangle(ast); // get a new AST with mangled names
	ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
	return pro.gen_code(ast);
};
/**
github mosen / buildy / buildy / lib / utils.js View on Github external
var min = function(o, callback) {

        var jsp = require("uglify-js").parser,
            pro = require("uglify-js").uglify,
            ast;

        try {
            ast = jsp.parse(o.source); // parse into syntax tree
            ast = pro.ast_mangle(ast);
            ast = pro.ast_squeeze(ast);
        } catch (e) {
            callback('The minify task failed, most likely the source file was unparseable. Please check your syntax. Error: ' + e.message);
            return;
        }

        if (!o.destFile) {
            callback(false, pro.gen_code(ast));
        } else {
            fs.writeFile(o.destFile, pro.gen_code(ast), 'utf8', function(err) {
                if (err) throw err;
                callback(false, o.destFile);
            });
        }
    };
github EMSL-MSC / NWPerf / web / enyo / tools / minifier / minify.js View on Github external
compress = function(inCode) {
	var ast = jsp.parse(inCode); // parse code and get the initial AST
	ast = pro.ast_mangle(ast); // get a new AST with mangled names
	ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
	return pro.gen_code(ast, {indent_level:0, beautify: !opt.aggro, ascii_only:true}); // compressed code here
};
github raptorjs-legacy / raptorjs / lib / raptor / js-minifier / js-minifier_node.js View on Github external
minify: function(src, options) {
            if (!options) {
                options = {};
            }
            
            var ast = parser.parse(src, options.strict_semicolons === true);
            
            if (options.lift_variables === true) {
                ast = uglify.ast_lift_variables(ast);
            }
            
            ast = uglify.ast_mangle(ast, options);
            ast = uglify.ast_squeeze(ast, options);
            return uglify.gen_code(ast);
        }
    };
github danwrong / loadbuilder / src / loadbuilder.js View on Github external
Script.prototype.getCode = function(parsedSource, minify) {
  var code, ast = parsedSource;
  if (minify) {
    ast = jspro.ast_mangle(ast);
    ast = jspro.ast_squeeze(ast);
  }
  code = jspro.gen_code(ast);
  return this.preCode + this.license + code + this.postCode;
};
Script.prototype.getFilename = function(modPath) {