@formatjs/ts-transformer 3.13.34 → 3.14.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_esnext/src/transform.js +36 -0
- package/package.json +11 -12
- package/src/transform.js +36 -0
|
@@ -162,6 +162,24 @@ function extractMessageDescriptor(ts, node, { overrideIdFn, extractSourceLocatio
|
|
|
162
162
|
break;
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
+
// {id: dedent`id`}
|
|
166
|
+
else if (ts.isTaggedTemplateExpression(initializer)) {
|
|
167
|
+
const { template } = initializer;
|
|
168
|
+
if (!ts.isNoSubstitutionTemplateLiteral(template)) {
|
|
169
|
+
throw new Error('Tagged template expression must be no substitution');
|
|
170
|
+
}
|
|
171
|
+
switch (name.text) {
|
|
172
|
+
case 'id':
|
|
173
|
+
msg.id = template.text;
|
|
174
|
+
break;
|
|
175
|
+
case 'defaultMessage':
|
|
176
|
+
msg.defaultMessage = template.text;
|
|
177
|
+
break;
|
|
178
|
+
case 'description':
|
|
179
|
+
msg.description = template.text;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
165
183
|
else if (ts.isJsxExpression(initializer) && initializer.expression) {
|
|
166
184
|
// <FormattedMessage foo={'barbaz'} />
|
|
167
185
|
if (ts.isStringLiteral(initializer.expression)) {
|
|
@@ -197,6 +215,24 @@ function extractMessageDescriptor(ts, node, { overrideIdFn, extractSourceLocatio
|
|
|
197
215
|
break;
|
|
198
216
|
}
|
|
199
217
|
}
|
|
218
|
+
// <FormattedMessage foo={dedent`dedent Hello World!`} />
|
|
219
|
+
else if (ts.isTaggedTemplateExpression(initializer.expression)) {
|
|
220
|
+
const { expression: { template }, } = initializer;
|
|
221
|
+
if (!ts.isNoSubstitutionTemplateLiteral(template)) {
|
|
222
|
+
throw new Error('Tagged template expression must be no substitution');
|
|
223
|
+
}
|
|
224
|
+
switch (name.text) {
|
|
225
|
+
case 'id':
|
|
226
|
+
msg.id = template.text;
|
|
227
|
+
break;
|
|
228
|
+
case 'defaultMessage':
|
|
229
|
+
msg.defaultMessage = template.text;
|
|
230
|
+
break;
|
|
231
|
+
case 'description':
|
|
232
|
+
msg.description = template.text;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
200
236
|
// <FormattedMessage foo={'bar' + 'baz'} />
|
|
201
237
|
else if (ts.isBinaryExpression(initializer.expression)) {
|
|
202
238
|
const { expression } = initializer;
|
package/package.json
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/ts-transformer",
|
|
3
3
|
"description": "TS Compiler transformer for formatjs",
|
|
4
|
-
"version": "3.
|
|
5
|
-
"license": "MIT",
|
|
4
|
+
"version": "3.14.1",
|
|
6
5
|
"author": "Long Ho <holevietlong@gmail.com>",
|
|
7
|
-
"
|
|
6
|
+
"bugs": "https://github.com/formatjs/formatjs/issues",
|
|
8
7
|
"dependencies": {
|
|
9
|
-
"@
|
|
8
|
+
"@formatjs/icu-messageformat-parser": "2.11.3",
|
|
10
9
|
"@types/node": "^22.0.0",
|
|
11
10
|
"chalk": "^4.1.2",
|
|
12
|
-
"json-stable-stringify": "^1.
|
|
11
|
+
"json-stable-stringify": "^1.3.0",
|
|
13
12
|
"tslib": "^2.8.0",
|
|
14
|
-
"typescript": "
|
|
15
|
-
"@formatjs/icu-messageformat-parser": "2.11.2"
|
|
13
|
+
"typescript": "5.8.3"
|
|
16
14
|
},
|
|
17
15
|
"devDependencies": {
|
|
18
16
|
"ts-jest": "^29"
|
|
19
17
|
},
|
|
20
|
-
"peerDependencies": {
|
|
21
|
-
"ts-jest": "^29"
|
|
22
|
-
},
|
|
23
|
-
"bugs": "https://github.com/formatjs/formatjs/issues",
|
|
24
18
|
"homepage": "https://github.com/formatjs/formatjs#readme",
|
|
25
19
|
"keywords": [
|
|
26
20
|
"i18n",
|
|
@@ -30,11 +24,16 @@
|
|
|
30
24
|
"transformer",
|
|
31
25
|
"typescript"
|
|
32
26
|
],
|
|
27
|
+
"license": "MIT",
|
|
33
28
|
"main": "index.js",
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"ts-jest": "^29"
|
|
31
|
+
},
|
|
34
32
|
"peerDependenciesMeta": {
|
|
35
33
|
"ts-jest": {
|
|
36
34
|
"optional": true
|
|
37
35
|
}
|
|
38
36
|
},
|
|
39
|
-
"repository": "formatjs/formatjs.git"
|
|
37
|
+
"repository": "formatjs/formatjs.git",
|
|
38
|
+
"types": "index.d.ts"
|
|
40
39
|
}
|
package/src/transform.js
CHANGED
|
@@ -167,6 +167,24 @@ function extractMessageDescriptor(ts, node, { overrideIdFn, extractSourceLocatio
|
|
|
167
167
|
break;
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
|
+
// {id: dedent`id`}
|
|
171
|
+
else if (ts.isTaggedTemplateExpression(initializer)) {
|
|
172
|
+
const { template } = initializer;
|
|
173
|
+
if (!ts.isNoSubstitutionTemplateLiteral(template)) {
|
|
174
|
+
throw new Error('Tagged template expression must be no substitution');
|
|
175
|
+
}
|
|
176
|
+
switch (name.text) {
|
|
177
|
+
case 'id':
|
|
178
|
+
msg.id = template.text;
|
|
179
|
+
break;
|
|
180
|
+
case 'defaultMessage':
|
|
181
|
+
msg.defaultMessage = template.text;
|
|
182
|
+
break;
|
|
183
|
+
case 'description':
|
|
184
|
+
msg.description = template.text;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
170
188
|
else if (ts.isJsxExpression(initializer) && initializer.expression) {
|
|
171
189
|
// <FormattedMessage foo={'barbaz'} />
|
|
172
190
|
if (ts.isStringLiteral(initializer.expression)) {
|
|
@@ -202,6 +220,24 @@ function extractMessageDescriptor(ts, node, { overrideIdFn, extractSourceLocatio
|
|
|
202
220
|
break;
|
|
203
221
|
}
|
|
204
222
|
}
|
|
223
|
+
// <FormattedMessage foo={dedent`dedent Hello World!`} />
|
|
224
|
+
else if (ts.isTaggedTemplateExpression(initializer.expression)) {
|
|
225
|
+
const { expression: { template }, } = initializer;
|
|
226
|
+
if (!ts.isNoSubstitutionTemplateLiteral(template)) {
|
|
227
|
+
throw new Error('Tagged template expression must be no substitution');
|
|
228
|
+
}
|
|
229
|
+
switch (name.text) {
|
|
230
|
+
case 'id':
|
|
231
|
+
msg.id = template.text;
|
|
232
|
+
break;
|
|
233
|
+
case 'defaultMessage':
|
|
234
|
+
msg.defaultMessage = template.text;
|
|
235
|
+
break;
|
|
236
|
+
case 'description':
|
|
237
|
+
msg.description = template.text;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
205
241
|
// <FormattedMessage foo={'bar' + 'baz'} />
|
|
206
242
|
else if (ts.isBinaryExpression(initializer.expression)) {
|
|
207
243
|
const { expression } = initializer;
|