Skip to content

Commit

Permalink
Merge pull request #849 from wycats/helper-undefined
Browse files Browse the repository at this point in the history
Fix undefined handling for pathed lookups
  • Loading branch information
kpdecker committed Aug 15, 2014
2 parents 2f14fa5 + 3ce105a commit cf343a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,9 @@ JavaScriptCompiler.prototype = {
for (; i < len; i++) {
this.replaceStack(function(current) {
var lookup = this.nameLookup(current, parts[i], 'context');
// We want to ensure that zero and false are handled properly for the first element
// of non-chained elements, if the context (falsy flag) needs to have the special
// handling for these values.
if (!falsy && !i && len === 1) {
// We want to ensure that zero and false are handled properly if the context (falsy flag)
// needs to have the special handling for these values.
if (!falsy) {
return ' != null ? ' + lookup + ' : ' + current;
} else {
// Otherwise we can use generic falsy handling
Expand Down
8 changes: 8 additions & 0 deletions spec/regressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,12 @@ describe('Regressions', function() {
it('GH-820: zero pathed rendering', function() {
shouldCompileTo('{{foo.bar}}', {foo: 0}, '');
});

it('GH-837: undefined values for helpers', function() {
var helpers = {
str: function(value) { return value + ''; }
};

shouldCompileTo('{{str bar.baz}}', [{}, helpers], 'undefined');
});
});

0 comments on commit cf343a1

Please sign in to comment.