summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/compiler.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2014-01-06 14:41:23 -0600
committerkpdecker <kpdecker@gmail.com>2014-01-06 14:41:23 -0600
commitc73aceb3d3415e9847fa0680f42bf80d5a652bac (patch)
treed7bd492bde29204fef2482f620dd610b7594e7e7 /lib/handlebars/compiler/compiler.js
parentdaeecf825cda40d5903095cb86e6b2872870c472 (diff)
downloadhandlebars.js-c73aceb3d3415e9847fa0680f42bf80d5a652bac.zip
handlebars.js-c73aceb3d3415e9847fa0680f42bf80d5a652bac.tar.gz
handlebars.js-c73aceb3d3415e9847fa0680f42bf80d5a652bac.tar.bz2
Refactor out pushParams method
Simplifies hash and param push logic
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r--lib/handlebars/compiler/compiler.js53
1 files changed, 19 insertions, 34 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index 32d2048..b428c5f 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -186,30 +186,14 @@ Compiler.prototype = {
},
hash: function(hash) {
- var pairs = hash.pairs, pair, val;
+ var pairs = hash.pairs, pair;
this.opcode('pushHash');
for(var i=0, l=pairs.length; i<l; i++) {
pair = pairs[i];
- val = pair[1];
-
- if (this.stringParams) {
- if(val.depth) {
- this.addDepth(val.depth);
- }
- this.opcode('getContext', val.depth || 0);
- this.opcode('pushStringParam', val.stringModeValue, val.type);
-
- if (val.type === 'sexpr') {
- // Subexpressions get evaluated and passed in
- // in string params mode.
- this.sexpr(val);
- }
- } else {
- this.accept(val);
- }
+ this.pushParam(pair[1]);
this.opcode('assignToHash', pair[0]);
}
this.opcode('popHash');
@@ -382,27 +366,28 @@ Compiler.prototype = {
},
pushParams: function(params) {
- var i = params.length, param;
+ var i = params.length;
while(i--) {
- param = params[i];
-
- if(this.stringParams) {
- if(param.depth) {
- this.addDepth(param.depth);
- }
+ this.pushParam(params[i]);
+ }
+ },
- this.opcode('getContext', param.depth || 0);
- this.opcode('pushStringParam', param.stringModeValue, param.type);
+ pushParam: function(val) {
+ if (this.stringParams) {
+ if(val.depth) {
+ this.addDepth(val.depth);
+ }
+ this.opcode('getContext', val.depth || 0);
+ this.opcode('pushStringParam', val.stringModeValue, val.type);
- if (param.type === 'sexpr') {
- // Subexpressions get evaluated and passed in
- // in string params mode.
- this.sexpr(param);
- }
- } else {
- this[param.type](param);
+ if (val.type === 'sexpr') {
+ // Subexpressions get evaluated and passed in
+ // in string params mode.
+ this.sexpr(val);
}
+ } else {
+ this.accept(val);
}
},