import * as babel from '@babel/core' ; import { NodePath , Visitor } from '@babel/traverse' ; type ImportDeclaration = babel . types . ImportDeclaration ; type Program = babel . types . Program ; export const findImportStatement = ( program , source ) => { let importStatement = null ; const visitor = { ImportDeclaration : path => { if ( path . get ( 'source' ) . node . value === source ) { importStatement = path ; path . stop ( ) ; } } , } ; program . traverse ( visitor ) ; return importStatement ; } ;