import ts from 'typescript' ; import * as utils from './utils' ; export function getName ( node ) { return node . name ; } export function getDeclarations ( node ) { const declarations = utils . getValueOrUndefined ( node . declarations ) ; return declarations === undefined ? [ ] : declarations ; } export function getValueDeclaration ( node ) { return utils . getValueOrUndefined ( node . valueDeclaration ) ; } export function getValueDeclarationOrThrow ( node ) { return utils . throwIfNullOrUndefined ( getValueDeclaration ( node ) , 'value declaration' ) ; } function hasSymbolFlag ( node , flag ) { return ( node . flags & flag ) !== 0 ; } export function getAliasedSymbol ( typeChecker , node ) { if ( hasSymbolFlag ( node , ts . SymbolFlags . Alias ) ) { return utils . getValueOrUndefined ( typeChecker . getAliasedSymbol ( node ) ) ; } if ( hasSymbolFlag ( node , ts . SymbolFlags . TypeAlias ) ) { const type = utils . getValueOrUndefined ( typeChecker . getDeclaredTypeOfSymbol ( node ) ) ; if ( type !== undefined ) { return utils . getValueOrUndefined ( type . getSymbol ( ) ) ; } } return undefined ; } export function getSymbolOrAlias ( typeChecker , symbol ) { const alias = getAliasedSymbol ( typeChecker , symbol ) ; return alias === undefined ? symbol : alias ; } export function getMembers ( node ) { const members = utils . getValueOrUndefined ( node . members ) ; return members === undefined ? utils . getValueOrUndefined ( node . exports ) : members ; } export function getMembersOrThrow ( node ) { return utils . throwIfNullOrUndefined ( getMembers ( node ) , 'members' ) ; } export function getMember ( node , name ) { const members = getMembers ( node ) ; return members === undefined ? undefined : members . get ( name as ts . __String ) ; } export function getMemberOrThrow ( node , name ) { return utils . throwIfNullOrUndefined ( getMember ( node , name ) , 'symbol member' ) ; } export function getExports ( node ) { return utils . getValueOrUndefined ( node . exports ) ; } export function getExportsOrThrow ( node ) { return utils . throwIfNullOrUndefined ( getExports ( node ) , 'exports' ) ; } export function getExport ( node , name ) { const exports = getExports ( node ) ; return exports === undefined ? undefined : exports . get ( name as ts . __String ) ; } export function getExportOrThrow ( node , name ) { return utils . throwIfNullOrUndefined ( getExport ( node , name ) , 'symbol export' ) ; } export function isArgumentsSymbol ( typeChecker , node ) { return typeChecker . isArgumentsSymbol ( node ) ; } export function getTarget ( symbol ) { const symbolAny = symbol ; return symbolAny . target == undefined ? symbol : symbolAny . target ; } export function getParent ( symbol ) { const symbolAny = symbol ; return symbolAny . parent == undefined ? undefined : symbolAny . parent ; }