@dcloudio/uni-cli-shared 3.0.0-5020320260806002 → 3.0.0-5020420260811002

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.
Files changed (46) hide show
  1. package/dist/resolve.d.ts +8 -0
  2. package/dist/resolve.js +78 -2
  3. package/lib/dom2/@intlify/core-base/LICENSE +20 -0
  4. package/lib/dom2/@intlify/core-base/dist/core-base.mjs +1903 -0
  5. package/lib/dom2/@intlify/core-base/package.json +11 -0
  6. package/lib/dom2/@intlify/message-compiler/LICENSE +20 -0
  7. package/lib/dom2/@intlify/message-compiler/dist/message-compiler.mjs +1550 -0
  8. package/lib/dom2/@intlify/message-compiler/package.json +11 -0
  9. package/lib/dom2/@intlify/shared/LICENSE +20 -0
  10. package/lib/dom2/@intlify/shared/dist/shared.mjs +333 -0
  11. package/lib/dom2/@intlify/shared/package.json +11 -0
  12. package/lib/dom2/@vue/devtools-api/LICENSE +21 -0
  13. package/lib/dom2/@vue/devtools-api/dist/index.js +26 -0
  14. package/lib/dom2/@vue/devtools-api/package.json +12 -0
  15. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.js +71 -68
  16. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.prod.js +71 -68
  17. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.d.ts +2 -20
  18. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.esm-bundler.js +53 -29
  19. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.js +23 -12
  20. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +22 -12
  21. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +80 -30
  22. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +5 -5
  23. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +20 -3
  24. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.js +369 -317
  25. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.prod.js +5 -5
  26. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +2032 -5522
  27. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.d.ts +11114 -33
  28. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +2825 -4668
  29. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.cjs.js +905 -2413
  30. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.d.ts +378 -544
  31. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.esm-browser.js +998 -2549
  32. package/lib/dom2/app/@vue/compiler-vapor-dom2/dist/compiler-vapor-dom2.cjs.js +1 -1
  33. package/lib/dom2/app/@vue/shared/dist/shared.cjs.js +26 -92
  34. package/lib/dom2/app/@vue/shared/dist/shared.cjs.prod.js +26 -92
  35. package/lib/dom2/app/@vue/shared/dist/shared.d.ts +2 -94
  36. package/lib/dom2/app/@vue/shared/dist/shared.esm-bundler.js +24 -83
  37. package/lib/dom2/pinia/LICENSE +21 -0
  38. package/lib/dom2/pinia/dist/pinia.mjs +1941 -0
  39. package/lib/dom2/pinia/package.json +11 -0
  40. package/lib/dom2/vue-i18n/LICENSE +20 -0
  41. package/lib/dom2/vue-i18n/dist/vue-i18n.esm-bundler.js +1 -0
  42. package/lib/dom2/vue-i18n/dist/vue-i18n.mjs +2501 -0
  43. package/lib/dom2/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js +1 -0
  44. package/lib/dom2/vue-i18n/dist/vue-i18n.runtime.mjs +2501 -0
  45. package/lib/dom2/vue-i18n/package.json +12 -0
  46. package/package.json +5 -5
@@ -0,0 +1,1550 @@
1
+ /*!
2
+ * message-compiler v11.4.6
3
+ * (c) 2026 kazuya kawaguchi
4
+ * Released under the MIT License.
5
+ */
6
+ import { format, assign, join, isString } from '@intlify/shared';
7
+
8
+ const LOCATION_STUB = {
9
+ start: { line: 1, column: 1, offset: 0 },
10
+ end: { line: 1, column: 1, offset: 0 }
11
+ };
12
+ function createPosition(line, column, offset) {
13
+ return { line, column, offset };
14
+ }
15
+ function createLocation(start, end, source) {
16
+ const loc = { start, end };
17
+ if (source != null) {
18
+ loc.source = source;
19
+ }
20
+ return loc;
21
+ }
22
+
23
+ const CompileErrorCodes = {
24
+ // tokenizer error codes
25
+ EXPECTED_TOKEN: 1,
26
+ INVALID_TOKEN_IN_PLACEHOLDER: 2,
27
+ UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER: 3,
28
+ UNKNOWN_ESCAPE_SEQUENCE: 4,
29
+ INVALID_UNICODE_ESCAPE_SEQUENCE: 5,
30
+ UNBALANCED_CLOSING_BRACE: 6,
31
+ UNTERMINATED_CLOSING_BRACE: 7,
32
+ EMPTY_PLACEHOLDER: 8,
33
+ NOT_ALLOW_NEST_PLACEHOLDER: 9,
34
+ INVALID_LINKED_FORMAT: 10,
35
+ // parser error codes
36
+ MUST_HAVE_MESSAGES_IN_PLURAL: 11,
37
+ UNEXPECTED_EMPTY_LINKED_MODIFIER: 12,
38
+ UNEXPECTED_EMPTY_LINKED_KEY: 13,
39
+ UNEXPECTED_LEXICAL_ANALYSIS: 14,
40
+ // generator error codes
41
+ UNHANDLED_CODEGEN_NODE_TYPE: 15,
42
+ // minifier error codes
43
+ UNHANDLED_MINIFIER_NODE_TYPE: 16
44
+ };
45
+ // Special value for higher-order compilers to pick up the last code
46
+ // to avoid collision of error codes.
47
+ // This should always be kept as the last item.
48
+ const COMPILE_ERROR_CODES_EXTEND_POINT = 17;
49
+ /** @internal */
50
+ const errorMessages = {
51
+ // tokenizer error messages
52
+ [CompileErrorCodes.EXPECTED_TOKEN]: `Expected token: '{0}'`,
53
+ [CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER]: `Invalid token in placeholder: '{0}'`,
54
+ [CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]: `Unterminated single quote in placeholder`,
55
+ [CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE]: `Unknown escape sequence: \\{0}`,
56
+ [CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE]: `Invalid unicode escape sequence: {0}`,
57
+ [CompileErrorCodes.UNBALANCED_CLOSING_BRACE]: `Unbalanced closing brace`,
58
+ [CompileErrorCodes.UNTERMINATED_CLOSING_BRACE]: `Unterminated closing brace`,
59
+ [CompileErrorCodes.EMPTY_PLACEHOLDER]: `Empty placeholder`,
60
+ [CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER]: `Not allowed nest placeholder`,
61
+ [CompileErrorCodes.INVALID_LINKED_FORMAT]: `Invalid linked format`,
62
+ // parser error messages
63
+ [CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL]: `Plural must have messages`,
64
+ [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER]: `Unexpected empty linked modifier`,
65
+ [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY]: `Unexpected empty linked key`,
66
+ [CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS]: `Unexpected lexical analysis in token: '{0}'`,
67
+ // generator error messages
68
+ [CompileErrorCodes.UNHANDLED_CODEGEN_NODE_TYPE]: `unhandled codegen node type: '{0}'`,
69
+ // minimizer error messages
70
+ [CompileErrorCodes.UNHANDLED_MINIFIER_NODE_TYPE]: `unhandled mimifier node type: '{0}'`
71
+ };
72
+ function createCompileError(code, loc, options = {}) {
73
+ const { domain, messages, args } = options;
74
+ const msg = (process.env.NODE_ENV !== 'production')
75
+ ? format((messages || errorMessages)[code] || '', ...(args || []))
76
+ : code;
77
+ const error = new SyntaxError(String(msg));
78
+ error.code = code;
79
+ if (loc) {
80
+ error.location = loc;
81
+ }
82
+ error.domain = domain;
83
+ return error;
84
+ }
85
+ /** @internal */
86
+ function defaultOnError(error) {
87
+ throw error;
88
+ }
89
+
90
+ // eslint-disable-next-line no-useless-escape
91
+ const RE_HTML_TAG = /<\/?[\w\s="/.':;#-\/]+>/;
92
+ const detectHtmlTag = (source) => RE_HTML_TAG.test(source);
93
+
94
+ const CHAR_SP = ' ';
95
+ const CHAR_CR = '\r';
96
+ const CHAR_LF = '\n';
97
+ const CHAR_LS = String.fromCharCode(0x2028);
98
+ const CHAR_PS = String.fromCharCode(0x2029);
99
+ function createScanner(str) {
100
+ const _buf = str;
101
+ let _index = 0;
102
+ let _line = 1;
103
+ let _column = 1;
104
+ let _peekOffset = 0;
105
+ const isCRLF = (index) => _buf[index] === CHAR_CR && _buf[index + 1] === CHAR_LF;
106
+ const isLF = (index) => _buf[index] === CHAR_LF;
107
+ const isPS = (index) => _buf[index] === CHAR_PS;
108
+ const isLS = (index) => _buf[index] === CHAR_LS;
109
+ const isLineEnd = (index) => isCRLF(index) || isLF(index) || isPS(index) || isLS(index);
110
+ const index = () => _index;
111
+ const line = () => _line;
112
+ const column = () => _column;
113
+ const peekOffset = () => _peekOffset;
114
+ const charAt = (offset) => isCRLF(offset) || isPS(offset) || isLS(offset) ? CHAR_LF : _buf[offset];
115
+ const currentChar = () => charAt(_index);
116
+ const currentPeek = () => charAt(_index + _peekOffset);
117
+ function next() {
118
+ _peekOffset = 0;
119
+ if (isLineEnd(_index)) {
120
+ _line++;
121
+ _column = 0;
122
+ }
123
+ if (isCRLF(_index)) {
124
+ _index++;
125
+ }
126
+ _index++;
127
+ _column++;
128
+ return _buf[_index];
129
+ }
130
+ function peek() {
131
+ if (isCRLF(_index + _peekOffset)) {
132
+ _peekOffset++;
133
+ }
134
+ _peekOffset++;
135
+ return _buf[_index + _peekOffset];
136
+ }
137
+ function reset() {
138
+ _index = 0;
139
+ _line = 1;
140
+ _column = 1;
141
+ _peekOffset = 0;
142
+ }
143
+ function resetPeek(offset = 0) {
144
+ _peekOffset = offset;
145
+ }
146
+ function skipToPeek() {
147
+ const target = _index + _peekOffset;
148
+ while (target !== _index) {
149
+ next();
150
+ }
151
+ _peekOffset = 0;
152
+ }
153
+ return {
154
+ index,
155
+ line,
156
+ column,
157
+ peekOffset,
158
+ charAt,
159
+ currentChar,
160
+ currentPeek,
161
+ next,
162
+ peek,
163
+ reset,
164
+ resetPeek,
165
+ skipToPeek
166
+ };
167
+ }
168
+
169
+ const EOF = undefined;
170
+ const DOT = '.';
171
+ const LITERAL_DELIMITER = "'";
172
+ const ERROR_DOMAIN$3 = 'tokenizer';
173
+ function createTokenizer(source, options = {}) {
174
+ const location = options.location !== false;
175
+ const _scnr = createScanner(source);
176
+ const currentOffset = () => _scnr.index();
177
+ const currentPosition = () => createPosition(_scnr.line(), _scnr.column(), _scnr.index());
178
+ const _initLoc = currentPosition();
179
+ const _initOffset = currentOffset();
180
+ const _context = {
181
+ currentType: 13 /* TokenTypes.EOF */,
182
+ offset: _initOffset,
183
+ startLoc: _initLoc,
184
+ endLoc: _initLoc,
185
+ lastType: 13 /* TokenTypes.EOF */,
186
+ lastOffset: _initOffset,
187
+ lastStartLoc: _initLoc,
188
+ lastEndLoc: _initLoc,
189
+ braceNest: 0,
190
+ inLinked: false,
191
+ text: ''
192
+ };
193
+ const context = () => _context;
194
+ const { onError } = options;
195
+ function emitError(code, pos, offset, ...args) {
196
+ const ctx = context();
197
+ pos.column += offset;
198
+ pos.offset += offset;
199
+ if (onError) {
200
+ const loc = location ? createLocation(ctx.startLoc, pos) : null;
201
+ const err = createCompileError(code, loc, {
202
+ domain: ERROR_DOMAIN$3,
203
+ args
204
+ });
205
+ onError(err);
206
+ }
207
+ }
208
+ function getToken(context, type, value) {
209
+ context.endLoc = currentPosition();
210
+ context.currentType = type;
211
+ const token = { type };
212
+ if (location) {
213
+ token.loc = createLocation(context.startLoc, context.endLoc);
214
+ }
215
+ if (value != null) {
216
+ token.value = value;
217
+ }
218
+ return token;
219
+ }
220
+ const getEndToken = (context) => getToken(context, 13 /* TokenTypes.EOF */);
221
+ function eat(scnr, ch) {
222
+ if (scnr.currentChar() === ch) {
223
+ scnr.next();
224
+ return ch;
225
+ }
226
+ else {
227
+ emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
228
+ return '';
229
+ }
230
+ }
231
+ function peekSpaces(scnr) {
232
+ let buf = '';
233
+ while (scnr.currentPeek() === CHAR_SP || scnr.currentPeek() === CHAR_LF) {
234
+ buf += scnr.currentPeek();
235
+ scnr.peek();
236
+ }
237
+ return buf;
238
+ }
239
+ function skipSpaces(scnr) {
240
+ const buf = peekSpaces(scnr);
241
+ scnr.skipToPeek();
242
+ return buf;
243
+ }
244
+ function isIdentifierStart(ch) {
245
+ if (ch === EOF) {
246
+ return false;
247
+ }
248
+ const cc = ch.charCodeAt(0);
249
+ return ((cc >= 97 && cc <= 122) || // a-z
250
+ (cc >= 65 && cc <= 90) || // A-Z
251
+ cc === 95 // _
252
+ );
253
+ }
254
+ function isNumberStart(ch) {
255
+ if (ch === EOF) {
256
+ return false;
257
+ }
258
+ const cc = ch.charCodeAt(0);
259
+ return cc >= 48 && cc <= 57; // 0-9
260
+ }
261
+ function isNamedIdentifierStart(scnr, context) {
262
+ const { currentType } = context;
263
+ if (currentType !== 2 /* TokenTypes.BraceLeft */) {
264
+ return false;
265
+ }
266
+ peekSpaces(scnr);
267
+ const ret = isIdentifierStart(scnr.currentPeek());
268
+ scnr.resetPeek();
269
+ return ret;
270
+ }
271
+ function isListIdentifierStart(scnr, context) {
272
+ const { currentType } = context;
273
+ if (currentType !== 2 /* TokenTypes.BraceLeft */) {
274
+ return false;
275
+ }
276
+ peekSpaces(scnr);
277
+ const ch = scnr.currentPeek() === '-' ? scnr.peek() : scnr.currentPeek();
278
+ const ret = isNumberStart(ch);
279
+ scnr.resetPeek();
280
+ return ret;
281
+ }
282
+ function isLiteralStart(scnr, context) {
283
+ const { currentType } = context;
284
+ if (currentType !== 2 /* TokenTypes.BraceLeft */) {
285
+ return false;
286
+ }
287
+ peekSpaces(scnr);
288
+ const ret = scnr.currentPeek() === LITERAL_DELIMITER;
289
+ scnr.resetPeek();
290
+ return ret;
291
+ }
292
+ function isLinkedDotStart(scnr, context) {
293
+ const { currentType } = context;
294
+ if (currentType !== 7 /* TokenTypes.LinkedAlias */) {
295
+ return false;
296
+ }
297
+ peekSpaces(scnr);
298
+ const ret = scnr.currentPeek() === "." /* TokenChars.LinkedDot */;
299
+ scnr.resetPeek();
300
+ return ret;
301
+ }
302
+ function isLinkedModifierStart(scnr, context) {
303
+ const { currentType } = context;
304
+ if (currentType !== 8 /* TokenTypes.LinkedDot */) {
305
+ return false;
306
+ }
307
+ peekSpaces(scnr);
308
+ const ret = isIdentifierStart(scnr.currentPeek());
309
+ scnr.resetPeek();
310
+ return ret;
311
+ }
312
+ function isLinkedDelimiterStart(scnr, context) {
313
+ const { currentType } = context;
314
+ if (!(currentType === 7 /* TokenTypes.LinkedAlias */ ||
315
+ currentType === 11 /* TokenTypes.LinkedModifier */)) {
316
+ return false;
317
+ }
318
+ peekSpaces(scnr);
319
+ const ret = scnr.currentPeek() === ":" /* TokenChars.LinkedDelimiter */;
320
+ scnr.resetPeek();
321
+ return ret;
322
+ }
323
+ function isLinkedReferStart(scnr, context) {
324
+ const { currentType } = context;
325
+ if (currentType !== 9 /* TokenTypes.LinkedDelimiter */) {
326
+ return false;
327
+ }
328
+ const fn = () => {
329
+ const ch = scnr.currentPeek();
330
+ if (ch === "{" /* TokenChars.BraceLeft */) {
331
+ return isIdentifierStart(scnr.peek());
332
+ }
333
+ else if (ch === "@" /* TokenChars.LinkedAlias */ ||
334
+ ch === "|" /* TokenChars.Pipe */ ||
335
+ ch === ":" /* TokenChars.LinkedDelimiter */ ||
336
+ ch === "." /* TokenChars.LinkedDot */ ||
337
+ ch === CHAR_SP ||
338
+ !ch) {
339
+ return false;
340
+ }
341
+ else if (ch === CHAR_LF) {
342
+ scnr.peek();
343
+ return fn();
344
+ }
345
+ else {
346
+ // other characters
347
+ return isTextStart(scnr, false);
348
+ }
349
+ };
350
+ const ret = fn();
351
+ scnr.resetPeek();
352
+ return ret;
353
+ }
354
+ function isPluralStart(scnr) {
355
+ peekSpaces(scnr);
356
+ const ret = scnr.currentPeek() === "|" /* TokenChars.Pipe */;
357
+ scnr.resetPeek();
358
+ return ret;
359
+ }
360
+ function isTextStart(scnr, reset = true) {
361
+ const fn = (hasSpace = false, prev = '') => {
362
+ const ch = scnr.currentPeek();
363
+ if (ch === "{" /* TokenChars.BraceLeft */) {
364
+ return hasSpace;
365
+ }
366
+ else if (ch === "@" /* TokenChars.LinkedAlias */ || !ch) {
367
+ return hasSpace;
368
+ }
369
+ else if (ch === "|" /* TokenChars.Pipe */) {
370
+ return !(prev === CHAR_SP || prev === CHAR_LF);
371
+ }
372
+ else if (ch === CHAR_SP) {
373
+ scnr.peek();
374
+ return fn(true, CHAR_SP);
375
+ }
376
+ else if (ch === CHAR_LF) {
377
+ scnr.peek();
378
+ return fn(true, CHAR_LF);
379
+ }
380
+ else {
381
+ return true;
382
+ }
383
+ };
384
+ const ret = fn();
385
+ reset && scnr.resetPeek();
386
+ return ret;
387
+ }
388
+ function takeChar(scnr, fn) {
389
+ const ch = scnr.currentChar();
390
+ if (ch === EOF) {
391
+ return EOF;
392
+ }
393
+ if (fn(ch)) {
394
+ scnr.next();
395
+ return ch;
396
+ }
397
+ return null;
398
+ }
399
+ function isIdentifier(ch) {
400
+ const cc = ch.charCodeAt(0);
401
+ return ((cc >= 97 && cc <= 122) || // a-z
402
+ (cc >= 65 && cc <= 90) || // A-Z
403
+ (cc >= 48 && cc <= 57) || // 0-9
404
+ cc === 95 || // _
405
+ cc === 36 // $
406
+ );
407
+ }
408
+ function takeIdentifierChar(scnr) {
409
+ return takeChar(scnr, isIdentifier);
410
+ }
411
+ function isNamedIdentifier(ch) {
412
+ const cc = ch.charCodeAt(0);
413
+ return ((cc >= 97 && cc <= 122) || // a-z
414
+ (cc >= 65 && cc <= 90) || // A-Z
415
+ (cc >= 48 && cc <= 57) || // 0-9
416
+ cc === 95 || // _
417
+ cc === 36 || // $
418
+ cc === 45 // -
419
+ );
420
+ }
421
+ function takeNamedIdentifierChar(scnr) {
422
+ return takeChar(scnr, isNamedIdentifier);
423
+ }
424
+ function isDigit(ch) {
425
+ const cc = ch.charCodeAt(0);
426
+ return cc >= 48 && cc <= 57; // 0-9
427
+ }
428
+ function takeDigit(scnr) {
429
+ return takeChar(scnr, isDigit);
430
+ }
431
+ function isHexDigit(ch) {
432
+ const cc = ch.charCodeAt(0);
433
+ return ((cc >= 48 && cc <= 57) || // 0-9
434
+ (cc >= 65 && cc <= 70) || // A-F
435
+ (cc >= 97 && cc <= 102)); // a-f
436
+ }
437
+ function takeHexDigit(scnr) {
438
+ return takeChar(scnr, isHexDigit);
439
+ }
440
+ function getDigits(scnr) {
441
+ let ch = '';
442
+ let num = '';
443
+ while ((ch = takeDigit(scnr))) {
444
+ num += ch;
445
+ }
446
+ return num;
447
+ }
448
+ function readText(scnr) {
449
+ let buf = '';
450
+ while (true) {
451
+ const ch = scnr.currentChar();
452
+ if (ch === '\\') {
453
+ const nextCh = scnr.peek();
454
+ if (nextCh === "{" /* TokenChars.BraceLeft */ ||
455
+ nextCh === "}" /* TokenChars.BraceRight */ ||
456
+ nextCh === "@" /* TokenChars.LinkedAlias */ ||
457
+ nextCh === "|" /* TokenChars.Pipe */ ||
458
+ nextCh === '\\') {
459
+ buf += ch + nextCh;
460
+ scnr.next();
461
+ scnr.next();
462
+ }
463
+ else {
464
+ scnr.resetPeek();
465
+ buf += ch;
466
+ scnr.next();
467
+ }
468
+ }
469
+ else if (ch === "{" /* TokenChars.BraceLeft */ ||
470
+ ch === "}" /* TokenChars.BraceRight */ ||
471
+ ch === "@" /* TokenChars.LinkedAlias */ ||
472
+ ch === "|" /* TokenChars.Pipe */ ||
473
+ !ch) {
474
+ break;
475
+ }
476
+ else if (ch === CHAR_SP || ch === CHAR_LF) {
477
+ if (isTextStart(scnr)) {
478
+ buf += ch;
479
+ scnr.next();
480
+ }
481
+ else if (isPluralStart(scnr)) {
482
+ break;
483
+ }
484
+ else {
485
+ buf += ch;
486
+ scnr.next();
487
+ }
488
+ }
489
+ else {
490
+ buf += ch;
491
+ scnr.next();
492
+ }
493
+ }
494
+ return buf;
495
+ }
496
+ function readNamedIdentifier(scnr) {
497
+ skipSpaces(scnr);
498
+ let ch = '';
499
+ let name = '';
500
+ while ((ch = takeNamedIdentifierChar(scnr))) {
501
+ name += ch;
502
+ }
503
+ // Check if takeNamedIdentifierChar stoped because of invalid characters
504
+ const currentChar = scnr.currentChar();
505
+ if (currentChar &&
506
+ currentChar !== '}' &&
507
+ currentChar !== EOF &&
508
+ currentChar !== CHAR_SP &&
509
+ currentChar !== CHAR_LF &&
510
+ currentChar !== '\u3000') {
511
+ const invalidPart = readInvalidIdentifier(scnr);
512
+ emitError(CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER, currentPosition(), 0, name + invalidPart);
513
+ return name + invalidPart;
514
+ }
515
+ if (scnr.currentChar() === EOF) {
516
+ emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
517
+ }
518
+ return name;
519
+ }
520
+ function readListIdentifier(scnr) {
521
+ skipSpaces(scnr);
522
+ let value = '';
523
+ if (scnr.currentChar() === '-') {
524
+ scnr.next();
525
+ value += `-${getDigits(scnr)}`;
526
+ }
527
+ else {
528
+ value += getDigits(scnr);
529
+ }
530
+ if (scnr.currentChar() === EOF) {
531
+ emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
532
+ }
533
+ return value;
534
+ }
535
+ function isLiteral(ch) {
536
+ return ch !== LITERAL_DELIMITER && ch !== CHAR_LF;
537
+ }
538
+ function readLiteral(scnr) {
539
+ skipSpaces(scnr);
540
+ // eslint-disable-next-line no-useless-escape
541
+ eat(scnr, `\'`);
542
+ let ch = '';
543
+ let literal = '';
544
+ while ((ch = takeChar(scnr, isLiteral))) {
545
+ if (ch === '\\') {
546
+ literal += readEscapeSequence(scnr);
547
+ }
548
+ else {
549
+ literal += ch;
550
+ }
551
+ }
552
+ const current = scnr.currentChar();
553
+ if (current === CHAR_LF || current === EOF) {
554
+ emitError(CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER, currentPosition(), 0);
555
+ // TODO: Is it correct really?
556
+ if (current === CHAR_LF) {
557
+ scnr.next();
558
+ // eslint-disable-next-line no-useless-escape
559
+ eat(scnr, `\'`);
560
+ }
561
+ return literal;
562
+ }
563
+ // eslint-disable-next-line no-useless-escape
564
+ eat(scnr, `\'`);
565
+ return literal;
566
+ }
567
+ function readEscapeSequence(scnr) {
568
+ const ch = scnr.currentChar();
569
+ switch (ch) {
570
+ case '\\':
571
+ case `\'`: // eslint-disable-line no-useless-escape
572
+ scnr.next();
573
+ return `\\${ch}`;
574
+ case 'u':
575
+ return readUnicodeEscapeSequence(scnr, ch, 4);
576
+ case 'U':
577
+ return readUnicodeEscapeSequence(scnr, ch, 6);
578
+ default:
579
+ emitError(CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE, currentPosition(), 0, ch);
580
+ return '';
581
+ }
582
+ }
583
+ function readUnicodeEscapeSequence(scnr, unicode, digits) {
584
+ eat(scnr, unicode);
585
+ let sequence = '';
586
+ for (let i = 0; i < digits; i++) {
587
+ const ch = takeHexDigit(scnr);
588
+ if (!ch) {
589
+ emitError(CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE, currentPosition(), 0, `\\${unicode}${sequence}${scnr.currentChar()}`);
590
+ break;
591
+ }
592
+ sequence += ch;
593
+ }
594
+ return `\\${unicode}${sequence}`;
595
+ }
596
+ function isInvalidIdentifier(ch) {
597
+ return (ch !== "{" /* TokenChars.BraceLeft */ &&
598
+ ch !== "}" /* TokenChars.BraceRight */ &&
599
+ ch !== CHAR_SP &&
600
+ ch !== CHAR_LF);
601
+ }
602
+ function readInvalidIdentifier(scnr) {
603
+ skipSpaces(scnr);
604
+ let ch = '';
605
+ let identifiers = '';
606
+ while ((ch = takeChar(scnr, isInvalidIdentifier))) {
607
+ identifiers += ch;
608
+ }
609
+ return identifiers;
610
+ }
611
+ function readLinkedModifier(scnr) {
612
+ let ch = '';
613
+ let name = '';
614
+ while ((ch = takeIdentifierChar(scnr))) {
615
+ name += ch;
616
+ }
617
+ return name;
618
+ }
619
+ function readLinkedRefer(scnr) {
620
+ const fn = (buf) => {
621
+ const ch = scnr.currentChar();
622
+ if (ch === "{" /* TokenChars.BraceLeft */ ||
623
+ ch === "@" /* TokenChars.LinkedAlias */ ||
624
+ ch === "|" /* TokenChars.Pipe */ ||
625
+ ch === "(" /* TokenChars.ParenLeft */ ||
626
+ ch === ")" /* TokenChars.ParenRight */ ||
627
+ !ch) {
628
+ return buf;
629
+ }
630
+ else if (ch === CHAR_SP) {
631
+ return buf;
632
+ }
633
+ else if (ch === CHAR_LF || ch === DOT) {
634
+ buf += ch;
635
+ scnr.next();
636
+ return fn(buf);
637
+ }
638
+ else {
639
+ buf += ch;
640
+ scnr.next();
641
+ return fn(buf);
642
+ }
643
+ };
644
+ return fn('');
645
+ }
646
+ function readPlural(scnr) {
647
+ skipSpaces(scnr);
648
+ const plural = eat(scnr, "|" /* TokenChars.Pipe */);
649
+ skipSpaces(scnr);
650
+ return plural;
651
+ }
652
+ // TODO: We need refactoring of token parsing ...
653
+ function readTokenInPlaceholder(scnr, context) {
654
+ let token = null;
655
+ const ch = scnr.currentChar();
656
+ switch (ch) {
657
+ case "{" /* TokenChars.BraceLeft */:
658
+ if (context.braceNest >= 1) {
659
+ emitError(CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER, currentPosition(), 0);
660
+ }
661
+ scnr.next();
662
+ token = getToken(context, 2 /* TokenTypes.BraceLeft */, "{" /* TokenChars.BraceLeft */);
663
+ skipSpaces(scnr);
664
+ context.braceNest++;
665
+ return token;
666
+ case "}" /* TokenChars.BraceRight */:
667
+ if (context.braceNest > 0 &&
668
+ context.currentType === 2 /* TokenTypes.BraceLeft */) {
669
+ emitError(CompileErrorCodes.EMPTY_PLACEHOLDER, currentPosition(), 0);
670
+ }
671
+ scnr.next();
672
+ token = getToken(context, 3 /* TokenTypes.BraceRight */, "}" /* TokenChars.BraceRight */);
673
+ context.braceNest--;
674
+ context.braceNest > 0 && skipSpaces(scnr);
675
+ if (context.inLinked && context.braceNest === 0) {
676
+ context.inLinked = false;
677
+ }
678
+ return token;
679
+ case "@" /* TokenChars.LinkedAlias */:
680
+ if (context.braceNest > 0) {
681
+ emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
682
+ }
683
+ token = readTokenInLinked(scnr, context) || getEndToken(context);
684
+ context.braceNest = 0;
685
+ return token;
686
+ default: {
687
+ let validNamedIdentifier = true;
688
+ let validListIdentifier = true;
689
+ let validLiteral = true;
690
+ if (isPluralStart(scnr)) {
691
+ if (context.braceNest > 0) {
692
+ emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
693
+ }
694
+ token = getToken(context, 1 /* TokenTypes.Pipe */, readPlural(scnr));
695
+ // reset
696
+ context.braceNest = 0;
697
+ context.inLinked = false;
698
+ return token;
699
+ }
700
+ if (context.braceNest > 0 &&
701
+ (context.currentType === 4 /* TokenTypes.Named */ ||
702
+ context.currentType === 5 /* TokenTypes.List */ ||
703
+ context.currentType === 6 /* TokenTypes.Literal */)) {
704
+ emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
705
+ context.braceNest = 0;
706
+ return readToken(scnr, context);
707
+ }
708
+ if ((validNamedIdentifier = isNamedIdentifierStart(scnr, context))) {
709
+ token = getToken(context, 4 /* TokenTypes.Named */, readNamedIdentifier(scnr));
710
+ skipSpaces(scnr);
711
+ return token;
712
+ }
713
+ if ((validListIdentifier = isListIdentifierStart(scnr, context))) {
714
+ token = getToken(context, 5 /* TokenTypes.List */, readListIdentifier(scnr));
715
+ skipSpaces(scnr);
716
+ return token;
717
+ }
718
+ if ((validLiteral = isLiteralStart(scnr, context))) {
719
+ token = getToken(context, 6 /* TokenTypes.Literal */, readLiteral(scnr));
720
+ skipSpaces(scnr);
721
+ return token;
722
+ }
723
+ if (!validNamedIdentifier && !validListIdentifier && !validLiteral) {
724
+ // TODO: we should be re-designed invalid cases, when we will extend message syntax near the future ...
725
+ token = getToken(context, 12 /* TokenTypes.InvalidPlace */, readInvalidIdentifier(scnr));
726
+ emitError(CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER, currentPosition(), 0, token.value);
727
+ skipSpaces(scnr);
728
+ return token;
729
+ }
730
+ break;
731
+ }
732
+ }
733
+ return token;
734
+ }
735
+ // TODO: We need refactoring of token parsing ...
736
+ function readTokenInLinked(scnr, context) {
737
+ const { currentType } = context;
738
+ let token = null;
739
+ const ch = scnr.currentChar();
740
+ if ((currentType === 7 /* TokenTypes.LinkedAlias */ ||
741
+ currentType === 8 /* TokenTypes.LinkedDot */ ||
742
+ currentType === 11 /* TokenTypes.LinkedModifier */ ||
743
+ currentType === 9 /* TokenTypes.LinkedDelimiter */) &&
744
+ (ch === CHAR_LF || ch === CHAR_SP)) {
745
+ emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);
746
+ }
747
+ switch (ch) {
748
+ case "@" /* TokenChars.LinkedAlias */:
749
+ scnr.next();
750
+ token = getToken(context, 7 /* TokenTypes.LinkedAlias */, "@" /* TokenChars.LinkedAlias */);
751
+ context.inLinked = true;
752
+ return token;
753
+ case "." /* TokenChars.LinkedDot */:
754
+ skipSpaces(scnr);
755
+ scnr.next();
756
+ return getToken(context, 8 /* TokenTypes.LinkedDot */, "." /* TokenChars.LinkedDot */);
757
+ case ":" /* TokenChars.LinkedDelimiter */:
758
+ skipSpaces(scnr);
759
+ scnr.next();
760
+ return getToken(context, 9 /* TokenTypes.LinkedDelimiter */, ":" /* TokenChars.LinkedDelimiter */);
761
+ default:
762
+ if (isPluralStart(scnr)) {
763
+ token = getToken(context, 1 /* TokenTypes.Pipe */, readPlural(scnr));
764
+ // reset
765
+ context.braceNest = 0;
766
+ context.inLinked = false;
767
+ return token;
768
+ }
769
+ if (isLinkedDotStart(scnr, context) ||
770
+ isLinkedDelimiterStart(scnr, context)) {
771
+ skipSpaces(scnr);
772
+ return readTokenInLinked(scnr, context);
773
+ }
774
+ if (isLinkedModifierStart(scnr, context)) {
775
+ skipSpaces(scnr);
776
+ return getToken(context, 11 /* TokenTypes.LinkedModifier */, readLinkedModifier(scnr));
777
+ }
778
+ if (isLinkedReferStart(scnr, context)) {
779
+ skipSpaces(scnr);
780
+ if (ch === "{" /* TokenChars.BraceLeft */) {
781
+ // scan the placeholder
782
+ return readTokenInPlaceholder(scnr, context) || token;
783
+ }
784
+ else {
785
+ return getToken(context, 10 /* TokenTypes.LinkedKey */, readLinkedRefer(scnr));
786
+ }
787
+ }
788
+ if (currentType === 7 /* TokenTypes.LinkedAlias */) {
789
+ emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);
790
+ }
791
+ context.braceNest = 0;
792
+ context.inLinked = false;
793
+ return readToken(scnr, context);
794
+ }
795
+ }
796
+ // TODO: We need refactoring of token parsing ...
797
+ function readToken(scnr, context) {
798
+ let token = { type: 13 /* TokenTypes.EOF */ };
799
+ if (context.braceNest > 0) {
800
+ return readTokenInPlaceholder(scnr, context) || getEndToken(context);
801
+ }
802
+ if (context.inLinked) {
803
+ return readTokenInLinked(scnr, context) || getEndToken(context);
804
+ }
805
+ const ch = scnr.currentChar();
806
+ switch (ch) {
807
+ case "{" /* TokenChars.BraceLeft */:
808
+ return readTokenInPlaceholder(scnr, context) || getEndToken(context);
809
+ case "}" /* TokenChars.BraceRight */:
810
+ emitError(CompileErrorCodes.UNBALANCED_CLOSING_BRACE, currentPosition(), 0);
811
+ scnr.next();
812
+ return getToken(context, 3 /* TokenTypes.BraceRight */, "}" /* TokenChars.BraceRight */);
813
+ case "@" /* TokenChars.LinkedAlias */:
814
+ return readTokenInLinked(scnr, context) || getEndToken(context);
815
+ default: {
816
+ if (isPluralStart(scnr)) {
817
+ token = getToken(context, 1 /* TokenTypes.Pipe */, readPlural(scnr));
818
+ // reset
819
+ context.braceNest = 0;
820
+ context.inLinked = false;
821
+ return token;
822
+ }
823
+ if (isTextStart(scnr)) {
824
+ return getToken(context, 0 /* TokenTypes.Text */, readText(scnr));
825
+ }
826
+ break;
827
+ }
828
+ }
829
+ return token;
830
+ }
831
+ function nextToken() {
832
+ const { currentType, offset, startLoc, endLoc } = _context;
833
+ _context.lastType = currentType;
834
+ _context.lastOffset = offset;
835
+ _context.lastStartLoc = startLoc;
836
+ _context.lastEndLoc = endLoc;
837
+ _context.offset = currentOffset();
838
+ _context.startLoc = currentPosition();
839
+ if (_scnr.currentChar() === EOF) {
840
+ return getToken(_context, 13 /* TokenTypes.EOF */);
841
+ }
842
+ return readToken(_scnr, _context);
843
+ }
844
+ return {
845
+ nextToken,
846
+ currentOffset,
847
+ currentPosition,
848
+ context
849
+ };
850
+ }
851
+
852
+ const ERROR_DOMAIN$2 = 'parser';
853
+ // Backslash backslash, backslash quote, uHHHH, UHHHHHH.
854
+ const KNOWN_ESCAPES = /(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;
855
+ // Text context escape sequences: \\, \@, \{, \}, \|
856
+ const TEXT_ESCAPES = /\\([\\@{}|])/g;
857
+ function fromTextEscapeSequence(_match, char) {
858
+ return char;
859
+ }
860
+ function fromEscapeSequence(match, codePoint4, codePoint6) {
861
+ switch (match) {
862
+ case `\\\\`:
863
+ return `\\`;
864
+ // eslint-disable-next-line no-useless-escape
865
+ case `\\\'`:
866
+ // eslint-disable-next-line no-useless-escape
867
+ return `\'`;
868
+ default: {
869
+ const codePoint = parseInt(codePoint4 || codePoint6, 16);
870
+ if (codePoint <= 0xd7ff || codePoint >= 0xe000) {
871
+ return String.fromCodePoint(codePoint);
872
+ }
873
+ // invalid ...
874
+ // Replace them with U+FFFD REPLACEMENT CHARACTER.
875
+ return '�';
876
+ }
877
+ }
878
+ }
879
+ function createParser(options = {}) {
880
+ const location = options.location !== false;
881
+ const { onError } = options;
882
+ function emitError(tokenzer, code, start, offset, ...args) {
883
+ const end = tokenzer.currentPosition();
884
+ end.offset += offset;
885
+ end.column += offset;
886
+ if (onError) {
887
+ const loc = location ? createLocation(start, end) : null;
888
+ const err = createCompileError(code, loc, {
889
+ domain: ERROR_DOMAIN$2,
890
+ args
891
+ });
892
+ onError(err);
893
+ }
894
+ }
895
+ function startNode(type, offset, loc) {
896
+ const node = { type };
897
+ if (location) {
898
+ node.start = offset;
899
+ node.end = offset;
900
+ node.loc = { start: loc, end: loc };
901
+ }
902
+ return node;
903
+ }
904
+ function endNode(node, offset, pos, type) {
905
+ if (location) {
906
+ node.end = offset;
907
+ if (node.loc) {
908
+ node.loc.end = pos;
909
+ }
910
+ }
911
+ }
912
+ function parseText(tokenizer, value) {
913
+ const context = tokenizer.context();
914
+ const node = startNode(3 /* NodeTypes.Text */, context.offset, context.startLoc);
915
+ node.value = value.replace(TEXT_ESCAPES, fromTextEscapeSequence);
916
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
917
+ return node;
918
+ }
919
+ function parseList(tokenizer, index) {
920
+ const context = tokenizer.context();
921
+ const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
922
+ const node = startNode(5 /* NodeTypes.List */, offset, loc);
923
+ node.index = parseInt(index, 10);
924
+ tokenizer.nextToken(); // skip brach right
925
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
926
+ return node;
927
+ }
928
+ function parseNamed(tokenizer, key) {
929
+ const context = tokenizer.context();
930
+ const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
931
+ const node = startNode(4 /* NodeTypes.Named */, offset, loc);
932
+ node.key = key;
933
+ tokenizer.nextToken(); // skip brach right
934
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
935
+ return node;
936
+ }
937
+ function parseLiteral(tokenizer, value) {
938
+ const context = tokenizer.context();
939
+ const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
940
+ const node = startNode(9 /* NodeTypes.Literal */, offset, loc);
941
+ node.value = value.replace(KNOWN_ESCAPES, fromEscapeSequence);
942
+ tokenizer.nextToken(); // skip brach right
943
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
944
+ return node;
945
+ }
946
+ function parseLinkedModifier(tokenizer) {
947
+ const token = tokenizer.nextToken();
948
+ const context = tokenizer.context();
949
+ const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc
950
+ const node = startNode(8 /* NodeTypes.LinkedModifier */, offset, loc);
951
+ if (token.type !== 11 /* TokenTypes.LinkedModifier */) {
952
+ // empty modifier
953
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER, context.lastStartLoc, 0);
954
+ node.value = '';
955
+ endNode(node, offset, loc);
956
+ return {
957
+ nextConsumeToken: token,
958
+ node
959
+ };
960
+ }
961
+ // check token
962
+ if (token.value == null) {
963
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
964
+ }
965
+ node.value = token.value || '';
966
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
967
+ return {
968
+ node
969
+ };
970
+ }
971
+ function parseLinkedKey(tokenizer, value) {
972
+ const context = tokenizer.context();
973
+ const node = startNode(7 /* NodeTypes.LinkedKey */, context.offset, context.startLoc);
974
+ node.value = value;
975
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
976
+ return node;
977
+ }
978
+ function parseLinked(tokenizer) {
979
+ const context = tokenizer.context();
980
+ const linkedNode = startNode(6 /* NodeTypes.Linked */, context.offset, context.startLoc);
981
+ let token = tokenizer.nextToken();
982
+ if (token.type === 8 /* TokenTypes.LinkedDot */) {
983
+ const parsed = parseLinkedModifier(tokenizer);
984
+ linkedNode.modifier = parsed.node;
985
+ token = parsed.nextConsumeToken || tokenizer.nextToken();
986
+ }
987
+ // asset check token
988
+ if (token.type !== 9 /* TokenTypes.LinkedDelimiter */) {
989
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
990
+ }
991
+ token = tokenizer.nextToken();
992
+ // skip brace left
993
+ if (token.type === 2 /* TokenTypes.BraceLeft */) {
994
+ token = tokenizer.nextToken();
995
+ }
996
+ switch (token.type) {
997
+ case 10 /* TokenTypes.LinkedKey */:
998
+ if (token.value == null) {
999
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1000
+ }
1001
+ linkedNode.key = parseLinkedKey(tokenizer, token.value || '');
1002
+ break;
1003
+ case 4 /* TokenTypes.Named */:
1004
+ if (token.value == null) {
1005
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1006
+ }
1007
+ linkedNode.key = parseNamed(tokenizer, token.value || '');
1008
+ break;
1009
+ case 5 /* TokenTypes.List */:
1010
+ if (token.value == null) {
1011
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1012
+ }
1013
+ linkedNode.key = parseList(tokenizer, token.value || '');
1014
+ break;
1015
+ case 6 /* TokenTypes.Literal */:
1016
+ if (token.value == null) {
1017
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1018
+ }
1019
+ linkedNode.key = parseLiteral(tokenizer, token.value || '');
1020
+ break;
1021
+ default: {
1022
+ // empty key
1023
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY, context.lastStartLoc, 0);
1024
+ const nextContext = tokenizer.context();
1025
+ const emptyLinkedKeyNode = startNode(7 /* NodeTypes.LinkedKey */, nextContext.offset, nextContext.startLoc);
1026
+ emptyLinkedKeyNode.value = '';
1027
+ endNode(emptyLinkedKeyNode, nextContext.offset, nextContext.startLoc);
1028
+ linkedNode.key = emptyLinkedKeyNode;
1029
+ endNode(linkedNode, nextContext.offset, nextContext.startLoc);
1030
+ return {
1031
+ nextConsumeToken: token,
1032
+ node: linkedNode
1033
+ };
1034
+ }
1035
+ }
1036
+ endNode(linkedNode, tokenizer.currentOffset(), tokenizer.currentPosition());
1037
+ return {
1038
+ node: linkedNode
1039
+ };
1040
+ }
1041
+ function parseMessage(tokenizer) {
1042
+ const context = tokenizer.context();
1043
+ const startOffset = context.currentType === 1 /* TokenTypes.Pipe */
1044
+ ? tokenizer.currentOffset()
1045
+ : context.offset;
1046
+ const startLoc = context.currentType === 1 /* TokenTypes.Pipe */
1047
+ ? context.endLoc
1048
+ : context.startLoc;
1049
+ const node = startNode(2 /* NodeTypes.Message */, startOffset, startLoc);
1050
+ node.items = [];
1051
+ let nextToken = null;
1052
+ do {
1053
+ const token = nextToken || tokenizer.nextToken();
1054
+ nextToken = null;
1055
+ switch (token.type) {
1056
+ case 0 /* TokenTypes.Text */:
1057
+ if (token.value == null) {
1058
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1059
+ }
1060
+ node.items.push(parseText(tokenizer, token.value || ''));
1061
+ break;
1062
+ case 5 /* TokenTypes.List */:
1063
+ if (token.value == null) {
1064
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1065
+ }
1066
+ node.items.push(parseList(tokenizer, token.value || ''));
1067
+ break;
1068
+ case 4 /* TokenTypes.Named */:
1069
+ if (token.value == null) {
1070
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1071
+ }
1072
+ node.items.push(parseNamed(tokenizer, token.value || ''));
1073
+ break;
1074
+ case 6 /* TokenTypes.Literal */:
1075
+ if (token.value == null) {
1076
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
1077
+ }
1078
+ node.items.push(parseLiteral(tokenizer, token.value || ''));
1079
+ break;
1080
+ case 7 /* TokenTypes.LinkedAlias */: {
1081
+ const parsed = parseLinked(tokenizer);
1082
+ node.items.push(parsed.node);
1083
+ nextToken = parsed.nextConsumeToken || null;
1084
+ break;
1085
+ }
1086
+ }
1087
+ } while (context.currentType !== 13 /* TokenTypes.EOF */ &&
1088
+ context.currentType !== 1 /* TokenTypes.Pipe */);
1089
+ // adjust message node loc
1090
+ const endOffset = context.currentType === 1 /* TokenTypes.Pipe */
1091
+ ? context.lastOffset
1092
+ : tokenizer.currentOffset();
1093
+ const endLoc = context.currentType === 1 /* TokenTypes.Pipe */
1094
+ ? context.lastEndLoc
1095
+ : tokenizer.currentPosition();
1096
+ endNode(node, endOffset, endLoc);
1097
+ return node;
1098
+ }
1099
+ function parsePlural(tokenizer, offset, loc, msgNode) {
1100
+ const context = tokenizer.context();
1101
+ let hasEmptyMessage = msgNode.items.length === 0;
1102
+ const node = startNode(1 /* NodeTypes.Plural */, offset, loc);
1103
+ node.cases = [];
1104
+ node.cases.push(msgNode);
1105
+ do {
1106
+ const msg = parseMessage(tokenizer);
1107
+ if (!hasEmptyMessage) {
1108
+ hasEmptyMessage = msg.items.length === 0;
1109
+ }
1110
+ node.cases.push(msg);
1111
+ } while (context.currentType !== 13 /* TokenTypes.EOF */);
1112
+ if (hasEmptyMessage) {
1113
+ emitError(tokenizer, CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL, loc, 0);
1114
+ }
1115
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1116
+ return node;
1117
+ }
1118
+ function parseResource(tokenizer) {
1119
+ const context = tokenizer.context();
1120
+ const { offset, startLoc } = context;
1121
+ const msgNode = parseMessage(tokenizer);
1122
+ if (context.currentType === 13 /* TokenTypes.EOF */) {
1123
+ return msgNode;
1124
+ }
1125
+ else {
1126
+ return parsePlural(tokenizer, offset, startLoc, msgNode);
1127
+ }
1128
+ }
1129
+ function parse(source) {
1130
+ const tokenizer = createTokenizer(source, assign({}, options));
1131
+ const context = tokenizer.context();
1132
+ const node = startNode(0 /* NodeTypes.Resource */, context.offset, context.startLoc);
1133
+ if (location && node.loc) {
1134
+ node.loc.source = source;
1135
+ }
1136
+ node.body = parseResource(tokenizer);
1137
+ if (options.onCacheKey) {
1138
+ node.cacheKey = options.onCacheKey(source);
1139
+ }
1140
+ // assert whether achieved to EOF
1141
+ if (context.currentType !== 13 /* TokenTypes.EOF */) {
1142
+ emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, source[context.offset] || '');
1143
+ }
1144
+ endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
1145
+ return node;
1146
+ }
1147
+ return { parse };
1148
+ }
1149
+ function getTokenCaption(token) {
1150
+ if (token.type === 13 /* TokenTypes.EOF */) {
1151
+ return 'EOF';
1152
+ }
1153
+ const name = (token.value || '').replace(/\r?\n/gu, '\\n');
1154
+ return name.length > 10 ? name.slice(0, 9) + '…' : name;
1155
+ }
1156
+
1157
+ function createTransformer(ast, options = {} // eslint-disable-line
1158
+ ) {
1159
+ const _context = {
1160
+ ast,
1161
+ helpers: new Set()
1162
+ };
1163
+ const context = () => _context;
1164
+ const helper = (name) => {
1165
+ _context.helpers.add(name);
1166
+ return name;
1167
+ };
1168
+ return { context, helper };
1169
+ }
1170
+ function traverseNodes(nodes, transformer) {
1171
+ for (let i = 0; i < nodes.length; i++) {
1172
+ traverseNode(nodes[i], transformer);
1173
+ }
1174
+ }
1175
+ function traverseNode(node, transformer) {
1176
+ // TODO: if we need pre-hook of transform, should be implemented to here
1177
+ switch (node.type) {
1178
+ case 1 /* NodeTypes.Plural */:
1179
+ traverseNodes(node.cases, transformer);
1180
+ transformer.helper("plural" /* HelperNameMap.PLURAL */);
1181
+ break;
1182
+ case 2 /* NodeTypes.Message */:
1183
+ traverseNodes(node.items, transformer);
1184
+ break;
1185
+ case 6 /* NodeTypes.Linked */: {
1186
+ const linked = node;
1187
+ traverseNode(linked.key, transformer);
1188
+ transformer.helper("linked" /* HelperNameMap.LINKED */);
1189
+ transformer.helper("type" /* HelperNameMap.TYPE */);
1190
+ break;
1191
+ }
1192
+ case 5 /* NodeTypes.List */:
1193
+ transformer.helper("interpolate" /* HelperNameMap.INTERPOLATE */);
1194
+ transformer.helper("list" /* HelperNameMap.LIST */);
1195
+ break;
1196
+ case 4 /* NodeTypes.Named */:
1197
+ transformer.helper("interpolate" /* HelperNameMap.INTERPOLATE */);
1198
+ transformer.helper("named" /* HelperNameMap.NAMED */);
1199
+ break;
1200
+ }
1201
+ // TODO: if we need post-hook of transform, should be implemented to here
1202
+ }
1203
+ // transform AST
1204
+ function transform(ast, options = {} // eslint-disable-line
1205
+ ) {
1206
+ const transformer = createTransformer(ast);
1207
+ transformer.helper("normalize" /* HelperNameMap.NORMALIZE */);
1208
+ // traverse
1209
+ ast.body && traverseNode(ast.body, transformer);
1210
+ // set meta information
1211
+ const context = transformer.context();
1212
+ ast.helpers = Array.from(context.helpers);
1213
+ }
1214
+
1215
+ function optimize(ast) {
1216
+ const body = ast.body;
1217
+ if (body.type === 2 /* NodeTypes.Message */) {
1218
+ optimizeMessageNode(body);
1219
+ }
1220
+ else {
1221
+ body.cases.forEach(c => optimizeMessageNode(c));
1222
+ }
1223
+ return ast;
1224
+ }
1225
+ function optimizeMessageNode(message) {
1226
+ if (message.items.length === 1) {
1227
+ const item = message.items[0];
1228
+ if (item.type === 3 /* NodeTypes.Text */ || item.type === 9 /* NodeTypes.Literal */) {
1229
+ message.static = item.value;
1230
+ delete item.value; // optimization for size
1231
+ }
1232
+ }
1233
+ else {
1234
+ const values = [];
1235
+ for (let i = 0; i < message.items.length; i++) {
1236
+ const item = message.items[i];
1237
+ if (!(item.type === 3 /* NodeTypes.Text */ || item.type === 9 /* NodeTypes.Literal */)) {
1238
+ break;
1239
+ }
1240
+ if (item.value == null) {
1241
+ break;
1242
+ }
1243
+ values.push(item.value);
1244
+ }
1245
+ if (values.length === message.items.length) {
1246
+ message.static = join(values);
1247
+ for (let i = 0; i < message.items.length; i++) {
1248
+ const item = message.items[i];
1249
+ if (item.type === 3 /* NodeTypes.Text */ || item.type === 9 /* NodeTypes.Literal */) {
1250
+ delete item.value; // optimization for size
1251
+ }
1252
+ }
1253
+ }
1254
+ }
1255
+ }
1256
+
1257
+ const ERROR_DOMAIN$1 = 'minifier';
1258
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1259
+ function minify(node) {
1260
+ node.t = node.type;
1261
+ switch (node.type) {
1262
+ case 0 /* NodeTypes.Resource */: {
1263
+ const resource = node;
1264
+ minify(resource.body);
1265
+ resource.b = resource.body;
1266
+ delete resource.body;
1267
+ break;
1268
+ }
1269
+ case 1 /* NodeTypes.Plural */: {
1270
+ const plural = node;
1271
+ const cases = plural.cases;
1272
+ for (let i = 0; i < cases.length; i++) {
1273
+ minify(cases[i]);
1274
+ }
1275
+ plural.c = cases;
1276
+ delete plural.cases;
1277
+ break;
1278
+ }
1279
+ case 2 /* NodeTypes.Message */: {
1280
+ const message = node;
1281
+ const items = message.items;
1282
+ for (let i = 0; i < items.length; i++) {
1283
+ minify(items[i]);
1284
+ }
1285
+ message.i = items;
1286
+ delete message.items;
1287
+ if (message.static) {
1288
+ message.s = message.static;
1289
+ delete message.static;
1290
+ }
1291
+ break;
1292
+ }
1293
+ case 3 /* NodeTypes.Text */:
1294
+ case 9 /* NodeTypes.Literal */:
1295
+ case 8 /* NodeTypes.LinkedModifier */:
1296
+ case 7 /* NodeTypes.LinkedKey */: {
1297
+ const valueNode = node;
1298
+ if (valueNode.value) {
1299
+ valueNode.v = valueNode.value;
1300
+ delete valueNode.value;
1301
+ }
1302
+ break;
1303
+ }
1304
+ case 6 /* NodeTypes.Linked */: {
1305
+ const linked = node;
1306
+ minify(linked.key);
1307
+ linked.k = linked.key;
1308
+ delete linked.key;
1309
+ if (linked.modifier) {
1310
+ minify(linked.modifier);
1311
+ linked.m = linked.modifier;
1312
+ delete linked.modifier;
1313
+ }
1314
+ break;
1315
+ }
1316
+ case 5 /* NodeTypes.List */: {
1317
+ const list = node;
1318
+ list.i = list.index;
1319
+ delete list.index;
1320
+ break;
1321
+ }
1322
+ case 4 /* NodeTypes.Named */: {
1323
+ const named = node;
1324
+ named.k = named.key;
1325
+ delete named.key;
1326
+ break;
1327
+ }
1328
+ default:
1329
+ if ((process.env.NODE_ENV !== 'production')) {
1330
+ throw createCompileError(CompileErrorCodes.UNHANDLED_MINIFIER_NODE_TYPE, null, {
1331
+ domain: ERROR_DOMAIN$1,
1332
+ args: [node.type]
1333
+ });
1334
+ }
1335
+ }
1336
+ delete node.type;
1337
+ }
1338
+ /* eslint-enable @typescript-eslint/no-explicit-any */
1339
+
1340
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
1341
+ /// <reference types="source-map-js" />
1342
+ const ERROR_DOMAIN = 'parser';
1343
+ function createCodeGenerator(ast, options) {
1344
+ const { filename, breakLineCode, needIndent: _needIndent } = options;
1345
+ const location = options.location !== false;
1346
+ const _context = {
1347
+ filename,
1348
+ code: '',
1349
+ column: 1,
1350
+ line: 1,
1351
+ offset: 0,
1352
+ map: undefined,
1353
+ breakLineCode,
1354
+ needIndent: _needIndent,
1355
+ indentLevel: 0
1356
+ };
1357
+ if (location && ast.loc) {
1358
+ _context.source = ast.loc.source;
1359
+ }
1360
+ const context = () => _context;
1361
+ function push(code, node) {
1362
+ _context.code += code;
1363
+ }
1364
+ function _newline(n, withBreakLine = true) {
1365
+ const _breakLineCode = withBreakLine ? breakLineCode : '';
1366
+ push(_needIndent ? _breakLineCode + ` `.repeat(n) : _breakLineCode);
1367
+ }
1368
+ function indent(withNewLine = true) {
1369
+ const level = ++_context.indentLevel;
1370
+ withNewLine && _newline(level);
1371
+ }
1372
+ function deindent(withNewLine = true) {
1373
+ const level = --_context.indentLevel;
1374
+ withNewLine && _newline(level);
1375
+ }
1376
+ function newline() {
1377
+ _newline(_context.indentLevel);
1378
+ }
1379
+ const helper = (key) => `_${key}`;
1380
+ const needIndent = () => _context.needIndent;
1381
+ return {
1382
+ context,
1383
+ push,
1384
+ indent,
1385
+ deindent,
1386
+ newline,
1387
+ helper,
1388
+ needIndent
1389
+ };
1390
+ }
1391
+ function generateLinkedNode(generator, node) {
1392
+ const { helper } = generator;
1393
+ generator.push(`${helper("linked" /* HelperNameMap.LINKED */)}(`);
1394
+ generateNode(generator, node.key);
1395
+ if (node.modifier) {
1396
+ generator.push(`, `);
1397
+ generateNode(generator, node.modifier);
1398
+ generator.push(`, _type`);
1399
+ }
1400
+ else {
1401
+ generator.push(`, undefined, _type`);
1402
+ }
1403
+ generator.push(`)`);
1404
+ }
1405
+ function generateMessageNode(generator, node) {
1406
+ const { helper, needIndent } = generator;
1407
+ generator.push(`${helper("normalize" /* HelperNameMap.NORMALIZE */)}([`);
1408
+ generator.indent(needIndent());
1409
+ const length = node.items.length;
1410
+ for (let i = 0; i < length; i++) {
1411
+ generateNode(generator, node.items[i]);
1412
+ if (i === length - 1) {
1413
+ break;
1414
+ }
1415
+ generator.push(', ');
1416
+ }
1417
+ generator.deindent(needIndent());
1418
+ generator.push('])');
1419
+ }
1420
+ function generatePluralNode(generator, node) {
1421
+ const { helper, needIndent } = generator;
1422
+ if (node.cases.length > 1) {
1423
+ generator.push(`${helper("plural" /* HelperNameMap.PLURAL */)}([`);
1424
+ generator.indent(needIndent());
1425
+ const length = node.cases.length;
1426
+ for (let i = 0; i < length; i++) {
1427
+ generateNode(generator, node.cases[i]);
1428
+ if (i === length - 1) {
1429
+ break;
1430
+ }
1431
+ generator.push(', ');
1432
+ }
1433
+ generator.deindent(needIndent());
1434
+ generator.push(`])`);
1435
+ }
1436
+ }
1437
+ function generateResource(generator, node) {
1438
+ if (node.body) {
1439
+ generateNode(generator, node.body);
1440
+ }
1441
+ else {
1442
+ generator.push('null');
1443
+ }
1444
+ }
1445
+ function generateNode(generator, node) {
1446
+ const { helper } = generator;
1447
+ switch (node.type) {
1448
+ case 0 /* NodeTypes.Resource */:
1449
+ generateResource(generator, node);
1450
+ break;
1451
+ case 1 /* NodeTypes.Plural */:
1452
+ generatePluralNode(generator, node);
1453
+ break;
1454
+ case 2 /* NodeTypes.Message */:
1455
+ generateMessageNode(generator, node);
1456
+ break;
1457
+ case 6 /* NodeTypes.Linked */:
1458
+ generateLinkedNode(generator, node);
1459
+ break;
1460
+ case 8 /* NodeTypes.LinkedModifier */:
1461
+ generator.push(JSON.stringify(node.value), node);
1462
+ break;
1463
+ case 7 /* NodeTypes.LinkedKey */:
1464
+ generator.push(JSON.stringify(node.value), node);
1465
+ break;
1466
+ case 5 /* NodeTypes.List */:
1467
+ generator.push(`${helper("interpolate" /* HelperNameMap.INTERPOLATE */)}(${helper("list" /* HelperNameMap.LIST */)}(${node.index}))`, node);
1468
+ break;
1469
+ case 4 /* NodeTypes.Named */:
1470
+ generator.push(`${helper("interpolate" /* HelperNameMap.INTERPOLATE */)}(${helper("named" /* HelperNameMap.NAMED */)}(${JSON.stringify(node.key)}))`, node);
1471
+ break;
1472
+ case 9 /* NodeTypes.Literal */:
1473
+ generator.push(JSON.stringify(node.value), node);
1474
+ break;
1475
+ case 3 /* NodeTypes.Text */:
1476
+ generator.push(JSON.stringify(node.value), node);
1477
+ break;
1478
+ default:
1479
+ if ((process.env.NODE_ENV !== 'production')) {
1480
+ throw createCompileError(CompileErrorCodes.UNHANDLED_CODEGEN_NODE_TYPE, null, {
1481
+ domain: ERROR_DOMAIN,
1482
+ args: [node.type]
1483
+ });
1484
+ }
1485
+ }
1486
+ }
1487
+ // generate code from AST
1488
+ const generate = (ast, options = {}) => {
1489
+ const mode = isString(options.mode) ? options.mode : 'normal';
1490
+ const filename = isString(options.filename)
1491
+ ? options.filename
1492
+ : 'message.intl';
1493
+ !!options.sourceMap;
1494
+ // prettier-ignore
1495
+ const breakLineCode = options.breakLineCode != null
1496
+ ? options.breakLineCode
1497
+ : mode === 'arrow'
1498
+ ? ';'
1499
+ : '\n';
1500
+ const needIndent = options.needIndent ? options.needIndent : mode !== 'arrow';
1501
+ const helpers = ast.helpers || [];
1502
+ const generator = createCodeGenerator(ast, {
1503
+ filename,
1504
+ breakLineCode,
1505
+ needIndent
1506
+ });
1507
+ generator.push(mode === 'normal' ? `function __msg__ (ctx) {` : `(ctx) => {`);
1508
+ generator.indent(needIndent);
1509
+ if (helpers.length > 0) {
1510
+ generator.push(`const { ${join(helpers.map(s => `${s}: _${s}`), ', ')} } = ctx`);
1511
+ generator.newline();
1512
+ }
1513
+ generator.push(`return `);
1514
+ generateNode(generator, ast);
1515
+ generator.deindent(needIndent);
1516
+ generator.push(`}`);
1517
+ delete ast.helpers;
1518
+ const { code, map } = generator.context();
1519
+ return {
1520
+ ast,
1521
+ code,
1522
+ map: map ? map.toJSON() : undefined // eslint-disable-line @typescript-eslint/no-explicit-any
1523
+ };
1524
+ };
1525
+
1526
+ function baseCompile(source, options = {}) {
1527
+ const assignedOptions = assign({}, options);
1528
+ const jit = !!assignedOptions.jit;
1529
+ const enalbeMinify = !!assignedOptions.minify;
1530
+ const enambeOptimize = assignedOptions.optimize == null ? true : assignedOptions.optimize;
1531
+ // parse source codes
1532
+ const parser = createParser(assignedOptions);
1533
+ const ast = parser.parse(source);
1534
+ if (!jit) {
1535
+ // transform ASTs
1536
+ transform(ast, assignedOptions);
1537
+ // generate javascript codes
1538
+ return generate(ast, assignedOptions);
1539
+ }
1540
+ else {
1541
+ // optimize ASTs
1542
+ enambeOptimize && optimize(ast);
1543
+ // minimize ASTs
1544
+ enalbeMinify && minify(ast);
1545
+ // In JIT mode, no ast transform, no code generation.
1546
+ return { ast, code: '' };
1547
+ }
1548
+ }
1549
+
1550
+ export { COMPILE_ERROR_CODES_EXTEND_POINT, CompileErrorCodes, ERROR_DOMAIN$2 as ERROR_DOMAIN, LOCATION_STUB, baseCompile, createCompileError, createLocation, createParser, createPosition, defaultOnError, detectHtmlTag, errorMessages };