handlebars.amd.js 92 KB

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