Files
test-repo/tests/config/format-test/visualize-range.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
803 B
JavaScript
Raw Normal View History

import indexToPosition from "index-to-position";
2026-02-01 08:57:18 +08:00
import { codeFrameColumns } from "../../../vendors/babel-code-frame-for-test.js";
const codeFrameColumnsOptions = {
linesAbove: Number.POSITIVE_INFINITY,
linesBelow: Number.POSITIVE_INFINITY,
};
2020-05-28 01:16:52 +08:00
2025-09-26 18:06:14 +08:00
const locationForRange = (text, range) => {
const [start, end] = [...range]
.sort((indexA, indexB) => indexA - indexB)
.map((index) => indexToPosition(text, index, { oneBasedLine: true }));
2020-05-28 01:16:52 +08:00
2025-09-26 18:06:14 +08:00
return { start, end };
2020-05-28 01:16:52 +08:00
};
const visualizeRange = (text, { rangeStart = 0, rangeEnd = text.length }) =>
codeFrameColumns(
text,
2025-09-26 18:06:14 +08:00
locationForRange(text, [rangeStart, rangeEnd]),
2020-11-30 12:29:48 +08:00
rangeStart > rangeEnd
? { ...codeFrameColumnsOptions, message: "[Reversed range]" }
: codeFrameColumnsOptions,
2020-05-28 01:16:52 +08:00
);
2022-01-04 17:00:25 +08:00
export default visualizeRange;