UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

57 lines (55 loc) 2.05 kB
import { tsUtils } from '@neo-one/ts-utils'; import ts from 'typescript'; import { NodeCompiler } from '../NodeCompiler'; export class TypeOfExpressionCompiler extends NodeCompiler { constructor() { super(...arguments); this.kind = ts.SyntaxKind.TypeOfExpression; } visitNode(sb, node, optionsIn) { const options = sb.pushValueOptions(optionsIn); const expr = tsUtils.expression.getExpression(node); const createPushString = (value) => () => { sb.emitOp(node, 'DROP'); sb.emitPushString(node, value); }; const pushObject = createPushString('object'); sb.visit(expr, options); sb.emitHelper(node, options, sb.helpers.forBuiltinType({ type: sb.context.analysis.getType(expr), array: pushObject, arrayStorage: pushObject, boolean: createPushString('boolean'), buffer: pushObject, null: createPushString('null'), number: createPushString('number'), object: pushObject, string: createPushString('string'), symbol: createPushString('symbol'), undefined: createPushString('undefined'), map: pushObject, mapStorage: pushObject, set: pushObject, setStorage: pushObject, error: pushObject, forwardValue: pushObject, iteratorResult: pushObject, iterable: pushObject, iterableIterator: pushObject, transaction: pushObject, output: pushObject, attribute: pushObject, input: pushObject, account: pushObject, asset: pushObject, contract: pushObject, header: pushObject, block: pushObject, })); sb.emitHelper(node, options, sb.helpers.wrapString); if (!optionsIn.pushValue) { sb.emitOp(node, 'DROP'); } } } //# sourceMappingURL=TypeOfExpressionCompiler.js.map