@solvprotocol/upgrade-safe-transpiler
Version:
Solidity preprocessor used to generate OpenZeppelin Contracts Upgrade Safe.
34 lines • 1.47 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConstructor = exports.getNodeBounds = exports.throwIfInvalidNode = void 0;
const ajv_1 = __importDefault(require("ajv"));
const util_1 = __importDefault(require("util"));
const schema_json_1 = __importDefault(require("solidity-ast/schema.json"));
const utils_1 = require("solidity-ast/utils");
const nodeSchemaValidator = new ajv_1.default({ allErrors: true });
// eslint-disable-next-line @typescript-eslint/no-var-requires
nodeSchemaValidator.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));
const isASTNode = nodeSchemaValidator.compile(schema_json_1.default);
function throwIfInvalidNode(node) {
if (!isASTNode(node)) {
throw new Error(util_1.default.inspect(node) + ' is not a valid AST node.');
}
}
exports.throwIfInvalidNode = throwIfInvalidNode;
function getNodeBounds(node) {
const [start, length] = node.src.split(':', 2).map(val => parseInt(val));
return { start, length };
}
exports.getNodeBounds = getNodeBounds;
function getConstructor(node) {
for (const fndef of (0, utils_1.findAll)('FunctionDefinition', node)) {
if (fndef.kind === 'constructor') {
return fndef;
}
}
}
exports.getConstructor = getConstructor;
//# sourceMappingURL=ast-utils.js.map