Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@intlify/message-compiler

Package Overview
Dependencies
Maintainers
2
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@intlify/message-compiler - npm Package Compare versions

Comparing version 9.3.0-beta.10 to 9.3.0-beta.11

296

dist/message-compiler.esm-browser.js
/*!
* message-compiler v9.3.0-beta.10
* message-compiler v9.3.0-beta.11
* (c) 2022 kazuya kawaguchi

@@ -25,4 +25,4 @@ * Released under the MIT License.

const isString = (val) => typeof val === 'string';
const isObject = (val) => // eslint-disable-line
val !== null && typeof val === 'object';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isObject = (val) => val !== null && typeof val === 'object';

@@ -189,7 +189,7 @@ const CompileErrorCodes = {

const _context = {
currentType: 14 /* EOF */,
currentType: 14 /* TokenTypes.EOF */,
offset: _initOffset,
startLoc: _initLoc,
endLoc: _initLoc,
lastType: 14 /* EOF */,
lastType: 14 /* TokenTypes.EOF */,
lastOffset: _initOffset,

@@ -229,3 +229,3 @@ lastStartLoc: _initLoc,

}
const getEndToken = (context) => getToken(context, 14 /* EOF */);
const getEndToken = (context) => getToken(context, 14 /* TokenTypes.EOF */);
function eat(scnr, ch) {

@@ -273,3 +273,3 @@ if (scnr.currentChar() === ch) {

const { currentType } = context;
if (currentType !== 2 /* BraceLeft */) {
if (currentType !== 2 /* TokenTypes.BraceLeft */) {
return false;

@@ -284,3 +284,3 @@ }

const { currentType } = context;
if (currentType !== 2 /* BraceLeft */) {
if (currentType !== 2 /* TokenTypes.BraceLeft */) {
return false;

@@ -296,3 +296,3 @@ }

const { currentType } = context;
if (currentType !== 2 /* BraceLeft */) {
if (currentType !== 2 /* TokenTypes.BraceLeft */) {
return false;

@@ -307,7 +307,7 @@ }

const { currentType } = context;
if (currentType !== 8 /* LinkedAlias */) {
if (currentType !== 8 /* TokenTypes.LinkedAlias */) {
return false;
}
peekSpaces(scnr);
const ret = scnr.currentPeek() === "." /* LinkedDot */;
const ret = scnr.currentPeek() === "." /* TokenChars.LinkedDot */;
scnr.resetPeek();

@@ -318,3 +318,3 @@ return ret;

const { currentType } = context;
if (currentType !== 9 /* LinkedDot */) {
if (currentType !== 9 /* TokenTypes.LinkedDot */) {
return false;

@@ -329,8 +329,8 @@ }

const { currentType } = context;
if (!(currentType === 8 /* LinkedAlias */ ||
currentType === 12 /* LinkedModifier */)) {
if (!(currentType === 8 /* TokenTypes.LinkedAlias */ ||
currentType === 12 /* TokenTypes.LinkedModifier */)) {
return false;
}
peekSpaces(scnr);
const ret = scnr.currentPeek() === ":" /* LinkedDelimiter */;
const ret = scnr.currentPeek() === ":" /* TokenChars.LinkedDelimiter */;
scnr.resetPeek();

@@ -341,3 +341,3 @@ return ret;

const { currentType } = context;
if (currentType !== 10 /* LinkedDelimiter */) {
if (currentType !== 10 /* TokenTypes.LinkedDelimiter */) {
return false;

@@ -347,10 +347,10 @@ }

const ch = scnr.currentPeek();
if (ch === "{" /* BraceLeft */) {
if (ch === "{" /* TokenChars.BraceLeft */) {
return isIdentifierStart(scnr.peek());
}
else if (ch === "@" /* LinkedAlias */ ||
ch === "%" /* Modulo */ ||
ch === "|" /* Pipe */ ||
ch === ":" /* LinkedDelimiter */ ||
ch === "." /* LinkedDot */ ||
else if (ch === "@" /* TokenChars.LinkedAlias */ ||
ch === "%" /* TokenChars.Modulo */ ||
ch === "|" /* TokenChars.Pipe */ ||
ch === ":" /* TokenChars.LinkedDelimiter */ ||
ch === "." /* TokenChars.LinkedDot */ ||
ch === CHAR_SP ||

@@ -375,3 +375,3 @@ !ch) {

peekSpaces(scnr);
const ret = scnr.currentPeek() === "|" /* Pipe */;
const ret = scnr.currentPeek() === "|" /* TokenChars.Pipe */;
scnr.resetPeek();

@@ -382,4 +382,4 @@ return ret;

const spaces = peekSpaces(scnr);
const ret = scnr.currentPeek() === "%" /* Modulo */ &&
scnr.peek() === "{" /* BraceLeft */;
const ret = scnr.currentPeek() === "%" /* TokenChars.Modulo */ &&
scnr.peek() === "{" /* TokenChars.BraceLeft */;
scnr.resetPeek();

@@ -394,14 +394,14 @@ return {

const ch = scnr.currentPeek();
if (ch === "{" /* BraceLeft */) {
return prev === "%" /* Modulo */ ? false : hasSpace;
if (ch === "{" /* TokenChars.BraceLeft */) {
return prev === "%" /* TokenChars.Modulo */ ? false : hasSpace;
}
else if (ch === "@" /* LinkedAlias */ || !ch) {
return prev === "%" /* Modulo */ ? true : hasSpace;
else if (ch === "@" /* TokenChars.LinkedAlias */ || !ch) {
return prev === "%" /* TokenChars.Modulo */ ? true : hasSpace;
}
else if (ch === "%" /* Modulo */) {
else if (ch === "%" /* TokenChars.Modulo */) {
scnr.peek();
return fn(hasSpace, "%" /* Modulo */, true);
return fn(hasSpace, "%" /* TokenChars.Modulo */, true);
}
else if (ch === "|" /* Pipe */) {
return prev === "%" /* Modulo */ || detectModulo
else if (ch === "|" /* TokenChars.Pipe */) {
return prev === "%" /* TokenChars.Modulo */ || detectModulo
? true

@@ -476,7 +476,7 @@ : !(prev === CHAR_SP || prev === CHAR_LF);

const ch = scnr.currentChar();
if (ch !== "%" /* Modulo */) {
if (ch !== "%" /* TokenChars.Modulo */) {
emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
}
scnr.next();
return "%" /* Modulo */;
return "%" /* TokenChars.Modulo */;
}

@@ -487,10 +487,10 @@ function readText(scnr) {

const ch = scnr.currentChar();
if (ch === "{" /* BraceLeft */ ||
ch === "}" /* BraceRight */ ||
ch === "@" /* LinkedAlias */ ||
ch === "|" /* Pipe */ ||
if (ch === "{" /* TokenChars.BraceLeft */ ||
ch === "}" /* TokenChars.BraceRight */ ||
ch === "@" /* TokenChars.LinkedAlias */ ||
ch === "|" /* TokenChars.Pipe */ ||
!ch) {
break;
}
else if (ch === "%" /* Modulo */) {
else if (ch === "%" /* TokenChars.Modulo */) {
if (isTextStart(scnr)) {

@@ -611,4 +611,4 @@ buf += ch;

let identifiers = '';
const closure = (ch) => ch !== "{" /* BraceLeft */ &&
ch !== "}" /* BraceRight */ &&
const closure = (ch) => ch !== "{" /* TokenChars.BraceLeft */ &&
ch !== "}" /* TokenChars.BraceRight */ &&
ch !== CHAR_SP &&

@@ -632,6 +632,6 @@ ch !== CHAR_LF;

const ch = scnr.currentChar();
if (ch === "{" /* BraceLeft */ ||
ch === "%" /* Modulo */ ||
ch === "@" /* LinkedAlias */ ||
ch === "|" /* Pipe */ ||
if (ch === "{" /* TokenChars.BraceLeft */ ||
ch === "%" /* TokenChars.Modulo */ ||
ch === "@" /* TokenChars.LinkedAlias */ ||
ch === "|" /* TokenChars.Pipe */ ||
!ch) {

@@ -658,3 +658,3 @@ return buf;

skipSpaces(scnr);
const plural = eat(scnr, "|" /* Pipe */);
const plural = eat(scnr, "|" /* TokenChars.Pipe */);
skipSpaces(scnr);

@@ -668,3 +668,3 @@ return plural;

switch (ch) {
case "{" /* BraceLeft */:
case "{" /* TokenChars.BraceLeft */:
if (context.braceNest >= 1) {

@@ -674,13 +674,13 @@ emitError(CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER, currentPosition(), 0);

scnr.next();
token = getToken(context, 2 /* BraceLeft */, "{" /* BraceLeft */);
token = getToken(context, 2 /* TokenTypes.BraceLeft */, "{" /* TokenChars.BraceLeft */);
skipSpaces(scnr);
context.braceNest++;
return token;
case "}" /* BraceRight */:
case "}" /* TokenChars.BraceRight */:
if (context.braceNest > 0 &&
context.currentType === 2 /* BraceLeft */) {
context.currentType === 2 /* TokenTypes.BraceLeft */) {
emitError(CompileErrorCodes.EMPTY_PLACEHOLDER, currentPosition(), 0);
}
scnr.next();
token = getToken(context, 3 /* BraceRight */, "}" /* BraceRight */);
token = getToken(context, 3 /* TokenTypes.BraceRight */, "}" /* TokenChars.BraceRight */);
context.braceNest--;

@@ -692,3 +692,3 @@ context.braceNest > 0 && skipSpaces(scnr);

return token;
case "@" /* LinkedAlias */:
case "@" /* TokenChars.LinkedAlias */:
if (context.braceNest > 0) {

@@ -708,3 +708,3 @@ emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);

}
token = getToken(context, 1 /* Pipe */, readPlural(scnr));
token = getToken(context, 1 /* TokenTypes.Pipe */, readPlural(scnr));
// reset

@@ -716,5 +716,5 @@ context.braceNest = 0;

if (context.braceNest > 0 &&
(context.currentType === 5 /* Named */ ||
context.currentType === 6 /* List */ ||
context.currentType === 7 /* Literal */)) {
(context.currentType === 5 /* TokenTypes.Named */ ||
context.currentType === 6 /* TokenTypes.List */ ||
context.currentType === 7 /* TokenTypes.Literal */)) {
emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);

@@ -725,3 +725,3 @@ context.braceNest = 0;

if ((validNamedIdentifier = isNamedIdentifierStart(scnr, context))) {
token = getToken(context, 5 /* Named */, readNamedIdentifier(scnr));
token = getToken(context, 5 /* TokenTypes.Named */, readNamedIdentifier(scnr));
skipSpaces(scnr);

@@ -731,3 +731,3 @@ return token;

if ((validListIdentifier = isListIdentifierStart(scnr, context))) {
token = getToken(context, 6 /* List */, readListIdentifier(scnr));
token = getToken(context, 6 /* TokenTypes.List */, readListIdentifier(scnr));
skipSpaces(scnr);

@@ -737,3 +737,3 @@ return token;

if ((validLiteral = isLiteralStart(scnr, context))) {
token = getToken(context, 7 /* Literal */, readLiteral(scnr));
token = getToken(context, 7 /* TokenTypes.Literal */, readLiteral(scnr));
skipSpaces(scnr);

@@ -744,3 +744,3 @@ return token;

// TODO: we should be re-designed invalid cases, when we will extend message syntax near the future ...
token = getToken(context, 13 /* InvalidPlace */, readInvalidIdentifier(scnr));
token = getToken(context, 13 /* TokenTypes.InvalidPlace */, readInvalidIdentifier(scnr));
emitError(CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER, currentPosition(), 0, token.value);

@@ -759,6 +759,6 @@ skipSpaces(scnr);

const ch = scnr.currentChar();
if ((currentType === 8 /* LinkedAlias */ ||
currentType === 9 /* LinkedDot */ ||
currentType === 12 /* LinkedModifier */ ||
currentType === 10 /* LinkedDelimiter */) &&
if ((currentType === 8 /* TokenTypes.LinkedAlias */ ||
currentType === 9 /* TokenTypes.LinkedDot */ ||
currentType === 12 /* TokenTypes.LinkedModifier */ ||
currentType === 10 /* TokenTypes.LinkedDelimiter */) &&
(ch === CHAR_LF || ch === CHAR_SP)) {

@@ -768,18 +768,18 @@ emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);

switch (ch) {
case "@" /* LinkedAlias */:
case "@" /* TokenChars.LinkedAlias */:
scnr.next();
token = getToken(context, 8 /* LinkedAlias */, "@" /* LinkedAlias */);
token = getToken(context, 8 /* TokenTypes.LinkedAlias */, "@" /* TokenChars.LinkedAlias */);
context.inLinked = true;
return token;
case "." /* LinkedDot */:
case "." /* TokenChars.LinkedDot */:
skipSpaces(scnr);
scnr.next();
return getToken(context, 9 /* LinkedDot */, "." /* LinkedDot */);
case ":" /* LinkedDelimiter */:
return getToken(context, 9 /* TokenTypes.LinkedDot */, "." /* TokenChars.LinkedDot */);
case ":" /* TokenChars.LinkedDelimiter */:
skipSpaces(scnr);
scnr.next();
return getToken(context, 10 /* LinkedDelimiter */, ":" /* LinkedDelimiter */);
return getToken(context, 10 /* TokenTypes.LinkedDelimiter */, ":" /* TokenChars.LinkedDelimiter */);
default:
if (isPluralStart(scnr)) {
token = getToken(context, 1 /* Pipe */, readPlural(scnr));
token = getToken(context, 1 /* TokenTypes.Pipe */, readPlural(scnr));
// reset

@@ -797,7 +797,7 @@ context.braceNest = 0;

skipSpaces(scnr);
return getToken(context, 12 /* LinkedModifier */, readLinkedModifier(scnr));
return getToken(context, 12 /* TokenTypes.LinkedModifier */, readLinkedModifier(scnr));
}
if (isLinkedReferStart(scnr, context)) {
skipSpaces(scnr);
if (ch === "{" /* BraceLeft */) {
if (ch === "{" /* TokenChars.BraceLeft */) {
// scan the placeholder

@@ -807,6 +807,6 @@ return readTokenInPlaceholder(scnr, context) || token;

else {
return getToken(context, 11 /* LinkedKey */, readLinkedRefer(scnr));
return getToken(context, 11 /* TokenTypes.LinkedKey */, readLinkedRefer(scnr));
}
}
if (currentType === 8 /* LinkedAlias */) {
if (currentType === 8 /* TokenTypes.LinkedAlias */) {
emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);

@@ -821,3 +821,3 @@ }

function readToken(scnr, context) {
let token = { type: 14 /* EOF */ };
let token = { type: 14 /* TokenTypes.EOF */ };
if (context.braceNest > 0) {

@@ -831,13 +831,13 @@ return readTokenInPlaceholder(scnr, context) || getEndToken(context);

switch (ch) {
case "{" /* BraceLeft */:
case "{" /* TokenChars.BraceLeft */:
return readTokenInPlaceholder(scnr, context) || getEndToken(context);
case "}" /* BraceRight */:
case "}" /* TokenChars.BraceRight */:
emitError(CompileErrorCodes.UNBALANCED_CLOSING_BRACE, currentPosition(), 0);
scnr.next();
return getToken(context, 3 /* BraceRight */, "}" /* BraceRight */);
case "@" /* LinkedAlias */:
return getToken(context, 3 /* TokenTypes.BraceRight */, "}" /* TokenChars.BraceRight */);
case "@" /* TokenChars.LinkedAlias */:
return readTokenInLinked(scnr, context) || getEndToken(context);
default:
if (isPluralStart(scnr)) {
token = getToken(context, 1 /* Pipe */, readPlural(scnr));
token = getToken(context, 1 /* TokenTypes.Pipe */, readPlural(scnr));
// reset

@@ -851,7 +851,7 @@ context.braceNest = 0;

return hasSpace
? getToken(context, 0 /* Text */, readText(scnr))
: getToken(context, 4 /* Modulo */, readModulo(scnr));
? getToken(context, 0 /* TokenTypes.Text */, readText(scnr))
: getToken(context, 4 /* TokenTypes.Modulo */, readModulo(scnr));
}
if (isTextStart(scnr)) {
return getToken(context, 0 /* Text */, readText(scnr));
return getToken(context, 0 /* TokenTypes.Text */, readText(scnr));
}

@@ -871,3 +871,3 @@ break;

if (_scnr.currentChar() === EOF) {
return getToken(_context, 14 /* EOF */);
return getToken(_context, 14 /* TokenTypes.EOF */);
}

@@ -942,3 +942,3 @@ return readToken(_scnr, _context);

const context = tokenizer.context();
const node = startNode(3 /* Text */, context.offset, context.startLoc);
const node = startNode(3 /* NodeTypes.Text */, context.offset, context.startLoc);
node.value = value;

@@ -951,3 +951,3 @@ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());

const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
const node = startNode(5 /* List */, offset, loc);
const node = startNode(5 /* NodeTypes.List */, offset, loc);
node.index = parseInt(index, 10);

@@ -961,3 +961,3 @@ tokenizer.nextToken(); // skip brach right

const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
const node = startNode(4 /* Named */, offset, loc);
const node = startNode(4 /* NodeTypes.Named */, offset, loc);
node.key = key;

@@ -971,3 +971,3 @@ tokenizer.nextToken(); // skip brach right

const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
const node = startNode(9 /* Literal */, offset, loc);
const node = startNode(9 /* NodeTypes.Literal */, offset, loc);
node.value = value.replace(KNOWN_ESCAPES, fromEscapeSequence);

@@ -982,4 +982,4 @@ tokenizer.nextToken(); // skip brach right

const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc
const node = startNode(8 /* LinkedModifier */, offset, loc);
if (token.type !== 12 /* LinkedModifier */) {
const node = startNode(8 /* NodeTypes.LinkedModifier */, offset, loc);
if (token.type !== 12 /* TokenTypes.LinkedModifier */) {
// empty modifier

@@ -1006,3 +1006,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER, context.lastStartLoc, 0);

const context = tokenizer.context();
const node = startNode(7 /* LinkedKey */, context.offset, context.startLoc);
const node = startNode(7 /* NodeTypes.LinkedKey */, context.offset, context.startLoc);
node.value = value;

@@ -1014,5 +1014,5 @@ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());

const context = tokenizer.context();
const linkedNode = startNode(6 /* Linked */, context.offset, context.startLoc);
const linkedNode = startNode(6 /* NodeTypes.Linked */, context.offset, context.startLoc);
let token = tokenizer.nextToken();
if (token.type === 9 /* LinkedDot */) {
if (token.type === 9 /* TokenTypes.LinkedDot */) {
const parsed = parseLinkedModifier(tokenizer);

@@ -1023,3 +1023,3 @@ linkedNode.modifier = parsed.node;

// asset check token
if (token.type !== 10 /* LinkedDelimiter */) {
if (token.type !== 10 /* TokenTypes.LinkedDelimiter */) {
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

@@ -1029,7 +1029,7 @@ }

// skip brace left
if (token.type === 2 /* BraceLeft */) {
if (token.type === 2 /* TokenTypes.BraceLeft */) {
token = tokenizer.nextToken();
}
switch (token.type) {
case 11 /* LinkedKey */:
case 11 /* TokenTypes.LinkedKey */:
if (token.value == null) {

@@ -1040,3 +1040,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

break;
case 5 /* Named */:
case 5 /* TokenTypes.Named */:
if (token.value == null) {

@@ -1047,3 +1047,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

break;
case 6 /* List */:
case 6 /* TokenTypes.List */:
if (token.value == null) {

@@ -1054,3 +1054,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

break;
case 7 /* Literal */:
case 7 /* TokenTypes.Literal */:
if (token.value == null) {

@@ -1065,3 +1065,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

const nextContext = tokenizer.context();
const emptyLinkedKeyNode = startNode(7 /* LinkedKey */, nextContext.offset, nextContext.startLoc);
const emptyLinkedKeyNode = startNode(7 /* NodeTypes.LinkedKey */, nextContext.offset, nextContext.startLoc);
emptyLinkedKeyNode.value = '';

@@ -1083,9 +1083,9 @@ endNode(emptyLinkedKeyNode, nextContext.offset, nextContext.startLoc);

const context = tokenizer.context();
const startOffset = context.currentType === 1 /* Pipe */
const startOffset = context.currentType === 1 /* TokenTypes.Pipe */
? tokenizer.currentOffset()
: context.offset;
const startLoc = context.currentType === 1 /* Pipe */
const startLoc = context.currentType === 1 /* TokenTypes.Pipe */
? context.endLoc
: context.startLoc;
const node = startNode(2 /* Message */, startOffset, startLoc);
const node = startNode(2 /* NodeTypes.Message */, startOffset, startLoc);
node.items = [];

@@ -1097,3 +1097,3 @@ let nextToken = null;

switch (token.type) {
case 0 /* Text */:
case 0 /* TokenTypes.Text */:
if (token.value == null) {

@@ -1104,3 +1104,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

break;
case 6 /* List */:
case 6 /* TokenTypes.List */:
if (token.value == null) {

@@ -1111,3 +1111,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

break;
case 5 /* Named */:
case 5 /* TokenTypes.Named */:
if (token.value == null) {

@@ -1118,3 +1118,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

break;
case 7 /* Literal */:
case 7 /* TokenTypes.Literal */:
if (token.value == null) {

@@ -1125,3 +1125,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

break;
case 8 /* LinkedAlias */:
case 8 /* TokenTypes.LinkedAlias */:
const parsed = parseLinked(tokenizer);

@@ -1132,9 +1132,9 @@ node.items.push(parsed.node);

}
} while (context.currentType !== 14 /* EOF */ &&
context.currentType !== 1 /* Pipe */);
} while (context.currentType !== 14 /* TokenTypes.EOF */ &&
context.currentType !== 1 /* TokenTypes.Pipe */);
// adjust message node loc
const endOffset = context.currentType === 1 /* Pipe */
const endOffset = context.currentType === 1 /* TokenTypes.Pipe */
? context.lastOffset
: tokenizer.currentOffset();
const endLoc = context.currentType === 1 /* Pipe */
const endLoc = context.currentType === 1 /* TokenTypes.Pipe */
? context.lastEndLoc

@@ -1148,3 +1148,3 @@ : tokenizer.currentPosition();

let hasEmptyMessage = msgNode.items.length === 0;
const node = startNode(1 /* Plural */, offset, loc);
const node = startNode(1 /* NodeTypes.Plural */, offset, loc);
node.cases = [];

@@ -1158,3 +1158,3 @@ node.cases.push(msgNode);

node.cases.push(msg);
} while (context.currentType !== 14 /* EOF */);
} while (context.currentType !== 14 /* TokenTypes.EOF */);
if (hasEmptyMessage) {

@@ -1170,3 +1170,3 @@ emitError(tokenizer, CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL, loc, 0);

const msgNode = parseMessage(tokenizer);
if (context.currentType === 14 /* EOF */) {
if (context.currentType === 14 /* TokenTypes.EOF */) {
return msgNode;

@@ -1181,3 +1181,3 @@ }

const context = tokenizer.context();
const node = startNode(0 /* Resource */, context.offset, context.startLoc);
const node = startNode(0 /* NodeTypes.Resource */, context.offset, context.startLoc);
if (location && node.loc) {

@@ -1188,3 +1188,3 @@ node.loc.source = source;

// assert whether achieved to EOF
if (context.currentType !== 14 /* EOF */) {
if (context.currentType !== 14 /* TokenTypes.EOF */) {
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, source[context.offset] || '');

@@ -1198,3 +1198,3 @@ }

function getTokenCaption(token) {
if (token.type === 14 /* EOF */) {
if (token.type === 14 /* TokenTypes.EOF */) {
return 'EOF';

@@ -1227,22 +1227,22 @@ }

switch (node.type) {
case 1 /* Plural */:
case 1 /* NodeTypes.Plural */:
traverseNodes(node.cases, transformer);
transformer.helper("plural" /* PLURAL */);
transformer.helper("plural" /* HelperNameMap.PLURAL */);
break;
case 2 /* Message */:
case 2 /* NodeTypes.Message */:
traverseNodes(node.items, transformer);
break;
case 6 /* Linked */:
case 6 /* NodeTypes.Linked */:
const linked = node;
traverseNode(linked.key, transformer);
transformer.helper("linked" /* LINKED */);
transformer.helper("type" /* TYPE */);
transformer.helper("linked" /* HelperNameMap.LINKED */);
transformer.helper("type" /* HelperNameMap.TYPE */);
break;
case 5 /* List */:
transformer.helper("interpolate" /* INTERPOLATE */);
transformer.helper("list" /* LIST */);
case 5 /* NodeTypes.List */:
transformer.helper("interpolate" /* HelperNameMap.INTERPOLATE */);
transformer.helper("list" /* HelperNameMap.LIST */);
break;
case 4 /* Named */:
transformer.helper("interpolate" /* INTERPOLATE */);
transformer.helper("named" /* NAMED */);
case 4 /* NodeTypes.Named */:
transformer.helper("interpolate" /* HelperNameMap.INTERPOLATE */);
transformer.helper("named" /* HelperNameMap.NAMED */);
break;

@@ -1256,3 +1256,3 @@ }

const transformer = createTransformer(ast);
transformer.helper("normalize" /* NORMALIZE */);
transformer.helper("normalize" /* HelperNameMap.NORMALIZE */);
// traverse

@@ -1312,3 +1312,3 @@ ast.body && traverseNode(ast.body, transformer);

const { helper } = generator;
generator.push(`${helper("linked" /* LINKED */)}(`);
generator.push(`${helper("linked" /* HelperNameMap.LINKED */)}(`);
generateNode(generator, node.key);

@@ -1327,3 +1327,3 @@ if (node.modifier) {

const { helper, needIndent } = generator;
generator.push(`${helper("normalize" /* NORMALIZE */)}([`);
generator.push(`${helper("normalize" /* HelperNameMap.NORMALIZE */)}([`);
generator.indent(needIndent());

@@ -1344,3 +1344,3 @@ const length = node.items.length;

if (node.cases.length > 1) {
generator.push(`${helper("plural" /* PLURAL */)}([`);
generator.push(`${helper("plural" /* HelperNameMap.PLURAL */)}([`);
generator.indent(needIndent());

@@ -1370,30 +1370,30 @@ const length = node.cases.length;

switch (node.type) {
case 0 /* Resource */:
case 0 /* NodeTypes.Resource */:
generateResource(generator, node);
break;
case 1 /* Plural */:
case 1 /* NodeTypes.Plural */:
generatePluralNode(generator, node);
break;
case 2 /* Message */:
case 2 /* NodeTypes.Message */:
generateMessageNode(generator, node);
break;
case 6 /* Linked */:
case 6 /* NodeTypes.Linked */:
generateLinkedNode(generator, node);
break;
case 8 /* LinkedModifier */:
case 8 /* NodeTypes.LinkedModifier */:
generator.push(JSON.stringify(node.value), node);
break;
case 7 /* LinkedKey */:
case 7 /* NodeTypes.LinkedKey */:
generator.push(JSON.stringify(node.value), node);
break;
case 5 /* List */:
generator.push(`${helper("interpolate" /* INTERPOLATE */)}(${helper("list" /* LIST */)}(${node.index}))`, node);
case 5 /* NodeTypes.List */:
generator.push(`${helper("interpolate" /* HelperNameMap.INTERPOLATE */)}(${helper("list" /* HelperNameMap.LIST */)}(${node.index}))`, node);
break;
case 4 /* Named */:
generator.push(`${helper("interpolate" /* INTERPOLATE */)}(${helper("named" /* NAMED */)}(${JSON.stringify(node.key)}))`, node);
case 4 /* NodeTypes.Named */:
generator.push(`${helper("interpolate" /* HelperNameMap.INTERPOLATE */)}(${helper("named" /* HelperNameMap.NAMED */)}(${JSON.stringify(node.key)}))`, node);
break;
case 9 /* Literal */:
case 9 /* NodeTypes.Literal */:
generator.push(JSON.stringify(node.value), node);
break;
case 3 /* Text */:
case 3 /* NodeTypes.Text */:
generator.push(JSON.stringify(node.value), node);

@@ -1400,0 +1400,0 @@ break;

/*!
* message-compiler v9.3.0-beta.10
* message-compiler v9.3.0-beta.11
* (c) 2022 kazuya kawaguchi

@@ -4,0 +4,0 @@ * Released under the MIT License.

/*!
* message-compiler v9.3.0-beta.10
* message-compiler v9.3.0-beta.11
* (c) 2022 kazuya kawaguchi

@@ -28,4 +28,4 @@ * Released under the MIT License.

const isString = (val) => typeof val === 'string';
const isObject = (val) => // eslint-disable-line
val !== null && typeof val === 'object';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const isObject = (val) => val !== null && typeof val === 'object';

@@ -192,7 +192,7 @@ const CompileErrorCodes = {

const _context = {
currentType: 14 /* EOF */,
currentType: 14 /* TokenTypes.EOF */,
offset: _initOffset,
startLoc: _initLoc,
endLoc: _initLoc,
lastType: 14 /* EOF */,
lastType: 14 /* TokenTypes.EOF */,
lastOffset: _initOffset,

@@ -232,3 +232,3 @@ lastStartLoc: _initLoc,

}
const getEndToken = (context) => getToken(context, 14 /* EOF */);
const getEndToken = (context) => getToken(context, 14 /* TokenTypes.EOF */);
function eat(scnr, ch) {

@@ -276,3 +276,3 @@ if (scnr.currentChar() === ch) {

const { currentType } = context;
if (currentType !== 2 /* BraceLeft */) {
if (currentType !== 2 /* TokenTypes.BraceLeft */) {
return false;

@@ -287,3 +287,3 @@ }

const { currentType } = context;
if (currentType !== 2 /* BraceLeft */) {
if (currentType !== 2 /* TokenTypes.BraceLeft */) {
return false;

@@ -299,3 +299,3 @@ }

const { currentType } = context;
if (currentType !== 2 /* BraceLeft */) {
if (currentType !== 2 /* TokenTypes.BraceLeft */) {
return false;

@@ -310,7 +310,7 @@ }

const { currentType } = context;
if (currentType !== 8 /* LinkedAlias */) {
if (currentType !== 8 /* TokenTypes.LinkedAlias */) {
return false;
}
peekSpaces(scnr);
const ret = scnr.currentPeek() === "." /* LinkedDot */;
const ret = scnr.currentPeek() === "." /* TokenChars.LinkedDot */;
scnr.resetPeek();

@@ -321,3 +321,3 @@ return ret;

const { currentType } = context;
if (currentType !== 9 /* LinkedDot */) {
if (currentType !== 9 /* TokenTypes.LinkedDot */) {
return false;

@@ -332,8 +332,8 @@ }

const { currentType } = context;
if (!(currentType === 8 /* LinkedAlias */ ||
currentType === 12 /* LinkedModifier */)) {
if (!(currentType === 8 /* TokenTypes.LinkedAlias */ ||
currentType === 12 /* TokenTypes.LinkedModifier */)) {
return false;
}
peekSpaces(scnr);
const ret = scnr.currentPeek() === ":" /* LinkedDelimiter */;
const ret = scnr.currentPeek() === ":" /* TokenChars.LinkedDelimiter */;
scnr.resetPeek();

@@ -344,3 +344,3 @@ return ret;

const { currentType } = context;
if (currentType !== 10 /* LinkedDelimiter */) {
if (currentType !== 10 /* TokenTypes.LinkedDelimiter */) {
return false;

@@ -350,10 +350,10 @@ }

const ch = scnr.currentPeek();
if (ch === "{" /* BraceLeft */) {
if (ch === "{" /* TokenChars.BraceLeft */) {
return isIdentifierStart(scnr.peek());
}
else if (ch === "@" /* LinkedAlias */ ||
ch === "%" /* Modulo */ ||
ch === "|" /* Pipe */ ||
ch === ":" /* LinkedDelimiter */ ||
ch === "." /* LinkedDot */ ||
else if (ch === "@" /* TokenChars.LinkedAlias */ ||
ch === "%" /* TokenChars.Modulo */ ||
ch === "|" /* TokenChars.Pipe */ ||
ch === ":" /* TokenChars.LinkedDelimiter */ ||
ch === "." /* TokenChars.LinkedDot */ ||
ch === CHAR_SP ||

@@ -378,3 +378,3 @@ !ch) {

peekSpaces(scnr);
const ret = scnr.currentPeek() === "|" /* Pipe */;
const ret = scnr.currentPeek() === "|" /* TokenChars.Pipe */;
scnr.resetPeek();

@@ -385,4 +385,4 @@ return ret;

const spaces = peekSpaces(scnr);
const ret = scnr.currentPeek() === "%" /* Modulo */ &&
scnr.peek() === "{" /* BraceLeft */;
const ret = scnr.currentPeek() === "%" /* TokenChars.Modulo */ &&
scnr.peek() === "{" /* TokenChars.BraceLeft */;
scnr.resetPeek();

@@ -397,14 +397,14 @@ return {

const ch = scnr.currentPeek();
if (ch === "{" /* BraceLeft */) {
return prev === "%" /* Modulo */ ? false : hasSpace;
if (ch === "{" /* TokenChars.BraceLeft */) {
return prev === "%" /* TokenChars.Modulo */ ? false : hasSpace;
}
else if (ch === "@" /* LinkedAlias */ || !ch) {
return prev === "%" /* Modulo */ ? true : hasSpace;
else if (ch === "@" /* TokenChars.LinkedAlias */ || !ch) {
return prev === "%" /* TokenChars.Modulo */ ? true : hasSpace;
}
else if (ch === "%" /* Modulo */) {
else if (ch === "%" /* TokenChars.Modulo */) {
scnr.peek();
return fn(hasSpace, "%" /* Modulo */, true);
return fn(hasSpace, "%" /* TokenChars.Modulo */, true);
}
else if (ch === "|" /* Pipe */) {
return prev === "%" /* Modulo */ || detectModulo
else if (ch === "|" /* TokenChars.Pipe */) {
return prev === "%" /* TokenChars.Modulo */ || detectModulo
? true

@@ -479,7 +479,7 @@ : !(prev === CHAR_SP || prev === CHAR_LF);

const ch = scnr.currentChar();
if (ch !== "%" /* Modulo */) {
if (ch !== "%" /* TokenChars.Modulo */) {
emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
}
scnr.next();
return "%" /* Modulo */;
return "%" /* TokenChars.Modulo */;
}

@@ -490,10 +490,10 @@ function readText(scnr) {

const ch = scnr.currentChar();
if (ch === "{" /* BraceLeft */ ||
ch === "}" /* BraceRight */ ||
ch === "@" /* LinkedAlias */ ||
ch === "|" /* Pipe */ ||
if (ch === "{" /* TokenChars.BraceLeft */ ||
ch === "}" /* TokenChars.BraceRight */ ||
ch === "@" /* TokenChars.LinkedAlias */ ||
ch === "|" /* TokenChars.Pipe */ ||
!ch) {
break;
}
else if (ch === "%" /* Modulo */) {
else if (ch === "%" /* TokenChars.Modulo */) {
if (isTextStart(scnr)) {

@@ -614,4 +614,4 @@ buf += ch;

let identifiers = '';
const closure = (ch) => ch !== "{" /* BraceLeft */ &&
ch !== "}" /* BraceRight */ &&
const closure = (ch) => ch !== "{" /* TokenChars.BraceLeft */ &&
ch !== "}" /* TokenChars.BraceRight */ &&
ch !== CHAR_SP &&

@@ -635,6 +635,6 @@ ch !== CHAR_LF;

const ch = scnr.currentChar();
if (ch === "{" /* BraceLeft */ ||
ch === "%" /* Modulo */ ||
ch === "@" /* LinkedAlias */ ||
ch === "|" /* Pipe */ ||
if (ch === "{" /* TokenChars.BraceLeft */ ||
ch === "%" /* TokenChars.Modulo */ ||
ch === "@" /* TokenChars.LinkedAlias */ ||
ch === "|" /* TokenChars.Pipe */ ||
!ch) {

@@ -661,3 +661,3 @@ return buf;

skipSpaces(scnr);
const plural = eat(scnr, "|" /* Pipe */);
const plural = eat(scnr, "|" /* TokenChars.Pipe */);
skipSpaces(scnr);

@@ -671,3 +671,3 @@ return plural;

switch (ch) {
case "{" /* BraceLeft */:
case "{" /* TokenChars.BraceLeft */:
if (context.braceNest >= 1) {

@@ -677,13 +677,13 @@ emitError(CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER, currentPosition(), 0);

scnr.next();
token = getToken(context, 2 /* BraceLeft */, "{" /* BraceLeft */);
token = getToken(context, 2 /* TokenTypes.BraceLeft */, "{" /* TokenChars.BraceLeft */);
skipSpaces(scnr);
context.braceNest++;
return token;
case "}" /* BraceRight */:
case "}" /* TokenChars.BraceRight */:
if (context.braceNest > 0 &&
context.currentType === 2 /* BraceLeft */) {
context.currentType === 2 /* TokenTypes.BraceLeft */) {
emitError(CompileErrorCodes.EMPTY_PLACEHOLDER, currentPosition(), 0);
}
scnr.next();
token = getToken(context, 3 /* BraceRight */, "}" /* BraceRight */);
token = getToken(context, 3 /* TokenTypes.BraceRight */, "}" /* TokenChars.BraceRight */);
context.braceNest--;

@@ -695,3 +695,3 @@ context.braceNest > 0 && skipSpaces(scnr);

return token;
case "@" /* LinkedAlias */:
case "@" /* TokenChars.LinkedAlias */:
if (context.braceNest > 0) {

@@ -711,3 +711,3 @@ emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);

}
token = getToken(context, 1 /* Pipe */, readPlural(scnr));
token = getToken(context, 1 /* TokenTypes.Pipe */, readPlural(scnr));
// reset

@@ -719,5 +719,5 @@ context.braceNest = 0;

if (context.braceNest > 0 &&
(context.currentType === 5 /* Named */ ||
context.currentType === 6 /* List */ ||
context.currentType === 7 /* Literal */)) {
(context.currentType === 5 /* TokenTypes.Named */ ||
context.currentType === 6 /* TokenTypes.List */ ||
context.currentType === 7 /* TokenTypes.Literal */)) {
emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);

@@ -728,3 +728,3 @@ context.braceNest = 0;

if ((validNamedIdentifier = isNamedIdentifierStart(scnr, context))) {
token = getToken(context, 5 /* Named */, readNamedIdentifier(scnr));
token = getToken(context, 5 /* TokenTypes.Named */, readNamedIdentifier(scnr));
skipSpaces(scnr);

@@ -734,3 +734,3 @@ return token;

if ((validListIdentifier = isListIdentifierStart(scnr, context))) {
token = getToken(context, 6 /* List */, readListIdentifier(scnr));
token = getToken(context, 6 /* TokenTypes.List */, readListIdentifier(scnr));
skipSpaces(scnr);

@@ -740,3 +740,3 @@ return token;

if ((validLiteral = isLiteralStart(scnr, context))) {
token = getToken(context, 7 /* Literal */, readLiteral(scnr));
token = getToken(context, 7 /* TokenTypes.Literal */, readLiteral(scnr));
skipSpaces(scnr);

@@ -747,3 +747,3 @@ return token;

// TODO: we should be re-designed invalid cases, when we will extend message syntax near the future ...
token = getToken(context, 13 /* InvalidPlace */, readInvalidIdentifier(scnr));
token = getToken(context, 13 /* TokenTypes.InvalidPlace */, readInvalidIdentifier(scnr));
emitError(CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER, currentPosition(), 0, token.value);

@@ -762,6 +762,6 @@ skipSpaces(scnr);

const ch = scnr.currentChar();
if ((currentType === 8 /* LinkedAlias */ ||
currentType === 9 /* LinkedDot */ ||
currentType === 12 /* LinkedModifier */ ||
currentType === 10 /* LinkedDelimiter */) &&
if ((currentType === 8 /* TokenTypes.LinkedAlias */ ||
currentType === 9 /* TokenTypes.LinkedDot */ ||
currentType === 12 /* TokenTypes.LinkedModifier */ ||
currentType === 10 /* TokenTypes.LinkedDelimiter */) &&
(ch === CHAR_LF || ch === CHAR_SP)) {

@@ -771,18 +771,18 @@ emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);

switch (ch) {
case "@" /* LinkedAlias */:
case "@" /* TokenChars.LinkedAlias */:
scnr.next();
token = getToken(context, 8 /* LinkedAlias */, "@" /* LinkedAlias */);
token = getToken(context, 8 /* TokenTypes.LinkedAlias */, "@" /* TokenChars.LinkedAlias */);
context.inLinked = true;
return token;
case "." /* LinkedDot */:
case "." /* TokenChars.LinkedDot */:
skipSpaces(scnr);
scnr.next();
return getToken(context, 9 /* LinkedDot */, "." /* LinkedDot */);
case ":" /* LinkedDelimiter */:
return getToken(context, 9 /* TokenTypes.LinkedDot */, "." /* TokenChars.LinkedDot */);
case ":" /* TokenChars.LinkedDelimiter */:
skipSpaces(scnr);
scnr.next();
return getToken(context, 10 /* LinkedDelimiter */, ":" /* LinkedDelimiter */);
return getToken(context, 10 /* TokenTypes.LinkedDelimiter */, ":" /* TokenChars.LinkedDelimiter */);
default:
if (isPluralStart(scnr)) {
token = getToken(context, 1 /* Pipe */, readPlural(scnr));
token = getToken(context, 1 /* TokenTypes.Pipe */, readPlural(scnr));
// reset

@@ -800,7 +800,7 @@ context.braceNest = 0;

skipSpaces(scnr);
return getToken(context, 12 /* LinkedModifier */, readLinkedModifier(scnr));
return getToken(context, 12 /* TokenTypes.LinkedModifier */, readLinkedModifier(scnr));
}
if (isLinkedReferStart(scnr, context)) {
skipSpaces(scnr);
if (ch === "{" /* BraceLeft */) {
if (ch === "{" /* TokenChars.BraceLeft */) {
// scan the placeholder

@@ -810,6 +810,6 @@ return readTokenInPlaceholder(scnr, context) || token;

else {
return getToken(context, 11 /* LinkedKey */, readLinkedRefer(scnr));
return getToken(context, 11 /* TokenTypes.LinkedKey */, readLinkedRefer(scnr));
}
}
if (currentType === 8 /* LinkedAlias */) {
if (currentType === 8 /* TokenTypes.LinkedAlias */) {
emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);

@@ -824,3 +824,3 @@ }

function readToken(scnr, context) {
let token = { type: 14 /* EOF */ };
let token = { type: 14 /* TokenTypes.EOF */ };
if (context.braceNest > 0) {

@@ -834,13 +834,13 @@ return readTokenInPlaceholder(scnr, context) || getEndToken(context);

switch (ch) {
case "{" /* BraceLeft */:
case "{" /* TokenChars.BraceLeft */:
return readTokenInPlaceholder(scnr, context) || getEndToken(context);
case "}" /* BraceRight */:
case "}" /* TokenChars.BraceRight */:
emitError(CompileErrorCodes.UNBALANCED_CLOSING_BRACE, currentPosition(), 0);
scnr.next();
return getToken(context, 3 /* BraceRight */, "}" /* BraceRight */);
case "@" /* LinkedAlias */:
return getToken(context, 3 /* TokenTypes.BraceRight */, "}" /* TokenChars.BraceRight */);
case "@" /* TokenChars.LinkedAlias */:
return readTokenInLinked(scnr, context) || getEndToken(context);
default:
if (isPluralStart(scnr)) {
token = getToken(context, 1 /* Pipe */, readPlural(scnr));
token = getToken(context, 1 /* TokenTypes.Pipe */, readPlural(scnr));
// reset

@@ -854,7 +854,7 @@ context.braceNest = 0;

return hasSpace
? getToken(context, 0 /* Text */, readText(scnr))
: getToken(context, 4 /* Modulo */, readModulo(scnr));
? getToken(context, 0 /* TokenTypes.Text */, readText(scnr))
: getToken(context, 4 /* TokenTypes.Modulo */, readModulo(scnr));
}
if (isTextStart(scnr)) {
return getToken(context, 0 /* Text */, readText(scnr));
return getToken(context, 0 /* TokenTypes.Text */, readText(scnr));
}

@@ -874,3 +874,3 @@ break;

if (_scnr.currentChar() === EOF) {
return getToken(_context, 14 /* EOF */);
return getToken(_context, 14 /* TokenTypes.EOF */);
}

@@ -945,3 +945,3 @@ return readToken(_scnr, _context);

const context = tokenizer.context();
const node = startNode(3 /* Text */, context.offset, context.startLoc);
const node = startNode(3 /* NodeTypes.Text */, context.offset, context.startLoc);
node.value = value;

@@ -954,3 +954,3 @@ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());

const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
const node = startNode(5 /* List */, offset, loc);
const node = startNode(5 /* NodeTypes.List */, offset, loc);
node.index = parseInt(index, 10);

@@ -964,3 +964,3 @@ tokenizer.nextToken(); // skip brach right

const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
const node = startNode(4 /* Named */, offset, loc);
const node = startNode(4 /* NodeTypes.Named */, offset, loc);
node.key = key;

@@ -974,3 +974,3 @@ tokenizer.nextToken(); // skip brach right

const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
const node = startNode(9 /* Literal */, offset, loc);
const node = startNode(9 /* NodeTypes.Literal */, offset, loc);
node.value = value.replace(KNOWN_ESCAPES, fromEscapeSequence);

@@ -985,4 +985,4 @@ tokenizer.nextToken(); // skip brach right

const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc
const node = startNode(8 /* LinkedModifier */, offset, loc);
if (token.type !== 12 /* LinkedModifier */) {
const node = startNode(8 /* NodeTypes.LinkedModifier */, offset, loc);
if (token.type !== 12 /* TokenTypes.LinkedModifier */) {
// empty modifier

@@ -1009,3 +1009,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER, context.lastStartLoc, 0);

const context = tokenizer.context();
const node = startNode(7 /* LinkedKey */, context.offset, context.startLoc);
const node = startNode(7 /* NodeTypes.LinkedKey */, context.offset, context.startLoc);
node.value = value;

@@ -1017,5 +1017,5 @@ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());

const context = tokenizer.context();
const linkedNode = startNode(6 /* Linked */, context.offset, context.startLoc);
const linkedNode = startNode(6 /* NodeTypes.Linked */, context.offset, context.startLoc);
let token = tokenizer.nextToken();
if (token.type === 9 /* LinkedDot */) {
if (token.type === 9 /* TokenTypes.LinkedDot */) {
const parsed = parseLinkedModifier(tokenizer);

@@ -1026,3 +1026,3 @@ linkedNode.modifier = parsed.node;

// asset check token
if (token.type !== 10 /* LinkedDelimiter */) {
if (token.type !== 10 /* TokenTypes.LinkedDelimiter */) {
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

@@ -1032,7 +1032,7 @@ }

// skip brace left
if (token.type === 2 /* BraceLeft */) {
if (token.type === 2 /* TokenTypes.BraceLeft */) {
token = tokenizer.nextToken();
}
switch (token.type) {
case 11 /* LinkedKey */:
case 11 /* TokenTypes.LinkedKey */:
if (token.value == null) {

@@ -1043,3 +1043,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

break;
case 5 /* Named */:
case 5 /* TokenTypes.Named */:
if (token.value == null) {

@@ -1050,3 +1050,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

break;
case 6 /* List */:
case 6 /* TokenTypes.List */:
if (token.value == null) {

@@ -1057,3 +1057,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

break;
case 7 /* Literal */:
case 7 /* TokenTypes.Literal */:
if (token.value == null) {

@@ -1068,3 +1068,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

const nextContext = tokenizer.context();
const emptyLinkedKeyNode = startNode(7 /* LinkedKey */, nextContext.offset, nextContext.startLoc);
const emptyLinkedKeyNode = startNode(7 /* NodeTypes.LinkedKey */, nextContext.offset, nextContext.startLoc);
emptyLinkedKeyNode.value = '';

@@ -1086,9 +1086,9 @@ endNode(emptyLinkedKeyNode, nextContext.offset, nextContext.startLoc);

const context = tokenizer.context();
const startOffset = context.currentType === 1 /* Pipe */
const startOffset = context.currentType === 1 /* TokenTypes.Pipe */
? tokenizer.currentOffset()
: context.offset;
const startLoc = context.currentType === 1 /* Pipe */
const startLoc = context.currentType === 1 /* TokenTypes.Pipe */
? context.endLoc
: context.startLoc;
const node = startNode(2 /* Message */, startOffset, startLoc);
const node = startNode(2 /* NodeTypes.Message */, startOffset, startLoc);
node.items = [];

@@ -1100,3 +1100,3 @@ let nextToken = null;

switch (token.type) {
case 0 /* Text */:
case 0 /* TokenTypes.Text */:
if (token.value == null) {

@@ -1107,3 +1107,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

break;
case 6 /* List */:
case 6 /* TokenTypes.List */:
if (token.value == null) {

@@ -1114,3 +1114,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

break;
case 5 /* Named */:
case 5 /* TokenTypes.Named */:
if (token.value == null) {

@@ -1121,3 +1121,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

break;
case 7 /* Literal */:
case 7 /* TokenTypes.Literal */:
if (token.value == null) {

@@ -1128,3 +1128,3 @@ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));

break;
case 8 /* LinkedAlias */:
case 8 /* TokenTypes.LinkedAlias */:
const parsed = parseLinked(tokenizer);

@@ -1135,9 +1135,9 @@ node.items.push(parsed.node);

}
} while (context.currentType !== 14 /* EOF */ &&
context.currentType !== 1 /* Pipe */);
} while (context.currentType !== 14 /* TokenTypes.EOF */ &&
context.currentType !== 1 /* TokenTypes.Pipe */);
// adjust message node loc
const endOffset = context.currentType === 1 /* Pipe */
const endOffset = context.currentType === 1 /* TokenTypes.Pipe */
? context.lastOffset
: tokenizer.currentOffset();
const endLoc = context.currentType === 1 /* Pipe */
const endLoc = context.currentType === 1 /* TokenTypes.Pipe */
? context.lastEndLoc

@@ -1151,3 +1151,3 @@ : tokenizer.currentPosition();

let hasEmptyMessage = msgNode.items.length === 0;
const node = startNode(1 /* Plural */, offset, loc);
const node = startNode(1 /* NodeTypes.Plural */, offset, loc);
node.cases = [];

@@ -1161,3 +1161,3 @@ node.cases.push(msgNode);

node.cases.push(msg);
} while (context.currentType !== 14 /* EOF */);
} while (context.currentType !== 14 /* TokenTypes.EOF */);
if (hasEmptyMessage) {

@@ -1173,3 +1173,3 @@ emitError(tokenizer, CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL, loc, 0);

const msgNode = parseMessage(tokenizer);
if (context.currentType === 14 /* EOF */) {
if (context.currentType === 14 /* TokenTypes.EOF */) {
return msgNode;

@@ -1184,3 +1184,3 @@ }

const context = tokenizer.context();
const node = startNode(0 /* Resource */, context.offset, context.startLoc);
const node = startNode(0 /* NodeTypes.Resource */, context.offset, context.startLoc);
if (location && node.loc) {

@@ -1191,3 +1191,3 @@ node.loc.source = source;

// assert whether achieved to EOF
if (context.currentType !== 14 /* EOF */) {
if (context.currentType !== 14 /* TokenTypes.EOF */) {
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, source[context.offset] || '');

@@ -1201,3 +1201,3 @@ }

function getTokenCaption(token) {
if (token.type === 14 /* EOF */) {
if (token.type === 14 /* TokenTypes.EOF */) {
return 'EOF';

@@ -1230,22 +1230,22 @@ }

switch (node.type) {
case 1 /* Plural */:
case 1 /* NodeTypes.Plural */:
traverseNodes(node.cases, transformer);
transformer.helper("plural" /* PLURAL */);
transformer.helper("plural" /* HelperNameMap.PLURAL */);
break;
case 2 /* Message */:
case 2 /* NodeTypes.Message */:
traverseNodes(node.items, transformer);
break;
case 6 /* Linked */:
case 6 /* NodeTypes.Linked */:
const linked = node;
traverseNode(linked.key, transformer);
transformer.helper("linked" /* LINKED */);
transformer.helper("type" /* TYPE */);
transformer.helper("linked" /* HelperNameMap.LINKED */);
transformer.helper("type" /* HelperNameMap.TYPE */);
break;
case 5 /* List */:
transformer.helper("interpolate" /* INTERPOLATE */);
transformer.helper("list" /* LIST */);
case 5 /* NodeTypes.List */:
transformer.helper("interpolate" /* HelperNameMap.INTERPOLATE */);
transformer.helper("list" /* HelperNameMap.LIST */);
break;
case 4 /* Named */:
transformer.helper("interpolate" /* INTERPOLATE */);
transformer.helper("named" /* NAMED */);
case 4 /* NodeTypes.Named */:
transformer.helper("interpolate" /* HelperNameMap.INTERPOLATE */);
transformer.helper("named" /* HelperNameMap.NAMED */);
break;

@@ -1259,3 +1259,3 @@ }

const transformer = createTransformer(ast);
transformer.helper("normalize" /* NORMALIZE */);
transformer.helper("normalize" /* HelperNameMap.NORMALIZE */);
// traverse

@@ -1315,3 +1315,3 @@ ast.body && traverseNode(ast.body, transformer);

const { helper } = generator;
generator.push(`${helper("linked" /* LINKED */)}(`);
generator.push(`${helper("linked" /* HelperNameMap.LINKED */)}(`);
generateNode(generator, node.key);

@@ -1330,3 +1330,3 @@ if (node.modifier) {

const { helper, needIndent } = generator;
generator.push(`${helper("normalize" /* NORMALIZE */)}([`);
generator.push(`${helper("normalize" /* HelperNameMap.NORMALIZE */)}([`);
generator.indent(needIndent());

@@ -1347,3 +1347,3 @@ const length = node.items.length;

if (node.cases.length > 1) {
generator.push(`${helper("plural" /* PLURAL */)}([`);
generator.push(`${helper("plural" /* HelperNameMap.PLURAL */)}([`);
generator.indent(needIndent());

@@ -1373,30 +1373,30 @@ const length = node.cases.length;

switch (node.type) {
case 0 /* Resource */:
case 0 /* NodeTypes.Resource */:
generateResource(generator, node);
break;
case 1 /* Plural */:
case 1 /* NodeTypes.Plural */:
generatePluralNode(generator, node);
break;
case 2 /* Message */:
case 2 /* NodeTypes.Message */:
generateMessageNode(generator, node);
break;
case 6 /* Linked */:
case 6 /* NodeTypes.Linked */:
generateLinkedNode(generator, node);
break;
case 8 /* LinkedModifier */:
case 8 /* NodeTypes.LinkedModifier */:
generator.push(JSON.stringify(node.value), node);
break;
case 7 /* LinkedKey */:
case 7 /* NodeTypes.LinkedKey */:
generator.push(JSON.stringify(node.value), node);
break;
case 5 /* List */:
generator.push(`${helper("interpolate" /* INTERPOLATE */)}(${helper("list" /* LIST */)}(${node.index}))`, node);
case 5 /* NodeTypes.List */:
generator.push(`${helper("interpolate" /* HelperNameMap.INTERPOLATE */)}(${helper("list" /* HelperNameMap.LIST */)}(${node.index}))`, node);
break;
case 4 /* Named */:
generator.push(`${helper("interpolate" /* INTERPOLATE */)}(${helper("named" /* NAMED */)}(${JSON.stringify(node.key)}))`, node);
case 4 /* NodeTypes.Named */:
generator.push(`${helper("interpolate" /* HelperNameMap.INTERPOLATE */)}(${helper("named" /* HelperNameMap.NAMED */)}(${JSON.stringify(node.key)}))`, node);
break;
case 9 /* Literal */:
case 9 /* NodeTypes.Literal */:
generator.push(JSON.stringify(node.value), node);
break;
case 3 /* Text */:
case 3 /* NodeTypes.Text */:
generator.push(JSON.stringify(node.value), node);

@@ -1403,0 +1403,0 @@ break;

/*!
* message-compiler v9.3.0-beta.10
* message-compiler v9.3.0-beta.11
* (c) 2022 kazuya kawaguchi

@@ -4,0 +4,0 @@ * Released under the MIT License.

{
"name": "@intlify/message-compiler",
"version": "9.3.0-beta.10",
"version": "9.3.0-beta.11",
"description": "@intlify/message-compiler",

@@ -36,3 +36,3 @@ "keywords": [

"dependencies": {
"@intlify/shared": "9.3.0-beta.10",
"@intlify/shared": "9.3.0-beta.11",
"source-map": "0.6.1"

@@ -39,0 +39,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc