dropkiq
Version:
Liquid Expressions Simplified
1 lines • 1.93 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var ParseState,whitespace_ctrl_1=require("./whitespace-ctrl"),html_token_1=require("./html-token"),tag_token_1=require("./tag-token"),token_1=require("./token"),output_token_1=require("./output-token"),error_1=require("../util/error"),liquid_options_1=require("../liquid-options"),node_1=require("./flatten/node");!function(e){e[e.HTML=0]="HTML",e[e.OUTPUT=1]="OUTPUT",e[e.TAG=2]="TAG"}(ParseState||(ParseState={}));var Tokenizer=function(){function e(e){this.options=liquid_options_1.applyDefault(e)}return e.prototype.tokenize=function(e,t){for(var n=[],o=this.options,r=o.tagDelimiterLeft,i=o.tagDelimiterRight,s=o.outputDelimiterLeft,a=o.outputDelimiterRight,u=0,l=1,_=ParseState.HTML,h="",T=0,p=1,k=1;u<e.length;){if("\n"===e[u]&&(l++,T=u+1),_===ParseState.HTML){if(e.substr(u,s.length)===s){h&&n.push(new html_token_1.HTMLToken(node_1.flatten(h),e,p,k,t)),h=s,p=l,k=u-T+1,u+=s.length,_=ParseState.OUTPUT;continue}if(e.substr(u,r.length)===r){h&&n.push(new html_token_1.HTMLToken(node_1.flatten(h),e,p,k,t)),h=r,p=l,k=u-T+1,u+=r.length,_=ParseState.TAG;continue}}else{if(_===ParseState.OUTPUT&&e.substr(u,a.length)===a){h+=a,n.push(new output_token_1.OutputToken(node_1.flatten(h),h.slice(s.length,-a.length),e,p,k,this.options,t)),h="",p=l,k=(u+=a.length)-T+1,_=ParseState.HTML;continue}if(e.substr(u,i.length)===i){h+=i,n.push(new tag_token_1.TagToken(node_1.flatten(h),h.slice(r.length,-i.length),e,p,k,this.options,t)),h="",p=l,k=(u+=i.length)-T+1,_=ParseState.HTML;continue}}h+=e[u++]}if(_!==ParseState.HTML){var g=_===ParseState.OUTPUT?"output":"tag",f=h.length>16?h.slice(0,13)+"...":h;throw new error_1.TokenizationError(g+' "'+f+'" not closed',new token_1.Token(node_1.flatten(h),e,p,k,t))}return h&&n.push(new html_token_1.HTMLToken(node_1.flatten(h),e,p,k,t)),whitespace_ctrl_1.whiteSpaceCtrl(n,this.options),n},e}();exports.Tokenizer=Tokenizer;