import traverse from '@babel/traverse' ; import * as t from '@babel/types' ; import type { Result } from './types' ; param ast export const getDefaultExport = ( ast ) : Result < t . ExportDefaultDeclaration > | undefined => { let result ; traverse ( ast , { ExportDefaultDeclaration ( path ) { result = { path , node : path . node . declaration } ; path . stop ( ) ; } , } ) ; return result ; } ; param ast param exportName export const getNamedExport = ( ast , exportName ) : Result < t . ExportNamedDeclaration > | undefined => { let result ; traverse ( ast , { ExportNamedDeclaration ( path ) { const { node } = path ; const declarations = t . isVariableDeclaration ( node . declaration ) ? node . declaration . declarations : node . specifiers ; ( declarations as ( t . VariableDeclarator | t . ExportSpecifier ) [ ] ) . find ( ( declaration ) => { const identifier = t . isVariableDeclarator ( declaration ) ? declaration . id : declaration . exported ; if ( t . isIdentifier ( identifier , { name : exportName } ) ) { result = { path , node : t . isVariableDeclarator ( declaration ) ? declaration . init : identifier , } ; path . stop ( ) ; return true ; } return false ; } ) ; } , } ) ; return result ; } ;