import * as path from "path" ; import { REFLECT_GENERIC_DECORATOR , REFLECT_DECORATOR_DECORATOR , TypeKind } from "tst-reflect" ; import * as ts from "typescript" ; import TransformerContext from "./contexts/TransformerContext" ; /**
 * Name of parameter for method/function declarations containing generic getType() calls
 */ export const GENERIC_PARAMS = "__genericParams__" ; /**
 * Package name/identifier
 */ export const PACKAGE_ID = "tst-reflect-transformer" ; /**
 * Name of decorator or JSDoc comment marking method for tracing
 */ export const TRACE_DECORATOR = "trace" ; param symbol param checker export function getType ( symbol , checker ) { if ( symbol . flags == ts . SymbolFlags . Interface || symbol . flags == ts . SymbolFlags . Alias ) { return checker . getDeclaredTypeOfSymbol ( symbol ) ; } if ( ! symbol . declarations ) { throw new Error ( "Unable to resolve declarations of symbol." ) ; } return checker . getTypeOfSymbolAtLocation ( symbol , symbol . declarations [ 0 ] ) ; } param symbol export function getTypeKind ( symbol ) { if ( ( symbol . flags & ts . SymbolFlags . Class ) == ts . SymbolFlags . Class ) { return TypeKind . Class ; } if ( ( symbol . flags & ts . SymbolFlags . Interface ) == ts . SymbolFlags . Interface ) { return TypeKind . Interface ; } throw new Error ( "Unknown type kind" ) ; } const nodeModulesPattern = "/node_modules/" ; param typeSymbol export function getTypeFullName ( typeSymbol ? ) { if ( ! typeSymbol ) { return undefined ; } if ( ! typeSymbol . declarations ) { throw new Error ( "Unable to resolve declarations of symbol." ) ; } let { packageName , rootDir } = TransformerContext . instance . config ; let filePath = typeSymbol . declarations [ 0 ] . getSourceFile ( ) . fileName ; const nodeModulesIndex = filePath . lastIndexOf ( nodeModulesPattern ) ; if ( nodeModulesIndex != - 1 ) { filePath = filePath . slice ( nodeModulesIndex + nodeModulesPattern . length ) ; } else if ( rootDir ) { filePath = packageName + "/" + path . relative ( rootDir , filePath ) . replace ( /\\/g , "/" ) ; } return filePath + ":" + typeSymbol . getName ( ) ; } param value export function isExpression ( value ) { return value . hasOwnProperty ( "kind" ) && ( value . constructor . name == "NodeObject" || value . constructor . name == "IdentifierObject" ) ; } param symbol export function hasReflectGenericJsDoc ( symbol ) { if ( ! symbol ) { return false ; } return symbol . getJsDocTags ( ) . some ( tag => tag . name === REFLECT_GENERIC_DECORATOR ) ; } param symbol export function hasReflectDecoratorJsDoc ( symbol ) { if ( ! symbol ) { return false ; } return symbol . getJsDocTags ( ) . some ( tag => tag . name === REFLECT_DECORATOR_DECORATOR ) ; } param symbol export function hasAnyReflectJsDoc ( symbol ) { if ( ! symbol ) { return false ; } return symbol . getJsDocTags ( ) . some ( tag => tag . name === REFLECT_GENERIC_DECORATOR || tag . name === REFLECT_DECORATOR_DECORATOR ) ; } param fncType export function hasTraceJsDoc ( fncType ) { const symbol = fncType . getSymbol ( ) ; if ( ! symbol ) { return false ; } return symbol . getJsDocTags ( ) . some ( tag => tag . name === TRACE_DECORATOR ) ; } description export function createCtorGetter ( typeCtor ) { if ( ! typeCtor ) { return undefined ; } return ts . factory . createArrowFunction ( undefined , undefined , [ ] , undefined , ts . factory . createToken ( ts . SyntaxKind . EqualsGreaterThanToken ) , typeCtor as ts . Expression ) ; }