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