import { GET_TYPE_FNC_NAME , TYPE_ID_PROPERTY_NAME } from "tst-reflect" ; import * as ts from "typescript" ; import { Context } from "../contexts/Context" ; import { hasReflectDecoratorJsDoc , hasReflectGenericJsDoc } from "../helpers" ; import { processDecorator } from "../processDecorator" ; import { processGenericCallExpression } from "../processGenericCallExpression" ; import { processGetTypeCallExpression } from "../processGetTypeCallExpression" ; import DeclarationVisitor from "./declarationVisitor" ; param nodeToVisit param context export function mainVisitor ( nodeToVisit , context ) { const node = DeclarationVisitor . instance . visitDeclaration ( nodeToVisit , context ) ; if ( node === undefined ) { return nodeToVisit ; } if ( ts . isCallExpression ( node ) ) { if ( ts . isIdentifier ( node . expression ) && node . expression . escapedText == GET_TYPE_FNC_NAME ) { if ( node . pos == - 1 ) { return node ; } const fncType = context . typeChecker . getTypeAtLocation ( node . expression ) ; if ( fncType . getProperty ( TYPE_ID_PROPERTY_NAME ) ) { const res = processGetTypeCallExpression ( node , context ) ; if ( res ) { return res ; } } } else { let identifier = undefined ; if ( ts . isIdentifier ( node . expression ) ) { identifier = node . expression ; } else if ( ts . isPropertyAccessExpression ( node . expression ) ) { identifier = node . expression . name ; } if ( identifier !== undefined ) { const type = context . typeChecker . getTypeAtLocation ( identifier ) ; if ( node . typeArguments ?. length ) { const res = processGenericCallExpression ( node , type , context ) ; if ( res ) { return ts . visitEachChild ( res , context . visitor , context . transformationContext ) ; } } } } } else if ( ts . isDecorator ( node ) && ts . isClassDeclaration ( node . parent ) && ts . isCallExpression ( node . expression ) ) { const type = context . typeChecker . getTypeAtLocation ( node . expression . expression ) ; if ( hasReflectDecoratorJsDoc ( type . getSymbol ( ) ) ) { const res = processDecorator ( node , type , context ) ; if ( res ) { return ts . visitEachChild ( res , context . visitor , context . transformationContext ) ; } } } return ts . visitEachChild ( node , context . visitor , context . transformationContext ) ; }