refactor(javascript): own source range validation once

This commit is contained in:
morluto committed 2026-10-22 07:45:47 +08:00
1 parent 603a7d022c
commit 452e3ccad1
5 files changed
+54 -73

No files matched your search

@@ -0,0 +1,22 @@
import { z } from "zod";
const sourcePointSchema = z.strictObject({
line: z.number().int().min(1),
column: z.number().int().min(0),
});
/** JavaScript source coordinates use one-based lines and zero-based columns. */
export const javascriptSourceRangeSchema = z
.strictObject({ start: sourcePointSchema, end: sourcePointSchema })
.superRefine((range, context) => {
if (
range.end.line < range.start.line ||
(range.end.line === range.start.line &&
range.end.column < range.start.column)
)
context.addIssue({
code: "custom",
path: ["end"],
message: "Source range end must not precede its start",
});
});