Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion typescript/fixtures/broken.cell
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cell Broken {
role: "broken";
on(Ping p) { emit Pong; }
membrane { accepts: Ping; emits: Pong; }
}
1 change: 1 addition & 0 deletions typescript/transpiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ describe('transpiler (file-level)', () => {
const result = transpileCellFile({ file: bad });
assert.equal(result.ok, false);
assert.ok(result.errors.length > 0);
assert.match(result.errors[0], /^line 1, column 1: Cell 'Broken' must declare/);
});

it('returns filesystem error for missing file', () => {
Expand Down
7 changes: 6 additions & 1 deletion typescript/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface TranspileResult {
signals: string[];
}

function formatDiagnostic(diagnostic: { message: string; pos?: AST.Position }): string {
if (!diagnostic.pos) return diagnostic.message;
return `line ${diagnostic.pos.line}, column ${diagnostic.pos.col}: ${diagnostic.message}`;
}

function tsType(type?: AST.TypeExpr): string {
if (!type) return 'unknown';
switch (type.kind) {
Expand Down Expand Up @@ -229,7 +234,7 @@ export function transpileCellFile(opts: TranspileFileOptions): TranspileResult {
};
}

const errors = diagnostics.filter(d => d.kind === 'error').map(d => d.message);
const errors = diagnostics.filter(d => d.kind === 'error').map(formatDiagnostic);
if (errors.length > 0) {
return {
ok: false,
Expand Down