c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove/* THIS FILE IS GENERATED BY A BUILD SCRIPT - DO NOT EDIT! */
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove// BEGIN(BROWSER)
93ba7d033a41a9c666ec4019e71a145259f65769Ryan Grove
93ba7d033a41a9c666ec4019e71a145259f65769Ryan Grove/*jshint eqnull:true*/
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan GroveHandlebars.Compiler = function() {};
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan GroveHandlebars.JavaScriptCompiler = function() {};
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove(function(Compiler, JavaScriptCompiler) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove Compiler.OPCODE_MAP = {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove appendContent: 1,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove getContext: 2,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove lookupWithHelpers: 3,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove lookup: 4,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove append: 5,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove invokeMustache: 6,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove appendEscaped: 7,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove pushString: 8,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove truthyOrFallback: 9,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove functionOrFallback: 10,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove invokeProgram: 11,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove invokePartial: 12,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove push: 13,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove assignToHash: 15,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove pushStringParam: 16
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove };
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove Compiler.MULTI_PARAM_OPCODES = {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove appendContent: 1,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove getContext: 1,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove lookupWithHelpers: 2,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove lookup: 1,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove invokeMustache: 3,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove pushString: 1,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove truthyOrFallback: 1,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove functionOrFallback: 1,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove invokeProgram: 3,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove invokePartial: 1,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove push: 1,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove assignToHash: 1,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove pushStringParam: 1
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove };
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove Compiler.DISASSEMBLE_MAP = {};
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for(var prop in Compiler.OPCODE_MAP) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var value = Compiler.OPCODE_MAP[prop];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove Compiler.DISASSEMBLE_MAP[value] = prop;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove Compiler.multiParamSize = function(code) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return Compiler.MULTI_PARAM_OPCODES[Compiler.DISASSEMBLE_MAP[code]];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove };
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove Compiler.prototype = {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove compiler: Compiler,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove disassemble: function() {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var opcodes = this.opcodes, opcode, nextCode;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var out = [], str, name, value;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for(var i=0, l=opcodes.length; i<l; i++) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove opcode = opcodes[i];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(opcode === 'DECLARE') {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove name = opcodes[++i];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove value = opcodes[++i];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove out.push("DECLARE " + name + " = " + value);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove str = Compiler.DISASSEMBLE_MAP[opcode];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var extraParams = Compiler.multiParamSize(opcode);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var codes = [];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for(var j=0; j<extraParams; j++) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove nextCode = opcodes[++i];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(typeof nextCode === "string") {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove nextCode = "\"" + nextCode.replace("\n", "\\n") + "\"";
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove codes.push(nextCode);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove str = str + " " + codes.join(" ");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove out.push(str);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return out.join("\n");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove guid: 0,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove compile: function(program, options) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.children = [];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.depths = {list: []};
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.options = options;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove // These changes will propagate to the other compiler components
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var knownHelpers = this.options.knownHelpers;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.options.knownHelpers = {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove 'helperMissing': true,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove 'blockHelperMissing': true,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove 'each': true,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove 'if': true,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove 'unless': true,
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove 'with': true,
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove 'log': true
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove };
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (knownHelpers) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for (var name in knownHelpers) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.options.knownHelpers[name] = knownHelpers[name];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return this.program(program);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove accept: function(node) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return this[node.type](node);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove program: function(program) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var statements = program.statements, statement;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcodes = [];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for(var i=0, l=statements.length; i<l; i++) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove statement = statements[i];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this[statement.type](statement);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.isSimple = l === 1;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.depths.list = this.depths.list.sort(function(a, b) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return a - b;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove });
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return this;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove compileProgram: function(program) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var result = new this.compiler().compile(program, this.options);
93ba7d033a41a9c666ec4019e71a145259f65769Ryan Grove var guid = this.guid++, depth;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.usePartial = this.usePartial || result.usePartial;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.children[guid] = result;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for(var i=0, l=result.depths.list.length; i<l; i++) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove depth = result.depths.list[i];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(depth < 2) { continue; }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove else { this.addDepth(depth - 1); }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return guid;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove block: function(block) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var mustache = block.mustache;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var depth, child, inverse, inverseGuid;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var params = this.setupStackForMustache(mustache);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var programGuid = this.compileProgram(block.program);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(block.program.inverse) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove inverseGuid = this.compileProgram(block.program.inverse);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.declare('inverse', inverseGuid);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('invokeProgram', programGuid, params.length, !!mustache.hash);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.declare('inverse', null);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('append');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove inverse: function(block) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var params = this.setupStackForMustache(block.mustache);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var programGuid = this.compileProgram(block.program);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.declare('inverse', programGuid);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('invokeProgram', null, params.length, !!block.mustache.hash);
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove this.declare('inverse', null);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('append');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove hash: function(hash) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var pairs = hash.pairs, pair, val;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('push', '{}');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for(var i=0, l=pairs.length; i<l; i++) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove pair = pairs[i];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove val = pair[1];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.accept(val);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('assignToHash', pair[0]);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove partial: function(partial) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var id = partial.id;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.usePartial = true;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(partial.context) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.ID(partial.context);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('push', 'depth0');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('invokePartial', id.original);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('append');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove content: function(content) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('appendContent', content.string);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove mustache: function(mustache) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var params = this.setupStackForMustache(mustache);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('invokeMustache', params.length, mustache.id.original, !!mustache.hash);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove if(mustache.escaped && !this.options.noEscape) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('appendEscaped');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('append');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove ID: function(id) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.addDepth(id.depth);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('getContext', id.depth);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('lookupWithHelpers', id.parts[0] || null, id.isScoped || false);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for(var i=1, l=id.parts.length; i<l; i++) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('lookup', id.parts[i]);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove STRING: function(string) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('pushString', string.string);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove INTEGER: function(integer) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('push', integer.integer);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove BOOLEAN: function(bool) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('push', bool.bool);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove comment: function() {},
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove // HELPERS
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove pushParams: function(params) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var i = params.length, param;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove while(i--) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove param = params[i];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(this.options.stringParams) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(param.depth) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.addDepth(param.depth);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('getContext', param.depth || 0);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcode('pushStringParam', param.string);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this[param.type](param);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove opcode: function(name, val1, val2, val3) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcodes.push(Compiler.OPCODE_MAP[name]);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(val1 !== undefined) { this.opcodes.push(val1); }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(val2 !== undefined) { this.opcodes.push(val2); }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(val3 !== undefined) { this.opcodes.push(val3); }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove declare: function(name, value) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcodes.push('DECLARE');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcodes.push(name);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.opcodes.push(value);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove addDepth: function(depth) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(depth === 0) { return; }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(!this.depths[depth]) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.depths[depth] = true;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.depths.list.push(depth);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove setupStackForMustache: function(mustache) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var params = mustache.params;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.pushParams(params);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(mustache.hash) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.hash(mustache.hash);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.ID(mustache.id);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return params;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove };
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove JavaScriptCompiler.prototype = {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove // PUBLIC API: You can override these methods in a subclass to provide
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove // alternative compiled forms for name lookup and buffering semantics
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove nameLookup: function(parent, name, type) {
8786ce1054827e072fd63a2082a6a723a4b5121fRyan Grove if (/^[0-9]+$/.test(name)) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return parent + "[" + name + "]";
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
8786ce1054827e072fd63a2082a6a723a4b5121fRyan Grove return parent + "." + name;
8786ce1054827e072fd63a2082a6a723a4b5121fRyan Grove }
8786ce1054827e072fd63a2082a6a723a4b5121fRyan Grove else {
8786ce1054827e072fd63a2082a6a723a4b5121fRyan Grove return parent + "['" + name + "']";
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove appendToBuffer: function(string) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (this.environment.isSimple) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return "return " + string + ";";
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return "buffer += " + string + ";";
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove initializeBuffer: function() {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return this.quotedString("");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove namespace: "Handlebars",
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove // END PUBLIC API
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove compile: function(environment, options, context, asObject) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.environment = environment;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.options = options || {};
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.name = this.environment.name;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.isChild = !!context;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.context = context || {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove programs: [],
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove aliases: { self: 'this' },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove registers: {list: []}
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove };
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.preamble();
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.stackSlot = 0;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.stackVars = [];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.compileChildren(environment, options);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var opcodes = environment.opcodes, opcode;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.i = 0;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for(l=opcodes.length; this.i<l; this.i++) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove opcode = this.nextOpcode(0);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(opcode[0] === 'DECLARE') {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.i = this.i + 2;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this[opcode[1]] = opcode[2];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.i = this.i + opcode[1].length;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this[opcode[0]].apply(this, opcode[1]);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return this.createFunctionContext(asObject);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove nextOpcode: function(n) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var opcodes = this.environment.opcodes, opcode = opcodes[this.i + n], name, val;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var extraParams, codes;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(opcode === 'DECLARE') {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove name = opcodes[this.i + 1];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove val = opcodes[this.i + 2];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return ['DECLARE', name, val];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove name = Compiler.DISASSEMBLE_MAP[opcode];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove extraParams = Compiler.multiParamSize(opcode);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove codes = [];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for(var j=0; j<extraParams; j++) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove codes.push(opcodes[this.i + j + 1 + n]);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return [name, codes];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove eat: function(opcode) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.i = this.i + opcode.length;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove preamble: function() {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var out = [];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove // this register will disambiguate helper lookup from finding a function in
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove // a context. This is necessary for mustache compatibility, which requires
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove // that context functions in blocks are evaluated by blockHelperMissing, and
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove // then proceed as if the resulting value was provided to blockHelperMissing.
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove this.useRegister('foundHelper');
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (!this.isChild) {
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove var namespace = this.namespace;
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove var copies = "helpers = helpers || " + namespace + ".helpers;";
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove if(this.environment.usePartial) { copies = copies + " partials = partials || " + namespace + ".partials;"; }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove out.push(copies);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove out.push('');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (!this.environment.isSimple) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove out.push(", buffer = " + this.initializeBuffer());
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove out.push("");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove // track the last context pushed into place to allow skipping the
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove // getContext opcode when it would be a noop
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.lastContext = 0;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source = out;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove createFunctionContext: function(asObject) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var locals = this.stackVars;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (!this.isChild) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove locals = locals.concat(this.context.registers.list);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(locals.length > 0) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source[1] = this.source[1] + ", " + locals.join(", ");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove // Generate minimizer alias mappings
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (!this.isChild) {
8786ce1054827e072fd63a2082a6a723a4b5121fRyan Grove var aliases = [];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for (var alias in this.context.aliases) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source[1] = this.source[1] + ', ' + alias + '=' + this.context.aliases[alias];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (this.source[1]) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source[1] = "var " + this.source[1].substring(2) + ";";
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove // Merge children
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (!this.isChild) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source[1] += '\n' + this.context.programs.join('\n') + '\n';
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (!this.environment.isSimple) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push("return buffer;");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var params = this.isChild ? ["depth0", "data"] : ["Handlebars", "depth0", "helpers", "partials", "data"];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for(var i=0, l=this.environment.depths.list.length; i<l; i++) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove params.push("depth" + this.environment.depths.list[i]);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (asObject) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove params.push(this.source.join("\n "));
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return Function.apply(this, params);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var functionSource = 'function ' + (this.name || '') + '(' + params.join(',') + ') {\n ' + this.source.join("\n ") + '}';
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove Handlebars.log(Handlebars.logger.DEBUG, functionSource + "\n\n");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return functionSource;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove appendContent: function(content) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push(this.appendToBuffer(this.quotedString(content)));
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove append: function() {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var local = this.popStack();
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push("if(" + local + " || " + local + " === 0) { " + this.appendToBuffer(local) + " }");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (this.environment.isSimple) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push("else { " + this.appendToBuffer("''") + " }");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove appendEscaped: function() {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var opcode = this.nextOpcode(1), extra = "";
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.context.aliases.escapeExpression = 'this.escapeExpression';
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(opcode[0] === 'appendContent') {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove extra = " + " + this.quotedString(opcode[1][0]);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.eat(opcode);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push(this.appendToBuffer("escapeExpression(" + this.popStack() + ")" + extra));
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove getContext: function(depth) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(this.lastContext !== depth) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.lastContext = depth;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove lookupWithHelpers: function(name, isScoped) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(name) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var topStack = this.nextStack();
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.usingKnownHelper = false;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var toPush;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (!isScoped && this.options.knownHelpers[name]) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove toPush = topStack + " = " + this.nameLookup('helpers', name, 'helper');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.usingKnownHelper = true;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else if (isScoped || this.options.knownHelpersOnly) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove toPush = topStack + " = " + this.nameLookup('depth' + this.lastContext, name, 'context');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove this.register('foundHelper', this.nameLookup('helpers', name, 'helper'));
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove toPush = topStack + " = foundHelper || " + this.nameLookup('depth' + this.lastContext, name, 'context');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove toPush += ';';
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push(toPush);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.pushStack('depth' + this.lastContext);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove lookup: function(name) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var topStack = this.topStack();
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push(topStack + " = (" + topStack + " === null || " + topStack + " === undefined || " + topStack + " === false ? " +
8786ce1054827e072fd63a2082a6a723a4b5121fRyan Grove topStack + " : " + this.nameLookup(topStack, name, 'context') + ");");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove pushStringParam: function(string) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.pushStack('depth' + this.lastContext);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.pushString(string);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove pushString: function(string) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.pushStack(this.quotedString(string));
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove push: function(name) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.pushStack(name);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove invokeMustache: function(paramSize, original, hasHash) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.populateParams(paramSize, this.quotedString(original), "{}", null, hasHash, function(nextStack, helperMissingString, id) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (!this.usingKnownHelper) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.context.aliases.helperMissing = 'helpers.helperMissing';
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.context.aliases.undef = 'void 0';
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push("else if(" + id + "=== undef) { " + nextStack + " = helperMissing.call(" + helperMissingString + "); }");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (nextStack !== id) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push("else { " + nextStack + " = " + id + "; }");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove });
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove invokeProgram: function(guid, paramSize, hasHash) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var inverse = this.programExpression(this.inverse);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var mainProgram = this.programExpression(guid);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.populateParams(paramSize, null, mainProgram, inverse, hasHash, function(nextStack, helperMissingString, id) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (!this.usingKnownHelper) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push("else { " + nextStack + " = blockHelperMissing.call(" + helperMissingString + "); }");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove });
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove populateParams: function(paramSize, helperId, program, inverse, hasHash, fn) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var needsRegister = hasHash || this.options.stringParams || inverse || this.options.data;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var id = this.popStack(), nextStack;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var params = [], param, stringParam, stringOptions;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (needsRegister) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.register('tmp1', program);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove stringOptions = 'tmp1';
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove stringOptions = '{ hash: {} }';
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (needsRegister) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var hash = (hasHash ? this.popStack() : '{}');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push('tmp1.hash = ' + hash + ';');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(this.options.stringParams) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push('tmp1.contexts = [];');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for(var i=0; i<paramSize; i++) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove param = this.popStack();
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove params.push(param);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(this.options.stringParams) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push('tmp1.contexts.push(' + this.popStack() + ');');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(inverse) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push('tmp1.fn = tmp1;');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push('tmp1.inverse = ' + inverse + ';');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(this.options.data) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push('tmp1.data = data;');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove params.push(stringOptions);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove this.populateCall(params, id, helperId || id, fn, program !== '{}');
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove populateCall: function(params, id, helperId, fn, program) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var paramString = ["depth0"].concat(params).join(", ");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var helperMissingString = ["depth0"].concat(helperId).concat(params).join(", ");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var nextStack = this.nextStack();
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if (this.usingKnownHelper) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push(nextStack + " = " + id + ".call(" + paramString + ");");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.context.aliases.functionType = '"function"';
8786ce1054827e072fd63a2082a6a723a4b5121fRyan Grove var condition = program ? "foundHelper && " : "";
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove this.source.push("if(" + condition + "typeof " + id + " === functionType) { " + nextStack + " = " + id + ".call(" + paramString + "); }");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove fn.call(this, nextStack, helperMissingString, id);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.usingKnownHelper = false;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove invokePartial: function(context) {
93ba7d033a41a9c666ec4019e71a145259f65769Ryan Grove var params = [this.nameLookup('partials', context, 'partial'), "'" + context + "'", this.popStack(), "helpers", "partials"];
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove if (this.options.data) {
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove params.push("data");
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove }
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove this.pushStack("self.invokePartial(" + params.join(", ") + ");");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove assignToHash: function(key) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var value = this.popStack();
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var hash = this.topStack();
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push(hash + "['" + key + "'] = " + value + ";");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove // HELPERS
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove compiler: JavaScriptCompiler,
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove compileChildren: function(environment, options) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var children = environment.children, child, compiler;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for(var i=0, l=children.length; i<l; i++) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove child = children[i];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove compiler = new this.compiler();
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.context.programs.push(''); // Placeholder to prevent name conflicts for nested children
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var index = this.context.programs.length;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove child.index = index;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove child.name = 'program' + index;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.context.programs[index] = compiler.compile(child, options, this.context);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove programExpression: function(guid) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(guid == null) { return "self.noop"; }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var child = this.environment.children[guid],
93ba7d033a41a9c666ec4019e71a145259f65769Ryan Grove depths = child.depths.list, depth;
93ba7d033a41a9c666ec4019e71a145259f65769Ryan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var programParams = [child.index, child.name, "data"];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for(var i=0, l = depths.length; i<l; i++) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove depth = depths[i];
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(depth === 1) { programParams.push("depth0"); }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove else { programParams.push("depth" + (depth - 1)); }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(depths.length === 0) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return "self.program(" + programParams.join(", ") + ")";
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove } else {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove programParams.shift();
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return "self.programWithDepth(" + programParams.join(", ") + ")";
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove register: function(name, val) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.useRegister(name);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push(name + " = " + val + ";");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove useRegister: function(name) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(!this.context.registers[name]) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.context.registers[name] = true;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.context.registers.list.push(name);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove pushStack: function(item) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.source.push(this.nextStack() + " = " + item + ";");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return "stack" + this.stackSlot;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove nextStack: function() {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove this.stackSlot++;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove if(this.stackSlot > this.stackVars.length) { this.stackVars.push("stack" + this.stackSlot); }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return "stack" + this.stackSlot;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove popStack: function() {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return "stack" + this.stackSlot--;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove topStack: function() {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return "stack" + this.stackSlot;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove },
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove quotedString: function(str) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return '"' + str
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove .replace(/\\/g, '\\\\')
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove .replace(/"/g, '\\"')
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove .replace(/\n/g, '\\n')
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove .replace(/\r/g, '\\r') + '"';
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove };
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove var reservedWords = (
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove "break else new var" +
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove " case finally return void" +
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove " catch for switch while" +
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove " continue function this with" +
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove " default if throw" +
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove " delete in try" +
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove " do instanceof typeof" +
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove " abstract enum int short" +
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove " boolean export interface static" +
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove " byte extends long super" +
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove " char final native synchronized" +
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove " class float package throws" +
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove " const goto private transient" +
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove " debugger implements protected volatile" +
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove " double import public let yield"
e0bd6b490d14919b958622a831bfadbf322397baRyan Grove ).split(" ");
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove for(var i=0, l=reservedWords.length; i<l; i++) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove compilerWords[reservedWords[i]] = true;
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove }
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
8786ce1054827e072fd63a2082a6a723a4b5121fRyan Grove JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
8786ce1054827e072fd63a2082a6a723a4b5121fRyan Grove if(!JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]+$/.test(name)) {
8786ce1054827e072fd63a2082a6a723a4b5121fRyan Grove return true;
8786ce1054827e072fd63a2082a6a723a4b5121fRyan Grove }
8786ce1054827e072fd63a2082a6a723a4b5121fRyan Grove return false;
8786ce1054827e072fd63a2082a6a723a4b5121fRyan Grove };
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove})(Handlebars.Compiler, Handlebars.JavaScriptCompiler);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan GroveHandlebars.precompile = function(string, options) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove options = options || {};
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var ast = Handlebars.parse(string);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove var environment = new Handlebars.Compiler().compile(ast, options);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove return new Handlebars.JavaScriptCompiler().compile(environment, options);
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove};
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan GroveHandlebars.compile = function(string, options) {
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove options = options || {};
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove var compiled;
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove function compile() {
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove var ast = Handlebars.parse(string);
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove var environment = new Handlebars.Compiler().compile(ast, options);
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true);
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove return Handlebars.template(templateSpec);
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove }
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove // Template is only compiled on first use and cached after that point.
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove return function(context, options) {
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove if (!compiled) {
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove compiled = compile();
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove }
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove return compiled.call(this, context, options);
abdaa6ad2027c0c8fe48867813c314c400a83e3dRyan Grove };
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove};
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove
c5eeeb5cc5fdca25f16cb4f2fd3e59dd0f937debRyan Grove// END(BROWSER)