@@ -25,11 +25,11 @@ function changeJsxToCoreDeprecatedFuncs(root, j: JSCodeshift) {
25
25
[
26
26
{
27
27
component : "DateFormat" ,
28
- macro : "date"
28
+ macro : "i18n. date"
29
29
} ,
30
30
{
31
31
component : "NumberFormat" ,
32
- macro : "number"
32
+ macro : "i18n. number"
33
33
}
34
34
] . forEach ( mapper => {
35
35
root
@@ -60,7 +60,17 @@ function changeJsxToCoreDeprecatedFuncs(root, j: JSCodeshift) {
60
60
}
61
61
62
62
// if someone uses the components inside ternaries we can't add {number()}, must be just number()
63
- return path . parentPath . value . type === "ConditionalExpression" ? ast : j . jsxExpressionContainer ( ast ) ;
63
+ if ( path . parentPath . value . type === "ConditionalExpression" || path . parentPath . value . type === "VariableDeclarator" ) {
64
+ return ast
65
+ }
66
+
67
+ // if is a direct return, just add parenthesis
68
+ if ( path . parentPath . value . type === "ReturnStatement" ) {
69
+ return j . parenthesizedExpression ( ast ) ;
70
+ }
71
+
72
+ // if not, just add {}
73
+ return j . jsxExpressionContainer ( ast ) ;
64
74
} ) ;
65
75
} )
66
76
@@ -80,8 +90,8 @@ function changeReactImportToNewImports(root: Collection , j: JSCodeshift) {
80
90
} ) ;
81
91
82
92
migrateTo ( root , linguiReactImports , j , "Trans" , "Trans" , "@lingui/macro" ) ;
83
- migrateTo ( root , linguiReactImports , j , "NumberFormat" , "number " , "@lingui/core" ) ;
84
- migrateTo ( root , linguiReactImports , j , "DateFormat" , "date " , "@lingui/core" ) ;
93
+ migrateTo ( root , linguiReactImports , j , "NumberFormat" , "i18n " , "@lingui/core" ) ;
94
+ migrateTo ( root , linguiReactImports , j , "DateFormat" , "i18n " , "@lingui/core" ) ;
85
95
}
86
96
87
97
/**
@@ -96,8 +106,8 @@ function changeFromMacroToCore(root: Collection , j: JSCodeshift) {
96
106
} ) ;
97
107
98
108
migrateTo ( root , linguiMacroImports , j , "number" , "number" , "@lingui/core" ) ;
99
- migrateTo ( root , linguiMacroImports , j , "date" , "date " , "@lingui/core" ) ;
100
- migrateTo ( root , linguiMacroImports , j , "NumberFormat" , "number " , "@lingui/core" ) ;
109
+ migrateTo ( root , linguiMacroImports , j , "date" , "i18n " , "@lingui/core" ) ;
110
+ migrateTo ( root , linguiMacroImports , j , "NumberFormat" , "i18n " , "@lingui/core" ) ;
101
111
}
102
112
103
113
/**
@@ -120,8 +130,10 @@ function migrateTo(root, linguiReactImports, j, lookupImport, newLookupImport, n
120
130
value : newPackageName
121
131
}
122
132
} ) ;
133
+
123
134
linguiReactImports . forEach ( ( path ) => {
124
135
const node = path . value ;
136
+ if ( ! node ) return ;
125
137
const transImportIndex = node . specifiers . findIndex ( ( el ) => el . imported . name === lookupImport ) ;
126
138
127
139
if ( transImportIndex !== - 1 ) {
0 commit comments