Add filename to the JS_Parse_Error exception.
authorEdward Casbon <edward@edwardcasbon.co.uk>
Mon, 11 Aug 2014 11:40:01 +0000 (12:40 +0100)
committerRichard van Velzen <rvanvelzen1@gmail.com>
Wed, 11 Feb 2015 22:21:22 +0000 (23:21 +0100)
It would be nice to have access to the filename of the file that includes the code that causes a JavaScript error. This is especially handy if uglifying multiple files at once.

Only a small change is needed for this to happen as it's already available in the function that throws the error.

lib/parse.js

index 78c1dd4..0e269ab 100644 (file)
@@ -187,8 +187,9 @@ function parse_js_number(num) {
     }
 };
 
-function JS_Parse_Error(message, line, col, pos) {
+function JS_Parse_Error(message, filename, line, col, pos) {
     this.message = message;
+    this.filename = filename;
     this.line = line;
     this.col = col;
     this.pos = pos;
@@ -200,7 +201,7 @@ JS_Parse_Error.prototype.toString = function() {
 };
 
 function js_error(message, filename, line, col, pos) {
-    throw new JS_Parse_Error(message, line, col, pos);
+    throw new JS_Parse_Error(message, filename, line, col, pos);
 };
 
 function is_token(token, type, val) {