refactor(javascript): centralize source range comparison

This commit is contained in:
morluto
2026-07-24 13:43:13 +00:00
parent 4e8aa98267
commit c9500d32f6
5 changed files with 22 additions and 29 deletions
@@ -388,6 +388,17 @@ export const rangeForOffsets = (
end: pointForOffset(source, end),
});
/** Compare two exact source ranges. */
export const sourceRangesEqual = (
left: JavaScriptSourceRange | null,
right: JavaScriptSourceRange,
): boolean =>
left !== null &&
left.start.line === right.start.line &&
left.start.column === right.start.column &&
left.end.line === right.end.line &&
left.end.column === right.end.column;
const pointForOffset = (source: string, offset: number) => {
const before = source.slice(0, offset);
const lines = before.split("\n");