@intlify/message-compiler 9.11.1 → 9.12.0
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 +44 -4
- package/dist/message-compiler.d.ts +23 -0
- package/dist/message-compiler.esm-browser.js +42 -5
- package/dist/message-compiler.esm-browser.prod.js +2 -2
- package/dist/message-compiler.global.js +44 -4
- package/dist/message-compiler.global.prod.js +2 -2
- package/dist/message-compiler.mjs +42 -5
- package/dist/message-compiler.node.mjs +42 -5
- package/dist/message-compiler.prod.cjs +44 -4
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* message-compiler v9.
|
|
2
|
+
* message-compiler v9.12.0
|
|
3
3
|
* (c) 2024 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -23,6 +23,23 @@ 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
|
+
|
|
26
43
|
const CompileErrorCodes = {
|
|
27
44
|
// tokenizer error codes
|
|
28
45
|
EXPECTED_TOKEN: 1,
|
|
@@ -873,7 +890,7 @@ function fromEscapeSequence(match, codePoint4, codePoint6) {
|
|
|
873
890
|
}
|
|
874
891
|
function createParser(options = {}) {
|
|
875
892
|
const location = options.location !== false;
|
|
876
|
-
const { onError } = options;
|
|
893
|
+
const { onError, onWarn } = options;
|
|
877
894
|
function emitError(tokenzer, code, start, offset, ...args) {
|
|
878
895
|
const end = tokenzer.currentPosition();
|
|
879
896
|
end.offset += offset;
|
|
@@ -887,6 +904,15 @@ function createParser(options = {}) {
|
|
|
887
904
|
onError(err);
|
|
888
905
|
}
|
|
889
906
|
}
|
|
907
|
+
function emitWarn(tokenzer, code, start, offset, ...args) {
|
|
908
|
+
const end = tokenzer.currentPosition();
|
|
909
|
+
end.offset += offset;
|
|
910
|
+
end.column += offset;
|
|
911
|
+
if (onWarn) {
|
|
912
|
+
const loc = location ? createLocation(start, end) : null;
|
|
913
|
+
onWarn(createCompileWarn(code, loc, args));
|
|
914
|
+
}
|
|
915
|
+
}
|
|
890
916
|
function startNode(type, offset, loc) {
|
|
891
917
|
const node = { type };
|
|
892
918
|
if (location) {
|
|
@@ -923,11 +949,14 @@ function createParser(options = {}) {
|
|
|
923
949
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
924
950
|
return node;
|
|
925
951
|
}
|
|
926
|
-
function parseNamed(tokenizer, key) {
|
|
952
|
+
function parseNamed(tokenizer, key, modulo) {
|
|
927
953
|
const context = tokenizer.context();
|
|
928
954
|
const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
|
|
929
955
|
const node = startNode(4 /* NodeTypes.Named */, offset, loc);
|
|
930
956
|
node.key = key;
|
|
957
|
+
if (modulo === true) {
|
|
958
|
+
node.modulo = true;
|
|
959
|
+
}
|
|
931
960
|
tokenizer.nextToken(); // skip brach right
|
|
932
961
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
933
962
|
return node;
|
|
@@ -1047,6 +1076,7 @@ function createParser(options = {}) {
|
|
|
1047
1076
|
const node = startNode(2 /* NodeTypes.Message */, startOffset, startLoc);
|
|
1048
1077
|
node.items = [];
|
|
1049
1078
|
let nextToken = null;
|
|
1079
|
+
let modulo = null;
|
|
1050
1080
|
do {
|
|
1051
1081
|
const token = nextToken || tokenizer.nextToken();
|
|
1052
1082
|
nextToken = null;
|
|
@@ -1063,11 +1093,18 @@ function createParser(options = {}) {
|
|
|
1063
1093
|
}
|
|
1064
1094
|
node.items.push(parseList(tokenizer, token.value || ''));
|
|
1065
1095
|
break;
|
|
1096
|
+
case 4 /* TokenTypes.Modulo */:
|
|
1097
|
+
modulo = true;
|
|
1098
|
+
break;
|
|
1066
1099
|
case 5 /* TokenTypes.Named */:
|
|
1067
1100
|
if (token.value == null) {
|
|
1068
1101
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1069
1102
|
}
|
|
1070
|
-
node.items.push(parseNamed(tokenizer, token.value || ''));
|
|
1103
|
+
node.items.push(parseNamed(tokenizer, token.value || '', !!modulo));
|
|
1104
|
+
if (modulo) {
|
|
1105
|
+
emitWarn(tokenizer, CompileWarnCodes.USE_MODULO_SYNTAX, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1106
|
+
modulo = null;
|
|
1107
|
+
}
|
|
1071
1108
|
break;
|
|
1072
1109
|
case 7 /* TokenTypes.Literal */:
|
|
1073
1110
|
if (token.value == null) {
|
|
@@ -1605,13 +1642,16 @@ function baseCompile(source, options = {}) {
|
|
|
1605
1642
|
}
|
|
1606
1643
|
|
|
1607
1644
|
exports.CompileErrorCodes = CompileErrorCodes;
|
|
1645
|
+
exports.CompileWarnCodes = CompileWarnCodes;
|
|
1608
1646
|
exports.ERROR_DOMAIN = ERROR_DOMAIN$2;
|
|
1609
1647
|
exports.LOCATION_STUB = LOCATION_STUB;
|
|
1610
1648
|
exports.baseCompile = baseCompile;
|
|
1611
1649
|
exports.createCompileError = createCompileError;
|
|
1650
|
+
exports.createCompileWarn = createCompileWarn;
|
|
1612
1651
|
exports.createLocation = createLocation;
|
|
1613
1652
|
exports.createParser = createParser;
|
|
1614
1653
|
exports.createPosition = createPosition;
|
|
1615
1654
|
exports.defaultOnError = defaultOnError;
|
|
1616
1655
|
exports.detectHtmlTag = detectHtmlTag;
|
|
1617
1656
|
exports.errorMessages = errorMessages;
|
|
1657
|
+
exports.warnMessages = warnMessages;
|
|
@@ -12,6 +12,7 @@ export declare interface CodeGenOptions {
|
|
|
12
12
|
mode?: 'normal' | 'arrow';
|
|
13
13
|
breakLineCode?: '\n' | ';';
|
|
14
14
|
needIndent?: boolean;
|
|
15
|
+
onWarn?: CompileWarnHandler;
|
|
15
16
|
onError?: CompileErrorHandler;
|
|
16
17
|
sourceMap?: boolean;
|
|
17
18
|
filename?: string;
|
|
@@ -70,8 +71,25 @@ export declare type CompileOptions = {
|
|
|
70
71
|
|
|
71
72
|
export declare type CompilerResult = CodeGenResult;
|
|
72
73
|
|
|
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
|
+
|
|
73
89
|
export declare function createCompileError<T extends number>(code: T, loc: SourceLocation | null, options?: CompileErrorOptions): CompileError;
|
|
74
90
|
|
|
91
|
+
export declare function createCompileWarn<T extends number>(code: T, loc: SourceLocation | null, ...args: unknown[]): CompileWarn;
|
|
92
|
+
|
|
75
93
|
export declare function createLocation(start: Position, end: Position, source?: string): SourceLocation;
|
|
76
94
|
|
|
77
95
|
export declare function createParser(options?: ParserOptions): Parser;
|
|
@@ -147,6 +165,7 @@ export declare interface MessageNode extends Node_2 {
|
|
|
147
165
|
export declare interface NamedNode extends Node_2 {
|
|
148
166
|
type: NodeTypes.Named;
|
|
149
167
|
key: Identifier;
|
|
168
|
+
modulo?: boolean;
|
|
150
169
|
/* Excluded from this release type: k */
|
|
151
170
|
}
|
|
152
171
|
|
|
@@ -179,6 +198,7 @@ export declare interface Parser {
|
|
|
179
198
|
export declare interface ParserOptions {
|
|
180
199
|
location?: boolean;
|
|
181
200
|
onCacheKey?: (source: string) => string;
|
|
201
|
+
onWarn?: CompileWarnHandler;
|
|
182
202
|
onError?: CompileErrorHandler;
|
|
183
203
|
}
|
|
184
204
|
|
|
@@ -220,7 +240,10 @@ export declare interface TokenizeOptions {
|
|
|
220
240
|
}
|
|
221
241
|
|
|
222
242
|
export declare interface TransformOptions {
|
|
243
|
+
onWarn?: CompileWarnHandler;
|
|
223
244
|
onError?: CompileErrorHandler;
|
|
224
245
|
}
|
|
225
246
|
|
|
247
|
+
/* Excluded from this release type: warnMessages */
|
|
248
|
+
|
|
226
249
|
export { }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* message-compiler v9.
|
|
2
|
+
* message-compiler v9.12.0
|
|
3
3
|
* (c) 2024 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -43,6 +43,23 @@ function join(items, separator = '') {
|
|
|
43
43
|
return items.reduce((str, item, index) => (index === 0 ? str + item : str + separator + item), '');
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
const CompileWarnCodes = {
|
|
47
|
+
USE_MODULO_SYNTAX: 1,
|
|
48
|
+
__EXTEND_POINT__: 2
|
|
49
|
+
};
|
|
50
|
+
/** @internal */
|
|
51
|
+
const warnMessages = {
|
|
52
|
+
[CompileWarnCodes.USE_MODULO_SYNTAX]: `Use modulo before '{{0}}'.`
|
|
53
|
+
};
|
|
54
|
+
function createCompileWarn(code, loc, ...args) {
|
|
55
|
+
const msg = format(warnMessages[code] || '', ...(args || [])) ;
|
|
56
|
+
const message = { message: String(msg), code };
|
|
57
|
+
if (loc) {
|
|
58
|
+
message.location = loc;
|
|
59
|
+
}
|
|
60
|
+
return message;
|
|
61
|
+
}
|
|
62
|
+
|
|
46
63
|
const CompileErrorCodes = {
|
|
47
64
|
// tokenizer error codes
|
|
48
65
|
EXPECTED_TOKEN: 1,
|
|
@@ -893,7 +910,7 @@ function fromEscapeSequence(match, codePoint4, codePoint6) {
|
|
|
893
910
|
}
|
|
894
911
|
function createParser(options = {}) {
|
|
895
912
|
const location = options.location !== false;
|
|
896
|
-
const { onError } = options;
|
|
913
|
+
const { onError, onWarn } = options;
|
|
897
914
|
function emitError(tokenzer, code, start, offset, ...args) {
|
|
898
915
|
const end = tokenzer.currentPosition();
|
|
899
916
|
end.offset += offset;
|
|
@@ -907,6 +924,15 @@ function createParser(options = {}) {
|
|
|
907
924
|
onError(err);
|
|
908
925
|
}
|
|
909
926
|
}
|
|
927
|
+
function emitWarn(tokenzer, code, start, offset, ...args) {
|
|
928
|
+
const end = tokenzer.currentPosition();
|
|
929
|
+
end.offset += offset;
|
|
930
|
+
end.column += offset;
|
|
931
|
+
if (onWarn) {
|
|
932
|
+
const loc = location ? createLocation(start, end) : null;
|
|
933
|
+
onWarn(createCompileWarn(code, loc, args));
|
|
934
|
+
}
|
|
935
|
+
}
|
|
910
936
|
function startNode(type, offset, loc) {
|
|
911
937
|
const node = { type };
|
|
912
938
|
if (location) {
|
|
@@ -943,11 +969,14 @@ function createParser(options = {}) {
|
|
|
943
969
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
944
970
|
return node;
|
|
945
971
|
}
|
|
946
|
-
function parseNamed(tokenizer, key) {
|
|
972
|
+
function parseNamed(tokenizer, key, modulo) {
|
|
947
973
|
const context = tokenizer.context();
|
|
948
974
|
const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
|
|
949
975
|
const node = startNode(4 /* NodeTypes.Named */, offset, loc);
|
|
950
976
|
node.key = key;
|
|
977
|
+
if (modulo === true) {
|
|
978
|
+
node.modulo = true;
|
|
979
|
+
}
|
|
951
980
|
tokenizer.nextToken(); // skip brach right
|
|
952
981
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
953
982
|
return node;
|
|
@@ -1067,6 +1096,7 @@ function createParser(options = {}) {
|
|
|
1067
1096
|
const node = startNode(2 /* NodeTypes.Message */, startOffset, startLoc);
|
|
1068
1097
|
node.items = [];
|
|
1069
1098
|
let nextToken = null;
|
|
1099
|
+
let modulo = null;
|
|
1070
1100
|
do {
|
|
1071
1101
|
const token = nextToken || tokenizer.nextToken();
|
|
1072
1102
|
nextToken = null;
|
|
@@ -1083,11 +1113,18 @@ function createParser(options = {}) {
|
|
|
1083
1113
|
}
|
|
1084
1114
|
node.items.push(parseList(tokenizer, token.value || ''));
|
|
1085
1115
|
break;
|
|
1116
|
+
case 4 /* TokenTypes.Modulo */:
|
|
1117
|
+
modulo = true;
|
|
1118
|
+
break;
|
|
1086
1119
|
case 5 /* TokenTypes.Named */:
|
|
1087
1120
|
if (token.value == null) {
|
|
1088
1121
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1089
1122
|
}
|
|
1090
|
-
node.items.push(parseNamed(tokenizer, token.value || ''));
|
|
1123
|
+
node.items.push(parseNamed(tokenizer, token.value || '', !!modulo));
|
|
1124
|
+
if (modulo) {
|
|
1125
|
+
emitWarn(tokenizer, CompileWarnCodes.USE_MODULO_SYNTAX, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1126
|
+
modulo = null;
|
|
1127
|
+
}
|
|
1091
1128
|
break;
|
|
1092
1129
|
case 7 /* TokenTypes.Literal */:
|
|
1093
1130
|
if (token.value == null) {
|
|
@@ -1568,4 +1605,4 @@ function baseCompile(source, options = {}) {
|
|
|
1568
1605
|
}
|
|
1569
1606
|
}
|
|
1570
1607
|
|
|
1571
|
-
export { CompileErrorCodes, ERROR_DOMAIN$2 as ERROR_DOMAIN, LOCATION_STUB, baseCompile, createCompileError, createLocation, createParser, createPosition, defaultOnError, detectHtmlTag, errorMessages };
|
|
1608
|
+
export { CompileErrorCodes, CompileWarnCodes, ERROR_DOMAIN$2 as ERROR_DOMAIN, LOCATION_STUB, baseCompile, createCompileError, createCompileWarn, createLocation, createParser, createPosition, defaultOnError, detectHtmlTag, errorMessages, warnMessages };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* message-compiler v9.
|
|
2
|
+
* message-compiler v9.12.0
|
|
3
3
|
* (c) 2024 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
const LOCATION_STUB={start:{line:1,column:1,offset:0},end:{line:1,column:1,offset:0}};function createPosition(e,t,n){return{line:e,column:t,offset:n}}function createLocation(e,t,n){const r={start:e,end:t};return null!=n&&(r.source=n),r}const assign=Object.assign,isString=e=>"string"==typeof e;function join(e,t=""){return e.reduce(((e,n,r)=>0===r?e+n:e+t+n),"")}const CompileErrorCodes={EXPECTED_TOKEN:1,INVALID_TOKEN_IN_PLACEHOLDER:2,UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER:3,UNKNOWN_ESCAPE_SEQUENCE:4,INVALID_UNICODE_ESCAPE_SEQUENCE:5,UNBALANCED_CLOSING_BRACE:6,UNTERMINATED_CLOSING_BRACE:7,EMPTY_PLACEHOLDER:8,NOT_ALLOW_NEST_PLACEHOLDER:9,INVALID_LINKED_FORMAT:10,MUST_HAVE_MESSAGES_IN_PLURAL:11,UNEXPECTED_EMPTY_LINKED_MODIFIER:12,UNEXPECTED_EMPTY_LINKED_KEY:13,UNEXPECTED_LEXICAL_ANALYSIS:14,UNHANDLED_CODEGEN_NODE_TYPE:15,UNHANDLED_MINIFIER_NODE_TYPE:16,__EXTEND_POINT__:17},errorMessages={[CompileErrorCodes.EXPECTED_TOKEN]:"Expected token: '{0}'",[CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER]:"Invalid token in placeholder: '{0}'",[CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]:"Unterminated single quote in placeholder",[CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE]:"Unknown escape sequence: \\{0}",[CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE]:"Invalid unicode escape sequence: {0}",[CompileErrorCodes.UNBALANCED_CLOSING_BRACE]:"Unbalanced closing brace",[CompileErrorCodes.UNTERMINATED_CLOSING_BRACE]:"Unterminated closing brace",[CompileErrorCodes.EMPTY_PLACEHOLDER]:"Empty placeholder",[CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER]:"Not allowed nest placeholder",[CompileErrorCodes.INVALID_LINKED_FORMAT]:"Invalid linked format",[CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL]:"Plural must have messages",[CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER]:"Unexpected empty linked modifier",[CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY]:"Unexpected empty linked key",[CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS]:"Unexpected lexical analysis in token: '{0}'",[CompileErrorCodes.UNHANDLED_CODEGEN_NODE_TYPE]:"unhandled codegen node type: '{0}'",[CompileErrorCodes.UNHANDLED_MINIFIER_NODE_TYPE]:"unhandled mimifier node type: '{0}'"};function createCompileError(e,t,n={}){const{domain:r,messages:o,args:s}=n,c=new SyntaxError(String(e));return c.code=e,t&&(c.location=t),c.domain=r,c}function defaultOnError(e){throw e}const RE_HTML_TAG=/<\/?[\w\s="/.':;#-\/]+>/,detectHtmlTag=e=>RE_HTML_TAG.test(e),CHAR_SP=" ",CHAR_CR="\r",CHAR_LF="\n",CHAR_LS=String.fromCharCode(8232),CHAR_PS=String.fromCharCode(8233);function createScanner(e){const t=e;let n=0,r=1,o=1,s=0;const c=e=>t[e]===CHAR_CR&&t[e+1]===CHAR_LF,i=e=>t[e]===CHAR_PS,a=e=>t[e]===CHAR_LS,u=e=>c(e)||(e=>t[e]===CHAR_LF)(e)||i(e)||a(e),l=e=>c(e)||i(e)||a(e)?CHAR_LF:t[e];function E(){return s=0,u(n)&&(r++,o=0),c(n)&&n++,n++,o++,t[n]}return{index:()=>n,line:()=>r,column:()=>o,peekOffset:()=>s,charAt:l,currentChar:()=>l(n),currentPeek:()=>l(n+s),next:E,peek:function(){return c(n+s)&&s++,s++,t[n+s]},reset:function(){n=0,r=1,o=1,s=0},resetPeek:function(e=0){s=e},skipToPeek:function(){const e=n+s;for(;e!==n;)E();s=0}}}const EOF=void 0,DOT=".",LITERAL_DELIMITER="'",ERROR_DOMAIN$1="tokenizer";function createTokenizer(e,t={}){const n=!1!==t.location,r=createScanner(e),o=()=>r.index(),s=()=>createPosition(r.line(),r.column(),r.index()),c=s(),i=o(),a={currentType:14,offset:i,startLoc:c,endLoc:c,lastType:14,lastOffset:i,lastStartLoc:c,lastEndLoc:c,braceNest:0,inLinked:!1,text:""},u=()=>a,{onError:l}=t;function E(e,t,r){e.endLoc=s(),e.currentType=t;const o={type:t};return n&&(o.loc=createLocation(e.startLoc,e.endLoc)),null!=r&&(o.value=r),o}const C=e=>E(e,14);function f(e,t){return e.currentChar()===t?(e.next(),t):(CompileErrorCodes.EXPECTED_TOKEN,s(),"")}function d(e){let t="";for(;e.currentPeek()===CHAR_SP||e.currentPeek()===CHAR_LF;)t+=e.currentPeek(),e.peek();return t}function p(e){const t=d(e);return e.skipToPeek(),t}function L(e){if(e===EOF)return!1;const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||95===t}function _(e,t){const{currentType:n}=t;if(2!==n)return!1;d(e);const r=function(e){if(e===EOF)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}("-"===e.currentPeek()?e.peek():e.currentPeek());return e.resetPeek(),r}function N(e){d(e);const t="|"===e.currentPeek();return e.resetPeek(),t}function A(e,t=!0){const n=(t=!1,r="",o=!1)=>{const s=e.currentPeek();return"{"===s?"%"!==r&&t:"@"!==s&&s?"%"===s?(e.peek(),n(t,"%",!0)):"|"===s?!("%"!==r&&!o)||!(r===CHAR_SP||r===CHAR_LF):s===CHAR_SP?(e.peek(),n(!0,CHAR_SP,o)):s!==CHAR_LF||(e.peek(),n(!0,CHAR_LF,o)):"%"===r||t},r=n();return t&&e.resetPeek(),r}function T(e,t){const n=e.currentChar();return n===EOF?EOF:t(n)?(e.next(),n):null}function m(e){return T(e,(e=>{const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||95===t||36===t}))}function k(e){return T(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57}))}function I(e){return T(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}))}function S(e){let t="",n="";for(;t=k(e);)n+=t;return n}function P(e){let t="";for(;;){const n=e.currentChar();if("{"===n||"}"===n||"@"===n||"|"===n||!n)break;if("%"===n){if(!A(e))break;t+=n,e.next()}else if(n===CHAR_SP||n===CHAR_LF)if(A(e))t+=n,e.next();else{if(N(e))break;t+=n,e.next()}else t+=n,e.next()}return t}function h(e){const t=e.currentChar();switch(t){case"\\":case"'":return e.next(),`\\${t}`;case"u":return O(e,t,4);case"U":return O(e,t,6);default:return CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE,s(),""}}function O(e,t,n){f(e,t);let r="";for(let o=0;o<n;o++){const t=I(e);if(!t){CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE,s(),e.currentChar();break}r+=t}return`\\${t}${r}`}function y(e){p(e);const t=f(e,"|");return p(e),t}function D(e,t){let n=null;switch(e.currentChar()){case"{":return t.braceNest>=1&&(CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER,s()),e.next(),n=E(t,2,"{"),p(e),t.braceNest++,n;case"}":return t.braceNest>0&&2===t.currentType&&(CompileErrorCodes.EMPTY_PLACEHOLDER,s()),e.next(),n=E(t,3,"}"),t.braceNest--,t.braceNest>0&&p(e),t.inLinked&&0===t.braceNest&&(t.inLinked=!1),n;case"@":return t.braceNest>0&&(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE,s()),n=R(e,t)||C(t),t.braceNest=0,n;default:{let r=!0,o=!0,c=!0;if(N(e))return t.braceNest>0&&(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE,s()),n=E(t,1,y(e)),t.braceNest=0,t.inLinked=!1,n;if(t.braceNest>0&&(5===t.currentType||6===t.currentType||7===t.currentType))return CompileErrorCodes.UNTERMINATED_CLOSING_BRACE,s(),t.braceNest=0,g(e,t);if(r=function(e,t){const{currentType:n}=t;if(2!==n)return!1;d(e);const r=L(e.currentPeek());return e.resetPeek(),r}(e,t))return n=E(t,5,function(e){p(e);let t="",n="";for(;t=m(e);)n+=t;return e.currentChar()===EOF&&(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE,s()),n}(e)),p(e),n;if(o=_(e,t))return n=E(t,6,function(e){p(e);let t="";return"-"===e.currentChar()?(e.next(),t+=`-${S(e)}`):t+=S(e),e.currentChar()===EOF&&(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE,s()),t}(e)),p(e),n;if(c=function(e,t){const{currentType:n}=t;if(2!==n)return!1;d(e);const r=e.currentPeek()===LITERAL_DELIMITER;return e.resetPeek(),r}(e,t))return n=E(t,7,function(e){p(e),f(e,"'");let t="",n="";const r=e=>e!==LITERAL_DELIMITER&&e!==CHAR_LF;for(;t=T(e,r);)n+="\\"===t?h(e):t;const o=e.currentChar();return o===CHAR_LF||o===EOF?(CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER,s(),o===CHAR_LF&&(e.next(),f(e,"'")),n):(f(e,"'"),n)}(e)),p(e),n;if(!r&&!o&&!c)return n=E(t,13,function(e){p(e);let t="",n="";const r=e=>"{"!==e&&"}"!==e&&e!==CHAR_SP&&e!==CHAR_LF;for(;t=T(e,r);)n+=t;return n}(e)),CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER,s(),n.value,p(e),n;break}}return n}function R(e,t){const{currentType:n}=t;let r=null;const o=e.currentChar();switch(8!==n&&9!==n&&12!==n&&10!==n||o!==CHAR_LF&&o!==CHAR_SP||(CompileErrorCodes.INVALID_LINKED_FORMAT,s()),o){case"@":return e.next(),r=E(t,8,"@"),t.inLinked=!0,r;case".":return p(e),e.next(),E(t,9,".");case":":return p(e),e.next(),E(t,10,":");default:return N(e)?(r=E(t,1,y(e)),t.braceNest=0,t.inLinked=!1,r):function(e,t){const{currentType:n}=t;if(8!==n)return!1;d(e);const r="."===e.currentPeek();return e.resetPeek(),r}(e,t)||function(e,t){const{currentType:n}=t;if(8!==n&&12!==n)return!1;d(e);const r=":"===e.currentPeek();return e.resetPeek(),r}(e,t)?(p(e),R(e,t)):function(e,t){const{currentType:n}=t;if(9!==n)return!1;d(e);const r=L(e.currentPeek());return e.resetPeek(),r}(e,t)?(p(e),E(t,12,function(e){let t="",n="";for(;t=m(e);)n+=t;return n}(e))):function(e,t){const{currentType:n}=t;if(10!==n)return!1;const r=()=>{const t=e.currentPeek();return"{"===t?L(e.peek()):!("@"===t||"%"===t||"|"===t||":"===t||"."===t||t===CHAR_SP||!t)&&(t===CHAR_LF?(e.peek(),r()):L(t))},o=r();return e.resetPeek(),o}(e,t)?(p(e),"{"===o?D(e,t)||r:E(t,11,function(e){const t=(n=!1,r)=>{const o=e.currentChar();return"{"!==o&&"%"!==o&&"@"!==o&&"|"!==o&&"("!==o&&")"!==o&&o?o===CHAR_SP?r:o===CHAR_LF||o===DOT?(r+=o,e.next(),t(n,r)):(r+=o,e.next(),t(!0,r)):r};return t(!1,"")}(e))):(8===n&&(CompileErrorCodes.INVALID_LINKED_FORMAT,s()),t.braceNest=0,t.inLinked=!1,g(e,t))}}function g(e,t){let n={type:14};if(t.braceNest>0)return D(e,t)||C(t);if(t.inLinked)return R(e,t)||C(t);switch(e.currentChar()){case"{":return D(e,t)||C(t);case"}":return CompileErrorCodes.UNBALANCED_CLOSING_BRACE,s(),e.next(),E(t,3,"}");case"@":return R(e,t)||C(t);default:{if(N(e))return n=E(t,1,y(e)),t.braceNest=0,t.inLinked=!1,n;const{isModulo:r,hasSpace:o}=function(e){const t=d(e),n="%"===e.currentPeek()&&"{"===e.peek();return e.resetPeek(),{isModulo:n,hasSpace:t.length>0}}(e);if(r)return o?E(t,0,P(e)):E(t,4,function(e){p(e);const t=e.currentChar();return"%"!==t&&(CompileErrorCodes.EXPECTED_TOKEN,s()),e.next(),"%"}(e));if(A(e))return E(t,0,P(e));break}}return n}return{nextToken:function(){const{currentType:e,offset:t,startLoc:n,endLoc:c}=a;return a.lastType=e,a.lastOffset=t,a.lastStartLoc=n,a.lastEndLoc=c,a.offset=o(),a.startLoc=s(),r.currentChar()===EOF?E(a,14):g(r,a)},currentOffset:o,currentPosition:s,context:u}}const ERROR_DOMAIN="parser",KNOWN_ESCAPES=/(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;function fromEscapeSequence(e,t,n){switch(e){case"\\\\":return"\\";case"\\'":return"'";default:{const e=parseInt(t||n,16);return e<=55295||e>=57344?String.fromCodePoint(e):"�"}}}function createParser(e={}){const t=!1!==e.location,{onError:n}=e;function r(e,n,r){const o={type:e};return t&&(o.start=n,o.end=n,o.loc={start:r,end:r}),o}function o(e,n,r,o){o&&(e.type=o),t&&(e.end=n,e.loc&&(e.loc.end=r))}function s(e,t){const n=e.context(),s=r(3,n.offset,n.startLoc);return s.value=t,o(s,e.currentOffset(),e.currentPosition()),s}function c(e,t){const n=e.context(),{lastOffset:s,lastStartLoc:c}=n,i=r(5,s,c);return i.index=parseInt(t,10),e.nextToken(),o(i,e.currentOffset(),e.currentPosition()),i}function i(e,t){const n=e.context(),{lastOffset:s,lastStartLoc:c}=n,i=r(4,s,c);return i.key=t,e.nextToken(),o(i,e.currentOffset(),e.currentPosition()),i}function a(e,t){const n=e.context(),{lastOffset:s,lastStartLoc:c}=n,i=r(9,s,c);return i.value=t.replace(KNOWN_ESCAPES,fromEscapeSequence),e.nextToken(),o(i,e.currentOffset(),e.currentPosition()),i}function u(e){const t=e.context(),n=r(6,t.offset,t.startLoc);let s=e.nextToken();if(9===s.type){const t=function(e){const t=e.nextToken(),n=e.context(),{lastOffset:s,lastStartLoc:c}=n,i=r(8,s,c);return 12!==t.type?(CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER,n.lastStartLoc,i.value="",o(i,s,c),{nextConsumeToken:t,node:i}):(null==t.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,n.lastStartLoc,getTokenCaption(t)),i.value=t.value||"",o(i,e.currentOffset(),e.currentPosition()),{node:i})}(e);n.modifier=t.node,s=t.nextConsumeToken||e.nextToken()}switch(10!==s.type&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(s)),s=e.nextToken(),2===s.type&&(s=e.nextToken()),s.type){case 11:null==s.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(s)),n.key=function(e,t){const n=e.context(),s=r(7,n.offset,n.startLoc);return s.value=t,o(s,e.currentOffset(),e.currentPosition()),s}(e,s.value||"");break;case 5:null==s.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(s)),n.key=i(e,s.value||"");break;case 6:null==s.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(s)),n.key=c(e,s.value||"");break;case 7:null==s.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(s)),n.key=a(e,s.value||"");break;default:{CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY,t.lastStartLoc;const c=e.context(),i=r(7,c.offset,c.startLoc);return i.value="",o(i,c.offset,c.startLoc),n.key=i,o(n,c.offset,c.startLoc),{nextConsumeToken:s,node:n}}}return o(n,e.currentOffset(),e.currentPosition()),{node:n}}function l(e){const t=e.context(),n=r(2,1===t.currentType?e.currentOffset():t.offset,1===t.currentType?t.endLoc:t.startLoc);n.items=[];let l=null;do{const r=l||e.nextToken();switch(l=null,r.type){case 0:null==r.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(r)),n.items.push(s(e,r.value||""));break;case 6:null==r.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(r)),n.items.push(c(e,r.value||""));break;case 5:null==r.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(r)),n.items.push(i(e,r.value||""));break;case 7:null==r.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(r)),n.items.push(a(e,r.value||""));break;case 8:{const t=u(e);n.items.push(t.node),l=t.nextConsumeToken||null;break}}}while(14!==t.currentType&&1!==t.currentType);return o(n,1===t.currentType?t.lastOffset:e.currentOffset(),1===t.currentType?t.lastEndLoc:e.currentPosition()),n}function E(e){const t=e.context(),{offset:n,startLoc:s}=t,c=l(e);return 14===t.currentType?c:function(e,t,n,s){const c=e.context();let i=0===s.items.length;const a=r(1,t,n);a.cases=[],a.cases.push(s);do{const t=l(e);i||(i=0===t.items.length),a.cases.push(t)}while(14!==c.currentType);return i&&CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL,o(a,e.currentOffset(),e.currentPosition()),a}(e,n,s,c)}return{parse:function(n){const s=createTokenizer(n,assign({},e)),c=s.context(),i=r(0,c.offset,c.startLoc);return t&&i.loc&&(i.loc.source=n),i.body=E(s),e.onCacheKey&&(i.cacheKey=e.onCacheKey(n)),14!==c.currentType&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,c.lastStartLoc,n[c.offset]),o(i,s.currentOffset(),s.currentPosition()),i}}}function getTokenCaption(e){if(14===e.type)return"EOF";const t=(e.value||"").replace(/\r?\n/gu,"\\n");return t.length>10?t.slice(0,9)+"…":t}function createTransformer(e,t={}){const n={ast:e,helpers:new Set};return{context:()=>n,helper:e=>(n.helpers.add(e),e)}}function traverseNodes(e,t){for(let n=0;n<e.length;n++)traverseNode(e[n],t)}function traverseNode(e,t){switch(e.type){case 1:traverseNodes(e.cases,t),t.helper("plural");break;case 2:traverseNodes(e.items,t);break;case 6:traverseNode(e.key,t),t.helper("linked"),t.helper("type");break;case 5:t.helper("interpolate"),t.helper("list");break;case 4:t.helper("interpolate"),t.helper("named")}}function transform(e,t={}){const n=createTransformer(e);n.helper("normalize"),e.body&&traverseNode(e.body,n);const r=n.context();e.helpers=Array.from(r.helpers)}function optimize(e){const t=e.body;return 2===t.type?optimizeMessageNode(t):t.cases.forEach((e=>optimizeMessageNode(e))),e}function optimizeMessageNode(e){if(1===e.items.length){const t=e.items[0];3!==t.type&&9!==t.type||(e.static=t.value,delete t.value)}else{const t=[];for(let n=0;n<e.items.length;n++){const r=e.items[n];if(3!==r.type&&9!==r.type)break;if(null==r.value)break;t.push(r.value)}if(t.length===e.items.length){e.static=join(t);for(let t=0;t<e.items.length;t++){const n=e.items[t];3!==n.type&&9!==n.type||delete n.value}}}}function minify(e){switch(e.t=e.type,e.type){case 0:{const t=e;minify(t.body),t.b=t.body,delete t.body;break}case 1:{const t=e,n=t.cases;for(let e=0;e<n.length;e++)minify(n[e]);t.c=n,delete t.cases;break}case 2:{const t=e,n=t.items;for(let e=0;e<n.length;e++)minify(n[e]);t.i=n,delete t.items,t.static&&(t.s=t.static,delete t.static);break}case 3:case 9:case 8:case 7:{const t=e;t.value&&(t.v=t.value,delete t.value);break}case 6:{const t=e;minify(t.key),t.k=t.key,delete t.key,t.modifier&&(minify(t.modifier),t.m=t.modifier,delete t.modifier);break}case 5:{const t=e;t.i=t.index,delete t.index;break}case 4:{const t=e;t.k=t.key,delete t.key;break}}delete e.type}function createCodeGenerator(e,t){const{sourceMap:n,filename:r,breakLineCode:o,needIndent:s}=t,c=!1!==t.location,i={filename:r,code:"",column:1,line:1,offset:0,map:void 0,breakLineCode:o,needIndent:s,indentLevel:0};c&&e.loc&&(i.source=e.loc.source);function a(e,t){i.code+=e}function u(e,t=!0){const n=t?o:"";a(s?n+" ".repeat(e):n)}return{context:()=>i,push:a,indent:function(e=!0){const t=++i.indentLevel;e&&u(t)},deindent:function(e=!0){const t=--i.indentLevel;e&&u(t)},newline:function(){u(i.indentLevel)},helper:e=>`_${e}`,needIndent:()=>i.needIndent}}function generateLinkedNode(e,t){const{helper:n}=e;e.push(`${n("linked")}(`),generateNode(e,t.key),t.modifier?(e.push(", "),generateNode(e,t.modifier),e.push(", _type")):e.push(", undefined, _type"),e.push(")")}function generateMessageNode(e,t){const{helper:n,needIndent:r}=e;e.push(`${n("normalize")}([`),e.indent(r());const o=t.items.length;for(let s=0;s<o&&(generateNode(e,t.items[s]),s!==o-1);s++)e.push(", ");e.deindent(r()),e.push("])")}function generatePluralNode(e,t){const{helper:n,needIndent:r}=e;if(t.cases.length>1){e.push(`${n("plural")}([`),e.indent(r());const o=t.cases.length;for(let n=0;n<o&&(generateNode(e,t.cases[n]),n!==o-1);n++)e.push(", ");e.deindent(r()),e.push("])")}}function generateResource(e,t){t.body?generateNode(e,t.body):e.push("null")}function generateNode(e,t){const{helper:n}=e;switch(t.type){case 0:generateResource(e,t);break;case 1:generatePluralNode(e,t);break;case 2:generateMessageNode(e,t);break;case 6:generateLinkedNode(e,t);break;case 8:case 7:case 9:case 3:e.push(JSON.stringify(t.value),t);break;case 5:e.push(`${n("interpolate")}(${n("list")}(${t.index}))`,t);break;case 4:e.push(`${n("interpolate")}(${n("named")}(${JSON.stringify(t.key)}))`,t)}}const generate=(e,t={})=>{const n=isString(t.mode)?t.mode:"normal",r=isString(t.filename)?t.filename:"message.intl",o=!!t.sourceMap,s=null!=t.breakLineCode?t.breakLineCode:"arrow"===n?";":"\n",c=t.needIndent?t.needIndent:"arrow"!==n,i=e.helpers||[],a=createCodeGenerator(e,{mode:n,filename:r,sourceMap:o,breakLineCode:s,needIndent:c});a.push("normal"===n?"function __msg__ (ctx) {":"(ctx) => {"),a.indent(c),i.length>0&&(a.push(`const { ${join(i.map((e=>`${e}: _${e}`)),", ")} } = ctx`),a.newline()),a.push("return "),generateNode(a,e),a.deindent(c),a.push("}"),delete e.helpers;const{code:u,map:l}=a.context();return{ast:e,code:u,map:l?l.toJSON():void 0}};function baseCompile(e,t={}){const n=assign({},t),r=!!n.jit,o=!!n.minify,s=null==n.optimize||n.optimize,c=createParser(n).parse(e);return r?(s&&optimize(c),o&&minify(c),{ast:c,code:""}):(transform(c,n),generate(c,n))}export{CompileErrorCodes,ERROR_DOMAIN,LOCATION_STUB,baseCompile,createCompileError,createLocation,createParser,createPosition,defaultOnError,detectHtmlTag,errorMessages};
|
|
6
|
+
const LOCATION_STUB={start:{line:1,column:1,offset:0},end:{line:1,column:1,offset:0}};function createPosition(e,t,n){return{line:e,column:t,offset:n}}function createLocation(e,t,n){const r={start:e,end:t};return null!=n&&(r.source=n),r}const assign=Object.assign,isString=e=>"string"==typeof e;function join(e,t=""){return e.reduce(((e,n,r)=>0===r?e+n:e+t+n),"")}const CompileWarnCodes={USE_MODULO_SYNTAX:1,__EXTEND_POINT__:2},warnMessages={[CompileWarnCodes.USE_MODULO_SYNTAX]:"Use modulo before '{{0}}'."};function createCompileWarn(e,t,...n){const r={message:String(e),code:e};return t&&(r.location=t),r}const CompileErrorCodes={EXPECTED_TOKEN:1,INVALID_TOKEN_IN_PLACEHOLDER:2,UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER:3,UNKNOWN_ESCAPE_SEQUENCE:4,INVALID_UNICODE_ESCAPE_SEQUENCE:5,UNBALANCED_CLOSING_BRACE:6,UNTERMINATED_CLOSING_BRACE:7,EMPTY_PLACEHOLDER:8,NOT_ALLOW_NEST_PLACEHOLDER:9,INVALID_LINKED_FORMAT:10,MUST_HAVE_MESSAGES_IN_PLURAL:11,UNEXPECTED_EMPTY_LINKED_MODIFIER:12,UNEXPECTED_EMPTY_LINKED_KEY:13,UNEXPECTED_LEXICAL_ANALYSIS:14,UNHANDLED_CODEGEN_NODE_TYPE:15,UNHANDLED_MINIFIER_NODE_TYPE:16,__EXTEND_POINT__:17},errorMessages={[CompileErrorCodes.EXPECTED_TOKEN]:"Expected token: '{0}'",[CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER]:"Invalid token in placeholder: '{0}'",[CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]:"Unterminated single quote in placeholder",[CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE]:"Unknown escape sequence: \\{0}",[CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE]:"Invalid unicode escape sequence: {0}",[CompileErrorCodes.UNBALANCED_CLOSING_BRACE]:"Unbalanced closing brace",[CompileErrorCodes.UNTERMINATED_CLOSING_BRACE]:"Unterminated closing brace",[CompileErrorCodes.EMPTY_PLACEHOLDER]:"Empty placeholder",[CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER]:"Not allowed nest placeholder",[CompileErrorCodes.INVALID_LINKED_FORMAT]:"Invalid linked format",[CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL]:"Plural must have messages",[CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER]:"Unexpected empty linked modifier",[CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY]:"Unexpected empty linked key",[CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS]:"Unexpected lexical analysis in token: '{0}'",[CompileErrorCodes.UNHANDLED_CODEGEN_NODE_TYPE]:"unhandled codegen node type: '{0}'",[CompileErrorCodes.UNHANDLED_MINIFIER_NODE_TYPE]:"unhandled mimifier node type: '{0}'"};function createCompileError(e,t,n={}){const{domain:r,messages:o,args:s}=n,c=new SyntaxError(String(e));return c.code=e,t&&(c.location=t),c.domain=r,c}function defaultOnError(e){throw e}const RE_HTML_TAG=/<\/?[\w\s="/.':;#-\/]+>/,detectHtmlTag=e=>RE_HTML_TAG.test(e),CHAR_SP=" ",CHAR_CR="\r",CHAR_LF="\n",CHAR_LS=String.fromCharCode(8232),CHAR_PS=String.fromCharCode(8233);function createScanner(e){const t=e;let n=0,r=1,o=1,s=0;const c=e=>t[e]===CHAR_CR&&t[e+1]===CHAR_LF,a=e=>t[e]===CHAR_PS,i=e=>t[e]===CHAR_LS,u=e=>c(e)||(e=>t[e]===CHAR_LF)(e)||a(e)||i(e),l=e=>c(e)||a(e)||i(e)?CHAR_LF:t[e];function E(){return s=0,u(n)&&(r++,o=0),c(n)&&n++,n++,o++,t[n]}return{index:()=>n,line:()=>r,column:()=>o,peekOffset:()=>s,charAt:l,currentChar:()=>l(n),currentPeek:()=>l(n+s),next:E,peek:function(){return c(n+s)&&s++,s++,t[n+s]},reset:function(){n=0,r=1,o=1,s=0},resetPeek:function(e=0){s=e},skipToPeek:function(){const e=n+s;for(;e!==n;)E();s=0}}}const EOF=void 0,DOT=".",LITERAL_DELIMITER="'",ERROR_DOMAIN$1="tokenizer";function createTokenizer(e,t={}){const n=!1!==t.location,r=createScanner(e),o=()=>r.index(),s=()=>createPosition(r.line(),r.column(),r.index()),c=s(),a=o(),i={currentType:14,offset:a,startLoc:c,endLoc:c,lastType:14,lastOffset:a,lastStartLoc:c,lastEndLoc:c,braceNest:0,inLinked:!1,text:""},u=()=>i,{onError:l}=t;function E(e,t,r){e.endLoc=s(),e.currentType=t;const o={type:t};return n&&(o.loc=createLocation(e.startLoc,e.endLoc)),null!=r&&(o.value=r),o}const C=e=>E(e,14);function d(e,t){return e.currentChar()===t?(e.next(),t):(CompileErrorCodes.EXPECTED_TOKEN,s(),"")}function f(e){let t="";for(;e.currentPeek()===CHAR_SP||e.currentPeek()===CHAR_LF;)t+=e.currentPeek(),e.peek();return t}function p(e){const t=f(e);return e.skipToPeek(),t}function _(e){if(e===EOF)return!1;const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||95===t}function L(e,t){const{currentType:n}=t;if(2!==n)return!1;f(e);const r=function(e){if(e===EOF)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}("-"===e.currentPeek()?e.peek():e.currentPeek());return e.resetPeek(),r}function N(e){f(e);const t="|"===e.currentPeek();return e.resetPeek(),t}function A(e,t=!0){const n=(t=!1,r="",o=!1)=>{const s=e.currentPeek();return"{"===s?"%"!==r&&t:"@"!==s&&s?"%"===s?(e.peek(),n(t,"%",!0)):"|"===s?!("%"!==r&&!o)||!(r===CHAR_SP||r===CHAR_LF):s===CHAR_SP?(e.peek(),n(!0,CHAR_SP,o)):s!==CHAR_LF||(e.peek(),n(!0,CHAR_LF,o)):"%"===r||t},r=n();return t&&e.resetPeek(),r}function T(e,t){const n=e.currentChar();return n===EOF?EOF:t(n)?(e.next(),n):null}function m(e){return T(e,(e=>{const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||95===t||36===t}))}function k(e){return T(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57}))}function I(e){return T(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}))}function S(e){let t="",n="";for(;t=k(e);)n+=t;return n}function P(e){let t="";for(;;){const n=e.currentChar();if("{"===n||"}"===n||"@"===n||"|"===n||!n)break;if("%"===n){if(!A(e))break;t+=n,e.next()}else if(n===CHAR_SP||n===CHAR_LF)if(A(e))t+=n,e.next();else{if(N(e))break;t+=n,e.next()}else t+=n,e.next()}return t}function O(e){const t=e.currentChar();switch(t){case"\\":case"'":return e.next(),`\\${t}`;case"u":return h(e,t,4);case"U":return h(e,t,6);default:return CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE,s(),""}}function h(e,t,n){d(e,t);let r="";for(let o=0;o<n;o++){const t=I(e);if(!t){CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE,s(),e.currentChar();break}r+=t}return`\\${t}${r}`}function D(e){p(e);const t=d(e,"|");return p(e),t}function y(e,t){let n=null;switch(e.currentChar()){case"{":return t.braceNest>=1&&(CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER,s()),e.next(),n=E(t,2,"{"),p(e),t.braceNest++,n;case"}":return t.braceNest>0&&2===t.currentType&&(CompileErrorCodes.EMPTY_PLACEHOLDER,s()),e.next(),n=E(t,3,"}"),t.braceNest--,t.braceNest>0&&p(e),t.inLinked&&0===t.braceNest&&(t.inLinked=!1),n;case"@":return t.braceNest>0&&(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE,s()),n=R(e,t)||C(t),t.braceNest=0,n;default:{let r=!0,o=!0,c=!0;if(N(e))return t.braceNest>0&&(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE,s()),n=E(t,1,D(e)),t.braceNest=0,t.inLinked=!1,n;if(t.braceNest>0&&(5===t.currentType||6===t.currentType||7===t.currentType))return CompileErrorCodes.UNTERMINATED_CLOSING_BRACE,s(),t.braceNest=0,g(e,t);if(r=function(e,t){const{currentType:n}=t;if(2!==n)return!1;f(e);const r=_(e.currentPeek());return e.resetPeek(),r}(e,t))return n=E(t,5,function(e){p(e);let t="",n="";for(;t=m(e);)n+=t;return e.currentChar()===EOF&&(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE,s()),n}(e)),p(e),n;if(o=L(e,t))return n=E(t,6,function(e){p(e);let t="";return"-"===e.currentChar()?(e.next(),t+=`-${S(e)}`):t+=S(e),e.currentChar()===EOF&&(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE,s()),t}(e)),p(e),n;if(c=function(e,t){const{currentType:n}=t;if(2!==n)return!1;f(e);const r=e.currentPeek()===LITERAL_DELIMITER;return e.resetPeek(),r}(e,t))return n=E(t,7,function(e){p(e),d(e,"'");let t="",n="";const r=e=>e!==LITERAL_DELIMITER&&e!==CHAR_LF;for(;t=T(e,r);)n+="\\"===t?O(e):t;const o=e.currentChar();return o===CHAR_LF||o===EOF?(CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER,s(),o===CHAR_LF&&(e.next(),d(e,"'")),n):(d(e,"'"),n)}(e)),p(e),n;if(!r&&!o&&!c)return n=E(t,13,function(e){p(e);let t="",n="";const r=e=>"{"!==e&&"}"!==e&&e!==CHAR_SP&&e!==CHAR_LF;for(;t=T(e,r);)n+=t;return n}(e)),CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER,s(),n.value,p(e),n;break}}return n}function R(e,t){const{currentType:n}=t;let r=null;const o=e.currentChar();switch(8!==n&&9!==n&&12!==n&&10!==n||o!==CHAR_LF&&o!==CHAR_SP||(CompileErrorCodes.INVALID_LINKED_FORMAT,s()),o){case"@":return e.next(),r=E(t,8,"@"),t.inLinked=!0,r;case".":return p(e),e.next(),E(t,9,".");case":":return p(e),e.next(),E(t,10,":");default:return N(e)?(r=E(t,1,D(e)),t.braceNest=0,t.inLinked=!1,r):function(e,t){const{currentType:n}=t;if(8!==n)return!1;f(e);const r="."===e.currentPeek();return e.resetPeek(),r}(e,t)||function(e,t){const{currentType:n}=t;if(8!==n&&12!==n)return!1;f(e);const r=":"===e.currentPeek();return e.resetPeek(),r}(e,t)?(p(e),R(e,t)):function(e,t){const{currentType:n}=t;if(9!==n)return!1;f(e);const r=_(e.currentPeek());return e.resetPeek(),r}(e,t)?(p(e),E(t,12,function(e){let t="",n="";for(;t=m(e);)n+=t;return n}(e))):function(e,t){const{currentType:n}=t;if(10!==n)return!1;const r=()=>{const t=e.currentPeek();return"{"===t?_(e.peek()):!("@"===t||"%"===t||"|"===t||":"===t||"."===t||t===CHAR_SP||!t)&&(t===CHAR_LF?(e.peek(),r()):_(t))},o=r();return e.resetPeek(),o}(e,t)?(p(e),"{"===o?y(e,t)||r:E(t,11,function(e){const t=(n=!1,r)=>{const o=e.currentChar();return"{"!==o&&"%"!==o&&"@"!==o&&"|"!==o&&"("!==o&&")"!==o&&o?o===CHAR_SP?r:o===CHAR_LF||o===DOT?(r+=o,e.next(),t(n,r)):(r+=o,e.next(),t(!0,r)):r};return t(!1,"")}(e))):(8===n&&(CompileErrorCodes.INVALID_LINKED_FORMAT,s()),t.braceNest=0,t.inLinked=!1,g(e,t))}}function g(e,t){let n={type:14};if(t.braceNest>0)return y(e,t)||C(t);if(t.inLinked)return R(e,t)||C(t);switch(e.currentChar()){case"{":return y(e,t)||C(t);case"}":return CompileErrorCodes.UNBALANCED_CLOSING_BRACE,s(),e.next(),E(t,3,"}");case"@":return R(e,t)||C(t);default:{if(N(e))return n=E(t,1,D(e)),t.braceNest=0,t.inLinked=!1,n;const{isModulo:r,hasSpace:o}=function(e){const t=f(e),n="%"===e.currentPeek()&&"{"===e.peek();return e.resetPeek(),{isModulo:n,hasSpace:t.length>0}}(e);if(r)return o?E(t,0,P(e)):E(t,4,function(e){p(e);const t=e.currentChar();return"%"!==t&&(CompileErrorCodes.EXPECTED_TOKEN,s()),e.next(),"%"}(e));if(A(e))return E(t,0,P(e));break}}return n}return{nextToken:function(){const{currentType:e,offset:t,startLoc:n,endLoc:c}=i;return i.lastType=e,i.lastOffset=t,i.lastStartLoc=n,i.lastEndLoc=c,i.offset=o(),i.startLoc=s(),r.currentChar()===EOF?E(i,14):g(r,i)},currentOffset:o,currentPosition:s,context:u}}const ERROR_DOMAIN="parser",KNOWN_ESCAPES=/(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;function fromEscapeSequence(e,t,n){switch(e){case"\\\\":return"\\";case"\\'":return"'";default:{const e=parseInt(t||n,16);return e<=55295||e>=57344?String.fromCodePoint(e):"�"}}}function createParser(e={}){const t=!1!==e.location,{onError:n,onWarn:r}=e;function o(e,n,r){const o={type:e};return t&&(o.start=n,o.end=n,o.loc={start:r,end:r}),o}function s(e,n,r,o){o&&(e.type=o),t&&(e.end=n,e.loc&&(e.loc.end=r))}function c(e,t){const n=e.context(),r=o(3,n.offset,n.startLoc);return r.value=t,s(r,e.currentOffset(),e.currentPosition()),r}function a(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:c}=n,a=o(5,r,c);return a.index=parseInt(t,10),e.nextToken(),s(a,e.currentOffset(),e.currentPosition()),a}function i(e,t,n){const r=e.context(),{lastOffset:c,lastStartLoc:a}=r,i=o(4,c,a);return i.key=t,!0===n&&(i.modulo=!0),e.nextToken(),s(i,e.currentOffset(),e.currentPosition()),i}function u(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:c}=n,a=o(9,r,c);return a.value=t.replace(KNOWN_ESCAPES,fromEscapeSequence),e.nextToken(),s(a,e.currentOffset(),e.currentPosition()),a}function l(e){const t=e.context(),n=o(6,t.offset,t.startLoc);let r=e.nextToken();if(9===r.type){const t=function(e){const t=e.nextToken(),n=e.context(),{lastOffset:r,lastStartLoc:c}=n,a=o(8,r,c);return 12!==t.type?(CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER,n.lastStartLoc,a.value="",s(a,r,c),{nextConsumeToken:t,node:a}):(null==t.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,n.lastStartLoc,getTokenCaption(t)),a.value=t.value||"",s(a,e.currentOffset(),e.currentPosition()),{node:a})}(e);n.modifier=t.node,r=t.nextConsumeToken||e.nextToken()}switch(10!==r.type&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(r)),r=e.nextToken(),2===r.type&&(r=e.nextToken()),r.type){case 11:null==r.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(r)),n.key=function(e,t){const n=e.context(),r=o(7,n.offset,n.startLoc);return r.value=t,s(r,e.currentOffset(),e.currentPosition()),r}(e,r.value||"");break;case 5:null==r.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(r)),n.key=i(e,r.value||"");break;case 6:null==r.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(r)),n.key=a(e,r.value||"");break;case 7:null==r.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(r)),n.key=u(e,r.value||"");break;default:{CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY,t.lastStartLoc;const c=e.context(),a=o(7,c.offset,c.startLoc);return a.value="",s(a,c.offset,c.startLoc),n.key=a,s(n,c.offset,c.startLoc),{nextConsumeToken:r,node:n}}}return s(n,e.currentOffset(),e.currentPosition()),{node:n}}function E(e){const t=e.context(),n=o(2,1===t.currentType?e.currentOffset():t.offset,1===t.currentType?t.endLoc:t.startLoc);n.items=[];let r=null,E=null;do{const o=r||e.nextToken();switch(r=null,o.type){case 0:null==o.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(o)),n.items.push(c(e,o.value||""));break;case 6:null==o.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(o)),n.items.push(a(e,o.value||""));break;case 4:E=!0;break;case 5:null==o.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(o)),n.items.push(i(e,o.value||"",!!E)),E&&(CompileWarnCodes.USE_MODULO_SYNTAX,t.lastStartLoc,getTokenCaption(o),E=null);break;case 7:null==o.value&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,getTokenCaption(o)),n.items.push(u(e,o.value||""));break;case 8:{const t=l(e);n.items.push(t.node),r=t.nextConsumeToken||null;break}}}while(14!==t.currentType&&1!==t.currentType);return s(n,1===t.currentType?t.lastOffset:e.currentOffset(),1===t.currentType?t.lastEndLoc:e.currentPosition()),n}function C(e){const t=e.context(),{offset:n,startLoc:r}=t,c=E(e);return 14===t.currentType?c:function(e,t,n,r){const c=e.context();let a=0===r.items.length;const i=o(1,t,n);i.cases=[],i.cases.push(r);do{const t=E(e);a||(a=0===t.items.length),i.cases.push(t)}while(14!==c.currentType);return a&&CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL,s(i,e.currentOffset(),e.currentPosition()),i}(e,n,r,c)}return{parse:function(n){const r=createTokenizer(n,assign({},e)),c=r.context(),a=o(0,c.offset,c.startLoc);return t&&a.loc&&(a.loc.source=n),a.body=C(r),e.onCacheKey&&(a.cacheKey=e.onCacheKey(n)),14!==c.currentType&&(CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS,c.lastStartLoc,n[c.offset]),s(a,r.currentOffset(),r.currentPosition()),a}}}function getTokenCaption(e){if(14===e.type)return"EOF";const t=(e.value||"").replace(/\r?\n/gu,"\\n");return t.length>10?t.slice(0,9)+"…":t}function createTransformer(e,t={}){const n={ast:e,helpers:new Set};return{context:()=>n,helper:e=>(n.helpers.add(e),e)}}function traverseNodes(e,t){for(let n=0;n<e.length;n++)traverseNode(e[n],t)}function traverseNode(e,t){switch(e.type){case 1:traverseNodes(e.cases,t),t.helper("plural");break;case 2:traverseNodes(e.items,t);break;case 6:traverseNode(e.key,t),t.helper("linked"),t.helper("type");break;case 5:t.helper("interpolate"),t.helper("list");break;case 4:t.helper("interpolate"),t.helper("named")}}function transform(e,t={}){const n=createTransformer(e);n.helper("normalize"),e.body&&traverseNode(e.body,n);const r=n.context();e.helpers=Array.from(r.helpers)}function optimize(e){const t=e.body;return 2===t.type?optimizeMessageNode(t):t.cases.forEach((e=>optimizeMessageNode(e))),e}function optimizeMessageNode(e){if(1===e.items.length){const t=e.items[0];3!==t.type&&9!==t.type||(e.static=t.value,delete t.value)}else{const t=[];for(let n=0;n<e.items.length;n++){const r=e.items[n];if(3!==r.type&&9!==r.type)break;if(null==r.value)break;t.push(r.value)}if(t.length===e.items.length){e.static=join(t);for(let t=0;t<e.items.length;t++){const n=e.items[t];3!==n.type&&9!==n.type||delete n.value}}}}function minify(e){switch(e.t=e.type,e.type){case 0:{const t=e;minify(t.body),t.b=t.body,delete t.body;break}case 1:{const t=e,n=t.cases;for(let e=0;e<n.length;e++)minify(n[e]);t.c=n,delete t.cases;break}case 2:{const t=e,n=t.items;for(let e=0;e<n.length;e++)minify(n[e]);t.i=n,delete t.items,t.static&&(t.s=t.static,delete t.static);break}case 3:case 9:case 8:case 7:{const t=e;t.value&&(t.v=t.value,delete t.value);break}case 6:{const t=e;minify(t.key),t.k=t.key,delete t.key,t.modifier&&(minify(t.modifier),t.m=t.modifier,delete t.modifier);break}case 5:{const t=e;t.i=t.index,delete t.index;break}case 4:{const t=e;t.k=t.key,delete t.key;break}}delete e.type}function createCodeGenerator(e,t){const{sourceMap:n,filename:r,breakLineCode:o,needIndent:s}=t,c=!1!==t.location,a={filename:r,code:"",column:1,line:1,offset:0,map:void 0,breakLineCode:o,needIndent:s,indentLevel:0};c&&e.loc&&(a.source=e.loc.source);function i(e,t){a.code+=e}function u(e,t=!0){const n=t?o:"";i(s?n+" ".repeat(e):n)}return{context:()=>a,push:i,indent:function(e=!0){const t=++a.indentLevel;e&&u(t)},deindent:function(e=!0){const t=--a.indentLevel;e&&u(t)},newline:function(){u(a.indentLevel)},helper:e=>`_${e}`,needIndent:()=>a.needIndent}}function generateLinkedNode(e,t){const{helper:n}=e;e.push(`${n("linked")}(`),generateNode(e,t.key),t.modifier?(e.push(", "),generateNode(e,t.modifier),e.push(", _type")):e.push(", undefined, _type"),e.push(")")}function generateMessageNode(e,t){const{helper:n,needIndent:r}=e;e.push(`${n("normalize")}([`),e.indent(r());const o=t.items.length;for(let s=0;s<o&&(generateNode(e,t.items[s]),s!==o-1);s++)e.push(", ");e.deindent(r()),e.push("])")}function generatePluralNode(e,t){const{helper:n,needIndent:r}=e;if(t.cases.length>1){e.push(`${n("plural")}([`),e.indent(r());const o=t.cases.length;for(let n=0;n<o&&(generateNode(e,t.cases[n]),n!==o-1);n++)e.push(", ");e.deindent(r()),e.push("])")}}function generateResource(e,t){t.body?generateNode(e,t.body):e.push("null")}function generateNode(e,t){const{helper:n}=e;switch(t.type){case 0:generateResource(e,t);break;case 1:generatePluralNode(e,t);break;case 2:generateMessageNode(e,t);break;case 6:generateLinkedNode(e,t);break;case 8:case 7:case 9:case 3:e.push(JSON.stringify(t.value),t);break;case 5:e.push(`${n("interpolate")}(${n("list")}(${t.index}))`,t);break;case 4:e.push(`${n("interpolate")}(${n("named")}(${JSON.stringify(t.key)}))`,t)}}const generate=(e,t={})=>{const n=isString(t.mode)?t.mode:"normal",r=isString(t.filename)?t.filename:"message.intl",o=!!t.sourceMap,s=null!=t.breakLineCode?t.breakLineCode:"arrow"===n?";":"\n",c=t.needIndent?t.needIndent:"arrow"!==n,a=e.helpers||[],i=createCodeGenerator(e,{mode:n,filename:r,sourceMap:o,breakLineCode:s,needIndent:c});i.push("normal"===n?"function __msg__ (ctx) {":"(ctx) => {"),i.indent(c),a.length>0&&(i.push(`const { ${join(a.map((e=>`${e}: _${e}`)),", ")} } = ctx`),i.newline()),i.push("return "),generateNode(i,e),i.deindent(c),i.push("}"),delete e.helpers;const{code:u,map:l}=i.context();return{ast:e,code:u,map:l?l.toJSON():void 0}};function baseCompile(e,t={}){const n=assign({},t),r=!!n.jit,o=!!n.minify,s=null==n.optimize||n.optimize,c=createParser(n).parse(e);return r?(s&&optimize(c),o&&minify(c),{ast:c,code:""}):(transform(c,n),generate(c,n))}export{CompileErrorCodes,CompileWarnCodes,ERROR_DOMAIN,LOCATION_STUB,baseCompile,createCompileError,createCompileWarn,createLocation,createParser,createPosition,defaultOnError,detectHtmlTag,errorMessages,warnMessages};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* message-compiler v9.
|
|
2
|
+
* message-compiler v9.12.0
|
|
3
3
|
* (c) 2024 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -46,6 +46,23 @@ 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
|
+
|
|
49
66
|
const CompileErrorCodes = {
|
|
50
67
|
// tokenizer error codes
|
|
51
68
|
EXPECTED_TOKEN: 1,
|
|
@@ -896,7 +913,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
896
913
|
}
|
|
897
914
|
function createParser(options = {}) {
|
|
898
915
|
const location = options.location !== false;
|
|
899
|
-
const { onError } = options;
|
|
916
|
+
const { onError, onWarn } = options;
|
|
900
917
|
function emitError(tokenzer, code, start, offset, ...args) {
|
|
901
918
|
const end = tokenzer.currentPosition();
|
|
902
919
|
end.offset += offset;
|
|
@@ -910,6 +927,15 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
910
927
|
onError(err);
|
|
911
928
|
}
|
|
912
929
|
}
|
|
930
|
+
function emitWarn(tokenzer, code, start, offset, ...args) {
|
|
931
|
+
const end = tokenzer.currentPosition();
|
|
932
|
+
end.offset += offset;
|
|
933
|
+
end.column += offset;
|
|
934
|
+
if (onWarn) {
|
|
935
|
+
const loc = location ? createLocation(start, end) : null;
|
|
936
|
+
onWarn(createCompileWarn(code, loc, args));
|
|
937
|
+
}
|
|
938
|
+
}
|
|
913
939
|
function startNode(type, offset, loc) {
|
|
914
940
|
const node = { type };
|
|
915
941
|
if (location) {
|
|
@@ -946,11 +972,14 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
946
972
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
947
973
|
return node;
|
|
948
974
|
}
|
|
949
|
-
function parseNamed(tokenizer, key) {
|
|
975
|
+
function parseNamed(tokenizer, key, modulo) {
|
|
950
976
|
const context = tokenizer.context();
|
|
951
977
|
const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
|
|
952
978
|
const node = startNode(4 /* NodeTypes.Named */, offset, loc);
|
|
953
979
|
node.key = key;
|
|
980
|
+
if (modulo === true) {
|
|
981
|
+
node.modulo = true;
|
|
982
|
+
}
|
|
954
983
|
tokenizer.nextToken(); // skip brach right
|
|
955
984
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
956
985
|
return node;
|
|
@@ -1070,6 +1099,7 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
1070
1099
|
const node = startNode(2 /* NodeTypes.Message */, startOffset, startLoc);
|
|
1071
1100
|
node.items = [];
|
|
1072
1101
|
let nextToken = null;
|
|
1102
|
+
let modulo = null;
|
|
1073
1103
|
do {
|
|
1074
1104
|
const token = nextToken || tokenizer.nextToken();
|
|
1075
1105
|
nextToken = null;
|
|
@@ -1086,11 +1116,18 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
1086
1116
|
}
|
|
1087
1117
|
node.items.push(parseList(tokenizer, token.value || ''));
|
|
1088
1118
|
break;
|
|
1119
|
+
case 4 /* TokenTypes.Modulo */:
|
|
1120
|
+
modulo = true;
|
|
1121
|
+
break;
|
|
1089
1122
|
case 5 /* TokenTypes.Named */:
|
|
1090
1123
|
if (token.value == null) {
|
|
1091
1124
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1092
1125
|
}
|
|
1093
|
-
node.items.push(parseNamed(tokenizer, token.value || ''));
|
|
1126
|
+
node.items.push(parseNamed(tokenizer, token.value || '', !!modulo));
|
|
1127
|
+
if (modulo) {
|
|
1128
|
+
emitWarn(tokenizer, CompileWarnCodes.USE_MODULO_SYNTAX, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1129
|
+
modulo = null;
|
|
1130
|
+
}
|
|
1094
1131
|
break;
|
|
1095
1132
|
case 7 /* TokenTypes.Literal */:
|
|
1096
1133
|
if (token.value == null) {
|
|
@@ -1572,16 +1609,19 @@ var IntlifyMessageCompiler = (function (exports) {
|
|
|
1572
1609
|
}
|
|
1573
1610
|
|
|
1574
1611
|
exports.CompileErrorCodes = CompileErrorCodes;
|
|
1612
|
+
exports.CompileWarnCodes = CompileWarnCodes;
|
|
1575
1613
|
exports.ERROR_DOMAIN = ERROR_DOMAIN$2;
|
|
1576
1614
|
exports.LOCATION_STUB = LOCATION_STUB;
|
|
1577
1615
|
exports.baseCompile = baseCompile;
|
|
1578
1616
|
exports.createCompileError = createCompileError;
|
|
1617
|
+
exports.createCompileWarn = createCompileWarn;
|
|
1579
1618
|
exports.createLocation = createLocation;
|
|
1580
1619
|
exports.createParser = createParser;
|
|
1581
1620
|
exports.createPosition = createPosition;
|
|
1582
1621
|
exports.defaultOnError = defaultOnError;
|
|
1583
1622
|
exports.detectHtmlTag = detectHtmlTag;
|
|
1584
1623
|
exports.errorMessages = errorMessages;
|
|
1624
|
+
exports.warnMessages = warnMessages;
|
|
1585
1625
|
|
|
1586
1626
|
return exports;
|
|
1587
1627
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* message-compiler v9.
|
|
2
|
+
* message-compiler v9.12.0
|
|
3
3
|
* (c) 2024 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
var IntlifyMessageCompiler=function(e){"use strict";function t(e,t,n){return{line:e,column:t,offset:n}}function n(e,t,n){const r={start:e,end:t};return null!=n&&(r.source=n),r}const r=Object.assign,c=e=>"string"==typeof e;function o(e,t=""){return e.reduce(((e,n,r)=>0===r?e+n:e+t+n),"")}const s={EXPECTED_TOKEN:1,INVALID_TOKEN_IN_PLACEHOLDER:2,UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER:3,UNKNOWN_ESCAPE_SEQUENCE:4,INVALID_UNICODE_ESCAPE_SEQUENCE:5,UNBALANCED_CLOSING_BRACE:6,UNTERMINATED_CLOSING_BRACE:7,EMPTY_PLACEHOLDER:8,NOT_ALLOW_NEST_PLACEHOLDER:9,INVALID_LINKED_FORMAT:10,MUST_HAVE_MESSAGES_IN_PLURAL:11,UNEXPECTED_EMPTY_LINKED_MODIFIER:12,UNEXPECTED_EMPTY_LINKED_KEY:13,UNEXPECTED_LEXICAL_ANALYSIS:14,UNHANDLED_CODEGEN_NODE_TYPE:15,UNHANDLED_MINIFIER_NODE_TYPE:16,__EXTEND_POINT__:17},u={[s.EXPECTED_TOKEN]:"Expected token: '{0}'",[s.INVALID_TOKEN_IN_PLACEHOLDER]:"Invalid token in placeholder: '{0}'",[s.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]:"Unterminated single quote in placeholder",[s.UNKNOWN_ESCAPE_SEQUENCE]:"Unknown escape sequence: \\{0}",[s.INVALID_UNICODE_ESCAPE_SEQUENCE]:"Invalid unicode escape sequence: {0}",[s.UNBALANCED_CLOSING_BRACE]:"Unbalanced closing brace",[s.UNTERMINATED_CLOSING_BRACE]:"Unterminated closing brace",[s.EMPTY_PLACEHOLDER]:"Empty placeholder",[s.NOT_ALLOW_NEST_PLACEHOLDER]:"Not allowed nest placeholder",[s.INVALID_LINKED_FORMAT]:"Invalid linked format",[s.MUST_HAVE_MESSAGES_IN_PLURAL]:"Plural must have messages",[s.UNEXPECTED_EMPTY_LINKED_MODIFIER]:"Unexpected empty linked modifier",[s.UNEXPECTED_EMPTY_LINKED_KEY]:"Unexpected empty linked key",[s.UNEXPECTED_LEXICAL_ANALYSIS]:"Unexpected lexical analysis in token: '{0}'",[s.UNHANDLED_CODEGEN_NODE_TYPE]:"unhandled codegen node type: '{0}'",[s.UNHANDLED_MINIFIER_NODE_TYPE]:"unhandled mimifier node type: '{0}'"};function a(e,t,n={}){const{domain:r,messages:c,args:o}=n,s=new SyntaxError(String(e));return s.code=e,t&&(s.location=t),s.domain=r,s}const i=/<\/?[\w\s="/.':;#-\/]+>/,l=" ",E="\r",f="\n",d=String.fromCharCode(8232),L=String.fromCharCode(8233);function N(e){const t=e;let n=0,r=1,c=1,o=0;const s=e=>t[e]===E&&t[e+1]===f,u=e=>t[e]===L,a=e=>t[e]===d,i=e=>s(e)||(e=>t[e]===f)(e)||u(e)||a(e),l=e=>s(e)||u(e)||a(e)?f:t[e];function N(){return o=0,i(n)&&(r++,c=0),s(n)&&n++,n++,c++,t[n]}return{index:()=>n,line:()=>r,column:()=>c,peekOffset:()=>o,charAt:l,currentChar:()=>l(n),currentPeek:()=>l(n+o),next:N,peek:function(){return s(n+o)&&o++,o++,t[n+o]},reset:function(){n=0,r=1,c=1,o=0},resetPeek:function(e=0){o=e},skipToPeek:function(){const e=n+o;for(;e!==n;)N();o=0}}}const _=void 0,p=".",C="'";function k(e,r={}){const c=!1!==r.location,o=N(e),u=()=>o.index(),a=()=>t(o.line(),o.column(),o.index()),i=a(),E=u(),d={currentType:14,offset:E,startLoc:i,endLoc:i,lastType:14,lastOffset:E,lastStartLoc:i,lastEndLoc:i,braceNest:0,inLinked:!1,text:""},L=()=>d,{onError:k}=r;function T(e,t,r){e.endLoc=a(),e.currentType=t;const o={type:t};return c&&(o.loc=n(e.startLoc,e.endLoc)),null!=r&&(o.value=r),o}const A=e=>T(e,14);function I(e,t){return e.currentChar()===t?(e.next(),t):(s.EXPECTED_TOKEN,a(),"")}function h(e){let t="";for(;e.currentPeek()===l||e.currentPeek()===f;)t+=e.currentPeek(),e.peek();return t}function P(e){const t=h(e);return e.skipToPeek(),t}function S(e){if(e===_)return!1;const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||95===t}function y(e,t){const{currentType:n}=t;if(2!==n)return!1;h(e);const r=function(e){if(e===_)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}("-"===e.currentPeek()?e.peek():e.currentPeek());return e.resetPeek(),r}function D(e){h(e);const t="|"===e.currentPeek();return e.resetPeek(),t}function O(e,t=!0){const n=(t=!1,r="",c=!1)=>{const o=e.currentPeek();return"{"===o?"%"!==r&&t:"@"!==o&&o?"%"===o?(e.peek(),n(t,"%",!0)):"|"===o?!("%"!==r&&!c)||!(r===l||r===f):o===l?(e.peek(),n(!0,l,c)):o!==f||(e.peek(),n(!0,f,c)):"%"===r||t},r=n();return t&&e.resetPeek(),r}function m(e,t){const n=e.currentChar();return n===_?_:t(n)?(e.next(),n):null}function b(e){return m(e,(e=>{const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||95===t||36===t}))}function x(e){return m(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57}))}function U(e){return m(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}))}function v(e){let t="",n="";for(;t=x(e);)n+=t;return n}function R(e){let t="";for(;;){const n=e.currentChar();if("{"===n||"}"===n||"@"===n||"|"===n||!n)break;if("%"===n){if(!O(e))break;t+=n,e.next()}else if(n===l||n===f)if(O(e))t+=n,e.next();else{if(D(e))break;t+=n,e.next()}else t+=n,e.next()}return t}function M(e){const t=e.currentChar();switch(t){case"\\":case"'":return e.next(),`\\${t}`;case"u":return g(e,t,4);case"U":return g(e,t,6);default:return s.UNKNOWN_ESCAPE_SEQUENCE,a(),""}}function g(e,t,n){I(e,t);let r="";for(let c=0;c<n;c++){const t=U(e);if(!t){s.INVALID_UNICODE_ESCAPE_SEQUENCE,a(),e.currentChar();break}r+=t}return`\\${t}${r}`}function X(e){P(e);const t=I(e,"|");return P(e),t}function Y(e,t){let n=null;switch(e.currentChar()){case"{":return t.braceNest>=1&&(s.NOT_ALLOW_NEST_PLACEHOLDER,a()),e.next(),n=T(t,2,"{"),P(e),t.braceNest++,n;case"}":return t.braceNest>0&&2===t.currentType&&(s.EMPTY_PLACEHOLDER,a()),e.next(),n=T(t,3,"}"),t.braceNest--,t.braceNest>0&&P(e),t.inLinked&&0===t.braceNest&&(t.inLinked=!1),n;case"@":return t.braceNest>0&&(s.UNTERMINATED_CLOSING_BRACE,a()),n=K(e,t)||A(t),t.braceNest=0,n;default:{let r=!0,c=!0,o=!0;if(D(e))return t.braceNest>0&&(s.UNTERMINATED_CLOSING_BRACE,a()),n=T(t,1,X(e)),t.braceNest=0,t.inLinked=!1,n;if(t.braceNest>0&&(5===t.currentType||6===t.currentType||7===t.currentType))return s.UNTERMINATED_CLOSING_BRACE,a(),t.braceNest=0,w(e,t);if(r=function(e,t){const{currentType:n}=t;if(2!==n)return!1;h(e);const r=S(e.currentPeek());return e.resetPeek(),r}(e,t))return n=T(t,5,function(e){P(e);let t="",n="";for(;t=b(e);)n+=t;return e.currentChar()===_&&(s.UNTERMINATED_CLOSING_BRACE,a()),n}(e)),P(e),n;if(c=y(e,t))return n=T(t,6,function(e){P(e);let t="";return"-"===e.currentChar()?(e.next(),t+=`-${v(e)}`):t+=v(e),e.currentChar()===_&&(s.UNTERMINATED_CLOSING_BRACE,a()),t}(e)),P(e),n;if(o=function(e,t){const{currentType:n}=t;if(2!==n)return!1;h(e);const r=e.currentPeek()===C;return e.resetPeek(),r}(e,t))return n=T(t,7,function(e){P(e),I(e,"'");let t="",n="";const r=e=>e!==C&&e!==f;for(;t=m(e,r);)n+="\\"===t?M(e):t;const c=e.currentChar();return c===f||c===_?(s.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER,a(),c===f&&(e.next(),I(e,"'")),n):(I(e,"'"),n)}(e)),P(e),n;if(!r&&!c&&!o)return n=T(t,13,function(e){P(e);let t="",n="";const r=e=>"{"!==e&&"}"!==e&&e!==l&&e!==f;for(;t=m(e,r);)n+=t;return n}(e)),s.INVALID_TOKEN_IN_PLACEHOLDER,a(),n.value,P(e),n;break}}return n}function K(e,t){const{currentType:n}=t;let r=null;const c=e.currentChar();switch(8!==n&&9!==n&&12!==n&&10!==n||c!==f&&c!==l||(s.INVALID_LINKED_FORMAT,a()),c){case"@":return e.next(),r=T(t,8,"@"),t.inLinked=!0,r;case".":return P(e),e.next(),T(t,9,".");case":":return P(e),e.next(),T(t,10,":");default:return D(e)?(r=T(t,1,X(e)),t.braceNest=0,t.inLinked=!1,r):function(e,t){const{currentType:n}=t;if(8!==n)return!1;h(e);const r="."===e.currentPeek();return e.resetPeek(),r}(e,t)||function(e,t){const{currentType:n}=t;if(8!==n&&12!==n)return!1;h(e);const r=":"===e.currentPeek();return e.resetPeek(),r}(e,t)?(P(e),K(e,t)):function(e,t){const{currentType:n}=t;if(9!==n)return!1;h(e);const r=S(e.currentPeek());return e.resetPeek(),r}(e,t)?(P(e),T(t,12,function(e){let t="",n="";for(;t=b(e);)n+=t;return n}(e))):function(e,t){const{currentType:n}=t;if(10!==n)return!1;const r=()=>{const t=e.currentPeek();return"{"===t?S(e.peek()):!("@"===t||"%"===t||"|"===t||":"===t||"."===t||t===l||!t)&&(t===f?(e.peek(),r()):S(t))},c=r();return e.resetPeek(),c}(e,t)?(P(e),"{"===c?Y(e,t)||r:T(t,11,function(e){const t=(n=!1,r)=>{const c=e.currentChar();return"{"!==c&&"%"!==c&&"@"!==c&&"|"!==c&&"("!==c&&")"!==c&&c?c===l?r:c===f||c===p?(r+=c,e.next(),t(n,r)):(r+=c,e.next(),t(!0,r)):r};return t(!1,"")}(e))):(8===n&&(s.INVALID_LINKED_FORMAT,a()),t.braceNest=0,t.inLinked=!1,w(e,t))}}function w(e,t){let n={type:14};if(t.braceNest>0)return Y(e,t)||A(t);if(t.inLinked)return K(e,t)||A(t);switch(e.currentChar()){case"{":return Y(e,t)||A(t);case"}":return s.UNBALANCED_CLOSING_BRACE,a(),e.next(),T(t,3,"}");case"@":return K(e,t)||A(t);default:{if(D(e))return n=T(t,1,X(e)),t.braceNest=0,t.inLinked=!1,n;const{isModulo:r,hasSpace:c}=function(e){const t=h(e),n="%"===e.currentPeek()&&"{"===e.peek();return e.resetPeek(),{isModulo:n,hasSpace:t.length>0}}(e);if(r)return c?T(t,0,R(e)):T(t,4,function(e){P(e);const t=e.currentChar();return"%"!==t&&(s.EXPECTED_TOKEN,a()),e.next(),"%"}(e));if(O(e))return T(t,0,R(e));break}}return n}return{nextToken:function(){const{currentType:e,offset:t,startLoc:n,endLoc:r}=d;return d.lastType=e,d.lastOffset=t,d.lastStartLoc=n,d.lastEndLoc=r,d.offset=u(),d.startLoc=a(),o.currentChar()===_?T(d,14):w(o,d)},currentOffset:u,currentPosition:a,context:L}}const T="parser",A=/(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;function I(e,t,n){switch(e){case"\\\\":return"\\";case"\\'":return"'";default:{const e=parseInt(t||n,16);return e<=55295||e>=57344?String.fromCodePoint(e):"�"}}}function h(e={}){const t=!1!==e.location,{onError:n}=e;function c(e,n,r){const c={type:e};return t&&(c.start=n,c.end=n,c.loc={start:r,end:r}),c}function o(e,n,r,c){c&&(e.type=c),t&&(e.end=n,e.loc&&(e.loc.end=r))}function u(e,t){const n=e.context(),r=c(3,n.offset,n.startLoc);return r.value=t,o(r,e.currentOffset(),e.currentPosition()),r}function a(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(5,r,s);return u.index=parseInt(t,10),e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function i(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(4,r,s);return u.key=t,e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function l(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:s}=n,u=c(9,r,s);return u.value=t.replace(A,I),e.nextToken(),o(u,e.currentOffset(),e.currentPosition()),u}function E(e){const t=e.context(),n=c(6,t.offset,t.startLoc);let r=e.nextToken();if(9===r.type){const t=function(e){const t=e.nextToken(),n=e.context(),{lastOffset:r,lastStartLoc:u}=n,a=c(8,r,u);return 12!==t.type?(s.UNEXPECTED_EMPTY_LINKED_MODIFIER,n.lastStartLoc,a.value="",o(a,r,u),{nextConsumeToken:t,node:a}):(null==t.value&&(s.UNEXPECTED_LEXICAL_ANALYSIS,n.lastStartLoc,P(t)),a.value=t.value||"",o(a,e.currentOffset(),e.currentPosition()),{node:a})}(e);n.modifier=t.node,r=t.nextConsumeToken||e.nextToken()}switch(10!==r.type&&(s.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,P(r)),r=e.nextToken(),2===r.type&&(r=e.nextToken()),r.type){case 11:null==r.value&&(s.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,P(r)),n.key=function(e,t){const n=e.context(),r=c(7,n.offset,n.startLoc);return r.value=t,o(r,e.currentOffset(),e.currentPosition()),r}(e,r.value||"");break;case 5:null==r.value&&(s.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,P(r)),n.key=i(e,r.value||"");break;case 6:null==r.value&&(s.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,P(r)),n.key=a(e,r.value||"");break;case 7:null==r.value&&(s.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,P(r)),n.key=l(e,r.value||"");break;default:{s.UNEXPECTED_EMPTY_LINKED_KEY,t.lastStartLoc;const u=e.context(),a=c(7,u.offset,u.startLoc);return a.value="",o(a,u.offset,u.startLoc),n.key=a,o(n,u.offset,u.startLoc),{nextConsumeToken:r,node:n}}}return o(n,e.currentOffset(),e.currentPosition()),{node:n}}function f(e){const t=e.context(),n=c(2,1===t.currentType?e.currentOffset():t.offset,1===t.currentType?t.endLoc:t.startLoc);n.items=[];let r=null;do{const c=r||e.nextToken();switch(r=null,c.type){case 0:null==c.value&&(s.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,P(c)),n.items.push(u(e,c.value||""));break;case 6:null==c.value&&(s.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,P(c)),n.items.push(a(e,c.value||""));break;case 5:null==c.value&&(s.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,P(c)),n.items.push(i(e,c.value||""));break;case 7:null==c.value&&(s.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,P(c)),n.items.push(l(e,c.value||""));break;case 8:{const t=E(e);n.items.push(t.node),r=t.nextConsumeToken||null;break}}}while(14!==t.currentType&&1!==t.currentType);return o(n,1===t.currentType?t.lastOffset:e.currentOffset(),1===t.currentType?t.lastEndLoc:e.currentPosition()),n}function d(e){const t=e.context(),{offset:n,startLoc:r}=t,u=f(e);return 14===t.currentType?u:function(e,t,n,r){const u=e.context();let a=0===r.items.length;const i=c(1,t,n);i.cases=[],i.cases.push(r);do{const t=f(e);a||(a=0===t.items.length),i.cases.push(t)}while(14!==u.currentType);return a&&s.MUST_HAVE_MESSAGES_IN_PLURAL,o(i,e.currentOffset(),e.currentPosition()),i}(e,n,r,u)}return{parse:function(n){const u=k(n,r({},e)),a=u.context(),i=c(0,a.offset,a.startLoc);return t&&i.loc&&(i.loc.source=n),i.body=d(u),e.onCacheKey&&(i.cacheKey=e.onCacheKey(n)),14!==a.currentType&&(s.UNEXPECTED_LEXICAL_ANALYSIS,a.lastStartLoc,n[a.offset]),o(i,u.currentOffset(),u.currentPosition()),i}}}function P(e){if(14===e.type)return"EOF";const t=(e.value||"").replace(/\r?\n/gu,"\\n");return t.length>10?t.slice(0,9)+"…":t}function S(e,t){for(let n=0;n<e.length;n++)y(e[n],t)}function y(e,t){switch(e.type){case 1:S(e.cases,t),t.helper("plural");break;case 2:S(e.items,t);break;case 6:y(e.key,t),t.helper("linked"),t.helper("type");break;case 5:t.helper("interpolate"),t.helper("list");break;case 4:t.helper("interpolate"),t.helper("named")}}function D(e,t={}){const n=function(e,t={}){const n={ast:e,helpers:new Set};return{context:()=>n,helper:e=>(n.helpers.add(e),e)}}(e);n.helper("normalize"),e.body&&y(e.body,n);const r=n.context();e.helpers=Array.from(r.helpers)}function O(e){if(1===e.items.length){const t=e.items[0];3!==t.type&&9!==t.type||(e.static=t.value,delete t.value)}else{const t=[];for(let n=0;n<e.items.length;n++){const r=e.items[n];if(3!==r.type&&9!==r.type)break;if(null==r.value)break;t.push(r.value)}if(t.length===e.items.length){e.static=o(t);for(let t=0;t<e.items.length;t++){const n=e.items[t];3!==n.type&&9!==n.type||delete n.value}}}}function m(e){switch(e.t=e.type,e.type){case 0:{const t=e;m(t.body),t.b=t.body,delete t.body;break}case 1:{const t=e,n=t.cases;for(let e=0;e<n.length;e++)m(n[e]);t.c=n,delete t.cases;break}case 2:{const t=e,n=t.items;for(let e=0;e<n.length;e++)m(n[e]);t.i=n,delete t.items,t.static&&(t.s=t.static,delete t.static);break}case 3:case 9:case 8:case 7:{const t=e;t.value&&(t.v=t.value,delete t.value);break}case 6:{const t=e;m(t.key),t.k=t.key,delete t.key,t.modifier&&(m(t.modifier),t.m=t.modifier,delete t.modifier);break}case 5:{const t=e;t.i=t.index,delete t.index;break}case 4:{const t=e;t.k=t.key,delete t.key;break}}delete e.type}function b(e,t){const{helper:n}=e;switch(t.type){case 0:!function(e,t){t.body?b(e,t.body):e.push("null")}(e,t);break;case 1:!function(e,t){const{helper:n,needIndent:r}=e;if(t.cases.length>1){e.push(`${n("plural")}([`),e.indent(r());const c=t.cases.length;for(let n=0;n<c&&(b(e,t.cases[n]),n!==c-1);n++)e.push(", ");e.deindent(r()),e.push("])")}}(e,t);break;case 2:!function(e,t){const{helper:n,needIndent:r}=e;e.push(`${n("normalize")}([`),e.indent(r());const c=t.items.length;for(let o=0;o<c&&(b(e,t.items[o]),o!==c-1);o++)e.push(", ");e.deindent(r()),e.push("])")}(e,t);break;case 6:!function(e,t){const{helper:n}=e;e.push(`${n("linked")}(`),b(e,t.key),t.modifier?(e.push(", "),b(e,t.modifier),e.push(", _type")):e.push(", undefined, _type"),e.push(")")}(e,t);break;case 8:case 7:case 9:case 3:e.push(JSON.stringify(t.value),t);break;case 5:e.push(`${n("interpolate")}(${n("list")}(${t.index}))`,t);break;case 4:e.push(`${n("interpolate")}(${n("named")}(${JSON.stringify(t.key)}))`,t)}}return e.CompileErrorCodes=s,e.ERROR_DOMAIN=T,e.LOCATION_STUB={start:{line:1,column:1,offset:0},end:{line:1,column:1,offset:0}},e.baseCompile=function(e,t={}){const n=r({},t),s=!!n.jit,u=!!n.minify,a=null==n.optimize||n.optimize,i=h(n).parse(e);return s?(a&&function(e){const t=e.body;2===t.type?O(t):t.cases.forEach((e=>O(e)))}(i),u&&m(i),{ast:i,code:""}):(D(i,n),((e,t={})=>{const n=c(t.mode)?t.mode:"normal",r=c(t.filename)?t.filename:"message.intl",s=!!t.sourceMap,u=null!=t.breakLineCode?t.breakLineCode:"arrow"===n?";":"\n",a=t.needIndent?t.needIndent:"arrow"!==n,i=e.helpers||[],l=function(e,t){const{sourceMap:n,filename:r,breakLineCode:c,needIndent:o}=t,s=!1!==t.location,u={filename:r,code:"",column:1,line:1,offset:0,map:void 0,breakLineCode:c,needIndent:o,indentLevel:0};function a(e,t){u.code+=e}function i(e,t=!0){const n=t?c:"";a(o?n+" ".repeat(e):n)}return s&&e.loc&&(u.source=e.loc.source),{context:()=>u,push:a,indent:function(e=!0){const t=++u.indentLevel;e&&i(t)},deindent:function(e=!0){const t=--u.indentLevel;e&&i(t)},newline:function(){i(u.indentLevel)},helper:e=>`_${e}`,needIndent:()=>u.needIndent}}(e,{mode:n,filename:r,sourceMap:s,breakLineCode:u,needIndent:a});l.push("normal"===n?"function __msg__ (ctx) {":"(ctx) => {"),l.indent(a),i.length>0&&(l.push(`const { ${o(i.map((e=>`${e}: _${e}`)),", ")} } = ctx`),l.newline()),l.push("return "),b(l,e),l.deindent(a),l.push("}"),delete e.helpers;const{code:E,map:f}=l.context();return{ast:e,code:E,map:f?f.toJSON():void 0}})(i,n))},e.createCompileError=a,e.createLocation=n,e.createParser=h,e.createPosition=t,e.defaultOnError=function(e){throw e},e.detectHtmlTag=e=>i.test(e),e.errorMessages=u,e}({});
|
|
6
|
+
var IntlifyMessageCompiler=function(e){"use strict";function t(e,t,n){return{line:e,column:t,offset:n}}function n(e,t,n){const r={start:e,end:t};return null!=n&&(r.source=n),r}const r=Object.assign,c=e=>"string"==typeof e;function o(e,t=""){return e.reduce(((e,n,r)=>0===r?e+n:e+t+n),"")}const s={USE_MODULO_SYNTAX:1,__EXTEND_POINT__:2},u={[s.USE_MODULO_SYNTAX]:"Use modulo before '{{0}}'."};function a(e,t,...n){const r={message:String(e),code:e};return t&&(r.location=t),r}const i={EXPECTED_TOKEN:1,INVALID_TOKEN_IN_PLACEHOLDER:2,UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER:3,UNKNOWN_ESCAPE_SEQUENCE:4,INVALID_UNICODE_ESCAPE_SEQUENCE:5,UNBALANCED_CLOSING_BRACE:6,UNTERMINATED_CLOSING_BRACE:7,EMPTY_PLACEHOLDER:8,NOT_ALLOW_NEST_PLACEHOLDER:9,INVALID_LINKED_FORMAT:10,MUST_HAVE_MESSAGES_IN_PLURAL:11,UNEXPECTED_EMPTY_LINKED_MODIFIER:12,UNEXPECTED_EMPTY_LINKED_KEY:13,UNEXPECTED_LEXICAL_ANALYSIS:14,UNHANDLED_CODEGEN_NODE_TYPE:15,UNHANDLED_MINIFIER_NODE_TYPE:16,__EXTEND_POINT__:17},l={[i.EXPECTED_TOKEN]:"Expected token: '{0}'",[i.INVALID_TOKEN_IN_PLACEHOLDER]:"Invalid token in placeholder: '{0}'",[i.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]:"Unterminated single quote in placeholder",[i.UNKNOWN_ESCAPE_SEQUENCE]:"Unknown escape sequence: \\{0}",[i.INVALID_UNICODE_ESCAPE_SEQUENCE]:"Invalid unicode escape sequence: {0}",[i.UNBALANCED_CLOSING_BRACE]:"Unbalanced closing brace",[i.UNTERMINATED_CLOSING_BRACE]:"Unterminated closing brace",[i.EMPTY_PLACEHOLDER]:"Empty placeholder",[i.NOT_ALLOW_NEST_PLACEHOLDER]:"Not allowed nest placeholder",[i.INVALID_LINKED_FORMAT]:"Invalid linked format",[i.MUST_HAVE_MESSAGES_IN_PLURAL]:"Plural must have messages",[i.UNEXPECTED_EMPTY_LINKED_MODIFIER]:"Unexpected empty linked modifier",[i.UNEXPECTED_EMPTY_LINKED_KEY]:"Unexpected empty linked key",[i.UNEXPECTED_LEXICAL_ANALYSIS]:"Unexpected lexical analysis in token: '{0}'",[i.UNHANDLED_CODEGEN_NODE_TYPE]:"unhandled codegen node type: '{0}'",[i.UNHANDLED_MINIFIER_NODE_TYPE]:"unhandled mimifier node type: '{0}'"};function E(e,t,n={}){const{domain:r,messages:c,args:o}=n,s=new SyntaxError(String(e));return s.code=e,t&&(s.location=t),s.domain=r,s}const f=/<\/?[\w\s="/.':;#-\/]+>/,d=" ",L="\r",N="\n",_=String.fromCharCode(8232),p=String.fromCharCode(8233);function C(e){const t=e;let n=0,r=1,c=1,o=0;const s=e=>t[e]===L&&t[e+1]===N,u=e=>t[e]===p,a=e=>t[e]===_,i=e=>s(e)||(e=>t[e]===N)(e)||u(e)||a(e),l=e=>s(e)||u(e)||a(e)?N:t[e];function E(){return o=0,i(n)&&(r++,c=0),s(n)&&n++,n++,c++,t[n]}return{index:()=>n,line:()=>r,column:()=>c,peekOffset:()=>o,charAt:l,currentChar:()=>l(n),currentPeek:()=>l(n+o),next:E,peek:function(){return s(n+o)&&o++,o++,t[n+o]},reset:function(){n=0,r=1,c=1,o=0},resetPeek:function(e=0){o=e},skipToPeek:function(){const e=n+o;for(;e!==n;)E();o=0}}}const T=void 0,k=".",A="'";function I(e,r={}){const c=!1!==r.location,o=C(e),s=()=>o.index(),u=()=>t(o.line(),o.column(),o.index()),a=u(),l=s(),E={currentType:14,offset:l,startLoc:a,endLoc:a,lastType:14,lastOffset:l,lastStartLoc:a,lastEndLoc:a,braceNest:0,inLinked:!1,text:""},f=()=>E,{onError:L}=r;function _(e,t,r){e.endLoc=u(),e.currentType=t;const o={type:t};return c&&(o.loc=n(e.startLoc,e.endLoc)),null!=r&&(o.value=r),o}const p=e=>_(e,14);function I(e,t){return e.currentChar()===t?(e.next(),t):(i.EXPECTED_TOKEN,u(),"")}function h(e){let t="";for(;e.currentPeek()===d||e.currentPeek()===N;)t+=e.currentPeek(),e.peek();return t}function S(e){const t=h(e);return e.skipToPeek(),t}function P(e){if(e===T)return!1;const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||95===t}function O(e,t){const{currentType:n}=t;if(2!==n)return!1;h(e);const r=function(e){if(e===T)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57}("-"===e.currentPeek()?e.peek():e.currentPeek());return e.resetPeek(),r}function D(e){h(e);const t="|"===e.currentPeek();return e.resetPeek(),t}function y(e,t=!0){const n=(t=!1,r="",c=!1)=>{const o=e.currentPeek();return"{"===o?"%"!==r&&t:"@"!==o&&o?"%"===o?(e.peek(),n(t,"%",!0)):"|"===o?!("%"!==r&&!c)||!(r===d||r===N):o===d?(e.peek(),n(!0,d,c)):o!==N||(e.peek(),n(!0,N,c)):"%"===r||t},r=n();return t&&e.resetPeek(),r}function m(e,t){const n=e.currentChar();return n===T?T:t(n)?(e.next(),n):null}function U(e){return m(e,(e=>{const t=e.charCodeAt(0);return t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||95===t||36===t}))}function b(e){return m(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57}))}function x(e){return m(e,(e=>{const t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}))}function v(e){let t="",n="";for(;t=b(e);)n+=t;return n}function R(e){let t="";for(;;){const n=e.currentChar();if("{"===n||"}"===n||"@"===n||"|"===n||!n)break;if("%"===n){if(!y(e))break;t+=n,e.next()}else if(n===d||n===N)if(y(e))t+=n,e.next();else{if(D(e))break;t+=n,e.next()}else t+=n,e.next()}return t}function M(e){const t=e.currentChar();switch(t){case"\\":case"'":return e.next(),`\\${t}`;case"u":return g(e,t,4);case"U":return g(e,t,6);default:return i.UNKNOWN_ESCAPE_SEQUENCE,u(),""}}function g(e,t,n){I(e,t);let r="";for(let c=0;c<n;c++){const t=x(e);if(!t){i.INVALID_UNICODE_ESCAPE_SEQUENCE,u(),e.currentChar();break}r+=t}return`\\${t}${r}`}function X(e){S(e);const t=I(e,"|");return S(e),t}function Y(e,t){let n=null;switch(e.currentChar()){case"{":return t.braceNest>=1&&(i.NOT_ALLOW_NEST_PLACEHOLDER,u()),e.next(),n=_(t,2,"{"),S(e),t.braceNest++,n;case"}":return t.braceNest>0&&2===t.currentType&&(i.EMPTY_PLACEHOLDER,u()),e.next(),n=_(t,3,"}"),t.braceNest--,t.braceNest>0&&S(e),t.inLinked&&0===t.braceNest&&(t.inLinked=!1),n;case"@":return t.braceNest>0&&(i.UNTERMINATED_CLOSING_BRACE,u()),n=K(e,t)||p(t),t.braceNest=0,n;default:{let r=!0,c=!0,o=!0;if(D(e))return t.braceNest>0&&(i.UNTERMINATED_CLOSING_BRACE,u()),n=_(t,1,X(e)),t.braceNest=0,t.inLinked=!1,n;if(t.braceNest>0&&(5===t.currentType||6===t.currentType||7===t.currentType))return i.UNTERMINATED_CLOSING_BRACE,u(),t.braceNest=0,w(e,t);if(r=function(e,t){const{currentType:n}=t;if(2!==n)return!1;h(e);const r=P(e.currentPeek());return e.resetPeek(),r}(e,t))return n=_(t,5,function(e){S(e);let t="",n="";for(;t=U(e);)n+=t;return e.currentChar()===T&&(i.UNTERMINATED_CLOSING_BRACE,u()),n}(e)),S(e),n;if(c=O(e,t))return n=_(t,6,function(e){S(e);let t="";return"-"===e.currentChar()?(e.next(),t+=`-${v(e)}`):t+=v(e),e.currentChar()===T&&(i.UNTERMINATED_CLOSING_BRACE,u()),t}(e)),S(e),n;if(o=function(e,t){const{currentType:n}=t;if(2!==n)return!1;h(e);const r=e.currentPeek()===A;return e.resetPeek(),r}(e,t))return n=_(t,7,function(e){S(e),I(e,"'");let t="",n="";const r=e=>e!==A&&e!==N;for(;t=m(e,r);)n+="\\"===t?M(e):t;const c=e.currentChar();return c===N||c===T?(i.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER,u(),c===N&&(e.next(),I(e,"'")),n):(I(e,"'"),n)}(e)),S(e),n;if(!r&&!c&&!o)return n=_(t,13,function(e){S(e);let t="",n="";const r=e=>"{"!==e&&"}"!==e&&e!==d&&e!==N;for(;t=m(e,r);)n+=t;return n}(e)),i.INVALID_TOKEN_IN_PLACEHOLDER,u(),n.value,S(e),n;break}}return n}function K(e,t){const{currentType:n}=t;let r=null;const c=e.currentChar();switch(8!==n&&9!==n&&12!==n&&10!==n||c!==N&&c!==d||(i.INVALID_LINKED_FORMAT,u()),c){case"@":return e.next(),r=_(t,8,"@"),t.inLinked=!0,r;case".":return S(e),e.next(),_(t,9,".");case":":return S(e),e.next(),_(t,10,":");default:return D(e)?(r=_(t,1,X(e)),t.braceNest=0,t.inLinked=!1,r):function(e,t){const{currentType:n}=t;if(8!==n)return!1;h(e);const r="."===e.currentPeek();return e.resetPeek(),r}(e,t)||function(e,t){const{currentType:n}=t;if(8!==n&&12!==n)return!1;h(e);const r=":"===e.currentPeek();return e.resetPeek(),r}(e,t)?(S(e),K(e,t)):function(e,t){const{currentType:n}=t;if(9!==n)return!1;h(e);const r=P(e.currentPeek());return e.resetPeek(),r}(e,t)?(S(e),_(t,12,function(e){let t="",n="";for(;t=U(e);)n+=t;return n}(e))):function(e,t){const{currentType:n}=t;if(10!==n)return!1;const r=()=>{const t=e.currentPeek();return"{"===t?P(e.peek()):!("@"===t||"%"===t||"|"===t||":"===t||"."===t||t===d||!t)&&(t===N?(e.peek(),r()):P(t))},c=r();return e.resetPeek(),c}(e,t)?(S(e),"{"===c?Y(e,t)||r:_(t,11,function(e){const t=(n=!1,r)=>{const c=e.currentChar();return"{"!==c&&"%"!==c&&"@"!==c&&"|"!==c&&"("!==c&&")"!==c&&c?c===d?r:c===N||c===k?(r+=c,e.next(),t(n,r)):(r+=c,e.next(),t(!0,r)):r};return t(!1,"")}(e))):(8===n&&(i.INVALID_LINKED_FORMAT,u()),t.braceNest=0,t.inLinked=!1,w(e,t))}}function w(e,t){let n={type:14};if(t.braceNest>0)return Y(e,t)||p(t);if(t.inLinked)return K(e,t)||p(t);switch(e.currentChar()){case"{":return Y(e,t)||p(t);case"}":return i.UNBALANCED_CLOSING_BRACE,u(),e.next(),_(t,3,"}");case"@":return K(e,t)||p(t);default:{if(D(e))return n=_(t,1,X(e)),t.braceNest=0,t.inLinked=!1,n;const{isModulo:r,hasSpace:c}=function(e){const t=h(e),n="%"===e.currentPeek()&&"{"===e.peek();return e.resetPeek(),{isModulo:n,hasSpace:t.length>0}}(e);if(r)return c?_(t,0,R(e)):_(t,4,function(e){S(e);const t=e.currentChar();return"%"!==t&&(i.EXPECTED_TOKEN,u()),e.next(),"%"}(e));if(y(e))return _(t,0,R(e));break}}return n}return{nextToken:function(){const{currentType:e,offset:t,startLoc:n,endLoc:r}=E;return E.lastType=e,E.lastOffset=t,E.lastStartLoc=n,E.lastEndLoc=r,E.offset=s(),E.startLoc=u(),o.currentChar()===T?_(E,14):w(o,E)},currentOffset:s,currentPosition:u,context:f}}const h="parser",S=/(?:\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6}))/g;function P(e,t,n){switch(e){case"\\\\":return"\\";case"\\'":return"'";default:{const e=parseInt(t||n,16);return e<=55295||e>=57344?String.fromCodePoint(e):"�"}}}function O(e={}){const t=!1!==e.location,{onError:n,onWarn:c}=e;function o(e,n,r){const c={type:e};return t&&(c.start=n,c.end=n,c.loc={start:r,end:r}),c}function u(e,n,r,c){c&&(e.type=c),t&&(e.end=n,e.loc&&(e.loc.end=r))}function a(e,t){const n=e.context(),r=o(3,n.offset,n.startLoc);return r.value=t,u(r,e.currentOffset(),e.currentPosition()),r}function l(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:c}=n,s=o(5,r,c);return s.index=parseInt(t,10),e.nextToken(),u(s,e.currentOffset(),e.currentPosition()),s}function E(e,t,n){const r=e.context(),{lastOffset:c,lastStartLoc:s}=r,a=o(4,c,s);return a.key=t,!0===n&&(a.modulo=!0),e.nextToken(),u(a,e.currentOffset(),e.currentPosition()),a}function f(e,t){const n=e.context(),{lastOffset:r,lastStartLoc:c}=n,s=o(9,r,c);return s.value=t.replace(S,P),e.nextToken(),u(s,e.currentOffset(),e.currentPosition()),s}function d(e){const t=e.context(),n=o(6,t.offset,t.startLoc);let r=e.nextToken();if(9===r.type){const t=function(e){const t=e.nextToken(),n=e.context(),{lastOffset:r,lastStartLoc:c}=n,s=o(8,r,c);return 12!==t.type?(i.UNEXPECTED_EMPTY_LINKED_MODIFIER,n.lastStartLoc,s.value="",u(s,r,c),{nextConsumeToken:t,node:s}):(null==t.value&&(i.UNEXPECTED_LEXICAL_ANALYSIS,n.lastStartLoc,D(t)),s.value=t.value||"",u(s,e.currentOffset(),e.currentPosition()),{node:s})}(e);n.modifier=t.node,r=t.nextConsumeToken||e.nextToken()}switch(10!==r.type&&(i.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,D(r)),r=e.nextToken(),2===r.type&&(r=e.nextToken()),r.type){case 11:null==r.value&&(i.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,D(r)),n.key=function(e,t){const n=e.context(),r=o(7,n.offset,n.startLoc);return r.value=t,u(r,e.currentOffset(),e.currentPosition()),r}(e,r.value||"");break;case 5:null==r.value&&(i.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,D(r)),n.key=E(e,r.value||"");break;case 6:null==r.value&&(i.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,D(r)),n.key=l(e,r.value||"");break;case 7:null==r.value&&(i.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,D(r)),n.key=f(e,r.value||"");break;default:{i.UNEXPECTED_EMPTY_LINKED_KEY,t.lastStartLoc;const c=e.context(),s=o(7,c.offset,c.startLoc);return s.value="",u(s,c.offset,c.startLoc),n.key=s,u(n,c.offset,c.startLoc),{nextConsumeToken:r,node:n}}}return u(n,e.currentOffset(),e.currentPosition()),{node:n}}function L(e){const t=e.context(),n=o(2,1===t.currentType?e.currentOffset():t.offset,1===t.currentType?t.endLoc:t.startLoc);n.items=[];let r=null,c=null;do{const o=r||e.nextToken();switch(r=null,o.type){case 0:null==o.value&&(i.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,D(o)),n.items.push(a(e,o.value||""));break;case 6:null==o.value&&(i.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,D(o)),n.items.push(l(e,o.value||""));break;case 4:c=!0;break;case 5:null==o.value&&(i.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,D(o)),n.items.push(E(e,o.value||"",!!c)),c&&(s.USE_MODULO_SYNTAX,t.lastStartLoc,D(o),c=null);break;case 7:null==o.value&&(i.UNEXPECTED_LEXICAL_ANALYSIS,t.lastStartLoc,D(o)),n.items.push(f(e,o.value||""));break;case 8:{const t=d(e);n.items.push(t.node),r=t.nextConsumeToken||null;break}}}while(14!==t.currentType&&1!==t.currentType);return u(n,1===t.currentType?t.lastOffset:e.currentOffset(),1===t.currentType?t.lastEndLoc:e.currentPosition()),n}function N(e){const t=e.context(),{offset:n,startLoc:r}=t,c=L(e);return 14===t.currentType?c:function(e,t,n,r){const c=e.context();let s=0===r.items.length;const a=o(1,t,n);a.cases=[],a.cases.push(r);do{const t=L(e);s||(s=0===t.items.length),a.cases.push(t)}while(14!==c.currentType);return s&&i.MUST_HAVE_MESSAGES_IN_PLURAL,u(a,e.currentOffset(),e.currentPosition()),a}(e,n,r,c)}return{parse:function(n){const c=I(n,r({},e)),s=c.context(),a=o(0,s.offset,s.startLoc);return t&&a.loc&&(a.loc.source=n),a.body=N(c),e.onCacheKey&&(a.cacheKey=e.onCacheKey(n)),14!==s.currentType&&(i.UNEXPECTED_LEXICAL_ANALYSIS,s.lastStartLoc,n[s.offset]),u(a,c.currentOffset(),c.currentPosition()),a}}}function D(e){if(14===e.type)return"EOF";const t=(e.value||"").replace(/\r?\n/gu,"\\n");return t.length>10?t.slice(0,9)+"…":t}function y(e,t){for(let n=0;n<e.length;n++)m(e[n],t)}function m(e,t){switch(e.type){case 1:y(e.cases,t),t.helper("plural");break;case 2:y(e.items,t);break;case 6:m(e.key,t),t.helper("linked"),t.helper("type");break;case 5:t.helper("interpolate"),t.helper("list");break;case 4:t.helper("interpolate"),t.helper("named")}}function U(e,t={}){const n=function(e,t={}){const n={ast:e,helpers:new Set};return{context:()=>n,helper:e=>(n.helpers.add(e),e)}}(e);n.helper("normalize"),e.body&&m(e.body,n);const r=n.context();e.helpers=Array.from(r.helpers)}function b(e){if(1===e.items.length){const t=e.items[0];3!==t.type&&9!==t.type||(e.static=t.value,delete t.value)}else{const t=[];for(let n=0;n<e.items.length;n++){const r=e.items[n];if(3!==r.type&&9!==r.type)break;if(null==r.value)break;t.push(r.value)}if(t.length===e.items.length){e.static=o(t);for(let t=0;t<e.items.length;t++){const n=e.items[t];3!==n.type&&9!==n.type||delete n.value}}}}function x(e){switch(e.t=e.type,e.type){case 0:{const t=e;x(t.body),t.b=t.body,delete t.body;break}case 1:{const t=e,n=t.cases;for(let e=0;e<n.length;e++)x(n[e]);t.c=n,delete t.cases;break}case 2:{const t=e,n=t.items;for(let e=0;e<n.length;e++)x(n[e]);t.i=n,delete t.items,t.static&&(t.s=t.static,delete t.static);break}case 3:case 9:case 8:case 7:{const t=e;t.value&&(t.v=t.value,delete t.value);break}case 6:{const t=e;x(t.key),t.k=t.key,delete t.key,t.modifier&&(x(t.modifier),t.m=t.modifier,delete t.modifier);break}case 5:{const t=e;t.i=t.index,delete t.index;break}case 4:{const t=e;t.k=t.key,delete t.key;break}}delete e.type}function v(e,t){const{helper:n}=e;switch(t.type){case 0:!function(e,t){t.body?v(e,t.body):e.push("null")}(e,t);break;case 1:!function(e,t){const{helper:n,needIndent:r}=e;if(t.cases.length>1){e.push(`${n("plural")}([`),e.indent(r());const c=t.cases.length;for(let n=0;n<c&&(v(e,t.cases[n]),n!==c-1);n++)e.push(", ");e.deindent(r()),e.push("])")}}(e,t);break;case 2:!function(e,t){const{helper:n,needIndent:r}=e;e.push(`${n("normalize")}([`),e.indent(r());const c=t.items.length;for(let o=0;o<c&&(v(e,t.items[o]),o!==c-1);o++)e.push(", ");e.deindent(r()),e.push("])")}(e,t);break;case 6:!function(e,t){const{helper:n}=e;e.push(`${n("linked")}(`),v(e,t.key),t.modifier?(e.push(", "),v(e,t.modifier),e.push(", _type")):e.push(", undefined, _type"),e.push(")")}(e,t);break;case 8:case 7:case 9:case 3:e.push(JSON.stringify(t.value),t);break;case 5:e.push(`${n("interpolate")}(${n("list")}(${t.index}))`,t);break;case 4:e.push(`${n("interpolate")}(${n("named")}(${JSON.stringify(t.key)}))`,t)}}return e.CompileErrorCodes=i,e.CompileWarnCodes=s,e.ERROR_DOMAIN=h,e.LOCATION_STUB={start:{line:1,column:1,offset:0},end:{line:1,column:1,offset:0}},e.baseCompile=function(e,t={}){const n=r({},t),s=!!n.jit,u=!!n.minify,a=null==n.optimize||n.optimize,i=O(n).parse(e);return s?(a&&function(e){const t=e.body;2===t.type?b(t):t.cases.forEach((e=>b(e)))}(i),u&&x(i),{ast:i,code:""}):(U(i,n),((e,t={})=>{const n=c(t.mode)?t.mode:"normal",r=c(t.filename)?t.filename:"message.intl",s=!!t.sourceMap,u=null!=t.breakLineCode?t.breakLineCode:"arrow"===n?";":"\n",a=t.needIndent?t.needIndent:"arrow"!==n,i=e.helpers||[],l=function(e,t){const{sourceMap:n,filename:r,breakLineCode:c,needIndent:o}=t,s=!1!==t.location,u={filename:r,code:"",column:1,line:1,offset:0,map:void 0,breakLineCode:c,needIndent:o,indentLevel:0};function a(e,t){u.code+=e}function i(e,t=!0){const n=t?c:"";a(o?n+" ".repeat(e):n)}return s&&e.loc&&(u.source=e.loc.source),{context:()=>u,push:a,indent:function(e=!0){const t=++u.indentLevel;e&&i(t)},deindent:function(e=!0){const t=--u.indentLevel;e&&i(t)},newline:function(){i(u.indentLevel)},helper:e=>`_${e}`,needIndent:()=>u.needIndent}}(e,{mode:n,filename:r,sourceMap:s,breakLineCode:u,needIndent:a});l.push("normal"===n?"function __msg__ (ctx) {":"(ctx) => {"),l.indent(a),i.length>0&&(l.push(`const { ${o(i.map((e=>`${e}: _${e}`)),", ")} } = ctx`),l.newline()),l.push("return "),v(l,e),l.deindent(a),l.push("}"),delete e.helpers;const{code:E,map:f}=l.context();return{ast:e,code:E,map:f?f.toJSON():void 0}})(i,n))},e.createCompileError=E,e.createCompileWarn=a,e.createLocation=n,e.createParser=O,e.createPosition=t,e.defaultOnError=function(e){throw e},e.detectHtmlTag=e=>f.test(e),e.errorMessages=l,e.warnMessages=u,e}({});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* message-compiler v9.
|
|
2
|
+
* message-compiler v9.12.0
|
|
3
3
|
* (c) 2024 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -20,6 +20,23 @@ function createLocation(start, end, source) {
|
|
|
20
20
|
return loc;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
const CompileWarnCodes = {
|
|
24
|
+
USE_MODULO_SYNTAX: 1,
|
|
25
|
+
__EXTEND_POINT__: 2
|
|
26
|
+
};
|
|
27
|
+
/** @internal */
|
|
28
|
+
const warnMessages = {
|
|
29
|
+
[CompileWarnCodes.USE_MODULO_SYNTAX]: `Use modulo before '{{0}}'.`
|
|
30
|
+
};
|
|
31
|
+
function createCompileWarn(code, loc, ...args) {
|
|
32
|
+
const msg = (process.env.NODE_ENV !== 'production') ? format(warnMessages[code] || '', ...(args || [])) : code;
|
|
33
|
+
const message = { message: String(msg), code };
|
|
34
|
+
if (loc) {
|
|
35
|
+
message.location = loc;
|
|
36
|
+
}
|
|
37
|
+
return message;
|
|
38
|
+
}
|
|
39
|
+
|
|
23
40
|
const CompileErrorCodes = {
|
|
24
41
|
// tokenizer error codes
|
|
25
42
|
EXPECTED_TOKEN: 1,
|
|
@@ -871,7 +888,7 @@ function fromEscapeSequence(match, codePoint4, codePoint6) {
|
|
|
871
888
|
}
|
|
872
889
|
function createParser(options = {}) {
|
|
873
890
|
const location = options.location !== false;
|
|
874
|
-
const { onError } = options;
|
|
891
|
+
const { onError, onWarn } = options;
|
|
875
892
|
function emitError(tokenzer, code, start, offset, ...args) {
|
|
876
893
|
const end = tokenzer.currentPosition();
|
|
877
894
|
end.offset += offset;
|
|
@@ -885,6 +902,15 @@ function createParser(options = {}) {
|
|
|
885
902
|
onError(err);
|
|
886
903
|
}
|
|
887
904
|
}
|
|
905
|
+
function emitWarn(tokenzer, code, start, offset, ...args) {
|
|
906
|
+
const end = tokenzer.currentPosition();
|
|
907
|
+
end.offset += offset;
|
|
908
|
+
end.column += offset;
|
|
909
|
+
if (onWarn) {
|
|
910
|
+
const loc = location ? createLocation(start, end) : null;
|
|
911
|
+
onWarn(createCompileWarn(code, loc, args));
|
|
912
|
+
}
|
|
913
|
+
}
|
|
888
914
|
function startNode(type, offset, loc) {
|
|
889
915
|
const node = { type };
|
|
890
916
|
if (location) {
|
|
@@ -921,11 +947,14 @@ function createParser(options = {}) {
|
|
|
921
947
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
922
948
|
return node;
|
|
923
949
|
}
|
|
924
|
-
function parseNamed(tokenizer, key) {
|
|
950
|
+
function parseNamed(tokenizer, key, modulo) {
|
|
925
951
|
const context = tokenizer.context();
|
|
926
952
|
const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
|
|
927
953
|
const node = startNode(4 /* NodeTypes.Named */, offset, loc);
|
|
928
954
|
node.key = key;
|
|
955
|
+
if (modulo === true) {
|
|
956
|
+
node.modulo = true;
|
|
957
|
+
}
|
|
929
958
|
tokenizer.nextToken(); // skip brach right
|
|
930
959
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
931
960
|
return node;
|
|
@@ -1045,6 +1074,7 @@ function createParser(options = {}) {
|
|
|
1045
1074
|
const node = startNode(2 /* NodeTypes.Message */, startOffset, startLoc);
|
|
1046
1075
|
node.items = [];
|
|
1047
1076
|
let nextToken = null;
|
|
1077
|
+
let modulo = null;
|
|
1048
1078
|
do {
|
|
1049
1079
|
const token = nextToken || tokenizer.nextToken();
|
|
1050
1080
|
nextToken = null;
|
|
@@ -1061,11 +1091,18 @@ function createParser(options = {}) {
|
|
|
1061
1091
|
}
|
|
1062
1092
|
node.items.push(parseList(tokenizer, token.value || ''));
|
|
1063
1093
|
break;
|
|
1094
|
+
case 4 /* TokenTypes.Modulo */:
|
|
1095
|
+
modulo = true;
|
|
1096
|
+
break;
|
|
1064
1097
|
case 5 /* TokenTypes.Named */:
|
|
1065
1098
|
if (token.value == null) {
|
|
1066
1099
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1067
1100
|
}
|
|
1068
|
-
node.items.push(parseNamed(tokenizer, token.value || ''));
|
|
1101
|
+
node.items.push(parseNamed(tokenizer, token.value || '', !!modulo));
|
|
1102
|
+
if (modulo) {
|
|
1103
|
+
emitWarn(tokenizer, CompileWarnCodes.USE_MODULO_SYNTAX, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1104
|
+
modulo = null;
|
|
1105
|
+
}
|
|
1069
1106
|
break;
|
|
1070
1107
|
case 7 /* TokenTypes.Literal */:
|
|
1071
1108
|
if (token.value == null) {
|
|
@@ -1546,4 +1583,4 @@ function baseCompile(source, options = {}) {
|
|
|
1546
1583
|
}
|
|
1547
1584
|
}
|
|
1548
1585
|
|
|
1549
|
-
export { CompileErrorCodes, ERROR_DOMAIN$2 as ERROR_DOMAIN, LOCATION_STUB, baseCompile, createCompileError, createLocation, createParser, createPosition, defaultOnError, detectHtmlTag, errorMessages };
|
|
1586
|
+
export { CompileErrorCodes, CompileWarnCodes, ERROR_DOMAIN$2 as ERROR_DOMAIN, LOCATION_STUB, baseCompile, createCompileError, createCompileWarn, createLocation, createParser, createPosition, defaultOnError, detectHtmlTag, errorMessages, warnMessages };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* message-compiler v9.
|
|
2
|
+
* message-compiler v9.12.0
|
|
3
3
|
* (c) 2024 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -21,6 +21,23 @@ 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
|
+
|
|
24
41
|
const CompileErrorCodes = {
|
|
25
42
|
// tokenizer error codes
|
|
26
43
|
EXPECTED_TOKEN: 1,
|
|
@@ -872,7 +889,7 @@ function fromEscapeSequence(match, codePoint4, codePoint6) {
|
|
|
872
889
|
}
|
|
873
890
|
function createParser(options = {}) {
|
|
874
891
|
const location = options.location !== false;
|
|
875
|
-
const { onError } = options;
|
|
892
|
+
const { onError, onWarn } = options;
|
|
876
893
|
function emitError(tokenzer, code, start, offset, ...args) {
|
|
877
894
|
const end = tokenzer.currentPosition();
|
|
878
895
|
end.offset += offset;
|
|
@@ -886,6 +903,15 @@ function createParser(options = {}) {
|
|
|
886
903
|
onError(err);
|
|
887
904
|
}
|
|
888
905
|
}
|
|
906
|
+
function emitWarn(tokenzer, code, start, offset, ...args) {
|
|
907
|
+
const end = tokenzer.currentPosition();
|
|
908
|
+
end.offset += offset;
|
|
909
|
+
end.column += offset;
|
|
910
|
+
if (onWarn) {
|
|
911
|
+
const loc = location ? createLocation(start, end) : null;
|
|
912
|
+
onWarn(createCompileWarn(code, loc, args));
|
|
913
|
+
}
|
|
914
|
+
}
|
|
889
915
|
function startNode(type, offset, loc) {
|
|
890
916
|
const node = { type };
|
|
891
917
|
if (location) {
|
|
@@ -922,11 +948,14 @@ function createParser(options = {}) {
|
|
|
922
948
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
923
949
|
return node;
|
|
924
950
|
}
|
|
925
|
-
function parseNamed(tokenizer, key) {
|
|
951
|
+
function parseNamed(tokenizer, key, modulo) {
|
|
926
952
|
const context = tokenizer.context();
|
|
927
953
|
const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
|
|
928
954
|
const node = startNode(4 /* NodeTypes.Named */, offset, loc);
|
|
929
955
|
node.key = key;
|
|
956
|
+
if (modulo === true) {
|
|
957
|
+
node.modulo = true;
|
|
958
|
+
}
|
|
930
959
|
tokenizer.nextToken(); // skip brach right
|
|
931
960
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
932
961
|
return node;
|
|
@@ -1046,6 +1075,7 @@ function createParser(options = {}) {
|
|
|
1046
1075
|
const node = startNode(2 /* NodeTypes.Message */, startOffset, startLoc);
|
|
1047
1076
|
node.items = [];
|
|
1048
1077
|
let nextToken = null;
|
|
1078
|
+
let modulo = null;
|
|
1049
1079
|
do {
|
|
1050
1080
|
const token = nextToken || tokenizer.nextToken();
|
|
1051
1081
|
nextToken = null;
|
|
@@ -1062,11 +1092,18 @@ function createParser(options = {}) {
|
|
|
1062
1092
|
}
|
|
1063
1093
|
node.items.push(parseList(tokenizer, token.value || ''));
|
|
1064
1094
|
break;
|
|
1095
|
+
case 4 /* TokenTypes.Modulo */:
|
|
1096
|
+
modulo = true;
|
|
1097
|
+
break;
|
|
1065
1098
|
case 5 /* TokenTypes.Named */:
|
|
1066
1099
|
if (token.value == null) {
|
|
1067
1100
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1068
1101
|
}
|
|
1069
|
-
node.items.push(parseNamed(tokenizer, token.value || ''));
|
|
1102
|
+
node.items.push(parseNamed(tokenizer, token.value || '', !!modulo));
|
|
1103
|
+
if (modulo) {
|
|
1104
|
+
emitWarn(tokenizer, CompileWarnCodes.USE_MODULO_SYNTAX, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1105
|
+
modulo = null;
|
|
1106
|
+
}
|
|
1070
1107
|
break;
|
|
1071
1108
|
case 7 /* TokenTypes.Literal */:
|
|
1072
1109
|
if (token.value == null) {
|
|
@@ -1603,4 +1640,4 @@ function baseCompile(source, options = {}) {
|
|
|
1603
1640
|
}
|
|
1604
1641
|
}
|
|
1605
1642
|
|
|
1606
|
-
export { CompileErrorCodes, ERROR_DOMAIN$2 as ERROR_DOMAIN, LOCATION_STUB, baseCompile, createCompileError, createLocation, createParser, createPosition, defaultOnError, detectHtmlTag, errorMessages };
|
|
1643
|
+
export { CompileErrorCodes, CompileWarnCodes, ERROR_DOMAIN$2 as ERROR_DOMAIN, LOCATION_STUB, baseCompile, createCompileError, createCompileWarn, createLocation, createParser, createPosition, defaultOnError, detectHtmlTag, errorMessages, warnMessages };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* message-compiler v9.
|
|
2
|
+
* message-compiler v9.12.0
|
|
3
3
|
* (c) 2024 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -23,6 +23,23 @@ 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 = code;
|
|
36
|
+
const message = { message: String(msg), code };
|
|
37
|
+
if (loc) {
|
|
38
|
+
message.location = loc;
|
|
39
|
+
}
|
|
40
|
+
return message;
|
|
41
|
+
}
|
|
42
|
+
|
|
26
43
|
const CompileErrorCodes = {
|
|
27
44
|
// tokenizer error codes
|
|
28
45
|
EXPECTED_TOKEN: 1,
|
|
@@ -872,7 +889,7 @@ function fromEscapeSequence(match, codePoint4, codePoint6) {
|
|
|
872
889
|
}
|
|
873
890
|
function createParser(options = {}) {
|
|
874
891
|
const location = options.location !== false;
|
|
875
|
-
const { onError } = options;
|
|
892
|
+
const { onError, onWarn } = options;
|
|
876
893
|
function emitError(tokenzer, code, start, offset, ...args) {
|
|
877
894
|
const end = tokenzer.currentPosition();
|
|
878
895
|
end.offset += offset;
|
|
@@ -886,6 +903,15 @@ function createParser(options = {}) {
|
|
|
886
903
|
onError(err);
|
|
887
904
|
}
|
|
888
905
|
}
|
|
906
|
+
function emitWarn(tokenzer, code, start, offset, ...args) {
|
|
907
|
+
const end = tokenzer.currentPosition();
|
|
908
|
+
end.offset += offset;
|
|
909
|
+
end.column += offset;
|
|
910
|
+
if (onWarn) {
|
|
911
|
+
const loc = location ? createLocation(start, end) : null;
|
|
912
|
+
onWarn(createCompileWarn(code, loc, args));
|
|
913
|
+
}
|
|
914
|
+
}
|
|
889
915
|
function startNode(type, offset, loc) {
|
|
890
916
|
const node = { type };
|
|
891
917
|
if (location) {
|
|
@@ -922,11 +948,14 @@ function createParser(options = {}) {
|
|
|
922
948
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
923
949
|
return node;
|
|
924
950
|
}
|
|
925
|
-
function parseNamed(tokenizer, key) {
|
|
951
|
+
function parseNamed(tokenizer, key, modulo) {
|
|
926
952
|
const context = tokenizer.context();
|
|
927
953
|
const { lastOffset: offset, lastStartLoc: loc } = context; // get brace left loc
|
|
928
954
|
const node = startNode(4 /* NodeTypes.Named */, offset, loc);
|
|
929
955
|
node.key = key;
|
|
956
|
+
if (modulo === true) {
|
|
957
|
+
node.modulo = true;
|
|
958
|
+
}
|
|
930
959
|
tokenizer.nextToken(); // skip brach right
|
|
931
960
|
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
932
961
|
return node;
|
|
@@ -1046,6 +1075,7 @@ function createParser(options = {}) {
|
|
|
1046
1075
|
const node = startNode(2 /* NodeTypes.Message */, startOffset, startLoc);
|
|
1047
1076
|
node.items = [];
|
|
1048
1077
|
let nextToken = null;
|
|
1078
|
+
let modulo = null;
|
|
1049
1079
|
do {
|
|
1050
1080
|
const token = nextToken || tokenizer.nextToken();
|
|
1051
1081
|
nextToken = null;
|
|
@@ -1062,11 +1092,18 @@ function createParser(options = {}) {
|
|
|
1062
1092
|
}
|
|
1063
1093
|
node.items.push(parseList(tokenizer, token.value || ''));
|
|
1064
1094
|
break;
|
|
1095
|
+
case 4 /* TokenTypes.Modulo */:
|
|
1096
|
+
modulo = true;
|
|
1097
|
+
break;
|
|
1065
1098
|
case 5 /* TokenTypes.Named */:
|
|
1066
1099
|
if (token.value == null) {
|
|
1067
1100
|
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1068
1101
|
}
|
|
1069
|
-
node.items.push(parseNamed(tokenizer, token.value || ''));
|
|
1102
|
+
node.items.push(parseNamed(tokenizer, token.value || '', !!modulo));
|
|
1103
|
+
if (modulo) {
|
|
1104
|
+
emitWarn(tokenizer, CompileWarnCodes.USE_MODULO_SYNTAX, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1105
|
+
modulo = null;
|
|
1106
|
+
}
|
|
1070
1107
|
break;
|
|
1071
1108
|
case 7 /* TokenTypes.Literal */:
|
|
1072
1109
|
if (token.value == null) {
|
|
@@ -1588,13 +1625,16 @@ function baseCompile(source, options = {}) {
|
|
|
1588
1625
|
}
|
|
1589
1626
|
|
|
1590
1627
|
exports.CompileErrorCodes = CompileErrorCodes;
|
|
1628
|
+
exports.CompileWarnCodes = CompileWarnCodes;
|
|
1591
1629
|
exports.ERROR_DOMAIN = ERROR_DOMAIN;
|
|
1592
1630
|
exports.LOCATION_STUB = LOCATION_STUB;
|
|
1593
1631
|
exports.baseCompile = baseCompile;
|
|
1594
1632
|
exports.createCompileError = createCompileError;
|
|
1633
|
+
exports.createCompileWarn = createCompileWarn;
|
|
1595
1634
|
exports.createLocation = createLocation;
|
|
1596
1635
|
exports.createParser = createParser;
|
|
1597
1636
|
exports.createPosition = createPosition;
|
|
1598
1637
|
exports.defaultOnError = defaultOnError;
|
|
1599
1638
|
exports.detectHtmlTag = detectHtmlTag;
|
|
1600
1639
|
exports.errorMessages = errorMessages;
|
|
1640
|
+
exports.warnMessages = warnMessages;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlify/message-compiler",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.12.0",
|
|
4
4
|
"description": "@intlify/message-compiler",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"types": "dist/message-compiler.d.ts",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"source-map-js": "^1.0.2",
|
|
37
|
-
"@intlify/shared": "9.
|
|
37
|
+
"@intlify/shared": "9.12.0"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">= 16"
|