import * as ts from 'typescript' ; import { getUses } from './getUses' ; export type IdentifiersMap = { readonly [ key ] : ts . Identifier [ ] ; } ; param node returns export function getBindingIdentifiers ( node ) { if ( node . importClause == null ) { return { } ; } const ret = { } ; if ( node . importClause . namedBindings !== undefined ) { if ( ts . isNamespaceImport ( node . importClause . namedBindings ) ) { throw new Error ( 'namespace import are not allowd' ) ; } if ( ts . isNamedImports ( node . importClause . namedBindings ) ) { node . importClause . namedBindings . elements . forEach ( ( { propertyName , name } ) => { const key = propertyName === undefined ? name . text : propertyName . text ; ret [ key ] = getUses ( name ) ; } ) ; } } if ( node . importClause . name !== undefined ) { const then = getUses ( node . importClause . name ) ; ret . default = [ ... ( ret . default === undefined ? [ ] : ret . default ) , ... then ] ; } return ret ; }