Skip to content

Commit 7b734e6

Browse files
author
Sergio
committed
feat: removeMacroWrap introduced to other macros
1 parent 030498b commit 7b734e6

File tree

3 files changed

+64
-33
lines changed

3 files changed

+64
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
11
import { i18n } from "@lingui/core";
2-
import { t } from "@lingui/macro";
2+
import { t, plural, select, selectOrdinal } from "@lingui/macro";
33

4-
i18n._(t`Some input`)
4+
i18n._(t`Some input`)
5+
i18n._(
6+
plural({
7+
value: 1,
8+
one: 'SORT_#_RESULT_BY:',
9+
other: 'SORT_#_RESULT_BY:',
10+
zero: 'SORT_#_RESULTS_BY:'
11+
})
12+
)
13+
i18n._(
14+
select({
15+
value: 2,
16+
other: 'SORT_#_RESULT_BY:',
17+
})
18+
)
19+
i18n._(
20+
selectOrdinal({
21+
value: 1,
22+
one: 'SORT_#_RESULT_BY:',
23+
other: 'SORT_#_RESULT_BY:',
24+
zero: 'SORT_#_RESULTS_BY:'
25+
})
26+
)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
import { i18n } from "@lingui/core";
2-
import { t } from "@lingui/macro";
2+
import { t, plural, select, selectOrdinal } from "@lingui/macro";
33

4-
t`Some input`
4+
t`Some input`
5+
plural(1, {
6+
one: 'SORT_#_RESULT_BY:',
7+
other: 'SORT_#_RESULT_BY:',
8+
zero: 'SORT_#_RESULTS_BY:'
9+
})
10+
select({
11+
value: 2,
12+
other: 'SORT_#_RESULT_BY:',
13+
})
14+
selectOrdinal({
15+
value: 1,
16+
one: 'SORT_#_RESULT_BY:',
17+
other: 'SORT_#_RESULT_BY:',
18+
zero: 'SORT_#_RESULTS_BY:'
19+
})

transforms/v2-to-v3.ts

+23-29
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const transform: Transform = (fileInfo, api) => {
99
removeMacroWrap(root, j)
1010
changeReactImportToNewImports(root, j)
1111
changeJsxToCoreDeprecatedFuncs(root, j)
12-
// replaceDeprecatedMethodsToMacros(root, j)
1312

1413
return root.toSource();
1514
};
@@ -153,13 +152,6 @@ function pluralPropsChanges(root, j) {
153152
})
154153
}
155154

156-
/**
157-
* i18n.t(), i18n.plural(), i18n.select() and i18n.selectOrdinal()
158-
* methods are removed and replaced with macros.
159-
*/
160-
function replaceDeprecatedMethodsToMacros(root , j: JSCodeshift) {
161-
}
162-
163155
/**
164156
* Rename I18nProvider.defaultRender prop to I18nProvider.defaultComponent
165157
*/
@@ -178,29 +170,31 @@ function renameDefaultRenderToDefaultComponent(root , j: JSCodeshift) {
178170
}
179171

180172
/**
181-
* Macros don't need to be wrapped inside i18n._: i18n._(t'Message') => t'Message'
173+
* Macros don't need to be wrapped inside i18n._: i18n._(t'Message') => t'Message'
174+
* i18n._(t``), i18n._(plural``), i18n._(select``) and i18n._(selectOrdinal``)
182175
*/
183-
function removeMacroWrap(root , j: JSCodeshift) {
176+
function removeMacroWrap(root, j: JSCodeshift) {
184177
return root
185-
.find(j.CallExpression, {
186-
arguments: [
187-
{
188-
tag: {
189-
name: "t"
178+
.find(j.CallExpression, {
179+
// if we want to filter by the argument...
180+
// arguments: [
181+
// {
182+
// tag: {
183+
// name: "t"
184+
// }
185+
// }
186+
// ],
187+
callee: {
188+
object: {
189+
name: "i18n"
190+
},
191+
property: {
192+
name: "_"
190193
}
191194
}
192-
],
193-
callee: {
194-
object: {
195-
name: "i18n"
196-
},
197-
property: {
198-
name: "_"
199-
}
200-
}
201-
})
202-
.replaceWith((nodePath) => {
203-
const { node } = nodePath;
204-
return node.arguments;
205-
})
195+
})
196+
.replaceWith((nodePath) => {
197+
const { node } = nodePath;
198+
return node.arguments;
199+
})
206200
}

0 commit comments

Comments
 (0)