From 5cf9e6e77ed2d85ce0484a0bbc845061073ee45f Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Wed, 21 Dec 2016 22:22:08 +0100 Subject: [PATCH] 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". --- lib/handlebars/exception.js | 5 ++++- spec/compiler.js | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/handlebars/exception.js b/lib/handlebars/exception.js index 08ae531aa..b9a5557b6 100644 --- a/lib/handlebars/exception.js +++ b/lib/handlebars/exception.js @@ -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; } diff --git a/spec/compiler.js b/spec/compiler.js index 9eaba4a21..95941bcc3 100644 --- a/spec/compiler.js +++ b/spec/compiler.js @@ -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',