From 0eaf9b84ad75a33a2a2dd9d524c2415a390cda85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=A1=D1=82?= =?UTF-8?q?=D0=BE=D0=BB=D0=B1=D0=BE=D0=B2?= Date: Tue, 27 May 2014 21:57:05 +0400 Subject: [PATCH] Fixed null object property --- lib/parser.js | 4 ++-- tests/basic.test.js | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index 458e02cb..4e0a98b4 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -399,12 +399,12 @@ TokenParser.prototype = { m = match, build = ''; - build = '(typeof ' + c + ' !== "undefined"'; + build = '(typeof ' + c + ' !== "undefined" && ' + c + ' !== null'; utils.each(m, function (v, i) { if (i === 0) { return; } - build += ' && ' + c + '.' + v + ' !== undefined'; + build += ' && ' + c + '.' + v + ' !== undefined && ' + c + '.' + v + ' !== null'; c += '.' + v; }); build += ')'; diff --git a/tests/basic.test.js b/tests/basic.test.js index a07f44dc..88288782 100644 --- a/tests/basic.test.js +++ b/tests/basic.test.js @@ -160,6 +160,13 @@ describe('options', function () { .to.throwError(); }); }); + + describe('null object', function () { + it('can skip null object', function () { + expect(swig.render('{{ a.property }}', { locals: { a: null }})).to.equal(''); + }); + }); + }); describe('separate instances', function () {