diff options
author | tomhuda <tomhuda@tilde.io> | 2012-05-28 14:19:48 -0700 |
---|---|---|
committer | tomhuda <tomhuda@tilde.io> | 2012-05-28 14:19:48 -0700 |
commit | 3486b530beb9a9516bb8c67470b3515133259559 (patch) | |
tree | 3518d8103cec4e6914e8d2eeb81c934f1f3814ca /lib/handlebars/compiler/compiler.js | |
parent | bc5efc1767abdaa5e8e702eb0f8833485e3f7c4f (diff) | |
download | handlebars.js-3486b530beb9a9516bb8c67470b3515133259559.zip handlebars.js-3486b530beb9a9516bb8c67470b3515133259559.tar.gz handlebars.js-3486b530beb9a9516bb8c67470b3515133259559.tar.bz2 |
Disambiguate more ahead of time
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 4580f31..12f1695 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -168,26 +168,43 @@ Handlebars.JavaScriptCompiler = function() {}; }, mustache: function(mustache) { - var id = mustache.id; + var isHelper = mustache.isHelper; + var isEligible = mustache.eligibleHelper; + var options = this.options; + + // if ambiguous, we can possibly resolve the ambiguity now + if (isEligible && !isHelper) { + var name = mustache.id.parts[0]; + + if (options.knownHelpers[name]) { + isHelper = true; + } else if (options.knownHelpersOnly) { + isEligible = false; + } + } - if (!mustache.eligibleHelper) { + if (!isEligible) { this.simpleMustache(mustache); - } else if (mustache.isHelper) { + } else if (isHelper) { this.helperMustache(mustache); } else { - var params = this.setupStackForMustache(mustache), - name = id.parts[0]; - - this.opcode('invokeMustache', params.length, mustache.id.original); + this.ambiguousMustache(mustache); } - if(mustache.escaped && !this.options.noEscape) { + if(mustache.escaped && !options.noEscape) { this.opcode('appendEscaped'); } else { this.opcode('append'); } }, + ambiguousMustache: function(mustache) { + var params = this.setupStackForMustache(mustache), + id = mustache.id, name = id.parts[0]; + + this.opcode('invokeMustache', params.length, id.original); + }, + simpleMustache: function(mustache) { var id = mustache.id; |