How to use the uglify-js.parser.parse 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 irinc / ixf / build / build.js View on Github external
data = fs.readFileSync('scripts/ixf-utilities.js','utf8').replace("Y_Y_Y_Y", now.getFullYear()).replace('ixf.version = "X.X.X"','ixf.version = "' + versionNumber + '"').replace("X.X.X",versionNumber + " - " + now.getFullYear() + "/" + (now.getMonth()+1) + "/" + now.getDate()),
		outMin = fs.openSync('scripts/ixf-utilities.min.js','w'),
		index = data.indexOf("/*"), lastIndex = data.indexOf("*/",index),
		ast, minCode, buffer, comment;

	// Write permanent comment to minified file
	if(index != -1 && lastIndex != -1) {
		comment = data.substring(index,lastIndex+2);
		console.log(comment);
		buffer = new Buffer(comment + "\n");
		fs.writeSync(outMin, buffer, 0, buffer.length);
		data = data.substring(lastIndex+2);
	}

	//Minify the code
	ast = jsp.parse(data); // 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
	minCode = pro.gen_code(ast); // compressed code here

	// Write minified code to file
	buffer = new Buffer(minCode+"\n");
	fs.writeSync(outMin, buffer, 0, buffer.length);
	fs.closeSync(outMin);
	console.log("  Output: scripts/ixf-utilities.min.js");

	if(callback)
		callback();
}
github youtify / youtify / make / generate_production_javascript.js View on Github external
function runUglify(mergedFile) {
    var ast;
    try {
        ast = jsp.parse(mergedFile); // parse code and get the initial AST
    } catch (e) {
        console.log('UglifyJS parse failed', e);
    }
    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); // compressed code here
}
github spmjs / spm / lib / actions / build / core / dependency.js View on Github external
function parseDepsByModuleCode(defineId, moduleCode) {
  var ast = astParser.parse(moduleCode);
  var deps = [];
  Ast.walk(ast, 'stat', function(stat) {
    if (stat.toString().indexOf('stat,call,name,define,string,' +
        defineId) !== 0) {
      return stat;
    }

    //[ 'stat', [ 'call', [ 'name', 'define' ],
    //    [ [Object], [Object], [Object] ] ] ]
    var depsArr = stat[1][2][1][1];
    depsArr.forEach(function(dep) {
      deps.push(dep[1]);
    });
    deps.unshift(defineId);
    return stat;
  });
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 zythum / youkuhtml5playerbookmark / 2.0 / combine.js View on Github external
loopRead(function(){
	var ast;
	combineFile = '(function(){' + combineFile + '})();';
	ast = jsp.parse(combineFile);
	ast = pro.ast_mangle(ast);
	ast = pro.ast_squeeze(ast);
	ast = pro.gen_code(ast);
	fs.writeFile('youkuhtml5playerbookmark2.js', ast, function() {
		console.log('-----youkuhtml5playerbookmark2.js updated!----');
	});
});
github jordwalke / FaxJs / FaxProcessor / FaxOptimizer.js View on Github external
var reducedRoot, optimizedRoot;
  try {
    /*
     * reducedRoot = FaxReducer.reduceAndCacheModule(baseName, src);
     * if (!reducedRoot) {
     * console.error("ERROR: Reduced root returned as empty:" + fileName);
     * }
     * optimizedRoot =
     *    FaxTailConstructionOptimizer.optimizeTailConstructions(reducedRoot);
     */
    optimizedRoot =
       FaxTailConstructionOptimizer.optimizeTailConstructions(jsParser.parse(src));
  } catch (e) {
    console.error("ERROR: CAUGHT EXCEPTION OPTIMIZING:" + fileName);
    optimizedRoot = jsParser.parse(src);
  }

  if (squeeze) {
    optimizedRoot = uglify.ast_squeeze(optimizedRoot);
  }
  if (mangle) {
    optimizedRoot = uglify.ast_mangle(optimizedRoot);
  }
  var gened = uglify.gen_code(optimizedRoot);
  if(gened !== src) {
    require('sys').puts("Found optimizations in file:" + fileName);
  } else {
    require('sys').puts("Did not find optimizations in:" + fileName);
  }
  return gened;
};
github jordwalke / FaxJs / FaxProcessor / FaxOptimizer.js View on Github external
* Reduce constructions into optimized rendering functions. Then transform
   * tail constructions into optimal tail constructions.
   */

  var reducedRoot, optimizedRoot;
  try {
    /*
     * reducedRoot = FaxReducer.reduceAndCacheModule(baseName, src);
     * if (!reducedRoot) {
     * console.error("ERROR: Reduced root returned as empty:" + fileName);
     * }
     * optimizedRoot =
     *    FaxTailConstructionOptimizer.optimizeTailConstructions(reducedRoot);
     */
    optimizedRoot =
       FaxTailConstructionOptimizer.optimizeTailConstructions(jsParser.parse(src));
  } catch (e) {
    console.error("ERROR: CAUGHT EXCEPTION OPTIMIZING:" + fileName);
    optimizedRoot = jsParser.parse(src);
  }

  if (squeeze) {
    optimizedRoot = uglify.ast_squeeze(optimizedRoot);
  }
  if (mangle) {
    optimizedRoot = uglify.ast_mangle(optimizedRoot);
  }
  var gened = uglify.gen_code(optimizedRoot);
  if(gened !== src) {
    require('sys').puts("Found optimizations in file:" + fileName);
  } else {
    require('sys').puts("Did not find optimizations in:" + fileName);
github jhamlet / node-infuse / lib / infuser.js View on Github external
if (!isSrc && existsSync(path)) {
                this.filepath = Path.resolve(path);
                src = this.source = FS.readFileSync(this.filepath, "utf8");
            }
            else {
                this.filepath = process.cwd();
                src = this.source = path;
            }
            
            this.dirpath = Path.dirname(this.filepath);
            this.infusions = this.options.infusions ||
                                new Infusions({
                                    embed: this.options.embed
                                });
            
            return this.infuseAst(jsp.parse(src));
        },
github manuelnelson / BoilerPlateMVC / src / Application.Web / bundler / bundler.js View on Github external
function minifyjs(js) {
    var ast = jsp.parse(js);
    ast = pro.ast_mangle(ast);
    ast = pro.ast_squeeze(ast);
    var minJs = pro.gen_code(ast);
    return minJs;
}