import { PluginPass } from '@babel/core' ; import { DeclareInterface , InterfaceDeclaration , InterfaceExtends , InterfaceTypeAnnotation , TSExpressionWithTypeArguments , TSInterfaceDeclaration , TSTypeLiteral , TypeAlias , isTSTypeLiteral , tsExpressionWithTypeArguments , tsInterfaceBody , tsInterfaceDeclaration , } from '@babel/types' ; import { convertIdentifier } from './identifier' ; import { convertObjectTypeAnnotation } from './object' ; import { convertTypeParameterDeclaration , convertTypeParameterInstantiation , } from './type-parameter' ; export interface TypeAliasForInterfaceType extends TypeAlias { right : InterfaceTypeAnnotation ; } export function convertInterfaceExtends ( node , state ) { const id = convertIdentifier ( node . id ) ; const typeParameters = convertTypeParameterInstantiation ( node . typeParameters , state ) ; return tsExpressionWithTypeArguments ( id , typeParameters ) ; } export function convertInterfaceDeclaration ( node , state ) { const typeParameters = convertTypeParameterDeclaration ( node . typeParameters , state ) ; const bodyMembers = convertObjectTypeAnnotation ( node . body , state ) ; const body = tsInterfaceBody ( isTSTypeLiteral ( bodyMembers ) ? bodyMembers . members : [ ] ) ; const _extends = node . extends && node . extends . length ? node . extends . map ( interfaceExtends => convertInterfaceExtends ( interfaceExtends , state ) ) : null ; return tsInterfaceDeclaration ( node . id , typeParameters , _extends , body ) ; } export function convertInterfaceTypeAlias ( node , state ) { const { right : _interface } = node ; const typeParameters = convertTypeParameterDeclaration ( node . typeParameters , state ) ; const bodyMembers = convertObjectTypeAnnotation ( _interface . body , state ) ; const body = tsInterfaceBody ( isTSTypeLiteral ( bodyMembers ) ? bodyMembers . members : [ ] ) ; const _extends = _interface . extends && _interface . extends . length ? _interface . extends . map ( _extends => convertInterfaceExtends ( _extends , state ) ) : null ; return tsInterfaceDeclaration ( node . id , typeParameters , _extends , body ) ; } export function convertInterfaceTypeAnnotation ( node , state ) { return convertObjectTypeAnnotation ( node . body , state ) as TSTypeLiteral ; }