@formatjs/icu-messageformat-parser 2.10.1 → 2.11.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/lib/manipulator.d.ts +6 -1
- package/lib/manipulator.js +24 -5
- package/manipulator.d.ts +6 -1
- package/manipulator.js +23 -4
- package/package.json +3 -3
package/lib/manipulator.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ import { MessageFormatElement } from './types';
|
|
|
11
11
|
* @param ast AST
|
|
12
12
|
*/
|
|
13
13
|
export declare function hoistSelectors(ast: MessageFormatElement[]): MessageFormatElement[];
|
|
14
|
+
interface IsStructurallySameResult {
|
|
15
|
+
error?: Error;
|
|
16
|
+
success: boolean;
|
|
17
|
+
}
|
|
14
18
|
/**
|
|
15
19
|
* Check if 2 ASTs are structurally the same. This primarily means that
|
|
16
20
|
* they have the same variables with the same type
|
|
@@ -18,4 +22,5 @@ export declare function hoistSelectors(ast: MessageFormatElement[]): MessageForm
|
|
|
18
22
|
* @param b
|
|
19
23
|
* @returns
|
|
20
24
|
*/
|
|
21
|
-
export declare function isStructurallySame(a: MessageFormatElement[], b: MessageFormatElement[]):
|
|
25
|
+
export declare function isStructurallySame(a: MessageFormatElement[], b: MessageFormatElement[]): IsStructurallySameResult;
|
|
26
|
+
export {};
|
package/lib/manipulator.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __spreadArray } from "tslib";
|
|
2
|
-
import { isArgumentElement, isDateElement, isNumberElement, isPluralElement, isSelectElement, isTagElement, isTimeElement, } from './types';
|
|
2
|
+
import { isArgumentElement, isDateElement, isNumberElement, isPluralElement, isSelectElement, isTagElement, isTimeElement, TYPE, } from './types';
|
|
3
3
|
function cloneDeep(obj) {
|
|
4
4
|
if (Array.isArray(obj)) {
|
|
5
5
|
// @ts-expect-error meh
|
|
@@ -107,10 +107,29 @@ export function isStructurallySame(a, b) {
|
|
|
107
107
|
collectVariables(a, aVars);
|
|
108
108
|
collectVariables(b, bVars);
|
|
109
109
|
if (aVars.size !== bVars.size) {
|
|
110
|
-
return
|
|
110
|
+
return {
|
|
111
|
+
success: false,
|
|
112
|
+
error: new Error("Different number of variables: [".concat(Array.from(aVars.keys()).join(', '), "] vs [").concat(Array.from(bVars.keys()).join(', '), "]")),
|
|
113
|
+
};
|
|
111
114
|
}
|
|
112
|
-
return Array.from(aVars.entries()).
|
|
115
|
+
return Array.from(aVars.entries()).reduce(function (result, _a) {
|
|
113
116
|
var key = _a[0], type = _a[1];
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
if (!result.success) {
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
var bType = bVars.get(key);
|
|
121
|
+
if (bType == null) {
|
|
122
|
+
return {
|
|
123
|
+
success: false,
|
|
124
|
+
error: new Error("Missing variable ".concat(key, " in message")),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (bType !== type) {
|
|
128
|
+
return {
|
|
129
|
+
success: false,
|
|
130
|
+
error: new Error("Variable ".concat(key, " has conflicting types: ").concat(TYPE[type], " vs ").concat(TYPE[bType])),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}, { success: true });
|
|
116
135
|
}
|
package/manipulator.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ import { MessageFormatElement } from './types';
|
|
|
11
11
|
* @param ast AST
|
|
12
12
|
*/
|
|
13
13
|
export declare function hoistSelectors(ast: MessageFormatElement[]): MessageFormatElement[];
|
|
14
|
+
interface IsStructurallySameResult {
|
|
15
|
+
error?: Error;
|
|
16
|
+
success: boolean;
|
|
17
|
+
}
|
|
14
18
|
/**
|
|
15
19
|
* Check if 2 ASTs are structurally the same. This primarily means that
|
|
16
20
|
* they have the same variables with the same type
|
|
@@ -18,4 +22,5 @@ export declare function hoistSelectors(ast: MessageFormatElement[]): MessageForm
|
|
|
18
22
|
* @param b
|
|
19
23
|
* @returns
|
|
20
24
|
*/
|
|
21
|
-
export declare function isStructurallySame(a: MessageFormatElement[], b: MessageFormatElement[]):
|
|
25
|
+
export declare function isStructurallySame(a: MessageFormatElement[], b: MessageFormatElement[]): IsStructurallySameResult;
|
|
26
|
+
export {};
|
package/manipulator.js
CHANGED
|
@@ -111,10 +111,29 @@ function isStructurallySame(a, b) {
|
|
|
111
111
|
collectVariables(a, aVars);
|
|
112
112
|
collectVariables(b, bVars);
|
|
113
113
|
if (aVars.size !== bVars.size) {
|
|
114
|
-
return
|
|
114
|
+
return {
|
|
115
|
+
success: false,
|
|
116
|
+
error: new Error("Different number of variables: [".concat(Array.from(aVars.keys()).join(', '), "] vs [").concat(Array.from(bVars.keys()).join(', '), "]")),
|
|
117
|
+
};
|
|
115
118
|
}
|
|
116
|
-
return Array.from(aVars.entries()).
|
|
119
|
+
return Array.from(aVars.entries()).reduce(function (result, _a) {
|
|
117
120
|
var key = _a[0], type = _a[1];
|
|
118
|
-
|
|
119
|
-
|
|
121
|
+
if (!result.success) {
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
var bType = bVars.get(key);
|
|
125
|
+
if (bType == null) {
|
|
126
|
+
return {
|
|
127
|
+
success: false,
|
|
128
|
+
error: new Error("Missing variable ".concat(key, " in message")),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (bType !== type) {
|
|
132
|
+
return {
|
|
133
|
+
success: false,
|
|
134
|
+
error: new Error("Variable ".concat(key, " has conflicting types: ").concat(types_1.TYPE[type], " vs ").concat(types_1.TYPE[bType])),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
}, { success: true });
|
|
120
139
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/icu-messageformat-parser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"tslib": "2",
|
|
15
|
-
"@formatjs/ecma402-abstract": "2.3.
|
|
16
|
-
"@formatjs/icu-skeleton-parser": "1.8.
|
|
15
|
+
"@formatjs/ecma402-abstract": "2.3.3",
|
|
16
|
+
"@formatjs/icu-skeleton-parser": "1.8.13"
|
|
17
17
|
}
|
|
18
18
|
}
|