Pass undefined fields to helpers in strict mode

This allows for `{{helper foo}}` to still operate under strict mode when `foo` is not defined on the context. This allows helpers to perform whatever existence checks they please so patterns like `{{#if foo}}{{foo}}{{/if}}` can be used to protect against missing values.

Fixes #1063
This commit is contained in:
kpdecker
2015-08-03 15:59:53 -05:00
parent 279e038ba7
commit 5d4b8da344
3 changed files with 30 additions and 9 deletions
@@ -390,7 +390,7 @@ JavaScriptCompiler.prototype = {
//
// Looks up the value of `name` on the current context and pushes
// it onto the stack.
lookupOnContext: function(parts, falsy, scoped) {
lookupOnContext: function(parts, falsy, strict, scoped) {
let i = 0;
if (!scoped && this.options.compat && !this.lastContext) {
@@ -401,7 +401,7 @@ JavaScriptCompiler.prototype = {
this.pushContext();
}
this.resolvePath('context', parts, i, falsy);
this.resolvePath('context', parts, i, falsy, strict);
},
// [lookupBlockParam]
@@ -424,19 +424,19 @@ JavaScriptCompiler.prototype = {
// On stack, after: data, ...
//
// Push the data lookup operator
lookupData: function(depth, parts) {
lookupData: function(depth, parts, strict) {
if (!depth) {
this.pushStackLiteral('data');
} else {
this.pushStackLiteral('this.data(data, ' + depth + ')');
}
this.resolvePath('data', parts, 0, true);
this.resolvePath('data', parts, 0, true, strict);
},
resolvePath: function(type, parts, i, falsy) {
resolvePath: function(type, parts, i, falsy, strict) {
if (this.options.strict || this.options.assumeObjects) {
this.push(strictLookup(this.options.strict, this, parts, type));
this.push(strictLookup(this.options.strict && strict, this, parts, type));
return;
}