UNPKG

@solvprotocol/upgrade-safe-transpiler

Version:

Solidity preprocessor used to generate OpenZeppelin Contracts Upgrade Safe.

53 lines 1.66 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; } resolveContract(id) { try { return this.resolveNode('ContractDefinition', id); } catch (e) { if (e instanceof ASTResolverError) { return undefined; } else { throw e; } } } resolveNode(nodeType, id) { const node = this.tryResolveNode(nodeType, id); if (node === undefined) { throw new ASTResolverError(nodeType); } return node; } tryResolveNode(nodeType, id) { var _a; for (const source in this.output.sources) { for (const c of (0, utils_1.findAll)(nodeType, this.output.sources[source].ast)) { if (c.id === id) { if ((_a = this.exclude) === null || _a === void 0 ? void 0 : _a.call(this, source)) { throw new Error(`Symbol #${id} was imported from an excluded file (${source})`); } else { return c; } } } } } } exports.ASTResolver = ASTResolver; class ASTResolverError extends Error { constructor(nodeType) { super(`Can't find required ${nodeType}`); } } exports.ASTResolverError = ASTResolverError; //# sourceMappingURL=ast-resolver.js.map