import type * as ts from 'typescript' ; import { Scope } from '../../scope/scope' ; import { core } from '../../core/core' ; import { GetMockPropertiesFromDeclarations , GetMockPropertiesFromSymbol , } from '../mock/mockProperties' ; import { isPropertyLike , PropertyLike } from '../mock/propertyLike' ; import { isSignatureLike , SignatureLike } from '../mock/signatureLike' ; export function GetProperties ( node , scope ) { const typeChecker = core . typeChecker ; const type = typeChecker . getTypeAtLocation ( node ) ; const symbols = typeChecker . getPropertiesOfType ( type ) ; if ( ! symbols . length && core . ts . isTypeLiteralNode ( node ) ) { return GetPropertiesFromMembers ( node , scope ) ; } else { const signatures = [ ] ; Array . prototype . push . apply ( signatures , typeChecker . getSignaturesOfType ( type , core . ts . SignatureKind . Call ) ) ; Array . prototype . push . apply ( signatures , typeChecker . getSignaturesOfType ( type , core . ts . SignatureKind . Construct ) ) ; return GetMockPropertiesFromSymbol ( symbols , signatures , scope ) ; } } export function GetPropertiesFromMembers ( node , scope ) { const members = node . members ; const signatures = [ ] ; const properties = [ ] ; for ( let i = 0 ; i < members . length ; i ++ ) { const declaration = members [ i ] ; if ( isSignatureLike ( declaration ) ) { signatures . push ( declaration ) ; } else if ( isPropertyLike ( declaration ) ) { properties . push ( declaration ) ; } } return GetMockPropertiesFromDeclarations ( properties , signatures , scope ) ; }