import { PluginPass } from '@babel/core' ; import { NullableTypeAnnotation , TSUnionType , isTSFunctionType , isTSNullKeyword , tsNullKeyword , tsParenthesizedType , tsUndefinedKeyword , tsUnionType , } from '@babel/types' ; import { convertFlowType } from './flow-type' ; export function convertNullableTypeAnnotation ( node , state , options = { skipUndefined : false , } ) { const tsType = convertFlowType ( node . typeAnnotation , state ) ; const unionElements = [ ] ; if ( ! isTSNullKeyword ( tsType ) ) { unionElements . push ( isTSFunctionType ( tsType ) ? tsParenthesizedType ( tsType ) : tsType ) ; } unionElements . push ( tsNullKeyword ( ) ) ; if ( ! options . skipUndefined ) { unionElements . push ( tsUndefinedKeyword ( ) ) ; } return tsUnionType ( unionElements ) ; }