Update 2nd level opcodes to use inlines

This commit is contained in:
kpdecker
2013-01-19 18:33:49 -06:00
parent e9ac494ffd
commit 39cc7c6816
+19 -11
View File
@@ -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