mirror of
https://git.sfja.dk/Mikkel/slige.git
synced 2025-01-30 22:20:54 +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 = {
|
export type File = {
|
||||||
stmts: Stmt[];
|
stmts: Stmt[];
|
||||||
};
|
};
|
||||||
@ -5,6 +7,7 @@ export type File = {
|
|||||||
export type Stmt = {
|
export type Stmt = {
|
||||||
id: number;
|
id: number;
|
||||||
kind: StmtKind;
|
kind: StmtKind;
|
||||||
|
span: Span;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type StmtKind =
|
export type StmtKind =
|
||||||
|
@ -52,7 +52,7 @@ export class FileTreeCollector implements ast.Visitor<[_P]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
visitModFileStmt(
|
visitModFileStmt(
|
||||||
_stmt: ast.Stmt,
|
stmt: ast.Stmt,
|
||||||
kind: ast.ModFileStmt,
|
kind: ast.ModFileStmt,
|
||||||
{ file }: _P,
|
{ file }: _P,
|
||||||
): ast.VisitRes {
|
): ast.VisitRes {
|
||||||
@ -65,6 +65,7 @@ export class FileTreeCollector implements ast.Visitor<[_P]> {
|
|||||||
severity: "fatal",
|
severity: "fatal",
|
||||||
msg: `module '${ident}' already declared`,
|
msg: `module '${ident}' already declared`,
|
||||||
file,
|
file,
|
||||||
|
span: stmt.span,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return new FileTreeCollector(
|
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