Files
liquidjs/dist/liquid.min.js
T
semantic-release-bot b51b0dabca chore(release): 7.0.0 [skip ci]
# [7.0.0](https://github.com/harttle/liquidjs/compare/v6.4.3...v7.0.0) (2019-02-14)

### chore

* **TypeScript:** ship Liquid to class ([1cc7249](https://github.com/harttle/liquidjs/commit/1cc7249))

### BREAKING CHANGES

* **TypeScript:** calling `Liquid()` without `new` now becomes invalid
2019-02-14 16:02:23 +00:00

3 lines
33 KiB
JavaScript

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Liquid=e()}(this,function(){"use strict";var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function e(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}function B(o,s,u,a){return new(u||(u=Promise))(function(t,e){function r(t){try{i(a.next(t))}catch(t){e(t)}}function n(t){try{i(a.throw(t))}catch(t){e(t)}}function i(e){e.done?t(e.value):new u(function(t){t(e.value)}).then(r,n)}i((a=a.apply(o,s||[])).next())})}function U(r,n){var i,o,s,t,u={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return t={next:e(0),throw:e(1),return:e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;u;)try{if(i=1,o&&(s=2&e[0]?o.return:e[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,e[1])).done)return s;switch(o=0,s&&(e=[2&e[0],s.value]),e[0]){case 0:case 1:s=e;break;case 4:return u.label++,{value:e[1],done:!1};case 5:u.label++,o=e[1],e=[0];continue;case 7:e=u.ops.pop(),u.trys.pop();continue;default:if(!(s=0<(s=u.trys).length&&s[s.length-1])&&(6===e[0]||2===e[0])){u=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]<s[3])){u.label=e[1];break}if(6===e[0]&&u.label<s[1]){u.label=s[1],s=e;break}if(s&&u.label<s[2]){u.label=s[2],u.ops.push(e);break}s[2]&&u.ops.pop(),u.trys.pop();continue}e=n.call(r,u)}catch(t){e=[6,t],o=0}finally{i=s=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}}var i=Object.prototype.toString,o=Array.prototype.toString;function W(t){return"[object String]"===i.call(t)}function s(t){return"function"==typeof t}function u(t){return a(t)?String(t):s(t.to_liquid)?u(t.to_liquid()):s(t.toLiquid)?u(t.toLiquid()):s(t.to_s)?t.to_s():-1<[i,o].indexOf(t.toString)?(e=t,r=[],JSON.stringify(e,function(t,e){if(X(e)){if(-1!==r.indexOf(e))return;r.push(e)}return e})):s(t.toString)?t.toString():i.call(t);var e,r}function J(t){return Object.create(t)}function a(t){return null==t}function G(t){return"[object Array]"===i.call(t)}function m(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return e=X(e)?e:{},t.forEach(function(t){return function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])}(e,t)}),e}function y(t){return t[t.length-1]}function X(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}var t=new RegExp(/'[^']*'/.source+"|"+/"[^"]*"/.source),f=new RegExp("(?:"+t.source+"|[^'\"])*"),r=/-?\d+\.?\d*|\.?\d+/,c=/true|false/,K=/[\w-]+[?]?/,l=new RegExp("\\[(?:"+t.source+"|[\\w-\\.]+)\\]"),p=new RegExp("(?:"+t.source+"|"+c.source+"|"+r.source+")"),h=new RegExp(K.source+"(?:\\."+K.source+"|"+l.source+")*"),d=new RegExp("(?:"+h.source+"|"+r.source+")"),g=new RegExp("\\("+d.source+"\\.\\."+d.source+"\\)"),v=new RegExp("\\(("+d.source+")\\.\\.("+d.source+")\\)"),Q=new RegExp("(?:"+h.source+"|"+p.source+"|"+g.source+")"),Z=new RegExp("(?:"+K.source+")\\s*:\\s*(?:"+Q.source+")"),w=new RegExp("("+K.source+")\\s*:\\s*("+Q.source+")","g"),b=new RegExp("^\\s*("+K.source+")\\s*([\\s\\S]*)\\s*$"),x=new RegExp("^"+p.source+"$","i"),T=new RegExp("^"+h.source+"$"),E=new RegExp("^"+r.source+"$"),k=new RegExp("^"+c.source+"$","i"),tt=new RegExp("^"+t.source+"$"),S=new RegExp("^"+v.source+"$"),_=new RegExp("^"+/-?\d+/.source+"$"),R=new RegExp("(?:"+K.source+"\\s*:\\s*)?"+Q.source),M=new RegExp(R.source+"(\\s*,\\s*"+R.source+")*"),O=new RegExp(K.source+"(?:\\s*:\\s*"+M.source+")?","g"),j=new RegExp("("+K.source+")(?:\\s*:\\s*("+M.source+"))?"),A=new RegExp("^"+j.source+"$"),D=[/\s+or\s+/,/\s+and\s+/,/==|!=|<=|>=|<|>|\s+contains\s+/];function q(){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}var C=function(){function t(t,e){this.input=e.input,this.line=e.line,this.file=e.file,this.originalError=t,this.token=e}return t.prototype.captureStackTrace=function(t){this.name=t.constructor.name,q.call(t);var e,s,u,r,a,n=this.originalError,i=(e=this.input,s=this.line,u=e.split("\n"),r=Math.max(s-2,1),a=Math.min(s+3,u.length),function(t,e,r){1===arguments.length&&(e=t,t=0),r=r||1;for(var n=[],i=t;i<e;i+=r)n.push(i);return n}(r,a+1).map(function(t){var e,r,n=t===s?">> ":" ",i=(e=String(a).length,r=t,r=String(r),Array(e-r.length).join(" ")+r),o=u[t-1];return""+n+i+"| "+o}).join("\n"));this.message=function(t,e){t=t||"",e.file&&(t+=", file:"+e.file);e.line&&(t+=", line:"+e.line);return t}(n.message,this.token),this.stack=i+"\n"+(this.stack||this.message)+(n.stack?"\nFrom "+n.stack:"")},t}(),F=function(n){function t(t,e){var r=n.call(this,{message:t},e)||this;return n.prototype.captureStackTrace.call(r,r),r}return e(t,n),t}(C);F.prototype=J(Error.prototype),F.prototype.constructor=F;var P=function(n){function t(t,e){var r=n.call(this,t,e)||this;return m(r,t),n.prototype.captureStackTrace.call(r,r),r}return e(t,n),t}(C);P.prototype=J(Error.prototype),P.prototype.constructor=P;var L=function(n){function t(t,e){var r=n.call(this,t,e.token)||this;return m(r,t),n.prototype.captureStackTrace.call(r,r),r}return e(t,n),t}(C);L.prototype=J(Error.prototype),L.prototype.constructor=L;var I=function(t){q.call(this),this.message=t+""};I.prototype=J(Error.prototype),I.prototype.constructor=I;var V=function(t){q.call(this),this.message=t+""};function et(t,e){if(!t)throw new V(e=e||"expect "+t+" to be true")}V.prototype=J(Error.prototype),V.prototype.constructor=V;var $=function(){function t(t,e){void 0===t&&(t={});this.opts=m({dynamicPartials:!0,strict_variables:!1,strict_filters:!1,blocks:{},root:[]},e),this.contexts=[t||{}]}return t.prototype.getAll=function(){return this.contexts.reduce(function(t,e){return m(t,e)},J(null))},t.prototype.get=function(t){var r=this,e=this.propertyAccessSeq(t),n=this.findContextFor(e[0])||y(this.contexts);return e.reduce(function(t,e){return r.readProperty(t,e)},n)},t.prototype.set=function(t,r){var n=this.propertyAccessSeq(t),i=this.findContextFor(n[0])||y(this.contexts);n.some(function(t,e){return!X(i)||(e===n.length-1?(i[t]=r,!0):(void 0===i[t]&&(i[t]={}),void(i=i[t])))})},t.prototype.unshift=function(t){return this.contexts.unshift(t)},t.prototype.push=function(t){return this.contexts.push(t)},t.prototype.pop=function(e){if(!arguments.length)return this.contexts.pop();var t=this.contexts.findIndex(function(t){return t===e});if(-1===t)throw new TypeError("scope not found, cannot pop");return this.contexts.splice(t,1)[0]},t.prototype.findContextFor=function(t,e){void 0===e&&(e=function(t){return!0});for(var r=this.contexts.length-1;0<=r;r--){var n=this.contexts[r];if(e(n)&&t in n)return n}return null},t.prototype.readProperty=function(t,e){var r,n;if(a(t)?r=void 0:(t=function(t){if(s(t.to_liquid))return t.to_liquid();if(s(t.toLiquid))return t.toLiquid();return t}(t),r="size"===e?a((n=t).size)&&(G(n)||W(n))?n.length:n.size:t[e],s(t.liquid_method_missing)&&(r=t.liquid_method_missing(e))),a(r)&&this.opts.strict_variables)throw new TypeError("undefined variable: "+e);return r},t.prototype.propertyAccessSeq=function(t){t=String(t);for(var e,r,n=[],i="",o=0;o<t.length;)switch(t[o]){case"[":u();var s=t[o+1];o=/['"]/.test(s)?(et(-1!==(e=t.indexOf(s,o+2)),"unbalanced "+s+": "+t),i=t.slice(o+2,e),u(),e+2):(et(-1!==(e=Y(t,o+1)),"unbalanced []: "+t),i=t.slice(o+1,e),r=i,_.test(r)||(i=String(this.get(i))),u(),e+1);break;case".":u(),o++;break;default:i+=t[o],o++}if(u(),!n.length)throw new TypeError('invalid path:"'+t+'"');return n;function u(){i.length&&n.push(i),i=""}},t}();function Y(t,e){for(var r=1,n=e;n<t.length;n++)if("["===t[n]&&r++,"]"===t[n]&&0===--r)return n;return-1}function H(t,e,i){return G(e=e||i.root)&&(e=e[0]),e.length&&"/"!==y(e)&&(e+="/"),function(t,e){var r=document.createElement("base");r.href=t;var n=document.getElementsByTagName("head")[0];n.insertBefore(r,n.firstChild);var i=document.createElement("a");i.href=e;var o=i.href;return n.removeChild(r),o}(e,t).replace(/^(\w+:\/\/[^/]+)(\/[^?]+)/,function(t,e,r){var n=r.split("/").pop();return/\.\w+$/.test(n)?t:e+r+i.extname})}function N(o,s,t){et(W(o),"illegal input");for(var r,n,i,e,u,a,c=/({%-?([\s\S]*?)-?%})|({{-?([\s\S]*?)-?}})/g,l=0,p=(r=o,n=0,i=-1,{get:function(t){var e=r.slice(i+1,t).split("\n");return n+=e.length-1,i=t,n+1}}),f=0,h=[],d=void 0;d=c.exec(o);f=c.lastIndex)d.index>f&&h.push(v(f,d.index)),h.push(d[1]?g(d[1],d[2].trim(),d.index):(e=d[3],u=d[4].trim(),a=d.index,{type:"value",line:p.get(a),trim_left:"{{-"===e.slice(0,3),trim_right:"-}}"===e.slice(-3),raw:e,value:u,input:o,file:s}));return o.length>f&&h.push(v(f,o.length)),function(s,u){u=m({greedy:!0},u);var a=!1;s.forEach(function(t,e){var r,n,i,o;i=t,o=u,!a&&("tag"===i.type?i.trim_left||o.trim_tag_left:"value"===i.type?i.trim_left||o.trim_value_left:void 0)&&function(t,e){if(t&&"html"===t.type){var r=e?/\s+$/g:/[\t\r ]*$/g;t.value=t.value.replace(r,"")}}(s[e-1],u.greedy),"tag"===t.type&&"raw"===t.name&&(a=!0),"tag"===t.type&&"endraw"===t.name&&(a=!1),r=t,n=u,!a&&("tag"===r.type?r.trim_right||n.trim_tag_right:"value"===r.type?r.trim_right||n.trim_value_right:void 0)&&function(t,e){if(t&&"html"===t.type){var r=e?/^\s+/g:/^[\t\r ]*\n?/g;t.value=t.value.replace(r,"")}}(s[e+1],u.greedy)})}(h,t),h;function g(t,e,r){var n=e.match(b),i={type:"tag",indent:l,line:p.get(r),trim_left:"{%-"===t.slice(0,3),trim_right:"-%}"===t.slice(-3),raw:t,value:e,input:o,file:s};if(!n)throw new F("illegal tag syntax",i);return i.name=n[1],i.args=n[2],i}function v(t,e){var r=o.slice(t,e);return l=y(r.split("\n")).length,{type:"html",raw:r,value:r}}}var z,rt=(z=ot,{"==":function(t,e){return t===e},"!=":function(t,e){return t!==e},">":function(t,e){return null!==t&&null!==e&&e<t},"<":function(t,e){return null!==t&&null!==e&&t<e},">=":function(t,e){return null!==t&&null!==e&&e<=t},"<=":function(t,e){return null!==t&&null!==e&&t<=e},contains:function(t,e){return!!t&&"function"==typeof t.indexOf&&-1<t.indexOf(e)},and:function(t,e){return z(t)&&z(e)},or:function(t,e){return z(t)||z(e)}});function nt(t,e){et(e,"unable to evalExp: scope undefined");for(var r,n=D,i=0;i<n.length;i++){var o=n[i],s=new RegExp("^("+f.source+")("+o.source+")("+f.source+")$");if(r=t.match(s)){var u=nt(r[1],e);return(0,rt[r[2].trim()])(u,nt(r[3],e))}}if(r=t.match(S)){for(var a=it(r[1],e),c=it(r[2],e),l=[],p=a;p<=c;p++)l.push(p);return l}return it(t,e)}function it(t,e){if(t=t&&t.trim()){if(r=t,x.test(r))return function(t){var e=t.match(E);if(e)return Number(t);if(e=t.match(k))return"true"===t.toLowerCase();if(e=t.match(tt))return t.slice(1,-1);throw new TypeError("cannot parse '"+t+"' as literal")}(t);var r,n;if(n=t,T.test(n))return e.get(t);throw new TypeError("cannot eval '"+t+"' as value")}}function ot(t){return!st(t)}function st(t){return!1===t||null==t}var ut={renderTemplates:function(u,a){return B(this,void 0,void 0,function(){var e,r,n,i,o,s;return U(this,function(t){switch(t.label){case 0:et(a,"unable to evalTemplates: scope undefined"),e="",r=0,n=u,t.label=1;case 1:if(!(r<n.length))return[3,6];i=n[r],t.label=2;case 2:return t.trys.push([2,4,,5]),o=e,[4,function(r){return B(this,void 0,void 0,function(){var e;return U(this,function(t){switch(t.label){case 0:return"tag"!==r.type?[3,2]:[4,this.renderTag(r,a)];case 1:return[2,void 0===(e=t.sent())?"":e];case 2:return"value"===r.type?[2,this.renderValue(r,a)]:[2,r.value]}})})}.call(this,i)];case 3:return e=o+t.sent(),[3,5];case 4:if((s=t.sent())instanceof I)throw s.resolvedHTML=e,s;throw s instanceof L?s:new L(s,i);case 5:return r++,[3,1];case 6:return[2,e]}})})},renderTag:function(e,r){return B(this,void 0,void 0,function(){return U(this,function(t){if("continue"===e.name)throw new I("continue");if("break"===e.name)throw new I("break");return[2,e.render(r)]})})},renderValue:function(r,n){return B(this,void 0,void 0,function(){var e;return U(this,function(t){return[2,void 0===(e=this.evalValue(r,n))?"":u(e)]})})},evalValue:function(t,r){return et(r,"unable to evalValue: scope undefined"),t.filters.reduce(function(t,e){return e.render(t,r)},nt(t.initial,r))}};function at(){var n={},i={render:function(n){return B(this,void 0,void 0,function(){var e,r;return U(this,function(t){return e=function(t,e){var r,n={};for(w.lastIndex=0;r=w.exec(t);){var i=r[1],o=r[2];n[i]=it(o,e)}return n}(this.token.args,n),"function"!=typeof(r=this.tagImpl).render?[2,""]:[2,r.render(n,e)]})})},parse:function(t,e){this.type="tag",this.token=t,this.name=t.name;var r=n[this.name];et(r,"tag "+this.name+" not found"),this.tagImpl=J(r),this.tagImpl.parse&&this.tagImpl.parse(t,e)}};return{construct:function(t,e){var r=J(i);return r.parse(t,e),r},register:function(t,e){n[t]=e},clear:function(){n={}}}}var ct=new RegExp(""+Q.source,"g");function lt(r,o){var e=function(){function t(t){this.tokens=t,this.handlers={}}return t.prototype.on=function(t,e){return this.handlers[t]=e,this},t.prototype.trigger=function(t,e){var r=this.handlers[t];if("function"==typeof r)return r(e),!0},t.prototype.start=function(){var t;for(this.trigger("start");!this.stopRequested&&(t=this.tokens.shift());)if(!(this.trigger("token",t)||"tag"===t.type&&this.trigger("tag:"+t.name,t))){var e=n(t,this.tokens);this.trigger("template",e)}return this.stopRequested||this.trigger("end"),this},t.prototype.stop=function(){return this.stopRequested=!0,this},t}();function n(e,t){try{var r=null;return(r="tag"===e.type?i(e,t):"value"===e.type?s(e.value):e).token=e,r}catch(t){throw new P(t,e)}}function i(t,e){return"continue"===t.name||"break"===t.name?t:r.construct(t,e)}function s(t){var e,r=(e=t,Q.exec(e));et(r,"illegal value string: "+t);var n=r[0];t=t.substr(r.index+r[0].length);for(var i=[];r=O.exec(t);)i.push([r[0].trim()]);return{type:"value",initial:n,filters:i.map(function(t){return o.construct(t)})}}return{parse:function(t){for(var e,r=[];e=t.shift();)r.push(n(e,t));return r},parseTag:i,parseStream:function(t){return new e(t)},parseValue:s}}function pt(r,n){var i=Promise.resolve("init"),o=[];return r.forEach(function(t,e){i=i.then(function(){return n(t,e,r)}).then(function(t){return o.push(t)})}),i.then(function(){return o})}var ft=/[^\s,]+/;function ht(t,e){var r,n,i,o,s,u,a,c,l,p,f,h,d,g,v,m,y,w,b,x,T,E,k,S,_,R,M,O,j,A,D,q,C,F,P,L,I,V,$,Y,H,N,z;r=t,n=e,i=new RegExp("("+K.source+")\\s*=([^]*)"),o=n.Types.AssignScope,r.registerTag("assign",{parse:function(t){var e=t.args.match(i);et(e,"illegal token "+t.raw),this.key=e[1],this.value=e[2]},render:function(t){var e=J(o);return e[this.key]=r.evalValue(this.value,t),t.push(e),Promise.resolve("")}}),s=t,u=e,a=new RegExp("("+K.source+")"),c=u.Types.CaptureScope,s.registerTag("capture",{parse:function(e,t){var r=this,n=e.args.match(a);et(n,e.args+" not valid identifier"),this.variable=n[1],this.templates=[];var i=s.parser.parseStream(t);i.on("tag:endcapture",function(t){return i.stop()}).on("template",function(t){return r.templates.push(t)}).on("end",function(t){throw new Error("tag "+e.raw+" not closed")}),i.start()},render:function(n,t){return B(this,void 0,void 0,function(){var e,r;return U(this,function(t){switch(t.label){case 0:return[4,s.renderer.renderTemplates(this.templates,n)];case 1:return e=t.sent(),(r=J(c))[this.variable]=e,n.push(r),[2]}})})}}),p=e,(l=t).registerTag("case",{parse:function(e,t){var r=this;this.cond=e.args,this.cases=[],this.elseTemplates=[];var n=[],i=l.parser.parseStream(t).on("tag:when",function(t){r.cases.push({val:t.args,templates:n=[]})}).on("tag:else",function(){return n=r.elseTemplates}).on("tag:endcase",function(t){return i.stop()}).on("template",function(t){return n.push(t)}).on("end",function(t){throw new Error("tag "+e.raw+" not closed")});i.start()},render:function(t,e){for(var r=0;r<this.cases.length;r++){var n=this.cases[r];if(p.evalExp(n.val,t)===p.evalExp(this.cond,t))return l.renderer.renderTemplates(n.templates,t)}return l.renderer.renderTemplates(this.elseTemplates,t)}}),(f=t).registerTag("comment",{parse:function(e,t){var r=f.parser.parseStream(t);r.on("token",function(t){"endcomment"===t.name&&r.stop()}).on("end",function(t){throw new Error("tag "+e.raw+" not closed")}),r.start()}}),h=t,d=e,g=new RegExp("^(?:("+Q.source+")\\s*:\\s*)?(.*)$"),v=new RegExp(Q.source,"g"),h.registerTag("cycle",{parse:function(t,e){var r=g.exec(t.args);et(r,"illegal tag: "+t.raw),this.group=r[1]||"";var n=r[2];for(this.candidates=[];r=v.exec(n);)this.candidates.push(r[0]);et(this.candidates.length,"empty candidates: "+t.raw)},render:function(t,e){var r="cycle:"+d.evalValue(this.group,t)+":"+this.candidates.join(","),n=t.opts.groups=t.opts.groups||{},i=n[r];void 0===i&&(i=n[r]=0);var o=this.candidates[i];return i=(i+1)%this.candidates.length,n[r]=i,d.evalValue(o,t)}}),m=t,y=e.Types,w=y.CaptureScope,b=y.AssignScope,x=y.DecrementScope,m.registerTag("decrement",{parse:function(t){var e=t.args.match(K);et(e,"illegal identifier "+t.args),this.variable=e[0]},render:function(t,e){var r=t.findContextFor(this.variable,function(t){var e=Object.getPrototypeOf(t);return e!==w&&e!==b});return r||(r=J(x),t.unshift(r)),"number"!=typeof r[this.variable]&&(r[this.variable]=0),--r[this.variable]}}),T=t,k=(E=e).Types.RenderBreakError,S=new RegExp("^("+K.source+")\\s+in\\s+("+Q.source+")(?:\\s+"+Z.source+")*(?:\\s+(reversed))?(?:\\s+"+Z.source+")*$"),T.registerTag("for",{parse:function(t,e){var r,n=this,i=S.exec(t.args);et(i,"illegal tag: "+t.raw),this.variable=i[1],this.collection=i[2],this.reversed=!!i[3],this.templates=[],this.elseTemplates=[];var o=T.parser.parseStream(e).on("start",function(){return r=n.templates}).on("tag:else",function(){return r=n.elseTemplates}).on("tag:endfor",function(){return o.stop()}).on("template",function(t){return r.push(t)}).on("end",function(){throw new Error("tag "+t.raw+" not closed")});o.start()},render:function(a,c){return B(this,void 0,void 0,function(){var n,e,r,i,o,s,u=this;return U(this,function(t){switch(t.label){case 0:return G(n=E.evalExp(this.collection,a))||(W(n)&&0<n.length?n=[n]:X(n)&&(n=Object.keys(n).map(function(t){return[t,n[t]]}))),G(n)&&n.length?(e=c.offset||0,r=void 0===c.limit?n.length:c.limit,n=n.slice(e,e+r),this.reversed&&n.reverse(),i=n.map(function(t,e){var r={};return r[u.variable]=t,r.forloop={first:0===e,index:e+1,index0:e,last:e===n.length-1,length:n.length,rindex:n.length-e,rindex0:n.length-e-1},r}),o="",s=!1,[4,pt(i,function(n){return B(u,void 0,void 0,function(){var e,r;return U(this,function(t){switch(t.label){case 0:if(s)return[2];a.push(n),t.label=1;case 1:return t.trys.push([1,3,,4]),e=o,[4,T.renderer.renderTemplates(this.templates,a)];case 2:return o=e+t.sent(),[3,4];case 3:if(!((r=t.sent())instanceof k))throw r;return o+=r.resolvedHTML,"break"===r.message&&(s=!0),[3,4];case 4:return a.pop(n),[2]}})})})]):[2,T.renderer.renderTemplates(this.elseTemplates,a)];case 1:return t.sent(),[2,o]}})})}}),R=e,(_=t).registerTag("if",{parse:function(e,t){var r,n=this;this.branches=[],this.elseTemplates=[];var i=_.parser.parseStream(t).on("start",function(){return n.branches.push({cond:e.args,templates:r=[]})}).on("tag:elsif",function(t){n.branches.push({cond:t.args,templates:r=[]})}).on("tag:else",function(){return r=n.elseTemplates}).on("tag:endif",function(t){return i.stop()}).on("template",function(t){return r.push(t)}).on("end",function(t){throw new Error("tag "+e.raw+" not closed")});i.start()},render:function(t,e){for(var r=0,n=this.branches;r<n.length;r++){var i=n[r],o=R.evalExp(i.cond,t);if(R.isTruthy(o))return _.renderer.renderTemplates(i.templates,t)}return _.renderer.renderTemplates(this.elseTemplates,t)}}),M=t,O=e,j=new RegExp("with\\s+("+Q.source+")"),M.registerTag("include",{parse:function(t){var e=ft.exec(t.args);e&&(this.staticValue=e[0]),(e=Q.exec(t.args))&&(this.value=e[0]),(e=j.exec(t.args))&&(this.with=e[1])},render:function(u,a){return B(this,void 0,void 0,function(){var e,r,n,i,o,s;return U(this,function(t){switch(t.label){case 0:return u.opts.dynamicPartials?tt.exec(this.value)?(r=this.value.slice(1,-1),[4,M.parseAndRender(r,u.getAll(),u.opts)]):[3,2]:[3,4];case 1:return e=t.sent(),[3,3];case 2:e=O.evalValue(this.value,u),t.label=3;case 3:return[3,5];case 4:e=this.staticValue,t.label=5;case 5:return et(e,"cannot include with empty filename"),n=u.opts.blocks,i=u.opts.blockMode,u.opts.blocks={},u.opts.blockMode="output",this.with&&(a[e]=O.evalValue(this.with,u)),[4,M.getTemplate(e,u.opts.root)];case 6:return o=t.sent(),u.push(a),[4,M.renderer.renderTemplates(o,u)];case 7:return s=t.sent(),u.pop(a),u.opts.blocks=n,u.opts.blockMode=i,[2,s]}})})}}),A=t,D=e.Types,q=D.CaptureScope,C=D.AssignScope,F=D.IncrementScope,A.registerTag("increment",{parse:function(t){var e=t.args.match(K);et(e,"illegal identifier "+t.args),this.variable=e[0]},render:function(t,e){var r=t.findContextFor(this.variable,function(t){var e=Object.getPrototypeOf(t);return e!==q&&e!==C});r||(r=J(F),t.unshift(r)),"number"!=typeof r[this.variable]&&(r[this.variable]=0);var n=r[this.variable];return r[this.variable]++,n}}),L=e,I=/\S+/,(P=t).registerTag("layout",{parse:function(t,e){var r=I.exec(t.args);r&&(this.staticLayout=r[0]),(r=Q.exec(t.args))&&(this.layout=r[0]),this.tpls=P.parser.parse(e)},render:function(o,s){return B(this,void 0,void 0,function(){var e,r,n,i;return U(this,function(t){switch(t.label){case 0:return et(e=o.opts.dynamicPartials?L.evalValue(this.layout,o):this.staticLayout,"cannot apply layout with empty filename"),o.opts.blockMode="store",[4,P.renderer.renderTemplates(this.tpls,o)];case 1:return r=t.sent(),void 0===o.opts.blocks[""]&&(o.opts.blocks[""]=r),[4,P.getTemplate(e,o.opts.root)];case 2:return n=t.sent(),o.push(s),o.opts.blockMode="output",[4,P.renderer.renderTemplates(n,o)];case 3:return i=t.sent(),o.pop(s),[2,i]}})})}}),P.registerTag("block",{parse:function(t,e){var r=this,n=/\w+/.exec(t.args);this.block=n?n[0]:"",this.tpls=[];var i=P.parser.parseStream(e).on("tag:endblock",function(){return i.stop()}).on("template",function(t){return r.tpls.push(t)}).on("end",function(){throw new Error("tag "+t.raw+" not closed")});i.start()},render:function(i){return B(this,void 0,void 0,function(){var e,r,n;return U(this,function(t){switch(t.label){case 0:return void 0===(e=i.opts.blocks[this.block])?[3,1]:(n=e,[3,3]);case 1:return[4,P.renderer.renderTemplates(this.tpls,i)];case 2:n=t.sent(),t.label=3;case 3:return r=n,"store"===i.opts.blockMode?(i.opts.blocks[this.block]=r,[2,""]):[2,r]}})})}}),(V=t).registerTag("raw",{parse:function(t,e){var r=this;this.tokens=[];var n=V.parser.parseStream(e);n.on("token",function(t){"endraw"===t.name?n.stop():r.tokens.push(t)}).on("end",function(){throw new Error("tag "+t.raw+" not closed")}),n.start()},render:function(t,e){return this.tokens.map(function(t){return t.raw}).join("")}}),$=t,Y=e,H=new RegExp("^("+K.source+")\\s+in\\s+("+Q.source+")(?:\\s+"+Z.source+")*$"),$.registerTag("tablerow",{parse:function(t,e){var r,n=this,i=H.exec(t.args);et(i,"illegal tag: "+t.raw),this.variable=i[1],this.collection=i[2],this.templates=[];var o=$.parser.parseStream(e).on("start",function(){return r=n.templates}).on("tag:endtablerow",function(t){return o.stop()}).on("template",function(t){return r.push(t)}).on("end",function(){throw new Error("tag "+t.raw+" not closed")});o.start()},render:function(c,l){return B(this,void 0,void 0,function(){var e,r,n,o,i,s,u,a=this;return U(this,function(t){switch(t.label){case 0:return e=Y.evalExp(this.collection,c)||[],r=l.offset||0,n=void 0===l.limit?e.length:l.limit,e=e.slice(r,r+n),o=l.cols||e.length,i=e.map(function(t,e){var r={};return r[a.variable]=t,r}),u="",[4,pt(i,function(n,i){return B(a,void 0,void 0,function(){var e,r;return U(this,function(t){switch(t.label){case 0:return s=Math.floor(i/o)+1,1==(e=i%o+1)&&(1!==s&&(u+="</tr>"),u+='<tr class="row'+s+'">'),u+='<td class="col'+e+'">',c.push(n),r=u,[4,$.renderer.renderTemplates(this.templates,c)];case 1:return u=r+t.sent(),u+="</td>",c.pop(n),[2,u]}})})})];case 1:return t.sent(),0<s&&(u+="</tr>"),[2,u]}})})}}),z=e,(N=t).registerTag("unless",{parse:function(e,t){var r,n=this;this.templates=[],this.elseTemplates=[];var i=N.parser.parseStream(t).on("start",function(t){r=n.templates,n.cond=e.args}).on("tag:else",function(){return r=n.elseTemplates}).on("tag:endunless",function(t){return i.stop()}).on("template",function(t){return r.push(t)}).on("end",function(t){throw new Error("tag "+e.raw+" not closed")});i.start()},render:function(t,e){var r=z.evalExp(this.cond,t);return z.isFalsy(r)?N.renderer.renderTemplates(this.templates,t):N.renderer.renderTemplates(this.elseTemplates,t)}})}var dt=["January","February","March","April","May","June","July","August","September","October","November","December"],gt=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],vt=dt.map(wt),mt=gt.map(wt),yt={1:"st",2:"nd",3:"rd",default:"th"};function wt(t){return t.slice(0,3)}var bt={daysInMonth:function(t){return[31,bt.isLeapYear(t)?29:28,31,30,31,30,31,31,30,31,30,31]},getDayOfYear:function(t){for(var e=0,r=0;r<t.getMonth();++r)e+=bt.daysInMonth(t)[r];return e+t.getDate()},getWeekOfYear:function(t,e){var r=this.getDayOfYear(t)+(e-t.getDay()),n=7-new Date(t.getFullYear(),0,1).getDay()+e;return xt.pad(Math.floor((r-n)/7)+1,2)},isLeapYear:function(t){var e=t.getFullYear();return!(0!=(3&e)||!(e%100||e%400==0&&e))},getSuffix:function(t){var e=t.getDate().toString(),r=parseInt(e.slice(-1));return yt[r]||yt.default},century:function(t){return parseInt(t.getFullYear().toString().substring(0,2),10)}},xt={pad:function(t,e,r){r||(r="0");for(var n=t.toString(),i=e-n.length;0<i--;)n=r+n;return n}},Tt={a:function(t){return mt[t.getDay()]},A:function(t){return gt[t.getDay()]},b:function(t){return vt[t.getMonth()]},B:function(t){return dt[t.getMonth()]},c:function(t){return t.toLocaleString()},C:function(t){return bt.century(t)},d:function(t){return xt.pad(t.getDate(),2)},e:function(t){return xt.pad(t.getDate(),2," ")},H:function(t){return xt.pad(t.getHours(),2)},I:function(t){return xt.pad(t.getHours()%12||12,2)},j:function(t){return xt.pad(bt.getDayOfYear(t),3)},k:function(t){return xt.pad(t.getHours(),2," ")},l:function(t){return xt.pad(t.getHours()%12||12,2," ")},L:function(t){return xt.pad(t.getMilliseconds(),3)},m:function(t){return xt.pad(t.getMonth()+1,2)},M:function(t){return xt.pad(t.getMinutes(),2)},p:function(t){return t.getHours()<12?"AM":"PM"},P:function(t){return t.getHours()<12?"am":"pm"},q:function(t){return bt.getSuffix(t)},s:function(t){return Math.round(t.valueOf()/1e3)},S:function(t){return xt.pad(t.getSeconds(),2)},u:function(t){return t.getDay()||7},U:function(t){return bt.getWeekOfYear(t,0)},w:function(t){return t.getDay()},W:function(t){return bt.getWeekOfYear(t,1)},x:function(t){return t.toLocaleDateString()},X:function(t){return t.toLocaleTimeString()},y:function(t){return t.getFullYear().toString().substring(2,4)},Y:function(t){return t.getFullYear()},z:function(t){var e=t.getTimezoneOffset()/60*100;return(0<e?"-":"+")+xt.pad(Math.abs(e),4)},"%":function(){return"%"}};Tt.h=Tt.b,Tt.N=Tt.L;var Et={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&#34;","'":"&#39;"},kt={"&amp;":"&","&lt;":"<","&gt;":">","&#34;":'"',"&#39;":"'"},St={abs:function(t){return Math.abs(t)},append:function(t,e){return t+e},capitalize:function(t){return Mt(t).charAt(0).toUpperCase()+t.slice(1)},ceil:function(t){return Math.ceil(t)},concat:function(t,e){return Array.prototype.concat.call(t,e)},date:function(t,e){var r,n=t;return"now"===t?n=new Date:W(t)&&(n=new Date(t)),(r=n)instanceof Date&&!isNaN(r.getTime())?function(t,e){for(var r="",n=e;;){var i=/%./g,o=i.exec(n);if(!o)return r+n;r+=n.slice(0,i.lastIndex-2),n=n.slice(i.lastIndex);var s=o[0].charAt(1),u=Tt[s];r+=u?u.call(this,t):"%"+s}}(n,e):t},default:function(t,e){return ot(t)?t:e},divided_by:function(t,e){return t/e},downcase:function(t){return t.toLowerCase()},escape:_t,escape_once:function(t){return _t(Mt(t).replace(/&(amp|lt|gt|#34|#39);/g,function(t){return kt[t]}))},first:function(t){return t[0]},floor:function(t){return Math.floor(t)},join:function(t,e){return t.join(void 0===e?" ":e)},last:function(t){return y(t)},lstrip:function(t){return Mt(t).replace(/^\s+/,"")},map:function(t,e){return t.map(function(t){return t[e]})},minus:Ot(function(t,e){return t-e}),modulo:Ot(function(t,e){return t%e}),newline_to_br:function(t){return t.replace(/\n/g,"<br />")},plus:Ot(function(t,e){return Number(t)+Number(e)}),prepend:function(t,e){return e+t},remove:function(t,e){return t.split(e).join("")},remove_first:function(t,e){return t.replace(e,"")},replace:function(t,e,r){return Mt(t).split(e).join(r)},replace_first:function(t,e,r){return Mt(t).replace(e,r)},reverse:function(t){return t.reverse()},round:function(t,e){var r=Math.pow(10,e||0);return Math.round(t*r,e)/r},rstrip:function(t){return Mt(t).replace(/\s+$/,"")},size:function(t){return t.length},slice:function(t,e,r){return void 0===r&&(r=1),t.slice(e,e+r)},sort:function(t,e){return t.sort(e)},split:function(t,e){return Mt(t).split(e)},strip:function(t){return Mt(t).trim()},strip_html:function(t){return Mt(t).replace(/<script.*?<\/script>|<!--.*?-->|<style.*?<\/style>|<.*?>/g,"")},strip_newlines:function(t){return Mt(t).replace(/\n/g,"")},times:function(t,e){return t*e},truncate:function(t,e,r){return r=void 0===r?"...":r,e=e||16,(t=Mt(t)).length<=e?t:t.substr(0,e-r.length)+r},truncatewords:function(t,e,r){void 0===r&&(r="...");var n=t.split(" "),i=n.slice(0,e).join(" ");return n.length>e&&(i+=r),i},uniq:function(t){var e={};return(t||[]).filter(function(t){return!e.hasOwnProperty(t)&&(e[t]=!0)})},upcase:function(t){return Mt(t).toUpperCase()},url_decode:function(t){return t.split("+").map(decodeURIComponent).join(" ")},url_encode:function(t){return t.split(" ").map(encodeURIComponent).join("+")}};function _t(t){return Mt(t).replace(/&|<|>|"|'/g,function(t){return Et[t]})}function Rt(t){var e=(t+"").split(".");return 1<e.length?e[1].length:0}function Mt(t){return t+""}function Ot(o){return function(t,e){var r,n,i=(r=t,n=e,Math.max(Rt(r),Rt(n)));return o(t,e).toFixed(i)}}function jt(r,t){return function(t,e){for(var r in t=t||{})if(t.hasOwnProperty(r)&&!1===e(t[r],r,t))break;return t}(St,function(t,e){return r.registerFilter(e,t)})}return jt.filters=St,function(){function e(t){(t=m({root:["."],cache:!1,extname:"",dynamicPartials:!0,trim_tag_right:!1,trim_tag_left:!1,trim_value_right:!1,trim_value_left:!1,greedy:!0,strict_filters:!1,strict_variables:!1},t)).root=function(t){if(G(t))return t;if(W(t))return[t];throw new TypeError("illegal root: "+t)}(t.root),t.cache&&(this.cache={}),this.options=t,this.tags=at(),this.filters=function(a){a=m({},a);var c={},e={render:function(t,e){var r=this.args.map(function(t){return it(t,e)});return r.unshift(t),this.filter.apply(null,r)},parse:function(t){var e=A.exec(t);et(e,"illegal filter: "+t);var r=e[1],n=e[2]||"",i=c[r];if("function"!=typeof i){if(a.strict_filters)throw new TypeError("undefined filter: "+r);return this.name=r,this.filter=function(t){return t},this.args=[],this}for(var o=[];e=ct.exec(n.trim());){var s=e[0],u=new RegExp(s+"\\s*:","g").exec(e.input);u&&u.index===e.index?o.push("'"+s+"'"):o.push(s)}return this.name=r,this.filter=i,this.args=o,this}};return{construct:function(t){return J(e).parse(t)},register:function(t,e){c[t]=e},clear:function(){c={}}}}(t),this.parser=lt(this.tags,this.filters),this.renderer=J(ut),ht(this,e),jt(this)}return e.prototype.parse=function(t,e){var r=N(t,e,this.options);return this.parser.parse(r)},e.prototype.render=function(t,e,r){r=m({},this.options,r);var n=new $(e,r);return this.renderer.renderTemplates(t,n)},e.prototype.parseAndRender=function(r,n,i){return B(this,void 0,void 0,function(){var e;return U(this,function(t){switch(t.label){case 0:return[4,this.parse(r)];case 1:return e=t.sent(),[2,this.render(e,n,i)]}})})},e.prototype.getTemplate=function(n,i){return B(this,void 0,void 0,function(){var r,e=this;return U(this,function(t){switch(t.label){case 0:return[4,H(n,i,this.options)];case 1:return r=t.sent(),[2,this.respectCache(r,function(){return B(e,void 0,void 0,function(){var e;return U(this,function(t){switch(t.label){case 0:return[4,function(n){return B(this,void 0,void 0,function(){return U(this,function(t){return[2,new Promise(function(t,e){var r=new XMLHttpRequest;r.onload=function(){200<=r.status&&r.status<300?t(r.responseText):e(new Error(r.statusText))},r.onerror=function(){e(new Error("An error occurred whilst receiving the response."))},r.open("GET",n),r.send()})]})})}(r)];case 1:return e=t.sent(),[2,this.parse(e,r)]}})})})]}})})},e.prototype.renderFile=function(r,n,i){return B(this,void 0,void 0,function(){var e;return U(this,function(t){switch(t.label){case 0:return i=m({},i),[4,this.getTemplate(r,i.root)];case 1:return e=t.sent(),[2,this.render(e,n,i)]}})})},e.prototype.respectCache=function(n,i){return B(this,void 0,void 0,function(){var e,r;return U(this,function(t){switch(t.label){case 0:return(e=this.options.cache)&&this.cache[n]?[2,this.cache[n]]:[4,i()];case 1:return r=t.sent(),e&&(this.cache[n]=r),[2,r]}})})},e.prototype.evalValue=function(t,e){var r=this.parser.parseValue(t.trim());return this.renderer.evalValue(r,e)},e.prototype.registerFilter=function(t,e){return this.filters.register(t,e)},e.prototype.registerTag=function(t,e){return this.tags.register(t,e)},e.prototype.plugin=function(t){return t.call(this,e)},e.prototype.express=function(n){n=n||{};var i=this;return function(t,e,r){et(G(this.root)||W(this.root),"illegal views root, are you using express.js?"),n.root=this.root,i.renderFile(t,e,n).then(function(t){return r(null,t)},r)}},(e.default=e).isTruthy=ot,e.isFalsy=st,e.evalExp=nt,e.evalValue=it,e.Types={ParseError:P,TokenizationError:F,RenderBreakError:I,AssertionError:V,AssignScope:{},CaptureScope:{},IncrementScope:{},DecrementScope:{}},e}()});
//# sourceMappingURL=liquid.min.js.map