@discord/intl 0.10.0-rc.3 → 0.10.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/dist/format.js CHANGED
@@ -35,7 +35,7 @@ class FormatBuilder {
35
35
  }
36
36
  exports.FormatBuilder = FormatBuilder;
37
37
  function bindFormatValuesWithBuilder(builder, nodes, locales, formatters, formatConfig, values = {}, currentPluralValue, originalMessage) {
38
- var _a, _b;
38
+ var _a;
39
39
  // Hot path for static messages that are just parsed as a single string element.
40
40
  if (nodes.length === 1 && typeof nodes[0] === 'string') {
41
41
  builder.pushLiteralText(nodes[0]);
@@ -146,17 +146,16 @@ function bindFormatValuesWithBuilder(builder, nodes, locales, formatters, format
146
146
  break;
147
147
  }
148
148
  case intl_ast_1.FormatJsNodeType.Select: {
149
- const value = node[1 /* AstNodeIndices.Value */];
149
+ const requestedOption = value;
150
150
  const options = node[2 /* AstNodeIndices.Options */];
151
- const option = value in options ? options[value] : options.other;
151
+ const option = requestedOption in options ? options[requestedOption] : options.other;
152
152
  if (option == null) {
153
- throw `${value} is not a known option for select value ${variableName}. Valid options are ${Object.keys(options).join(', ')}`;
153
+ throw `${requestedOption} is not a known option for select value ${variableName}. Valid options are ${Object.keys(options).join(', ')}`;
154
154
  }
155
155
  bindFormatValuesWithBuilder(builder, option, locales, formatters, formatConfig, values);
156
156
  break;
157
157
  }
158
158
  case intl_ast_1.FormatJsNodeType.Plural: {
159
- const value = node[1 /* AstNodeIndices.Value */];
160
159
  const options = node[2 /* AstNodeIndices.Options */];
161
160
  const offset = node[3 /* AstNodeIndices.Offset */];
162
161
  const pluralType = node[4 /* AstNodeIndices.PluralType */];
@@ -175,8 +174,8 @@ function bindFormatValuesWithBuilder(builder, nodes, locales, formatters, format
175
174
  throw `${value} is not a known option for plural value ${variableName}. Valid options are ${Object.keys(options).join(', ')}`;
176
175
  }
177
176
  bindFormatValuesWithBuilder(builder, option, locales, formatters, formatConfig, values,
178
- // @ts-expect-error assert this `as number` properly.
179
- value - ((_b = node.offset) !== null && _b !== void 0 ? _b : 0));
177
+ // @ts-expect-error assert this `as number` properly
178
+ value - (offset !== null && offset !== void 0 ? offset : 0));
180
179
  break;
181
180
  }
182
181
  }
@@ -109,7 +109,7 @@ class MessageLoader {
109
109
  getBinds() {
110
110
  const onChange = this.onChange.bind(this);
111
111
  const result = {};
112
- for (const key in this.messageKeys) {
112
+ for (const key of this.messageKeys) {
113
113
  const bound = (locale) => this.get(key, locale);
114
114
  bound.onChange = onChange;
115
115
  result[key] = bound;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discord/intl",
3
- "version": "0.10.0-rc.3",
3
+ "version": "0.10.0",
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.10.0-rc.3"
22
+ "@discord/intl-ast": "0.10.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@swc/cli": "^0.3.12",
package/src/format.ts CHANGED
@@ -192,18 +192,17 @@ export function bindFormatValuesWithBuilder<T, Builder extends FormatBuilder<T>>
192
192
  }
193
193
 
194
194
  case FormatJsNodeType.Select: {
195
- const value = node[AstNodeIndices.Value];
195
+ const requestedOption = value as string;
196
196
  const options = node[AstNodeIndices.Options];
197
- const option = value in options ? options[value] : options.other;
197
+ const option = requestedOption in options ? options[requestedOption] : options.other;
198
198
  if (option == null) {
199
- throw `${value} is not a known option for select value ${variableName}. Valid options are ${Object.keys(options).join(', ')}`;
199
+ throw `${requestedOption} is not a known option for select value ${variableName}. Valid options are ${Object.keys(options).join(', ')}`;
200
200
  }
201
201
  bindFormatValuesWithBuilder(builder, option, locales, formatters, formatConfig, values);
202
202
  break;
203
203
  }
204
204
 
205
205
  case FormatJsNodeType.Plural: {
206
- const value = node[AstNodeIndices.Value];
207
206
  const options = node[AstNodeIndices.Options];
208
207
  const offset = node[AstNodeIndices.Offset];
209
208
  const pluralType = node[AstNodeIndices.PluralType];
@@ -227,8 +226,8 @@ export function bindFormatValuesWithBuilder<T, Builder extends FormatBuilder<T>>
227
226
  formatters,
228
227
  formatConfig,
229
228
  values,
230
- // @ts-expect-error assert this `as number` properly.
231
- (value as number) - (node.offset ?? 0),
229
+ // @ts-expect-error assert this `as number` properly
230
+ (value as number) - (offset ?? 0),
232
231
  );
233
232
  break;
234
233
  }
@@ -195,7 +195,7 @@ export class MessageLoader {
195
195
  getBinds(): Record<string, IntlMessageGetter> {
196
196
  const onChange = this.onChange.bind(this);
197
197
  const result: Record<string, IntlMessageGetter> = {};
198
- for (const key in this.messageKeys) {
198
+ for (const key of this.messageKeys) {
199
199
  const bound = (locale: LocaleId) => this.get(key, locale);
200
200
  bound.onChange = onChange;
201
201
  result[key] = bound;