@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
|
*/
|
|
@@ -23,23 +23,6 @@ function createLocation(start, end, source) {
|
|
|
23
23
|
return loc;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const CompileWarnCodes = {
|
|
27
|
-
USE_MODULO_SYNTAX: 1,
|
|
28
|
-
__EXTEND_POINT__: 2
|
|
29
|
-
};
|
|
30
|
-
/** @internal */
|
|
31
|
-
const warnMessages = {
|
|
32
|
-
[CompileWarnCodes.USE_MODULO_SYNTAX]: `Use modulo before '{{0}}'.`
|
|
33
|
-
};
|
|
34
|
-
function createCompileWarn(code, loc, ...args) {
|
|
35
|
-
const msg = shared.format(warnMessages[code] || '', ...(args || [])) ;
|
|
36
|
-
const message = { message: String(msg), code };
|
|
37
|
-
if (loc) {
|
|
38
|
-
message.location = loc;
|
|
39
|
-
}
|
|
40
|
-
return message;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
26
|
const CompileErrorCodes = {
|
|
44
27
|
// tokenizer error codes
|
|
45
28
|
EXPECTED_TOKEN: 1,
|
|
@@ -164,7 +147,6 @@ function createScanner(str) {
|
|
|
164
147
|
}
|
|
165
148
|
function skipToPeek() {
|
|
166
149
|
const target = _index + _peekOffset;
|
|
167
|
-
// eslint-disable-next-line no-unmodified-loop-condition
|
|
168
150
|
while (target !== _index) {
|
|
169
151
|
next();
|
|
170
152
|
}
|
|
@@ -198,11 +180,11 @@ function createTokenizer(source, options = {}) {
|
|
|
198
180
|
const _initLoc = currentPosition();
|
|
199
181
|
const _initOffset = currentOffset();
|
|
200
182
|
const _context = {
|
|
201
|
-
currentType:
|
|
183
|
+
currentType: 13 /* TokenTypes.EOF */,
|
|
202
184
|
offset: _initOffset,
|
|
203
185
|
startLoc: _initLoc,
|
|
204
186
|
endLoc: _initLoc,
|
|
205
|
-
lastType:
|
|
187
|
+
lastType: 13 /* TokenTypes.EOF */,
|
|
206
188
|
lastOffset: _initOffset,
|
|
207
189
|
lastStartLoc: _initLoc,
|
|
208
190
|
lastEndLoc: _initLoc,
|
|
@@ -237,7 +219,7 @@ function createTokenizer(source, options = {}) {
|
|
|
237
219
|
}
|
|
238
220
|
return token;
|
|
239
221
|
}
|
|
240
|
-
const getEndToken = (context) => getToken(context,
|
|
222
|
+
const getEndToken = (context) => getToken(context, 13 /* TokenTypes.EOF */);
|
|
241
223
|
function eat(scnr, ch) {
|
|
242
224
|
if (scnr.currentChar() === ch) {
|
|
243
225
|
scnr.next();
|
|
@@ -311,7 +293,7 @@ function createTokenizer(source, options = {}) {
|
|
|
311
293
|
}
|
|
312
294
|
function isLinkedDotStart(scnr, context) {
|
|
313
295
|
const { currentType } = context;
|
|
314
|
-
if (currentType !==
|
|
296
|
+
if (currentType !== 7 /* TokenTypes.LinkedAlias */) {
|
|
315
297
|
return false;
|
|
316
298
|
}
|
|
317
299
|
peekSpaces(scnr);
|
|
@@ -321,7 +303,7 @@ function createTokenizer(source, options = {}) {
|
|
|
321
303
|
}
|
|
322
304
|
function isLinkedModifierStart(scnr, context) {
|
|
323
305
|
const { currentType } = context;
|
|
324
|
-
if (currentType !==
|
|
306
|
+
if (currentType !== 8 /* TokenTypes.LinkedDot */) {
|
|
325
307
|
return false;
|
|
326
308
|
}
|
|
327
309
|
peekSpaces(scnr);
|
|
@@ -331,8 +313,8 @@ function createTokenizer(source, options = {}) {
|
|
|
331
313
|
}
|
|
332
314
|
function isLinkedDelimiterStart(scnr, context) {
|
|
333
315
|
const { currentType } = context;
|
|
334
|
-
if (!(currentType ===
|
|
335
|
-
currentType ===
|
|
316
|
+
if (!(currentType === 7 /* TokenTypes.LinkedAlias */ ||
|
|
317
|
+
currentType === 11 /* TokenTypes.LinkedModifier */)) {
|
|
336
318
|
return false;
|
|
337
319
|
}
|
|
338
320
|
peekSpaces(scnr);
|
|
@@ -342,7 +324,7 @@ function createTokenizer(source, options = {}) {
|
|
|
342
324
|
}
|
|
343
325
|
function isLinkedReferStart(scnr, context) {
|
|
344
326
|
const { currentType } = context;
|
|
345
|
-
if (currentType !==
|
|
327
|
+
if (currentType !== 9 /* TokenTypes.LinkedDelimiter */) {
|
|
346
328
|
return false;
|
|
347
329
|
}
|
|
348
330
|
const fn = () => {
|
|
@@ -351,7 +333,6 @@ function createTokenizer(source, options = {}) {
|
|
|
351
333
|
return isIdentifierStart(scnr.peek());
|
|
352
334
|
}
|
|
353
335
|
else if (ch === "@" /* TokenChars.LinkedAlias */ ||
|
|
354
|
-
ch === "%" /* TokenChars.Modulo */ ||
|
|
355
336
|
ch === "|" /* TokenChars.Pipe */ ||
|
|
356
337
|
ch === ":" /* TokenChars.LinkedDelimiter */ ||
|
|
357
338
|
ch === "." /* TokenChars.LinkedDot */ ||
|
|
@@ -378,41 +359,25 @@ function createTokenizer(source, options = {}) {
|
|
|
378
359
|
scnr.resetPeek();
|
|
379
360
|
return ret;
|
|
380
361
|
}
|
|
381
|
-
function detectModuloStart(scnr) {
|
|
382
|
-
const spaces = peekSpaces(scnr);
|
|
383
|
-
const ret = scnr.currentPeek() === "%" /* TokenChars.Modulo */ &&
|
|
384
|
-
scnr.peek() === "{" /* TokenChars.BraceLeft */;
|
|
385
|
-
scnr.resetPeek();
|
|
386
|
-
return {
|
|
387
|
-
isModulo: ret,
|
|
388
|
-
hasSpace: spaces.length > 0
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
362
|
function isTextStart(scnr, reset = true) {
|
|
392
|
-
const fn = (hasSpace = false, prev = ''
|
|
363
|
+
const fn = (hasSpace = false, prev = '') => {
|
|
393
364
|
const ch = scnr.currentPeek();
|
|
394
365
|
if (ch === "{" /* TokenChars.BraceLeft */) {
|
|
395
|
-
return
|
|
366
|
+
return hasSpace;
|
|
396
367
|
}
|
|
397
368
|
else if (ch === "@" /* TokenChars.LinkedAlias */ || !ch) {
|
|
398
|
-
return
|
|
399
|
-
}
|
|
400
|
-
else if (ch === "%" /* TokenChars.Modulo */) {
|
|
401
|
-
scnr.peek();
|
|
402
|
-
return fn(hasSpace, "%" /* TokenChars.Modulo */, true);
|
|
369
|
+
return hasSpace;
|
|
403
370
|
}
|
|
404
371
|
else if (ch === "|" /* TokenChars.Pipe */) {
|
|
405
|
-
return prev ===
|
|
406
|
-
? true
|
|
407
|
-
: !(prev === CHAR_SP || prev === CHAR_LF);
|
|
372
|
+
return !(prev === CHAR_SP || prev === CHAR_LF);
|
|
408
373
|
}
|
|
409
374
|
else if (ch === CHAR_SP) {
|
|
410
375
|
scnr.peek();
|
|
411
|
-
return fn(true, CHAR_SP
|
|
376
|
+
return fn(true, CHAR_SP);
|
|
412
377
|
}
|
|
413
378
|
else if (ch === CHAR_LF) {
|
|
414
379
|
scnr.peek();
|
|
415
|
-
return fn(true, CHAR_LF
|
|
380
|
+
return fn(true, CHAR_LF);
|
|
416
381
|
}
|
|
417
382
|
else {
|
|
418
383
|
return true;
|
|
@@ -482,18 +447,8 @@ function createTokenizer(source, options = {}) {
|
|
|
482
447
|
}
|
|
483
448
|
return num;
|
|
484
449
|
}
|
|
485
|
-
function readModulo(scnr) {
|
|
486
|
-
skipSpaces(scnr);
|
|
487
|
-
const ch = scnr.currentChar();
|
|
488
|
-
if (ch !== "%" /* TokenChars.Modulo */) {
|
|
489
|
-
emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
|
|
490
|
-
}
|
|
491
|
-
scnr.next();
|
|
492
|
-
return "%" /* TokenChars.Modulo */;
|
|
493
|
-
}
|
|
494
450
|
function readText(scnr) {
|
|
495
451
|
let buf = '';
|
|
496
|
-
// eslint-disable-next-line no-constant-condition
|
|
497
452
|
while (true) {
|
|
498
453
|
const ch = scnr.currentChar();
|
|
499
454
|
if (ch === "{" /* TokenChars.BraceLeft */ ||
|
|
@@ -503,15 +458,6 @@ function createTokenizer(source, options = {}) {
|
|
|
503
458
|
!ch) {
|
|
504
459
|
break;
|
|
505
460
|
}
|
|
506
|
-
else if (ch === "%" /* TokenChars.Modulo */) {
|
|
507
|
-
if (isTextStart(scnr)) {
|
|
508
|
-
buf += ch;
|
|
509
|
-
scnr.next();
|
|
510
|
-
}
|
|
511
|
-
else {
|
|
512
|
-
break;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
461
|
else if (ch === CHAR_SP || ch === CHAR_LF) {
|
|
516
462
|
if (isTextStart(scnr)) {
|
|
517
463
|
buf += ch;
|
|
@@ -647,7 +593,6 @@ function createTokenizer(source, options = {}) {
|
|
|
647
593
|
const fn = (buf) => {
|
|
648
594
|
const ch = scnr.currentChar();
|
|
649
595
|
if (ch === "{" /* TokenChars.BraceLeft */ ||
|
|
650
|
-
ch === "%" /* TokenChars.Modulo */ ||
|
|
651
596
|
ch === "@" /* TokenChars.LinkedAlias */ ||
|
|
652
597
|
ch === "|" /* TokenChars.Pipe */ ||
|
|
653
598
|
ch === "(" /* TokenChars.ParenLeft */ ||
|
|
@@ -726,31 +671,31 @@ function createTokenizer(source, options = {}) {
|
|
|
726
671
|
return token;
|
|
727
672
|
}
|
|
728
673
|
if (context.braceNest > 0 &&
|
|
729
|
-
(context.currentType ===
|
|
730
|
-
context.currentType ===
|
|
731
|
-
context.currentType ===
|
|
674
|
+
(context.currentType === 4 /* TokenTypes.Named */ ||
|
|
675
|
+
context.currentType === 5 /* TokenTypes.List */ ||
|
|
676
|
+
context.currentType === 6 /* TokenTypes.Literal */)) {
|
|
732
677
|
emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
|
|
733
678
|
context.braceNest = 0;
|
|
734
679
|
return readToken(scnr, context);
|
|
735
680
|
}
|
|
736
681
|
if ((validNamedIdentifier = isNamedIdentifierStart(scnr, context))) {
|
|
737
|
-
token = getToken(context,
|
|
682
|
+
token = getToken(context, 4 /* TokenTypes.Named */, readNamedIdentifier(scnr));
|
|
738
683
|
skipSpaces(scnr);
|
|
739
684
|
return token;
|
|
740
685
|
}
|
|
741
686
|
if ((validListIdentifier = isListIdentifierStart(scnr, context))) {
|
|
742
|
-
token = getToken(context,
|
|
687
|
+
token = getToken(context, 5 /* TokenTypes.List */, readListIdentifier(scnr));
|
|
743
688
|
skipSpaces(scnr);
|
|
744
689
|
return token;
|
|
745
690
|
}
|
|
746
691
|
if ((validLiteral = isLiteralStart(scnr, context))) {
|
|
747
|
-
token = getToken(context,
|
|
692
|
+
token = getToken(context, 6 /* TokenTypes.Literal */, readLiteral(scnr));
|
|
748
693
|
skipSpaces(scnr);
|
|
749
694
|
return token;
|
|
750
695
|
}
|
|
751
696
|
if (!validNamedIdentifier && !validListIdentifier && !validLiteral) {
|
|
752
697
|
// TODO: we should be re-designed invalid cases, when we will extend message syntax near the future ...
|
|
753
|
-
token = getToken(context,
|
|
698
|
+
token = getToken(context, 12 /* TokenTypes.InvalidPlace */, readInvalidIdentifier(scnr));
|
|
754
699
|
emitError(CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER, currentPosition(), 0, token.value);
|
|
755
700
|
skipSpaces(scnr);
|
|
756
701
|
return token;
|
|
@@ -765,27 +710,27 @@ function createTokenizer(source, options = {}) {
|
|
|
765
710
|
const { currentType } = context;
|
|
766
711
|
let token = null;
|
|
767
712
|
const ch = scnr.currentChar();
|
|
768
|
-
if ((currentType ===
|
|
769
|
-
currentType ===
|
|
770
|
-
currentType ===
|
|
771
|
-
currentType ===
|
|
713
|
+
if ((currentType === 7 /* TokenTypes.LinkedAlias */ ||
|
|
714
|
+
currentType === 8 /* TokenTypes.LinkedDot */ ||
|
|
715
|
+
currentType === 11 /* TokenTypes.LinkedModifier */ ||
|
|
716
|
+
currentType === 9 /* TokenTypes.LinkedDelimiter */) &&
|
|
772
717
|
(ch === CHAR_LF || ch === CHAR_SP)) {
|
|
773
718
|
emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);
|
|
774
719
|
}
|
|
775
720
|
switch (ch) {
|
|
776
721
|
case "@" /* TokenChars.LinkedAlias */:
|
|
777
722
|
scnr.next();
|
|
778
|
-
token = getToken(context,
|
|
723
|
+
token = getToken(context, 7 /* TokenTypes.LinkedAlias */, "@" /* TokenChars.LinkedAlias */);
|
|
779
724
|
context.inLinked = true;
|
|
780
725
|
return token;
|
|
781
726
|
case "." /* TokenChars.LinkedDot */:
|
|
782
727
|
skipSpaces(scnr);
|
|
783
728
|
scnr.next();
|
|
784
|
-
return getToken(context,
|
|
729
|
+
return getToken(context, 8 /* TokenTypes.LinkedDot */, "." /* TokenChars.LinkedDot */);
|
|
785
730
|
case ":" /* TokenChars.LinkedDelimiter */:
|
|
786
731
|
skipSpaces(scnr);
|
|
787
732
|
scnr.next();
|
|
788
|
-
return getToken(context,
|
|
733
|
+
return getToken(context, 9 /* TokenTypes.LinkedDelimiter */, ":" /* TokenChars.LinkedDelimiter */);
|
|
789
734
|
default:
|
|
790
735
|
if (isPluralStart(scnr)) {
|
|
791
736
|
token = getToken(context, 1 /* TokenTypes.Pipe */, readPlural(scnr));
|
|
@@ -801,7 +746,7 @@ function createTokenizer(source, options = {}) {
|
|
|
801
746
|
}
|
|
802
747
|
if (isLinkedModifierStart(scnr, context)) {
|
|
803
748
|
skipSpaces(scnr);
|
|
804
|
-
return getToken(context,
|
|
749
|
+
return getToken(context, 11 /* TokenTypes.LinkedModifier */, readLinkedModifier(scnr));
|
|
805
750
|
}
|
|
806
751
|
if (isLinkedReferStart(scnr, context)) {
|
|
807
752
|
skipSpaces(scnr);
|
|
@@ -810,10 +755,10 @@ function createTokenizer(source, options = {}) {
|
|
|
810
755
|
return readTokenInPlaceholder(scnr, context) || token;
|
|
811
756
|
}
|
|
812
757
|
else {
|
|
813
|
-
return getToken(context,
|
|
758
|
+
return getToken(context, 10 /* TokenTypes.LinkedKey */, readLinkedRefer(scnr));
|
|
814
759
|
}
|
|
815
760
|
}
|
|
816
|
-
if (currentType ===
|
|
761
|
+
if (currentType === 7 /* TokenTypes.LinkedAlias */) {
|
|
817
762
|
emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);
|
|
818
763
|
}
|
|
819
764
|
context.braceNest = 0;
|
|
@@ -823,7 +768,7 @@ function createTokenizer(source, options = {}) {
|
|
|
823
768
|
}
|
|
824
769
|
// TODO: We need refactoring of token parsing ...
|
|
825
770
|
function readToken(scnr, context) {
|
|
826
|
-
let token = { type:
|
|
771
|
+
let token = { type: 13 /* TokenTypes.EOF */ };
|
|
827
772
|
if (context.braceNest > 0) {
|
|
828
773
|
return readTokenInPlaceholder(scnr, context) || getEndToken(context);
|
|
829
774
|
}
|
|
@@ -848,12 +793,6 @@ function createTokenizer(source, options = {}) {
|
|
|
848
793
|
context.inLinked = false;
|
|
849
794
|
return token;
|
|
850
795
|
}
|
|
851
|
-
const { isModulo, hasSpace } = detectModuloStart(scnr);
|
|
852
|
-
if (isModulo) {
|
|
853
|
-
return hasSpace
|
|
854
|
-
? getToken(context, 0 /* TokenTypes.Text */, readText(scnr))
|
|
855
|
-
: getToken(context, 4 /* TokenTypes.Modulo */, readModulo(scnr));
|
|
856
|
-
}
|
|
857
796
|
if (isTextStart(scnr)) {
|
|
858
797
|
return getToken(context, 0 /* TokenTypes.Text */, readText(scnr));
|
|
859
798
|
}
|
|
@@ -871,7 +810,7 @@ function createTokenizer(source, options = {}) {
|
|
|
871
810
|
_context.offset = currentOffset();
|
|
872
811
|
_context.startLoc = currentPosition();
|
|
873
812
|
if (_scnr.currentChar() === EOF) {
|
|
874
|
-
return getToken(_context,
|
|
813
|
+
return getToken(_context, 13 /* TokenTypes.EOF */);
|
|
875
814
|
}
|
|
876
815
|
return readToken(_scnr, _context);
|
|
877
816
|
}
|
|
@@ -907,7 +846,7 @@ function fromEscapeSequence(match, codePoint4, codePoint6) {
|
|
|
907
846
|
}
|
|
908
847
|
function createParser(options = {}) {
|
|
909
848
|
const location = options.location !== false;
|
|
910
|
-
const { onError
|
|
849
|
+
const { onError } = options;
|
|
911
850
|
function emitError(tokenzer, code, start, offset, ...args) {
|
|
912
851
|
const end = tokenzer.currentPosition();
|
|
913
852
|
end.offset += offset;
|
|
@@ -921,15 +860,6 @@ function createParser(options = {}) {
|
|
|
921
860
|
onError(err);
|
|
922
861
|
}
|
|
923
862
|
}
|
|
924
|
-
function emitWarn(tokenzer, code, start, offset, ...args) {
|
|
925
|
-
const end = tokenzer.currentPosition();
|
|
926
|
-
end.offset += offset;
|
|
927
|
-
end.column += offset;
|
|
928
|
-
if (onWarn) {
|
|
929
|
-
const loc = location ? createLocation(start, end) : null;
|
|
930
|
-
onWarn(createCompileWarn(code, loc, args));
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
863
|
function startNode(type, offset, loc) {
|
|
934
864
|
const node = { type };
|
|
935
865
|
if (location) {
|
|
@@ -966,14 +896,11 @@ function createParser(options = {}) {
|
|
|
966
896
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
967
897
|
return node;
|
|
968
898
|
}
|
|
969
|
-
function parseNamed(tokenizer, key
|
|
899
|
+
function parseNamed(tokenizer, key) {
|
|
970
900
|
const context = tokenizer.context();
|
|
971
901
|
const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
|
|
972
902
|
const node = startNode(4 /* NodeTypes.Named */, offset, loc);
|
|
973
903
|
node.key = key;
|
|
974
|
-
if (modulo === true) {
|
|
975
|
-
node.modulo = true;
|
|
976
|
-
}
|
|
977
904
|
tokenizer.nextToken(); // skip brach right
|
|
978
905
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
979
906
|
return node;
|
|
@@ -992,7 +919,7 @@ function createParser(options = {}) {
|
|
|
992
919
|
const context = tokenizer.context();
|
|
993
920
|
const { lastOffset: offset, lastStartLoc: loc } = context; // get linked dot loc
|
|
994
921
|
const node = startNode(8 /* NodeTypes.LinkedModifier */, offset, loc);
|
|
995
|
-
if (token.type !==
|
|
922
|
+
if (token.type !== 11 /* TokenTypes.LinkedModifier */) {
|
|
996
923
|
// empty modifier
|
|
997
924
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER, context.lastStartLoc, 0);
|
|
998
925
|
node.value = '';
|
|
@@ -1023,13 +950,13 @@ function createParser(options = {}) {
|
|
|
1023
950
|
const context = tokenizer.context();
|
|
1024
951
|
const linkedNode = startNode(6 /* NodeTypes.Linked */, context.offset, context.startLoc);
|
|
1025
952
|
let token = tokenizer.nextToken();
|
|
1026
|
-
if (token.type ===
|
|
953
|
+
if (token.type === 8 /* TokenTypes.LinkedDot */) {
|
|
1027
954
|
const parsed = parseLinkedModifier(tokenizer);
|
|
1028
955
|
linkedNode.modifier = parsed.node;
|
|
1029
956
|
token = parsed.nextConsumeToken || tokenizer.nextToken();
|
|
1030
957
|
}
|
|
1031
958
|
// asset check token
|
|
1032
|
-
if (token.type !==
|
|
959
|
+
if (token.type !== 9 /* TokenTypes.LinkedDelimiter */) {
|
|
1033
960
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1034
961
|
}
|
|
1035
962
|
token = tokenizer.nextToken();
|
|
@@ -1038,25 +965,25 @@ function createParser(options = {}) {
|
|
|
1038
965
|
token = tokenizer.nextToken();
|
|
1039
966
|
}
|
|
1040
967
|
switch (token.type) {
|
|
1041
|
-
case
|
|
968
|
+
case 10 /* TokenTypes.LinkedKey */:
|
|
1042
969
|
if (token.value == null) {
|
|
1043
970
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1044
971
|
}
|
|
1045
972
|
linkedNode.key = parseLinkedKey(tokenizer, token.value || '');
|
|
1046
973
|
break;
|
|
1047
|
-
case
|
|
974
|
+
case 4 /* TokenTypes.Named */:
|
|
1048
975
|
if (token.value == null) {
|
|
1049
976
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1050
977
|
}
|
|
1051
978
|
linkedNode.key = parseNamed(tokenizer, token.value || '');
|
|
1052
979
|
break;
|
|
1053
|
-
case
|
|
980
|
+
case 5 /* TokenTypes.List */:
|
|
1054
981
|
if (token.value == null) {
|
|
1055
982
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1056
983
|
}
|
|
1057
984
|
linkedNode.key = parseList(tokenizer, token.value || '');
|
|
1058
985
|
break;
|
|
1059
|
-
case
|
|
986
|
+
case 6 /* TokenTypes.Literal */:
|
|
1060
987
|
if (token.value == null) {
|
|
1061
988
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1062
989
|
}
|
|
@@ -1093,7 +1020,6 @@ function createParser(options = {}) {
|
|
|
1093
1020
|
const node = startNode(2 /* NodeTypes.Message */, startOffset, startLoc);
|
|
1094
1021
|
node.items = [];
|
|
1095
1022
|
let nextToken = null;
|
|
1096
|
-
let modulo = null;
|
|
1097
1023
|
do {
|
|
1098
1024
|
const token = nextToken || tokenizer.nextToken();
|
|
1099
1025
|
nextToken = null;
|
|
@@ -1104,39 +1030,32 @@ function createParser(options = {}) {
|
|
|
1104
1030
|
}
|
|
1105
1031
|
node.items.push(parseText(tokenizer, token.value || ''));
|
|
1106
1032
|
break;
|
|
1107
|
-
case
|
|
1033
|
+
case 5 /* TokenTypes.List */:
|
|
1108
1034
|
if (token.value == null) {
|
|
1109
1035
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1110
1036
|
}
|
|
1111
1037
|
node.items.push(parseList(tokenizer, token.value || ''));
|
|
1112
1038
|
break;
|
|
1113
|
-
case 4 /* TokenTypes.
|
|
1114
|
-
modulo = true;
|
|
1115
|
-
break;
|
|
1116
|
-
case 5 /* TokenTypes.Named */:
|
|
1039
|
+
case 4 /* TokenTypes.Named */:
|
|
1117
1040
|
if (token.value == null) {
|
|
1118
1041
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1119
1042
|
}
|
|
1120
|
-
node.items.push(parseNamed(tokenizer, token.value || ''
|
|
1121
|
-
if (modulo) {
|
|
1122
|
-
emitWarn(tokenizer, CompileWarnCodes.USE_MODULO_SYNTAX, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1123
|
-
modulo = null;
|
|
1124
|
-
}
|
|
1043
|
+
node.items.push(parseNamed(tokenizer, token.value || ''));
|
|
1125
1044
|
break;
|
|
1126
|
-
case
|
|
1045
|
+
case 6 /* TokenTypes.Literal */:
|
|
1127
1046
|
if (token.value == null) {
|
|
1128
1047
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1129
1048
|
}
|
|
1130
1049
|
node.items.push(parseLiteral(tokenizer, token.value || ''));
|
|
1131
1050
|
break;
|
|
1132
|
-
case
|
|
1051
|
+
case 7 /* TokenTypes.LinkedAlias */: {
|
|
1133
1052
|
const parsed = parseLinked(tokenizer);
|
|
1134
1053
|
node.items.push(parsed.node);
|
|
1135
1054
|
nextToken = parsed.nextConsumeToken || null;
|
|
1136
1055
|
break;
|
|
1137
1056
|
}
|
|
1138
1057
|
}
|
|
1139
|
-
} while (context.currentType !==
|
|
1058
|
+
} while (context.currentType !== 13 /* TokenTypes.EOF */ &&
|
|
1140
1059
|
context.currentType !== 1 /* TokenTypes.Pipe */);
|
|
1141
1060
|
// adjust message node loc
|
|
1142
1061
|
const endOffset = context.currentType === 1 /* TokenTypes.Pipe */
|
|
@@ -1160,7 +1079,7 @@ function createParser(options = {}) {
|
|
|
1160
1079
|
hasEmptyMessage = msg.items.length === 0;
|
|
1161
1080
|
}
|
|
1162
1081
|
node.cases.push(msg);
|
|
1163
|
-
} while (context.currentType !==
|
|
1082
|
+
} while (context.currentType !== 13 /* TokenTypes.EOF */);
|
|
1164
1083
|
if (hasEmptyMessage) {
|
|
1165
1084
|
emitError(tokenizer, CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL, loc, 0);
|
|
1166
1085
|
}
|
|
@@ -1171,7 +1090,7 @@ function createParser(options = {}) {
|
|
|
1171
1090
|
const context = tokenizer.context();
|
|
1172
1091
|
const { offset, startLoc } = context;
|
|
1173
1092
|
const msgNode = parseMessage(tokenizer);
|
|
1174
|
-
if (context.currentType ===
|
|
1093
|
+
if (context.currentType === 13 /* TokenTypes.EOF */) {
|
|
1175
1094
|
return msgNode;
|
|
1176
1095
|
}
|
|
1177
1096
|
else {
|
|
@@ -1190,7 +1109,7 @@ function createParser(options = {}) {
|
|
|
1190
1109
|
node.cacheKey = options.onCacheKey(source);
|
|
1191
1110
|
}
|
|
1192
1111
|
// assert whether achieved to EOF
|
|
1193
|
-
if (context.currentType !==
|
|
1112
|
+
if (context.currentType !== 13 /* TokenTypes.EOF */) {
|
|
1194
1113
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, source[context.offset] || '');
|
|
1195
1114
|
}
|
|
1196
1115
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
@@ -1199,7 +1118,7 @@ function createParser(options = {}) {
|
|
|
1199
1118
|
return { parse };
|
|
1200
1119
|
}
|
|
1201
1120
|
function getTokenCaption(token) {
|
|
1202
|
-
if (token.type ===
|
|
1121
|
+
if (token.type === 13 /* TokenTypes.EOF */) {
|
|
1203
1122
|
return 'EOF';
|
|
1204
1123
|
}
|
|
1205
1124
|
const name = (token.value || '').replace(/\r?\n/gu, '\\n');
|
|
@@ -1561,8 +1480,7 @@ function generateNode(generator, node) {
|
|
|
1561
1480
|
}
|
|
1562
1481
|
}
|
|
1563
1482
|
// generate code from AST
|
|
1564
|
-
const generate = (ast, options = {}
|
|
1565
|
-
) => {
|
|
1483
|
+
const generate = (ast, options = {}) => {
|
|
1566
1484
|
const mode = shared.isString(options.mode) ? options.mode : 'normal';
|
|
1567
1485
|
const filename = shared.isString(options.filename)
|
|
1568
1486
|
? options.filename
|
|
@@ -1659,16 +1577,13 @@ function baseCompile(source, options = {}) {
|
|
|
1659
1577
|
}
|
|
1660
1578
|
|
|
1661
1579
|
exports.CompileErrorCodes = CompileErrorCodes;
|
|
1662
|
-
exports.CompileWarnCodes = CompileWarnCodes;
|
|
1663
1580
|
exports.ERROR_DOMAIN = ERROR_DOMAIN$2;
|
|
1664
1581
|
exports.LOCATION_STUB = LOCATION_STUB;
|
|
1665
1582
|
exports.baseCompile = baseCompile;
|
|
1666
1583
|
exports.createCompileError = createCompileError;
|
|
1667
|
-
exports.createCompileWarn = createCompileWarn;
|
|
1668
1584
|
exports.createLocation = createLocation;
|
|
1669
1585
|
exports.createParser = createParser;
|
|
1670
1586
|
exports.createPosition = createPosition;
|
|
1671
1587
|
exports.defaultOnError = defaultOnError;
|
|
1672
1588
|
exports.detectHtmlTag = detectHtmlTag;
|
|
1673
1589
|
exports.errorMessages = errorMessages;
|
|
1674
|
-
exports.warnMessages = warnMessages;
|
|
@@ -12,7 +12,6 @@ export declare interface CodeGenOptions {
|
|
|
12
12
|
mode?: 'normal' | 'arrow';
|
|
13
13
|
breakLineCode?: '\n' | ';';
|
|
14
14
|
needIndent?: boolean;
|
|
15
|
-
onWarn?: CompileWarnHandler;
|
|
16
15
|
onError?: CompileErrorHandler;
|
|
17
16
|
sourceMap?: boolean;
|
|
18
17
|
filename?: string;
|
|
@@ -71,25 +70,8 @@ export declare type CompileOptions = {
|
|
|
71
70
|
|
|
72
71
|
export declare type CompilerResult = CodeGenResult;
|
|
73
72
|
|
|
74
|
-
export declare interface CompileWarn {
|
|
75
|
-
message: string;
|
|
76
|
-
code: number;
|
|
77
|
-
location?: SourceLocation;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export declare const CompileWarnCodes: {
|
|
81
|
-
readonly USE_MODULO_SYNTAX: 1;
|
|
82
|
-
readonly __EXTEND_POINT__: 2;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export declare type CompileWarnCodes = (typeof CompileWarnCodes)[keyof typeof CompileWarnCodes];
|
|
86
|
-
|
|
87
|
-
export declare type CompileWarnHandler = (warn: CompileWarn) => void;
|
|
88
|
-
|
|
89
73
|
export declare function createCompileError<T extends number>(code: T, loc: SourceLocation | null, options?: CompileErrorOptions): CompileError;
|
|
90
74
|
|
|
91
|
-
export declare function createCompileWarn<T extends number>(code: T, loc: SourceLocation | null, ...args: unknown[]): CompileWarn;
|
|
92
|
-
|
|
93
75
|
export declare function createLocation(start: Position, end: Position, source?: string): SourceLocation;
|
|
94
76
|
|
|
95
77
|
export declare function createParser(options?: ParserOptions): Parser;
|
|
@@ -198,7 +180,6 @@ export declare interface Parser {
|
|
|
198
180
|
export declare interface ParserOptions {
|
|
199
181
|
location?: boolean;
|
|
200
182
|
onCacheKey?: (source: string) => string;
|
|
201
|
-
onWarn?: CompileWarnHandler;
|
|
202
183
|
onError?: CompileErrorHandler;
|
|
203
184
|
}
|
|
204
185
|
|
|
@@ -240,10 +221,7 @@ export declare interface TokenizeOptions {
|
|
|
240
221
|
}
|
|
241
222
|
|
|
242
223
|
export declare interface TransformOptions {
|
|
243
|
-
onWarn?: CompileWarnHandler;
|
|
244
224
|
onError?: CompileErrorHandler;
|
|
245
225
|
}
|
|
246
226
|
|
|
247
|
-
/* Excluded from this release type: warnMessages */
|
|
248
|
-
|
|
249
227
|
export { }
|