weekly release 4.0dev
[moodle.git] / lib / amd / build / mustache.min.js
1 function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}(function(a,b){if("object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&exports&&"string"!=typeof exports.nodeName){b(exports)}else if("function"==typeof define&&define.amd){define ("core/mustache",["exports"],b)}else{a.Mustache={};b(a.Mustache)}})(this,function(a){var o=Object.prototype.toString,p=Array.isArray||function(a){return"[object Array]"===o.call(a)};function b(a){return"function"==typeof a}function c(a){return p(a)?"array":_typeof(a)}function d(a){return a.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function e(a,b){return null!=a&&"object"===_typeof(a)&&b in a}function f(a,b){return null!=a&&"object"!==_typeof(a)&&a.hasOwnProperty&&a.hasOwnProperty(b)}var q=RegExp.prototype.test;function g(a,b){return q.call(a,b)}function h(a){return!g(/\S/,a)}var r={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};var s=/\s*=/;function i(b,c){if(!b)return[];var g=!1,m=[],n=[],o=[],q=!1,r=!1,t="",u=0;function e(){if(q&&!r){while(o.length){delete n[o.pop()]}}else{o=[]}q=!1;r=!1}var v,w,x;function f(a){if("string"==typeof a)a=a.split(/\s+/,2);if(!p(a)||2!==a.length)throw new Error("Invalid tags: "+a);v=new RegExp(d(a[0])+"\\s*");w=new RegExp("\\s*"+d(a[1]));x=new RegExp("\\s*"+d("}"+a[1]))}f(c||a.tags);var y=new l(b),z,A,B,C,D,E;while(!y.eos()){z=y.pos;B=y.scanUntil(v);if(B){for(var F=0,G=B.length;F<G;++F){C=B.charAt(F);if(h(C)){o.push(n.length);t+=C}else{r=!0;g=!0;t+=" "}n.push(["text",C,z,z+1]);z+=1;if("\n"===C){e();t="";u=0;g=!1}}}if(!y.scan(v))break;q=!0;A=y.scan(/#|\^|\/|>|\{|&|=|!|\$|</)||"name";y.scan(/\s*/);if("="===A){B=y.scanUntil(s);y.scan(s);y.scanUntil(w)}else if("{"===A){B=y.scanUntil(x);y.scan(/\s*\}/);y.scanUntil(w);A="&"}else{B=y.scanUntil(w)}if(!y.scan(w))throw new Error("Unclosed tag at "+y.pos);if(">"==A){D=[A,B,z,y.pos,t,u,g]}else{D=[A,B,z,y.pos]}u++;n.push(D);if("#"===A||"^"===A||"$"===A||"<"===A){m.push(D)}else if("/"===A){E=m.pop();if(!E)throw new Error("Unopened section \""+B+"\" at "+z);if(E[1]!==B)throw new Error("Unclosed section \""+E[1]+"\" at "+z)}else if("name"===A||"{"===A||"&"===A){r=!0}else if("="===A){f(B)}}e();E=m.pop();if(E)throw new Error("Unclosed section \""+E[1]+"\" at "+y.pos);return k(j(n))}function j(a){for(var b=[],c,d,e=0,f=a.length;e<f;++e){c=a[e];if(c){if("text"===c[0]&&d&&"text"===d[0]){d[1]+=c[1];d[3]=c[3]}else{b.push(c);d=c}}}return b}function k(a){for(var b=[],c=b,d=[],e,f,g=0,h=a.length;g<h;++g){e=a[g];switch(e[0]){case"$":case"<":case"#":case"^":c.push(e);d.push(e);c=e[4]=[];break;case"/":f=d.pop();f[5]=e[2];c=0<d.length?d[d.length-1][4]:b;break;default:c.push(e);}}return b}function l(a){this.string=a;this.tail=a;this.pos=0}l.prototype.eos=function(){return""===this.tail};l.prototype.scan=function(a){var b=this.tail.match(a);if(!b||0!==b.index)return"";var c=b[0];this.tail=this.tail.substring(c.length);this.pos+=c.length;return c};l.prototype.scanUntil=function(a){var b=this.tail.search(a),c;switch(b){case-1:c=this.tail;this.tail="";break;case 0:c="";break;default:c=this.tail.substring(0,b);this.tail=this.tail.substring(b);}this.pos+=c.length;return c};function m(a,b){this.view=a;this.blocks={};this.cache={".":this.view};this.parent=b}m.prototype.push=function(a){return new m(a,this)};m.prototype.setBlockVar=function(a,b){var c=this.blocks;c[a]=b;return b};m.prototype.clearBlockVars=function(){this.blocks={}};m.prototype.getBlockVar=function(a){var b=this.blocks,c;if(b.hasOwnProperty(a)){c=b[a]}else{if(this.parent){c=this.parent.getBlockVar(a)}}return c};m.prototype.lookup=function(a){var c=this.cache,d;if(c.hasOwnProperty(a)){d=c[a]}else{var g=this,h,i,j,k=!1;while(g){if(0<a.indexOf(".")){h=g.view;i=a.split(".");j=0;while(null!=h&&j<i.length){if(j===i.length-1)k=e(h,i[j])||f(h,i[j]);h=h[i[j++]]}}else{h=g.view[a];k=e(g.view,a)}if(k){d=h;break}g=g.parent}c[a]=d}if(b(d))d=d.call(this.view);return d};function n(){this.cache={}}n.prototype.clearCache=function(){this.cache={}};n.prototype.parse=function(b,c){var d=this.cache,e=b+":"+(c||a.tags).join(":"),f=d[e];if(null==f)f=d[e]=i(b,c);return f};n.prototype.render=function(a,b,c,d){var e=this.parse(a,d),f=b instanceof m?b:new m(b);return this.renderTokens(e,f,c,a,d)};n.prototype.renderTokens=function(a,b,c,d,e){for(var f="",g,h,j,k=0,l=a.length;k<l;++k){j=void 0;g=a[k];h=g[0];if("#"===h)j=this.renderSection(g,b,c,d);else if("^"===h)j=this.renderInverted(g,b,c,d);else if(">"===h)j=this.renderPartial(g,b,c,e);else if("<"===h)j=this.renderBlock(g,b,c,d);else if("$"===h)j=this.renderBlockVariable(g,b,c,d);else if("&"===h)j=this.unescapedValue(g,b);else if("name"===h)j=this.escapedValue(g,b);else if("text"===h)j=this.rawValue(g);if(j!==void 0)f+=j}return f};n.prototype.renderSection=function(a,c,d,e){var g=this,h="",i=c.lookup(a[1]);function f(a){return g.render(a,c,d)}if(!i)return;if(p(i)){for(var k=0,l=i.length;k<l;++k){h+=this.renderTokens(a[4],c.push(i[k]),d,e)}}else if("object"===_typeof(i)||"string"==typeof i||"number"==typeof i){h+=this.renderTokens(a[4],c.push(i),d,e)}else if(b(i)){if("string"!=typeof e)throw new Error("Cannot use higher-order sections without the original template");i=i.call(c.view,e.slice(a[3],a[5]),f);if(null!=i)h+=i}else{h+=this.renderTokens(a[4],c,d,e)}return h};n.prototype.renderInverted=function(a,b,c,d){var e=b.lookup(a[1]);if(!e||p(e)&&0===e.length)return this.renderTokens(a[4],b,c,d)};n.prototype.indentPartial=function(a,b,c){for(var d=b.replace(/[^ \t]/g,""),e=a.split("\n"),f=0;f<e.length;f++){if(e[f].length&&(0<f||!c)){e[f]=d+e[f]}}return e.join("\n")};n.prototype.renderPartial=function(a,c,d,e){if(!d)return;var f=b(d)?d(a[1]):d[a[1]];if(null!=f){var g=a[6],h=a[5],i=a[4],j=f;if(0==h&&i){j=this.indentPartial(f,i,g)}return this.renderTokens(this.parse(j,e),c,d,j)}};n.prototype.renderBlock=function(a,c,d,e){if(!d)return;var f=b(d)?d(a[1]):d[a[1]];if(null!=f)c.clearBlockVars();this.renderTokens(a[4],c,d,e);var g=this.renderTokens(this.parse(f),c,d,f);c.clearBlockVars();return g};n.prototype.renderBlockVariable=function(a,b,c,d){var e=a[1],f=b.getBlockVar(e);if(!f){b.setBlockVar(e,d.slice(a[3],a[5]));return this.renderTokens(a[4],b,c,d)}else{return this.renderTokens(this.parse(f),b,c,f)}};n.prototype.unescapedValue=function(a,b){var c=b.lookup(a[1]);if(null!=c)return c};n.prototype.escapedValue=function(b,c){var d=c.lookup(b[1]);if(null!=d)return a.escape(d)};n.prototype.rawValue=function(a){return a[1]};a.name="mustache.js";a.version="3.1.0";a.tags=["{{","}}"];var t=new n;a.clearCache=function(){return t.clearCache()};a.parse=function(a,b){return t.parse(a,b)};a.render=function(a,b,d,e){if("string"!=typeof a){throw new TypeError("Invalid template! Template should be a \"string\" but \""+c(a)+"\" was given as the first argument for mustache#render(template, view, partials)")}return t.render(a,b,d,e)};a.to_html=function(c,d,e,f){var g=a.render(c,d,e);if(b(f)){f(g)}else{return g}};a.escape=function(a){return(a+"").replace(/[&<>"'`=\/]/g,function(a){return r[a]})};a.Scanner=l;a.Context=m;a.Writer=n;return a});
2 //# sourceMappingURL=mustache.min.js.map