diff options
author | kpdecker <kpdecker@gmail.com> | 2014-07-06 23:40:46 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2014-07-06 23:41:15 -0500 |
commit | b5a5c76ceb85fee36340e14b79306a436d32ff72 (patch) | |
tree | 08f036fce72b0e0f1c700383cdba1d13033334ec /lib/handlebars/compiler/compiler.js | |
parent | 4aad72d2230a6eaaf242130c57ad1efa4d701f3c (diff) | |
download | handlebars.js-b5a5c76ceb85fee36340e14b79306a436d32ff72.zip handlebars.js-b5a5c76ceb85fee36340e14b79306a436d32ff72.tar.gz handlebars.js-b5a5c76ceb85fee36340e14b79306a436d32ff72.tar.bz2 |
Rework lookup null protector logic
- Move the lookup null protection out of `nameLookup` and into that contexts that are aware of the needs for falsy vs. not displayed values.
- Optimize lookup for nested path operations
Fixes #731
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index e5f2280..31176c9 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -275,6 +275,8 @@ Compiler.prototype = { } else if (this.options.knownHelpersOnly) { throw new Exception("You specified knownHelpersOnly, but used the unknown helper " + name, sexpr); } else { + id.falsy = true; + this.ID(id); this.opcode('invokeHelper', params.length, id.original, sexpr.isRoot); } @@ -298,23 +300,16 @@ Compiler.prototype = { var name = id.parts[0]; if (!name) { + // Context reference, i.e. `{{foo .}}` or `{{foo ..}}` this.opcode('pushContext'); } else { - this.opcode('lookupOnContext', id.parts[0]); - } - - for(var i=1, l=id.parts.length; i<l; i++) { - this.opcode('lookup', id.parts[i]); + this.opcode('lookupOnContext', id.parts, id.falsy); } }, DATA: function(data) { this.options.data = true; - this.opcode('lookupData', data.id.depth); - var parts = data.id.parts; - for(var i=0, l=parts.length; i<l; i++) { - this.opcode('lookup', parts[i]); - } + this.opcode('lookupData', data.id.depth, data.id.parts); }, STRING: function(string) { |