UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

32 lines (30 loc) 1.27 kB
import { tsUtils } from '@neo-one/ts-utils'; import ts from 'typescript'; import { NodeCompiler } from '../NodeCompiler'; export class TemplateExpressionCompiler extends NodeCompiler { constructor() { super(...arguments); this.kind = ts.SyntaxKind.TemplateExpression; } visitNode(sb, node, optionsIn) { const options = sb.pushValueOptions(optionsIn); const head = tsUtils.template.getTemplateHead(node); sb.emitPushString(head, tsUtils.literal.getLiteralValue(head)); tsUtils.template.getTemplateSpans(node).forEach((span) => { const expr = tsUtils.expression.getExpression(span); sb.visit(expr, options); sb.emitHelper(expr, options, sb.helpers.toString({ type: sb.context.analysis.getType(expr) })); sb.emitOp(expr, 'CAT'); const spanLiteral = tsUtils.template.getLiteral(span); sb.emitPushString(spanLiteral, tsUtils.literal.getLiteralValue(spanLiteral)); sb.emitOp(expr, 'CAT'); }); if (optionsIn.pushValue) { sb.emitHelper(node, options, sb.helpers.wrapString); } else { sb.emitOp(node, 'DROP'); } } } //# sourceMappingURL=TemplateExpressionCompiler.js.map