Skip to content

Commit

Permalink
improve usability (#5753)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl authored Dec 2, 2022
1 parent 59e3855 commit 650e63c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions bin/uglifyjs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ if (typeof options.sourceMap == "object" && "base" in options.sourceMap) {
if (specified["self"]) {
if (paths.length) UglifyJS.AST_Node.warn("Ignoring input files since --self was passed");
if (!options.wrap) options.wrap = "UglifyJS";
if (!("toplevel" in options)) options.toplevel = false;
paths = UglifyJS.FILES;
} else if (paths.length) {
paths = simple_glob(paths);
Expand Down
6 changes: 5 additions & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ function JS_Parse_Error(message, filename, line, col, pos) {
this.line = line;
this.col = col;
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.constructor = JS_Parse_Error;
Expand Down
14 changes: 11 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ function configure_error_stack(ex, cause) {
var msg = "" + cause.message;
cause = null;
var index = stack.indexOf(msg);
if (index >= 0) index += msg.length;
index = stack.indexOf("\n", index) + 1;
if (index < 0) {
index = 0;
} else {
index += msg.length;
index = stack.indexOf("\n", index) + 1;
}
stack = stack.slice(0, index) + stack.slice(stack.indexOf("\n", index) + 1);
}
return stack;
Expand All @@ -77,7 +81,11 @@ function configure_error_stack(ex, cause) {
function DefaultsError(msg, defs) {
this.message = msg;
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.constructor = DefaultsError;
Expand Down

0 comments on commit 650e63c

Please sign in to comment.