UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

7 lines (6 loc) 15.5 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e=require("../../shared/dist/shared.esm-bundler.js"); /*! * message-compiler v9.2.2 * (c) 2022 kazuya kawaguchi * Released under the MIT License. */const t={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,__EXTEND_POINT__:15};function n(e,t,n={}){const{domain:r,messages:c,args:o}=n,s=new SyntaxError(String(e));return s.code=e,t&&(s.location=t),s.domain=r,s}function r(e,t,n){return{line:e,column:t,offset:n}}function c(e,t,n){const r={start:e,end:t};return null!=n&&(r.source=n),r}const o=String.fromCharCode(8232),s=String.fromCharCode(8233);function u(e){const t=e;let n=0,r=1,c=1,u=0;const a=e=>"\r"===t[e]&&"\n"===t[e+1],i=e=>t[e]===s,f=e=>t[e]===o,l=e=>a(e)||(e=>"\n"===t[e])(e)||i(e)||f(e),E=e=>a(e)||i(e)||f(e)?"\n":t[e];function L(){return u=0,l(n)&&(r++,c=0),a(n)&&n++,n++,c++,t[n]}return{index:()=>n,line:()=>r,column:()=>c,peekOffset:()=>u,charAt:E,currentChar:()=>E(n),currentPeek:()=>E(n+u),next:L,peek:function(){return a(n+u)&&u++,u++,t[n+u]},reset:function(){n=0,r=1,c=1,u=0},resetPeek:function(e=0){u=e},skipToPeek:function(){const e=n+u;for(;e!==n;)L();u=0}}}const a=void 0;function i(e,o={}){const s=!1!==o.location,i=u(e),f=()=>i.index(),l=()=>r(i.line(),i.column(),i.index()),E=l(),L=f(),p={currentType:14,offset:L,startLoc:E,endLoc:E,lastType:14,lastOffset:L,lastStartLoc:E,lastEndLoc:E,braceNest:0,inLinked:!1,text:""},d=()=>p,{onError:N}=o;function _(e,t,r,...o){const s=d();if(t.column+=r,t.offset+=r,N){const r=n(e,c(s.startLoc,t),{domain:"tokenizer",args:o});N(r)}}function C(e,t,n){e.endLoc=l(),e.currentType=t;const r={type:t};return s&&(r.loc=c(e.startLoc,e.endLoc)),null!=n&&(r.value=n),r}const k=e=>C(e,14);function T(e,n){return e.currentChar()===n?(e.next(),n):(_(t.EXPECTED_TOKEN,l(),0,n),"")}function A(e){let t="";for(;" "===e.currentPeek()||"\n"===e.currentPeek();)t+=e.currentPeek(),e.peek();return t}function h(e){const t=A(e);return e.skipToPeek(),t}function I(e){if(e===a)return!1;const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||95===t}function S(e,t){const{currentType:n}=t;if(2!==n)return!1;A(e);const r=function(e){if(e===a)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}("-"===e.currentPeek()?e.peek():e.currentPeek());return e.resetPeek(),r}function P(e){A(e);const t="|"===e.currentPeek();return e.resetPeek(),t}function x(e,t=!0){const n=(t=!1,r="",c=!1)=>{const o=e.currentPeek();return"{"===o?"%"!==r&&t:"@"!==o&&o?"%"===o?(e.peek(),n(t,"%",!0)):"|"===o?!("%"!==r&&!c)||!(" "===r||"\n"===r):" "===o?(e.peek(),n(!0," ",c)):"\n"!==o||(e.peek(),n(!0,"\n",c)):"%"===r||t},r=n();return t&&e.resetPeek(),r}function O(e,t){const n=e.currentChar();return n===a?a:t(n)?(e.next(),n):null}function y(e){return O(e,(e=>{const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||95===t||36===t}))}function m(e){return O(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57}))}function D(e){return O(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}))}function b(e){let t="",n="";for(;t=m(e);)n+=t;return n}function U(e){let t="";for(;;){const n=e.currentChar();if("{"===n||"}"===n||"@"===n||"|"===n||!n)break;if("%"===n){if(!x(e))break;t+=n,e.next()}else if(" "===n||"\n"===n)if(x(e))t+=n,e.next();else{if(P(e))break;t+=n,e.next()}else t+=n,e.next()}return t}function v(e){const n=e.currentChar();switch(n){case"\\":case"'":return e.next(),`\\${n}`;case"u":return R(e,n,4);case"U":return R(e,n,6);default:return _(t.UNKNOWN_ESCAPE_SEQUENCE,l(),0,n),""}}function R(e,n,r){T(e,n);let c="";for(let o=0;o<r;o++){const r=D(e);if(!r){_(t.INVALID_UNICODE_ESCAPE_SEQUENCE,l(),0,`\\${n}${c}${e.currentChar()}`);break}c+=r}return`\\${n}${c}`}function X(e){h(e);const t=T(e,"|");return h(e),t}function M(e,n){let r=null;switch(e.currentChar()){case"{":return n.braceNest>=1&&_(t.NOT_ALLOW_NEST_PLACEHOLDER,l(),0),e.next(),r=C(n,2,"{"),h(e),n.braceNest++,r;case"}":return n.braceNest>0&&2===n.currentType&&_(t.EMPTY_PLACEHOLDER,l(),0),e.next(),r=C(n,3,"}"),n.braceNest--,n.braceNest>0&&h(e),n.inLinked&&0===n.braceNest&&(n.inLinked=!1),r;case"@":return n.braceNest>0&&_(t.UNTERMINATED_CLOSING_BRACE,l(),0),r=g(e,n)||k(n),n.braceNest=0,r;default:let c=!0,o=!0,s=!0;if(P(e))return n.braceNest>0&&_(t.UNTERMINATED_CLOSING_BRACE,l(),0),r=C(n,1,X(e)),n.braceNest=0,n.inLinked=!1,r;if(n.braceNest>0&&(5===n.currentType||6===n.currentType||7===n.currentType))return _(t.UNTERMINATED_CLOSING_BRACE,l(),0),n.braceNest=0,Y(e,n);if(c=function(e,t){const{currentType:n}=t;if(2!==n)return!1;A(e);const r=I(e.currentPeek());return e.resetPeek(),r}(e,n))return r=C(n,5,function(e){h(e);let n="",r="";for(;n=y(e);)r+=n;return e.currentChar()===a&&_(t.UNTERMINATED_CLOSING_BRACE,l(),0),r}(e)),h(e),r;if(o=S(e,n))return r=C(n,6,function(e){h(e);let n="";return"-"===e.currentChar()?(e.next(),n+=`-${b(e)}`):n+=b(e),e.currentChar()===a&&_(t.UNTERMINATED_CLOSING_BRACE,l(),0),n}(e)),h(e),r;if(s=function(e,t){const{currentType:n}=t;if(2!==n)return!1;A(e);const r="'"===e.currentPeek();return e.resetPeek(),r}(e,n))return r=C(n,7,function(e){h(e),T(e,"'");let n="",r="";const c=e=>"'"!==e&&"\n"!==e;for(;n=O(e,c);)r+="\\"===n?v(e):n;const o=e.currentChar();return"\n"===o||o===a?(_(t.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER,l(),0),"\n"===o&&(e.next(),T(e,"'")),r):(T(e,"'"),r)}(e)),h(e),r;if(!c&&!o&&!s)return r=C(n,13,function(e){h(e);let t="",n="";const r=e=>"{"!==e&&"}"!==e&&" "!==e&&"\n"!==e;for(;t=O(e,r);)n+=t;return n}(e)),_(t.INVALID_TOKEN_IN_PLACEHOLDER,l(),0,r.value),h(e),r}return r}function g(e,n){const{currentType:r}=n;let c=null;const o=e.currentChar();switch(8!==r&&9!==r&&12!==r&&10!==r||"\n"!==o&&" "!==o||_(t.INVALID_LINKED_FORMAT,l(),0),o){case"@":return e.next(),c=C(n,8,"@"),n.inLinked=!0,c;case".":return h(e),e.next(),C(n,9,".");case":":return h(e),e.next(),C(n,10,":");default:return P(e)?(c=C(n,1,X(e)),n.braceNest=0,n.inLinked=!1,c):function(e,t){const{currentType:n}=t;if(8!==n)return!1;A(e);const r="."===e.currentPeek();return e.resetPeek(),r}(e,n)||function(e,t){const{currentType:n}=t;if(8!==n&&12!==n)return!1;A(e);const r=":"===e.currentPeek();return e.resetPeek(),r}(e,n)?(h(e),g(e,n)):function(e,t){const{currentType:n}=t;if(9!==n)return!1;A(e);const r=I(e.currentPeek());return e.resetPeek(),r}(e,n)?(h(e),C(n,12,function(e){let t="",n="";for(;t=y(e);)n+=t;return n}(e))):function(e,t){const{currentType:n}=t;if(10!==n)return!1;const r=()=>{const t=e.currentPeek();return"{"===t?I(e.peek()):!("@"===t||"%"===t||"|"===t||":"===t||"."===t||" "===t||!t)&&("\n"===t?(e.peek(),r()):I(t))},c=r();return e.resetPeek(),c}(e,n)?(h(e),"{"===o?M(e,n)||c:C(n,11,function(e){const t=(n=!1,r)=>{const c=e.currentChar();return"{"!==c&&"%"!==c&&"@"!==c&&"|"!==c&&c?" "===c?r:"\n"===c?(r+=c,e.next(),t(n,r)):(r+=c,e.next(),t(!0,r)):r};return t(!1,"")}(e))):(8===r&&_(t.INVALID_LINKED_FORMAT,l(),0),n.braceNest=0,n.inLinked=!1,Y(e,n))}}function Y(e,n){let r={type:14};if(n.braceNest>0)return M(e,n)||k(n);if(n.inLinked)return g(e,n)||k(n);switch(e.currentChar()){case"{":return M(e,n)||k(n);case"}":return _(t.UNBALANCED_CLOSING_BRACE,l(),0),e.next(),C(n,3,"}");case"@":return g(e,n)||k(n);default:if(P(e))return r=C(n,1,X(e)),n.braceNest=0,n.inLinked=!1,r;const{isModulo:c,hasSpace:o}=function(e){const t=A(e),n="%"===e.currentPeek()&&"{"===e.peek();return e.resetPeek(),{isModulo:n,hasSpace:t.length>0}}(e);if(c)return o?C(n,0,U(e)):C(n,4,function(e){h(e);const n=e.currentChar();return"%"!==n&&_(t.EXPECTED_TOKEN,l(),0,n),e.next(),"%"}(e));if(x(e))return C(n,0,U(e))}return r}return{nextToken:function(){const{currentType:e,offset:t,startLoc:n,endLoc:r}=p;return p.lastType=e,p.lastOffset=t,p.lastStartLoc=n,p.lastEndLoc=r,p.offset=f(),p.startLoc=l(),i.currentChar()===a?C(p,14):Y(i,p)},currentOffset:f,currentPosition:l,context:d}}const f=/(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;function l(e,t,n){switch(e){case"\\\\":return"\\";case"\\'":return"'";default:{const e=parseInt(t||n,16);return e<=55295||e>=57344?String.fromCodePoint(e):"�"}}}function E(r={}){const o=!1!==r.location,{onError:s}=r;function u(e,t,r,o,...u){const a=e.currentPosition();if(a.offset+=o,a.column+=o,s){const e=n(t,c(r,a),{domain:"parser",args:u});s(e)}}function a(e,t,n){const r={type:e,start:t,end:t};return o&&(r.loc={start:n,end:n}),r}function E(e,t,n,r){e.end=t,r&&(e.type=r),o&&e.loc&&(e.loc.end=n)}function p(e,t){const n=e.context(),r=a(3,n.offset,n.startLoc);return r.value=t,E(r,e.currentOffset(),e.currentPosition()),r}function d(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:c}=n,o=a(5,r,c);return o.index=parseInt(t,10),e.nextToken(),E(o,e.currentOffset(),e.currentPosition()),o}function N(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:c}=n,o=a(4,r,c);return o.key=t,e.nextToken(),E(o,e.currentOffset(),e.currentPosition()),o}function _(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:c}=n,o=a(9,r,c);return o.value=t.replace(f,l),e.nextToken(),E(o,e.currentOffset(),e.currentPosition()),o}function C(e){const n=e.context(),r=a(6,n.offset,n.startLoc);let c=e.nextToken();if(9===c.type){const n=function(e){const n=e.nextToken(),r=e.context(),{lastOffset:c,lastStartLoc:o}=r,s=a(8,c,o);return 12!==n.type?(u(e,t.UNEXPECTED_EMPTY_LINKED_MODIFIER,r.lastStartLoc,0),s.value="",E(s,c,o),{nextConsumeToken:n,node:s}):(null==n.value&&u(e,t.UNEXPECTED_LEXICAL_ANALYSIS,r.lastStartLoc,0,L(n)),s.value=n.value||"",E(s,e.currentOffset(),e.currentPosition()),{node:s})}(e);r.modifier=n.node,c=n.nextConsumeToken||e.nextToken()}switch(10!==c.type&&u(e,t.UNEXPECTED_LEXICAL_ANALYSIS,n.lastStartLoc,0,L(c)),c=e.nextToken(),2===c.type&&(c=e.nextToken()),c.type){case 11:null==c.value&&u(e,t.UNEXPECTED_LEXICAL_ANALYSIS,n.lastStartLoc,0,L(c)),r.key=function(e,t){const n=e.context(),r=a(7,n.offset,n.startLoc);return r.value=t,E(r,e.currentOffset(),e.currentPosition()),r}(e,c.value||"");break;case 5:null==c.value&&u(e,t.UNEXPECTED_LEXICAL_ANALYSIS,n.lastStartLoc,0,L(c)),r.key=N(e,c.value||"");break;case 6:null==c.value&&u(e,t.UNEXPECTED_LEXICAL_ANALYSIS,n.lastStartLoc,0,L(c)),r.key=d(e,c.value||"");break;case 7:null==c.value&&u(e,t.UNEXPECTED_LEXICAL_ANALYSIS,n.lastStartLoc,0,L(c)),r.key=_(e,c.value||"");break;default:u(e,t.UNEXPECTED_EMPTY_LINKED_KEY,n.lastStartLoc,0);const o=e.context(),s=a(7,o.offset,o.startLoc);return s.value="",E(s,o.offset,o.startLoc),r.key=s,E(r,o.offset,o.startLoc),{nextConsumeToken:c,node:r}}return E(r,e.currentOffset(),e.currentPosition()),{node:r}}function k(e){const n=e.context(),r=a(2,1===n.currentType?e.currentOffset():n.offset,1===n.currentType?n.endLoc:n.startLoc);r.items=[];let c=null;do{const o=c||e.nextToken();switch(c=null,o.type){case 0:null==o.value&&u(e,t.UNEXPECTED_LEXICAL_ANALYSIS,n.lastStartLoc,0,L(o)),r.items.push(p(e,o.value||""));break;case 6:null==o.value&&u(e,t.UNEXPECTED_LEXICAL_ANALYSIS,n.lastStartLoc,0,L(o)),r.items.push(d(e,o.value||""));break;case 5:null==o.value&&u(e,t.UNEXPECTED_LEXICAL_ANALYSIS,n.lastStartLoc,0,L(o)),r.items.push(N(e,o.value||""));break;case 7:null==o.value&&u(e,t.UNEXPECTED_LEXICAL_ANALYSIS,n.lastStartLoc,0,L(o)),r.items.push(_(e,o.value||""));break;case 8:const s=C(e);r.items.push(s.node),c=s.nextConsumeToken||null}}while(14!==n.currentType&&1!==n.currentType);return E(r,1===n.currentType?n.lastOffset:e.currentOffset(),1===n.currentType?n.lastEndLoc:e.currentPosition()),r}function T(e){const n=e.context(),{offset:r,startLoc:c}=n,o=k(e);return 14===n.currentType?o:function(e,n,r,c){const o=e.context();let s=0===c.items.length;const i=a(1,n,r);i.cases=[],i.cases.push(c);do{const t=k(e);s||(s=0===t.items.length),i.cases.push(t)}while(14!==o.currentType);return s&&u(e,t.MUST_HAVE_MESSAGES_IN_PLURAL,r,0),E(i,e.currentOffset(),e.currentPosition()),i}(e,r,c,o)}return{parse:function(n){const c=i(n,e.assign({},r)),s=c.context(),f=a(0,s.offset,s.startLoc);return o&&f.loc&&(f.loc.source=n),f.body=T(c),14!==s.currentType&&u(c,t.UNEXPECTED_LEXICAL_ANALYSIS,s.lastStartLoc,0,n[s.offset]||""),E(f,c.currentOffset(),c.currentPosition()),f}}}function L(e){if(14===e.type)return"EOF";const t=(e.value||"").replace(/\r?\n/gu,"\\n");return t.length>10?t.slice(0,9)+"…":t}function p(e,t){for(let n=0;n<e.length;n++)d(e[n],t)}function d(e,t){switch(e.type){case 1:p(e.cases,t),t.helper("plural");break;case 2:p(e.items,t);break;case 6:d(e.key,t),t.helper("linked"),t.helper("type");break;case 5:t.helper("interpolate"),t.helper("list");break;case 4:t.helper("interpolate"),t.helper("named")}}function N(e,t={}){const n=function(e,t={}){const n={ast:e,helpers:new Set};return{context:()=>n,helper:e=>(n.helpers.add(e),e)}}(e);n.helper("normalize"),e.body&&d(e.body,n);const r=n.context();e.helpers=Array.from(r.helpers)}function _(e,t){const{helper:n}=e;switch(t.type){case 0:!function(e,t){t.body?_(e,t.body):e.push("null")}(e,t);break;case 1:!function(e,t){const{helper:n,needIndent:r}=e;if(t.cases.length>1){e.push(`${n("plural")}([`),e.indent(r());const c=t.cases.length;for(let n=0;n<c&&(_(e,t.cases[n]),n!==c-1);n++)e.push(", ");e.deindent(r()),e.push("])")}}(e,t);break;case 2:!function(e,t){const{helper:n,needIndent:r}=e;e.push(`${n("normalize")}([`),e.indent(r());const c=t.items.length;for(let o=0;o<c&&(_(e,t.items[o]),o!==c-1);o++)e.push(", ");e.deindent(r()),e.push("])")}(e,t);break;case 6:!function(e,t){const{helper:n}=e;e.push(`${n("linked")}(`),_(e,t.key),t.modifier?(e.push(", "),_(e,t.modifier),e.push(", _type")):e.push(", undefined, _type"),e.push(")")}(e,t);break;case 8:case 7:case 9:case 3:e.push(JSON.stringify(t.value),t);break;case 5:e.push(`${n("interpolate")}(${n("list")}(${t.index}))`,t);break;case 4:e.push(`${n("interpolate")}(${n("named")}(${JSON.stringify(t.key)}))`,t)}}exports.CompileErrorCodes=t,exports.ERROR_DOMAIN="parser",exports.baseCompile=function(t,n={}){const r=e.assign({},n),c=E(r).parse(t);return N(c,r),((t,n={})=>{const r=e.isString(n.mode)?n.mode:"normal",c=e.isString(n.filename)?n.filename:"message.intl",o=!!n.sourceMap,s=null!=n.breakLineCode?n.breakLineCode:"arrow"===r?";":"\n",u=n.needIndent?n.needIndent:"arrow"!==r,a=t.helpers||[],i=function(e,t){const{sourceMap:n,filename:r,breakLineCode:c,needIndent:o}=t,s={source:e.loc.source,filename:r,code:"",column:1,line:1,offset:0,map:void 0,breakLineCode:c,needIndent:o,indentLevel:0};function u(e,t){s.code+=e}function a(e,t=!0){const n=t?c:"";u(o?n+" ".repeat(e):n)}return{context:()=>s,push:u,indent:function(e=!0){const t=++s.indentLevel;e&&a(t)},deindent:function(e=!0){const t=--s.indentLevel;e&&a(t)},newline:function(){a(s.indentLevel)},helper:e=>`_${e}`,needIndent:()=>s.needIndent}}(t,{mode:r,filename:c,sourceMap:o,breakLineCode:s,needIndent:u});i.push("normal"===r?"function __msg__ (ctx) {":"(ctx) => {"),i.indent(u),a.length>0&&(i.push(`const { ${a.map((e=>`${e}: _${e}`)).join(", ")} } = ctx`),i.newline()),i.push("return "),_(i,t),i.deindent(u),i.push("}");const{code:f,map:l}=i.context();return{ast:t,code:f,map:l?l.toJSON():void 0}})(c,r)},exports.createCompileError=n,exports.createLocation=c,exports.createParser=E,exports.createPosition=r,exports.defaultOnError=function(e){throw e};