UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

34 lines (32 loc) 1.38 kB
import { tsUtils } from '@neo-one/ts-utils'; import ts from 'typescript'; import { Types } from '../../../constants'; import { BuiltinInstanceMemberCall } from '../../BuiltinInstanceMemberCall'; export class MapStorageSet extends BuiltinInstanceMemberCall { canCall(_sb, _func, node) { return tsUtils.argumented.getArguments(node).length === 2; } emitCall(sb, func, node, optionsIn, visited) { const options = sb.pushValueOptions(optionsIn); if (!visited) { sb.visit(tsUtils.expression.getExpression(func), options); } if (tsUtils.argumented.getArguments(node).length < 2) { return; } const key = tsUtils.argumented.getArguments(node)[0]; const keyType = sb.context.analysis.getType(key); if (optionsIn.pushValue) { sb.emitOp(node, 'DUP'); } sb.visit(key, options); if (key.kind === ts.SyntaxKind.NumericLiteral) { sb.emitHelper(key, options, sb.helpers.unwrapNumber); sb.emitHelper(key, options, sb.helpers.coerceToInt); sb.emitHelper(key, options, sb.helpers.wrapNumber); } sb.visit(tsUtils.argumented.getArguments(node)[1], options); sb.emitHelper(node, optionsIn, sb.helpers.setStructuredStorage({ type: Types.MapStorage, keyType })); } } //# sourceMappingURL=set.js.map