Ignore empty when iterating on sparse arrays

Fixes #1065
This commit is contained in:
kpdecker
2015-08-04 12:40:33 -05:00
parent 0de8dac702
commit 06d515a89d
2 changed files with 13 additions and 0 deletions
+6
View File
@@ -25,6 +25,12 @@ export default function(instance) {
}
function execIteration(field, index, last) {
// Don't iterate over undefined values since we can't execute blocks against them
// in non-strict (js) mode.
if (context[field] == null) {
return;
}
if (data) {
data.key = field;
data.index = index;
+7
View File
@@ -196,4 +196,11 @@ describe('Regressions', function() {
shouldCompileToWithPartials(root, [{}, helpers, partials], true, '<partial>');
});
it('GH-1065: Sparse arrays', function() {
var array = [];
array[1] = 'foo';
array[3] = 'bar';
shouldCompileTo('{{#each array}}{{@index}}{{.}}{{/each}}', {array: array}, '1foo3bar');
});
});