Remove deprecated calls to utils.print/utils.error

Close #542, #641, #647
This commit is contained in:
Mihai Bazon
2015-05-04 15:07:16 +03:00
parent c3a10c135e
commit d2dda34b2a
2 changed files with 32 additions and 26 deletions

View File

@@ -132,24 +132,24 @@ normalize(ARGS);
if (ARGS.noerr) { if (ARGS.noerr) {
UglifyJS.DefaultsError.croak = function(msg, defs) { UglifyJS.DefaultsError.croak = function(msg, defs) {
sys.error("WARN: " + msg); print_error("WARN: " + msg);
}; };
} }
if (ARGS.version || ARGS.V) { if (ARGS.version || ARGS.V) {
var json = require("../package.json"); var json = require("../package.json");
sys.puts(json.name + ' ' + json.version); print(json.name + ' ' + json.version);
process.exit(0); process.exit(0);
} }
if (ARGS.ast_help) { if (ARGS.ast_help) {
var desc = UglifyJS.describe_ast(); var desc = UglifyJS.describe_ast();
sys.puts(typeof desc == "string" ? desc : JSON.stringify(desc, null, 2)); print(typeof desc == "string" ? desc : JSON.stringify(desc, null, 2));
process.exit(0); process.exit(0);
} }
if (ARGS.h || ARGS.help) { if (ARGS.h || ARGS.help) {
sys.puts(yargs.help()); print(yargs.help());
process.exit(0); process.exit(0);
} }
@@ -221,7 +221,7 @@ if (ARGS.comments != null) {
try { try {
OUTPUT_OPTIONS.comments = new RegExp(ARGS.comments.substr(1, regex_pos - 1), ARGS.comments.substr(regex_pos + 1)); OUTPUT_OPTIONS.comments = new RegExp(ARGS.comments.substr(1, regex_pos - 1), ARGS.comments.substr(regex_pos + 1));
} catch (e) { } catch (e) {
sys.error("ERROR: Invalid --comments: " + e.message); print_error("ERROR: Invalid --comments: " + e.message);
} }
} else if (ARGS.comments == "all") { } else if (ARGS.comments == "all") {
OUTPUT_OPTIONS.comments = true; OUTPUT_OPTIONS.comments = true;
@@ -241,7 +241,7 @@ var files = ARGS._.slice();
if (ARGS.self) { if (ARGS.self) {
if (files.length > 0) { if (files.length > 0) {
sys.error("WARN: Ignoring input files since --self was passed"); print_error("WARN: Ignoring input files since --self was passed");
} }
files = UglifyJS.FILES; files = UglifyJS.FILES;
if (!ARGS.wrap) ARGS.wrap = "UglifyJS"; if (!ARGS.wrap) ARGS.wrap = "UglifyJS";
@@ -253,7 +253,7 @@ var ORIG_MAP = ARGS.in_source_map;
if (ORIG_MAP) { if (ORIG_MAP) {
ORIG_MAP = JSON.parse(fs.readFileSync(ORIG_MAP)); ORIG_MAP = JSON.parse(fs.readFileSync(ORIG_MAP));
if (files.length == 0) { if (files.length == 0) {
sys.error("INFO: Using file from the input source map: " + ORIG_MAP.file); print_error("INFO: Using file from the input source map: " + ORIG_MAP.file);
files = [ ORIG_MAP.file ]; files = [ ORIG_MAP.file ];
} }
if (ARGS.source_map_root == null) { if (ARGS.source_map_root == null) {
@@ -266,12 +266,12 @@ if (files.length == 0) {
} }
if (files.indexOf("-") >= 0 && ARGS.source_map) { if (files.indexOf("-") >= 0 && ARGS.source_map) {
sys.error("ERROR: Source map doesn't work with input from STDIN"); print_error("ERROR: Source map doesn't work with input from STDIN");
process.exit(1); process.exit(1);
} }
if (files.filter(function(el){ return el == "-" }).length > 1) { if (files.filter(function(el){ return el == "-" }).length > 1) {
sys.error("ERROR: Can read a single file from STDIN (two or more dashes specified)"); print_error("ERROR: Can read a single file from STDIN (two or more dashes specified)");
process.exit(1); process.exit(1);
} }
@@ -294,9 +294,9 @@ try {
var compressor = COMPRESS && UglifyJS.Compressor(COMPRESS); var compressor = COMPRESS && UglifyJS.Compressor(COMPRESS);
} catch(ex) { } catch(ex) {
if (ex instanceof UglifyJS.DefaultsError) { if (ex instanceof UglifyJS.DefaultsError) {
sys.error(ex.msg); print_error(ex.msg);
sys.error("Supported options:"); print_error("Supported options:");
sys.error(sys.inspect(ex.defs)); print_error(sys.inspect(ex.defs));
process.exit(1); process.exit(1);
} }
} }
@@ -304,7 +304,7 @@ try {
async.eachLimit(files, 1, function (file, cb) { async.eachLimit(files, 1, function (file, cb) {
read_whole_file(file, function (err, code) { read_whole_file(file, function (err, code) {
if (err) { if (err) {
sys.error("ERROR: can't read file: " + file); print_error("ERROR: can't read file: " + file);
process.exit(1); process.exit(1);
} }
if (ARGS.p != null) { if (ARGS.p != null) {
@@ -341,9 +341,9 @@ async.eachLimit(files, 1, function (file, cb) {
}); });
} catch(ex) { } catch(ex) {
if (ex instanceof UglifyJS.JS_Parse_Error) { if (ex instanceof UglifyJS.JS_Parse_Error) {
sys.error("Parse error at " + file + ":" + ex.line + "," + ex.col); print_error("Parse error at " + file + ":" + ex.line + "," + ex.col);
sys.error(ex.message); print_error(ex.message);
sys.error(ex.stack); print_error(ex.stack);
process.exit(1); process.exit(1);
} }
throw ex; throw ex;
@@ -444,15 +444,15 @@ async.eachLimit(files, 1, function (file, cb) {
if (OUTPUT_FILE) { if (OUTPUT_FILE) {
fs.writeFileSync(OUTPUT_FILE, output, "utf8"); fs.writeFileSync(OUTPUT_FILE, output, "utf8");
} else { } else {
sys.print(output); print(output);
} }
if (ARGS.stats) { if (ARGS.stats) {
sys.error(UglifyJS.string_template("Timing information (compressed {count} files):", { print_error(UglifyJS.string_template("Timing information (compressed {count} files):", {
count: files.length count: files.length
})); }));
for (var i in STATS) if (STATS.hasOwnProperty(i)) { for (var i in STATS) if (STATS.hasOwnProperty(i)) {
sys.error(UglifyJS.string_template("- {name}: {time}s", { print_error(UglifyJS.string_template("- {name}: {time}s", {
name: i, name: i,
time: (STATS[i] / 1000).toFixed(3) time: (STATS[i] / 1000).toFixed(3)
})); }));
@@ -479,7 +479,7 @@ function getOptions(x, constants) {
ast = UglifyJS.parse(x, { expression: true }); ast = UglifyJS.parse(x, { expression: true });
} catch(ex) { } catch(ex) {
if (ex instanceof UglifyJS.JS_Parse_Error) { if (ex instanceof UglifyJS.JS_Parse_Error) {
sys.error("Error parsing arguments in: " + x); print_error("Error parsing arguments in: " + x);
process.exit(1); process.exit(1);
} }
} }
@@ -498,8 +498,8 @@ function getOptions(x, constants) {
ret[name] = true; ret[name] = true;
return true; // no descend return true; // no descend
} }
sys.error(node.TYPE) print_error(node.TYPE)
sys.error("Error parsing arguments in: " + x); print_error("Error parsing arguments in: " + x);
process.exit(1); process.exit(1);
})); }));
} }
@@ -531,3 +531,11 @@ function time_it(name, cont) {
} }
return ret; return ret;
} }
function print_error(msg) {
console.error("%s", msg);
}
function print(txt) {
console.log("%s", txt);
}

View File

@@ -1,10 +1,8 @@
var path = require("path"); var path = require("path");
var fs = require("fs"); var fs = require("fs");
var vm = require("vm"); var vm = require("vm");
var sys = require("util");
var UglifyJS = vm.createContext({ var UglifyJS = vm.createContext({
sys : sys,
console : console, console : console,
process : process, process : process,
Buffer : Buffer, Buffer : Buffer,
@@ -19,7 +17,7 @@ function load_global(file) {
} catch(ex) { } catch(ex) {
// XXX: in case of a syntax error, the message is kinda // XXX: in case of a syntax error, the message is kinda
// useless. (no location information). // useless. (no location information).
sys.debug("ERROR in file: " + file + " / " + ex); console.log("ERROR in file: " + file + " / " + ex);
process.exit(1); process.exit(1);
} }
}; };
@@ -42,7 +40,7 @@ var FILES = exports.FILES = [
FILES.forEach(load_global); FILES.forEach(load_global);
UglifyJS.AST_Node.warn_function = function(txt) { UglifyJS.AST_Node.warn_function = function(txt) {
sys.error("WARN: " + txt); console.error("WARN: %s", txt);
}; };
// XXX: perhaps we shouldn't export everything but heck, I'm lazy. // XXX: perhaps we shouldn't export everything but heck, I'm lazy.