@intlify/core 9.2.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2943 @@
1
+ /*!
2
+ * core v9.2.0-beta.10
3
+ * (c) 2021 kazuya kawaguchi
4
+ * Released under the MIT License.
5
+ */
6
+ var IntlifyCore = (function (exports) {
7
+ 'use strict';
8
+
9
+ /**
10
+ * Original Utilities
11
+ * written by kazuya kawaguchi
12
+ */
13
+ const inBrowser = typeof window !== 'undefined';
14
+ let mark;
15
+ let measure;
16
+ {
17
+ const perf = inBrowser && window.performance;
18
+ if (perf &&
19
+ perf.mark &&
20
+ perf.measure &&
21
+ perf.clearMarks &&
22
+ perf.clearMeasures) {
23
+ mark = (tag) => perf.mark(tag);
24
+ measure = (name, startTag, endTag) => {
25
+ perf.measure(name, startTag, endTag);
26
+ perf.clearMarks(startTag);
27
+ perf.clearMarks(endTag);
28
+ };
29
+ }
30
+ }
31
+ const RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
32
+ /* eslint-disable */
33
+ function format(message, ...args) {
34
+ if (args.length === 1 && isObject(args[0])) {
35
+ args = args[0];
36
+ }
37
+ if (!args || !args.hasOwnProperty) {
38
+ args = {};
39
+ }
40
+ return message.replace(RE_ARGS, (match, identifier) => {
41
+ return args.hasOwnProperty(identifier) ? args[identifier] : '';
42
+ });
43
+ }
44
+ const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source });
45
+ const friendlyJSONstringify = (json) => JSON.stringify(json)
46
+ .replace(/\u2028/g, '\\u2028')
47
+ .replace(/\u2029/g, '\\u2029')
48
+ .replace(/\u0027/g, '\\u0027');
49
+ const isNumber = (val) => typeof val === 'number' && isFinite(val);
50
+ const isDate = (val) => toTypeString(val) === '[object Date]';
51
+ const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
52
+ const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
53
+ function warn(msg, err) {
54
+ if (typeof console !== 'undefined') {
55
+ console.warn(`[intlify] ` + msg);
56
+ /* istanbul ignore if */
57
+ if (err) {
58
+ console.warn(err.stack);
59
+ }
60
+ }
61
+ }
62
+ const assign = Object.assign;
63
+ function escapeHtml(rawText) {
64
+ return rawText
65
+ .replace(/</g, '&lt;')
66
+ .replace(/>/g, '&gt;')
67
+ .replace(/"/g, '&quot;')
68
+ .replace(/'/g, '&apos;');
69
+ }
70
+ /* eslint-enable */
71
+ /**
72
+ * Useful Utilities By Evan you
73
+ * Modified by kazuya kawaguchi
74
+ * MIT License
75
+ * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
76
+ * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
77
+ */
78
+ const isArray = Array.isArray;
79
+ const isFunction = (val) => typeof val === 'function';
80
+ const isString = (val) => typeof val === 'string';
81
+ const isBoolean = (val) => typeof val === 'boolean';
82
+ const isObject = (val) => // eslint-disable-line
83
+ val !== null && typeof val === 'object';
84
+ const objectToString = Object.prototype.toString;
85
+ const toTypeString = (value) => objectToString.call(value);
86
+ const isPlainObject = (val) => toTypeString(val) === '[object Object]';
87
+ // for converting list and named values to displayed strings.
88
+ const toDisplayString = (val) => {
89
+ return val == null
90
+ ? ''
91
+ : isArray(val) || (isPlainObject(val) && val.toString === objectToString)
92
+ ? JSON.stringify(val, null, 2)
93
+ : String(val);
94
+ };
95
+ const RANGE = 2;
96
+ function generateCodeFrame(source, start = 0, end = source.length) {
97
+ const lines = source.split(/\r?\n/);
98
+ let count = 0;
99
+ const res = [];
100
+ for (let i = 0; i < lines.length; i++) {
101
+ count += lines[i].length + 1;
102
+ if (count >= start) {
103
+ for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
104
+ if (j < 0 || j >= lines.length)
105
+ continue;
106
+ const line = j + 1;
107
+ res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
108
+ const lineLength = lines[j].length;
109
+ if (j === i) {
110
+ // push underline
111
+ const pad = start - (count - lineLength) + 1;
112
+ const length = Math.max(1, end > count ? lineLength - pad : end - start);
113
+ res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
114
+ }
115
+ else if (j > i) {
116
+ if (end > count) {
117
+ const length = Math.max(Math.min(end - count, lineLength), 1);
118
+ res.push(` | ` + '^'.repeat(length));
119
+ }
120
+ count += lineLength + 1;
121
+ }
122
+ }
123
+ break;
124
+ }
125
+ }
126
+ return res.join('\n');
127
+ }
128
+
129
+ const CompileErrorCodes = {
130
+ // tokenizer error codes
131
+ EXPECTED_TOKEN: 1,
132
+ INVALID_TOKEN_IN_PLACEHOLDER: 2,
133
+ UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER: 3,
134
+ UNKNOWN_ESCAPE_SEQUENCE: 4,
135
+ INVALID_UNICODE_ESCAPE_SEQUENCE: 5,
136
+ UNBALANCED_CLOSING_BRACE: 6,
137
+ UNTERMINATED_CLOSING_BRACE: 7,
138
+ EMPTY_PLACEHOLDER: 8,
139
+ NOT_ALLOW_NEST_PLACEHOLDER: 9,
140
+ INVALID_LINKED_FORMAT: 10,
141
+ // parser error codes
142
+ MUST_HAVE_MESSAGES_IN_PLURAL: 11,
143
+ UNEXPECTED_EMPTY_LINKED_MODIFIER: 12,
144
+ UNEXPECTED_EMPTY_LINKED_KEY: 13,
145
+ UNEXPECTED_LEXICAL_ANALYSIS: 14,
146
+ // Special value for higher-order compilers to pick up the last code
147
+ // to avoid collision of error codes. This should always be kept as the last
148
+ // item.
149
+ __EXTEND_POINT__: 15
150
+ };
151
+ /** @internal */
152
+ const errorMessages$1 = {
153
+ // tokenizer error messages
154
+ [CompileErrorCodes.EXPECTED_TOKEN]: `Expected token: '{0}'`,
155
+ [CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER]: `Invalid token in placeholder: '{0}'`,
156
+ [CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]: `Unterminated single quote in placeholder`,
157
+ [CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE]: `Unknown escape sequence: \\{0}`,
158
+ [CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE]: `Invalid unicode escape sequence: {0}`,
159
+ [CompileErrorCodes.UNBALANCED_CLOSING_BRACE]: `Unbalanced closing brace`,
160
+ [CompileErrorCodes.UNTERMINATED_CLOSING_BRACE]: `Unterminated closing brace`,
161
+ [CompileErrorCodes.EMPTY_PLACEHOLDER]: `Empty placeholder`,
162
+ [CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER]: `Not allowed nest placeholder`,
163
+ [CompileErrorCodes.INVALID_LINKED_FORMAT]: `Invalid linked format`,
164
+ // parser error messages
165
+ [CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL]: `Plural must have messages`,
166
+ [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER]: `Unexpected empty linked modifier`,
167
+ [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY]: `Unexpected empty linked key`,
168
+ [CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS]: `Unexpected lexical analysis in token: '{0}'`
169
+ };
170
+ function createCompileError(code, loc, options = {}) {
171
+ const { domain, messages, args } = options;
172
+ const msg = format((messages || errorMessages$1)[code] || '', ...(args || []))
173
+ ;
174
+ const error = new SyntaxError(String(msg));
175
+ error.code = code;
176
+ if (loc) {
177
+ error.location = loc;
178
+ }
179
+ error.domain = domain;
180
+ return error;
181
+ }
182
+ /** @internal */
183
+ function defaultOnError(error) {
184
+ throw error;
185
+ }
186
+
187
+ function createPosition(line, column, offset) {
188
+ return { line, column, offset };
189
+ }
190
+ function createLocation(start, end, source) {
191
+ const loc = { start, end };
192
+ if (source != null) {
193
+ loc.source = source;
194
+ }
195
+ return loc;
196
+ }
197
+
198
+ const CHAR_SP = ' ';
199
+ const CHAR_CR = '\r';
200
+ const CHAR_LF = '\n';
201
+ const CHAR_LS = String.fromCharCode(0x2028);
202
+ const CHAR_PS = String.fromCharCode(0x2029);
203
+ function createScanner(str) {
204
+ const _buf = str;
205
+ let _index = 0;
206
+ let _line = 1;
207
+ let _column = 1;
208
+ let _peekOffset = 0;
209
+ const isCRLF = (index) => _buf[index] === CHAR_CR && _buf[index + 1] === CHAR_LF;
210
+ const isLF = (index) => _buf[index] === CHAR_LF;
211
+ const isPS = (index) => _buf[index] === CHAR_PS;
212
+ const isLS = (index) => _buf[index] === CHAR_LS;
213
+ const isLineEnd = (index) => isCRLF(index) || isLF(index) || isPS(index) || isLS(index);
214
+ const index = () => _index;
215
+ const line = () => _line;
216
+ const column = () => _column;
217
+ const peekOffset = () => _peekOffset;
218
+ const charAt = (offset) => isCRLF(offset) || isPS(offset) || isLS(offset) ? CHAR_LF : _buf[offset];
219
+ const currentChar = () => charAt(_index);
220
+ const currentPeek = () => charAt(_index + _peekOffset);
221
+ function next() {
222
+ _peekOffset = 0;
223
+ if (isLineEnd(_index)) {
224
+ _line++;
225
+ _column = 0;
226
+ }
227
+ if (isCRLF(_index)) {
228
+ _index++;
229
+ }
230
+ _index++;
231
+ _column++;
232
+ return _buf[_index];
233
+ }
234
+ function peek() {
235
+ if (isCRLF(_index + _peekOffset)) {
236
+ _peekOffset++;
237
+ }
238
+ _peekOffset++;
239
+ return _buf[_index + _peekOffset];
240
+ }
241
+ function reset() {
242
+ _index = 0;
243
+ _line = 1;
244
+ _column = 1;
245
+ _peekOffset = 0;
246
+ }
247
+ function resetPeek(offset = 0) {
248
+ _peekOffset = offset;
249
+ }
250
+ function skipToPeek() {
251
+ const target = _index + _peekOffset;
252
+ // eslint-disable-next-line no-unmodified-loop-condition
253
+ while (target !== _index) {
254
+ next();
255
+ }
256
+ _peekOffset = 0;
257
+ }
258
+ return {
259
+ index,
260
+ line,
261
+ column,
262
+ peekOffset,
263
+ charAt,
264
+ currentChar,
265
+ currentPeek,
266
+ next,
267
+ peek,
268
+ reset,
269
+ resetPeek,
270
+ skipToPeek
271
+ };
272
+ }
273
+
274
+ const EOF = undefined;
275
+ const LITERAL_DELIMITER = "'";
276
+ const ERROR_DOMAIN$1 = 'tokenizer';
277
+ function createTokenizer(source, options = {}) {
278
+ const location = options.location !== false;
279
+ const _scnr = createScanner(source);
280
+ const currentOffset = () => _scnr.index();
281
+ const currentPosition = () => createPosition(_scnr.line(), _scnr.column(), _scnr.index());
282
+ const _initLoc = currentPosition();
283
+ const _initOffset = currentOffset();
284
+ const _context = {
285
+ currentType: 14 /* EOF */,
286
+ offset: _initOffset,
287
+ startLoc: _initLoc,
288
+ endLoc: _initLoc,
289
+ lastType: 14 /* EOF */,
290
+ lastOffset: _initOffset,
291
+ lastStartLoc: _initLoc,
292
+ lastEndLoc: _initLoc,
293
+ braceNest: 0,
294
+ inLinked: false,
295
+ text: ''
296
+ };
297
+ const context = () => _context;
298
+ const { onError } = options;
299
+ function emitError(code, pos, offset, ...args) {
300
+ const ctx = context();
301
+ pos.column += offset;
302
+ pos.offset += offset;
303
+ if (onError) {
304
+ const loc = createLocation(ctx.startLoc, pos);
305
+ const err = createCompileError(code, loc, {
306
+ domain: ERROR_DOMAIN$1,
307
+ args
308
+ });
309
+ onError(err);
310
+ }
311
+ }
312
+ function getToken(context, type, value) {
313
+ context.endLoc = currentPosition();
314
+ context.currentType = type;
315
+ const token = { type };
316
+ if (location) {
317
+ token.loc = createLocation(context.startLoc, context.endLoc);
318
+ }
319
+ if (value != null) {
320
+ token.value = value;
321
+ }
322
+ return token;
323
+ }
324
+ const getEndToken = (context) => getToken(context, 14 /* EOF */);
325
+ function eat(scnr, ch) {
326
+ if (scnr.currentChar() === ch) {
327
+ scnr.next();
328
+ return ch;
329
+ }
330
+ else {
331
+ emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
332
+ return '';
333
+ }
334
+ }
335
+ function peekSpaces(scnr) {
336
+ let buf = '';
337
+ while (scnr.currentPeek() === CHAR_SP || scnr.currentPeek() === CHAR_LF) {
338
+ buf += scnr.currentPeek();
339
+ scnr.peek();
340
+ }
341
+ return buf;
342
+ }
343
+ function skipSpaces(scnr) {
344
+ const buf = peekSpaces(scnr);
345
+ scnr.skipToPeek();
346
+ return buf;
347
+ }
348
+ function isIdentifierStart(ch) {
349
+ if (ch === EOF) {
350
+ return false;
351
+ }
352
+ const cc = ch.charCodeAt(0);
353
+ return ((cc >= 97 && cc <= 122) || // a-z
354
+ (cc >= 65 && cc <= 90) || // A-Z
355
+ cc === 95 // _
356
+ );
357
+ }
358
+ function isNumberStart(ch) {
359
+ if (ch === EOF) {
360
+ return false;
361
+ }
362
+ const cc = ch.charCodeAt(0);
363
+ return cc >= 48 && cc <= 57; // 0-9
364
+ }
365
+ function isNamedIdentifierStart(scnr, context) {
366
+ const { currentType } = context;
367
+ if (currentType !== 2 /* BraceLeft */) {
368
+ return false;
369
+ }
370
+ peekSpaces(scnr);
371
+ const ret = isIdentifierStart(scnr.currentPeek());
372
+ scnr.resetPeek();
373
+ return ret;
374
+ }
375
+ function isListIdentifierStart(scnr, context) {
376
+ const { currentType } = context;
377
+ if (currentType !== 2 /* BraceLeft */) {
378
+ return false;
379
+ }
380
+ peekSpaces(scnr);
381
+ const ch = scnr.currentPeek() === '-' ? scnr.peek() : scnr.currentPeek();
382
+ const ret = isNumberStart(ch);
383
+ scnr.resetPeek();
384
+ return ret;
385
+ }
386
+ function isLiteralStart(scnr, context) {
387
+ const { currentType } = context;
388
+ if (currentType !== 2 /* BraceLeft */) {
389
+ return false;
390
+ }
391
+ peekSpaces(scnr);
392
+ const ret = scnr.currentPeek() === LITERAL_DELIMITER;
393
+ scnr.resetPeek();
394
+ return ret;
395
+ }
396
+ function isLinkedDotStart(scnr, context) {
397
+ const { currentType } = context;
398
+ if (currentType !== 8 /* LinkedAlias */) {
399
+ return false;
400
+ }
401
+ peekSpaces(scnr);
402
+ const ret = scnr.currentPeek() === "." /* LinkedDot */;
403
+ scnr.resetPeek();
404
+ return ret;
405
+ }
406
+ function isLinkedModifierStart(scnr, context) {
407
+ const { currentType } = context;
408
+ if (currentType !== 9 /* LinkedDot */) {
409
+ return false;
410
+ }
411
+ peekSpaces(scnr);
412
+ const ret = isIdentifierStart(scnr.currentPeek());
413
+ scnr.resetPeek();
414
+ return ret;
415
+ }
416
+ function isLinkedDelimiterStart(scnr, context) {
417
+ const { currentType } = context;
418
+ if (!(currentType === 8 /* LinkedAlias */ ||
419
+ currentType === 12 /* LinkedModifier */)) {
420
+ return false;
421
+ }
422
+ peekSpaces(scnr);
423
+ const ret = scnr.currentPeek() === ":" /* LinkedDelimiter */;
424
+ scnr.resetPeek();
425
+ return ret;
426
+ }
427
+ function isLinkedReferStart(scnr, context) {
428
+ const { currentType } = context;
429
+ if (currentType !== 10 /* LinkedDelimiter */) {
430
+ return false;
431
+ }
432
+ const fn = () => {
433
+ const ch = scnr.currentPeek();
434
+ if (ch === "{" /* BraceLeft */) {
435
+ return isIdentifierStart(scnr.peek());
436
+ }
437
+ else if (ch === "@" /* LinkedAlias */ ||
438
+ ch === "%" /* Modulo */ ||
439
+ ch === "|" /* Pipe */ ||
440
+ ch === ":" /* LinkedDelimiter */ ||
441
+ ch === "." /* LinkedDot */ ||
442
+ ch === CHAR_SP ||
443
+ !ch) {
444
+ return false;
445
+ }
446
+ else if (ch === CHAR_LF) {
447
+ scnr.peek();
448
+ return fn();
449
+ }
450
+ else {
451
+ // other characters
452
+ return isIdentifierStart(ch);
453
+ }
454
+ };
455
+ const ret = fn();
456
+ scnr.resetPeek();
457
+ return ret;
458
+ }
459
+ function isPluralStart(scnr) {
460
+ peekSpaces(scnr);
461
+ const ret = scnr.currentPeek() === "|" /* Pipe */;
462
+ scnr.resetPeek();
463
+ return ret;
464
+ }
465
+ function isTextStart(scnr, reset = true) {
466
+ const fn = (hasSpace = false, prev = '', detectModulo = false) => {
467
+ const ch = scnr.currentPeek();
468
+ if (ch === "{" /* BraceLeft */) {
469
+ return prev === "%" /* Modulo */ ? false : hasSpace;
470
+ }
471
+ else if (ch === "@" /* LinkedAlias */ || !ch) {
472
+ return prev === "%" /* Modulo */ ? true : hasSpace;
473
+ }
474
+ else if (ch === "%" /* Modulo */) {
475
+ scnr.peek();
476
+ return fn(hasSpace, "%" /* Modulo */, true);
477
+ }
478
+ else if (ch === "|" /* Pipe */) {
479
+ return prev === "%" /* Modulo */ || detectModulo
480
+ ? true
481
+ : !(prev === CHAR_SP || prev === CHAR_LF);
482
+ }
483
+ else if (ch === CHAR_SP) {
484
+ scnr.peek();
485
+ return fn(true, CHAR_SP, detectModulo);
486
+ }
487
+ else if (ch === CHAR_LF) {
488
+ scnr.peek();
489
+ return fn(true, CHAR_LF, detectModulo);
490
+ }
491
+ else {
492
+ return true;
493
+ }
494
+ };
495
+ const ret = fn();
496
+ reset && scnr.resetPeek();
497
+ return ret;
498
+ }
499
+ function takeChar(scnr, fn) {
500
+ const ch = scnr.currentChar();
501
+ if (ch === EOF) {
502
+ return EOF;
503
+ }
504
+ if (fn(ch)) {
505
+ scnr.next();
506
+ return ch;
507
+ }
508
+ return null;
509
+ }
510
+ function takeIdentifierChar(scnr) {
511
+ const closure = (ch) => {
512
+ const cc = ch.charCodeAt(0);
513
+ return ((cc >= 97 && cc <= 122) || // a-z
514
+ (cc >= 65 && cc <= 90) || // A-Z
515
+ (cc >= 48 && cc <= 57) || // 0-9
516
+ cc === 95 || // _
517
+ cc === 36 // $
518
+ );
519
+ };
520
+ return takeChar(scnr, closure);
521
+ }
522
+ function takeDigit(scnr) {
523
+ const closure = (ch) => {
524
+ const cc = ch.charCodeAt(0);
525
+ return cc >= 48 && cc <= 57; // 0-9
526
+ };
527
+ return takeChar(scnr, closure);
528
+ }
529
+ function takeHexDigit(scnr) {
530
+ const closure = (ch) => {
531
+ const cc = ch.charCodeAt(0);
532
+ return ((cc >= 48 && cc <= 57) || // 0-9
533
+ (cc >= 65 && cc <= 70) || // A-F
534
+ (cc >= 97 && cc <= 102)); // a-f
535
+ };
536
+ return takeChar(scnr, closure);
537
+ }
538
+ function getDigits(scnr) {
539
+ let ch = '';
540
+ let num = '';
541
+ while ((ch = takeDigit(scnr))) {
542
+ num += ch;
543
+ }
544
+ return num;
545
+ }
546
+ function readText(scnr) {
547
+ const fn = (buf) => {
548
+ const ch = scnr.currentChar();
549
+ if (ch === "{" /* BraceLeft */ ||
550
+ ch === "}" /* BraceRight */ ||
551
+ ch === "@" /* LinkedAlias */ ||
552
+ !ch) {
553
+ return buf;
554
+ }
555
+ else if (ch === "%" /* Modulo */) {
556
+ if (isTextStart(scnr)) {
557
+ buf += ch;
558
+ scnr.next();
559
+ return fn(buf);
560
+ }
561
+ else {
562
+ return buf;
563
+ }
564
+ }
565
+ else if (ch === "|" /* Pipe */) {
566
+ return buf;
567
+ }
568
+ else if (ch === CHAR_SP || ch === CHAR_LF) {
569
+ if (isTextStart(scnr)) {
570
+ buf += ch;
571
+ scnr.next();
572
+ return fn(buf);
573
+ }
574
+ else if (isPluralStart(scnr)) {
575
+ return buf;
576
+ }
577
+ else {
578
+ buf += ch;
579
+ scnr.next();
580
+ return fn(buf);
581
+ }
582
+ }
583
+ else {
584
+ buf += ch;
585
+ scnr.next();
586
+ return fn(buf);
587
+ }
588
+ };
589
+ return fn('');
590
+ }
591
+ function readNamedIdentifier(scnr) {
592
+ skipSpaces(scnr);
593
+ let ch = '';
594
+ let name = '';
595
+ while ((ch = takeIdentifierChar(scnr))) {
596
+ name += ch;
597
+ }
598
+ if (scnr.currentChar() === EOF) {
599
+ emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
600
+ }
601
+ return name;
602
+ }
603
+ function readListIdentifier(scnr) {
604
+ skipSpaces(scnr);
605
+ let value = '';
606
+ if (scnr.currentChar() === '-') {
607
+ scnr.next();
608
+ value += `-${getDigits(scnr)}`;
609
+ }
610
+ else {
611
+ value += getDigits(scnr);
612
+ }
613
+ if (scnr.currentChar() === EOF) {
614
+ emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
615
+ }
616
+ return value;
617
+ }
618
+ function readLiteral(scnr) {
619
+ skipSpaces(scnr);
620
+ eat(scnr, `\'`);
621
+ let ch = '';
622
+ let literal = '';
623
+ const fn = (x) => x !== LITERAL_DELIMITER && x !== CHAR_LF;
624
+ while ((ch = takeChar(scnr, fn))) {
625
+ if (ch === '\\') {
626
+ literal += readEscapeSequence(scnr);
627
+ }
628
+ else {
629
+ literal += ch;
630
+ }
631
+ }
632
+ const current = scnr.currentChar();
633
+ if (current === CHAR_LF || current === EOF) {
634
+ emitError(CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER, currentPosition(), 0);
635
+ // TODO: Is it correct really?
636
+ if (current === CHAR_LF) {
637
+ scnr.next();
638
+ eat(scnr, `\'`);
639
+ }
640
+ return literal;
641
+ }
642
+ eat(scnr, `\'`);
643
+ return literal;
644
+ }
645
+ function readEscapeSequence(scnr) {
646
+ const ch = scnr.currentChar();
647
+ switch (ch) {
648
+ case '\\':
649
+ case `\'`:
650
+ scnr.next();
651
+ return `\\${ch}`;
652
+ case 'u':
653
+ return readUnicodeEscapeSequence(scnr, ch, 4);
654
+ case 'U':
655
+ return readUnicodeEscapeSequence(scnr, ch, 6);
656
+ default:
657
+ emitError(CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE, currentPosition(), 0, ch);
658
+ return '';
659
+ }
660
+ }
661
+ function readUnicodeEscapeSequence(scnr, unicode, digits) {
662
+ eat(scnr, unicode);
663
+ let sequence = '';
664
+ for (let i = 0; i < digits; i++) {
665
+ const ch = takeHexDigit(scnr);
666
+ if (!ch) {
667
+ emitError(CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE, currentPosition(), 0, `\\${unicode}${sequence}${scnr.currentChar()}`);
668
+ break;
669
+ }
670
+ sequence += ch;
671
+ }
672
+ return `\\${unicode}${sequence}`;
673
+ }
674
+ function readInvalidIdentifier(scnr) {
675
+ skipSpaces(scnr);
676
+ let ch = '';
677
+ let identifiers = '';
678
+ const closure = (ch) => ch !== "{" /* BraceLeft */ &&
679
+ ch !== "}" /* BraceRight */ &&
680
+ ch !== CHAR_SP &&
681
+ ch !== CHAR_LF;
682
+ while ((ch = takeChar(scnr, closure))) {
683
+ identifiers += ch;
684
+ }
685
+ return identifiers;
686
+ }
687
+ function readLinkedModifier(scnr) {
688
+ let ch = '';
689
+ let name = '';
690
+ while ((ch = takeIdentifierChar(scnr))) {
691
+ name += ch;
692
+ }
693
+ return name;
694
+ }
695
+ function readLinkedRefer(scnr) {
696
+ const fn = (detect = false, buf) => {
697
+ const ch = scnr.currentChar();
698
+ if (ch === "{" /* BraceLeft */ ||
699
+ ch === "%" /* Modulo */ ||
700
+ ch === "@" /* LinkedAlias */ ||
701
+ ch === "|" /* Pipe */ ||
702
+ !ch) {
703
+ return buf;
704
+ }
705
+ else if (ch === CHAR_SP) {
706
+ return buf;
707
+ }
708
+ else if (ch === CHAR_LF) {
709
+ buf += ch;
710
+ scnr.next();
711
+ return fn(detect, buf);
712
+ }
713
+ else {
714
+ buf += ch;
715
+ scnr.next();
716
+ return fn(true, buf);
717
+ }
718
+ };
719
+ return fn(false, '');
720
+ }
721
+ function readPlural(scnr) {
722
+ skipSpaces(scnr);
723
+ const plural = eat(scnr, "|" /* Pipe */);
724
+ skipSpaces(scnr);
725
+ return plural;
726
+ }
727
+ // TODO: We need refactoring of token parsing ...
728
+ function readTokenInPlaceholder(scnr, context) {
729
+ let token = null;
730
+ const ch = scnr.currentChar();
731
+ switch (ch) {
732
+ case "{" /* BraceLeft */:
733
+ if (context.braceNest >= 1) {
734
+ emitError(CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER, currentPosition(), 0);
735
+ }
736
+ scnr.next();
737
+ token = getToken(context, 2 /* BraceLeft */, "{" /* BraceLeft */);
738
+ skipSpaces(scnr);
739
+ context.braceNest++;
740
+ return token;
741
+ case "}" /* BraceRight */:
742
+ if (context.braceNest > 0 &&
743
+ context.currentType === 2 /* BraceLeft */) {
744
+ emitError(CompileErrorCodes.EMPTY_PLACEHOLDER, currentPosition(), 0);
745
+ }
746
+ scnr.next();
747
+ token = getToken(context, 3 /* BraceRight */, "}" /* BraceRight */);
748
+ context.braceNest--;
749
+ context.braceNest > 0 && skipSpaces(scnr);
750
+ if (context.inLinked && context.braceNest === 0) {
751
+ context.inLinked = false;
752
+ }
753
+ return token;
754
+ case "@" /* LinkedAlias */:
755
+ if (context.braceNest > 0) {
756
+ emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
757
+ }
758
+ token = readTokenInLinked(scnr, context) || getEndToken(context);
759
+ context.braceNest = 0;
760
+ return token;
761
+ default:
762
+ let validNamedIdentifier = true;
763
+ let validListIdentifier = true;
764
+ let validLiteral = true;
765
+ if (isPluralStart(scnr)) {
766
+ if (context.braceNest > 0) {
767
+ emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
768
+ }
769
+ token = getToken(context, 1 /* Pipe */, readPlural(scnr));
770
+ // reset
771
+ context.braceNest = 0;
772
+ context.inLinked = false;
773
+ return token;
774
+ }
775
+ if (context.braceNest > 0 &&
776
+ (context.currentType === 5 /* Named */ ||
777
+ context.currentType === 6 /* List */ ||
778
+ context.currentType === 7 /* Literal */)) {
779
+ emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
780
+ context.braceNest = 0;
781
+ return readToken(scnr, context);
782
+ }
783
+ if ((validNamedIdentifier = isNamedIdentifierStart(scnr, context))) {
784
+ token = getToken(context, 5 /* Named */, readNamedIdentifier(scnr));
785
+ skipSpaces(scnr);
786
+ return token;
787
+ }
788
+ if ((validListIdentifier = isListIdentifierStart(scnr, context))) {
789
+ token = getToken(context, 6 /* List */, readListIdentifier(scnr));
790
+ skipSpaces(scnr);
791
+ return token;
792
+ }
793
+ if ((validLiteral = isLiteralStart(scnr, context))) {
794
+ token = getToken(context, 7 /* Literal */, readLiteral(scnr));
795
+ skipSpaces(scnr);
796
+ return token;
797
+ }
798
+ if (!validNamedIdentifier && !validListIdentifier && !validLiteral) {
799
+ // TODO: we should be re-designed invalid cases, when we will extend message syntax near the future ...
800
+ token = getToken(context, 13 /* InvalidPlace */, readInvalidIdentifier(scnr));
801
+ emitError(CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER, currentPosition(), 0, token.value);
802
+ skipSpaces(scnr);
803
+ return token;
804
+ }
805
+ break;
806
+ }
807
+ return token;
808
+ }
809
+ // TODO: We need refactoring of token parsing ...
810
+ function readTokenInLinked(scnr, context) {
811
+ const { currentType } = context;
812
+ let token = null;
813
+ const ch = scnr.currentChar();
814
+ if ((currentType === 8 /* LinkedAlias */ ||
815
+ currentType === 9 /* LinkedDot */ ||
816
+ currentType === 12 /* LinkedModifier */ ||
817
+ currentType === 10 /* LinkedDelimiter */) &&
818
+ (ch === CHAR_LF || ch === CHAR_SP)) {
819
+ emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);
820
+ }
821
+ switch (ch) {
822
+ case "@" /* LinkedAlias */:
823
+ scnr.next();
824
+ token = getToken(context, 8 /* LinkedAlias */, "@" /* LinkedAlias */);
825
+ context.inLinked = true;
826
+ return token;
827
+ case "." /* LinkedDot */:
828
+ skipSpaces(scnr);
829
+ scnr.next();
830
+ return getToken(context, 9 /* LinkedDot */, "." /* LinkedDot */);
831
+ case ":" /* LinkedDelimiter */:
832
+ skipSpaces(scnr);
833
+ scnr.next();
834
+ return getToken(context, 10 /* LinkedDelimiter */, ":" /* LinkedDelimiter */);
835
+ default:
836
+ if (isPluralStart(scnr)) {
837
+ token = getToken(context, 1 /* Pipe */, readPlural(scnr));
838
+ // reset
839
+ context.braceNest = 0;
840
+ context.inLinked = false;
841
+ return token;
842
+ }
843
+ if (isLinkedDotStart(scnr, context) ||
844
+ isLinkedDelimiterStart(scnr, context)) {
845
+ skipSpaces(scnr);
846
+ return readTokenInLinked(scnr, context);
847
+ }
848
+ if (isLinkedModifierStart(scnr, context)) {
849
+ skipSpaces(scnr);
850
+ return getToken(context, 12 /* LinkedModifier */, readLinkedModifier(scnr));
851
+ }
852
+ if (isLinkedReferStart(scnr, context)) {
853
+ skipSpaces(scnr);
854
+ if (ch === "{" /* BraceLeft */) {
855
+ // scan the placeholder
856
+ return readTokenInPlaceholder(scnr, context) || token;
857
+ }
858
+ else {
859
+ return getToken(context, 11 /* LinkedKey */, readLinkedRefer(scnr));
860
+ }
861
+ }
862
+ if (currentType === 8 /* LinkedAlias */) {
863
+ emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);
864
+ }
865
+ context.braceNest = 0;
866
+ context.inLinked = false;
867
+ return readToken(scnr, context);
868
+ }
869
+ }
870
+ // TODO: We need refactoring of token parsing ...
871
+ function readToken(scnr, context) {
872
+ let token = { type: 14 /* EOF */ };
873
+ if (context.braceNest > 0) {
874
+ return readTokenInPlaceholder(scnr, context) || getEndToken(context);
875
+ }
876
+ if (context.inLinked) {
877
+ return readTokenInLinked(scnr, context) || getEndToken(context);
878
+ }
879
+ const ch = scnr.currentChar();
880
+ switch (ch) {
881
+ case "{" /* BraceLeft */:
882
+ return readTokenInPlaceholder(scnr, context) || getEndToken(context);
883
+ case "}" /* BraceRight */:
884
+ emitError(CompileErrorCodes.UNBALANCED_CLOSING_BRACE, currentPosition(), 0);
885
+ scnr.next();
886
+ return getToken(context, 3 /* BraceRight */, "}" /* BraceRight */);
887
+ case "@" /* LinkedAlias */:
888
+ return readTokenInLinked(scnr, context) || getEndToken(context);
889
+ default:
890
+ if (isPluralStart(scnr)) {
891
+ token = getToken(context, 1 /* Pipe */, readPlural(scnr));
892
+ // reset
893
+ context.braceNest = 0;
894
+ context.inLinked = false;
895
+ return token;
896
+ }
897
+ if (isTextStart(scnr)) {
898
+ return getToken(context, 0 /* Text */, readText(scnr));
899
+ }
900
+ if (ch === "%" /* Modulo */) {
901
+ scnr.next();
902
+ return getToken(context, 4 /* Modulo */, "%" /* Modulo */);
903
+ }
904
+ break;
905
+ }
906
+ return token;
907
+ }
908
+ function nextToken() {
909
+ const { currentType, offset, startLoc, endLoc } = _context;
910
+ _context.lastType = currentType;
911
+ _context.lastOffset = offset;
912
+ _context.lastStartLoc = startLoc;
913
+ _context.lastEndLoc = endLoc;
914
+ _context.offset = currentOffset();
915
+ _context.startLoc = currentPosition();
916
+ if (_scnr.currentChar() === EOF) {
917
+ return getToken(_context, 14 /* EOF */);
918
+ }
919
+ return readToken(_scnr, _context);
920
+ }
921
+ return {
922
+ nextToken,
923
+ currentOffset,
924
+ currentPosition,
925
+ context
926
+ };
927
+ }
928
+
929
+ const ERROR_DOMAIN = 'parser';
930
+ // Backslash backslash, backslash quote, uHHHH, UHHHHHH.
931
+ const KNOWN_ESCAPES = /(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;
932
+ function fromEscapeSequence(match, codePoint4, codePoint6) {
933
+ switch (match) {
934
+ case `\\\\`:
935
+ return `\\`;
936
+ case `\\\'`:
937
+ return `\'`;
938
+ default: {
939
+ const codePoint = parseInt(codePoint4 || codePoint6, 16);
940
+ if (codePoint <= 0xd7ff || codePoint >= 0xe000) {
941
+ return String.fromCodePoint(codePoint);
942
+ }
943
+ // invalid ...
944
+ // Replace them with U+FFFD REPLACEMENT CHARACTER.
945
+ return '�';
946
+ }
947
+ }
948
+ }
949
+ function createParser(options = {}) {
950
+ const location = options.location !== false;
951
+ const { onError } = options;
952
+ function emitError(tokenzer, code, start, offset, ...args) {
953
+ const end = tokenzer.currentPosition();
954
+ end.offset += offset;
955
+ end.column += offset;
956
+ if (onError) {
957
+ const loc = createLocation(start, end);
958
+ const err = createCompileError(code, loc, {
959
+ domain: ERROR_DOMAIN,
960
+ args
961
+ });
962
+ onError(err);
963
+ }
964
+ }
965
+ function startNode(type, offset, loc) {
966
+ const node = {
967
+ type,
968
+ start: offset,
969
+ end: offset
970
+ };
971
+ if (location) {
972
+ node.loc = { start: loc, end: loc };
973
+ }
974
+ return node;
975
+ }
976
+ function endNode(node, offset, pos, type) {
977
+ node.end = offset;
978
+ if (type) {
979
+ node.type = type;
980
+ }
981
+ if (location && node.loc) {
982
+ node.loc.end = pos;
983
+ }
984
+ }
985
+ function parseText(tokenizer, value) {
986
+ const context = tokenizer.context();
987
+ const node = startNode(3 /* Text */, context.offset, context.startLoc);
988
+ node.value = value;
989
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
990
+ return node;
991
+ }
992
+ function parseList(tokenizer, index) {
993
+ const context = tokenizer.context();
994
+ const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
995
+ const node = startNode(5 /* List */, offset, loc);
996
+ node.index = parseInt(index, 10);
997
+ tokenizer.nextToken(); // skip brach right
998
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
999
+ return node;
1000
+ }
1001
+ function parseNamed(tokenizer, key) {
1002
+ const context = tokenizer.context();
1003
+ const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
1004
+ const node = startNode(4 /* Named */, offset, loc);
1005
+ node.key = key;
1006
+ tokenizer.nextToken(); // skip brach right
1007
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1008
+ return node;
1009
+ }
1010
+ function parseLiteral(tokenizer, value) {
1011
+ const context = tokenizer.context();
1012
+ const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
1013
+ const node = startNode(9 /* Literal */, offset, loc);
1014
+ node.value = value.replace(KNOWN_ESCAPES, fromEscapeSequence);
1015
+ tokenizer.nextToken(); // skip brach right
1016
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1017
+ return node;
1018
+ }
1019
+ function parseLinkedModifier(tokenizer) {
1020
+ const token = tokenizer.nextToken();
1021
+ const context = tokenizer.context();
1022
+ const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc
1023
+ const node = startNode(8 /* LinkedModifier */, offset, loc);
1024
+ if (token.type !== 12 /* LinkedModifier */) {
1025
+ // empty modifier
1026
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER, context.lastStartLoc, 0);
1027
+ node.value = '';
1028
+ endNode(node, offset, loc);
1029
+ return {
1030
+ nextConsumeToken: token,
1031
+ node
1032
+ };
1033
+ }
1034
+ // check token
1035
+ if (token.value == null) {
1036
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1037
+ }
1038
+ node.value = token.value || '';
1039
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1040
+ return {
1041
+ node
1042
+ };
1043
+ }
1044
+ function parseLinkedKey(tokenizer, value) {
1045
+ const context = tokenizer.context();
1046
+ const node = startNode(7 /* LinkedKey */, context.offset, context.startLoc);
1047
+ node.value = value;
1048
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1049
+ return node;
1050
+ }
1051
+ function parseLinked(tokenizer) {
1052
+ const context = tokenizer.context();
1053
+ const linkedNode = startNode(6 /* Linked */, context.offset, context.startLoc);
1054
+ let token = tokenizer.nextToken();
1055
+ if (token.type === 9 /* LinkedDot */) {
1056
+ const parsed = parseLinkedModifier(tokenizer);
1057
+ linkedNode.modifier = parsed.node;
1058
+ token = parsed.nextConsumeToken || tokenizer.nextToken();
1059
+ }
1060
+ // asset check token
1061
+ if (token.type !== 10 /* LinkedDelimiter */) {
1062
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1063
+ }
1064
+ token = tokenizer.nextToken();
1065
+ // skip brace left
1066
+ if (token.type === 2 /* BraceLeft */) {
1067
+ token = tokenizer.nextToken();
1068
+ }
1069
+ switch (token.type) {
1070
+ case 11 /* LinkedKey */:
1071
+ if (token.value == null) {
1072
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1073
+ }
1074
+ linkedNode.key = parseLinkedKey(tokenizer, token.value || '');
1075
+ break;
1076
+ case 5 /* Named */:
1077
+ if (token.value == null) {
1078
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1079
+ }
1080
+ linkedNode.key = parseNamed(tokenizer, token.value || '');
1081
+ break;
1082
+ case 6 /* List */:
1083
+ if (token.value == null) {
1084
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1085
+ }
1086
+ linkedNode.key = parseList(tokenizer, token.value || '');
1087
+ break;
1088
+ case 7 /* Literal */:
1089
+ if (token.value == null) {
1090
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1091
+ }
1092
+ linkedNode.key = parseLiteral(tokenizer, token.value || '');
1093
+ break;
1094
+ default:
1095
+ // empty key
1096
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY, context.lastStartLoc, 0);
1097
+ const nextContext = tokenizer.context();
1098
+ const emptyLinkedKeyNode = startNode(7 /* LinkedKey */, nextContext.offset, nextContext.startLoc);
1099
+ emptyLinkedKeyNode.value = '';
1100
+ endNode(emptyLinkedKeyNode, nextContext.offset, nextContext.startLoc);
1101
+ linkedNode.key = emptyLinkedKeyNode;
1102
+ endNode(linkedNode, nextContext.offset, nextContext.startLoc);
1103
+ return {
1104
+ nextConsumeToken: token,
1105
+ node: linkedNode
1106
+ };
1107
+ }
1108
+ endNode(linkedNode, tokenizer.currentOffset(), tokenizer.currentPosition());
1109
+ return {
1110
+ node: linkedNode
1111
+ };
1112
+ }
1113
+ function parseMessage(tokenizer) {
1114
+ const context = tokenizer.context();
1115
+ const startOffset = context.currentType === 1 /* Pipe */
1116
+ ? tokenizer.currentOffset()
1117
+ : context.offset;
1118
+ const startLoc = context.currentType === 1 /* Pipe */
1119
+ ? context.endLoc
1120
+ : context.startLoc;
1121
+ const node = startNode(2 /* Message */, startOffset, startLoc);
1122
+ node.items = [];
1123
+ let nextToken = null;
1124
+ do {
1125
+ const token = nextToken || tokenizer.nextToken();
1126
+ nextToken = null;
1127
+ switch (token.type) {
1128
+ case 0 /* Text */:
1129
+ if (token.value == null) {
1130
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1131
+ }
1132
+ node.items.push(parseText(tokenizer, token.value || ''));
1133
+ break;
1134
+ case 6 /* List */:
1135
+ if (token.value == null) {
1136
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1137
+ }
1138
+ node.items.push(parseList(tokenizer, token.value || ''));
1139
+ break;
1140
+ case 5 /* Named */:
1141
+ if (token.value == null) {
1142
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1143
+ }
1144
+ node.items.push(parseNamed(tokenizer, token.value || ''));
1145
+ break;
1146
+ case 7 /* Literal */:
1147
+ if (token.value == null) {
1148
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1149
+ }
1150
+ node.items.push(parseLiteral(tokenizer, token.value || ''));
1151
+ break;
1152
+ case 8 /* LinkedAlias */:
1153
+ const parsed = parseLinked(tokenizer);
1154
+ node.items.push(parsed.node);
1155
+ nextToken = parsed.nextConsumeToken || null;
1156
+ break;
1157
+ }
1158
+ } while (context.currentType !== 14 /* EOF */ &&
1159
+ context.currentType !== 1 /* Pipe */);
1160
+ // adjust message node loc
1161
+ const endOffset = context.currentType === 1 /* Pipe */
1162
+ ? context.lastOffset
1163
+ : tokenizer.currentOffset();
1164
+ const endLoc = context.currentType === 1 /* Pipe */
1165
+ ? context.lastEndLoc
1166
+ : tokenizer.currentPosition();
1167
+ endNode(node, endOffset, endLoc);
1168
+ return node;
1169
+ }
1170
+ function parsePlural(tokenizer, offset, loc, msgNode) {
1171
+ const context = tokenizer.context();
1172
+ let hasEmptyMessage = msgNode.items.length === 0;
1173
+ const node = startNode(1 /* Plural */, offset, loc);
1174
+ node.cases = [];
1175
+ node.cases.push(msgNode);
1176
+ do {
1177
+ const msg = parseMessage(tokenizer);
1178
+ if (!hasEmptyMessage) {
1179
+ hasEmptyMessage = msg.items.length === 0;
1180
+ }
1181
+ node.cases.push(msg);
1182
+ } while (context.currentType !== 14 /* EOF */);
1183
+ if (hasEmptyMessage) {
1184
+ emitError(tokenizer, CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL, loc, 0);
1185
+ }
1186
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1187
+ return node;
1188
+ }
1189
+ function parseResource(tokenizer) {
1190
+ const context = tokenizer.context();
1191
+ const { offset, startLoc } = context;
1192
+ const msgNode = parseMessage(tokenizer);
1193
+ if (context.currentType === 14 /* EOF */) {
1194
+ return msgNode;
1195
+ }
1196
+ else {
1197
+ return parsePlural(tokenizer, offset, startLoc, msgNode);
1198
+ }
1199
+ }
1200
+ function parse(source) {
1201
+ const tokenizer = createTokenizer(source, assign({}, options));
1202
+ const context = tokenizer.context();
1203
+ const node = startNode(0 /* Resource */, context.offset, context.startLoc);
1204
+ if (location && node.loc) {
1205
+ node.loc.source = source;
1206
+ }
1207
+ node.body = parseResource(tokenizer);
1208
+ // assert whether achieved to EOF
1209
+ if (context.currentType !== 14 /* EOF */) {
1210
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, source[context.offset] || '');
1211
+ }
1212
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1213
+ return node;
1214
+ }
1215
+ return { parse };
1216
+ }
1217
+ function getTokenCaption(token) {
1218
+ if (token.type === 14 /* EOF */) {
1219
+ return 'EOF';
1220
+ }
1221
+ const name = (token.value || '').replace(/\r?\n/gu, '\\n');
1222
+ return name.length > 10 ? name.slice(0, 9) + '…' : name;
1223
+ }
1224
+
1225
+ function createTransformer(ast, options = {} // eslint-disable-line
1226
+ ) {
1227
+ const _context = {
1228
+ ast,
1229
+ helpers: new Set()
1230
+ };
1231
+ const context = () => _context;
1232
+ const helper = (name) => {
1233
+ _context.helpers.add(name);
1234
+ return name;
1235
+ };
1236
+ return { context, helper };
1237
+ }
1238
+ function traverseNodes(nodes, transformer) {
1239
+ for (let i = 0; i < nodes.length; i++) {
1240
+ traverseNode(nodes[i], transformer);
1241
+ }
1242
+ }
1243
+ function traverseNode(node, transformer) {
1244
+ // TODO: if we need pre-hook of transform, should be implemented to here
1245
+ switch (node.type) {
1246
+ case 1 /* Plural */:
1247
+ traverseNodes(node.cases, transformer);
1248
+ transformer.helper("plural" /* PLURAL */);
1249
+ break;
1250
+ case 2 /* Message */:
1251
+ traverseNodes(node.items, transformer);
1252
+ break;
1253
+ case 6 /* Linked */:
1254
+ const linked = node;
1255
+ traverseNode(linked.key, transformer);
1256
+ transformer.helper("linked" /* LINKED */);
1257
+ break;
1258
+ case 5 /* List */:
1259
+ transformer.helper("interpolate" /* INTERPOLATE */);
1260
+ transformer.helper("list" /* LIST */);
1261
+ break;
1262
+ case 4 /* Named */:
1263
+ transformer.helper("interpolate" /* INTERPOLATE */);
1264
+ transformer.helper("named" /* NAMED */);
1265
+ break;
1266
+ }
1267
+ // TODO: if we need post-hook of transform, should be implemented to here
1268
+ }
1269
+ // transform AST
1270
+ function transform(ast, options = {} // eslint-disable-line
1271
+ ) {
1272
+ const transformer = createTransformer(ast);
1273
+ transformer.helper("normalize" /* NORMALIZE */);
1274
+ // traverse
1275
+ ast.body && traverseNode(ast.body, transformer);
1276
+ // set meta information
1277
+ const context = transformer.context();
1278
+ ast.helpers = Array.from(context.helpers);
1279
+ }
1280
+
1281
+ function createCodeGenerator(ast, options) {
1282
+ const { sourceMap, filename, breakLineCode, needIndent: _needIndent } = options;
1283
+ const _context = {
1284
+ source: ast.loc.source,
1285
+ filename,
1286
+ code: '',
1287
+ column: 1,
1288
+ line: 1,
1289
+ offset: 0,
1290
+ map: undefined,
1291
+ breakLineCode,
1292
+ needIndent: _needIndent,
1293
+ indentLevel: 0
1294
+ };
1295
+ const context = () => _context;
1296
+ function push(code, node) {
1297
+ _context.code += code;
1298
+ }
1299
+ function _newline(n, withBreakLine = true) {
1300
+ const _breakLineCode = withBreakLine ? breakLineCode : '';
1301
+ push(_needIndent ? _breakLineCode + ` `.repeat(n) : _breakLineCode);
1302
+ }
1303
+ function indent(withNewLine = true) {
1304
+ const level = ++_context.indentLevel;
1305
+ withNewLine && _newline(level);
1306
+ }
1307
+ function deindent(withNewLine = true) {
1308
+ const level = --_context.indentLevel;
1309
+ withNewLine && _newline(level);
1310
+ }
1311
+ function newline() {
1312
+ _newline(_context.indentLevel);
1313
+ }
1314
+ const helper = (key) => `_${key}`;
1315
+ const needIndent = () => _context.needIndent;
1316
+ return {
1317
+ context,
1318
+ push,
1319
+ indent,
1320
+ deindent,
1321
+ newline,
1322
+ helper,
1323
+ needIndent
1324
+ };
1325
+ }
1326
+ function generateLinkedNode(generator, node) {
1327
+ const { helper } = generator;
1328
+ generator.push(`${helper("linked" /* LINKED */)}(`);
1329
+ generateNode(generator, node.key);
1330
+ if (node.modifier) {
1331
+ generator.push(`, `);
1332
+ generateNode(generator, node.modifier);
1333
+ }
1334
+ generator.push(`)`);
1335
+ }
1336
+ function generateMessageNode(generator, node) {
1337
+ const { helper, needIndent } = generator;
1338
+ generator.push(`${helper("normalize" /* NORMALIZE */)}([`);
1339
+ generator.indent(needIndent());
1340
+ const length = node.items.length;
1341
+ for (let i = 0; i < length; i++) {
1342
+ generateNode(generator, node.items[i]);
1343
+ if (i === length - 1) {
1344
+ break;
1345
+ }
1346
+ generator.push(', ');
1347
+ }
1348
+ generator.deindent(needIndent());
1349
+ generator.push('])');
1350
+ }
1351
+ function generatePluralNode(generator, node) {
1352
+ const { helper, needIndent } = generator;
1353
+ if (node.cases.length > 1) {
1354
+ generator.push(`${helper("plural" /* PLURAL */)}([`);
1355
+ generator.indent(needIndent());
1356
+ const length = node.cases.length;
1357
+ for (let i = 0; i < length; i++) {
1358
+ generateNode(generator, node.cases[i]);
1359
+ if (i === length - 1) {
1360
+ break;
1361
+ }
1362
+ generator.push(', ');
1363
+ }
1364
+ generator.deindent(needIndent());
1365
+ generator.push(`])`);
1366
+ }
1367
+ }
1368
+ function generateResource(generator, node) {
1369
+ if (node.body) {
1370
+ generateNode(generator, node.body);
1371
+ }
1372
+ else {
1373
+ generator.push('null');
1374
+ }
1375
+ }
1376
+ function generateNode(generator, node) {
1377
+ const { helper } = generator;
1378
+ switch (node.type) {
1379
+ case 0 /* Resource */:
1380
+ generateResource(generator, node);
1381
+ break;
1382
+ case 1 /* Plural */:
1383
+ generatePluralNode(generator, node);
1384
+ break;
1385
+ case 2 /* Message */:
1386
+ generateMessageNode(generator, node);
1387
+ break;
1388
+ case 6 /* Linked */:
1389
+ generateLinkedNode(generator, node);
1390
+ break;
1391
+ case 8 /* LinkedModifier */:
1392
+ generator.push(JSON.stringify(node.value), node);
1393
+ break;
1394
+ case 7 /* LinkedKey */:
1395
+ generator.push(JSON.stringify(node.value), node);
1396
+ break;
1397
+ case 5 /* List */:
1398
+ generator.push(`${helper("interpolate" /* INTERPOLATE */)}(${helper("list" /* LIST */)}(${node.index}))`, node);
1399
+ break;
1400
+ case 4 /* Named */:
1401
+ generator.push(`${helper("interpolate" /* INTERPOLATE */)}(${helper("named" /* NAMED */)}(${JSON.stringify(node.key)}))`, node);
1402
+ break;
1403
+ case 9 /* Literal */:
1404
+ generator.push(JSON.stringify(node.value), node);
1405
+ break;
1406
+ case 3 /* Text */:
1407
+ generator.push(JSON.stringify(node.value), node);
1408
+ break;
1409
+ default:
1410
+ {
1411
+ throw new Error(`unhandled codegen node type: ${node.type}`);
1412
+ }
1413
+ }
1414
+ }
1415
+ // generate code from AST
1416
+ const generate = (ast, options = {} // eslint-disable-line
1417
+ ) => {
1418
+ const mode = isString(options.mode) ? options.mode : 'normal';
1419
+ const filename = isString(options.filename)
1420
+ ? options.filename
1421
+ : 'message.intl';
1422
+ const sourceMap = !!options.sourceMap;
1423
+ // prettier-ignore
1424
+ const breakLineCode = options.breakLineCode != null
1425
+ ? options.breakLineCode
1426
+ : mode === 'arrow'
1427
+ ? ';'
1428
+ : '\n';
1429
+ const needIndent = options.needIndent ? options.needIndent : mode !== 'arrow';
1430
+ const helpers = ast.helpers || [];
1431
+ const generator = createCodeGenerator(ast, {
1432
+ mode,
1433
+ filename,
1434
+ sourceMap,
1435
+ breakLineCode,
1436
+ needIndent
1437
+ });
1438
+ generator.push(mode === 'normal' ? `function __msg__ (ctx) {` : `(ctx) => {`);
1439
+ generator.indent(needIndent);
1440
+ if (helpers.length > 0) {
1441
+ generator.push(`const { ${helpers.map(s => `${s}: _${s}`).join(', ')} } = ctx`);
1442
+ generator.newline();
1443
+ }
1444
+ generator.push(`return `);
1445
+ generateNode(generator, ast);
1446
+ generator.deindent(needIndent);
1447
+ generator.push(`}`);
1448
+ const { code, map } = generator.context();
1449
+ return {
1450
+ ast,
1451
+ code,
1452
+ map: map ? map.toJSON() : undefined // eslint-disable-line @typescript-eslint/no-explicit-any
1453
+ };
1454
+ };
1455
+
1456
+ function baseCompile(source, options = {}) {
1457
+ const assignedOptions = assign({}, options);
1458
+ // parse source codes
1459
+ const parser = createParser(assignedOptions);
1460
+ const ast = parser.parse(source);
1461
+ // transform ASTs
1462
+ transform(ast, assignedOptions);
1463
+ // generate javascript codes
1464
+ return generate(ast, assignedOptions);
1465
+ }
1466
+
1467
+ const pathStateMachine = [];
1468
+ pathStateMachine[0 /* BEFORE_PATH */] = {
1469
+ ["w" /* WORKSPACE */]: [0 /* BEFORE_PATH */],
1470
+ ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
1471
+ ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */],
1472
+ ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */]
1473
+ };
1474
+ pathStateMachine[1 /* IN_PATH */] = {
1475
+ ["w" /* WORKSPACE */]: [1 /* IN_PATH */],
1476
+ ["." /* DOT */]: [2 /* BEFORE_IDENT */],
1477
+ ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */],
1478
+ ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */]
1479
+ };
1480
+ pathStateMachine[2 /* BEFORE_IDENT */] = {
1481
+ ["w" /* WORKSPACE */]: [2 /* BEFORE_IDENT */],
1482
+ ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
1483
+ ["0" /* ZERO */]: [3 /* IN_IDENT */, 0 /* APPEND */]
1484
+ };
1485
+ pathStateMachine[3 /* IN_IDENT */] = {
1486
+ ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
1487
+ ["0" /* ZERO */]: [3 /* IN_IDENT */, 0 /* APPEND */],
1488
+ ["w" /* WORKSPACE */]: [1 /* IN_PATH */, 1 /* PUSH */],
1489
+ ["." /* DOT */]: [2 /* BEFORE_IDENT */, 1 /* PUSH */],
1490
+ ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */, 1 /* PUSH */],
1491
+ ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */, 1 /* PUSH */]
1492
+ };
1493
+ pathStateMachine[4 /* IN_SUB_PATH */] = {
1494
+ ["'" /* SINGLE_QUOTE */]: [5 /* IN_SINGLE_QUOTE */, 0 /* APPEND */],
1495
+ ["\"" /* DOUBLE_QUOTE */]: [6 /* IN_DOUBLE_QUOTE */, 0 /* APPEND */],
1496
+ ["[" /* LEFT_BRACKET */]: [
1497
+ 4 /* IN_SUB_PATH */,
1498
+ 2 /* INC_SUB_PATH_DEPTH */
1499
+ ],
1500
+ ["]" /* RIGHT_BRACKET */]: [1 /* IN_PATH */, 3 /* PUSH_SUB_PATH */],
1501
+ ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
1502
+ ["l" /* ELSE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */]
1503
+ };
1504
+ pathStateMachine[5 /* IN_SINGLE_QUOTE */] = {
1505
+ ["'" /* SINGLE_QUOTE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */],
1506
+ ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
1507
+ ["l" /* ELSE */]: [5 /* IN_SINGLE_QUOTE */, 0 /* APPEND */]
1508
+ };
1509
+ pathStateMachine[6 /* IN_DOUBLE_QUOTE */] = {
1510
+ ["\"" /* DOUBLE_QUOTE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */],
1511
+ ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
1512
+ ["l" /* ELSE */]: [6 /* IN_DOUBLE_QUOTE */, 0 /* APPEND */]
1513
+ };
1514
+ /**
1515
+ * Check if an expression is a literal value.
1516
+ */
1517
+ const literalValueRE = /^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;
1518
+ function isLiteral(exp) {
1519
+ return literalValueRE.test(exp);
1520
+ }
1521
+ /**
1522
+ * Strip quotes from a string
1523
+ */
1524
+ function stripQuotes(str) {
1525
+ const a = str.charCodeAt(0);
1526
+ const b = str.charCodeAt(str.length - 1);
1527
+ return a === b && (a === 0x22 || a === 0x27) ? str.slice(1, -1) : str;
1528
+ }
1529
+ /**
1530
+ * Determine the type of a character in a keypath.
1531
+ */
1532
+ function getPathCharType(ch) {
1533
+ if (ch === undefined || ch === null) {
1534
+ return "o" /* END_OF_FAIL */;
1535
+ }
1536
+ const code = ch.charCodeAt(0);
1537
+ switch (code) {
1538
+ case 0x5b: // [
1539
+ case 0x5d: // ]
1540
+ case 0x2e: // .
1541
+ case 0x22: // "
1542
+ case 0x27: // '
1543
+ return ch;
1544
+ case 0x5f: // _
1545
+ case 0x24: // $
1546
+ case 0x2d: // -
1547
+ return "i" /* IDENT */;
1548
+ case 0x09: // Tab (HT)
1549
+ case 0x0a: // Newline (LF)
1550
+ case 0x0d: // Return (CR)
1551
+ case 0xa0: // No-break space (NBSP)
1552
+ case 0xfeff: // Byte Order Mark (BOM)
1553
+ case 0x2028: // Line Separator (LS)
1554
+ case 0x2029: // Paragraph Separator (PS)
1555
+ return "w" /* WORKSPACE */;
1556
+ }
1557
+ return "i" /* IDENT */;
1558
+ }
1559
+ /**
1560
+ * Format a subPath, return its plain form if it is
1561
+ * a literal string or number. Otherwise prepend the
1562
+ * dynamic indicator (*).
1563
+ */
1564
+ function formatSubPath(path) {
1565
+ const trimmed = path.trim();
1566
+ // invalid leading 0
1567
+ if (path.charAt(0) === '0' && isNaN(parseInt(path))) {
1568
+ return false;
1569
+ }
1570
+ return isLiteral(trimmed)
1571
+ ? stripQuotes(trimmed)
1572
+ : "*" /* ASTARISK */ + trimmed;
1573
+ }
1574
+ /**
1575
+ * Parse a string path into an array of segments
1576
+ */
1577
+ function parse(path) {
1578
+ const keys = [];
1579
+ let index = -1;
1580
+ let mode = 0 /* BEFORE_PATH */;
1581
+ let subPathDepth = 0;
1582
+ let c;
1583
+ let key; // eslint-disable-line
1584
+ let newChar;
1585
+ let type;
1586
+ let transition;
1587
+ let action;
1588
+ let typeMap;
1589
+ const actions = [];
1590
+ actions[0 /* APPEND */] = () => {
1591
+ if (key === undefined) {
1592
+ key = newChar;
1593
+ }
1594
+ else {
1595
+ key += newChar;
1596
+ }
1597
+ };
1598
+ actions[1 /* PUSH */] = () => {
1599
+ if (key !== undefined) {
1600
+ keys.push(key);
1601
+ key = undefined;
1602
+ }
1603
+ };
1604
+ actions[2 /* INC_SUB_PATH_DEPTH */] = () => {
1605
+ actions[0 /* APPEND */]();
1606
+ subPathDepth++;
1607
+ };
1608
+ actions[3 /* PUSH_SUB_PATH */] = () => {
1609
+ if (subPathDepth > 0) {
1610
+ subPathDepth--;
1611
+ mode = 4 /* IN_SUB_PATH */;
1612
+ actions[0 /* APPEND */]();
1613
+ }
1614
+ else {
1615
+ subPathDepth = 0;
1616
+ if (key === undefined) {
1617
+ return false;
1618
+ }
1619
+ key = formatSubPath(key);
1620
+ if (key === false) {
1621
+ return false;
1622
+ }
1623
+ else {
1624
+ actions[1 /* PUSH */]();
1625
+ }
1626
+ }
1627
+ };
1628
+ function maybeUnescapeQuote() {
1629
+ const nextChar = path[index + 1];
1630
+ if ((mode === 5 /* IN_SINGLE_QUOTE */ &&
1631
+ nextChar === "'" /* SINGLE_QUOTE */) ||
1632
+ (mode === 6 /* IN_DOUBLE_QUOTE */ &&
1633
+ nextChar === "\"" /* DOUBLE_QUOTE */)) {
1634
+ index++;
1635
+ newChar = '\\' + nextChar;
1636
+ actions[0 /* APPEND */]();
1637
+ return true;
1638
+ }
1639
+ }
1640
+ while (mode !== null) {
1641
+ index++;
1642
+ c = path[index];
1643
+ if (c === '\\' && maybeUnescapeQuote()) {
1644
+ continue;
1645
+ }
1646
+ type = getPathCharType(c);
1647
+ typeMap = pathStateMachine[mode];
1648
+ transition = typeMap[type] || typeMap["l" /* ELSE */] || 8 /* ERROR */;
1649
+ // check parse error
1650
+ if (transition === 8 /* ERROR */) {
1651
+ return;
1652
+ }
1653
+ mode = transition[0];
1654
+ if (transition[1] !== undefined) {
1655
+ action = actions[transition[1]];
1656
+ if (action) {
1657
+ newChar = c;
1658
+ if (action() === false) {
1659
+ return;
1660
+ }
1661
+ }
1662
+ }
1663
+ // check parse finish
1664
+ if (mode === 7 /* AFTER_PATH */) {
1665
+ return keys;
1666
+ }
1667
+ }
1668
+ }
1669
+ // path token cache
1670
+ const cache = new Map();
1671
+ /**
1672
+ * key-value message resolver
1673
+ *
1674
+ * @remarks
1675
+ * Resolves messages with the key-value structure. Note that messages with a hierarchical structure such as objects cannot be resolved
1676
+ *
1677
+ * @param obj - A target object to be resolved with path
1678
+ * @param path - A {@link Path | path} to resolve the value of message
1679
+ *
1680
+ * @returns A resolved {@link PathValue | path value}
1681
+ *
1682
+ * @VueI18nGeneral
1683
+ */
1684
+ function resolveWithKeyValue(obj, path) {
1685
+ return isObject(obj) ? obj[path] : null;
1686
+ }
1687
+ /**
1688
+ * message resolver
1689
+ *
1690
+ * @remarks
1691
+ * Resolves messages. messages with a hierarchical structure such as objects can be resolved. This resolver is used in VueI18n as default.
1692
+ *
1693
+ * @param obj - A target object to be resolved with path
1694
+ * @param path - A {@link Path | path} to resolve the value of message
1695
+ *
1696
+ * @returns A resolved {@link PathValue | path value}
1697
+ *
1698
+ * @VueI18nGeneral
1699
+ */
1700
+ function resolveValue(obj, path) {
1701
+ // check object
1702
+ if (!isObject(obj)) {
1703
+ return null;
1704
+ }
1705
+ // parse path
1706
+ let hit = cache.get(path);
1707
+ if (!hit) {
1708
+ hit = parse(path);
1709
+ if (hit) {
1710
+ cache.set(path, hit);
1711
+ }
1712
+ }
1713
+ // check hit
1714
+ if (!hit) {
1715
+ return null;
1716
+ }
1717
+ // resolve path value
1718
+ const len = hit.length;
1719
+ let last = obj;
1720
+ let i = 0;
1721
+ while (i < len) {
1722
+ const val = last[hit[i]];
1723
+ if (val === undefined) {
1724
+ return null;
1725
+ }
1726
+ last = val;
1727
+ i++;
1728
+ }
1729
+ return last;
1730
+ }
1731
+
1732
+ const DEFAULT_MODIFIER = (str) => str;
1733
+ const DEFAULT_MESSAGE = (ctx) => ''; // eslint-disable-line
1734
+ const DEFAULT_MESSAGE_DATA_TYPE = 'text';
1735
+ const DEFAULT_NORMALIZE = (values) => values.length === 0 ? '' : values.join('');
1736
+ const DEFAULT_INTERPOLATE = toDisplayString;
1737
+ function pluralDefault(choice, choicesLength) {
1738
+ choice = Math.abs(choice);
1739
+ if (choicesLength === 2) {
1740
+ // prettier-ignore
1741
+ return choice
1742
+ ? choice > 1
1743
+ ? 1
1744
+ : 0
1745
+ : 1;
1746
+ }
1747
+ return choice ? Math.min(choice, 2) : 0;
1748
+ }
1749
+ function getPluralIndex(options) {
1750
+ // prettier-ignore
1751
+ const index = isNumber(options.pluralIndex)
1752
+ ? options.pluralIndex
1753
+ : -1;
1754
+ // prettier-ignore
1755
+ return options.named && (isNumber(options.named.count) || isNumber(options.named.n))
1756
+ ? isNumber(options.named.count)
1757
+ ? options.named.count
1758
+ : isNumber(options.named.n)
1759
+ ? options.named.n
1760
+ : index
1761
+ : index;
1762
+ }
1763
+ function normalizeNamed(pluralIndex, props) {
1764
+ if (!props.count) {
1765
+ props.count = pluralIndex;
1766
+ }
1767
+ if (!props.n) {
1768
+ props.n = pluralIndex;
1769
+ }
1770
+ }
1771
+ function createMessageContext(options = {}) {
1772
+ const locale = options.locale;
1773
+ const pluralIndex = getPluralIndex(options);
1774
+ const pluralRule = isObject(options.pluralRules) &&
1775
+ isString(locale) &&
1776
+ isFunction(options.pluralRules[locale])
1777
+ ? options.pluralRules[locale]
1778
+ : pluralDefault;
1779
+ const orgPluralRule = isObject(options.pluralRules) &&
1780
+ isString(locale) &&
1781
+ isFunction(options.pluralRules[locale])
1782
+ ? pluralDefault
1783
+ : undefined;
1784
+ const plural = (messages) => messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
1785
+ const _list = options.list || [];
1786
+ const list = (index) => _list[index];
1787
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1788
+ const _named = options.named || {};
1789
+ isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
1790
+ const named = (key) => _named[key];
1791
+ // TODO: need to design resolve message function?
1792
+ function message(key) {
1793
+ // prettier-ignore
1794
+ const msg = isFunction(options.messages)
1795
+ ? options.messages(key)
1796
+ : isObject(options.messages)
1797
+ ? options.messages[key]
1798
+ : false;
1799
+ return !msg
1800
+ ? options.parent
1801
+ ? options.parent.message(key) // resolve from parent messages
1802
+ : DEFAULT_MESSAGE
1803
+ : msg;
1804
+ }
1805
+ const _modifier = (name) => options.modifiers
1806
+ ? options.modifiers[name]
1807
+ : DEFAULT_MODIFIER;
1808
+ const normalize = isPlainObject(options.processor) && isFunction(options.processor.normalize)
1809
+ ? options.processor.normalize
1810
+ : DEFAULT_NORMALIZE;
1811
+ const interpolate = isPlainObject(options.processor) &&
1812
+ isFunction(options.processor.interpolate)
1813
+ ? options.processor.interpolate
1814
+ : DEFAULT_INTERPOLATE;
1815
+ const type = isPlainObject(options.processor) && isString(options.processor.type)
1816
+ ? options.processor.type
1817
+ : DEFAULT_MESSAGE_DATA_TYPE;
1818
+ const ctx = {
1819
+ ["list" /* LIST */]: list,
1820
+ ["named" /* NAMED */]: named,
1821
+ ["plural" /* PLURAL */]: plural,
1822
+ ["linked" /* LINKED */]: (key, modifier) => {
1823
+ // TODO: should check `key`
1824
+ const msg = message(key)(ctx);
1825
+ return isString(modifier) ? _modifier(modifier)(msg) : msg;
1826
+ },
1827
+ ["message" /* MESSAGE */]: message,
1828
+ ["type" /* TYPE */]: type,
1829
+ ["interpolate" /* INTERPOLATE */]: interpolate,
1830
+ ["normalize" /* NORMALIZE */]: normalize
1831
+ };
1832
+ return ctx;
1833
+ }
1834
+
1835
+ const IntlifyDevToolsHooks = {
1836
+ I18nInit: 'i18n:init',
1837
+ FunctionTranslate: 'function:translate'
1838
+ };
1839
+
1840
+ let devtools = null;
1841
+ function setDevToolsHook(hook) {
1842
+ devtools = hook;
1843
+ }
1844
+ function getDevToolsHook() {
1845
+ return devtools;
1846
+ }
1847
+ function initI18nDevTools(i18n, version, meta) {
1848
+ // TODO: queue if devtools is undefined
1849
+ devtools &&
1850
+ devtools.emit(IntlifyDevToolsHooks.I18nInit, {
1851
+ timestamp: Date.now(),
1852
+ i18n,
1853
+ version,
1854
+ meta
1855
+ });
1856
+ }
1857
+ const translateDevTools = /* #__PURE__*/ createDevToolsHook(IntlifyDevToolsHooks.FunctionTranslate);
1858
+ function createDevToolsHook(hook) {
1859
+ return (payloads) => devtools && devtools.emit(hook, payloads);
1860
+ }
1861
+
1862
+ const CoreWarnCodes = {
1863
+ NOT_FOUND_KEY: 1,
1864
+ FALLBACK_TO_TRANSLATE: 2,
1865
+ CANNOT_FORMAT_NUMBER: 3,
1866
+ FALLBACK_TO_NUMBER_FORMAT: 4,
1867
+ CANNOT_FORMAT_DATE: 5,
1868
+ FALLBACK_TO_DATE_FORMAT: 6,
1869
+ __EXTEND_POINT__: 7
1870
+ };
1871
+ /** @internal */
1872
+ const warnMessages = {
1873
+ [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale messages.`,
1874
+ [CoreWarnCodes.FALLBACK_TO_TRANSLATE]: `Fall back to translate '{key}' key with '{target}' locale.`,
1875
+ [CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
1876
+ [CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
1877
+ [CoreWarnCodes.CANNOT_FORMAT_DATE]: `Cannot format a date value due to not supported Intl.DateTimeFormat.`,
1878
+ [CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale.`
1879
+ };
1880
+ function getWarnMessage(code, ...args) {
1881
+ return format(warnMessages[code], ...args);
1882
+ }
1883
+
1884
+ /**
1885
+ * Fallback with simple implemenation
1886
+ *
1887
+ * @remarks
1888
+ * A fallback locale function implemented with a simple fallback algorithm.
1889
+ *
1890
+ * Basically, it returns the value as specified in the `fallbackLocale` props, and is processed with the fallback inside intlify.
1891
+ *
1892
+ * @param ctx - A {@link CoreContext | context}
1893
+ * @param fallback - A {@link FallbackLocale | fallback locale}
1894
+ * @param start - A starting {@link Locale | locale}
1895
+ *
1896
+ * @returns Fallback locales
1897
+ *
1898
+ * @VueI18nGeneral
1899
+ */
1900
+ function fallbackWithSimple(ctx, fallback, start // eslint-disable-line @typescript-eslint/no-unused-vars
1901
+ ) {
1902
+ // prettier-ignore
1903
+ return [...new Set([
1904
+ start,
1905
+ ...(isArray(fallback)
1906
+ ? fallback
1907
+ : isObject(fallback)
1908
+ ? Object.keys(fallback)
1909
+ : isString(fallback)
1910
+ ? [fallback]
1911
+ : [start])
1912
+ ])];
1913
+ }
1914
+ /**
1915
+ * Fallback with locale chain
1916
+ *
1917
+ * @remarks
1918
+ * A fallback locale function implemented with a fallback chain algorithm. It's used in VueI18n as default.
1919
+ *
1920
+ * @param ctx - A {@link CoreContext | context}
1921
+ * @param fallback - A {@link FallbackLocale | fallback locale}
1922
+ * @param start - A starting {@link Locale | locale}
1923
+ *
1924
+ * @returns Fallback locales
1925
+ *
1926
+ * @VueI18nSee [Fallbacking](../guide/essentials/fallback)
1927
+ *
1928
+ * @VueI18nGeneral
1929
+ */
1930
+ function fallbackWithLocaleChain(ctx, fallback, start) {
1931
+ const startLocale = isString(start) ? start : DEFAULT_LOCALE;
1932
+ const context = ctx;
1933
+ if (!context.__localeChainCache) {
1934
+ context.__localeChainCache = new Map();
1935
+ }
1936
+ let chain = context.__localeChainCache.get(startLocale);
1937
+ if (!chain) {
1938
+ chain = [];
1939
+ // first block defined by start
1940
+ let block = [start];
1941
+ // while any intervening block found
1942
+ while (isArray(block)) {
1943
+ block = appendBlockToChain(chain, block, fallback);
1944
+ }
1945
+ // prettier-ignore
1946
+ // last block defined by default
1947
+ const defaults = isArray(fallback) || !isPlainObject(fallback)
1948
+ ? fallback
1949
+ : fallback['default']
1950
+ ? fallback['default']
1951
+ : null;
1952
+ // convert defaults to array
1953
+ block = isString(defaults) ? [defaults] : defaults;
1954
+ if (isArray(block)) {
1955
+ appendBlockToChain(chain, block, false);
1956
+ }
1957
+ context.__localeChainCache.set(startLocale, chain);
1958
+ }
1959
+ return chain;
1960
+ }
1961
+ function appendBlockToChain(chain, block, blocks) {
1962
+ let follow = true;
1963
+ for (let i = 0; i < block.length && isBoolean(follow); i++) {
1964
+ const locale = block[i];
1965
+ if (isString(locale)) {
1966
+ follow = appendLocaleToChain(chain, block[i], blocks);
1967
+ }
1968
+ }
1969
+ return follow;
1970
+ }
1971
+ function appendLocaleToChain(chain, locale, blocks) {
1972
+ let follow;
1973
+ const tokens = locale.split('-');
1974
+ do {
1975
+ const target = tokens.join('-');
1976
+ follow = appendItemToChain(chain, target, blocks);
1977
+ tokens.splice(-1, 1);
1978
+ } while (tokens.length && follow === true);
1979
+ return follow;
1980
+ }
1981
+ function appendItemToChain(chain, target, blocks) {
1982
+ let follow = false;
1983
+ if (!chain.includes(target)) {
1984
+ follow = true;
1985
+ if (target) {
1986
+ follow = target[target.length - 1] !== '!';
1987
+ const locale = target.replace(/!/g, '');
1988
+ chain.push(locale);
1989
+ if ((isArray(blocks) || isPlainObject(blocks)) &&
1990
+ blocks[locale] // eslint-disable-line @typescript-eslint/no-explicit-any
1991
+ ) {
1992
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1993
+ follow = blocks[locale];
1994
+ }
1995
+ }
1996
+ }
1997
+ return follow;
1998
+ }
1999
+
2000
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2001
+ /**
2002
+ * Intlify core-base version
2003
+ * @internal
2004
+ */
2005
+ const VERSION = '9.2.0-beta.10';
2006
+ const NOT_REOSLVED = -1;
2007
+ const DEFAULT_LOCALE = 'en-US';
2008
+ const MISSING_RESOLVE_VALUE = '';
2009
+ function getDefaultLinkedModifiers() {
2010
+ return {
2011
+ upper: (val) => (isString(val) ? val.toUpperCase() : val),
2012
+ lower: (val) => (isString(val) ? val.toLowerCase() : val),
2013
+ // prettier-ignore
2014
+ capitalize: (val) => (isString(val)
2015
+ ? `${val.charAt(0).toLocaleUpperCase()}${val.substr(1)}`
2016
+ : val)
2017
+ };
2018
+ }
2019
+ let _compiler;
2020
+ function registerMessageCompiler(compiler) {
2021
+ _compiler = compiler;
2022
+ }
2023
+ let _resolver;
2024
+ /**
2025
+ * Register the message resolver
2026
+ *
2027
+ * @param resolver - A {@link MessageResolver} function
2028
+ *
2029
+ * @VueI18nGeneral
2030
+ */
2031
+ function registerMessageResolver(resolver) {
2032
+ _resolver = resolver;
2033
+ }
2034
+ let _fallbacker;
2035
+ /**
2036
+ * Register the locale fallbacker
2037
+ *
2038
+ * @param fallbacker - A {@link LocaleFallbacker} function
2039
+ *
2040
+ * @VueI18nGeneral
2041
+ */
2042
+ function registerLocaleFallbacker(fallbacker) {
2043
+ _fallbacker = fallbacker;
2044
+ }
2045
+ // Additional Meta for Intlify DevTools
2046
+ let _additionalMeta = null;
2047
+ const setAdditionalMeta = (meta) => {
2048
+ _additionalMeta = meta;
2049
+ };
2050
+ const getAdditionalMeta = () => _additionalMeta;
2051
+ // ID for CoreContext
2052
+ let _cid = 0;
2053
+ function createCoreContext(options = {}) {
2054
+ // setup options
2055
+ const version = isString(options.version) ? options.version : VERSION;
2056
+ const locale = isString(options.locale) ? options.locale : DEFAULT_LOCALE;
2057
+ const fallbackLocale = isArray(options.fallbackLocale) ||
2058
+ isPlainObject(options.fallbackLocale) ||
2059
+ isString(options.fallbackLocale) ||
2060
+ options.fallbackLocale === false
2061
+ ? options.fallbackLocale
2062
+ : locale;
2063
+ const messages = isPlainObject(options.messages)
2064
+ ? options.messages
2065
+ : { [locale]: {} };
2066
+ const datetimeFormats = isPlainObject(options.datetimeFormats)
2067
+ ? options.datetimeFormats
2068
+ : { [locale]: {} }
2069
+ ;
2070
+ const numberFormats = isPlainObject(options.numberFormats)
2071
+ ? options.numberFormats
2072
+ : { [locale]: {} }
2073
+ ;
2074
+ const modifiers = assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
2075
+ const pluralRules = options.pluralRules || {};
2076
+ const missing = isFunction(options.missing) ? options.missing : null;
2077
+ const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
2078
+ ? options.missingWarn
2079
+ : true;
2080
+ const fallbackWarn = isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
2081
+ ? options.fallbackWarn
2082
+ : true;
2083
+ const fallbackFormat = !!options.fallbackFormat;
2084
+ const unresolving = !!options.unresolving;
2085
+ const postTranslation = isFunction(options.postTranslation)
2086
+ ? options.postTranslation
2087
+ : null;
2088
+ const processor = isPlainObject(options.processor) ? options.processor : null;
2089
+ const warnHtmlMessage = isBoolean(options.warnHtmlMessage)
2090
+ ? options.warnHtmlMessage
2091
+ : true;
2092
+ const escapeParameter = !!options.escapeParameter;
2093
+ const messageCompiler = isFunction(options.messageCompiler)
2094
+ ? options.messageCompiler
2095
+ : _compiler;
2096
+ const messageResolver = isFunction(options.messageResolver)
2097
+ ? options.messageResolver
2098
+ : _resolver || resolveWithKeyValue;
2099
+ const localeFallbacker = isFunction(options.localeFallbacker)
2100
+ ? options.localeFallbacker
2101
+ : _fallbacker || fallbackWithSimple;
2102
+ const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
2103
+ // setup internal options
2104
+ const internalOptions = options;
2105
+ const __datetimeFormatters = isObject(internalOptions.__datetimeFormatters)
2106
+ ? internalOptions.__datetimeFormatters
2107
+ : new Map()
2108
+ ;
2109
+ const __numberFormatters = isObject(internalOptions.__numberFormatters)
2110
+ ? internalOptions.__numberFormatters
2111
+ : new Map()
2112
+ ;
2113
+ const __meta = isObject(internalOptions.__meta) ? internalOptions.__meta : {};
2114
+ _cid++;
2115
+ const context = {
2116
+ version,
2117
+ cid: _cid,
2118
+ locale,
2119
+ fallbackLocale,
2120
+ messages,
2121
+ modifiers,
2122
+ pluralRules,
2123
+ missing,
2124
+ missingWarn,
2125
+ fallbackWarn,
2126
+ fallbackFormat,
2127
+ unresolving,
2128
+ postTranslation,
2129
+ processor,
2130
+ warnHtmlMessage,
2131
+ escapeParameter,
2132
+ messageCompiler,
2133
+ messageResolver,
2134
+ localeFallbacker,
2135
+ onWarn,
2136
+ __meta
2137
+ };
2138
+ {
2139
+ context.datetimeFormats = datetimeFormats;
2140
+ context.numberFormats = numberFormats;
2141
+ context.__datetimeFormatters = __datetimeFormatters;
2142
+ context.__numberFormatters = __numberFormatters;
2143
+ }
2144
+ // for vue-devtools timeline event
2145
+ {
2146
+ context.__v_emitter =
2147
+ internalOptions.__v_emitter != null
2148
+ ? internalOptions.__v_emitter
2149
+ : undefined;
2150
+ }
2151
+ // NOTE: experimental !!
2152
+ {
2153
+ initI18nDevTools(context, version, __meta);
2154
+ }
2155
+ return context;
2156
+ }
2157
+ /** @internal */
2158
+ function isTranslateFallbackWarn(fallback, key) {
2159
+ return fallback instanceof RegExp ? fallback.test(key) : fallback;
2160
+ }
2161
+ /** @internal */
2162
+ function isTranslateMissingWarn(missing, key) {
2163
+ return missing instanceof RegExp ? missing.test(key) : missing;
2164
+ }
2165
+ /** @internal */
2166
+ function handleMissing(context, key, locale, missingWarn, type) {
2167
+ const { missing, onWarn } = context;
2168
+ // for vue-devtools timeline event
2169
+ {
2170
+ const emitter = context.__v_emitter;
2171
+ if (emitter) {
2172
+ emitter.emit("missing" /* MISSING */, {
2173
+ locale,
2174
+ key,
2175
+ type,
2176
+ groupId: `${type}:${key}`
2177
+ });
2178
+ }
2179
+ }
2180
+ if (missing !== null) {
2181
+ const ret = missing(context, locale, key, type);
2182
+ return isString(ret) ? ret : key;
2183
+ }
2184
+ else {
2185
+ if (isTranslateMissingWarn(missingWarn, key)) {
2186
+ onWarn(getWarnMessage(CoreWarnCodes.NOT_FOUND_KEY, { key, locale }));
2187
+ }
2188
+ return key;
2189
+ }
2190
+ }
2191
+ /** @internal */
2192
+ function updateFallbackLocale(ctx, locale, fallback) {
2193
+ const context = ctx;
2194
+ context.__localeChainCache = new Map();
2195
+ ctx.localeFallbacker(ctx, fallback, locale);
2196
+ }
2197
+ /* eslint-enable @typescript-eslint/no-explicit-any */
2198
+
2199
+ const RE_HTML_TAG = /<\/?[\w\s="/.':;#-\/]+>/;
2200
+ const WARN_MESSAGE = `Detected HTML in '{source}' message. Recommend not using HTML messages to avoid XSS.`;
2201
+ function checkHtmlMessage(source, options) {
2202
+ const warnHtmlMessage = isBoolean(options.warnHtmlMessage)
2203
+ ? options.warnHtmlMessage
2204
+ : true;
2205
+ if (warnHtmlMessage && RE_HTML_TAG.test(source)) {
2206
+ warn(format(WARN_MESSAGE, { source }));
2207
+ }
2208
+ }
2209
+ const defaultOnCacheKey = (source) => source;
2210
+ let compileCache = Object.create(null);
2211
+ function clearCompileCache() {
2212
+ compileCache = Object.create(null);
2213
+ }
2214
+ function compileToFunction(source, options = {}) {
2215
+ {
2216
+ // check HTML message
2217
+ checkHtmlMessage(source, options);
2218
+ // check caches
2219
+ const onCacheKey = options.onCacheKey || defaultOnCacheKey;
2220
+ const key = onCacheKey(source);
2221
+ const cached = compileCache[key];
2222
+ if (cached) {
2223
+ return cached;
2224
+ }
2225
+ // compile error detecting
2226
+ let occurred = false;
2227
+ const onError = options.onError || defaultOnError;
2228
+ options.onError = (err) => {
2229
+ occurred = true;
2230
+ onError(err);
2231
+ };
2232
+ // compile
2233
+ const { code } = baseCompile(source, options);
2234
+ // evaluate function
2235
+ const msg = new Function(`return ${code}`)();
2236
+ // if occurred compile error, don't cache
2237
+ return !occurred ? (compileCache[key] = msg) : msg;
2238
+ }
2239
+ }
2240
+
2241
+ let code = CompileErrorCodes.__EXTEND_POINT__;
2242
+ const inc = () => code++;
2243
+ const CoreErrorCodes = {
2244
+ INVALID_ARGUMENT: code,
2245
+ INVALID_DATE_ARGUMENT: inc(),
2246
+ INVALID_ISO_DATE_ARGUMENT: inc(),
2247
+ __EXTEND_POINT__: inc() // 18
2248
+ };
2249
+ function createCoreError(code) {
2250
+ return createCompileError(code, null, { messages: errorMessages } );
2251
+ }
2252
+ /** @internal */
2253
+ const errorMessages = {
2254
+ [CoreErrorCodes.INVALID_ARGUMENT]: 'Invalid arguments',
2255
+ [CoreErrorCodes.INVALID_DATE_ARGUMENT]: 'The date provided is an invalid Date object.' +
2256
+ 'Make sure your Date represents a valid date.',
2257
+ [CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT]: 'The argument provided is not a valid ISO date string'
2258
+ };
2259
+
2260
+ const NOOP_MESSAGE_FUNCTION = () => '';
2261
+ const isMessageFunction = (val) => isFunction(val);
2262
+ // implementation of `translate` function
2263
+ function translate(context, ...args) {
2264
+ const { fallbackFormat, postTranslation, unresolving, fallbackLocale, messages } = context;
2265
+ const [key, options] = parseTranslateArgs(...args);
2266
+ const missingWarn = isBoolean(options.missingWarn)
2267
+ ? options.missingWarn
2268
+ : context.missingWarn;
2269
+ const fallbackWarn = isBoolean(options.fallbackWarn)
2270
+ ? options.fallbackWarn
2271
+ : context.fallbackWarn;
2272
+ const escapeParameter = isBoolean(options.escapeParameter)
2273
+ ? options.escapeParameter
2274
+ : context.escapeParameter;
2275
+ const resolvedMessage = !!options.resolvedMessage;
2276
+ // prettier-ignore
2277
+ const defaultMsgOrKey = isString(options.default) || isBoolean(options.default) // default by function option
2278
+ ? !isBoolean(options.default)
2279
+ ? options.default
2280
+ : key
2281
+ : fallbackFormat // default by `fallbackFormat` option
2282
+ ? key
2283
+ : '';
2284
+ const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== '';
2285
+ const locale = isString(options.locale) ? options.locale : context.locale;
2286
+ // escape params
2287
+ escapeParameter && escapeParams(options);
2288
+ // resolve message format
2289
+ // eslint-disable-next-line prefer-const
2290
+ let [format, targetLocale, message] = !resolvedMessage
2291
+ ? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn)
2292
+ : [
2293
+ key,
2294
+ locale,
2295
+ messages[locale] || {}
2296
+ ];
2297
+ // if you use default message, set it as message format!
2298
+ let cacheBaseKey = key;
2299
+ if (!resolvedMessage &&
2300
+ !(isString(format) || isMessageFunction(format))) {
2301
+ if (enableDefaultMsg) {
2302
+ format = defaultMsgOrKey;
2303
+ cacheBaseKey = format;
2304
+ }
2305
+ }
2306
+ // checking message format and target locale
2307
+ if (!resolvedMessage &&
2308
+ (!(isString(format) || isMessageFunction(format)) ||
2309
+ !isString(targetLocale))) {
2310
+ return unresolving ? NOT_REOSLVED : key;
2311
+ }
2312
+ if (isString(format) && context.messageCompiler == null) {
2313
+ warn(`The message format compilation is not supported in this build. ` +
2314
+ `Because message compiler isn't included. ` +
2315
+ `You need to pre-compilation all message format. ` +
2316
+ `So translate function return '${key}'.`);
2317
+ return key;
2318
+ }
2319
+ // setup compile error detecting
2320
+ let occurred = false;
2321
+ const errorDetector = () => {
2322
+ occurred = true;
2323
+ };
2324
+ // compile message format
2325
+ const msg = !isMessageFunction(format)
2326
+ ? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector)
2327
+ : format;
2328
+ // if occurred compile error, return the message format
2329
+ if (occurred) {
2330
+ return format;
2331
+ }
2332
+ // evaluate message with context
2333
+ const ctxOptions = getMessageContextOptions(context, targetLocale, message, options);
2334
+ const msgContext = createMessageContext(ctxOptions);
2335
+ const messaged = evaluateMessage(context, msg, msgContext);
2336
+ // if use post translation option, proceed it with handler
2337
+ const ret = postTranslation ? postTranslation(messaged) : messaged;
2338
+ // NOTE: experimental !!
2339
+ {
2340
+ // prettier-ignore
2341
+ const payloads = {
2342
+ timestamp: Date.now(),
2343
+ key: isString(key)
2344
+ ? key
2345
+ : isMessageFunction(format)
2346
+ ? format.key
2347
+ : '',
2348
+ locale: targetLocale || (isMessageFunction(format)
2349
+ ? format.locale
2350
+ : ''),
2351
+ format: isString(format)
2352
+ ? format
2353
+ : isMessageFunction(format)
2354
+ ? format.source
2355
+ : '',
2356
+ message: ret
2357
+ };
2358
+ payloads.meta = assign({}, context.__meta, getAdditionalMeta() || {});
2359
+ translateDevTools(payloads);
2360
+ }
2361
+ return ret;
2362
+ }
2363
+ function escapeParams(options) {
2364
+ if (isArray(options.list)) {
2365
+ options.list = options.list.map(item => isString(item) ? escapeHtml(item) : item);
2366
+ }
2367
+ else if (isObject(options.named)) {
2368
+ Object.keys(options.named).forEach(key => {
2369
+ if (isString(options.named[key])) {
2370
+ options.named[key] = escapeHtml(options.named[key]);
2371
+ }
2372
+ });
2373
+ }
2374
+ }
2375
+ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
2376
+ const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
2377
+ const locales = localeFallbacker(context, fallbackLocale, locale); // eslint-disable-line @typescript-eslint/no-explicit-any
2378
+ let message = {};
2379
+ let targetLocale;
2380
+ let format = null;
2381
+ let from = locale;
2382
+ let to = null;
2383
+ const type = 'translate';
2384
+ for (let i = 0; i < locales.length; i++) {
2385
+ targetLocale = to = locales[i];
2386
+ if (locale !== targetLocale &&
2387
+ isTranslateFallbackWarn(fallbackWarn, key)) {
2388
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_TRANSLATE, {
2389
+ key,
2390
+ target: targetLocale
2391
+ }));
2392
+ }
2393
+ // for vue-devtools timeline event
2394
+ if (locale !== targetLocale) {
2395
+ const emitter = context.__v_emitter;
2396
+ if (emitter) {
2397
+ emitter.emit("fallback" /* FALBACK */, {
2398
+ type,
2399
+ key,
2400
+ from,
2401
+ to,
2402
+ groupId: `${type}:${key}`
2403
+ });
2404
+ }
2405
+ }
2406
+ message =
2407
+ messages[targetLocale] || {};
2408
+ // for vue-devtools timeline event
2409
+ let start = null;
2410
+ let startTag;
2411
+ let endTag;
2412
+ if (inBrowser) {
2413
+ start = window.performance.now();
2414
+ startTag = 'intlify-message-resolve-start';
2415
+ endTag = 'intlify-message-resolve-end';
2416
+ mark && mark(startTag);
2417
+ }
2418
+ if ((format = resolveValue(message, key)) === null) {
2419
+ // if null, resolve with object key path
2420
+ format = message[key]; // eslint-disable-line @typescript-eslint/no-explicit-any
2421
+ }
2422
+ // for vue-devtools timeline event
2423
+ if (inBrowser) {
2424
+ const end = window.performance.now();
2425
+ const emitter = context.__v_emitter;
2426
+ if (emitter && start && format) {
2427
+ emitter.emit("message-resolve" /* MESSAGE_RESOLVE */, {
2428
+ type: "message-resolve" /* MESSAGE_RESOLVE */,
2429
+ key,
2430
+ message: format,
2431
+ time: end - start,
2432
+ groupId: `${type}:${key}`
2433
+ });
2434
+ }
2435
+ if (startTag && endTag && mark && measure) {
2436
+ mark(endTag);
2437
+ measure('intlify message resolve', startTag, endTag);
2438
+ }
2439
+ }
2440
+ if (isString(format) || isFunction(format))
2441
+ break;
2442
+ const missingRet = handleMissing(context, // eslint-disable-line @typescript-eslint/no-explicit-any
2443
+ key, targetLocale, missingWarn, type);
2444
+ if (missingRet !== key) {
2445
+ format = missingRet;
2446
+ }
2447
+ from = to;
2448
+ }
2449
+ return [format, targetLocale, message];
2450
+ }
2451
+ function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector) {
2452
+ const { messageCompiler, warnHtmlMessage } = context;
2453
+ if (isMessageFunction(format)) {
2454
+ const msg = format;
2455
+ msg.locale = msg.locale || targetLocale;
2456
+ msg.key = msg.key || key;
2457
+ return msg;
2458
+ }
2459
+ // for vue-devtools timeline event
2460
+ let start = null;
2461
+ let startTag;
2462
+ let endTag;
2463
+ if (inBrowser) {
2464
+ start = window.performance.now();
2465
+ startTag = 'intlify-message-compilation-start';
2466
+ endTag = 'intlify-message-compilation-end';
2467
+ mark && mark(startTag);
2468
+ }
2469
+ const msg = messageCompiler(format, getCompileOptions(context, targetLocale, cacheBaseKey, format, warnHtmlMessage, errorDetector));
2470
+ // for vue-devtools timeline event
2471
+ if (inBrowser) {
2472
+ const end = window.performance.now();
2473
+ const emitter = context.__v_emitter;
2474
+ if (emitter && start) {
2475
+ emitter.emit("message-compilation" /* MESSAGE_COMPILATION */, {
2476
+ type: "message-compilation" /* MESSAGE_COMPILATION */,
2477
+ message: format,
2478
+ time: end - start,
2479
+ groupId: `${'translate'}:${key}`
2480
+ });
2481
+ }
2482
+ if (startTag && endTag && mark && measure) {
2483
+ mark(endTag);
2484
+ measure('intlify message compilation', startTag, endTag);
2485
+ }
2486
+ }
2487
+ msg.locale = targetLocale;
2488
+ msg.key = key;
2489
+ msg.source = format;
2490
+ return msg;
2491
+ }
2492
+ function evaluateMessage(context, msg, msgCtx) {
2493
+ // for vue-devtools timeline event
2494
+ let start = null;
2495
+ let startTag;
2496
+ let endTag;
2497
+ if (inBrowser) {
2498
+ start = window.performance.now();
2499
+ startTag = 'intlify-message-evaluation-start';
2500
+ endTag = 'intlify-message-evaluation-end';
2501
+ mark && mark(startTag);
2502
+ }
2503
+ const messaged = msg(msgCtx);
2504
+ // for vue-devtools timeline event
2505
+ if (inBrowser) {
2506
+ const end = window.performance.now();
2507
+ const emitter = context.__v_emitter;
2508
+ if (emitter && start) {
2509
+ emitter.emit("message-evaluation" /* MESSAGE_EVALUATION */, {
2510
+ type: "message-evaluation" /* MESSAGE_EVALUATION */,
2511
+ value: messaged,
2512
+ time: end - start,
2513
+ groupId: `${'translate'}:${msg.key}`
2514
+ });
2515
+ }
2516
+ if (startTag && endTag && mark && measure) {
2517
+ mark(endTag);
2518
+ measure('intlify message evaluation', startTag, endTag);
2519
+ }
2520
+ }
2521
+ return messaged;
2522
+ }
2523
+ /** @internal */
2524
+ function parseTranslateArgs(...args) {
2525
+ const [arg1, arg2, arg3] = args;
2526
+ const options = {};
2527
+ if (!isString(arg1) && !isNumber(arg1) && !isMessageFunction(arg1)) {
2528
+ throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
2529
+ }
2530
+ // prettier-ignore
2531
+ const key = isNumber(arg1)
2532
+ ? String(arg1)
2533
+ : isMessageFunction(arg1)
2534
+ ? arg1
2535
+ : arg1;
2536
+ if (isNumber(arg2)) {
2537
+ options.plural = arg2;
2538
+ }
2539
+ else if (isString(arg2)) {
2540
+ options.default = arg2;
2541
+ }
2542
+ else if (isPlainObject(arg2) && !isEmptyObject(arg2)) {
2543
+ options.named = arg2;
2544
+ }
2545
+ else if (isArray(arg2)) {
2546
+ options.list = arg2;
2547
+ }
2548
+ if (isNumber(arg3)) {
2549
+ options.plural = arg3;
2550
+ }
2551
+ else if (isString(arg3)) {
2552
+ options.default = arg3;
2553
+ }
2554
+ else if (isPlainObject(arg3)) {
2555
+ assign(options, arg3);
2556
+ }
2557
+ return [key, options];
2558
+ }
2559
+ function getCompileOptions(context, locale, key, source, warnHtmlMessage, errorDetector) {
2560
+ return {
2561
+ warnHtmlMessage,
2562
+ onError: (err) => {
2563
+ errorDetector && errorDetector(err);
2564
+ {
2565
+ const message = `Message compilation error: ${err.message}`;
2566
+ const codeFrame = err.location &&
2567
+ generateCodeFrame(source, err.location.start.offset, err.location.end.offset);
2568
+ const emitter = context.__v_emitter;
2569
+ if (emitter) {
2570
+ emitter.emit("compile-error" /* COMPILE_ERROR */, {
2571
+ message: source,
2572
+ error: err.message,
2573
+ start: err.location && err.location.start.offset,
2574
+ end: err.location && err.location.end.offset,
2575
+ groupId: `${'translate'}:${key}`
2576
+ });
2577
+ }
2578
+ console.error(codeFrame ? `${message}\n${codeFrame}` : message);
2579
+ }
2580
+ },
2581
+ onCacheKey: (source) => generateFormatCacheKey(locale, key, source)
2582
+ };
2583
+ }
2584
+ function getMessageContextOptions(context, locale, message, options) {
2585
+ const { modifiers, pluralRules, messageResolver: resolveValue } = context;
2586
+ const resolveMessage = (key) => {
2587
+ const val = resolveValue(message, key);
2588
+ if (isString(val)) {
2589
+ let occurred = false;
2590
+ const errorDetector = () => {
2591
+ occurred = true;
2592
+ };
2593
+ const msg = compileMessageFormat(context, key, locale, val, key, errorDetector);
2594
+ return !occurred
2595
+ ? msg
2596
+ : NOOP_MESSAGE_FUNCTION;
2597
+ }
2598
+ else if (isMessageFunction(val)) {
2599
+ return val;
2600
+ }
2601
+ else {
2602
+ // TODO: should be implemented warning message
2603
+ return NOOP_MESSAGE_FUNCTION;
2604
+ }
2605
+ };
2606
+ const ctxOptions = {
2607
+ locale,
2608
+ modifiers,
2609
+ pluralRules,
2610
+ messages: resolveMessage
2611
+ };
2612
+ if (context.processor) {
2613
+ ctxOptions.processor = context.processor;
2614
+ }
2615
+ if (options.list) {
2616
+ ctxOptions.list = options.list;
2617
+ }
2618
+ if (options.named) {
2619
+ ctxOptions.named = options.named;
2620
+ }
2621
+ if (isNumber(options.plural)) {
2622
+ ctxOptions.pluralIndex = options.plural;
2623
+ }
2624
+ return ctxOptions;
2625
+ }
2626
+
2627
+ const intlDefined = typeof Intl !== 'undefined';
2628
+ const Availabilities = {
2629
+ dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined',
2630
+ numberFormat: intlDefined && typeof Intl.NumberFormat !== 'undefined'
2631
+ };
2632
+
2633
+ // implementation of `datetime` function
2634
+ function datetime(context, ...args) {
2635
+ const { datetimeFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
2636
+ const { __datetimeFormatters } = context;
2637
+ if (!Availabilities.dateTimeFormat) {
2638
+ onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
2639
+ return MISSING_RESOLVE_VALUE;
2640
+ }
2641
+ const [key, value, options, overrides] = parseDateTimeArgs(...args);
2642
+ const missingWarn = isBoolean(options.missingWarn)
2643
+ ? options.missingWarn
2644
+ : context.missingWarn;
2645
+ const fallbackWarn = isBoolean(options.fallbackWarn)
2646
+ ? options.fallbackWarn
2647
+ : context.fallbackWarn;
2648
+ const part = !!options.part;
2649
+ const locale = isString(options.locale) ? options.locale : context.locale;
2650
+ const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
2651
+ fallbackLocale, locale);
2652
+ if (!isString(key) || key === '') {
2653
+ return new Intl.DateTimeFormat(locale).format(value);
2654
+ }
2655
+ // resolve format
2656
+ let datetimeFormat = {};
2657
+ let targetLocale;
2658
+ let format = null;
2659
+ let from = locale;
2660
+ let to = null;
2661
+ const type = 'datetime format';
2662
+ for (let i = 0; i < locales.length; i++) {
2663
+ targetLocale = to = locales[i];
2664
+ if (locale !== targetLocale &&
2665
+ isTranslateFallbackWarn(fallbackWarn, key)) {
2666
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DATE_FORMAT, {
2667
+ key,
2668
+ target: targetLocale
2669
+ }));
2670
+ }
2671
+ // for vue-devtools timeline event
2672
+ if (locale !== targetLocale) {
2673
+ const emitter = context.__v_emitter;
2674
+ if (emitter) {
2675
+ emitter.emit("fallback" /* FALBACK */, {
2676
+ type,
2677
+ key,
2678
+ from,
2679
+ to,
2680
+ groupId: `${type}:${key}`
2681
+ });
2682
+ }
2683
+ }
2684
+ datetimeFormat =
2685
+ datetimeFormats[targetLocale] || {};
2686
+ format = datetimeFormat[key];
2687
+ if (isPlainObject(format))
2688
+ break;
2689
+ handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
2690
+ from = to;
2691
+ }
2692
+ // checking format and target locale
2693
+ if (!isPlainObject(format) || !isString(targetLocale)) {
2694
+ return unresolving ? NOT_REOSLVED : key;
2695
+ }
2696
+ let id = `${targetLocale}__${key}`;
2697
+ if (!isEmptyObject(overrides)) {
2698
+ id = `${id}__${JSON.stringify(overrides)}`;
2699
+ }
2700
+ let formatter = __datetimeFormatters.get(id);
2701
+ if (!formatter) {
2702
+ formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
2703
+ __datetimeFormatters.set(id, formatter);
2704
+ }
2705
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
2706
+ }
2707
+ /** @internal */
2708
+ function parseDateTimeArgs(...args) {
2709
+ const [arg1, arg2, arg3, arg4] = args;
2710
+ let options = {};
2711
+ let overrides = {};
2712
+ let value;
2713
+ if (isString(arg1)) {
2714
+ // Only allow ISO strings - other date formats are often supported,
2715
+ // but may cause different results in different browsers.
2716
+ const matches = arg1.match(/(\d{4}-\d{2}-\d{2})(T|\s)?(.*)/);
2717
+ if (!matches) {
2718
+ throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
2719
+ }
2720
+ // Some browsers can not parse the iso datetime separated by space,
2721
+ // this is a compromise solution by replace the 'T'/' ' with 'T'
2722
+ const dateTime = matches[3]
2723
+ ? matches[3].trim().startsWith('T')
2724
+ ? `${matches[1].trim()}${matches[3].trim()}`
2725
+ : `${matches[1].trim()}T${matches[3].trim()}`
2726
+ : matches[1].trim();
2727
+ value = new Date(dateTime);
2728
+ try {
2729
+ // This will fail if the date is not valid
2730
+ value.toISOString();
2731
+ }
2732
+ catch (e) {
2733
+ throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
2734
+ }
2735
+ }
2736
+ else if (isDate(arg1)) {
2737
+ if (isNaN(arg1.getTime())) {
2738
+ throw createCoreError(CoreErrorCodes.INVALID_DATE_ARGUMENT);
2739
+ }
2740
+ value = arg1;
2741
+ }
2742
+ else if (isNumber(arg1)) {
2743
+ value = arg1;
2744
+ }
2745
+ else {
2746
+ throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
2747
+ }
2748
+ if (isString(arg2)) {
2749
+ options.key = arg2;
2750
+ }
2751
+ else if (isPlainObject(arg2)) {
2752
+ options = arg2;
2753
+ }
2754
+ if (isString(arg3)) {
2755
+ options.locale = arg3;
2756
+ }
2757
+ else if (isPlainObject(arg3)) {
2758
+ overrides = arg3;
2759
+ }
2760
+ if (isPlainObject(arg4)) {
2761
+ overrides = arg4;
2762
+ }
2763
+ return [options.key || '', value, options, overrides];
2764
+ }
2765
+ /** @internal */
2766
+ function clearDateTimeFormat(ctx, locale, format) {
2767
+ const context = ctx;
2768
+ for (const key in format) {
2769
+ const id = `${locale}__${key}`;
2770
+ if (!context.__datetimeFormatters.has(id)) {
2771
+ continue;
2772
+ }
2773
+ context.__datetimeFormatters.delete(id);
2774
+ }
2775
+ }
2776
+
2777
+ // implementation of `number` function
2778
+ function number(context, ...args) {
2779
+ const { numberFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
2780
+ const { __numberFormatters } = context;
2781
+ if (!Availabilities.numberFormat) {
2782
+ onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
2783
+ return MISSING_RESOLVE_VALUE;
2784
+ }
2785
+ const [key, value, options, overrides] = parseNumberArgs(...args);
2786
+ const missingWarn = isBoolean(options.missingWarn)
2787
+ ? options.missingWarn
2788
+ : context.missingWarn;
2789
+ const fallbackWarn = isBoolean(options.fallbackWarn)
2790
+ ? options.fallbackWarn
2791
+ : context.fallbackWarn;
2792
+ const part = !!options.part;
2793
+ const locale = isString(options.locale) ? options.locale : context.locale;
2794
+ const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
2795
+ fallbackLocale, locale);
2796
+ if (!isString(key) || key === '') {
2797
+ return new Intl.NumberFormat(locale).format(value);
2798
+ }
2799
+ // resolve format
2800
+ let numberFormat = {};
2801
+ let targetLocale;
2802
+ let format = null;
2803
+ let from = locale;
2804
+ let to = null;
2805
+ const type = 'number format';
2806
+ for (let i = 0; i < locales.length; i++) {
2807
+ targetLocale = to = locales[i];
2808
+ if (locale !== targetLocale &&
2809
+ isTranslateFallbackWarn(fallbackWarn, key)) {
2810
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
2811
+ key,
2812
+ target: targetLocale
2813
+ }));
2814
+ }
2815
+ // for vue-devtools timeline event
2816
+ if (locale !== targetLocale) {
2817
+ const emitter = context.__v_emitter;
2818
+ if (emitter) {
2819
+ emitter.emit("fallback" /* FALBACK */, {
2820
+ type,
2821
+ key,
2822
+ from,
2823
+ to,
2824
+ groupId: `${type}:${key}`
2825
+ });
2826
+ }
2827
+ }
2828
+ numberFormat =
2829
+ numberFormats[targetLocale] || {};
2830
+ format = numberFormat[key];
2831
+ if (isPlainObject(format))
2832
+ break;
2833
+ handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
2834
+ from = to;
2835
+ }
2836
+ // checking format and target locale
2837
+ if (!isPlainObject(format) || !isString(targetLocale)) {
2838
+ return unresolving ? NOT_REOSLVED : key;
2839
+ }
2840
+ let id = `${targetLocale}__${key}`;
2841
+ if (!isEmptyObject(overrides)) {
2842
+ id = `${id}__${JSON.stringify(overrides)}`;
2843
+ }
2844
+ let formatter = __numberFormatters.get(id);
2845
+ if (!formatter) {
2846
+ formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
2847
+ __numberFormatters.set(id, formatter);
2848
+ }
2849
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
2850
+ }
2851
+ /** @internal */
2852
+ function parseNumberArgs(...args) {
2853
+ const [arg1, arg2, arg3, arg4] = args;
2854
+ let options = {};
2855
+ let overrides = {};
2856
+ if (!isNumber(arg1)) {
2857
+ throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
2858
+ }
2859
+ const value = arg1;
2860
+ if (isString(arg2)) {
2861
+ options.key = arg2;
2862
+ }
2863
+ else if (isPlainObject(arg2)) {
2864
+ options = arg2;
2865
+ }
2866
+ if (isString(arg3)) {
2867
+ options.locale = arg3;
2868
+ }
2869
+ else if (isPlainObject(arg3)) {
2870
+ overrides = arg3;
2871
+ }
2872
+ if (isPlainObject(arg4)) {
2873
+ overrides = arg4;
2874
+ }
2875
+ return [options.key || '', value, options, overrides];
2876
+ }
2877
+ /** @internal */
2878
+ function clearNumberFormat(ctx, locale, format) {
2879
+ const context = ctx;
2880
+ for (const key in format) {
2881
+ const id = `${locale}__${key}`;
2882
+ if (!context.__numberFormatters.has(id)) {
2883
+ continue;
2884
+ }
2885
+ context.__numberFormatters.delete(id);
2886
+ }
2887
+ }
2888
+
2889
+ // register message compiler at @intlify/core
2890
+ registerMessageCompiler(compileToFunction);
2891
+ // register message resolver at @intlify/core
2892
+ registerMessageResolver(resolveValue);
2893
+ // register fallback locale at @intlify/core
2894
+ registerLocaleFallbacker(fallbackWithLocaleChain);
2895
+
2896
+ exports.CompileErrorCodes = CompileErrorCodes;
2897
+ exports.CoreErrorCodes = CoreErrorCodes;
2898
+ exports.CoreWarnCodes = CoreWarnCodes;
2899
+ exports.DEFAULT_LOCALE = DEFAULT_LOCALE;
2900
+ exports.DEFAULT_MESSAGE_DATA_TYPE = DEFAULT_MESSAGE_DATA_TYPE;
2901
+ exports.MISSING_RESOLVE_VALUE = MISSING_RESOLVE_VALUE;
2902
+ exports.NOT_REOSLVED = NOT_REOSLVED;
2903
+ exports.VERSION = VERSION;
2904
+ exports.clearCompileCache = clearCompileCache;
2905
+ exports.clearDateTimeFormat = clearDateTimeFormat;
2906
+ exports.clearNumberFormat = clearNumberFormat;
2907
+ exports.compileToFunction = compileToFunction;
2908
+ exports.createCompileError = createCompileError;
2909
+ exports.createCoreContext = createCoreContext;
2910
+ exports.createCoreError = createCoreError;
2911
+ exports.createMessageContext = createMessageContext;
2912
+ exports.datetime = datetime;
2913
+ exports.fallbackWithLocaleChain = fallbackWithLocaleChain;
2914
+ exports.fallbackWithSimple = fallbackWithSimple;
2915
+ exports.getAdditionalMeta = getAdditionalMeta;
2916
+ exports.getDevToolsHook = getDevToolsHook;
2917
+ exports.getWarnMessage = getWarnMessage;
2918
+ exports.handleMissing = handleMissing;
2919
+ exports.initI18nDevTools = initI18nDevTools;
2920
+ exports.isMessageFunction = isMessageFunction;
2921
+ exports.isTranslateFallbackWarn = isTranslateFallbackWarn;
2922
+ exports.isTranslateMissingWarn = isTranslateMissingWarn;
2923
+ exports.number = number;
2924
+ exports.parse = parse;
2925
+ exports.parseDateTimeArgs = parseDateTimeArgs;
2926
+ exports.parseNumberArgs = parseNumberArgs;
2927
+ exports.parseTranslateArgs = parseTranslateArgs;
2928
+ exports.registerLocaleFallbacker = registerLocaleFallbacker;
2929
+ exports.registerMessageCompiler = registerMessageCompiler;
2930
+ exports.registerMessageResolver = registerMessageResolver;
2931
+ exports.resolveValue = resolveValue;
2932
+ exports.resolveWithKeyValue = resolveWithKeyValue;
2933
+ exports.setAdditionalMeta = setAdditionalMeta;
2934
+ exports.setDevToolsHook = setDevToolsHook;
2935
+ exports.translate = translate;
2936
+ exports.translateDevTools = translateDevTools;
2937
+ exports.updateFallbackLocale = updateFallbackLocale;
2938
+
2939
+ Object.defineProperty(exports, '__esModule', { value: true });
2940
+
2941
+ return exports;
2942
+
2943
+ }({}));