return Error from minify() (#1880)

Have `minify()` return `Error` in `result.error` rather than throwing it.
This commit is contained in:
Alex Lam S.L
2017-05-08 07:05:19 +08:00
committed by GitHub
parent da295de82b
commit a3b2eb75bd
3 changed files with 28 additions and 25 deletions

View File

@@ -172,7 +172,7 @@ function run() {
UglifyJS.AST_Node.warn_function = function(msg) {
console.error("WARN:", msg);
};
if (program.stats) program.stats = Date.now();
if (program.stats) program.stats = Date.now();
try {
if (program.parse) {
if (program.parse.acorn) {
@@ -192,8 +192,12 @@ function run() {
});
}
}
var result = UglifyJS.minify(files, options);
} catch (ex) {
fatal("ERROR: " + ex.message);
}
var result = UglifyJS.minify(files, options);
if (result.error) {
var ex = result.error;
if (ex.name == "SyntaxError") {
console.error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col);
var col = ex.col;
@@ -217,8 +221,7 @@ function run() {
console.error(ex.defs);
}
fatal("ERROR: " + ex.message);
}
if (program.output == "ast") {
} else if (program.output == "ast") {
console.log(JSON.stringify(result.ast, function(key, value) {
if (skip_key(key)) return;
if (value instanceof UglifyJS.AST_Token) return;