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