import ts = require ( 'typescript' ) ; import { namespaceBlacklist } from './namespaceBlacklist' ; export function isUnique < T > ( value , index , self ) { return self . indexOf ( value ) === index ; } export function removeExportStarPrefix ( path ) { if ( path . startsWith ( '*:' ) ) return path . slice ( 2 ) ; else if ( path . startsWith ( '*as:' ) ) return path . slice ( 4 ) ; return path ; } const whitelist = [ ts . SyntaxKind . MethodDeclaration , ts . SyntaxKind . PropertyAssignment , ts . SyntaxKind . JsxElement , ts . SyntaxKind . JsxSelfClosingElement , ] ; function runForChildren ( next , fun ) { next . getChildren ( ) . filter ( ( c ) => ! namespaceBlacklist . includes ( c . kind ) || whitelist . includes ( c . kind ) ) . forEach ( ( node ) => { fun ( node ) ; } ) ; } export function recurseIntoChildren ( next , fun ) { const alsoProcessChildren = fun ( next ) ; if ( alsoProcessChildren ) { runForChildren ( next , ( node ) => recurseIntoChildren ( node , fun ) ) ; } return alsoProcessChildren ; } export function findAllChildrenOfKind ( node , kind ) { const childrenFound = [ ] ; const innerFindFirstChildOfKind = ( childNode ) : boolean => { if ( childNode . kind === kind ) { childrenFound . push ( childNode ) ; } return true ; } ; recurseIntoChildren ( node , innerFindFirstChildOfKind ) ; return childrenFound ; } export function findFirstChildOfKind ( node , kind ) { let childFound = null ; const innerFindFirstChildOfKind = ( childNode ) : boolean => { if ( ! childFound && childNode . kind === kind ) { childFound = childNode ; return false ; } return true ; } ; recurseIntoChildren ( node , innerFindFirstChildOfKind ) ; return childFound ; }