@intlify/message-compiler 9.13.0 → 10.0.0-alpha.1
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.
- package/dist/message-compiler.cjs +59 -144
- package/dist/message-compiler.d.ts +0 -22
- package/dist/message-compiler.esm-browser.js +60 -142
- package/dist/message-compiler.esm-browser.prod.js +2 -2
- package/dist/message-compiler.global.js +59 -144
- package/dist/message-compiler.global.prod.js +2 -2
- package/dist/message-compiler.mjs +60 -142
- package/dist/message-compiler.node.mjs +60 -142
- package/dist/message-compiler.prod.cjs +59 -144
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* message-compiler
|
|
2
|
+
* message-compiler v10.0.0-alpha.1
|
|
3
3
|
* (c) 2024 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -46,23 +46,6 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
46
46
|
return items.reduce((str, item, index) => (index === 0 ? str + item : str + separator + item), '');
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
const CompileWarnCodes = {
|
|
50
|
-
USE_MODULO_SYNTAX: 1,
|
|
51
|
-
__EXTEND_POINT__: 2
|
|
52
|
-
};
|
|
53
|
-
/** @internal */
|
|
54
|
-
const warnMessages = {
|
|
55
|
-
[CompileWarnCodes.USE_MODULO_SYNTAX]: `Use modulo before '{{0}}'.`
|
|
56
|
-
};
|
|
57
|
-
function createCompileWarn(code, loc, ...args) {
|
|
58
|
-
const msg = format(warnMessages[code] || '', ...(args || [])) ;
|
|
59
|
-
const message = { message: String(msg), code };
|
|
60
|
-
if (loc) {
|
|
61
|
-
message.location = loc;
|
|
62
|
-
}
|
|
63
|
-
return message;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
49
|
const CompileErrorCodes = {
|
|
67
50
|
// tokenizer error codes
|
|
68
51
|
EXPECTED_TOKEN: 1,
|
|
@@ -187,7 +170,6 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
187
170
|
}
|
|
188
171
|
function skipToPeek() {
|
|
189
172
|
const target = _index + _peekOffset;
|
|
190
|
-
// eslint-disable-next-line no-unmodified-loop-condition
|
|
191
173
|
while (target !== _index) {
|
|
192
174
|
next();
|
|
193
175
|
}
|
|
@@ -221,11 +203,11 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
221
203
|
const _initLoc = currentPosition();
|
|
222
204
|
const _initOffset = currentOffset();
|
|
223
205
|
const _context = {
|
|
224
|
-
currentType:
|
|
206
|
+
currentType: 13 /* TokenTypes.EOF */,
|
|
225
207
|
offset: _initOffset,
|
|
226
208
|
startLoc: _initLoc,
|
|
227
209
|
endLoc: _initLoc,
|
|
228
|
-
lastType:
|
|
210
|
+
lastType: 13 /* TokenTypes.EOF */,
|
|
229
211
|
lastOffset: _initOffset,
|
|
230
212
|
lastStartLoc: _initLoc,
|
|
231
213
|
lastEndLoc: _initLoc,
|
|
@@ -260,7 +242,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
260
242
|
}
|
|
261
243
|
return token;
|
|
262
244
|
}
|
|
263
|
-
const getEndToken = (context) => getToken(context,
|
|
245
|
+
const getEndToken = (context) => getToken(context, 13 /* TokenTypes.EOF */);
|
|
264
246
|
function eat(scnr, ch) {
|
|
265
247
|
if (scnr.currentChar() === ch) {
|
|
266
248
|
scnr.next();
|
|
@@ -334,7 +316,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
334
316
|
}
|
|
335
317
|
function isLinkedDotStart(scnr, context) {
|
|
336
318
|
const { currentType } = context;
|
|
337
|
-
if (currentType !==
|
|
319
|
+
if (currentType !== 7 /* TokenTypes.LinkedAlias */) {
|
|
338
320
|
return false;
|
|
339
321
|
}
|
|
340
322
|
peekSpaces(scnr);
|
|
@@ -344,7 +326,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
344
326
|
}
|
|
345
327
|
function isLinkedModifierStart(scnr, context) {
|
|
346
328
|
const { currentType } = context;
|
|
347
|
-
if (currentType !==
|
|
329
|
+
if (currentType !== 8 /* TokenTypes.LinkedDot */) {
|
|
348
330
|
return false;
|
|
349
331
|
}
|
|
350
332
|
peekSpaces(scnr);
|
|
@@ -354,8 +336,8 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
354
336
|
}
|
|
355
337
|
function isLinkedDelimiterStart(scnr, context) {
|
|
356
338
|
const { currentType } = context;
|
|
357
|
-
if (!(currentType ===
|
|
358
|
-
currentType ===
|
|
339
|
+
if (!(currentType === 7 /* TokenTypes.LinkedAlias */ ||
|
|
340
|
+
currentType === 11 /* TokenTypes.LinkedModifier */)) {
|
|
359
341
|
return false;
|
|
360
342
|
}
|
|
361
343
|
peekSpaces(scnr);
|
|
@@ -365,7 +347,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
365
347
|
}
|
|
366
348
|
function isLinkedReferStart(scnr, context) {
|
|
367
349
|
const { currentType } = context;
|
|
368
|
-
if (currentType !==
|
|
350
|
+
if (currentType !== 9 /* TokenTypes.LinkedDelimiter */) {
|
|
369
351
|
return false;
|
|
370
352
|
}
|
|
371
353
|
const fn = () => {
|
|
@@ -374,7 +356,6 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
374
356
|
return isIdentifierStart(scnr.peek());
|
|
375
357
|
}
|
|
376
358
|
else if (ch === "@" /* TokenChars.LinkedAlias */ ||
|
|
377
|
-
ch === "%" /* TokenChars.Modulo */ ||
|
|
378
359
|
ch === "|" /* TokenChars.Pipe */ ||
|
|
379
360
|
ch === ":" /* TokenChars.LinkedDelimiter */ ||
|
|
380
361
|
ch === "." /* TokenChars.LinkedDot */ ||
|
|
@@ -388,7 +369,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
388
369
|
}
|
|
389
370
|
else {
|
|
390
371
|
// other characters
|
|
391
|
-
return
|
|
372
|
+
return isTextStart(scnr, false);
|
|
392
373
|
}
|
|
393
374
|
};
|
|
394
375
|
const ret = fn();
|
|
@@ -401,41 +382,25 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
401
382
|
scnr.resetPeek();
|
|
402
383
|
return ret;
|
|
403
384
|
}
|
|
404
|
-
function detectModuloStart(scnr) {
|
|
405
|
-
const spaces = peekSpaces(scnr);
|
|
406
|
-
const ret = scnr.currentPeek() === "%" /* TokenChars.Modulo */ &&
|
|
407
|
-
scnr.peek() === "{" /* TokenChars.BraceLeft */;
|
|
408
|
-
scnr.resetPeek();
|
|
409
|
-
return {
|
|
410
|
-
isModulo: ret,
|
|
411
|
-
hasSpace: spaces.length > 0
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
385
|
function isTextStart(scnr, reset = true) {
|
|
415
|
-
const fn = (hasSpace = false, prev = ''
|
|
386
|
+
const fn = (hasSpace = false, prev = '') => {
|
|
416
387
|
const ch = scnr.currentPeek();
|
|
417
388
|
if (ch === "{" /* TokenChars.BraceLeft */) {
|
|
418
|
-
return
|
|
389
|
+
return hasSpace;
|
|
419
390
|
}
|
|
420
391
|
else if (ch === "@" /* TokenChars.LinkedAlias */ || !ch) {
|
|
421
|
-
return
|
|
422
|
-
}
|
|
423
|
-
else if (ch === "%" /* TokenChars.Modulo */) {
|
|
424
|
-
scnr.peek();
|
|
425
|
-
return fn(hasSpace, "%" /* TokenChars.Modulo */, true);
|
|
392
|
+
return hasSpace;
|
|
426
393
|
}
|
|
427
394
|
else if (ch === "|" /* TokenChars.Pipe */) {
|
|
428
|
-
return prev ===
|
|
429
|
-
? true
|
|
430
|
-
: !(prev === CHAR_SP || prev === CHAR_LF);
|
|
395
|
+
return !(prev === CHAR_SP || prev === CHAR_LF);
|
|
431
396
|
}
|
|
432
397
|
else if (ch === CHAR_SP) {
|
|
433
398
|
scnr.peek();
|
|
434
|
-
return fn(true, CHAR_SP
|
|
399
|
+
return fn(true, CHAR_SP);
|
|
435
400
|
}
|
|
436
401
|
else if (ch === CHAR_LF) {
|
|
437
402
|
scnr.peek();
|
|
438
|
-
return fn(true, CHAR_LF
|
|
403
|
+
return fn(true, CHAR_LF);
|
|
439
404
|
}
|
|
440
405
|
else {
|
|
441
406
|
return true;
|
|
@@ -505,18 +470,8 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
505
470
|
}
|
|
506
471
|
return num;
|
|
507
472
|
}
|
|
508
|
-
function readModulo(scnr) {
|
|
509
|
-
skipSpaces(scnr);
|
|
510
|
-
const ch = scnr.currentChar();
|
|
511
|
-
if (ch !== "%" /* TokenChars.Modulo */) {
|
|
512
|
-
emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
|
|
513
|
-
}
|
|
514
|
-
scnr.next();
|
|
515
|
-
return "%" /* TokenChars.Modulo */;
|
|
516
|
-
}
|
|
517
473
|
function readText(scnr) {
|
|
518
474
|
let buf = '';
|
|
519
|
-
// eslint-disable-next-line no-constant-condition
|
|
520
475
|
while (true) {
|
|
521
476
|
const ch = scnr.currentChar();
|
|
522
477
|
if (ch === "{" /* TokenChars.BraceLeft */ ||
|
|
@@ -526,15 +481,6 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
526
481
|
!ch) {
|
|
527
482
|
break;
|
|
528
483
|
}
|
|
529
|
-
else if (ch === "%" /* TokenChars.Modulo */) {
|
|
530
|
-
if (isTextStart(scnr)) {
|
|
531
|
-
buf += ch;
|
|
532
|
-
scnr.next();
|
|
533
|
-
}
|
|
534
|
-
else {
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
484
|
else if (ch === CHAR_SP || ch === CHAR_LF) {
|
|
539
485
|
if (isTextStart(scnr)) {
|
|
540
486
|
buf += ch;
|
|
@@ -667,10 +613,9 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
667
613
|
return name;
|
|
668
614
|
}
|
|
669
615
|
function readLinkedRefer(scnr) {
|
|
670
|
-
const fn = (
|
|
616
|
+
const fn = (buf) => {
|
|
671
617
|
const ch = scnr.currentChar();
|
|
672
618
|
if (ch === "{" /* TokenChars.BraceLeft */ ||
|
|
673
|
-
ch === "%" /* TokenChars.Modulo */ ||
|
|
674
619
|
ch === "@" /* TokenChars.LinkedAlias */ ||
|
|
675
620
|
ch === "|" /* TokenChars.Pipe */ ||
|
|
676
621
|
ch === "(" /* TokenChars.ParenLeft */ ||
|
|
@@ -684,15 +629,15 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
684
629
|
else if (ch === CHAR_LF || ch === DOT) {
|
|
685
630
|
buf += ch;
|
|
686
631
|
scnr.next();
|
|
687
|
-
return fn(
|
|
632
|
+
return fn(buf);
|
|
688
633
|
}
|
|
689
634
|
else {
|
|
690
635
|
buf += ch;
|
|
691
636
|
scnr.next();
|
|
692
|
-
return fn(
|
|
637
|
+
return fn(buf);
|
|
693
638
|
}
|
|
694
639
|
};
|
|
695
|
-
return fn(
|
|
640
|
+
return fn('');
|
|
696
641
|
}
|
|
697
642
|
function readPlural(scnr) {
|
|
698
643
|
skipSpaces(scnr);
|
|
@@ -749,31 +694,31 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
749
694
|
return token;
|
|
750
695
|
}
|
|
751
696
|
if (context.braceNest > 0 &&
|
|
752
|
-
(context.currentType ===
|
|
753
|
-
context.currentType ===
|
|
754
|
-
context.currentType ===
|
|
697
|
+
(context.currentType === 4 /* TokenTypes.Named */ ||
|
|
698
|
+
context.currentType === 5 /* TokenTypes.List */ ||
|
|
699
|
+
context.currentType === 6 /* TokenTypes.Literal */)) {
|
|
755
700
|
emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
|
|
756
701
|
context.braceNest = 0;
|
|
757
702
|
return readToken(scnr, context);
|
|
758
703
|
}
|
|
759
704
|
if ((validNamedIdentifier = isNamedIdentifierStart(scnr, context))) {
|
|
760
|
-
token = getToken(context,
|
|
705
|
+
token = getToken(context, 4 /* TokenTypes.Named */, readNamedIdentifier(scnr));
|
|
761
706
|
skipSpaces(scnr);
|
|
762
707
|
return token;
|
|
763
708
|
}
|
|
764
709
|
if ((validListIdentifier = isListIdentifierStart(scnr, context))) {
|
|
765
|
-
token = getToken(context,
|
|
710
|
+
token = getToken(context, 5 /* TokenTypes.List */, readListIdentifier(scnr));
|
|
766
711
|
skipSpaces(scnr);
|
|
767
712
|
return token;
|
|
768
713
|
}
|
|
769
714
|
if ((validLiteral = isLiteralStart(scnr, context))) {
|
|
770
|
-
token = getToken(context,
|
|
715
|
+
token = getToken(context, 6 /* TokenTypes.Literal */, readLiteral(scnr));
|
|
771
716
|
skipSpaces(scnr);
|
|
772
717
|
return token;
|
|
773
718
|
}
|
|
774
719
|
if (!validNamedIdentifier && !validListIdentifier && !validLiteral) {
|
|
775
720
|
// TODO: we should be re-designed invalid cases, when we will extend message syntax near the future ...
|
|
776
|
-
token = getToken(context,
|
|
721
|
+
token = getToken(context, 12 /* TokenTypes.InvalidPlace */, readInvalidIdentifier(scnr));
|
|
777
722
|
emitError(CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER, currentPosition(), 0, token.value);
|
|
778
723
|
skipSpaces(scnr);
|
|
779
724
|
return token;
|
|
@@ -788,27 +733,27 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
788
733
|
const { currentType } = context;
|
|
789
734
|
let token = null;
|
|
790
735
|
const ch = scnr.currentChar();
|
|
791
|
-
if ((currentType ===
|
|
792
|
-
currentType ===
|
|
793
|
-
currentType ===
|
|
794
|
-
currentType ===
|
|
736
|
+
if ((currentType === 7 /* TokenTypes.LinkedAlias */ ||
|
|
737
|
+
currentType === 8 /* TokenTypes.LinkedDot */ ||
|
|
738
|
+
currentType === 11 /* TokenTypes.LinkedModifier */ ||
|
|
739
|
+
currentType === 9 /* TokenTypes.LinkedDelimiter */) &&
|
|
795
740
|
(ch === CHAR_LF || ch === CHAR_SP)) {
|
|
796
741
|
emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);
|
|
797
742
|
}
|
|
798
743
|
switch (ch) {
|
|
799
744
|
case "@" /* TokenChars.LinkedAlias */:
|
|
800
745
|
scnr.next();
|
|
801
|
-
token = getToken(context,
|
|
746
|
+
token = getToken(context, 7 /* TokenTypes.LinkedAlias */, "@" /* TokenChars.LinkedAlias */);
|
|
802
747
|
context.inLinked = true;
|
|
803
748
|
return token;
|
|
804
749
|
case "." /* TokenChars.LinkedDot */:
|
|
805
750
|
skipSpaces(scnr);
|
|
806
751
|
scnr.next();
|
|
807
|
-
return getToken(context,
|
|
752
|
+
return getToken(context, 8 /* TokenTypes.LinkedDot */, "." /* TokenChars.LinkedDot */);
|
|
808
753
|
case ":" /* TokenChars.LinkedDelimiter */:
|
|
809
754
|
skipSpaces(scnr);
|
|
810
755
|
scnr.next();
|
|
811
|
-
return getToken(context,
|
|
756
|
+
return getToken(context, 9 /* TokenTypes.LinkedDelimiter */, ":" /* TokenChars.LinkedDelimiter */);
|
|
812
757
|
default:
|
|
813
758
|
if (isPluralStart(scnr)) {
|
|
814
759
|
token = getToken(context, 1 /* TokenTypes.Pipe */, readPlural(scnr));
|
|
@@ -824,7 +769,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
824
769
|
}
|
|
825
770
|
if (isLinkedModifierStart(scnr, context)) {
|
|
826
771
|
skipSpaces(scnr);
|
|
827
|
-
return getToken(context,
|
|
772
|
+
return getToken(context, 11 /* TokenTypes.LinkedModifier */, readLinkedModifier(scnr));
|
|
828
773
|
}
|
|
829
774
|
if (isLinkedReferStart(scnr, context)) {
|
|
830
775
|
skipSpaces(scnr);
|
|
@@ -833,10 +778,10 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
833
778
|
return readTokenInPlaceholder(scnr, context) || token;
|
|
834
779
|
}
|
|
835
780
|
else {
|
|
836
|
-
return getToken(context,
|
|
781
|
+
return getToken(context, 10 /* TokenTypes.LinkedKey */, readLinkedRefer(scnr));
|
|
837
782
|
}
|
|
838
783
|
}
|
|
839
|
-
if (currentType ===
|
|
784
|
+
if (currentType === 7 /* TokenTypes.LinkedAlias */) {
|
|
840
785
|
emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);
|
|
841
786
|
}
|
|
842
787
|
context.braceNest = 0;
|
|
@@ -846,7 +791,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
846
791
|
}
|
|
847
792
|
// TODO: We need refactoring of token parsing ...
|
|
848
793
|
function readToken(scnr, context) {
|
|
849
|
-
let token = { type:
|
|
794
|
+
let token = { type: 13 /* TokenTypes.EOF */ };
|
|
850
795
|
if (context.braceNest > 0) {
|
|
851
796
|
return readTokenInPlaceholder(scnr, context) || getEndToken(context);
|
|
852
797
|
}
|
|
@@ -871,12 +816,6 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
871
816
|
context.inLinked = false;
|
|
872
817
|
return token;
|
|
873
818
|
}
|
|
874
|
-
const { isModulo, hasSpace } = detectModuloStart(scnr);
|
|
875
|
-
if (isModulo) {
|
|
876
|
-
return hasSpace
|
|
877
|
-
? getToken(context, 0 /* TokenTypes.Text */, readText(scnr))
|
|
878
|
-
: getToken(context, 4 /* TokenTypes.Modulo */, readModulo(scnr));
|
|
879
|
-
}
|
|
880
819
|
if (isTextStart(scnr)) {
|
|
881
820
|
return getToken(context, 0 /* TokenTypes.Text */, readText(scnr));
|
|
882
821
|
}
|
|
@@ -894,7 +833,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
894
833
|
_context.offset = currentOffset();
|
|
895
834
|
_context.startLoc = currentPosition();
|
|
896
835
|
if (_scnr.currentChar() === EOF) {
|
|
897
|
-
return getToken(_context,
|
|
836
|
+
return getToken(_context, 13 /* TokenTypes.EOF */);
|
|
898
837
|
}
|
|
899
838
|
return readToken(_scnr, _context);
|
|
900
839
|
}
|
|
@@ -930,7 +869,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
930
869
|
}
|
|
931
870
|
function createParser(options = {}) {
|
|
932
871
|
const location = options.location !== false;
|
|
933
|
-
const { onError
|
|
872
|
+
const { onError } = options;
|
|
934
873
|
function emitError(tokenzer, code, start, offset, ...args) {
|
|
935
874
|
const end = tokenzer.currentPosition();
|
|
936
875
|
end.offset += offset;
|
|
@@ -944,15 +883,6 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
944
883
|
onError(err);
|
|
945
884
|
}
|
|
946
885
|
}
|
|
947
|
-
function emitWarn(tokenzer, code, start, offset, ...args) {
|
|
948
|
-
const end = tokenzer.currentPosition();
|
|
949
|
-
end.offset += offset;
|
|
950
|
-
end.column += offset;
|
|
951
|
-
if (onWarn) {
|
|
952
|
-
const loc = location ? createLocation(start, end) : null;
|
|
953
|
-
onWarn(createCompileWarn(code, loc, args));
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
886
|
function startNode(type, offset, loc) {
|
|
957
887
|
const node = { type };
|
|
958
888
|
if (location) {
|
|
@@ -989,14 +919,11 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
989
919
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
990
920
|
return node;
|
|
991
921
|
}
|
|
992
|
-
function parseNamed(tokenizer, key
|
|
922
|
+
function parseNamed(tokenizer, key) {
|
|
993
923
|
const context = tokenizer.context();
|
|
994
924
|
const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
|
|
995
925
|
const node = startNode(4 /* NodeTypes.Named */, offset, loc);
|
|
996
926
|
node.key = key;
|
|
997
|
-
if (modulo === true) {
|
|
998
|
-
node.modulo = true;
|
|
999
|
-
}
|
|
1000
927
|
tokenizer.nextToken(); // skip brach right
|
|
1001
928
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
1002
929
|
return node;
|
|
@@ -1015,7 +942,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
1015
942
|
const context = tokenizer.context();
|
|
1016
943
|
const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc
|
|
1017
944
|
const node = startNode(8 /* NodeTypes.LinkedModifier */, offset, loc);
|
|
1018
|
-
if (token.type !==
|
|
945
|
+
if (token.type !== 11 /* TokenTypes.LinkedModifier */) {
|
|
1019
946
|
// empty modifier
|
|
1020
947
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER, context.lastStartLoc, 0);
|
|
1021
948
|
node.value = '';
|
|
@@ -1046,13 +973,13 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
1046
973
|
const context = tokenizer.context();
|
|
1047
974
|
const linkedNode = startNode(6 /* NodeTypes.Linked */, context.offset, context.startLoc);
|
|
1048
975
|
let token = tokenizer.nextToken();
|
|
1049
|
-
if (token.type ===
|
|
976
|
+
if (token.type === 8 /* TokenTypes.LinkedDot */) {
|
|
1050
977
|
const parsed = parseLinkedModifier(tokenizer);
|
|
1051
978
|
linkedNode.modifier = parsed.node;
|
|
1052
979
|
token = parsed.nextConsumeToken || tokenizer.nextToken();
|
|
1053
980
|
}
|
|
1054
981
|
// asset check token
|
|
1055
|
-
if (token.type !==
|
|
982
|
+
if (token.type !== 9 /* TokenTypes.LinkedDelimiter */) {
|
|
1056
983
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1057
984
|
}
|
|
1058
985
|
token = tokenizer.nextToken();
|
|
@@ -1061,25 +988,25 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
1061
988
|
token = tokenizer.nextToken();
|
|
1062
989
|
}
|
|
1063
990
|
switch (token.type) {
|
|
1064
|
-
case
|
|
991
|
+
case 10 /* TokenTypes.LinkedKey */:
|
|
1065
992
|
if (token.value == null) {
|
|
1066
993
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1067
994
|
}
|
|
1068
995
|
linkedNode.key = parseLinkedKey(tokenizer, token.value || '');
|
|
1069
996
|
break;
|
|
1070
|
-
case
|
|
997
|
+
case 4 /* TokenTypes.Named */:
|
|
1071
998
|
if (token.value == null) {
|
|
1072
999
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1073
1000
|
}
|
|
1074
1001
|
linkedNode.key = parseNamed(tokenizer, token.value || '');
|
|
1075
1002
|
break;
|
|
1076
|
-
case
|
|
1003
|
+
case 5 /* TokenTypes.List */:
|
|
1077
1004
|
if (token.value == null) {
|
|
1078
1005
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1079
1006
|
}
|
|
1080
1007
|
linkedNode.key = parseList(tokenizer, token.value || '');
|
|
1081
1008
|
break;
|
|
1082
|
-
case
|
|
1009
|
+
case 6 /* TokenTypes.Literal */:
|
|
1083
1010
|
if (token.value == null) {
|
|
1084
1011
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1085
1012
|
}
|
|
@@ -1116,7 +1043,6 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
1116
1043
|
const node = startNode(2 /* NodeTypes.Message */, startOffset, startLoc);
|
|
1117
1044
|
node.items = [];
|
|
1118
1045
|
let nextToken = null;
|
|
1119
|
-
let modulo = null;
|
|
1120
1046
|
do {
|
|
1121
1047
|
const token = nextToken || tokenizer.nextToken();
|
|
1122
1048
|
nextToken = null;
|
|
@@ -1127,39 +1053,32 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
1127
1053
|
}
|
|
1128
1054
|
node.items.push(parseText(tokenizer, token.value || ''));
|
|
1129
1055
|
break;
|
|
1130
|
-
case
|
|
1056
|
+
case 5 /* TokenTypes.List */:
|
|
1131
1057
|
if (token.value == null) {
|
|
1132
1058
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1133
1059
|
}
|
|
1134
1060
|
node.items.push(parseList(tokenizer, token.value || ''));
|
|
1135
1061
|
break;
|
|
1136
|
-
case 4 /* TokenTypes.
|
|
1137
|
-
modulo = true;
|
|
1138
|
-
break;
|
|
1139
|
-
case 5 /* TokenTypes.Named */:
|
|
1062
|
+
case 4 /* TokenTypes.Named */:
|
|
1140
1063
|
if (token.value == null) {
|
|
1141
1064
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1142
1065
|
}
|
|
1143
|
-
node.items.push(parseNamed(tokenizer, token.value || ''
|
|
1144
|
-
if (modulo) {
|
|
1145
|
-
emitWarn(tokenizer, CompileWarnCodes.USE_MODULO_SYNTAX, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1146
|
-
modulo = null;
|
|
1147
|
-
}
|
|
1066
|
+
node.items.push(parseNamed(tokenizer, token.value || ''));
|
|
1148
1067
|
break;
|
|
1149
|
-
case
|
|
1068
|
+
case 6 /* TokenTypes.Literal */:
|
|
1150
1069
|
if (token.value == null) {
|
|
1151
1070
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1152
1071
|
}
|
|
1153
1072
|
node.items.push(parseLiteral(tokenizer, token.value || ''));
|
|
1154
1073
|
break;
|
|
1155
|
-
case
|
|
1074
|
+
case 7 /* TokenTypes.LinkedAlias */: {
|
|
1156
1075
|
const parsed = parseLinked(tokenizer);
|
|
1157
1076
|
node.items.push(parsed.node);
|
|
1158
1077
|
nextToken = parsed.nextConsumeToken || null;
|
|
1159
1078
|
break;
|
|
1160
1079
|
}
|
|
1161
1080
|
}
|
|
1162
|
-
} while (context.currentType !==
|
|
1081
|
+
} while (context.currentType !== 13 /* TokenTypes.EOF */ &&
|
|
1163
1082
|
context.currentType !== 1 /* TokenTypes.Pipe */);
|
|
1164
1083
|
// adjust message node loc
|
|
1165
1084
|
const endOffset = context.currentType === 1 /* TokenTypes.Pipe */
|
|
@@ -1183,7 +1102,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
1183
1102
|
hasEmptyMessage = msg.items.length === 0;
|
|
1184
1103
|
}
|
|
1185
1104
|
node.cases.push(msg);
|
|
1186
|
-
} while (context.currentType !==
|
|
1105
|
+
} while (context.currentType !== 13 /* TokenTypes.EOF */);
|
|
1187
1106
|
if (hasEmptyMessage) {
|
|
1188
1107
|
emitError(tokenizer, CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL, loc, 0);
|
|
1189
1108
|
}
|
|
@@ -1194,7 +1113,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
1194
1113
|
const context = tokenizer.context();
|
|
1195
1114
|
const { offset, startLoc } = context;
|
|
1196
1115
|
const msgNode = parseMessage(tokenizer);
|
|
1197
|
-
if (context.currentType ===
|
|
1116
|
+
if (context.currentType === 13 /* TokenTypes.EOF */) {
|
|
1198
1117
|
return msgNode;
|
|
1199
1118
|
}
|
|
1200
1119
|
else {
|
|
@@ -1213,7 +1132,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
1213
1132
|
node.cacheKey = options.onCacheKey(source);
|
|
1214
1133
|
}
|
|
1215
1134
|
// assert whether achieved to EOF
|
|
1216
|
-
if (context.currentType !==
|
|
1135
|
+
if (context.currentType !== 13 /* TokenTypes.EOF */) {
|
|
1217
1136
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, source[context.offset] || '');
|
|
1218
1137
|
}
|
|
1219
1138
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
@@ -1222,7 +1141,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
1222
1141
|
return { parse };
|
|
1223
1142
|
}
|
|
1224
1143
|
function getTokenCaption(token) {
|
|
1225
|
-
if (token.type ===
|
|
1144
|
+
if (token.type === 13 /* TokenTypes.EOF */) {
|
|
1226
1145
|
return 'EOF';
|
|
1227
1146
|
}
|
|
1228
1147
|
const name = (token.value || '').replace(/\r?\n/gu, '\\n');
|
|
@@ -1560,8 +1479,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
1560
1479
|
}
|
|
1561
1480
|
}
|
|
1562
1481
|
// generate code from AST
|
|
1563
|
-
const generate = (ast, options = {}
|
|
1564
|
-
) => {
|
|
1482
|
+
const generate = (ast, options = {}) => {
|
|
1565
1483
|
const mode = isString(options.mode) ? options.mode : 'normal';
|
|
1566
1484
|
const filename = isString(options.filename)
|
|
1567
1485
|
? options.filename
|
|
@@ -1626,19 +1544,16 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
1626
1544
|
}
|
|
1627
1545
|
|
|
1628
1546
|
exports.CompileErrorCodes = CompileErrorCodes;
|
|
1629
|
-
exports.CompileWarnCodes = CompileWarnCodes;
|
|
1630
1547
|
exports.ERROR_DOMAIN = ERROR_DOMAIN$2;
|
|
1631
1548
|
exports.LOCATION_STUB = LOCATION_STUB;
|
|
1632
1549
|
exports.baseCompile = baseCompile;
|
|
1633
1550
|
exports.createCompileError = createCompileError;
|
|
1634
|
-
exports.createCompileWarn = createCompileWarn;
|
|
1635
1551
|
exports.createLocation = createLocation;
|
|
1636
1552
|
exports.createParser = createParser;
|
|
1637
1553
|
exports.createPosition = createPosition;
|
|
1638
1554
|
exports.defaultOnError = defaultOnError;
|
|
1639
1555
|
exports.detectHtmlTag = detectHtmlTag;
|
|
1640
1556
|
exports.errorMessages = errorMessages;
|
|
1641
|
-
exports.warnMessages = warnMessages;
|
|
1642
1557
|
|
|
1643
1558
|
return exports;
|
|
1644
1559
|
|