UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

69 lines (67 loc) 2.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ForwardValueAs = void 0; const ts_utils_1 = require("@neo-one/ts-utils"); const constants_1 = require("../../../constants"); const BuiltinInstanceMemberCall_1 = require("../../BuiltinInstanceMemberCall"); class ForwardValueAs extends BuiltinInstanceMemberCall_1.BuiltinInstanceMemberCall { constructor(type, isNullable = false) { super(); this.type = type; this.isNullable = isNullable; } canCall(_sb, _func, _node) { return true; } emitCall(sb, func, node, optionsIn, visited) { const options = sb.pushValueOptions(optionsIn); if (!visited) { sb.visit(ts_utils_1.tsUtils.expression.getExpression(func), options); } const handleValue = () => { if (this.type === constants_1.Types.Array) { sb.emitHelper(node, options, sb.helpers.arrMap({ map: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.wrapForwardValue); }, })); } if (this.type === constants_1.Types.Map) { sb.emitHelper(node, options, sb.helpers.mapMap({ map: (innerOptions) => { sb.emitHelper(node, innerOptions, sb.helpers.wrapForwardValue); sb.emitOp(node, 'SWAP'); sb.emitHelper(node, innerOptions, sb.helpers.wrapForwardValue); sb.emitOp(node, 'SWAP'); }, })); } sb.emitHelper(node, options, sb.helpers.wrapVal({ type: this.type })); }; sb.emitHelper(node, options, sb.helpers.unwrapForwardValue); if (this.isNullable) { sb.emitHelper(node, options, sb.helpers.if({ condition: () => { sb.emitOp(node, 'DUP'); sb.emitPushBuffer(node, Buffer.alloc(0, 0)); sb.emitOp(node, 'EQUAL'); }, whenTrue: () => { sb.emitOp(node, 'DROP'); sb.emitHelper(node, options, sb.helpers.wrapUndefined); }, whenFalse: () => { handleValue(); }, })); } else { handleValue(); } if (!optionsIn.pushValue) { sb.emitOp(node, 'DROP'); } } } exports.ForwardValueAs = ForwardValueAs; //# sourceMappingURL=ForwardValueAs.js.map