improve usability (#5753)

This commit is contained in:
Alex Lam S.L
2022-12-02 04:14:07 +02:00
committed by GitHub
parent 59e385591c
commit 650e63c8aa
3 changed files with 17 additions and 4 deletions

View File

@@ -272,6 +272,7 @@ if (typeof options.sourceMap == "object" && "base" in options.sourceMap) {
if (specified["self"]) { if (specified["self"]) {
if (paths.length) UglifyJS.AST_Node.warn("Ignoring input files since --self was passed"); if (paths.length) UglifyJS.AST_Node.warn("Ignoring input files since --self was passed");
if (!options.wrap) options.wrap = "UglifyJS"; if (!options.wrap) options.wrap = "UglifyJS";
if (!("toplevel" in options)) options.toplevel = false;
paths = UglifyJS.FILES; paths = UglifyJS.FILES;
} else if (paths.length) { } else if (paths.length) {
paths = simple_glob(paths); paths = simple_glob(paths);

View File

@@ -207,7 +207,11 @@ function JS_Parse_Error(message, filename, line, col, pos) {
this.line = line; this.line = line;
this.col = col; this.col = col;
this.pos = pos; this.pos = pos;
configure_error_stack(this, new SyntaxError(message, filename, line, col)); try {
throw new SyntaxError(message, filename, line, col);
} catch (cause) {
configure_error_stack(this, cause);
}
} }
JS_Parse_Error.prototype = Object.create(SyntaxError.prototype); JS_Parse_Error.prototype = Object.create(SyntaxError.prototype);
JS_Parse_Error.prototype.constructor = JS_Parse_Error; JS_Parse_Error.prototype.constructor = JS_Parse_Error;

View File

@@ -65,8 +65,12 @@ function configure_error_stack(ex, cause) {
var msg = "" + cause.message; var msg = "" + cause.message;
cause = null; cause = null;
var index = stack.indexOf(msg); var index = stack.indexOf(msg);
if (index >= 0) index += msg.length; if (index < 0) {
index = stack.indexOf("\n", index) + 1; index = 0;
} else {
index += msg.length;
index = stack.indexOf("\n", index) + 1;
}
stack = stack.slice(0, index) + stack.slice(stack.indexOf("\n", index) + 1); stack = stack.slice(0, index) + stack.slice(stack.indexOf("\n", index) + 1);
} }
return stack; return stack;
@@ -77,7 +81,11 @@ function configure_error_stack(ex, cause) {
function DefaultsError(msg, defs) { function DefaultsError(msg, defs) {
this.message = msg; this.message = msg;
this.defs = defs; this.defs = defs;
configure_error_stack(this, new Error(msg)); try {
throw new Error(msg);
} catch (cause) {
configure_error_stack(this, cause);
}
} }
DefaultsError.prototype = Object.create(Error.prototype); DefaultsError.prototype = Object.create(Error.prototype);
DefaultsError.prototype.constructor = DefaultsError; DefaultsError.prototype.constructor = DefaultsError;