import { NodePath } from '@babel/traverse' ; import { ExportDeclaration , ImportDeclaration , ImportSpecifier , isExportNamedDeclaration , isFlow , isFlowType , isImportDeclaration , typeofTypeAnnotation , } from '@babel/types' ; import { convertReactImports } from './react/imports' ; function convertImportSpecifiers ( path ) { const { node } = path ; const specifiers = isImportDeclaration ( node ) ? node . specifiers : [ node ] ; if ( node . importKind === 'typeof' ) { specifiers . forEach ( specifier => { const binding = path . scope . getBinding ( specifier . local . name ) ; if ( binding ) { binding . referencePaths . map ( path => { if ( isFlowType ( path . parent ) ) { path . parentPath . replaceWith ( typeofTypeAnnotation ( path . parent ) ) ; } } ) ; } } ) ; } } export function convertImportDeclaration ( path ) { convertImportSpecifiers ( path ) ; convertReactImports ( path ) ; path . node . importKind = null ; return path . node ; } export function convertImportSpecifier ( path ) { convertImportSpecifiers ( path ) ; path . node . importKind = null ; return path . node ; } export function convertExportDeclaration ( path ) { const { node } = path ; if ( isExportNamedDeclaration ( node ) ) { if ( node . exportKind === 'type' && ! isFlow ( node . declaration ) ) { node . exportKind = null ; } } return path . node ; }