UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

59 lines (57 loc) 2.63 kB
import { tsUtils } from '@neo-one/ts-utils'; import ts from 'typescript'; import { NodeCompiler } from '../NodeCompiler'; export class ExportDeclarationCompiler extends NodeCompiler { constructor() { super(...arguments); this.kind = ts.SyntaxKind.ExportDeclaration; } visitNode(sb, node, optionsIn) { const options = sb.pushValueOptions(optionsIn); const getName = (namedExport) => { let name = tsUtils.node.getName(namedExport); const alias = tsUtils.importExport.getAliasName(namedExport); if (alias !== undefined) { name = alias; } return name; }; const getExportName = (namedExport) => tsUtils.node.getName(namedExport); const moduleSpecifier = tsUtils.importExport.getModuleSpecifierSourceFile(sb.context.typeChecker, node); sb.emitHelper(node, options, sb.helpers.getCurrentModule); if (moduleSpecifier === undefined) { tsUtils.exportDeclaration .getNamedExports(node) .filter((namedExport) => tsUtils.exportSpecifier .getLocalTargetDeclarations(sb.context.typeChecker, namedExport) .some((decl) => !tsUtils.declaration.isAmbient(decl))) .filter((namedExport) => { const symbol = sb.context.analysis.getSymbol(namedExport); return (symbol !== undefined && tsUtils.symbol.getDeclarations(symbol).some((decl) => !tsUtils.declaration.isAmbient(decl))); }) .forEach((namedExport) => { sb.emitOp(node, 'DUP'); sb.scope.get(sb, node, options, getName(namedExport)); sb.emitHelper(node, options, sb.helpers.export({ name: getExportName(namedExport) })); }); } else { sb.loadModule(moduleSpecifier); tsUtils.exportDeclaration .getNamedExports(node) .filter((namedExport) => sb.hasExport(moduleSpecifier, getName(namedExport))) .forEach((namedExport) => { sb.emitOp(node, 'SWAP'); sb.emitOp(node, 'TUCK'); sb.emitOp(node, 'OVER'); sb.emitPushString(node, getName(namedExport)); sb.emitOp(node, 'PICKITEM'); sb.emitHelper(node, options, sb.helpers.export({ name: getExportName(namedExport) })); }); sb.emitOp(node, 'DROP'); } sb.emitOp(node, 'DROP'); } } //# sourceMappingURL=ExportDeclarationCompiler.js.map