Permalink
Browse files

Fixed uglify error handling

  • Loading branch information...
1 parent c92bdb4 commit 5dd36211e53f1bd1d869d3b01aa8412b6ac0ca7d @tj committed Aug 3, 2011
Showing with 15 additions and 3 deletions.
  1. +15 −3 lib/parser.js
View
@@ -9,8 +9,8 @@
* Module dependencies.
*/
-var parse = require('uglify-js').parser.parse;
-
+var parse = require('uglify-js').parser.parse
+ , sys = require('sys');
/**
* Return stats for the given javascript `str`.
@@ -231,6 +231,18 @@ module.exports = function(str){
visit(node[1]);
};
- visit(parse(str));
+ try {
+ visit(parse(str));
+ } catch (err) {
+ if ('JS_Parse_Error' != err.constructor.name) throw err;
+ var line = str.split('\n')[err.line];
+ err = new SyntaxError(err.message
+ + ' on line '
+ + err.line
+ + ':' + err.col
+ + ':\n ' + sys.inspect(line));
+ throw err;
+ }
+
return stats;
};

0 comments on commit 5dd3621

Please sign in to comment.