Skip to content

Commit

Permalink
Merge pull request #122 from mattbasta/loopfix
Browse files Browse the repository at this point in the history
Reverse order of context/frame lookup (issue #119)
  • Loading branch information
jlongster committed Aug 21, 2013
2 parents 6de5328 + cd27a80 commit 254b0eb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ function callWrap(obj, name, args) {
}

function contextOrFrameLookup(context, frame, name) {
var val = context.lookup(name);
var val = frame.lookup(name);
return (val !== undefined && val !== null) ?
val :
frame.lookup(name);
context.lookup(name);
}

function handleError(error, lineno, colno) {
Expand Down
15 changes: 15 additions & 0 deletions tests/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,21 @@
equal('{% ' + block + ' k, v in items %}{{ loop.length }}{% ' + end + ' %}',
{ items: { foo: 1, bar: 2 }},
'22');

render('{% set item = passed_var %}' +
'{% include "item.html" %}\n' +
'{% ' + block + ' i in passed_iter %}' +
'{% set item = i %}' +
'{% include "item.html" %}\n' +
'{% ' + end + ' %}',
{
passed_var: 'test',
passed_iter: ['1', '2', '3']
},
{},
function(err, res) {
expect(res).to.be('showing test\nshowing 1\nshowing 2\nshowing 3\n');
});
}

it('should compile for blocks', function(done) {
Expand Down

0 comments on commit 254b0eb

Please sign in to comment.