UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

48 lines (46 loc) 1.93 kB
import { tsUtils } from '@neo-one/ts-utils'; import { TypedHelper } from '../types'; export class ArrToStringHelper extends TypedHelper { constructor({ type, knownType, hasJoinString = false }) { super({ type, knownType }); this.hasJoinString = hasJoinString; } emit(sb, node, options) { if (!options.pushValue) { sb.emitOp(node, 'DROP'); return; } const types = this.type === undefined ? [] : tsUtils.type_.getArrayTypes(this.type); const type = types.length === 1 ? tsUtils.type_.getArrayType(types[0]) : undefined; const joinString = sb.scope.addUnique(); if (!this.hasJoinString) { sb.emitPushString(node, ','); } sb.scope.set(sb, node, options, joinString); sb.emitPushString(node, ''); sb.emitHelper(node, options, sb.helpers.arrReduce({ withIndex: true, each: (innerOptions) => { sb.emitHelper(node, options, sb.helpers.if({ condition: () => { sb.emitOp(node, 'ROT'); sb.emitPushInt(node, 0); sb.emitOp(node, 'NUMEQUAL'); }, whenTrue: () => { sb.emitOp(node, 'DROP'); sb.emitHelper(node, innerOptions, sb.helpers.toString({ type, initial: false })); }, whenFalse: () => { sb.scope.get(sb, node, options, joinString); sb.emitOp(node, 'CAT'); sb.emitOp(node, 'SWAP'); sb.emitHelper(node, innerOptions, sb.helpers.toString({ type, initial: false })); sb.emitOp(node, 'CAT'); }, })); }, })); } } //# sourceMappingURL=ArrToStringHelper.js.map