@@ -10,6 +10,7 @@ const transform: Transform = (fileInfo, api, options) => {
1010 changeJsxToCoreDeprecatedFuncs ( root , j )
1111 changeFromMacroToCore ( root , j )
1212 pluralPropsChanges ( root , j )
13+ tWithIdPropsChanges ( root , j )
1314
1415 return root . toSource ( options . printOptions ) ;
1516} ;
@@ -235,4 +236,31 @@ function removeMacroWrap(root, j: JSCodeshift) {
235236 const { node } = nodePath ;
236237 return node . arguments ;
237238 } )
238- }
239+ }
240+
241+ /**
242+ * t arguments changed. Id needs to be passed as a part of an object.
243+ * t('id')'Message') => t({ id: 'id', message: `Message` })
244+ * No attempts are made to convert template literal into a regular string; this
245+ * is a project-specific codestyle rule that should be fixed with Prettier or
246+ * eslint.
247+ */
248+ function tWithIdPropsChanges ( root , j : JSCodeshift ) {
249+ return root
250+ . find ( j . TaggedTemplateExpression , {
251+ tag : {
252+ callee : {
253+ name : "t"
254+ }
255+ }
256+ } )
257+ . replaceWith ( ( nodePath ) => {
258+ const id = nodePath . node . tag . arguments [ 0 ] . value ;
259+ return j . callExpression ( nodePath . node . tag . callee , [
260+ j . objectExpression ( [
261+ j . property ( "init" , j . identifier ( "id" ) , j . literal ( id ) ) ,
262+ j . property ( "init" , j . identifier ( "message" ) , nodePath . node . quasi )
263+ ] )
264+ ] ) ;
265+ } )
266+ }
0 commit comments