@intlify/message-compiler 9.2.0-beta.36 → 9.2.0-beta.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * message-compiler v9.2.0-beta.36
2
+ * message-compiler v9.2.0-beta.37
3
3
  * (c) 2022 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -350,6 +350,16 @@ function createTokenizer(source, options = {}) {
350
350
  scnr.resetPeek();
351
351
  return ret;
352
352
  }
353
+ function detectModuloStart(scnr) {
354
+ const spaces = peekSpaces(scnr);
355
+ const ret = scnr.currentPeek() === "%" /* Modulo */ &&
356
+ scnr.peek() === "{" /* BraceLeft */;
357
+ scnr.resetPeek();
358
+ return {
359
+ isModulo: ret,
360
+ hasSpace: spaces.length > 0
361
+ };
362
+ }
353
363
  function isTextStart(scnr, reset = true) {
354
364
  const fn = (hasSpace = false, prev = '', detectModulo = false) => {
355
365
  const ch = scnr.currentPeek();
@@ -431,6 +441,15 @@ function createTokenizer(source, options = {}) {
431
441
  }
432
442
  return num;
433
443
  }
444
+ function readModulo(scnr) {
445
+ skipSpaces(scnr);
446
+ const ch = scnr.currentChar();
447
+ if (ch !== "%" /* Modulo */) {
448
+ emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
449
+ }
450
+ scnr.next();
451
+ return "%" /* Modulo */;
452
+ }
434
453
  function readText(scnr) {
435
454
  let buf = '';
436
455
  while (true) {
@@ -777,13 +796,15 @@ function createTokenizer(source, options = {}) {
777
796
  context.inLinked = false;
778
797
  return token;
779
798
  }
799
+ const { isModulo, hasSpace } = detectModuloStart(scnr);
800
+ if (isModulo) {
801
+ return hasSpace
802
+ ? getToken(context, 0 /* Text */, readText(scnr))
803
+ : getToken(context, 4 /* Modulo */, readModulo(scnr));
804
+ }
780
805
  if (isTextStart(scnr)) {
781
806
  return getToken(context, 0 /* Text */, readText(scnr));
782
807
  }
783
- if (ch === "%" /* Modulo */) {
784
- scnr.next();
785
- return getToken(context, 4 /* Modulo */, "%" /* Modulo */);
786
- }
787
808
  break;
788
809
  }
789
810
  return token;
@@ -1367,17 +1388,14 @@ const generate = (ast, options = {} // eslint-disable-line
1367
1388
  function getMappingName(node) {
1368
1389
  switch (node.type) {
1369
1390
  case 3 /* Text */:
1391
+ case 9 /* Literal */:
1392
+ case 8 /* LinkedModifier */:
1393
+ case 7 /* LinkedKey */:
1370
1394
  return node.value;
1371
1395
  case 5 /* List */:
1372
1396
  return node.index.toString();
1373
1397
  case 4 /* Named */:
1374
1398
  return node.key;
1375
- case 9 /* Literal */:
1376
- return node.value;
1377
- case 8 /* LinkedModifier */:
1378
- return node.value;
1379
- case 7 /* LinkedKey */:
1380
- return node.value;
1381
1399
  default:
1382
1400
  return undefined;
1383
1401
  }
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * message-compiler v9.2.0-beta.36
2
+ * message-compiler v9.2.0-beta.37
3
3
  * (c) 2022 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -349,6 +349,16 @@ function createTokenizer(source, options = {}) {
349
349
  scnr.resetPeek();
350
350
  return ret;
351
351
  }
352
+ function detectModuloStart(scnr) {
353
+ const spaces = peekSpaces(scnr);
354
+ const ret = scnr.currentPeek() === "%" /* Modulo */ &&
355
+ scnr.peek() === "{" /* BraceLeft */;
356
+ scnr.resetPeek();
357
+ return {
358
+ isModulo: ret,
359
+ hasSpace: spaces.length > 0
360
+ };
361
+ }
352
362
  function isTextStart(scnr, reset = true) {
353
363
  const fn = (hasSpace = false, prev = '', detectModulo = false) => {
354
364
  const ch = scnr.currentPeek();
@@ -430,6 +440,15 @@ function createTokenizer(source, options = {}) {
430
440
  }
431
441
  return num;
432
442
  }
443
+ function readModulo(scnr) {
444
+ skipSpaces(scnr);
445
+ const ch = scnr.currentChar();
446
+ if (ch !== "%" /* Modulo */) {
447
+ emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
448
+ }
449
+ scnr.next();
450
+ return "%" /* Modulo */;
451
+ }
433
452
  function readText(scnr) {
434
453
  let buf = '';
435
454
  while (true) {
@@ -776,13 +795,15 @@ function createTokenizer(source, options = {}) {
776
795
  context.inLinked = false;
777
796
  return token;
778
797
  }
798
+ const { isModulo, hasSpace } = detectModuloStart(scnr);
799
+ if (isModulo) {
800
+ return hasSpace
801
+ ? getToken(context, 0 /* Text */, readText(scnr))
802
+ : getToken(context, 4 /* Modulo */, readModulo(scnr));
803
+ }
779
804
  if (isTextStart(scnr)) {
780
805
  return getToken(context, 0 /* Text */, readText(scnr));
781
806
  }
782
- if (ch === "%" /* Modulo */) {
783
- scnr.next();
784
- return getToken(context, 4 /* Modulo */, "%" /* Modulo */);
785
- }
786
807
  break;
787
808
  }
788
809
  return token;
@@ -1362,17 +1383,14 @@ const generate = (ast, options = {} // eslint-disable-line
1362
1383
  function getMappingName(node) {
1363
1384
  switch (node.type) {
1364
1385
  case 3 /* Text */:
1386
+ case 9 /* Literal */:
1387
+ case 8 /* LinkedModifier */:
1388
+ case 7 /* LinkedKey */:
1365
1389
  return node.value;
1366
1390
  case 5 /* List */:
1367
1391
  return node.index.toString();
1368
1392
  case 4 /* Named */:
1369
1393
  return node.key;
1370
- case 9 /* Literal */:
1371
- return node.value;
1372
- case 8 /* LinkedModifier */:
1373
- return node.value;
1374
- case 7 /* LinkedKey */:
1375
- return node.value;
1376
1394
  default:
1377
1395
  return undefined;
1378
1396
  }
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * message-compiler v9.2.0-beta.36
2
+ * message-compiler v9.2.0-beta.37
3
3
  * (c) 2022 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -365,6 +365,16 @@ function createTokenizer(source, options = {}) {
365
365
  scnr.resetPeek();
366
366
  return ret;
367
367
  }
368
+ function detectModuloStart(scnr) {
369
+ const spaces = peekSpaces(scnr);
370
+ const ret = scnr.currentPeek() === "%" /* Modulo */ &&
371
+ scnr.peek() === "{" /* BraceLeft */;
372
+ scnr.resetPeek();
373
+ return {
374
+ isModulo: ret,
375
+ hasSpace: spaces.length > 0
376
+ };
377
+ }
368
378
  function isTextStart(scnr, reset = true) {
369
379
  const fn = (hasSpace = false, prev = '', detectModulo = false) => {
370
380
  const ch = scnr.currentPeek();
@@ -446,6 +456,15 @@ function createTokenizer(source, options = {}) {
446
456
  }
447
457
  return num;
448
458
  }
459
+ function readModulo(scnr) {
460
+ skipSpaces(scnr);
461
+ const ch = scnr.currentChar();
462
+ if (ch !== "%" /* Modulo */) {
463
+ emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
464
+ }
465
+ scnr.next();
466
+ return "%" /* Modulo */;
467
+ }
449
468
  function readText(scnr) {
450
469
  let buf = '';
451
470
  while (true) {
@@ -792,13 +811,15 @@ function createTokenizer(source, options = {}) {
792
811
  context.inLinked = false;
793
812
  return token;
794
813
  }
814
+ const { isModulo, hasSpace } = detectModuloStart(scnr);
815
+ if (isModulo) {
816
+ return hasSpace
817
+ ? getToken(context, 0 /* Text */, readText(scnr))
818
+ : getToken(context, 4 /* Modulo */, readModulo(scnr));
819
+ }
795
820
  if (isTextStart(scnr)) {
796
821
  return getToken(context, 0 /* Text */, readText(scnr));
797
822
  }
798
- if (ch === "%" /* Modulo */) {
799
- scnr.next();
800
- return getToken(context, 4 /* Modulo */, "%" /* Modulo */);
801
- }
802
823
  break;
803
824
  }
804
825
  return token;
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * message-compiler v9.2.0-beta.36
2
+ * message-compiler v9.2.0-beta.37
3
3
  * (c) 2022 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
6
- const e=Object.assign,t=e=>"string"==typeof e,n={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},r={[n.EXPECTED_TOKEN]:"Expected token: '{0}'",[n.INVALID_TOKEN_IN_PLACEHOLDER]:"Invalid token in placeholder: '{0}'",[n.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]:"Unterminated single quote in placeholder",[n.UNKNOWN_ESCAPE_SEQUENCE]:"Unknown escape sequence: \\{0}",[n.INVALID_UNICODE_ESCAPE_SEQUENCE]:"Invalid unicode escape sequence: {0}",[n.UNBALANCED_CLOSING_BRACE]:"Unbalanced closing brace",[n.UNTERMINATED_CLOSING_BRACE]:"Unterminated closing brace",[n.EMPTY_PLACEHOLDER]:"Empty placeholder",[n.NOT_ALLOW_NEST_PLACEHOLDER]:"Not allowed nest placeholder",[n.INVALID_LINKED_FORMAT]:"Invalid linked format",[n.MUST_HAVE_MESSAGES_IN_PLURAL]:"Plural must have messages",[n.UNEXPECTED_EMPTY_LINKED_MODIFIER]:"Unexpected empty linked modifier",[n.UNEXPECTED_EMPTY_LINKED_KEY]:"Unexpected empty linked key",[n.UNEXPECTED_LEXICAL_ANALYSIS]:"Unexpected lexical analysis in token: '{0}'"};function c(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 o(e){throw e}const s={start:{line:1,column:1,offset:0},end:{line:1,column:1,offset:0}};function u(e,t,n){return{line:e,column:t,offset:n}}function a(e,t,n){const r={start:e,end:t};return null!=n&&(r.source=n),r}const i=String.fromCharCode(8232),l=String.fromCharCode(8233);function f(e){const t=e;let n=0,r=1,c=1,o=0;const s=e=>"\r"===t[e]&&"\n"===t[e+1],u=e=>t[e]===l,a=e=>t[e]===i,f=e=>s(e)||(e=>"\n"===t[e])(e)||u(e)||a(e),d=e=>s(e)||u(e)||a(e)?"\n":t[e];function p(){return o=0,f(n)&&(r++,c=0),s(n)&&n++,n++,c++,t[n]}return{index:()=>n,line:()=>r,column:()=>c,peekOffset:()=>o,charAt:d,currentChar:()=>d(n),currentPeek:()=>d(n+o),next:p,peek:function(){return s(n+o)&&o++,o++,t[n+o]},reset:function(){n=0,r=1,c=1,o=0},resetPeek:function(e=0){o=e},skipToPeek:function(){const e=n+o;for(;e!==n;)p();o=0}}}const d=void 0;function p(e,t={}){const n=!1!==t.location,r=f(e),c=()=>r.index(),o=()=>u(r.line(),r.column(),r.index()),s=o(),i=c(),l={currentType:14,offset:i,startLoc:s,endLoc:s,lastType:14,lastOffset:i,lastStartLoc:s,lastEndLoc:s,braceNest:0,inLinked:!1,text:""},p=()=>l,{onError:E}=t;function L(e,t,r){e.endLoc=o(),e.currentType=t;const c={type:t};return n&&(c.loc=a(e.startLoc,e.endLoc)),null!=r&&(c.value=r),c}const k=e=>L(e,14);function h(e,t){return e.currentChar()===t?(e.next(),t):(o(),"")}function N(e){let t="";for(;" "===e.currentPeek()||"\n"===e.currentPeek();)t+=e.currentPeek(),e.peek();return t}function _(e){const t=N(e);return e.skipToPeek(),t}function T(e){if(e===d)return!1;const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||95===t}function C(e,t){const{currentType:n}=t;if(2!==n)return!1;N(e);const r=function(e){if(e===d)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){N(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 y(e,t){const n=e.currentChar();return n===d?d:t(n)?(e.next(),n):null}function m(e){return y(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 I(e){return y(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57}))}function O(e){return y(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}))}function S(e){let t="",n="";for(;t=I(e);)n+=t;return n}function A(e){const t=e.currentChar();switch(t){case"\\":case"'":return e.next(),`\\${t}`;case"u":return b(e,t,4);case"U":return b(e,t,6);default:return o(),""}}function b(e,t,n){h(e,t);let r="";for(let t=0;t<n;t++){const t=O(e);if(!t){o(),e.currentChar();break}r+=t}return`\\${t}${r}`}function v(e){_(e);const t=h(e,"|");return _(e),t}function D(e,t){let n=null;switch(e.currentChar()){case"{":return t.braceNest>=1&&o(),e.next(),n=L(t,2,"{"),_(e),t.braceNest++,n;case"}":return t.braceNest>0&&2===t.currentType&&o(),e.next(),n=L(t,3,"}"),t.braceNest--,t.braceNest>0&&_(e),t.inLinked&&0===t.braceNest&&(t.inLinked=!1),n;case"@":return t.braceNest>0&&o(),n=U(e,t)||k(t),t.braceNest=0,n;default:let r=!0,c=!0,s=!0;if(P(e))return t.braceNest>0&&o(),n=L(t,1,v(e)),t.braceNest=0,t.inLinked=!1,n;if(t.braceNest>0&&(5===t.currentType||6===t.currentType||7===t.currentType))return o(),t.braceNest=0,g(e,t);if(r=function(e,t){const{currentType:n}=t;if(2!==n)return!1;N(e);const r=T(e.currentPeek());return e.resetPeek(),r}(e,t))return n=L(t,5,function(e){_(e);let t="",n="";for(;t=m(e);)n+=t;return e.currentChar()===d&&o(),n}(e)),_(e),n;if(c=C(e,t))return n=L(t,6,function(e){_(e);let t="";return"-"===e.currentChar()?(e.next(),t+=`-${S(e)}`):t+=S(e),e.currentChar()===d&&o(),t}(e)),_(e),n;if(s=function(e,t){const{currentType:n}=t;if(2!==n)return!1;N(e);const r="'"===e.currentPeek();return e.resetPeek(),r}(e,t))return n=L(t,7,function(e){_(e),h(e,"'");let t="",n="";const r=e=>"'"!==e&&"\n"!==e;for(;t=y(e,r);)n+="\\"===t?A(e):t;const c=e.currentChar();return"\n"===c||c===d?(o(),"\n"===c&&(e.next(),h(e,"'")),n):(h(e,"'"),n)}(e)),_(e),n;if(!r&&!c&&!s)return n=L(t,13,function(e){_(e);let t="",n="";const r=e=>"{"!==e&&"}"!==e&&" "!==e&&"\n"!==e;for(;t=y(e,r);)n+=t;return n}(e)),o(),n.value,_(e),n}return n}function U(e,t){const{currentType:n}=t;let r=null;const c=e.currentChar();switch(8!==n&&9!==n&&12!==n&&10!==n||"\n"!==c&&" "!==c||o(),c){case"@":return e.next(),r=L(t,8,"@"),t.inLinked=!0,r;case".":return _(e),e.next(),L(t,9,".");case":":return _(e),e.next(),L(t,10,":");default:return P(e)?(r=L(t,1,v(e)),t.braceNest=0,t.inLinked=!1,r):function(e,t){const{currentType:n}=t;if(8!==n)return!1;N(e);const r="."===e.currentPeek();return e.resetPeek(),r}(e,t)||function(e,t){const{currentType:n}=t;if(8!==n&&12!==n)return!1;N(e);const r=":"===e.currentPeek();return e.resetPeek(),r}(e,t)?(_(e),U(e,t)):function(e,t){const{currentType:n}=t;if(9!==n)return!1;N(e);const r=T(e.currentPeek());return e.resetPeek(),r}(e,t)?(_(e),L(t,12,function(e){let t="",n="";for(;t=m(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?T(e.peek()):!("@"===t||"%"===t||"|"===t||":"===t||"."===t||" "===t||!t)&&("\n"===t?(e.peek(),r()):T(t))},c=r();return e.resetPeek(),c}(e,t)?(_(e),"{"===c?D(e,t)||r:L(t,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===n&&o(),t.braceNest=0,t.inLinked=!1,g(e,t))}}function g(e,t){let n={type:14};if(t.braceNest>0)return D(e,t)||k(t);if(t.inLinked)return U(e,t)||k(t);const r=e.currentChar();switch(r){case"{":return D(e,t)||k(t);case"}":return o(),e.next(),L(t,3,"}");case"@":return U(e,t)||k(t);default:if(P(e))return n=L(t,1,v(e)),t.braceNest=0,t.inLinked=!1,n;if(x(e))return L(t,0,function(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}(e));if("%"===r)return e.next(),L(t,4,"%")}return n}return{nextToken:function(){const{currentType:e,offset:t,startLoc:n,endLoc:s}=l;return l.lastType=e,l.lastOffset=t,l.lastStartLoc=n,l.lastEndLoc=s,l.offset=c(),l.startLoc=o(),r.currentChar()===d?L(l,14):g(r,l)},currentOffset:c,currentPosition:o,context:p}}const E="parser",L=/(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;function k(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 h(t={}){const n=!1!==t.location,{onError:r}=t;function c(e,t,r){const c={type:e,start:t,end:t};return n&&(c.loc={start:r,end:r}),c}function o(e,t,r,c){e.end=t,c&&(e.type=c),n&&e.loc&&(e.loc.end=r)}function s(e,t){const n=e.context(),r=c(3,n.offset,n.startLoc);return r.value=t,o(r,e.currentOffset(),e.currentPosition()),r}function u(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(5,r,s);return u.index=parseInt(t,10),e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function a(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(4,r,s);return u.key=t,e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function i(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(9,r,s);return u.value=t.replace(L,k),e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function l(e){const t=e.context(),n=c(6,t.offset,t.startLoc);let r=e.nextToken();if(9===r.type){const t=function(e){const t=e.nextToken(),n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(8,r,s);return 12!==t.type?(n.lastStartLoc,u.value="",o(u,r,s),{nextConsumeToken:t,node:u}):(null==t.value&&(n.lastStartLoc,N(t)),u.value=t.value||"",o(u,e.currentOffset(),e.currentPosition()),{node:u})}(e);n.modifier=t.node,r=t.nextConsumeToken||e.nextToken()}switch(10!==r.type&&(t.lastStartLoc,N(r)),r=e.nextToken(),2===r.type&&(r=e.nextToken()),r.type){case 11:null==r.value&&(t.lastStartLoc,N(r)),n.key=function(e,t){const n=e.context(),r=c(7,n.offset,n.startLoc);return r.value=t,o(r,e.currentOffset(),e.currentPosition()),r}(e,r.value||"");break;case 5:null==r.value&&(t.lastStartLoc,N(r)),n.key=a(e,r.value||"");break;case 6:null==r.value&&(t.lastStartLoc,N(r)),n.key=u(e,r.value||"");break;case 7:null==r.value&&(t.lastStartLoc,N(r)),n.key=i(e,r.value||"");break;default:t.lastStartLoc;const s=e.context(),l=c(7,s.offset,s.startLoc);return l.value="",o(l,s.offset,s.startLoc),n.key=l,o(n,s.offset,s.startLoc),{nextConsumeToken:r,node:n}}return o(n,e.currentOffset(),e.currentPosition()),{node:n}}function f(e){const t=e.context(),n=c(2,1===t.currentType?e.currentOffset():t.offset,1===t.currentType?t.endLoc:t.startLoc);n.items=[];let r=null;do{const c=r||e.nextToken();switch(r=null,c.type){case 0:null==c.value&&(t.lastStartLoc,N(c)),n.items.push(s(e,c.value||""));break;case 6:null==c.value&&(t.lastStartLoc,N(c)),n.items.push(u(e,c.value||""));break;case 5:null==c.value&&(t.lastStartLoc,N(c)),n.items.push(a(e,c.value||""));break;case 7:null==c.value&&(t.lastStartLoc,N(c)),n.items.push(i(e,c.value||""));break;case 8:const o=l(e);n.items.push(o.node),r=o.nextConsumeToken||null}}while(14!==t.currentType&&1!==t.currentType);return o(n,1===t.currentType?t.lastOffset:e.currentOffset(),1===t.currentType?t.lastEndLoc:e.currentPosition()),n}function d(e){const t=e.context(),{offset:n,startLoc:r}=t,s=f(e);return 14===t.currentType?s:function(e,t,n,r){const s=e.context();let u=0===r.items.length;const a=c(1,t,n);a.cases=[],a.cases.push(r);do{const t=f(e);u||(u=0===t.items.length),a.cases.push(t)}while(14!==s.currentType);return o(a,e.currentOffset(),e.currentPosition()),a}(e,n,r,s)}return{parse:function(r){const s=p(r,e({},t)),u=s.context(),a=c(0,u.offset,u.startLoc);return n&&a.loc&&(a.loc.source=r),a.body=d(s),14!==u.currentType&&(u.lastStartLoc,r[u.offset]),o(a,s.currentOffset(),s.currentPosition()),a}}}function N(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 _(e,t){for(let n=0;n<e.length;n++)T(e[n],t)}function T(e,t){switch(e.type){case 1:_(e.cases,t),t.helper("plural");break;case 2:_(e.items,t);break;case 6:T(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 C(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&&T(e.body,n);const r=n.context();e.helpers=Array.from(r.helpers)}function P(e,t){const{helper:n}=e;switch(t.type){case 0:!function(e,t){t.body?P(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&&(P(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 n=0;n<c&&(P(e,t.items[n]),n!==c-1);n++)e.push(", ");e.deindent(r()),e.push("])")}(e,t);break;case 6:!function(e,t){const{helper:n}=e;e.push(`${n("linked")}(`),P(e,t.key),t.modifier?(e.push(", "),P(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)}}function x(n,r={}){const c=e({},r),o=h(c).parse(n);return C(o,c),((e,n={})=>{const r=t(n.mode)?n.mode:"normal",c=t(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=e.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}}(e,{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 "),P(i,e),i.deindent(u),i.push("}");const{code:l,map:f}=i.context();return{ast:e,code:l,map:f?f.toJSON():void 0}})(o,c)}export{n as CompileErrorCodes,E as ERROR_DOMAIN,s as LocationStub,x as baseCompile,c as createCompileError,a as createLocation,h as createParser,u as createPosition,o as defaultOnError,r as errorMessages};
6
+ const e=Object.assign,t=e=>"string"==typeof e,n={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},r={[n.EXPECTED_TOKEN]:"Expected token: '{0}'",[n.INVALID_TOKEN_IN_PLACEHOLDER]:"Invalid token in placeholder: '{0}'",[n.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]:"Unterminated single quote in placeholder",[n.UNKNOWN_ESCAPE_SEQUENCE]:"Unknown escape sequence: \\{0}",[n.INVALID_UNICODE_ESCAPE_SEQUENCE]:"Invalid unicode escape sequence: {0}",[n.UNBALANCED_CLOSING_BRACE]:"Unbalanced closing brace",[n.UNTERMINATED_CLOSING_BRACE]:"Unterminated closing brace",[n.EMPTY_PLACEHOLDER]:"Empty placeholder",[n.NOT_ALLOW_NEST_PLACEHOLDER]:"Not allowed nest placeholder",[n.INVALID_LINKED_FORMAT]:"Invalid linked format",[n.MUST_HAVE_MESSAGES_IN_PLURAL]:"Plural must have messages",[n.UNEXPECTED_EMPTY_LINKED_MODIFIER]:"Unexpected empty linked modifier",[n.UNEXPECTED_EMPTY_LINKED_KEY]:"Unexpected empty linked key",[n.UNEXPECTED_LEXICAL_ANALYSIS]:"Unexpected lexical analysis in token: '{0}'"};function c(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 o(e){throw e}const s={start:{line:1,column:1,offset:0},end:{line:1,column:1,offset:0}};function u(e,t,n){return{line:e,column:t,offset:n}}function a(e,t,n){const r={start:e,end:t};return null!=n&&(r.source=n),r}const i=String.fromCharCode(8232),l=String.fromCharCode(8233);function f(e){const t=e;let n=0,r=1,c=1,o=0;const s=e=>"\r"===t[e]&&"\n"===t[e+1],u=e=>t[e]===l,a=e=>t[e]===i,f=e=>s(e)||(e=>"\n"===t[e])(e)||u(e)||a(e),d=e=>s(e)||u(e)||a(e)?"\n":t[e];function p(){return o=0,f(n)&&(r++,c=0),s(n)&&n++,n++,c++,t[n]}return{index:()=>n,line:()=>r,column:()=>c,peekOffset:()=>o,charAt:d,currentChar:()=>d(n),currentPeek:()=>d(n+o),next:p,peek:function(){return s(n+o)&&o++,o++,t[n+o]},reset:function(){n=0,r=1,c=1,o=0},resetPeek:function(e=0){o=e},skipToPeek:function(){const e=n+o;for(;e!==n;)p();o=0}}}const d=void 0;function p(e,t={}){const n=!1!==t.location,r=f(e),c=()=>r.index(),o=()=>u(r.line(),r.column(),r.index()),s=o(),i=c(),l={currentType:14,offset:i,startLoc:s,endLoc:s,lastType:14,lastOffset:i,lastStartLoc:s,lastEndLoc:s,braceNest:0,inLinked:!1,text:""},p=()=>l,{onError:E}=t;function k(e,t,r){e.endLoc=o(),e.currentType=t;const c={type:t};return n&&(c.loc=a(e.startLoc,e.endLoc)),null!=r&&(c.value=r),c}const L=e=>k(e,14);function h(e,t){return e.currentChar()===t?(e.next(),t):(o(),"")}function N(e){let t="";for(;" "===e.currentPeek()||"\n"===e.currentPeek();)t+=e.currentPeek(),e.peek();return t}function _(e){const t=N(e);return e.skipToPeek(),t}function T(e){if(e===d)return!1;const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||95===t}function C(e,t){const{currentType:n}=t;if(2!==n)return!1;N(e);const r=function(e){if(e===d)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){N(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 y(e,t){const n=e.currentChar();return n===d?d:t(n)?(e.next(),n):null}function m(e){return y(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 I(e){return y(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57}))}function S(e){return y(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}))}function O(e){let t="",n="";for(;t=I(e);)n+=t;return n}function A(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 b(e){const t=e.currentChar();switch(t){case"\\":case"'":return e.next(),`\\${t}`;case"u":return v(e,t,4);case"U":return v(e,t,6);default:return o(),""}}function v(e,t,n){h(e,t);let r="";for(let t=0;t<n;t++){const t=S(e);if(!t){o(),e.currentChar();break}r+=t}return`\\${t}${r}`}function D(e){_(e);const t=h(e,"|");return _(e),t}function U(e,t){let n=null;switch(e.currentChar()){case"{":return t.braceNest>=1&&o(),e.next(),n=k(t,2,"{"),_(e),t.braceNest++,n;case"}":return t.braceNest>0&&2===t.currentType&&o(),e.next(),n=k(t,3,"}"),t.braceNest--,t.braceNest>0&&_(e),t.inLinked&&0===t.braceNest&&(t.inLinked=!1),n;case"@":return t.braceNest>0&&o(),n=g(e,t)||L(t),t.braceNest=0,n;default:let r=!0,c=!0,s=!0;if(P(e))return t.braceNest>0&&o(),n=k(t,1,D(e)),t.braceNest=0,t.inLinked=!1,n;if(t.braceNest>0&&(5===t.currentType||6===t.currentType||7===t.currentType))return o(),t.braceNest=0,M(e,t);if(r=function(e,t){const{currentType:n}=t;if(2!==n)return!1;N(e);const r=T(e.currentPeek());return e.resetPeek(),r}(e,t))return n=k(t,5,function(e){_(e);let t="",n="";for(;t=m(e);)n+=t;return e.currentChar()===d&&o(),n}(e)),_(e),n;if(c=C(e,t))return n=k(t,6,function(e){_(e);let t="";return"-"===e.currentChar()?(e.next(),t+=`-${O(e)}`):t+=O(e),e.currentChar()===d&&o(),t}(e)),_(e),n;if(s=function(e,t){const{currentType:n}=t;if(2!==n)return!1;N(e);const r="'"===e.currentPeek();return e.resetPeek(),r}(e,t))return n=k(t,7,function(e){_(e),h(e,"'");let t="",n="";const r=e=>"'"!==e&&"\n"!==e;for(;t=y(e,r);)n+="\\"===t?b(e):t;const c=e.currentChar();return"\n"===c||c===d?(o(),"\n"===c&&(e.next(),h(e,"'")),n):(h(e,"'"),n)}(e)),_(e),n;if(!r&&!c&&!s)return n=k(t,13,function(e){_(e);let t="",n="";const r=e=>"{"!==e&&"}"!==e&&" "!==e&&"\n"!==e;for(;t=y(e,r);)n+=t;return n}(e)),o(),n.value,_(e),n}return n}function g(e,t){const{currentType:n}=t;let r=null;const c=e.currentChar();switch(8!==n&&9!==n&&12!==n&&10!==n||"\n"!==c&&" "!==c||o(),c){case"@":return e.next(),r=k(t,8,"@"),t.inLinked=!0,r;case".":return _(e),e.next(),k(t,9,".");case":":return _(e),e.next(),k(t,10,":");default:return P(e)?(r=k(t,1,D(e)),t.braceNest=0,t.inLinked=!1,r):function(e,t){const{currentType:n}=t;if(8!==n)return!1;N(e);const r="."===e.currentPeek();return e.resetPeek(),r}(e,t)||function(e,t){const{currentType:n}=t;if(8!==n&&12!==n)return!1;N(e);const r=":"===e.currentPeek();return e.resetPeek(),r}(e,t)?(_(e),g(e,t)):function(e,t){const{currentType:n}=t;if(9!==n)return!1;N(e);const r=T(e.currentPeek());return e.resetPeek(),r}(e,t)?(_(e),k(t,12,function(e){let t="",n="";for(;t=m(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?T(e.peek()):!("@"===t||"%"===t||"|"===t||":"===t||"."===t||" "===t||!t)&&("\n"===t?(e.peek(),r()):T(t))},c=r();return e.resetPeek(),c}(e,t)?(_(e),"{"===c?U(e,t)||r:k(t,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===n&&o(),t.braceNest=0,t.inLinked=!1,M(e,t))}}function M(e,t){let n={type:14};if(t.braceNest>0)return U(e,t)||L(t);if(t.inLinked)return g(e,t)||L(t);switch(e.currentChar()){case"{":return U(e,t)||L(t);case"}":return o(),e.next(),k(t,3,"}");case"@":return g(e,t)||L(t);default:if(P(e))return n=k(t,1,D(e)),t.braceNest=0,t.inLinked=!1,n;const{isModulo:r,hasSpace:c}=function(e){const t=N(e),n="%"===e.currentPeek()&&"{"===e.peek();return e.resetPeek(),{isModulo:n,hasSpace:t.length>0}}(e);if(r)return c?k(t,0,A(e)):k(t,4,function(e){_(e);return"%"!==e.currentChar()&&o(),e.next(),"%"}(e));if(x(e))return k(t,0,A(e))}return n}return{nextToken:function(){const{currentType:e,offset:t,startLoc:n,endLoc:s}=l;return l.lastType=e,l.lastOffset=t,l.lastStartLoc=n,l.lastEndLoc=s,l.offset=c(),l.startLoc=o(),r.currentChar()===d?k(l,14):M(r,l)},currentOffset:c,currentPosition:o,context:p}}const E="parser",k=/(?:\\\\|\\'|\\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 h(t={}){const n=!1!==t.location,{onError:r}=t;function c(e,t,r){const c={type:e,start:t,end:t};return n&&(c.loc={start:r,end:r}),c}function o(e,t,r,c){e.end=t,c&&(e.type=c),n&&e.loc&&(e.loc.end=r)}function s(e,t){const n=e.context(),r=c(3,n.offset,n.startLoc);return r.value=t,o(r,e.currentOffset(),e.currentPosition()),r}function u(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(5,r,s);return u.index=parseInt(t,10),e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function a(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(4,r,s);return u.key=t,e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function i(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(9,r,s);return u.value=t.replace(k,L),e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function l(e){const t=e.context(),n=c(6,t.offset,t.startLoc);let r=e.nextToken();if(9===r.type){const t=function(e){const t=e.nextToken(),n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(8,r,s);return 12!==t.type?(n.lastStartLoc,u.value="",o(u,r,s),{nextConsumeToken:t,node:u}):(null==t.value&&(n.lastStartLoc,N(t)),u.value=t.value||"",o(u,e.currentOffset(),e.currentPosition()),{node:u})}(e);n.modifier=t.node,r=t.nextConsumeToken||e.nextToken()}switch(10!==r.type&&(t.lastStartLoc,N(r)),r=e.nextToken(),2===r.type&&(r=e.nextToken()),r.type){case 11:null==r.value&&(t.lastStartLoc,N(r)),n.key=function(e,t){const n=e.context(),r=c(7,n.offset,n.startLoc);return r.value=t,o(r,e.currentOffset(),e.currentPosition()),r}(e,r.value||"");break;case 5:null==r.value&&(t.lastStartLoc,N(r)),n.key=a(e,r.value||"");break;case 6:null==r.value&&(t.lastStartLoc,N(r)),n.key=u(e,r.value||"");break;case 7:null==r.value&&(t.lastStartLoc,N(r)),n.key=i(e,r.value||"");break;default:t.lastStartLoc;const s=e.context(),l=c(7,s.offset,s.startLoc);return l.value="",o(l,s.offset,s.startLoc),n.key=l,o(n,s.offset,s.startLoc),{nextConsumeToken:r,node:n}}return o(n,e.currentOffset(),e.currentPosition()),{node:n}}function f(e){const t=e.context(),n=c(2,1===t.currentType?e.currentOffset():t.offset,1===t.currentType?t.endLoc:t.startLoc);n.items=[];let r=null;do{const c=r||e.nextToken();switch(r=null,c.type){case 0:null==c.value&&(t.lastStartLoc,N(c)),n.items.push(s(e,c.value||""));break;case 6:null==c.value&&(t.lastStartLoc,N(c)),n.items.push(u(e,c.value||""));break;case 5:null==c.value&&(t.lastStartLoc,N(c)),n.items.push(a(e,c.value||""));break;case 7:null==c.value&&(t.lastStartLoc,N(c)),n.items.push(i(e,c.value||""));break;case 8:const o=l(e);n.items.push(o.node),r=o.nextConsumeToken||null}}while(14!==t.currentType&&1!==t.currentType);return o(n,1===t.currentType?t.lastOffset:e.currentOffset(),1===t.currentType?t.lastEndLoc:e.currentPosition()),n}function d(e){const t=e.context(),{offset:n,startLoc:r}=t,s=f(e);return 14===t.currentType?s:function(e,t,n,r){const s=e.context();let u=0===r.items.length;const a=c(1,t,n);a.cases=[],a.cases.push(r);do{const t=f(e);u||(u=0===t.items.length),a.cases.push(t)}while(14!==s.currentType);return o(a,e.currentOffset(),e.currentPosition()),a}(e,n,r,s)}return{parse:function(r){const s=p(r,e({},t)),u=s.context(),a=c(0,u.offset,u.startLoc);return n&&a.loc&&(a.loc.source=r),a.body=d(s),14!==u.currentType&&(u.lastStartLoc,r[u.offset]),o(a,s.currentOffset(),s.currentPosition()),a}}}function N(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 _(e,t){for(let n=0;n<e.length;n++)T(e[n],t)}function T(e,t){switch(e.type){case 1:_(e.cases,t),t.helper("plural");break;case 2:_(e.items,t);break;case 6:T(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 C(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&&T(e.body,n);const r=n.context();e.helpers=Array.from(r.helpers)}function P(e,t){const{helper:n}=e;switch(t.type){case 0:!function(e,t){t.body?P(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&&(P(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 n=0;n<c&&(P(e,t.items[n]),n!==c-1);n++)e.push(", ");e.deindent(r()),e.push("])")}(e,t);break;case 6:!function(e,t){const{helper:n}=e;e.push(`${n("linked")}(`),P(e,t.key),t.modifier?(e.push(", "),P(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)}}function x(n,r={}){const c=e({},r),o=h(c).parse(n);return C(o,c),((e,n={})=>{const r=t(n.mode)?n.mode:"normal",c=t(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=e.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}}(e,{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 "),P(i,e),i.deindent(u),i.push("}");const{code:l,map:f}=i.context();return{ast:e,code:l,map:f?f.toJSON():void 0}})(o,c)}export{n as CompileErrorCodes,E as ERROR_DOMAIN,s as LocationStub,x as baseCompile,c as createCompileError,a as createLocation,h as createParser,u as createPosition,o as defaultOnError,r as errorMessages};
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * message-compiler v9.2.0-beta.36
2
+ * message-compiler v9.2.0-beta.37
3
3
  * (c) 2022 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -346,6 +346,16 @@ function createTokenizer(source, options = {}) {
346
346
  scnr.resetPeek();
347
347
  return ret;
348
348
  }
349
+ function detectModuloStart(scnr) {
350
+ const spaces = peekSpaces(scnr);
351
+ const ret = scnr.currentPeek() === "%" /* Modulo */ &&
352
+ scnr.peek() === "{" /* BraceLeft */;
353
+ scnr.resetPeek();
354
+ return {
355
+ isModulo: ret,
356
+ hasSpace: spaces.length > 0
357
+ };
358
+ }
349
359
  function isTextStart(scnr, reset = true) {
350
360
  const fn = (hasSpace = false, prev = '', detectModulo = false) => {
351
361
  const ch = scnr.currentPeek();
@@ -427,6 +437,15 @@ function createTokenizer(source, options = {}) {
427
437
  }
428
438
  return num;
429
439
  }
440
+ function readModulo(scnr) {
441
+ skipSpaces(scnr);
442
+ const ch = scnr.currentChar();
443
+ if (ch !== "%" /* Modulo */) {
444
+ emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
445
+ }
446
+ scnr.next();
447
+ return "%" /* Modulo */;
448
+ }
430
449
  function readText(scnr) {
431
450
  let buf = '';
432
451
  while (true) {
@@ -773,13 +792,15 @@ function createTokenizer(source, options = {}) {
773
792
  context.inLinked = false;
774
793
  return token;
775
794
  }
795
+ const { isModulo, hasSpace } = detectModuloStart(scnr);
796
+ if (isModulo) {
797
+ return hasSpace
798
+ ? getToken(context, 0 /* Text */, readText(scnr))
799
+ : getToken(context, 4 /* Modulo */, readModulo(scnr));
800
+ }
776
801
  if (isTextStart(scnr)) {
777
802
  return getToken(context, 0 /* Text */, readText(scnr));
778
803
  }
779
- if (ch === "%" /* Modulo */) {
780
- scnr.next();
781
- return getToken(context, 4 /* Modulo */, "%" /* Modulo */);
782
- }
783
804
  break;
784
805
  }
785
806
  return token;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * message-compiler v9.2.0-beta.36
2
+ * message-compiler v9.2.0-beta.37
3
3
  * (c) 2022 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -368,6 +368,16 @@ var IntlifyMessageCompiler = (function (exports) {
368
368
  scnr.resetPeek();
369
369
  return ret;
370
370
  }
371
+ function detectModuloStart(scnr) {
372
+ const spaces = peekSpaces(scnr);
373
+ const ret = scnr.currentPeek() === "%" /* Modulo */ &&
374
+ scnr.peek() === "{" /* BraceLeft */;
375
+ scnr.resetPeek();
376
+ return {
377
+ isModulo: ret,
378
+ hasSpace: spaces.length > 0
379
+ };
380
+ }
371
381
  function isTextStart(scnr, reset = true) {
372
382
  const fn = (hasSpace = false, prev = '', detectModulo = false) => {
373
383
  const ch = scnr.currentPeek();
@@ -449,6 +459,15 @@ var IntlifyMessageCompiler = (function (exports) {
449
459
  }
450
460
  return num;
451
461
  }
462
+ function readModulo(scnr) {
463
+ skipSpaces(scnr);
464
+ const ch = scnr.currentChar();
465
+ if (ch !== "%" /* Modulo */) {
466
+ emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
467
+ }
468
+ scnr.next();
469
+ return "%" /* Modulo */;
470
+ }
452
471
  function readText(scnr) {
453
472
  let buf = '';
454
473
  while (true) {
@@ -795,13 +814,15 @@ var IntlifyMessageCompiler = (function (exports) {
795
814
  context.inLinked = false;
796
815
  return token;
797
816
  }
817
+ const { isModulo, hasSpace } = detectModuloStart(scnr);
818
+ if (isModulo) {
819
+ return hasSpace
820
+ ? getToken(context, 0 /* Text */, readText(scnr))
821
+ : getToken(context, 4 /* Modulo */, readModulo(scnr));
822
+ }
798
823
  if (isTextStart(scnr)) {
799
824
  return getToken(context, 0 /* Text */, readText(scnr));
800
825
  }
801
- if (ch === "%" /* Modulo */) {
802
- scnr.next();
803
- return getToken(context, 4 /* Modulo */, "%" /* Modulo */);
804
- }
805
826
  break;
806
827
  }
807
828
  return token;
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * message-compiler v9.2.0-beta.36
2
+ * message-compiler v9.2.0-beta.37
3
3
  * (c) 2022 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
6
- var IntlifyMessageCompiler=function(e){"use strict";const t=Object.assign,n=e=>"string"==typeof e,r={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},c={[r.EXPECTED_TOKEN]:"Expected token: '{0}'",[r.INVALID_TOKEN_IN_PLACEHOLDER]:"Invalid token in placeholder: '{0}'",[r.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]:"Unterminated single quote in placeholder",[r.UNKNOWN_ESCAPE_SEQUENCE]:"Unknown escape sequence: \\{0}",[r.INVALID_UNICODE_ESCAPE_SEQUENCE]:"Invalid unicode escape sequence: {0}",[r.UNBALANCED_CLOSING_BRACE]:"Unbalanced closing brace",[r.UNTERMINATED_CLOSING_BRACE]:"Unterminated closing brace",[r.EMPTY_PLACEHOLDER]:"Empty placeholder",[r.NOT_ALLOW_NEST_PLACEHOLDER]:"Not allowed nest placeholder",[r.INVALID_LINKED_FORMAT]:"Invalid linked format",[r.MUST_HAVE_MESSAGES_IN_PLURAL]:"Plural must have messages",[r.UNEXPECTED_EMPTY_LINKED_MODIFIER]:"Unexpected empty linked modifier",[r.UNEXPECTED_EMPTY_LINKED_KEY]:"Unexpected empty linked key",[r.UNEXPECTED_LEXICAL_ANALYSIS]:"Unexpected lexical analysis in token: '{0}'"};function o(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 s(e,t,n){return{line:e,column:t,offset:n}}function u(e,t,n){const r={start:e,end:t};return null!=n&&(r.source=n),r}const a=" ",i="\n",l=String.fromCharCode(8232),f=String.fromCharCode(8233);function d(e){const t=e;let n=0,r=1,c=1,o=0;const s=e=>"\r"===t[e]&&t[e+1]===i,u=e=>t[e]===f,a=e=>t[e]===l,d=e=>s(e)||(e=>t[e]===i)(e)||u(e)||a(e),p=e=>s(e)||u(e)||a(e)?i:t[e];function E(){return o=0,d(n)&&(r++,c=0),s(n)&&n++,n++,c++,t[n]}return{index:()=>n,line:()=>r,column:()=>c,peekOffset:()=>o,charAt:p,currentChar:()=>p(n),currentPeek:()=>p(n+o),next:E,peek:function(){return s(n+o)&&o++,o++,t[n+o]},reset:function(){n=0,r=1,c=1,o=0},resetPeek:function(e=0){o=e},skipToPeek:function(){const e=n+o;for(;e!==n;)E();o=0}}}const p=void 0;function E(e,t={}){const n=!1!==t.location,r=d(e),c=()=>r.index(),o=()=>s(r.line(),r.column(),r.index()),l=o(),f=c(),E={currentType:14,offset:f,startLoc:l,endLoc:l,lastType:14,lastOffset:f,lastStartLoc:l,lastEndLoc:l,braceNest:0,inLinked:!1,text:""},L=()=>E,{onError:k}=t;function h(e,t,r){e.endLoc=o(),e.currentType=t;const c={type:t};return n&&(c.loc=u(e.startLoc,e.endLoc)),null!=r&&(c.value=r),c}const N=e=>h(e,14);function _(e,t){return e.currentChar()===t?(e.next(),t):(o(),"")}function T(e){let t="";for(;e.currentPeek()===a||e.currentPeek()===i;)t+=e.currentPeek(),e.peek();return t}function C(e){const t=T(e);return e.skipToPeek(),t}function P(e){if(e===p)return!1;const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||95===t}function y(e,t){const{currentType:n}=t;if(2!==n)return!1;T(e);const r=function(e){if(e===p)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}("-"===e.currentPeek()?e.peek():e.currentPeek());return e.resetPeek(),r}function x(e){T(e);const t="|"===e.currentPeek();return e.resetPeek(),t}function m(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===a||r===i):o===a?(e.peek(),n(!0,a,c)):o!==i||(e.peek(),n(!0,i,c)):"%"===r||t},r=n();return t&&e.resetPeek(),r}function I(e,t){const n=e.currentChar();return n===p?p:t(n)?(e.next(),n):null}function O(e){return I(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 S(e){return I(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57}))}function b(e){return I(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}))}function A(e){let t="",n="";for(;t=S(e);)n+=t;return n}function v(e){const t=e.currentChar();switch(t){case"\\":case"'":return e.next(),`\\${t}`;case"u":return D(e,t,4);case"U":return D(e,t,6);default:return o(),""}}function D(e,t,n){_(e,t);let r="";for(let t=0;t<n;t++){const t=b(e);if(!t){o(),e.currentChar();break}r+=t}return`\\${t}${r}`}function U(e){C(e);const t=_(e,"|");return C(e),t}function g(e,t){let n=null;switch(e.currentChar()){case"{":return t.braceNest>=1&&o(),e.next(),n=h(t,2,"{"),C(e),t.braceNest++,n;case"}":return t.braceNest>0&&2===t.currentType&&o(),e.next(),n=h(t,3,"}"),t.braceNest--,t.braceNest>0&&C(e),t.inLinked&&0===t.braceNest&&(t.inLinked=!1),n;case"@":return t.braceNest>0&&o(),n=M(e,t)||N(t),t.braceNest=0,n;default:let r=!0,c=!0,s=!0;if(x(e))return t.braceNest>0&&o(),n=h(t,1,U(e)),t.braceNest=0,t.inLinked=!1,n;if(t.braceNest>0&&(5===t.currentType||6===t.currentType||7===t.currentType))return o(),t.braceNest=0,R(e,t);if(r=function(e,t){const{currentType:n}=t;if(2!==n)return!1;T(e);const r=P(e.currentPeek());return e.resetPeek(),r}(e,t))return n=h(t,5,function(e){C(e);let t="",n="";for(;t=O(e);)n+=t;return e.currentChar()===p&&o(),n}(e)),C(e),n;if(c=y(e,t))return n=h(t,6,function(e){C(e);let t="";return"-"===e.currentChar()?(e.next(),t+=`-${A(e)}`):t+=A(e),e.currentChar()===p&&o(),t}(e)),C(e),n;if(s=function(e,t){const{currentType:n}=t;if(2!==n)return!1;T(e);const r="'"===e.currentPeek();return e.resetPeek(),r}(e,t))return n=h(t,7,function(e){C(e),_(e,"'");let t="",n="";const r=e=>"'"!==e&&e!==i;for(;t=I(e,r);)n+="\\"===t?v(e):t;const c=e.currentChar();return c===i||c===p?(o(),c===i&&(e.next(),_(e,"'")),n):(_(e,"'"),n)}(e)),C(e),n;if(!r&&!c&&!s)return n=h(t,13,function(e){C(e);let t="",n="";const r=e=>"{"!==e&&"}"!==e&&e!==a&&e!==i;for(;t=I(e,r);)n+=t;return n}(e)),o(),n.value,C(e),n}return n}function M(e,t){const{currentType:n}=t;let r=null;const c=e.currentChar();switch(8!==n&&9!==n&&12!==n&&10!==n||c!==i&&c!==a||o(),c){case"@":return e.next(),r=h(t,8,"@"),t.inLinked=!0,r;case".":return C(e),e.next(),h(t,9,".");case":":return C(e),e.next(),h(t,10,":");default:return x(e)?(r=h(t,1,U(e)),t.braceNest=0,t.inLinked=!1,r):function(e,t){const{currentType:n}=t;if(8!==n)return!1;T(e);const r="."===e.currentPeek();return e.resetPeek(),r}(e,t)||function(e,t){const{currentType:n}=t;if(8!==n&&12!==n)return!1;T(e);const r=":"===e.currentPeek();return e.resetPeek(),r}(e,t)?(C(e),M(e,t)):function(e,t){const{currentType:n}=t;if(9!==n)return!1;T(e);const r=P(e.currentPeek());return e.resetPeek(),r}(e,t)?(C(e),h(t,12,function(e){let t="",n="";for(;t=O(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?P(e.peek()):!("@"===t||"%"===t||"|"===t||":"===t||"."===t||t===a||!t)&&(t===i?(e.peek(),r()):P(t))},c=r();return e.resetPeek(),c}(e,t)?(C(e),"{"===c?g(e,t)||r:h(t,11,function(e){const t=(n=!1,r)=>{const c=e.currentChar();return"{"!==c&&"%"!==c&&"@"!==c&&"|"!==c&&c?c===a?r:c===i?(r+=c,e.next(),t(n,r)):(r+=c,e.next(),t(!0,r)):r};return t(!1,"")}(e))):(8===n&&o(),t.braceNest=0,t.inLinked=!1,R(e,t))}}function R(e,t){let n={type:14};if(t.braceNest>0)return g(e,t)||N(t);if(t.inLinked)return M(e,t)||N(t);const r=e.currentChar();switch(r){case"{":return g(e,t)||N(t);case"}":return o(),e.next(),h(t,3,"}");case"@":return M(e,t)||N(t);default:if(x(e))return n=h(t,1,U(e)),t.braceNest=0,t.inLinked=!1,n;if(m(e))return h(t,0,function(e){let t="";for(;;){const n=e.currentChar();if("{"===n||"}"===n||"@"===n||"|"===n||!n)break;if("%"===n){if(!m(e))break;t+=n,e.next()}else if(n===a||n===i)if(m(e))t+=n,e.next();else{if(x(e))break;t+=n,e.next()}else t+=n,e.next()}return t}(e));if("%"===r)return e.next(),h(t,4,"%")}return n}return{nextToken:function(){const{currentType:e,offset:t,startLoc:n,endLoc:s}=E;return E.lastType=e,E.lastOffset=t,E.lastStartLoc=n,E.lastEndLoc=s,E.offset=c(),E.startLoc=o(),r.currentChar()===p?h(E,14):R(r,E)},currentOffset:c,currentPosition:o,context:L}}const L="parser",k=/(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;function h(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 N(e={}){const n=!1!==e.location,{onError:r}=e;function c(e,t,r){const c={type:e,start:t,end:t};return n&&(c.loc={start:r,end:r}),c}function o(e,t,r,c){e.end=t,c&&(e.type=c),n&&e.loc&&(e.loc.end=r)}function s(e,t){const n=e.context(),r=c(3,n.offset,n.startLoc);return r.value=t,o(r,e.currentOffset(),e.currentPosition()),r}function u(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(5,r,s);return u.index=parseInt(t,10),e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function a(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(4,r,s);return u.key=t,e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function i(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(9,r,s);return u.value=t.replace(k,h),e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function l(e){const t=e.context(),n=c(6,t.offset,t.startLoc);let r=e.nextToken();if(9===r.type){const t=function(e){const t=e.nextToken(),n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(8,r,s);return 12!==t.type?(n.lastStartLoc,u.value="",o(u,r,s),{nextConsumeToken:t,node:u}):(null==t.value&&(n.lastStartLoc,_(t)),u.value=t.value||"",o(u,e.currentOffset(),e.currentPosition()),{node:u})}(e);n.modifier=t.node,r=t.nextConsumeToken||e.nextToken()}switch(10!==r.type&&(t.lastStartLoc,_(r)),r=e.nextToken(),2===r.type&&(r=e.nextToken()),r.type){case 11:null==r.value&&(t.lastStartLoc,_(r)),n.key=function(e,t){const n=e.context(),r=c(7,n.offset,n.startLoc);return r.value=t,o(r,e.currentOffset(),e.currentPosition()),r}(e,r.value||"");break;case 5:null==r.value&&(t.lastStartLoc,_(r)),n.key=a(e,r.value||"");break;case 6:null==r.value&&(t.lastStartLoc,_(r)),n.key=u(e,r.value||"");break;case 7:null==r.value&&(t.lastStartLoc,_(r)),n.key=i(e,r.value||"");break;default:t.lastStartLoc;const s=e.context(),l=c(7,s.offset,s.startLoc);return l.value="",o(l,s.offset,s.startLoc),n.key=l,o(n,s.offset,s.startLoc),{nextConsumeToken:r,node:n}}return o(n,e.currentOffset(),e.currentPosition()),{node:n}}function f(e){const t=e.context(),n=c(2,1===t.currentType?e.currentOffset():t.offset,1===t.currentType?t.endLoc:t.startLoc);n.items=[];let r=null;do{const c=r||e.nextToken();switch(r=null,c.type){case 0:null==c.value&&(t.lastStartLoc,_(c)),n.items.push(s(e,c.value||""));break;case 6:null==c.value&&(t.lastStartLoc,_(c)),n.items.push(u(e,c.value||""));break;case 5:null==c.value&&(t.lastStartLoc,_(c)),n.items.push(a(e,c.value||""));break;case 7:null==c.value&&(t.lastStartLoc,_(c)),n.items.push(i(e,c.value||""));break;case 8:const o=l(e);n.items.push(o.node),r=o.nextConsumeToken||null}}while(14!==t.currentType&&1!==t.currentType);return o(n,1===t.currentType?t.lastOffset:e.currentOffset(),1===t.currentType?t.lastEndLoc:e.currentPosition()),n}function d(e){const t=e.context(),{offset:n,startLoc:r}=t,s=f(e);return 14===t.currentType?s:function(e,t,n,r){const s=e.context();let u=0===r.items.length;const a=c(1,t,n);a.cases=[],a.cases.push(r);do{const t=f(e);u||(u=0===t.items.length),a.cases.push(t)}while(14!==s.currentType);return o(a,e.currentOffset(),e.currentPosition()),a}(e,n,r,s)}return{parse:function(r){const s=E(r,t({},e)),u=s.context(),a=c(0,u.offset,u.startLoc);return n&&a.loc&&(a.loc.source=r),a.body=d(s),14!==u.currentType&&(u.lastStartLoc,r[u.offset]),o(a,s.currentOffset(),s.currentPosition()),a}}}function _(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 T(e,t){for(let n=0;n<e.length;n++)C(e[n],t)}function C(e,t){switch(e.type){case 1:T(e.cases,t),t.helper("plural");break;case 2:T(e.items,t);break;case 6:C(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 P(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&&C(e.body,n);const r=n.context();e.helpers=Array.from(r.helpers)}function y(e,t){const{helper:n}=e;switch(t.type){case 0:!function(e,t){t.body?y(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&&(y(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 n=0;n<c&&(y(e,t.items[n]),n!==c-1);n++)e.push(", ");e.deindent(r()),e.push("])")}(e,t);break;case 6:!function(e,t){const{helper:n}=e;e.push(`${n("linked")}(`),y(e,t.key),t.modifier?(e.push(", "),y(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)}}return e.CompileErrorCodes=r,e.ERROR_DOMAIN=L,e.LocationStub={start:{line:1,column:1,offset:0},end:{line:1,column:1,offset:0}},e.baseCompile=function(e,r={}){const c=t({},r),o=N(c).parse(e);return P(o,c),((e,t={})=>{const r=n(t.mode)?t.mode:"normal",c=n(t.filename)?t.filename:"message.intl",o=!!t.sourceMap,s=null!=t.breakLineCode?t.breakLineCode:"arrow"===r?";":"\n",u=t.needIndent?t.needIndent:"arrow"!==r,a=e.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}}(e,{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 "),y(i,e),i.deindent(u),i.push("}");const{code:l,map:f}=i.context();return{ast:e,code:l,map:f?f.toJSON():void 0}})(o,c)},e.createCompileError=o,e.createLocation=u,e.createParser=N,e.createPosition=s,e.defaultOnError=function(e){throw e},e.errorMessages=c,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
6
+ var IntlifyMessageCompiler=function(e){"use strict";const t=Object.assign,n=e=>"string"==typeof e,r={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},c={[r.EXPECTED_TOKEN]:"Expected token: '{0}'",[r.INVALID_TOKEN_IN_PLACEHOLDER]:"Invalid token in placeholder: '{0}'",[r.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]:"Unterminated single quote in placeholder",[r.UNKNOWN_ESCAPE_SEQUENCE]:"Unknown escape sequence: \\{0}",[r.INVALID_UNICODE_ESCAPE_SEQUENCE]:"Invalid unicode escape sequence: {0}",[r.UNBALANCED_CLOSING_BRACE]:"Unbalanced closing brace",[r.UNTERMINATED_CLOSING_BRACE]:"Unterminated closing brace",[r.EMPTY_PLACEHOLDER]:"Empty placeholder",[r.NOT_ALLOW_NEST_PLACEHOLDER]:"Not allowed nest placeholder",[r.INVALID_LINKED_FORMAT]:"Invalid linked format",[r.MUST_HAVE_MESSAGES_IN_PLURAL]:"Plural must have messages",[r.UNEXPECTED_EMPTY_LINKED_MODIFIER]:"Unexpected empty linked modifier",[r.UNEXPECTED_EMPTY_LINKED_KEY]:"Unexpected empty linked key",[r.UNEXPECTED_LEXICAL_ANALYSIS]:"Unexpected lexical analysis in token: '{0}'"};function o(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 s(e,t,n){return{line:e,column:t,offset:n}}function u(e,t,n){const r={start:e,end:t};return null!=n&&(r.source=n),r}const a=" ",i="\n",l=String.fromCharCode(8232),f=String.fromCharCode(8233);function d(e){const t=e;let n=0,r=1,c=1,o=0;const s=e=>"\r"===t[e]&&t[e+1]===i,u=e=>t[e]===f,a=e=>t[e]===l,d=e=>s(e)||(e=>t[e]===i)(e)||u(e)||a(e),p=e=>s(e)||u(e)||a(e)?i:t[e];function E(){return o=0,d(n)&&(r++,c=0),s(n)&&n++,n++,c++,t[n]}return{index:()=>n,line:()=>r,column:()=>c,peekOffset:()=>o,charAt:p,currentChar:()=>p(n),currentPeek:()=>p(n+o),next:E,peek:function(){return s(n+o)&&o++,o++,t[n+o]},reset:function(){n=0,r=1,c=1,o=0},resetPeek:function(e=0){o=e},skipToPeek:function(){const e=n+o;for(;e!==n;)E();o=0}}}const p=void 0;function E(e,t={}){const n=!1!==t.location,r=d(e),c=()=>r.index(),o=()=>s(r.line(),r.column(),r.index()),l=o(),f=c(),E={currentType:14,offset:f,startLoc:l,endLoc:l,lastType:14,lastOffset:f,lastStartLoc:l,lastEndLoc:l,braceNest:0,inLinked:!1,text:""},L=()=>E,{onError:k}=t;function h(e,t,r){e.endLoc=o(),e.currentType=t;const c={type:t};return n&&(c.loc=u(e.startLoc,e.endLoc)),null!=r&&(c.value=r),c}const N=e=>h(e,14);function _(e,t){return e.currentChar()===t?(e.next(),t):(o(),"")}function T(e){let t="";for(;e.currentPeek()===a||e.currentPeek()===i;)t+=e.currentPeek(),e.peek();return t}function C(e){const t=T(e);return e.skipToPeek(),t}function P(e){if(e===p)return!1;const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||95===t}function y(e,t){const{currentType:n}=t;if(2!==n)return!1;T(e);const r=function(e){if(e===p)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}("-"===e.currentPeek()?e.peek():e.currentPeek());return e.resetPeek(),r}function x(e){T(e);const t="|"===e.currentPeek();return e.resetPeek(),t}function m(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===a||r===i):o===a?(e.peek(),n(!0,a,c)):o!==i||(e.peek(),n(!0,i,c)):"%"===r||t},r=n();return t&&e.resetPeek(),r}function I(e,t){const n=e.currentChar();return n===p?p:t(n)?(e.next(),n):null}function O(e){return I(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 S(e){return I(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57}))}function b(e){return I(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}))}function A(e){let t="",n="";for(;t=S(e);)n+=t;return n}function v(e){let t="";for(;;){const n=e.currentChar();if("{"===n||"}"===n||"@"===n||"|"===n||!n)break;if("%"===n){if(!m(e))break;t+=n,e.next()}else if(n===a||n===i)if(m(e))t+=n,e.next();else{if(x(e))break;t+=n,e.next()}else t+=n,e.next()}return t}function D(e){const t=e.currentChar();switch(t){case"\\":case"'":return e.next(),`\\${t}`;case"u":return U(e,t,4);case"U":return U(e,t,6);default:return o(),""}}function U(e,t,n){_(e,t);let r="";for(let t=0;t<n;t++){const t=b(e);if(!t){o(),e.currentChar();break}r+=t}return`\\${t}${r}`}function g(e){C(e);const t=_(e,"|");return C(e),t}function M(e,t){let n=null;switch(e.currentChar()){case"{":return t.braceNest>=1&&o(),e.next(),n=h(t,2,"{"),C(e),t.braceNest++,n;case"}":return t.braceNest>0&&2===t.currentType&&o(),e.next(),n=h(t,3,"}"),t.braceNest--,t.braceNest>0&&C(e),t.inLinked&&0===t.braceNest&&(t.inLinked=!1),n;case"@":return t.braceNest>0&&o(),n=R(e,t)||N(t),t.braceNest=0,n;default:let r=!0,c=!0,s=!0;if(x(e))return t.braceNest>0&&o(),n=h(t,1,g(e)),t.braceNest=0,t.inLinked=!1,n;if(t.braceNest>0&&(5===t.currentType||6===t.currentType||7===t.currentType))return o(),t.braceNest=0,w(e,t);if(r=function(e,t){const{currentType:n}=t;if(2!==n)return!1;T(e);const r=P(e.currentPeek());return e.resetPeek(),r}(e,t))return n=h(t,5,function(e){C(e);let t="",n="";for(;t=O(e);)n+=t;return e.currentChar()===p&&o(),n}(e)),C(e),n;if(c=y(e,t))return n=h(t,6,function(e){C(e);let t="";return"-"===e.currentChar()?(e.next(),t+=`-${A(e)}`):t+=A(e),e.currentChar()===p&&o(),t}(e)),C(e),n;if(s=function(e,t){const{currentType:n}=t;if(2!==n)return!1;T(e);const r="'"===e.currentPeek();return e.resetPeek(),r}(e,t))return n=h(t,7,function(e){C(e),_(e,"'");let t="",n="";const r=e=>"'"!==e&&e!==i;for(;t=I(e,r);)n+="\\"===t?D(e):t;const c=e.currentChar();return c===i||c===p?(o(),c===i&&(e.next(),_(e,"'")),n):(_(e,"'"),n)}(e)),C(e),n;if(!r&&!c&&!s)return n=h(t,13,function(e){C(e);let t="",n="";const r=e=>"{"!==e&&"}"!==e&&e!==a&&e!==i;for(;t=I(e,r);)n+=t;return n}(e)),o(),n.value,C(e),n}return n}function R(e,t){const{currentType:n}=t;let r=null;const c=e.currentChar();switch(8!==n&&9!==n&&12!==n&&10!==n||c!==i&&c!==a||o(),c){case"@":return e.next(),r=h(t,8,"@"),t.inLinked=!0,r;case".":return C(e),e.next(),h(t,9,".");case":":return C(e),e.next(),h(t,10,":");default:return x(e)?(r=h(t,1,g(e)),t.braceNest=0,t.inLinked=!1,r):function(e,t){const{currentType:n}=t;if(8!==n)return!1;T(e);const r="."===e.currentPeek();return e.resetPeek(),r}(e,t)||function(e,t){const{currentType:n}=t;if(8!==n&&12!==n)return!1;T(e);const r=":"===e.currentPeek();return e.resetPeek(),r}(e,t)?(C(e),R(e,t)):function(e,t){const{currentType:n}=t;if(9!==n)return!1;T(e);const r=P(e.currentPeek());return e.resetPeek(),r}(e,t)?(C(e),h(t,12,function(e){let t="",n="";for(;t=O(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?P(e.peek()):!("@"===t||"%"===t||"|"===t||":"===t||"."===t||t===a||!t)&&(t===i?(e.peek(),r()):P(t))},c=r();return e.resetPeek(),c}(e,t)?(C(e),"{"===c?M(e,t)||r:h(t,11,function(e){const t=(n=!1,r)=>{const c=e.currentChar();return"{"!==c&&"%"!==c&&"@"!==c&&"|"!==c&&c?c===a?r:c===i?(r+=c,e.next(),t(n,r)):(r+=c,e.next(),t(!0,r)):r};return t(!1,"")}(e))):(8===n&&o(),t.braceNest=0,t.inLinked=!1,w(e,t))}}function w(e,t){let n={type:14};if(t.braceNest>0)return M(e,t)||N(t);if(t.inLinked)return R(e,t)||N(t);switch(e.currentChar()){case"{":return M(e,t)||N(t);case"}":return o(),e.next(),h(t,3,"}");case"@":return R(e,t)||N(t);default:if(x(e))return n=h(t,1,g(e)),t.braceNest=0,t.inLinked=!1,n;const{isModulo:r,hasSpace:c}=function(e){const t=T(e),n="%"===e.currentPeek()&&"{"===e.peek();return e.resetPeek(),{isModulo:n,hasSpace:t.length>0}}(e);if(r)return c?h(t,0,v(e)):h(t,4,function(e){C(e);return"%"!==e.currentChar()&&o(),e.next(),"%"}(e));if(m(e))return h(t,0,v(e))}return n}return{nextToken:function(){const{currentType:e,offset:t,startLoc:n,endLoc:s}=E;return E.lastType=e,E.lastOffset=t,E.lastStartLoc=n,E.lastEndLoc=s,E.offset=c(),E.startLoc=o(),r.currentChar()===p?h(E,14):w(r,E)},currentOffset:c,currentPosition:o,context:L}}const L="parser",k=/(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;function h(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 N(e={}){const n=!1!==e.location,{onError:r}=e;function c(e,t,r){const c={type:e,start:t,end:t};return n&&(c.loc={start:r,end:r}),c}function o(e,t,r,c){e.end=t,c&&(e.type=c),n&&e.loc&&(e.loc.end=r)}function s(e,t){const n=e.context(),r=c(3,n.offset,n.startLoc);return r.value=t,o(r,e.currentOffset(),e.currentPosition()),r}function u(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(5,r,s);return u.index=parseInt(t,10),e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function a(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(4,r,s);return u.key=t,e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function i(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(9,r,s);return u.value=t.replace(k,h),e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function l(e){const t=e.context(),n=c(6,t.offset,t.startLoc);let r=e.nextToken();if(9===r.type){const t=function(e){const t=e.nextToken(),n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(8,r,s);return 12!==t.type?(n.lastStartLoc,u.value="",o(u,r,s),{nextConsumeToken:t,node:u}):(null==t.value&&(n.lastStartLoc,_(t)),u.value=t.value||"",o(u,e.currentOffset(),e.currentPosition()),{node:u})}(e);n.modifier=t.node,r=t.nextConsumeToken||e.nextToken()}switch(10!==r.type&&(t.lastStartLoc,_(r)),r=e.nextToken(),2===r.type&&(r=e.nextToken()),r.type){case 11:null==r.value&&(t.lastStartLoc,_(r)),n.key=function(e,t){const n=e.context(),r=c(7,n.offset,n.startLoc);return r.value=t,o(r,e.currentOffset(),e.currentPosition()),r}(e,r.value||"");break;case 5:null==r.value&&(t.lastStartLoc,_(r)),n.key=a(e,r.value||"");break;case 6:null==r.value&&(t.lastStartLoc,_(r)),n.key=u(e,r.value||"");break;case 7:null==r.value&&(t.lastStartLoc,_(r)),n.key=i(e,r.value||"");break;default:t.lastStartLoc;const s=e.context(),l=c(7,s.offset,s.startLoc);return l.value="",o(l,s.offset,s.startLoc),n.key=l,o(n,s.offset,s.startLoc),{nextConsumeToken:r,node:n}}return o(n,e.currentOffset(),e.currentPosition()),{node:n}}function f(e){const t=e.context(),n=c(2,1===t.currentType?e.currentOffset():t.offset,1===t.currentType?t.endLoc:t.startLoc);n.items=[];let r=null;do{const c=r||e.nextToken();switch(r=null,c.type){case 0:null==c.value&&(t.lastStartLoc,_(c)),n.items.push(s(e,c.value||""));break;case 6:null==c.value&&(t.lastStartLoc,_(c)),n.items.push(u(e,c.value||""));break;case 5:null==c.value&&(t.lastStartLoc,_(c)),n.items.push(a(e,c.value||""));break;case 7:null==c.value&&(t.lastStartLoc,_(c)),n.items.push(i(e,c.value||""));break;case 8:const o=l(e);n.items.push(o.node),r=o.nextConsumeToken||null}}while(14!==t.currentType&&1!==t.currentType);return o(n,1===t.currentType?t.lastOffset:e.currentOffset(),1===t.currentType?t.lastEndLoc:e.currentPosition()),n}function d(e){const t=e.context(),{offset:n,startLoc:r}=t,s=f(e);return 14===t.currentType?s:function(e,t,n,r){const s=e.context();let u=0===r.items.length;const a=c(1,t,n);a.cases=[],a.cases.push(r);do{const t=f(e);u||(u=0===t.items.length),a.cases.push(t)}while(14!==s.currentType);return o(a,e.currentOffset(),e.currentPosition()),a}(e,n,r,s)}return{parse:function(r){const s=E(r,t({},e)),u=s.context(),a=c(0,u.offset,u.startLoc);return n&&a.loc&&(a.loc.source=r),a.body=d(s),14!==u.currentType&&(u.lastStartLoc,r[u.offset]),o(a,s.currentOffset(),s.currentPosition()),a}}}function _(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 T(e,t){for(let n=0;n<e.length;n++)C(e[n],t)}function C(e,t){switch(e.type){case 1:T(e.cases,t),t.helper("plural");break;case 2:T(e.items,t);break;case 6:C(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 P(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&&C(e.body,n);const r=n.context();e.helpers=Array.from(r.helpers)}function y(e,t){const{helper:n}=e;switch(t.type){case 0:!function(e,t){t.body?y(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&&(y(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 n=0;n<c&&(y(e,t.items[n]),n!==c-1);n++)e.push(", ");e.deindent(r()),e.push("])")}(e,t);break;case 6:!function(e,t){const{helper:n}=e;e.push(`${n("linked")}(`),y(e,t.key),t.modifier?(e.push(", "),y(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)}}return e.CompileErrorCodes=r,e.ERROR_DOMAIN=L,e.LocationStub={start:{line:1,column:1,offset:0},end:{line:1,column:1,offset:0}},e.baseCompile=function(e,r={}){const c=t({},r),o=N(c).parse(e);return P(o,c),((e,t={})=>{const r=n(t.mode)?t.mode:"normal",c=n(t.filename)?t.filename:"message.intl",o=!!t.sourceMap,s=null!=t.breakLineCode?t.breakLineCode:"arrow"===r?";":"\n",u=t.needIndent?t.needIndent:"arrow"!==r,a=e.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}}(e,{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 "),y(i,e),i.deindent(u),i.push("}");const{code:l,map:f}=i.context();return{ast:e,code:l,map:f?f.toJSON():void 0}})(o,c)},e.createCompileError=o,e.createLocation=u,e.createParser=N,e.createPosition=s,e.defaultOnError=function(e){throw e},e.errorMessages=c,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlify/message-compiler",
3
- "version": "9.2.0-beta.36",
3
+ "version": "9.2.0-beta.37",
4
4
  "description": "@intlify/message-compiler",
5
5
  "keywords": [
6
6
  "compiler",
@@ -34,11 +34,11 @@
34
34
  "jsdelivr": "dist/message-compiler.global.js",
35
35
  "types": "dist/message-compiler.d.ts",
36
36
  "dependencies": {
37
- "@intlify/shared": "9.2.0-beta.36",
37
+ "@intlify/shared": "9.2.0-beta.37",
38
38
  "source-map": "0.6.1"
39
39
  },
40
40
  "engines": {
41
- "node": ">= 12"
41
+ "node": ">= 14"
42
42
  },
43
43
  "buildOptions": {
44
44
  "name": "IntlifyMessageCompiler",