import { API , FileInfo , Options } from 'jscodeshift' ; export function fixtureUndefined ( file , api , options ) { const j = api . jscodeshift ; const root = j ( file . source ) ; const printOptions = options . printOptions || { quote : 'single' , trailingComma : false , lineTerminator : '\n' } ; root . find ( j . IfStatement ) . filter ( ( path ) => { if ( path . node . test . type !== 'UnaryExpression' ) { return false ; } return true ; } ) . forEach ( ( path ) => { const id = path . node . test . argument . name ; const newCond = j . ifStatement ( j . binaryExpression ( '===' , j . identifier ( id ) , j . identifier ( 'undefined' ) ) , path . node . consequent , path . node . alternate ) ; j ( path ) . replaceWith ( newCond ) ; } ) ; return root . toSource ( printOptions ) ; } export const parser = 'tsx' ; export default fixtureUndefined ;