Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var compressor = UglifyJS.Compressor({});
var compressed_ast = toplevel.transform(compressor);
compressed_ast.figure_out_scope();
compressed_ast.compute_char_frequency();
compressed_ast.mangle_names();
var stream = UglifyJS.OutputStream({});
compressed_ast.print(stream);
var code = stream.toString(); // this is your minified code
var code = compressed_ast.print_to_string({});
var source_map = UglifyJS.SourceMap({});
var stream = UglifyJS.OutputStream({
//...
source_map: source_map
});
compressed_ast.print(stream);
var code = stream.toString();
var map = source_map.toString(); // json output for your source map
var compressor = UglifyJS.Compressor({});
var compressed_ast = toplevel.transform(compressor);
compressed_ast.figure_out_scope();
compressed_ast.compute_char_frequency();
compressed_ast.mangle_names();
var stream = UglifyJS.OutputStream({});
compressed_ast.print(stream);
var code = stream.toString(); // this is your minified code
var code = compressed_ast.print_to_string({});
var source_map = UglifyJS.SourceMap({});
var stream = UglifyJS.OutputStream({
//...
source_map: source_map
});
compressed_ast.print(stream);
var code = stream.toString();
var map = source_map.toString(); // json output for your source map
exports.minify = function(files, dest, options) {
options = options || {};
grunt.verbose.write('Minifying with UglifyJS...');
var topLevel = null;
var totalCode = '';
var outputOptions = getOutputOptions(options, dest);
var output = UglifyJS.OutputStream(outputOptions);
// Grab and parse all source files
files.forEach(function(file){
var code = grunt.file.read(file);
if (typeof options.sourceMapPrefix !== 'undefined') {
file = file.replace(/^\/+/, "").split(/\/+/).slice(options.sourceMapPrefix).join("/");
}
totalCode += code;
topLevel = UglifyJS.parse(code, {
filename: file,
toplevel: topLevel
});
});
// Wrap code in a common js wrapper.
if (options.wrap) {
// Mangling
compressed_ast.figure_out_scope();
compressed_ast.compute_char_frequency();
compressed_ast.mangle_names();
// output file
var source_map_options = {
file: path.basename(minifiedOutputPath),
root: 'src'
};
var source_map = uglify.SourceMap( source_map_options )
var stream = uglify.OutputStream( {
source_map: source_map,
comments: new RegExp( LICENSE )
} );
compressed_ast.print( stream );
var code = stream.toString();
console.log( ' Writing minified output: ' + minifiedOutputPath );
fs.writeFileSync( minifiedOutputPath, code + sourcemapping, 'utf8' );
if ( args.sourcemaps ) {
console.log( ' Writing source map.' );
fs.writeFileSync( sourcemapPath, source_map.toString(), 'utf8' );
ast.figure_out_scope()
const compressed = ast.transform(compressor)
if (mangle) {
compressed.figure_out_scope()
compressed.compute_char_frequency()
compressed.mangle_names()
}
const outSourceMap = new UglifyJS.SourceMap({
file: `${id}.js`,
root: sourceRoot
})
const stream = new UglifyJS.OutputStream({
ascii_only: true,
screw_ie8: false,
source_map: outSourceMap
})
/* eslint-enable camelcase */
compressed.print(stream)
const js = stream.toString()
const map = JSON.parse(outSourceMap.toString())
const generator = new SourceMapGenerator.fromSourceMap(new SourceMapConsumer(map))
sourceMaps.forEach(function(sourceMap) {
generator.applySourceMap(new SourceMapConsumer(sourceMap), sourceMap.sources[0], sourceRoot)
})
return {
js,
if (!process.env.DEBUG) {
// Parse.
var ast = uglify.parse(compiledSource);
// Compress.
ast.figure_out_scope();
ast.transform(uglify.Compressor());
// Mangle.
ast.compute_char_frequency();
ast.figure_out_scope();
ast.mangle_names();
// Output.
var stream = uglify.OutputStream({ source_map: null });
ast.print(stream);
var source = '(function(window,document){' +
stream + '})(window,document);';
obj.buffer = new Buffer(source, 'utf8');
} else {
obj.buffer = new Buffer(compiledSource, 'utf8');
}
}
}
res.push(ist.inject('line', subNode.start.line));
} else if (subNode instanceof Uglify.AST_Var) {
res.push(ist.inject('line', subNode.start.line));
}
res.push(subNode);
}
node.body = res;
}
});
// figure_out_scope
ast.figure_out_scope();
// walk process
ast.walk(walker);
var out = Uglify.OutputStream({
preserve_line : true,
comments: 'all',
beautify: true
});
// rebuild file
ast.print(out);
this.code = out.toString();
return this;
},
/**
format: 'umd',
sourceMap: true,
sourceMapFile: pkg.name + '.js',
moduleName: 'L.esri.Heat',
globals: {
'esri-leaflet': 'L.esri'
}
});
var sourceMap = UglifyJS.SourceMap({
file: pkg.name + '.js',
root: process.cwd(),
orig: JSON.parse(transpiled.map)
});
var stream = UglifyJS.OutputStream({
preamble: copyright,
source_map: sourceMap
});
UglifyJS.parse(transpiled.code).print(stream);
var code = stream.toString();
var map = sourceMap.toString().replace(new RegExp(path.join(process.cwd(), 'src'), 'g'), '../src');
fs.writeFileSync(path.join('dist', pkg.name + '.js'), code + '\n//# sourceMappingURL=./' + pkg.name + '.js.map');
fs.writeFileSync(path.join('dist', pkg.name + '.js.map'), map);
process.exit(0);
}).catch(function (error) {
console.log(error);
}).then(function (bundle) {
var transpiled = bundle.generate({
format: 'umd',
sourceMap: true,
sourceMapFile: pkg.name + '.js',
moduleName: 'L.esri'
});
var sourceMap = UglifyJS.SourceMap({
file: pkg.name + '.js',
root: process.cwd(),
orig: JSON.parse(transpiled.map)
});
var stream = UglifyJS.OutputStream({
preamble: copyright,
source_map: sourceMap
});
UglifyJS.parse(transpiled.code).print(stream);
var code = stream.toString();
var map = sourceMap.toString().replace(new RegExp(path.join(process.cwd(), 'src'), 'g'), '../src');
fs.writeFileSync(path.join('dist', pkg.name + '.js'), code + '\n//# sourceMappingURL=./' + pkg.name + '.js.map');
fs.writeFileSync(path.join('dist', pkg.name + '.js.map'), map);
process.exit(0);
}).catch(function (error) {
console.log(error);