File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed 
codemods/reverse-identifiers Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ import  {  applyTransform  }  from  "@codeshift/test-utils" ; 
2+ import  *  as  transformer  from  "./transform" ; 
3+ 
4+ describe ( "codeshift-community#reverse-identifiers transform" ,  ( )  =>  { 
5+   it ( "should transform correctly" ,  async  ( )  =>  { 
6+     const  result  =  await  applyTransform ( 
7+       transformer , 
8+       ` 
9+ var foo = 'codeshift-community'; 
10+ console.log(foo); 
11+       ` , 
12+       {  parser : "tsx"  } 
13+     ) ; 
14+ 
15+     expect ( result ) . toMatchInlineSnapshot ( ` 
16+       "var oof = 'codeshift-community'; 
17+       elosnoc.gol(oof);" 
18+     ` ) ; 
19+   } ) ; 
20+ } ) ; 
Original file line number Diff line number Diff line change 1+ import  {  API ,  FileInfo ,  Options  }  from  "jscodeshift" ; 
2+ 
3+ export  default  function  transformer ( 
4+   file : FileInfo , 
5+   {  jscodeshift : j  } : API , 
6+   options : Options 
7+ )  { 
8+   const  source  =  j ( file . source ) ; 
9+ 
10+   /** 
11+    * Codemod logic goes here 👇 
12+    * ----- 
13+    * This is where the core logic for your codemod will go, 
14+    * consider grouping specific actions into 'motions' and running them in sequence 
15+    * 
16+    * See this page for more information: 
17+    * https://codeshiftcommunity.github.io/CodeshiftCommunity/docs/authoring#motions 
18+    */ 
19+   source . find ( j . Identifier ) . forEach ( ( path )  =>  { 
20+     j ( path ) . replaceWith ( 
21+       j . identifier ( 
22+         path . node . name 
23+           . split ( "" ) 
24+           . reverse ( ) 
25+           . join ( "" ) 
26+       ) 
27+     ) ; 
28+   } ) ; 
29+ 
30+   /** 
31+    * Return your modified AST here 👇 
32+    * ----- 
33+    * This is where your modified AST will be transformed back into a string 
34+    * and written back to the file. 
35+    */ 
36+   return  source . toSource ( options . printOptions ) ; 
37+ } 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments