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 () {