Skip to content

Commit

Permalink
Move lambda resolution to runtime
Browse files Browse the repository at this point in the history
This has a very positive impact on precompiled output size, particularly for known-helpers cases, and little or no impact on the throughput numbers.
  • Loading branch information
kpdecker committed Jul 6, 2014
1 parent 704961b commit 4aad72d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down

0 comments on commit 4aad72d

Please sign in to comment.