@@ -13,8 +13,8 @@ import {
1313 PropertyAccessExpression ,
1414 VariableDeclaration ,
1515 Symbol ,
16- NewExpression ,
17- Identifier
16+ Identifier ,
17+ TypeNode
1818} from 'ts-morph' ;
1919import { Function as UniFunction , Dependency , Receiver } from '../types/uniast' ;
2020import { assignSymbolName , SymbolResolver } from '../utils/symbol-resolver' ;
@@ -46,8 +46,13 @@ export class FunctionParser {
4646 // Parse function declarations
4747 const functionDeclarations = sourceFile . getFunctions ( ) ;
4848 for ( const func of functionDeclarations ) {
49- const funcObj = this . parseFunction ( func , moduleName , packagePath , sourceFile ) ;
50- functions [ funcObj . Name ] = funcObj ;
49+ try {
50+ const funcObj = this . parseFunction ( func , moduleName , packagePath , sourceFile ) ;
51+ functions [ funcObj . Name ] = funcObj ;
52+ } catch ( error ) {
53+ console . error ( 'Error processing function:' , func , error ) ;
54+ }
55+
5156 }
5257
5358 // Parse method declarations in classes
@@ -63,22 +68,34 @@ export class FunctionParser {
6368 const methods = cls . getMethods ( ) ;
6469
6570 for ( const method of methods ) {
66- const methodObj = this . parseMethod ( method , moduleName , packagePath , sourceFile , className ) ;
67- functions [ methodObj . Name ] = methodObj ;
71+ try {
72+ const methodObj = this . parseMethod ( method , moduleName , packagePath , sourceFile , className ) ;
73+ functions [ methodObj . Name ] = methodObj ;
74+ } catch ( error ) {
75+ console . error ( 'Error processing method:' , method , error ) ;
76+ }
6877 }
6978
7079 // Parse constructors
7180 const constructors = cls . getConstructors ( ) ;
7281 for ( const ctor of constructors ) {
73- const ctorObj = this . parseConstructor ( ctor , moduleName , packagePath , sourceFile , className ) ;
74- functions [ ctorObj . Name ] = ctorObj ;
82+ try {
83+ const ctorObj = this . parseConstructor ( ctor , moduleName , packagePath , sourceFile , className ) ;
84+ functions [ ctorObj . Name ] = ctorObj ;
85+ } catch ( error ) {
86+ console . error ( 'Error processing constructor:' , ctor , error ) ;
87+ }
7588 }
7689
7790 // Parse static methods
7891 const staticMethods = cls . getStaticMethods ( ) ;
7992 for ( const staticMethod of staticMethods ) {
80- const methodObj = this . parseMethod ( staticMethod , moduleName , packagePath , sourceFile , className ) ;
81- functions [ methodObj . Name ] = methodObj ;
93+ try {
94+ const methodObj = this . parseMethod ( staticMethod , moduleName , packagePath , sourceFile , className ) ;
95+ functions [ methodObj . Name ] = methodObj ;
96+ } catch ( error ) {
97+ console . error ( 'Error processing static method:' , staticMethod , error ) ;
98+ }
8299 }
83100 }
84101
@@ -94,8 +111,13 @@ export class FunctionParser {
94111 } else {
95112 funcName = "anonymous_" + varDecl . getStart ( )
96113 }
97- const funcObj = this . parseArrowFunction ( initializer , funcName , moduleName , packagePath , sourceFile , varDecl ) ;
98- functions [ funcObj . Name ] = funcObj ;
114+ try {
115+ const funcObj = this . parseArrowFunction ( initializer , funcName , moduleName , packagePath , sourceFile , varDecl ) ;
116+ functions [ funcObj . Name ] = funcObj ;
117+ } catch ( error ) {
118+ console . error ( 'Error processing arrow function:' , initializer , error ) ;
119+ }
120+
99121 }
100122 }
101123
@@ -105,8 +127,12 @@ export class FunctionParser {
105127 const methods = iface . getMethods ( ) ;
106128
107129 for ( const method of methods ) {
108- const methodObj = this . parseInterfaceMethod ( method , moduleName , packagePath , sourceFile ) ;
109- functions [ methodObj . Name ] = methodObj ;
130+ try {
131+ const methodObj = this . parseInterfaceMethod ( method , moduleName , packagePath , sourceFile ) ;
132+ functions [ methodObj . Name ] = methodObj ;
133+ } catch ( error ) {
134+ console . error ( 'Error processing interface method:' , method , error ) ;
135+ }
110136 }
111137 }
112138
@@ -414,7 +440,7 @@ export class FunctionParser {
414440 }
415441
416442 // External function could not find decls.
417- if ( resolvedSymbol . isExternal ) {
443+ if ( resolvedSymbol . isExternal ) {
418444 calls . push ( dep ) ;
419445 continue ;
420446 }
@@ -467,10 +493,10 @@ export class FunctionParser {
467493 if ( Node . isIdentifier ( expr ) ) {
468494 lastIdentifier = expr ;
469495 } else if ( Node . isPropertyAccessExpression ( expr ) ) {
470- lastIdentifier = expr . getNameNode ( ) ;
496+ lastIdentifier = expr . getNameNode ( ) ;
471497 }
472498
473- if ( lastIdentifier ) {
499+ if ( lastIdentifier ) {
474500 this . processNewCall ( node , lastIdentifier , moduleName , packagePath , sourceFile , calls , visited ) ;
475501 }
476502 }
@@ -514,7 +540,7 @@ export class FunctionParser {
514540 EndOffset : resolvedSymbol . endOffset
515541 }
516542
517- if ( resolvedSymbol . isExternal ) {
543+ if ( resolvedSymbol . isExternal ) {
518544 calls . push ( dep ) ;
519545 return ;
520546 }
@@ -571,7 +597,7 @@ export class FunctionParser {
571597 EndOffset : resolvedSymbol . endOffset
572598 }
573599
574- if ( resolvedSymbol . isExternal ) {
600+ if ( resolvedSymbol . isExternal ) {
575601 calls . push ( dep ) ;
576602 return ;
577603 }
@@ -603,7 +629,24 @@ export class FunctionParser {
603629 const visited = new Set < string > ( ) ;
604630
605631 // Extract from type references and find their definitions
606- const typeNodes = node . getDescendantsOfKind ( SyntaxKind . Identifier ) ;
632+ const typeNodes : TypeNode [ ] = node . getDescendantsOfKind ( SyntaxKind . TypeReference )
633+
634+ for ( const param of node . getParameters ( ) ) {
635+ const t = param . getTypeNode ( )
636+ if ( t ) {
637+ typeNodes . push ( t )
638+ }
639+ }
640+
641+ const returnTypeNode = node . getReturnTypeNode ( ) ;
642+ if ( returnTypeNode ) typeNodes . push ( returnTypeNode ) ;
643+
644+ for ( const typeParam of node . getTypeParameters ( ) ) {
645+ const constraint = typeParam . getConstraint ( ) ;
646+ if ( constraint ) typeNodes . push ( constraint ) ;
647+ const def = typeParam . getDefault ( ) ;
648+ if ( def ) typeNodes . push ( def ) ;
649+ }
607650
608651 for ( const typeNode of typeNodes ) {
609652 // Handle union and intersection types by extracting individual type references
@@ -696,7 +739,8 @@ export class FunctionParser {
696739
697740 // Global variable assignments
698741 ( Node . isPropertyAssignment ( parent ) && parent . getNameNode ( ) === identifier ) ||
699- ( Node . isShorthandPropertyAssignment ( parent ) && parent . getNameNode ( ) === identifier )
742+ ( Node . isShorthandPropertyAssignment ( parent ) && parent . getNameNode ( ) === identifier ) ||
743+ Node . isTypeReference ( parent )
700744 ) {
701745 continue ;
702746 }
0 commit comments