summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/compiler.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2013-01-19 18:33:49 -0600
committerkpdecker <kpdecker@gmail.com>2013-01-19 18:33:49 -0600
commit39cc7c681678fae2f631f93b913ff2a8ae579c6b (patch)
treed8ea64e845465d5835aa38f8cd2caf46ef39e49e /lib/handlebars/compiler/compiler.js
parente9ac494ffd76c9d3a4312a595c271c2ffe662d74 (diff)
downloadhandlebars.js-39cc7c681678fae2f631f93b913ff2a8ae579c6b.zip
handlebars.js-39cc7c681678fae2f631f93b913ff2a8ae579c6b.tar.gz
handlebars.js-39cc7c681678fae2f631f93b913ff2a8ae579c6b.tar.bz2
Update 2nd level opcodes to use inlines
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r--lib/handlebars/compiler/compiler.js30
1 files changed, 19 insertions, 11 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index f9bec39..760cba6 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -162,6 +162,7 @@ Handlebars.JavaScriptCompiler = function() {};
this.opcode('assignToHash', pair[0]);
}
+ this.opcode('popHash');
},
partial: function(partial) {
@@ -648,7 +649,7 @@ Handlebars.JavaScriptCompiler = function() {};
this.replaceStack(function(current) {
return "typeof " + current + " === functionType ? " + current + ".apply(depth0) : " + current;
- });
+ }, true);
},
// [lookup]
@@ -661,7 +662,7 @@ Handlebars.JavaScriptCompiler = function() {};
lookup: function(name) {
this.replaceStack(function(current) {
return current + " == null || " + current + " === false ? " + current + " : " + this.nameLookup(current, name, 'context');
- });
+ }, true);
},
// [lookupData]
@@ -702,11 +703,16 @@ Handlebars.JavaScriptCompiler = function() {};
}
},
pushHash: function() {
- this.push('{}');
+ this.hash = {values: [], types: []};
+ },
+ popHash: function() {
+ var hash = this.hash;
+ this.hash = undefined;
if (this.options.stringParams) {
- this.register('hashTypes', '{}');
+ this.register('hashTypes', '{' + hash.types.join(',') + '}');
}
+ this.pushStack('{' + hash.values.join(',\n\t') + '\n }', true);
},
// [pushString]
@@ -726,7 +732,7 @@ Handlebars.JavaScriptCompiler = function() {};
//
// Push an expression onto the stack
push: function(expr) {
- this.pushStack(expr);
+ this.pushStack(expr, true);
},
// [pushLiteral]
@@ -842,17 +848,19 @@ Handlebars.JavaScriptCompiler = function() {};
// Pops a value and hash off the stack, assigns `hash[key] = value`
// and pushes the hash back onto the stack.
assignToHash: function(key) {
- var value = this.popStack();
+ var value = this.popStack(),
+ type;
if (this.options.stringParams) {
- var type = this.popStack();
+ type = this.popStack();
this.popStack();
- this.source.push("hashTypes['" + key + "'] = " + type + ";");
}
- var hash = this.topStack();
-
- this.source.push(hash + "['" + key + "'] = " + value + ";");
+ var hash = this.hash;
+ if (type) {
+ hash.types.push("'" + key + "': " + type);
+ }
+ hash.values.push("'" + key + "': (" + value + ")");
},
// HELPERS