@formatjs/icu-messageformat-parser 2.11.4 → 3.0.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/date-time-pattern-generator.js +6 -9
- package/error.d.ts +1 -1
- package/error.js +2 -5
- package/index.d.ts +4 -4
- package/index.js +16 -21
- package/manipulator.d.ts +1 -1
- package/manipulator.js +16 -20
- package/no-parser.d.ts +2 -2
- package/no-parser.js +4 -10
- package/package.json +14 -9
- package/parser.d.ts +2 -2
- package/parser.js +59 -62
- package/printer.d.ts +1 -1
- package/printer.js +15 -20
- package/regex.generated.js +2 -5
- package/time-data.generated.js +1 -4
- package/types.js +17 -33
- package/lib/date-time-pattern-generator.d.ts +0 -8
- package/lib/date-time-pattern-generator.js +0 -83
- package/lib/error.d.ts +0 -68
- package/lib/error.js +0 -63
- package/lib/index.d.ts +0 -7
- package/lib/index.js +0 -46
- package/lib/manipulator.d.ts +0 -26
- package/lib/manipulator.js +0 -135
- package/lib/no-parser.d.ts +0 -4
- package/lib/no-parser.js +0 -6
- package/lib/parser.d.ts +0 -147
- package/lib/parser.js +0 -1276
- package/lib/printer.d.ts +0 -4
- package/lib/printer.js +0 -101
- package/lib/regex.generated.d.ts +0 -2
- package/lib/regex.generated.js +0 -3
- package/lib/time-data.generated.d.ts +0 -1
- package/lib/time-data.generated.js +0 -1417
- package/lib/types.d.ts +0 -120
- package/lib/types.js +0 -94
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
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 =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
package/error.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
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 || (
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 (
|
|
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 (
|
|
14
|
+
else if (isNumberElement(el) && isNumberSkeleton(el.style)) {
|
|
19
15
|
delete el.style.location;
|
|
20
16
|
}
|
|
21
|
-
else if ((
|
|
22
|
-
|
|
17
|
+
else if ((isDateElement(el) || isTimeElement(el)) &&
|
|
18
|
+
isDateTimeSkeleton(el.style)) {
|
|
23
19
|
delete el.style.location;
|
|
24
20
|
}
|
|
25
|
-
else if (
|
|
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 =
|
|
33
|
-
var result = new
|
|
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(
|
|
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
|
-
|
|
43
|
+
export * from './types.js';
|
|
48
44
|
// only for testing
|
|
49
|
-
|
|
50
|
-
|
|
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
package/manipulator.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
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(
|
|
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
|
|
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 (
|
|
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 (
|
|
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 (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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 (
|
|
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 (
|
|
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(
|
|
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
package/no-parser.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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,18 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/icu-messageformat-parser",
|
|
3
|
-
"version": "
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"types": "index.d.ts",
|
|
3
|
+
"version": "3.0.0",
|
|
6
4
|
"dependencies": {
|
|
7
|
-
"
|
|
8
|
-
"@formatjs/icu-skeleton-parser": "
|
|
9
|
-
"
|
|
5
|
+
"@formatjs/ecma402-abstract": "3.0.0",
|
|
6
|
+
"@formatjs/icu-skeleton-parser": "2.0.0",
|
|
7
|
+
"tslib": "^2.8.0"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./index.js",
|
|
11
|
+
"./no-parser.js": "./no-parser.js",
|
|
12
|
+
"./printer.js": "./printer.js",
|
|
13
|
+
"./manipulator.js": "./manipulator.js"
|
|
10
14
|
},
|
|
11
|
-
"
|
|
12
|
-
"module": "lib/index.js",
|
|
15
|
+
"license": "MIT",
|
|
13
16
|
"repository": {
|
|
14
17
|
"type": "git",
|
|
15
18
|
"url": "https://github.com/formatjs/formatjs.git",
|
|
16
19
|
"directory": "packages/icu-messageformat-parser"
|
|
17
|
-
}
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"types": "index.d.ts"
|
|
18
23
|
}
|
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;
|