@discord/intl 0.7.0 → 0.7.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/dist/format.js +5 -5
- package/dist/intl-manager.js +2 -2
- package/package.json +2 -2
- package/src/format.ts +5 -5
- package/src/intl-manager.ts +2 -2
package/dist/format.js
CHANGED
|
@@ -37,16 +37,16 @@ exports.FormatBuilder = FormatBuilder;
|
|
|
37
37
|
function bindFormatValuesWithBuilder(builder, nodes, locales, formatters, formatConfig, values = {}, currentPluralValue, originalMessage) {
|
|
38
38
|
var _a, _b;
|
|
39
39
|
// Hot path for static messages that are just parsed as a single string element.
|
|
40
|
-
if (nodes.length === 1 && typeof nodes[0]
|
|
41
|
-
builder.pushLiteralText(nodes[0]
|
|
40
|
+
if (nodes.length === 1 && typeof nodes[0] === 'string') {
|
|
41
|
+
builder.pushLiteralText(nodes[0]);
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
for (const node of nodes) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
builder.pushLiteralText(nodeType);
|
|
45
|
+
if (typeof node === 'string') {
|
|
46
|
+
builder.pushLiteralText(node);
|
|
48
47
|
continue;
|
|
49
48
|
}
|
|
49
|
+
const nodeType = node[intl_ast_1.AstNodeIndices.Type];
|
|
50
50
|
switch (nodeType) {
|
|
51
51
|
case intl_ast_1.FormatJsNodeType.Pound:
|
|
52
52
|
// Replace `#` in plural rules with the actual numeric value. Only
|
package/dist/intl-manager.js
CHANGED
|
@@ -72,7 +72,7 @@ class IntlManager {
|
|
|
72
72
|
if (resolved == null || resolved.ast.length === 0)
|
|
73
73
|
return '';
|
|
74
74
|
const value = resolved.ast[0];
|
|
75
|
-
if (typeof value
|
|
75
|
+
if (typeof value !== 'string') {
|
|
76
76
|
throw new Error('Attempted to call `string` formatting on a non-literal message: ' +
|
|
77
77
|
JSON.stringify(resolved));
|
|
78
78
|
}
|
|
@@ -81,7 +81,7 @@ class IntlManager {
|
|
|
81
81
|
// contain a single static text node and no placeholders or rich text.
|
|
82
82
|
// As it stands, this is _technically_ typed as string | undefined, even though
|
|
83
83
|
// TypeScript doesn't actually complain about it.
|
|
84
|
-
return value
|
|
84
|
+
return value;
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
87
|
* Return a raw string representing the syntax of the original message, as
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discord/intl",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Client runtime for managing messages and translations in a React project.",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@formatjs/intl": "^2.10.1",
|
|
20
20
|
"@intrnl/xxhash64": "^0.1.2",
|
|
21
21
|
"intl-messageformat": "^10.5.11",
|
|
22
|
-
"@discord/intl-ast": "0.7.
|
|
22
|
+
"@discord/intl-ast": "0.7.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@swc/cli": "^0.3.12",
|
package/src/format.ts
CHANGED
|
@@ -56,17 +56,17 @@ export function bindFormatValuesWithBuilder<T, Builder extends FormatBuilder<T>>
|
|
|
56
56
|
originalMessage?: string,
|
|
57
57
|
) {
|
|
58
58
|
// Hot path for static messages that are just parsed as a single string element.
|
|
59
|
-
if (nodes.length === 1 && typeof nodes[0]
|
|
60
|
-
builder.pushLiteralText(nodes[0]
|
|
59
|
+
if (nodes.length === 1 && typeof nodes[0] === 'string') {
|
|
60
|
+
builder.pushLiteralText(nodes[0]);
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
for (const node of nodes) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
builder.pushLiteralText(nodeType);
|
|
65
|
+
if (typeof node === 'string') {
|
|
66
|
+
builder.pushLiteralText(node);
|
|
68
67
|
continue;
|
|
69
68
|
}
|
|
69
|
+
const nodeType = node[AstNodeIndices.Type];
|
|
70
70
|
switch (nodeType) {
|
|
71
71
|
case FormatJsNodeType.Pound:
|
|
72
72
|
// Replace `#` in plural rules with the actual numeric value. Only
|
package/src/intl-manager.ts
CHANGED
|
@@ -121,7 +121,7 @@ export class IntlManager {
|
|
|
121
121
|
if (resolved == null || resolved.ast.length === 0) return '';
|
|
122
122
|
|
|
123
123
|
const value = resolved.ast[0] as LiteralNode;
|
|
124
|
-
if (typeof value
|
|
124
|
+
if (typeof value !== 'string') {
|
|
125
125
|
throw new Error(
|
|
126
126
|
'Attempted to call `string` formatting on a non-literal message: ' +
|
|
127
127
|
JSON.stringify(resolved),
|
|
@@ -133,7 +133,7 @@ export class IntlManager {
|
|
|
133
133
|
// contain a single static text node and no placeholders or rich text.
|
|
134
134
|
// As it stands, this is _technically_ typed as string | undefined, even though
|
|
135
135
|
// TypeScript doesn't actually complain about it.
|
|
136
|
-
return value
|
|
136
|
+
return value;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/**
|