Skip to content

Commit

Permalink
fix: Typo in logic sig visitor and typing of options decorators + inc…
Browse files Browse the repository at this point in the history
…rease test coverage
  • Loading branch information
tristanmenzel committed Dec 6, 2024
1 parent d8c8c9a commit 56725d2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/algo-ts/src/base-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ type ContractOptions = {
* @param options An object containing the configuration options
*/
export function contract(options: ContractOptions) {
return <TContract extends Contract>(contract: ConstructorFor<TContract>) => contract
return <T extends ConstructorFor<Contract>>(contract: T) => contract
}
2 changes: 1 addition & 1 deletion packages/algo-ts/src/logic-sig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ type LogicSigOptions = {
* @param options An object containing the configuration options
*/
export function logicsig(options: LogicSigOptions) {
return <TLogicSig extends LogicSig>(logicSig: ConstructorFor<TLogicSig>) => logicSig
return <T extends ConstructorFor<LogicSig>>(logicSig: T) => logicSig
}
14 changes: 7 additions & 7 deletions src/awst_build/ast-visitors/logic-sig-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ export class LogicSigVisitor extends BaseVisitor implements Visitor<ClassElement
this.context.addToCompilationSet(logicSig.id, logicSig)
}

private throwStructNotSupported(node: ts.Node, desc: string): never {
private throwLogicSigNotSupported(node: ts.Node, desc: string): never {
throw new CodeError(`${desc} are not supported in logic signature definitions`, {
sourceLocation: this.sourceLocation(node),
})
}

visitClassStaticBlockDeclaration(node: ts.ClassStaticBlockDeclaration) {
this.throwStructNotSupported(node, 'Class static block declarations')
this.throwLogicSigNotSupported(node, 'Class static block declarations')
}
visitConstructor(node: ts.ConstructorDeclaration) {
this.throwStructNotSupported(node, 'Constructor declarations')
this.throwLogicSigNotSupported(node, 'Constructor declarations')
}
visitGetAccessor(node: ts.GetAccessorDeclaration) {
this.throwStructNotSupported(node, 'Property declarations')
this.throwLogicSigNotSupported(node, 'Property declarations')
}
visitIndexSignature(node: ts.IndexSignatureDeclaration) {
this.throwStructNotSupported(node, 'Index signature declarations')
this.throwLogicSigNotSupported(node, 'Index signature declarations')
}
visitMethodDeclaration(node: ts.MethodDeclaration) {
const sourceLocation = this.sourceLocation(node)
Expand All @@ -108,12 +108,12 @@ export class LogicSigVisitor extends BaseVisitor implements Visitor<ClassElement
this.program = LogicSigProgramVisitor.buildLogicSigProgram(this.context.createChildContext(), node)
}
visitPropertyDeclaration(node: ts.PropertyDeclaration) {
this.throwStructNotSupported(node, 'Property declarations')
this.throwLogicSigNotSupported(node, 'Property declarations')
}
visitSemicolonClassElement(node: ts.SemicolonClassElement) {
// Ignore
}
visitSetAccessor(node: ts.SetAccessorDeclaration) {
this.throwStructNotSupported(node, 'Property declarations')
this.throwLogicSigNotSupported(node, 'Property declarations')
}
}
40 changes: 40 additions & 0 deletions tests/expected-output/logic-sig.algo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { logicsig, LogicSig } from '@algorandfoundation/algorand-typescript'

@logicsig({ name: 'BadLogicSig' })
// @expect-error Only one decorator is allowed per logic signature.
@logicsig({ name: 'BadLogicSig' })
class BadLogicSig extends LogicSig {
// @expect-error Property declarations are not supported in logic signature definitions
static staticProp: string
// @expect-error Class static block declarations are not supported in logic signature definitions
static {
this.staticProp = 'oh noes'
}

program(): boolean {
return true
}

// @expect-error Constructor declarations are not supported in logic signature definitions
constructor() {
super()
}

// @expect-error Property declarations are not supported in logic signature definitions
instanceProp: string = ''

// @expect-error Property declarations are not supported in logic signature definitions
get readAccessor() {
return this.instanceProp
}

// @expect-error Property declarations are not supported in logic signature definitions
set writeAccessor(val: string) {
this.instanceProp = val
}

// @expect-error LogicSig classes may only contain a program implementation method named 'program'. Consider making 'someMethod' a free subroutine.
public someMethod() {
return this.instanceProp + BadLogicSig.staticProp
}
}

0 comments on commit 56725d2

Please sign in to comment.