How to use the uglify-js.uglify.ast_walker 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 gflarity / response / test_old / node_modules / tap / node_modules / runforcover / node_modules / bunker / node_modules / burrito / node_modules / uglify-js / tmp / instrument2.js View on Github external
function instrument(code) {
        var ast = jsp.parse(code, false, true); // true for the third arg specifies that we want
                                                // to have start/end tokens embedded in the
                                                // statements
        var w = pro.ast_walker();

        function trace (line, comment) {
                var code = pro.gen_code(line, { beautify: true });
                var data = line[0]

                var args = []
                if (!comment) comment = ""
                if (typeof data === "object") {
                        code = code.split(/\n/).shift()
                        args = [ [ "string", data.toString() ],
                                 [ "string", code ],
                                 [ "num", data.start.line ],
                                 [ "num", data.start.col ],
                                 [ "num", data.end.line ],
                                 [ "num", data.end.col ]]
                } else {
github postaljs / postal.js / example / node / node_modules / socket.io / node_modules / socket.io-client / node_modules / uglify-js / tmp / instrument2.js View on Github external
function instrument( code ) {
	var ast = jsp.parse( code, false, true ); // true for the third arg specifies that we want
	// to have start/end tokens embedded in the
	// statements
	var w = pro.ast_walker();

	function trace( line, comment ) {
		var code = pro.gen_code( line, { beautify : true } );
		var data = line[0]

		var args = []
		if ( !comment ) {
			comment = ""
		}
		if ( typeof data === "object" ) {
			code = code.split( /\n/ ).shift()
			args = [
				[ "string", data.toString() ],
				[ "string", code ],
				[ "num", data.start.line ],
				[ "num", data.start.col ],
github piuccio / node-coverage / lib / interpreters / basic javascript.js View on Github external
if (options.verbose) {
			console.log("\t", file, "ignored");
		}
		return clientCode.generateWithHeaderOnly(content);
	}

	try {
		var tree = parser.parse(content,false, true);
	} catch (ex) {
		console.error("Error instrumentig file", file, options.verbose ? ex : ex.message);
		var code = clientCode.formatContent(content);
		code.error = true;
		return code;
	}

	var walker = uglify.ast_walker();
	// this is the list of nodes being analyzed by the walker
	// without this, w.walk(this) would re-enter the newly generated code with infinite recursion
	var analyzing = [];
	// list of all lines' id encounterd in this file
	var lines = [];
	// list of all conditions' id encounterd in this file
	var allConditions = [];
	// list of all functions' id encounterd in this file
	var allFunctions = [];

	/**
	 * A statement was found in the file, remember its id.
	 */
	function rememberStatement (id) {
		lines.push(id);
	};
github postaljs / postal.js / example / node / node_modules / socket.io / node_modules / socket.io-client / node_modules / uglify-js / tmp / instrument.js View on Github external
function instrument( code ) {
	var ast = jsp.parse( code, false, true ); // true for the third arg specifies that we want
	// to have start/end tokens embedded in the
	// statements
	var w = pro.ast_walker();

	// we're gonna need this to push elements that we're currently looking at, to avoid
	// endless recursion.
	var analyzing = [];

	function do_stat() {
		var ret;
		if ( this[0].start && analyzing.indexOf( this ) < 0 ) {
			// without the `analyzing' hack, w.walk(this) would re-enter here leading
			// to infinite recursion
			analyzing.push( this );
			ret = [ "splice", // XXX: "block" is safer
			        [
				        [ "stat",
				          [ "call", [ "name", "trace" ],
				            [
github DevExpress / testcafe / src / compiler / legacy / compiler.js View on Github external
var Compiler = module.exports = function (filename, modules, requireReader, sourceIndex) {
    this.walker = astProcessor.ast_walker();

    this.filename = filename;
    this.src = null;
    this.workingDir = path.dirname(this.filename);

    this.modules = modules;
    this.requireReader = requireReader;

    this.sourceIndex = sourceIndex || [];

    this.requires = [];

    this.line = 0;

    this.errs = [];
    this.okFlag = true;
github mosen / buildy / lib / buildy / tasks / yui.js View on Github external
function generate_literal(ast) {

    var w = process.ast_walker();
    var make = w.walk;
    return w.with_walkers({
        "string": function(str) { return str; },
        "name": function(name) {
            if (name.toLowerCase() === 'true') { return true; }
            if (name.toLowerCase() === 'false') { return false; }
            return name;
        },
        "object": function(props) {

            var o = {};
            props.forEach(function(p) {
                var key = p[0], val = p[1];

                o[key] = make(val);
            });
github david-mark-llc / jessie / src / builder / libs / jessie / Builder.js View on Github external
Builder.prototype.setupHeaderDeclarations = function() {
	var ast = uglifyParser.parse(this.header + this.footer);
	var w = pro.ast_walker();
	ast = w.with_walkers({
		"var": function (defs) {
			defs.forEach(function(def){
				this.headerDeclarations.push(def[0]);
			}.bind(this));
		}.bind(this)
	}, function() {
        return w.walk(ast);
	});
};
github zazl / optimizer / org.dojotoolkit.optimizer.amd / optimizer / amd / astwalker.js View on Github external
function getMissingNameIndex(src) {
	var jsp = require("uglify-js").parser;
	var uglify = require("uglify-js").uglify;
	
	var ast = jsp.parse(src, false, true);
	var w = uglify.ast_walker();
	var nameIndex = -1;
	w.with_walkers({
	    "call": function(expr, args) {
			if (expr[0] === "name" && expr[1] === "define") {
				if (args[0][0].name !== "string") {
					nameIndex = w.parent()[0].start.pos + (src.substring(w.parent()[0].start.pos).indexOf('(')+1);
				}
			}
		}
	}, function(){
	    w.walk(ast);
	});
	return nameIndex;
};
github zazl / optimizer / org.dojotoolkit.optimizer.amd / optimizer / amd / astwalker.js View on Github external
}
	var url = idToUrl(uri, config);
	if (url.charAt(0) !== '/') {
		url = '/'+url;
	}

	if (moduleMap.get(uri) === undefined) {
		var src = resourceloader.readText(url+'.js');
		if (src === null) {
			throw new Error("Unable to load src for ["+url+"]. Module ["+(pathStack.length > 0 ? pathStack[pathStack.length-1] : "root")+"] has a dependency on it.");
		}
		var ast = astcache.getAst(uri+'.js', config.astparser);
		if (ast === null) {
			ast = jsp.parse(src, false, true);
		}
		var w = uglify.ast_walker();
		var id = uri;
		var module = moduleCreator.createModule(id, url);
		moduleMap.add(uri, module);
		w.with_walkers({
		    "call": function(expr, args) {
				if (expr[0] === "name" && (expr[1] === "define" || expr[1] === "require")) {
					var dependencyArg;
                    if (expr[1] === "define") {
                    	module.defineFound = true;
                    	if (args[0][0].name !== "string") {
                    		var start = w.parent()[0].start;
                    		var nameIndex = start.pos + (src.substring(start.pos).indexOf('(')+1);
                    		missingNamesList.push({uri: url, id: id, nameIndex: nameIndex});
                    	}
                    }
				    if (expr[1] === "require") {