mirror of
https://git.sfja.dk/Mikkel/slige.git
synced 2025-01-30 14:50:53 +00:00
test diagnostics
This commit is contained in:
parent
cd087392b9
commit
7766c88512
@ -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 =
|
||||
|
@ -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(
|
||||
|
27
compiler/test_diagnostics.ts
Normal file
27
compiler/test_diagnostics.ts
Normal 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 },
|
||||
},
|
||||
});
|
Loading…
Reference in New Issue
Block a user