parser-vue.js 6 KB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t.prettierPlugins=t.prettierPlugins||{},t.prettierPlugins.vue=e())}(this,function(){"use strict";var t="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function e(){throw new Error("setTimeout has not been defined")}function n(){throw new Error("clearTimeout has not been defined")}var r=e,o=n;function a(t){if(r===setTimeout)return setTimeout(t,0);if((r===e||!r)&&setTimeout)return r=setTimeout,setTimeout(t,0);try{return r(t,0)}catch(e){try{return r.call(null,t,0)}catch(e){return r.call(this,t,0)}}}"function"==typeof t.setTimeout&&(r=setTimeout),"function"==typeof t.clearTimeout&&(o=clearTimeout);var i,u=[],c=!1,s=-1;function l(){c&&i&&(c=!1,i.length?u=i.concat(u):s=-1,u.length&&f())}function f(){if(!c){var t=a(l);c=!0;for(var e=u.length;e;){for(i=u,u=[];++s<e;)i&&i[s].run();s=-1,e=u.length}i=null,c=!1,function(t){if(o===clearTimeout)return clearTimeout(t);if((o===n||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(t);try{o(t)}catch(e){try{return o.call(null,t)}catch(e){return o.call(this,t)}}}(t)}}function h(t,e){this.fun=t,this.array=e}h.prototype.run=function(){this.fun.apply(null,this.array)};function d(){}var g=d,p=d,m=d,v=d,w=d,y=d,T=d;var b=t.performance||{},x=b.now||b.mozNow||b.msNow||b.oNow||b.webkitNow||function(){return(new Date).getTime()};var E=new Date;var N={nextTick:function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];u.push(new h(t,e)),1!==u.length||c||a(f)},title:"browser",browser:!0,env:{},argv:[],version:"",versions:{},on:g,addListener:p,once:m,off:v,removeListener:w,removeAllListeners:y,emit:T,binding:function(t){throw new Error("process.binding is not supported")},cwd:function(){return"/"},chdir:function(t){throw new Error("process.chdir is not supported")},umask:function(){return 0},hrtime:function(t){var e=.001*x.call(b),n=Math.floor(e),r=Math.floor(e%1*1e9);return t&&(n-=t[0],(r-=t[1])<0&&(n--,r+=1e9)),[n,r]},platform:"browser",release:{},config:{},uptime:function(){return(new Date-E)/1e3}};function O(t,e){for(var n=Object.create(null),r=t.split(","),o=0;o<r.length;o++)n[r[o]]=!0;return e?function(t){return n[t.toLowerCase()]}:function(t){return n[t]}}var C=function(){return!1},D=O("address,article,aside,base,blockquote,body,caption,col,colgroup,dd,details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,title,tr,track"),L=/^\s*([^\s"'<>/=]+)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/,S="[a-zA-Z_][\\w\\-\\.]*",k="((?:".concat(S,"\\:)?").concat(S,")"),A=new RegExp("^<".concat(k)),q=/^\s*(\/?)>/,M=new RegExp("^<\\/".concat(k,"[^>]*>")),P=/^<!DOCTYPE [^>]+>/i,R=/^<!--/,_=/^<!\[/,j=!1;"x".replace(/x(.)?/g,function(t,e){j=""===e});var z=O("script,style,textarea",!0),F={},H={"&lt;":"<","&gt;":">","&quot;":'"',"&amp;":"&","&#10;":"\n","&#9;":"\t"},V=/&(?:lt|gt|quot|amp);/g,$=/&(?:lt|gt|quot|amp|#10|#9);/g,B=O("pre,textarea",!0),K=function(t,e){return t&&B(t)&&"\n"===e[0]};function U(t,e){var n=e?$:V;return t.replace(n,function(t){return H[t]})}return{parsers:{vue:{parse:function(t){var e={tag:"root",attrs:[],unary:!1,start:0,contentStart:0,contentEnd:t.length,end:t.length,children:[],comments:[]},n=[e],r=e;return function(t,e){for(var n,r,o=[],a=e.expectHTML,i=e.isUnaryTag||C,u=e.canBeLeftOpenTag||C,c=0;t;){if(n=t,r&&z(r))!function(){var n=0,o=r.toLowerCase(),a=F[o]||(F[o]=new RegExp("([\\s\\S]*?)(</"+o+"[^>]*>)","i")),i=t.replace(a,function(t,r,a){return n=a.length,z(o)||"noscript"===o||(r=r.replace(/<!--([\s\S]*?)-->/g,"$1").replace(/<!\[CDATA\[([\s\S]*?)]]>/g,"$1")),K(o,r)&&(r=r.slice(1)),e.chars&&e.chars(r),""});c+=t.length-i.length,t=i,x(o,c-n,c)}();else{var s=t.indexOf("<");if(0===s){if(R.test(t)){var l=t.indexOf("--\x3e");if(l>=0){e.shouldKeepComment&&e.comment(t.substring(4,l)),y(l+3);continue}}if(_.test(t)){var f=t.indexOf("]>");if(f>=0){y(f+2);continue}}var h=t.match(P);if(h){y(h[0].length);continue}var d=t.match(M);if(d){var g=c;y(d[0].length),x(d[1],g,c);continue}var p=T();if(p){b(p),K(r,t)&&y(1);continue}}var m=void 0,v=void 0,w=void 0;if(s>=0){for(v=t.slice(s);!(M.test(v)||A.test(v)||R.test(v)||_.test(v)||(w=v.indexOf("<",1))<0);)s+=w,v=t.slice(s);m=t.substring(0,s),y(s)}s<0&&(m=t,t=""),e.chars&&m&&e.chars(m)}if(t===n){e.chars&&e.chars(t),"production"!==N.env.NODE_ENV&&!o.length&&e.warn&&e.warn('Mal-formatted tag at end of template: "'.concat(t,'"'));break}}function y(e){c+=e,t=t.substring(e)}function T(){var e=t.match(A);if(e){var n,r,o={tagName:e[1],attrs:[],start:c};for(y(e[0].length);!(n=t.match(q))&&(r=t.match(L));)y(r[0].length),o.attrs.push(r);if(n)return o.unarySlash=n[1],y(n[0].length),o.end=c,o}}function b(t){var n=t.tagName,c=t.unarySlash;a&&("p"===r&&D(n)&&x(r),u(n)&&r===n&&x(n));for(var s=i(n)||!!c,l=t.attrs.length,f=new Array(l),h=0;h<l;h++){var d=t.attrs[h];j&&-1===d[0].indexOf('""')&&(""===d[3]&&delete d[3],""===d[4]&&delete d[4],""===d[5]&&delete d[5]);var g=d[3]||d[4]||d[5]||"",p="a"===n&&"href"===d[1]?e.shouldDecodeNewlinesForHref:e.shouldDecodeNewlines;f[h]={name:d[1],value:U(g,p)}}s||(o.push({tag:n,lowerCasedTag:n.toLowerCase(),attrs:f}),r=n),e.start&&e.start(n,f,s,t.start,t.end)}function x(t,n,a){var i,u;if(null==n&&(n=c),null==a&&(a=c),t&&(u=t.toLowerCase()),t)for(i=o.length-1;i>=0&&o[i].lowerCasedTag!==u;i--);else i=0;if(i>=0){for(var s=o.length-1;s>=i;s--)"production"!==N.env.NODE_ENV&&(s>i||!t)&&e.warn&&e.warn("tag <".concat(o[s].tag,"> has no matching end tag.")),e.end&&e.end(o[s].tag,n,a);o.length=i,r=i&&o[i-1].tag}else"br"===u?e.start&&e.start(t,[],!0,n,a):"p"===u&&(e.start&&e.start(t,[],!1,n,a),e.end&&e.end(t,n,a))}x()}(t,{start:function(t,e,o,a,i){var u={tag:t,attrs:e,unary:o,start:a,children:[]};r.children.push(u),o?u.end=i:(u.contentStart=i,n.push(u),r=u)},end:function(t,e,o){n.pop(),r.contentEnd=e,r.end=o,r=n[n.length-1]}}),e},astFormat:"vue"}}}});