lib/condenser/minifiers/node_modules/uglify-js/bin/uglifyjs in condenser-0.0.8 vs lib/condenser/minifiers/node_modules/uglify-js/bin/uglifyjs in condenser-0.0.9

- old
+ new

@@ -38,41 +38,57 @@ program.option("-b, --beautify [options]", "Beautify output/specify output options.", parse_js()); program.option("-o, --output <file>", "Output file (default STDOUT)."); program.option("--comments [filter]", "Preserve copyright comments in the output."); program.option("--config-file <file>", "Read minify() options from JSON file."); program.option("-d, --define <expr>[=value]", "Global definitions.", parse_js("define")); +program.option("-e, --enclose [arg[,...][:value[,...]]]", "Embed everything in a big function, with configurable argument(s) & value(s)."); program.option("--ie8", "Support non-standard Internet Explorer 8."); program.option("--keep-fnames", "Do not mangle/drop function names. Useful for code relying on Function.prototype.name."); program.option("--name-cache <file>", "File to hold mangled name mappings."); program.option("--rename", "Force symbol expansion."); program.option("--no-rename", "Disable symbol expansion."); program.option("--self", "Build UglifyJS as a library (implies --wrap UglifyJS)"); program.option("--source-map [options]", "Enable source map/specify source map options.", parse_js()); -program.option("--timings", "Display operations run time on STDERR.") +program.option("--timings", "Display operations run time on STDERR."); program.option("--toplevel", "Compress and/or mangle variables in toplevel scope."); program.option("--verbose", "Print diagnostic messages."); program.option("--warn", "Print warning messages."); program.option("--wrap <name>", "Embed everything as a function with “exports” corresponding to “name” globally."); program.arguments("[files...]").parseArgv(process.argv); if (program.configFile) { options = JSON.parse(read_file(program.configFile)); + if (options.mangle && options.mangle.properties && options.mangle.properties.regex) { + options.mangle.properties.regex = UglifyJS.parse(options.mangle.properties.regex, { + expression: true + }).value; + } } if (!program.output && program.sourceMap && program.sourceMap.url != "inline") { - fatal("ERROR: cannot write source map to STDOUT"); + fatal("cannot write source map to STDOUT"); } [ "compress", + "enclose", "ie8", "mangle", "sourceMap", "toplevel", "wrap" ].forEach(function(name) { if (name in program) { options[name] = program[name]; } }); +if (program.verbose) { + options.warnings = "verbose"; +} else if (program.warn) { + options.warnings = true; +} +if (options.warnings) { + UglifyJS.AST_Node.log_function(print_error, options.warnings == "verbose"); + delete options.warnings; +} if (program.beautify) { options.output = typeof program.beautify == "object" ? program.beautify : {}; if (!("beautify" in options.output)) { options.output.beautify = true; } @@ -96,11 +112,11 @@ delete program.mangleProps.domprops; } else { if (typeof program.mangleProps != "object") program.mangleProps = {}; if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = []; require("../tools/domprops").forEach(function(name) { - UglifyJS._push_uniq(program.mangleProps.reserved, name); + UglifyJS.push_uniq(program.mangleProps.reserved, name); }); } if (typeof options.mangle != "object") options.mangle = {}; options.mangle.properties = program.mangleProps; } @@ -115,11 +131,11 @@ } if (program.parse) { if (!program.parse.acorn && !program.parse.spidermonkey) { options.parse = program.parse; } else if (program.sourceMap && program.sourceMap.content == "inline") { - fatal("ERROR: inline source map only works with built-in parser"); + fatal("inline source map only works with built-in parser"); } } if (~program.rawArgs.indexOf("--rename")) { options.rename = true; } else if (!program.rename) { @@ -135,19 +151,12 @@ return function(name) { return path.relative(base, name); }; }(); } -if (program.verbose) { - options.warnings = "verbose"; -} else if (program.warn) { - options.warnings = true; -} if (program.self) { - if (program.args.length) { - print_error("WARN: Ignoring input files since --self was passed"); - } + if (program.args.length) UglifyJS.AST_Node.warn("Ignoring input files since --self was passed"); if (!options.wrap) options.wrap = "UglifyJS"; simple_glob(UglifyJS.FILES).forEach(function(name) { files[convert_path(name)] = read_file(name); }); run(); @@ -171,16 +180,13 @@ function convert_ast(fn) { return UglifyJS.AST_Node.from_mozilla_ast(Object.keys(files).reduce(fn, null)); } function run() { - UglifyJS.AST_Node.warn_function = function(msg) { - print_error("WARN: " + msg); - }; var content = program.sourceMap && program.sourceMap.content; if (content && content != "inline") { - print_error("INFO: Using input source map: " + content); + UglifyJS.AST_Node.info("Using input source map: " + content); options.sourceMap.content = read_file(content, content); } if (program.timings) options.timings = true; try { if (program.parse) { @@ -207,28 +213,30 @@ var result = UglifyJS.minify(files, options); if (result.error) { var ex = result.error; if (ex.name == "SyntaxError") { print_error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col); - var col = ex.col; - var lines = files[ex.filename].split(/\r?\n/); - var line = lines[ex.line - 1]; - if (!line && !col) { - line = lines[ex.line - 2]; - col = line.length; - } - if (line) { - var limit = 70; - if (col > limit) { - line = line.slice(col - limit); - col = limit; + var file = files[ex.filename]; + if (file) { + var col = ex.col; + var lines = file.split(/\r?\n/); + var line = lines[ex.line - 1]; + if (!line && !col) { + line = lines[ex.line - 2]; + col = line.length; } - print_error(line.slice(0, 80)); - print_error(line.slice(0, col).replace(/\S/g, " ") + "^"); + if (line) { + var limit = 70; + if (col > limit) { + line = line.slice(col - limit); + col = limit; + } + print_error(line.slice(0, 80)); + print_error(line.slice(0, col).replace(/\S/g, " ") + "^"); + } } - } - if (ex.defs) { + } else if (ex.defs) { print_error("Supported options:"); print_error(format_object(ex.defs)); } fatal(ex); } else if (program.output == "ast") { @@ -284,11 +292,15 @@ print_error("- " + phase + ": " + result.timings[phase].toFixed(3) + "s"); } } function fatal(message) { - if (message instanceof Error) message = message.stack.replace(/^\S*?Error:/, "ERROR:") + if (message instanceof Error) { + message = message.stack.replace(/^\S*?Error:/, "ERROR:") + } else { + message = "ERROR: " + message; + } print_error(message); process.exit(1); } // A file glob function that only supports "*" and "?" wildcards in the basename. @@ -333,21 +345,13 @@ function parse_js(flag) { return function(value, options) { options = options || {}; try { - UglifyJS.minify(value, { - parse: { - expression: true - }, - compress: false, - mangle: false, - output: { - ast: true, - code: false - } - }).ast.walk(new UglifyJS.TreeWalker(function(node) { + UglifyJS.parse(value, { + expression: true + }).walk(new UglifyJS.TreeWalker(function(node) { if (node instanceof UglifyJS.AST_Assign) { var name = node.left.print_to_string(); var value = node.right; if (flag) { options[name] = value; @@ -364,17 +368,17 @@ return true; } if (!(node instanceof UglifyJS.AST_Sequence)) throw node; function to_string(value) { - return value instanceof UglifyJS.AST_Constant ? value.getValue() : value.print_to_string({ + return value instanceof UglifyJS.AST_Constant ? value.value : value.print_to_string({ quote_keys: true }); } })); - } catch(ex) { + } catch (ex) { if (flag) { - fatal("Error parsing arguments for '" + flag + "': " + value); + fatal("cannot parse arguments for '" + flag + "': " + value); } else { options[value] = null; } } return options;