replace sys.print/debug/error/puts with console equivalent

This commit is contained in:
David Frank 2015-03-29 01:16:16 +08:00
parent 276b9a31cd
commit 4282af1969
3 changed files with 27 additions and 27 deletions

View File

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

View File

@ -12,8 +12,8 @@ var failed_files = {};
run_compress_tests();
if (failures) {
sys.error("\n!!! Failed " + failures + " test cases.");
sys.error("!!! " + Object.keys(failed_files).join(", "));
console.error("\n!!! Failed " + failures + " test cases.");
console.error("!!! " + Object.keys(failed_files).join(", "));
process.exit(1);
}
@ -31,7 +31,7 @@ function tmpl() {
function log() {
var txt = tmpl.apply(this, arguments);
sys.puts(txt);
console.log(txt);
}
function log_directory(dir) {

View File

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