mirror of
https://github.com/oven-sh/bun
synced 2026-02-18 14:51:52 +00:00
fix(repl): include source location in parse error messages
Parse error messages now include line and column information when available (e.g., "Parse error [1:5]: Unexpected token") to help users locate the source of syntax errors more easily. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -932,10 +932,23 @@ pub const Repl = struct {
|
||||
const parse_result = transpiler.parse(parse_opts, null) orelse {
|
||||
// Check for parse errors
|
||||
if (transpiler.log.errors > 0) {
|
||||
// Print errors
|
||||
// Print errors with source location context if available
|
||||
for (transpiler.log.msgs.items) |msg| {
|
||||
if (msg.kind == .err) {
|
||||
Output.pretty("<red>Parse error: {s}<r>\n", .{msg.data.text});
|
||||
if (msg.data.location) |loc| {
|
||||
if (loc.line > 0) {
|
||||
// Include line and column information
|
||||
Output.pretty("<red>Parse error<r> <d>[{d}:{d}]<r><red>: {s}<r>\n", .{
|
||||
loc.line,
|
||||
loc.column + 1, // Convert 0-based to 1-based
|
||||
msg.data.text,
|
||||
});
|
||||
} else {
|
||||
Output.pretty("<red>Parse error: {s}<r>\n", .{msg.data.text});
|
||||
}
|
||||
} else {
|
||||
Output.pretty("<red>Parse error: {s}<r>\n", .{msg.data.text});
|
||||
}
|
||||
}
|
||||
}
|
||||
transpiler.log.msgs.clearRetainingCapacity();
|
||||
|
||||
Reference in New Issue
Block a user