@formatjs/icu-messageformat-parser 3.0.4 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,21 +5,14 @@ Hand-written ICU MessageFormat parser with compatible output as
5
5
  but 6 - 10 times as fast.
6
6
 
7
7
  ```
8
- $ node benchmark
9
- complex_msg AST length 10861
10
- normal_msg AST length 1665
11
- simple_msg AST length 364
12
- string_msg AST length 131
8
+ $ bazel run //packages/icu-messageformat-parser/benchmark:benchmark
9
+ complex_msg AST length 2599
10
+ normal_msg AST length 400
11
+ simple_msg AST length 79
12
+ string_msg AST length 36
13
13
 
14
- == Baseline ==
15
- complex_msg x 4,884 ops/sec ±0.97% (91 runs sampled)
16
- normal_msg x 40,113 ops/sec ±1.08% (92 runs sampled)
17
- simple_msg x 200,401 ops/sec ±1.12% (91 runs sampled)
18
- string_msg x 241,103 ops/sec ±0.84% (92 runs sampled)
19
-
20
- == This package ==
21
- complex_msg x 31,590 ops/sec ±0.80% (88 runs sampled)
22
- normal_msg x 278,703 ops/sec ±0.83% (95 runs sampled)
23
- simple_msg x 2,038,061 ops/sec ±0.90% (96 runs sampled)
24
- string_msg x 2,392,794 ops/sec ±0.67% (96 runs sampled)
14
+ complex_msg x 58,910 ops/sec ±0.33%
15
+ normal_msg x 405,440 ops/sec ±0.53%
16
+ simple_msg x 2,592,098 ops/sec ±0.44%
17
+ string_msg x 4,511,129 ops/sec ±2.22%
25
18
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/icu-messageformat-parser",
3
- "version": "3.0.4",
3
+ "version": "3.1.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "types": "index.d.ts",
@@ -12,8 +12,8 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "tslib": "^2.8.0",
15
- "@formatjs/icu-skeleton-parser": "2.0.3",
16
- "@formatjs/ecma402-abstract": "3.0.3"
15
+ "@formatjs/ecma402-abstract": "3.0.4",
16
+ "@formatjs/icu-skeleton-parser": "2.0.4"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",
package/parser.js CHANGED
@@ -1,4 +1,3 @@
1
- var _a;
2
1
  import { __assign } from "tslib";
3
2
  import { ErrorKind } from './error.js';
4
3
  import { SKELETON_TYPE, TYPE, } from './types.js';
@@ -12,68 +11,9 @@ function createLocation(start, end) {
12
11
  }
13
12
  // #region Ponyfills
14
13
  // Consolidate these variables up top for easier toggling during debugging
15
- var hasNativeStartsWith = !!String.prototype.startsWith && '_a'.startsWith('a', 1);
16
- var hasNativeFromCodePoint = !!String.fromCodePoint;
17
14
  var hasNativeFromEntries = !!Object.fromEntries;
18
- var hasNativeCodePointAt = !!String.prototype.codePointAt;
19
15
  var hasTrimStart = !!String.prototype.trimStart;
20
16
  var hasTrimEnd = !!String.prototype.trimEnd;
21
- var hasNativeIsSafeInteger = !!Number.isSafeInteger;
22
- var isSafeInteger = hasNativeIsSafeInteger
23
- ? Number.isSafeInteger
24
- : function (n) {
25
- return (typeof n === 'number' &&
26
- isFinite(n) &&
27
- Math.floor(n) === n &&
28
- Math.abs(n) <= 0x1fffffffffffff);
29
- };
30
- // IE11 does not support y and u.
31
- var REGEX_SUPPORTS_U_AND_Y = true;
32
- try {
33
- var re = RE('([^\\p{White_Space}\\p{Pattern_Syntax}]*)', 'yu');
34
- /**
35
- * legacy Edge or Xbox One browser
36
- * Unicode flag support: supported
37
- * Pattern_Syntax support: not supported
38
- * See https://github.com/formatjs/formatjs/issues/2822
39
- */
40
- REGEX_SUPPORTS_U_AND_Y = ((_a = re.exec('a')) === null || _a === void 0 ? void 0 : _a[0]) === 'a';
41
- }
42
- catch (_b) {
43
- REGEX_SUPPORTS_U_AND_Y = false;
44
- }
45
- var startsWith = hasNativeStartsWith
46
- ? // Native
47
- function startsWith(s, search, position) {
48
- return s.startsWith(search, position);
49
- }
50
- : // For IE11
51
- function startsWith(s, search, position) {
52
- return s.slice(position, position + search.length) === search;
53
- };
54
- var fromCodePoint = hasNativeFromCodePoint
55
- ? String.fromCodePoint
56
- : // IE11
57
- function fromCodePoint() {
58
- var codePoints = [];
59
- for (var _i = 0; _i < arguments.length; _i++) {
60
- codePoints[_i] = arguments[_i];
61
- }
62
- var elements = '';
63
- var length = codePoints.length;
64
- var i = 0;
65
- var code;
66
- while (length > i) {
67
- code = codePoints[i++];
68
- if (code > 0x10ffff)
69
- throw RangeError(code + ' is not a valid code point');
70
- elements +=
71
- code < 0x10000
72
- ? String.fromCharCode(code)
73
- : String.fromCharCode(((code -= 0x10000) >> 10) + 0xd800, (code % 0x400) + 0xdc00);
74
- }
75
- return elements;
76
- };
77
17
  var fromEntries =
78
18
  // native
79
19
  hasNativeFromEntries
@@ -87,27 +27,6 @@ hasNativeFromEntries
87
27
  }
88
28
  return obj;
89
29
  };
90
- var codePointAt = hasNativeCodePointAt
91
- ? // Native
92
- function codePointAt(s, index) {
93
- return s.codePointAt(index);
94
- }
95
- : // IE 11
96
- function codePointAt(s, index) {
97
- var size = s.length;
98
- if (index < 0 || index >= size) {
99
- return undefined;
100
- }
101
- var first = s.charCodeAt(index);
102
- var second;
103
- return first < 0xd800 ||
104
- first > 0xdbff ||
105
- index + 1 === size ||
106
- (second = s.charCodeAt(index + 1)) < 0xdc00 ||
107
- second > 0xdfff
108
- ? first
109
- : ((first - 0xd800) << 10) + (second - 0xdc00) + 0x10000;
110
- };
111
30
  var trimStart = hasTrimStart
112
31
  ? // Native
113
32
  function trimStart(s) {
@@ -126,36 +45,13 @@ var trimEnd = hasTrimEnd
126
45
  function trimEnd(s) {
127
46
  return s.replace(SPACE_SEPARATOR_END_REGEX, '');
128
47
  };
129
- // Prevent minifier to translate new RegExp to literal form that might cause syntax error on IE11.
130
- function RE(s, flag) {
131
- return new RegExp(s, flag);
132
- }
133
48
  // #endregion
134
- var matchIdentifierAtIndex;
135
- if (REGEX_SUPPORTS_U_AND_Y) {
136
- // Native
137
- var IDENTIFIER_PREFIX_RE_1 = RE('([^\\p{White_Space}\\p{Pattern_Syntax}]*)', 'yu');
138
- matchIdentifierAtIndex = function matchIdentifierAtIndex(s, index) {
139
- var _a;
140
- IDENTIFIER_PREFIX_RE_1.lastIndex = index;
141
- var match = IDENTIFIER_PREFIX_RE_1.exec(s);
142
- return (_a = match[1]) !== null && _a !== void 0 ? _a : '';
143
- };
144
- }
145
- else {
146
- // IE11
147
- matchIdentifierAtIndex = function matchIdentifierAtIndex(s, index) {
148
- var match = [];
149
- while (true) {
150
- var c = codePointAt(s, index);
151
- if (c === undefined || _isWhiteSpace(c) || _isPatternSyntax(c)) {
152
- break;
153
- }
154
- match.push(c);
155
- index += c >= 0x10000 ? 2 : 1;
156
- }
157
- return fromCodePoint.apply(void 0, match);
158
- };
49
+ var IDENTIFIER_PREFIX_RE = new RegExp('([^\\p{White_Space}\\p{Pattern_Syntax}]*)', 'yu');
50
+ function matchIdentifierAtIndex(s, index) {
51
+ var _a;
52
+ IDENTIFIER_PREFIX_RE.lastIndex = index;
53
+ var match = IDENTIFIER_PREFIX_RE.exec(s);
54
+ return (_a = match[1]) !== null && _a !== void 0 ? _a : '';
159
55
  }
160
56
  var Parser = /** @class */ (function () {
161
57
  function Parser(message, options) {
@@ -402,7 +298,7 @@ var Parser = /** @class */ (function () {
402
298
  }
403
299
  this.bump();
404
300
  }
405
- return fromCodePoint.apply(void 0, codePoints);
301
+ return String.fromCodePoint.apply(String, codePoints);
406
302
  };
407
303
  Parser.prototype.tryParseUnquoted = function (nestingLevel, parentArgType) {
408
304
  if (this.isEOF()) {
@@ -418,7 +314,7 @@ var Parser = /** @class */ (function () {
418
314
  }
419
315
  else {
420
316
  this.bump();
421
- return fromCodePoint(ch);
317
+ return String.fromCodePoint(ch);
422
318
  }
423
319
  };
424
320
  Parser.prototype.parseArgument = function (nestingLevel, expectingCloseTag) {
@@ -522,7 +418,7 @@ var Parser = /** @class */ (function () {
522
418
  }
523
419
  var location_1 = createLocation(openingBracePosition, this.clonePosition());
524
420
  // Extract style or skeleton
525
- if (styleAndLocation && startsWith(styleAndLocation === null || styleAndLocation === void 0 ? void 0 : styleAndLocation.style, '::', 0)) {
421
+ if (styleAndLocation && styleAndLocation.style.startsWith('::')) {
526
422
  // Skeleton starts with `::`.
527
423
  var skeleton = trimStart(styleAndLocation.style.slice(2));
528
424
  if (argType === 'number') {
@@ -837,7 +733,7 @@ var Parser = /** @class */ (function () {
837
733
  return this.error(expectNumberError, location);
838
734
  }
839
735
  decimal *= sign;
840
- if (!isSafeInteger(decimal)) {
736
+ if (!Number.isSafeInteger(decimal)) {
841
737
  return this.error(invalidNumberError, location);
842
738
  }
843
739
  return { val: decimal, err: null };
@@ -865,7 +761,7 @@ var Parser = /** @class */ (function () {
865
761
  if (offset >= this.message.length) {
866
762
  throw Error('out of bound');
867
763
  }
868
- var code = codePointAt(this.message, offset);
764
+ var code = this.message.codePointAt(offset);
869
765
  if (code === undefined) {
870
766
  throw Error("Offset ".concat(offset, " is at invalid UTF-16 code unit boundary"));
871
767
  }
@@ -905,7 +801,7 @@ var Parser = /** @class */ (function () {
905
801
  * and return false.
906
802
  */
907
803
  Parser.prototype.bumpIf = function (prefix) {
908
- if (startsWith(this.message, prefix, this.offset())) {
804
+ if (this.message.startsWith(prefix, this.offset())) {
909
805
  for (var i = 0; i < prefix.length; i++) {
910
806
  this.bump();
911
807
  }
@@ -1020,257 +916,3 @@ function _isWhiteSpace(c) {
1020
916
  c === 0x2028 ||
1021
917
  c === 0x2029);
1022
918
  }
1023
- /**
1024
- * Code point equivalent of regex `\p{Pattern_Syntax}`.
1025
- * See https://www.unicode.org/Public/UCD/latest/ucd/PropList.txt
1026
- */
1027
- function _isPatternSyntax(c) {
1028
- return ((c >= 0x0021 && c <= 0x0023) ||
1029
- c === 0x0024 ||
1030
- (c >= 0x0025 && c <= 0x0027) ||
1031
- c === 0x0028 ||
1032
- c === 0x0029 ||
1033
- c === 0x002a ||
1034
- c === 0x002b ||
1035
- c === 0x002c ||
1036
- c === 0x002d ||
1037
- (c >= 0x002e && c <= 0x002f) ||
1038
- (c >= 0x003a && c <= 0x003b) ||
1039
- (c >= 0x003c && c <= 0x003e) ||
1040
- (c >= 0x003f && c <= 0x0040) ||
1041
- c === 0x005b ||
1042
- c === 0x005c ||
1043
- c === 0x005d ||
1044
- c === 0x005e ||
1045
- c === 0x0060 ||
1046
- c === 0x007b ||
1047
- c === 0x007c ||
1048
- c === 0x007d ||
1049
- c === 0x007e ||
1050
- c === 0x00a1 ||
1051
- (c >= 0x00a2 && c <= 0x00a5) ||
1052
- c === 0x00a6 ||
1053
- c === 0x00a7 ||
1054
- c === 0x00a9 ||
1055
- c === 0x00ab ||
1056
- c === 0x00ac ||
1057
- c === 0x00ae ||
1058
- c === 0x00b0 ||
1059
- c === 0x00b1 ||
1060
- c === 0x00b6 ||
1061
- c === 0x00bb ||
1062
- c === 0x00bf ||
1063
- c === 0x00d7 ||
1064
- c === 0x00f7 ||
1065
- (c >= 0x2010 && c <= 0x2015) ||
1066
- (c >= 0x2016 && c <= 0x2017) ||
1067
- c === 0x2018 ||
1068
- c === 0x2019 ||
1069
- c === 0x201a ||
1070
- (c >= 0x201b && c <= 0x201c) ||
1071
- c === 0x201d ||
1072
- c === 0x201e ||
1073
- c === 0x201f ||
1074
- (c >= 0x2020 && c <= 0x2027) ||
1075
- (c >= 0x2030 && c <= 0x2038) ||
1076
- c === 0x2039 ||
1077
- c === 0x203a ||
1078
- (c >= 0x203b && c <= 0x203e) ||
1079
- (c >= 0x2041 && c <= 0x2043) ||
1080
- c === 0x2044 ||
1081
- c === 0x2045 ||
1082
- c === 0x2046 ||
1083
- (c >= 0x2047 && c <= 0x2051) ||
1084
- c === 0x2052 ||
1085
- c === 0x2053 ||
1086
- (c >= 0x2055 && c <= 0x205e) ||
1087
- (c >= 0x2190 && c <= 0x2194) ||
1088
- (c >= 0x2195 && c <= 0x2199) ||
1089
- (c >= 0x219a && c <= 0x219b) ||
1090
- (c >= 0x219c && c <= 0x219f) ||
1091
- c === 0x21a0 ||
1092
- (c >= 0x21a1 && c <= 0x21a2) ||
1093
- c === 0x21a3 ||
1094
- (c >= 0x21a4 && c <= 0x21a5) ||
1095
- c === 0x21a6 ||
1096
- (c >= 0x21a7 && c <= 0x21ad) ||
1097
- c === 0x21ae ||
1098
- (c >= 0x21af && c <= 0x21cd) ||
1099
- (c >= 0x21ce && c <= 0x21cf) ||
1100
- (c >= 0x21d0 && c <= 0x21d1) ||
1101
- c === 0x21d2 ||
1102
- c === 0x21d3 ||
1103
- c === 0x21d4 ||
1104
- (c >= 0x21d5 && c <= 0x21f3) ||
1105
- (c >= 0x21f4 && c <= 0x22ff) ||
1106
- (c >= 0x2300 && c <= 0x2307) ||
1107
- c === 0x2308 ||
1108
- c === 0x2309 ||
1109
- c === 0x230a ||
1110
- c === 0x230b ||
1111
- (c >= 0x230c && c <= 0x231f) ||
1112
- (c >= 0x2320 && c <= 0x2321) ||
1113
- (c >= 0x2322 && c <= 0x2328) ||
1114
- c === 0x2329 ||
1115
- c === 0x232a ||
1116
- (c >= 0x232b && c <= 0x237b) ||
1117
- c === 0x237c ||
1118
- (c >= 0x237d && c <= 0x239a) ||
1119
- (c >= 0x239b && c <= 0x23b3) ||
1120
- (c >= 0x23b4 && c <= 0x23db) ||
1121
- (c >= 0x23dc && c <= 0x23e1) ||
1122
- (c >= 0x23e2 && c <= 0x2426) ||
1123
- (c >= 0x2427 && c <= 0x243f) ||
1124
- (c >= 0x2440 && c <= 0x244a) ||
1125
- (c >= 0x244b && c <= 0x245f) ||
1126
- (c >= 0x2500 && c <= 0x25b6) ||
1127
- c === 0x25b7 ||
1128
- (c >= 0x25b8 && c <= 0x25c0) ||
1129
- c === 0x25c1 ||
1130
- (c >= 0x25c2 && c <= 0x25f7) ||
1131
- (c >= 0x25f8 && c <= 0x25ff) ||
1132
- (c >= 0x2600 && c <= 0x266e) ||
1133
- c === 0x266f ||
1134
- (c >= 0x2670 && c <= 0x2767) ||
1135
- c === 0x2768 ||
1136
- c === 0x2769 ||
1137
- c === 0x276a ||
1138
- c === 0x276b ||
1139
- c === 0x276c ||
1140
- c === 0x276d ||
1141
- c === 0x276e ||
1142
- c === 0x276f ||
1143
- c === 0x2770 ||
1144
- c === 0x2771 ||
1145
- c === 0x2772 ||
1146
- c === 0x2773 ||
1147
- c === 0x2774 ||
1148
- c === 0x2775 ||
1149
- (c >= 0x2794 && c <= 0x27bf) ||
1150
- (c >= 0x27c0 && c <= 0x27c4) ||
1151
- c === 0x27c5 ||
1152
- c === 0x27c6 ||
1153
- (c >= 0x27c7 && c <= 0x27e5) ||
1154
- c === 0x27e6 ||
1155
- c === 0x27e7 ||
1156
- c === 0x27e8 ||
1157
- c === 0x27e9 ||
1158
- c === 0x27ea ||
1159
- c === 0x27eb ||
1160
- c === 0x27ec ||
1161
- c === 0x27ed ||
1162
- c === 0x27ee ||
1163
- c === 0x27ef ||
1164
- (c >= 0x27f0 && c <= 0x27ff) ||
1165
- (c >= 0x2800 && c <= 0x28ff) ||
1166
- (c >= 0x2900 && c <= 0x2982) ||
1167
- c === 0x2983 ||
1168
- c === 0x2984 ||
1169
- c === 0x2985 ||
1170
- c === 0x2986 ||
1171
- c === 0x2987 ||
1172
- c === 0x2988 ||
1173
- c === 0x2989 ||
1174
- c === 0x298a ||
1175
- c === 0x298b ||
1176
- c === 0x298c ||
1177
- c === 0x298d ||
1178
- c === 0x298e ||
1179
- c === 0x298f ||
1180
- c === 0x2990 ||
1181
- c === 0x2991 ||
1182
- c === 0x2992 ||
1183
- c === 0x2993 ||
1184
- c === 0x2994 ||
1185
- c === 0x2995 ||
1186
- c === 0x2996 ||
1187
- c === 0x2997 ||
1188
- c === 0x2998 ||
1189
- (c >= 0x2999 && c <= 0x29d7) ||
1190
- c === 0x29d8 ||
1191
- c === 0x29d9 ||
1192
- c === 0x29da ||
1193
- c === 0x29db ||
1194
- (c >= 0x29dc && c <= 0x29fb) ||
1195
- c === 0x29fc ||
1196
- c === 0x29fd ||
1197
- (c >= 0x29fe && c <= 0x2aff) ||
1198
- (c >= 0x2b00 && c <= 0x2b2f) ||
1199
- (c >= 0x2b30 && c <= 0x2b44) ||
1200
- (c >= 0x2b45 && c <= 0x2b46) ||
1201
- (c >= 0x2b47 && c <= 0x2b4c) ||
1202
- (c >= 0x2b4d && c <= 0x2b73) ||
1203
- (c >= 0x2b74 && c <= 0x2b75) ||
1204
- (c >= 0x2b76 && c <= 0x2b95) ||
1205
- c === 0x2b96 ||
1206
- (c >= 0x2b97 && c <= 0x2bff) ||
1207
- (c >= 0x2e00 && c <= 0x2e01) ||
1208
- c === 0x2e02 ||
1209
- c === 0x2e03 ||
1210
- c === 0x2e04 ||
1211
- c === 0x2e05 ||
1212
- (c >= 0x2e06 && c <= 0x2e08) ||
1213
- c === 0x2e09 ||
1214
- c === 0x2e0a ||
1215
- c === 0x2e0b ||
1216
- c === 0x2e0c ||
1217
- c === 0x2e0d ||
1218
- (c >= 0x2e0e && c <= 0x2e16) ||
1219
- c === 0x2e17 ||
1220
- (c >= 0x2e18 && c <= 0x2e19) ||
1221
- c === 0x2e1a ||
1222
- c === 0x2e1b ||
1223
- c === 0x2e1c ||
1224
- c === 0x2e1d ||
1225
- (c >= 0x2e1e && c <= 0x2e1f) ||
1226
- c === 0x2e20 ||
1227
- c === 0x2e21 ||
1228
- c === 0x2e22 ||
1229
- c === 0x2e23 ||
1230
- c === 0x2e24 ||
1231
- c === 0x2e25 ||
1232
- c === 0x2e26 ||
1233
- c === 0x2e27 ||
1234
- c === 0x2e28 ||
1235
- c === 0x2e29 ||
1236
- (c >= 0x2e2a && c <= 0x2e2e) ||
1237
- c === 0x2e2f ||
1238
- (c >= 0x2e30 && c <= 0x2e39) ||
1239
- (c >= 0x2e3a && c <= 0x2e3b) ||
1240
- (c >= 0x2e3c && c <= 0x2e3f) ||
1241
- c === 0x2e40 ||
1242
- c === 0x2e41 ||
1243
- c === 0x2e42 ||
1244
- (c >= 0x2e43 && c <= 0x2e4f) ||
1245
- (c >= 0x2e50 && c <= 0x2e51) ||
1246
- c === 0x2e52 ||
1247
- (c >= 0x2e53 && c <= 0x2e7f) ||
1248
- (c >= 0x3001 && c <= 0x3003) ||
1249
- c === 0x3008 ||
1250
- c === 0x3009 ||
1251
- c === 0x300a ||
1252
- c === 0x300b ||
1253
- c === 0x300c ||
1254
- c === 0x300d ||
1255
- c === 0x300e ||
1256
- c === 0x300f ||
1257
- c === 0x3010 ||
1258
- c === 0x3011 ||
1259
- (c >= 0x3012 && c <= 0x3013) ||
1260
- c === 0x3014 ||
1261
- c === 0x3015 ||
1262
- c === 0x3016 ||
1263
- c === 0x3017 ||
1264
- c === 0x3018 ||
1265
- c === 0x3019 ||
1266
- c === 0x301a ||
1267
- c === 0x301b ||
1268
- c === 0x301c ||
1269
- c === 0x301d ||
1270
- (c >= 0x301e && c <= 0x301f) ||
1271
- c === 0x3020 ||
1272
- c === 0x3030 ||
1273
- c === 0xfd3e ||
1274
- c === 0xfd3f ||
1275
- (c >= 0xfe45 && c <= 0xfe46));
1276
- }
@@ -1,5 +1,5 @@
1
1
  // @generated from time-data-gen.ts
2
- // prettier-ignore
2
+ // prettier-ignore
3
3
  export var timeData = {
4
4
  "001": [
5
5
  "H",