From c7dc3539566dac1fbc82661b432ee26c4731548a Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Tue, 20 Dec 2016 09:32:18 +0100 Subject: [PATCH] Testcase to verify that compile-errors have a column-property Related to #1284 The test ensures that the property is there, because it is important to some people. --- spec/compiler.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/compiler.js b/spec/compiler.js index be1fb007d..9eaba4a21 100644 --- a/spec/compiler.js +++ b/spec/compiler.js @@ -38,6 +38,22 @@ describe('compiler', function() { }, Error, 'You must pass a string or Handlebars AST to Handlebars.compile. You passed [object Object]'); }); + it('should include the location in the error (row and column)', 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.message, 'if doesn\'t match def - 2:5', 'Checking error message'); + if (Object.getOwnPropertyDescriptor(err, 'column').writable) { + // In Safari 8, the column-property is read-only. This means that even if it is set with defineProperty, + // its value won't change (https://github.com/jquery/esprima/issues/1290#issuecomment-132455482) + // Since this was neither working in Handlebars 3 nor in 4.0.5, we only check the column for other browsers. + equal(err.column, 5, 'Checking error column'); + } + equal(err.lineNumber, 2, 'Checking error row'); + } + }); + it('can utilize AST instance', function() { equal(Handlebars.compile({ type: 'Program',