UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

44 lines (42 loc) 1.62 kB
import { tsUtils } from '@neo-one/ts-utils'; import ts from 'typescript'; import { NodeCompiler } from '../NodeCompiler'; export class ForStatementCompiler extends NodeCompiler { constructor() { super(...arguments); this.kind = ts.SyntaxKind.ForStatement; } visitNode(sb, node, options) { let condition; const exprCondition = tsUtils.statement.getCondition(node); if (exprCondition !== undefined) { condition = () => { sb.visit(exprCondition, sb.pushValueOptions(options)); sb.emitHelper(exprCondition, sb.pushValueOptions(options), sb.helpers.toBoolean({ type: sb.context.analysis.getType(exprCondition), })); }; } let incrementor; const exprIncrementor = tsUtils.statement.getIncrementor(node); if (exprIncrementor !== undefined) { incrementor = () => { sb.visit(exprIncrementor, sb.noPushValueOptions(options)); }; } const exprInitializer = tsUtils.statement.getInitializer(node); if (exprInitializer !== undefined) { sb.visit(exprInitializer, sb.noPushValueOptions(options)); } sb.emitHelper(node, options, sb.helpers.forLoop({ condition, incrementor, each: (innerOptions) => { sb.visit(tsUtils.statement.getStatement(node), sb.noPushValueOptions(innerOptions)); }, cleanup: () => { }, })); } } //# sourceMappingURL=ForStatementCompiler.js.map