@formatjs/ts-transformer 2.12.13 → 2.13.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/package.json +1 -1
- package/src/transform.d.ts +6 -0
- package/src/transform.d.ts.map +1 -1
- package/src/transform.js +6 -4
package/package.json
CHANGED
package/src/transform.d.ts
CHANGED
|
@@ -35,6 +35,12 @@ export interface Opts {
|
|
|
35
35
|
* e.g: `['FormattedFooBarMessage']`.
|
|
36
36
|
*/
|
|
37
37
|
additionalComponentNames?: string[];
|
|
38
|
+
/**
|
|
39
|
+
* Additional function names to extract messages from,
|
|
40
|
+
* e.g: `['formatMessage', '$t']`
|
|
41
|
+
* Default to `['formatMessage']`
|
|
42
|
+
*/
|
|
43
|
+
additionalFunctionNames?: string[];
|
|
38
44
|
/**
|
|
39
45
|
* Opt-in to extract from `intl.formatMessage` call with the same restrictions,
|
|
40
46
|
* e.g: has to be called with object literal such as
|
package/src/transform.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../../../../packages/ts-transformer/src/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,iBAAiB,EAAC,MAAM,SAAS,CAAC;AAG1C,oBAAY,SAAS,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,IAAI,CAAC;AAC9E,oBAAY,aAAa,GAAG,CAC1B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACzB,IAAI,CAAC;AAEV,oBAAY,iBAAiB,GAAG,CAC9B,EAAE,CAAC,EAAE,MAAM,EACX,cAAc,CAAC,EAAE,MAAM,EACvB,WAAW,CAAC,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,MAAM,KACd,MAAM,CAAC;AAQZ,aAAK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YG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;OAEG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;IACpC;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAC;IACnC;;;;OAIG;IACH,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B;;;OAGG;IACH,eAAe,CAAC,EAAE,aAAa,CAAC;IAChC;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAAC;IAC1C;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AA4fD,wBAAgB,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,wDAwBzD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,wDAEnC"}
|
package/src/transform.js
CHANGED
|
@@ -210,7 +210,8 @@ function extractMessageDescriptor(ts, node, _a, sf) {
|
|
|
210
210
|
* @param node
|
|
211
211
|
* @param sf
|
|
212
212
|
*/
|
|
213
|
-
function isIntlFormatMessageCall(ts, node) {
|
|
213
|
+
function isIntlFormatMessageCall(ts, node, additionalFunctionNames) {
|
|
214
|
+
var fnNames = new Set(tslib_1.__spreadArrays(['formatMessage'], additionalFunctionNames));
|
|
214
215
|
var method = node.expression;
|
|
215
216
|
// Handle intl.formatMessage()
|
|
216
217
|
if (ts.isPropertyAccessExpression(method)) {
|
|
@@ -221,7 +222,7 @@ function isIntlFormatMessageCall(ts, node) {
|
|
|
221
222
|
method.expression.name.text === 'intl'));
|
|
222
223
|
}
|
|
223
224
|
// Handle formatMessage()
|
|
224
|
-
return ts.isIdentifier(method) && method.text
|
|
225
|
+
return ts.isIdentifier(method) && fnNames.has(method.text);
|
|
225
226
|
}
|
|
226
227
|
function extractMessageFromJsxComponent(ts, factory, node, opts, sf) {
|
|
227
228
|
var onMsgExtracted = opts.onMsgExtracted;
|
|
@@ -293,7 +294,7 @@ function generateNewProperties(ts, factory, node, msg, ast) {
|
|
|
293
294
|
return newProps;
|
|
294
295
|
}
|
|
295
296
|
function extractMessagesFromCallExpression(ts, factory, node, opts, sf) {
|
|
296
|
-
var onMsgExtracted = opts.onMsgExtracted;
|
|
297
|
+
var onMsgExtracted = opts.onMsgExtracted, additionalFunctionNames = opts.additionalFunctionNames;
|
|
297
298
|
if (isMultipleMessageDecl(ts, node)) {
|
|
298
299
|
var _a = node.arguments, arg = _a[0], restArgs = _a.slice(1);
|
|
299
300
|
var descriptorsObj = void 0;
|
|
@@ -338,7 +339,8 @@ function extractMessagesFromCallExpression(ts, factory, node, opts, sf) {
|
|
|
338
339
|
}
|
|
339
340
|
}
|
|
340
341
|
else if (isSingularMessageDecl(ts, node, opts.additionalComponentNames || []) ||
|
|
341
|
-
(opts.extractFromFormatMessageCall &&
|
|
342
|
+
(opts.extractFromFormatMessageCall &&
|
|
343
|
+
isIntlFormatMessageCall(ts, node, additionalFunctionNames || []))) {
|
|
342
344
|
var _b = node.arguments, descriptorsObj = _b[0], restArgs = _b.slice(1);
|
|
343
345
|
if (ts.isObjectLiteralExpression(descriptorsObj)) {
|
|
344
346
|
var msg = extractMessageDescriptor(ts, descriptorsObj, opts, sf);
|