1- import {
2- anyPType ,
3- ARC4BooleanType ,
4- ARC4StringType ,
5- ARC4StructType ,
6- ARC4TupleType ,
7- BoxMapPType ,
8- BoxPType ,
9- ContractClassPType ,
10- DynamicArrayType ,
11- FunctionPType ,
12- GlobalStateType ,
13- LocalStateType ,
14- PType ,
15- SourceLocation ,
16- StaticArrayType ,
17- TypeResolver ,
18- UFixedNxMType ,
19- UintNType ,
20- } from '@algorandfoundation/puya-ts'
1+ import { ptypes , SourceLocation , TypeResolver } from '@algorandfoundation/puya-ts'
212import ts from 'typescript'
223import type { TypeInfo } from '../encoders'
234import { instanceOfAny } from '../typescript-helpers'
@@ -33,7 +14,7 @@ const { factory } = ts
3314
3415type VisitorHelper = {
3516 additionalStatements : ts . Statement [ ]
36- resolveType ( node : ts . Node ) : PType
17+ resolveType ( node : ts . Node ) : ptypes . PType
3718 sourceLocation ( node : ts . Node ) : SourceLocation
3819}
3920
@@ -49,11 +30,11 @@ export class SourceFileVisitor {
4930
5031 this . helper = {
5132 additionalStatements : [ ] ,
52- resolveType ( node : ts . Node ) : PType {
33+ resolveType ( node : ts . Node ) : ptypes . PType {
5334 try {
5435 return typeResolver . resolve ( node , this . sourceLocation ( node ) )
5536 } catch {
56- return anyPType
37+ return ptypes . anyPType
5738 }
5839 } ,
5940 sourceLocation ( node : ts . Node ) : SourceLocation {
@@ -106,7 +87,7 @@ class ExpressionVisitor {
10687 let type = this . helper . resolveType ( node )
10788
10889 // `voted = LocalState<uint64>()` is resolved to FunctionPType with returnType LocalState<uint64>
109- if ( type instanceof FunctionPType ) type = type . returnType
90+ if ( type instanceof ptypes . FunctionPType ) type = type . returnType
11091
11192 const isGeneric = isGenericType ( type )
11293 const isArc4Encoded = isArc4EncodedType ( type )
@@ -256,7 +237,7 @@ class ClassVisitor {
256237 private classDec : ts . ClassDeclaration ,
257238 ) {
258239 const classType = helper . resolveType ( classDec )
259- this . isArc4 = classType instanceof ContractClassPType && classType . isARC4
240+ this . isArc4 = classType instanceof ptypes . ContractClassPType && classType . isARC4
260241 }
261242
262243 public result ( ) : ts . ClassDeclaration {
@@ -267,7 +248,7 @@ class ClassVisitor {
267248 if ( ts . isMethodDeclaration ( node ) ) {
268249 if ( this . classDec . name && this . isArc4 ) {
269250 const methodType = this . helper . resolveType ( node )
270- if ( methodType instanceof FunctionPType ) {
251+ if ( methodType instanceof ptypes . FunctionPType ) {
271252 this . helper . additionalStatements . push ( nodeFactory . attachMetaData ( this . classDec . name , node , methodType ) )
272253 }
273254 }
@@ -282,50 +263,58 @@ class ClassVisitor {
282263 }
283264}
284265
285- const isGenericType = ( type : PType ) : boolean =>
266+ const isGenericType = ( type : ptypes . PType ) : boolean =>
286267 instanceOfAny (
287268 type ,
288- ARC4StructType ,
289- ARC4TupleType ,
290- BoxMapPType ,
291- BoxPType ,
292- DynamicArrayType ,
293- GlobalStateType ,
294- LocalStateType ,
295- StaticArrayType ,
296- UFixedNxMType ,
297- UintNType ,
269+ ptypes . ARC4StructType ,
270+ ptypes . ARC4TupleType ,
271+ ptypes . BoxMapPType ,
272+ ptypes . BoxPType ,
273+ ptypes . DynamicArrayType ,
274+ ptypes . GlobalStateType ,
275+ ptypes . LocalStateType ,
276+ ptypes . StaticArrayType ,
277+ ptypes . UFixedNxMType ,
278+ ptypes . UintNType ,
298279 )
299280
300- const isArc4EncodedType = ( type : PType ) : boolean =>
301- instanceOfAny ( type , ARC4StructType , ARC4TupleType , DynamicArrayType , StaticArrayType , UFixedNxMType , UintNType ) ||
302- type === ARC4StringType ||
303- type === ARC4BooleanType
304-
305- const getGenericTypeInfo = ( type : PType ) : TypeInfo => {
281+ const isArc4EncodedType = ( type : ptypes . PType ) : boolean =>
282+ instanceOfAny (
283+ type ,
284+ ptypes . ARC4StructType ,
285+ ptypes . ARC4TupleType ,
286+ ptypes . DynamicArrayType ,
287+ ptypes . StaticArrayType ,
288+ ptypes . UFixedNxMType ,
289+ ptypes . UintNType ,
290+ ) ||
291+ type === ptypes . ARC4StringType ||
292+ type === ptypes . ARC4BooleanType
293+
294+ const getGenericTypeInfo = ( type : ptypes . PType ) : TypeInfo => {
306295 const genericArgs : TypeInfo [ ] | Record < string , TypeInfo > = [ ]
307296
308- if ( instanceOfAny ( type , LocalStateType , GlobalStateType , BoxPType ) ) {
297+ if ( instanceOfAny ( type , ptypes . LocalStateType , ptypes . GlobalStateType , ptypes . BoxPType ) ) {
309298 genericArgs . push ( getGenericTypeInfo ( type . contentType ) )
310- } else if ( type instanceof BoxMapPType ) {
299+ } else if ( type instanceof ptypes . BoxMapPType ) {
311300 genericArgs . push ( getGenericTypeInfo ( type . keyType ) )
312301 genericArgs . push ( getGenericTypeInfo ( type . contentType ) )
313- } else if ( instanceOfAny ( type , StaticArrayType , DynamicArrayType ) ) {
302+ } else if ( instanceOfAny ( type , ptypes . StaticArrayType , ptypes . DynamicArrayType ) ) {
314303 genericArgs . push ( getGenericTypeInfo ( type . elementType ) )
315- } else if ( type instanceof UFixedNxMType ) {
304+ } else if ( type instanceof ptypes . UFixedNxMType ) {
316305 genericArgs . push ( { name : type . n . toString ( ) } )
317306 genericArgs . push ( { name : type . m . toString ( ) } )
318- } else if ( type instanceof UintNType ) {
307+ } else if ( type instanceof ptypes . UintNType ) {
319308 genericArgs . push ( { name : type . n . toString ( ) } )
320- } else if ( type instanceof ARC4StructType ) {
309+ } else if ( type instanceof ptypes . ARC4StructType ) {
321310 genericArgs . push (
322311 ...Object . fromEntries (
323312 Object . entries ( type . fields )
324313 . map ( ( [ key , value ] ) => [ key , getGenericTypeInfo ( value ) ] )
325314 . filter ( ( x ) => ! ! x ) ,
326315 ) ,
327316 )
328- } else if ( type instanceof ARC4TupleType ) {
317+ } else if ( type instanceof ptypes . ARC4TupleType ) {
329318 genericArgs . push ( ...type . items . map ( getGenericTypeInfo ) )
330319 }
331320
0 commit comments