UNPKG

@solvprotocol/upgrade-safe-transpiler

Version:

Solidity preprocessor used to generate OpenZeppelin Contracts Upgrade Safe.

35 lines 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sortTransformations = exports.split = exports.applyTransformation = void 0; const shifts_1 = require("../shifts"); const compare_1 = require("./compare"); function applyTransformation(t, content, shifts, helper) { const sb = (0, shifts_1.shiftBounds)(shifts, t); const [pre, mid, post] = split(content, sb.start, sb.length); const text = Buffer.from('text' in t ? t.text : t.transform(mid.toString(), helper)); const shift = { amount: text.length - sb.length, location: t.start + t.length, lengthZero: t.length === 0, }; const result = Buffer.concat([pre, text, post]); return { result, shift }; } exports.applyTransformation = applyTransformation; function split(source, start, length) { const pre = source.slice(0, start); const mid = source.slice(start, start + length); const post = source.slice(start + length); return [pre, mid, post]; } exports.split = split; function sortTransformations(transformations, sourcePath) { for (const t of transformations) { if (t.length < 0) { throw new Error(`${sourcePath}: transformation ${t.kind} has negative length`); } } return Array.from(transformations).sort(compare_1.compareTransformations); } exports.sortTransformations = sortTransformations; //# sourceMappingURL=apply.js.map