diff options
author | kpdecker <kpdecker@gmail.com> | 2014-07-06 12:53:01 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2014-07-06 12:53:01 -0500 |
commit | 4aad72d2230a6eaaf242130c57ad1efa4d701f3c (patch) | |
tree | 5ef8394e33ce3206032fe6b256db0b64444af694 | |
parent | 704961b37840a439d6576a0d8f0f595838ab0963 (diff) | |
download | handlebars.js-4aad72d2230a6eaaf242130c57ad1efa4d701f3c.zip handlebars.js-4aad72d2230a6eaaf242130c57ad1efa4d701f3c.tar.gz handlebars.js-4aad72d2230a6eaaf242130c57ad1efa4d701f3c.tar.bz2 |
Move lambda resolution to runtime
This has a very positive impact on precompiled output size, particularly for known-helpers cases, and little or no impact on the throughput numbers.
-rw-r--r-- | lib/handlebars/compiler/javascript-compiler.js | 6 | ||||
-rw-r--r-- | lib/handlebars/runtime.js | 4 |
2 files changed, 6 insertions, 4 deletions
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index 4b9db92..4d950d4 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -377,11 +377,9 @@ JavaScriptCompiler.prototype = { // If the `value` is a lambda, replace it on the stack by // the return value of the lambda resolvePossibleLambda: function() { - this.aliases.functionType = '"function"'; + this.aliases.lambda = 'this.lambda'; - this.replaceStack(function(current) { - return "typeof " + current + " === functionType ? " + current + ".apply(depth0) : " + current; - }); + this.push('lambda(' + this.popStack() + ', depth0)'); }, // [lookup] diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js index d43f465..b9fc77d 100644 --- a/lib/handlebars/runtime.js +++ b/lib/handlebars/runtime.js @@ -50,6 +50,10 @@ export function template(templateSpec, env) { // Just add water var container = { + lambda: function(current, context) { + return typeof current === 'function' ? current.call(context) : current; + }, + escapeExpression: Utils.escapeExpression, invokePartial: invokePartialWrapper, |