summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/compiler.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-08-03 15:59:53 -0500
committerkpdecker <kpdecker@gmail.com>2015-08-03 15:59:53 -0500
commit5d4b8da344ab5060205678375df298a3d738e862 (patch)
tree376491aa30d6cbcd22c54f64711573daf43d8981 /lib/handlebars/compiler/compiler.js
parent279e038ba7ff7e5966a60e36d326e2d4c310f0c6 (diff)
downloadhandlebars.js-5d4b8da344ab5060205678375df298a3d738e862.zip
handlebars.js-5d4b8da344ab5060205678375df298a3d738e862.tar.gz
handlebars.js-5d4b8da344ab5060205678375df298a3d738e862.tar.bz2
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
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r--lib/handlebars/compiler/compiler.js10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index c1ef47e..59a425f 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -217,13 +217,16 @@ Compiler.prototype = {
this.opcode('pushProgram', program);
this.opcode('pushProgram', inverse);
+ path.strict = true;
this.accept(path);
this.opcode('invokeAmbiguous', name, isBlock);
},
simpleSexpr: function(sexpr) {
- this.accept(sexpr.path);
+ let path = sexpr.path;
+ path.strict = true;
+ this.accept(path);
this.opcode('resolvePossibleLambda');
},
@@ -237,6 +240,7 @@ Compiler.prototype = {
} else if (this.options.knownHelpersOnly) {
throw new Exception('You specified knownHelpersOnly, but used the unknown helper ' + name, sexpr);
} else {
+ path.strict = true;
path.falsy = true;
this.accept(path);
@@ -259,9 +263,9 @@ Compiler.prototype = {
this.opcode('pushContext');
} else if (path.data) {
this.options.data = true;
- this.opcode('lookupData', path.depth, path.parts);
+ this.opcode('lookupData', path.depth, path.parts, path.strict);
} else {
- this.opcode('lookupOnContext', path.parts, path.falsy, scoped);
+ this.opcode('lookupOnContext', path.parts, path.falsy, path.strict, scoped);
}
},