How to use the uglify-js.AST_Node 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 qooxdoo / qooxdoo / tool / grunt / task / package / compression / lib / compression.js View on Github external
console.log("comp", escg.generate(tree));
      }
    };

    // compress with UglifyJS2

    // if there's an esprima AST use it
    var cacheOrNull = (opts.cachePath) ? new Cache(opts.cachePath) : null;

    if (cacheOrNull) {
      var curCacheId = cacheOrNull.createCacheId('tree', envMap, classId);
      if (cacheOrNull.has(curCacheId)) {
        var tree = JSON.parse(cacheOrNull.read(curCacheId), adjustRegexLiteral);
        if (tree !== null && typeof(tree) !== 'undefined') {
          // debugClass(classId);
          var ast = U2.AST_Node.from_mozilla_ast(tree);
          ast.figure_out_scope();
          var compressor = U2.Compressor({warnings: false});
          ast = ast.transform(compressor);
          compressedCode = ast.print_to_string();
        }
      }
    }

    // compress in any case
    var result = U2.minify(compressedCode, {fromString: true});
    compressedCode = result.code;

    // qx specific optimizations
    if (opts.privates) {
      compressedCode = replacePrivates(classId, compressedCode);
    }
github Dajust / reduxTrello / node_modules / webpack / lib / optimize / UglifyJsPlugin.js View on Github external
if(err.line) {
						var original = sourceMap && sourceMap.originalPositionFor({
							line: err.line,
							column: err.col
						});
						if(original && original.source) {
							compilation.errors.push(new Error(file + " from UglifyJs\n" + err.message + " [" + requestShortener.shorten(original.source) + ":" + original.line + "," + original.column + "]"));
						} else {
							compilation.errors.push(new Error(file + " from UglifyJs\n" + err.message + " [" + file + ":" + err.line + "," + err.col + "]"));
						}
					} else if(err.msg) {
						compilation.errors.push(new Error(file + " from UglifyJs\n" + err.msg));
					} else
						compilation.errors.push(new Error(file + " from UglifyJs\n" + err.stack));
				} finally {
					uglify.AST_Node.warn_function = oldWarnFunction; // eslint-disable-line camelcase
				}
			});
			callback();
github cedricdelpoux / react-google-map / node_modules / webpack / lib / optimize / UglifyJsPlugin.js View on Github external
var asset = compilation.assets[file];
					if(asset.__UglifyJsPlugin) {
						compilation.assets[file] = asset.__UglifyJsPlugin;
						return;
					}
					if(options.sourceMap !== false) {
						if(asset.sourceAndMap) {
							var sourceAndMap = asset.sourceAndMap();
							var inputSourceMap = sourceAndMap.map;
							var input = sourceAndMap.source;
						} else {
							var inputSourceMap = asset.map();
							var input = asset.source();
						}
						var sourceMap = new SourceMapConsumer(inputSourceMap);
						uglify.AST_Node.warn_function = function(warning) { // eslint-disable-line camelcase
							var match = /\[.+:([0-9]+),([0-9]+)\]/.exec(warning);
							var line = +match[1];
							var column = +match[2];
							var original = sourceMap.originalPositionFor({
								line: line,
								column: column
							});
							if(!original || !original.source || original.source === file) return;
							warnings.push(warning.replace(/\[.+:([0-9]+),([0-9]+)\]/, "") +
								"[" + requestShortener.shorten(original.source) + ":" + original.line + "," + original.column + "]");
						};
					} else {
						var input = asset.source();
						uglify.AST_Node.warn_function = function(warning) { // eslint-disable-line camelcase
							warnings.push(warning);
						};
github youzan / fast-uglifyjs-plugin / lib / worker.js View on Github external
output.beautify = options.beautify;
    for (var k in options.output) {
        output[k] = options.output[k];
    }
    if (options.sourceMap) {
        var map = uglify.SourceMap({ // eslint-disable-line new-cap
            file: task.file,
            root: ""
        });
        output.source_map = map; // eslint-disable-line camelcase
    }
    var stream = uglify.OutputStream(output); // eslint-disable-line new-cap
    ast.print(stream);
    if (map) map = map + "";
    stream = stream + "";
    uglify.AST_Node.warn_function = oldWarnFunction;
    process.send({
        cmd: 'complete',
        result: {map: map, stream: stream, file: task.file, pid: process.pid},
        time: Date.now()
    })
}
github ForbesLindesay / stop / lib / minify-js.js View on Github external
stream._transform = function (page, _, cb) {
    if (page.headers['content-type'].indexOf('application/javascript') !== -1 && (!filter || filter(page.url))) {
      if (!silent) {
        console.log(chalk.blue('minfing ') + page.url);
      }
      var before = page.body.length;
      var sys = require("util");
      var warn = UglifyJS.AST_Node.warn_function;
      UglifyJS.AST_Node.warn_function = function (warning) {
        if (!silent) {
          console.log(chalk.yellow('WARN: ') + warning.replace(/\?\:/, ''));
        }
      };
      options.warnings = options.warnings !== false;
      options.fromString = true;
      page.body = new Buffer(UglifyJS.minify(page.body.toString(), options).code);
      UglifyJS.AST_Node.warn_function = warn;
      var after = page.body.length;
      if (!silent) {
        console.log(formatSize(before, 'source') + arrow + formatSize(after, 'minify'));
      }
    }
    stream.push(page);
    cb();
github jlooper / MIKE / sample-app / public / kendo / bower_components / kendo-ui / src / build / kendo-meta.js View on Github external
function minify(code, filename) {
    var ast;
    if (code instanceof U2.AST_Node) {
        ast = code;
    } else {
        ast = U2_parse(code, { filename: filename });
    }
    var compressor = U2.Compressor({
        unsafe       : true,
        hoist_vars   : true,
        warnings     : false,
        pure_getters : true,
    });
    ast.figure_out_scope();
    ast = ast.transform(compressor);
    ast.figure_out_scope();
    ast.compute_char_frequency();
    ast.mangle_names({
        except: [ "define" ]
github facebookarchive / WebDriverAgent / Inspector / node_modules / webpack / lib / optimize / UglifyJsPlugin.js View on Github external
files.forEach(function(file) {
				var oldWarnFunction = uglify.AST_Node.warn_function;
				var warnings = [];
				try {
					var asset = compilation.assets[file];
					if(asset.__UglifyJsPlugin) {
						compilation.assets[file] = asset.__UglifyJsPlugin;
						return;
					}
					if(options.sourceMap !== false) {
						if(asset.sourceAndMap) {
							var sourceAndMap = asset.sourceAndMap();
							var inputSourceMap = sourceAndMap.map;
							var input = sourceAndMap.source;
						} else {
							var inputSourceMap = asset.map();
							var input = asset.source();
						}
github telerik / kendo-ui-core / build / kendo-meta.js View on Github external
function minify(code, filename) {
    var ast;
    if (code instanceof U2.AST_Node) {
        ast = code;
    } else {
        ast = U2_parse(code, { filename: filename });
    }
    var compressor = U2.Compressor({
        unsafe       : true,
        hoist_vars   : true,
        warnings     : false,
        pure_getters : true,
    });
    ast.figure_out_scope();
    ast = ast.transform(compressor);
    ast.figure_out_scope();
    ast.compute_char_frequency();
    ast.mangle_names({
        except: [ "define" ]
github Arnavion / libjass / build / uglify.js View on Github external
this._root.walk(new UglifyJS.TreeWalker(function (node, descend) {
			if (node instanceof UglifyJS.AST_Lambda && !node.name) {
				node.name = Object.create(UglifyJS.AST_Node.prototype);
				node.name.print = function () { };
			}
		}));
github mishoo / livenode / livenode.js View on Github external
function rewrite_globals(code, ctx) {
    var ast;
    if (code instanceof u2.AST_Node) {
        ast = new u2.AST_Toplevel({
            body: [ code ]
        });
    } else {
        ast = u2.parse(code);
        ast.figure_out_scope({ screw_ie: true });
    }
    var hoisted = [];
    var warnings = [];
    function in_context(sym) {
        if (ctx) {
            return sym.global() && sym.name in ctx;
        } else {
            return sym.global() && !sym.undeclared();
        }
    };