Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
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();
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);
};
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()
})
}
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();
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" ]
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();
}
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" ]
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 () { };
}
}));
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();
}
};