UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

64 lines (62 loc) 3.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExportDeclarationCompiler = void 0; const tslib_1 = require("tslib"); const ts_utils_1 = require("@neo-one/ts-utils"); const typescript_1 = tslib_1.__importDefault(require("typescript")); const NodeCompiler_1 = require("../NodeCompiler"); class ExportDeclarationCompiler extends NodeCompiler_1.NodeCompiler { constructor() { super(...arguments); this.kind = typescript_1.default.SyntaxKind.ExportDeclaration; } visitNode(sb, node, optionsIn) { const options = sb.pushValueOptions(optionsIn); const getName = (namedExport) => { let name = ts_utils_1.tsUtils.node.getName(namedExport); const alias = ts_utils_1.tsUtils.importExport.getAliasName(namedExport); if (alias !== undefined) { name = alias; } return name; }; const getExportName = (namedExport) => ts_utils_1.tsUtils.node.getName(namedExport); const moduleSpecifier = ts_utils_1.tsUtils.importExport.getModuleSpecifierSourceFile(sb.context.typeChecker, node); sb.emitHelper(node, options, sb.helpers.getCurrentModule); if (moduleSpecifier === undefined) { ts_utils_1.tsUtils.exportDeclaration .getNamedExports(node) .filter((namedExport) => ts_utils_1.tsUtils.exportSpecifier .getLocalTargetDeclarations(sb.context.typeChecker, namedExport) .some((decl) => !ts_utils_1.tsUtils.declaration.isAmbient(decl))) .filter((namedExport) => { const symbol = sb.context.analysis.getSymbol(namedExport); return (symbol !== undefined && ts_utils_1.tsUtils.symbol.getDeclarations(symbol).some((decl) => !ts_utils_1.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); ts_utils_1.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'); } } exports.ExportDeclarationCompiler = ExportDeclarationCompiler; //# sourceMappingURL=ExportDeclarationCompiler.js.map