@@ -31,7 +31,12 @@ import {
3131 removeGlobalModule ,
3232} from "./modules" ;
3333import { replaceTSTypeReference } from "./ts-type" ;
34- import { getMostUsedStringLiteralQuote , isTypeScriptFile } from "./utils" ;
34+ import {
35+ IndentationType ,
36+ getMostUsedIndentationType ,
37+ getMostUsedStringLiteralQuote ,
38+ isTypeScriptFile ,
39+ } from "./utils" ;
3540
3641const transformer = async ( file : FileInfo , api : API ) => {
3742 const j = isTypeScriptFile ( file . path ) ? api . jscodeshift . withParser ( "ts" ) : api . jscodeshift ;
@@ -72,6 +77,7 @@ const transformer = async (file: FileInfo, api: API) => {
7277
7378 // Compute recast options before doing transformations
7479 const quote = getMostUsedStringLiteralQuote ( j , source ) ;
80+ const useTabs = getMostUsedIndentationType ( file . source ) === IndentationType . TAB ;
7581
7682 const awsGlobalConfig = getAwsGlobalConfig ( j , source , v2GlobalName ) ;
7783 for ( const [ v2ClientName , v3ClientMetadata ] of Object . entries ( clientMetadataRecord ) ) {
@@ -106,7 +112,14 @@ const transformer = async (file: FileInfo, api: API) => {
106112 replaceAwsUtilFunctions ( j , source , v2GlobalName ) ;
107113 removeGlobalModule ( j , source , v2GlobalName ) ;
108114
109- return source . toSource ( { quote } ) ;
115+ const sourceString = source . toSource ( { quote, useTabs } ) ;
116+
117+ if ( useTabs ) {
118+ // Refs: https://github.com/benjamn/recast/issues/315
119+ return sourceString . replace ( / { 4 , } / g, "\t" ) ;
120+ }
121+
122+ return sourceString ;
110123} ;
111124
112125export default transformer ;
0 commit comments