barber-emblem 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ var exports = this.exports || {};
2
+
3
+ var Emblem;
4
+ var self = this;
5
+
6
+ var Barber = {
7
+ precompile: function(string) {
8
+ Emblem = self.Emblem;
9
+ var handlebarsVariant = exports.emberHandlebars || Handlebars;
10
+
11
+ return Emblem.precompile(handlebarsVariant, string).toString();
12
+ }
13
+ };
@@ -0,0 +1,2178 @@
1
+ /*
2
+
3
+ Copyright (C) 2011 by Yehuda Katz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
23
+ */
24
+
25
+ // lib/handlebars/base.js
26
+
27
+ /*jshint eqnull:true*/
28
+ this.Handlebars = {};
29
+
30
+ (function(Handlebars) {
31
+
32
+ Handlebars.VERSION = "1.0.rc.2";
33
+
34
+ Handlebars.helpers = {};
35
+ Handlebars.partials = {};
36
+
37
+ Handlebars.registerHelper = function(name, fn, inverse) {
38
+ if(inverse) { fn.not = inverse; }
39
+ this.helpers[name] = fn;
40
+ };
41
+
42
+ Handlebars.registerPartial = function(name, str) {
43
+ this.partials[name] = str;
44
+ };
45
+
46
+ Handlebars.registerHelper('helperMissing', function(arg) {
47
+ if(arguments.length === 2) {
48
+ return undefined;
49
+ } else {
50
+ throw new Error("Could not find property '" + arg + "'");
51
+ }
52
+ });
53
+
54
+ var toString = Object.prototype.toString, functionType = "[object Function]";
55
+
56
+ Handlebars.registerHelper('blockHelperMissing', function(context, options) {
57
+ var inverse = options.inverse || function() {}, fn = options.fn;
58
+
59
+
60
+ var ret = "";
61
+ var type = toString.call(context);
62
+
63
+ if(type === functionType) { context = context.call(this); }
64
+
65
+ if(context === true) {
66
+ return fn(this);
67
+ } else if(context === false || context == null) {
68
+ return inverse(this);
69
+ } else if(type === "[object Array]") {
70
+ if(context.length > 0) {
71
+ return Handlebars.helpers.each(context, options);
72
+ } else {
73
+ return inverse(this);
74
+ }
75
+ } else {
76
+ return fn(context);
77
+ }
78
+ });
79
+
80
+ Handlebars.K = function() {};
81
+
82
+ Handlebars.createFrame = Object.create || function(object) {
83
+ Handlebars.K.prototype = object;
84
+ var obj = new Handlebars.K();
85
+ Handlebars.K.prototype = null;
86
+ return obj;
87
+ };
88
+
89
+ Handlebars.logger = {
90
+ DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
91
+
92
+ methodMap: {0: 'debug', 1: 'info', 2: 'warn', 3: 'error'},
93
+
94
+ // can be overridden in the host environment
95
+ log: function(level, obj) {
96
+ if (Handlebars.logger.level <= level) {
97
+ var method = Handlebars.logger.methodMap[level];
98
+ if (typeof console !== 'undefined' && console[method]) {
99
+ console[method].call(console, obj);
100
+ }
101
+ }
102
+ }
103
+ };
104
+
105
+ Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
106
+
107
+ Handlebars.registerHelper('each', function(context, options) {
108
+ var fn = options.fn, inverse = options.inverse;
109
+ var i = 0, ret = "", data;
110
+
111
+ if (options.data) {
112
+ data = Handlebars.createFrame(options.data);
113
+ }
114
+
115
+ if(context && typeof context === 'object') {
116
+ if(context instanceof Array){
117
+ for(var j = context.length; i<j; i++) {
118
+ if (data) { data.index = i; }
119
+ ret = ret + fn(context[i], { data: data });
120
+ }
121
+ } else {
122
+ for(var key in context) {
123
+ if(context.hasOwnProperty(key)) {
124
+ if(data) { data.key = key; }
125
+ ret = ret + fn(context[key], {data: data});
126
+ i++;
127
+ }
128
+ }
129
+ }
130
+ }
131
+
132
+ if(i === 0){
133
+ ret = inverse(this);
134
+ }
135
+
136
+ return ret;
137
+ });
138
+
139
+ Handlebars.registerHelper('if', function(context, options) {
140
+ var type = toString.call(context);
141
+ if(type === functionType) { context = context.call(this); }
142
+
143
+ if(!context || Handlebars.Utils.isEmpty(context)) {
144
+ return options.inverse(this);
145
+ } else {
146
+ return options.fn(this);
147
+ }
148
+ });
149
+
150
+ Handlebars.registerHelper('unless', function(context, options) {
151
+ var fn = options.fn, inverse = options.inverse;
152
+ options.fn = inverse;
153
+ options.inverse = fn;
154
+
155
+ return Handlebars.helpers['if'].call(this, context, options);
156
+ });
157
+
158
+ Handlebars.registerHelper('with', function(context, options) {
159
+ return options.fn(context);
160
+ });
161
+
162
+ Handlebars.registerHelper('log', function(context, options) {
163
+ var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
164
+ Handlebars.log(level, context);
165
+ });
166
+
167
+ }(this.Handlebars));
168
+ ;
169
+ // lib/handlebars/compiler/parser.js
170
+ /* Jison generated parser */
171
+ var handlebars = (function(){
172
+ var parser = {trace: function trace() { },
173
+ yy: {},
174
+ symbols_: {"error":2,"root":3,"program":4,"EOF":5,"simpleInverse":6,"statements":7,"statement":8,"openInverse":9,"closeBlock":10,"openBlock":11,"mustache":12,"partial":13,"CONTENT":14,"COMMENT":15,"OPEN_BLOCK":16,"inMustache":17,"CLOSE":18,"OPEN_INVERSE":19,"OPEN_ENDBLOCK":20,"path":21,"OPEN":22,"OPEN_UNESCAPED":23,"OPEN_PARTIAL":24,"partialName":25,"params":26,"hash":27,"DATA":28,"param":29,"STRING":30,"INTEGER":31,"BOOLEAN":32,"hashSegments":33,"hashSegment":34,"ID":35,"EQUALS":36,"PARTIAL_NAME":37,"pathSegments":38,"SEP":39,"$accept":0,"$end":1},
175
+ terminals_: {2:"error",5:"EOF",14:"CONTENT",15:"COMMENT",16:"OPEN_BLOCK",18:"CLOSE",19:"OPEN_INVERSE",20:"OPEN_ENDBLOCK",22:"OPEN",23:"OPEN_UNESCAPED",24:"OPEN_PARTIAL",28:"DATA",30:"STRING",31:"INTEGER",32:"BOOLEAN",35:"ID",36:"EQUALS",37:"PARTIAL_NAME",39:"SEP"},
176
+ productions_: [0,[3,2],[4,2],[4,3],[4,2],[4,1],[4,1],[4,0],[7,1],[7,2],[8,3],[8,3],[8,1],[8,1],[8,1],[8,1],[11,3],[9,3],[10,3],[12,3],[12,3],[13,3],[13,4],[6,2],[17,3],[17,2],[17,2],[17,1],[17,1],[26,2],[26,1],[29,1],[29,1],[29,1],[29,1],[29,1],[27,1],[33,2],[33,1],[34,3],[34,3],[34,3],[34,3],[34,3],[25,1],[21,1],[38,3],[38,1]],
177
+ performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
178
+
179
+ var $0 = $$.length - 1;
180
+ switch (yystate) {
181
+ case 1: return $$[$0-1];
182
+ break;
183
+ case 2: this.$ = new yy.ProgramNode([], $$[$0]);
184
+ break;
185
+ case 3: this.$ = new yy.ProgramNode($$[$0-2], $$[$0]);
186
+ break;
187
+ case 4: this.$ = new yy.ProgramNode($$[$0-1], []);
188
+ break;
189
+ case 5: this.$ = new yy.ProgramNode($$[$0]);
190
+ break;
191
+ case 6: this.$ = new yy.ProgramNode([], []);
192
+ break;
193
+ case 7: this.$ = new yy.ProgramNode([]);
194
+ break;
195
+ case 8: this.$ = [$$[$0]];
196
+ break;
197
+ case 9: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
198
+ break;
199
+ case 10: this.$ = new yy.BlockNode($$[$0-2], $$[$0-1].inverse, $$[$0-1], $$[$0]);
200
+ break;
201
+ case 11: this.$ = new yy.BlockNode($$[$0-2], $$[$0-1], $$[$0-1].inverse, $$[$0]);
202
+ break;
203
+ case 12: this.$ = $$[$0];
204
+ break;
205
+ case 13: this.$ = $$[$0];
206
+ break;
207
+ case 14: this.$ = new yy.ContentNode($$[$0]);
208
+ break;
209
+ case 15: this.$ = new yy.CommentNode($$[$0]);
210
+ break;
211
+ case 16: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
212
+ break;
213
+ case 17: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
214
+ break;
215
+ case 18: this.$ = $$[$0-1];
216
+ break;
217
+ case 19: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1]);
218
+ break;
219
+ case 20: this.$ = new yy.MustacheNode($$[$0-1][0], $$[$0-1][1], true);
220
+ break;
221
+ case 21: this.$ = new yy.PartialNode($$[$0-1]);
222
+ break;
223
+ case 22: this.$ = new yy.PartialNode($$[$0-2], $$[$0-1]);
224
+ break;
225
+ case 23:
226
+ break;
227
+ case 24: this.$ = [[$$[$0-2]].concat($$[$0-1]), $$[$0]];
228
+ break;
229
+ case 25: this.$ = [[$$[$0-1]].concat($$[$0]), null];
230
+ break;
231
+ case 26: this.$ = [[$$[$0-1]], $$[$0]];
232
+ break;
233
+ case 27: this.$ = [[$$[$0]], null];
234
+ break;
235
+ case 28: this.$ = [[new yy.DataNode($$[$0])], null];
236
+ break;
237
+ case 29: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
238
+ break;
239
+ case 30: this.$ = [$$[$0]];
240
+ break;
241
+ case 31: this.$ = $$[$0];
242
+ break;
243
+ case 32: this.$ = new yy.StringNode($$[$0]);
244
+ break;
245
+ case 33: this.$ = new yy.IntegerNode($$[$0]);
246
+ break;
247
+ case 34: this.$ = new yy.BooleanNode($$[$0]);
248
+ break;
249
+ case 35: this.$ = new yy.DataNode($$[$0]);
250
+ break;
251
+ case 36: this.$ = new yy.HashNode($$[$0]);
252
+ break;
253
+ case 37: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
254
+ break;
255
+ case 38: this.$ = [$$[$0]];
256
+ break;
257
+ case 39: this.$ = [$$[$0-2], $$[$0]];
258
+ break;
259
+ case 40: this.$ = [$$[$0-2], new yy.StringNode($$[$0])];
260
+ break;
261
+ case 41: this.$ = [$$[$0-2], new yy.IntegerNode($$[$0])];
262
+ break;
263
+ case 42: this.$ = [$$[$0-2], new yy.BooleanNode($$[$0])];
264
+ break;
265
+ case 43: this.$ = [$$[$0-2], new yy.DataNode($$[$0])];
266
+ break;
267
+ case 44: this.$ = new yy.PartialNameNode($$[$0]);
268
+ break;
269
+ case 45: this.$ = new yy.IdNode($$[$0]);
270
+ break;
271
+ case 46: $$[$0-2].push($$[$0]); this.$ = $$[$0-2];
272
+ break;
273
+ case 47: this.$ = [$$[$0]];
274
+ break;
275
+ }
276
+ },
277
+ table: [{3:1,4:2,5:[2,7],6:3,7:4,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,5],22:[1,14],23:[1,15],24:[1,16]},{1:[3]},{5:[1,17]},{5:[2,6],7:18,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,19],20:[2,6],22:[1,14],23:[1,15],24:[1,16]},{5:[2,5],6:20,8:21,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,5],20:[2,5],22:[1,14],23:[1,15],24:[1,16]},{17:23,18:[1,22],21:24,28:[1,25],35:[1,27],38:26},{5:[2,8],14:[2,8],15:[2,8],16:[2,8],19:[2,8],20:[2,8],22:[2,8],23:[2,8],24:[2,8]},{4:28,6:3,7:4,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,5],20:[2,7],22:[1,14],23:[1,15],24:[1,16]},{4:29,6:3,7:4,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,5],20:[2,7],22:[1,14],23:[1,15],24:[1,16]},{5:[2,12],14:[2,12],15:[2,12],16:[2,12],19:[2,12],20:[2,12],22:[2,12],23:[2,12],24:[2,12]},{5:[2,13],14:[2,13],15:[2,13],16:[2,13],19:[2,13],20:[2,13],22:[2,13],23:[2,13],24:[2,13]},{5:[2,14],14:[2,14],15:[2,14],16:[2,14],19:[2,14],20:[2,14],22:[2,14],23:[2,14],24:[2,14]},{5:[2,15],14:[2,15],15:[2,15],16:[2,15],19:[2,15],20:[2,15],22:[2,15],23:[2,15],24:[2,15]},{17:30,21:24,28:[1,25],35:[1,27],38:26},{17:31,21:24,28:[1,25],35:[1,27],38:26},{17:32,21:24,28:[1,25],35:[1,27],38:26},{25:33,37:[1,34]},{1:[2,1]},{5:[2,2],8:21,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,19],20:[2,2],22:[1,14],23:[1,15],24:[1,16]},{17:23,21:24,28:[1,25],35:[1,27],38:26},{5:[2,4],7:35,8:6,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,19],20:[2,4],22:[1,14],23:[1,15],24:[1,16]},{5:[2,9],14:[2,9],15:[2,9],16:[2,9],19:[2,9],20:[2,9],22:[2,9],23:[2,9],24:[2,9]},{5:[2,23],14:[2,23],15:[2,23],16:[2,23],19:[2,23],20:[2,23],22:[2,23],23:[2,23],24:[2,23]},{18:[1,36]},{18:[2,27],21:41,26:37,27:38,28:[1,45],29:39,30:[1,42],31:[1,43],32:[1,44],33:40,34:46,35:[1,47],38:26},{18:[2,28]},{18:[2,45],28:[2,45],30:[2,45],31:[2,45],32:[2,45],35:[2,45],39:[1,48]},{18:[2,47],28:[2,47],30:[2,47],31:[2,47],32:[2,47],35:[2,47],39:[2,47]},{10:49,20:[1,50]},{10:51,20:[1,50]},{18:[1,52]},{18:[1,53]},{18:[1,54]},{18:[1,55],21:56,35:[1,27],38:26},{18:[2,44],35:[2,44]},{5:[2,3],8:21,9:7,11:8,12:9,13:10,14:[1,11],15:[1,12],16:[1,13],19:[1,19],20:[2,3],22:[1,14],23:[1,15],24:[1,16]},{14:[2,17],15:[2,17],16:[2,17],19:[2,17],20:[2,17],22:[2,17],23:[2,17],24:[2,17]},{18:[2,25],21:41,27:57,28:[1,45],29:58,30:[1,42],31:[1,43],32:[1,44],33:40,34:46,35:[1,47],38:26},{18:[2,26]},{18:[2,30],28:[2,30],30:[2,30],31:[2,30],32:[2,30],35:[2,30]},{18:[2,36],34:59,35:[1,60]},{18:[2,31],28:[2,31],30:[2,31],31:[2,31],32:[2,31],35:[2,31]},{18:[2,32],28:[2,32],30:[2,32],31:[2,32],32:[2,32],35:[2,32]},{18:[2,33],28:[2,33],30:[2,33],31:[2,33],32:[2,33],35:[2,33]},{18:[2,34],28:[2,34],30:[2,34],31:[2,34],32:[2,34],35:[2,34]},{18:[2,35],28:[2,35],30:[2,35],31:[2,35],32:[2,35],35:[2,35]},{18:[2,38],35:[2,38]},{18:[2,47],28:[2,47],30:[2,47],31:[2,47],32:[2,47],35:[2,47],36:[1,61],39:[2,47]},{35:[1,62]},{5:[2,10],14:[2,10],15:[2,10],16:[2,10],19:[2,10],20:[2,10],22:[2,10],23:[2,10],24:[2,10]},{21:63,35:[1,27],38:26},{5:[2,11],14:[2,11],15:[2,11],16:[2,11],19:[2,11],20:[2,11],22:[2,11],23:[2,11],24:[2,11]},{14:[2,16],15:[2,16],16:[2,16],19:[2,16],20:[2,16],22:[2,16],23:[2,16],24:[2,16]},{5:[2,19],14:[2,19],15:[2,19],16:[2,19],19:[2,19],20:[2,19],22:[2,19],23:[2,19],24:[2,19]},{5:[2,20],14:[2,20],15:[2,20],16:[2,20],19:[2,20],20:[2,20],22:[2,20],23:[2,20],24:[2,20]},{5:[2,21],14:[2,21],15:[2,21],16:[2,21],19:[2,21],20:[2,21],22:[2,21],23:[2,21],24:[2,21]},{18:[1,64]},{18:[2,24]},{18:[2,29],28:[2,29],30:[2,29],31:[2,29],32:[2,29],35:[2,29]},{18:[2,37],35:[2,37]},{36:[1,61]},{21:65,28:[1,69],30:[1,66],31:[1,67],32:[1,68],35:[1,27],38:26},{18:[2,46],28:[2,46],30:[2,46],31:[2,46],32:[2,46],35:[2,46],39:[2,46]},{18:[1,70]},{5:[2,22],14:[2,22],15:[2,22],16:[2,22],19:[2,22],20:[2,22],22:[2,22],23:[2,22],24:[2,22]},{18:[2,39],35:[2,39]},{18:[2,40],35:[2,40]},{18:[2,41],35:[2,41]},{18:[2,42],35:[2,42]},{18:[2,43],35:[2,43]},{5:[2,18],14:[2,18],15:[2,18],16:[2,18],19:[2,18],20:[2,18],22:[2,18],23:[2,18],24:[2,18]}],
278
+ defaultActions: {17:[2,1],25:[2,28],38:[2,26],57:[2,24]},
279
+ parseError: function parseError(str, hash) {
280
+ throw new Error(str);
281
+ },
282
+ parse: function parse(input) {
283
+ var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
284
+ this.lexer.setInput(input);
285
+ this.lexer.yy = this.yy;
286
+ this.yy.lexer = this.lexer;
287
+ this.yy.parser = this;
288
+ if (typeof this.lexer.yylloc == "undefined")
289
+ this.lexer.yylloc = {};
290
+ var yyloc = this.lexer.yylloc;
291
+ lstack.push(yyloc);
292
+ var ranges = this.lexer.options && this.lexer.options.ranges;
293
+ if (typeof this.yy.parseError === "function")
294
+ this.parseError = this.yy.parseError;
295
+ function popStack(n) {
296
+ stack.length = stack.length - 2 * n;
297
+ vstack.length = vstack.length - n;
298
+ lstack.length = lstack.length - n;
299
+ }
300
+ function lex() {
301
+ var token;
302
+ token = self.lexer.lex() || 1;
303
+ if (typeof token !== "number") {
304
+ token = self.symbols_[token] || token;
305
+ }
306
+ return token;
307
+ }
308
+ var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
309
+ while (true) {
310
+ state = stack[stack.length - 1];
311
+ if (this.defaultActions[state]) {
312
+ action = this.defaultActions[state];
313
+ } else {
314
+ if (symbol === null || typeof symbol == "undefined") {
315
+ symbol = lex();
316
+ }
317
+ action = table[state] && table[state][symbol];
318
+ }
319
+ if (typeof action === "undefined" || !action.length || !action[0]) {
320
+ var errStr = "";
321
+ if (!recovering) {
322
+ expected = [];
323
+ for (p in table[state])
324
+ if (this.terminals_[p] && p > 2) {
325
+ expected.push("'" + this.terminals_[p] + "'");
326
+ }
327
+ if (this.lexer.showPosition) {
328
+ errStr = "Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'";
329
+ } else {
330
+ errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1?"end of input":"'" + (this.terminals_[symbol] || symbol) + "'");
331
+ }
332
+ this.parseError(errStr, {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected});
333
+ }
334
+ }
335
+ if (action[0] instanceof Array && action.length > 1) {
336
+ throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
337
+ }
338
+ switch (action[0]) {
339
+ case 1:
340
+ stack.push(symbol);
341
+ vstack.push(this.lexer.yytext);
342
+ lstack.push(this.lexer.yylloc);
343
+ stack.push(action[1]);
344
+ symbol = null;
345
+ if (!preErrorSymbol) {
346
+ yyleng = this.lexer.yyleng;
347
+ yytext = this.lexer.yytext;
348
+ yylineno = this.lexer.yylineno;
349
+ yyloc = this.lexer.yylloc;
350
+ if (recovering > 0)
351
+ recovering--;
352
+ } else {
353
+ symbol = preErrorSymbol;
354
+ preErrorSymbol = null;
355
+ }
356
+ break;
357
+ case 2:
358
+ len = this.productions_[action[1]][1];
359
+ yyval.$ = vstack[vstack.length - len];
360
+ yyval._$ = {first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column};
361
+ if (ranges) {
362
+ yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
363
+ }
364
+ r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
365
+ if (typeof r !== "undefined") {
366
+ return r;
367
+ }
368
+ if (len) {
369
+ stack = stack.slice(0, -1 * len * 2);
370
+ vstack = vstack.slice(0, -1 * len);
371
+ lstack = lstack.slice(0, -1 * len);
372
+ }
373
+ stack.push(this.productions_[action[1]][0]);
374
+ vstack.push(yyval.$);
375
+ lstack.push(yyval._$);
376
+ newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
377
+ stack.push(newState);
378
+ break;
379
+ case 3:
380
+ return true;
381
+ }
382
+ }
383
+ return true;
384
+ }
385
+ };
386
+ /* Jison generated lexer */
387
+ var lexer = (function(){
388
+ var lexer = ({EOF:1,
389
+ parseError:function parseError(str, hash) {
390
+ if (this.yy.parser) {
391
+ this.yy.parser.parseError(str, hash);
392
+ } else {
393
+ throw new Error(str);
394
+ }
395
+ },
396
+ setInput:function (input) {
397
+ this._input = input;
398
+ this._more = this._less = this.done = false;
399
+ this.yylineno = this.yyleng = 0;
400
+ this.yytext = this.matched = this.match = '';
401
+ this.conditionStack = ['INITIAL'];
402
+ this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0};
403
+ if (this.options.ranges) this.yylloc.range = [0,0];
404
+ this.offset = 0;
405
+ return this;
406
+ },
407
+ input:function () {
408
+ var ch = this._input[0];
409
+ this.yytext += ch;
410
+ this.yyleng++;
411
+ this.offset++;
412
+ this.match += ch;
413
+ this.matched += ch;
414
+ var lines = ch.match(/(?:\r\n?|\n).*/g);
415
+ if (lines) {
416
+ this.yylineno++;
417
+ this.yylloc.last_line++;
418
+ } else {
419
+ this.yylloc.last_column++;
420
+ }
421
+ if (this.options.ranges) this.yylloc.range[1]++;
422
+
423
+ this._input = this._input.slice(1);
424
+ return ch;
425
+ },
426
+ unput:function (ch) {
427
+ var len = ch.length;
428
+ var lines = ch.split(/(?:\r\n?|\n)/g);
429
+
430
+ this._input = ch + this._input;
431
+ this.yytext = this.yytext.substr(0, this.yytext.length-len-1);
432
+ //this.yyleng -= len;
433
+ this.offset -= len;
434
+ var oldLines = this.match.split(/(?:\r\n?|\n)/g);
435
+ this.match = this.match.substr(0, this.match.length-1);
436
+ this.matched = this.matched.substr(0, this.matched.length-1);
437
+
438
+ if (lines.length-1) this.yylineno -= lines.length-1;
439
+ var r = this.yylloc.range;
440
+
441
+ this.yylloc = {first_line: this.yylloc.first_line,
442
+ last_line: this.yylineno+1,
443
+ first_column: this.yylloc.first_column,
444
+ last_column: lines ?
445
+ (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length:
446
+ this.yylloc.first_column - len
447
+ };
448
+
449
+ if (this.options.ranges) {
450
+ this.yylloc.range = [r[0], r[0] + this.yyleng - len];
451
+ }
452
+ return this;
453
+ },
454
+ more:function () {
455
+ this._more = true;
456
+ return this;
457
+ },
458
+ less:function (n) {
459
+ this.unput(this.match.slice(n));
460
+ },
461
+ pastInput:function () {
462
+ var past = this.matched.substr(0, this.matched.length - this.match.length);
463
+ return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
464
+ },
465
+ upcomingInput:function () {
466
+ var next = this.match;
467
+ if (next.length < 20) {
468
+ next += this._input.substr(0, 20-next.length);
469
+ }
470
+ return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, "");
471
+ },
472
+ showPosition:function () {
473
+ var pre = this.pastInput();
474
+ var c = new Array(pre.length + 1).join("-");
475
+ return pre + this.upcomingInput() + "\n" + c+"^";
476
+ },
477
+ next:function () {
478
+ if (this.done) {
479
+ return this.EOF;
480
+ }
481
+ if (!this._input) this.done = true;
482
+
483
+ var token,
484
+ match,
485
+ tempMatch,
486
+ index,
487
+ col,
488
+ lines;
489
+ if (!this._more) {
490
+ this.yytext = '';
491
+ this.match = '';
492
+ }
493
+ var rules = this._currentRules();
494
+ for (var i=0;i < rules.length; i++) {
495
+ tempMatch = this._input.match(this.rules[rules[i]]);
496
+ if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
497
+ match = tempMatch;
498
+ index = i;
499
+ if (!this.options.flex) break;
500
+ }
501
+ }
502
+ if (match) {
503
+ lines = match[0].match(/(?:\r\n?|\n).*/g);
504
+ if (lines) this.yylineno += lines.length;
505
+ this.yylloc = {first_line: this.yylloc.last_line,
506
+ last_line: this.yylineno+1,
507
+ first_column: this.yylloc.last_column,
508
+ last_column: lines ? lines[lines.length-1].length-lines[lines.length-1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length};
509
+ this.yytext += match[0];
510
+ this.match += match[0];
511
+ this.matches = match;
512
+ this.yyleng = this.yytext.length;
513
+ if (this.options.ranges) {
514
+ this.yylloc.range = [this.offset, this.offset += this.yyleng];
515
+ }
516
+ this._more = false;
517
+ this._input = this._input.slice(match[0].length);
518
+ this.matched += match[0];
519
+ token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]);
520
+ if (this.done && this._input) this.done = false;
521
+ if (token) return token;
522
+ else return;
523
+ }
524
+ if (this._input === "") {
525
+ return this.EOF;
526
+ } else {
527
+ return this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(),
528
+ {text: "", token: null, line: this.yylineno});
529
+ }
530
+ },
531
+ lex:function lex() {
532
+ var r = this.next();
533
+ if (typeof r !== 'undefined') {
534
+ return r;
535
+ } else {
536
+ return this.lex();
537
+ }
538
+ },
539
+ begin:function begin(condition) {
540
+ this.conditionStack.push(condition);
541
+ },
542
+ popState:function popState() {
543
+ return this.conditionStack.pop();
544
+ },
545
+ _currentRules:function _currentRules() {
546
+ return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
547
+ },
548
+ topState:function () {
549
+ return this.conditionStack[this.conditionStack.length-2];
550
+ },
551
+ pushState:function begin(condition) {
552
+ this.begin(condition);
553
+ }});
554
+ lexer.options = {};
555
+ lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
556
+
557
+ var YYSTATE=YY_START;
558
+ switch($avoiding_name_collisions) {
559
+ case 0:
560
+ if(yy_.yytext.slice(-1) !== "\\") this.begin("mu");
561
+ if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1), this.begin("emu");
562
+ if(yy_.yytext) return 14;
563
+
564
+ break;
565
+ case 1: return 14;
566
+ break;
567
+ case 2:
568
+ if(yy_.yytext.slice(-1) !== "\\") this.popState();
569
+ if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1);
570
+ return 14;
571
+
572
+ break;
573
+ case 3: yy_.yytext = yy_.yytext.substr(0, yy_.yyleng-4); this.popState(); return 15;
574
+ break;
575
+ case 4: this.begin("par"); return 24;
576
+ break;
577
+ case 5: return 16;
578
+ break;
579
+ case 6: return 20;
580
+ break;
581
+ case 7: return 19;
582
+ break;
583
+ case 8: return 19;
584
+ break;
585
+ case 9: return 23;
586
+ break;
587
+ case 10: return 23;
588
+ break;
589
+ case 11: this.popState(); this.begin('com');
590
+ break;
591
+ case 12: yy_.yytext = yy_.yytext.substr(3,yy_.yyleng-5); this.popState(); return 15;
592
+ break;
593
+ case 13: return 22;
594
+ break;
595
+ case 14: return 36;
596
+ break;
597
+ case 15: return 35;
598
+ break;
599
+ case 16: return 35;
600
+ break;
601
+ case 17: return 39;
602
+ break;
603
+ case 18: /*ignore whitespace*/
604
+ break;
605
+ case 19: this.popState(); return 18;
606
+ break;
607
+ case 20: this.popState(); return 18;
608
+ break;
609
+ case 21: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 30;
610
+ break;
611
+ case 22: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\'/g,"'"); return 30;
612
+ break;
613
+ case 23: yy_.yytext = yy_.yytext.substr(1); return 28;
614
+ break;
615
+ case 24: return 32;
616
+ break;
617
+ case 25: return 32;
618
+ break;
619
+ case 26: return 31;
620
+ break;
621
+ case 27: return 35;
622
+ break;
623
+ case 28: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 35;
624
+ break;
625
+ case 29: return 'INVALID';
626
+ break;
627
+ case 30: /*ignore whitespace*/
628
+ break;
629
+ case 31: this.popState(); return 37;
630
+ break;
631
+ case 32: return 5;
632
+ break;
633
+ }
634
+ };
635
+ lexer.rules = [/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|$)))/,/^(?:[\s\S]*?--\}\})/,/^(?:\{\{>)/,/^(?:\{\{#)/,/^(?:\{\{\/)/,/^(?:\{\{\^)/,/^(?:\{\{\s*else\b)/,/^(?:\{\{\{)/,/^(?:\{\{&)/,/^(?:\{\{!--)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{)/,/^(?:=)/,/^(?:\.(?=[} ]))/,/^(?:\.\.)/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}\}\})/,/^(?:\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@[a-zA-Z]+)/,/^(?:true(?=[}\s]))/,/^(?:false(?=[}\s]))/,/^(?:[0-9]+(?=[}\s]))/,/^(?:[a-zA-Z0-9_$-]+(?=[=}\s\/.]))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:\s+)/,/^(?:[a-zA-Z0-9_$-/]+)/,/^(?:$)/];
636
+ lexer.conditions = {"mu":{"rules":[4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,32],"inclusive":false},"emu":{"rules":[2],"inclusive":false},"com":{"rules":[3],"inclusive":false},"par":{"rules":[30,31],"inclusive":false},"INITIAL":{"rules":[0,1,32],"inclusive":true}};
637
+ return lexer;})();
638
+ parser.lexer = lexer;
639
+ function Parser () { this.yy = {}; }Parser.prototype = parser;parser.Parser = Parser;
640
+ return new Parser;
641
+ })();;
642
+ // lib/handlebars/compiler/base.js
643
+ Handlebars.Parser = handlebars;
644
+
645
+ Handlebars.parse = function(input) {
646
+
647
+ // Just return if an already-compile AST was passed in.
648
+ if(input.constructor === Handlebars.AST.ProgramNode) { return input; }
649
+
650
+ Handlebars.Parser.yy = Handlebars.AST;
651
+ return Handlebars.Parser.parse(input);
652
+ };
653
+
654
+ Handlebars.print = function(ast) {
655
+ return new Handlebars.PrintVisitor().accept(ast);
656
+ };;
657
+ // lib/handlebars/compiler/ast.js
658
+ (function() {
659
+
660
+ Handlebars.AST = {};
661
+
662
+ Handlebars.AST.ProgramNode = function(statements, inverse) {
663
+ this.type = "program";
664
+ this.statements = statements;
665
+ if(inverse) { this.inverse = new Handlebars.AST.ProgramNode(inverse); }
666
+ };
667
+
668
+ Handlebars.AST.MustacheNode = function(rawParams, hash, unescaped) {
669
+ this.type = "mustache";
670
+ this.escaped = !unescaped;
671
+ this.hash = hash;
672
+
673
+ var id = this.id = rawParams[0];
674
+ var params = this.params = rawParams.slice(1);
675
+
676
+ // a mustache is an eligible helper if:
677
+ // * its id is simple (a single part, not `this` or `..`)
678
+ var eligibleHelper = this.eligibleHelper = id.isSimple;
679
+
680
+ // a mustache is definitely a helper if:
681
+ // * it is an eligible helper, and
682
+ // * it has at least one parameter or hash segment
683
+ this.isHelper = eligibleHelper && (params.length || hash);
684
+
685
+ // if a mustache is an eligible helper but not a definite
686
+ // helper, it is ambiguous, and will be resolved in a later
687
+ // pass or at runtime.
688
+ };
689
+
690
+ Handlebars.AST.PartialNode = function(partialName, context) {
691
+ this.type = "partial";
692
+ this.partialName = partialName;
693
+ this.context = context;
694
+ };
695
+
696
+ var verifyMatch = function(open, close) {
697
+ if(open.original !== close.original) {
698
+ throw new Handlebars.Exception(open.original + " doesn't match " + close.original);
699
+ }
700
+ };
701
+
702
+ Handlebars.AST.BlockNode = function(mustache, program, inverse, close) {
703
+ verifyMatch(mustache.id, close);
704
+ this.type = "block";
705
+ this.mustache = mustache;
706
+ this.program = program;
707
+ this.inverse = inverse;
708
+
709
+ if (this.inverse && !this.program) {
710
+ this.isInverse = true;
711
+ }
712
+ };
713
+
714
+ Handlebars.AST.ContentNode = function(string) {
715
+ this.type = "content";
716
+ this.string = string;
717
+ };
718
+
719
+ Handlebars.AST.HashNode = function(pairs) {
720
+ this.type = "hash";
721
+ this.pairs = pairs;
722
+ };
723
+
724
+ Handlebars.AST.IdNode = function(parts) {
725
+ this.type = "ID";
726
+ this.original = parts.join(".");
727
+
728
+ var dig = [], depth = 0;
729
+
730
+ for(var i=0,l=parts.length; i<l; i++) {
731
+ var part = parts[i];
732
+
733
+ if (part === ".." || part === "." || part === "this") {
734
+ if (dig.length > 0) { throw new Handlebars.Exception("Invalid path: " + this.original); }
735
+ else if (part === "..") { depth++; }
736
+ else { this.isScoped = true; }
737
+ }
738
+ else { dig.push(part); }
739
+ }
740
+
741
+ this.parts = dig;
742
+ this.string = dig.join('.');
743
+ this.depth = depth;
744
+
745
+ // an ID is simple if it only has one part, and that part is not
746
+ // `..` or `this`.
747
+ this.isSimple = parts.length === 1 && !this.isScoped && depth === 0;
748
+
749
+ this.stringModeValue = this.string;
750
+ };
751
+
752
+ Handlebars.AST.PartialNameNode = function(name) {
753
+ this.type = "PARTIAL_NAME";
754
+ this.name = name;
755
+ };
756
+
757
+ Handlebars.AST.DataNode = function(id) {
758
+ this.type = "DATA";
759
+ this.id = id;
760
+ };
761
+
762
+ Handlebars.AST.StringNode = function(string) {
763
+ this.type = "STRING";
764
+ this.string = string;
765
+ this.stringModeValue = string;
766
+ };
767
+
768
+ Handlebars.AST.IntegerNode = function(integer) {
769
+ this.type = "INTEGER";
770
+ this.integer = integer;
771
+ this.stringModeValue = Number(integer);
772
+ };
773
+
774
+ Handlebars.AST.BooleanNode = function(bool) {
775
+ this.type = "BOOLEAN";
776
+ this.bool = bool;
777
+ this.stringModeValue = bool === "true";
778
+ };
779
+
780
+ Handlebars.AST.CommentNode = function(comment) {
781
+ this.type = "comment";
782
+ this.comment = comment;
783
+ };
784
+
785
+ })();;
786
+ // lib/handlebars/utils.js
787
+
788
+ var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
789
+
790
+ Handlebars.Exception = function(message) {
791
+ var tmp = Error.prototype.constructor.apply(this, arguments);
792
+
793
+ // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
794
+ for (var idx = 0; idx < errorProps.length; idx++) {
795
+ this[errorProps[idx]] = tmp[errorProps[idx]];
796
+ }
797
+ };
798
+ Handlebars.Exception.prototype = new Error();
799
+
800
+ // Build out our basic SafeString type
801
+ Handlebars.SafeString = function(string) {
802
+ this.string = string;
803
+ };
804
+ Handlebars.SafeString.prototype.toString = function() {
805
+ return this.string.toString();
806
+ };
807
+
808
+ (function() {
809
+ var escape = {
810
+ "&": "&amp;",
811
+ "<": "&lt;",
812
+ ">": "&gt;",
813
+ '"': "&quot;",
814
+ "'": "&#x27;",
815
+ "`": "&#x60;"
816
+ };
817
+
818
+ var badChars = /[&<>"'`]/g;
819
+ var possible = /[&<>"'`]/;
820
+
821
+ var escapeChar = function(chr) {
822
+ return escape[chr] || "&amp;";
823
+ };
824
+
825
+ Handlebars.Utils = {
826
+ escapeExpression: function(string) {
827
+ // don't escape SafeStrings, since they're already safe
828
+ if (string instanceof Handlebars.SafeString) {
829
+ return string.toString();
830
+ } else if (string == null || string === false) {
831
+ return "";
832
+ }
833
+
834
+ if(!possible.test(string)) { return string; }
835
+ return string.replace(badChars, escapeChar);
836
+ },
837
+
838
+ isEmpty: function(value) {
839
+ if (!value && value !== 0) {
840
+ return true;
841
+ } else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
842
+ return true;
843
+ } else {
844
+ return false;
845
+ }
846
+ }
847
+ };
848
+ })();;
849
+ // lib/handlebars/compiler/compiler.js
850
+
851
+ /*jshint eqnull:true*/
852
+ Handlebars.Compiler = function() {};
853
+ Handlebars.JavaScriptCompiler = function() {};
854
+
855
+ (function(Compiler, JavaScriptCompiler) {
856
+ // the foundHelper register will disambiguate helper lookup from finding a
857
+ // function in a context. This is necessary for mustache compatibility, which
858
+ // requires that context functions in blocks are evaluated by blockHelperMissing,
859
+ // and then proceed as if the resulting value was provided to blockHelperMissing.
860
+
861
+ Compiler.prototype = {
862
+ compiler: Compiler,
863
+
864
+ disassemble: function() {
865
+ var opcodes = this.opcodes, opcode, out = [], params, param;
866
+
867
+ for (var i=0, l=opcodes.length; i<l; i++) {
868
+ opcode = opcodes[i];
869
+
870
+ if (opcode.opcode === 'DECLARE') {
871
+ out.push("DECLARE " + opcode.name + "=" + opcode.value);
872
+ } else {
873
+ params = [];
874
+ for (var j=0; j<opcode.args.length; j++) {
875
+ param = opcode.args[j];
876
+ if (typeof param === "string") {
877
+ param = "\"" + param.replace("\n", "\\n") + "\"";
878
+ }
879
+ params.push(param);
880
+ }
881
+ out.push(opcode.opcode + " " + params.join(" "));
882
+ }
883
+ }
884
+
885
+ return out.join("\n");
886
+ },
887
+ equals: function(other) {
888
+ var len = this.opcodes.length;
889
+ if (other.opcodes.length !== len) {
890
+ return false;
891
+ }
892
+
893
+ for (var i = 0; i < len; i++) {
894
+ var opcode = this.opcodes[i],
895
+ otherOpcode = other.opcodes[i];
896
+ if (opcode.opcode !== otherOpcode.opcode || opcode.args.length !== otherOpcode.args.length) {
897
+ return false;
898
+ }
899
+ for (var j = 0; j < opcode.args.length; j++) {
900
+ if (opcode.args[j] !== otherOpcode.args[j]) {
901
+ return false;
902
+ }
903
+ }
904
+ }
905
+ return true;
906
+ },
907
+
908
+ guid: 0,
909
+
910
+ compile: function(program, options) {
911
+ this.children = [];
912
+ this.depths = {list: []};
913
+ this.options = options;
914
+
915
+ // These changes will propagate to the other compiler components
916
+ var knownHelpers = this.options.knownHelpers;
917
+ this.options.knownHelpers = {
918
+ 'helperMissing': true,
919
+ 'blockHelperMissing': true,
920
+ 'each': true,
921
+ 'if': true,
922
+ 'unless': true,
923
+ 'with': true,
924
+ 'log': true
925
+ };
926
+ if (knownHelpers) {
927
+ for (var name in knownHelpers) {
928
+ this.options.knownHelpers[name] = knownHelpers[name];
929
+ }
930
+ }
931
+
932
+ return this.program(program);
933
+ },
934
+
935
+ accept: function(node) {
936
+ return this[node.type](node);
937
+ },
938
+
939
+ program: function(program) {
940
+ var statements = program.statements, statement;
941
+ this.opcodes = [];
942
+
943
+ for(var i=0, l=statements.length; i<l; i++) {
944
+ statement = statements[i];
945
+ this[statement.type](statement);
946
+ }
947
+ this.isSimple = l === 1;
948
+
949
+ this.depths.list = this.depths.list.sort(function(a, b) {
950
+ return a - b;
951
+ });
952
+
953
+ return this;
954
+ },
955
+
956
+ compileProgram: function(program) {
957
+ var result = new this.compiler().compile(program, this.options);
958
+ var guid = this.guid++, depth;
959
+
960
+ this.usePartial = this.usePartial || result.usePartial;
961
+
962
+ this.children[guid] = result;
963
+
964
+ for(var i=0, l=result.depths.list.length; i<l; i++) {
965
+ depth = result.depths.list[i];
966
+
967
+ if(depth < 2) { continue; }
968
+ else { this.addDepth(depth - 1); }
969
+ }
970
+
971
+ return guid;
972
+ },
973
+
974
+ block: function(block) {
975
+ var mustache = block.mustache,
976
+ program = block.program,
977
+ inverse = block.inverse;
978
+
979
+ if (program) {
980
+ program = this.compileProgram(program);
981
+ }
982
+
983
+ if (inverse) {
984
+ inverse = this.compileProgram(inverse);
985
+ }
986
+
987
+ var type = this.classifyMustache(mustache);
988
+
989
+ if (type === "helper") {
990
+ this.helperMustache(mustache, program, inverse);
991
+ } else if (type === "simple") {
992
+ this.simpleMustache(mustache);
993
+
994
+ // now that the simple mustache is resolved, we need to
995
+ // evaluate it by executing `blockHelperMissing`
996
+ this.opcode('pushProgram', program);
997
+ this.opcode('pushProgram', inverse);
998
+ this.opcode('emptyHash');
999
+ this.opcode('blockValue');
1000
+ } else {
1001
+ this.ambiguousMustache(mustache, program, inverse);
1002
+
1003
+ // now that the simple mustache is resolved, we need to
1004
+ // evaluate it by executing `blockHelperMissing`
1005
+ this.opcode('pushProgram', program);
1006
+ this.opcode('pushProgram', inverse);
1007
+ this.opcode('emptyHash');
1008
+ this.opcode('ambiguousBlockValue');
1009
+ }
1010
+
1011
+ this.opcode('append');
1012
+ },
1013
+
1014
+ hash: function(hash) {
1015
+ var pairs = hash.pairs, pair, val;
1016
+
1017
+ this.opcode('pushHash');
1018
+
1019
+ for(var i=0, l=pairs.length; i<l; i++) {
1020
+ pair = pairs[i];
1021
+ val = pair[1];
1022
+
1023
+ if (this.options.stringParams) {
1024
+ this.opcode('pushStringParam', val.stringModeValue, val.type);
1025
+ } else {
1026
+ this.accept(val);
1027
+ }
1028
+
1029
+ this.opcode('assignToHash', pair[0]);
1030
+ }
1031
+ this.opcode('popHash');
1032
+ },
1033
+
1034
+ partial: function(partial) {
1035
+ var partialName = partial.partialName;
1036
+ this.usePartial = true;
1037
+
1038
+ if(partial.context) {
1039
+ this.ID(partial.context);
1040
+ } else {
1041
+ this.opcode('push', 'depth0');
1042
+ }
1043
+
1044
+ this.opcode('invokePartial', partialName.name);
1045
+ this.opcode('append');
1046
+ },
1047
+
1048
+ content: function(content) {
1049
+ this.opcode('appendContent', content.string);
1050
+ },
1051
+
1052
+ mustache: function(mustache) {
1053
+ var options = this.options;
1054
+ var type = this.classifyMustache(mustache);
1055
+
1056
+ if (type === "simple") {
1057
+ this.simpleMustache(mustache);
1058
+ } else if (type === "helper") {
1059
+ this.helperMustache(mustache);
1060
+ } else {
1061
+ this.ambiguousMustache(mustache);
1062
+ }
1063
+
1064
+ if(mustache.escaped && !options.noEscape) {
1065
+ this.opcode('appendEscaped');
1066
+ } else {
1067
+ this.opcode('append');
1068
+ }
1069
+ },
1070
+
1071
+ ambiguousMustache: function(mustache, program, inverse) {
1072
+ var id = mustache.id,
1073
+ name = id.parts[0],
1074
+ isBlock = program != null || inverse != null;
1075
+
1076
+ this.opcode('getContext', id.depth);
1077
+
1078
+ this.opcode('pushProgram', program);
1079
+ this.opcode('pushProgram', inverse);
1080
+
1081
+ this.opcode('invokeAmbiguous', name, isBlock);
1082
+ },
1083
+
1084
+ simpleMustache: function(mustache) {
1085
+ var id = mustache.id;
1086
+
1087
+ if (id.type === 'DATA') {
1088
+ this.DATA(id);
1089
+ } else if (id.parts.length) {
1090
+ this.ID(id);
1091
+ } else {
1092
+ // Simplified ID for `this`
1093
+ this.addDepth(id.depth);
1094
+ this.opcode('getContext', id.depth);
1095
+ this.opcode('pushContext');
1096
+ }
1097
+
1098
+ this.opcode('resolvePossibleLambda');
1099
+ },
1100
+
1101
+ helperMustache: function(mustache, program, inverse) {
1102
+ var params = this.setupFullMustacheParams(mustache, program, inverse),
1103
+ name = mustache.id.parts[0];
1104
+
1105
+ if (this.options.knownHelpers[name]) {
1106
+ this.opcode('invokeKnownHelper', params.length, name);
1107
+ } else if (this.knownHelpersOnly) {
1108
+ throw new Error("You specified knownHelpersOnly, but used the unknown helper " + name);
1109
+ } else {
1110
+ this.opcode('invokeHelper', params.length, name);
1111
+ }
1112
+ },
1113
+
1114
+ ID: function(id) {
1115
+ this.addDepth(id.depth);
1116
+ this.opcode('getContext', id.depth);
1117
+
1118
+ var name = id.parts[0];
1119
+ if (!name) {
1120
+ this.opcode('pushContext');
1121
+ } else {
1122
+ this.opcode('lookupOnContext', id.parts[0]);
1123
+ }
1124
+
1125
+ for(var i=1, l=id.parts.length; i<l; i++) {
1126
+ this.opcode('lookup', id.parts[i]);
1127
+ }
1128
+ },
1129
+
1130
+ DATA: function(data) {
1131
+ this.options.data = true;
1132
+ this.opcode('lookupData', data.id);
1133
+ },
1134
+
1135
+ STRING: function(string) {
1136
+ this.opcode('pushString', string.string);
1137
+ },
1138
+
1139
+ INTEGER: function(integer) {
1140
+ this.opcode('pushLiteral', integer.integer);
1141
+ },
1142
+
1143
+ BOOLEAN: function(bool) {
1144
+ this.opcode('pushLiteral', bool.bool);
1145
+ },
1146
+
1147
+ comment: function() {},
1148
+
1149
+ // HELPERS
1150
+ opcode: function(name) {
1151
+ this.opcodes.push({ opcode: name, args: [].slice.call(arguments, 1) });
1152
+ },
1153
+
1154
+ declare: function(name, value) {
1155
+ this.opcodes.push({ opcode: 'DECLARE', name: name, value: value });
1156
+ },
1157
+
1158
+ addDepth: function(depth) {
1159
+ if(isNaN(depth)) { throw new Error("EWOT"); }
1160
+ if(depth === 0) { return; }
1161
+
1162
+ if(!this.depths[depth]) {
1163
+ this.depths[depth] = true;
1164
+ this.depths.list.push(depth);
1165
+ }
1166
+ },
1167
+
1168
+ classifyMustache: function(mustache) {
1169
+ var isHelper = mustache.isHelper;
1170
+ var isEligible = mustache.eligibleHelper;
1171
+ var options = this.options;
1172
+
1173
+ // if ambiguous, we can possibly resolve the ambiguity now
1174
+ if (isEligible && !isHelper) {
1175
+ var name = mustache.id.parts[0];
1176
+
1177
+ if (options.knownHelpers[name]) {
1178
+ isHelper = true;
1179
+ } else if (options.knownHelpersOnly) {
1180
+ isEligible = false;
1181
+ }
1182
+ }
1183
+
1184
+ if (isHelper) { return "helper"; }
1185
+ else if (isEligible) { return "ambiguous"; }
1186
+ else { return "simple"; }
1187
+ },
1188
+
1189
+ pushParams: function(params) {
1190
+ var i = params.length, param;
1191
+
1192
+ while(i--) {
1193
+ param = params[i];
1194
+
1195
+ if(this.options.stringParams) {
1196
+ if(param.depth) {
1197
+ this.addDepth(param.depth);
1198
+ }
1199
+
1200
+ this.opcode('getContext', param.depth || 0);
1201
+ this.opcode('pushStringParam', param.stringModeValue, param.type);
1202
+ } else {
1203
+ this[param.type](param);
1204
+ }
1205
+ }
1206
+ },
1207
+
1208
+ setupMustacheParams: function(mustache) {
1209
+ var params = mustache.params;
1210
+ this.pushParams(params);
1211
+
1212
+ if(mustache.hash) {
1213
+ this.hash(mustache.hash);
1214
+ } else {
1215
+ this.opcode('emptyHash');
1216
+ }
1217
+
1218
+ return params;
1219
+ },
1220
+
1221
+ // this will replace setupMustacheParams when we're done
1222
+ setupFullMustacheParams: function(mustache, program, inverse) {
1223
+ var params = mustache.params;
1224
+ this.pushParams(params);
1225
+
1226
+ this.opcode('pushProgram', program);
1227
+ this.opcode('pushProgram', inverse);
1228
+
1229
+ if(mustache.hash) {
1230
+ this.hash(mustache.hash);
1231
+ } else {
1232
+ this.opcode('emptyHash');
1233
+ }
1234
+
1235
+ return params;
1236
+ }
1237
+ };
1238
+
1239
+ var Literal = function(value) {
1240
+ this.value = value;
1241
+ };
1242
+
1243
+ JavaScriptCompiler.prototype = {
1244
+ // PUBLIC API: You can override these methods in a subclass to provide
1245
+ // alternative compiled forms for name lookup and buffering semantics
1246
+ nameLookup: function(parent, name /* , type*/) {
1247
+ if (/^[0-9]+$/.test(name)) {
1248
+ return parent + "[" + name + "]";
1249
+ } else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
1250
+ return parent + "." + name;
1251
+ }
1252
+ else {
1253
+ return parent + "['" + name + "']";
1254
+ }
1255
+ },
1256
+
1257
+ appendToBuffer: function(string) {
1258
+ if (this.environment.isSimple) {
1259
+ return "return " + string + ";";
1260
+ } else {
1261
+ return {
1262
+ appendToBuffer: true,
1263
+ content: string,
1264
+ toString: function() { return "buffer += " + string + ";"; }
1265
+ };
1266
+ }
1267
+ },
1268
+
1269
+ initializeBuffer: function() {
1270
+ return this.quotedString("");
1271
+ },
1272
+
1273
+ namespace: "Handlebars",
1274
+ // END PUBLIC API
1275
+
1276
+ compile: function(environment, options, context, asObject) {
1277
+ this.environment = environment;
1278
+ this.options = options || {};
1279
+
1280
+ Handlebars.log(Handlebars.logger.DEBUG, this.environment.disassemble() + "\n\n");
1281
+
1282
+ this.name = this.environment.name;
1283
+ this.isChild = !!context;
1284
+ this.context = context || {
1285
+ programs: [],
1286
+ environments: [],
1287
+ aliases: { }
1288
+ };
1289
+
1290
+ this.preamble();
1291
+
1292
+ this.stackSlot = 0;
1293
+ this.stackVars = [];
1294
+ this.registers = { list: [] };
1295
+ this.compileStack = [];
1296
+ this.inlineStack = [];
1297
+
1298
+ this.compileChildren(environment, options);
1299
+
1300
+ var opcodes = environment.opcodes, opcode;
1301
+
1302
+ this.i = 0;
1303
+
1304
+ for(l=opcodes.length; this.i<l; this.i++) {
1305
+ opcode = opcodes[this.i];
1306
+
1307
+ if(opcode.opcode === 'DECLARE') {
1308
+ this[opcode.name] = opcode.value;
1309
+ } else {
1310
+ this[opcode.opcode].apply(this, opcode.args);
1311
+ }
1312
+ }
1313
+
1314
+ return this.createFunctionContext(asObject);
1315
+ },
1316
+
1317
+ nextOpcode: function() {
1318
+ var opcodes = this.environment.opcodes;
1319
+ return opcodes[this.i + 1];
1320
+ },
1321
+
1322
+ eat: function() {
1323
+ this.i = this.i + 1;
1324
+ },
1325
+
1326
+ preamble: function() {
1327
+ var out = [];
1328
+
1329
+ if (!this.isChild) {
1330
+ var namespace = this.namespace;
1331
+ var copies = "helpers = helpers || " + namespace + ".helpers;";
1332
+ if (this.environment.usePartial) { copies = copies + " partials = partials || " + namespace + ".partials;"; }
1333
+ if (this.options.data) { copies = copies + " data = data || {};"; }
1334
+ out.push(copies);
1335
+ } else {
1336
+ out.push('');
1337
+ }
1338
+
1339
+ if (!this.environment.isSimple) {
1340
+ out.push(", buffer = " + this.initializeBuffer());
1341
+ } else {
1342
+ out.push("");
1343
+ }
1344
+
1345
+ // track the last context pushed into place to allow skipping the
1346
+ // getContext opcode when it would be a noop
1347
+ this.lastContext = 0;
1348
+ this.source = out;
1349
+ },
1350
+
1351
+ createFunctionContext: function(asObject) {
1352
+ var locals = this.stackVars.concat(this.registers.list);
1353
+
1354
+ if(locals.length > 0) {
1355
+ this.source[1] = this.source[1] + ", " + locals.join(", ");
1356
+ }
1357
+
1358
+ // Generate minimizer alias mappings
1359
+ if (!this.isChild) {
1360
+ for (var alias in this.context.aliases) {
1361
+ this.source[1] = this.source[1] + ', ' + alias + '=' + this.context.aliases[alias];
1362
+ }
1363
+ }
1364
+
1365
+ if (this.source[1]) {
1366
+ this.source[1] = "var " + this.source[1].substring(2) + ";";
1367
+ }
1368
+
1369
+ // Merge children
1370
+ if (!this.isChild) {
1371
+ this.source[1] += '\n' + this.context.programs.join('\n') + '\n';
1372
+ }
1373
+
1374
+ if (!this.environment.isSimple) {
1375
+ this.source.push("return buffer;");
1376
+ }
1377
+
1378
+ var params = this.isChild ? ["depth0", "data"] : ["Handlebars", "depth0", "helpers", "partials", "data"];
1379
+
1380
+ for(var i=0, l=this.environment.depths.list.length; i<l; i++) {
1381
+ params.push("depth" + this.environment.depths.list[i]);
1382
+ }
1383
+
1384
+ // Perform a second pass over the output to merge content when possible
1385
+ var source = this.mergeSource();
1386
+
1387
+ if (!this.isChild) {
1388
+ source = "this.compiledVersion = '"+Handlebars.VERSION+"';\n"+source;
1389
+ }
1390
+
1391
+ if (asObject) {
1392
+ params.push(source);
1393
+
1394
+ return Function.apply(this, params);
1395
+ } else {
1396
+ var functionSource = 'function ' + (this.name || '') + '(' + params.join(',') + ') {\n ' + source + '}';
1397
+ Handlebars.log(Handlebars.logger.DEBUG, functionSource + "\n\n");
1398
+ return functionSource;
1399
+ }
1400
+ },
1401
+ mergeSource: function() {
1402
+ // WARN: We are not handling the case where buffer is still populated as the source should
1403
+ // not have buffer append operations as their final action.
1404
+ var source = '',
1405
+ buffer;
1406
+ for (var i = 0, len = this.source.length; i < len; i++) {
1407
+ var line = this.source[i];
1408
+ if (line.appendToBuffer) {
1409
+ if (buffer) {
1410
+ buffer = buffer + '\n + ' + line.content;
1411
+ } else {
1412
+ buffer = line.content;
1413
+ }
1414
+ } else {
1415
+ if (buffer) {
1416
+ source += 'buffer += ' + buffer + ';\n ';
1417
+ buffer = undefined;
1418
+ }
1419
+ source += line + '\n ';
1420
+ }
1421
+ }
1422
+ return source;
1423
+ },
1424
+
1425
+ // [blockValue]
1426
+ //
1427
+ // On stack, before: hash, inverse, program, value
1428
+ // On stack, after: return value of blockHelperMissing
1429
+ //
1430
+ // The purpose of this opcode is to take a block of the form
1431
+ // `{{#foo}}...{{/foo}}`, resolve the value of `foo`, and
1432
+ // replace it on the stack with the result of properly
1433
+ // invoking blockHelperMissing.
1434
+ blockValue: function() {
1435
+ this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
1436
+
1437
+ var params = ["depth0"];
1438
+ this.setupParams(0, params);
1439
+
1440
+ this.replaceStack(function(current) {
1441
+ params.splice(1, 0, current);
1442
+ return "blockHelperMissing.call(" + params.join(", ") + ")";
1443
+ });
1444
+ },
1445
+
1446
+ // [ambiguousBlockValue]
1447
+ //
1448
+ // On stack, before: hash, inverse, program, value
1449
+ // Compiler value, before: lastHelper=value of last found helper, if any
1450
+ // On stack, after, if no lastHelper: same as [blockValue]
1451
+ // On stack, after, if lastHelper: value
1452
+ ambiguousBlockValue: function() {
1453
+ this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
1454
+
1455
+ var params = ["depth0"];
1456
+ this.setupParams(0, params);
1457
+
1458
+ var current = this.topStack();
1459
+ params.splice(1, 0, current);
1460
+
1461
+ // Use the options value generated from the invocation
1462
+ params[params.length-1] = 'options';
1463
+
1464
+ this.source.push("if (!" + this.lastHelper + ") { " + current + " = blockHelperMissing.call(" + params.join(", ") + "); }");
1465
+ },
1466
+
1467
+ // [appendContent]
1468
+ //
1469
+ // On stack, before: ...
1470
+ // On stack, after: ...
1471
+ //
1472
+ // Appends the string value of `content` to the current buffer
1473
+ appendContent: function(content) {
1474
+ this.source.push(this.appendToBuffer(this.quotedString(content)));
1475
+ },
1476
+
1477
+ // [append]
1478
+ //
1479
+ // On stack, before: value, ...
1480
+ // On stack, after: ...
1481
+ //
1482
+ // Coerces `value` to a String and appends it to the current buffer.
1483
+ //
1484
+ // If `value` is truthy, or 0, it is coerced into a string and appended
1485
+ // Otherwise, the empty string is appended
1486
+ append: function() {
1487
+ // Force anything that is inlined onto the stack so we don't have duplication
1488
+ // when we examine local
1489
+ this.flushInline();
1490
+ var local = this.popStack();
1491
+ this.source.push("if(" + local + " || " + local + " === 0) { " + this.appendToBuffer(local) + " }");
1492
+ if (this.environment.isSimple) {
1493
+ this.source.push("else { " + this.appendToBuffer("''") + " }");
1494
+ }
1495
+ },
1496
+
1497
+ // [appendEscaped]
1498
+ //
1499
+ // On stack, before: value, ...
1500
+ // On stack, after: ...
1501
+ //
1502
+ // Escape `value` and append it to the buffer
1503
+ appendEscaped: function() {
1504
+ this.context.aliases.escapeExpression = 'this.escapeExpression';
1505
+
1506
+ this.source.push(this.appendToBuffer("escapeExpression(" + this.popStack() + ")"));
1507
+ },
1508
+
1509
+ // [getContext]
1510
+ //
1511
+ // On stack, before: ...
1512
+ // On stack, after: ...
1513
+ // Compiler value, after: lastContext=depth
1514
+ //
1515
+ // Set the value of the `lastContext` compiler value to the depth
1516
+ getContext: function(depth) {
1517
+ if(this.lastContext !== depth) {
1518
+ this.lastContext = depth;
1519
+ }
1520
+ },
1521
+
1522
+ // [lookupOnContext]
1523
+ //
1524
+ // On stack, before: ...
1525
+ // On stack, after: currentContext[name], ...
1526
+ //
1527
+ // Looks up the value of `name` on the current context and pushes
1528
+ // it onto the stack.
1529
+ lookupOnContext: function(name) {
1530
+ this.push(this.nameLookup('depth' + this.lastContext, name, 'context'));
1531
+ },
1532
+
1533
+ // [pushContext]
1534
+ //
1535
+ // On stack, before: ...
1536
+ // On stack, after: currentContext, ...
1537
+ //
1538
+ // Pushes the value of the current context onto the stack.
1539
+ pushContext: function() {
1540
+ this.pushStackLiteral('depth' + this.lastContext);
1541
+ },
1542
+
1543
+ // [resolvePossibleLambda]
1544
+ //
1545
+ // On stack, before: value, ...
1546
+ // On stack, after: resolved value, ...
1547
+ //
1548
+ // If the `value` is a lambda, replace it on the stack by
1549
+ // the return value of the lambda
1550
+ resolvePossibleLambda: function() {
1551
+ this.context.aliases.functionType = '"function"';
1552
+
1553
+ this.replaceStack(function(current) {
1554
+ return "typeof " + current + " === functionType ? " + current + ".apply(depth0) : " + current;
1555
+ });
1556
+ },
1557
+
1558
+ // [lookup]
1559
+ //
1560
+ // On stack, before: value, ...
1561
+ // On stack, after: value[name], ...
1562
+ //
1563
+ // Replace the value on the stack with the result of looking
1564
+ // up `name` on `value`
1565
+ lookup: function(name) {
1566
+ this.replaceStack(function(current) {
1567
+ return current + " == null || " + current + " === false ? " + current + " : " + this.nameLookup(current, name, 'context');
1568
+ });
1569
+ },
1570
+
1571
+ // [lookupData]
1572
+ //
1573
+ // On stack, before: ...
1574
+ // On stack, after: data[id], ...
1575
+ //
1576
+ // Push the result of looking up `id` on the current data
1577
+ lookupData: function(id) {
1578
+ this.push(this.nameLookup('data', id, 'data'));
1579
+ },
1580
+
1581
+ // [pushStringParam]
1582
+ //
1583
+ // On stack, before: ...
1584
+ // On stack, after: string, currentContext, ...
1585
+ //
1586
+ // This opcode is designed for use in string mode, which
1587
+ // provides the string value of a parameter along with its
1588
+ // depth rather than resolving it immediately.
1589
+ pushStringParam: function(string, type) {
1590
+ this.pushStackLiteral('depth' + this.lastContext);
1591
+
1592
+ this.pushString(type);
1593
+
1594
+ if (typeof string === 'string') {
1595
+ this.pushString(string);
1596
+ } else {
1597
+ this.pushStackLiteral(string);
1598
+ }
1599
+ },
1600
+
1601
+ emptyHash: function() {
1602
+ this.pushStackLiteral('{}');
1603
+
1604
+ if (this.options.stringParams) {
1605
+ this.register('hashTypes', '{}');
1606
+ }
1607
+ },
1608
+ pushHash: function() {
1609
+ this.hash = {values: [], types: []};
1610
+ },
1611
+ popHash: function() {
1612
+ var hash = this.hash;
1613
+ this.hash = undefined;
1614
+
1615
+ if (this.options.stringParams) {
1616
+ this.register('hashTypes', '{' + hash.types.join(',') + '}');
1617
+ }
1618
+ this.push('{\n ' + hash.values.join(',\n ') + '\n }');
1619
+ },
1620
+
1621
+ // [pushString]
1622
+ //
1623
+ // On stack, before: ...
1624
+ // On stack, after: quotedString(string), ...
1625
+ //
1626
+ // Push a quoted version of `string` onto the stack
1627
+ pushString: function(string) {
1628
+ this.pushStackLiteral(this.quotedString(string));
1629
+ },
1630
+
1631
+ // [push]
1632
+ //
1633
+ // On stack, before: ...
1634
+ // On stack, after: expr, ...
1635
+ //
1636
+ // Push an expression onto the stack
1637
+ push: function(expr) {
1638
+ this.inlineStack.push(expr);
1639
+ return expr;
1640
+ },
1641
+
1642
+ // [pushLiteral]
1643
+ //
1644
+ // On stack, before: ...
1645
+ // On stack, after: value, ...
1646
+ //
1647
+ // Pushes a value onto the stack. This operation prevents
1648
+ // the compiler from creating a temporary variable to hold
1649
+ // it.
1650
+ pushLiteral: function(value) {
1651
+ this.pushStackLiteral(value);
1652
+ },
1653
+
1654
+ // [pushProgram]
1655
+ //
1656
+ // On stack, before: ...
1657
+ // On stack, after: program(guid), ...
1658
+ //
1659
+ // Push a program expression onto the stack. This takes
1660
+ // a compile-time guid and converts it into a runtime-accessible
1661
+ // expression.
1662
+ pushProgram: function(guid) {
1663
+ if (guid != null) {
1664
+ this.pushStackLiteral(this.programExpression(guid));
1665
+ } else {
1666
+ this.pushStackLiteral(null);
1667
+ }
1668
+ },
1669
+
1670
+ // [invokeHelper]
1671
+ //
1672
+ // On stack, before: hash, inverse, program, params..., ...
1673
+ // On stack, after: result of helper invocation
1674
+ //
1675
+ // Pops off the helper's parameters, invokes the helper,
1676
+ // and pushes the helper's return value onto the stack.
1677
+ //
1678
+ // If the helper is not found, `helperMissing` is called.
1679
+ invokeHelper: function(paramSize, name) {
1680
+ this.context.aliases.helperMissing = 'helpers.helperMissing';
1681
+
1682
+ var helper = this.lastHelper = this.setupHelper(paramSize, name, true);
1683
+
1684
+ this.push(helper.name);
1685
+ this.replaceStack(function(name) {
1686
+ return name + ' ? ' + name + '.call(' +
1687
+ helper.callParams + ") " + ": helperMissing.call(" +
1688
+ helper.helperMissingParams + ")";
1689
+ });
1690
+ },
1691
+
1692
+ // [invokeKnownHelper]
1693
+ //
1694
+ // On stack, before: hash, inverse, program, params..., ...
1695
+ // On stack, after: result of helper invocation
1696
+ //
1697
+ // This operation is used when the helper is known to exist,
1698
+ // so a `helperMissing` fallback is not required.
1699
+ invokeKnownHelper: function(paramSize, name) {
1700
+ var helper = this.setupHelper(paramSize, name);
1701
+ this.push(helper.name + ".call(" + helper.callParams + ")");
1702
+ },
1703
+
1704
+ // [invokeAmbiguous]
1705
+ //
1706
+ // On stack, before: hash, inverse, program, params..., ...
1707
+ // On stack, after: result of disambiguation
1708
+ //
1709
+ // This operation is used when an expression like `{{foo}}`
1710
+ // is provided, but we don't know at compile-time whether it
1711
+ // is a helper or a path.
1712
+ //
1713
+ // This operation emits more code than the other options,
1714
+ // and can be avoided by passing the `knownHelpers` and
1715
+ // `knownHelpersOnly` flags at compile-time.
1716
+ invokeAmbiguous: function(name, helperCall) {
1717
+ this.context.aliases.functionType = '"function"';
1718
+
1719
+ this.pushStackLiteral('{}'); // Hash value
1720
+ var helper = this.setupHelper(0, name, helperCall);
1721
+
1722
+ var helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper');
1723
+
1724
+ var nonHelper = this.nameLookup('depth' + this.lastContext, name, 'context');
1725
+ var nextStack = this.nextStack();
1726
+
1727
+ this.source.push('if (' + nextStack + ' = ' + helperName + ') { ' + nextStack + ' = ' + nextStack + '.call(' + helper.callParams + '); }');
1728
+ this.source.push('else { ' + nextStack + ' = ' + nonHelper + '; ' + nextStack + ' = typeof ' + nextStack + ' === functionType ? ' + nextStack + '.apply(depth0) : ' + nextStack + '; }');
1729
+ },
1730
+
1731
+ // [invokePartial]
1732
+ //
1733
+ // On stack, before: context, ...
1734
+ // On stack after: result of partial invocation
1735
+ //
1736
+ // This operation pops off a context, invokes a partial with that context,
1737
+ // and pushes the result of the invocation back.
1738
+ invokePartial: function(name) {
1739
+ var params = [this.nameLookup('partials', name, 'partial'), "'" + name + "'", this.popStack(), "helpers", "partials"];
1740
+
1741
+ if (this.options.data) {
1742
+ params.push("data");
1743
+ }
1744
+
1745
+ this.context.aliases.self = "this";
1746
+ this.push("self.invokePartial(" + params.join(", ") + ")");
1747
+ },
1748
+
1749
+ // [assignToHash]
1750
+ //
1751
+ // On stack, before: value, hash, ...
1752
+ // On stack, after: hash, ...
1753
+ //
1754
+ // Pops a value and hash off the stack, assigns `hash[key] = value`
1755
+ // and pushes the hash back onto the stack.
1756
+ assignToHash: function(key) {
1757
+ var value = this.popStack(),
1758
+ type;
1759
+
1760
+ if (this.options.stringParams) {
1761
+ type = this.popStack();
1762
+ this.popStack();
1763
+ }
1764
+
1765
+ var hash = this.hash;
1766
+ if (type) {
1767
+ hash.types.push("'" + key + "': " + type);
1768
+ }
1769
+ hash.values.push("'" + key + "': (" + value + ")");
1770
+ },
1771
+
1772
+ // HELPERS
1773
+
1774
+ compiler: JavaScriptCompiler,
1775
+
1776
+ compileChildren: function(environment, options) {
1777
+ var children = environment.children, child, compiler;
1778
+
1779
+ for(var i=0, l=children.length; i<l; i++) {
1780
+ child = children[i];
1781
+ compiler = new this.compiler();
1782
+
1783
+ var index = this.matchExistingProgram(child);
1784
+
1785
+ if (index == null) {
1786
+ this.context.programs.push(''); // Placeholder to prevent name conflicts for nested children
1787
+ index = this.context.programs.length;
1788
+ child.index = index;
1789
+ child.name = 'program' + index;
1790
+ this.context.programs[index] = compiler.compile(child, options, this.context);
1791
+ this.context.environments[index] = child;
1792
+ } else {
1793
+ child.index = index;
1794
+ child.name = 'program' + index;
1795
+ }
1796
+ }
1797
+ },
1798
+ matchExistingProgram: function(child) {
1799
+ for (var i = 0, len = this.context.environments.length; i < len; i++) {
1800
+ var environment = this.context.environments[i];
1801
+ if (environment && environment.equals(child)) {
1802
+ return i;
1803
+ }
1804
+ }
1805
+ },
1806
+
1807
+ programExpression: function(guid) {
1808
+ this.context.aliases.self = "this";
1809
+
1810
+ if(guid == null) {
1811
+ return "self.noop";
1812
+ }
1813
+
1814
+ var child = this.environment.children[guid],
1815
+ depths = child.depths.list, depth;
1816
+
1817
+ var programParams = [child.index, child.name, "data"];
1818
+
1819
+ for(var i=0, l = depths.length; i<l; i++) {
1820
+ depth = depths[i];
1821
+
1822
+ if(depth === 1) { programParams.push("depth0"); }
1823
+ else { programParams.push("depth" + (depth - 1)); }
1824
+ }
1825
+
1826
+ if(depths.length === 0) {
1827
+ return "self.program(" + programParams.join(", ") + ")";
1828
+ } else {
1829
+ programParams.shift();
1830
+ return "self.programWithDepth(" + programParams.join(", ") + ")";
1831
+ }
1832
+ },
1833
+
1834
+ register: function(name, val) {
1835
+ this.useRegister(name);
1836
+ this.source.push(name + " = " + val + ";");
1837
+ },
1838
+
1839
+ useRegister: function(name) {
1840
+ if(!this.registers[name]) {
1841
+ this.registers[name] = true;
1842
+ this.registers.list.push(name);
1843
+ }
1844
+ },
1845
+
1846
+ pushStackLiteral: function(item) {
1847
+ return this.push(new Literal(item));
1848
+ },
1849
+
1850
+ pushStack: function(item) {
1851
+ this.flushInline();
1852
+
1853
+ var stack = this.incrStack();
1854
+ if (item) {
1855
+ this.source.push(stack + " = " + item + ";");
1856
+ }
1857
+ this.compileStack.push(stack);
1858
+ return stack;
1859
+ },
1860
+
1861
+ replaceStack: function(callback) {
1862
+ var prefix = '',
1863
+ inline = this.isInline(),
1864
+ stack;
1865
+
1866
+ // If we are currently inline then we want to merge the inline statement into the
1867
+ // replacement statement via ','
1868
+ if (inline) {
1869
+ var top = this.popStack(true);
1870
+
1871
+ if (top instanceof Literal) {
1872
+ // Literals do not need to be inlined
1873
+ stack = top.value;
1874
+ } else {
1875
+ // Get or create the current stack name for use by the inline
1876
+ var name = this.stackSlot ? this.topStackName() : this.incrStack();
1877
+
1878
+ prefix = '(' + this.push(name) + ' = ' + top + '),';
1879
+ stack = this.topStack();
1880
+ }
1881
+ } else {
1882
+ stack = this.topStack();
1883
+ }
1884
+
1885
+ var item = callback.call(this, stack);
1886
+
1887
+ if (inline) {
1888
+ if (this.inlineStack.length || this.compileStack.length) {
1889
+ this.popStack();
1890
+ }
1891
+ this.push('(' + prefix + item + ')');
1892
+ } else {
1893
+ // Prevent modification of the context depth variable. Through replaceStack
1894
+ if (!/^stack/.test(stack)) {
1895
+ stack = this.nextStack();
1896
+ }
1897
+
1898
+ this.source.push(stack + " = (" + prefix + item + ");");
1899
+ }
1900
+ return stack;
1901
+ },
1902
+
1903
+ nextStack: function() {
1904
+ return this.pushStack();
1905
+ },
1906
+
1907
+ incrStack: function() {
1908
+ this.stackSlot++;
1909
+ if(this.stackSlot > this.stackVars.length) { this.stackVars.push("stack" + this.stackSlot); }
1910
+ return this.topStackName();
1911
+ },
1912
+ topStackName: function() {
1913
+ return "stack" + this.stackSlot;
1914
+ },
1915
+ flushInline: function() {
1916
+ var inlineStack = this.inlineStack;
1917
+ if (inlineStack.length) {
1918
+ this.inlineStack = [];
1919
+ for (var i = 0, len = inlineStack.length; i < len; i++) {
1920
+ var entry = inlineStack[i];
1921
+ if (entry instanceof Literal) {
1922
+ this.compileStack.push(entry);
1923
+ } else {
1924
+ this.pushStack(entry);
1925
+ }
1926
+ }
1927
+ }
1928
+ },
1929
+ isInline: function() {
1930
+ return this.inlineStack.length;
1931
+ },
1932
+
1933
+ popStack: function(wrapped) {
1934
+ var inline = this.isInline(),
1935
+ item = (inline ? this.inlineStack : this.compileStack).pop();
1936
+
1937
+ if (!wrapped && (item instanceof Literal)) {
1938
+ return item.value;
1939
+ } else {
1940
+ if (!inline) {
1941
+ this.stackSlot--;
1942
+ }
1943
+ return item;
1944
+ }
1945
+ },
1946
+
1947
+ topStack: function(wrapped) {
1948
+ var stack = (this.isInline() ? this.inlineStack : this.compileStack),
1949
+ item = stack[stack.length - 1];
1950
+
1951
+ if (!wrapped && (item instanceof Literal)) {
1952
+ return item.value;
1953
+ } else {
1954
+ return item;
1955
+ }
1956
+ },
1957
+
1958
+ quotedString: function(str) {
1959
+ return '"' + str
1960
+ .replace(/\\/g, '\\\\')
1961
+ .replace(/"/g, '\\"')
1962
+ .replace(/\n/g, '\\n')
1963
+ .replace(/\r/g, '\\r') + '"';
1964
+ },
1965
+
1966
+ setupHelper: function(paramSize, name, missingParams) {
1967
+ var params = [];
1968
+ this.setupParams(paramSize, params, missingParams);
1969
+ var foundHelper = this.nameLookup('helpers', name, 'helper');
1970
+
1971
+ return {
1972
+ params: params,
1973
+ name: foundHelper,
1974
+ callParams: ["depth0"].concat(params).join(", "),
1975
+ helperMissingParams: missingParams && ["depth0", this.quotedString(name)].concat(params).join(", ")
1976
+ };
1977
+ },
1978
+
1979
+ // the params and contexts arguments are passed in arrays
1980
+ // to fill in
1981
+ setupParams: function(paramSize, params, useRegister) {
1982
+ var options = [], contexts = [], types = [], param, inverse, program;
1983
+
1984
+ options.push("hash:" + this.popStack());
1985
+
1986
+ inverse = this.popStack();
1987
+ program = this.popStack();
1988
+
1989
+ // Avoid setting fn and inverse if neither are set. This allows
1990
+ // helpers to do a check for `if (options.fn)`
1991
+ if (program || inverse) {
1992
+ if (!program) {
1993
+ this.context.aliases.self = "this";
1994
+ program = "self.noop";
1995
+ }
1996
+
1997
+ if (!inverse) {
1998
+ this.context.aliases.self = "this";
1999
+ inverse = "self.noop";
2000
+ }
2001
+
2002
+ options.push("inverse:" + inverse);
2003
+ options.push("fn:" + program);
2004
+ }
2005
+
2006
+ for(var i=0; i<paramSize; i++) {
2007
+ param = this.popStack();
2008
+ params.push(param);
2009
+
2010
+ if(this.options.stringParams) {
2011
+ types.push(this.popStack());
2012
+ contexts.push(this.popStack());
2013
+ }
2014
+ }
2015
+
2016
+ if (this.options.stringParams) {
2017
+ options.push("contexts:[" + contexts.join(",") + "]");
2018
+ options.push("types:[" + types.join(",") + "]");
2019
+ options.push("hashTypes:hashTypes");
2020
+ }
2021
+
2022
+ if(this.options.data) {
2023
+ options.push("data:data");
2024
+ }
2025
+
2026
+ options = "{" + options.join(",") + "}";
2027
+ if (useRegister) {
2028
+ this.register('options', options);
2029
+ params.push('options');
2030
+ } else {
2031
+ params.push(options);
2032
+ }
2033
+ return params.join(", ");
2034
+ }
2035
+ };
2036
+
2037
+ var reservedWords = (
2038
+ "break else new var" +
2039
+ " case finally return void" +
2040
+ " catch for switch while" +
2041
+ " continue function this with" +
2042
+ " default if throw" +
2043
+ " delete in try" +
2044
+ " do instanceof typeof" +
2045
+ " abstract enum int short" +
2046
+ " boolean export interface static" +
2047
+ " byte extends long super" +
2048
+ " char final native synchronized" +
2049
+ " class float package throws" +
2050
+ " const goto private transient" +
2051
+ " debugger implements protected volatile" +
2052
+ " double import public let yield"
2053
+ ).split(" ");
2054
+
2055
+ var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
2056
+
2057
+ for(var i=0, l=reservedWords.length; i<l; i++) {
2058
+ compilerWords[reservedWords[i]] = true;
2059
+ }
2060
+
2061
+ JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
2062
+ if(!JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]+$/.test(name)) {
2063
+ return true;
2064
+ }
2065
+ return false;
2066
+ };
2067
+
2068
+ })(Handlebars.Compiler, Handlebars.JavaScriptCompiler);
2069
+
2070
+ Handlebars.precompile = function(input, options) {
2071
+ if (!input || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) {
2072
+ throw new Handlebars.Exception("You must pass a string or Handlebars AST to Handlebars.compile. You passed " + input);
2073
+ }
2074
+
2075
+ options = options || {};
2076
+ if (!('data' in options)) {
2077
+ options.data = true;
2078
+ }
2079
+ var ast = Handlebars.parse(input);
2080
+ var environment = new Handlebars.Compiler().compile(ast, options);
2081
+ return new Handlebars.JavaScriptCompiler().compile(environment, options);
2082
+ };
2083
+
2084
+ Handlebars.compile = function(input, options) {
2085
+ if (!input || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) {
2086
+ throw new Handlebars.Exception("You must pass a string or Handlebars AST to Handlebars.compile. You passed " + input);
2087
+ }
2088
+
2089
+ options = options || {};
2090
+ if (!('data' in options)) {
2091
+ options.data = true;
2092
+ }
2093
+ var compiled;
2094
+ function compile() {
2095
+ var ast = Handlebars.parse(input);
2096
+ var environment = new Handlebars.Compiler().compile(ast, options);
2097
+ var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true);
2098
+ return Handlebars.template(templateSpec);
2099
+ }
2100
+
2101
+ // Template is only compiled on first use and cached after that point.
2102
+ return function(context, options) {
2103
+ if (!compiled) {
2104
+ compiled = compile();
2105
+ }
2106
+ return compiled.call(this, context, options);
2107
+ };
2108
+ };
2109
+ ;
2110
+ // lib/handlebars/runtime.js
2111
+ Handlebars.VM = {
2112
+ template: function(templateSpec) {
2113
+ // Just add water
2114
+ var container = {
2115
+ escapeExpression: Handlebars.Utils.escapeExpression,
2116
+ invokePartial: Handlebars.VM.invokePartial,
2117
+ programs: [],
2118
+ program: function(i, fn, data) {
2119
+ var programWrapper = this.programs[i];
2120
+ if(data) {
2121
+ return Handlebars.VM.program(fn, data);
2122
+ } else if(programWrapper) {
2123
+ return programWrapper;
2124
+ } else {
2125
+ programWrapper = this.programs[i] = Handlebars.VM.program(fn);
2126
+ return programWrapper;
2127
+ }
2128
+ },
2129
+ programWithDepth: Handlebars.VM.programWithDepth,
2130
+ noop: Handlebars.VM.noop,
2131
+ compiledVersion: null
2132
+ };
2133
+
2134
+ return function(context, options) {
2135
+ options = options || {};
2136
+ var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data);
2137
+ if (container.compiledVersion !== Handlebars.VERSION) {
2138
+ throw "Template was compiled with "+(container.compiledVersion || 'unknown version')+", but runtime is "+Handlebars.VERSION;
2139
+ }
2140
+ return result;
2141
+ };
2142
+ },
2143
+
2144
+ programWithDepth: function(fn, data, $depth) {
2145
+ var args = Array.prototype.slice.call(arguments, 2);
2146
+
2147
+ return function(context, options) {
2148
+ options = options || {};
2149
+
2150
+ return fn.apply(this, [context, options.data || data].concat(args));
2151
+ };
2152
+ },
2153
+ program: function(fn, data) {
2154
+ return function(context, options) {
2155
+ options = options || {};
2156
+
2157
+ return fn(context, options.data || data);
2158
+ };
2159
+ },
2160
+ noop: function() { return ""; },
2161
+ invokePartial: function(partial, name, context, helpers, partials, data) {
2162
+ var options = { helpers: helpers, partials: partials, data: data };
2163
+
2164
+ if(partial === undefined) {
2165
+ throw new Handlebars.Exception("The partial " + name + " could not be found");
2166
+ } else if(partial instanceof Function) {
2167
+ return partial(context, options);
2168
+ } else if (!Handlebars.compile) {
2169
+ throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
2170
+ } else {
2171
+ partials[name] = Handlebars.compile(partial, {data: data !== undefined});
2172
+ return partials[name](context, options);
2173
+ }
2174
+ }
2175
+ };
2176
+
2177
+ Handlebars.template = Handlebars.VM.template;
2178
+ ;