UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

36 lines (34 loc) 1.2 kB
import { tsUtils } from '@neo-one/ts-utils'; import ts from 'typescript'; import { NodeCompiler } from '../NodeCompiler'; export class IfStatementCompiler extends NodeCompiler { constructor() { super(...arguments); this.kind = ts.SyntaxKind.IfStatement; } visitNode(sb, node, options) { const condition = () => { const cond = tsUtils.expression.getExpression(node); sb.visit(cond, sb.pushValueOptions(options)); sb.emitHelper(cond, sb.pushValueOptions(options), sb.helpers.toBoolean({ type: sb.context.analysis.getType(cond), })); }; const whenTrue = () => { sb.visit(tsUtils.statement.getThenStatement(node), options); }; let whenFalse; const nodeWhenFalse = tsUtils.statement.getElseStatement(node); if (nodeWhenFalse !== undefined) { whenFalse = () => { sb.visit(nodeWhenFalse, options); }; } sb.emitHelper(node, options, sb.helpers.if({ condition, whenTrue, whenFalse, })); } } //# sourceMappingURL=IfStatementCompiler.js.map