@formatjs/icu-messageformat-parser 2.0.12

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.
Files changed (51) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +25 -0
  3. package/error.d.ts +69 -0
  4. package/error.d.ts.map +1 -0
  5. package/error.js +66 -0
  6. package/index.d.ts +5 -0
  7. package/index.d.ts.map +1 -0
  8. package/index.js +47 -0
  9. package/lib/error.d.ts +69 -0
  10. package/lib/error.d.ts.map +1 -0
  11. package/lib/error.js +63 -0
  12. package/lib/index.d.ts +5 -0
  13. package/lib/index.d.ts.map +1 -0
  14. package/lib/index.js +43 -0
  15. package/lib/manipulator.d.ts +14 -0
  16. package/lib/manipulator.d.ts.map +1 -0
  17. package/lib/manipulator.js +52 -0
  18. package/lib/no-parser.d.ts +3 -0
  19. package/lib/no-parser.d.ts.map +1 -0
  20. package/lib/no-parser.js +4 -0
  21. package/lib/parser.d.ts +143 -0
  22. package/lib/parser.d.ts.map +1 -0
  23. package/lib/parser.js +1267 -0
  24. package/lib/printer.d.ts +5 -0
  25. package/lib/printer.d.ts.map +1 -0
  26. package/lib/printer.js +91 -0
  27. package/lib/regex.generated.d.ts +3 -0
  28. package/lib/regex.generated.d.ts.map +1 -0
  29. package/lib/regex.generated.js +3 -0
  30. package/lib/types.d.ts +129 -0
  31. package/lib/types.d.ts.map +1 -0
  32. package/lib/types.js +94 -0
  33. package/manipulator.d.ts +14 -0
  34. package/manipulator.d.ts.map +1 -0
  35. package/manipulator.js +56 -0
  36. package/no-parser.d.ts +3 -0
  37. package/no-parser.d.ts.map +1 -0
  38. package/no-parser.js +9 -0
  39. package/package.json +13 -0
  40. package/parser.d.ts +143 -0
  41. package/parser.d.ts.map +1 -0
  42. package/parser.js +1270 -0
  43. package/printer.d.ts +5 -0
  44. package/printer.d.ts.map +1 -0
  45. package/printer.js +97 -0
  46. package/regex.generated.d.ts +3 -0
  47. package/regex.generated.d.ts.map +1 -0
  48. package/regex.generated.js +6 -0
  49. package/types.d.ts +129 -0
  50. package/types.d.ts.map +1 -0
  51. package/types.js +110 -0
package/parser.js ADDED
@@ -0,0 +1,1270 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Parser = void 0;
5
+ var tslib_1 = require("tslib");
6
+ var error_1 = require("./error");
7
+ var types_1 = require("./types");
8
+ var regex_generated_1 = require("./regex.generated");
9
+ var icu_skeleton_parser_1 = require("@formatjs/icu-skeleton-parser");
10
+ var SPACE_SEPARATOR_START_REGEX = new RegExp("^" + regex_generated_1.SPACE_SEPARATOR_REGEX.source + "*");
11
+ var SPACE_SEPARATOR_END_REGEX = new RegExp(regex_generated_1.SPACE_SEPARATOR_REGEX.source + "*$");
12
+ function createLocation(start, end) {
13
+ return { start: start, end: end };
14
+ }
15
+ // #region Ponyfills
16
+ // Consolidate these variables up top for easier toggling during debugging
17
+ var hasNativeStartsWith = !!String.prototype.startsWith;
18
+ var hasNativeFromCodePoint = !!String.fromCodePoint;
19
+ var hasNativeFromEntries = !!Object.fromEntries;
20
+ var hasNativeCodePointAt = !!String.prototype.codePointAt;
21
+ var hasTrimStart = !!String.prototype.trimStart;
22
+ var hasTrimEnd = !!String.prototype.trimEnd;
23
+ var hasNativeIsSafeInteger = !!Number.isSafeInteger;
24
+ var isSafeInteger = hasNativeIsSafeInteger
25
+ ? Number.isSafeInteger
26
+ : function (n) {
27
+ return (typeof n === 'number' &&
28
+ isFinite(n) &&
29
+ Math.floor(n) === n &&
30
+ Math.abs(n) <= 0x1fffffffffffff);
31
+ };
32
+ // IE11 does not support y and u.
33
+ var REGEX_SUPPORTS_U_AND_Y = true;
34
+ try {
35
+ var re = RE('([^\\p{White_Space}\\p{Pattern_Syntax}]*)', 'yu');
36
+ /**
37
+ * legacy Edge or Xbox One browser
38
+ * Unicode flag support: supported
39
+ * Pattern_Syntax support: not supported
40
+ * See https://github.com/formatjs/formatjs/issues/2822
41
+ */
42
+ REGEX_SUPPORTS_U_AND_Y = ((_a = re.exec('a')) === null || _a === void 0 ? void 0 : _a[0]) === 'a';
43
+ }
44
+ catch (_) {
45
+ REGEX_SUPPORTS_U_AND_Y = false;
46
+ }
47
+ var startsWith = hasNativeStartsWith
48
+ ? // Native
49
+ function startsWith(s, search, position) {
50
+ return s.startsWith(search, position);
51
+ }
52
+ : // For IE11
53
+ function startsWith(s, search, position) {
54
+ return s.slice(position, position + search.length) === search;
55
+ };
56
+ var fromCodePoint = hasNativeFromCodePoint
57
+ ? String.fromCodePoint
58
+ : // IE11
59
+ function fromCodePoint() {
60
+ var codePoints = [];
61
+ for (var _i = 0; _i < arguments.length; _i++) {
62
+ codePoints[_i] = arguments[_i];
63
+ }
64
+ var elements = '';
65
+ var length = codePoints.length;
66
+ var i = 0;
67
+ var code;
68
+ while (length > i) {
69
+ code = codePoints[i++];
70
+ if (code > 0x10ffff)
71
+ throw RangeError(code + ' is not a valid code point');
72
+ elements +=
73
+ code < 0x10000
74
+ ? String.fromCharCode(code)
75
+ : String.fromCharCode(((code -= 0x10000) >> 10) + 0xd800, (code % 0x400) + 0xdc00);
76
+ }
77
+ return elements;
78
+ };
79
+ var fromEntries =
80
+ // native
81
+ hasNativeFromEntries
82
+ ? Object.fromEntries
83
+ : // Ponyfill
84
+ function fromEntries(entries) {
85
+ var obj = {};
86
+ for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
87
+ var _a = entries_1[_i], k = _a[0], v = _a[1];
88
+ obj[k] = v;
89
+ }
90
+ return obj;
91
+ };
92
+ var codePointAt = hasNativeCodePointAt
93
+ ? // Native
94
+ function codePointAt(s, index) {
95
+ return s.codePointAt(index);
96
+ }
97
+ : // IE 11
98
+ function codePointAt(s, index) {
99
+ var size = s.length;
100
+ if (index < 0 || index >= size) {
101
+ return undefined;
102
+ }
103
+ var first = s.charCodeAt(index);
104
+ var second;
105
+ return first < 0xd800 ||
106
+ first > 0xdbff ||
107
+ index + 1 === size ||
108
+ (second = s.charCodeAt(index + 1)) < 0xdc00 ||
109
+ second > 0xdfff
110
+ ? first
111
+ : ((first - 0xd800) << 10) + (second - 0xdc00) + 0x10000;
112
+ };
113
+ var trimStart = hasTrimStart
114
+ ? // Native
115
+ function trimStart(s) {
116
+ return s.trimStart();
117
+ }
118
+ : // Ponyfill
119
+ function trimStart(s) {
120
+ return s.replace(SPACE_SEPARATOR_START_REGEX, '');
121
+ };
122
+ var trimEnd = hasTrimEnd
123
+ ? // Native
124
+ function trimEnd(s) {
125
+ return s.trimEnd();
126
+ }
127
+ : // Ponyfill
128
+ function trimEnd(s) {
129
+ return s.replace(SPACE_SEPARATOR_END_REGEX, '');
130
+ };
131
+ // Prevent minifier to translate new RegExp to literal form that might cause syntax error on IE11.
132
+ function RE(s, flag) {
133
+ return new RegExp(s, flag);
134
+ }
135
+ // #endregion
136
+ var matchIdentifierAtIndex;
137
+ if (REGEX_SUPPORTS_U_AND_Y) {
138
+ // Native
139
+ var IDENTIFIER_PREFIX_RE_1 = RE('([^\\p{White_Space}\\p{Pattern_Syntax}]*)', 'yu');
140
+ matchIdentifierAtIndex = function matchIdentifierAtIndex(s, index) {
141
+ var _a;
142
+ IDENTIFIER_PREFIX_RE_1.lastIndex = index;
143
+ var match = IDENTIFIER_PREFIX_RE_1.exec(s);
144
+ return (_a = match[1]) !== null && _a !== void 0 ? _a : '';
145
+ };
146
+ }
147
+ else {
148
+ // IE11
149
+ matchIdentifierAtIndex = function matchIdentifierAtIndex(s, index) {
150
+ var match = [];
151
+ while (true) {
152
+ var c = codePointAt(s, index);
153
+ if (c === undefined || _isWhiteSpace(c) || _isPatternSyntax(c)) {
154
+ break;
155
+ }
156
+ match.push(c);
157
+ index += c >= 0x10000 ? 2 : 1;
158
+ }
159
+ return fromCodePoint.apply(void 0, match);
160
+ };
161
+ }
162
+ var Parser = /** @class */ (function () {
163
+ function Parser(message, options) {
164
+ if (options === void 0) { options = {}; }
165
+ this.message = message;
166
+ this.position = { offset: 0, line: 1, column: 1 };
167
+ this.ignoreTag = !!options.ignoreTag;
168
+ this.requiresOtherClause = !!options.requiresOtherClause;
169
+ this.shouldParseSkeletons = !!options.shouldParseSkeletons;
170
+ }
171
+ Parser.prototype.parse = function () {
172
+ if (this.offset() !== 0) {
173
+ throw Error('parser can only be used once');
174
+ }
175
+ return this.parseMessage(0, '', false);
176
+ };
177
+ Parser.prototype.parseMessage = function (nestingLevel, parentArgType, expectingCloseTag) {
178
+ var elements = [];
179
+ while (!this.isEOF()) {
180
+ var char = this.char();
181
+ if (char === 123 /* `{` */) {
182
+ var result = this.parseArgument(nestingLevel, expectingCloseTag);
183
+ if (result.err) {
184
+ return result;
185
+ }
186
+ elements.push(result.val);
187
+ }
188
+ else if (char === 125 /* `}` */ && nestingLevel > 0) {
189
+ break;
190
+ }
191
+ else if (char === 35 /* `#` */ &&
192
+ (parentArgType === 'plural' || parentArgType === 'selectordinal')) {
193
+ var position = this.clonePosition();
194
+ this.bump();
195
+ elements.push({
196
+ type: types_1.TYPE.pound,
197
+ location: createLocation(position, this.clonePosition()),
198
+ });
199
+ }
200
+ else if (char === 60 /* `<` */ &&
201
+ !this.ignoreTag &&
202
+ this.peek() === 47 // char code for '/'
203
+ ) {
204
+ if (expectingCloseTag) {
205
+ break;
206
+ }
207
+ else {
208
+ return this.error(error_1.ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(this.clonePosition(), this.clonePosition()));
209
+ }
210
+ }
211
+ else if (char === 60 /* `<` */ &&
212
+ !this.ignoreTag &&
213
+ _isAlpha(this.peek() || 0)) {
214
+ var result = this.parseTag(nestingLevel, parentArgType);
215
+ if (result.err) {
216
+ return result;
217
+ }
218
+ elements.push(result.val);
219
+ }
220
+ else {
221
+ var result = this.parseLiteral(nestingLevel, parentArgType);
222
+ if (result.err) {
223
+ return result;
224
+ }
225
+ elements.push(result.val);
226
+ }
227
+ }
228
+ return { val: elements, err: null };
229
+ };
230
+ /**
231
+ * A tag name must start with an ASCII lower/upper case letter. The grammar is based on the
232
+ * [custom element name][] except that a dash is NOT always mandatory and uppercase letters
233
+ * are accepted:
234
+ *
235
+ * ```
236
+ * tag ::= "<" tagName (whitespace)* "/>" | "<" tagName (whitespace)* ">" message "</" tagName (whitespace)* ">"
237
+ * tagName ::= [a-z] (PENChar)*
238
+ * PENChar ::=
239
+ * "-" | "." | [0-9] | "_" | [a-z] | [A-Z] | #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] |
240
+ * [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] |
241
+ * [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
242
+ * ```
243
+ *
244
+ * [custom element name]: https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
245
+ * NOTE: We're a bit more lax here since HTML technically does not allow uppercase HTML element but we do
246
+ * since other tag-based engines like React allow it
247
+ */
248
+ Parser.prototype.parseTag = function (nestingLevel, parentArgType) {
249
+ var startPosition = this.clonePosition();
250
+ this.bump(); // `<`
251
+ var tagName = this.parseTagName();
252
+ this.bumpSpace();
253
+ if (this.bumpIf('/>')) {
254
+ // Self closing tag
255
+ return {
256
+ val: {
257
+ type: types_1.TYPE.literal,
258
+ value: "<" + tagName + "/>",
259
+ location: createLocation(startPosition, this.clonePosition()),
260
+ },
261
+ err: null,
262
+ };
263
+ }
264
+ else if (this.bumpIf('>')) {
265
+ var childrenResult = this.parseMessage(nestingLevel + 1, parentArgType, true);
266
+ if (childrenResult.err) {
267
+ return childrenResult;
268
+ }
269
+ var children = childrenResult.val;
270
+ // Expecting a close tag
271
+ var endTagStartPosition = this.clonePosition();
272
+ if (this.bumpIf('</')) {
273
+ if (this.isEOF() || !_isAlpha(this.char())) {
274
+ return this.error(error_1.ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition()));
275
+ }
276
+ var closingTagNameStartPosition = this.clonePosition();
277
+ var closingTagName = this.parseTagName();
278
+ if (tagName !== closingTagName) {
279
+ return this.error(error_1.ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(closingTagNameStartPosition, this.clonePosition()));
280
+ }
281
+ this.bumpSpace();
282
+ if (!this.bumpIf('>')) {
283
+ return this.error(error_1.ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition()));
284
+ }
285
+ return {
286
+ val: {
287
+ type: types_1.TYPE.tag,
288
+ value: tagName,
289
+ children: children,
290
+ location: createLocation(startPosition, this.clonePosition()),
291
+ },
292
+ err: null,
293
+ };
294
+ }
295
+ else {
296
+ return this.error(error_1.ErrorKind.UNCLOSED_TAG, createLocation(startPosition, this.clonePosition()));
297
+ }
298
+ }
299
+ else {
300
+ return this.error(error_1.ErrorKind.INVALID_TAG, createLocation(startPosition, this.clonePosition()));
301
+ }
302
+ };
303
+ /**
304
+ * This method assumes that the caller has peeked ahead for the first tag character.
305
+ */
306
+ Parser.prototype.parseTagName = function () {
307
+ var startOffset = this.offset();
308
+ this.bump(); // the first tag name character
309
+ while (!this.isEOF() && _isPotentialElementNameChar(this.char())) {
310
+ this.bump();
311
+ }
312
+ return this.message.slice(startOffset, this.offset());
313
+ };
314
+ Parser.prototype.parseLiteral = function (nestingLevel, parentArgType) {
315
+ var start = this.clonePosition();
316
+ var value = '';
317
+ while (true) {
318
+ var parseQuoteResult = this.tryParseQuote(parentArgType);
319
+ if (parseQuoteResult) {
320
+ value += parseQuoteResult;
321
+ continue;
322
+ }
323
+ var parseUnquotedResult = this.tryParseUnquoted(nestingLevel, parentArgType);
324
+ if (parseUnquotedResult) {
325
+ value += parseUnquotedResult;
326
+ continue;
327
+ }
328
+ var parseLeftAngleResult = this.tryParseLeftAngleBracket();
329
+ if (parseLeftAngleResult) {
330
+ value += parseLeftAngleResult;
331
+ continue;
332
+ }
333
+ break;
334
+ }
335
+ var location = createLocation(start, this.clonePosition());
336
+ return {
337
+ val: { type: types_1.TYPE.literal, value: value, location: location },
338
+ err: null,
339
+ };
340
+ };
341
+ Parser.prototype.tryParseLeftAngleBracket = function () {
342
+ if (!this.isEOF() &&
343
+ this.char() === 60 /* `<` */ &&
344
+ (this.ignoreTag ||
345
+ // If at the opening tag or closing tag position, bail.
346
+ !_isAlphaOrSlash(this.peek() || 0))) {
347
+ this.bump(); // `<`
348
+ return '<';
349
+ }
350
+ return null;
351
+ };
352
+ /**
353
+ * Starting with ICU 4.8, an ASCII apostrophe only starts quoted text if it immediately precedes
354
+ * a character that requires quoting (that is, "only where needed"), and works the same in
355
+ * nested messages as on the top level of the pattern. The new behavior is otherwise compatible.
356
+ */
357
+ Parser.prototype.tryParseQuote = function (parentArgType) {
358
+ if (this.isEOF() || this.char() !== 39 /* `'` */) {
359
+ return null;
360
+ }
361
+ // Parse escaped char following the apostrophe, or early return if there is no escaped char.
362
+ // Check if is valid escaped character
363
+ switch (this.peek()) {
364
+ case 39 /* `'` */:
365
+ // double quote, should return as a single quote.
366
+ this.bump();
367
+ this.bump();
368
+ return "'";
369
+ // '{', '<', '>', '}'
370
+ case 123:
371
+ case 60:
372
+ case 62:
373
+ case 125:
374
+ break;
375
+ case 35: // '#'
376
+ if (parentArgType === 'plural' || parentArgType === 'selectordinal') {
377
+ break;
378
+ }
379
+ return null;
380
+ default:
381
+ return null;
382
+ }
383
+ this.bump(); // apostrophe
384
+ var codePoints = [this.char()]; // escaped char
385
+ this.bump();
386
+ // read chars until the optional closing apostrophe is found
387
+ while (!this.isEOF()) {
388
+ var ch = this.char();
389
+ if (ch === 39 /* `'` */) {
390
+ if (this.peek() === 39 /* `'` */) {
391
+ codePoints.push(39);
392
+ // Bump one more time because we need to skip 2 characters.
393
+ this.bump();
394
+ }
395
+ else {
396
+ // Optional closing apostrophe.
397
+ this.bump();
398
+ break;
399
+ }
400
+ }
401
+ else {
402
+ codePoints.push(ch);
403
+ }
404
+ this.bump();
405
+ }
406
+ return fromCodePoint.apply(void 0, codePoints);
407
+ };
408
+ Parser.prototype.tryParseUnquoted = function (nestingLevel, parentArgType) {
409
+ if (this.isEOF()) {
410
+ return null;
411
+ }
412
+ var ch = this.char();
413
+ if (ch === 60 /* `<` */ ||
414
+ ch === 123 /* `{` */ ||
415
+ (ch === 35 /* `#` */ &&
416
+ (parentArgType === 'plural' || parentArgType === 'selectordinal')) ||
417
+ (ch === 125 /* `}` */ && nestingLevel > 0)) {
418
+ return null;
419
+ }
420
+ else {
421
+ this.bump();
422
+ return fromCodePoint(ch);
423
+ }
424
+ };
425
+ Parser.prototype.parseArgument = function (nestingLevel, expectingCloseTag) {
426
+ var openingBracePosition = this.clonePosition();
427
+ this.bump(); // `{`
428
+ this.bumpSpace();
429
+ if (this.isEOF()) {
430
+ return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
431
+ }
432
+ if (this.char() === 125 /* `}` */) {
433
+ this.bump();
434
+ return this.error(error_1.ErrorKind.EMPTY_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
435
+ }
436
+ // argument name
437
+ var value = this.parseIdentifierIfPossible().value;
438
+ if (!value) {
439
+ return this.error(error_1.ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
440
+ }
441
+ this.bumpSpace();
442
+ if (this.isEOF()) {
443
+ return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
444
+ }
445
+ switch (this.char()) {
446
+ // Simple argument: `{name}`
447
+ case 125 /* `}` */: {
448
+ this.bump(); // `}`
449
+ return {
450
+ val: {
451
+ type: types_1.TYPE.argument,
452
+ // value does not include the opening and closing braces.
453
+ value: value,
454
+ location: createLocation(openingBracePosition, this.clonePosition()),
455
+ },
456
+ err: null,
457
+ };
458
+ }
459
+ // Argument with options: `{name, format, ...}`
460
+ case 44 /* `,` */: {
461
+ this.bump(); // `,`
462
+ this.bumpSpace();
463
+ if (this.isEOF()) {
464
+ return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
465
+ }
466
+ return this.parseArgumentOptions(nestingLevel, expectingCloseTag, value, openingBracePosition);
467
+ }
468
+ default:
469
+ return this.error(error_1.ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
470
+ }
471
+ };
472
+ /**
473
+ * Advance the parser until the end of the identifier, if it is currently on
474
+ * an identifier character. Return an empty string otherwise.
475
+ */
476
+ Parser.prototype.parseIdentifierIfPossible = function () {
477
+ var startingPosition = this.clonePosition();
478
+ var startOffset = this.offset();
479
+ var value = matchIdentifierAtIndex(this.message, startOffset);
480
+ var endOffset = startOffset + value.length;
481
+ this.bumpTo(endOffset);
482
+ var endPosition = this.clonePosition();
483
+ var location = createLocation(startingPosition, endPosition);
484
+ return { value: value, location: location };
485
+ };
486
+ Parser.prototype.parseArgumentOptions = function (nestingLevel, expectingCloseTag, value, openingBracePosition) {
487
+ var _a;
488
+ // Parse this range:
489
+ // {name, type, style}
490
+ // ^---^
491
+ var typeStartPosition = this.clonePosition();
492
+ var argType = this.parseIdentifierIfPossible().value;
493
+ var typeEndPosition = this.clonePosition();
494
+ switch (argType) {
495
+ case '':
496
+ // Expecting a style string number, date, time, plural, selectordinal, or select.
497
+ return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition));
498
+ case 'number':
499
+ case 'date':
500
+ case 'time': {
501
+ // Parse this range:
502
+ // {name, number, style}
503
+ // ^-------^
504
+ this.bumpSpace();
505
+ var styleAndLocation = null;
506
+ if (this.bumpIf(',')) {
507
+ this.bumpSpace();
508
+ var styleStartPosition = this.clonePosition();
509
+ var result = this.parseSimpleArgStyleIfPossible();
510
+ if (result.err) {
511
+ return result;
512
+ }
513
+ var style = trimEnd(result.val);
514
+ if (style.length === 0) {
515
+ return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_STYLE, createLocation(this.clonePosition(), this.clonePosition()));
516
+ }
517
+ var styleLocation = createLocation(styleStartPosition, this.clonePosition());
518
+ styleAndLocation = { style: style, styleLocation: styleLocation };
519
+ }
520
+ var argCloseResult = this.tryParseArgumentClose(openingBracePosition);
521
+ if (argCloseResult.err) {
522
+ return argCloseResult;
523
+ }
524
+ var location_1 = createLocation(openingBracePosition, this.clonePosition());
525
+ // Extract style or skeleton
526
+ if (styleAndLocation && startsWith(styleAndLocation === null || styleAndLocation === void 0 ? void 0 : styleAndLocation.style, '::', 0)) {
527
+ // Skeleton starts with `::`.
528
+ var skeleton = trimStart(styleAndLocation.style.slice(2));
529
+ if (argType === 'number') {
530
+ var result = this.parseNumberSkeletonFromString(skeleton, styleAndLocation.styleLocation);
531
+ if (result.err) {
532
+ return result;
533
+ }
534
+ return {
535
+ val: { type: types_1.TYPE.number, value: value, location: location_1, style: result.val },
536
+ err: null,
537
+ };
538
+ }
539
+ else {
540
+ if (skeleton.length === 0) {
541
+ return this.error(error_1.ErrorKind.EXPECT_DATE_TIME_SKELETON, location_1);
542
+ }
543
+ var style = {
544
+ type: types_1.SKELETON_TYPE.dateTime,
545
+ pattern: skeleton,
546
+ location: styleAndLocation.styleLocation,
547
+ parsedOptions: this.shouldParseSkeletons
548
+ ? icu_skeleton_parser_1.parseDateTimeSkeleton(skeleton)
549
+ : {},
550
+ };
551
+ var type = argType === 'date' ? types_1.TYPE.date : types_1.TYPE.time;
552
+ return {
553
+ val: { type: type, value: value, location: location_1, style: style },
554
+ err: null,
555
+ };
556
+ }
557
+ }
558
+ // Regular style or no style.
559
+ return {
560
+ val: {
561
+ type: argType === 'number'
562
+ ? types_1.TYPE.number
563
+ : argType === 'date'
564
+ ? types_1.TYPE.date
565
+ : types_1.TYPE.time,
566
+ value: value,
567
+ location: location_1,
568
+ style: (_a = styleAndLocation === null || styleAndLocation === void 0 ? void 0 : styleAndLocation.style) !== null && _a !== void 0 ? _a : null,
569
+ },
570
+ err: null,
571
+ };
572
+ }
573
+ case 'plural':
574
+ case 'selectordinal':
575
+ case 'select': {
576
+ // Parse this range:
577
+ // {name, plural, options}
578
+ // ^---------^
579
+ var typeEndPosition_1 = this.clonePosition();
580
+ this.bumpSpace();
581
+ if (!this.bumpIf(',')) {
582
+ return this.error(error_1.ErrorKind.EXPECT_SELECT_ARGUMENT_OPTIONS, createLocation(typeEndPosition_1, tslib_1.__assign({}, typeEndPosition_1)));
583
+ }
584
+ this.bumpSpace();
585
+ // Parse offset:
586
+ // {name, plural, offset:1, options}
587
+ // ^-----^
588
+ //
589
+ // or the first option:
590
+ //
591
+ // {name, plural, one {...} other {...}}
592
+ // ^--^
593
+ var identifierAndLocation = this.parseIdentifierIfPossible();
594
+ var pluralOffset = 0;
595
+ if (argType !== 'select' && identifierAndLocation.value === 'offset') {
596
+ if (!this.bumpIf(':')) {
597
+ return this.error(error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, createLocation(this.clonePosition(), this.clonePosition()));
598
+ }
599
+ this.bumpSpace();
600
+ var result = this.tryParseDecimalInteger(error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, error_1.ErrorKind.INVALID_PLURAL_ARGUMENT_OFFSET_VALUE);
601
+ if (result.err) {
602
+ return result;
603
+ }
604
+ // Parse another identifier for option parsing
605
+ this.bumpSpace();
606
+ identifierAndLocation = this.parseIdentifierIfPossible();
607
+ pluralOffset = result.val;
608
+ }
609
+ var optionsResult = this.tryParsePluralOrSelectOptions(nestingLevel, argType, expectingCloseTag, identifierAndLocation);
610
+ if (optionsResult.err) {
611
+ return optionsResult;
612
+ }
613
+ var argCloseResult = this.tryParseArgumentClose(openingBracePosition);
614
+ if (argCloseResult.err) {
615
+ return argCloseResult;
616
+ }
617
+ var location_2 = createLocation(openingBracePosition, this.clonePosition());
618
+ if (argType === 'select') {
619
+ return {
620
+ val: {
621
+ type: types_1.TYPE.select,
622
+ value: value,
623
+ options: fromEntries(optionsResult.val),
624
+ location: location_2,
625
+ },
626
+ err: null,
627
+ };
628
+ }
629
+ else {
630
+ return {
631
+ val: {
632
+ type: types_1.TYPE.plural,
633
+ value: value,
634
+ options: fromEntries(optionsResult.val),
635
+ offset: pluralOffset,
636
+ pluralType: argType === 'plural' ? 'cardinal' : 'ordinal',
637
+ location: location_2,
638
+ },
639
+ err: null,
640
+ };
641
+ }
642
+ }
643
+ default:
644
+ return this.error(error_1.ErrorKind.INVALID_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition));
645
+ }
646
+ };
647
+ Parser.prototype.tryParseArgumentClose = function (openingBracePosition) {
648
+ // Parse: {value, number, ::currency/GBP }
649
+ //
650
+ if (this.isEOF() || this.char() !== 125 /* `}` */) {
651
+ return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
652
+ }
653
+ this.bump(); // `}`
654
+ return { val: true, err: null };
655
+ };
656
+ /**
657
+ * See: https://github.com/unicode-org/icu/blob/af7ed1f6d2298013dc303628438ec4abe1f16479/icu4c/source/common/messagepattern.cpp#L659
658
+ */
659
+ Parser.prototype.parseSimpleArgStyleIfPossible = function () {
660
+ var nestedBraces = 0;
661
+ var startPosition = this.clonePosition();
662
+ while (!this.isEOF()) {
663
+ var ch = this.char();
664
+ switch (ch) {
665
+ case 39 /* `'` */: {
666
+ // Treat apostrophe as quoting but include it in the style part.
667
+ // Find the end of the quoted literal text.
668
+ this.bump();
669
+ var apostrophePosition = this.clonePosition();
670
+ if (!this.bumpUntil("'")) {
671
+ return this.error(error_1.ErrorKind.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE, createLocation(apostrophePosition, this.clonePosition()));
672
+ }
673
+ this.bump();
674
+ break;
675
+ }
676
+ case 123 /* `{` */: {
677
+ nestedBraces += 1;
678
+ this.bump();
679
+ break;
680
+ }
681
+ case 125 /* `}` */: {
682
+ if (nestedBraces > 0) {
683
+ nestedBraces -= 1;
684
+ }
685
+ else {
686
+ return {
687
+ val: this.message.slice(startPosition.offset, this.offset()),
688
+ err: null,
689
+ };
690
+ }
691
+ break;
692
+ }
693
+ default:
694
+ this.bump();
695
+ break;
696
+ }
697
+ }
698
+ return {
699
+ val: this.message.slice(startPosition.offset, this.offset()),
700
+ err: null,
701
+ };
702
+ };
703
+ Parser.prototype.parseNumberSkeletonFromString = function (skeleton, location) {
704
+ var tokens = [];
705
+ try {
706
+ tokens = icu_skeleton_parser_1.parseNumberSkeletonFromString(skeleton);
707
+ }
708
+ catch (e) {
709
+ return this.error(error_1.ErrorKind.INVALID_NUMBER_SKELETON, location);
710
+ }
711
+ return {
712
+ val: {
713
+ type: types_1.SKELETON_TYPE.number,
714
+ tokens: tokens,
715
+ location: location,
716
+ parsedOptions: this.shouldParseSkeletons
717
+ ? icu_skeleton_parser_1.parseNumberSkeleton(tokens)
718
+ : {},
719
+ },
720
+ err: null,
721
+ };
722
+ };
723
+ /**
724
+ * @param nesting_level The current nesting level of messages.
725
+ * This can be positive when parsing message fragment in select or plural argument options.
726
+ * @param parent_arg_type The parent argument's type.
727
+ * @param parsed_first_identifier If provided, this is the first identifier-like selector of
728
+ * the argument. It is a by-product of a previous parsing attempt.
729
+ * @param expecting_close_tag If true, this message is directly or indirectly nested inside
730
+ * between a pair of opening and closing tags. The nested message will not parse beyond
731
+ * the closing tag boundary.
732
+ */
733
+ Parser.prototype.tryParsePluralOrSelectOptions = function (nestingLevel, parentArgType, expectCloseTag, parsedFirstIdentifier) {
734
+ var _a;
735
+ var hasOtherClause = false;
736
+ var options = [];
737
+ var parsedSelectors = new Set();
738
+ var selector = parsedFirstIdentifier.value, selectorLocation = parsedFirstIdentifier.location;
739
+ // Parse:
740
+ // one {one apple}
741
+ // ^--^
742
+ while (true) {
743
+ if (selector.length === 0) {
744
+ var startPosition = this.clonePosition();
745
+ if (parentArgType !== 'select' && this.bumpIf('=')) {
746
+ // Try parse `={number}` selector
747
+ var result = this.tryParseDecimalInteger(error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, error_1.ErrorKind.INVALID_PLURAL_ARGUMENT_SELECTOR);
748
+ if (result.err) {
749
+ return result;
750
+ }
751
+ selectorLocation = createLocation(startPosition, this.clonePosition());
752
+ selector = this.message.slice(startPosition.offset, this.offset());
753
+ }
754
+ else {
755
+ break;
756
+ }
757
+ }
758
+ // Duplicate selector clauses
759
+ if (parsedSelectors.has(selector)) {
760
+ return this.error(parentArgType === 'select'
761
+ ? error_1.ErrorKind.DUPLICATE_SELECT_ARGUMENT_SELECTOR
762
+ : error_1.ErrorKind.DUPLICATE_PLURAL_ARGUMENT_SELECTOR, selectorLocation);
763
+ }
764
+ if (selector === 'other') {
765
+ hasOtherClause = true;
766
+ }
767
+ // Parse:
768
+ // one {one apple}
769
+ // ^----------^
770
+ this.bumpSpace();
771
+ var openingBracePosition = this.clonePosition();
772
+ if (!this.bumpIf('{')) {
773
+ return this.error(parentArgType === 'select'
774
+ ? error_1.ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT
775
+ : error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT, createLocation(this.clonePosition(), this.clonePosition()));
776
+ }
777
+ var fragmentResult = this.parseMessage(nestingLevel + 1, parentArgType, expectCloseTag);
778
+ if (fragmentResult.err) {
779
+ return fragmentResult;
780
+ }
781
+ var argCloseResult = this.tryParseArgumentClose(openingBracePosition);
782
+ if (argCloseResult.err) {
783
+ return argCloseResult;
784
+ }
785
+ options.push([
786
+ selector,
787
+ {
788
+ value: fragmentResult.val,
789
+ location: createLocation(openingBracePosition, this.clonePosition()),
790
+ },
791
+ ]);
792
+ // Keep track of the existing selectors
793
+ parsedSelectors.add(selector);
794
+ // Prep next selector clause.
795
+ this.bumpSpace();
796
+ (_a = this.parseIdentifierIfPossible(), selector = _a.value, selectorLocation = _a.location);
797
+ }
798
+ if (options.length === 0) {
799
+ return this.error(parentArgType === 'select'
800
+ ? error_1.ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR
801
+ : error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, createLocation(this.clonePosition(), this.clonePosition()));
802
+ }
803
+ if (this.requiresOtherClause && !hasOtherClause) {
804
+ return this.error(error_1.ErrorKind.MISSING_OTHER_CLAUSE, createLocation(this.clonePosition(), this.clonePosition()));
805
+ }
806
+ return { val: options, err: null };
807
+ };
808
+ Parser.prototype.tryParseDecimalInteger = function (expectNumberError, invalidNumberError) {
809
+ var sign = 1;
810
+ var startingPosition = this.clonePosition();
811
+ if (this.bumpIf('+')) {
812
+ }
813
+ else if (this.bumpIf('-')) {
814
+ sign = -1;
815
+ }
816
+ var hasDigits = false;
817
+ var decimal = 0;
818
+ while (!this.isEOF()) {
819
+ var ch = this.char();
820
+ if (ch >= 48 /* `0` */ && ch <= 57 /* `9` */) {
821
+ hasDigits = true;
822
+ decimal = decimal * 10 + (ch - 48);
823
+ this.bump();
824
+ }
825
+ else {
826
+ break;
827
+ }
828
+ }
829
+ var location = createLocation(startingPosition, this.clonePosition());
830
+ if (!hasDigits) {
831
+ return this.error(expectNumberError, location);
832
+ }
833
+ decimal *= sign;
834
+ if (!isSafeInteger(decimal)) {
835
+ return this.error(invalidNumberError, location);
836
+ }
837
+ return { val: decimal, err: null };
838
+ };
839
+ Parser.prototype.offset = function () {
840
+ return this.position.offset;
841
+ };
842
+ Parser.prototype.isEOF = function () {
843
+ return this.offset() === this.message.length;
844
+ };
845
+ Parser.prototype.clonePosition = function () {
846
+ // This is much faster than `Object.assign` or spread.
847
+ return {
848
+ offset: this.position.offset,
849
+ line: this.position.line,
850
+ column: this.position.column,
851
+ };
852
+ };
853
+ /**
854
+ * Return the code point at the current position of the parser.
855
+ * Throws if the index is out of bound.
856
+ */
857
+ Parser.prototype.char = function () {
858
+ var offset = this.position.offset;
859
+ if (offset >= this.message.length) {
860
+ throw Error('out of bound');
861
+ }
862
+ var code = codePointAt(this.message, offset);
863
+ if (code === undefined) {
864
+ throw Error("Offset " + offset + " is at invalid UTF-16 code unit boundary");
865
+ }
866
+ return code;
867
+ };
868
+ Parser.prototype.error = function (kind, location) {
869
+ return {
870
+ val: null,
871
+ err: {
872
+ kind: kind,
873
+ message: this.message,
874
+ location: location,
875
+ },
876
+ };
877
+ };
878
+ /** Bump the parser to the next UTF-16 code unit. */
879
+ Parser.prototype.bump = function () {
880
+ if (this.isEOF()) {
881
+ return;
882
+ }
883
+ var code = this.char();
884
+ if (code === 10 /* '\n' */) {
885
+ this.position.line += 1;
886
+ this.position.column = 1;
887
+ this.position.offset += 1;
888
+ }
889
+ else {
890
+ this.position.column += 1;
891
+ // 0 ~ 0x10000 -> unicode BMP, otherwise skip the surrogate pair.
892
+ this.position.offset += code < 0x10000 ? 1 : 2;
893
+ }
894
+ };
895
+ /**
896
+ * If the substring starting at the current position of the parser has
897
+ * the given prefix, then bump the parser to the character immediately
898
+ * following the prefix and return true. Otherwise, don't bump the parser
899
+ * and return false.
900
+ */
901
+ Parser.prototype.bumpIf = function (prefix) {
902
+ if (startsWith(this.message, prefix, this.offset())) {
903
+ for (var i = 0; i < prefix.length; i++) {
904
+ this.bump();
905
+ }
906
+ return true;
907
+ }
908
+ return false;
909
+ };
910
+ /**
911
+ * Bump the parser until the pattern character is found and return `true`.
912
+ * Otherwise bump to the end of the file and return `false`.
913
+ */
914
+ Parser.prototype.bumpUntil = function (pattern) {
915
+ var currentOffset = this.offset();
916
+ var index = this.message.indexOf(pattern, currentOffset);
917
+ if (index >= 0) {
918
+ this.bumpTo(index);
919
+ return true;
920
+ }
921
+ else {
922
+ this.bumpTo(this.message.length);
923
+ return false;
924
+ }
925
+ };
926
+ /**
927
+ * Bump the parser to the target offset.
928
+ * If target offset is beyond the end of the input, bump the parser to the end of the input.
929
+ */
930
+ Parser.prototype.bumpTo = function (targetOffset) {
931
+ if (this.offset() > targetOffset) {
932
+ throw Error("targetOffset " + targetOffset + " must be greater than or equal to the current offset " + this.offset());
933
+ }
934
+ targetOffset = Math.min(targetOffset, this.message.length);
935
+ while (true) {
936
+ var offset = this.offset();
937
+ if (offset === targetOffset) {
938
+ break;
939
+ }
940
+ if (offset > targetOffset) {
941
+ throw Error("targetOffset " + targetOffset + " is at invalid UTF-16 code unit boundary");
942
+ }
943
+ this.bump();
944
+ if (this.isEOF()) {
945
+ break;
946
+ }
947
+ }
948
+ };
949
+ /** advance the parser through all whitespace to the next non-whitespace code unit. */
950
+ Parser.prototype.bumpSpace = function () {
951
+ while (!this.isEOF() && _isWhiteSpace(this.char())) {
952
+ this.bump();
953
+ }
954
+ };
955
+ /**
956
+ * Peek at the *next* Unicode codepoint in the input without advancing the parser.
957
+ * If the input has been exhausted, then this returns null.
958
+ */
959
+ Parser.prototype.peek = function () {
960
+ if (this.isEOF()) {
961
+ return null;
962
+ }
963
+ var code = this.char();
964
+ var offset = this.offset();
965
+ var nextCode = this.message.charCodeAt(offset + (code >= 0x10000 ? 2 : 1));
966
+ return nextCode !== null && nextCode !== void 0 ? nextCode : null;
967
+ };
968
+ return Parser;
969
+ }());
970
+ exports.Parser = Parser;
971
+ /**
972
+ * This check if codepoint is alphabet (lower & uppercase)
973
+ * @param codepoint
974
+ * @returns
975
+ */
976
+ function _isAlpha(codepoint) {
977
+ return ((codepoint >= 97 && codepoint <= 122) ||
978
+ (codepoint >= 65 && codepoint <= 90));
979
+ }
980
+ function _isAlphaOrSlash(codepoint) {
981
+ return _isAlpha(codepoint) || codepoint === 47; /* '/' */
982
+ }
983
+ /** See `parseTag` function docs. */
984
+ function _isPotentialElementNameChar(c) {
985
+ return (c === 45 /* '-' */ ||
986
+ c === 46 /* '.' */ ||
987
+ (c >= 48 && c <= 57) /* 0..9 */ ||
988
+ c === 95 /* '_' */ ||
989
+ (c >= 97 && c <= 122) /** a..z */ ||
990
+ (c >= 65 && c <= 90) /* A..Z */ ||
991
+ c == 0xb7 ||
992
+ (c >= 0xc0 && c <= 0xd6) ||
993
+ (c >= 0xd8 && c <= 0xf6) ||
994
+ (c >= 0xf8 && c <= 0x37d) ||
995
+ (c >= 0x37f && c <= 0x1fff) ||
996
+ (c >= 0x200c && c <= 0x200d) ||
997
+ (c >= 0x203f && c <= 0x2040) ||
998
+ (c >= 0x2070 && c <= 0x218f) ||
999
+ (c >= 0x2c00 && c <= 0x2fef) ||
1000
+ (c >= 0x3001 && c <= 0xd7ff) ||
1001
+ (c >= 0xf900 && c <= 0xfdcf) ||
1002
+ (c >= 0xfdf0 && c <= 0xfffd) ||
1003
+ (c >= 0x10000 && c <= 0xeffff));
1004
+ }
1005
+ /**
1006
+ * Code point equivalent of regex `\p{White_Space}`.
1007
+ * From: https://www.unicode.org/Public/UCD/latest/ucd/PropList.txt
1008
+ */
1009
+ function _isWhiteSpace(c) {
1010
+ return ((c >= 0x0009 && c <= 0x000d) ||
1011
+ c === 0x0020 ||
1012
+ c === 0x0085 ||
1013
+ (c >= 0x200e && c <= 0x200f) ||
1014
+ c === 0x2028 ||
1015
+ c === 0x2029);
1016
+ }
1017
+ /**
1018
+ * Code point equivalent of regex `\p{Pattern_Syntax}`.
1019
+ * See https://www.unicode.org/Public/UCD/latest/ucd/PropList.txt
1020
+ */
1021
+ function _isPatternSyntax(c) {
1022
+ return ((c >= 0x0021 && c <= 0x0023) ||
1023
+ c === 0x0024 ||
1024
+ (c >= 0x0025 && c <= 0x0027) ||
1025
+ c === 0x0028 ||
1026
+ c === 0x0029 ||
1027
+ c === 0x002a ||
1028
+ c === 0x002b ||
1029
+ c === 0x002c ||
1030
+ c === 0x002d ||
1031
+ (c >= 0x002e && c <= 0x002f) ||
1032
+ (c >= 0x003a && c <= 0x003b) ||
1033
+ (c >= 0x003c && c <= 0x003e) ||
1034
+ (c >= 0x003f && c <= 0x0040) ||
1035
+ c === 0x005b ||
1036
+ c === 0x005c ||
1037
+ c === 0x005d ||
1038
+ c === 0x005e ||
1039
+ c === 0x0060 ||
1040
+ c === 0x007b ||
1041
+ c === 0x007c ||
1042
+ c === 0x007d ||
1043
+ c === 0x007e ||
1044
+ c === 0x00a1 ||
1045
+ (c >= 0x00a2 && c <= 0x00a5) ||
1046
+ c === 0x00a6 ||
1047
+ c === 0x00a7 ||
1048
+ c === 0x00a9 ||
1049
+ c === 0x00ab ||
1050
+ c === 0x00ac ||
1051
+ c === 0x00ae ||
1052
+ c === 0x00b0 ||
1053
+ c === 0x00b1 ||
1054
+ c === 0x00b6 ||
1055
+ c === 0x00bb ||
1056
+ c === 0x00bf ||
1057
+ c === 0x00d7 ||
1058
+ c === 0x00f7 ||
1059
+ (c >= 0x2010 && c <= 0x2015) ||
1060
+ (c >= 0x2016 && c <= 0x2017) ||
1061
+ c === 0x2018 ||
1062
+ c === 0x2019 ||
1063
+ c === 0x201a ||
1064
+ (c >= 0x201b && c <= 0x201c) ||
1065
+ c === 0x201d ||
1066
+ c === 0x201e ||
1067
+ c === 0x201f ||
1068
+ (c >= 0x2020 && c <= 0x2027) ||
1069
+ (c >= 0x2030 && c <= 0x2038) ||
1070
+ c === 0x2039 ||
1071
+ c === 0x203a ||
1072
+ (c >= 0x203b && c <= 0x203e) ||
1073
+ (c >= 0x2041 && c <= 0x2043) ||
1074
+ c === 0x2044 ||
1075
+ c === 0x2045 ||
1076
+ c === 0x2046 ||
1077
+ (c >= 0x2047 && c <= 0x2051) ||
1078
+ c === 0x2052 ||
1079
+ c === 0x2053 ||
1080
+ (c >= 0x2055 && c <= 0x205e) ||
1081
+ (c >= 0x2190 && c <= 0x2194) ||
1082
+ (c >= 0x2195 && c <= 0x2199) ||
1083
+ (c >= 0x219a && c <= 0x219b) ||
1084
+ (c >= 0x219c && c <= 0x219f) ||
1085
+ c === 0x21a0 ||
1086
+ (c >= 0x21a1 && c <= 0x21a2) ||
1087
+ c === 0x21a3 ||
1088
+ (c >= 0x21a4 && c <= 0x21a5) ||
1089
+ c === 0x21a6 ||
1090
+ (c >= 0x21a7 && c <= 0x21ad) ||
1091
+ c === 0x21ae ||
1092
+ (c >= 0x21af && c <= 0x21cd) ||
1093
+ (c >= 0x21ce && c <= 0x21cf) ||
1094
+ (c >= 0x21d0 && c <= 0x21d1) ||
1095
+ c === 0x21d2 ||
1096
+ c === 0x21d3 ||
1097
+ c === 0x21d4 ||
1098
+ (c >= 0x21d5 && c <= 0x21f3) ||
1099
+ (c >= 0x21f4 && c <= 0x22ff) ||
1100
+ (c >= 0x2300 && c <= 0x2307) ||
1101
+ c === 0x2308 ||
1102
+ c === 0x2309 ||
1103
+ c === 0x230a ||
1104
+ c === 0x230b ||
1105
+ (c >= 0x230c && c <= 0x231f) ||
1106
+ (c >= 0x2320 && c <= 0x2321) ||
1107
+ (c >= 0x2322 && c <= 0x2328) ||
1108
+ c === 0x2329 ||
1109
+ c === 0x232a ||
1110
+ (c >= 0x232b && c <= 0x237b) ||
1111
+ c === 0x237c ||
1112
+ (c >= 0x237d && c <= 0x239a) ||
1113
+ (c >= 0x239b && c <= 0x23b3) ||
1114
+ (c >= 0x23b4 && c <= 0x23db) ||
1115
+ (c >= 0x23dc && c <= 0x23e1) ||
1116
+ (c >= 0x23e2 && c <= 0x2426) ||
1117
+ (c >= 0x2427 && c <= 0x243f) ||
1118
+ (c >= 0x2440 && c <= 0x244a) ||
1119
+ (c >= 0x244b && c <= 0x245f) ||
1120
+ (c >= 0x2500 && c <= 0x25b6) ||
1121
+ c === 0x25b7 ||
1122
+ (c >= 0x25b8 && c <= 0x25c0) ||
1123
+ c === 0x25c1 ||
1124
+ (c >= 0x25c2 && c <= 0x25f7) ||
1125
+ (c >= 0x25f8 && c <= 0x25ff) ||
1126
+ (c >= 0x2600 && c <= 0x266e) ||
1127
+ c === 0x266f ||
1128
+ (c >= 0x2670 && c <= 0x2767) ||
1129
+ c === 0x2768 ||
1130
+ c === 0x2769 ||
1131
+ c === 0x276a ||
1132
+ c === 0x276b ||
1133
+ c === 0x276c ||
1134
+ c === 0x276d ||
1135
+ c === 0x276e ||
1136
+ c === 0x276f ||
1137
+ c === 0x2770 ||
1138
+ c === 0x2771 ||
1139
+ c === 0x2772 ||
1140
+ c === 0x2773 ||
1141
+ c === 0x2774 ||
1142
+ c === 0x2775 ||
1143
+ (c >= 0x2794 && c <= 0x27bf) ||
1144
+ (c >= 0x27c0 && c <= 0x27c4) ||
1145
+ c === 0x27c5 ||
1146
+ c === 0x27c6 ||
1147
+ (c >= 0x27c7 && c <= 0x27e5) ||
1148
+ c === 0x27e6 ||
1149
+ c === 0x27e7 ||
1150
+ c === 0x27e8 ||
1151
+ c === 0x27e9 ||
1152
+ c === 0x27ea ||
1153
+ c === 0x27eb ||
1154
+ c === 0x27ec ||
1155
+ c === 0x27ed ||
1156
+ c === 0x27ee ||
1157
+ c === 0x27ef ||
1158
+ (c >= 0x27f0 && c <= 0x27ff) ||
1159
+ (c >= 0x2800 && c <= 0x28ff) ||
1160
+ (c >= 0x2900 && c <= 0x2982) ||
1161
+ c === 0x2983 ||
1162
+ c === 0x2984 ||
1163
+ c === 0x2985 ||
1164
+ c === 0x2986 ||
1165
+ c === 0x2987 ||
1166
+ c === 0x2988 ||
1167
+ c === 0x2989 ||
1168
+ c === 0x298a ||
1169
+ c === 0x298b ||
1170
+ c === 0x298c ||
1171
+ c === 0x298d ||
1172
+ c === 0x298e ||
1173
+ c === 0x298f ||
1174
+ c === 0x2990 ||
1175
+ c === 0x2991 ||
1176
+ c === 0x2992 ||
1177
+ c === 0x2993 ||
1178
+ c === 0x2994 ||
1179
+ c === 0x2995 ||
1180
+ c === 0x2996 ||
1181
+ c === 0x2997 ||
1182
+ c === 0x2998 ||
1183
+ (c >= 0x2999 && c <= 0x29d7) ||
1184
+ c === 0x29d8 ||
1185
+ c === 0x29d9 ||
1186
+ c === 0x29da ||
1187
+ c === 0x29db ||
1188
+ (c >= 0x29dc && c <= 0x29fb) ||
1189
+ c === 0x29fc ||
1190
+ c === 0x29fd ||
1191
+ (c >= 0x29fe && c <= 0x2aff) ||
1192
+ (c >= 0x2b00 && c <= 0x2b2f) ||
1193
+ (c >= 0x2b30 && c <= 0x2b44) ||
1194
+ (c >= 0x2b45 && c <= 0x2b46) ||
1195
+ (c >= 0x2b47 && c <= 0x2b4c) ||
1196
+ (c >= 0x2b4d && c <= 0x2b73) ||
1197
+ (c >= 0x2b74 && c <= 0x2b75) ||
1198
+ (c >= 0x2b76 && c <= 0x2b95) ||
1199
+ c === 0x2b96 ||
1200
+ (c >= 0x2b97 && c <= 0x2bff) ||
1201
+ (c >= 0x2e00 && c <= 0x2e01) ||
1202
+ c === 0x2e02 ||
1203
+ c === 0x2e03 ||
1204
+ c === 0x2e04 ||
1205
+ c === 0x2e05 ||
1206
+ (c >= 0x2e06 && c <= 0x2e08) ||
1207
+ c === 0x2e09 ||
1208
+ c === 0x2e0a ||
1209
+ c === 0x2e0b ||
1210
+ c === 0x2e0c ||
1211
+ c === 0x2e0d ||
1212
+ (c >= 0x2e0e && c <= 0x2e16) ||
1213
+ c === 0x2e17 ||
1214
+ (c >= 0x2e18 && c <= 0x2e19) ||
1215
+ c === 0x2e1a ||
1216
+ c === 0x2e1b ||
1217
+ c === 0x2e1c ||
1218
+ c === 0x2e1d ||
1219
+ (c >= 0x2e1e && c <= 0x2e1f) ||
1220
+ c === 0x2e20 ||
1221
+ c === 0x2e21 ||
1222
+ c === 0x2e22 ||
1223
+ c === 0x2e23 ||
1224
+ c === 0x2e24 ||
1225
+ c === 0x2e25 ||
1226
+ c === 0x2e26 ||
1227
+ c === 0x2e27 ||
1228
+ c === 0x2e28 ||
1229
+ c === 0x2e29 ||
1230
+ (c >= 0x2e2a && c <= 0x2e2e) ||
1231
+ c === 0x2e2f ||
1232
+ (c >= 0x2e30 && c <= 0x2e39) ||
1233
+ (c >= 0x2e3a && c <= 0x2e3b) ||
1234
+ (c >= 0x2e3c && c <= 0x2e3f) ||
1235
+ c === 0x2e40 ||
1236
+ c === 0x2e41 ||
1237
+ c === 0x2e42 ||
1238
+ (c >= 0x2e43 && c <= 0x2e4f) ||
1239
+ (c >= 0x2e50 && c <= 0x2e51) ||
1240
+ c === 0x2e52 ||
1241
+ (c >= 0x2e53 && c <= 0x2e7f) ||
1242
+ (c >= 0x3001 && c <= 0x3003) ||
1243
+ c === 0x3008 ||
1244
+ c === 0x3009 ||
1245
+ c === 0x300a ||
1246
+ c === 0x300b ||
1247
+ c === 0x300c ||
1248
+ c === 0x300d ||
1249
+ c === 0x300e ||
1250
+ c === 0x300f ||
1251
+ c === 0x3010 ||
1252
+ c === 0x3011 ||
1253
+ (c >= 0x3012 && c <= 0x3013) ||
1254
+ c === 0x3014 ||
1255
+ c === 0x3015 ||
1256
+ c === 0x3016 ||
1257
+ c === 0x3017 ||
1258
+ c === 0x3018 ||
1259
+ c === 0x3019 ||
1260
+ c === 0x301a ||
1261
+ c === 0x301b ||
1262
+ c === 0x301c ||
1263
+ c === 0x301d ||
1264
+ (c >= 0x301e && c <= 0x301f) ||
1265
+ c === 0x3020 ||
1266
+ c === 0x3030 ||
1267
+ c === 0xfd3e ||
1268
+ c === 0xfd3f ||
1269
+ (c >= 0xfe45 && c <= 0xfe46));
1270
+ }