ember-template-compiler-source 1.0.0.pre4.3 → 1.0.0.pre4.4

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