diff --git a/package.json b/package.json index 15ee4fb..50b0976 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tezwell/smartts-sdk", - "version": "0.7.1", + "version": "0.7.2", "description": "SmartTS SDK is a metaprogramming framework for building Tezos smart contracts from Javascript.", "keywords": [ "Tezos", diff --git a/src/core/statement.ts b/src/core/statement.ts index d0da035..8f66892 100644 --- a/src/core/statement.ts +++ b/src/core/statement.ts @@ -5,8 +5,8 @@ import { LineInfo } from '../misc/utils'; import StatementAtom from './enums/statement'; import { Expression } from './expression'; import ExpressionAtom from './enums/expression'; -import { Proxied, proxy } from '../misc/proxy'; -import { Add, GetVariable, Iterator, LessThanOrEqual } from '../expression'; +import { Proxied } from '../misc/proxy'; +import { Add, GetVariable, Iterator, LessThanOrEqual, VariantCaseArgument } from '../expression'; import { NewVariable, SetValue } from '../statement'; export class Statement implements IStatement { @@ -87,7 +87,7 @@ export class VariantMatchStatement implements IStatement { variantArgumentName?: string, ): this { variantArgumentName ||= `${this.argumentName}_${branch}`; - const variantArgument = this.variantArgument(variantArgumentName, this.line); + const variantArgument = VariantCaseArgument(variantArgumentName, this.line); this.cases[branch] = { argumentName: variantArgumentName, statements: buildStatements(variantArgument) }; return this; } @@ -96,10 +96,6 @@ export class VariantMatchStatement implements IStatement { return new Expression(ExpressionAtom.cases_arg, `"${argumentName}"`, line); } - private variantArgument(argumentName: string, line: LineInfo) { - return proxy(new Expression(ExpressionAtom.variant_arg, `"${argumentName}"`, line), Expression.proxyHandler); - } - [Symbol.toPrimitive]() { const caseArgument = this.caseArgument(this.argumentName, this.line); const matchCases = Object.keys(this.cases).map((branch) => { diff --git a/src/expression/variables.ts b/src/expression/variables.ts index a18dfb5..0ca1f3c 100644 --- a/src/expression/variables.ts +++ b/src/expression/variables.ts @@ -112,6 +112,23 @@ export const LambdaArgument = ( Expression.proxyHandler, ); +/** + * Get the argument of a variant match case. + * + * ```typescript + * VariantCaseArgument("action_1") + * ``` + * + * @category | Variable Accessors + * + * @param name The name of the argument + * @param {LineInfo} line Source code line information (Used in error messages) + * + * @returns {IExpression} An expression + */ +export const VariantCaseArgument = (name: string, line = new LineInfo()) => + proxy(new Expression(ExpressionAtom.variant_arg, `"${name}"`, line), Expression.proxyHandler); + /** * Get operations list from the stack or an empty list otherwise. *