Skip to content

Commit

Permalink
Make "column"-property of Errors enumerable
Browse files Browse the repository at this point in the history
Fixes #1284

Appearently, there is a use-case of stringifying the error in order to
evaluated its properties on another system. There was a regression
from 4.0.5  to 4.0.6 that the column-property of compilation errors
was not  enumerable anymore in 4.0.6 (due to  commit 20c965c) and
thus was not included in the output of "JSON.stringify".
  • Loading branch information
nknapp committed Dec 30, 2016
1 parent c7dc353 commit a023cb4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/handlebars/exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ function Exception(message, node) {
// Work around issue under safari where we can't directly set the column value
/* istanbul ignore next */
if (Object.defineProperty) {
Object.defineProperty(this, 'column', {value: column});
Object.defineProperty(this, 'column', {
value: column,
enumerable: true
});
} else {
this.column = column;
}
Expand Down
9 changes: 9 additions & 0 deletions spec/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ describe('compiler', function() {
}
});

it('should include the location as enumerable property', function() {
try {
Handlebars.compile(' \n {{#if}}\n{{/def}}')();
equal(true, false, 'Statement must throw exception. This line should not be executed.');
} catch (err) {
equal(err.propertyIsEnumerable('column'), true, 'Checking error column');
}
});

it('can utilize AST instance', function() {
equal(Handlebars.compile({
type: 'Program',
Expand Down

0 comments on commit a023cb4

Please sign in to comment.