diff options
author | kpdecker <kpdecker@gmail.com> | 2014-01-01 19:14:51 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2014-01-01 19:14:51 -0600 |
commit | 6e4e1f84040d8c7ee415ef711be7572ec94f3eb6 (patch) | |
tree | 90445963d0a48378bc200158d8d85fd4ce124dad /lib/handlebars/exception.js | |
parent | 3c85720137c039cefc38046541f05731d151a506 (diff) | |
download | handlebars.js-6e4e1f84040d8c7ee415ef711be7572ec94f3eb6.zip handlebars.js-6e4e1f84040d8c7ee415ef711be7572ec94f3eb6.tar.gz handlebars.js-6e4e1f84040d8c7ee415ef711be7572ec94f3eb6.tar.bz2 |
Include line info in compiler thrown exceptions
Fixes #636
Diffstat (limited to 'lib/handlebars/exception.js')
-rw-r--r-- | lib/handlebars/exception.js | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/handlebars/exception.js b/lib/handlebars/exception.js index 6de9cfd..8c5c2f6 100644 --- a/lib/handlebars/exception.js +++ b/lib/handlebars/exception.js @@ -1,13 +1,25 @@ var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack']; -function Exception(/* message */) { - var tmp = Error.prototype.constructor.apply(this, arguments); +function Exception(message, node) { + var line; + if (node && node.firstLine) { + line = node.firstLine; + + message += ' - ' + line + ':' + node.firstColumn; + } + + var tmp = Error.prototype.constructor.call(this, message); // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work. for (var idx = 0; idx < errorProps.length; idx++) { this[errorProps[idx]] = tmp[errorProps[idx]]; } + + if (line) { + this.lineNumber = line; + this.column = node.firstColumn; + } } Exception.prototype = new Error(); |