@@ -355,6 +355,7 @@ class MethodDecVisitor extends FunctionOrMethodVisitor {
355355
356356class ClassVisitor {
357357 private isArc4 : boolean
358+ private _sourceFileName : string | undefined
358359 constructor (
359360 private context : Context ,
360361 private helper : VisitorHelper ,
@@ -368,15 +369,23 @@ class ClassVisitor {
368369 return this . visit ( this . classDec ) as ts . ClassDeclaration
369370 }
370371
372+ private get sourceFileName ( ) : string {
373+ if ( ! this . _sourceFileName ) {
374+ this . _sourceFileName = normalisePath ( this . classDec . parent . getSourceFile ( ) . fileName , this . context . currentDirectory )
375+ }
376+ return this . _sourceFileName
377+ }
378+
371379 private visit = ( node : ts . Node ) : ts . Node => {
372380 if ( ts . isMethodDeclaration ( node ) ) {
373381 if ( this . classDec . name && this . isArc4 ) {
374382 const methodType = this . helper . resolveType ( node )
375383 if ( methodType instanceof ptypes . FunctionPType ) {
376384 const argTypes = methodType . parameters . map ( ( p ) => JSON . stringify ( getGenericTypeInfo ( p [ 1 ] ) ) )
377385 const returnType = JSON . stringify ( getGenericTypeInfo ( methodType . returnType ) )
378- const sourceFileName = normalisePath ( this . classDec . parent . getSourceFile ( ) . fileName , this . context . currentDirectory )
379- this . helper . additionalStatements . push ( nodeFactory . attachMetaData ( sourceFileName , this . classDec . name , node , argTypes , returnType ) )
386+ this . helper . additionalStatements . push (
387+ nodeFactory . attachMetaData ( this . sourceFileName , this . classDec . name , node , argTypes , returnType ) ,
388+ )
380389 }
381390 }
382391
0 commit comments