@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
31 lines (29 loc) • 1.13 kB
JavaScript
import { tsUtils } from '@neo-one/ts-utils';
import ts from 'typescript';
import { BuiltinInstanceMemberCall } from '../BuiltinInstanceMemberCall';
export class ArrayReduce extends BuiltinInstanceMemberCall {
constructor() {
super(...arguments);
this.isReadonly = false;
}
canCall(_sb, _func, node) {
return ts.isCallExpression(node) && 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;
}
sb.emitHelper(node, options, sb.helpers.unwrapArray);
sb.visit(tsUtils.argumented.getArguments(node)[1], options);
sb.visit(tsUtils.argumented.getArguments(node)[0], options);
sb.emitHelper(node, options, sb.helpers.arrReduceFunc);
if (!optionsIn.pushValue) {
sb.emitOp(node, 'DROP');
}
}
}
//# sourceMappingURL=reduce.js.map