UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

52 lines (50 loc) 2.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ArrToStringHelper = void 0; const ts_utils_1 = require("@neo-one/ts-utils"); const types_1 = require("../types"); class ArrToStringHelper extends types_1.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 ? [] : ts_utils_1.tsUtils.type_.getArrayTypes(this.type); const type = types.length === 1 ? ts_utils_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'); }, })); }, })); } } exports.ArrToStringHelper = ArrToStringHelper; //# sourceMappingURL=ArrToStringHelper.js.map