@formatjs/icu-messageformat-parser 2.11.4 → 3.0.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.
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBestPattern = getBestPattern;
4
- var time_data_generated_1 = require("./time-data.generated");
1
+ import { timeData } from './time-data.generated.js';
5
2
  /**
6
3
  * Returns the best matching date time pattern if a date time skeleton
7
4
  * pattern is provided with a locale. Follows the Unicode specification:
@@ -9,7 +6,7 @@ var time_data_generated_1 = require("./time-data.generated");
9
6
  * @param skeleton date time skeleton pattern that possibly includes j, J or C
10
7
  * @param locale
11
8
  */
12
- function getBestPattern(skeleton, locale) {
9
+ export function getBestPattern(skeleton, locale) {
13
10
  var skeletonCopy = '';
14
11
  for (var patternPos = 0; patternPos < skeleton.length; patternPos++) {
15
12
  var patternChar = skeleton.charAt(patternPos);
@@ -78,9 +75,9 @@ function getDefaultHourSymbolFromLocale(locale) {
78
75
  if (languageTag !== 'root') {
79
76
  regionTag = locale.maximize().region;
80
77
  }
81
- var hourCycles = time_data_generated_1.timeData[regionTag || ''] ||
82
- time_data_generated_1.timeData[languageTag || ''] ||
83
- time_data_generated_1.timeData["".concat(languageTag, "-001")] ||
84
- time_data_generated_1.timeData['001'];
78
+ var hourCycles = timeData[regionTag || ''] ||
79
+ timeData[languageTag || ''] ||
80
+ timeData["".concat(languageTag, "-001")] ||
81
+ timeData['001'];
85
82
  return hourCycles[0];
86
83
  }
package/error.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Location } from './types';
1
+ import { Location } from './types.js';
2
2
  export interface ParserError {
3
3
  kind: ErrorKind;
4
4
  message: string;
package/error.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorKind = void 0;
4
- var ErrorKind;
1
+ export var ErrorKind;
5
2
  (function (ErrorKind) {
6
3
  /** Argument is unclosed (e.g. `{0`) */
7
4
  ErrorKind[ErrorKind["EXPECT_ARGUMENT_CLOSING_BRACE"] = 1] = "EXPECT_ARGUMENT_CLOSING_BRACE";
@@ -63,4 +60,4 @@ var ErrorKind;
63
60
  ErrorKind[ErrorKind["UNMATCHED_CLOSING_TAG"] = 26] = "UNMATCHED_CLOSING_TAG";
64
61
  /** The opening tag has unmatched closing tag. (e.g. `<bold>foo`) */
65
62
  ErrorKind[ErrorKind["UNCLOSED_TAG"] = 27] = "UNCLOSED_TAG";
66
- })(ErrorKind || (exports.ErrorKind = ErrorKind = {}));
63
+ })(ErrorKind || (ErrorKind = {}));
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Parser, ParserOptions } from './parser';
2
- import { MessageFormatElement } from './types';
1
+ import { Parser, ParserOptions } from './parser.js';
2
+ import { MessageFormatElement } from './types.js';
3
3
  export declare function parse(message: string, opts?: ParserOptions): MessageFormatElement[];
4
- export * from './types';
4
+ export * from './types.js';
5
5
  export type { ParserOptions };
6
6
  export declare const _Parser: typeof Parser;
7
- export { isStructurallySame } from './manipulator';
7
+ export { isStructurallySame } from './manipulator.js';
package/index.js CHANGED
@@ -1,38 +1,34 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isStructurallySame = exports._Parser = void 0;
4
- exports.parse = parse;
5
- var tslib_1 = require("tslib");
6
- var error_1 = require("./error");
7
- var parser_1 = require("./parser");
8
- var types_1 = require("./types");
1
+ import { __assign } from "tslib";
2
+ import { ErrorKind } from './error.js';
3
+ import { Parser } from './parser.js';
4
+ import { isDateElement, isDateTimeSkeleton, isNumberElement, isNumberSkeleton, isPluralElement, isSelectElement, isTagElement, isTimeElement, } from './types.js';
9
5
  function pruneLocation(els) {
10
6
  els.forEach(function (el) {
11
7
  delete el.location;
12
- if ((0, types_1.isSelectElement)(el) || (0, types_1.isPluralElement)(el)) {
8
+ if (isSelectElement(el) || isPluralElement(el)) {
13
9
  for (var k in el.options) {
14
10
  delete el.options[k].location;
15
11
  pruneLocation(el.options[k].value);
16
12
  }
17
13
  }
18
- else if ((0, types_1.isNumberElement)(el) && (0, types_1.isNumberSkeleton)(el.style)) {
14
+ else if (isNumberElement(el) && isNumberSkeleton(el.style)) {
19
15
  delete el.style.location;
20
16
  }
21
- else if (((0, types_1.isDateElement)(el) || (0, types_1.isTimeElement)(el)) &&
22
- (0, types_1.isDateTimeSkeleton)(el.style)) {
17
+ else if ((isDateElement(el) || isTimeElement(el)) &&
18
+ isDateTimeSkeleton(el.style)) {
23
19
  delete el.style.location;
24
20
  }
25
- else if ((0, types_1.isTagElement)(el)) {
21
+ else if (isTagElement(el)) {
26
22
  pruneLocation(el.children);
27
23
  }
28
24
  });
29
25
  }
30
- function parse(message, opts) {
26
+ export function parse(message, opts) {
31
27
  if (opts === void 0) { opts = {}; }
32
- opts = tslib_1.__assign({ shouldParseSkeletons: true, requiresOtherClause: true }, opts);
33
- var result = new parser_1.Parser(message, opts).parse();
28
+ opts = __assign({ shouldParseSkeletons: true, requiresOtherClause: true }, opts);
29
+ var result = new Parser(message, opts).parse();
34
30
  if (result.err) {
35
- var error = SyntaxError(error_1.ErrorKind[result.err.kind]);
31
+ var error = SyntaxError(ErrorKind[result.err.kind]);
36
32
  // @ts-expect-error Assign to error object
37
33
  error.location = result.err.location;
38
34
  // @ts-expect-error Assign to error object
@@ -44,8 +40,7 @@ function parse(message, opts) {
44
40
  }
45
41
  return result.val;
46
42
  }
47
- tslib_1.__exportStar(require("./types"), exports);
43
+ export * from './types.js';
48
44
  // only for testing
49
- exports._Parser = parser_1.Parser;
50
- var manipulator_1 = require("./manipulator");
51
- Object.defineProperty(exports, "isStructurallySame", { enumerable: true, get: function () { return manipulator_1.isStructurallySame; } });
45
+ export var _Parser = Parser;
46
+ export { isStructurallySame } from './manipulator.js';
package/manipulator.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MessageFormatElement } from './types';
1
+ import { MessageFormatElement } from './types.js';
2
2
  /**
3
3
  * Hoist all selectors to the beginning of the AST & flatten the
4
4
  * resulting options. E.g:
package/manipulator.js CHANGED
@@ -1,13 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hoistSelectors = hoistSelectors;
4
- exports.isStructurallySame = isStructurallySame;
5
- var tslib_1 = require("tslib");
6
- var types_1 = require("./types");
1
+ import { __spreadArray } from "tslib";
2
+ import { isArgumentElement, isDateElement, isNumberElement, isPluralElement, isSelectElement, isTagElement, isTimeElement, TYPE, } from './types.js';
7
3
  function cloneDeep(obj) {
8
4
  if (Array.isArray(obj)) {
9
5
  // @ts-expect-error meh
10
- return tslib_1.__spreadArray([], obj.map(cloneDeep), true);
6
+ return obj.map(cloneDeep);
11
7
  }
12
8
  if (obj !== null && typeof obj === 'object') {
13
9
  // @ts-expect-error meh
@@ -24,7 +20,7 @@ function hoistPluralOrSelectElement(ast, el, positionToInject) {
24
20
  var cloned = cloneDeep(el);
25
21
  var options = cloned.options;
26
22
  cloned.options = Object.keys(options).reduce(function (all, k) {
27
- var newValue = hoistSelectors(tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray([], ast.slice(0, positionToInject), true), options[k].value, true), ast.slice(positionToInject + 1), true));
23
+ var newValue = hoistSelectors(__spreadArray(__spreadArray(__spreadArray([], ast.slice(0, positionToInject), true), options[k].value, true), ast.slice(positionToInject + 1), true));
28
24
  all[k] = {
29
25
  value: newValue,
30
26
  };
@@ -33,14 +29,14 @@ function hoistPluralOrSelectElement(ast, el, positionToInject) {
33
29
  return cloned;
34
30
  }
35
31
  function isPluralOrSelectElement(el) {
36
- return (0, types_1.isPluralElement)(el) || (0, types_1.isSelectElement)(el);
32
+ return isPluralElement(el) || isSelectElement(el);
37
33
  }
38
34
  function findPluralOrSelectElement(ast) {
39
35
  return !!ast.find(function (el) {
40
36
  if (isPluralOrSelectElement(el)) {
41
37
  return true;
42
38
  }
43
- if ((0, types_1.isTagElement)(el)) {
39
+ if (isTagElement(el)) {
44
40
  return findPluralOrSelectElement(el.children);
45
41
  }
46
42
  return false;
@@ -57,13 +53,13 @@ function findPluralOrSelectElement(ast) {
57
53
  * sentences are not translator-friendly
58
54
  * @param ast AST
59
55
  */
60
- function hoistSelectors(ast) {
56
+ export function hoistSelectors(ast) {
61
57
  for (var i = 0; i < ast.length; i++) {
62
58
  var el = ast[i];
63
59
  if (isPluralOrSelectElement(el)) {
64
60
  return [hoistPluralOrSelectElement(ast, el, i)];
65
61
  }
66
- if ((0, types_1.isTagElement)(el) && findPluralOrSelectElement([el])) {
62
+ if (isTagElement(el) && findPluralOrSelectElement([el])) {
67
63
  throw new Error('Cannot hoist plural/select within a tag element. Please put the tag element inside each plural/select option');
68
64
  }
69
65
  }
@@ -77,22 +73,22 @@ function hoistSelectors(ast) {
77
73
  function collectVariables(ast, vars) {
78
74
  if (vars === void 0) { vars = new Map(); }
79
75
  ast.forEach(function (el) {
80
- if ((0, types_1.isArgumentElement)(el) ||
81
- (0, types_1.isDateElement)(el) ||
82
- (0, types_1.isTimeElement)(el) ||
83
- (0, types_1.isNumberElement)(el)) {
76
+ if (isArgumentElement(el) ||
77
+ isDateElement(el) ||
78
+ isTimeElement(el) ||
79
+ isNumberElement(el)) {
84
80
  if (el.value in vars && vars.get(el.value) !== el.type) {
85
81
  throw new Error("Variable ".concat(el.value, " has conflicting types"));
86
82
  }
87
83
  vars.set(el.value, el.type);
88
84
  }
89
- if ((0, types_1.isPluralElement)(el) || (0, types_1.isSelectElement)(el)) {
85
+ if (isPluralElement(el) || isSelectElement(el)) {
90
86
  vars.set(el.value, el.type);
91
87
  Object.keys(el.options).forEach(function (k) {
92
88
  collectVariables(el.options[k].value, vars);
93
89
  });
94
90
  }
95
- if ((0, types_1.isTagElement)(el)) {
91
+ if (isTagElement(el)) {
96
92
  vars.set(el.value, el.type);
97
93
  collectVariables(el.children, vars);
98
94
  }
@@ -105,7 +101,7 @@ function collectVariables(ast, vars) {
105
101
  * @param b
106
102
  * @returns
107
103
  */
108
- function isStructurallySame(a, b) {
104
+ export function isStructurallySame(a, b) {
109
105
  var aVars = new Map();
110
106
  var bVars = new Map();
111
107
  collectVariables(a, aVars);
@@ -131,7 +127,7 @@ function isStructurallySame(a, b) {
131
127
  if (bType !== type) {
132
128
  return {
133
129
  success: false,
134
- error: new Error("Variable ".concat(key, " has conflicting types: ").concat(types_1.TYPE[type], " vs ").concat(types_1.TYPE[bType])),
130
+ error: new Error("Variable ".concat(key, " has conflicting types: ").concat(TYPE[type], " vs ").concat(TYPE[bType])),
135
131
  };
136
132
  }
137
133
  return result;
package/no-parser.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export declare function parse(): void;
2
- export * from './types';
2
+ export * from './types.js';
3
3
  export declare const _Parser: undefined;
4
- export { isStructurallySame } from './manipulator';
4
+ export { isStructurallySame } from './manipulator.js';
package/no-parser.js CHANGED
@@ -1,12 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isStructurallySame = exports._Parser = void 0;
4
- exports.parse = parse;
5
- var tslib_1 = require("tslib");
6
- function parse() {
1
+ export function parse() {
7
2
  throw new Error("You're trying to format an uncompiled message with react-intl without parser, please import from 'react-intl' instead");
8
3
  }
9
- tslib_1.__exportStar(require("./types"), exports);
10
- exports._Parser = undefined;
11
- var manipulator_1 = require("./manipulator");
12
- Object.defineProperty(exports, "isStructurallySame", { enumerable: true, get: function () { return manipulator_1.isStructurallySame; } });
4
+ export * from './types.js';
5
+ export var _Parser = undefined;
6
+ export { isStructurallySame } from './manipulator.js';
package/package.json CHANGED
@@ -1,15 +1,20 @@
1
1
  {
2
2
  "name": "@formatjs/icu-messageformat-parser",
3
- "version": "2.11.4",
3
+ "version": "3.0.1",
4
4
  "license": "MIT",
5
+ "type": "module",
5
6
  "types": "index.d.ts",
7
+ "exports": {
8
+ ".": "./index.js",
9
+ "./no-parser.js": "./no-parser.js",
10
+ "./printer.js": "./printer.js",
11
+ "./manipulator.js": "./manipulator.js"
12
+ },
6
13
  "dependencies": {
7
14
  "tslib": "^2.8.0",
8
- "@formatjs/icu-skeleton-parser": "1.8.16",
9
- "@formatjs/ecma402-abstract": "2.3.6"
15
+ "@formatjs/ecma402-abstract": "3.0.1",
16
+ "@formatjs/icu-skeleton-parser": "2.0.1"
10
17
  },
11
- "main": "index.js",
12
- "module": "lib/index.js",
13
18
  "repository": {
14
19
  "type": "git",
15
20
  "url": "https://github.com/formatjs/formatjs.git",
package/parser.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ParserError } from './error';
2
- import { MessageFormatElement } from './types';
1
+ import { ParserError } from './error.js';
2
+ import { MessageFormatElement } from './types.js';
3
3
  export interface Position {
4
4
  /** Offset in terms of UTF-16 *code unit*. */
5
5
  offset: number;