UNPKG

@gnus.ai/upgrade-safe-transpiler-diamond

Version:

Solidity preprocessor used to generate OpenZeppelin Contracts Upgrade Safe using Diamond Pattern (EIP-2535).

59 lines 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ASTResolverError = exports.ASTResolver = void 0; const utils_1 = require("solidity-ast/utils"); class ASTResolver { constructor(output, exclude) { this.output = output; this.exclude = exclude; this.nodeInfoResolver = new utils_1.NodeInfoResolver(output); } resolveScope(id) { return this.nodeInfoResolver.getNodeInfo(id); } resolveContract(id) { var _a; const contract = (_a = this.nodeInfoResolver.getNodeInfo(id)) === null || _a === void 0 ? void 0 : _a.node; if (contract && contract.nodeType === 'ContractDefinition') { return contract; } return undefined; } resolveNode(nodeType, id, doThrows = true) { const node = this.tryResolveNode(nodeType, id, doThrows); if (node === undefined && doThrows) { throw new ASTResolverError(nodeType); } return node; } tryResolveNode(nodeType, id, doThrows = true) { var _a; const nodeInfo = this.resolveScope(id); if (nodeInfo) { const node = nodeInfo.node; if (nodeType === node.nodeType) { if (((_a = this.exclude) === null || _a === void 0 ? void 0 : _a.call(this, nodeInfo.path)) && doThrows) { throw new Error(`Symbol was imported from an excluded file (${nodeInfo.path})`); } else { return node; } } else { return undefined; } } return undefined; } } exports.ASTResolver = ASTResolver; class ASTResolverError extends Error { constructor(nodeType) { if (!Array.isArray(nodeType)) { nodeType = [nodeType]; } super(`Can't find required ${nodeType.join(',')}`); } } exports.ASTResolverError = ASTResolverError; //# sourceMappingURL=ast-resolver.js.map