How to use the uglify-js.uglify.gen_code 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 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 david-mark-llc / jessie / src / builder / libs / jessie / Builder.js View on Github external
Builder.prototype.minify = function(output) {
	var ast = uglifyParser.parse(output);

	switch(this.options.minificationLevel) {
		case "1":
			output = pro.gen_code(ast, { beautify: true });
			break;
		case "2":
			output = pro.gen_code(ast);
			break;
		case "3":
			ast = pro.ast_mangle(ast);
			output = pro.gen_code(ast);
			break;
		default:
			// nothing
	}

	return output;
};
github DevExpress / testcafe / src / compiler / legacy / analysis / require_analyzer.js View on Github external
function analyzeRequireCode (requireAst, descriptor, errs, sourceIndex) {
    //OPTIMIZATION: use footprints to determine if we need deeper analysis
    var originalSrc = descriptor.jsCode;

    if (Common.MIXIN_FOOTPRINT_REGEXP.test(descriptor.jsCode)) {
        var rebuildCode = extractMixins(requireAst, descriptor, errs, sourceIndex);

        //NOTE: we need to rebuild js code if mixins were removed from AST
        if (rebuildCode) {
            requireAst        = Ast.getRemainderAst(requireAst);
            descriptor.jsCode = requireAst ? astProcessor.gen_code(requireAst, { beautify: true }) : '';
        }
    }

    if (Common.ACTION_OR_ASSERTION_FOOTPRINT_REGEXP.test(descriptor.jsCode)) {
        //NOTE: validate what require file doesn't contain action functions calls and update source index
        if (CallAnalyzer.run(requireAst, descriptor.filename, errs, true, sourceIndex, originalSrc)) {
            //NOTE: if call analyzer found assertions and added them to index, we need to rebuild again
            descriptor.jsCode = requireAst ? astProcessor.gen_code(requireAst, { beautify: true }) : '';
        }
    }
}
github DevExpress / testcafe / src / compiler / legacy / compiler.js View on Github external
Compiler.prototype._addOutputTestStepData = function (testName, testStepData) {
    var js = astProcessor.gen_code(['array', testStepData.asts], {beautify: true});

    this.out.testsStepData[testName] = {
        names: testStepData.names,
        js: Hammerhead.wrapDomAccessors(js, true)
    };
};
github jordwalke / FaxJs / FaxProcessor / FaxOptimizer.js View on Github external
*    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 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
"const" : do_stat,
		"return" : do_stat,
		"throw" : do_stat,
		"try" : do_stat,
		"defun" : do_stat,
		"if" : do_stat,
		"while" : do_stat,
		"do" : do_stat,
		"for" : do_stat,
		"for-in" : do_stat,
		"switch" : do_stat,
		"with" : do_stat
	}, function () {
		return w.walk( ast );
	} );
	return pro.gen_code( new_ast, { beautify : true } );
}
github TBEDP / datavjs / bin / build.js View on Github external
exports.minify = function (input) {
  var ast = uglify.ast_squeeze(uglify.ast_mangle(parser.parse(input)));
  return uglify.gen_code(ast);
};
github serby / compact / lib / compact.js View on Github external
function compress(data, compressorOptions) {
    var ast = parser.parse(data)
    var uglifyOptions = {}
    if (typeof compressorOptions !== 'undefined') {
      uglifyOptions = compressorOptions
    } else if (options.uglify !== 'undefined') {
      uglifyOptions = options.uglify
    }

    ast = uglifyer.ast_mangle(ast, uglifyOptions)
    ast = uglifyer.ast_squeeze(ast, uglifyOptions)
    return uglifyer.gen_code(ast, uglifyOptions)
  }
github ServiceStack / Bundler / src / 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;
}
github ServiceStackApps / SocialBootstrapApi / src / SocialBootstrapApi / 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;
}