@intlify/message-compiler 9.13.1 → 10.0.0-alpha.2
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 +54 -139
- package/dist/message-compiler.d.ts +0 -22
- package/dist/message-compiler.esm-browser.js +55 -137
- package/dist/message-compiler.esm-browser.prod.js +2 -2
- package/dist/message-compiler.global.js +54 -139
- package/dist/message-compiler.global.prod.js +2 -2
- package/dist/message-compiler.mjs +55 -137
- package/dist/message-compiler.node.mjs +55 -137
- package/dist/message-compiler.prod.cjs +54 -139
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* message-compiler
|
|
2
|
+
* message-compiler v10.0.0-alpha.2
|
|
3
3
|
* (c) 2024 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -21,23 +21,6 @@ function createLocation(start, end, source) {
|
|
|
21
21
|
return loc;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const CompileWarnCodes = {
|
|
25
|
-
USE_MODULO_SYNTAX: 1,
|
|
26
|
-
__EXTEND_POINT__: 2
|
|
27
|
-
};
|
|
28
|
-
/** @internal */
|
|
29
|
-
const warnMessages = {
|
|
30
|
-
[CompileWarnCodes.USE_MODULO_SYNTAX]: `Use modulo before '{{0}}'.`
|
|
31
|
-
};
|
|
32
|
-
function createCompileWarn(code, loc, ...args) {
|
|
33
|
-
const msg = (process.env.NODE_ENV !== 'production') ? format(warnMessages[code] || '', ...(args || [])) : code;
|
|
34
|
-
const message = { message: String(msg), code };
|
|
35
|
-
if (loc) {
|
|
36
|
-
message.location = loc;
|
|
37
|
-
}
|
|
38
|
-
return message;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
24
|
const CompileErrorCodes = {
|
|
42
25
|
// tokenizer error codes
|
|
43
26
|
EXPECTED_TOKEN: 1,
|
|
@@ -163,7 +146,6 @@ function createScanner(str) {
|
|
|
163
146
|
}
|
|
164
147
|
function skipToPeek() {
|
|
165
148
|
const target = _index + _peekOffset;
|
|
166
|
-
// eslint-disable-next-line no-unmodified-loop-condition
|
|
167
149
|
while (target !== _index) {
|
|
168
150
|
next();
|
|
169
151
|
}
|
|
@@ -197,11 +179,11 @@ function createTokenizer(source, options = {}) {
|
|
|
197
179
|
const _initLoc = currentPosition();
|
|
198
180
|
const _initOffset = currentOffset();
|
|
199
181
|
const _context = {
|
|
200
|
-
currentType:
|
|
182
|
+
currentType: 13 /* TokenTypes.EOF */,
|
|
201
183
|
offset: _initOffset,
|
|
202
184
|
startLoc: _initLoc,
|
|
203
185
|
endLoc: _initLoc,
|
|
204
|
-
lastType:
|
|
186
|
+
lastType: 13 /* TokenTypes.EOF */,
|
|
205
187
|
lastOffset: _initOffset,
|
|
206
188
|
lastStartLoc: _initLoc,
|
|
207
189
|
lastEndLoc: _initLoc,
|
|
@@ -236,7 +218,7 @@ function createTokenizer(source, options = {}) {
|
|
|
236
218
|
}
|
|
237
219
|
return token;
|
|
238
220
|
}
|
|
239
|
-
const getEndToken = (context) => getToken(context,
|
|
221
|
+
const getEndToken = (context) => getToken(context, 13 /* TokenTypes.EOF */);
|
|
240
222
|
function eat(scnr, ch) {
|
|
241
223
|
if (scnr.currentChar() === ch) {
|
|
242
224
|
scnr.next();
|
|
@@ -310,7 +292,7 @@ function createTokenizer(source, options = {}) {
|
|
|
310
292
|
}
|
|
311
293
|
function isLinkedDotStart(scnr, context) {
|
|
312
294
|
const { currentType } = context;
|
|
313
|
-
if (currentType !==
|
|
295
|
+
if (currentType !== 7 /* TokenTypes.LinkedAlias */) {
|
|
314
296
|
return false;
|
|
315
297
|
}
|
|
316
298
|
peekSpaces(scnr);
|
|
@@ -320,7 +302,7 @@ function createTokenizer(source, options = {}) {
|
|
|
320
302
|
}
|
|
321
303
|
function isLinkedModifierStart(scnr, context) {
|
|
322
304
|
const { currentType } = context;
|
|
323
|
-
if (currentType !==
|
|
305
|
+
if (currentType !== 8 /* TokenTypes.LinkedDot */) {
|
|
324
306
|
return false;
|
|
325
307
|
}
|
|
326
308
|
peekSpaces(scnr);
|
|
@@ -330,8 +312,8 @@ function createTokenizer(source, options = {}) {
|
|
|
330
312
|
}
|
|
331
313
|
function isLinkedDelimiterStart(scnr, context) {
|
|
332
314
|
const { currentType } = context;
|
|
333
|
-
if (!(currentType ===
|
|
334
|
-
currentType ===
|
|
315
|
+
if (!(currentType === 7 /* TokenTypes.LinkedAlias */ ||
|
|
316
|
+
currentType === 11 /* TokenTypes.LinkedModifier */)) {
|
|
335
317
|
return false;
|
|
336
318
|
}
|
|
337
319
|
peekSpaces(scnr);
|
|
@@ -341,7 +323,7 @@ function createTokenizer(source, options = {}) {
|
|
|
341
323
|
}
|
|
342
324
|
function isLinkedReferStart(scnr, context) {
|
|
343
325
|
const { currentType } = context;
|
|
344
|
-
if (currentType !==
|
|
326
|
+
if (currentType !== 9 /* TokenTypes.LinkedDelimiter */) {
|
|
345
327
|
return false;
|
|
346
328
|
}
|
|
347
329
|
const fn = () => {
|
|
@@ -350,7 +332,6 @@ function createTokenizer(source, options = {}) {
|
|
|
350
332
|
return isIdentifierStart(scnr.peek());
|
|
351
333
|
}
|
|
352
334
|
else if (ch === "@" /* TokenChars.LinkedAlias */ ||
|
|
353
|
-
ch === "%" /* TokenChars.Modulo */ ||
|
|
354
335
|
ch === "|" /* TokenChars.Pipe */ ||
|
|
355
336
|
ch === ":" /* TokenChars.LinkedDelimiter */ ||
|
|
356
337
|
ch === "." /* TokenChars.LinkedDot */ ||
|
|
@@ -377,41 +358,25 @@ function createTokenizer(source, options = {}) {
|
|
|
377
358
|
scnr.resetPeek();
|
|
378
359
|
return ret;
|
|
379
360
|
}
|
|
380
|
-
function detectModuloStart(scnr) {
|
|
381
|
-
const spaces = peekSpaces(scnr);
|
|
382
|
-
const ret = scnr.currentPeek() === "%" /* TokenChars.Modulo */ &&
|
|
383
|
-
scnr.peek() === "{" /* TokenChars.BraceLeft */;
|
|
384
|
-
scnr.resetPeek();
|
|
385
|
-
return {
|
|
386
|
-
isModulo: ret,
|
|
387
|
-
hasSpace: spaces.length > 0
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
361
|
function isTextStart(scnr, reset = true) {
|
|
391
|
-
const fn = (hasSpace = false, prev = ''
|
|
362
|
+
const fn = (hasSpace = false, prev = '') => {
|
|
392
363
|
const ch = scnr.currentPeek();
|
|
393
364
|
if (ch === "{" /* TokenChars.BraceLeft */) {
|
|
394
|
-
return
|
|
365
|
+
return hasSpace;
|
|
395
366
|
}
|
|
396
367
|
else if (ch === "@" /* TokenChars.LinkedAlias */ || !ch) {
|
|
397
|
-
return
|
|
398
|
-
}
|
|
399
|
-
else if (ch === "%" /* TokenChars.Modulo */) {
|
|
400
|
-
scnr.peek();
|
|
401
|
-
return fn(hasSpace, "%" /* TokenChars.Modulo */, true);
|
|
368
|
+
return hasSpace;
|
|
402
369
|
}
|
|
403
370
|
else if (ch === "|" /* TokenChars.Pipe */) {
|
|
404
|
-
return prev ===
|
|
405
|
-
? true
|
|
406
|
-
: !(prev === CHAR_SP || prev === CHAR_LF);
|
|
371
|
+
return !(prev === CHAR_SP || prev === CHAR_LF);
|
|
407
372
|
}
|
|
408
373
|
else if (ch === CHAR_SP) {
|
|
409
374
|
scnr.peek();
|
|
410
|
-
return fn(true, CHAR_SP
|
|
375
|
+
return fn(true, CHAR_SP);
|
|
411
376
|
}
|
|
412
377
|
else if (ch === CHAR_LF) {
|
|
413
378
|
scnr.peek();
|
|
414
|
-
return fn(true, CHAR_LF
|
|
379
|
+
return fn(true, CHAR_LF);
|
|
415
380
|
}
|
|
416
381
|
else {
|
|
417
382
|
return true;
|
|
@@ -481,18 +446,8 @@ function createTokenizer(source, options = {}) {
|
|
|
481
446
|
}
|
|
482
447
|
return num;
|
|
483
448
|
}
|
|
484
|
-
function readModulo(scnr) {
|
|
485
|
-
skipSpaces(scnr);
|
|
486
|
-
const ch = scnr.currentChar();
|
|
487
|
-
if (ch !== "%" /* TokenChars.Modulo */) {
|
|
488
|
-
emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
|
|
489
|
-
}
|
|
490
|
-
scnr.next();
|
|
491
|
-
return "%" /* TokenChars.Modulo */;
|
|
492
|
-
}
|
|
493
449
|
function readText(scnr) {
|
|
494
450
|
let buf = '';
|
|
495
|
-
// eslint-disable-next-line no-constant-condition
|
|
496
451
|
while (true) {
|
|
497
452
|
const ch = scnr.currentChar();
|
|
498
453
|
if (ch === "{" /* TokenChars.BraceLeft */ ||
|
|
@@ -502,15 +457,6 @@ function createTokenizer(source, options = {}) {
|
|
|
502
457
|
!ch) {
|
|
503
458
|
break;
|
|
504
459
|
}
|
|
505
|
-
else if (ch === "%" /* TokenChars.Modulo */) {
|
|
506
|
-
if (isTextStart(scnr)) {
|
|
507
|
-
buf += ch;
|
|
508
|
-
scnr.next();
|
|
509
|
-
}
|
|
510
|
-
else {
|
|
511
|
-
break;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
460
|
else if (ch === CHAR_SP || ch === CHAR_LF) {
|
|
515
461
|
if (isTextStart(scnr)) {
|
|
516
462
|
buf += ch;
|
|
@@ -646,7 +592,6 @@ function createTokenizer(source, options = {}) {
|
|
|
646
592
|
const fn = (buf) => {
|
|
647
593
|
const ch = scnr.currentChar();
|
|
648
594
|
if (ch === "{" /* TokenChars.BraceLeft */ ||
|
|
649
|
-
ch === "%" /* TokenChars.Modulo */ ||
|
|
650
595
|
ch === "@" /* TokenChars.LinkedAlias */ ||
|
|
651
596
|
ch === "|" /* TokenChars.Pipe */ ||
|
|
652
597
|
ch === "(" /* TokenChars.ParenLeft */ ||
|
|
@@ -725,31 +670,31 @@ function createTokenizer(source, options = {}) {
|
|
|
725
670
|
return token;
|
|
726
671
|
}
|
|
727
672
|
if (context.braceNest > 0 &&
|
|
728
|
-
(context.currentType ===
|
|
729
|
-
context.currentType ===
|
|
730
|
-
context.currentType ===
|
|
673
|
+
(context.currentType === 4 /* TokenTypes.Named */ ||
|
|
674
|
+
context.currentType === 5 /* TokenTypes.List */ ||
|
|
675
|
+
context.currentType === 6 /* TokenTypes.Literal */)) {
|
|
731
676
|
emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
|
|
732
677
|
context.braceNest = 0;
|
|
733
678
|
return readToken(scnr, context);
|
|
734
679
|
}
|
|
735
680
|
if ((validNamedIdentifier = isNamedIdentifierStart(scnr, context))) {
|
|
736
|
-
token = getToken(context,
|
|
681
|
+
token = getToken(context, 4 /* TokenTypes.Named */, readNamedIdentifier(scnr));
|
|
737
682
|
skipSpaces(scnr);
|
|
738
683
|
return token;
|
|
739
684
|
}
|
|
740
685
|
if ((validListIdentifier = isListIdentifierStart(scnr, context))) {
|
|
741
|
-
token = getToken(context,
|
|
686
|
+
token = getToken(context, 5 /* TokenTypes.List */, readListIdentifier(scnr));
|
|
742
687
|
skipSpaces(scnr);
|
|
743
688
|
return token;
|
|
744
689
|
}
|
|
745
690
|
if ((validLiteral = isLiteralStart(scnr, context))) {
|
|
746
|
-
token = getToken(context,
|
|
691
|
+
token = getToken(context, 6 /* TokenTypes.Literal */, readLiteral(scnr));
|
|
747
692
|
skipSpaces(scnr);
|
|
748
693
|
return token;
|
|
749
694
|
}
|
|
750
695
|
if (!validNamedIdentifier && !validListIdentifier && !validLiteral) {
|
|
751
696
|
// TODO: we should be re-designed invalid cases, when we will extend message syntax near the future ...
|
|
752
|
-
token = getToken(context,
|
|
697
|
+
token = getToken(context, 12 /* TokenTypes.InvalidPlace */, readInvalidIdentifier(scnr));
|
|
753
698
|
emitError(CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER, currentPosition(), 0, token.value);
|
|
754
699
|
skipSpaces(scnr);
|
|
755
700
|
return token;
|
|
@@ -764,27 +709,27 @@ function createTokenizer(source, options = {}) {
|
|
|
764
709
|
const { currentType } = context;
|
|
765
710
|
let token = null;
|
|
766
711
|
const ch = scnr.currentChar();
|
|
767
|
-
if ((currentType ===
|
|
768
|
-
currentType ===
|
|
769
|
-
currentType ===
|
|
770
|
-
currentType ===
|
|
712
|
+
if ((currentType === 7 /* TokenTypes.LinkedAlias */ ||
|
|
713
|
+
currentType === 8 /* TokenTypes.LinkedDot */ ||
|
|
714
|
+
currentType === 11 /* TokenTypes.LinkedModifier */ ||
|
|
715
|
+
currentType === 9 /* TokenTypes.LinkedDelimiter */) &&
|
|
771
716
|
(ch === CHAR_LF || ch === CHAR_SP)) {
|
|
772
717
|
emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);
|
|
773
718
|
}
|
|
774
719
|
switch (ch) {
|
|
775
720
|
case "@" /* TokenChars.LinkedAlias */:
|
|
776
721
|
scnr.next();
|
|
777
|
-
token = getToken(context,
|
|
722
|
+
token = getToken(context, 7 /* TokenTypes.LinkedAlias */, "@" /* TokenChars.LinkedAlias */);
|
|
778
723
|
context.inLinked = true;
|
|
779
724
|
return token;
|
|
780
725
|
case "." /* TokenChars.LinkedDot */:
|
|
781
726
|
skipSpaces(scnr);
|
|
782
727
|
scnr.next();
|
|
783
|
-
return getToken(context,
|
|
728
|
+
return getToken(context, 8 /* TokenTypes.LinkedDot */, "." /* TokenChars.LinkedDot */);
|
|
784
729
|
case ":" /* TokenChars.LinkedDelimiter */:
|
|
785
730
|
skipSpaces(scnr);
|
|
786
731
|
scnr.next();
|
|
787
|
-
return getToken(context,
|
|
732
|
+
return getToken(context, 9 /* TokenTypes.LinkedDelimiter */, ":" /* TokenChars.LinkedDelimiter */);
|
|
788
733
|
default:
|
|
789
734
|
if (isPluralStart(scnr)) {
|
|
790
735
|
token = getToken(context, 1 /* TokenTypes.Pipe */, readPlural(scnr));
|
|
@@ -800,7 +745,7 @@ function createTokenizer(source, options = {}) {
|
|
|
800
745
|
}
|
|
801
746
|
if (isLinkedModifierStart(scnr, context)) {
|
|
802
747
|
skipSpaces(scnr);
|
|
803
|
-
return getToken(context,
|
|
748
|
+
return getToken(context, 11 /* TokenTypes.LinkedModifier */, readLinkedModifier(scnr));
|
|
804
749
|
}
|
|
805
750
|
if (isLinkedReferStart(scnr, context)) {
|
|
806
751
|
skipSpaces(scnr);
|
|
@@ -809,10 +754,10 @@ function createTokenizer(source, options = {}) {
|
|
|
809
754
|
return readTokenInPlaceholder(scnr, context) || token;
|
|
810
755
|
}
|
|
811
756
|
else {
|
|
812
|
-
return getToken(context,
|
|
757
|
+
return getToken(context, 10 /* TokenTypes.LinkedKey */, readLinkedRefer(scnr));
|
|
813
758
|
}
|
|
814
759
|
}
|
|
815
|
-
if (currentType ===
|
|
760
|
+
if (currentType === 7 /* TokenTypes.LinkedAlias */) {
|
|
816
761
|
emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);
|
|
817
762
|
}
|
|
818
763
|
context.braceNest = 0;
|
|
@@ -822,7 +767,7 @@ function createTokenizer(source, options = {}) {
|
|
|
822
767
|
}
|
|
823
768
|
// TODO: We need refactoring of token parsing ...
|
|
824
769
|
function readToken(scnr, context) {
|
|
825
|
-
let token = { type:
|
|
770
|
+
let token = { type: 13 /* TokenTypes.EOF */ };
|
|
826
771
|
if (context.braceNest > 0) {
|
|
827
772
|
return readTokenInPlaceholder(scnr, context) || getEndToken(context);
|
|
828
773
|
}
|
|
@@ -847,12 +792,6 @@ function createTokenizer(source, options = {}) {
|
|
|
847
792
|
context.inLinked = false;
|
|
848
793
|
return token;
|
|
849
794
|
}
|
|
850
|
-
const { isModulo, hasSpace } = detectModuloStart(scnr);
|
|
851
|
-
if (isModulo) {
|
|
852
|
-
return hasSpace
|
|
853
|
-
? getToken(context, 0 /* TokenTypes.Text */, readText(scnr))
|
|
854
|
-
: getToken(context, 4 /* TokenTypes.Modulo */, readModulo(scnr));
|
|
855
|
-
}
|
|
856
795
|
if (isTextStart(scnr)) {
|
|
857
796
|
return getToken(context, 0 /* TokenTypes.Text */, readText(scnr));
|
|
858
797
|
}
|
|
@@ -870,7 +809,7 @@ function createTokenizer(source, options = {}) {
|
|
|
870
809
|
_context.offset = currentOffset();
|
|
871
810
|
_context.startLoc = currentPosition();
|
|
872
811
|
if (_scnr.currentChar() === EOF) {
|
|
873
|
-
return getToken(_context,
|
|
812
|
+
return getToken(_context, 13 /* TokenTypes.EOF */);
|
|
874
813
|
}
|
|
875
814
|
return readToken(_scnr, _context);
|
|
876
815
|
}
|
|
@@ -906,7 +845,7 @@ function fromEscapeSequence(match, codePoint4, codePoint6) {
|
|
|
906
845
|
}
|
|
907
846
|
function createParser(options = {}) {
|
|
908
847
|
const location = options.location !== false;
|
|
909
|
-
const { onError
|
|
848
|
+
const { onError } = options;
|
|
910
849
|
function emitError(tokenzer, code, start, offset, ...args) {
|
|
911
850
|
const end = tokenzer.currentPosition();
|
|
912
851
|
end.offset += offset;
|
|
@@ -920,15 +859,6 @@ function createParser(options = {}) {
|
|
|
920
859
|
onError(err);
|
|
921
860
|
}
|
|
922
861
|
}
|
|
923
|
-
function emitWarn(tokenzer, code, start, offset, ...args) {
|
|
924
|
-
const end = tokenzer.currentPosition();
|
|
925
|
-
end.offset += offset;
|
|
926
|
-
end.column += offset;
|
|
927
|
-
if (onWarn) {
|
|
928
|
-
const loc = location ? createLocation(start, end) : null;
|
|
929
|
-
onWarn(createCompileWarn(code, loc, args));
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
862
|
function startNode(type, offset, loc) {
|
|
933
863
|
const node = { type };
|
|
934
864
|
if (location) {
|
|
@@ -965,14 +895,11 @@ function createParser(options = {}) {
|
|
|
965
895
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
966
896
|
return node;
|
|
967
897
|
}
|
|
968
|
-
function parseNamed(tokenizer, key
|
|
898
|
+
function parseNamed(tokenizer, key) {
|
|
969
899
|
const context = tokenizer.context();
|
|
970
900
|
const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
|
|
971
901
|
const node = startNode(4 /* NodeTypes.Named */, offset, loc);
|
|
972
902
|
node.key = key;
|
|
973
|
-
if (modulo === true) {
|
|
974
|
-
node.modulo = true;
|
|
975
|
-
}
|
|
976
903
|
tokenizer.nextToken(); // skip brach right
|
|
977
904
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
978
905
|
return node;
|
|
@@ -991,7 +918,7 @@ function createParser(options = {}) {
|
|
|
991
918
|
const context = tokenizer.context();
|
|
992
919
|
const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc
|
|
993
920
|
const node = startNode(8 /* NodeTypes.LinkedModifier */, offset, loc);
|
|
994
|
-
if (token.type !==
|
|
921
|
+
if (token.type !== 11 /* TokenTypes.LinkedModifier */) {
|
|
995
922
|
// empty modifier
|
|
996
923
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER, context.lastStartLoc, 0);
|
|
997
924
|
node.value = '';
|
|
@@ -1022,13 +949,13 @@ function createParser(options = {}) {
|
|
|
1022
949
|
const context = tokenizer.context();
|
|
1023
950
|
const linkedNode = startNode(6 /* NodeTypes.Linked */, context.offset, context.startLoc);
|
|
1024
951
|
let token = tokenizer.nextToken();
|
|
1025
|
-
if (token.type ===
|
|
952
|
+
if (token.type === 8 /* TokenTypes.LinkedDot */) {
|
|
1026
953
|
const parsed = parseLinkedModifier(tokenizer);
|
|
1027
954
|
linkedNode.modifier = parsed.node;
|
|
1028
955
|
token = parsed.nextConsumeToken || tokenizer.nextToken();
|
|
1029
956
|
}
|
|
1030
957
|
// asset check token
|
|
1031
|
-
if (token.type !==
|
|
958
|
+
if (token.type !== 9 /* TokenTypes.LinkedDelimiter */) {
|
|
1032
959
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1033
960
|
}
|
|
1034
961
|
token = tokenizer.nextToken();
|
|
@@ -1037,25 +964,25 @@ function createParser(options = {}) {
|
|
|
1037
964
|
token = tokenizer.nextToken();
|
|
1038
965
|
}
|
|
1039
966
|
switch (token.type) {
|
|
1040
|
-
case
|
|
967
|
+
case 10 /* TokenTypes.LinkedKey */:
|
|
1041
968
|
if (token.value == null) {
|
|
1042
969
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1043
970
|
}
|
|
1044
971
|
linkedNode.key = parseLinkedKey(tokenizer, token.value || '');
|
|
1045
972
|
break;
|
|
1046
|
-
case
|
|
973
|
+
case 4 /* TokenTypes.Named */:
|
|
1047
974
|
if (token.value == null) {
|
|
1048
975
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1049
976
|
}
|
|
1050
977
|
linkedNode.key = parseNamed(tokenizer, token.value || '');
|
|
1051
978
|
break;
|
|
1052
|
-
case
|
|
979
|
+
case 5 /* TokenTypes.List */:
|
|
1053
980
|
if (token.value == null) {
|
|
1054
981
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1055
982
|
}
|
|
1056
983
|
linkedNode.key = parseList(tokenizer, token.value || '');
|
|
1057
984
|
break;
|
|
1058
|
-
case
|
|
985
|
+
case 6 /* TokenTypes.Literal */:
|
|
1059
986
|
if (token.value == null) {
|
|
1060
987
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1061
988
|
}
|
|
@@ -1092,7 +1019,6 @@ function createParser(options = {}) {
|
|
|
1092
1019
|
const node = startNode(2 /* NodeTypes.Message */, startOffset, startLoc);
|
|
1093
1020
|
node.items = [];
|
|
1094
1021
|
let nextToken = null;
|
|
1095
|
-
let modulo = null;
|
|
1096
1022
|
do {
|
|
1097
1023
|
const token = nextToken || tokenizer.nextToken();
|
|
1098
1024
|
nextToken = null;
|
|
@@ -1103,39 +1029,32 @@ function createParser(options = {}) {
|
|
|
1103
1029
|
}
|
|
1104
1030
|
node.items.push(parseText(tokenizer, token.value || ''));
|
|
1105
1031
|
break;
|
|
1106
|
-
case
|
|
1032
|
+
case 5 /* TokenTypes.List */:
|
|
1107
1033
|
if (token.value == null) {
|
|
1108
1034
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1109
1035
|
}
|
|
1110
1036
|
node.items.push(parseList(tokenizer, token.value || ''));
|
|
1111
1037
|
break;
|
|
1112
|
-
case 4 /* TokenTypes.
|
|
1113
|
-
modulo = true;
|
|
1114
|
-
break;
|
|
1115
|
-
case 5 /* TokenTypes.Named */:
|
|
1038
|
+
case 4 /* TokenTypes.Named */:
|
|
1116
1039
|
if (token.value == null) {
|
|
1117
1040
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1118
1041
|
}
|
|
1119
|
-
node.items.push(parseNamed(tokenizer, token.value || ''
|
|
1120
|
-
if (modulo) {
|
|
1121
|
-
emitWarn(tokenizer, CompileWarnCodes.USE_MODULO_SYNTAX, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1122
|
-
modulo = null;
|
|
1123
|
-
}
|
|
1042
|
+
node.items.push(parseNamed(tokenizer, token.value || ''));
|
|
1124
1043
|
break;
|
|
1125
|
-
case
|
|
1044
|
+
case 6 /* TokenTypes.Literal */:
|
|
1126
1045
|
if (token.value == null) {
|
|
1127
1046
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1128
1047
|
}
|
|
1129
1048
|
node.items.push(parseLiteral(tokenizer, token.value || ''));
|
|
1130
1049
|
break;
|
|
1131
|
-
case
|
|
1050
|
+
case 7 /* TokenTypes.LinkedAlias */: {
|
|
1132
1051
|
const parsed = parseLinked(tokenizer);
|
|
1133
1052
|
node.items.push(parsed.node);
|
|
1134
1053
|
nextToken = parsed.nextConsumeToken || null;
|
|
1135
1054
|
break;
|
|
1136
1055
|
}
|
|
1137
1056
|
}
|
|
1138
|
-
} while (context.currentType !==
|
|
1057
|
+
} while (context.currentType !== 13 /* TokenTypes.EOF */ &&
|
|
1139
1058
|
context.currentType !== 1 /* TokenTypes.Pipe */);
|
|
1140
1059
|
// adjust message node loc
|
|
1141
1060
|
const endOffset = context.currentType === 1 /* TokenTypes.Pipe */
|
|
@@ -1159,7 +1078,7 @@ function createParser(options = {}) {
|
|
|
1159
1078
|
hasEmptyMessage = msg.items.length === 0;
|
|
1160
1079
|
}
|
|
1161
1080
|
node.cases.push(msg);
|
|
1162
|
-
} while (context.currentType !==
|
|
1081
|
+
} while (context.currentType !== 13 /* TokenTypes.EOF */);
|
|
1163
1082
|
if (hasEmptyMessage) {
|
|
1164
1083
|
emitError(tokenizer, CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL, loc, 0);
|
|
1165
1084
|
}
|
|
@@ -1170,7 +1089,7 @@ function createParser(options = {}) {
|
|
|
1170
1089
|
const context = tokenizer.context();
|
|
1171
1090
|
const { offset, startLoc } = context;
|
|
1172
1091
|
const msgNode = parseMessage(tokenizer);
|
|
1173
|
-
if (context.currentType ===
|
|
1092
|
+
if (context.currentType === 13 /* TokenTypes.EOF */) {
|
|
1174
1093
|
return msgNode;
|
|
1175
1094
|
}
|
|
1176
1095
|
else {
|
|
@@ -1189,7 +1108,7 @@ function createParser(options = {}) {
|
|
|
1189
1108
|
node.cacheKey = options.onCacheKey(source);
|
|
1190
1109
|
}
|
|
1191
1110
|
// assert whether achieved to EOF
|
|
1192
|
-
if (context.currentType !==
|
|
1111
|
+
if (context.currentType !== 13 /* TokenTypes.EOF */) {
|
|
1193
1112
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, source[context.offset] || '');
|
|
1194
1113
|
}
|
|
1195
1114
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
@@ -1198,7 +1117,7 @@ function createParser(options = {}) {
|
|
|
1198
1117
|
return { parse };
|
|
1199
1118
|
}
|
|
1200
1119
|
function getTokenCaption(token) {
|
|
1201
|
-
if (token.type ===
|
|
1120
|
+
if (token.type === 13 /* TokenTypes.EOF */) {
|
|
1202
1121
|
return 'EOF';
|
|
1203
1122
|
}
|
|
1204
1123
|
const name = (token.value || '').replace(/\r?\n/gu, '\\n');
|
|
@@ -1560,8 +1479,7 @@ function generateNode(generator, node) {
|
|
|
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
|
|
@@ -1657,4 +1575,4 @@ function baseCompile(source, options = {}) {
|
|
|
1657
1575
|
}
|
|
1658
1576
|
}
|
|
1659
1577
|
|
|
1660
|
-
export { CompileErrorCodes,
|
|
1578
|
+
export { CompileErrorCodes, ERROR_DOMAIN$2 as ERROR_DOMAIN, LOCATION_STUB, baseCompile, createCompileError, createLocation, createParser, createPosition, defaultOnError, detectHtmlTag, errorMessages };
|