import { PluginPass } from '@babel/core' ; import { TSTypeParameter , TSTypeParameterDeclaration , TSTypeParameterInstantiation , TypeParameter , TypeParameterDeclaration , TypeParameterInstantiation , tsTypeParameter , tsTypeParameterDeclaration , tsTypeParameterInstantiation , } from '@babel/types' ; import { WARNINGS , logWarning } from '../util/warnings' ; import { convertFlowType } from './flow-type' ; export function convertTypeParameter ( node , state ) { const typeParameter = tsTypeParameter ( undefined , undefined , node . name || '' ) ; if ( node . bound ) { typeParameter . constraint = convertFlowType ( node . bound . typeAnnotation , state ) ; } if ( node . default ) { typeParameter . default = convertFlowType ( node . default , state ) ; } if ( node . variance ) { logWarning ( WARNINGS . genericTypeAnnotation . variance , state . file . code , node . variance . loc ) ; } return typeParameter ; } export function convertTypeParameterDeclaration ( node , state ) { if ( ! node ) { return null ; } return tsTypeParameterDeclaration ( node . params . map ( node => convertTypeParameter ( node , state ) ) ) ; } export function convertTypeParameterInstantiation ( node , state ) { if ( ! node ) { return null ; } return tsTypeParameterInstantiation ( node . params . map ( param => convertFlowType ( param , state ) ) ) ; }