@formatjs/icu-messageformat-parser 3.1.1 → 3.2.1

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/manipulator.js CHANGED
@@ -1,5 +1,5 @@
1
- import { __spreadArray } from "tslib";
2
- import { isArgumentElement, isDateElement, isNumberElement, isPluralElement, isSelectElement, isTagElement, isTimeElement, TYPE, } from './types.js';
1
+ import { __assign, __spreadArray } from "tslib";
2
+ import { isArgumentElement, isDateElement, isNumberElement, isPluralElement, isPoundElement, isSelectElement, isTagElement, isTimeElement, TYPE, } from './types.js';
3
3
  function cloneDeep(obj) {
4
4
  if (Array.isArray(obj)) {
5
5
  // @ts-expect-error meh
@@ -15,12 +15,55 @@ function cloneDeep(obj) {
15
15
  }
16
16
  return obj;
17
17
  }
18
+ /**
19
+ * Replace pound elements with number elements referencing the given variable.
20
+ * This is needed when nesting plurals - the # in the outer plural should become
21
+ * an explicit variable reference when nested inside another plural.
22
+ * GH #4202
23
+ */
24
+ function replacePoundWithArgument(ast, variableName) {
25
+ return ast.map(function (el) {
26
+ if (isPoundElement(el)) {
27
+ // Replace # with {variableName, number}
28
+ return {
29
+ type: TYPE.number,
30
+ value: variableName,
31
+ style: null,
32
+ location: el.location,
33
+ };
34
+ }
35
+ if (isPluralElement(el) || isSelectElement(el)) {
36
+ // Recursively process options
37
+ var newOptions = {};
38
+ for (var _i = 0, _a = Object.keys(el.options); _i < _a.length; _i++) {
39
+ var key = _a[_i];
40
+ newOptions[key] = {
41
+ value: replacePoundWithArgument(el.options[key].value, variableName),
42
+ };
43
+ }
44
+ return __assign(__assign({}, el), { options: newOptions });
45
+ }
46
+ if (isTagElement(el)) {
47
+ return __assign(__assign({}, el), { children: replacePoundWithArgument(el.children, variableName) });
48
+ }
49
+ return el;
50
+ });
51
+ }
18
52
  function hoistPluralOrSelectElement(ast, el, positionToInject) {
19
53
  // pull this out of the ast and move it to the top
20
54
  var cloned = cloneDeep(el);
21
55
  var options = cloned.options;
56
+ // GH #4202: Check if there are other plural/select elements after this one
57
+ var afterElements = ast.slice(positionToInject + 1);
58
+ var hasSubsequentPluralOrSelect = afterElements.some(isPluralOrSelectElement);
22
59
  cloned.options = Object.keys(options).reduce(function (all, k) {
23
- var newValue = hoistSelectors(__spreadArray(__spreadArray(__spreadArray([], ast.slice(0, positionToInject), true), options[k].value, true), ast.slice(positionToInject + 1), true));
60
+ var optionValue = options[k].value;
61
+ // GH #4202: If there are subsequent plurals/selects and this is a plural,
62
+ // replace # with explicit variable reference to avoid ambiguity
63
+ if (hasSubsequentPluralOrSelect && isPluralElement(el)) {
64
+ optionValue = replacePoundWithArgument(optionValue, el.value);
65
+ }
66
+ var newValue = hoistSelectors(__spreadArray(__spreadArray(__spreadArray([], ast.slice(0, positionToInject), true), optionValue, true), afterElements, true));
24
67
  all[k] = {
25
68
  value: newValue,
26
69
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/icu-messageformat-parser",
3
- "version": "3.1.1",
3
+ "version": "3.2.1",
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/ecma402-abstract": "3.0.5",
16
- "@formatjs/icu-skeleton-parser": "2.0.5"
15
+ "@formatjs/ecma402-abstract": "3.0.7",
16
+ "@formatjs/icu-skeleton-parser": "2.0.7"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",
@@ -468,6 +468,12 @@ export var timeData = {
468
468
  "hb",
469
469
  "hB"
470
470
  ],
471
+ "GS": [
472
+ "H",
473
+ "h",
474
+ "hb",
475
+ "hB"
476
+ ],
471
477
  "GT": [
472
478
  "h",
473
479
  "H",
@@ -1380,6 +1386,10 @@ export var timeData = {
1380
1386
  "h",
1381
1387
  "H"
1382
1388
  ],
1389
+ "ku-SY": [
1390
+ "H",
1391
+ "hB"
1392
+ ],
1383
1393
  "ml-IN": [
1384
1394
  "hB",
1385
1395
  "h",