@discord/intl 0.11.2-rc.1 → 0.11.2-rc.3

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/message.js CHANGED
@@ -24,63 +24,65 @@ exports.InternalIntlMessage = InternalIntlMessage;
24
24
  // appended, rather than creating a bunch of intermediate strings.
25
25
  function serializeAst(ast, result) {
26
26
  for (const node of ast) {
27
- if (typeof node[0] === 'string') {
28
- result.value += node[0];
29
- return;
27
+ if (typeof node === 'string') {
28
+ result.value += node;
29
+ continue;
30
30
  }
31
31
  switch (node[0 /* AstNodeIndices.Type */]) {
32
32
  case intl_ast_1.FormatJsNodeType.Argument:
33
33
  result.value += '{' + node[1 /* AstNodeIndices.Value */] + '}';
34
- return;
34
+ break;
35
35
  case intl_ast_1.FormatJsNodeType.Date:
36
36
  result.value += '{' + node[1 /* AstNodeIndices.Value */] + ', date';
37
37
  if (node[2 /* AstNodeIndices.Style */] != null) {
38
38
  result.value += ', ' + node[2 /* AstNodeIndices.Style */];
39
39
  }
40
40
  result.value += '}';
41
- return;
41
+ break;
42
42
  case intl_ast_1.FormatJsNodeType.Time:
43
43
  result.value += '{' + node[1 /* AstNodeIndices.Value */] + ', time';
44
44
  if (node[2 /* AstNodeIndices.Style */] != null) {
45
45
  result.value += ', ' + node[2 /* AstNodeIndices.Style */];
46
46
  }
47
47
  result.value += '}';
48
- return;
48
+ break;
49
49
  case intl_ast_1.FormatJsNodeType.Number:
50
50
  result.value += '{' + node[1 /* AstNodeIndices.Value */] + ', number';
51
51
  if (node[2 /* AstNodeIndices.Style */] != null) {
52
52
  result.value += ', ' + node[2 /* AstNodeIndices.Style */];
53
53
  }
54
54
  result.value += '}';
55
- return;
55
+ break;
56
56
  case intl_ast_1.FormatJsNodeType.Plural: {
57
57
  const pluralType = node[4 /* AstNodeIndices.PluralType */] == 'ordinal' ? 'selectordinal' : 'plural';
58
- result.value += '{' + node[1 /* AstNodeIndices.Value */] + ', ' + pluralType + ', ';
58
+ result.value += '{' + node[1 /* AstNodeIndices.Value */] + ', ' + pluralType + ',';
59
59
  if (node[3 /* AstNodeIndices.Offset */]) {
60
- result.value += 'offset:' + node[3 /* AstNodeIndices.Offset */];
60
+ result.value += ' offset:' + node[3 /* AstNodeIndices.Offset */];
61
61
  }
62
62
  for (const [name, arm] of Object.entries(node[2 /* AstNodeIndices.Options */])) {
63
63
  result.value += ' ' + name + ' {';
64
64
  serializeAst(arm, result);
65
65
  result.value += '}';
66
66
  }
67
- return;
67
+ result.value += '}';
68
+ break;
68
69
  }
69
70
  case intl_ast_1.FormatJsNodeType.Pound:
70
71
  result.value += '#';
71
- return;
72
+ break;
72
73
  case intl_ast_1.FormatJsNodeType.Select: {
73
- result.value += '{' + node[1 /* AstNodeIndices.Value */] + ', select, ';
74
+ result.value += '{' + node[1 /* AstNodeIndices.Value */] + ', select,';
74
75
  for (const [name, arm] of Object.entries(node[2 /* AstNodeIndices.Options */])) {
75
76
  result.value += ' ' + name + ' {';
76
77
  serializeAst(arm, result);
77
78
  result.value += '}';
78
79
  }
79
- return;
80
+ result.value += '}';
81
+ break;
80
82
  }
81
83
  case intl_ast_1.FormatJsNodeType.Tag:
82
84
  serializeAstTag(node, result);
83
- return;
85
+ break;
84
86
  }
85
87
  }
86
88
  }
@@ -90,38 +92,39 @@ function serializeAstTag(node, result) {
90
92
  result.value += '**';
91
93
  serializeAst(node[2 /* AstNodeIndices.Children */], result);
92
94
  result.value += '**';
93
- return;
95
+ break;
94
96
  case '$i':
95
97
  result.value += '*';
96
98
  serializeAst(node[2 /* AstNodeIndices.Children */], result);
97
99
  result.value += '*';
98
- return;
100
+ break;
99
101
  case '$code':
100
102
  result.value += '`';
101
103
  serializeAst(node[2 /* AstNodeIndices.Children */], result);
102
104
  result.value += '`';
103
- return;
105
+ break;
104
106
  case '$p':
105
107
  serializeAst(node[2 /* AstNodeIndices.Children */], result);
106
108
  result.value += '\n\n';
107
- return;
109
+ break;
108
110
  case '$link':
109
111
  // The target is the first child of the link. We don't have to care if it's a placeholder
110
112
  // or not, because the serialization will automatically remove the extra empty.
111
- const [target, ...children] = node[2 /* AstNodeIndices.Children */];
113
+ const children = node[2 /* AstNodeIndices.Children */];
114
+ const target = node[3 /* AstNodeIndices.Control */];
112
115
  result.value += '[';
113
116
  serializeAst(children, result);
114
117
  result.value += '](';
115
118
  if (target != null) {
116
- serializeAst([target], result);
119
+ serializeAst(target, result);
117
120
  }
118
121
  result.value += ')';
119
- return;
122
+ break;
120
123
  default:
121
124
  // Any other tag name is a hook, which just adds the `$[` on a link tag.
122
125
  result.value += '$[';
123
126
  serializeAst(node[2 /* AstNodeIndices.Children */], result);
124
127
  result.value += '](' + node[1 /* AstNodeIndices.Value */] + ')';
125
- return;
128
+ break;
126
129
  }
127
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discord/intl",
3
- "version": "0.11.2-rc.1",
3
+ "version": "0.11.2-rc.3",
4
4
  "license": "MIT",
5
5
  "description": "Client runtime for managing messages and translations in a React project.",
6
6
  "main": "./dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "@formatjs/intl": "^2.10.1",
24
24
  "@intrnl/xxhash64": "^0.1.2",
25
25
  "intl-messageformat": "^10.5.11",
26
- "@discord/intl-ast": "0.11.2-rc.1"
26
+ "@discord/intl-ast": "0.11.2-rc.3"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@swc/cli": "^0.3.12",
package/src/message.ts CHANGED
@@ -34,65 +34,67 @@ export class InternalIntlMessage {
34
34
  // appended, rather than creating a bunch of intermediate strings.
35
35
  function serializeAst(ast: AstNode[], result: { value: string }) {
36
36
  for (const node of ast) {
37
- if (typeof node[0] === 'string') {
38
- result.value += node[0];
39
- return;
37
+ if (typeof node === 'string') {
38
+ result.value += node;
39
+ continue;
40
40
  }
41
41
 
42
42
  switch (node[AstNodeIndices.Type]) {
43
43
  case FormatJsNodeType.Argument:
44
44
  result.value += '{' + node[AstNodeIndices.Value] + '}';
45
- return;
45
+ break;
46
46
  case FormatJsNodeType.Date:
47
47
  result.value += '{' + node[AstNodeIndices.Value] + ', date';
48
48
  if (node[AstNodeIndices.Style] != null) {
49
49
  result.value += ', ' + node[AstNodeIndices.Style];
50
50
  }
51
51
  result.value += '}';
52
- return;
52
+ break;
53
53
  case FormatJsNodeType.Time:
54
54
  result.value += '{' + node[AstNodeIndices.Value] + ', time';
55
55
  if (node[AstNodeIndices.Style] != null) {
56
56
  result.value += ', ' + node[AstNodeIndices.Style];
57
57
  }
58
58
  result.value += '}';
59
- return;
59
+ break;
60
60
  case FormatJsNodeType.Number:
61
61
  result.value += '{' + node[AstNodeIndices.Value] + ', number';
62
62
  if (node[AstNodeIndices.Style] != null) {
63
63
  result.value += ', ' + node[AstNodeIndices.Style];
64
64
  }
65
65
  result.value += '}';
66
- return;
66
+ break;
67
67
  case FormatJsNodeType.Plural: {
68
68
  const pluralType =
69
69
  node[AstNodeIndices.PluralType] == 'ordinal' ? 'selectordinal' : 'plural';
70
- result.value += '{' + node[AstNodeIndices.Value] + ', ' + pluralType + ', ';
70
+ result.value += '{' + node[AstNodeIndices.Value] + ', ' + pluralType + ',';
71
71
  if (node[AstNodeIndices.Offset]) {
72
- result.value += 'offset:' + node[AstNodeIndices.Offset];
72
+ result.value += ' offset:' + node[AstNodeIndices.Offset];
73
73
  }
74
74
  for (const [name, arm] of Object.entries(node[AstNodeIndices.Options])) {
75
75
  result.value += ' ' + name + ' {';
76
76
  serializeAst(arm, result);
77
77
  result.value += '}';
78
78
  }
79
- return;
79
+ result.value += '}';
80
+ break;
80
81
  }
81
82
  case FormatJsNodeType.Pound:
82
83
  result.value += '#';
83
- return;
84
+ break;
84
85
  case FormatJsNodeType.Select: {
85
- result.value += '{' + node[AstNodeIndices.Value] + ', select, ';
86
+ result.value += '{' + node[AstNodeIndices.Value] + ', select,';
86
87
  for (const [name, arm] of Object.entries(node[AstNodeIndices.Options])) {
87
88
  result.value += ' ' + name + ' {';
88
89
  serializeAst(arm, result);
89
90
  result.value += '}';
90
91
  }
91
- return;
92
+ result.value += '}';
93
+ break;
92
94
  }
93
95
  case FormatJsNodeType.Tag:
94
96
  serializeAstTag(node, result);
95
- return;
97
+ break;
96
98
  }
97
99
  }
98
100
  }
@@ -103,38 +105,39 @@ function serializeAstTag(node: TagNode, result: { value: string }) {
103
105
  result.value += '**';
104
106
  serializeAst(node[AstNodeIndices.Children], result);
105
107
  result.value += '**';
106
- return;
108
+ break;
107
109
  case '$i':
108
110
  result.value += '*';
109
111
  serializeAst(node[AstNodeIndices.Children], result);
110
112
  result.value += '*';
111
- return;
113
+ break;
112
114
  case '$code':
113
115
  result.value += '`';
114
116
  serializeAst(node[AstNodeIndices.Children], result);
115
117
  result.value += '`';
116
- return;
118
+ break;
117
119
  case '$p':
118
120
  serializeAst(node[AstNodeIndices.Children], result);
119
121
  result.value += '\n\n';
120
- return;
122
+ break;
121
123
  case '$link':
122
124
  // The target is the first child of the link. We don't have to care if it's a placeholder
123
125
  // or not, because the serialization will automatically remove the extra empty.
124
- const [target, ...children] = node[AstNodeIndices.Children];
126
+ const children = node[AstNodeIndices.Children];
127
+ const target = node[AstNodeIndices.Control];
125
128
  result.value += '[';
126
129
  serializeAst(children, result);
127
130
  result.value += '](';
128
131
  if (target != null) {
129
- serializeAst([target], result);
132
+ serializeAst(target, result);
130
133
  }
131
134
  result.value += ')';
132
- return;
135
+ break;
133
136
  default:
134
137
  // Any other tag name is a hook, which just adds the `$[` on a link tag.
135
138
  result.value += '$[';
136
139
  serializeAst(node[AstNodeIndices.Children], result);
137
140
  result.value += '](' + node[AstNodeIndices.Value] + ')';
138
- return;
141
+ break;
139
142
  }
140
143
  }