Skip to content

Commit 57cdfd1

Browse files
committed
Make "column"-property of Errors enumerable
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".
1 parent 7a51fa7 commit 57cdfd1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/handlebars/exception.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ function Exception(message, node) {
3131
// Work around issue under safari where we can't directly set the column value
3232
/* istanbul ignore next */
3333
if (Object.defineProperty) {
34-
Object.defineProperty(this, 'column', {value: column});
34+
Object.defineProperty(this, 'column', {
35+
value: column,
36+
enumerable: true
37+
});
3538
} else {
3639
this.column = column;
3740
}

spec/compiler.js

+9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ describe('compiler', function() {
4848
}
4949
});
5050

51+
it('should include the location as enumerable property', function() {
52+
try {
53+
Handlebars.compile(' \n {{#if}}\n{{/def}}')();
54+
equal(true, false, 'Statement must throw exception. This line should not be executed.');
55+
} catch (err) {
56+
equal(err.propertyIsEnumerable('column'), true, 'Checking error column');
57+
}
58+
});
59+
5160
it('can utilize AST instance', function() {
5261
equal(Handlebars.compile({
5362
type: 'Program',

0 commit comments

Comments
 (0)