| @@ -121,7 +121,7 @@ | |||||
| }; | }; | ||||
| function Context(view, parent) { | function Context(view, parent) { | ||||
| this.view = view || {}; | |||||
| this.view = view == null ? {} : view; | |||||
| this.parent = parent; | this.parent = parent; | ||||
| this._cache = {}; | this._cache = {}; | ||||
| } | } | ||||
| @@ -135,9 +135,10 @@ | |||||
| }; | }; | ||||
| Context.prototype.lookup = function (name) { | Context.prototype.lookup = function (name) { | ||||
| var value = this._cache[name]; | |||||
| if (!value) { | |||||
| var value; | |||||
| if (name in this._cache) { | |||||
| value = this._cache[name]; | |||||
| } else { | |||||
| if (name === '.') { | if (name === '.') { | ||||
| value = this.view; | value = this.view; | ||||
| } else { | } else { | ||||
| @@ -148,7 +149,7 @@ | |||||
| value = context.view; | value = context.view; | ||||
| var names = name.split('.'), i = 0; | var names = name.split('.'), i = 0; | ||||
| while (value && i < names.length) { | |||||
| while (value != null && i < names.length) { | |||||
| value = value[names[i++]]; | value = value[names[i++]]; | ||||
| } | } | ||||
| } else { | } else { | ||||
| @@ -0,0 +1 @@ | |||||
| ({ nums: [0, 1, 2] }) | |||||
| @@ -0,0 +1 @@ | |||||
| {{#nums}}{{.}},{{/nums}} | |||||
| @@ -0,0 +1 @@ | |||||
| 0,1,2, | |||||
| @@ -43,6 +43,23 @@ describe('A new Mustache.Context', function () { | |||||
| }); | }); | ||||
| }); | }); | ||||
| describe('A Mustache.Context', function () { | |||||
| var context; | |||||
| describe('with an empty string in the lookup chain', function () { | |||||
| var view, context; | |||||
| beforeEach(function () { | |||||
| view = { a: '' }; | |||||
| view.a.b = 'value'; | |||||
| context = new Context(view); | |||||
| }); | |||||
| it('is able to lookup a nested property', function () { | |||||
| assert.equal(context.lookup('a.b'), view.a.b); | |||||
| }); | |||||
| }); | |||||
| }); | |||||
| describe('Mustache.Context.make', function () { | describe('Mustache.Context.make', function () { | ||||
| it('returns the same object when given a Context', function () { | it('returns the same object when given a Context', function () { | ||||
| var context = new Context; | var context = new Context; | ||||