ray-template/js/@intlify_message-compiler@11.1.3-DphV8pYf.js

4 lines
16 KiB
JavaScript
Raw Permalink Blame History

import{e as te,a as j,p as ne}from"./@intlify_shared@11.1.3-Byx4ULsF.js";function ke(r,n,c){return{line:r,column:n,offset:c}}function J(r,n,c){return{start:r,end:n}}const h={EXPECTED_TOKEN:1,INVALID_TOKEN_IN_PLACEHOLDER:2,UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER:3,UNKNOWN_ESCAPE_SEQUENCE:4,INVALID_UNICODE_ESCAPE_SEQUENCE:5,UNBALANCED_CLOSING_BRACE:6,UNTERMINATED_CLOSING_BRACE:7,EMPTY_PLACEHOLDER:8,NOT_ALLOW_NEST_PLACEHOLDER:9,INVALID_LINKED_FORMAT:10,MUST_HAVE_MESSAGES_IN_PLURAL:11,UNEXPECTED_EMPTY_LINKED_MODIFIER:12,UNEXPECTED_EMPTY_LINKED_KEY:13,UNEXPECTED_LEXICAL_ANALYSIS:14},Be=17;function re(r,n,c={}){const{domain:a,messages:p,args:u}=c,T=r,_=new SyntaxError(String(T));return _.code=r,n&&(_.location=n),_.domain=a,_}function Ve(r){throw r}const X=" ",Ae="\r",b=`
`,Pe="\u2028",ye="\u2029";function me(r){const n=r;let c=0,a=1,p=1,u=0;const T=N=>n[N]===Ae&&n[N+1]===b,_=N=>n[N]===b,k=N=>n[N]===ye,m=N=>n[N]===Pe,D=N=>T(N)||_(N)||k(N)||m(N),A=()=>c,I=()=>a,v=()=>p,U=()=>u,S=N=>T(N)||k(N)||m(N)?b:n[N],C=()=>S(c),s=()=>S(c+u);function l(){return u=0,D(c)&&(a++,p=0),T(c)&&c++,c++,p++,n[c]}function d(){return T(c+u)&&u++,u++,n[c+u]}function o(){c=0,a=1,p=1,u=0}function E(N=0){u=N}function L(){const N=c+u;for(;N!==c;)l();u=0}return{index:A,line:I,column:v,peekOffset:U,charAt:S,currentChar:C,currentPeek:s,next:l,peek:d,reset:o,resetPeek:E,skipToPeek:L}}const $=void 0,Oe=".",Z="'",be="tokenizer";function De(r,n={}){const c=n.location!==!1,a=me(r),p=()=>a.index(),u=()=>ke(a.line(),a.column(),a.index()),T=u(),_=p(),k={currentType:13,offset:_,startLoc:T,endLoc:T,lastType:13,lastOffset:_,lastStartLoc:T,lastEndLoc:T,braceNest:0,inLinked:!1,text:""},m=()=>k,{onError:D}=n;function A(e,t,i,...f){const P=m();if(t.column+=i,t.offset+=i,D){const y=c?J(P.startLoc,t):null,R=re(e,y,{domain:be,args:f});D(R)}}function I(e,t,i){e.endLoc=u(),e.currentType=t;const f={type:t};return c&&(f.loc=J(e.startLoc,e.endLoc)),i!=null&&(f.value=i),f}const v=e=>I(e,13);function U(e,t){return e.currentChar()===t?(e.next(),t):(A(h.EXPECTED_TOKEN,u(),0,t),"")}function S(e){let t="";for(;e.currentPeek()===X||e.currentPeek()===b;)t+=e.currentPeek(),e.peek();return t}function C(e){const t=S(e);return e.skipToPeek(),t}function s(e){if(e===$)return!1;const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||t===95}function l(e){if(e===$)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}function d(e,t){const{currentType:i}=t;if(i!==2)return!1;S(e);const f=s(e.currentPeek());return e.resetPeek(),f}function o(e,t){const{currentType:i}=t;if(i!==2)return!1;S(e);const f=e.currentPeek()==="-"?e.peek():e.currentPeek(),P=l(f);return e.resetPeek(),P}function E(e,t){const{currentType:i}=t;if(i!==2)return!1;S(e);const f=e.currentPeek()===Z;return e.resetPeek(),f}function L(e,t){const{currentType:i}=t;if(i!==7)return!1;S(e);const f=e.currentPeek()===".";return e.resetPeek(),f}function N(e,t){const{currentType:i}=t;if(i!==8)return!1;S(e);const f=s(e.currentPeek());return e.resetPeek(),f}function w(e,t){const{currentType:i}=t;if(!(i===7||i===11))return!1;S(e);const f=e.currentPeek()===":";return e.resetPeek(),f}function O(e,t){const{currentType:i}=t;if(i!==9)return!1;const f=()=>{const y=e.currentPeek();return y==="{"?s(e.peek()):y==="@"||y==="|"||y===":"||y==="."||y===X||!y?!1:y===b?(e.peek(),f()):G(e,!1)},P=f();return e.resetPeek(),P}function g(e){S(e);const t=e.currentPeek()==="|";return e.resetPeek(),t}function G(e,t=!0){const i=(P=!1,y="")=>{const R=e.currentPeek();return R==="{"||R==="@"||!R?P:R==="|"?!(y===X||y===b):R===X?(e.peek(),i(!0,X)):R===b?(e.peek(),i(!0,b)):!0},f=i();return t&&e.resetPeek(),f}function K(e,t){const i=e.currentChar();return i===$?$:t(i)?(e.next(),i):null}function se(e){const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||t===95||t===36}function ie(e){return K(e,se)}function ce(e){const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||t===95||t===36||t===45}function ue(e){return K(e,ce)}function ae(e){const t=e.charCodeAt(0);return t>=48&&t<=57}function oe(e){return K(e,ae)}function le(e){const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function fe(e){return K(e,le)}function W(e){let t="",i="";for(;t=oe(e);)i+=t;return i}function de(e){let t="";for(;;){const i=e.currentChar();if(i==="{"||i==="}"||i==="@"||i==="|"||!i)break;if(i===X||i===b)if(G(e))t+=i,e.next();else{if(g(e))break;t+=i,e.next()}else t+=i,e.next()}return t}function Ee(e){C(e);let t="",i="";for(;t=ue(e);)i+=t;return e.currentChar()===$&&A(h.UNTERMINATED_CLOSING_BRACE,u(),0),i}function Le(e){C(e);let t="";return e.currentChar()==="-"?(e.next(),t+=`-${W(e)}`):t+=W(e),e.currentChar()===$&&A(h.UNTERMINATED_CLOSING_BRACE,u(),0),t}function pe(e){return e!==Z&&e!==b}function Ne(e){C(e),U(e,"'");let t="",i="";for(;t=K(e,pe);)t==="\\"?i+=_e(e):i+=t;const f=e.currentChar();return f===b||f===$?(A(h.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER,u(),0),f===b&&(e.next(),U(e,"'")),i):(U(e,"'"),i)}function _e(e){const t=e.currentChar();switch(t){case"\\":case"'":return e.next(),`\\${t}`;case"u":return q(e,t,4);case"U":return q(e,t,6);default:return A(h.UNKNOWN_ESCAPE_SEQUENCE,u(),0,t),""}}function q(e,t,i){U(e,t);let f="";for(let P=0;P<i;P++){const y=fe(e);if(!y){A(h.INVALID_UNICODE_ESCAPE_SEQUENCE,u(),0,`\\${t}${f}${e.currentChar()}`);break}f+=y}return`\\${t}${f}`}function he(e){return e!=="{"&&e!=="}"&&e!==X&&e!==b}function Ce(e){C(e);let t="",i="";for(;t=K(e,he);)i+=t;return i}function Te(e){let t="",i="";for(;t=ie(e);)i+=t;return i}function Ie(e){const t=i=>{const f=e.currentChar();return f==="{"||f==="@"||f==="|"||f==="("||f===")"||!f||f===X?i:(i+=f,e.next(),t(i))};return t("")}function F(e){C(e);const t=U(e,"|");return C(e),t}function B(e,t){let i=null;switch(e.currentChar()){case"{":return t.braceNest>=1&&A(h.NOT_ALLOW_NEST_PLACEHOLDER,u(),0),e.next(),i=I(t,2,"{"),C(e),t.braceNest++,i;case"}":return t.braceNest>0&&t.currentType===2&&A(h.EMPTY_PLACEHOLDER,u(),0),e.next(),i=I(t,3,"}"),t.braceNest--,t.braceNest>0&&C(e),t.inLinked&&t.braceNest===0&&(t.inLinked=!1),i;case"@":return t.braceNest>0&&A(h.UNTERMINATED_CLOSING_BRACE,u(),0),i=H(e,t)||v(t),t.braceNest=0,i;default:{let P=!0,y=!0,R=!0;if(g(e))return t.braceNest>0&&A(h.UNTERMINATED_CLOSING_BRACE,u(),0),i=I(t,1,F(e)),t.braceNest=0,t.inLinked=!1,i;if(t.braceNest>0&&(t.currentType===4||t.currentType===5||t.currentType===6))return A(h.UNTERMINATED_CLOSING_BRACE,u(),0),t.braceNest=0,V(e,t);if(P=d(e,t))return i=I(t,4,Ee(e)),C(e),i;if(y=o(e,t))return i=I(t,5,Le(e)),C(e),i;if(R=E(e,t))return i=I(t,6,Ne(e)),C(e),i;if(!P&&!y&&!R)return i=I(t,12,Ce(e)),A(h.INVALID_TOKEN_IN_PLACEHOLDER,u(),0,i.value),C(e),i;break}}return i}function H(e,t){const{currentType:i}=t;let f=null;const P=e.currentChar();switch((i===7||i===8||i===11||i===9)&&(P===b||P===X)&&A(h.INVALID_LINKED_FORMAT,u(),0),P){case"@":return e.next(),f=I(t,7,"@"),t.inLinked=!0,f;case".":return C(e),e.next(),I(t,8,".");case":":return C(e),e.next(),I(t,9,":");default:return g(e)?(f=I(t,1,F(e)),t.braceNest=0,t.inLinked=!1,f):L(e,t)||w(e,t)?(C(e),H(e,t)):N(e,t)?(C(e),I(t,11,Te(e))):O(e,t)?(C(e),P==="{"?B(e,t)||f:I(t,10,Ie(e))):(i===7&&A(h.INVALID_LINKED_FORMAT,u(),0),t.braceNest=0,t.inLinked=!1,V(e,t))}}function V(e,t){let i={type:13};if(t.braceNest>0)return B(e,t)||v(t);if(t.inLinked)return H(e,t)||v(t);switch(e.currentChar()){case"{":return B(e,t)||v(t);case"}":return A(h.UNBALANCED_CLOSING_BRACE,u(),0),e.next(),I(t,3,"}");case"@":return H(e,t)||v(t);default:{if(g(e))return i=I(t,1,F(e)),t.braceNest=0,t.inLinked=!1,i;if(G(e))return I(t,0,de(e));break}}return i}function Se(){const{currentType:e,offset:t,startLoc:i,endLoc:f}=k;return k.lastType=e,k.lastOffset=t,k.lastStartLoc=i,k.lastEndLoc=f,k.offset=p(),k.startLoc=u(),a.currentChar()===$?I(k,13):V(a,k)}return{nextToken:Se,currentOffset:p,currentPosition:u,context:m}}const ve="parser",Re=/(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;function Ue(r,n,c){switch(r){case"\\\\":return"\\";case"\\'":return"'";default:{const a=parseInt(n||c,16);return a<=55295||a>=57344?String.fromCodePoint(a):"<22>"}}}function Me(r={}){const n=r.location!==!1,{onError:c}=r;function a(s,l,d,o,...E){const L=s.currentPosition();if(L.offset+=o,L.column+=o,c){const N=n?J(d,L):null,w=re(l,N,{domain:ve,args:E});c(w)}}function p(s,l,d){const o={type:s};return n&&(o.start=l,o.end=l,o.loc={start:d,end:d}),o}function u(s,l,d,o){n&&(s.end=l,s.loc&&(s.loc.end=d))}function T(s,l){const d=s.context(),o=p(3,d.offset,d.startLoc);return o.value=l,u(o,s.currentOffset(),s.currentPosition()),o}function _(s,l){const d=s.context(),{lastOffset:o,lastStartLoc:E}=d,L=p(5,o,E);return L.index=parseInt(l,10),s.nextToken(),u(L,s.currentOffset(),s.currentPosition()),L}function k(s,l){const d=s.context(),{lastOffset:o,lastStartLoc:E}=d,L=p(4,o,E);return L.key=l,s.nextToken(),u(L,s.currentOffset(),s.currentPosition()),L}function m(s,l){const d=s.context(),{lastOffset:o,lastStartLoc:E}=d,L=p(9,o,E);return L.value=l.replace(Re,Ue),s.nextToken(),u(L,s.currentOffset(),s.currentPosition()),L}function D(s){const l=s.nextToken(),d=s.context(),{lastOffset:o,lastStartLoc:E}=d,L=p(8,o,E);return l.type!==11?(a(s,h.UNEXPECTED_EMPTY_LINKED_MODIFIER,d.lastStartLoc,0),L.value="",u(L,o,E),{nextConsumeToken:l,node:L}):(l.value==null&&a(s,h.UNEXPECTED_LEXICAL_ANALYSIS,d.lastStartLoc,0,M(l)),L.value=l.value||"",u(L,s.currentOffset(),s.currentPosition()),{node:L})}function A(s,l){const d=s.context(),o=p(7,d.offset,d.startLoc);return o.value=l,u(o,s.currentOffset(),s.currentPosition()),o}function I(s){const l=s.context(),d=p(6,l.offset,l.startLoc);let o=s.nextToken();if(o.type===8){const E=D(s);d.modifier=E.node,o=E.nextConsumeToken||s.nextToken()}switch(o.type!==9&&a(s,h.UNEXPECTED_LEXICAL_ANALYSIS,l.lastStartLoc,0,M(o)),o=s.nextToken(),o.type===2&&(o=s.nextToken()),o.type){case 10:o.value==null&&a(s,h.UNEXPECTED_LEXICAL_ANALYSIS,l.lastStartLoc,0,M(o)),d.key=A(s,o.value||"");break;case 4:o.value==null&&a(s,h.UNEXPECTED_LEXICAL_ANALYSIS,l.lastStartLoc,0,M(o)),d.key=k(s,o.value||"");break;case 5:o.value==null&&a(s,h.UNEXPECTED_LEXICAL_ANALYSIS,l.lastStartLoc,0,M(o)),d.key=_(s,o.value||"");break;case 6:o.value==null&&a(s,h.UNEXPECTED_LEXICAL_ANALYSIS,l.lastStartLoc,0,M(o)),d.key=m(s,o.value||"");break;default:{a(s,h.UNEXPECTED_EMPTY_LINKED_KEY,l.lastStartLoc,0);const E=s.context(),L=p(7,E.offset,E.startLoc);return L.value="",u(L,E.offset,E.startLoc),d.key=L,u(d,E.offset,E.startLoc),{nextConsumeToken:o,node:d}}}return u(d,s.currentOffset(),s.currentPosition()),{node:d}}function v(s){const l=s.context(),d=l.currentType===1?s.currentOffset():l.offset,o=l.currentType===1?l.endLoc:l.startLoc,E=p(2,d,o);E.items=[];let L=null;do{const O=L||s.nextToken();switch(L=null,O.type){case 0:O.value==null&&a(s,h.UNEXPECTED_LEXICAL_ANALYSIS,l.lastStartLoc,0,M(O)),E.items.push(T(s,O.value||""));break;case 5:O.value==null&&a(s,h.UNEXPECTED_LEXICAL_ANALYSIS,l.lastStartLoc,0,M(O)),E.items.push(_(s,O.value||""));break;case 4:O.value==null&&a(s,h.UNEXPECTED_LEXICAL_ANALYSIS,l.lastStartLoc,0,M(O)),E.items.push(k(s,O.value||""));break;case 6:O.value==null&&a(s,h.UNEXPECTED_LEXICAL_ANALYSIS,l.lastStartLoc,0,M(O)),E.items.push(m(s,O.value||""));break;case 7:{const g=I(s);E.items.push(g.node),L=g.nextConsumeToken||null;break}}}while(l.currentType!==13&&l.currentType!==1);const N=l.currentType===1?l.lastOffset:s.currentOffset(),w=l.currentType===1?l.lastEndLoc:s.currentPosition();return u(E,N,w),E}function U(s,l,d,o){const E=s.context();let L=o.items.length===0;const N=p(1,l,d);N.cases=[],N.cases.push(o);do{const w=v(s);L||(L=w.items.length===0),N.cases.push(w)}while(E.currentType!==13);return L&&a(s,h.MUST_HAVE_MESSAGES_IN_PLURAL,d,0),u(N,s.currentOffset(),s.currentPosition()),N}function S(s){const l=s.context(),{offset:d,startLoc:o}=l,E=v(s);return l.currentType===13?E:U(s,d,o,E)}function C(s){const l=De(s,te({},r)),d=l.context(),o=p(0,d.offset,d.startLoc);return n&&o.loc&&(o.loc.source=s),o.body=S(l),r.onCacheKey&&(o.cacheKey=r.onCacheKey(s)),d.currentType!==13&&a(l,h.UNEXPECTED_LEXICAL_ANALYSIS,d.lastStartLoc,0,s[d.offset]||""),u(o,l.currentOffset(),l.currentPosition()),o}return{parse:C}}function M(r){if(r.type===13)return"EOF";const n=(r.value||"").replace(/\r?\n/gu,"\\n");return n.length>10?n.slice(0,9)+"…":n}function Xe(r,n={}){const c={ast:r,helpers:new Set};return{context:()=>c,helper:u=>(c.helpers.add(u),u)}}function z(r,n){for(let c=0;c<r.length;c++)Q(r[c],n)}function Q(r,n){switch(r.type){case 1:z(r.cases,n),n.helper("plural");break;case 2:z(r.items,n);break;case 6:{Q(r.key,n),n.helper("linked"),n.helper("type");break}case 5:n.helper("interpolate"),n.helper("list");break;case 4:n.helper("interpolate"),n.helper("named");break}}function we(r,n={}){const c=Xe(r);c.helper("normalize"),r.body&&Q(r.body,c);const a=c.context();r.helpers=Array.from(a.helpers)}function $e(r){const n=r.body;return n.type===2?ee(n):n.cases.forEach(c=>ee(c)),r}function ee(r){if(r.items.length===1){const n=r.items[0];(n.type===3||n.type===9)&&(r.static=n.value,delete n.value)}else{const n=[];for(let c=0;c<r.items.length;c++){const a=r.items[c];if(!(a.type===3||a.type===9)||a.value==null)break;n.push(a.value)}if(n.length===r.items.length){r.static=ne(n);for(let c=0;c<r.items.length;c++){const a=r.items[c];(a.type===3||a.type===9)&&delete a.value}}}}function Y(r){switch(r.t=r.type,r.type){case 0:{const n=r;Y(n.body),n.b=n.body,delete n.body;break}case 1:{const n=r,c=n.cases;for(let a=0;a<c.length;a++)Y(c[a]);n.c=c,delete n.cases;break}case 2:{const n=r,c=n.items;for(let a=0;a<c.length;a++)Y(c[a]);n.i=c,delete n.items,n.static&&(n.s=n.static,delete n.static);break}case 3:case 9:case 8:case 7:{const n=r;n.value&&(n.v=n.value,delete n.value);break}case 6:{const n=r;Y(n.key),n.k=n.key,delete n.key,n.modifier&&(Y(n.modifier),n.m=n.modifier,delete n.modifier);break}case 5:{const n=r;n.i=n.index,delete n.index;break}case 4:{const n=r;n.k=n.key,delete n.key;break}}delete r.type}function ge(r,n){const{filename:c,breakLineCode:a,needIndent:p}=n,u=n.location!==!1,T={filename:c,code:"",column:1,line:1,offset:0,map:void 0,breakLineCode:a,needIndent:p,indentLevel:0};u&&r.loc&&(T.source=r.loc.source);const _=()=>T;function k(S,C){T.code+=S}function m(S,C=!0){const s=C?a:"";k(p?s+" ".repeat(S):s)}function D(S=!0){const C=++T.indentLevel;S&&m(C)}function A(S=!0){const C=--T.indentLevel;S&&m(C)}function I(){m(T.indentLevel)}return{context:_,push:k,indent:D,deindent:A,newline:I,helper:S=>`_${S}`,needIndent:()=>T.needIndent}}function Ke(r,n){const{helper:c}=r;r.push(`${c("linked")}(`),x(r,n.key),n.modifier?(r.push(", "),x(r,n.modifier),r.push(", _type")):r.push(", undefined, _type"),r.push(")")}function Ye(r,n){const{helper:c,needIndent:a}=r;r.push(`${c("normalize")}([`),r.indent(a());const p=n.items.length;for(let u=0;u<p&&(x(r,n.items[u]),u!==p-1);u++)r.push(", ");r.deindent(a()),r.push("])")}function xe(r,n){const{helper:c,needIndent:a}=r;if(n.cases.length>1){r.push(`${c("plural")}([`),r.indent(a());const p=n.cases.length;for(let u=0;u<p&&(x(r,n.cases[u]),u!==p-1);u++)r.push(", ");r.deindent(a()),r.push("])")}}function He(r,n){n.body?x(r,n.body):r.push("null")}function x(r,n){const{helper:c}=r;switch(n.type){case 0:He(r,n);break;case 1:xe(r,n);break;case 2:Ye(r,n);break;case 6:Ke(r,n);break;case 8:r.push(JSON.stringify(n.value),n);break;case 7:r.push(JSON.stringify(n.value),n);break;case 5:r.push(`${c("interpolate")}(${c("list")}(${n.index}))`,n);break;case 4:r.push(`${c("interpolate")}(${c("named")}(${JSON.stringify(n.key)}))`,n);break;case 9:r.push(JSON.stringify(n.value),n);break;case 3:r.push(JSON.stringify(n.value),n);break}}const Ge=(r,n={})=>{const c=j(n.mode)?n.mode:"normal",a=j(n.filename)?n.filename:"message.intl";n.sourceMap;const p=n.breakLineCode!=null?n.breakLineCode:c==="arrow"?";":`
`,u=n.needIndent?n.needIndent:c!=="arrow",T=r.helpers||[],_=ge(r,{filename:a,breakLineCode:p,needIndent:u});_.push(c==="normal"?"function __msg__ (ctx) {":"(ctx) => {"),_.indent(u),T.length>0&&(_.push(`const { ${ne(T.map(D=>`${D}: _${D}`),", ")} } = ctx`),_.newline()),_.push("return "),x(_,r),_.deindent(u),_.push("}"),delete r.helpers;const{code:k,map:m}=_.context();return{ast:r,code:k,map:m?m.toJSON():void 0}};function Je(r,n={}){const c=te({},n),a=!!c.jit,p=!!c.minify,u=c.optimize==null?!0:c.optimize,_=Me(c).parse(r);return a?(u&&$e(_),p&&Y(_),{ast:_,code:""}):(we(_,c),Ge(_,c))}export{Be as C,Je as b,re as c,Ve as d};