test diagnostics

This commit is contained in:
SimonFJ20 2025-01-23 10:28:48 +01:00
parent cd087392b9
commit 7766c88512
3 changed files with 32 additions and 1 deletions

View File

@ -1,3 +1,5 @@
import { Span } from "../diagnostics.ts";
export type File = {
stmts: Stmt[];
};
@ -5,6 +7,7 @@ export type File = {
export type Stmt = {
id: number;
kind: StmtKind;
span: Span;
};
export type StmtKind =

View File

@ -52,7 +52,7 @@ export class FileTreeCollector implements ast.Visitor<[_P]> {
}
visitModFileStmt(
_stmt: ast.Stmt,
stmt: ast.Stmt,
kind: ast.ModFileStmt,
{ file }: _P,
): ast.VisitRes {
@ -65,6 +65,7 @@ export class FileTreeCollector implements ast.Visitor<[_P]> {
severity: "fatal",
msg: `module '${ident}' already declared`,
file,
span: stmt.span,
});
}
return new FileTreeCollector(

View File

@ -0,0 +1,27 @@
import { Ctx } from "./ctx.ts";
import { prettyPrintReport } from "./diagnostics.ts";
const ctx = new Ctx();
const text = `
make an error here
`;
const file = ctx.addFile(
"root",
"path/file.ts",
"path/file.ts",
undefined,
text,
);
prettyPrintReport(ctx, {
file,
msg: "an error",
severity: "error",
origin: "compiler",
span: {
begin: { idx: 6, line: 2, col: 6 },
end: { idx: 13, line: 2, col: 13 },
},
});