@@ -90,6 +90,7 @@ class ExpressionVisitor {
9090 private context : ts . TransformationContext ,
9191 private helper : VisitorHelper ,
9292 private expressionNode : ts . Expression ,
93+ private stubbedFunctionName ?: string ,
9394 ) { }
9495
9596 public result ( ) : ts . Expression {
@@ -104,6 +105,7 @@ class ExpressionVisitor {
104105 if ( type instanceof ptypes . FunctionPType ) type = type . returnType
105106
106107 const isGeneric = isGenericType ( type )
108+ const needsToCaptureTypeInfo = isGeneric && isStateOrBoxType ( type )
107109 const isArc4Encoded = isArc4EncodedType ( type )
108110 const info = isGeneric || isArc4Encoded ? getGenericTypeInfo ( type ) : undefined
109111 let updatedNode = node
@@ -113,20 +115,22 @@ class ExpressionVisitor {
113115 updatedNode = nodeFactory . instantiateARC4EncodedType ( updatedNode , info )
114116 }
115117 }
118+
116119 if ( ts . isCallExpression ( updatedNode ) ) {
117- const stubbedFunctionName = tryGetStubbedFunctionName ( updatedNode , this . helper )
118- const infos = [ info ]
120+ const stubbedFunctionName = this . stubbedFunctionName ?? tryGetStubbedFunctionName ( updatedNode , this . helper )
121+ this . stubbedFunctionName = undefined
122+ let infoArg = info
119123 if ( isCallingEmit ( stubbedFunctionName ) ) {
120- infos [ 0 ] = this . helper . resolveTypeParameters ( updatedNode ) . map ( getGenericTypeInfo ) [ 0 ]
124+ infoArg = this . helper . resolveTypeParameters ( updatedNode ) . map ( getGenericTypeInfo ) [ 0 ]
121125 }
122126 if ( isCallingDecodeArc4 ( stubbedFunctionName ) ) {
123127 const targetType = ptypes . ptypeToArc4EncodedType ( type , this . helper . sourceLocation ( node ) )
124128 const targetTypeInfo = getGenericTypeInfo ( targetType )
125- infos [ 0 ] = targetTypeInfo
129+ infoArg = targetTypeInfo
126130 }
127- updatedNode = stubbedFunctionName ? nodeFactory . callStubbedFunction ( stubbedFunctionName , updatedNode , ... infos ) : updatedNode
131+ updatedNode = stubbedFunctionName ? nodeFactory . callStubbedFunction ( stubbedFunctionName , updatedNode , infoArg ) : updatedNode
128132 }
129- return isGeneric
133+ return needsToCaptureTypeInfo
130134 ? nodeFactory . captureGenericTypeInfo ( ts . visitEachChild ( updatedNode , this . visit , this . context ) , JSON . stringify ( info ) )
131135 : ts . visitEachChild ( updatedNode , this . visit , this . context )
132136 }
@@ -218,8 +222,11 @@ class FunctionOrMethodVisitor {
218222 if ( ts . isNewExpression ( node ) ) {
219223 return new ExpressionVisitor ( this . context , this . helper , node ) . result ( )
220224 }
221- if ( ts . isCallExpression ( node ) && tryGetStubbedFunctionName ( node , this . helper ) ) {
222- return new ExpressionVisitor ( this . context , this . helper , node ) . result ( )
225+ if ( ts . isCallExpression ( node ) ) {
226+ const stubbedFunctionName = tryGetStubbedFunctionName ( node , this . helper )
227+ if ( stubbedFunctionName ) {
228+ return new ExpressionVisitor ( this . context , this . helper , node , stubbedFunctionName ) . result ( )
229+ }
223230 }
224231
225232 return node
@@ -305,6 +312,9 @@ const isGenericType = (type: ptypes.PType): boolean =>
305312 ptypes . TuplePType ,
306313 )
307314
315+ const isStateOrBoxType = ( type : ptypes . PType ) : boolean =>
316+ instanceOfAny ( type , ptypes . BoxMapPType , ptypes . BoxPType , ptypes . GlobalStateType , ptypes . LocalStateType )
317+
308318const isArc4EncodedType = ( type : ptypes . PType ) : boolean =>
309319 instanceOfAny (
310320 type ,
0 commit comments