@intlify/message-compiler
Advanced tools
Comparing version 9.0.0-beta.14 to 9.0.0-beta.15
/*! | ||
* @intlify/message-compiler v9.0.0-beta.14 | ||
* @intlify/message-compiler v9.0.0-beta.15 | ||
* (c) 2020 kazuya kawaguchi | ||
@@ -142,3 +142,3 @@ * Released under the MIT License. | ||
function createTokenizer(source, options = {}) { | ||
const location = !options.location; | ||
const location = options.location !== false; | ||
const _scnr = createScanner(source); | ||
@@ -812,3 +812,3 @@ const currentOffset = () => _scnr.index(); | ||
function createParser(options = {}) { | ||
const location = !options.location; | ||
const location = options.location !== false; | ||
const { onError } = options; | ||
@@ -885,2 +885,14 @@ function emitError(tokenzer, code, start, offset, ...args) { | ||
const context = tokenizer.context(); | ||
const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc | ||
const node = startNode(8 /* LinkedModifier */, offset, loc); | ||
if (token.type !== 12 /* LinkedModifier */) { | ||
// empty modifier | ||
emitError(tokenizer, 11 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, token.type); | ||
node.value = ''; | ||
endNode(node, offset, loc); | ||
return { | ||
nextConsumeToken: token, | ||
node | ||
}; | ||
} | ||
// check token | ||
@@ -890,7 +902,7 @@ if (token.value == null) { | ||
} | ||
const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc | ||
const node = startNode(8 /* LinkedModifier */, offset, loc); | ||
node.value = token.value || ''; | ||
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition()); | ||
return node; | ||
return { | ||
node | ||
}; | ||
} | ||
@@ -909,4 +921,5 @@ function parseLinkedKey(tokenizer, value) { | ||
if (token.type === 9 /* LinkedDot */) { | ||
linkedNode.modifier = parseLinkedModifier(tokenizer); | ||
token = tokenizer.nextToken(); | ||
const parsed = parseLinkedModifier(tokenizer); | ||
linkedNode.modifier = parsed.node; | ||
token = parsed.nextConsumeToken || tokenizer.nextToken(); | ||
} | ||
@@ -947,5 +960,20 @@ // asset check token | ||
break; | ||
default: | ||
// empty key | ||
emitError(tokenizer, 11 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, token.type); | ||
const nextContext = tokenizer.context(); | ||
const emptyLinkedKeyNode = startNode(7 /* LinkedKey */, nextContext.offset, nextContext.startLoc); | ||
emptyLinkedKeyNode.value = ''; | ||
endNode(emptyLinkedKeyNode, nextContext.offset, nextContext.startLoc); | ||
linkedNode.key = emptyLinkedKeyNode; | ||
endNode(linkedNode, nextContext.offset, nextContext.startLoc); | ||
return { | ||
nextConsumeToken: token, | ||
node: linkedNode | ||
}; | ||
} | ||
endNode(linkedNode, tokenizer.currentOffset(), tokenizer.currentPosition()); | ||
return linkedNode; | ||
return { | ||
node: linkedNode | ||
}; | ||
} | ||
@@ -962,4 +990,6 @@ function parseMessage(tokenizer) { | ||
node.items = []; | ||
let nextToken = null; | ||
do { | ||
const token = tokenizer.nextToken(); | ||
const token = nextToken || tokenizer.nextToken(); | ||
nextToken = null; | ||
switch (token.type) { | ||
@@ -991,3 +1021,5 @@ case 0 /* Text */: | ||
case 8 /* LinkedAlias */: | ||
node.items.push(parseLinked(tokenizer)); | ||
const parsed = parseLinked(tokenizer); | ||
node.items.push(parsed.node); | ||
nextToken = parsed.nextConsumeToken || null; | ||
break; | ||
@@ -994,0 +1026,0 @@ } |
/*! | ||
* @intlify/message-compiler v9.0.0-beta.14 | ||
* @intlify/message-compiler v9.0.0-beta.15 | ||
* (c) 2020 kazuya kawaguchi | ||
@@ -141,3 +141,3 @@ * Released under the MIT License. | ||
function createTokenizer(source, options = {}) { | ||
const location = !options.location; | ||
const location = options.location !== false; | ||
const _scnr = createScanner(source); | ||
@@ -811,3 +811,3 @@ const currentOffset = () => _scnr.index(); | ||
function createParser(options = {}) { | ||
const location = !options.location; | ||
const location = options.location !== false; | ||
const { onError } = options; | ||
@@ -884,2 +884,14 @@ function emitError(tokenzer, code, start, offset, ...args) { | ||
const context = tokenizer.context(); | ||
const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc | ||
const node = startNode(8 /* LinkedModifier */, offset, loc); | ||
if (token.type !== 12 /* LinkedModifier */) { | ||
// empty modifier | ||
emitError(tokenizer, 11 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, token.type); | ||
node.value = ''; | ||
endNode(node, offset, loc); | ||
return { | ||
nextConsumeToken: token, | ||
node | ||
}; | ||
} | ||
// check token | ||
@@ -889,7 +901,7 @@ if (token.value == null) { | ||
} | ||
const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc | ||
const node = startNode(8 /* LinkedModifier */, offset, loc); | ||
node.value = token.value || ''; | ||
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition()); | ||
return node; | ||
return { | ||
node | ||
}; | ||
} | ||
@@ -908,4 +920,5 @@ function parseLinkedKey(tokenizer, value) { | ||
if (token.type === 9 /* LinkedDot */) { | ||
linkedNode.modifier = parseLinkedModifier(tokenizer); | ||
token = tokenizer.nextToken(); | ||
const parsed = parseLinkedModifier(tokenizer); | ||
linkedNode.modifier = parsed.node; | ||
token = parsed.nextConsumeToken || tokenizer.nextToken(); | ||
} | ||
@@ -946,5 +959,20 @@ // asset check token | ||
break; | ||
default: | ||
// empty key | ||
emitError(tokenizer, 11 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, token.type); | ||
const nextContext = tokenizer.context(); | ||
const emptyLinkedKeyNode = startNode(7 /* LinkedKey */, nextContext.offset, nextContext.startLoc); | ||
emptyLinkedKeyNode.value = ''; | ||
endNode(emptyLinkedKeyNode, nextContext.offset, nextContext.startLoc); | ||
linkedNode.key = emptyLinkedKeyNode; | ||
endNode(linkedNode, nextContext.offset, nextContext.startLoc); | ||
return { | ||
nextConsumeToken: token, | ||
node: linkedNode | ||
}; | ||
} | ||
endNode(linkedNode, tokenizer.currentOffset(), tokenizer.currentPosition()); | ||
return linkedNode; | ||
return { | ||
node: linkedNode | ||
}; | ||
} | ||
@@ -961,4 +989,6 @@ function parseMessage(tokenizer) { | ||
node.items = []; | ||
let nextToken = null; | ||
do { | ||
const token = tokenizer.nextToken(); | ||
const token = nextToken || tokenizer.nextToken(); | ||
nextToken = null; | ||
switch (token.type) { | ||
@@ -990,3 +1020,5 @@ case 0 /* Text */: | ||
case 8 /* LinkedAlias */: | ||
node.items.push(parseLinked(tokenizer)); | ||
const parsed = parseLinked(tokenizer); | ||
node.items.push(parsed.node); | ||
nextToken = parsed.nextConsumeToken || null; | ||
break; | ||
@@ -993,0 +1025,0 @@ } |
@@ -93,3 +93,3 @@ import { RawSourceMap } from 'source-map'; | ||
export declare interface LinkedModitierNode extends Node_2 { | ||
export declare interface LinkedModifierNode extends Node_2 { | ||
type: NodeTypes.LinkedModifier; | ||
@@ -101,3 +101,3 @@ value: Identifier; | ||
type: NodeTypes.Linked; | ||
modifier?: LinkedModitierNode; | ||
modifier?: LinkedModifierNode; | ||
key: LinkedKeyNode | NamedNode | ListNode | LiteralNode; | ||
@@ -104,0 +104,0 @@ } |
/*! | ||
* @intlify/message-compiler v9.0.0-beta.14 | ||
* @intlify/message-compiler v9.0.0-beta.15 | ||
* (c) 2020 kazuya kawaguchi | ||
@@ -156,3 +156,3 @@ * Released under the MIT License. | ||
function createTokenizer(source, options = {}) { | ||
const location = !options.location; | ||
const location = options.location !== false; | ||
const _scnr = createScanner(source); | ||
@@ -826,3 +826,3 @@ const currentOffset = () => _scnr.index(); | ||
function createParser(options = {}) { | ||
const location = !options.location; | ||
const location = options.location !== false; | ||
const { onError } = options; | ||
@@ -899,2 +899,14 @@ function emitError(tokenzer, code, start, offset, ...args) { | ||
const context = tokenizer.context(); | ||
const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc | ||
const node = startNode(8 /* LinkedModifier */, offset, loc); | ||
if (token.type !== 12 /* LinkedModifier */) { | ||
// empty modifier | ||
emitError(tokenizer, 11 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, token.type); | ||
node.value = ''; | ||
endNode(node, offset, loc); | ||
return { | ||
nextConsumeToken: token, | ||
node | ||
}; | ||
} | ||
// check token | ||
@@ -904,7 +916,7 @@ if (token.value == null) { | ||
} | ||
const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc | ||
const node = startNode(8 /* LinkedModifier */, offset, loc); | ||
node.value = token.value || ''; | ||
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition()); | ||
return node; | ||
return { | ||
node | ||
}; | ||
} | ||
@@ -923,4 +935,5 @@ function parseLinkedKey(tokenizer, value) { | ||
if (token.type === 9 /* LinkedDot */) { | ||
linkedNode.modifier = parseLinkedModifier(tokenizer); | ||
token = tokenizer.nextToken(); | ||
const parsed = parseLinkedModifier(tokenizer); | ||
linkedNode.modifier = parsed.node; | ||
token = parsed.nextConsumeToken || tokenizer.nextToken(); | ||
} | ||
@@ -961,5 +974,20 @@ // asset check token | ||
break; | ||
default: | ||
// empty key | ||
emitError(tokenizer, 11 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, token.type); | ||
const nextContext = tokenizer.context(); | ||
const emptyLinkedKeyNode = startNode(7 /* LinkedKey */, nextContext.offset, nextContext.startLoc); | ||
emptyLinkedKeyNode.value = ''; | ||
endNode(emptyLinkedKeyNode, nextContext.offset, nextContext.startLoc); | ||
linkedNode.key = emptyLinkedKeyNode; | ||
endNode(linkedNode, nextContext.offset, nextContext.startLoc); | ||
return { | ||
nextConsumeToken: token, | ||
node: linkedNode | ||
}; | ||
} | ||
endNode(linkedNode, tokenizer.currentOffset(), tokenizer.currentPosition()); | ||
return linkedNode; | ||
return { | ||
node: linkedNode | ||
}; | ||
} | ||
@@ -976,4 +1004,6 @@ function parseMessage(tokenizer) { | ||
node.items = []; | ||
let nextToken = null; | ||
do { | ||
const token = tokenizer.nextToken(); | ||
const token = nextToken || tokenizer.nextToken(); | ||
nextToken = null; | ||
switch (token.type) { | ||
@@ -1005,3 +1035,5 @@ case 0 /* Text */: | ||
case 8 /* LinkedAlias */: | ||
node.items.push(parseLinked(tokenizer)); | ||
const parsed = parseLinked(tokenizer); | ||
node.items.push(parsed.node); | ||
nextToken = parsed.nextConsumeToken || null; | ||
break; | ||
@@ -1008,0 +1040,0 @@ } |
/*! | ||
* @intlify/message-compiler v9.0.0-beta.14 | ||
* @intlify/message-compiler v9.0.0-beta.15 | ||
* (c) 2020 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/ | ||
const e=e=>"string"==typeof e,n={0:"Expected token: '{0}'",1:"Invalid token in placeholder: '{0}'",2:"Unterminated single quote in placeholder",3:"Unknown escape sequence: \\{0}",4:"Invalid unicode escape sequence: {0}",5:"Unbalanced closing brace",6:"Unterminated closing brace",7:"Empty placeholder",8:"Not allowed nest placeholder",9:"Invalid linked format",10:"Plural must have messages",11:"Unexpected lexical analysis in token: '{0}'"};function t(e,n,t={}){const{domain:r}=t,c=new SyntaxError(String(e));return c.code=e,n&&(c.location=n),c.domain=r,c}function r(e){throw e}const c={start:{line:1,column:1,offset:0},end:{line:1,column:1,offset:0}};function o(e,n,t){return{line:e,column:n,offset:t}}function s(e,n,t){const r={start:e,end:n};return null!=t&&(r.source=t),r}const u=String.fromCharCode(8232),i=String.fromCharCode(8233);function a(e){const n=e;let t=0,r=1,c=1,o=0;const s=e=>"\r"===n[e]&&"\n"===n[e+1],a=e=>n[e]===i,f=e=>n[e]===u,l=e=>s(e)||(e=>"\n"===n[e])(e)||a(e)||f(e),d=e=>s(e)||a(e)||f(e)?"\n":n[e];function p(){return o=0,l(t)&&(r++,c=0),s(t)&&t++,t++,c++,n[t]}return{index:()=>t,line:()=>r,column:()=>c,peekOffset:()=>o,charAt:d,currentChar:()=>d(t),currentPeek:()=>d(t+o),next:p,peek:function(){return s(t+o)&&o++,o++,n[t+o]},reset:function(){t=0,r=1,c=1,o=0},resetPeek:function(e=0){o=e},skipToPeek:function(){const e=t+o;for(;e!==t;)p();o=0}}}const f=void 0;function l(e,n={}){const t=!n.location,r=a(e),c=()=>r.index(),u=()=>o(r.line(),r.column(),r.index()),i=u(),l=c(),d={currentType:14,offset:l,startLoc:i,endLoc:i,lastType:14,lastOffset:l,lastStartLoc:i,lastEndLoc:i,braceNest:0,inLinked:!1,text:""},p=()=>d,{onError:k}=n;function h(e,n,r){e.endLoc=u(),e.currentType=n;const c={type:n};return t&&(c.loc=s(e.startLoc,e.endLoc)),null!=r&&(c.value=r),c}const x=e=>h(e,14);function y(e,n){return e.currentChar()===n?(e.next(),n):(u(),"")}function m(e){let n="";for(;" "===e.currentPeek()||"\n"===e.currentPeek();)n+=e.currentPeek(),e.peek();return n}function b(e){const n=m(e);return e.skipToPeek(),n}function L(e){if(e===f)return!1;const n=e.charCodeAt(0);return n>=97&&n<=122||n>=65&&n<=90}function P(e,n){const{currentType:t}=n;if(2!==t)return!1;m(e);const r=function(e){if(e===f)return!1;const n=e.charCodeAt(0);return n>=48&&n<=57}("-"===e.currentPeek()?e.peek():e.currentPeek());return e.resetPeek(),r}function T(e){m(e);const n="|"===e.currentPeek();return e.resetPeek(),n}function C(e,n=!0){const t=(n=!1,r="",c=!1)=>{const o=e.currentPeek();return"{"===o?"%"!==r&&n:"@"!==o&&o?"%"===o?(e.peek(),t(n,"%",!0)):"|"===o?!("%"!==r&&!c)||!(" "===r||"\n"===r):" "===o?(e.peek(),t(!0," ",c)):"\n"!==o||(e.peek(),t(!0,"\n",c)):"%"===r||n},r=t();return n&&e.resetPeek(),r}function v(e,n){const t=e.currentChar();return t===f?f:n(t)?(e.next(),t):null}function O(e){return v(e,(e=>{const n=e.charCodeAt(0);return n>=97&&n<=122||n>=65&&n<=90||n>=48&&n<=57||95===n||36===n}))}function N(e){return v(e,(e=>{const n=e.charCodeAt(0);return n>=48&&n<=57}))}function g(e){return v(e,(e=>{const n=e.charCodeAt(0);return n>=48&&n<=57||n>=65&&n<=70||n>=97&&n<=102}))}function w(e){let n="",t="";for(;n=N(e);)t+=n;return t}function $(e){const n=e.currentChar();switch(n){case"\\":case"'":return e.next(),`\\${n}`;case"u":return S(e,n,4);case"U":return S(e,n,6);default:return u(),""}}function S(e,n,t){y(e,n);let r="";for(let n=0;n<t;n++){const n=g(e);if(!n){u(),e.currentChar();break}r+=n}return`\\${n}${r}`}function I(e){b(e);const n=y(e,"|");return b(e),n}function A(e,n){let t=null;switch(e.currentChar()){case"{":return n.braceNest>=1&&u(),e.next(),t=h(n,2,"{"),b(e),n.braceNest++,t;case"}":return n.braceNest>0&&2===n.currentType&&u(),e.next(),t=h(n,3,"}"),n.braceNest--,n.braceNest>0&&b(e),n.inLinked&&0===n.braceNest&&(n.inLinked=!1),t;case"@":return n.braceNest>0&&u(),t=E(e,n)||x(n),n.braceNest=0,t;default:let r=!0,c=!0,o=!0;if(T(e))return n.braceNest>0&&u(),t=h(n,1,I(e)),n.braceNest=0,n.inLinked=!1,t;if(n.braceNest>0&&(5===n.currentType||6===n.currentType||7===n.currentType))return u(),n.braceNest=0,U(e,n);if(r=function(e,n){const{currentType:t}=n;if(2!==t)return!1;m(e);const r=L(e.currentPeek());return e.resetPeek(),r}(e,n))return t=h(n,5,function(e){b(e);let n="",t="";for(;n=O(e);)t+=n;return e.currentChar()===f&&u(),t}(e)),b(e),t;if(c=P(e,n))return t=h(n,6,function(e){b(e);let n="";return"-"===e.currentChar()?(e.next(),n+=`-${w(e)}`):n+=w(e),e.currentChar()===f&&u(),n}(e)),b(e),t;if(o=function(e,n){const{currentType:t}=n;if(2!==t)return!1;m(e);const r="'"===e.currentPeek();return e.resetPeek(),r}(e,n))return t=h(n,7,function(e){b(e),y(e,"'");let n="",t="";const r=e=>"'"!==e&&"\n"!==e;for(;n=v(e,r);)t+="\\"===n?$(e):n;const c=e.currentChar();return"\n"===c||c===f?(u(),"\n"===c&&(e.next(),y(e,"'")),t):(y(e,"'"),t)}(e)),b(e),t;if(!r&&!c&&!o)return t=h(n,13,function(e){b(e);let n="",t="";const r=e=>"{"!==e&&"}"!==e&&" "!==e&&"\n"!==e;for(;n=v(e,r);)t+=n;return t}(e)),u(),b(e),t}return t}function E(e,n){const{currentType:t}=n;let r=null;const c=e.currentChar();switch(8!==t&&9!==t&&12!==t&&10!==t||"\n"!==c&&" "!==c||u(),c){case"@":return e.next(),r=h(n,8,"@"),n.inLinked=!0,r;case".":return b(e),e.next(),h(n,9,".");case":":return b(e),e.next(),h(n,10,":");default:return T(e)?(r=h(n,1,I(e)),n.braceNest=0,n.inLinked=!1,r):function(e,n){const{currentType:t}=n;if(8!==t)return!1;m(e);const r="."===e.currentPeek();return e.resetPeek(),r}(e,n)||function(e,n){const{currentType:t}=n;if(8!==t&&12!==t)return!1;m(e);const r=":"===e.currentPeek();return e.resetPeek(),r}(e,n)?(b(e),E(e,n)):function(e,n){const{currentType:t}=n;if(9!==t)return!1;m(e);const r=L(e.currentPeek());return e.resetPeek(),r}(e,n)?(b(e),h(n,12,function(e){let n="",t="";for(;n=O(e);)t+=n;return t}(e))):function(e,n){const{currentType:t}=n;if(10!==t)return!1;const r=()=>{const n=e.currentPeek();return"{"===n?L(e.peek()):!("@"===n||"%"===n||"|"===n||":"===n||"."===n||" "===n||!n)&&("\n"===n?(e.peek(),r()):L(n))},c=r();return e.resetPeek(),c}(e,n)?(b(e),"{"===c?A(e,n)||r:h(n,11,function(e){const n=(t=!1,r)=>{const c=e.currentChar();return"{"!==c&&"%"!==c&&"@"!==c&&"|"!==c&&c?" "===c?r:"\n"===c?(r+=c,e.next(),n(t,r)):(r+=c,e.next(),n(!0,r)):r};return n(!1,"")}(e))):(8===t&&u(),n.braceNest=0,n.inLinked=!1,U(e,n))}}function U(e,n){let t={type:14};if(n.braceNest>0)return A(e,n)||x(n);if(n.inLinked)return E(e,n)||x(n);const r=e.currentChar();switch(r){case"{":return A(e,n)||x(n);case"}":return u(),e.next(),h(n,3,"}");case"@":return E(e,n)||x(n);default:if(T(e))return t=h(n,1,I(e)),n.braceNest=0,n.inLinked=!1,t;if(C(e))return h(n,0,function(e){const n=t=>{const r=e.currentChar();return"{"!==r&&"}"!==r&&"@"!==r&&r?"%"===r?C(e)?(t+=r,e.next(),n(t)):t:"|"===r?t:" "===r||"\n"===r?C(e)?(t+=r,e.next(),n(t)):T(e)?t:(t+=r,e.next(),n(t)):(t+=r,e.next(),n(t)):t};return n("")}(e));if("%"===r)return e.next(),h(n,4,"%")}return t}return{nextToken:function(){const{currentType:e,offset:n,startLoc:t,endLoc:o}=d;return d.lastType=e,d.lastOffset=n,d.lastStartLoc=t,d.lastEndLoc=o,d.offset=c(),d.startLoc=u(),r.currentChar()===f?h(d,14):U(r,d)},currentOffset:c,currentPosition:u,context:p}}const d="parser",p=/(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;function k(e,n,t){switch(e){case"\\\\":return"\\";case"\\'":return"'";default:{const e=parseInt(n||t,16);return e<=55295||e>=57344?String.fromCodePoint(e):"�"}}}function h(e={}){const n=!e.location,{onError:t}=e;function r(e,t,r){const c={type:e,start:t,end:t};return n&&(c.loc={start:r,end:r}),c}function c(e,t,r,c){e.end=t,c&&(e.type=c),n&&e.loc&&(e.loc.end=r)}function o(e,n){const t=e.context(),o=r(3,t.offset,t.startLoc);return o.value=n,c(o,e.currentOffset(),e.currentPosition()),o}function s(e,n){const t=e.context(),{lastOffset:o,lastStartLoc:s}=t,u=r(5,o,s);return u.index=parseInt(n,10),e.nextToken(),c(u,e.currentOffset(),e.currentPosition()),u}function u(e,n){const t=e.context(),{lastOffset:o,lastStartLoc:s}=t,u=r(4,o,s);return u.key=n,e.nextToken(),c(u,e.currentOffset(),e.currentPosition()),u}function i(e,n){const t=e.context(),{lastOffset:o,lastStartLoc:s}=t,u=r(9,o,s);return u.value=n.replace(p,k),e.nextToken(),c(u,e.currentOffset(),e.currentPosition()),u}function a(e){const n=e.context(),t=r(6,n.offset,n.startLoc);let o=e.nextToken();switch(9===o.type&&(t.modifier=function(e){const n=e.nextToken(),t=e.context(),{lastOffset:o,lastStartLoc:s}=t,u=r(8,o,s);return u.value=n.value||"",c(u,e.currentOffset(),e.currentPosition()),u}(e),o=e.nextToken()),o=e.nextToken(),2===o.type&&(o=e.nextToken()),o.type){case 11:t.key=function(e,n){const t=e.context(),o=r(7,t.offset,t.startLoc);return o.value=n,c(o,e.currentOffset(),e.currentPosition()),o}(e,o.value||"");break;case 5:t.key=u(e,o.value||"");break;case 6:t.key=s(e,o.value||"");break;case 7:t.key=i(e,o.value||"")}return c(t,e.currentOffset(),e.currentPosition()),t}function f(e){const n=e.context(),t=r(2,1===n.currentType?e.currentOffset():n.offset,1===n.currentType?n.endLoc:n.startLoc);t.items=[];do{const n=e.nextToken();switch(n.type){case 0:t.items.push(o(e,n.value||""));break;case 6:t.items.push(s(e,n.value||""));break;case 5:t.items.push(u(e,n.value||""));break;case 7:t.items.push(i(e,n.value||""));break;case 8:t.items.push(a(e))}}while(14!==n.currentType&&1!==n.currentType);return c(t,1===n.currentType?n.lastOffset:e.currentOffset(),1===n.currentType?n.lastEndLoc:e.currentPosition()),t}function d(e){const n=e.context(),{offset:t,startLoc:o}=n,s=f(e);return 14===n.currentType?s:function(e,n,t,o){const s=e.context();let u=0===o.items.length;const i=r(1,n,t);i.cases=[],i.cases.push(o);do{const n=f(e);u||(u=0===n.items.length),i.cases.push(n)}while(14!==s.currentType);return c(i,e.currentOffset(),e.currentPosition()),i}(e,t,o,s)}return{parse:function(t){const o=l(t,{...e}),s=o.context(),u=r(0,s.offset,s.startLoc);return n&&u.loc&&(u.loc.source=t),u.body=d(o),c(u,o.currentOffset(),o.currentPosition()),u}}}function x(e,n){for(let t=0;t<e.length;t++)y(e[t],n)}function y(e,n){switch(e.type){case 1:x(e.cases,n),n.helper("plural");break;case 2:x(e.items,n);break;case 6:y(e.key,n),n.helper("linked");break;case 5:n.helper("interpolate"),n.helper("list");break;case 4:n.helper("interpolate"),n.helper("named")}}function m(e,n={}){const t=function(e,n={}){const t={ast:e,helpers:new Set};return{context:()=>t,helper:e=>(t.helpers.add(e),e)}}(e);t.helper("normalize"),e.body&&y(e.body,t);const r=t.context();e.helpers=[...r.helpers]}function b(e,n){const{helper:t}=e;switch(n.type){case 0:!function(e,n){n.body?b(e,n.body):e.push("null")}(e,n);break;case 1:!function(e,n){const{helper:t,needIndent:r}=e;if(n.cases.length>1){e.push(`${t("plural")}([`),e.indent(r());const c=n.cases.length;for(let t=0;t<c&&(b(e,n.cases[t]),t!==c-1);t++)e.push(", ");e.deindent(r()),e.push("])")}}(e,n);break;case 2:!function(e,n){const{helper:t,needIndent:r}=e;e.push(`${t("normalize")}([`),e.indent(r());const c=n.items.length;for(let t=0;t<c&&(b(e,n.items[t]),t!==c-1);t++)e.push(", ");e.deindent(r()),e.push("])")}(e,n);break;case 6:!function(e,n){const{helper:t}=e;e.push(`${t("linked")}(`),b(e,n.key),n.modifier&&(e.push(", "),b(e,n.modifier)),e.push(")")}(e,n);break;case 8:case 7:e.push(JSON.stringify(n.value),n);break;case 5:e.push(`${t("interpolate")}(${t("list")}(${n.index}))`,n);break;case 4:e.push(`${t("interpolate")}(${t("named")}(${JSON.stringify(n.key)}))`,n);break;case 9:case 3:e.push(JSON.stringify(n.value),n)}}function L(n,t={}){const r=h({...t}).parse(n);return m(r,{...t}),((n,t={})=>{const r=e(t.mode)?t.mode:"normal",c=e(t.filename)?t.filename:"message.intl",o=t.needIndent?t.needIndent:"arrow"!==r,s=n.helpers||[],u=function(e,n){const{filename:t,breakLineCode:r,needIndent:c}=n,o={source:e.loc.source,filename:t,code:"",column:1,line:1,offset:0,map:void 0,breakLineCode:r,needIndent:c,indentLevel:0};function s(e,n){o.code+=e}function u(e,n=!0){const t=n?r:"";s(c?t+" ".repeat(e):t)}return{context:()=>o,push:s,indent:function(e=!0){const n=++o.indentLevel;e&&u(n)},deindent:function(e=!0){const n=--o.indentLevel;e&&u(n)},newline:function(){u(o.indentLevel)},helper:e=>`_${e}`,needIndent:()=>o.needIndent}}(n,{mode:r,filename:c,sourceMap:!!t.sourceMap,breakLineCode:null!=t.breakLineCode?t.breakLineCode:"arrow"===r?";":"\n",needIndent:o});u.push("normal"===r?"function __msg__ (ctx) {":"(ctx) => {"),u.indent(o),s.length>0&&(u.push(`const { ${s.map((e=>`${e}: _${e}`)).join(", ")} } = ctx`),u.newline()),u.push("return "),b(u,n),u.deindent(o),u.push("}");const{code:i,map:a}=u.context();return{ast:n,code:i,map:a?a.toJSON():void 0}})(r,{...t})}export{d as ERROR_DOMAIN,c as LocationStub,L as baseCompile,t as createCompileError,s as createLocation,h as createParser,o as createPosition,r as defaultOnError,n as errorMessages}; | ||
const e=e=>"string"==typeof e,n={0:"Expected token: '{0}'",1:"Invalid token in placeholder: '{0}'",2:"Unterminated single quote in placeholder",3:"Unknown escape sequence: \\{0}",4:"Invalid unicode escape sequence: {0}",5:"Unbalanced closing brace",6:"Unterminated closing brace",7:"Empty placeholder",8:"Not allowed nest placeholder",9:"Invalid linked format",10:"Plural must have messages",11:"Unexpected lexical analysis in token: '{0}'"};function t(e,n,t={}){const{domain:r}=t,c=new SyntaxError(String(e));return c.code=e,n&&(c.location=n),c.domain=r,c}function r(e){throw e}const c={start:{line:1,column:1,offset:0},end:{line:1,column:1,offset:0}};function o(e,n,t){return{line:e,column:n,offset:t}}function s(e,n,t){const r={start:e,end:n};return null!=t&&(r.source=t),r}const u=String.fromCharCode(8232),i=String.fromCharCode(8233);function a(e){const n=e;let t=0,r=1,c=1,o=0;const s=e=>"\r"===n[e]&&"\n"===n[e+1],a=e=>n[e]===i,f=e=>n[e]===u,l=e=>s(e)||(e=>"\n"===n[e])(e)||a(e)||f(e),d=e=>s(e)||a(e)||f(e)?"\n":n[e];function p(){return o=0,l(t)&&(r++,c=0),s(t)&&t++,t++,c++,n[t]}return{index:()=>t,line:()=>r,column:()=>c,peekOffset:()=>o,charAt:d,currentChar:()=>d(t),currentPeek:()=>d(t+o),next:p,peek:function(){return s(t+o)&&o++,o++,n[t+o]},reset:function(){t=0,r=1,c=1,o=0},resetPeek:function(e=0){o=e},skipToPeek:function(){const e=t+o;for(;e!==t;)p();o=0}}}const f=void 0;function l(e,n={}){const t=!1!==n.location,r=a(e),c=()=>r.index(),u=()=>o(r.line(),r.column(),r.index()),i=u(),l=c(),d={currentType:14,offset:l,startLoc:i,endLoc:i,lastType:14,lastOffset:l,lastStartLoc:i,lastEndLoc:i,braceNest:0,inLinked:!1,text:""},p=()=>d,{onError:k}=n;function h(e,n,r){e.endLoc=u(),e.currentType=n;const c={type:n};return t&&(c.loc=s(e.startLoc,e.endLoc)),null!=r&&(c.value=r),c}const x=e=>h(e,14);function y(e,n){return e.currentChar()===n?(e.next(),n):(u(),"")}function m(e){let n="";for(;" "===e.currentPeek()||"\n"===e.currentPeek();)n+=e.currentPeek(),e.peek();return n}function b(e){const n=m(e);return e.skipToPeek(),n}function L(e){if(e===f)return!1;const n=e.charCodeAt(0);return n>=97&&n<=122||n>=65&&n<=90}function T(e,n){const{currentType:t}=n;if(2!==t)return!1;m(e);const r=function(e){if(e===f)return!1;const n=e.charCodeAt(0);return n>=48&&n<=57}("-"===e.currentPeek()?e.peek():e.currentPeek());return e.resetPeek(),r}function P(e){m(e);const n="|"===e.currentPeek();return e.resetPeek(),n}function C(e,n=!0){const t=(n=!1,r="",c=!1)=>{const o=e.currentPeek();return"{"===o?"%"!==r&&n:"@"!==o&&o?"%"===o?(e.peek(),t(n,"%",!0)):"|"===o?!("%"!==r&&!c)||!(" "===r||"\n"===r):" "===o?(e.peek(),t(!0," ",c)):"\n"!==o||(e.peek(),t(!0,"\n",c)):"%"===r||n},r=t();return n&&e.resetPeek(),r}function v(e,n){const t=e.currentChar();return t===f?f:n(t)?(e.next(),t):null}function O(e){return v(e,(e=>{const n=e.charCodeAt(0);return n>=97&&n<=122||n>=65&&n<=90||n>=48&&n<=57||95===n||36===n}))}function N(e){return v(e,(e=>{const n=e.charCodeAt(0);return n>=48&&n<=57}))}function g(e){return v(e,(e=>{const n=e.charCodeAt(0);return n>=48&&n<=57||n>=65&&n<=70||n>=97&&n<=102}))}function w(e){let n="",t="";for(;n=N(e);)t+=n;return t}function $(e){const n=e.currentChar();switch(n){case"\\":case"'":return e.next(),`\\${n}`;case"u":return S(e,n,4);case"U":return S(e,n,6);default:return u(),""}}function S(e,n,t){y(e,n);let r="";for(let n=0;n<t;n++){const n=g(e);if(!n){u(),e.currentChar();break}r+=n}return`\\${n}${r}`}function I(e){b(e);const n=y(e,"|");return b(e),n}function A(e,n){let t=null;switch(e.currentChar()){case"{":return n.braceNest>=1&&u(),e.next(),t=h(n,2,"{"),b(e),n.braceNest++,t;case"}":return n.braceNest>0&&2===n.currentType&&u(),e.next(),t=h(n,3,"}"),n.braceNest--,n.braceNest>0&&b(e),n.inLinked&&0===n.braceNest&&(n.inLinked=!1),t;case"@":return n.braceNest>0&&u(),t=E(e,n)||x(n),n.braceNest=0,t;default:let r=!0,c=!0,o=!0;if(P(e))return n.braceNest>0&&u(),t=h(n,1,I(e)),n.braceNest=0,n.inLinked=!1,t;if(n.braceNest>0&&(5===n.currentType||6===n.currentType||7===n.currentType))return u(),n.braceNest=0,U(e,n);if(r=function(e,n){const{currentType:t}=n;if(2!==t)return!1;m(e);const r=L(e.currentPeek());return e.resetPeek(),r}(e,n))return t=h(n,5,function(e){b(e);let n="",t="";for(;n=O(e);)t+=n;return e.currentChar()===f&&u(),t}(e)),b(e),t;if(c=T(e,n))return t=h(n,6,function(e){b(e);let n="";return"-"===e.currentChar()?(e.next(),n+=`-${w(e)}`):n+=w(e),e.currentChar()===f&&u(),n}(e)),b(e),t;if(o=function(e,n){const{currentType:t}=n;if(2!==t)return!1;m(e);const r="'"===e.currentPeek();return e.resetPeek(),r}(e,n))return t=h(n,7,function(e){b(e),y(e,"'");let n="",t="";const r=e=>"'"!==e&&"\n"!==e;for(;n=v(e,r);)t+="\\"===n?$(e):n;const c=e.currentChar();return"\n"===c||c===f?(u(),"\n"===c&&(e.next(),y(e,"'")),t):(y(e,"'"),t)}(e)),b(e),t;if(!r&&!c&&!o)return t=h(n,13,function(e){b(e);let n="",t="";const r=e=>"{"!==e&&"}"!==e&&" "!==e&&"\n"!==e;for(;n=v(e,r);)t+=n;return t}(e)),u(),b(e),t}return t}function E(e,n){const{currentType:t}=n;let r=null;const c=e.currentChar();switch(8!==t&&9!==t&&12!==t&&10!==t||"\n"!==c&&" "!==c||u(),c){case"@":return e.next(),r=h(n,8,"@"),n.inLinked=!0,r;case".":return b(e),e.next(),h(n,9,".");case":":return b(e),e.next(),h(n,10,":");default:return P(e)?(r=h(n,1,I(e)),n.braceNest=0,n.inLinked=!1,r):function(e,n){const{currentType:t}=n;if(8!==t)return!1;m(e);const r="."===e.currentPeek();return e.resetPeek(),r}(e,n)||function(e,n){const{currentType:t}=n;if(8!==t&&12!==t)return!1;m(e);const r=":"===e.currentPeek();return e.resetPeek(),r}(e,n)?(b(e),E(e,n)):function(e,n){const{currentType:t}=n;if(9!==t)return!1;m(e);const r=L(e.currentPeek());return e.resetPeek(),r}(e,n)?(b(e),h(n,12,function(e){let n="",t="";for(;n=O(e);)t+=n;return t}(e))):function(e,n){const{currentType:t}=n;if(10!==t)return!1;const r=()=>{const n=e.currentPeek();return"{"===n?L(e.peek()):!("@"===n||"%"===n||"|"===n||":"===n||"."===n||" "===n||!n)&&("\n"===n?(e.peek(),r()):L(n))},c=r();return e.resetPeek(),c}(e,n)?(b(e),"{"===c?A(e,n)||r:h(n,11,function(e){const n=(t=!1,r)=>{const c=e.currentChar();return"{"!==c&&"%"!==c&&"@"!==c&&"|"!==c&&c?" "===c?r:"\n"===c?(r+=c,e.next(),n(t,r)):(r+=c,e.next(),n(!0,r)):r};return n(!1,"")}(e))):(8===t&&u(),n.braceNest=0,n.inLinked=!1,U(e,n))}}function U(e,n){let t={type:14};if(n.braceNest>0)return A(e,n)||x(n);if(n.inLinked)return E(e,n)||x(n);const r=e.currentChar();switch(r){case"{":return A(e,n)||x(n);case"}":return u(),e.next(),h(n,3,"}");case"@":return E(e,n)||x(n);default:if(P(e))return t=h(n,1,I(e)),n.braceNest=0,n.inLinked=!1,t;if(C(e))return h(n,0,function(e){const n=t=>{const r=e.currentChar();return"{"!==r&&"}"!==r&&"@"!==r&&r?"%"===r?C(e)?(t+=r,e.next(),n(t)):t:"|"===r?t:" "===r||"\n"===r?C(e)?(t+=r,e.next(),n(t)):P(e)?t:(t+=r,e.next(),n(t)):(t+=r,e.next(),n(t)):t};return n("")}(e));if("%"===r)return e.next(),h(n,4,"%")}return t}return{nextToken:function(){const{currentType:e,offset:n,startLoc:t,endLoc:o}=d;return d.lastType=e,d.lastOffset=n,d.lastStartLoc=t,d.lastEndLoc=o,d.offset=c(),d.startLoc=u(),r.currentChar()===f?h(d,14):U(r,d)},currentOffset:c,currentPosition:u,context:p}}const d="parser",p=/(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;function k(e,n,t){switch(e){case"\\\\":return"\\";case"\\'":return"'";default:{const e=parseInt(n||t,16);return e<=55295||e>=57344?String.fromCodePoint(e):"�"}}}function h(e={}){const n=!1!==e.location,{onError:t}=e;function r(e,t,r){const c={type:e,start:t,end:t};return n&&(c.loc={start:r,end:r}),c}function c(e,t,r,c){e.end=t,c&&(e.type=c),n&&e.loc&&(e.loc.end=r)}function o(e,n){const t=e.context(),o=r(3,t.offset,t.startLoc);return o.value=n,c(o,e.currentOffset(),e.currentPosition()),o}function s(e,n){const t=e.context(),{lastOffset:o,lastStartLoc:s}=t,u=r(5,o,s);return u.index=parseInt(n,10),e.nextToken(),c(u,e.currentOffset(),e.currentPosition()),u}function u(e,n){const t=e.context(),{lastOffset:o,lastStartLoc:s}=t,u=r(4,o,s);return u.key=n,e.nextToken(),c(u,e.currentOffset(),e.currentPosition()),u}function i(e,n){const t=e.context(),{lastOffset:o,lastStartLoc:s}=t,u=r(9,o,s);return u.value=n.replace(p,k),e.nextToken(),c(u,e.currentOffset(),e.currentPosition()),u}function a(e){const n=e.context(),t=r(6,n.offset,n.startLoc);let o=e.nextToken();if(9===o.type){const n=function(e){const n=e.nextToken(),t=e.context(),{lastOffset:o,lastStartLoc:s}=t,u=r(8,o,s);return 12!==n.type?(u.value="",c(u,o,s),{nextConsumeToken:n,node:u}):(u.value=n.value||"",c(u,e.currentOffset(),e.currentPosition()),{node:u})}(e);t.modifier=n.node,o=n.nextConsumeToken||e.nextToken()}switch(o=e.nextToken(),2===o.type&&(o=e.nextToken()),o.type){case 11:t.key=function(e,n){const t=e.context(),o=r(7,t.offset,t.startLoc);return o.value=n,c(o,e.currentOffset(),e.currentPosition()),o}(e,o.value||"");break;case 5:t.key=u(e,o.value||"");break;case 6:t.key=s(e,o.value||"");break;case 7:t.key=i(e,o.value||"");break;default:const n=e.context(),a=r(7,n.offset,n.startLoc);return a.value="",c(a,n.offset,n.startLoc),t.key=a,c(t,n.offset,n.startLoc),{nextConsumeToken:o,node:t}}return c(t,e.currentOffset(),e.currentPosition()),{node:t}}function f(e){const n=e.context(),t=r(2,1===n.currentType?e.currentOffset():n.offset,1===n.currentType?n.endLoc:n.startLoc);t.items=[];let f=null;do{const n=f||e.nextToken();switch(f=null,n.type){case 0:t.items.push(o(e,n.value||""));break;case 6:t.items.push(s(e,n.value||""));break;case 5:t.items.push(u(e,n.value||""));break;case 7:t.items.push(i(e,n.value||""));break;case 8:const r=a(e);t.items.push(r.node),f=r.nextConsumeToken||null}}while(14!==n.currentType&&1!==n.currentType);return c(t,1===n.currentType?n.lastOffset:e.currentOffset(),1===n.currentType?n.lastEndLoc:e.currentPosition()),t}function d(e){const n=e.context(),{offset:t,startLoc:o}=n,s=f(e);return 14===n.currentType?s:function(e,n,t,o){const s=e.context();let u=0===o.items.length;const i=r(1,n,t);i.cases=[],i.cases.push(o);do{const n=f(e);u||(u=0===n.items.length),i.cases.push(n)}while(14!==s.currentType);return c(i,e.currentOffset(),e.currentPosition()),i}(e,t,o,s)}return{parse:function(t){const o=l(t,{...e}),s=o.context(),u=r(0,s.offset,s.startLoc);return n&&u.loc&&(u.loc.source=t),u.body=d(o),c(u,o.currentOffset(),o.currentPosition()),u}}}function x(e,n){for(let t=0;t<e.length;t++)y(e[t],n)}function y(e,n){switch(e.type){case 1:x(e.cases,n),n.helper("plural");break;case 2:x(e.items,n);break;case 6:y(e.key,n),n.helper("linked");break;case 5:n.helper("interpolate"),n.helper("list");break;case 4:n.helper("interpolate"),n.helper("named")}}function m(e,n={}){const t=function(e,n={}){const t={ast:e,helpers:new Set};return{context:()=>t,helper:e=>(t.helpers.add(e),e)}}(e);t.helper("normalize"),e.body&&y(e.body,t);const r=t.context();e.helpers=[...r.helpers]}function b(e,n){const{helper:t}=e;switch(n.type){case 0:!function(e,n){n.body?b(e,n.body):e.push("null")}(e,n);break;case 1:!function(e,n){const{helper:t,needIndent:r}=e;if(n.cases.length>1){e.push(`${t("plural")}([`),e.indent(r());const c=n.cases.length;for(let t=0;t<c&&(b(e,n.cases[t]),t!==c-1);t++)e.push(", ");e.deindent(r()),e.push("])")}}(e,n);break;case 2:!function(e,n){const{helper:t,needIndent:r}=e;e.push(`${t("normalize")}([`),e.indent(r());const c=n.items.length;for(let t=0;t<c&&(b(e,n.items[t]),t!==c-1);t++)e.push(", ");e.deindent(r()),e.push("])")}(e,n);break;case 6:!function(e,n){const{helper:t}=e;e.push(`${t("linked")}(`),b(e,n.key),n.modifier&&(e.push(", "),b(e,n.modifier)),e.push(")")}(e,n);break;case 8:case 7:e.push(JSON.stringify(n.value),n);break;case 5:e.push(`${t("interpolate")}(${t("list")}(${n.index}))`,n);break;case 4:e.push(`${t("interpolate")}(${t("named")}(${JSON.stringify(n.key)}))`,n);break;case 9:case 3:e.push(JSON.stringify(n.value),n)}}function L(n,t={}){const r=h({...t}).parse(n);return m(r,{...t}),((n,t={})=>{const r=e(t.mode)?t.mode:"normal",c=e(t.filename)?t.filename:"message.intl",o=t.needIndent?t.needIndent:"arrow"!==r,s=n.helpers||[],u=function(e,n){const{filename:t,breakLineCode:r,needIndent:c}=n,o={source:e.loc.source,filename:t,code:"",column:1,line:1,offset:0,map:void 0,breakLineCode:r,needIndent:c,indentLevel:0};function s(e,n){o.code+=e}function u(e,n=!0){const t=n?r:"";s(c?t+" ".repeat(e):t)}return{context:()=>o,push:s,indent:function(e=!0){const n=++o.indentLevel;e&&u(n)},deindent:function(e=!0){const n=--o.indentLevel;e&&u(n)},newline:function(){u(o.indentLevel)},helper:e=>`_${e}`,needIndent:()=>o.needIndent}}(n,{mode:r,filename:c,sourceMap:!!t.sourceMap,breakLineCode:null!=t.breakLineCode?t.breakLineCode:"arrow"===r?";":"\n",needIndent:o});u.push("normal"===r?"function __msg__ (ctx) {":"(ctx) => {"),u.indent(o),s.length>0&&(u.push(`const { ${s.map((e=>`${e}: _${e}`)).join(", ")} } = ctx`),u.newline()),u.push("return "),b(u,n),u.deindent(o),u.push("}");const{code:i,map:a}=u.context();return{ast:n,code:i,map:a?a.toJSON():void 0}})(r,{...t})}export{d as ERROR_DOMAIN,c as LocationStub,L as baseCompile,t as createCompileError,s as createLocation,h as createParser,o as createPosition,r as defaultOnError,n as errorMessages}; |
/*! | ||
* @intlify/message-compiler v9.0.0-beta.14 | ||
* @intlify/message-compiler v9.0.0-beta.15 | ||
* (c) 2020 kazuya kawaguchi | ||
@@ -138,3 +138,3 @@ * Released under the MIT License. | ||
function createTokenizer(source, options = {}) { | ||
const location = !options.location; | ||
const location = options.location !== false; | ||
const _scnr = createScanner(source); | ||
@@ -808,3 +808,3 @@ const currentOffset = () => _scnr.index(); | ||
function createParser(options = {}) { | ||
const location = !options.location; | ||
const location = options.location !== false; | ||
const { onError } = options; | ||
@@ -881,2 +881,14 @@ function emitError(tokenzer, code, start, offset, ...args) { | ||
const context = tokenizer.context(); | ||
const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc | ||
const node = startNode(8 /* LinkedModifier */, offset, loc); | ||
if (token.type !== 12 /* LinkedModifier */) { | ||
// empty modifier | ||
emitError(tokenizer, 11 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, token.type); | ||
node.value = ''; | ||
endNode(node, offset, loc); | ||
return { | ||
nextConsumeToken: token, | ||
node | ||
}; | ||
} | ||
// check token | ||
@@ -886,7 +898,7 @@ if (token.value == null) { | ||
} | ||
const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc | ||
const node = startNode(8 /* LinkedModifier */, offset, loc); | ||
node.value = token.value || ''; | ||
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition()); | ||
return node; | ||
return { | ||
node | ||
}; | ||
} | ||
@@ -905,4 +917,5 @@ function parseLinkedKey(tokenizer, value) { | ||
if (token.type === 9 /* LinkedDot */) { | ||
linkedNode.modifier = parseLinkedModifier(tokenizer); | ||
token = tokenizer.nextToken(); | ||
const parsed = parseLinkedModifier(tokenizer); | ||
linkedNode.modifier = parsed.node; | ||
token = parsed.nextConsumeToken || tokenizer.nextToken(); | ||
} | ||
@@ -943,5 +956,20 @@ // asset check token | ||
break; | ||
default: | ||
// empty key | ||
emitError(tokenizer, 11 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, token.type); | ||
const nextContext = tokenizer.context(); | ||
const emptyLinkedKeyNode = startNode(7 /* LinkedKey */, nextContext.offset, nextContext.startLoc); | ||
emptyLinkedKeyNode.value = ''; | ||
endNode(emptyLinkedKeyNode, nextContext.offset, nextContext.startLoc); | ||
linkedNode.key = emptyLinkedKeyNode; | ||
endNode(linkedNode, nextContext.offset, nextContext.startLoc); | ||
return { | ||
nextConsumeToken: token, | ||
node: linkedNode | ||
}; | ||
} | ||
endNode(linkedNode, tokenizer.currentOffset(), tokenizer.currentPosition()); | ||
return linkedNode; | ||
return { | ||
node: linkedNode | ||
}; | ||
} | ||
@@ -958,4 +986,6 @@ function parseMessage(tokenizer) { | ||
node.items = []; | ||
let nextToken = null; | ||
do { | ||
const token = tokenizer.nextToken(); | ||
const token = nextToken || tokenizer.nextToken(); | ||
nextToken = null; | ||
switch (token.type) { | ||
@@ -987,3 +1017,5 @@ case 0 /* Text */: | ||
case 8 /* LinkedAlias */: | ||
node.items.push(parseLinked(tokenizer)); | ||
const parsed = parseLinked(tokenizer); | ||
node.items.push(parsed.node); | ||
nextToken = parsed.nextConsumeToken || null; | ||
break; | ||
@@ -990,0 +1022,0 @@ } |
/*! | ||
* @intlify/message-compiler v9.0.0-beta.14 | ||
* @intlify/message-compiler v9.0.0-beta.15 | ||
* (c) 2020 kazuya kawaguchi | ||
@@ -159,3 +159,3 @@ * Released under the MIT License. | ||
function createTokenizer(source, options = {}) { | ||
const location = !options.location; | ||
const location = options.location !== false; | ||
const _scnr = createScanner(source); | ||
@@ -829,3 +829,3 @@ const currentOffset = () => _scnr.index(); | ||
function createParser(options = {}) { | ||
const location = !options.location; | ||
const location = options.location !== false; | ||
const { onError } = options; | ||
@@ -902,2 +902,14 @@ function emitError(tokenzer, code, start, offset, ...args) { | ||
const context = tokenizer.context(); | ||
const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc | ||
const node = startNode(8 /* LinkedModifier */, offset, loc); | ||
if (token.type !== 12 /* LinkedModifier */) { | ||
// empty modifier | ||
emitError(tokenizer, 11 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, token.type); | ||
node.value = ''; | ||
endNode(node, offset, loc); | ||
return { | ||
nextConsumeToken: token, | ||
node | ||
}; | ||
} | ||
// check token | ||
@@ -907,7 +919,7 @@ if (token.value == null) { | ||
} | ||
const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc | ||
const node = startNode(8 /* LinkedModifier */, offset, loc); | ||
node.value = token.value || ''; | ||
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition()); | ||
return node; | ||
return { | ||
node | ||
}; | ||
} | ||
@@ -926,4 +938,5 @@ function parseLinkedKey(tokenizer, value) { | ||
if (token.type === 9 /* LinkedDot */) { | ||
linkedNode.modifier = parseLinkedModifier(tokenizer); | ||
token = tokenizer.nextToken(); | ||
const parsed = parseLinkedModifier(tokenizer); | ||
linkedNode.modifier = parsed.node; | ||
token = parsed.nextConsumeToken || tokenizer.nextToken(); | ||
} | ||
@@ -964,5 +977,20 @@ // asset check token | ||
break; | ||
default: | ||
// empty key | ||
emitError(tokenizer, 11 /* UNEXPECTED_LEXICAL_ANALYSIS */, context.lastStartLoc, 0, token.type); | ||
const nextContext = tokenizer.context(); | ||
const emptyLinkedKeyNode = startNode(7 /* LinkedKey */, nextContext.offset, nextContext.startLoc); | ||
emptyLinkedKeyNode.value = ''; | ||
endNode(emptyLinkedKeyNode, nextContext.offset, nextContext.startLoc); | ||
linkedNode.key = emptyLinkedKeyNode; | ||
endNode(linkedNode, nextContext.offset, nextContext.startLoc); | ||
return { | ||
nextConsumeToken: token, | ||
node: linkedNode | ||
}; | ||
} | ||
endNode(linkedNode, tokenizer.currentOffset(), tokenizer.currentPosition()); | ||
return linkedNode; | ||
return { | ||
node: linkedNode | ||
}; | ||
} | ||
@@ -979,4 +1007,6 @@ function parseMessage(tokenizer) { | ||
node.items = []; | ||
let nextToken = null; | ||
do { | ||
const token = tokenizer.nextToken(); | ||
const token = nextToken || tokenizer.nextToken(); | ||
nextToken = null; | ||
switch (token.type) { | ||
@@ -1008,3 +1038,5 @@ case 0 /* Text */: | ||
case 8 /* LinkedAlias */: | ||
node.items.push(parseLinked(tokenizer)); | ||
const parsed = parseLinked(tokenizer); | ||
node.items.push(parsed.node); | ||
nextToken = parsed.nextConsumeToken || null; | ||
break; | ||
@@ -1011,0 +1043,0 @@ } |
/*! | ||
* @intlify/message-compiler v9.0.0-beta.14 | ||
* @intlify/message-compiler v9.0.0-beta.15 | ||
* (c) 2020 kazuya kawaguchi | ||
* Released under the MIT License. | ||
*/ | ||
var IntlifyMessageCompiler=function(e){"use strict";const t=e=>"string"==typeof e,n={0:"Expected token: '{0}'",1:"Invalid token in placeholder: '{0}'",2:"Unterminated single quote in placeholder",3:"Unknown escape sequence: \\{0}",4:"Invalid unicode escape sequence: {0}",5:"Unbalanced closing brace",6:"Unterminated closing brace",7:"Empty placeholder",8:"Not allowed nest placeholder",9:"Invalid linked format",10:"Plural must have messages",11:"Unexpected lexical analysis in token: '{0}'"};function r(e,t,n={}){const{domain:r}=n,c=new SyntaxError(String(e));return c.code=e,t&&(c.location=t),c.domain=r,c}function c(e,t,n){return{line:e,column:t,offset:n}}function o(e,t,n){const r={start:e,end:t};return null!=n&&(r.source=n),r}const s=" ",u="\n",i=String.fromCharCode(8232),a=String.fromCharCode(8233);function f(e){const t=e;let n=0,r=1,c=1,o=0;const s=e=>"\r"===t[e]&&t[e+1]===u,f=e=>t[e]===a,l=e=>t[e]===i,d=e=>s(e)||(e=>t[e]===u)(e)||f(e)||l(e),p=e=>s(e)||f(e)||l(e)?u:t[e];function k(){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:k,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;)k();o=0}}}const l=void 0;function d(e,t={}){const n=!t.location,r=f(e),i=()=>r.index(),a=()=>c(r.line(),r.column(),r.index()),d=a(),p=i(),k={currentType:14,offset:p,startLoc:d,endLoc:d,lastType:14,lastOffset:p,lastStartLoc:d,lastEndLoc:d,braceNest:0,inLinked:!1,text:""},h=()=>k,{onError:x}=t;function y(e,t,r){e.endLoc=a(),e.currentType=t;const c={type:t};return n&&(c.loc=o(e.startLoc,e.endLoc)),null!=r&&(c.value=r),c}const m=e=>y(e,14);function b(e,t){return e.currentChar()===t?(e.next(),t):(a(),"")}function L(e){let t="";for(;e.currentPeek()===s||e.currentPeek()===u;)t+=e.currentPeek(),e.peek();return t}function P(e){const t=L(e);return e.skipToPeek(),t}function T(e){if(e===l)return!1;const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90}function C(e,t){const{currentType:n}=t;if(2!==n)return!1;L(e);const r=function(e){if(e===l)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}("-"===e.currentPeek()?e.peek():e.currentPeek());return e.resetPeek(),r}function v(e){L(e);const t="|"===e.currentPeek();return e.resetPeek(),t}function O(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===s||r===u):o===s?(e.peek(),n(!0,s,c)):o!==u||(e.peek(),n(!0,u,c)):"%"===r||t},r=n();return t&&e.resetPeek(),r}function g(e,t){const n=e.currentChar();return n===l?l:t(n)?(e.next(),n):null}function N(e){return g(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 w(e){return g(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57}))}function S(e){return g(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}))}function $(e){let t="",n="";for(;t=w(e);)n+=t;return n}function I(e){const t=e.currentChar();switch(t){case"\\":case"'":return e.next(),`\\${t}`;case"u":return E(e,t,4);case"U":return E(e,t,6);default:return a(),""}}function E(e,t,n){b(e,t);let r="";for(let t=0;t<n;t++){const t=S(e);if(!t){a(),e.currentChar();break}r+=t}return`\\${t}${r}`}function A(e){P(e);const t=b(e,"|");return P(e),t}function _(e,t){let n=null;switch(e.currentChar()){case"{":return t.braceNest>=1&&a(),e.next(),n=y(t,2,"{"),P(e),t.braceNest++,n;case"}":return t.braceNest>0&&2===t.currentType&&a(),e.next(),n=y(t,3,"}"),t.braceNest--,t.braceNest>0&&P(e),t.inLinked&&0===t.braceNest&&(t.inLinked=!1),n;case"@":return t.braceNest>0&&a(),n=U(e,t)||m(t),t.braceNest=0,n;default:let r=!0,c=!0,o=!0;if(v(e))return t.braceNest>0&&a(),n=y(t,1,A(e)),t.braceNest=0,t.inLinked=!1,n;if(t.braceNest>0&&(5===t.currentType||6===t.currentType||7===t.currentType))return a(),t.braceNest=0,M(e,t);if(r=function(e,t){const{currentType:n}=t;if(2!==n)return!1;L(e);const r=T(e.currentPeek());return e.resetPeek(),r}(e,t))return n=y(t,5,function(e){P(e);let t="",n="";for(;t=N(e);)n+=t;return e.currentChar()===l&&a(),n}(e)),P(e),n;if(c=C(e,t))return n=y(t,6,function(e){P(e);let t="";return"-"===e.currentChar()?(e.next(),t+=`-${$(e)}`):t+=$(e),e.currentChar()===l&&a(),t}(e)),P(e),n;if(o=function(e,t){const{currentType:n}=t;if(2!==n)return!1;L(e);const r="'"===e.currentPeek();return e.resetPeek(),r}(e,t))return n=y(t,7,function(e){P(e),b(e,"'");let t="",n="";const r=e=>"'"!==e&&e!==u;for(;t=g(e,r);)n+="\\"===t?I(e):t;const c=e.currentChar();return c===u||c===l?(a(),c===u&&(e.next(),b(e,"'")),n):(b(e,"'"),n)}(e)),P(e),n;if(!r&&!c&&!o)return n=y(t,13,function(e){P(e);let t="",n="";const r=e=>"{"!==e&&"}"!==e&&e!==s&&e!==u;for(;t=g(e,r);)n+=t;return n}(e)),a(),P(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||c!==u&&c!==s||a(),c){case"@":return e.next(),r=y(t,8,"@"),t.inLinked=!0,r;case".":return P(e),e.next(),y(t,9,".");case":":return P(e),e.next(),y(t,10,":");default:return v(e)?(r=y(t,1,A(e)),t.braceNest=0,t.inLinked=!1,r):function(e,t){const{currentType:n}=t;if(8!==n)return!1;L(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;L(e);const r=":"===e.currentPeek();return e.resetPeek(),r}(e,t)?(P(e),U(e,t)):function(e,t){const{currentType:n}=t;if(9!==n)return!1;L(e);const r=T(e.currentPeek());return e.resetPeek(),r}(e,t)?(P(e),y(t,12,function(e){let t="",n="";for(;t=N(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===s||!t)&&(t===u?(e.peek(),r()):T(t))},c=r();return e.resetPeek(),c}(e,t)?(P(e),"{"===c?_(e,t)||r:y(t,11,function(e){const t=(n=!1,r)=>{const c=e.currentChar();return"{"!==c&&"%"!==c&&"@"!==c&&"|"!==c&&c?c===s?r:c===u?(r+=c,e.next(),t(n,r)):(r+=c,e.next(),t(!0,r)):r};return t(!1,"")}(e))):(8===n&&a(),t.braceNest=0,t.inLinked=!1,M(e,t))}}function M(e,t){let n={type:14};if(t.braceNest>0)return _(e,t)||m(t);if(t.inLinked)return U(e,t)||m(t);const r=e.currentChar();switch(r){case"{":return _(e,t)||m(t);case"}":return a(),e.next(),y(t,3,"}");case"@":return U(e,t)||m(t);default:if(v(e))return n=y(t,1,A(e)),t.braceNest=0,t.inLinked=!1,n;if(O(e))return y(t,0,function(e){const t=n=>{const r=e.currentChar();return"{"!==r&&"}"!==r&&"@"!==r&&r?"%"===r?O(e)?(n+=r,e.next(),t(n)):n:"|"===r?n:r===s||r===u?O(e)?(n+=r,e.next(),t(n)):v(e)?n:(n+=r,e.next(),t(n)):(n+=r,e.next(),t(n)):n};return t("")}(e));if("%"===r)return e.next(),y(t,4,"%")}return n}return{nextToken:function(){const{currentType:e,offset:t,startLoc:n,endLoc:c}=k;return k.lastType=e,k.lastOffset=t,k.lastStartLoc=n,k.lastEndLoc=c,k.offset=i(),k.startLoc=a(),r.currentChar()===l?y(k,14):M(r,k)},currentOffset:i,currentPosition:a,context:h}}const p="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 x(e={}){const t=!e.location,{onError:n}=e;function r(e,n,r){const c={type:e,start:n,end:n};return t&&(c.loc={start:r,end:r}),c}function c(e,n,r,c){e.end=n,c&&(e.type=c),t&&e.loc&&(e.loc.end=r)}function o(e,t){const n=e.context(),o=r(3,n.offset,n.startLoc);return o.value=t,c(o,e.currentOffset(),e.currentPosition()),o}function s(e,t){const n=e.context(),{lastOffset:o,lastStartLoc:s}=n,u=r(5,o,s);return u.index=parseInt(t,10),e.nextToken(),c(u,e.currentOffset(),e.currentPosition()),u}function u(e,t){const n=e.context(),{lastOffset:o,lastStartLoc:s}=n,u=r(4,o,s);return u.key=t,e.nextToken(),c(u,e.currentOffset(),e.currentPosition()),u}function i(e,t){const n=e.context(),{lastOffset:o,lastStartLoc:s}=n,u=r(9,o,s);return u.value=t.replace(k,h),e.nextToken(),c(u,e.currentOffset(),e.currentPosition()),u}function a(e){const t=e.context(),n=r(6,t.offset,t.startLoc);let o=e.nextToken();switch(9===o.type&&(n.modifier=function(e){const t=e.nextToken(),n=e.context(),{lastOffset:o,lastStartLoc:s}=n,u=r(8,o,s);return u.value=t.value||"",c(u,e.currentOffset(),e.currentPosition()),u}(e),o=e.nextToken()),o=e.nextToken(),2===o.type&&(o=e.nextToken()),o.type){case 11:n.key=function(e,t){const n=e.context(),o=r(7,n.offset,n.startLoc);return o.value=t,c(o,e.currentOffset(),e.currentPosition()),o}(e,o.value||"");break;case 5:n.key=u(e,o.value||"");break;case 6:n.key=s(e,o.value||"");break;case 7:n.key=i(e,o.value||"")}return c(n,e.currentOffset(),e.currentPosition()),n}function f(e){const t=e.context(),n=r(2,1===t.currentType?e.currentOffset():t.offset,1===t.currentType?t.endLoc:t.startLoc);n.items=[];do{const t=e.nextToken();switch(t.type){case 0:n.items.push(o(e,t.value||""));break;case 6:n.items.push(s(e,t.value||""));break;case 5:n.items.push(u(e,t.value||""));break;case 7:n.items.push(i(e,t.value||""));break;case 8:n.items.push(a(e))}}while(14!==t.currentType&&1!==t.currentType);return c(n,1===t.currentType?t.lastOffset:e.currentOffset(),1===t.currentType?t.lastEndLoc:e.currentPosition()),n}function l(e){const t=e.context(),{offset:n,startLoc:o}=t,s=f(e);return 14===t.currentType?s:function(e,t,n,o){const s=e.context();let u=0===o.items.length;const i=r(1,t,n);i.cases=[],i.cases.push(o);do{const t=f(e);u||(u=0===t.items.length),i.cases.push(t)}while(14!==s.currentType);return c(i,e.currentOffset(),e.currentPosition()),i}(e,n,o,s)}return{parse:function(n){const o=d(n,{...e}),s=o.context(),u=r(0,s.offset,s.startLoc);return t&&u.loc&&(u.loc.source=n),u.body=l(o),c(u,o.currentOffset(),o.currentPosition()),u}}}function y(e,t){for(let n=0;n<e.length;n++)m(e[n],t)}function m(e,t){switch(e.type){case 1:y(e.cases,t),t.helper("plural");break;case 2:y(e.items,t);break;case 6:m(e.key,t),t.helper("linked");break;case 5:t.helper("interpolate"),t.helper("list");break;case 4:t.helper("interpolate"),t.helper("named")}}function b(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&&m(e.body,n);const r=n.context();e.helpers=[...r.helpers]}function L(e,t){const{helper:n}=e;switch(t.type){case 0:!function(e,t){t.body?L(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&&(L(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&&(L(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")}(`),L(e,t.key),t.modifier&&(e.push(", "),L(e,t.modifier)),e.push(")")}(e,t);break;case 8:case 7: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);break;case 9:case 3:e.push(JSON.stringify(t.value),t)}}return e.ERROR_DOMAIN=p,e.LocationStub={start:{line:1,column:1,offset:0},end:{line:1,column:1,offset:0}},e.baseCompile=function(e,n={}){const r=x({...n}).parse(e);return b(r,{...n}),((e,n={})=>{const r=t(n.mode)?n.mode:"normal",c=t(n.filename)?n.filename:"message.intl",o=n.needIndent?n.needIndent:"arrow"!==r,s=e.helpers||[],u=function(e,t){const{filename:n,breakLineCode:r,needIndent:c}=t,o={source:e.loc.source,filename:n,code:"",column:1,line:1,offset:0,map:void 0,breakLineCode:r,needIndent:c,indentLevel:0};function s(e,t){o.code+=e}function u(e,t=!0){const n=t?r:"";s(c?n+" ".repeat(e):n)}return{context:()=>o,push:s,indent:function(e=!0){const t=++o.indentLevel;e&&u(t)},deindent:function(e=!0){const t=--o.indentLevel;e&&u(t)},newline:function(){u(o.indentLevel)},helper:e=>`_${e}`,needIndent:()=>o.needIndent}}(e,{mode:r,filename:c,sourceMap:!!n.sourceMap,breakLineCode:null!=n.breakLineCode?n.breakLineCode:"arrow"===r?";":"\n",needIndent:o});u.push("normal"===r?"function __msg__ (ctx) {":"(ctx) => {"),u.indent(o),s.length>0&&(u.push(`const { ${s.map((e=>`${e}: _${e}`)).join(", ")} } = ctx`),u.newline()),u.push("return "),L(u,e),u.deindent(o),u.push("}");const{code:i,map:a}=u.context();return{ast:e,code:i,map:a?a.toJSON():void 0}})(r,{...n})},e.createCompileError=r,e.createLocation=o,e.createParser=x,e.createPosition=c,e.defaultOnError=function(e){throw e},e.errorMessages=n,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); | ||
var IntlifyMessageCompiler=function(e){"use strict";const n=e=>"string"==typeof e,t={0:"Expected token: '{0}'",1:"Invalid token in placeholder: '{0}'",2:"Unterminated single quote in placeholder",3:"Unknown escape sequence: \\{0}",4:"Invalid unicode escape sequence: {0}",5:"Unbalanced closing brace",6:"Unterminated closing brace",7:"Empty placeholder",8:"Not allowed nest placeholder",9:"Invalid linked format",10:"Plural must have messages",11:"Unexpected lexical analysis in token: '{0}'"};function r(e,n,t={}){const{domain:r}=t,c=new SyntaxError(String(e));return c.code=e,n&&(c.location=n),c.domain=r,c}function c(e,n,t){return{line:e,column:n,offset:t}}function o(e,n,t){const r={start:e,end:n};return null!=t&&(r.source=t),r}const s=" ",u="\n",i=String.fromCharCode(8232),a=String.fromCharCode(8233);function f(e){const n=e;let t=0,r=1,c=1,o=0;const s=e=>"\r"===n[e]&&n[e+1]===u,f=e=>n[e]===a,l=e=>n[e]===i,d=e=>s(e)||(e=>n[e]===u)(e)||f(e)||l(e),p=e=>s(e)||f(e)||l(e)?u:n[e];function k(){return o=0,d(t)&&(r++,c=0),s(t)&&t++,t++,c++,n[t]}return{index:()=>t,line:()=>r,column:()=>c,peekOffset:()=>o,charAt:p,currentChar:()=>p(t),currentPeek:()=>p(t+o),next:k,peek:function(){return s(t+o)&&o++,o++,n[t+o]},reset:function(){t=0,r=1,c=1,o=0},resetPeek:function(e=0){o=e},skipToPeek:function(){const e=t+o;for(;e!==t;)k();o=0}}}const l=void 0;function d(e,n={}){const t=!1!==n.location,r=f(e),i=()=>r.index(),a=()=>c(r.line(),r.column(),r.index()),d=a(),p=i(),k={currentType:14,offset:p,startLoc:d,endLoc:d,lastType:14,lastOffset:p,lastStartLoc:d,lastEndLoc:d,braceNest:0,inLinked:!1,text:""},h=()=>k,{onError:x}=n;function y(e,n,r){e.endLoc=a(),e.currentType=n;const c={type:n};return t&&(c.loc=o(e.startLoc,e.endLoc)),null!=r&&(c.value=r),c}const m=e=>y(e,14);function b(e,n){return e.currentChar()===n?(e.next(),n):(a(),"")}function L(e){let n="";for(;e.currentPeek()===s||e.currentPeek()===u;)n+=e.currentPeek(),e.peek();return n}function P(e){const n=L(e);return e.skipToPeek(),n}function T(e){if(e===l)return!1;const n=e.charCodeAt(0);return n>=97&&n<=122||n>=65&&n<=90}function C(e,n){const{currentType:t}=n;if(2!==t)return!1;L(e);const r=function(e){if(e===l)return!1;const n=e.charCodeAt(0);return n>=48&&n<=57}("-"===e.currentPeek()?e.peek():e.currentPeek());return e.resetPeek(),r}function v(e){L(e);const n="|"===e.currentPeek();return e.resetPeek(),n}function O(e,n=!0){const t=(n=!1,r="",c=!1)=>{const o=e.currentPeek();return"{"===o?"%"!==r&&n:"@"!==o&&o?"%"===o?(e.peek(),t(n,"%",!0)):"|"===o?!("%"!==r&&!c)||!(r===s||r===u):o===s?(e.peek(),t(!0,s,c)):o!==u||(e.peek(),t(!0,u,c)):"%"===r||n},r=t();return n&&e.resetPeek(),r}function g(e,n){const t=e.currentChar();return t===l?l:n(t)?(e.next(),t):null}function N(e){return g(e,(e=>{const n=e.charCodeAt(0);return n>=97&&n<=122||n>=65&&n<=90||n>=48&&n<=57||95===n||36===n}))}function w(e){return g(e,(e=>{const n=e.charCodeAt(0);return n>=48&&n<=57}))}function S(e){return g(e,(e=>{const n=e.charCodeAt(0);return n>=48&&n<=57||n>=65&&n<=70||n>=97&&n<=102}))}function $(e){let n="",t="";for(;n=w(e);)t+=n;return t}function I(e){const n=e.currentChar();switch(n){case"\\":case"'":return e.next(),`\\${n}`;case"u":return E(e,n,4);case"U":return E(e,n,6);default:return a(),""}}function E(e,n,t){b(e,n);let r="";for(let n=0;n<t;n++){const n=S(e);if(!n){a(),e.currentChar();break}r+=n}return`\\${n}${r}`}function A(e){P(e);const n=b(e,"|");return P(e),n}function _(e,n){let t=null;switch(e.currentChar()){case"{":return n.braceNest>=1&&a(),e.next(),t=y(n,2,"{"),P(e),n.braceNest++,t;case"}":return n.braceNest>0&&2===n.currentType&&a(),e.next(),t=y(n,3,"}"),n.braceNest--,n.braceNest>0&&P(e),n.inLinked&&0===n.braceNest&&(n.inLinked=!1),t;case"@":return n.braceNest>0&&a(),t=U(e,n)||m(n),n.braceNest=0,t;default:let r=!0,c=!0,o=!0;if(v(e))return n.braceNest>0&&a(),t=y(n,1,A(e)),n.braceNest=0,n.inLinked=!1,t;if(n.braceNest>0&&(5===n.currentType||6===n.currentType||7===n.currentType))return a(),n.braceNest=0,M(e,n);if(r=function(e,n){const{currentType:t}=n;if(2!==t)return!1;L(e);const r=T(e.currentPeek());return e.resetPeek(),r}(e,n))return t=y(n,5,function(e){P(e);let n="",t="";for(;n=N(e);)t+=n;return e.currentChar()===l&&a(),t}(e)),P(e),t;if(c=C(e,n))return t=y(n,6,function(e){P(e);let n="";return"-"===e.currentChar()?(e.next(),n+=`-${$(e)}`):n+=$(e),e.currentChar()===l&&a(),n}(e)),P(e),t;if(o=function(e,n){const{currentType:t}=n;if(2!==t)return!1;L(e);const r="'"===e.currentPeek();return e.resetPeek(),r}(e,n))return t=y(n,7,function(e){P(e),b(e,"'");let n="",t="";const r=e=>"'"!==e&&e!==u;for(;n=g(e,r);)t+="\\"===n?I(e):n;const c=e.currentChar();return c===u||c===l?(a(),c===u&&(e.next(),b(e,"'")),t):(b(e,"'"),t)}(e)),P(e),t;if(!r&&!c&&!o)return t=y(n,13,function(e){P(e);let n="",t="";const r=e=>"{"!==e&&"}"!==e&&e!==s&&e!==u;for(;n=g(e,r);)t+=n;return t}(e)),a(),P(e),t}return t}function U(e,n){const{currentType:t}=n;let r=null;const c=e.currentChar();switch(8!==t&&9!==t&&12!==t&&10!==t||c!==u&&c!==s||a(),c){case"@":return e.next(),r=y(n,8,"@"),n.inLinked=!0,r;case".":return P(e),e.next(),y(n,9,".");case":":return P(e),e.next(),y(n,10,":");default:return v(e)?(r=y(n,1,A(e)),n.braceNest=0,n.inLinked=!1,r):function(e,n){const{currentType:t}=n;if(8!==t)return!1;L(e);const r="."===e.currentPeek();return e.resetPeek(),r}(e,n)||function(e,n){const{currentType:t}=n;if(8!==t&&12!==t)return!1;L(e);const r=":"===e.currentPeek();return e.resetPeek(),r}(e,n)?(P(e),U(e,n)):function(e,n){const{currentType:t}=n;if(9!==t)return!1;L(e);const r=T(e.currentPeek());return e.resetPeek(),r}(e,n)?(P(e),y(n,12,function(e){let n="",t="";for(;n=N(e);)t+=n;return t}(e))):function(e,n){const{currentType:t}=n;if(10!==t)return!1;const r=()=>{const n=e.currentPeek();return"{"===n?T(e.peek()):!("@"===n||"%"===n||"|"===n||":"===n||"."===n||n===s||!n)&&(n===u?(e.peek(),r()):T(n))},c=r();return e.resetPeek(),c}(e,n)?(P(e),"{"===c?_(e,n)||r:y(n,11,function(e){const n=(t=!1,r)=>{const c=e.currentChar();return"{"!==c&&"%"!==c&&"@"!==c&&"|"!==c&&c?c===s?r:c===u?(r+=c,e.next(),n(t,r)):(r+=c,e.next(),n(!0,r)):r};return n(!1,"")}(e))):(8===t&&a(),n.braceNest=0,n.inLinked=!1,M(e,n))}}function M(e,n){let t={type:14};if(n.braceNest>0)return _(e,n)||m(n);if(n.inLinked)return U(e,n)||m(n);const r=e.currentChar();switch(r){case"{":return _(e,n)||m(n);case"}":return a(),e.next(),y(n,3,"}");case"@":return U(e,n)||m(n);default:if(v(e))return t=y(n,1,A(e)),n.braceNest=0,n.inLinked=!1,t;if(O(e))return y(n,0,function(e){const n=t=>{const r=e.currentChar();return"{"!==r&&"}"!==r&&"@"!==r&&r?"%"===r?O(e)?(t+=r,e.next(),n(t)):t:"|"===r?t:r===s||r===u?O(e)?(t+=r,e.next(),n(t)):v(e)?t:(t+=r,e.next(),n(t)):(t+=r,e.next(),n(t)):t};return n("")}(e));if("%"===r)return e.next(),y(n,4,"%")}return t}return{nextToken:function(){const{currentType:e,offset:n,startLoc:t,endLoc:c}=k;return k.lastType=e,k.lastOffset=n,k.lastStartLoc=t,k.lastEndLoc=c,k.offset=i(),k.startLoc=a(),r.currentChar()===l?y(k,14):M(r,k)},currentOffset:i,currentPosition:a,context:h}}const p="parser",k=/(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;function h(e,n,t){switch(e){case"\\\\":return"\\";case"\\'":return"'";default:{const e=parseInt(n||t,16);return e<=55295||e>=57344?String.fromCodePoint(e):"�"}}}function x(e={}){const n=!1!==e.location,{onError:t}=e;function r(e,t,r){const c={type:e,start:t,end:t};return n&&(c.loc={start:r,end:r}),c}function c(e,t,r,c){e.end=t,c&&(e.type=c),n&&e.loc&&(e.loc.end=r)}function o(e,n){const t=e.context(),o=r(3,t.offset,t.startLoc);return o.value=n,c(o,e.currentOffset(),e.currentPosition()),o}function s(e,n){const t=e.context(),{lastOffset:o,lastStartLoc:s}=t,u=r(5,o,s);return u.index=parseInt(n,10),e.nextToken(),c(u,e.currentOffset(),e.currentPosition()),u}function u(e,n){const t=e.context(),{lastOffset:o,lastStartLoc:s}=t,u=r(4,o,s);return u.key=n,e.nextToken(),c(u,e.currentOffset(),e.currentPosition()),u}function i(e,n){const t=e.context(),{lastOffset:o,lastStartLoc:s}=t,u=r(9,o,s);return u.value=n.replace(k,h),e.nextToken(),c(u,e.currentOffset(),e.currentPosition()),u}function a(e){const n=e.context(),t=r(6,n.offset,n.startLoc);let o=e.nextToken();if(9===o.type){const n=function(e){const n=e.nextToken(),t=e.context(),{lastOffset:o,lastStartLoc:s}=t,u=r(8,o,s);return 12!==n.type?(u.value="",c(u,o,s),{nextConsumeToken:n,node:u}):(u.value=n.value||"",c(u,e.currentOffset(),e.currentPosition()),{node:u})}(e);t.modifier=n.node,o=n.nextConsumeToken||e.nextToken()}switch(o=e.nextToken(),2===o.type&&(o=e.nextToken()),o.type){case 11:t.key=function(e,n){const t=e.context(),o=r(7,t.offset,t.startLoc);return o.value=n,c(o,e.currentOffset(),e.currentPosition()),o}(e,o.value||"");break;case 5:t.key=u(e,o.value||"");break;case 6:t.key=s(e,o.value||"");break;case 7:t.key=i(e,o.value||"");break;default:const n=e.context(),a=r(7,n.offset,n.startLoc);return a.value="",c(a,n.offset,n.startLoc),t.key=a,c(t,n.offset,n.startLoc),{nextConsumeToken:o,node:t}}return c(t,e.currentOffset(),e.currentPosition()),{node:t}}function f(e){const n=e.context(),t=r(2,1===n.currentType?e.currentOffset():n.offset,1===n.currentType?n.endLoc:n.startLoc);t.items=[];let f=null;do{const n=f||e.nextToken();switch(f=null,n.type){case 0:t.items.push(o(e,n.value||""));break;case 6:t.items.push(s(e,n.value||""));break;case 5:t.items.push(u(e,n.value||""));break;case 7:t.items.push(i(e,n.value||""));break;case 8:const r=a(e);t.items.push(r.node),f=r.nextConsumeToken||null}}while(14!==n.currentType&&1!==n.currentType);return c(t,1===n.currentType?n.lastOffset:e.currentOffset(),1===n.currentType?n.lastEndLoc:e.currentPosition()),t}function l(e){const n=e.context(),{offset:t,startLoc:o}=n,s=f(e);return 14===n.currentType?s:function(e,n,t,o){const s=e.context();let u=0===o.items.length;const i=r(1,n,t);i.cases=[],i.cases.push(o);do{const n=f(e);u||(u=0===n.items.length),i.cases.push(n)}while(14!==s.currentType);return c(i,e.currentOffset(),e.currentPosition()),i}(e,t,o,s)}return{parse:function(t){const o=d(t,{...e}),s=o.context(),u=r(0,s.offset,s.startLoc);return n&&u.loc&&(u.loc.source=t),u.body=l(o),c(u,o.currentOffset(),o.currentPosition()),u}}}function y(e,n){for(let t=0;t<e.length;t++)m(e[t],n)}function m(e,n){switch(e.type){case 1:y(e.cases,n),n.helper("plural");break;case 2:y(e.items,n);break;case 6:m(e.key,n),n.helper("linked");break;case 5:n.helper("interpolate"),n.helper("list");break;case 4:n.helper("interpolate"),n.helper("named")}}function b(e,n={}){const t=function(e,n={}){const t={ast:e,helpers:new Set};return{context:()=>t,helper:e=>(t.helpers.add(e),e)}}(e);t.helper("normalize"),e.body&&m(e.body,t);const r=t.context();e.helpers=[...r.helpers]}function L(e,n){const{helper:t}=e;switch(n.type){case 0:!function(e,n){n.body?L(e,n.body):e.push("null")}(e,n);break;case 1:!function(e,n){const{helper:t,needIndent:r}=e;if(n.cases.length>1){e.push(`${t("plural")}([`),e.indent(r());const c=n.cases.length;for(let t=0;t<c&&(L(e,n.cases[t]),t!==c-1);t++)e.push(", ");e.deindent(r()),e.push("])")}}(e,n);break;case 2:!function(e,n){const{helper:t,needIndent:r}=e;e.push(`${t("normalize")}([`),e.indent(r());const c=n.items.length;for(let t=0;t<c&&(L(e,n.items[t]),t!==c-1);t++)e.push(", ");e.deindent(r()),e.push("])")}(e,n);break;case 6:!function(e,n){const{helper:t}=e;e.push(`${t("linked")}(`),L(e,n.key),n.modifier&&(e.push(", "),L(e,n.modifier)),e.push(")")}(e,n);break;case 8:case 7:e.push(JSON.stringify(n.value),n);break;case 5:e.push(`${t("interpolate")}(${t("list")}(${n.index}))`,n);break;case 4:e.push(`${t("interpolate")}(${t("named")}(${JSON.stringify(n.key)}))`,n);break;case 9:case 3:e.push(JSON.stringify(n.value),n)}}return e.ERROR_DOMAIN=p,e.LocationStub={start:{line:1,column:1,offset:0},end:{line:1,column:1,offset:0}},e.baseCompile=function(e,t={}){const r=x({...t}).parse(e);return b(r,{...t}),((e,t={})=>{const r=n(t.mode)?t.mode:"normal",c=n(t.filename)?t.filename:"message.intl",o=t.needIndent?t.needIndent:"arrow"!==r,s=e.helpers||[],u=function(e,n){const{filename:t,breakLineCode:r,needIndent:c}=n,o={source:e.loc.source,filename:t,code:"",column:1,line:1,offset:0,map:void 0,breakLineCode:r,needIndent:c,indentLevel:0};function s(e,n){o.code+=e}function u(e,n=!0){const t=n?r:"";s(c?t+" ".repeat(e):t)}return{context:()=>o,push:s,indent:function(e=!0){const n=++o.indentLevel;e&&u(n)},deindent:function(e=!0){const n=--o.indentLevel;e&&u(n)},newline:function(){u(o.indentLevel)},helper:e=>`_${e}`,needIndent:()=>o.needIndent}}(e,{mode:r,filename:c,sourceMap:!!t.sourceMap,breakLineCode:null!=t.breakLineCode?t.breakLineCode:"arrow"===r?";":"\n",needIndent:o});u.push("normal"===r?"function __msg__ (ctx) {":"(ctx) => {"),u.indent(o),s.length>0&&(u.push(`const { ${s.map((e=>`${e}: _${e}`)).join(", ")} } = ctx`),u.newline()),u.push("return "),L(u,e),u.deindent(o),u.push("}");const{code:i,map:a}=u.context();return{ast:e,code:i,map:a?a.toJSON():void 0}})(r,{...t})},e.createCompileError=r,e.createLocation=o,e.createParser=x,e.createPosition=c,e.defaultOnError=function(e){throw e},e.errorMessages=t,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); |
{ | ||
"name": "@intlify/message-compiler", | ||
"version": "9.0.0-beta.14", | ||
"version": "9.0.0-beta.15", | ||
"description": "@intlify/message-compiler", | ||
@@ -33,4 +33,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@intlify/message-resolver": "9.0.0-beta.14", | ||
"@intlify/shared": "9.0.0-beta.14", | ||
"@intlify/message-resolver": "9.0.0-beta.15", | ||
"@intlify/shared": "9.0.0-beta.15", | ||
"source-map": "0.6.1" | ||
@@ -37,0 +37,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
283821
6989
+ Added@intlify/message-resolver@9.0.0-beta.15(transitive)
+ Added@intlify/shared@9.0.0-beta.15(transitive)
- Removed@intlify/message-resolver@9.0.0-beta.14(transitive)
- Removed@intlify/shared@9.0.0-beta.14(transitive)