@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
32 lines (30 loc) • 1.1 kB
JavaScript
import { tsUtils } from '@neo-one/ts-utils';
import ts from 'typescript';
import { BuiltinInstanceMemberCall } from '../BuiltinInstanceMemberCall';
const isUTF8 = (node) => ts.isStringLiteral(node) && tsUtils.literal.getLiteralValue(node) === 'utf8';
export class BufferToString extends BuiltinInstanceMemberCall {
canCall(_sb, _func, node) {
const arg = tsUtils.argumented.getArguments(node)[0];
if (arg === undefined) {
return false;
}
return isUTF8(arg);
}
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 < 1) {
return;
}
if (optionsIn.pushValue) {
sb.emitHelper(node, options, sb.helpers.unwrapBuffer);
sb.emitHelper(node, options, sb.helpers.wrapString);
}
else {
sb.emitOp(node, 'DROP');
}
}
}
//# sourceMappingURL=toString.js.map