UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

46 lines (44 loc) 1.88 kB
import { tsUtils } from '@neo-one/ts-utils'; import ts from 'typescript'; import { ContractPropertyName } from '../../../../constants'; import { BuiltinType } from '../../types'; export class SmartContractAddress { constructor() { this.types = new Set([BuiltinType.InstanceMemberValue]); } emitValue(sb, node, options, visited = false) { let isLinkedSmartContract = false; if (ts.isBindingElement(node)) { const propNode = tsUtils.node.getNameNode(node); const propSymbol = sb.context.analysis.getSymbol(propNode); if (propSymbol !== undefined) { const parentSymbol = tsUtils.symbol.getParent(propSymbol); if (parentSymbol !== undefined) { const decls = tsUtils.symbol.getDeclarations(parentSymbol); if (decls.length > 0) { isLinkedSmartContract = !sb.isCurrentSmartContract(decls[0]); } } } } else { isLinkedSmartContract = !sb.isCurrentSmartContract(tsUtils.expression.getExpression(node)); } if (isLinkedSmartContract) { if (!visited && (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node))) { sb.visit(tsUtils.expression.getExpression(node), sb.pushValueOptions(options)); } sb.emitPushString(node, ContractPropertyName.address); sb.emitHelper(node, options, sb.helpers.getPropertyObjectProperty); return; } if (visited) { sb.emitOp(node, 'DROP'); } if (options.pushValue) { sb.emitSysCall(node, 'System.ExecutionEngine.GetExecutingScriptHash'); sb.emitHelper(node, options, sb.helpers.wrapBuffer); } } } //# sourceMappingURL=address.js.map