UNPKG

@solvprotocol/upgrade-safe-transpiler

Version:

Solidity preprocessor used to generate OpenZeppelin Contracts Upgrade Safe.

38 lines 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.compareContainment = exports.compareTransformations = void 0; function compareTransformations(a, b) { const c = compareContainment(a, b); if (c === 'partial overlap') { throw new Error(`Transformations ${a.kind} and ${b.kind} overlap`); } else if (c === 'disjoint') { // sort by midpoint return a.start + a.length / 2 - (b.start + b.length / 2); } else { return c; } } exports.compareTransformations = compareTransformations; function compareContainment(a, b) { const a_end = a.start + a.length; const b_end = b.start + b.length; const x = (a.start - b.start) * (a_end - b_end); if (x > 0 || (x === 0 && a.length * b.length === 0)) { if (a.start === b.start && a.length === b.length) { return 0; } else if (a.start + a.length <= b.start || b.start + b.length <= a.start) { return 'disjoint'; } else { return 'partial overlap'; } } else { return a.length - b.length; } } exports.compareContainment = compareContainment; //# sourceMappingURL=compare.js.map